From 23dac2c1d1996fe86ba43070beac8e03075c6f9f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 23:11:29 +0200 Subject: [PATCH 01/10] Archive each judge reply the loop rejects, with why and the reply --- CHANGELOG.md | 1 + bin/loop_claude/cycle/judge.py | 15 +++++++++---- bin/loop_claude/cycle/retry.py | 5 ++++- bin/loop_claude/cycle/run.py | 11 +++++++-- bin/loop_claude/loop/main.py | 4 +++- bin/loop_claude/test_black_box.py | 2 +- bin/loop_claude/test_loop_claude.py | 35 +++++++++++++++++++++++++++-- bin/transcript_archive/outcomes.py | 6 +++++ todo.md | 5 ----- 9 files changed, 68 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e560a603..0311b096 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- `loop-claude` archives each judge reply it rejects in the chunk's `.outcomes.md`, with why and the reply as json: a reply that misses or mistypes a field, or whose passage the transcript does not hold. Before, such a reply reached only stderr, so a run that exited 1 overnight could not say what the judge had returned. stderr no longer repeats the reply after its reason. If archiving fails, `loop-claude` exits 1, as for any archive. - `workflow-bench/bench.py` gives each run a fixed list of allowed tools. Before, it skipped every permission check. A run may launch agents, run `/security-review`, edit its clone (not the clone's `.git/` or `.claude/`) and its report, and read its clone and the copy of `~/.claude` it benches. For git it gets one command, `workflow-bench/review_git.py`, and no bare `git`. The wrapper runs `log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit -m` on the run's clone, whatever the working directory. It allows only the options it lists for each, and refuses an argument that names a path outside the clone. git runs with no global or system config, hook, pager or editor. A run loads no settings or MCP servers from `~/.claude` or from the case's clone, so their hooks and extra directories do not apply to it. Every other call is denied. Expect a benched review that needs another git command, or to run a project's code or tests, to say in its report that it could not. - Every goal in `README.md` → Goals is marked `**Maintain:**`, a state to hold, or `**Achieve:**`, a direction to pursue. Each achieve goal has a signal, a counter-signal and a one-line reason under it. A change that breaks a maintain goal is redesigned or dropped, whatever it scores: `rules/todo-items.md` says so, and larv-review's goal alignment step no longer merges such a PR. `rules/goals-and-audience.md` states the form for every project's README. Expect larv-review to stop a PR on a maintain goal where it asked you before. - Reshape every project's `todo.md` to the new shape below: until it is reshaped, that is the project's only work, as it is while README.md lacks Goals and Audience, and `rank_todo.py` says so. First move every machine to this release: an older release rejects the new formula, so it fails on every reshaped `todo.md`. Then mark the README's goals `**Maintain:**` or `**Achieve:**`, score each item's L, E and I, and set a bar on the new scale below the score of every item to keep, since the old bar would drop most items. Until then, an old-shape `todo.md` still ranks by its own formula and weights. diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index 48eaa97d..697f5f64 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -74,6 +74,12 @@ JUDGE_SCHEMA = { } +@dataclasses.dataclass(frozen=True) +class Rejected(Failure): + """The judge replied, and loop-claude refused the reply for the reason; reply is what the judge returned, as json.""" + reply: str + + @dataclasses.dataclass(frozen=True) class Interrupt: evidence: str @@ -127,8 +133,9 @@ def verdict_from(output: object) -> Verdict | Failure: return Unfinished(output["evidence"], bundled, output["escalation"]) -def judge(root: str, task: str, premises: str, records: str, rendered_transcript: str, rung: Rung, effects: Effects) -> Verdict | Stop: - return retried("judge", lambda: judge_once(root, task, premises, records, rendered_transcript, rung, effects), effects) +def judge(root: str, task: str, premises: str, records: str, rendered_transcript: str, rung: Rung, effects: Effects, keep: typing.Callable[[Failure], Stop | None]) -> Verdict | Stop: + """keep sees each failure of a judge run, such as a Rejected reply, before the retry.""" + return retried("judge", lambda: judge_once(root, task, premises, records, rendered_transcript, rung, effects), effects, keep) def judge_once(root: str, task: str, premises: str, records: str, rendered_transcript: str, rung: Rung, effects: Effects) -> Verdict | Failure | Limited: @@ -159,9 +166,9 @@ def run_judge(root: str, args: list[str], prompt: str, shown: str, quotable: str return reply verdict = verdict_from(structured_output(reply)) if isinstance(verdict, Failure): - return Failure(f"{verdict.reason}; it replied: {json.dumps(reply, ensure_ascii=False)}") + return Rejected(verdict.reason, json.dumps(reply, ensure_ascii=False)) if not grounded(verdict.evidence, shown): - 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 "")) + return Rejected(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 ""), json.dumps(reply, ensure_ascii=False)) if isinstance(verdict, QuotedAnswer) and not verbatim(verdict.answer, quotable): return Interrupt(verdict.evidence, verdict.question) if isinstance(verdict, Unfinished) and verdict.escalation and not verbatim(verdict.escalation, shown): diff --git a/bin/loop_claude/cycle/retry.py b/bin/loop_claude/cycle/retry.py index 32c16aa3..e2272d76 100644 --- a/bin/loop_claude/cycle/retry.py +++ b/bin/loop_claude/cycle/retry.py @@ -14,7 +14,8 @@ RETRY_DELAY = 60 UNKNOWN_RESET_POLL = 600 -def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effects: Effects) -> T | Stop: +def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effects: Effects, keep: typing.Callable[[Failure], Stop | None] = lambda failure: None) -> T | Stop: + """The attempt's result, retried on a failure; keep sees each failure before the retry, and a Stop from it ends the retrying.""" failures = 0 while True: result = attempt() @@ -28,6 +29,8 @@ def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effec continue if not isinstance(result, Failure): return result + if stop := keep(result): + return stop failures += 1 if failures == FAILURES_RUNNING: return Stop(1, f"the {who} failed three times running: {result.reason}") diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index 6ff50c6c..d0d67520 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -7,7 +7,7 @@ from transcript_archive.write import archive from claude_code.session import delete_session, Session, session_open, transcript_file from loop_claude.effects import Effects from failure import Failure -from loop_claude.cycle.judge import Finished, Interrupt, judge, QuotedAnswer, Unfinished +from loop_claude.cycle.judge import Finished, Interrupt, judge, QuotedAnswer, Rejected, Unfinished from loop_claude.cycle.interrupt import interrupt from loop_claude.routing import judge_rung from transcript_archive import outcomes @@ -115,10 +115,17 @@ 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, cycle.records, render(entries), judge_of(cycle), cycle.effects) + verdict = judge(cycle.root, cycle.task, cycle.premises, cycle.records, render(entries), judge_of(cycle), cycle.effects, lambda failure: keep_rejection(cycle, transcript_path, failure)) return verdict if isinstance(verdict, Stop) else Ruled(verdict) +def keep_rejection(cycle: Cycle, transcript_path: str, failure: Failure) -> Stop | None: + """Archives a judge reply that loop-claude refused, so the archive answers why a run exited 1 or a verdict took a retry.""" + if isinstance(failure, Rejected) and (unkept := archive(cycle.project_archive, transcript_path, cycle.task, outcomes.rejected(failure.reason, failure.reply, str(judge_of(cycle))), cycle.effects.now())): + return Stop(1, unkept.reason) + return None + + def ask(cycle: Cycle, transcript_path: str, ruling: Interrupt | QuotedAnswer) -> HumanAnswered | Stop: question = question_for(ruling) # Archived now, so the transcript the question was asked on is kept with it; the human's answer then grows the transcript. diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 2532ac11..cce7eb34 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -30,7 +30,9 @@ copied to $LOOP_CLAUDE_TRANSCRIPTS///.jsonl (default line with a timestamp, the same for every cycle of a chunk. Beside the copy, .outcomes.md holds the verdict, with the transcript passage the judge rested it on, any passage it quoted to show an escalation trigger fired, and the judge's rung; each answer the judge quoted, with the -question it answers; and why the loop stopped. Each of these opens with its UTC time. Claude Code keeps a folder per session beside its transcript, holding the subagents' +question it answers; each judge reply the loop rejected, with why and the reply as json; and why +the loop stopped. Each of these opens with its UTC time. Claude Code keeps a folder per session +beside its transcript, holding the subagents' transcripts among other files; that folder, and every other file named after the session except the transcript, are copied into /session/. A file there is replaced only by a version that grew from it. A file Claude Code rewrote lands beside its copy as .. diff --git a/bin/loop_claude/test_black_box.py b/bin/loop_claude/test_black_box.py index 28c62f32..8faecb58 100644 --- a/bin/loop_claude/test_black_box.py +++ b/bin/loop_claude/test_black_box.py @@ -480,7 +480,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 printed no json reply; it printed: nothing\n", run.stderr) - 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}}') + self.assertEqual(run.stderr.strip().splitlines()[-1], 'the judge failed three times running: the judge\'s reply has no answer of type string') def test_waits_out_a_usage_limit_which_ends_a_run_of_failures(self): checkout = Checkout(self) diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index ef450370..5d2094d5 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -231,6 +231,26 @@ class Cycles(unittest.TestCase): self.assertEqual(run.run_cycle(self.cycle(fake)), Stop(130, "")) self.assertEqual(self.archived_outcomes(), ["Task: Do it.\n\n2026-09-21T14:13:20Z Stopped: Ctrl-C\n\nWorker: worker-model\n", "Task: Do it.\n\n2026-09-21T14:13:20Z Stopped: the judge failed three times running: the judge exited 1\n\nWorker: worker-model\n"]) + def test_each_judge_reply_the_loop_rejects_is_archived_with_why_beside_the_verdict_that_follows(self): + unfilled = ran(json.dumps({"structured_output": {"interrupt": False}})) + misquoted = judged("finished", evidence="never said") + fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[unfilled, misquoted, judged("finished")]) + self.assertEqual(run.run_cycle(self.cycle(fake)), Finished("working")) + stamp = "2026-09-21T14:13:20Z" + self.assertEqual(self.archived_outcomes(), [ + "Task: Do it.\n\n" + f"{stamp} Judge reply rejected: the judge's reply has no answer of type string\n\nReply:\n> {unfilled.stdout}\n\nJudge: judge-model\n\n" + f"{stamp} Judge reply rejected: the judge quoted 'never said', which is not in the transcript\n\nReply:\n> {misquoted.stdout}\n\nJudge: judge-model\n\n" + f"{stamp} Verdict: finished\n\nEvidence:\n> working\n\nJudge: judge-model\nWorker: worker-model\n"]) + + def test_archives_the_judges_rejected_replies_though_it_fails_three_times_running(self): + unfilled = ran(json.dumps({"structured_output": {"interrupt": False}})) + fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[unfilled] * 3) + self.assertEqual(run.run_cycle(self.cycle(fake)).code, 1) + [archived] = self.archived_outcomes() + self.assertEqual(archived.count(f"Reply:\n> {unfilled.stdout}\n"), 3) + self.assertIn("Stopped: the judge failed three times running", archived) + def test_archives_each_chunks_session_folder_replacing_a_copy_only_with_what_grew_from_it(self): folder = self.paths.claude_code_transcripts / "-fake" / str(self.session.id) (folder / "subagents" / "workflows").mkdir(parents=True) @@ -341,6 +361,16 @@ class Retried(unittest.TestCase): self.assertEqual(retry.retried("judge", lambda: Failure("no"), fake.effects()), Stop(1, "the judge failed three times running: no")) self.assertEqual(fake.calls, [("sleep", 60), ("sleep", 60)]) + def test_hands_each_failure_to_the_keeper_and_stops_where_it_stops(self): + kept = [] + def keep(failure): + kept.append(failure) + return Stop(1, "no room") if len(kept) == 2 else None + fake = FakeEffects() + self.assertEqual(retry.retried("judge", lambda: Failure("no"), fake.effects(), keep), Stop(1, "no room")) + self.assertEqual(kept, [Failure("no")] * 2) + self.assertEqual(fake.calls, [("sleep", 60)]) + def test_waits_out_a_usage_limit_which_ends_a_run_of_failures(self): fake = FakeEffects() results = [Failure("one"), Failure("two"), Limited(NOW + 3600, "limit"), Failure("three"), Limited(None, "limit"), Limited(NOW - 600, "limit"), Failure("four"), Failure("five"), Failure("six")] @@ -956,6 +986,7 @@ class ExitContract(unittest.TestCase): ("cycle/run.py", "work", "1", "f'claude left no transcript for session", "claude leaves no transcript"), ("cycle/run.py", "keep_answer", "1", "failure.reason", read), ("cycle/run.py", "rule", "1", "entries.reason", read), + ("cycle/run.py", "keep_rejection", "1", "unkept.reason", read), ("cycle/run.py", "ask", "1", "failure.reason", read), ("cycle/run.py", "close", "1", "failure.reason", read), ("cycle/run.py", "close", "1", "failure.reason", "a finished chunk's session cannot be deleted"), @@ -999,7 +1030,7 @@ class JudgeFailures(unittest.TestCase): ("verdict_from", 'f"the judge\'s reply has no {name}', field), ("verdict_from", "'the judge interrupted without a question'", unasked), ("verdict_from", "'the judge quoted an answer without a question'", unasked), - ("run_judge", "f'{verdict.reason}; it replied:", field), + ("run_judge", "verdict.reason", field), ("run_judge", "f'the judge quoted {verdict.evidence!r}, which is not in the transcript", "quotes a passage the transcript does not hold"), ("claude_reply", "f'could not start claude:", started), ("claude_reply", "proc.stderr.strip() or f'{who} exited", exited), @@ -1008,7 +1039,7 @@ class JudgeFailures(unittest.TestCase): found = [] for module in (judge, reply): functions = [node for node in ast.walk(ast.parse(pathlib.Path(module.__file__).read_text())) if isinstance(node, ast.FunctionDef)] - found += sorted((call.lineno, function.name, ast.unparse(call.args[0])) for function in functions for call in ast.walk(function) if isinstance(call, ast.Call) and getattr(call.func, "id", None) == "Failure") + found += sorted((call.lineno, function.name, ast.unparse(call.args[0])) for function in functions for call in ast.walk(function) if isinstance(call, ast.Call) and getattr(call.func, "id", None) in ("Failure", "Rejected")) self.assertEqual(len(found), len(clauses), found) for (_, function, reason), (want_function, reason_start, _) in zip(found, clauses): self.assertEqual(function, want_function) diff --git a/bin/transcript_archive/outcomes.py b/bin/transcript_archive/outcomes.py index 2420ca10..02c21757 100644 --- a/bin/transcript_archive/outcomes.py +++ b/bin/transcript_archive/outcomes.py @@ -8,6 +8,7 @@ FINISHED = "Verdict: finished" UNFINISHED = "Verdict: unfinished" INTERRUPTED = "Verdict: interrupt" ANSWERED = "Verdict: quoted answer" +REJECTED = "Judge reply rejected" # The file opens with the task, then a blank line, then the first stamped outcome. TASK_AT = re.compile(rf"\A{re.escape(TASK)}(.*?)\n\n{STAMPED} ", re.DOTALL) ANY_VERDICT_AT = re.compile(rf"^({STAMPED}) ({'|'.join(re.escape(verdict) for verdict in (FINISHED, UNFINISHED, INTERRUPTED, ANSWERED))})$", re.MULTILINE) @@ -41,6 +42,11 @@ def answered(question: str, sources: str, answer: str, evidence: str, judge: str return f"{ANSWERED}\n\n{question}\n\n{sources} says:\n{quoted(answer)}\n\nEvidence:\n{quoted(evidence)}\n\n{JUDGE}{judge}" +def rejected(why: str, reply: str, judge: str) -> str: + """A judge reply that loop-claude refused: why, and the reply as the judge returned it, as json.""" + return f"{REJECTED}: {why}\n\nReply:\n{quoted(reply)}\n\n{JUDGE}{judge}" + + def stepped_up(worker: str) -> str: """The rung the next cycle steps up to, archived as it steps, so a rerun after any exit resumes on it.""" return f"Stepped up\n\n{WORKER}{worker}" diff --git a/todo.md b/todo.md index 8b58dedf..665dc377 100644 --- a/todo.md +++ b/todo.md @@ -12,7 +12,6 @@ | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| -| 65 | 0.2.0 | | defect | **Archive each judge reply the loop rejects.** | 2 | 1 | 3 | 4 | 4 | 3 by 3 | 5.5 | | 153 | 0.2.0 | | decision | **Route the judge and the reviewers on the highest E + I in their chunk, an item the worker takes in included.** | 3 | 1 | 3 | 5 | 4 | 1.2 by 5 | 3.0 | | 161 | 0.2.0 | | | **Have loop-claude run a preflight script before each fresh worker and put its findings in the worker's prompt, so the worker no longer spends tool calls finding the chunk's mechanical facts.** | 4 | 2 | 3 | 7 | 6 | 1.1 by 4, 1.4 by 6, 1.5 by 6 | 2.9 | | 84 | 0.2.0 | | | **Check, at each release's scoring run, that seats in a paired ruling agree more often than two scoring runs on near-identical code do, as the paired-ruling decision assumes.** | 2 | 2 | 2 | 4 | 4 | 1.4 by 5 | 2.3 | @@ -83,10 +82,6 @@ ## Details -### 65. Archive each judge reply the loop rejects. - -A defect: goal 3, keeping unattended runs' transcripts backed up, does not hold while a rejected judge reply reaches only stderr. Raised by the principles audit of PR #215: the judge runs with `--no-session-persistence`, so the archive cannot answer the 3am question of why the loop rejected a verdict. - ### 153. Route the judge and the reviewers on the highest E + I in their chunk, an item the worker takes in included. The judge reports the L of an item the worker takes in, and `routing.stepped` lifts the worker to the rung it picks, but the judge and the reviewers route on the routed item's E + I alone, which the archived route line holds. So when the worker takes in an item whose defects would escape further or break more, the judge and the reviewers stay on a lower rung than that item needs: a missed interrupt lets the worker settle a decision that is lilleman's (goal 1.2), and a weaker review lets a defect through (goal 1.1). The judge must report the highest E + I taken in too, and the route must carry it, archived so a rerun keeps it; loop-claude then hands the reviewers' rung it picks to the worker's prompt and environment. -- 2.52.0 From de8d602d0c022fb79aeb5bc6ad97b365885f3ec7 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 23:11:40 +0200 Subject: [PATCH 02/10] Record the chunk's reading cost --- docs/reading-cost.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/reading-cost.md b/docs/reading-cost.md index bd07ab08..08349e57 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -554,3 +554,18 @@ Read most (opens and searches): - `bin/markdown_text.py` 2 - `bin/repo_checks/test_import_order.py` 2 - `bin/score_outcomes/test_score_outcomes.py` 2 + +## Reading cost, chunk 02faae89d301, finished 2026-10-16T21:06:07Z + +46142 new input tokens before the first commit. + +Read most (opens and searches): + +- `todo.md` 5 +- `CHANGELOG.md` 3 +- `docs/decisions.md` 3 +- `README.md` 1 +- `principles/technical-principles.md` 1 +- `settings.json` 1 +- `workflow-bench/bench.py` 1 +- `workflow-bench/run-prompt.md` 1 -- 2.52.0 From 13672afc26f9e83f986cb24ea2e257d3d5762d13 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 23:12:07 +0200 Subject: [PATCH 03/10] Refresh the reading-cost figures of the lowering item --- todo.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/todo.md b/todo.md index 665dc377..cdfc5353 100644 --- a/todo.md +++ b/todo.md @@ -357,7 +357,7 @@ While `rank_todo.py` ranks two shapes, projects follow two sets of scoring rules ### 155. Lower the reading cost of the files a chunk reads most before its first commit. -`bin/reading-cost` on 2026-10-16: the median of the last 5 chunks is 213,946 new input tokens before their first commit, up from 139,738 for the 5 before them. Read most over the last 5, by opens and searches: `todo.md` 58, `README.md` 13, `CHANGELOG.md` 11, `bin/loop_claude/test_loop_claude.py` 11, `docs/decisions.md` 11, `AGENTS.md` 10, `bin/todo_table.py` 7, `agents/stability-reviewer.md` 6, `bin/loop_claude/cycle/judge.py` 5, `bin/rule_hook/test_rule_hook.py` 5. The chunk that ships this item runs `bin/reading-cost --reset`. +`bin/reading-cost` on 2026-10-16: the median of the last 5 chunks is 189,487 new input tokens before their first commit, up from 146,584 for the 5 before them. Read most over the last 5, by opens and searches: `todo.md` 51, `README.md` 12, `CHANGELOG.md` 11, `bin/loop_claude/test_loop_claude.py` 11, `AGENTS.md` 7, `bin/todo_table.py` 7, `docs/decisions.md` 7, `agents/stability-reviewer.md` 6, `bin/loop_claude/cycle/judge.py` 5, `bin/rule_hook/test_rule_hook.py` 5. The chunk that ships this item runs `bin/reading-cost --reset`. ### 1. Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume. -- 2.52.0 From 49004f22a29869e075cc5704997504a9a5f2136b Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 23:22:41 +0200 Subject: [PATCH 04/10] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1;=20test=20the=20exit=201=20a?= =?UTF-8?q?=20rejected=20reply=20that=20cannot=20be=20archived=20causes,?= =?UTF-8?q?=20and=20tidy=20keep's=20type=20and=20docstrings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/loop_claude/cycle/judge.py | 11 ++++++----- bin/loop_claude/cycle/retry.py | 2 +- bin/loop_claude/cycle/run.py | 6 +++--- bin/loop_claude/test_loop_claude.py | 9 +++++++++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index 697f5f64..b3f73c69 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -133,9 +133,9 @@ def verdict_from(output: object) -> Verdict | Failure: return Unfinished(output["evidence"], bundled, output["escalation"]) -def judge(root: str, task: str, premises: str, records: str, rendered_transcript: str, rung: Rung, effects: Effects, keep: typing.Callable[[Failure], Stop | None]) -> Verdict | Stop: - """keep sees each failure of a judge run, such as a Rejected reply, before the retry.""" - return retried("judge", lambda: judge_once(root, task, premises, records, rendered_transcript, rung, effects), effects, keep) +def judge(root: str, task: str, premises: str, records: str, rendered_transcript: str, rung: Rung, effects: Effects, keep: typing.Callable[[Rejected], Stop | None]) -> Verdict | Stop: + """keep sees each reply loop-claude rejected, the last of three included; a Stop from it ends the retrying.""" + return retried("judge", lambda: judge_once(root, task, premises, records, rendered_transcript, rung, effects), effects, lambda failure: keep(failure) if isinstance(failure, Rejected) else None) def judge_once(root: str, task: str, premises: str, records: str, rendered_transcript: str, rung: Rung, effects: Effects) -> Verdict | Failure | Limited: @@ -165,10 +165,11 @@ def run_judge(root: str, args: list[str], prompt: str, shown: str, quotable: str if isinstance(reply, Failure | Limited): return reply verdict = verdict_from(structured_output(reply)) + replied = json.dumps(reply, ensure_ascii=False) if isinstance(verdict, Failure): - return Rejected(verdict.reason, json.dumps(reply, ensure_ascii=False)) + return Rejected(verdict.reason, replied) if not grounded(verdict.evidence, shown): - return Rejected(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 ""), json.dumps(reply, ensure_ascii=False)) + return Rejected(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 ""), replied) if isinstance(verdict, QuotedAnswer) and not verbatim(verdict.answer, quotable): return Interrupt(verdict.evidence, verdict.question) if isinstance(verdict, Unfinished) and verdict.escalation and not verbatim(verdict.escalation, shown): diff --git a/bin/loop_claude/cycle/retry.py b/bin/loop_claude/cycle/retry.py index e2272d76..149d52d0 100644 --- a/bin/loop_claude/cycle/retry.py +++ b/bin/loop_claude/cycle/retry.py @@ -15,7 +15,7 @@ UNKNOWN_RESET_POLL = 600 def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effects: Effects, keep: typing.Callable[[Failure], Stop | None] = lambda failure: None) -> T | Stop: - """The attempt's result, retried on a failure; keep sees each failure before the retry, and a Stop from it ends the retrying.""" + """The attempt's result, retried on a failure; keep sees each failure, the last of three included, and a Stop from it ends the retrying.""" failures = 0 while True: result = attempt() diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index d0d67520..3fc69489 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -115,13 +115,13 @@ 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, cycle.records, render(entries), judge_of(cycle), cycle.effects, lambda failure: keep_rejection(cycle, transcript_path, failure)) + verdict = judge(cycle.root, cycle.task, cycle.premises, cycle.records, render(entries), judge_of(cycle), cycle.effects, lambda rejected: keep_rejection(cycle, transcript_path, rejected)) return verdict if isinstance(verdict, Stop) else Ruled(verdict) -def keep_rejection(cycle: Cycle, transcript_path: str, failure: Failure) -> Stop | None: +def keep_rejection(cycle: Cycle, transcript_path: str, rejected: Rejected) -> Stop | None: """Archives a judge reply that loop-claude refused, so the archive answers why a run exited 1 or a verdict took a retry.""" - if isinstance(failure, Rejected) and (unkept := archive(cycle.project_archive, transcript_path, cycle.task, outcomes.rejected(failure.reason, failure.reply, str(judge_of(cycle))), cycle.effects.now())): + if unkept := archive(cycle.project_archive, transcript_path, cycle.task, outcomes.rejected(rejected.reason, rejected.reply, str(judge_of(cycle))), cycle.effects.now()): return Stop(1, unkept.reason) return None diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index 5d2094d5..70faf288 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -243,6 +243,15 @@ class Cycles(unittest.TestCase): f"{stamp} Judge reply rejected: the judge quoted 'never said', which is not in the transcript\n\nReply:\n> {misquoted.stdout}\n\nJudge: judge-model\n\n" f"{stamp} Verdict: finished\n\nEvidence:\n> working\n\nJudge: judge-model\nWorker: worker-model\n"]) + def test_stops_when_a_rejected_reply_cannot_be_archived(self): + self.archive.parent.mkdir(parents=True) + self.archive.write_text("") + fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[ran(json.dumps({"structured_output": {"interrupt": False}})), judged("finished")]) + stop = run.run_cycle(self.cycle(fake)) + self.assertRegex(stop.reason, f"^could not archive the transcript: {self.archive}/[0-9a-f]{{64}}: Not a directory$") + self.assertEqual(stop.code, 1) + self.assertEqual(len(fake.made("claude")), 1) + def test_archives_the_judges_rejected_replies_though_it_fails_three_times_running(self): unfilled = ran(json.dumps({"structured_output": {"interrupt": False}})) fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[unfilled] * 3) -- 2.52.0 From c98b3e2e2163f8ca3bc868266e8de1106b1f3522 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 23:22:41 +0200 Subject: [PATCH 05/10] =?UTF-8?q?Answer=20principles=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1;=20the=20same=20test=20answers?= =?UTF-8?q?=20it,=20and=20the=20reply's=20json=20is=20built=20once?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 084730cbe0926e974ef7ad8f9f9fcf8d52a60fea Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 23:22:41 +0200 Subject: [PATCH 06/10] =?UTF-8?q?Answer=20security=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1;=20nothing=20to=20answer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 3be800cb467786afade783b30fcaa3f284a1c8ac Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 23:22:41 +0200 Subject: [PATCH 07/10] =?UTF-8?q?Answer=20product-owner=20round=201:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=200=20=F0=9F=9F=A1;=20nothing=20to=20answer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From d9d007fa7a4b7488aa692bfb423d73b53b11d914 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 23:27:24 +0200 Subject: [PATCH 08/10] =?UTF-8?q?Answer=20prose=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1;=20list=20no=20kinds=20of=20re?= =?UTF-8?q?jected=20reply=20in=20the=20changelog,=20say=20rejected=20throu?= =?UTF-8?q?ghout,=20and=20rewrap=20the=20help=20paragraph?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- bin/loop_claude/cycle/judge.py | 3 +-- bin/loop_claude/cycle/retry.py | 2 +- bin/loop_claude/cycle/run.py | 2 +- bin/loop_claude/loop/main.py | 12 ++++++------ bin/transcript_archive/outcomes.py | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0311b096..0a35e41b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ ## Unreleased -- `loop-claude` archives each judge reply it rejects in the chunk's `.outcomes.md`, with why and the reply as json: a reply that misses or mistypes a field, or whose passage the transcript does not hold. Before, such a reply reached only stderr, so a run that exited 1 overnight could not say what the judge had returned. stderr no longer repeats the reply after its reason. If archiving fails, `loop-claude` exits 1, as for any archive. - `workflow-bench/bench.py` gives each run a fixed list of allowed tools. Before, it skipped every permission check. A run may launch agents, run `/security-review`, edit its clone (not the clone's `.git/` or `.claude/`) and its report, and read its clone and the copy of `~/.claude` it benches. For git it gets one command, `workflow-bench/review_git.py`, and no bare `git`. The wrapper runs `log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit -m` on the run's clone, whatever the working directory. It allows only the options it lists for each, and refuses an argument that names a path outside the clone. git runs with no global or system config, hook, pager or editor. A run loads no settings or MCP servers from `~/.claude` or from the case's clone, so their hooks and extra directories do not apply to it. Every other call is denied. Expect a benched review that needs another git command, or to run a project's code or tests, to say in its report that it could not. - Every goal in `README.md` → Goals is marked `**Maintain:**`, a state to hold, or `**Achieve:**`, a direction to pursue. Each achieve goal has a signal, a counter-signal and a one-line reason under it. A change that breaks a maintain goal is redesigned or dropped, whatever it scores: `rules/todo-items.md` says so, and larv-review's goal alignment step no longer merges such a PR. `rules/goals-and-audience.md` states the form for every project's README. Expect larv-review to stop a PR on a maintain goal where it asked you before. - Reshape every project's `todo.md` to the new shape below: until it is reshaped, that is the project's only work, as it is while README.md lacks Goals and Audience, and `rank_todo.py` says so. First move every machine to this release: an older release rejects the new formula, so it fails on every reshaped `todo.md`. Then mark the README's goals `**Maintain:**` or `**Achieve:**`, score each item's L, E and I, and set a bar on the new scale below the score of every item to keep, since the old bar would drop most items. Until then, an old-shape `todo.md` still ranks by its own formula and weights. @@ -14,6 +13,7 @@ - larv-review's principles audit is a pass of its own, and runs on every chunk that changes code, config or tests, not only on one with an architectural decision. A chunk of prose or planning alone skips it. - `rule-hook` refuses an Agent call that launches a reviewer, a comprehension seat or the security pass on a rung below the one `loop-claude` names for it, and takes no override: pass the model and effort the refusal names. - `score-outcomes` lists a project's score anchors: the shipped items its `docs/score-anchors.md` names for each level of L, E and I, each with what its chunk measured. `rules/todo-items.md` has a scorer compare a new item with them, and says how to choose two or three per level. Add the file to each project that merges with merge commits; elsewhere, score by the level descriptions in `rules/todo-items.md`. +- `loop-claude` archives each judge reply it rejects in the chunk's `.outcomes.md`, with the reason and the reply as json. Before, such a reply reached only stderr, so a run that exited 1 overnight could not say what the judge had returned. stderr now prints only the reason; the reply is in outcomes.md. If archiving fails, `loop-claude` exits 1. ## 0.1.0 diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index b3f73c69..2b5350f6 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -76,7 +76,7 @@ JUDGE_SCHEMA = { @dataclasses.dataclass(frozen=True) class Rejected(Failure): - """The judge replied, and loop-claude refused the reply for the reason; reply is what the judge returned, as json.""" + """A judge reply loop-claude rejected: reason says why, reply holds the reply as json.""" reply: str @@ -134,7 +134,6 @@ def verdict_from(output: object) -> Verdict | Failure: def judge(root: str, task: str, premises: str, records: str, rendered_transcript: str, rung: Rung, effects: Effects, keep: typing.Callable[[Rejected], Stop | None]) -> Verdict | Stop: - """keep sees each reply loop-claude rejected, the last of three included; a Stop from it ends the retrying.""" return retried("judge", lambda: judge_once(root, task, premises, records, rendered_transcript, rung, effects), effects, lambda failure: keep(failure) if isinstance(failure, Rejected) else None) diff --git a/bin/loop_claude/cycle/retry.py b/bin/loop_claude/cycle/retry.py index 149d52d0..ca4ba056 100644 --- a/bin/loop_claude/cycle/retry.py +++ b/bin/loop_claude/cycle/retry.py @@ -15,7 +15,7 @@ UNKNOWN_RESET_POLL = 600 def retried(who: str, attempt: typing.Callable[[], T | Failure | Limited], effects: Effects, keep: typing.Callable[[Failure], Stop | None] = lambda failure: None) -> T | Stop: - """The attempt's result, retried on a failure; keep sees each failure, the last of three included, and a Stop from it ends the retrying.""" + """The attempt's result, retried on a failure. keep sees each failure, the third running included; a Stop from keep ends the retrying.""" failures = 0 while True: result = attempt() diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index 3fc69489..b2a8b13a 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -120,7 +120,7 @@ def rule(cycle: Cycle, transcript_path: str) -> Ruled | Stop: def keep_rejection(cycle: Cycle, transcript_path: str, rejected: Rejected) -> Stop | None: - """Archives a judge reply that loop-claude refused, so the archive answers why a run exited 1 or a verdict took a retry.""" + """Archives a judge reply loop-claude rejected, so the archive shows what the judge returned before a retry or an exit 1.""" if unkept := archive(cycle.project_archive, transcript_path, cycle.task, outcomes.rejected(rejected.reason, rejected.reply, str(judge_of(cycle))), cycle.effects.now()): return Stop(1, unkept.reason) return None diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index cce7eb34..0f8e2157 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -30,12 +30,12 @@ copied to $LOOP_CLAUDE_TRANSCRIPTS///.jsonl (default line with a timestamp, the same for every cycle of a chunk. Beside the copy, .outcomes.md holds the verdict, with the transcript passage the judge rested it on, any passage it quoted to show an escalation trigger fired, and the judge's rung; each answer the judge quoted, with the -question it answers; each judge reply the loop rejected, with why and the reply as json; and why -the loop stopped. Each of these opens with its UTC time. Claude Code keeps a folder per session -beside its transcript, holding the subagents' -transcripts among other files; that folder, and every other file named after the session except -the transcript, are copied into /session/. A file there is replaced only by a version that -grew from it. A file Claude Code rewrote lands beside its copy as .. +question it answers; each judge reply the loop rejected, with the reason and the reply as json; +and why the loop stopped. Each of these opens with its UTC time. Claude Code keeps a folder per +session beside its transcript, holding the subagents' transcripts among other files; that folder, +and every other file named after the session except the transcript, are copied into +/session/. A file there is replaced only by a version that grew from it. A file Claude Code +rewrote lands beside its copy as .. Every claude loop-claude starts runs the project's model, saved per in ~/.claude/loop-claude-models.json and read each cycle, unless routing, below, puts the worker, diff --git a/bin/transcript_archive/outcomes.py b/bin/transcript_archive/outcomes.py index 02c21757..d987f9da 100644 --- a/bin/transcript_archive/outcomes.py +++ b/bin/transcript_archive/outcomes.py @@ -43,7 +43,7 @@ def answered(question: str, sources: str, answer: str, evidence: str, judge: str def rejected(why: str, reply: str, judge: str) -> str: - """A judge reply that loop-claude refused: why, and the reply as the judge returned it, as json.""" + """A judge reply loop-claude rejected, with the reason and the reply as json.""" return f"{REJECTED}: {why}\n\nReply:\n{quoted(reply)}\n\n{JUDGE}{judge}" -- 2.52.0 From dcc47e745cf8e389ad8033853ea79787766786bd Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 23:27:24 +0200 Subject: [PATCH 09/10] =?UTF-8?q?Answer=20principles=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1;=20nothing=20to=20answer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From e91221cab516927dd19aa4ace4e2ec1f0847364b Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 23:27:24 +0200 Subject: [PATCH 10/10] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1;=20nothing=20to=20answer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0