Give failure one spelling

This commit is contained in:
2026-09-28 21:21:35 +02:00
parent 750c417c2d
commit 0fc6afd1e7
10 changed files with 22 additions and 26 deletions
+3 -3
View File
@@ -5,7 +5,7 @@ from loop_claude.checkout import project_name
from loop_claude.file_writes import make_private, replace_file from loop_claude.file_writes import make_private, replace_file
from loop_claude.interrupt import interrupt from loop_claude.interrupt import interrupt
from loop_claude.judge import judge from loop_claude.judge import judge
from loop_claude.outcome import Continue, Failure, Retry, Stop from loop_claude.outcome import Continue, Failure, Stop
from loop_claude.session import delete_session, session_for, transcript_file from loop_claude.session import delete_session, session_for, transcript_file
from loop_claude.transcript import read, render from loop_claude.transcript import read, render
from loop_claude.worker import run_worker, worker_args from loop_claude.worker import run_worker, worker_args
@@ -15,7 +15,7 @@ def run_cycle(root, task, premises, models, paths):
session = session_for(root, paths) session = session_for(root, paths)
resuming = bool(transcript_file(session)) resuming = bool(transcript_file(session))
if failure := run_worker(root, worker_args(task, session, models.worker, resuming)): if failure := run_worker(root, worker_args(task, session, models.worker, resuming)):
return Retry(failure.reason) return failure
path = transcript_file(session) path = transcript_file(session)
if not path: if not path:
return Stop(1, f"claude left no transcript for session {session.id}") return Stop(1, f"claude left no transcript for session {session.id}")
@@ -57,6 +57,6 @@ def archive(root, path, note, paths):
if not copy.exists(): if not copy.exists():
for dest, data in ((copy.with_suffix(".verdict.md"), f"{note}\n".encode()), (copy, raw)): for dest, data in ((copy.with_suffix(".verdict.md"), f"{note}\n".encode()), (copy, raw)):
if failure := replace_file(dest, data): if failure := replace_file(dest, data):
return Failure(f"could not archive the transcript: {dest}: {failure.strerror}") return Failure(f"could not archive the transcript: {dest}: {failure.reason}")
print(f"transcript: {copy}", file=sys.stderr) print(f"transcript: {copy}", file=sys.stderr)
return None return None
+3 -1
View File
@@ -1,6 +1,8 @@
import json import json
import os import os
from loop_claude.outcome import Failure
def make_private(folder): def make_private(folder):
mask = os.umask(0o077) mask = os.umask(0o077)
@@ -25,5 +27,5 @@ def replace_file(path, data):
except OSError as failure: except OSError as failure:
if os.path.exists(staged): if os.path.exists(staged):
os.remove(staged) os.remove(staged)
return failure return Failure(failure.strerror)
return None return None
+3 -3
View File
@@ -39,7 +39,7 @@ import sys
from loop_claude.checkout import checkout_root from loop_claude.checkout import checkout_root
from loop_claude.cycle import run_cycle from loop_claude.cycle import run_cycle
from loop_claude.models import project_models from loop_claude.models import project_models
from loop_claude.outcome import Continue, Retry, Stop from loop_claude.outcome import Continue, Failure, Stop
from loop_claude.premises import read_premises from loop_claude.premises import read_premises
from loop_claude.reload import RELOAD_FLAG, decode_state, exec_if_edited, fingerprint from loop_claude.reload import RELOAD_FLAG, decode_state, exec_if_edited, fingerprint
from loop_claude.retry import stop_or_sleep_a_minute from loop_claude.retry import stop_or_sleep_a_minute
@@ -81,9 +81,9 @@ def run_loop(argv, env, paths, launcher, cwd):
match run_cycle(state.root, state.task, premises, models, paths): match run_cycle(state.root, state.task, premises, models, paths):
case Stop() as stop: case Stop() as stop:
return stop return stop
case Retry(failure): case Failure(reason):
state = dataclasses.replace(state, failures=state.failures + 1) state = dataclasses.replace(state, failures=state.failures + 1)
if stop := stop_or_sleep_a_minute("worker", state.failures, failure): if stop := stop_or_sleep_a_minute("worker", state.failures, reason):
return stop return stop
case Continue(): case Continue():
state = dataclasses.replace(state, failures=0) state = dataclasses.replace(state, failures=0)
+1 -1
View File
@@ -40,7 +40,7 @@ def project_model(name, paths):
if isinstance(models, Stop): if isinstance(models, Stop):
return models return models
if failure := replace_json(saved, {**models, name: chosen}, indent="\t", sort_keys=True): if failure := replace_json(saved, {**models, name: chosen}, indent="\t", sort_keys=True):
return Stop(1, f"could not save the model in {saved}: {failure.strerror}") return Stop(1, f"could not save the model in {saved}: {failure.reason}")
print(f"{name} runs on {chosen}", file=sys.stderr) print(f"{name} runs on {chosen}", file=sys.stderr)
return chosen return chosen
-5
View File
@@ -11,11 +11,6 @@ class Failure:
reason: str reason: str
@dataclasses.dataclass(frozen=True)
class Retry:
failure: str
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True)
class Stop: class Stop:
code: int code: int
+2 -2
View File
@@ -19,13 +19,13 @@ def human_turns(entries):
def render(entries): def render(entries):
lines = [] lines = []
for entry in entries: for entry in entries:
lines += [line for part in assistant_parts(entry) if (line := said(part))] lines += [line for part in assistant_parts(entry) if (line := part_line(part))]
if (text := human_text(entry)) is not None: if (text := human_text(entry)) is not None:
lines.append("[human] " + text) lines.append("[human] " + text)
return "\n\n".join(lines) return "\n\n".join(lines)
def said(part, limit=400): def part_line(part, limit=400):
if (text := part_text(part)) and text.strip(): if (text := part_text(part)) and text.strip():
return text return text
if call := tool_call(part): if call := tool_call(part):
+1 -1
View File
@@ -21,6 +21,6 @@ def trust(config, roots):
if not untrusted: if not untrusted:
return return
if failure := replace_json(config, data, indent=2): if failure := replace_json(config, data, indent=2):
print(f"could not write {config}: {failure.strerror}", file=sys.stderr) print(f"could not write {config}: {failure.reason}", file=sys.stderr)
return return
print("trusted for the interrupt: " + ", ".join(untrusted), file=sys.stderr) print("trusted for the interrupt: " + ", ".join(untrusted), file=sys.stderr)
+2 -2
View File
@@ -2,7 +2,7 @@ import subprocess
from loop_claude.claude_code import assistant_parts, ends_stream, parse from loop_claude.claude_code import assistant_parts, ends_stream, parse
from loop_claude.outcome import Failure from loop_claude.outcome import Failure
from loop_claude.transcript import said from loop_claude.transcript import part_line
def run_worker(root, args): def run_worker(root, args):
@@ -16,7 +16,7 @@ def run_worker(root, args):
event = parse(raw) or {} event = parse(raw) or {}
done = done or ends_stream(event) done = done or ends_stream(event)
for part in assistant_parts(event): for part in assistant_parts(event):
if line := said(part, 160): if line := part_line(part, 160):
print(line, flush=True) print(line, flush=True)
code = proc.wait() code = proc.wait()
if code < 0: if code < 0:
+7 -7
View File
@@ -8,7 +8,7 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from loop_claude import claude_code, file_writes, judge, main, premises, transcript from loop_claude import claude_code, file_writes, judge, main, premises, transcript
from loop_claude.outcome import Stop from loop_claude.outcome import Failure, Stop
CWD = pathlib.Path("/c") CWD = pathlib.Path("/c")
@@ -58,12 +58,12 @@ class HumanTurns(unittest.TestCase):
]), 3) ]), 3)
class Said(unittest.TestCase): class PartLine(unittest.TestCase):
def test_renders_text_and_tool_calls_and_nothing_else(self): def test_renders_text_and_tool_calls_and_nothing_else(self):
self.assertEqual(transcript.said({"type": "text", "text": "hi"}), "hi") self.assertEqual(transcript.part_line({"type": "text", "text": "hi"}), "hi")
self.assertEqual(transcript.said({"type": "text", "text": " \n"}), "") self.assertEqual(transcript.part_line({"type": "text", "text": " \n"}), "")
self.assertEqual(transcript.said({"type": "tool_use", "name": "Bash", "input": {"command": "x" * 500}}, 20), '[tool Bash] {"command": "xxxxxxx') self.assertEqual(transcript.part_line({"type": "tool_use", "name": "Bash", "input": {"command": "x" * 500}}, 20), '[tool Bash] {"command": "xxxxxxx')
self.assertEqual(transcript.said("not a part"), "") self.assertEqual(transcript.part_line("not a part"), "")
class Parse(unittest.TestCase): class Parse(unittest.TestCase):
@@ -103,7 +103,7 @@ class ReplaceFile(unittest.TestCase):
def test_removes_what_it_staged_when_the_replace_fails(self): def test_removes_what_it_staged_when_the_replace_fails(self):
with tempfile.TemporaryDirectory() as root: with tempfile.TemporaryDirectory() as root:
os.mkdir(os.path.join(root, "in-the-way")) os.mkdir(os.path.join(root, "in-the-way"))
self.assertIsInstance(file_writes.replace_file(os.path.join(root, "in-the-way"), b"data"), IsADirectoryError) self.assertEqual(file_writes.replace_file(os.path.join(root, "in-the-way"), b"data"), Failure("Is a directory"))
self.assertEqual(os.listdir(root), ["in-the-way"]) self.assertEqual(os.listdir(root), ["in-the-way"])
-1
View File
@@ -8,7 +8,6 @@ The rebuild lifts every dimension: each item below is one chunk on a worktree ba
The places the panel on `rebuild` at 37edc9a named (`docs/decisions.md`), capping dimension first: The places the panel on `rebuild` at 37edc9a named (`docs/decisions.md`), capping dimension first:
- **Give failure one spelling: `Failure.reason` and `Retry.failure`, `replace_file`'s raw `OSError`, and `said` named for what it tests.** Keep `LoopState`'s fields: they are main's `--reloaded` state (`docs/decisions.md`).
- **Group `bin/loop_claude/`'s 18 flat modules, and move `principles/review-findings.md` beside larv-review.** Two seats; `claude_code.py` is the first group. - **Group `bin/loop_claude/`'s 18 flat modules, and move `principles/review-findings.md` beside larv-review.** Two seats; `claude_code.py` is the first group.
- **Show the judge a reply the human sends while claude works.** Claude Code 2.1.284 writes it as an `"attachment"` entry, which `render` drops, so the judge can rule on a question the human already answered during an interrupt. - **Show the judge a reply the human sends while claude works.** Claude Code 2.1.284 writes it as an `"attachment"` entry, which `render` drops, so the judge can rule on a question the human already answered during an interrupt.
- **Score `rebuild` with the four-seat panel at 7.0 or above on every dimension and the overall, none below the last run, and open its PR into main for the human.** ⚠️ Leave that PR ready and unmerged: only the human merges it, after approving the whole rebuild. A dimension under the floor gets its places filed above this item. - **Score `rebuild` with the four-seat panel at 7.0 or above on every dimension and the overall, none below the last run, and open its PR into main for the human.** ⚠️ Leave that PR ready and unmerged: only the human merges it, after approving the whole rebuild. A dimension under the floor gets its places filed above this item.