From 57ddf715b3ad0091908ce24a6f5f3d9ec5276761 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 2 Oct 2026 09:17:16 +0200 Subject: [PATCH] Answer the stability, product-owner and prose reviews' first round --- CHANGELOG.md | 2 +- bin/loop_claude/cycle/judge.py | 2 +- bin/loop_claude/cycle/retry.py | 6 ++--- bin/loop_claude/cycle/states.py | 2 +- bin/loop_claude/failure.py | 2 +- bin/loop_claude/loop/main.py | 43 +++++++++++++++++-------------- bin/loop_claude/loop/reload.py | 2 +- bin/test_loop_claude.py | 6 ++--- bin/test_loop_claude_black_box.py | 4 +-- docs/decisions.md | 4 +-- todo.md | 6 ++--- 11 files changed, 41 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c0cc17d..cf75fbdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ - `loop-claude`'s judge quotes the transcript for every verdict, and a verdict quoting nothing or interrupting without a question, or a `claude` the judge cannot start, is a failed judge run; a `claude` that cannot start for an interrupt exits 1. - `loop-claude`'s exit-2 message says what the human is needed for. - `loop-claude` exits 1 saying why when `git`, or python for a reload, cannot start. -- `loop-claude --help` lists each exit-1 cause on its own line, and a reload's exit 1 names what it could not read and the likely cause: the edit changed what one script hands the next. +- `loop-claude --help` lists each exit cause on its own line, and when an edit to `loop-claude` breaks its reload, the exit-1 message names what the edited script could not read. - `loop-claude` shows the judge's reply when it rejects the judge's verdict. - `loop-claude` retries a failed worker within its cycle. - `loop-claude` counts an interrupt reply starting with `<` as typed. diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index cece3396..76e2f1bb 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -74,7 +74,7 @@ def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str, if isinstance(verdict, Failure): return Failure(f"{verdict.reason}; it replied: {proc.stdout.strip() or 'nothing'}") if not grounded(verdict.evidence, rendered_transcript): - return Failure(f"the judge quoted {verdict.evidence!r}, nothing in the transcript" + (f", for the question: {verdict.question}" if isinstance(verdict, Interrupt) else "")) + return Failure(f"the judge quoted {verdict.evidence!r}, which is not in the transcript" + (f", for the question: {verdict.question}" if isinstance(verdict, Interrupt) else "")) return verdict diff --git a/bin/loop_claude/cycle/retry.py b/bin/loop_claude/cycle/retry.py index 392b3d2e..9a4d73b2 100644 --- a/bin/loop_claude/cycle/retry.py +++ b/bin/loop_claude/cycle/retry.py @@ -5,8 +5,6 @@ from loop_claude.effects import Effects from loop_claude.failure import Failure from loop_claude.stop import Stop -ATTEMPTS = 3 -RETRY_DELAY_SECONDS = 60 T = typing.TypeVar("T") @@ -17,7 +15,7 @@ def retried(who: str, attempt: typing.Callable[[], T | Failure], effects: Effect result = attempt() if not isinstance(result, Failure): return result - if failures == ATTEMPTS: + if failures == 3: return Stop(1, f"the {who} failed three times running: {result.reason}") print(f"retrying the {who} in a minute: {result.reason}", file=sys.stderr) - effects.sleep(RETRY_DELAY_SECONDS) + effects.sleep(60) diff --git a/bin/loop_claude/cycle/states.py b/bin/loop_claude/cycle/states.py index cbf2a60c..14d8a36a 100644 --- a/bin/loop_claude/cycle/states.py +++ b/bin/loop_claude/cycle/states.py @@ -66,7 +66,7 @@ def transition(state: State, event: Event) -> State: return Finishing(transcript_path) case Judging(), Ruled(Unfinished()): return Ended() - # The interrupt is a whole claude session on the terminal, so the judge rules again on what it left. + # The human works in the interrupt's claude session, so the judge rules again on the transcript it leaves. case Interrupting(transcript_path), Answered(): return Judging(transcript_path) case Finishing(), Archived(): diff --git a/bin/loop_claude/failure.py b/bin/loop_claude/failure.py index 996febdc..a9102158 100644 --- a/bin/loop_claude/failure.py +++ b/bin/loop_claude/failure.py @@ -3,5 +3,5 @@ import dataclasses @dataclasses.dataclass(frozen=True) class Failure: - """A step failed, for reason; its caller decides what follows.""" + """A step failed with reason; its caller decides what follows.""" reason: str diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index eca28366..0fdbf84f 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -4,12 +4,26 @@ usage: loop-claude Run it anywhere inside a project checkout whose README.md has ## Goals and ## Audience, the premises; the task runs at the checkout root. Each cycle a worker runs the task; a judge then reads -the transcript against them and rules whether the chunk, the work of one PR, is finished. +the transcript against the premises and rules whether the chunk, the work of one PR, is finished. A question only the human can answer, or a release ready to cut, is an interrupt: `claude --resume` on the terminal, every worktree first marked trusted in ~/.claude.json. An unfinished chunk resumes its session next cycle; the next chunk starts a fresh session. Cycles continue until an exit below or Ctrl-C. Words: ~/.claude/CLAUDE.md → "Vocabulary". +Each project has one session, named "A loop-claude", where is the checkout's path +relative to ~/code, or to / outside it. The session is deleted when its chunk finishes. At every +interrupt, and when the chunk finishes, the session's transcript is copied to +$LOOP_CLAUDE_TRANSCRIPTS//.jsonl (default ~/.claude/loop-claude-transcripts), the +verdict beside it in .verdict.md. + +Every claude it starts runs the project's model, saved per in ~/.claude/loop-claude-models.json +and read each cycle; a project without an entry, as on its first run, is asked for one. +LOOP_CLAUDE_JUDGE_MODEL overrides it for the judge, LOOP_CLAUDE_WORKER_MODEL for the worker and the +interrupt; with both set, nothing is asked. + +A change to bin/loop-claude or bin/loop_claude/**/*.py takes effect at the next cycle boundary, once +loop-claude --help succeeds: the loop reloads into the edited script. + Exit 1, saying why, when: - no task is given - git cannot start or finds no checkout @@ -20,28 +34,19 @@ Exit 1, saying why, when: - a finished chunk's session cannot be deleted - claude cannot start for an interrupt - python cannot start for a reload -- a reload cannot read the cycle number, checkout root and task the edited script was handed, as - when the edit changed what one script hands the next +- a reload cannot read the cycle number, checkout root and task the running script handed it, + likely because the edit changed that handover - the worker or the judge fails three times running, retried a minute apart within the cycle. A worker fails when claude cannot start, exits non-zero, is killed, or ends without a result event; a judge when claude cannot start or exits non-zero, or its reply misses or mistypes a field, - interrupts without a question, or quotes nothing in the transcript. -Exit 2: the human is needed, to pick the model or answer an interrupt, and stdin or stdout is not a -terminal, the input ends, or the interrupt ended with nothing typed. Rerunning resumes any -open session. + interrupts without a question, or quotes a line the transcript does not hold. -Each project has one session, "A loop-claude", being the checkout relative to ~/code, -or to / outside it, deleted when the chunk finishes. At every interrupt and when the chunk finishes -its transcript is copied to $LOOP_CLAUDE_TRANSCRIPTS//.jsonl (default -~/.claude/loop-claude-transcripts), the verdict beside it in .verdict.md. +Exit 2, when the human is needed and cannot answer: +- stdin or stdout is not a terminal, when a model must be picked or an interrupt answered +- the input ends while a model is picked +- an interrupt ends with nothing typed +Rerunning resumes any open session. -Every claude it starts runs the project's model, saved per in ~/.claude/loop-claude-models.json -and read each cycle; a project without an entry, as on its first run, is asked for one. -LOOP_CLAUDE_JUDGE_MODEL overrides it for the judge, LOOP_CLAUDE_WORKER_MODEL for the worker and the -interrupt; with both set, nothing is asked. - -A change to bin/loop-claude or bin/loop_claude/**/*.py takes effect at the next cycle boundary, once -loop-claude --help succeeds. """ import dataclasses import pathlib @@ -100,5 +105,5 @@ def loop_run_from(argv: list[str], cwd: pathlib.Path, effects: Effects) -> LoopR return root if isinstance(root, Stop) else LoopRun(0, root, task) loop_run = decode_handed(argv[1], LoopRun) if len(argv) == 2 else None if not (loop_run and loop_run.root and loop_run.task): - return Stop(1, f"the reload cannot read the cycle number, checkout root and task the edited script was handed in {argv[1:]}, as when the edit changed what one script hands the next; rerun loop-claude ") + return Stop(1, f"the edited loop-claude cannot read the cycle number, checkout root and task the running one handed it, likely because the edit changed that handover; rerun loop-claude . Handed: {' '.join(argv[1:])}") return loop_run diff --git a/bin/loop_claude/loop/reload.py b/bin/loop_claude/loop/reload.py index 0dafe413..82e581ae 100644 --- a/bin/loop_claude/loop/reload.py +++ b/bin/loop_claude/loop/reload.py @@ -15,7 +15,7 @@ T = typing.TypeVar("T") # A field change stops a running loop at its next reload: the new script rejects the old fields. @dataclasses.dataclass(frozen=True) class LoopRun: - """What a reload hands the edited script, as JSON on argv: the cycle number, checkout root and task.""" + """What a reload hands the edited script, as JSON on argv.""" cycle_number: int root: str task: str diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 0eb9a1ff..78effad3 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -348,7 +348,7 @@ class LoopRuns(unittest.TestCase): def test_stops_naming_the_reload_when_it_hands_over_anything_but_the_state_with_a_task(self): for handed in (["3", "2", "/r", "do it"], ["3"], ["[1]"], [json.dumps({"cycle_number": 3, "root": "/r"})], [json.dumps({"cycle_number": 3, "root": "/r", "task": ""})], [json.dumps({"cycle_number": "3", "root": "/r", "task": "do it"})], [json.dumps({"cycle_number": 3, "root": "", "task": "do it"})], [json.dumps({"cycle_number": 3, "root": "/r", "task": "do it", "turns": 1})], [json.dumps({"cycle_number": 3, "failures": 0, "root": "/r", "task": "do it"})]): with self.subTest(handed=handed): - self.assertEqual(main.loop_run_from([main.RELOAD_FLAG, *handed], CWD, FakeEffects().effects()), Stop(1, f"the reload cannot read the cycle number, checkout root and task the edited script was handed in {handed}, as when the edit changed what one script hands the next; rerun loop-claude ")) + self.assertEqual(main.loop_run_from([main.RELOAD_FLAG, *handed], CWD, FakeEffects().effects()), Stop(1, f"the edited loop-claude cannot read the cycle number, checkout root and task the running one handed it, likely because the edit changed that handover; rerun loop-claude . Handed: {' '.join(handed)}")) def test_decodes_a_state_whose_annotations_are_strings(self): @dataclasses.dataclass(frozen=True) @@ -370,7 +370,7 @@ class ExitContract(unittest.TestCase): def test_every_exit_1_stop_has_its_clause_in_help(self): read, git, premises_ = "a transcript cannot be read or archived", "git cannot start or finds no checkout", "README.md holds no premises" models_ = "the models file cannot be read or written" - # Each Stop with an exit code other than 0, 2 or 130, in source order, by its code and the start of its reason, with its --help clause. + # Every Stop whose code is not a literal 0, 2 or 130, in source order: path, function, code, start of reason, its --help clause. clauses = [ ("cycle/interrupt.py", "interrupt", "1", "entries.reason", read), ("cycle/interrupt.py", "interrupt", "1", "f'could not start claude for the interrupt:", "claude cannot start for an interrupt"), @@ -382,7 +382,7 @@ class ExitContract(unittest.TestCase): ("cycle/run.py", "close", "1", "failure.reason", read), ("cycle/run.py", "close", "1", "failure.reason", "a finished chunk's session cannot be deleted"), ("loop/main.py", "loop_run_from", "0 if task else 1", "__doc__.strip()", "no task is given"), - ("loop/main.py", "loop_run_from", "1", "f'the reload cannot read the cycle number,", "a reload cannot read the cycle number, checkout root and task"), + ("loop/main.py", "loop_run_from", "1", 'f"the edited loop-claude cannot read the cycle number,', "a reload cannot read the cycle number, checkout root and task"), ("loop/reload.py", "exec_if_edited", "1", "f'could not reload loop-claude:", "python cannot start for a reload"), ("project/checkout.py", "checkout_root", "1", "f'could not start git:", git), ("project/checkout.py", "checkout_root", "1", "found.stderr.strip()", git), diff --git a/bin/test_loop_claude_black_box.py b/bin/test_loop_claude_black_box.py index 3c5bfafd..fda16a3a 100644 --- a/bin/test_loop_claude_black_box.py +++ b/bin/test_loop_claude_black_box.py @@ -397,8 +397,8 @@ class Cycles(unittest.TestCase): self.assertEqual(run.code, 130) self.assertEqual(run.roles(), ["worker", "judge", "judge", "judge", "worker", "judge"]) self.assertEqual(run.sleeps, [60, 60]) - self.assertIn("the judge quoted 'never said', nothing in the transcript, for the question: A or B?", run.stderr) - self.assertIn("retrying the judge in a minute: the judge quoted '', nothing in the transcript\n", run.stderr) + self.assertIn("the judge quoted 'never said', which is not in the transcript, for the question: A or B?", run.stderr) + self.assertIn("retrying the judge in a minute: the judge quoted '', which is not in the transcript\n", run.stderr) def test_retries_a_judge_claude_cannot_start(self): checkout = Checkout(self) diff --git a/docs/decisions.md b/docs/decisions.md index d678debe..5b378b94 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -34,7 +34,7 @@ ## loop-claude: each project's model lives in `~/.claude/loop-claude-models.json`, which only loop-claude writes -2026-09-26, lilleman. Serves goal 4. Claude Code rewrites the user settings' `model` whenever one is picked inside a session, so a loop reading settings runs whatever was picked last; `~/.claude/loop-claude-models.json` has loop-claude as its one writer, and every claude it starts gets that model as `--model`. The file is per machine, outside the synced allowlist, since a tracked file the loop writes would dirty the checkout. A project's model is a per-machine choice, outside the setup goal 1 shares, so a new machine asks once per project; lilleman, 2026-10-02. Valid while Claude Code keeps rewriting the settings' model from inside a session. +2026-09-26, lilleman. Serves goal 4. Claude Code rewrites the user settings' `model` whenever one is picked inside a session, so a loop reading settings runs whatever was picked last; `~/.claude/loop-claude-models.json` has loop-claude as its one writer, and every claude it starts gets that model as `--model`. The file is per machine, outside the synced allowlist, since a tracked file the loop writes would dirty the checkout. 2026-10-02, lilleman: goal 1 shares the setup across machines, and a project's model is not part of it, so each new machine asks once per project. Valid while Claude Code keeps rewriting the settings' model from inside a session. ## review: a pass gets at most three rounds per chunk; instead of a fourth, the run asks the human @@ -70,7 +70,7 @@ ## workflow changes: once the bench runs, a change merges only after three benches rule it better -2026-10-01, lilleman; binding from when `todo.md`'s "Bench about one chunk in ten against an open PR that changes the workflow" lands, lilleman, 2026-10-02. Serves goals 4.1 and 4.4. The 2026-09-30 bench showed one run cannot tell a workflow's effect from the variance between runs. One bench ruling it worse closes the PR, since quality comes first (goal 4.1), and `docs/workflow-learnings.md` keeps what the PR changed and why it lost. Three is a starting number, to be evaluated against the stats. Valid until that evaluation changes the number. +2026-10-01, lilleman. 2026-10-02, lilleman: binding once `todo.md`'s "Bench about one chunk in ten against an open PR that changes the workflow" lands. Serves goals 4.1 and 4.4. The 2026-09-30 bench showed one run cannot tell a workflow's effect from the variance between runs. One bench ruling it worse closes the PR, since quality comes first (goal 4.1), and `docs/workflow-learnings.md` keeps what the PR changed and why it lost. Three is a starting number, to be evaluated against the stats. Valid until that evaluation changes the number. ## review: `/security-review` is the security pass of record diff --git a/todo.md b/todo.md index 00a82e11..04dda10b 100644 --- a/todo.md +++ b/todo.md @@ -27,9 +27,9 @@ - Have `Session` carry the project key, so `Cycle` cannot hold a key and a session for different projects. - Inject the black-box tests' sleep through `Effects.sleep`; today `SITECUSTOMIZE` swaps `time.sleep` in the child process. - Return a `Failure` from `replace_file` when removing the staged file fails too. - - Tell a catalog file that cannot be read from no catalog: today the prompt says none is cached. + - Say so when a catalog file cannot be read; today the prompt says no catalog is cached. - Sort `transcript_file`'s glob, and delete a session's files under every project folder that holds its id. - - Give `decode_handed` its one type, `LoopRun`. + - Type `decode_handed` for `LoopRun`, its one caller's type, and drop the type variable `T`. - **Give each cycle phase one name across its state, step and event.** Today `Judging` runs `rule` and yields `Ruled`, and `Finishing` runs `close`, which also deletes the session, and yields `Archived`. Goal 4.1. - **Copy the transcript archive off the machine, or say in README how it is backed up.** It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost disk loses every unattended run's record. Goal 2. - **Inject output and storage into `Effects`, and test what each step prints.** `print` and `open` are called directly across `bin/loop_claude/`, so the stderr lines of the CLI contract can be checked only through the black-box tests. Goal 4.1. @@ -50,5 +50,5 @@ - **Write a `workflow-review` skill that reads the stats and files each change it proposes to the workflow as a plan item, and have `AGENTS.md` run it on the chunk shipping a release's last item.** The workflow is `CLAUDE.md`, `principles/`, the skills, the agents and `loop-claude`. The skill's signals: findings outside the chunk's diff and comprehension scores per release, both from the stats; fixes after merge, from git; and the human's corrections, from the archived transcripts. Goal 4.4. - **Bench about one chunk in ten against an open PR that changes the workflow, and have a blind claude rule which run better serves this repo's goal 4.** Redo the chunk under the PR, from the commit it started from. The ruling claude is not told which run is which. `loop-claude` picks the chunk at random, small diffs and big ones alike; with no such PR open, no bench runs. The same outcome with less code and prose, in the chunk or in the workflow, also counts as better. The PR merges only once three benches rule it better. A bench that rules it worse closes the PR and records, in `docs/workflow-learnings.md`, what the PR changed and why it lost. The ruling and both runs' numbers go on the chunk's stats line. Start from `workflow-bench/`, written for the 2026-09-30 bench's four fixed cases. Needs the stats line. Goals 4.1 and 4.4. - **Put the scoring run's four seat prompts in `skills/comprehension-panel/`.** Each run copies them from the last run's handoff folder outside the repo, so another machine cannot rerun a comparable panel. Goal 1. -- **Make larv-review §3 readable without another file open.** Applying one rule of "Round cap", "Re-entry" or "Findings" takes `review-findings.md`, `CLAUDE.md` → "Vocabulary" and the decision log open beside it. The rules cite each other by number ("Round cap" rule 6), so a renumbering breaks a citation silently. Nothing says where a pass's round count is recorded, so a resumed or compacted session loses it. Goal 4.1. +- **Make larv-review §3 applicable on its own, cite its rules by name, and say where a pass's round count is recorded.** Revise the decision "vocabulary: the concept words are defined under `CLAUDE.md` → "Vocabulary" and cited by a bare link" to match. Applying one rule of "Round cap", "Re-entry" or "Findings" takes `review-findings.md`, `CLAUDE.md` → "Vocabulary" and the decision log open beside it. The rules cite each other by number ("Round cap" rule 6), so a renumbering breaks a citation silently. Nothing says where a pass's round count is recorded, so a resumed or compacted session loses it. Goal 4.1. - **Wait out a usage limit and retry however long it lasts, without counting it as a failed run.** Today a worker or judge that hits a usage limit fails three times a minute apart, and the loop exits 1, so an unattended loop dies at every limit. The transcript line Claude Code writes for it, marked `"error":"rate_limit"`, holds the reset time: `You've hit your session limit · resets 7:40pm (Europe/Stockholm)`. Sleep until 2 minutes past it. The judge runs without a transcript, so find what its JSON reply carries on a limit. Where no reset time can be read, retry every 10 minutes: a retry before the reset fails (https://platform.claude.com/docs/en/api/rate-limits), so polling sooner only spends requests. Print when the next try is due, and update `--help`'s exit 1. Goal 4.