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