From 6d5d19bd69598513cfbb2f440e24d3be81f64b22 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 00:25:24 +0200 Subject: [PATCH 01/20] Give the judge what the project records and ten times more of the chunk's transcript --- AGENTS.md | 2 +- CHANGELOG.md | 1 + bin/loop_claude/cycle/judge.py | 19 +++++++++++-------- bin/loop_claude/cycle/run.py | 3 ++- bin/loop_claude/loop/main.py | 11 +++++++++-- bin/loop_claude/project/records.py | 23 +++++++++++++++++++++++ bin/test_loop_claude.py | 24 ++++++++++++++++++++++-- bin/test_loop_claude_black_box.py | 7 +++++-- docs/decisions.md | 4 ++-- todo.md | 10 ---------- 10 files changed, 76 insertions(+), 28 deletions(-) create mode 100644 bin/loop_claude/project/records.py diff --git a/AGENTS.md b/AGENTS.md index 2b829f35..52e5174b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -3,7 +3,7 @@ Decisions live in `docs/decisions.md`: - larv-review: a project under the comprehension floor is fixed at the capping dimension -- loop-claude: a judge decides each interrupt from the transcript and the README's premises; the worker's own account of which goal settles a choice decides nothing +- loop-claude: a judge decides each interrupt from the transcript, the README's premises and the project's records; the worker's own account of which goal settles a choice decides nothing - loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it - loop-claude: before an interrupt, it marks the checkout and each of its worktrees trusted in `~/.claude.json` - bin/: the tests rerun themselves on a `uv`-fetched Python at README Install's floor diff --git a/CHANGELOG.md b/CHANGELOG.md index 39056b6f..362e500f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- `loop-claude`'s judge reads the project's `AGENTS.md`, `docs/decisions.md` and `docs/decisions/*.md` beside the README's goals and audience, and does not interrupt for a choice they settle. It judges the transcript's last 400,000 characters, up from 40,000. `loop-claude` exits 1 when one of those files cannot be read or is not UTF-8. - `loop-claude` waits out a usage limit and retries: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. A limit is not a failure, and restarts the count of three failures in a row. It prints what claude said about the limit and when the next try is due. - Add the official plugin marketplace and install every plugin `settings.json` enables (README → Install): `claude-security`, `code-review` and `rust-analyzer-lsp`, which needs `rust-analyzer` on `PATH` for Rust projects. With `claude-security`, larv-review's full security scan runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. - systems-architect and product-owner-reviewer can no longer edit what they review; stability-reviewer keeps its shell to run tests, and loses Claude Code's file-editing tools. diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index 2c8b481e..c4fd0ebe 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -10,18 +10,20 @@ from loop_claude.failure import Failure from loop_claude.limited import Limited from loop_claude.stop import Stop -JUDGED_TRANSCRIPT_TAIL = 40000 +# About 100,000 tokens, so the prompt fits a 200,000-token context; the largest session rendered here was 364,000 on 2026-10-03. +JUDGED_TRANSCRIPT_TAIL = 400000 JUDGE_RULES = ( "Decide whether the human must now be interrupted. interrupt=true when any of these appear:\n" "- the agent asks the human anything, seeks approval, or says a decision is the human's\n" - "- it carried on under an assumption that decides the deliverable and that the human could " - "reasonably reject; a caveat about transient state it then handled is not one\n" + "- it carried on under an assumption that decides the deliverable, that the human could " + "reasonably reject and that neither README.md nor the project's records settle; a caveat about " + "transient state it then handled is not one\n" "- it is blocked on something only the human can supply: a credential, a version bump, a release " "ready to cut, a choice outside the repo\n" "- it flags that the goals, the plan or the task itself is unclear, missing or in need of change\n" - "- it chose between alternatives the README text does not discriminate between - it does not " - "rule the rejected one out - and the choice materially changes the deliverable\n" + "- it chose between alternatives that neither README.md nor the project's records discriminate " + "between - neither rules the rejected one out - and the choice materially changes the deliverable\n" "interrupt=false otherwise. Bookkeeping the agent settled silently - what to document, wording, " "where a note goes - is not on its own a reason to interrupt. The human may have replied inside the transcript, on a [human] line: judge only what " "is still open, never a question they already answered there.\n" @@ -49,7 +51,7 @@ JUDGE_SCHEMA = { } -def judge(root: str, task: str, premises: str, rendered_transcript: str, model: str, effects: Effects) -> Verdict | Stop: +def judge(root: str, task: str, premises: str, records: str, rendered_transcript: str, model: str, effects: Effects) -> Verdict | Stop: # No tools, so the verdict rests on the transcript grounded() checks it against; no persistence, so its runs stay out of the session picker. args = [ "-p", @@ -60,7 +62,7 @@ def judge(root: str, task: str, premises: str, rendered_transcript: str, model: "--permission-mode", "bypassPermissions", "--tools", "", ] - prompt = judge_prompt(task, premises, rendered_transcript) + prompt = judge_prompt(task, premises, records, rendered_transcript) return retried("judge", lambda: run_judge(root, args, prompt, rendered_transcript, effects), effects) @@ -83,9 +85,10 @@ def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str, return verdict -def judge_prompt(task: str, premises: str, rendered_transcript: str) -> str: +def judge_prompt(task: str, premises: str, records: str, rendered_transcript: str) -> str: return ( f"From README.md:\n{premises}\n\n" + f"The project's records, its working rules and decisions:\n{records or 'none'}\n\n" f"The task an agent was given:\n{task}\n\n" # The tail, where an interrupt or a finish lands; the session's transcript grows cycle over cycle. f"What the agent did and said, and what the human typed on [human] lines, latest last:\n{rendered_transcript[-JUDGED_TRANSCRIPT_TAIL:]}\n\n" diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index d889ec1f..f3f9a106 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -24,6 +24,7 @@ class Cycle: paths: Paths premises: str project_key: str + records: str root: str session: Session task: str @@ -75,7 +76,7 @@ def rule(cycle: Cycle, transcript_path: str) -> Ruled | Stop: entries = read_transcript(transcript_path) if isinstance(entries, Failure): return Stop(1, entries.reason) - verdict = judge(cycle.root, cycle.task, cycle.premises, render(entries), cycle.models.judge, cycle.effects) + verdict = judge(cycle.root, cycle.task, cycle.premises, cycle.records, render(entries), cycle.models.judge, cycle.effects) return verdict if isinstance(verdict, Stop) else Ruled(verdict) diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index a9b593d2..3d41a74b 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -4,7 +4,9 @@ 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 the premises and rules whether the chunk, the work of one PR, is finished. +the transcript's last 400,000 characters against the premises and the project's records, AGENTS.md, +docs/decisions.md and docs/decisions/*.md where they exist, and rules whether the chunk, the work of +one PR, is finished. A choice the premises or the records settle is not asked again. 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. @@ -34,6 +36,7 @@ Exit 1, saying why, when: - no task is given - git cannot start or finds no checkout - README.md holds no premises +- AGENTS.md or a decision file cannot be read, or is not UTF-8 - the models file cannot be read or written - claude leaves no transcript - a transcript cannot be read or archived @@ -71,6 +74,7 @@ from loop_claude.paths import Paths from loop_claude.project.checkout import checkout_root, project_key from loop_claude.project.model_choice import get_or_ask_models from loop_claude.project.premises import read_premises +from loop_claude.project.records import read_records from loop_claude.stop import Stop @@ -98,11 +102,14 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc premises = read_premises(loop_run.root) if isinstance(premises, Stop): return premises + records = read_records(loop_run.root) + if isinstance(records, Stop): + return records models = get_or_ask_models(key, paths, env, effects) if isinstance(models, Stop): return models print(f"\n=== cycle {loop_run.cycle_number} ===", flush=True) - if stop := run_cycle(Cycle(effects=effects, models=models, paths=paths, premises=premises, project_key=key, root=loop_run.root, session=session, task=loop_run.task)): + if stop := run_cycle(Cycle(effects=effects, models=models, paths=paths, premises=premises, project_key=key, records=records, root=loop_run.root, session=session, task=loop_run.task)): return stop diff --git a/bin/loop_claude/project/records.py b/bin/loop_claude/project/records.py new file mode 100644 index 00000000..95f05ed9 --- /dev/null +++ b/bin/loop_claude/project/records.py @@ -0,0 +1,23 @@ +import pathlib + +from loop_claude.stop import Stop + + +def read_records(root: str) -> str | Stop: + """AGENTS.md and the decision log, each headed by its path; a file the project lacks is left out.""" + project = pathlib.Path(root) + paths = [project / "AGENTS.md", project / "docs" / "decisions.md", *sorted(project.glob("docs/decisions/*.md"))] + records = [] + for path in paths: + name = path.relative_to(project) + try: + text = path.read_text(encoding="utf-8") + except FileNotFoundError: + continue + except OSError as failure: + return Stop(1, f"{name} in {root}: {failure.strerror} - the judge cannot read the project's records.") + except UnicodeDecodeError as failure: + line = failure.object.count(b"\n", 0, failure.start) + 1 + return Stop(1, f"{name} is not UTF-8 on line {line} - the judge cannot read the project's records.") + records.append(f"From {name}:\n{text.strip()}") + return "\n\n".join(records) diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 84e6440f..490ca273 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -24,7 +24,7 @@ from loop_claude.effects import Effects from loop_claude.failure import Failure from loop_claude.limited import Limited from loop_claude.loop import main, reload -from loop_claude.project import checkout, model_choice, premises +from loop_claude.project import checkout, model_choice, premises, records from loop_claude.stop import Stop CWD = pathlib.Path("/c") @@ -156,7 +156,7 @@ class Cycles(unittest.TestCase): self.session = session.session_for("proj", self.paths) def cycle(self, fake): - return run.Cycle(effects=fake.effects(), models=model_choice.Models("judge-model", "worker-model"), paths=self.paths, premises="## Goals", project_key="proj", root=str(self.home), session=self.session, task="Do it.") + return run.Cycle(effects=fake.effects(), models=model_choice.Models("judge-model", "worker-model"), paths=self.paths, premises="## Goals", project_key="proj", records="", root=str(self.home), session=self.session, task="Do it.") def archived_verdicts(self): return sorted(path.read_text() for path in (self.paths.transcript_archive / "proj").glob("*/*.verdict.md")) @@ -348,6 +348,24 @@ class WorkerArgs(unittest.TestCase): self.assertNotIn("Do it.", " ".join(resumed)) +class Records(unittest.TestCase): + def test_heads_each_record_the_project_has_by_its_path(self): + with tempfile.TemporaryDirectory() as root: + self.assertEqual(records.read_records(root), "") + pathlib.Path(root, "docs", "decisions").mkdir(parents=True) + pathlib.Path(root, "docs", "decisions", "b.md").write_text("# B\n") + pathlib.Path(root, "docs", "decisions", "a.md").write_text("# A\n") + pathlib.Path(root, "AGENTS.md").write_text("\n# Rules\n") + self.assertEqual(records.read_records(root), "From AGENTS.md:\n# Rules\n\nFrom docs/decisions/a.md:\n# A\n\nFrom docs/decisions/b.md:\n# B") + + def test_stops_on_a_record_it_cannot_read(self): + with tempfile.TemporaryDirectory() as root: + pathlib.Path(root, "docs", "decisions.md").mkdir(parents=True) + self.assertEqual(records.read_records(root), Stop(1, f"docs/decisions.md in {root}: Is a directory - the judge cannot read the project's records.")) + pathlib.Path(root, "AGENTS.md").write_bytes(b"# Rules\n\xff\n") + self.assertEqual(records.read_records(root), Stop(1, "AGENTS.md is not UTF-8 on line 2 - the judge cannot read the project's records.")) + + class Sections(unittest.TestCase): def test_keeps_every_headed_section_with_its_bodies(self): text = "# Title\n\nintro\n\n## Goals\n\n1. one\n```sh\n# not a heading\n```\n### Later\n2. two\n#1 priority\n\n## Empty\n\n## Audience\nme\n## Audience\nagain\n# Appendix\nnot audience\n" @@ -513,6 +531,8 @@ class ExitContract(unittest.TestCase): ("project/premises.py", "read_premises", "1", "f'README.md has no ##", premises_), ("project/premises.py", "read_premises", "1", "f'README.md has ## {name} more than once", premises_), ("project/premises.py", "read_premises", "1", "f'README.md has nothing under", premises_), + ("project/records.py", "read_records", "1", 'f"{name} in {root}:', "AGENTS.md or a decision file cannot be read, or is not UTF-8"), + ("project/records.py", "read_records", "1", 'f"{name} is not UTF-8', "AGENTS.md or a decision file cannot be read, or is not UTF-8"), ] root = pathlib.Path(main.__file__).parents[1] found = [] diff --git a/bin/test_loop_claude_black_box.py b/bin/test_loop_claude_black_box.py index 10f69aea..8c4cdfbb 100644 --- a/bin/test_loop_claude_black_box.py +++ b/bin/test_loop_claude_black_box.py @@ -323,6 +323,8 @@ class Cycles(unittest.TestCase): def test_resumes_the_session_while_unfinished_and_starts_it_fresh_after_finishing(self): checkout = Checkout(self) (checkout.root / "sub").mkdir() + (checkout.root / "docs").mkdir() + (checkout.root / "docs" / "decisions.md").write_text("# Decisions\n") run = checkout.run([ worker(say="started"), judge(evidence="started"), worker(say="landed-it", siblings=True), judge(finished=True, evidence="landed-it"), @@ -341,6 +343,7 @@ class Cycles(unittest.TestCase): self.assertNotIn(TASK, argument(workers[1], "-p")) self.assertEqual({call["cwd"] for call in run.calls}, {str(checkout.root)}) self.assertIn("1. Work.", run.calls[1]["stdin"]) + self.assertIn("From docs/decisions.md:\n# Decisions", run.calls[1]["stdin"]) self.assertEqual({argument(call, "--model") for call in workers}, {"worker-model"}) self.assertEqual({argument(call, "--model") for call in run.calls if call["role"] == "judge"}, {"judge-model"}) self.assertIn("landed-it", run.calls[3]["stdin"]) @@ -428,9 +431,9 @@ class Cycles(unittest.TestCase): def test_hands_the_judge_the_tail_of_a_long_transcript(self): checkout = Checkout(self) - run = checkout.run([worker(say="early " * 20000 + "LATE")]) + run = checkout.run([worker(say="early " * 80000 + "LATE")]) self.assertIn("LATE", run.calls[1]["stdin"]) - self.assertLess(run.calls[1]["stdin"].count("early"), 20000) + self.assertEqual(run.calls[1]["stdin"].count("early"), (400000 - len("LATE")) // len("early ")) self.assertTrue(run.calls[1]["stdin"].rstrip().endswith("an open PR, a review not yet run, CI not yet reported.")) def test_skips_a_malformed_transcript_or_stream_line(self): diff --git a/docs/decisions.md b/docs/decisions.md index b2627f9f..c60d48b2 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -4,9 +4,9 @@ 2026-09-20, lilleman. Serves goal 4. Across six projects scored with the four seats, Locality or Self-sufficiency capped every seat and Navigation capped none, so a layout fix would not lift a project under the floor. Valid while the scoring run keeps those four seats. -## loop-claude: a judge decides each interrupt from the transcript and the README's premises; the worker's own account of which goal settles a choice decides nothing +## loop-claude: a judge decides each interrupt from the transcript, the README's premises and the project's records; the worker's own account of which goal settles a choice decides nothing -2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); `todo.md` item 7 ends the README-only bar. Valid while the worker's self-report stays unreliable. +2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). The records settle a choice the worker made or an assumption it carried on under; a question the worker itself asks still interrupts, since a worker left unanswered would ask it again next cycle. Valid while the worker's self-report stays unreliable. ## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it diff --git a/todo.md b/todo.md index 0564d9be..c388b5e5 100644 --- a/todo.md +++ b/todo.md @@ -25,8 +25,6 @@ | ID | Release | Exempt | Item | R | S | A | G | Goals | Score | |---|---|---|---|---|---|---|---|---|---| | 1 | 0.1.0 | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 3 | 5 | 8 | 9 | 2, 3 | 27.8 | -| 7 | 0.1.0 | decision | **Give the judge the project's recorded decisions, and ask it whether anything the project records settles a choice.** | 3 | 4 | 8 | 8 | 4.2 | 19.0 | -| 8 | 0.1.0 | | **Judge a cycle on more than the transcript's last 40,000 characters.** | 4 | 5 | 7 | 8 | 4.2 | 15.8 | | 13 | 0.1.0 | decision | **Make larv-review §3 applicable on its own, cite its rules by name, and say where a pass's round count is recorded.** | 3 | 5 | 6 | 7 | 4.1 | 15.6 | | 23 | 0.1.0 | | **Launch a principles auditor only for a principles file the project shows applies, and rerun only the reviewer whose finding a fix answers.** | 3 | 4 | 7 | 8 | 4.4 | 13.5 | | 21 | 0.1.0 | | **Give `settings.json`'s model one writer, and sort its keys.** | 3 | 3 | 6 | 7 | 4.3 | 12.9 | @@ -46,14 +44,6 @@ It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost 2026-10-02, the human: ai-sandbox is the VM `loop-claude` will run on, hosted on the server bender. bender-infra, the infrastructure-as-code project that manages bender, will back up ai-sandbox's data volume once ai-sandbox is rebuilt. The item waits for the human to say the rebuild has landed. Before writing the README line, check that `~/.claude` lives on that volume and that the backup is private and encrypted at rest. -### 7. Give the judge the project's recorded decisions, and ask it whether anything the project records settles a choice. - -Today it reads only the README's Goals and Audience (`premises.py`) and cannot see an answer recorded in `docs/decisions.md` or `AGENTS.md`, so it can interrupt the human again for a question already answered. Revise the decision "loop-claude: a judge decides each interrupt from the transcript and the README's premises; the worker's own account of which goal settles a choice decides nothing" to match. - -### 8. Judge a cycle on more than the transcript's last 40,000 characters. - -`judge_prompt` cuts the transcript there. The session spans every cycle of the chunk, so a decision made early in a long run is never judged, and the human is not interrupted for it. Larger chunks make runs longer. - ### 13. Make larv-review §3 applicable on its own, cite its rules by name, and say where a pass's round count is recorded. 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. -- 2.52.0 From 6340e5a993454c04797d4ac7fd3c67733df9a0d6 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 00:35:40 +0200 Subject: [PATCH 02/20] Answer the first round: resume the worker with the records' answer to its question, read docs/decisions.md alone, scope --help's promise --- CHANGELOG.md | 2 +- bin/loop_claude/cycle/judge.py | 17 +++++--- bin/loop_claude/cycle/run.py | 10 ++--- bin/loop_claude/cycle/states.py | 19 ++++++--- bin/loop_claude/cycle/verdicts.py | 10 ++++- bin/loop_claude/cycle/worker.py | 5 ++- bin/loop_claude/loop/main.py | 13 +++--- bin/loop_claude/project/records.py | 9 ++--- bin/test_loop_claude.py | 63 ++++++++++++++++++++---------- bin/test_loop_claude_black_box.py | 4 +- docs/decisions.md | 2 +- 11 files changed, 100 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 362e500f..c678e388 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `loop-claude`'s judge reads the project's `AGENTS.md`, `docs/decisions.md` and `docs/decisions/*.md` beside the README's goals and audience, and does not interrupt for a choice they settle. It judges the transcript's last 400,000 characters, up from 40,000. `loop-claude` exits 1 when one of those files cannot be read or is not UTF-8. +- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question they answer, the worker resumes with the judge's quote of the answer; the worker's next question in that cycle goes to you. The judge reads the transcript's last 400,000 characters, up from 40,000. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. - `loop-claude` waits out a usage limit and retries: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. A limit is not a failure, and restarts the count of three failures in a row. It prints what claude said about the limit and when the next try is due. - Add the official plugin marketplace and install every plugin `settings.json` enables (README → Install): `claude-security`, `code-review` and `rust-analyzer-lsp`, which needs `rust-analyzer` on `PATH` for Rust projects. With `claude-security`, larv-review's full security scan runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. - systems-architect and product-owner-reviewer can no longer edit what they review; stability-reviewer keeps its shell to run tests, and loses Claude Code's file-editing tools. diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index c4fd0ebe..d990d311 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -4,13 +4,13 @@ import typing from loop_claude.claude_code.entries import hit_limit, limit_said, parse_entry, structured_output from loop_claude.cycle.retry import retried -from loop_claude.cycle.verdicts import Finished, Interrupt, Unfinished, Verdict +from loop_claude.cycle.verdicts import Finished, Interrupt, Recorded, Unfinished, Verdict from loop_claude.effects import Effects from loop_claude.failure import Failure from loop_claude.limited import Limited from loop_claude.stop import Stop -# About 100,000 tokens, so the prompt fits a 200,000-token context; the largest session rendered here was 364,000 on 2026-10-03. +# About 100,000 tokens, leaving a 200,000-token context room for the rest of the prompt; the largest session rendered here was 364,000 characters on 2026-10-03. JUDGED_TRANSCRIPT_TAIL = 400000 JUDGE_RULES = ( @@ -29,6 +29,8 @@ JUDGE_RULES = ( "is still open, never a question they already answered there.\n" "Where the agent asked or flagged something itself, the question is that one, in the agent's own " "wording; never construct another from facts it stated.\n" + "Where README.md or the project's records answer that question, quote the passage that answers it " + "in answer, verbatim; the agent is then given that passage in place of the human's reply.\n" "finished=true when the chunk is complete: merged, or nothing remains that the agent could do on " "its own. finished=false when work remains that a further run can continue: an open PR, a review " "not yet run, CI not yet reported." @@ -36,6 +38,7 @@ JUDGE_RULES = ( @dataclasses.dataclass(frozen=True) class Reply: + answer: str = dataclasses.field(metadata={"description": "The passage of README.md or the project's records that answers the agent's question, quoted verbatim. Empty when nothing there answers it, or when interrupt is false."}) evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the transcript line the verdict rests on: what triggers the interrupt, else what shows the chunk finished or the work remaining."}) finished: bool interrupt: bool @@ -63,10 +66,10 @@ def judge(root: str, task: str, premises: str, records: str, rendered_transcript "--tools", "", ] prompt = judge_prompt(task, premises, records, rendered_transcript) - return retried("judge", lambda: run_judge(root, args, prompt, rendered_transcript, effects), effects) + return retried("judge", lambda: run_judge(root, args, prompt, rendered_transcript, f"{premises}\n\n{records}", effects), effects) -def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str, effects: Effects) -> Verdict | Failure | Limited: +def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str, recorded: str, effects: Effects) -> Verdict | Failure | Limited: try: proc = effects.claude(args, root, prompt) except OSError as failure: @@ -81,7 +84,9 @@ 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}, which is not 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 | Recorded) else "")) + if isinstance(verdict, Recorded) and not grounded(verdict.answer, recorded): + return Failure(f"the judge answered {verdict.question!r} with {verdict.answer!r}, which README.md and the project's records do not hold") return verdict @@ -106,6 +111,8 @@ def verdict_from(output: object) -> Verdict | Failure: if output["interrupt"]: if not output["question"].strip(): return Failure("the judge interrupted without a question") + if output["answer"].strip(): + return Recorded(output["evidence"], output["question"], output["answer"]) return Interrupt(output["evidence"], output["question"]) return Finished(output["evidence"]) if output["finished"] else Unfinished(output["evidence"]) diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index f3f9a106..2c5982b2 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -52,9 +52,9 @@ def stopped(cycle: Cycle, stop: Stop, why: str) -> Stop: def step(cycle: Cycle, state: Active) -> Event | Stop: match state: - case Working(): - return work(cycle) - case Judging(transcript_path): + case Working(answer): + return work(cycle, answer) + case Judging(transcript_path, _): return rule(cycle, transcript_path) case Interrupting(transcript_path, question): return ask(cycle, transcript_path, question) @@ -64,9 +64,9 @@ def step(cycle: Cycle, state: Active) -> Event | Stop: typing.assert_never(state) -def work(cycle: Cycle) -> WorkerRan | Stop: +def work(cycle: Cycle, answer: str | None) -> WorkerRan | Stop: # session_open runs inside the lambda: a failed attempt may have opened the session. - if stop := retried("worker", lambda: run_worker(cycle.root, worker_args(cycle.task, cycle.session, cycle.models.worker, session_open(cycle.session)), cycle.effects), cycle.effects): + if stop := retried("worker", lambda: run_worker(cycle.root, worker_args(cycle.task, cycle.session, cycle.models.worker, session_open(cycle.session), answer), cycle.effects), cycle.effects): return stop path = transcript_file(cycle.session) return WorkerRan(path) if path is not None else Stop(1, f"claude left no transcript for session {cycle.session.id}") diff --git a/bin/loop_claude/cycle/states.py b/bin/loop_claude/cycle/states.py index ad0f5b11..c5061115 100644 --- a/bin/loop_claude/cycle/states.py +++ b/bin/loop_claude/cycle/states.py @@ -1,16 +1,18 @@ import dataclasses -from loop_claude.cycle.verdicts import Finished, Interrupt, Unfinished, Verdict +from loop_claude.cycle.verdicts import Finished, Interrupt, Recorded, Unfinished, Verdict @dataclasses.dataclass(frozen=True) class Working: - """The worker runs.""" + """The worker runs, resumed with the records' answer when there is one.""" + answer: str | None = None @dataclasses.dataclass(frozen=True) class Judging: transcript_path: str + answered_from_records: bool = False @dataclasses.dataclass(frozen=True) @@ -59,11 +61,16 @@ Event = WorkerRan | Ruled | Answered | Archived def transition(state: State, event: Event) -> State: match state, event: - case Working(), WorkerRan(transcript_path): - return Judging(transcript_path) - case Judging(transcript_path), Ruled(Interrupt(question=question)): + case Working(answer), WorkerRan(transcript_path): + return Judging(transcript_path, answer is not None) + case Judging(_, False), Ruled(Recorded(answer=answer)): + return Working(answer) + # The worker asked again after the records' answer, so the answer did not settle it. + case Judging(transcript_path, True), Ruled(Recorded(question=question)): return Interrupting(transcript_path, question) - case Judging(transcript_path), Ruled(Finished() | Unfinished() as verdict): + case Judging(transcript_path, _), Ruled(Interrupt(question=question)): + return Interrupting(transcript_path, question) + case Judging(transcript_path, _), Ruled(Finished() | Unfinished() as verdict): return Closing(transcript_path, verdict) # The human works in the interrupt's claude session, so the judge rules again on the transcript it leaves. case Interrupting(transcript_path), Answered(): diff --git a/bin/loop_claude/cycle/verdicts.py b/bin/loop_claude/cycle/verdicts.py index 1fa48086..a414f95a 100644 --- a/bin/loop_claude/cycle/verdicts.py +++ b/bin/loop_claude/cycle/verdicts.py @@ -7,6 +7,14 @@ class Interrupt: question: str +@dataclasses.dataclass(frozen=True) +class Recorded: + """The agent asked a question that README.md or the project's records answer, quoted in answer.""" + evidence: str + question: str + answer: str + + @dataclasses.dataclass(frozen=True) class Finished: evidence: str @@ -17,4 +25,4 @@ class Unfinished: evidence: str -Verdict = Interrupt | Finished | Unfinished +Verdict = Interrupt | Recorded | Finished | Unfinished diff --git a/bin/loop_claude/cycle/worker.py b/bin/loop_claude/cycle/worker.py index dcc642bf..27cfffab 100644 --- a/bin/loop_claude/cycle/worker.py +++ b/bin/loop_claude/cycle/worker.py @@ -37,9 +37,10 @@ def worker_outcome(code: int, result: dict | None, resets: list[int]) -> Failure return None if result is not None else Failure("claude exited 0 without a result event") -def worker_args(task: str, session: Session, model: str, resuming: bool) -> list[str]: +def worker_args(task: str, session: Session, model: str, resuming: bool, answer: str | None = None) -> list[str]: if resuming: - start = ["-p", "Continue the task; the previous run stopped before it was finished.", "--resume", str(session.id)] + prompt = f"README.md or the project's records answer your question:\n\n{answer}\n\nContinue the task." if answer is not None else "Continue the task; the previous run stopped before it was finished." + start = ["-p", prompt, "--resume", str(session.id)] else: start = ["-p", f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one.", "--name", session.name, "--session-id", str(session.id)] return [ diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 3d41a74b..1c23569e 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -4,9 +4,11 @@ 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's last 400,000 characters against the premises and the project's records, AGENTS.md, -docs/decisions.md and docs/decisions/*.md where they exist, and rules whether the chunk, the work of -one PR, is finished. A choice the premises or the records settle is not asked again. +the transcript's last 400,000 characters against the premises and the project's records, AGENTS.md +and docs/decisions.md where they exist, and rules whether the chunk, the work of one PR, is finished. +A choice the worker made that the premises or the records settle is not asked about. When the worker +asks a question they answer, the judge quotes the answer and the worker resumes with it; the +worker's next question in the cycle goes to the human. 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. @@ -36,7 +38,7 @@ Exit 1, saying why, when: - no task is given - git cannot start or finds no checkout - README.md holds no premises -- AGENTS.md or a decision file cannot be read, or is not UTF-8 +- AGENTS.md or docs/decisions.md cannot be read, or is not UTF-8 - the models file cannot be read or written - claude leaves no transcript - a transcript cannot be read or archived @@ -48,7 +50,8 @@ Exit 1, saying why, when: - 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 a line the transcript does not hold. A usage limit is + interrupts without a question, quotes a line the transcript does not hold, or quotes an answer + the premises and the records do not hold. A usage limit is not a failure, and restarts the count of three: the worker or the judge is retried 2 minutes after the limit resets, or every 10 minutes when the reset time is unknown or more than 2 minutes past. The judge's reply gives its reset time only as text, so the judge is always diff --git a/bin/loop_claude/project/records.py b/bin/loop_claude/project/records.py index 95f05ed9..f9bd185b 100644 --- a/bin/loop_claude/project/records.py +++ b/bin/loop_claude/project/records.py @@ -4,14 +4,11 @@ from loop_claude.stop import Stop def read_records(root: str) -> str | Stop: - """AGENTS.md and the decision log, each headed by its path; a file the project lacks is left out.""" - project = pathlib.Path(root) - paths = [project / "AGENTS.md", project / "docs" / "decisions.md", *sorted(project.glob("docs/decisions/*.md"))] + """AGENTS.md and docs/decisions.md, each headed by its path; a file the project lacks is left out.""" records = [] - for path in paths: - name = path.relative_to(project) + for name in ("AGENTS.md", "docs/decisions.md"): try: - text = path.read_text(encoding="utf-8") + text = pathlib.Path(root, name).read_text(encoding="utf-8") except FileNotFoundError: continue except OSError as failure: diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 490ca273..f994c2e1 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -19,7 +19,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) from loop_claude import file_writes, paths from loop_claude.claude_code import entries, session, transcript, trust from loop_claude.cycle import archive, interrupt, judge, retry, run, states, worker -from loop_claude.cycle.verdicts import Finished, Interrupt, Unfinished +from loop_claude.cycle.verdicts import Finished, Interrupt, Recorded, Unfinished from loop_claude.effects import Effects from loop_claude.failure import Failure from loop_claude.limited import Limited @@ -91,8 +91,8 @@ def ran(stdout="", code=0, stderr=""): return subprocess.CompletedProcess([], code, stdout, stderr) -def judged(verdict, evidence="working"): - reply = {"evidence": evidence, "finished": verdict == "finished", "interrupt": verdict == "interrupt", "question": "Which one?" if verdict == "interrupt" else ""} +def judged(verdict, evidence="working", answer=""): + reply = {"answer": answer, "evidence": evidence, "finished": verdict == "finished", "interrupt": verdict == "interrupt", "question": "Which one?" if verdict == "interrupt" else ""} return ran(json.dumps({"structured_output": reply})) @@ -129,7 +129,13 @@ class Transitions(unittest.TestCase): def test_each_state_moves_on_its_events_and_only_on_them(self): legal = ( (states.Working(), states.WorkerRan("/t"), states.Judging("/t")), + (states.Working("A."), states.WorkerRan("/t"), states.Judging("/t", True)), (states.Judging("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")), + (states.Judging("/t", True), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")), + (states.Judging("/t"), states.Ruled(Recorded("e", "Which one?", "A.")), states.Working("A.")), + (states.Judging("/t", True), states.Ruled(Recorded("e", "Which one?", "A.")), states.Interrupting("/t", "Which one?")), + (states.Judging("/t", True), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), + (states.Judging("/t", True), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), (states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), (states.Interrupting("/t", "q"), states.Answered(), states.Judging("/t")), @@ -138,8 +144,8 @@ class Transitions(unittest.TestCase): for state, event, after in legal: with self.subTest(state=state, event=event): self.assertEqual(states.transition(state, event), after) - every_state = (states.Working(), states.Judging("/t"), states.Interrupting("/t", "q"), states.Closing("/t", Finished("e")), states.Ended()) - every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.Answered(), states.Archived()) + every_state = (states.Working(), states.Working("A."), states.Judging("/t"), states.Judging("/t", True), states.Interrupting("/t", "q"), states.Closing("/t", Finished("e")), states.Ended()) + every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Ruled(Recorded("e", "Which one?", "A.")), states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.Answered(), states.Archived()) for state in every_state: for event in every_event: if (state, event) not in [(state, event) for state, event, _ in legal]: @@ -155,8 +161,8 @@ class Cycles(unittest.TestCase): self.paths = paths.paths_from(self.home, {}) self.session = session.session_for("proj", self.paths) - def cycle(self, fake): - return run.Cycle(effects=fake.effects(), models=model_choice.Models("judge-model", "worker-model"), paths=self.paths, premises="## Goals", project_key="proj", records="", root=str(self.home), session=self.session, task="Do it.") + def cycle(self, fake, records=""): + return run.Cycle(effects=fake.effects(), models=model_choice.Models("judge-model", "worker-model"), paths=self.paths, premises="## Goals", project_key="proj", records=records, root=str(self.home), session=self.session, task="Do it.") def archived_verdicts(self): return sorted(path.read_text() for path in (self.paths.transcript_archive / "proj").glob("*/*.verdict.md")) @@ -235,6 +241,21 @@ class Cycles(unittest.TestCase): self.assertNotIn("the second", prompts[0]) self.assertIn("[human] the second", prompts[1]) + def test_a_question_the_records_answer_resumes_the_worker_with_the_answer_once_per_cycle(self): + answered = judged("interrupt", answer="Use *A*.") + fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 2, claude=[answered, answered, judged("unfinished")], on_terminal_claude=[0], git=[ran()]) + with contextlib.redirect_stderr(io.StringIO()): + self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed")) + resumed = fake.made("stream_claude")[1] + self.assertEqual(resumed[resumed.index("-p") + 1], "README.md or the project's records answer your question:\n\nUse *A*.\n\nContinue the task.") + self.assertEqual(len(fake.made("claude_on_terminal")), 1) + + def test_the_judge_fails_on_an_answer_the_records_do_not_hold(self): + invented = judged("interrupt", answer="Use B.") + fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[invented] * 3) + with contextlib.redirect_stderr(io.StringIO()): + self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(1, "the judge failed three times running: the judge answered 'Which one?' with 'Use B.', which README.md and the project's records do not hold")) + @unittest.skipIf(os.geteuid() == 0, "root writes into a read-only directory") def test_stops_keeping_the_transcript_when_the_finished_chunks_session_cannot_be_deleted(self): folder = self.paths.claude_code_transcripts / "-fake" / str(self.session.id) @@ -295,7 +316,7 @@ class Limits(unittest.TestCase): def test_the_judge_reports_a_limit_whatever_its_exit_code(self): reply = json.dumps({"type": "result", "api_error_status": 429, "is_error": True, "result": "You've hit your session limit · resets 7:40pm (Europe/Stockholm)"}) fake = FakeEffects(claude=[ran(reply, code=1, stderr="limited")]) - self.assertEqual(judge.run_judge("/r", [], "", "", fake.effects()), Limited(None, "You've hit your session limit · resets 7:40pm (Europe/Stockholm)")) + self.assertEqual(judge.run_judge("/r", [], "", "", "", fake.effects()), Limited(None, "You've hit your session limit · resets 7:40pm (Europe/Stockholm)")) def test_reads_only_a_rejecting_events_whole_seconds(self): for info, want in [({"status": "rejected", "resetsAt": NOW}, NOW), ({"status": "allowed", "resetsAt": NOW}, None), ({"status": "rejected", "resetsAt": True}, None), ({"status": "rejected"}, None), ("rejected", None)]: @@ -352,11 +373,11 @@ class Records(unittest.TestCase): def test_heads_each_record_the_project_has_by_its_path(self): with tempfile.TemporaryDirectory() as root: self.assertEqual(records.read_records(root), "") - pathlib.Path(root, "docs", "decisions").mkdir(parents=True) - pathlib.Path(root, "docs", "decisions", "b.md").write_text("# B\n") - pathlib.Path(root, "docs", "decisions", "a.md").write_text("# A\n") + pathlib.Path(root, "docs").mkdir() + pathlib.Path(root, "docs", "decisions.md").write_text("# Decisions\n") + self.assertEqual(records.read_records(root), "From docs/decisions.md:\n# Decisions") pathlib.Path(root, "AGENTS.md").write_text("\n# Rules\n") - self.assertEqual(records.read_records(root), "From AGENTS.md:\n# Rules\n\nFrom docs/decisions/a.md:\n# A\n\nFrom docs/decisions/b.md:\n# B") + self.assertEqual(records.read_records(root), "From AGENTS.md:\n# Rules\n\nFrom docs/decisions.md:\n# Decisions") def test_stops_on_a_record_it_cannot_read(self): with tempfile.TemporaryDirectory() as root: @@ -471,12 +492,14 @@ class Grounded(unittest.TestCase): class Verdict(unittest.TestCase): def test_needs_every_field_the_schema_requires(self): - self.assertEqual(judge.verdict_from({"interrupt": False, "evidence": "e", "finished": True, "question": ""}), Finished("e")) - self.assertEqual(judge.verdict_from({"interrupt": False, "evidence": "e", "finished": False, "question": "ignored"}), Unfinished("e")) - self.assertEqual(judge.verdict_from({"interrupt": True, "evidence": "e", "finished": True, "question": "Which one?"}), Interrupt("e", "Which one?")) - self.assertEqual(judge.verdict_from({"interrupt": "no", "evidence": "", "finished": True, "question": ""}), Failure("the judge's reply has no interrupt of type boolean")) - self.assertEqual(judge.verdict_from({"interrupt": False, "evidence": None, "finished": True, "question": ""}), Failure("the judge's reply has no evidence of type string")) - self.assertEqual(judge.verdict_from({"interrupt": True, "evidence": "x", "finished": False, "question": " "}), Failure("the judge interrupted without a question")) + self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": "e", "finished": True, "question": ""}), Finished("e")) + self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": "e", "finished": False, "question": "ignored"}), Unfinished("e")) + self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "e", "finished": True, "question": "Which one?"}), Interrupt("e", "Which one?")) + self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"}), Recorded("e", "Which one?", "A.")) + self.assertEqual(judge.verdict_from({"answer": "ignored", "interrupt": False, "evidence": "e", "finished": False, "question": ""}), Unfinished("e")) + self.assertEqual(judge.verdict_from({"answer": "", "interrupt": "no", "evidence": "", "finished": True, "question": ""}), Failure("the judge's reply has no interrupt of type boolean")) + self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": None, "finished": True, "question": ""}), Failure("the judge's reply has no evidence of type string")) + self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "x", "finished": False, "question": " "}), Failure("the judge interrupted without a question")) self.assertEqual(judge.verdict_from(None), Failure("the judge returned no reply")) @@ -531,8 +554,8 @@ class ExitContract(unittest.TestCase): ("project/premises.py", "read_premises", "1", "f'README.md has no ##", premises_), ("project/premises.py", "read_premises", "1", "f'README.md has ## {name} more than once", premises_), ("project/premises.py", "read_premises", "1", "f'README.md has nothing under", premises_), - ("project/records.py", "read_records", "1", 'f"{name} in {root}:', "AGENTS.md or a decision file cannot be read, or is not UTF-8"), - ("project/records.py", "read_records", "1", 'f"{name} is not UTF-8', "AGENTS.md or a decision file cannot be read, or is not UTF-8"), + ("project/records.py", "read_records", "1", 'f"{name} in {root}:', "AGENTS.md or docs/decisions.md cannot be read, or is not UTF-8"), + ("project/records.py", "read_records", "1", 'f"{name} is not UTF-8', "AGENTS.md or docs/decisions.md cannot be read, or is not UTF-8"), ] root = pathlib.Path(main.__file__).parents[1] found = [] diff --git a/bin/test_loop_claude_black_box.py b/bin/test_loop_claude_black_box.py index 8c4cdfbb..58a7ca9a 100644 --- a/bin/test_loop_claude_black_box.py +++ b/bin/test_loop_claude_black_box.py @@ -116,7 +116,7 @@ def worker(**step): def judge(interrupt=False, finished=False, evidence="working", question="", **step): - verdict = {"evidence": evidence, "finished": finished, "interrupt": interrupt, "question": question} + verdict = {"answer": "", "evidence": evidence, "finished": finished, "interrupt": interrupt, "question": question} return {"role": "judge", "verdict": verdict, **step} @@ -392,7 +392,7 @@ class Cycles(unittest.TestCase): self.assertEqual(run.sleeps, [60, 60]) self.assertIn("retrying the judge in a minute: judge down", run.stderr) self.assertIn("retrying the judge in a minute: the judge returned no reply; it replied: nothing\n", run.stderr) - self.assertEqual(run.stderr.strip().splitlines()[-1], 'the judge failed three times running: the judge\'s reply has no evidence of type string; it replied: {"structured_output": {"interrupt": false}}') + self.assertEqual(run.stderr.strip().splitlines()[-1], 'the judge failed three times running: the judge\'s reply has no answer of type string; it replied: {"structured_output": {"interrupt": false}}') def test_waits_out_a_usage_limit_which_ends_a_run_of_failures(self): checkout = Checkout(self) diff --git a/docs/decisions.md b/docs/decisions.md index c60d48b2..d4c7346f 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -6,7 +6,7 @@ ## loop-claude: a judge decides each interrupt from the transcript, the README's premises and the project's records; the worker's own account of which goal settles a choice decides nothing -2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). The records settle a choice the worker made or an assumption it carried on under; a question the worker itself asks still interrupts, since a worker left unanswered would ask it again next cycle. Valid while the worker's self-report stays unreliable. +2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). A question the worker asks that the records answer is answered by the judge's verbatim quote of them, once per cycle: the worker asking again shows the record did not settle it, and that goes to the human. Valid while the worker's self-report stays unreliable. ## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it -- 2.52.0 From 160b1dae5f99d7bc173d26840dbe06a8eda0282d Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 00:39:20 +0200 Subject: [PATCH 03/20] Answer the architect: fail a judge that answers without interrupting, read every checkout file through one function --- bin/loop_claude/cycle/judge.py | 5 ++++- bin/loop_claude/loop/main.py | 8 ++++---- bin/loop_claude/project/checkout.py | 10 ++++++++++ bin/loop_claude/project/premises.py | 13 +++++-------- bin/loop_claude/project/records.py | 13 +++++-------- bin/test_loop_claude.py | 9 ++++----- 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index d990d311..079a96fe 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -14,7 +14,8 @@ from loop_claude.stop import Stop JUDGED_TRANSCRIPT_TAIL = 400000 JUDGE_RULES = ( - "Decide whether the human must now be interrupted. interrupt=true when any of these appear:\n" + "Decide whether the agent has something open that the human, or README.md and the project's records, " + "must answer. interrupt=true when any of these appear:\n" "- the agent asks the human anything, seeks approval, or says a decision is the human's\n" "- it carried on under an assumption that decides the deliverable, that the human could " "reasonably reject and that neither README.md nor the project's records settle; a caveat about " @@ -108,6 +109,8 @@ def verdict_from(output: object) -> Verdict | Failure: if not isinstance(output.get(name), kind): return Failure(f"the judge's reply has no {name} of type {JSON_TYPES[kind]}") # An interrupt outranks finished: the human answers before the chunk can close. + if output["answer"].strip() and not output["interrupt"]: + return Failure("the judge answered without interrupting") if output["interrupt"]: if not output["question"].strip(): return Failure("the judge interrupted without a question") diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 1c23569e..4f5a8505 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -37,8 +37,8 @@ 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 +- README.md, or AGENTS.md or docs/decisions.md where they exist, cannot be read or is not UTF-8 - README.md holds no premises -- AGENTS.md or docs/decisions.md cannot be read, or is not UTF-8 - the models file cannot be read or written - claude leaves no transcript - a transcript cannot be read or archived @@ -50,9 +50,9 @@ Exit 1, saying why, when: - 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, quotes a line the transcript does not hold, or quotes an answer - the premises and the records do not hold. A usage limit is - not a failure, and restarts the count of three: the worker or the judge is retried 2 minutes + interrupts without a question, answers without interrupting, quotes a line the transcript does + not hold, or quotes an answer the premises and the records do not hold. A usage limit is not a + failure, and restarts the count of three: the worker or the judge is retried 2 minutes after the limit resets, or every 10 minutes when the reset time is unknown or more than 2 minutes past. The judge's reply gives its reset time only as text, so the judge is always retried every 10 minutes. stderr says when the next try is due. diff --git a/bin/loop_claude/project/checkout.py b/bin/loop_claude/project/checkout.py index 4fc70c25..fb787d0b 100644 --- a/bin/loop_claude/project/checkout.py +++ b/bin/loop_claude/project/checkout.py @@ -27,3 +27,13 @@ def worktrees(root: str, effects: Effects) -> list[str]: def project_key(root: str, code: pathlib.Path) -> str: return root.removeprefix(f"{code}/").lstrip("/") + + +def read_checkout_file(root: str, name: str, consequence: str) -> str | Stop: + try: + return pathlib.Path(root, name).read_text(encoding="utf-8") + except OSError as failure: + return Stop(1, f"{name} in {root}: {failure.strerror} - {consequence}.") + except UnicodeDecodeError as failure: + line = failure.object.count(b"\n", 0, failure.start) + 1 + return Stop(1, f"{name} is not UTF-8 on line {line} - {consequence}.") diff --git a/bin/loop_claude/project/premises.py b/bin/loop_claude/project/premises.py index ba152799..f30f0a28 100644 --- a/bin/loop_claude/project/premises.py +++ b/bin/loop_claude/project/premises.py @@ -1,19 +1,16 @@ -import pathlib import re +from loop_claude.project.checkout import read_checkout_file from loop_claude.stop import Stop FENCE = re.compile(r"^ {0,3}(`{3,}|~{3,})", re.M) def read_premises(root: str) -> str | Stop: - try: - found = sections(pathlib.Path(root, "README.md").read_text(encoding="utf-8")) - except OSError as failure: - return Stop(1, f"README.md in {root}: {failure.strerror} - no premises.") - except UnicodeDecodeError as failure: - line = failure.object.count(b"\n", 0, failure.start) + 1 - return Stop(1, f"README.md is not UTF-8 on line {line} - no premises.") + text = read_checkout_file(root, "README.md", "no premises") + if isinstance(text, Stop): + return text + found = sections(text) for name in ("Goals", "Audience"): bodies = found.get(name, []) if not bodies: diff --git a/bin/loop_claude/project/records.py b/bin/loop_claude/project/records.py index f9bd185b..10ce9714 100644 --- a/bin/loop_claude/project/records.py +++ b/bin/loop_claude/project/records.py @@ -1,5 +1,6 @@ import pathlib +from loop_claude.project.checkout import read_checkout_file from loop_claude.stop import Stop @@ -7,14 +8,10 @@ def read_records(root: str) -> str | Stop: """AGENTS.md and docs/decisions.md, each headed by its path; a file the project lacks is left out.""" records = [] for name in ("AGENTS.md", "docs/decisions.md"): - try: - text = pathlib.Path(root, name).read_text(encoding="utf-8") - except FileNotFoundError: + if not pathlib.Path(root, name).exists(): continue - except OSError as failure: - return Stop(1, f"{name} in {root}: {failure.strerror} - the judge cannot read the project's records.") - except UnicodeDecodeError as failure: - line = failure.object.count(b"\n", 0, failure.start) + 1 - return Stop(1, f"{name} is not UTF-8 on line {line} - the judge cannot read the project's records.") + text = read_checkout_file(root, name, "the judge cannot read the project's records") + if isinstance(text, Stop): + return text records.append(f"From {name}:\n{text.strip()}") return "\n\n".join(records) diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index f994c2e1..7e1fede4 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -496,7 +496,7 @@ class Verdict(unittest.TestCase): self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": "e", "finished": False, "question": "ignored"}), Unfinished("e")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "e", "finished": True, "question": "Which one?"}), Interrupt("e", "Which one?")) self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"}), Recorded("e", "Which one?", "A.")) - self.assertEqual(judge.verdict_from({"answer": "ignored", "interrupt": False, "evidence": "e", "finished": False, "question": ""}), Unfinished("e")) + self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": False, "evidence": "e", "finished": False, "question": ""}), Failure("the judge answered without interrupting")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": "no", "evidence": "", "finished": True, "question": ""}), Failure("the judge's reply has no interrupt of type boolean")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": None, "finished": True, "question": ""}), Failure("the judge's reply has no evidence of type string")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "x", "finished": False, "question": " "}), Failure("the judge interrupted without a question")) @@ -529,6 +529,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" + unreadable = "README.md, or AGENTS.md or docs/decisions.md where they exist, cannot be read or is not UTF-8" # 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), @@ -546,16 +547,14 @@ class ExitContract(unittest.TestCase): ("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), + ("project/checkout.py", "read_checkout_file", "1", "f'{name} in {root}:", unreadable), + ("project/checkout.py", "read_checkout_file", "1", "f'{name} is not UTF-8", unreadable), ("project/model_choice.py", "get_or_ask_model", "1", "f'could not save the model in", models_), ("project/model_choice.py", "read_models_file", "1", 'f"could not read {saved}: {getattr(', models_), ("project/model_choice.py", "read_models_file", "1", "f'could not read {saved}: not an object", models_), - ("project/premises.py", "read_premises", "1", "f'README.md in {root}:", premises_), - ("project/premises.py", "read_premises", "1", "f'README.md is not UTF-8", premises_), ("project/premises.py", "read_premises", "1", "f'README.md has no ##", premises_), ("project/premises.py", "read_premises", "1", "f'README.md has ## {name} more than once", premises_), ("project/premises.py", "read_premises", "1", "f'README.md has nothing under", premises_), - ("project/records.py", "read_records", "1", 'f"{name} in {root}:', "AGENTS.md or docs/decisions.md cannot be read, or is not UTF-8"), - ("project/records.py", "read_records", "1", 'f"{name} is not UTF-8', "AGENTS.md or docs/decisions.md cannot be read, or is not UTF-8"), ] root = pathlib.Path(main.__file__).parents[1] found = [] -- 2.52.0 From 2f46a13e5d6b32cd19c3ea1cd27152d39021ceee Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 00:54:16 +0200 Subject: [PATCH 04/20] Answer the third round: show the judge loop-claude's prompts, one records answer per cycle through an interrupt, name the answer's two sources apart --- CHANGELOG.md | 1 + CLAUDE.md | 2 +- bin/loop_claude/claude_code/entries.py | 7 +++++++ bin/loop_claude/claude_code/transcript.py | 4 +++- bin/loop_claude/cycle/judge.py | 18 +++++++++-------- bin/loop_claude/cycle/run.py | 8 ++++---- bin/loop_claude/cycle/states.py | 24 ++++++++++++----------- bin/loop_claude/cycle/verdicts.py | 4 ++-- bin/test_loop_claude.py | 21 ++++++++++---------- docs/decisions.md | 2 +- 10 files changed, 53 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c678e388..babbc29a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question they answer, the worker resumes with the judge's quote of the answer; the worker's next question in that cycle goes to you. The judge reads the transcript's last 400,000 characters, up from 40,000. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. +- A project's decision log is `docs/decisions.md` alone, the one file the judge, `rank_todo.py` and the reviewers read; `CLAUDE.md` no longer allows splitting it into `docs/decisions/`. - `loop-claude` waits out a usage limit and retries: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. A limit is not a failure, and restarts the count of three failures in a row. It prints what claude said about the limit and when the next try is due. - Add the official plugin marketplace and install every plugin `settings.json` enables (README → Install): `claude-security`, `code-review` and `rust-analyzer-lsp`, which needs `rust-analyzer` on `PATH` for Rust projects. With `claude-security`, larv-review's full security scan runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. - systems-architect and product-owner-reviewer can no longer edit what they review; stability-reviewer keeps its shell to run tests, and loses Claude Code's file-editing tools. diff --git a/CLAUDE.md b/CLAUDE.md index d2774744..93f2e327 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -87,7 +87,7 @@ Prose describing the code as it stands — a comment, a README, an `AGENTS.md`, ### Decisions: one home, each linked to a goal or a technical principle -**A choice that shapes what the code does, made in one place, is a comment there, with its reason. Made in more than one place, it is a decision, and the decision log owns it.** A decision's rejected alternative, or what it deliberately does not cover, stays out of every call site. **The decision log has one home: `docs/decisions.md`**, or `docs/decisions/` split by area once it outgrows one file. A title states the whole decision in one line: what holds at the commit it ships in, in words a reader finds in the code or the plan. `AGENTS.md` lists every title, so a session works by the decisions without loading their background. A session reads the entry under a title only to question, revise or add a decision. The entry holds the background: its date, who made it, the reasoning, and the premise it rests on ("valid while X") so it can expire honestly when that premise dies. A choice found anywhere else — an `AGENTS.md` body, a comment, or a README section that is neither a goal nor how one is met — moves: to a comment at its one place, or, once made in more than one place, to the log, leaving its title in `AGENTS.md`'s list. A goal stays a goal in the README; the log records only what the goal leaves open. +**A choice that shapes what the code does, made in one place, is a comment there, with its reason. Made in more than one place, it is a decision, and the decision log owns it.** A decision's rejected alternative, or what it deliberately does not cover, stays out of every call site. **The decision log has one home: `docs/decisions.md`**. A title states the whole decision in one line: what holds at the commit it ships in, in words a reader finds in the code or the plan. `AGENTS.md` lists every title, so a session works by the decisions without loading their background. A session reads the entry under a title only to question, revise or add a decision. The entry holds the background: its date, who made it, the reasoning, and the premise it rests on ("valid while X") so it can expire honestly when that premise dies. A choice found anywhere else — an `AGENTS.md` body, a comment, or a README section that is neither a goal nor how one is met — moves: to a comment at its one place, or, once made in more than one place, to the log, leaving its title in `AGENTS.md`'s list. A goal stays a goal in the README; the log records only what the goal leaves open. **Every decision links to a goal or a technical principle.** An entry names the goal it serves or the technical principle under `~/.claude/principles/` it applies; one that can do neither is a missing goal, and an entry already in the repo with neither behind it is a finding. Propose the goal, never a reason of your own — "Ask, don't guess" under "Working loop" says how. An entry working against a goal or a technical principle stands only while it names the `todo.md` item that ends it. diff --git a/bin/loop_claude/claude_code/entries.py b/bin/loop_claude/claude_code/entries.py index f226a57c..1bd0b534 100644 --- a/bin/loop_claude/claude_code/entries.py +++ b/bin/loop_claude/claude_code/entries.py @@ -65,6 +65,13 @@ def human_text(entry: dict) -> str | None: return text if isinstance(text, str) else "".join(part_text(part) or "" for part in parts(entry)) +# {"type": "user", "promptSource": "sdk", "message": {"content": "Continue the task; the previous run stopped before it was finished."}} +def loop_text(entry: dict) -> str | None: + """What a -p prompt of loop-claude's told the agent.""" + text = content(entry) + return text if entry.get("type") == "user" and entry.get("promptSource") == "sdk" and isinstance(text, str) else None + + # What the human types while claude works, written only as this entry: # {"type": "attachment", "attachment": {"type": "queued_command", "commandMode": "prompt", "origin": {"kind": "human"}, "prompt": "B"}} def queued_human_text(entry: dict) -> str | None: diff --git a/bin/loop_claude/claude_code/transcript.py b/bin/loop_claude/claude_code/transcript.py index 64599c11..bf2ae8f6 100644 --- a/bin/loop_claude/claude_code/transcript.py +++ b/bin/loop_claude/claude_code/transcript.py @@ -1,6 +1,6 @@ import json -from loop_claude.claude_code.entries import assistant_parts, human_text, parse_entry, part_text, tool_call +from loop_claude.claude_code.entries import assistant_parts, human_text, loop_text, parse_entry, part_text, tool_call from loop_claude.failure import Failure JUDGED_TOOL_INPUT = 400 @@ -30,6 +30,8 @@ def render(entries: list[dict]) -> str: lines += [line for part in assistant_parts(entry) if (line := part_line(part, JUDGED_TOOL_INPUT))] if (text := human_text(entry)) is not None: lines.append("[human] " + text) + elif (text := loop_text(entry)) is not None: + lines.append("[loop] " + text) return "\n\n".join(lines) diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index 079a96fe..b5031725 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -4,13 +4,13 @@ import typing from loop_claude.claude_code.entries import hit_limit, limit_said, parse_entry, structured_output from loop_claude.cycle.retry import retried -from loop_claude.cycle.verdicts import Finished, Interrupt, Recorded, Unfinished, Verdict +from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished, Verdict from loop_claude.effects import Effects from loop_claude.failure import Failure from loop_claude.limited import Limited from loop_claude.stop import Stop -# About 100,000 tokens, leaving a 200,000-token context room for the rest of the prompt; the largest session rendered here was 364,000 characters on 2026-10-03. +# About 100,000 tokens, half a 200,000-token context; the largest session rendered here was 364,000 characters on 2026-10-03. JUDGED_TRANSCRIPT_TAIL = 400000 JUDGE_RULES = ( @@ -27,7 +27,9 @@ JUDGE_RULES = ( "between - neither rules the rejected one out - and the choice materially changes the deliverable\n" "interrupt=false otherwise. Bookkeeping the agent settled silently - what to document, wording, " "where a note goes - is not on its own a reason to interrupt. The human may have replied inside the transcript, on a [human] line: judge only what " - "is still open, never a question they already answered there.\n" + "is still open, never a question they already answered there. A [loop] line is what loop-claude told " + "the agent, such as an answer quoted from README.md or the project's records; a question it answered " + "is no longer open.\n" "Where the agent asked or flagged something itself, the question is that one, in the agent's own " "wording; never construct another from facts it stated.\n" "Where README.md or the project's records answer that question, quote the passage that answers it " @@ -85,8 +87,8 @@ 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}, which is not in the transcript" + (f", for the question: {verdict.question}" if isinstance(verdict, Interrupt | Recorded) else "")) - if isinstance(verdict, Recorded) and not grounded(verdict.answer, recorded): + 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 | AnsweredFromRecords) else "")) + if isinstance(verdict, AnsweredFromRecords) and not grounded(verdict.answer, recorded): return Failure(f"the judge answered {verdict.question!r} with {verdict.answer!r}, which README.md and the project's records do not hold") return verdict @@ -97,7 +99,7 @@ def judge_prompt(task: str, premises: str, records: str, rendered_transcript: st f"The project's records, its working rules and decisions:\n{records or 'none'}\n\n" f"The task an agent was given:\n{task}\n\n" # The tail, where an interrupt or a finish lands; the session's transcript grows cycle over cycle. - f"What the agent did and said, and what the human typed on [human] lines, latest last:\n{rendered_transcript[-JUDGED_TRANSCRIPT_TAIL:]}\n\n" + f"What the agent did and said, what the human typed on [human] lines and what loop-claude told it on [loop] lines, latest last:\n{rendered_transcript[-JUDGED_TRANSCRIPT_TAIL:]}\n\n" f"{JUDGE_RULES}" ) @@ -108,14 +110,14 @@ def verdict_from(output: object) -> Verdict | Failure: for name, kind in REPLY_TYPES.items(): if not isinstance(output.get(name), kind): return Failure(f"the judge's reply has no {name} of type {JSON_TYPES[kind]}") - # An interrupt outranks finished: the human answers before the chunk can close. if output["answer"].strip() and not output["interrupt"]: return Failure("the judge answered without interrupting") + # An interrupt outranks finished: the human answers before the chunk can close. if output["interrupt"]: if not output["question"].strip(): return Failure("the judge interrupted without a question") if output["answer"].strip(): - return Recorded(output["evidence"], output["question"], output["answer"]) + return AnsweredFromRecords(output["evidence"], output["question"], output["answer"]) return Interrupt(output["evidence"], output["question"]) return Finished(output["evidence"]) if output["finished"] else Unfinished(output["evidence"]) diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index 2c5982b2..861a2c50 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -7,7 +7,7 @@ from loop_claude.cycle.archive import archive from loop_claude.cycle.interrupt import interrupt from loop_claude.cycle.judge import judge from loop_claude.cycle.retry import retried -from loop_claude.cycle.states import Active, Answered, Archived, Closing, Ended, Event, Interrupting, Judging, Ruled, State, WorkerRan, Working, transition +from loop_claude.cycle.states import Active, Archived, Closing, Ended, Event, HumanAnswered, Interrupting, Judging, Ruled, State, WorkerRan, Working, transition from loop_claude.cycle.verdicts import Finished, Unfinished from loop_claude.cycle.worker import run_worker, worker_args from loop_claude.effects import Effects @@ -56,7 +56,7 @@ def step(cycle: Cycle, state: Active) -> Event | Stop: return work(cycle, answer) case Judging(transcript_path, _): return rule(cycle, transcript_path) - case Interrupting(transcript_path, question): + case Interrupting(transcript_path, question, _): return ask(cycle, transcript_path, question) case Closing(transcript_path, verdict): return close(cycle, transcript_path, verdict) @@ -80,11 +80,11 @@ def rule(cycle: Cycle, transcript_path: str) -> Ruled | Stop: return verdict if isinstance(verdict, Stop) else Ruled(verdict) -def ask(cycle: Cycle, transcript_path: str, question: str) -> Answered | Stop: +def ask(cycle: Cycle, transcript_path: str, question: str) -> HumanAnswered | Stop: # Archived now, so the transcript the question was asked on is kept with it; the human's answer then grows the transcript. if failure := archive(cycle.project_key, transcript_path, cycle.task, f"Verdict: interrupt\n\n{question}", cycle.paths): return Stop(1, failure.reason) - return interrupt(cycle.root, cycle.session.id, cycle.models.worker, transcript_path, question, cycle.paths, cycle.effects) or Answered() + return interrupt(cycle.root, cycle.session.id, cycle.models.worker, transcript_path, question, cycle.paths, cycle.effects) or HumanAnswered() def close(cycle: Cycle, transcript_path: str, verdict: Finished | Unfinished) -> Archived | Stop: diff --git a/bin/loop_claude/cycle/states.py b/bin/loop_claude/cycle/states.py index c5061115..480a22c7 100644 --- a/bin/loop_claude/cycle/states.py +++ b/bin/loop_claude/cycle/states.py @@ -1,6 +1,6 @@ import dataclasses -from loop_claude.cycle.verdicts import Finished, Interrupt, Recorded, Unfinished, Verdict +from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished, Verdict @dataclasses.dataclass(frozen=True) @@ -11,6 +11,7 @@ class Working: @dataclasses.dataclass(frozen=True) class Judging: + """The judge rules; answered_from_records holds once the records answered a question this cycle.""" transcript_path: str answered_from_records: bool = False @@ -19,6 +20,7 @@ class Judging: class Interrupting: transcript_path: str question: str + answered_from_records: bool = False @dataclasses.dataclass(frozen=True) @@ -47,7 +49,7 @@ class Ruled: @dataclasses.dataclass(frozen=True) -class Answered: +class HumanAnswered: pass @@ -56,25 +58,25 @@ class Archived: pass -Event = WorkerRan | Ruled | Answered | Archived +Event = WorkerRan | Ruled | HumanAnswered | Archived def transition(state: State, event: Event) -> State: match state, event: case Working(answer), WorkerRan(transcript_path): return Judging(transcript_path, answer is not None) - case Judging(_, False), Ruled(Recorded(answer=answer)): + case Judging(_, False), Ruled(AnsweredFromRecords(answer=answer)): return Working(answer) - # The worker asked again after the records' answer, so the answer did not settle it. - case Judging(transcript_path, True), Ruled(Recorded(question=question)): - return Interrupting(transcript_path, question) - case Judging(transcript_path, _), Ruled(Interrupt(question=question)): - return Interrupting(transcript_path, question) + # One records answer per cycle, so a worker the answer did not satisfy cannot loop unattended. + case Judging(transcript_path, True), Ruled(AnsweredFromRecords(question=question)): + return Interrupting(transcript_path, question, True) + case Judging(transcript_path, answered_from_records), Ruled(Interrupt(question=question)): + return Interrupting(transcript_path, question, answered_from_records) case Judging(transcript_path, _), Ruled(Finished() | Unfinished() as verdict): return Closing(transcript_path, verdict) # 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 Interrupting(transcript_path, _, answered_from_records), HumanAnswered(): + return Judging(transcript_path, answered_from_records) case Closing(), Archived(): return Ended() raise ValueError(f"no transition from {state} on {event}") diff --git a/bin/loop_claude/cycle/verdicts.py b/bin/loop_claude/cycle/verdicts.py index a414f95a..f3ce6d5a 100644 --- a/bin/loop_claude/cycle/verdicts.py +++ b/bin/loop_claude/cycle/verdicts.py @@ -8,7 +8,7 @@ class Interrupt: @dataclasses.dataclass(frozen=True) -class Recorded: +class AnsweredFromRecords: """The agent asked a question that README.md or the project's records answer, quoted in answer.""" evidence: str question: str @@ -25,4 +25,4 @@ class Unfinished: evidence: str -Verdict = Interrupt | Recorded | Finished | Unfinished +Verdict = Interrupt | AnsweredFromRecords | Finished | Unfinished diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 7e1fede4..bb7024aa 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -19,7 +19,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) from loop_claude import file_writes, paths from loop_claude.claude_code import entries, session, transcript, trust from loop_claude.cycle import archive, interrupt, judge, retry, run, states, worker -from loop_claude.cycle.verdicts import Finished, Interrupt, Recorded, Unfinished +from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished from loop_claude.effects import Effects from loop_claude.failure import Failure from loop_claude.limited import Limited @@ -131,21 +131,22 @@ class Transitions(unittest.TestCase): (states.Working(), states.WorkerRan("/t"), states.Judging("/t")), (states.Working("A."), states.WorkerRan("/t"), states.Judging("/t", True)), (states.Judging("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")), - (states.Judging("/t", True), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")), - (states.Judging("/t"), states.Ruled(Recorded("e", "Which one?", "A.")), states.Working("A.")), - (states.Judging("/t", True), states.Ruled(Recorded("e", "Which one?", "A.")), states.Interrupting("/t", "Which one?")), + (states.Judging("/t", True), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", True)), + (states.Judging("/t"), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Working("A.")), + (states.Judging("/t", True), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Interrupting("/t", "Which one?", True)), (states.Judging("/t", True), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t", True), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), (states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), - (states.Interrupting("/t", "q"), states.Answered(), states.Judging("/t")), + (states.Interrupting("/t", "q"), states.HumanAnswered(), states.Judging("/t")), + (states.Interrupting("/t", "q", True), states.HumanAnswered(), states.Judging("/t", True)), (states.Closing("/t", Finished("e")), states.Archived(), states.Ended()), ) for state, event, after in legal: with self.subTest(state=state, event=event): self.assertEqual(states.transition(state, event), after) - every_state = (states.Working(), states.Working("A."), states.Judging("/t"), states.Judging("/t", True), states.Interrupting("/t", "q"), states.Closing("/t", Finished("e")), states.Ended()) - every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Ruled(Recorded("e", "Which one?", "A.")), states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.Answered(), states.Archived()) + every_state = (states.Working(), states.Working("A."), states.Judging("/t"), states.Judging("/t", True), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", True), states.Closing("/t", Finished("e")), states.Ended()) + every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanAnswered(), states.Archived()) for state in every_state: for event in every_event: if (state, event) not in [(state, event) for state, event, _ in legal]: @@ -399,7 +400,7 @@ class Sections(unittest.TestCase): class Render(unittest.TestCase): - def test_joins_assistant_text_and_tool_calls_and_human_turns_and_skips_the_rest(self): + def test_joins_assistant_text_tool_calls_human_turns_and_loop_prompts_and_skips_the_rest(self): said = transcript.render([ human("do it"), assistant({"type": "text", "text": "Starting."}, {"type": "tool_use", "name": "Bash", "input": {"command": "ls"}}), @@ -411,7 +412,7 @@ class Render(unittest.TestCase): queued("origin/main moved", "coordinator"), {**human("Continue the task; the previous run stopped before it was finished."), "promptSource": "sdk"}, ]) - self.assertEqual(said, '[human] do it\n\nStarting.\n\n[tool Bash] {"command": "ls"}\n\n[human] yes, merge it\n\n[human] B, while you work') + self.assertEqual(said, '[human] do it\n\nStarting.\n\n[tool Bash] {"command": "ls"}\n\n[human] yes, merge it\n\n[human] B, while you work\n\n[loop] Continue the task; the previous run stopped before it was finished.') class CopyFor(unittest.TestCase): @@ -495,7 +496,7 @@ class Verdict(unittest.TestCase): self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": "e", "finished": True, "question": ""}), Finished("e")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": "e", "finished": False, "question": "ignored"}), Unfinished("e")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "e", "finished": True, "question": "Which one?"}), Interrupt("e", "Which one?")) - self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"}), Recorded("e", "Which one?", "A.")) + self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"}), AnsweredFromRecords("e", "Which one?", "A.")) self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": False, "evidence": "e", "finished": False, "question": ""}), Failure("the judge answered without interrupting")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": "no", "evidence": "", "finished": True, "question": ""}), Failure("the judge's reply has no interrupt of type boolean")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": None, "finished": True, "question": ""}), Failure("the judge's reply has no evidence of type string")) diff --git a/docs/decisions.md b/docs/decisions.md index d4c7346f..29771c85 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -6,7 +6,7 @@ ## loop-claude: a judge decides each interrupt from the transcript, the README's premises and the project's records; the worker's own account of which goal settles a choice decides nothing -2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). A question the worker asks that the records answer is answered by the judge's verbatim quote of them, once per cycle: the worker asking again shows the record did not settle it, and that goes to the human. Valid while the worker's self-report stays unreliable. +2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). A question the worker asks that the records answer is answered by the judge's verbatim quote of them, which the judge then sees as a `[loop]` line. That happens at most once per cycle, so a worker the answer did not satisfy cannot loop unattended (goal 4.4); its next question that cycle goes to the human. Valid while the worker's self-report stays unreliable. ## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it -- 2.52.0 From 1839c8a19ef6b9120a34618a9bea3eb76626d99b Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 01:32:22 +0200 Subject: [PATCH 05/20] Answer the fourth round: a repeated question goes to the human, three records answers a cycle as the backstop, the quote in the interrupt, the cycle redefined --- CHANGELOG.md | 2 +- CLAUDE.md | 2 +- bin/loop_claude/cycle/judge.py | 2 +- bin/loop_claude/cycle/run.py | 2 +- bin/loop_claude/cycle/states.py | 31 +++++++++++++++++-------------- bin/loop_claude/loop/main.py | 4 ++-- bin/test_loop_claude.py | 29 ++++++++++++++++------------- docs/decisions.md | 2 +- todo.md | 7 ++++++- 9 files changed, 46 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82bf0e2c..9aaf0b70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Unreleased - Unless another Exempt reason fits, larv-review marks a `todo.md` item filed from a 🟡 finding against `~/.claude/principles/` with `principle`, an Exempt reason that keeps it whatever its score. -- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question they answer, the worker resumes with the judge's quote of the answer; the worker's next question in that cycle goes to you. The judge reads the transcript's last 400,000 characters, up from 40,000. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. +- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question they answer, the worker resumes with the judge's quote of the answer, up to three times a cycle; a question asked again after its answer, or a fourth, goes to you, with the quote. The judge reads the transcript's last 400,000 characters, up from 40,000. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. - A project's decision log is `docs/decisions.md` alone, the one file the judge, `rank_todo.py` and the reviewers read; `CLAUDE.md` no longer allows splitting it into `docs/decisions/`. - `loop-claude` waits out a usage limit and retries: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. A limit is not a failure, and restarts the count of three failures in a row. It prints what claude said about the limit and when the next try is due. - Add the official plugin marketplace and install every plugin `settings.json` enables (README → Install): `claude-security`, `code-review` and `rust-analyzer-lsp`, which needs `rust-analyzer` on `PATH` for Rust projects. With `claude-security`, larv-review's full security scan runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. diff --git a/CLAUDE.md b/CLAUDE.md index bc1a464b..ce3e71f6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -151,7 +151,7 @@ The rules every project follows, compose-not-entangle first: `~/.claude/principl ## Vocabulary - **chunk** — the unit of work, shipped as one PR; "Working loop" says what it holds. -- **cycle** — one worker run and the judge's verdict on it, in `loop-claude`. +- **cycle** — in `loop-claude`, a worker run and the judge's verdicts on it, with any interrupts and records answers in between, until the chunk closes or continues next cycle. - **gate** — the merge gate: the checks a PR passes before it merges. - **interrupt** — `loop-claude` handing the terminal to the human, `claude --resume`, for a decision that is theirs. - **judge** — the headless claude that reads a worker's transcript each cycle and decides whether to interrupt and whether the chunk is finished. diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index b5031725..b44c125c 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -29,7 +29,7 @@ JUDGE_RULES = ( "where a note goes - is not on its own a reason to interrupt. The human may have replied inside the transcript, on a [human] line: judge only what " "is still open, never a question they already answered there. A [loop] line is what loop-claude told " "the agent, such as an answer quoted from README.md or the project's records; a question it answered " - "is no longer open.\n" + "is no longer open, unless the agent asks it again: then it is the human's, with answer empty.\n" "Where the agent asked or flagged something itself, the question is that one, in the agent's own " "wording; never construct another from facts it stated.\n" "Where README.md or the project's records answer that question, quote the passage that answers it " diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index 861a2c50..47c1e8a4 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -52,7 +52,7 @@ def stopped(cycle: Cycle, stop: Stop, why: str) -> Stop: def step(cycle: Cycle, state: Active) -> Event | Stop: match state: - case Working(answer): + case Working(answer, _): return work(cycle, answer) case Judging(transcript_path, _): return rule(cycle, transcript_path) diff --git a/bin/loop_claude/cycle/states.py b/bin/loop_claude/cycle/states.py index 480a22c7..8d941b2e 100644 --- a/bin/loop_claude/cycle/states.py +++ b/bin/loop_claude/cycle/states.py @@ -2,25 +2,29 @@ import dataclasses from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished, Verdict +# A backstop, so a worker the records' answers do not satisfy cannot loop unattended; the judge sends a repeated question to the human. +RECORDS_ANSWERS_PER_CYCLE = 3 + @dataclasses.dataclass(frozen=True) class Working: """The worker runs, resumed with the records' answer when there is one.""" answer: str | None = None + records_answers: int = 0 @dataclasses.dataclass(frozen=True) class Judging: - """The judge rules; answered_from_records holds once the records answered a question this cycle.""" + """The judge rules; records_answers counts the questions the records answered this cycle.""" transcript_path: str - answered_from_records: bool = False + records_answers: int = 0 @dataclasses.dataclass(frozen=True) class Interrupting: transcript_path: str question: str - answered_from_records: bool = False + records_answers: int = 0 @dataclasses.dataclass(frozen=True) @@ -63,20 +67,19 @@ Event = WorkerRan | Ruled | HumanAnswered | Archived def transition(state: State, event: Event) -> State: match state, event: - case Working(answer), WorkerRan(transcript_path): - return Judging(transcript_path, answer is not None) - case Judging(_, False), Ruled(AnsweredFromRecords(answer=answer)): - return Working(answer) - # One records answer per cycle, so a worker the answer did not satisfy cannot loop unattended. - case Judging(transcript_path, True), Ruled(AnsweredFromRecords(question=question)): - return Interrupting(transcript_path, question, True) - case Judging(transcript_path, answered_from_records), Ruled(Interrupt(question=question)): - return Interrupting(transcript_path, question, answered_from_records) + case Working(_, records_answers), WorkerRan(transcript_path): + return Judging(transcript_path, records_answers) + case Judging(_, records_answers), Ruled(AnsweredFromRecords(answer=answer)) if records_answers < RECORDS_ANSWERS_PER_CYCLE: + return Working(answer, records_answers + 1) + case Judging(transcript_path, records_answers), Ruled(AnsweredFromRecords(question=question, answer=answer)): + return Interrupting(transcript_path, f"{question}\n\nREADME.md or the project's records say:\n{answer}", records_answers) + case Judging(transcript_path, records_answers), Ruled(Interrupt(question=question)): + return Interrupting(transcript_path, question, records_answers) case Judging(transcript_path, _), Ruled(Finished() | Unfinished() as verdict): return Closing(transcript_path, verdict) # The human works in the interrupt's claude session, so the judge rules again on the transcript it leaves. - case Interrupting(transcript_path, _, answered_from_records), HumanAnswered(): - return Judging(transcript_path, answered_from_records) + case Interrupting(transcript_path, _, records_answers), HumanAnswered(): + return Judging(transcript_path, records_answers) case Closing(), Archived(): return Ended() raise ValueError(f"no transition from {state} on {event}") diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 4f5a8505..8d35e331 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -7,8 +7,8 @@ premises; the task runs at the checkout root. Each cycle a worker runs the task; the transcript's last 400,000 characters against the premises and the project's records, AGENTS.md and docs/decisions.md where they exist, and rules whether the chunk, the work of one PR, is finished. A choice the worker made that the premises or the records settle is not asked about. When the worker -asks a question they answer, the judge quotes the answer and the worker resumes with it; the -worker's next question in the cycle goes to the human. +asks a question they answer, the judge quotes the answer and the worker resumes with it, up to three +times a cycle; a question asked again after its answer, or a fourth, goes to the human. 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. diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index bb7024aa..5830a512 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -127,26 +127,28 @@ class Streamed: class Transitions(unittest.TestCase): def test_each_state_moves_on_its_events_and_only_on_them(self): + answered = states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")) legal = ( (states.Working(), states.WorkerRan("/t"), states.Judging("/t")), - (states.Working("A."), states.WorkerRan("/t"), states.Judging("/t", True)), + (states.Working("A.", 3), states.WorkerRan("/t"), states.Judging("/t", 3)), (states.Judging("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")), - (states.Judging("/t", True), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", True)), - (states.Judging("/t"), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Working("A.")), - (states.Judging("/t", True), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Interrupting("/t", "Which one?", True)), - (states.Judging("/t", True), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), - (states.Judging("/t", True), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), + (states.Judging("/t", 3), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", 3)), + (states.Judging("/t"), answered, states.Working("A.", 1)), + (states.Judging("/t", 2), answered, states.Working("A.", 3)), + (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md or the project's records say:\nA.", 3)), (states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), + (states.Judging("/t", 3), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), + (states.Judging("/t", 3), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), (states.Interrupting("/t", "q"), states.HumanAnswered(), states.Judging("/t")), - (states.Interrupting("/t", "q", True), states.HumanAnswered(), states.Judging("/t", True)), + (states.Interrupting("/t", "q", 3), states.HumanAnswered(), states.Judging("/t", 3)), (states.Closing("/t", Finished("e")), states.Archived(), states.Ended()), ) for state, event, after in legal: with self.subTest(state=state, event=event): self.assertEqual(states.transition(state, event), after) - every_state = (states.Working(), states.Working("A."), states.Judging("/t"), states.Judging("/t", True), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", True), states.Closing("/t", Finished("e")), states.Ended()) - every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanAnswered(), states.Archived()) + every_state = (states.Working(), states.Working("A.", 3), states.Judging("/t"), states.Judging("/t", 3), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", 3), states.Closing("/t", Finished("e")), states.Ended()) + every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), answered, states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanAnswered(), states.Archived()) for state in every_state: for event in every_event: if (state, event) not in [(state, event) for state, event, _ in legal]: @@ -242,14 +244,15 @@ class Cycles(unittest.TestCase): self.assertNotIn("the second", prompts[0]) self.assertIn("[human] the second", prompts[1]) - def test_a_question_the_records_answer_resumes_the_worker_with_the_answer_once_per_cycle(self): + def test_a_question_the_records_answer_resumes_the_worker_with_the_answer_three_times_a_cycle(self): answered = judged("interrupt", answer="Use *A*.") - fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 2, claude=[answered, answered, judged("unfinished")], on_terminal_claude=[0], git=[ran()]) - with contextlib.redirect_stderr(io.StringIO()): + fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 4, claude=[answered] * 4, on_terminal_claude=[0], git=[ran()]) + with contextlib.redirect_stderr(io.StringIO()) as said: self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed")) resumed = fake.made("stream_claude")[1] self.assertEqual(resumed[resumed.index("-p") + 1], "README.md or the project's records answer your question:\n\nUse *A*.\n\nContinue the task.") - self.assertEqual(len(fake.made("claude_on_terminal")), 1) + self.assertEqual(len(fake.made("stream_claude")), 4) + self.assertIn("Which one?\n\nREADME.md or the project's records say:\nUse *A*.", said.getvalue()) def test_the_judge_fails_on_an_answer_the_records_do_not_hold(self): invented = judged("interrupt", answer="Use B.") diff --git a/docs/decisions.md b/docs/decisions.md index 037b7d6d..2fdae179 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -6,7 +6,7 @@ ## loop-claude: a judge decides each interrupt from the transcript, the README's premises and the project's records; the worker's own account of which goal settles a choice decides nothing -2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). A question the worker asks that the records answer is answered by the judge's verbatim quote of them, which the judge then sees as a `[loop]` line. That happens at most once per cycle, so a worker the answer did not satisfy cannot loop unattended (goal 4.4); its next question that cycle goes to the human. Valid while the worker's self-report stays unreliable. +2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). A question the worker asks that the records answer is answered by the judge's verbatim quote of them, which the judge then sees as a `[loop]` line; the worker asking it again shows the record did not settle it, and the judge sends it to the human. A backstop of three records answers per cycle keeps a worker the answers do not satisfy from looping unattended (goal 4.4); a fourth goes to the human with the judge's quote, so the cost is one interrupt. Valid while the worker's self-report stays unreliable. ## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it diff --git a/todo.md b/todo.md index c388b5e5..eb5cdd81 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 9` -`Next ID = 39` +`Next ID = 40` | Goal | W | |---|---| @@ -35,6 +35,7 @@ | 29 | 0.1.0 | | **Make the contributor a standing member of every project's audience, unless its `## Audience` says maintainability does not matter.** | 2 | 2 | 3 | 5 | 4.1, 4.4 | 9.1 | | 17 | 0.1.0 | decision | **Make `JUDGE_RULES` and the Claude Code flags `loop-claude` passes readable without `CLAUDE.md` or Claude Code's docs open.** | 1 | 2 | 3 | 4 | 4.1 | 9.0 | | 6 | 0.1.0 | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 5 | 5 | 4 | 5 | 4.1 | 7.4 | +| 39 | 0.1.0 | principle | **Sort each Python file's imports by the first name each binds.** | 2 | 3 | 3 | 3 | 4.1 | 6.6 | ## Details @@ -85,3 +86,7 @@ The 2026-10-02 scoring runs on PR #191 named both under Self-sufficiency: the ju ### 6. Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay. Claude Code owns that file and writes it. `trust` reads it, changes it and writes it back, so a write that lands in between is lost. + +### 39. Sort each Python file's imports by the first name each binds. + +The principle "Deterministic order wherever order carries no meaning" sorts imports on their first binding; `bin/loop_claude/` and `bin/rank_todo.py` sort `from loop_claude…` imports by module path, as in `loop/main.py` and `cycle/run.py`, so moving a module reorders imports in every file that uses it. Filed by the 2026-10-03 principles audit on PR #202. -- 2.52.0 From 9252884a552d1ad06537c3bdad390e1f2c0b9786 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 01:33:34 +0200 Subject: [PATCH 06/20] Say in the changelog that only the fourth question carries the quote --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9aaf0b70..72cca699 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Unreleased - Unless another Exempt reason fits, larv-review marks a `todo.md` item filed from a 🟡 finding against `~/.claude/principles/` with `principle`, an Exempt reason that keeps it whatever its score. -- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question they answer, the worker resumes with the judge's quote of the answer, up to three times a cycle; a question asked again after its answer, or a fourth, goes to you, with the quote. The judge reads the transcript's last 400,000 characters, up from 40,000. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. +- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question they answer, the worker resumes with the judge's quote of the answer, up to three times a cycle; a question asked again after its answer goes to you, and a fourth goes to you with the quote. The judge reads the transcript's last 400,000 characters, up from 40,000. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. - A project's decision log is `docs/decisions.md` alone, the one file the judge, `rank_todo.py` and the reviewers read; `CLAUDE.md` no longer allows splitting it into `docs/decisions/`. - `loop-claude` waits out a usage limit and retries: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. A limit is not a failure, and restarts the count of three failures in a row. It prints what claude said about the limit and when the next try is due. - Add the official plugin marketplace and install every plugin `settings.json` enables (README → Install): `claude-security`, `code-review` and `rust-analyzer-lsp`, which needs `rust-analyzer` on `PATH` for Rust projects. With `claude-security`, larv-review's full security scan runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. -- 2.52.0 From 4eec8d74ff8169deb03b89ffe019a423d11bfdbb Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 01:34:25 +0200 Subject: [PATCH 07/20] Answer the fifth round's nits: cycle holds worker runs, a test ties --help's limits to the constants --- CLAUDE.md | 2 +- bin/test_loop_claude.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CLAUDE.md b/CLAUDE.md index ce3e71f6..cc6ded35 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -151,7 +151,7 @@ The rules every project follows, compose-not-entangle first: `~/.claude/principl ## Vocabulary - **chunk** — the unit of work, shipped as one PR; "Working loop" says what it holds. -- **cycle** — in `loop-claude`, a worker run and the judge's verdicts on it, with any interrupts and records answers in between, until the chunk closes or continues next cycle. +- **cycle** — in `loop-claude`, worker runs and the judge's verdicts on them, with any interrupts and records answers in between, until the chunk closes or continues next cycle. - **gate** — the merge gate: the checks a PR passes before it merges. - **interrupt** — `loop-claude` handing the terminal to the human, `claude --resume`, for a decision that is theirs. - **judge** — the headless claude that reads a worker's transcript each cycle and decides whether to interrupt and whether the chunk is finished. diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 5830a512..5f5a3030 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -529,6 +529,12 @@ class LoopRuns(unittest.TestCase): self.assertEqual(reload.exec_if_edited(launcher, "stale", main.LoopRun(1, "/r", "do it"), fake.effects()), Stop(1, "could not reload loop-claude: No such file or directory; rerun loop-claude ")) +class HelpLimits(unittest.TestCase): + def test_help_states_the_limits_the_code_holds(self): + self.assertIn(f"last {judge.JUDGED_TRANSCRIPT_TAIL:,} characters", main.__doc__) + self.assertIn(f"up to {['one', 'two', 'three', 'four'][states.RECORDS_ANSWERS_PER_CYCLE - 1]}\ntimes a cycle", main.__doc__) + + 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" -- 2.52.0 From 74d9df412e0c3542d1a59247f5d2ca542aade4fe Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 01:34:31 +0200 Subject: [PATCH 08/20] Name what the records-answer backstop bounds --- bin/loop_claude/cycle/states.py | 2 +- docs/decisions.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/loop_claude/cycle/states.py b/bin/loop_claude/cycle/states.py index 8d941b2e..7abb04e8 100644 --- a/bin/loop_claude/cycle/states.py +++ b/bin/loop_claude/cycle/states.py @@ -2,7 +2,7 @@ import dataclasses from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished, Verdict -# A backstop, so a worker the records' answers do not satisfy cannot loop unattended; the judge sends a repeated question to the human. +# A backstop for what the judge misses, such as a reworded repeat, so the worker cannot loop unattended on the records' answers. RECORDS_ANSWERS_PER_CYCLE = 3 diff --git a/docs/decisions.md b/docs/decisions.md index 2fdae179..16ea9c1a 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -6,7 +6,7 @@ ## loop-claude: a judge decides each interrupt from the transcript, the README's premises and the project's records; the worker's own account of which goal settles a choice decides nothing -2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). A question the worker asks that the records answer is answered by the judge's verbatim quote of them, which the judge then sees as a `[loop]` line; the worker asking it again shows the record did not settle it, and the judge sends it to the human. A backstop of three records answers per cycle keeps a worker the answers do not satisfy from looping unattended (goal 4.4); a fourth goes to the human with the judge's quote, so the cost is one interrupt. Valid while the worker's self-report stays unreliable. +2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). A question the worker asks that the records answer is answered by the judge's verbatim quote of them, which the judge then sees as a `[loop]` line; the worker asking it again shows the record did not settle it, and the judge sends it to the human. A backstop of three records answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so it cannot loop unattended (goal 4.4); a fourth goes to the human with the judge's quote, so the cost is one interrupt. Valid while the worker's self-report stays unreliable. ## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it -- 2.52.0 From 09fb7dcdd58067179323bcfb0ae739671d70e37e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 01:42:37 +0200 Subject: [PATCH 09/20] Answer the stability and product passes: print each records answer, name its question, drop a misquote to an interrupt, budget the whole prompt --- CHANGELOG.md | 2 +- CLAUDE.md | 2 +- bin/loop_claude/cycle/judge.py | 18 ++++++------- bin/loop_claude/cycle/run.py | 12 +++++---- bin/loop_claude/cycle/states.py | 8 +++--- bin/loop_claude/cycle/worker.py | 10 +++++--- bin/loop_claude/loop/main.py | 17 +++++++------ bin/loop_claude/project/checkout.py | 2 +- bin/test_loop_claude.py | 39 ++++++++++++++++------------- bin/test_loop_claude_black_box.py | 5 ++-- 10 files changed, 62 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72cca699..597fa3c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Unreleased - Unless another Exempt reason fits, larv-review marks a `todo.md` item filed from a 🟡 finding against `~/.claude/principles/` with `principle`, an Exempt reason that keeps it whatever its score. -- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question they answer, the worker resumes with the judge's quote of the answer, up to three times a cycle; a question asked again after its answer goes to you, and a fourth goes to you with the quote. The judge reads the transcript's last 400,000 characters, up from 40,000. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. +- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question they answer, the worker resumes with the judge's quote of the answer, which `loop-claude` prints, up to three times a cycle; a question asked again after its answer goes to you, and a fourth goes to you with the quote. A quote the records do not hold word for word is dropped, and the question goes to you. The judge reads as much of the transcript's end as fits a 400,000-character prompt, up from the last 40,000 characters. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. - A project's decision log is `docs/decisions.md` alone, the one file the judge, `rank_todo.py` and the reviewers read; `CLAUDE.md` no longer allows splitting it into `docs/decisions/`. - `loop-claude` waits out a usage limit and retries: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. A limit is not a failure, and restarts the count of three failures in a row. It prints what claude said about the limit and when the next try is due. - Add the official plugin marketplace and install every plugin `settings.json` enables (README → Install): `claude-security`, `code-review` and `rust-analyzer-lsp`, which needs `rust-analyzer` on `PATH` for Rust projects. With `claude-security`, larv-review's full security scan runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. diff --git a/CLAUDE.md b/CLAUDE.md index cc6ded35..fb771bd5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -151,7 +151,7 @@ The rules every project follows, compose-not-entangle first: `~/.claude/principl ## Vocabulary - **chunk** — the unit of work, shipped as one PR; "Working loop" says what it holds. -- **cycle** — in `loop-claude`, worker runs and the judge's verdicts on them, with any interrupts and records answers in between, until the chunk closes or continues next cycle. +- **cycle** — in `loop-claude`, worker runs and the judge's verdicts on them, with any interrupts, and any answers the judge quoted from the project's records, in between, until the chunk closes or continues next cycle. - **gate** — the merge gate: the checks a PR passes before it merges. - **interrupt** — `loop-claude` handing the terminal to the human, `claude --resume`, for a decision that is theirs. - **judge** — the headless claude that reads a worker's transcript each cycle and decides whether to interrupt and whether the chunk is finished. diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index b44c125c..2eaa8860 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -10,8 +10,8 @@ from loop_claude.failure import Failure from loop_claude.limited import Limited from loop_claude.stop import Stop -# About 100,000 tokens, half a 200,000-token context; the largest session rendered here was 364,000 characters on 2026-10-03. -JUDGED_TRANSCRIPT_TAIL = 400000 +# At 3 to 4 characters a token, 100,000 to 133,000 tokens, which leaves a 200,000-token context room for the reply; the largest session rendered here was 364,000 characters on 2026-10-03. +JUDGE_PROMPT_CHARS = 400000 JUDGE_RULES = ( "Decide whether the agent has something open that the human, or README.md and the project's records, " @@ -88,20 +88,22 @@ def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str, 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}, which is not in the transcript" + (f", for the question: {verdict.question}" if isinstance(verdict, Interrupt | AnsweredFromRecords) else "")) + # An answer the records do not hold verbatim is dropped, and the question goes to the human. if isinstance(verdict, AnsweredFromRecords) and not grounded(verdict.answer, recorded): - return Failure(f"the judge answered {verdict.question!r} with {verdict.answer!r}, which README.md and the project's records do not hold") + return Interrupt(verdict.evidence, verdict.question) return verdict def judge_prompt(task: str, premises: str, records: str, rendered_transcript: str) -> str: - return ( + head = ( f"From README.md:\n{premises}\n\n" f"The project's records, its working rules and decisions:\n{records or 'none'}\n\n" f"The task an agent was given:\n{task}\n\n" - # The tail, where an interrupt or a finish lands; the session's transcript grows cycle over cycle. - f"What the agent did and said, what the human typed on [human] lines and what loop-claude told it on [loop] lines, latest last:\n{rendered_transcript[-JUDGED_TRANSCRIPT_TAIL:]}\n\n" - f"{JUDGE_RULES}" + "What the agent did and said, what the human typed on [human] lines and what loop-claude told it on [loop] lines, latest last:\n" ) + room = max(0, JUDGE_PROMPT_CHARS - len(head) - len(JUDGE_RULES) - 2) + # The tail, where an interrupt or a finish lands; the session's transcript grows cycle over cycle. + return f"{head}{rendered_transcript[max(0, len(rendered_transcript) - room):]}\n\n{JUDGE_RULES}" def verdict_from(output: object) -> Verdict | Failure: @@ -110,8 +112,6 @@ def verdict_from(output: object) -> Verdict | Failure: for name, kind in REPLY_TYPES.items(): if not isinstance(output.get(name), kind): return Failure(f"the judge's reply has no {name} of type {JSON_TYPES[kind]}") - if output["answer"].strip() and not output["interrupt"]: - return Failure("the judge answered without interrupting") # An interrupt outranks finished: the human answers before the chunk can close. if output["interrupt"]: if not output["question"].strip(): diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index 47c1e8a4..0c8d63e6 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -8,7 +8,7 @@ from loop_claude.cycle.interrupt import interrupt from loop_claude.cycle.judge import judge from loop_claude.cycle.retry import retried from loop_claude.cycle.states import Active, Archived, Closing, Ended, Event, HumanAnswered, Interrupting, Judging, Ruled, State, WorkerRan, Working, transition -from loop_claude.cycle.verdicts import Finished, Unfinished +from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Unfinished from loop_claude.cycle.worker import run_worker, worker_args from loop_claude.effects import Effects from loop_claude.failure import Failure @@ -52,8 +52,8 @@ def stopped(cycle: Cycle, stop: Stop, why: str) -> Stop: def step(cycle: Cycle, state: Active) -> Event | Stop: match state: - case Working(answer, _): - return work(cycle, answer) + case Working(answered, _): + return work(cycle, answered) case Judging(transcript_path, _): return rule(cycle, transcript_path) case Interrupting(transcript_path, question, _): @@ -64,9 +64,11 @@ def step(cycle: Cycle, state: Active) -> Event | Stop: typing.assert_never(state) -def work(cycle: Cycle, answer: str | None) -> WorkerRan | Stop: +def work(cycle: Cycle, answered: AnsweredFromRecords | None) -> WorkerRan | Stop: + if answered is not None: + print(f"\n=== the records answered: {answered.question} ===\n{answered.answer}", flush=True) # session_open runs inside the lambda: a failed attempt may have opened the session. - if stop := retried("worker", lambda: run_worker(cycle.root, worker_args(cycle.task, cycle.session, cycle.models.worker, session_open(cycle.session), answer), cycle.effects), cycle.effects): + if stop := retried("worker", lambda: run_worker(cycle.root, worker_args(cycle.task, cycle.session, cycle.models.worker, session_open(cycle.session), answered), cycle.effects), cycle.effects): return stop path = transcript_file(cycle.session) return WorkerRan(path) if path is not None else Stop(1, f"claude left no transcript for session {cycle.session.id}") diff --git a/bin/loop_claude/cycle/states.py b/bin/loop_claude/cycle/states.py index 7abb04e8..e0417c58 100644 --- a/bin/loop_claude/cycle/states.py +++ b/bin/loop_claude/cycle/states.py @@ -9,7 +9,7 @@ RECORDS_ANSWERS_PER_CYCLE = 3 @dataclasses.dataclass(frozen=True) class Working: """The worker runs, resumed with the records' answer when there is one.""" - answer: str | None = None + answered: AnsweredFromRecords | None = None records_answers: int = 0 @@ -69,10 +69,10 @@ def transition(state: State, event: Event) -> State: match state, event: case Working(_, records_answers), WorkerRan(transcript_path): return Judging(transcript_path, records_answers) - case Judging(_, records_answers), Ruled(AnsweredFromRecords(answer=answer)) if records_answers < RECORDS_ANSWERS_PER_CYCLE: - return Working(answer, records_answers + 1) + case Judging(_, records_answers), Ruled(AnsweredFromRecords() as answered) if records_answers < RECORDS_ANSWERS_PER_CYCLE: + return Working(answered, records_answers + 1) case Judging(transcript_path, records_answers), Ruled(AnsweredFromRecords(question=question, answer=answer)): - return Interrupting(transcript_path, f"{question}\n\nREADME.md or the project's records say:\n{answer}", records_answers) + return Interrupting(transcript_path, f"{question}\n\nREADME.md or the project's records say:\n{answer}\n\nThe records answered {records_answers} questions this cycle, so this one comes to you.", records_answers) case Judging(transcript_path, records_answers), Ruled(Interrupt(question=question)): return Interrupting(transcript_path, question, records_answers) case Judging(transcript_path, _), Ruled(Finished() | Unfinished() as verdict): diff --git a/bin/loop_claude/cycle/worker.py b/bin/loop_claude/cycle/worker.py index 27cfffab..d053fdd7 100644 --- a/bin/loop_claude/cycle/worker.py +++ b/bin/loop_claude/cycle/worker.py @@ -1,6 +1,7 @@ from loop_claude.claude_code.entries import assistant_parts, ends_stream, hit_limit, limit_said, parse_entry, rejected_until from loop_claude.claude_code.session import Session from loop_claude.claude_code.transcript import part_line +from loop_claude.cycle.verdicts import AnsweredFromRecords from loop_claude.effects import Effects from loop_claude.failure import Failure from loop_claude.limited import Limited @@ -37,10 +38,11 @@ def worker_outcome(code: int, result: dict | None, resets: list[int]) -> Failure return None if result is not None else Failure("claude exited 0 without a result event") -def worker_args(task: str, session: Session, model: str, resuming: bool, answer: str | None = None) -> list[str]: - if resuming: - prompt = f"README.md or the project's records answer your question:\n\n{answer}\n\nContinue the task." if answer is not None else "Continue the task; the previous run stopped before it was finished." - start = ["-p", prompt, "--resume", str(session.id)] +def worker_args(task: str, session: Session, model: str, resuming: bool, answered: AnsweredFromRecords | None = None) -> list[str]: + if answered is not None: + start = ["-p", f"Your question: {answered.question}\n\nREADME.md or the project's records answer it:\n\n{answered.answer}\n\nContinue the task.", "--resume", str(session.id)] + elif resuming: + start = ["-p", "Continue the task; the previous run stopped before it was finished.", "--resume", str(session.id)] else: start = ["-p", f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one.", "--name", session.name, "--session-id", str(session.id)] return [ diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 8d35e331..cbda1ea9 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -4,11 +4,12 @@ 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's last 400,000 characters against the premises and the project's records, AGENTS.md -and docs/decisions.md where they exist, and rules whether the chunk, the work of one PR, is finished. -A choice the worker made that the premises or the records settle is not asked about. When the worker -asks a question they answer, the judge quotes the answer and the worker resumes with it, up to three -times a cycle; a question asked again after its answer, or a fourth, goes to the human. +as much of the transcript's end as fits a 400,000-character prompt against the premises and the +project's records, AGENTS.md and docs/decisions.md where they exist, and rules whether the chunk, +the work of one PR, is finished. A choice the worker made that the premises or the records settle is +not asked about. When the worker asks a question they answer, the judge quotes the answer, printed +on stdout, and the worker resumes with it, up to three times a cycle; a question asked again after +its answer goes to the human, and a fourth with the quote. 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. @@ -50,9 +51,9 @@ Exit 1, saying why, when: - 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, answers without interrupting, quotes a line the transcript does - not hold, or quotes an answer the premises and the records do not hold. A usage limit is not a - failure, and restarts the count of three: the worker or the judge is retried 2 minutes + interrupts without a question, or quotes a line the transcript does not hold; an answer it + quotes that the premises and the records do not hold is dropped, and the question goes to the + human. A usage limit is not a failure, and restarts the count of three: the worker or the judge is retried 2 minutes after the limit resets, or every 10 minutes when the reset time is unknown or more than 2 minutes past. The judge's reply gives its reset time only as text, so the judge is always retried every 10 minutes. stderr says when the next try is due. diff --git a/bin/loop_claude/project/checkout.py b/bin/loop_claude/project/checkout.py index fb787d0b..de5f057d 100644 --- a/bin/loop_claude/project/checkout.py +++ b/bin/loop_claude/project/checkout.py @@ -36,4 +36,4 @@ def read_checkout_file(root: str, name: str, consequence: str) -> str | Stop: return Stop(1, f"{name} in {root}: {failure.strerror} - {consequence}.") except UnicodeDecodeError as failure: line = failure.object.count(b"\n", 0, failure.start) + 1 - return Stop(1, f"{name} is not UTF-8 on line {line} - {consequence}.") + return Stop(1, f"{name} in {root} is not UTF-8 on line {line} - {consequence}.") diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 5f5a3030..999afe79 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -130,12 +130,12 @@ class Transitions(unittest.TestCase): answered = states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")) legal = ( (states.Working(), states.WorkerRan("/t"), states.Judging("/t")), - (states.Working("A.", 3), states.WorkerRan("/t"), states.Judging("/t", 3)), + (states.Working(AnsweredFromRecords("e", "Which one?", "A."), 3), states.WorkerRan("/t"), states.Judging("/t", 3)), (states.Judging("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")), (states.Judging("/t", 3), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", 3)), - (states.Judging("/t"), answered, states.Working("A.", 1)), - (states.Judging("/t", 2), answered, states.Working("A.", 3)), - (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md or the project's records say:\nA.", 3)), + (states.Judging("/t"), answered, states.Working(AnsweredFromRecords("e", "Which one?", "A."), 1)), + (states.Judging("/t", 2), answered, states.Working(AnsweredFromRecords("e", "Which one?", "A."), 3)), + (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md or the project's records say:\nA.\n\nThe records answered 3 questions this cycle, so this one comes to you.", 3)), (states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t", 3), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), @@ -147,7 +147,7 @@ class Transitions(unittest.TestCase): for state, event, after in legal: with self.subTest(state=state, event=event): self.assertEqual(states.transition(state, event), after) - every_state = (states.Working(), states.Working("A.", 3), states.Judging("/t"), states.Judging("/t", 3), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", 3), states.Closing("/t", Finished("e")), states.Ended()) + every_state = (states.Working(), states.Working(AnsweredFromRecords("e", "Which one?", "A."), 3), states.Judging("/t"), states.Judging("/t", 3), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", 3), states.Closing("/t", Finished("e")), states.Ended()) every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), answered, states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanAnswered(), states.Archived()) for state in every_state: for event in every_event: @@ -247,18 +247,21 @@ class Cycles(unittest.TestCase): def test_a_question_the_records_answer_resumes_the_worker_with_the_answer_three_times_a_cycle(self): answered = judged("interrupt", answer="Use *A*.") fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 4, claude=[answered] * 4, on_terminal_claude=[0], git=[ran()]) - with contextlib.redirect_stderr(io.StringIO()) as said: + with contextlib.redirect_stderr(io.StringIO()) as said, contextlib.redirect_stdout(io.StringIO()) as printed: self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed")) resumed = fake.made("stream_claude")[1] - self.assertEqual(resumed[resumed.index("-p") + 1], "README.md or the project's records answer your question:\n\nUse *A*.\n\nContinue the task.") + self.assertEqual(resumed[resumed.index("-p") + 1], "Your question: Which one?\n\nREADME.md or the project's records answer it:\n\nUse *A*.\n\nContinue the task.") self.assertEqual(len(fake.made("stream_claude")), 4) - self.assertIn("Which one?\n\nREADME.md or the project's records say:\nUse *A*.", said.getvalue()) + self.assertEqual(printed.getvalue().count("=== the records answered: Which one? ===\nUse *A*."), 3) + self.assertIn("Which one?\n\nREADME.md or the project's records say:\nUse *A*.\n\nThe records answered 3 questions this cycle", said.getvalue()) - def test_the_judge_fails_on_an_answer_the_records_do_not_hold(self): - invented = judged("interrupt", answer="Use B.") - fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[invented] * 3) - with contextlib.redirect_stderr(io.StringIO()): - self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(1, "the judge failed three times running: the judge answered 'Which one?' with 'Use B.', which README.md and the project's records do not hold")) + def test_an_answer_the_records_do_not_hold_is_dropped_and_the_question_goes_to_the_human(self): + fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt", answer="Use B.")], on_terminal_claude=[0], git=[ran()]) + with contextlib.redirect_stderr(io.StringIO()) as said: + self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed")) + self.assertEqual(len(fake.made("stream_claude")), 1) + self.assertIn("\nWhich one?\n", said.getvalue()) + self.assertNotIn("Use B.", said.getvalue()) @unittest.skipIf(os.geteuid() == 0, "root writes into a read-only directory") def test_stops_keeping_the_transcript_when_the_finished_chunks_session_cannot_be_deleted(self): @@ -388,7 +391,7 @@ class Records(unittest.TestCase): pathlib.Path(root, "docs", "decisions.md").mkdir(parents=True) self.assertEqual(records.read_records(root), Stop(1, f"docs/decisions.md in {root}: Is a directory - the judge cannot read the project's records.")) pathlib.Path(root, "AGENTS.md").write_bytes(b"# Rules\n\xff\n") - self.assertEqual(records.read_records(root), Stop(1, "AGENTS.md is not UTF-8 on line 2 - the judge cannot read the project's records.")) + self.assertEqual(records.read_records(root), Stop(1, f"AGENTS.md in {root} is not UTF-8 on line 2 - the judge cannot read the project's records.")) class Sections(unittest.TestCase): @@ -500,7 +503,7 @@ class Verdict(unittest.TestCase): self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": "e", "finished": False, "question": "ignored"}), Unfinished("e")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "e", "finished": True, "question": "Which one?"}), Interrupt("e", "Which one?")) self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"}), AnsweredFromRecords("e", "Which one?", "A.")) - self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": False, "evidence": "e", "finished": False, "question": ""}), Failure("the judge answered without interrupting")) + self.assertEqual(judge.verdict_from({"answer": "ignored", "interrupt": False, "evidence": "e", "finished": False, "question": ""}), Unfinished("e")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": "no", "evidence": "", "finished": True, "question": ""}), Failure("the judge's reply has no interrupt of type boolean")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": None, "finished": True, "question": ""}), Failure("the judge's reply has no evidence of type string")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "x", "finished": False, "question": " "}), Failure("the judge interrupted without a question")) @@ -531,8 +534,8 @@ class LoopRuns(unittest.TestCase): class HelpLimits(unittest.TestCase): def test_help_states_the_limits_the_code_holds(self): - self.assertIn(f"last {judge.JUDGED_TRANSCRIPT_TAIL:,} characters", main.__doc__) - self.assertIn(f"up to {['one', 'two', 'three', 'four'][states.RECORDS_ANSWERS_PER_CYCLE - 1]}\ntimes a cycle", main.__doc__) + self.assertIn(f"a {judge.JUDGE_PROMPT_CHARS:,}-character prompt", main.__doc__) + self.assertIn(f"up to {['one', 'two', 'three', 'four'][states.RECORDS_ANSWERS_PER_CYCLE - 1]} times a cycle", main.__doc__) class ExitContract(unittest.TestCase): @@ -558,7 +561,7 @@ class ExitContract(unittest.TestCase): ("project/checkout.py", "checkout_root", "1", "f'could not start git:", git), ("project/checkout.py", "checkout_root", "1", "found.stderr.strip()", git), ("project/checkout.py", "read_checkout_file", "1", "f'{name} in {root}:", unreadable), - ("project/checkout.py", "read_checkout_file", "1", "f'{name} is not UTF-8", unreadable), + ("project/checkout.py", "read_checkout_file", "1", "f'{name} in {root} is not UTF-8", unreadable), ("project/model_choice.py", "get_or_ask_model", "1", "f'could not save the model in", models_), ("project/model_choice.py", "read_models_file", "1", 'f"could not read {saved}: {getattr(', models_), ("project/model_choice.py", "read_models_file", "1", "f'could not read {saved}: not an object", models_), diff --git a/bin/test_loop_claude_black_box.py b/bin/test_loop_claude_black_box.py index 58a7ca9a..8c9f0209 100644 --- a/bin/test_loop_claude_black_box.py +++ b/bin/test_loop_claude_black_box.py @@ -282,7 +282,7 @@ class Premises(unittest.TestCase): self.assertIn("not a git repository", run.stderr) readmes = { None: "README.md in {root}: No such file or directory - no premises.", - b"# P\n## Goals\n1. g\xff\n## Audience\nme\n": "README.md is not UTF-8 on line 3 - no premises.", + b"# P\n## Goals\n1. g\xff\n## Audience\nme\n": "README.md in {root} is not UTF-8 on line 3 - no premises.", b"# P\n## Audience\nme\n": "README.md has no ## Goals heading - no premises.", b"# P\n## Goals\n1. g\n": "README.md has no ## Audience heading - no premises.", b"# P\n## Goals\n\n## Audience\nme\n": "README.md has nothing under ## Goals - no premises.", @@ -433,7 +433,8 @@ class Cycles(unittest.TestCase): checkout = Checkout(self) run = checkout.run([worker(say="early " * 80000 + "LATE")]) self.assertIn("LATE", run.calls[1]["stdin"]) - self.assertEqual(run.calls[1]["stdin"].count("early"), (400000 - len("LATE")) // len("early ")) + self.assertEqual(len(run.calls[1]["stdin"]), 400000) + self.assertLess(run.calls[1]["stdin"].count("early"), 80000) self.assertTrue(run.calls[1]["stdin"].rstrip().endswith("an open PR, a review not yet run, CI not yet reported.")) def test_skips_a_malformed_transcript_or_stream_line(self): -- 2.52.0 From 80f1cc2dc976833c82f72dcb34a4a02c85c2e24e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 01:44:23 +0200 Subject: [PATCH 10/20] Answer the stability pass's second round: say why a misquote is no failure, rewrap --help --- bin/loop_claude/cycle/judge.py | 2 +- bin/loop_claude/loop/main.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index 2eaa8860..2d3f02af 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -88,7 +88,7 @@ def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str, 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}, which is not in the transcript" + (f", for the question: {verdict.question}" if isinstance(verdict, Interrupt | AnsweredFromRecords) else "")) - # An answer the records do not hold verbatim is dropped, and the question goes to the human. + # Not a Failure: a misquote would otherwise exit an unattended loop. if isinstance(verdict, AnsweredFromRecords) and not grounded(verdict.answer, recorded): return Interrupt(verdict.evidence, verdict.question) return verdict diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index cbda1ea9..1d13fdd5 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -51,11 +51,11 @@ Exit 1, saying why, when: - 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 a line the transcript does not hold; an answer it - quotes that the premises and the records do not hold is dropped, and the question goes to the - human. A usage limit is not a failure, and restarts the count of three: the worker or the judge is retried 2 minutes - after the limit resets, or every 10 minutes when the reset time is unknown or more than 2 - minutes past. The judge's reply gives its reset time only as text, so the judge is always + interrupts without a question, or quotes a line the transcript does not hold; an answer it quotes + that the premises and the records do not hold is dropped, and the question goes to the human. A + usage limit is not a failure, and restarts the count of three: the worker or the judge is retried + 2 minutes after the limit resets, or every 10 minutes when the reset time is unknown or more than + 2 minutes past. The judge's reply gives its reset time only as text, so the judge is always retried every 10 minutes. stderr says when the next try is due. Exit 2, when the human is needed and cannot answer: -- 2.52.0 From 0eb97e9e88f489558b48d9ac65343329c6659646 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 01:49:33 +0200 Subject: [PATCH 11/20] Answer the prose pass: name README.md beside the records, one idea per sentence in --help and the judge's rules, date the decision's revision --- AGENTS.md | 2 +- CHANGELOG.md | 4 ++-- CLAUDE.md | 2 +- bin/loop_claude/cycle/judge.py | 10 +++++----- bin/loop_claude/cycle/run.py | 2 +- bin/loop_claude/cycle/states.py | 8 ++++---- bin/loop_claude/loop/main.py | 26 +++++++++++++------------- bin/test_loop_claude.py | 9 ++++----- docs/decisions.md | 6 ++++-- 9 files changed, 35 insertions(+), 34 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 52e5174b..8c449c13 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -3,7 +3,7 @@ Decisions live in `docs/decisions.md`: - larv-review: a project under the comprehension floor is fixed at the capping dimension -- loop-claude: a judge decides each interrupt from the transcript, the README's premises and the project's records; the worker's own account of which goal settles a choice decides nothing +- loop-claude: a judge decides each interrupt and each quoted answer from the transcript, the README's premises, `AGENTS.md` and `docs/decisions.md`; the worker's own account of which goal settles a choice decides nothing - loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it - loop-claude: before an interrupt, it marks the checkout and each of its worktrees trusted in `~/.claude.json` - bin/: the tests rerun themselves on a `uv`-fetched Python at README Install's floor diff --git a/CHANGELOG.md b/CHANGELOG.md index 597fa3c3..a2026dd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,8 @@ ## Unreleased - Unless another Exempt reason fits, larv-review marks a `todo.md` item filed from a 🟡 finding against `~/.claude/principles/` with `principle`, an Exempt reason that keeps it whatever its score. -- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question they answer, the worker resumes with the judge's quote of the answer, which `loop-claude` prints, up to three times a cycle; a question asked again after its answer goes to you, and a fourth goes to you with the quote. A quote the records do not hold word for word is dropped, and the question goes to you. The judge reads as much of the transcript's end as fits a 400,000-character prompt, up from the last 40,000 characters. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. -- A project's decision log is `docs/decisions.md` alone, the one file the judge, `rank_todo.py` and the reviewers read; `CLAUDE.md` no longer allows splitting it into `docs/decisions/`. +- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question that the README or those files answer, the worker resumes with the judge's quote of the answer, which `loop-claude` prints. A quote they do not hold word for word is dropped, and the question goes to you. So does a question asked again after its answer, and the fourth question they answer in one cycle, with the quote. The judge reads as much of the transcript's end as fits a 400,000-character prompt, up from the last 40,000 characters. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. +- A project's decision log is `docs/decisions.md` alone, the one file the judge, `rank_todo.py` and the reviewers read. - `loop-claude` waits out a usage limit and retries: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. A limit is not a failure, and restarts the count of three failures in a row. It prints what claude said about the limit and when the next try is due. - Add the official plugin marketplace and install every plugin `settings.json` enables (README → Install): `claude-security`, `code-review` and `rust-analyzer-lsp`, which needs `rust-analyzer` on `PATH` for Rust projects. With `claude-security`, larv-review's full security scan runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. - systems-architect and product-owner-reviewer can no longer edit what they review; stability-reviewer keeps its shell to run tests, and loses Claude Code's file-editing tools. diff --git a/CLAUDE.md b/CLAUDE.md index fb771bd5..47a333e9 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -151,7 +151,7 @@ The rules every project follows, compose-not-entangle first: `~/.claude/principl ## Vocabulary - **chunk** — the unit of work, shipped as one PR; "Working loop" says what it holds. -- **cycle** — in `loop-claude`, worker runs and the judge's verdicts on them, with any interrupts, and any answers the judge quoted from the project's records, in between, until the chunk closes or continues next cycle. +- **cycle** — in `loop-claude`, worker runs and the judge's verdict on each, until the chunk closes or is left for the next cycle. In between, the human answers any interrupt, or the worker resumes with an answer the judge quoted from `README.md`, `AGENTS.md` or `docs/decisions.md`. - **gate** — the merge gate: the checks a PR passes before it merges. - **interrupt** — `loop-claude` handing the terminal to the human, `claude --resume`, for a decision that is theirs. - **judge** — the headless claude that reads a worker's transcript each cycle and decides whether to interrupt and whether the chunk is finished. diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index 2d3f02af..c1fd0a12 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -14,8 +14,8 @@ from loop_claude.stop import Stop JUDGE_PROMPT_CHARS = 400000 JUDGE_RULES = ( - "Decide whether the agent has something open that the human, or README.md and the project's records, " - "must answer. interrupt=true when any of these appear:\n" + "Decide whether the agent has something open that the human must answer, or that README.md or the " + "project's records answer. interrupt=true when any of these appear:\n" "- the agent asks the human anything, seeks approval, or says a decision is the human's\n" "- it carried on under an assumption that decides the deliverable, that the human could " "reasonably reject and that neither README.md nor the project's records settle; a caveat about " @@ -28,12 +28,12 @@ JUDGE_RULES = ( "interrupt=false otherwise. Bookkeeping the agent settled silently - what to document, wording, " "where a note goes - is not on its own a reason to interrupt. The human may have replied inside the transcript, on a [human] line: judge only what " "is still open, never a question they already answered there. A [loop] line is what loop-claude told " - "the agent, such as an answer quoted from README.md or the project's records; a question it answered " - "is no longer open, unless the agent asks it again: then it is the human's, with answer empty.\n" + "the agent, such as an answer quoted from README.md or the project's records. A question a [loop] " + "line answered is no longer open. If the agent asks it again, put it to the human, with answer empty.\n" "Where the agent asked or flagged something itself, the question is that one, in the agent's own " "wording; never construct another from facts it stated.\n" "Where README.md or the project's records answer that question, quote the passage that answers it " - "in answer, verbatim; the agent is then given that passage in place of the human's reply.\n" + "in answer, verbatim, with interrupt=true; the agent is then given that passage in place of the human's reply.\n" "finished=true when the chunk is complete: merged, or nothing remains that the agent could do on " "its own. finished=false when work remains that a further run can continue: an open PR, a review " "not yet run, CI not yet reported." diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index 0c8d63e6..d2a49450 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -66,7 +66,7 @@ def step(cycle: Cycle, state: Active) -> Event | Stop: def work(cycle: Cycle, answered: AnsweredFromRecords | None) -> WorkerRan | Stop: if answered is not None: - print(f"\n=== the records answered: {answered.question} ===\n{answered.answer}", flush=True) + print(f"\n=== README.md or the records answered: {answered.question} ===\n{answered.answer}", flush=True) # session_open runs inside the lambda: a failed attempt may have opened the session. if stop := retried("worker", lambda: run_worker(cycle.root, worker_args(cycle.task, cycle.session, cycle.models.worker, session_open(cycle.session), answered), cycle.effects), cycle.effects): return stop diff --git a/bin/loop_claude/cycle/states.py b/bin/loop_claude/cycle/states.py index e0417c58..d0d60729 100644 --- a/bin/loop_claude/cycle/states.py +++ b/bin/loop_claude/cycle/states.py @@ -2,20 +2,20 @@ import dataclasses from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished, Verdict -# A backstop for what the judge misses, such as a reworded repeat, so the worker cannot loop unattended on the records' answers. +# A backstop for what the judge misses, such as a reworded repeat, so the worker cannot loop unattended on answers quoted from README.md or the records. RECORDS_ANSWERS_PER_CYCLE = 3 @dataclasses.dataclass(frozen=True) class Working: - """The worker runs, resumed with the records' answer when there is one.""" + """The worker runs, resumed with an answer quoted from README.md or the records when there is one.""" answered: AnsweredFromRecords | None = None records_answers: int = 0 @dataclasses.dataclass(frozen=True) class Judging: - """The judge rules; records_answers counts the questions the records answered this cycle.""" + """The judge rules; records_answers counts the questions README.md or the records answered this cycle.""" transcript_path: str records_answers: int = 0 @@ -72,7 +72,7 @@ def transition(state: State, event: Event) -> State: case Judging(_, records_answers), Ruled(AnsweredFromRecords() as answered) if records_answers < RECORDS_ANSWERS_PER_CYCLE: return Working(answered, records_answers + 1) case Judging(transcript_path, records_answers), Ruled(AnsweredFromRecords(question=question, answer=answer)): - return Interrupting(transcript_path, f"{question}\n\nREADME.md or the project's records say:\n{answer}\n\nThe records answered {records_answers} questions this cycle, so this one comes to you.", records_answers) + return Interrupting(transcript_path, f"{question}\n\nREADME.md or the project's records say:\n{answer}\n\nREADME.md or the records answered {records_answers} questions this cycle, so this one comes to you.", records_answers) case Judging(transcript_path, records_answers), Ruled(Interrupt(question=question)): return Interrupting(transcript_path, question, records_answers) case Judging(transcript_path, _), Ruled(Finished() | Unfinished() as verdict): diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 1d13fdd5..afa8a7a2 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -3,13 +3,14 @@ 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 -as much of the transcript's end as fits a 400,000-character prompt against the premises and the -project's records, AGENTS.md and docs/decisions.md where they exist, and rules whether the chunk, -the work of one PR, is finished. A choice the worker made that the premises or the records settle is -not asked about. When the worker asks a question they answer, the judge quotes the answer, printed -on stdout, and the worker resumes with it, up to three times a cycle; a question asked again after -its answer goes to the human, and a fourth with the quote. +premises; the task runs at the checkout root. Each cycle a worker runs the task. A judge then reads +the transcript's end, the premises, and the project's records: AGENTS.md and docs/decisions.md, +where they exist. It rules whether the chunk, the work of one PR, is finished. A choice the worker +made that the premises or the records settle is not asked about. When the worker asks a question +they answer, the judge quotes the answer, loop-claude prints it, and the worker resumes with it. A +quote they do not hold word for word is dropped, and the question goes to the human. So does a +question asked again after its answer, and the fourth question they answer in one cycle, with the +quote. 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. @@ -51,12 +52,11 @@ Exit 1, saying why, when: - 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 a line the transcript does not hold; an answer it quotes - that the premises and the records do not hold is dropped, and the question goes to the human. A - usage limit is not a failure, and restarts the count of three: the worker or the judge is retried - 2 minutes after the limit resets, or every 10 minutes when the reset time is unknown or more than - 2 minutes past. The judge's reply gives its reset time only as text, so the judge is always - retried every 10 minutes. stderr says when the next try is due. + interrupts without a question, or quotes a line the transcript does not hold. A usage limit is not + a failure, and restarts the count of three: the worker or the judge is retried 2 minutes after the + limit resets, or every 10 minutes when the reset time is unknown or more than 2 minutes past. The + judge's reply gives its reset time only as text, so the judge is always retried every 10 minutes. + stderr says when the next try is due. 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 diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 999afe79..c5c0a0c2 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -135,7 +135,7 @@ class Transitions(unittest.TestCase): (states.Judging("/t", 3), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", 3)), (states.Judging("/t"), answered, states.Working(AnsweredFromRecords("e", "Which one?", "A."), 1)), (states.Judging("/t", 2), answered, states.Working(AnsweredFromRecords("e", "Which one?", "A."), 3)), - (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md or the project's records say:\nA.\n\nThe records answered 3 questions this cycle, so this one comes to you.", 3)), + (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md or the project's records say:\nA.\n\nREADME.md or the records answered 3 questions this cycle, so this one comes to you.", 3)), (states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t", 3), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), @@ -252,8 +252,8 @@ class Cycles(unittest.TestCase): resumed = fake.made("stream_claude")[1] self.assertEqual(resumed[resumed.index("-p") + 1], "Your question: Which one?\n\nREADME.md or the project's records answer it:\n\nUse *A*.\n\nContinue the task.") self.assertEqual(len(fake.made("stream_claude")), 4) - self.assertEqual(printed.getvalue().count("=== the records answered: Which one? ===\nUse *A*."), 3) - self.assertIn("Which one?\n\nREADME.md or the project's records say:\nUse *A*.\n\nThe records answered 3 questions this cycle", said.getvalue()) + self.assertEqual(printed.getvalue().count("=== README.md or the records answered: Which one? ===\nUse *A*."), 3) + self.assertIn("Which one?\n\nREADME.md or the project's records say:\nUse *A*.\n\nREADME.md or the records answered 3 questions this cycle", said.getvalue()) def test_an_answer_the_records_do_not_hold_is_dropped_and_the_question_goes_to_the_human(self): fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt", answer="Use B.")], on_terminal_claude=[0], git=[ran()]) @@ -534,8 +534,7 @@ class LoopRuns(unittest.TestCase): class HelpLimits(unittest.TestCase): def test_help_states_the_limits_the_code_holds(self): - self.assertIn(f"a {judge.JUDGE_PROMPT_CHARS:,}-character prompt", main.__doc__) - self.assertIn(f"up to {['one', 'two', 'three', 'four'][states.RECORDS_ANSWERS_PER_CYCLE - 1]} times a cycle", main.__doc__) + self.assertIn(f"the {['second', 'third', 'fourth', 'fifth'][states.RECORDS_ANSWERS_PER_CYCLE - 1]} question they answer in one cycle", main.__doc__.replace("\n", " ")) class ExitContract(unittest.TestCase): diff --git a/docs/decisions.md b/docs/decisions.md index 16ea9c1a..7eafd6b7 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -4,9 +4,11 @@ 2026-09-20, lilleman. Serves goal 4. Across six projects scored with the four seats, Locality or Self-sufficiency capped every seat and Navigation capped none, so a layout fix would not lift a project under the floor. Valid while the scoring run keeps those four seats. -## loop-claude: a judge decides each interrupt from the transcript, the README's premises and the project's records; the worker's own account of which goal settles a choice decides nothing +## loop-claude: a judge decides each interrupt and each quoted answer from the transcript, the README's premises, `AGENTS.md` and `docs/decisions.md`; the worker's own account of which goal settles a choice decides nothing -2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). A question the worker asks that the records answer is answered by the judge's verbatim quote of them, which the judge then sees as a `[loop]` line; the worker asking it again shows the record did not settle it, and the judge sends it to the human. A backstop of three records answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so it cannot loop unattended (goal 4.4); a fourth goes to the human with the judge's quote, so the cost is one interrupt. Valid while the worker's self-report stays unreliable. +2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. Valid while the worker's self-report stays unreliable. + +2026-10-01, lilleman: the judge reads `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); its bar becomes whether the README or those files discriminate. 2026-10-03, implemented: a question the worker asks that they answer is answered by the judge's verbatim quote, which the judge then sees as a `[loop]` line. The worker asking it again shows the quote did not settle it, and the judge sends it to the human. A backstop of three quoted answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so the worker cannot loop unattended (goal 4.4); the fourth question they answer in one cycle goes to the human with the judge's quote, so the cost is one interrupt. ## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it -- 2.52.0 From 03cccd24f4a272b3f5fe9b681df03df2e30d7e82 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 01:51:47 +0200 Subject: [PATCH 12/20] Answer the prose pass's second round: the quote goes with the fourth question only, name the three files the human sees --- CHANGELOG.md | 2 +- bin/loop_claude/cycle/run.py | 2 +- bin/loop_claude/cycle/states.py | 2 +- bin/loop_claude/loop/main.py | 4 ++-- bin/test_loop_claude.py | 6 +++--- docs/decisions.md | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2026dd5..d8173855 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Unreleased - Unless another Exempt reason fits, larv-review marks a `todo.md` item filed from a 🟡 finding against `~/.claude/principles/` with `principle`, an Exempt reason that keeps it whatever its score. -- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question that the README or those files answer, the worker resumes with the judge's quote of the answer, which `loop-claude` prints. A quote they do not hold word for word is dropped, and the question goes to you. So does a question asked again after its answer, and the fourth question they answer in one cycle, with the quote. The judge reads as much of the transcript's end as fits a 400,000-character prompt, up from the last 40,000 characters. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. +- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question that the README or those files answer, the worker resumes with the judge's quote of the answer, which `loop-claude` prints. A quote they do not hold word for word is dropped, and the question goes to you. So does a question asked again after its answer. The fourth question they answer in one cycle goes to you too, with the quote. The judge reads as much of the transcript's end as fits a 400,000-character prompt, up from the last 40,000 characters. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. - A project's decision log is `docs/decisions.md` alone, the one file the judge, `rank_todo.py` and the reviewers read. - `loop-claude` waits out a usage limit and retries: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. A limit is not a failure, and restarts the count of three failures in a row. It prints what claude said about the limit and when the next try is due. - Add the official plugin marketplace and install every plugin `settings.json` enables (README → Install): `claude-security`, `code-review` and `rust-analyzer-lsp`, which needs `rust-analyzer` on `PATH` for Rust projects. With `claude-security`, larv-review's full security scan runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index d2a49450..69987cfc 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -66,7 +66,7 @@ def step(cycle: Cycle, state: Active) -> Event | Stop: def work(cycle: Cycle, answered: AnsweredFromRecords | None) -> WorkerRan | Stop: if answered is not None: - print(f"\n=== README.md or the records answered: {answered.question} ===\n{answered.answer}", flush=True) + print(f"\n=== README.md, AGENTS.md or docs/decisions.md answered: {answered.question} ===\n{answered.answer}", flush=True) # session_open runs inside the lambda: a failed attempt may have opened the session. if stop := retried("worker", lambda: run_worker(cycle.root, worker_args(cycle.task, cycle.session, cycle.models.worker, session_open(cycle.session), answered), cycle.effects), cycle.effects): return stop diff --git a/bin/loop_claude/cycle/states.py b/bin/loop_claude/cycle/states.py index d0d60729..2d5acca0 100644 --- a/bin/loop_claude/cycle/states.py +++ b/bin/loop_claude/cycle/states.py @@ -72,7 +72,7 @@ def transition(state: State, event: Event) -> State: case Judging(_, records_answers), Ruled(AnsweredFromRecords() as answered) if records_answers < RECORDS_ANSWERS_PER_CYCLE: return Working(answered, records_answers + 1) case Judging(transcript_path, records_answers), Ruled(AnsweredFromRecords(question=question, answer=answer)): - return Interrupting(transcript_path, f"{question}\n\nREADME.md or the project's records say:\n{answer}\n\nREADME.md or the records answered {records_answers} questions this cycle, so this one comes to you.", records_answers) + return Interrupting(transcript_path, f"{question}\n\nREADME.md, AGENTS.md or docs/decisions.md say:\n{answer}\n\nREADME.md, AGENTS.md or docs/decisions.md answered {records_answers} questions this cycle, so this one comes to you.", records_answers) case Judging(transcript_path, records_answers), Ruled(Interrupt(question=question)): return Interrupting(transcript_path, question, records_answers) case Judging(transcript_path, _), Ruled(Finished() | Unfinished() as verdict): diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index afa8a7a2..fe2dcfb5 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -9,8 +9,8 @@ where they exist. It rules whether the chunk, the work of one PR, is finished. A made that the premises or the records settle is not asked about. When the worker asks a question they answer, the judge quotes the answer, loop-claude prints it, and the worker resumes with it. A quote they do not hold word for word is dropped, and the question goes to the human. So does a -question asked again after its answer, and the fourth question they answer in one cycle, with the -quote. +question asked again after its answer. The fourth question they answer in one cycle goes to the +human too, with the quote. 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. diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index c5c0a0c2..2e0a827e 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -135,7 +135,7 @@ class Transitions(unittest.TestCase): (states.Judging("/t", 3), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", 3)), (states.Judging("/t"), answered, states.Working(AnsweredFromRecords("e", "Which one?", "A."), 1)), (states.Judging("/t", 2), answered, states.Working(AnsweredFromRecords("e", "Which one?", "A."), 3)), - (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md or the project's records say:\nA.\n\nREADME.md or the records answered 3 questions this cycle, so this one comes to you.", 3)), + (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md say:\nA.\n\nREADME.md, AGENTS.md or docs/decisions.md answered 3 questions this cycle, so this one comes to you.", 3)), (states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t", 3), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), @@ -252,8 +252,8 @@ class Cycles(unittest.TestCase): resumed = fake.made("stream_claude")[1] self.assertEqual(resumed[resumed.index("-p") + 1], "Your question: Which one?\n\nREADME.md or the project's records answer it:\n\nUse *A*.\n\nContinue the task.") self.assertEqual(len(fake.made("stream_claude")), 4) - self.assertEqual(printed.getvalue().count("=== README.md or the records answered: Which one? ===\nUse *A*."), 3) - self.assertIn("Which one?\n\nREADME.md or the project's records say:\nUse *A*.\n\nREADME.md or the records answered 3 questions this cycle", said.getvalue()) + self.assertEqual(printed.getvalue().count("=== README.md, AGENTS.md or docs/decisions.md answered: Which one? ===\nUse *A*."), 3) + self.assertIn("Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md say:\nUse *A*.\n\nREADME.md, AGENTS.md or docs/decisions.md answered 3 questions this cycle", said.getvalue()) def test_an_answer_the_records_do_not_hold_is_dropped_and_the_question_goes_to_the_human(self): fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt", answer="Use B.")], on_terminal_claude=[0], git=[ran()]) diff --git a/docs/decisions.md b/docs/decisions.md index 7eafd6b7..2cab55bd 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -8,7 +8,7 @@ 2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. Valid while the worker's self-report stays unreliable. -2026-10-01, lilleman: the judge reads `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); its bar becomes whether the README or those files discriminate. 2026-10-03, implemented: a question the worker asks that they answer is answered by the judge's verbatim quote, which the judge then sees as a `[loop]` line. The worker asking it again shows the quote did not settle it, and the judge sends it to the human. A backstop of three quoted answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so the worker cannot loop unattended (goal 4.4); the fourth question they answer in one cycle goes to the human with the judge's quote, so the cost is one interrupt. +2026-10-01, lilleman: the judge reads `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); its bar becomes whether the README or those files discriminate. 2026-10-03, implemented: when README.md or those files answer the worker's question, the judge quotes the answer verbatim and the worker resumes with it. The judge then sees the quote as a `[loop]` line. The worker asking it again shows the quote did not settle it, and the judge sends it to the human. A backstop of three quoted answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so the worker cannot loop unattended (goal 4.4); the fourth question they answer in one cycle goes to the human with the judge's quote, so the cost is one interrupt. ## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it -- 2.52.0 From 45b4030347c14bf55caf2b64545972b8957825d2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 01:52:34 +0200 Subject: [PATCH 13/20] Match the help-limits test to the reworded sentence --- bin/test_loop_claude.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 2e0a827e..5b697322 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -534,7 +534,7 @@ class LoopRuns(unittest.TestCase): class HelpLimits(unittest.TestCase): def test_help_states_the_limits_the_code_holds(self): - self.assertIn(f"the {['second', 'third', 'fourth', 'fifth'][states.RECORDS_ANSWERS_PER_CYCLE - 1]} question they answer in one cycle", main.__doc__.replace("\n", " ")) + self.assertIn(f"The {['second', 'third', 'fourth', 'fifth'][states.RECORDS_ANSWERS_PER_CYCLE - 1]} question they answer in one cycle", main.__doc__.replace("\n", " ")) class ExitContract(unittest.TestCase): -- 2.52.0 From fdc3bc38d4c0ebbe0b887bedf3d953d27b58e217 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 01:53:58 +0200 Subject: [PATCH 14/20] Answer the prose pass's third round: name the three files in the worker's prompt, say They once named --- bin/loop_claude/cycle/states.py | 2 +- bin/loop_claude/cycle/worker.py | 2 +- bin/test_loop_claude.py | 6 +++--- docs/decisions.md | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/loop_claude/cycle/states.py b/bin/loop_claude/cycle/states.py index 2d5acca0..33d13d74 100644 --- a/bin/loop_claude/cycle/states.py +++ b/bin/loop_claude/cycle/states.py @@ -72,7 +72,7 @@ def transition(state: State, event: Event) -> State: case Judging(_, records_answers), Ruled(AnsweredFromRecords() as answered) if records_answers < RECORDS_ANSWERS_PER_CYCLE: return Working(answered, records_answers + 1) case Judging(transcript_path, records_answers), Ruled(AnsweredFromRecords(question=question, answer=answer)): - return Interrupting(transcript_path, f"{question}\n\nREADME.md, AGENTS.md or docs/decisions.md say:\n{answer}\n\nREADME.md, AGENTS.md or docs/decisions.md answered {records_answers} questions this cycle, so this one comes to you.", records_answers) + return Interrupting(transcript_path, f"{question}\n\nREADME.md, AGENTS.md or docs/decisions.md say:\n{answer}\n\nThey answered {records_answers} questions this cycle, so this one comes to you.", records_answers) case Judging(transcript_path, records_answers), Ruled(Interrupt(question=question)): return Interrupting(transcript_path, question, records_answers) case Judging(transcript_path, _), Ruled(Finished() | Unfinished() as verdict): diff --git a/bin/loop_claude/cycle/worker.py b/bin/loop_claude/cycle/worker.py index d053fdd7..eb433a3c 100644 --- a/bin/loop_claude/cycle/worker.py +++ b/bin/loop_claude/cycle/worker.py @@ -40,7 +40,7 @@ def worker_outcome(code: int, result: dict | None, resets: list[int]) -> Failure def worker_args(task: str, session: Session, model: str, resuming: bool, answered: AnsweredFromRecords | None = None) -> list[str]: if answered is not None: - start = ["-p", f"Your question: {answered.question}\n\nREADME.md or the project's records answer it:\n\n{answered.answer}\n\nContinue the task.", "--resume", str(session.id)] + start = ["-p", f"Your question: {answered.question}\n\nREADME.md, AGENTS.md or docs/decisions.md answer it:\n\n{answered.answer}\n\nContinue the task.", "--resume", str(session.id)] elif resuming: start = ["-p", "Continue the task; the previous run stopped before it was finished.", "--resume", str(session.id)] else: diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 5b697322..66c3dfd0 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -135,7 +135,7 @@ class Transitions(unittest.TestCase): (states.Judging("/t", 3), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", 3)), (states.Judging("/t"), answered, states.Working(AnsweredFromRecords("e", "Which one?", "A."), 1)), (states.Judging("/t", 2), answered, states.Working(AnsweredFromRecords("e", "Which one?", "A."), 3)), - (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md say:\nA.\n\nREADME.md, AGENTS.md or docs/decisions.md answered 3 questions this cycle, so this one comes to you.", 3)), + (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md say:\nA.\n\nThey answered 3 questions this cycle, so this one comes to you.", 3)), (states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t", 3), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), @@ -250,10 +250,10 @@ class Cycles(unittest.TestCase): with contextlib.redirect_stderr(io.StringIO()) as said, contextlib.redirect_stdout(io.StringIO()) as printed: self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed")) resumed = fake.made("stream_claude")[1] - self.assertEqual(resumed[resumed.index("-p") + 1], "Your question: Which one?\n\nREADME.md or the project's records answer it:\n\nUse *A*.\n\nContinue the task.") + self.assertEqual(resumed[resumed.index("-p") + 1], "Your question: Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md answer it:\n\nUse *A*.\n\nContinue the task.") self.assertEqual(len(fake.made("stream_claude")), 4) self.assertEqual(printed.getvalue().count("=== README.md, AGENTS.md or docs/decisions.md answered: Which one? ===\nUse *A*."), 3) - self.assertIn("Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md say:\nUse *A*.\n\nREADME.md, AGENTS.md or docs/decisions.md answered 3 questions this cycle", said.getvalue()) + self.assertIn("Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md say:\nUse *A*.\n\nThey answered 3 questions this cycle", said.getvalue()) def test_an_answer_the_records_do_not_hold_is_dropped_and_the_question_goes_to_the_human(self): fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt", answer="Use B.")], on_terminal_claude=[0], git=[ran()]) diff --git a/docs/decisions.md b/docs/decisions.md index 2cab55bd..f092b43c 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -8,7 +8,7 @@ 2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. Valid while the worker's self-report stays unreliable. -2026-10-01, lilleman: the judge reads `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); its bar becomes whether the README or those files discriminate. 2026-10-03, implemented: when README.md or those files answer the worker's question, the judge quotes the answer verbatim and the worker resumes with it. The judge then sees the quote as a `[loop]` line. The worker asking it again shows the quote did not settle it, and the judge sends it to the human. A backstop of three quoted answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so the worker cannot loop unattended (goal 4.4); the fourth question they answer in one cycle goes to the human with the judge's quote, so the cost is one interrupt. +2026-10-01, lilleman: the judge reads `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); its bar becomes whether the README or those files discriminate. 2026-10-03, implemented: when README.md or those files answer the worker's question, the judge quotes the answer verbatim and the worker resumes with it. The judge then sees the quote as a `[loop]` line. The worker asking it again shows the quote did not settle it, and the judge sends it to the human. A backstop of three quoted answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so the worker cannot loop unattended (goal 4.4); the fourth question README.md or those files answer in one cycle goes to the human with the judge's quote, so the cost is one interrupt. ## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it -- 2.52.0 From 2d46aa3b8f49881ea4b89eec349bd3aa3984ba41 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 11:33:34 +0200 Subject: [PATCH 15/20] Fix under the floor's Shape: interrupt means only the human, QuotedAnswer names the verdict, one owner for the record files, Limited beside its cycle --- bin/loop_claude/cycle/judge.py | 31 ++++++++++++----------- bin/loop_claude/{ => cycle}/limited.py | 0 bin/loop_claude/cycle/retry.py | 2 +- bin/loop_claude/cycle/run.py | 7 +++--- bin/loop_claude/cycle/states.py | 35 +++++++++++++------------- bin/loop_claude/cycle/verdicts.py | 4 +-- bin/loop_claude/cycle/worker.py | 9 ++++--- bin/loop_claude/project/records.py | 6 ++++- bin/test_loop_claude.py | 31 ++++++++++++----------- docs/decisions.md | 2 +- 10 files changed, 68 insertions(+), 59 deletions(-) rename bin/loop_claude/{ => cycle}/limited.py (100%) diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index c1fd0a12..abe5d68d 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -3,20 +3,20 @@ import json import typing from loop_claude.claude_code.entries import hit_limit, limit_said, parse_entry, structured_output +from loop_claude.cycle.limited import Limited from loop_claude.cycle.retry import retried -from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished, Verdict +from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict from loop_claude.effects import Effects from loop_claude.failure import Failure -from loop_claude.limited import Limited from loop_claude.stop import Stop # At 3 to 4 characters a token, 100,000 to 133,000 tokens, which leaves a 200,000-token context room for the reply; the largest session rendered here was 364,000 characters on 2026-10-03. JUDGE_PROMPT_CHARS = 400000 JUDGE_RULES = ( - "Decide whether the agent has something open that the human must answer, or that README.md or the " - "project's records answer. interrupt=true when any of these appear:\n" - "- the agent asks the human anything, seeks approval, or says a decision is the human's\n" + "Decide whether the human must now be interrupted. interrupt=true when any of these appear:\n" + "- the agent asks the human anything, seeks approval, or says a decision is the human's, and neither " + "README.md nor the project's records answer it\n" "- it carried on under an assumption that decides the deliverable, that the human could " "reasonably reject and that neither README.md nor the project's records settle; a caveat about " "transient state it then handled is not one\n" @@ -29,11 +29,12 @@ JUDGE_RULES = ( "where a note goes - is not on its own a reason to interrupt. The human may have replied inside the transcript, on a [human] line: judge only what " "is still open, never a question they already answered there. A [loop] line is what loop-claude told " "the agent, such as an answer quoted from README.md or the project's records. A question a [loop] " - "line answered is no longer open. If the agent asks it again, put it to the human, with answer empty.\n" + "line answered is no longer open. If the agent asks it again, interrupt with that question.\n" "Where the agent asked or flagged something itself, the question is that one, in the agent's own " "wording; never construct another from facts it stated.\n" - "Where README.md or the project's records answer that question, quote the passage that answers it " - "in answer, verbatim, with interrupt=true; the agent is then given that passage in place of the human's reply.\n" + "Where README.md or the project's records answer the agent's own question, set interrupt=false, put " + "that question in question and quote the passage that answers it in answer, verbatim; the agent is " + "then given that passage in place of the human's reply.\n" "finished=true when the chunk is complete: merged, or nothing remains that the agent could do on " "its own. finished=false when work remains that a further run can continue: an open PR, a review " "not yet run, CI not yet reported." @@ -41,11 +42,11 @@ JUDGE_RULES = ( @dataclasses.dataclass(frozen=True) class Reply: - answer: str = dataclasses.field(metadata={"description": "The passage of README.md or the project's records that answers the agent's question, quoted verbatim. Empty when nothing there answers it, or when interrupt is false."}) + answer: str = dataclasses.field(metadata={"description": "With interrupt false, the passage of README.md or the project's records that answers the agent's question, quoted verbatim. Empty otherwise."}) evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the transcript line the verdict rests on: what triggers the interrupt, else what shows the chunk finished or the work remaining."}) finished: bool interrupt: bool - question: str = dataclasses.field(metadata={"description": "The single question to put to the human. Empty when interrupt is false."}) + question: str = dataclasses.field(metadata={"description": "The single question to put to the human, or the agent's question that answer answers. Empty otherwise."}) REPLY_TYPES = typing.get_type_hints(Reply) @@ -87,9 +88,9 @@ 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}, which is not in the transcript" + (f", for the question: {verdict.question}" if isinstance(verdict, Interrupt | AnsweredFromRecords) 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 | QuotedAnswer) else "")) # Not a Failure: a misquote would otherwise exit an unattended loop. - if isinstance(verdict, AnsweredFromRecords) and not grounded(verdict.answer, recorded): + if isinstance(verdict, QuotedAnswer) and not grounded(verdict.answer, recorded): return Interrupt(verdict.evidence, verdict.question) return verdict @@ -112,13 +113,13 @@ def verdict_from(output: object) -> Verdict | Failure: for name, kind in REPLY_TYPES.items(): if not isinstance(output.get(name), kind): return Failure(f"the judge's reply has no {name} of type {JSON_TYPES[kind]}") - # An interrupt outranks finished: the human answers before the chunk can close. + # An interrupt outranks a quoted answer and finished: the human answers before the chunk can close. if output["interrupt"]: if not output["question"].strip(): return Failure("the judge interrupted without a question") - if output["answer"].strip(): - return AnsweredFromRecords(output["evidence"], output["question"], output["answer"]) return Interrupt(output["evidence"], output["question"]) + if output["answer"].strip() and output["question"].strip(): + return QuotedAnswer(output["evidence"], output["question"], output["answer"]) return Finished(output["evidence"]) if output["finished"] else Unfinished(output["evidence"]) diff --git a/bin/loop_claude/limited.py b/bin/loop_claude/cycle/limited.py similarity index 100% rename from bin/loop_claude/limited.py rename to bin/loop_claude/cycle/limited.py diff --git a/bin/loop_claude/cycle/retry.py b/bin/loop_claude/cycle/retry.py index 571df431..f4be7406 100644 --- a/bin/loop_claude/cycle/retry.py +++ b/bin/loop_claude/cycle/retry.py @@ -1,9 +1,9 @@ import sys import typing +from loop_claude.cycle.limited import Limited from loop_claude.effects import Effects from loop_claude.failure import Failure -from loop_claude.limited import Limited from loop_claude.stop import Stop T = typing.TypeVar("T") diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index 69987cfc..413a04c8 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -8,12 +8,13 @@ from loop_claude.cycle.interrupt import interrupt from loop_claude.cycle.judge import judge from loop_claude.cycle.retry import retried from loop_claude.cycle.states import Active, Archived, Closing, Ended, Event, HumanAnswered, Interrupting, Judging, Ruled, State, WorkerRan, Working, transition -from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Unfinished +from loop_claude.cycle.verdicts import Finished, QuotedAnswer, Unfinished from loop_claude.cycle.worker import run_worker, worker_args from loop_claude.effects import Effects from loop_claude.failure import Failure from loop_claude.paths import Paths from loop_claude.project.model_choice import Models +from loop_claude.project.records import QUOTE_SOURCES from loop_claude.stop import Stop @@ -64,9 +65,9 @@ def step(cycle: Cycle, state: Active) -> Event | Stop: typing.assert_never(state) -def work(cycle: Cycle, answered: AnsweredFromRecords | None) -> WorkerRan | Stop: +def work(cycle: Cycle, answered: QuotedAnswer | None) -> WorkerRan | Stop: if answered is not None: - print(f"\n=== README.md, AGENTS.md or docs/decisions.md answered: {answered.question} ===\n{answered.answer}", flush=True) + print(f"\n=== {QUOTE_SOURCES} answered: {answered.question} ===\n{answered.answer}", flush=True) # session_open runs inside the lambda: a failed attempt may have opened the session. if stop := retried("worker", lambda: run_worker(cycle.root, worker_args(cycle.task, cycle.session, cycle.models.worker, session_open(cycle.session), answered), cycle.effects), cycle.effects): return stop diff --git a/bin/loop_claude/cycle/states.py b/bin/loop_claude/cycle/states.py index 33d13d74..747018c1 100644 --- a/bin/loop_claude/cycle/states.py +++ b/bin/loop_claude/cycle/states.py @@ -1,30 +1,31 @@ import dataclasses -from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished, Verdict +from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict +from loop_claude.project.records import QUOTE_SOURCES # A backstop for what the judge misses, such as a reworded repeat, so the worker cannot loop unattended on answers quoted from README.md or the records. -RECORDS_ANSWERS_PER_CYCLE = 3 +QUOTED_ANSWERS_PER_CYCLE = 3 @dataclasses.dataclass(frozen=True) class Working: """The worker runs, resumed with an answer quoted from README.md or the records when there is one.""" - answered: AnsweredFromRecords | None = None - records_answers: int = 0 + answered: QuotedAnswer | None = None + quoted_answers: int = 0 @dataclasses.dataclass(frozen=True) class Judging: - """The judge rules; records_answers counts the questions README.md or the records answered this cycle.""" + """The judge rules; quoted_answers counts the questions README.md or the records answered this cycle.""" transcript_path: str - records_answers: int = 0 + quoted_answers: int = 0 @dataclasses.dataclass(frozen=True) class Interrupting: transcript_path: str question: str - records_answers: int = 0 + quoted_answers: int = 0 @dataclasses.dataclass(frozen=True) @@ -67,19 +68,19 @@ Event = WorkerRan | Ruled | HumanAnswered | Archived def transition(state: State, event: Event) -> State: match state, event: - case Working(_, records_answers), WorkerRan(transcript_path): - return Judging(transcript_path, records_answers) - case Judging(_, records_answers), Ruled(AnsweredFromRecords() as answered) if records_answers < RECORDS_ANSWERS_PER_CYCLE: - return Working(answered, records_answers + 1) - case Judging(transcript_path, records_answers), Ruled(AnsweredFromRecords(question=question, answer=answer)): - return Interrupting(transcript_path, f"{question}\n\nREADME.md, AGENTS.md or docs/decisions.md say:\n{answer}\n\nThey answered {records_answers} questions this cycle, so this one comes to you.", records_answers) - case Judging(transcript_path, records_answers), Ruled(Interrupt(question=question)): - return Interrupting(transcript_path, question, records_answers) + case Working(_, quoted_answers), WorkerRan(transcript_path): + return Judging(transcript_path, quoted_answers) + case Judging(_, quoted_answers), Ruled(QuotedAnswer() as answered) if quoted_answers < QUOTED_ANSWERS_PER_CYCLE: + return Working(answered, quoted_answers + 1) + case Judging(transcript_path, quoted_answers), Ruled(QuotedAnswer(question=question, answer=answer)): + return Interrupting(transcript_path, f"{question}\n\n{QUOTE_SOURCES} says:\n{answer}\n\nThey answered {quoted_answers} questions this cycle, so this one comes to you.", quoted_answers) + case Judging(transcript_path, quoted_answers), Ruled(Interrupt(question=question)): + return Interrupting(transcript_path, question, quoted_answers) case Judging(transcript_path, _), Ruled(Finished() | Unfinished() as verdict): return Closing(transcript_path, verdict) # The human works in the interrupt's claude session, so the judge rules again on the transcript it leaves. - case Interrupting(transcript_path, _, records_answers), HumanAnswered(): - return Judging(transcript_path, records_answers) + case Interrupting(transcript_path, _, quoted_answers), HumanAnswered(): + return Judging(transcript_path, quoted_answers) case Closing(), Archived(): return Ended() raise ValueError(f"no transition from {state} on {event}") diff --git a/bin/loop_claude/cycle/verdicts.py b/bin/loop_claude/cycle/verdicts.py index f3ce6d5a..ffc48f61 100644 --- a/bin/loop_claude/cycle/verdicts.py +++ b/bin/loop_claude/cycle/verdicts.py @@ -8,7 +8,7 @@ class Interrupt: @dataclasses.dataclass(frozen=True) -class AnsweredFromRecords: +class QuotedAnswer: """The agent asked a question that README.md or the project's records answer, quoted in answer.""" evidence: str question: str @@ -25,4 +25,4 @@ class Unfinished: evidence: str -Verdict = Interrupt | AnsweredFromRecords | Finished | Unfinished +Verdict = Interrupt | QuotedAnswer | Finished | Unfinished diff --git a/bin/loop_claude/cycle/worker.py b/bin/loop_claude/cycle/worker.py index eb433a3c..a268e800 100644 --- a/bin/loop_claude/cycle/worker.py +++ b/bin/loop_claude/cycle/worker.py @@ -1,10 +1,11 @@ from loop_claude.claude_code.entries import assistant_parts, ends_stream, hit_limit, limit_said, parse_entry, rejected_until from loop_claude.claude_code.session import Session from loop_claude.claude_code.transcript import part_line -from loop_claude.cycle.verdicts import AnsweredFromRecords +from loop_claude.cycle.limited import Limited +from loop_claude.cycle.verdicts import QuotedAnswer from loop_claude.effects import Effects from loop_claude.failure import Failure -from loop_claude.limited import Limited +from loop_claude.project.records import QUOTE_SOURCES PRINTED_TOOL_INPUT = 160 @@ -38,9 +39,9 @@ def worker_outcome(code: int, result: dict | None, resets: list[int]) -> Failure return None if result is not None else Failure("claude exited 0 without a result event") -def worker_args(task: str, session: Session, model: str, resuming: bool, answered: AnsweredFromRecords | None = None) -> list[str]: +def worker_args(task: str, session: Session, model: str, resuming: bool, answered: QuotedAnswer | None = None) -> list[str]: if answered is not None: - start = ["-p", f"Your question: {answered.question}\n\nREADME.md, AGENTS.md or docs/decisions.md answer it:\n\n{answered.answer}\n\nContinue the task.", "--resume", str(session.id)] + start = ["-p", f"Your question: {answered.question}\n\n{QUOTE_SOURCES} answers it:\n\n{answered.answer}\n\nContinue the task.", "--resume", str(session.id)] elif resuming: start = ["-p", "Continue the task; the previous run stopped before it was finished.", "--resume", str(session.id)] else: diff --git a/bin/loop_claude/project/records.py b/bin/loop_claude/project/records.py index 10ce9714..5c7311f2 100644 --- a/bin/loop_claude/project/records.py +++ b/bin/loop_claude/project/records.py @@ -3,11 +3,15 @@ import pathlib from loop_claude.project.checkout import read_checkout_file from loop_claude.stop import Stop +RECORD_FILES = ("AGENTS.md", "docs/decisions.md") +# Where an answer the judge quotes comes from, as the human and the worker read it. +QUOTE_SOURCES = "README.md, " + " or ".join(RECORD_FILES) + def read_records(root: str) -> str | Stop: """AGENTS.md and docs/decisions.md, each headed by its path; a file the project lacks is left out.""" records = [] - for name in ("AGENTS.md", "docs/decisions.md"): + for name in RECORD_FILES: if not pathlib.Path(root, name).exists(): continue text = read_checkout_file(root, name, "the judge cannot read the project's records") diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 66c3dfd0..250242e6 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -19,10 +19,10 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) from loop_claude import file_writes, paths from loop_claude.claude_code import entries, session, transcript, trust from loop_claude.cycle import archive, interrupt, judge, retry, run, states, worker -from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished +from loop_claude.cycle.limited import Limited +from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished from loop_claude.effects import Effects from loop_claude.failure import Failure -from loop_claude.limited import Limited from loop_claude.loop import main, reload from loop_claude.project import checkout, model_choice, premises, records from loop_claude.stop import Stop @@ -92,7 +92,7 @@ def ran(stdout="", code=0, stderr=""): def judged(verdict, evidence="working", answer=""): - reply = {"answer": answer, "evidence": evidence, "finished": verdict == "finished", "interrupt": verdict == "interrupt", "question": "Which one?" if verdict == "interrupt" else ""} + reply = {"answer": answer, "evidence": evidence, "finished": verdict == "finished", "interrupt": verdict == "interrupt", "question": "Which one?" if verdict in ("interrupt", "quoted") else ""} return ran(json.dumps({"structured_output": reply})) @@ -127,15 +127,15 @@ class Streamed: class Transitions(unittest.TestCase): def test_each_state_moves_on_its_events_and_only_on_them(self): - answered = states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")) + answered = states.Ruled(QuotedAnswer("e", "Which one?", "A.")) legal = ( (states.Working(), states.WorkerRan("/t"), states.Judging("/t")), - (states.Working(AnsweredFromRecords("e", "Which one?", "A."), 3), states.WorkerRan("/t"), states.Judging("/t", 3)), + (states.Working(QuotedAnswer("e", "Which one?", "A."), 3), states.WorkerRan("/t"), states.Judging("/t", 3)), (states.Judging("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")), (states.Judging("/t", 3), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", 3)), - (states.Judging("/t"), answered, states.Working(AnsweredFromRecords("e", "Which one?", "A."), 1)), - (states.Judging("/t", 2), answered, states.Working(AnsweredFromRecords("e", "Which one?", "A."), 3)), - (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md say:\nA.\n\nThey answered 3 questions this cycle, so this one comes to you.", 3)), + (states.Judging("/t"), answered, states.Working(QuotedAnswer("e", "Which one?", "A."), 1)), + (states.Judging("/t", 2), answered, states.Working(QuotedAnswer("e", "Which one?", "A."), 3)), + (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md says:\nA.\n\nThey answered 3 questions this cycle, so this one comes to you.", 3)), (states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t", 3), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), @@ -147,7 +147,7 @@ class Transitions(unittest.TestCase): for state, event, after in legal: with self.subTest(state=state, event=event): self.assertEqual(states.transition(state, event), after) - every_state = (states.Working(), states.Working(AnsweredFromRecords("e", "Which one?", "A."), 3), states.Judging("/t"), states.Judging("/t", 3), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", 3), states.Closing("/t", Finished("e")), states.Ended()) + every_state = (states.Working(), states.Working(QuotedAnswer("e", "Which one?", "A."), 3), states.Judging("/t"), states.Judging("/t", 3), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", 3), states.Closing("/t", Finished("e")), states.Ended()) every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), answered, states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanAnswered(), states.Archived()) for state in every_state: for event in every_event: @@ -245,18 +245,18 @@ class Cycles(unittest.TestCase): self.assertIn("[human] the second", prompts[1]) def test_a_question_the_records_answer_resumes_the_worker_with_the_answer_three_times_a_cycle(self): - answered = judged("interrupt", answer="Use *A*.") + answered = judged("quoted", answer="Use *A*.") fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 4, claude=[answered] * 4, on_terminal_claude=[0], git=[ran()]) with contextlib.redirect_stderr(io.StringIO()) as said, contextlib.redirect_stdout(io.StringIO()) as printed: self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed")) resumed = fake.made("stream_claude")[1] - self.assertEqual(resumed[resumed.index("-p") + 1], "Your question: Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md answer it:\n\nUse *A*.\n\nContinue the task.") + self.assertEqual(resumed[resumed.index("-p") + 1], "Your question: Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md answers it:\n\nUse *A*.\n\nContinue the task.") self.assertEqual(len(fake.made("stream_claude")), 4) self.assertEqual(printed.getvalue().count("=== README.md, AGENTS.md or docs/decisions.md answered: Which one? ===\nUse *A*."), 3) - self.assertIn("Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md say:\nUse *A*.\n\nThey answered 3 questions this cycle", said.getvalue()) + self.assertIn("Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md says:\nUse *A*.\n\nThey answered 3 questions this cycle", said.getvalue()) def test_an_answer_the_records_do_not_hold_is_dropped_and_the_question_goes_to_the_human(self): - fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt", answer="Use B.")], on_terminal_claude=[0], git=[ran()]) + fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("quoted", answer="Use B.")], on_terminal_claude=[0], git=[ran()]) with contextlib.redirect_stderr(io.StringIO()) as said: self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed")) self.assertEqual(len(fake.made("stream_claude")), 1) @@ -502,7 +502,8 @@ class Verdict(unittest.TestCase): self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": "e", "finished": True, "question": ""}), Finished("e")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": "e", "finished": False, "question": "ignored"}), Unfinished("e")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "e", "finished": True, "question": "Which one?"}), Interrupt("e", "Which one?")) - self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"}), AnsweredFromRecords("e", "Which one?", "A.")) + self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": False, "evidence": "e", "finished": False, "question": "Which one?"}), QuotedAnswer("e", "Which one?", "A.")) + self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"}), Interrupt("e", "Which one?")) self.assertEqual(judge.verdict_from({"answer": "ignored", "interrupt": False, "evidence": "e", "finished": False, "question": ""}), Unfinished("e")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": "no", "evidence": "", "finished": True, "question": ""}), Failure("the judge's reply has no interrupt of type boolean")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": None, "finished": True, "question": ""}), Failure("the judge's reply has no evidence of type string")) @@ -534,7 +535,7 @@ class LoopRuns(unittest.TestCase): class HelpLimits(unittest.TestCase): def test_help_states_the_limits_the_code_holds(self): - self.assertIn(f"The {['second', 'third', 'fourth', 'fifth'][states.RECORDS_ANSWERS_PER_CYCLE - 1]} question they answer in one cycle", main.__doc__.replace("\n", " ")) + self.assertIn(f"The {['second', 'third', 'fourth', 'fifth'][states.QUOTED_ANSWERS_PER_CYCLE - 1]} question they answer in one cycle", main.__doc__.replace("\n", " ")) class ExitContract(unittest.TestCase): diff --git a/docs/decisions.md b/docs/decisions.md index f092b43c..d5334467 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -8,7 +8,7 @@ 2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. Valid while the worker's self-report stays unreliable. -2026-10-01, lilleman: the judge reads `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); its bar becomes whether the README or those files discriminate. 2026-10-03, implemented: when README.md or those files answer the worker's question, the judge quotes the answer verbatim and the worker resumes with it. The judge then sees the quote as a `[loop]` line. The worker asking it again shows the quote did not settle it, and the judge sends it to the human. A backstop of three quoted answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so the worker cannot loop unattended (goal 4.4); the fourth question README.md or those files answer in one cycle goes to the human with the judge's quote, so the cost is one interrupt. +2026-10-01, lilleman: the judge reads `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); its bar becomes whether the README or those files discriminate. 2026-10-03, implemented: when README.md or those files answer the worker's question, the judge quotes the answer verbatim and the worker resumes with it. The judge then sees the quote as a `[loop]` line. The worker asking it again shows the quote did not settle it, and the judge sends it to the human. A backstop of three quoted answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so the worker cannot loop unattended (goal 4.4); the fourth question that README.md or those files answer in one cycle goes to the human with the judge's quote, so the cost is one interrupt. ## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it -- 2.52.0 From 28cbea70d46519b08c8d320d7b613ce2bb7bb7cf Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 12:13:57 +0200 Subject: [PATCH 16/20] Answer round seven: the judge's rules no longer contradict on a repeated question, QUOTE_SOURCES names README.md's Goals and Audience, the decision names its premise, file item 40 --- bin/loop_claude/cycle/judge.py | 14 +++++++------- bin/loop_claude/cycle/states.py | 2 +- bin/loop_claude/cycle/verdicts.py | 2 +- bin/loop_claude/project/records.py | 6 +++--- bin/test_loop_claude.py | 10 +++++----- docs/decisions.md | 2 +- todo.md | 7 ++++++- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index abe5d68d..b96f5072 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -16,7 +16,7 @@ JUDGE_PROMPT_CHARS = 400000 JUDGE_RULES = ( "Decide whether the human must now be interrupted. interrupt=true when any of these appear:\n" "- the agent asks the human anything, seeks approval, or says a decision is the human's, and neither " - "README.md nor the project's records answer it\n" + "README.md nor the project's records settle the matter\n" "- it carried on under an assumption that decides the deliverable, that the human could " "reasonably reject and that neither README.md nor the project's records settle; a caveat about " "transient state it then handled is not one\n" @@ -29,11 +29,11 @@ JUDGE_RULES = ( "where a note goes - is not on its own a reason to interrupt. The human may have replied inside the transcript, on a [human] line: judge only what " "is still open, never a question they already answered there. A [loop] line is what loop-claude told " "the agent, such as an answer quoted from README.md or the project's records. A question a [loop] " - "line answered is no longer open. If the agent asks it again, interrupt with that question.\n" + "line answered is settled. If the agent asks it again, interrupt with that question.\n" "Where the agent asked or flagged something itself, the question is that one, in the agent's own " "wording; never construct another from facts it stated.\n" - "Where README.md or the project's records answer the agent's own question, set interrupt=false, put " - "that question in question and quote the passage that answers it in answer, verbatim; the agent is " + "Where README.md or the project's records answer the agent's own question and no [loop] line has " + "quoted that answer yet, set interrupt=false, put that question in question and quote the passage that answers it in answer, verbatim; the agent is " "then given that passage in place of the human's reply.\n" "finished=true when the chunk is complete: merged, or nothing remains that the agent could do on " "its own. finished=false when work remains that a further run can continue: an open PR, a review " @@ -46,7 +46,7 @@ class Reply: evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the transcript line the verdict rests on: what triggers the interrupt, else what shows the chunk finished or the work remaining."}) finished: bool interrupt: bool - question: str = dataclasses.field(metadata={"description": "The single question to put to the human, or the agent's question that answer answers. Empty otherwise."}) + question: str = dataclasses.field(metadata={"description": "With interrupt true, the single question to put to the human. With a quoted answer, the agent's question that the answer field answers. Empty otherwise."}) REPLY_TYPES = typing.get_type_hints(Reply) @@ -73,7 +73,7 @@ def judge(root: str, task: str, premises: str, records: str, rendered_transcript return retried("judge", lambda: run_judge(root, args, prompt, rendered_transcript, f"{premises}\n\n{records}", effects), effects) -def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str, recorded: str, effects: Effects) -> Verdict | Failure | Limited: +def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str, quotable: str, effects: Effects) -> Verdict | Failure | Limited: try: proc = effects.claude(args, root, prompt) except OSError as failure: @@ -90,7 +90,7 @@ def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str, if not grounded(verdict.evidence, rendered_transcript): 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 | QuotedAnswer) else "")) # Not a Failure: a misquote would otherwise exit an unattended loop. - if isinstance(verdict, QuotedAnswer) and not grounded(verdict.answer, recorded): + if isinstance(verdict, QuotedAnswer) and not grounded(verdict.answer, quotable): return Interrupt(verdict.evidence, verdict.question) return verdict diff --git a/bin/loop_claude/cycle/states.py b/bin/loop_claude/cycle/states.py index 747018c1..aa74f42d 100644 --- a/bin/loop_claude/cycle/states.py +++ b/bin/loop_claude/cycle/states.py @@ -73,7 +73,7 @@ def transition(state: State, event: Event) -> State: case Judging(_, quoted_answers), Ruled(QuotedAnswer() as answered) if quoted_answers < QUOTED_ANSWERS_PER_CYCLE: return Working(answered, quoted_answers + 1) case Judging(transcript_path, quoted_answers), Ruled(QuotedAnswer(question=question, answer=answer)): - return Interrupting(transcript_path, f"{question}\n\n{QUOTE_SOURCES} says:\n{answer}\n\nThey answered {quoted_answers} questions this cycle, so this one comes to you.", quoted_answers) + return Interrupting(transcript_path, f"{question}\n\n{QUOTE_SOURCES} says:\n{answer}\n\nThose files have answered {quoted_answers} questions this cycle, the most allowed, so this one comes to you.", quoted_answers) case Judging(transcript_path, quoted_answers), Ruled(Interrupt(question=question)): return Interrupting(transcript_path, question, quoted_answers) case Judging(transcript_path, _), Ruled(Finished() | Unfinished() as verdict): diff --git a/bin/loop_claude/cycle/verdicts.py b/bin/loop_claude/cycle/verdicts.py index ffc48f61..172e8159 100644 --- a/bin/loop_claude/cycle/verdicts.py +++ b/bin/loop_claude/cycle/verdicts.py @@ -9,7 +9,7 @@ class Interrupt: @dataclasses.dataclass(frozen=True) class QuotedAnswer: - """The agent asked a question that README.md or the project's records answer, quoted in answer.""" + """The agent asked a question that README.md or the project's records answer. The answer field quotes the passage.""" evidence: str question: str answer: str diff --git a/bin/loop_claude/project/records.py b/bin/loop_claude/project/records.py index 5c7311f2..42fe7d33 100644 --- a/bin/loop_claude/project/records.py +++ b/bin/loop_claude/project/records.py @@ -4,12 +4,12 @@ from loop_claude.project.checkout import read_checkout_file from loop_claude.stop import Stop RECORD_FILES = ("AGENTS.md", "docs/decisions.md") -# Where an answer the judge quotes comes from, as the human and the worker read it. -QUOTE_SOURCES = "README.md, " + " or ".join(RECORD_FILES) +# The files a quoted answer comes from, named as the human and the worker see them; of README.md the judge sees only the premises. +QUOTE_SOURCES = "README.md's Goals and Audience, " + " or ".join(RECORD_FILES) def read_records(root: str) -> str | Stop: - """AGENTS.md and docs/decisions.md, each headed by its path; a file the project lacks is left out.""" + """The record files, each headed by its path; a file the project lacks is left out.""" records = [] for name in RECORD_FILES: if not pathlib.Path(root, name).exists(): diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 250242e6..5cb3afc5 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -135,7 +135,7 @@ class Transitions(unittest.TestCase): (states.Judging("/t", 3), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", 3)), (states.Judging("/t"), answered, states.Working(QuotedAnswer("e", "Which one?", "A."), 1)), (states.Judging("/t", 2), answered, states.Working(QuotedAnswer("e", "Which one?", "A."), 3)), - (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md says:\nA.\n\nThey answered 3 questions this cycle, so this one comes to you.", 3)), + (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md's Goals and Audience, AGENTS.md or docs/decisions.md says:\nA.\n\nThose files have answered 3 questions this cycle, the most allowed, so this one comes to you.", 3)), (states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t", 3), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), @@ -250,10 +250,10 @@ class Cycles(unittest.TestCase): with contextlib.redirect_stderr(io.StringIO()) as said, contextlib.redirect_stdout(io.StringIO()) as printed: self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed")) resumed = fake.made("stream_claude")[1] - self.assertEqual(resumed[resumed.index("-p") + 1], "Your question: Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md answers it:\n\nUse *A*.\n\nContinue the task.") + self.assertEqual(resumed[resumed.index("-p") + 1], "Your question: Which one?\n\nREADME.md's Goals and Audience, AGENTS.md or docs/decisions.md answers it:\n\nUse *A*.\n\nContinue the task.") self.assertEqual(len(fake.made("stream_claude")), 4) - self.assertEqual(printed.getvalue().count("=== README.md, AGENTS.md or docs/decisions.md answered: Which one? ===\nUse *A*."), 3) - self.assertIn("Which one?\n\nREADME.md, AGENTS.md or docs/decisions.md says:\nUse *A*.\n\nThey answered 3 questions this cycle", said.getvalue()) + self.assertEqual(printed.getvalue().count("=== README.md's Goals and Audience, AGENTS.md or docs/decisions.md answered: Which one? ===\nUse *A*."), 3) + self.assertIn("Which one?\n\nREADME.md's Goals and Audience, AGENTS.md or docs/decisions.md says:\nUse *A*.\n\nThose files have answered 3 questions this cycle", said.getvalue()) def test_an_answer_the_records_do_not_hold_is_dropped_and_the_question_goes_to_the_human(self): fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("quoted", answer="Use B.")], on_terminal_claude=[0], git=[ran()]) @@ -542,7 +542,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" - unreadable = "README.md, or AGENTS.md or docs/decisions.md where they exist, cannot be read or is not UTF-8" + unreadable = f"README.md, or {' or '.join(records.RECORD_FILES)} where they exist, cannot be read or is not UTF-8" # 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), diff --git a/docs/decisions.md b/docs/decisions.md index d5334467..20d2956c 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -8,7 +8,7 @@ 2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. Valid while the worker's self-report stays unreliable. -2026-10-01, lilleman: the judge reads `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); its bar becomes whether the README or those files discriminate. 2026-10-03, implemented: when README.md or those files answer the worker's question, the judge quotes the answer verbatim and the worker resumes with it. The judge then sees the quote as a `[loop]` line. The worker asking it again shows the quote did not settle it, and the judge sends it to the human. A backstop of three quoted answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so the worker cannot loop unattended (goal 4.4); the fourth question that README.md or those files answer in one cycle goes to the human with the judge's quote, so the cost is one interrupt. +2026-10-01, lilleman: the judge reads `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); its bar becomes whether the README or those files discriminate. 2026-10-03, implemented: when README.md or those files answer the worker's question, the judge quotes the answer verbatim and the worker resumes with it. The judge then sees the quote as a `[loop]` line. The worker asking it again shows the quote did not settle it, and the judge sends it to the human. A backstop of three quoted answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so the worker cannot loop unattended (goal 4.4); the fourth question that README.md or those files answer in one cycle goes to the human with the judge's quote, so the cost is one interrupt. Valid while the worker writes records only in a worktree, as `CLAUDE.md` → "Working with the codebase" has it, so the records the judge reads from the checkout root are merged ones. ## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it diff --git a/todo.md b/todo.md index eb5cdd81..6aa2a2d3 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 9` -`Next ID = 40` +`Next ID = 41` | Goal | W | |---|---| @@ -27,6 +27,7 @@ | 1 | 0.1.0 | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 3 | 5 | 8 | 9 | 2, 3 | 27.8 | | 13 | 0.1.0 | decision | **Make larv-review §3 applicable on its own, cite its rules by name, and say where a pass's round count is recorded.** | 3 | 5 | 6 | 7 | 4.1 | 15.6 | | 23 | 0.1.0 | | **Launch a principles auditor only for a principles file the project shows applies, and rerun only the reviewer whose finding a fix answers.** | 3 | 4 | 7 | 8 | 4.4 | 13.5 | +| 40 | 0.1.0 | | **Render tool input in the judged transcript with its non-ASCII characters as written, so the judge's quotes of it ground.** | 2 | 1 | 5 | 6 | 4.2 | 13.0 | | 21 | 0.1.0 | | **Give `settings.json`'s model one writer, and sort its keys.** | 3 | 3 | 6 | 7 | 4.3 | 12.9 | | 36 | 0.1.0 | | **Ask the user once before a full security scan, folding larv-review's ask into the plugin's cost prompt.** | 2 | 2 | 5 | 5 | 4.2 | 11.9 | | 12 | 0.1.0 | | **Run the test suite in CI on every PR, or record in `docs/decisions.md` why the local run is enough.** | 2 | 4 | 4 | 6 | 4.1 | 11.7 | @@ -53,6 +54,10 @@ Applying one rule of "Round cap", "Re-entry" or "Findings" takes `review-finding On this repo the frontend, REST and logging auditors each read the whole project to report "does not apply", and one 🟢 fix reruns ten whole-project reads. +### 40. Render tool input in the judged transcript with its non-ASCII characters as written, so the judge's quotes of it ground. + +`part_line` renders a tool call with `json.dumps(arguments)`, which escapes non-ASCII as `\uXXXX`. A judge quoting such a line with the characters as written, Swedish text say, fails `grounded` three times on one transcript, and the loop exits 1. Raised, unverified, by the 2026-10-03 scoring run on PR #202. + ### 21. Give `settings.json`'s model one writer, and sort its keys. Claude Code rewrites `"model"` in this tracked file whenever a model is picked, so one `/model` dirties the checkout and overrides the synced choice. -- 2.52.0 From 50e8056f4d1dfc2896d53d5612cb495fa639eba2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 14:13:30 +0200 Subject: [PATCH 17/20] Move the Markdown section parser out of premises into its own module; file the log loop's ellipsis crash as item 41 --- bin/loop_claude/markdown_sections.py | 27 ++++++++++++++++++++++++++ bin/loop_claude/project/premises.py | 29 +--------------------------- bin/rank_todo.py | 2 +- bin/test_loop_claude.py | 10 +++++----- todo.md | 7 ++++++- 5 files changed, 40 insertions(+), 35 deletions(-) create mode 100644 bin/loop_claude/markdown_sections.py diff --git a/bin/loop_claude/markdown_sections.py b/bin/loop_claude/markdown_sections.py new file mode 100644 index 00000000..593d6655 --- /dev/null +++ b/bin/loop_claude/markdown_sections.py @@ -0,0 +1,27 @@ +import re + +FENCE = re.compile(r"^ {0,3}(`{3,}|~{3,})", re.M) + + +def sections(text: str) -> dict[str, list[str]]: + blocks: list[tuple[str | None, list[str]]] = [] + opener = "" + for line in text.splitlines(): + if fence := FENCE.match(line): + marker = fence.group(1) + if not opener: + opener = marker + elif marker[0] == opener[0] and len(marker) >= len(opener) and not line[fence.end():].strip(): + opener = "" + fenced = bool(opener or fence) + if not fenced and line.startswith("## "): + blocks.append((line.strip()[3:], [])) + elif not fenced and line.startswith("# "): + blocks.append((None, [])) + elif blocks and line.strip(): + blocks[-1][1].append(line) + found: dict[str, list[str]] = {} + for name, body in blocks: + if name is not None: + found.setdefault(name, []).append("\n".join(body)) + return found diff --git a/bin/loop_claude/project/premises.py b/bin/loop_claude/project/premises.py index f30f0a28..45b080f4 100644 --- a/bin/loop_claude/project/premises.py +++ b/bin/loop_claude/project/premises.py @@ -1,10 +1,7 @@ -import re - +from loop_claude.markdown_sections import sections from loop_claude.project.checkout import read_checkout_file from loop_claude.stop import Stop -FENCE = re.compile(r"^ {0,3}(`{3,}|~{3,})", re.M) - def read_premises(root: str) -> str | Stop: text = read_checkout_file(root, "README.md", "no premises") @@ -20,27 +17,3 @@ def read_premises(root: str) -> str | Stop: if not bodies[0]: return Stop(1, f"README.md has nothing under ## {name} - no premises.") return f"## Goals\n{found['Goals'][0]}\n\n## Audience\n{found['Audience'][0]}" - - -def sections(text: str) -> dict[str, list[str]]: - blocks: list[tuple[str | None, list[str]]] = [] - opener = "" - for line in text.splitlines(): - if fence := FENCE.match(line): - marker = fence.group(1) - if not opener: - opener = marker - elif marker[0] == opener[0] and len(marker) >= len(opener) and not line[fence.end():].strip(): - opener = "" - fenced = bool(opener or fence) - if not fenced and line.startswith("## "): - blocks.append((line.strip()[3:], [])) - elif not fenced and line.startswith("# "): - blocks.append((None, [])) - elif blocks and line.strip(): - blocks[-1][1].append(line) - found: dict[str, list[str]] = {} - for name, body in blocks: - if name is not None: - found.setdefault(name, []).append("\n".join(body)) - return found diff --git a/bin/rank_todo.py b/bin/rank_todo.py index edff2d7e..f6dfdb92 100755 --- a/bin/rank_todo.py +++ b/bin/rank_todo.py @@ -60,7 +60,7 @@ import sys # Kept inside loop_claude/ so reload's fingerprint covers them. from loop_claude.failure import Failure from loop_claude.file_writes import replace_file -from loop_claude.project.premises import FENCE, sections +from loop_claude.markdown_sections import FENCE, sections EXEMPTIONS = ("", "decision", "defect", "principle", "question", "security") ITEMS_HEADER = "| ID | Release | Exempt | Item | R | S | A | G | Goals | Score |" diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 5cb3afc5..cdf11d26 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -16,7 +16,7 @@ import uuid sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) -from loop_claude import file_writes, paths +from loop_claude import file_writes, markdown_sections, paths from loop_claude.claude_code import entries, session, transcript, trust from loop_claude.cycle import archive, interrupt, judge, retry, run, states, worker from loop_claude.cycle.limited import Limited @@ -24,7 +24,7 @@ from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfini from loop_claude.effects import Effects from loop_claude.failure import Failure from loop_claude.loop import main, reload -from loop_claude.project import checkout, model_choice, premises, records +from loop_claude.project import checkout, model_choice, records from loop_claude.stop import Stop CWD = pathlib.Path("/c") @@ -397,12 +397,12 @@ class Records(unittest.TestCase): class Sections(unittest.TestCase): def test_keeps_every_headed_section_with_its_bodies(self): text = "# Title\n\nintro\n\n## Goals\n\n1. one\n```sh\n# not a heading\n```\n### Later\n2. two\n#1 priority\n\n## Empty\n\n## Audience\nme\n## Audience\nagain\n# Appendix\nnot audience\n" - self.assertEqual(premises.sections(text), {"Goals": ["1. one\n```sh\n# not a heading\n```\n### Later\n2. two\n#1 priority"], "Empty": [""], "Audience": ["me", "again"]}) + self.assertEqual(markdown_sections.sections(text), {"Goals": ["1. one\n```sh\n# not a heading\n```\n### Later\n2. two\n#1 priority"], "Empty": [""], "Audience": ["me", "again"]}) def test_closes_a_fence_only_on_its_own_marker(self): text = "## Goals\n````md\n~~~\n## Quoted\n```\n````\n ~~~\n## Also quoted\n ~~~\n1. one\n## Audience\nme\n" - self.assertEqual(list(premises.sections(text)), ["Goals", "Audience"]) - self.assertEqual(list(premises.sections("```\nquoted:\n```python\n## Inside\n```\n## Goals\n1. one\n")), ["Goals"]) + self.assertEqual(list(markdown_sections.sections(text)), ["Goals", "Audience"]) + self.assertEqual(list(markdown_sections.sections("```\nquoted:\n```python\n## Inside\n```\n## Goals\n1. one\n")), ["Goals"]) class Render(unittest.TestCase): diff --git a/todo.md b/todo.md index 6aa2a2d3..2330d235 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 9` -`Next ID = 41` +`Next ID = 42` | Goal | W | |---|---| @@ -24,6 +24,7 @@ | ID | Release | Exempt | Item | R | S | A | G | Goals | Score | |---|---|---|---|---|---|---|---|---|---| +| 41 | 0.1.0 | defect | **Ground a judge's quote that elides with an ellipsis, each fragment found in order, and tell the judge to quote one passage.** | 2 | 2 | 10 | 10 | 4, 4.2 | 30.9 | | 1 | 0.1.0 | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 3 | 5 | 8 | 9 | 2, 3 | 27.8 | | 13 | 0.1.0 | decision | **Make larv-review §3 applicable on its own, cite its rules by name, and say where a pass's round count is recorded.** | 3 | 5 | 6 | 7 | 4.1 | 15.6 | | 23 | 0.1.0 | | **Launch a principles auditor only for a principles file the project shows applies, and rerun only the reviewer whose finding a fix answers.** | 3 | 4 | 7 | 8 | 4.4 | 13.5 | @@ -40,6 +41,10 @@ ## Details +### 41. Ground a judge's quote that elides with an ellipsis, each fragment found in order, and tell the judge to quote one passage. + +On 2026-10-03 the log project's loop exited 1: "the judge failed three times running: the judge quoted \"**Decision for you:** security, … ... I recommend one more round of each ... I recommend skipping it: …\", which is not in the transcript". Each fragment the judge joined with " ... " is in the rendered transcript; `grounded` matches the evidence as one contiguous string, so a correct interrupt was rejected three times and the human was never asked. The archive is `loop-claude-transcripts/log/dbac9d70…/5d8c9152….verdict.md`. Fix both ends: `grounded` splits on `...` and `…` and finds the fragments in order, and the `evidence` description asks for one contiguous passage. + ### 1. Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume. It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost disk loses every unattended run's record. Back it up only to a destination private to me and encrypted at rest: the worker runs with permissions bypassed, so the archived tool results can hold credentials it read. -- 2.52.0 From d1435684df35b762d1bbc5a0ef6ab879b53b6f6f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 14:18:52 +0200 Subject: [PATCH 18/20] Answer round eight: a quoted answer without a question fails the judge run, the first rule names the [loop] repeat, prose nits --- bin/loop_claude/cycle/judge.py | 8 +++++--- bin/loop_claude/loop/main.py | 2 +- bin/test_loop_claude.py | 2 +- docs/decisions.md | 2 +- todo.md | 12 ++++++------ 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index b96f5072..b3756cd9 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -16,7 +16,7 @@ JUDGE_PROMPT_CHARS = 400000 JUDGE_RULES = ( "Decide whether the human must now be interrupted. interrupt=true when any of these appear:\n" "- the agent asks the human anything, seeks approval, or says a decision is the human's, and neither " - "README.md nor the project's records settle the matter\n" + "README.md nor the project's records settle the matter, or a [loop] line already answered it\n" "- it carried on under an assumption that decides the deliverable, that the human could " "reasonably reject and that neither README.md nor the project's records settle; a caveat about " "transient state it then handled is not one\n" @@ -43,7 +43,7 @@ JUDGE_RULES = ( @dataclasses.dataclass(frozen=True) class Reply: answer: str = dataclasses.field(metadata={"description": "With interrupt false, the passage of README.md or the project's records that answers the agent's question, quoted verbatim. Empty otherwise."}) - evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the transcript line the verdict rests on: what triggers the interrupt, else what shows the chunk finished or the work remaining."}) + evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the transcript line the verdict rests on: what triggers the interrupt, what the agent asked for a quoted answer, else what shows the chunk finished or the work remaining."}) finished: bool interrupt: bool question: str = dataclasses.field(metadata={"description": "With interrupt true, the single question to put to the human. With a quoted answer, the agent's question that the answer field answers. Empty otherwise."}) @@ -118,7 +118,9 @@ def verdict_from(output: object) -> Verdict | Failure: if not output["question"].strip(): return Failure("the judge interrupted without a question") return Interrupt(output["evidence"], output["question"]) - if output["answer"].strip() and output["question"].strip(): + if output["answer"].strip(): + if not output["question"].strip(): + return Failure("the judge quoted an answer without a question") return QuotedAnswer(output["evidence"], output["question"], output["answer"]) return Finished(output["evidence"]) if output["finished"] else Unfinished(output["evidence"]) diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index fe2dcfb5..305ec16e 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -52,7 +52,7 @@ Exit 1, saying why, when: - 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 a line the transcript does not hold. A usage limit is not + interrupts or quotes an answer without a question, or quotes a line the transcript does not hold. A usage limit is not a failure, and restarts the count of three: the worker or the judge is retried 2 minutes after the limit resets, or every 10 minutes when the reset time is unknown or more than 2 minutes past. The judge's reply gives its reset time only as text, so the judge is always retried every 10 minutes. diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index cdf11d26..c78b3a6d 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -504,7 +504,7 @@ class Verdict(unittest.TestCase): self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "e", "finished": True, "question": "Which one?"}), Interrupt("e", "Which one?")) self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": False, "evidence": "e", "finished": False, "question": "Which one?"}), QuotedAnswer("e", "Which one?", "A.")) self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"}), Interrupt("e", "Which one?")) - self.assertEqual(judge.verdict_from({"answer": "ignored", "interrupt": False, "evidence": "e", "finished": False, "question": ""}), Unfinished("e")) + self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": False, "evidence": "e", "finished": True, "question": ""}), Failure("the judge quoted an answer without a question")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": "no", "evidence": "", "finished": True, "question": ""}), Failure("the judge's reply has no interrupt of type boolean")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": None, "finished": True, "question": ""}), Failure("the judge's reply has no evidence of type string")) self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "x", "finished": False, "question": " "}), Failure("the judge interrupted without a question")) diff --git a/docs/decisions.md b/docs/decisions.md index 20d2956c..c1c0cf15 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -8,7 +8,7 @@ 2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. Valid while the worker's self-report stays unreliable. -2026-10-01, lilleman: the judge reads `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); its bar becomes whether the README or those files discriminate. 2026-10-03, implemented: when README.md or those files answer the worker's question, the judge quotes the answer verbatim and the worker resumes with it. The judge then sees the quote as a `[loop]` line. The worker asking it again shows the quote did not settle it, and the judge sends it to the human. A backstop of three quoted answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so the worker cannot loop unattended (goal 4.4); the fourth question that README.md or those files answer in one cycle goes to the human with the judge's quote, so the cost is one interrupt. Valid while the worker writes records only in a worktree, as `CLAUDE.md` → "Working with the codebase" has it, so the records the judge reads from the checkout root are merged ones. +2026-10-01, lilleman: the judge reads `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); its bar becomes whether the README or those files discriminate. 2026-10-03, implemented: when the README's premises or those files answer the worker's question, the judge quotes the answer verbatim and the worker resumes with it. The judge then sees the quote as a `[loop]` line. The worker asking it again shows the quote did not settle it, and the judge sends it to the human. A backstop of three quoted answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so the worker cannot loop unattended (goal 4.4); the fourth question that the README's premises or those files answer in one cycle goes to the human with the judge's quote. The count holds through an interrupt, so each later such question that cycle costs one interrupt too. Valid while the worker writes records only in a worktree, as `CLAUDE.md` → "Working with the codebase" has it, so the records the judge reads from the checkout root are merged ones. ## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it diff --git a/todo.md b/todo.md index 2330d235..5ef90c0e 100644 --- a/todo.md +++ b/todo.md @@ -24,11 +24,11 @@ | ID | Release | Exempt | Item | R | S | A | G | Goals | Score | |---|---|---|---|---|---|---|---|---|---| -| 41 | 0.1.0 | defect | **Ground a judge's quote that elides with an ellipsis, each fragment found in order, and tell the judge to quote one passage.** | 2 | 2 | 10 | 10 | 4, 4.2 | 30.9 | +| 41 | 0.1.0 | defect | **Accept a judge's quote that elides with an ellipsis when its fragments appear in the transcript in order, and tell the judge to quote one passage.** | 2 | 2 | 10 | 10 | 4, 4.2 | 30.9 | | 1 | 0.1.0 | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 3 | 5 | 8 | 9 | 2, 3 | 27.8 | | 13 | 0.1.0 | decision | **Make larv-review §3 applicable on its own, cite its rules by name, and say where a pass's round count is recorded.** | 3 | 5 | 6 | 7 | 4.1 | 15.6 | | 23 | 0.1.0 | | **Launch a principles auditor only for a principles file the project shows applies, and rerun only the reviewer whose finding a fix answers.** | 3 | 4 | 7 | 8 | 4.4 | 13.5 | -| 40 | 0.1.0 | | **Render tool input in the judged transcript with its non-ASCII characters as written, so the judge's quotes of it ground.** | 2 | 1 | 5 | 6 | 4.2 | 13.0 | +| 40 | 0.1.0 | | **Render tool input in the judged transcript with its non-ASCII characters as written, so the judge's quotes of it match the transcript.** | 2 | 1 | 5 | 6 | 4.2 | 13.0 | | 21 | 0.1.0 | | **Give `settings.json`'s model one writer, and sort its keys.** | 3 | 3 | 6 | 7 | 4.3 | 12.9 | | 36 | 0.1.0 | | **Ask the user once before a full security scan, folding larv-review's ask into the plugin's cost prompt.** | 2 | 2 | 5 | 5 | 4.2 | 11.9 | | 12 | 0.1.0 | | **Run the test suite in CI on every PR, or record in `docs/decisions.md` why the local run is enough.** | 2 | 4 | 4 | 6 | 4.1 | 11.7 | @@ -41,9 +41,9 @@ ## Details -### 41. Ground a judge's quote that elides with an ellipsis, each fragment found in order, and tell the judge to quote one passage. +### 41. Accept a judge's quote that elides with an ellipsis when its fragments appear in the transcript in order, and tell the judge to quote one passage. -On 2026-10-03 the log project's loop exited 1: "the judge failed three times running: the judge quoted \"**Decision for you:** security, … ... I recommend one more round of each ... I recommend skipping it: …\", which is not in the transcript". Each fragment the judge joined with " ... " is in the rendered transcript; `grounded` matches the evidence as one contiguous string, so a correct interrupt was rejected three times and the human was never asked. The archive is `loop-claude-transcripts/log/dbac9d70…/5d8c9152….verdict.md`. Fix both ends: `grounded` splits on `...` and `…` and finds the fragments in order, and the `evidence` description asks for one contiguous passage. +On 2026-10-03 the log project's loop exited 1: "the judge failed three times running: the judge quoted \"**Decision for you:** security, … ... I recommend one more round of each ... I recommend skipping it: …\", which is not in the transcript". Each fragment the judge joined with " ... " is in the rendered transcript; `grounded` matches the evidence as one contiguous string, so a correct interrupt was rejected three times and the human was never asked. The archive is `~/.claude/loop-claude-transcripts/log/dbac9d7096282d2bc6c38fc8c03cd74b50d29b75080b1f647c0f305a088db894/5d8c9152cdcd91e90dfd2773cd81c9e64bcd412ff148c5cf19e2a728ceee5028.verdict.md`. Fix both ends: `grounded` splits on `...` and `…` and finds the fragments in order, and the `evidence` description asks for one contiguous passage. ### 1. Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume. @@ -59,9 +59,9 @@ Applying one rule of "Round cap", "Re-entry" or "Findings" takes `review-finding On this repo the frontend, REST and logging auditors each read the whole project to report "does not apply", and one 🟢 fix reruns ten whole-project reads. -### 40. Render tool input in the judged transcript with its non-ASCII characters as written, so the judge's quotes of it ground. +### 40. Render tool input in the judged transcript with its non-ASCII characters as written, so the judge's quotes of it match the transcript. -`part_line` renders a tool call with `json.dumps(arguments)`, which escapes non-ASCII as `\uXXXX`. A judge quoting such a line with the characters as written, Swedish text say, fails `grounded` three times on one transcript, and the loop exits 1. Raised, unverified, by the 2026-10-03 scoring run on PR #202. +`part_line` renders a tool call with `json.dumps(arguments)`, which escapes non-ASCII as `\uXXXX`. A judge that quotes such a line with its characters as written, such as Swedish text, fails `grounded` three times on one transcript, and the loop exits 1. Raised, unverified, by the 2026-10-03 scoring run on PR #202. ### 21. Give `settings.json`'s model one writer, and sort its keys. -- 2.52.0 From e906ebc87ba4490efbec00e6a9d86d70f3389177 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 15:40:48 +0200 Subject: [PATCH 19/20] Ship under the floor: record PR #202's scores, rank the places the seats named after item 41 --- docs/decisions.md | 2 +- todo.md | 33 ++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/docs/decisions.md b/docs/decisions.md index c1c0cf15..c812f76f 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -32,7 +32,7 @@ ## comprehension floor: every dimension and the overall at 7.0 or above, and 0.1.0 waits on it -2026-09-27, lilleman, restating the 2026-09-24 target and extending it to the overall. Serves goal 4. The 2026-09-28 run, Junior A, Mid A, the maintainability senior and the inherited architect at depth 1 over every non-test file, blind to `todo.md` and this log, scored Navigation 7.25, Locality 6.0, Shape 6.5, Self-sufficiency 6.25, overall 6.25; on 2026-09-26 they were 7.75, 6.25, 7.0, 6.75, 6.75. Every seat scored Locality 6, and three of four named `run_cycle`'s three-way return and larv-review's re-entry rules, split across the passes on 2026-09-28. The same seats on `rebuild` scored 7.5, 6.63, 6.88, 6.5, 7.0 at 37edc9a, later that day, 7.5, 6.75, 6.88, 6.75, 7.0 at 7f9de5c, 7.38, 6.25, 6.88, 6.75, 6.88 at 2f9ab2f on 2026-09-29, Locality lowest again and every seat naming the reload state and the two retry counters, and 7.5, 7.0, 7.25, 6.75, 7.13 at 2c74bbc later that day, Self-sufficiency lowest and every seat naming the round's definition split across larv-review's two files, and 7.38, 6.75, 7.25, 6.5, 6.88 at 8585257 on 2026-10-01, lowering every dimension but Shape, and the overall, Self-sufficiency lowest and every seat naming larv-review §3's round rules; the places it named under Self-sufficiency and Locality are filed in `todo.md` under 0.1.0, and a later scoring run may not score any dimension or the overall below its best run on `rebuild`, 2026-10-01, lilleman. `rebuild` merged into main under the floor at 8585257's scores, 2026-10-01, lilleman. The 2026-10-01 run on PR #182 (the loop state machine) scored 7.5, 6.5, 6.88, 6.25, 6.38; lilleman shipped that PR under the floor and below `rebuild`'s best run the same day, its places filed in `todo.md` under 0.1.0. The 2026-10-02 run on PR #187 (`loop_claude`'s names, the exit contract) scored 7.75, 7.25, 7.38, 6.88, 7.25 at 70362d0, every seat naming larv-review §3 under Self-sufficiency, and 7.63, 7.13, 7.38, 7.0, 7.13 at 1971dba later that day, the first run at the floor, with no dimension or the overall below its best run on `rebuild`. The 2026-10-02 runs on PR #191 (the status line in Python) scored 7.5, 7.0, 7.13, 6.88, 7.13; 7.25, 6.75, 7.25, 6.88, 7.0; 7.63, 6.88, 7.38, 7.0, 7.13; and 7.63, 7.0, 7.25, 6.75, 7.25. Every seat rated the status line easy. The places they named under Locality and Self-sufficiency are filed in `todo.md` under 0.1.0, except `entries.py`'s heuristics over Claude Code's transcript format, which the seats scored as the problem's own difficulty. lilleman decided the same day to ship that PR under the floor. The 2026-10-02 runs on PR #194 (each cycle's transcript archived) scored 8.0, 7.25, 7.38, 7.13, 7.5 at 6ccd5b1 and 7.75, 7.13, 7.25, 7.0, 7.25 at d104ea0, both at the floor, every seat naming `archive` as the unit it would least want to modify. On 2026-10-02, applying `todo.md`'s bar deleted every place these scoring runs filed except `todo.md` items 13 and 17. The 2026-10-02 runs on PR #196 (`todo.md` as one scored table) scored 7.63, 6.88, 7.25, 6.88, 7.13 at c0dba66; 7.5, 6.88, 7.13, 6.75, 7.0 at 798dfd7; and 7.5, 7.0, 7.0, 6.75, 7.0 at b712076. Under Self-sufficiency, every seat named larv-review §3 and the agents, which a reader follows only with `CLAUDE.md` open. lilleman decided the same day to ship that PR under the floor; the place filed is `todo.md` item 13. The 2026-10-02 run on PR #198 (a usage limit waited out) scored 7.63, 6.88, 7.38, 6.75, 7.13 at 8e85033. Under Self-sufficiency, every seat named larv-review §3, which `todo.md` item 13 covers; under Locality, they named `archive`'s invariants spread over `session.py` and `run.py`, `rank_todo.py` reaching into `premises.sections`, and `stopped` comparing reason strings, each under `todo.md`'s bar and not filed. lilleman decided the same day to ship that PR under the floor. Valid until the next scoring run, which uses the same four seats. +2026-09-27, lilleman, restating the 2026-09-24 target and extending it to the overall. Serves goal 4. The 2026-09-28 run, Junior A, Mid A, the maintainability senior and the inherited architect at depth 1 over every non-test file, blind to `todo.md` and this log, scored Navigation 7.25, Locality 6.0, Shape 6.5, Self-sufficiency 6.25, overall 6.25; on 2026-09-26 they were 7.75, 6.25, 7.0, 6.75, 6.75. Every seat scored Locality 6, and three of four named `run_cycle`'s three-way return and larv-review's re-entry rules, split across the passes on 2026-09-28. The same seats on `rebuild` scored 7.5, 6.63, 6.88, 6.5, 7.0 at 37edc9a, later that day, 7.5, 6.75, 6.88, 6.75, 7.0 at 7f9de5c, 7.38, 6.25, 6.88, 6.75, 6.88 at 2f9ab2f on 2026-09-29, Locality lowest again and every seat naming the reload state and the two retry counters, and 7.5, 7.0, 7.25, 6.75, 7.13 at 2c74bbc later that day, Self-sufficiency lowest and every seat naming the round's definition split across larv-review's two files, and 7.38, 6.75, 7.25, 6.5, 6.88 at 8585257 on 2026-10-01, lowering every dimension but Shape, and the overall, Self-sufficiency lowest and every seat naming larv-review §3's round rules; the places it named under Self-sufficiency and Locality are filed in `todo.md` under 0.1.0, and a later scoring run may not score any dimension or the overall below its best run on `rebuild`, 2026-10-01, lilleman. `rebuild` merged into main under the floor at 8585257's scores, 2026-10-01, lilleman. The 2026-10-01 run on PR #182 (the loop state machine) scored 7.5, 6.5, 6.88, 6.25, 6.38; lilleman shipped that PR under the floor and below `rebuild`'s best run the same day, its places filed in `todo.md` under 0.1.0. The 2026-10-02 run on PR #187 (`loop_claude`'s names, the exit contract) scored 7.75, 7.25, 7.38, 6.88, 7.25 at 70362d0, every seat naming larv-review §3 under Self-sufficiency, and 7.63, 7.13, 7.38, 7.0, 7.13 at 1971dba later that day, the first run at the floor, with no dimension or the overall below its best run on `rebuild`. The 2026-10-02 runs on PR #191 (the status line in Python) scored 7.5, 7.0, 7.13, 6.88, 7.13; 7.25, 6.75, 7.25, 6.88, 7.0; 7.63, 6.88, 7.38, 7.0, 7.13; and 7.63, 7.0, 7.25, 6.75, 7.25. Every seat rated the status line easy. The places they named under Locality and Self-sufficiency are filed in `todo.md` under 0.1.0, except `entries.py`'s heuristics over Claude Code's transcript format, which the seats scored as the problem's own difficulty. lilleman decided the same day to ship that PR under the floor. The 2026-10-02 runs on PR #194 (each cycle's transcript archived) scored 8.0, 7.25, 7.38, 7.13, 7.5 at 6ccd5b1 and 7.75, 7.13, 7.25, 7.0, 7.25 at d104ea0, both at the floor, every seat naming `archive` as the unit it would least want to modify. On 2026-10-02, applying `todo.md`'s bar deleted every place these scoring runs filed except `todo.md` items 13 and 17. The 2026-10-02 runs on PR #196 (`todo.md` as one scored table) scored 7.63, 6.88, 7.25, 6.88, 7.13 at c0dba66; 7.5, 6.88, 7.13, 6.75, 7.0 at 798dfd7; and 7.5, 7.0, 7.0, 6.75, 7.0 at b712076. Under Self-sufficiency, every seat named larv-review §3 and the agents, which a reader follows only with `CLAUDE.md` open. lilleman decided the same day to ship that PR under the floor; the place filed is `todo.md` item 13. The 2026-10-02 run on PR #198 (a usage limit waited out) scored 7.63, 6.88, 7.38, 6.75, 7.13 at 8e85033. Under Self-sufficiency, every seat named larv-review §3, which `todo.md` item 13 covers; under Locality, they named `archive`'s invariants spread over `session.py` and `run.py`, `rank_todo.py` reaching into `premises.sections`, and `stopped` comparing reason strings, each under `todo.md`'s bar and not filed. lilleman decided the same day to ship that PR under the floor. The 2026-10-03 runs on PR #202 (the judge reads the project's records) scored 7.75, 7.13, 7.25, 7.0, 7.25 in the first round and 7.5, 7.0, 7.0, 6.75, 7.0 in the eighth; between them a dimension moved by up to 0.4 on near-identical code. Under Self-sufficiency every seat named larv-review §3 and the agents leaning on `CLAUDE.md`, the Claude Code flags left unexplained, and the judge's contract spread over its prompt, schema, parser and `--help`; under Shape, the names "record", "verdict" and "judge" each over two things, and `loop_claude/` hosting modules `rank_todo.py` shares. lilleman decided the same day to ship that PR under the floor and to do those places next: `todo.md` items 13, 17, 42, 43 and 44, ranked after item 41. Valid until the next scoring run, which uses the same four seats. ## loop-claude: each project's model lives in `~/.claude/loop-claude-models.json`, which only loop-claude writes diff --git a/todo.md b/todo.md index 5ef90c0e..fd647819 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 9` -`Next ID = 42` +`Next ID = 45` | Goal | W | |---|---| @@ -25,8 +25,12 @@ | ID | Release | Exempt | Item | R | S | A | G | Goals | Score | |---|---|---|---|---|---|---|---|---|---| | 41 | 0.1.0 | defect | **Accept a judge's quote that elides with an ellipsis when its fragments appear in the transcript in order, and tell the judge to quote one passage.** | 2 | 2 | 10 | 10 | 4, 4.2 | 30.9 | +| 17 | 0.1.0 | decision | **Make `JUDGE_RULES` and the Claude Code flags `loop-claude` passes readable without `CLAUDE.md` or Claude Code's docs open.** | 1 | 2 | 10 | 9 | 4, 4.1 | 30.6 | +| 13 | 0.1.0 | decision | **Make larv-review §3 applicable on its own, cite its rules by name, and say where a pass's round count is recorded.** | 3 | 5 | 10 | 10 | 4, 4.1 | 29.1 | | 1 | 0.1.0 | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 3 | 5 | 8 | 9 | 2, 3 | 27.8 | -| 13 | 0.1.0 | decision | **Make larv-review §3 applicable on its own, cite its rules by name, and say where a pass's round count is recorded.** | 3 | 5 | 6 | 7 | 4.1 | 15.6 | +| 42 | 0.1.0 | decision | **Give the judge's contract one home, so its prompt, reply schema, parser and `--help` cannot drift apart.** | 3 | 4 | 9 | 9 | 4, 4.1 | 26.1 | +| 44 | 0.1.0 | decision | **Move the modules `rank_todo.py` shares out from under `loop_claude/`, keeping them inside reload's fingerprint.** | 2 | 2 | 8 | 8 | 4, 4.1 | 24.2 | +| 43 | 0.1.0 | decision | **Give "record", "verdict" and "judge" one meaning each across loop-claude, larv-review and workflow-bench.** | 2 | 3 | 8 | 8 | 4, 4.1 | 24.0 | | 23 | 0.1.0 | | **Launch a principles auditor only for a principles file the project shows applies, and rerun only the reviewer whose finding a fix answers.** | 3 | 4 | 7 | 8 | 4.4 | 13.5 | | 40 | 0.1.0 | | **Render tool input in the judged transcript with its non-ASCII characters as written, so the judge's quotes of it match the transcript.** | 2 | 1 | 5 | 6 | 4.2 | 13.0 | | 21 | 0.1.0 | | **Give `settings.json`'s model one writer, and sort its keys.** | 3 | 3 | 6 | 7 | 4.3 | 12.9 | @@ -35,7 +39,6 @@ | 5 | 0.1.0 | decision | **Key a project on its checkout's full path, and refuse to start while another session uses that key.** | 5 | 5 | 5 | 6 | 4.1 | 10.5 | | 4 | 0.1.0 | | **Name each chunk's archive folder by the chunk's start time, so `/` lists chunks in the order they ran.** | 3 | 2 | 4 | 3 | 2 | 9.8 | | 29 | 0.1.0 | | **Make the contributor a standing member of every project's audience, unless its `## Audience` says maintainability does not matter.** | 2 | 2 | 3 | 5 | 4.1, 4.4 | 9.1 | -| 17 | 0.1.0 | decision | **Make `JUDGE_RULES` and the Claude Code flags `loop-claude` passes readable without `CLAUDE.md` or Claude Code's docs open.** | 1 | 2 | 3 | 4 | 4.1 | 9.0 | | 6 | 0.1.0 | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 5 | 5 | 4 | 5 | 4.1 | 7.4 | | 39 | 0.1.0 | principle | **Sort each Python file's imports by the first name each binds.** | 2 | 3 | 3 | 3 | 4.1 | 6.6 | @@ -45,15 +48,31 @@ On 2026-10-03 the log project's loop exited 1: "the judge failed three times running: the judge quoted \"**Decision for you:** security, … ... I recommend one more round of each ... I recommend skipping it: …\", which is not in the transcript". Each fragment the judge joined with " ... " is in the rendered transcript; `grounded` matches the evidence as one contiguous string, so a correct interrupt was rejected three times and the human was never asked. The archive is `~/.claude/loop-claude-transcripts/log/dbac9d7096282d2bc6c38fc8c03cd74b50d29b75080b1f647c0f305a088db894/5d8c9152cdcd91e90dfd2773cd81c9e64bcd412ff148c5cf19e2a728ceee5028.verdict.md`. Fix both ends: `grounded` splits on `...` and `…` and finds the fragments in order, and the `evidence` description asks for one contiguous passage. +### 17. Make `JUDGE_RULES` and the Claude Code flags `loop-claude` passes readable without `CLAUDE.md` or Claude Code's docs open. + +The 2026-10-02 scoring runs on PR #191 named both under Self-sufficiency: the judge's rules use "chunk" and "a release ready to cut" from `CLAUDE.md` with no link, and `--resume`, `--session-id`, `--no-session-persistence`, `--json-schema` and stream-json's result event go unexplained in `worker.py` and `judge.py`. + +### 13. Make larv-review §3 applicable on its own, cite its rules by name, and say where a pass's round count is recorded. + +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. + ### 1. Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume. It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost disk loses every unattended run's record. Back it up only to a destination private to me and encrypted at rest: the worker runs with permissions bypassed, so the archived tool results can hold credentials it read. 2026-10-02, the human: ai-sandbox is the VM `loop-claude` will run on, hosted on the server bender. bender-infra, the infrastructure-as-code project that manages bender, will back up ai-sandbox's data volume once ai-sandbox is rebuilt. The item waits for the human to say the rebuild has landed. Before writing the README line, check that `~/.claude` lives on that volume and that the backup is private and encrypted at rest. -### 13. Make larv-review §3 applicable on its own, cite its rules by name, and say where a pass's round count is recorded. +### 42. Give the judge's contract one home, so its prompt, reply schema, parser and `--help` cannot drift apart. -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. +The 2026-10-03 scoring runs on PR #202 named it under Self-sufficiency and Locality: what a reply means is stated in `JUDGE_RULES`, the `Reply` field descriptions, `verdict_from`'s precedence, `transition`'s cap and the `--help` docstring, and the repeated-question rule lives only in the prompt. Derive or test-tie each to one definition; the interrupt wording moves out of `transition` into `run.ask`. + +### 44. Move the modules `rank_todo.py` shares out from under `loop_claude/`, keeping them inside reload's fingerprint. + +Named under Shape by the same runs: `failure.py`, `file_writes.py` and `markdown_sections.py` sit in loop-claude's package because `reload.fingerprint` hashes only `loop_claude/**/*.py`, and nothing at the package says a second tool depends on them. Widen the fingerprint to a named shared package. + +### 43. Give "record", "verdict" and "judge" one meaning each across loop-claude, larv-review and workflow-bench. + +Named under Shape by the same runs: loop-claude's records are `AGENTS.md` and `docs/decisions.md`, larv-review's "record" is a decision-log entry or plan item older than the chunk; `Verdict` is the judge's ruling and `.verdict.md` also holds stop reasons; `cycle/judge.py` and `workflow-bench/judge.py` are different judges. ### 23. Launch a principles auditor only for a principles file the project shows applies, and rerun only the reviewer whose finding a fix answers. @@ -89,10 +108,6 @@ Today the folder is the SHA-256 of the transcript's first timestamped line, whic State that in `CLAUDE.md`'s goals-and-audience rule, and have larv-review's comprehension floor name the contributor as the reader it serves. The floor then gates every chunk while the contributor stands, and a project that drops them skips it. -### 17. Make `JUDGE_RULES` and the Claude Code flags `loop-claude` passes readable without `CLAUDE.md` or Claude Code's docs open. - -The 2026-10-02 scoring runs on PR #191 named both under Self-sufficiency: the judge's rules use "chunk" and "a release ready to cut" from `CLAUDE.md` with no link, and `--resume`, `--session-id`, `--no-session-persistence`, `--json-schema` and stream-json's result event go unexplained in `worker.py` and `judge.py`. - ### 6. Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay. Claude Code owns that file and writes it. `trust` reads it, changes it and writes it back, so a write that lands in between is lost. -- 2.52.0 From 2cd26461e8ba191b13bbca1f60f2e00522e3d126 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 15:43:04 +0200 Subject: [PATCH 20/20] Answer the last prose and stability nits: the judge's first rule and evidence wording, the floor entry's new paragraph, rewrap --help --- bin/loop_claude/cycle/judge.py | 4 ++-- bin/loop_claude/loop/main.py | 10 +++++----- docs/decisions.md | 6 ++++-- todo.md | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index b3756cd9..b3857aac 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -16,7 +16,7 @@ JUDGE_PROMPT_CHARS = 400000 JUDGE_RULES = ( "Decide whether the human must now be interrupted. interrupt=true when any of these appear:\n" "- the agent asks the human anything, seeks approval, or says a decision is the human's, and neither " - "README.md nor the project's records settle the matter, or a [loop] line already answered it\n" + "README.md nor the project's records settle the matter, or it asks again a question a [loop] line already answered\n" "- it carried on under an assumption that decides the deliverable, that the human could " "reasonably reject and that neither README.md nor the project's records settle; a caveat about " "transient state it then handled is not one\n" @@ -43,7 +43,7 @@ JUDGE_RULES = ( @dataclasses.dataclass(frozen=True) class Reply: answer: str = dataclasses.field(metadata={"description": "With interrupt false, the passage of README.md or the project's records that answers the agent's question, quoted verbatim. Empty otherwise."}) - evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the transcript line the verdict rests on: what triggers the interrupt, what the agent asked for a quoted answer, else what shows the chunk finished or the work remaining."}) + evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the transcript line the verdict rests on: what triggers the interrupt; for a quoted answer, the agent's question; else what shows the chunk finished or the work remaining."}) finished: bool interrupt: bool question: str = dataclasses.field(metadata={"description": "With interrupt true, the single question to put to the human. With a quoted answer, the agent's question that the answer field answers. Empty otherwise."}) diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 305ec16e..9b3d74dd 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -52,11 +52,11 @@ Exit 1, saying why, when: - 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 or quotes an answer without a question, or quotes a line the transcript does not hold. A usage limit is not - a failure, and restarts the count of three: the worker or the judge is retried 2 minutes after the - limit resets, or every 10 minutes when the reset time is unknown or more than 2 minutes past. The - judge's reply gives its reset time only as text, so the judge is always retried every 10 minutes. - stderr says when the next try is due. + interrupts or quotes an answer without a question, or quotes a line the transcript does not hold. + A usage limit is not a failure, and restarts the count of three: the worker or the judge is + retried 2 minutes after the limit resets, or every 10 minutes when the reset time is unknown or + more than 2 minutes past. The judge's reply gives its reset time only as text, so the judge is + always retried every 10 minutes. stderr says when the next try is due. 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 diff --git a/docs/decisions.md b/docs/decisions.md index c812f76f..626cd016 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -8,7 +8,7 @@ 2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. Valid while the worker's self-report stays unreliable. -2026-10-01, lilleman: the judge reads `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); its bar becomes whether the README or those files discriminate. 2026-10-03, implemented: when the README's premises or those files answer the worker's question, the judge quotes the answer verbatim and the worker resumes with it. The judge then sees the quote as a `[loop]` line. The worker asking it again shows the quote did not settle it, and the judge sends it to the human. A backstop of three quoted answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so the worker cannot loop unattended (goal 4.4); the fourth question that the README's premises or those files answer in one cycle goes to the human with the judge's quote. The count holds through an interrupt, so each later such question that cycle costs one interrupt too. Valid while the worker writes records only in a worktree, as `CLAUDE.md` → "Working with the codebase" has it, so the records the judge reads from the checkout root are merged ones. +2026-10-01, lilleman: the judge reads `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2); its bar becomes whether the README or those files discriminate. 2026-10-03, implemented: when the README's premises or those files answer the worker's question, the judge quotes the answer verbatim and the worker resumes with it. The judge then sees the quote as a `[loop]` line. The worker asking it again shows the quote did not settle it, and the judge sends it to the human. A backstop of three quoted answers per cycle bounds what the judge misses, such as a reworded repeat or a worker asking without end, so the worker cannot loop unattended (goal 4.4); the fourth question that the README's premises or those files answer in one cycle goes to the human with the judge's quote. An interrupt does not reset the count, so every later question those files answer in that cycle also goes to the human. Valid while the worker writes records only in a worktree, as `CLAUDE.md` → "Working with the codebase" has it, so the records the judge reads from the checkout root are merged ones. ## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it @@ -32,7 +32,9 @@ ## comprehension floor: every dimension and the overall at 7.0 or above, and 0.1.0 waits on it -2026-09-27, lilleman, restating the 2026-09-24 target and extending it to the overall. Serves goal 4. The 2026-09-28 run, Junior A, Mid A, the maintainability senior and the inherited architect at depth 1 over every non-test file, blind to `todo.md` and this log, scored Navigation 7.25, Locality 6.0, Shape 6.5, Self-sufficiency 6.25, overall 6.25; on 2026-09-26 they were 7.75, 6.25, 7.0, 6.75, 6.75. Every seat scored Locality 6, and three of four named `run_cycle`'s three-way return and larv-review's re-entry rules, split across the passes on 2026-09-28. The same seats on `rebuild` scored 7.5, 6.63, 6.88, 6.5, 7.0 at 37edc9a, later that day, 7.5, 6.75, 6.88, 6.75, 7.0 at 7f9de5c, 7.38, 6.25, 6.88, 6.75, 6.88 at 2f9ab2f on 2026-09-29, Locality lowest again and every seat naming the reload state and the two retry counters, and 7.5, 7.0, 7.25, 6.75, 7.13 at 2c74bbc later that day, Self-sufficiency lowest and every seat naming the round's definition split across larv-review's two files, and 7.38, 6.75, 7.25, 6.5, 6.88 at 8585257 on 2026-10-01, lowering every dimension but Shape, and the overall, Self-sufficiency lowest and every seat naming larv-review §3's round rules; the places it named under Self-sufficiency and Locality are filed in `todo.md` under 0.1.0, and a later scoring run may not score any dimension or the overall below its best run on `rebuild`, 2026-10-01, lilleman. `rebuild` merged into main under the floor at 8585257's scores, 2026-10-01, lilleman. The 2026-10-01 run on PR #182 (the loop state machine) scored 7.5, 6.5, 6.88, 6.25, 6.38; lilleman shipped that PR under the floor and below `rebuild`'s best run the same day, its places filed in `todo.md` under 0.1.0. The 2026-10-02 run on PR #187 (`loop_claude`'s names, the exit contract) scored 7.75, 7.25, 7.38, 6.88, 7.25 at 70362d0, every seat naming larv-review §3 under Self-sufficiency, and 7.63, 7.13, 7.38, 7.0, 7.13 at 1971dba later that day, the first run at the floor, with no dimension or the overall below its best run on `rebuild`. The 2026-10-02 runs on PR #191 (the status line in Python) scored 7.5, 7.0, 7.13, 6.88, 7.13; 7.25, 6.75, 7.25, 6.88, 7.0; 7.63, 6.88, 7.38, 7.0, 7.13; and 7.63, 7.0, 7.25, 6.75, 7.25. Every seat rated the status line easy. The places they named under Locality and Self-sufficiency are filed in `todo.md` under 0.1.0, except `entries.py`'s heuristics over Claude Code's transcript format, which the seats scored as the problem's own difficulty. lilleman decided the same day to ship that PR under the floor. The 2026-10-02 runs on PR #194 (each cycle's transcript archived) scored 8.0, 7.25, 7.38, 7.13, 7.5 at 6ccd5b1 and 7.75, 7.13, 7.25, 7.0, 7.25 at d104ea0, both at the floor, every seat naming `archive` as the unit it would least want to modify. On 2026-10-02, applying `todo.md`'s bar deleted every place these scoring runs filed except `todo.md` items 13 and 17. The 2026-10-02 runs on PR #196 (`todo.md` as one scored table) scored 7.63, 6.88, 7.25, 6.88, 7.13 at c0dba66; 7.5, 6.88, 7.13, 6.75, 7.0 at 798dfd7; and 7.5, 7.0, 7.0, 6.75, 7.0 at b712076. Under Self-sufficiency, every seat named larv-review §3 and the agents, which a reader follows only with `CLAUDE.md` open. lilleman decided the same day to ship that PR under the floor; the place filed is `todo.md` item 13. The 2026-10-02 run on PR #198 (a usage limit waited out) scored 7.63, 6.88, 7.38, 6.75, 7.13 at 8e85033. Under Self-sufficiency, every seat named larv-review §3, which `todo.md` item 13 covers; under Locality, they named `archive`'s invariants spread over `session.py` and `run.py`, `rank_todo.py` reaching into `premises.sections`, and `stopped` comparing reason strings, each under `todo.md`'s bar and not filed. lilleman decided the same day to ship that PR under the floor. The 2026-10-03 runs on PR #202 (the judge reads the project's records) scored 7.75, 7.13, 7.25, 7.0, 7.25 in the first round and 7.5, 7.0, 7.0, 6.75, 7.0 in the eighth; between them a dimension moved by up to 0.4 on near-identical code. Under Self-sufficiency every seat named larv-review §3 and the agents leaning on `CLAUDE.md`, the Claude Code flags left unexplained, and the judge's contract spread over its prompt, schema, parser and `--help`; under Shape, the names "record", "verdict" and "judge" each over two things, and `loop_claude/` hosting modules `rank_todo.py` shares. lilleman decided the same day to ship that PR under the floor and to do those places next: `todo.md` items 13, 17, 42, 43 and 44, ranked after item 41. Valid until the next scoring run, which uses the same four seats. +2026-09-27, lilleman, restating the 2026-09-24 target and extending it to the overall. Serves goal 4. The 2026-09-28 run, Junior A, Mid A, the maintainability senior and the inherited architect at depth 1 over every non-test file, blind to `todo.md` and this log, scored Navigation 7.25, Locality 6.0, Shape 6.5, Self-sufficiency 6.25, overall 6.25; on 2026-09-26 they were 7.75, 6.25, 7.0, 6.75, 6.75. Every seat scored Locality 6, and three of four named `run_cycle`'s three-way return and larv-review's re-entry rules, split across the passes on 2026-09-28. The same seats on `rebuild` scored 7.5, 6.63, 6.88, 6.5, 7.0 at 37edc9a, later that day, 7.5, 6.75, 6.88, 6.75, 7.0 at 7f9de5c, 7.38, 6.25, 6.88, 6.75, 6.88 at 2f9ab2f on 2026-09-29, Locality lowest again and every seat naming the reload state and the two retry counters, and 7.5, 7.0, 7.25, 6.75, 7.13 at 2c74bbc later that day, Self-sufficiency lowest and every seat naming the round's definition split across larv-review's two files, and 7.38, 6.75, 7.25, 6.5, 6.88 at 8585257 on 2026-10-01, lowering every dimension but Shape, and the overall, Self-sufficiency lowest and every seat naming larv-review §3's round rules; the places it named under Self-sufficiency and Locality are filed in `todo.md` under 0.1.0, and a later scoring run may not score any dimension or the overall below its best run on `rebuild`, 2026-10-01, lilleman. `rebuild` merged into main under the floor at 8585257's scores, 2026-10-01, lilleman. The 2026-10-01 run on PR #182 (the loop state machine) scored 7.5, 6.5, 6.88, 6.25, 6.38; lilleman shipped that PR under the floor and below `rebuild`'s best run the same day, its places filed in `todo.md` under 0.1.0. The 2026-10-02 run on PR #187 (`loop_claude`'s names, the exit contract) scored 7.75, 7.25, 7.38, 6.88, 7.25 at 70362d0, every seat naming larv-review §3 under Self-sufficiency, and 7.63, 7.13, 7.38, 7.0, 7.13 at 1971dba later that day, the first run at the floor, with no dimension or the overall below its best run on `rebuild`. The 2026-10-02 runs on PR #191 (the status line in Python) scored 7.5, 7.0, 7.13, 6.88, 7.13; 7.25, 6.75, 7.25, 6.88, 7.0; 7.63, 6.88, 7.38, 7.0, 7.13; and 7.63, 7.0, 7.25, 6.75, 7.25. Every seat rated the status line easy. The places they named under Locality and Self-sufficiency are filed in `todo.md` under 0.1.0, except `entries.py`'s heuristics over Claude Code's transcript format, which the seats scored as the problem's own difficulty. lilleman decided the same day to ship that PR under the floor. The 2026-10-02 runs on PR #194 (each cycle's transcript archived) scored 8.0, 7.25, 7.38, 7.13, 7.5 at 6ccd5b1 and 7.75, 7.13, 7.25, 7.0, 7.25 at d104ea0, both at the floor, every seat naming `archive` as the unit it would least want to modify. On 2026-10-02, applying `todo.md`'s bar deleted every place these scoring runs filed except `todo.md` items 13 and 17. The 2026-10-02 runs on PR #196 (`todo.md` as one scored table) scored 7.63, 6.88, 7.25, 6.88, 7.13 at c0dba66; 7.5, 6.88, 7.13, 6.75, 7.0 at 798dfd7; and 7.5, 7.0, 7.0, 6.75, 7.0 at b712076. Under Self-sufficiency, every seat named larv-review §3 and the agents, which a reader follows only with `CLAUDE.md` open. lilleman decided the same day to ship that PR under the floor; the place filed is `todo.md` item 13. The 2026-10-02 run on PR #198 (a usage limit waited out) scored 7.63, 6.88, 7.38, 6.75, 7.13 at 8e85033. Under Self-sufficiency, every seat named larv-review §3, which `todo.md` item 13 covers; under Locality, they named `archive`'s invariants spread over `session.py` and `run.py`, `rank_todo.py` reaching into `premises.sections`, and `stopped` comparing reason strings, each under `todo.md`'s bar and not filed. lilleman decided the same day to ship that PR under the floor. + +The 2026-10-03 runs on PR #202 (the judge reads the project's records) scored 7.75, 7.13, 7.25, 7.0, 7.25 in the first round and 7.5, 7.0, 7.0, 6.75, 7.0 in the eighth; between them a dimension moved by up to 0.4 on near-identical code. Under Self-sufficiency every seat named larv-review §3 and the agents leaning on `CLAUDE.md`, the Claude Code flags left unexplained, and the judge's contract spread over its prompt, schema, parser and `--help`; under Shape, that "record", "verdict" and "judge" each name two things, and that `loop_claude/` holds modules `rank_todo.py` also uses. lilleman decided the same day to ship that PR under the floor and to fix those places next: `todo.md` items 13, 17, 42, 43 and 44, ranked after item 41. Valid until the next scoring run, which uses the same four seats. ## loop-claude: each project's model lives in `~/.claude/loop-claude-models.json`, which only loop-claude writes diff --git a/todo.md b/todo.md index fd647819..4cfbf3af 100644 --- a/todo.md +++ b/todo.md @@ -64,7 +64,7 @@ It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost ### 42. Give the judge's contract one home, so its prompt, reply schema, parser and `--help` cannot drift apart. -The 2026-10-03 scoring runs on PR #202 named it under Self-sufficiency and Locality: what a reply means is stated in `JUDGE_RULES`, the `Reply` field descriptions, `verdict_from`'s precedence, `transition`'s cap and the `--help` docstring, and the repeated-question rule lives only in the prompt. Derive or test-tie each to one definition; the interrupt wording moves out of `transition` into `run.ask`. +The 2026-10-03 scoring runs on PR #202 named it under Self-sufficiency and Locality: what a reply means is stated in `JUDGE_RULES`, the `Reply` field descriptions, `verdict_from`'s precedence, `transition`'s cap and the `--help` docstring, and the repeated-question rule lives only in the prompt. Derive each from one definition, or tie it to that definition with a test; the interrupt wording moves out of `transition` into `run.ask`. ### 44. Move the modules `rank_todo.py` shares out from under `loop_claude/`, keeping them inside reload's fingerprint. -- 2.52.0