diff --git a/AGENTS.md b/AGENTS.md index 640a7ed5..8381c19e 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 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: a judge decides each interrupt and each quoted answer from the transcript, the README's premises, `AGENTS.md`, `docs/decisions.md` and `~/.claude/CLAUDE.md`, and holds a chunk open while an answer the human typed in it is recorded nowhere; 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 52e66790..033d3424 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- `loop-claude`'s judge reads your `~/.claude/CLAUDE.md` beside the project's `AGENTS.md` and `docs/decisions.md`. It no longer interrupts for a choice that file settles, and it answers the worker's questions from it. +- `loop-claude`'s judge holds a chunk open until each answer you typed in it that a later chunk could need is recorded. An answer counts as recorded once the README's goals or audience, `AGENTS.md`, `docs/decisions.md` or `~/.claude/CLAUDE.md` hold it. It also counts once the transcript shows the worker writing it into the README's goals or audience, `AGENTS.md`, `docs/decisions.md`, `todo.md` or a code comment. The worker writing to `~/.claude/CLAUDE.md` does not count, since new rules there are yours. The resumed worker is told this rule. +- `loop-claude` archives each answer the judge quotes, with the question it answers and its UTC time, in `.outcomes.md`. - larv-review keeps its three-round cap across a resumed session. It closes each review round with a commit naming the pass and the round, empty when the round changed nothing, and counts rounds from the branch's own commits. - larv-review runs `/security-review` in a subagent, so the run goes on to the next pass without you prompting it. - larv-review asks once before the full security scan: it states the evidence and its recommendation, and `claude-security`'s cost prompt is the ask. diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index 130544b9..c9eb7ea1 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -54,7 +54,7 @@ def judge_prompt(task: str, premises: str, records: str, rendered_transcript: st """The prompt, and the part of the transcript it shows, which the judge's evidence must quote.""" 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 records: the project's working rules and decisions, then the human's rules for every project:\n{records or 'none'}\n\n" f"The task an agent was given:\n{task}\n\n" "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" ) diff --git a/bin/loop_claude/cycle/judge_reply.py b/bin/loop_claude/cycle/judge_reply.py index c7f8e1db..266352ac 100644 --- a/bin/loop_claude/cycle/judge_reply.py +++ b/bin/loop_claude/cycle/judge_reply.py @@ -3,39 +3,44 @@ import typing from failure import Failure +RECORD_PLACES = "README.md's Goals or Audience, AGENTS.md, docs/decisions.md, todo.md or a comment" +ANSWERS_RECORDED = f"every answer the human typed in it that a later chunk could need is recorded in {RECORD_PLACES} at the one place it governs" 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 records settle the matter\n" "- 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 " + "reasonably reject and that neither README.md nor the 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 choice " "outside the repo, or a release ready to cut, which only the human may publish\n" "- it flags that the goals, the plan in todo.md or the task itself is unclear, missing or in need of change\n" - "- it chose between alternatives that neither README.md nor the project's records discriminate " + "- it chose between alternatives that neither README.md nor the 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. A [loop] line is what loop-claude told " - "the agent, such as an answer quoted from README.md or the project's records.\n" + "the agent, such as an answer quoted from README.md or the records.\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 and no [loop] line has " + "Where README.md or the records answer the agent's own question and no [loop] line has " "quoted that answer yet, set interrupt=false and quote the passage that answers it; the agent is " "then given that passage in place of the human's reply. An interrupt outranks a quoted answer, and either " "outranks finished.\n" "The chunk is the piece of work the agent is on, shipped as one pull request. " "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." + f"its own. Even then, it is finished only once {ANSWERS_RECORDED}. An answer counts as recorded " + "where README.md or the records above hold it, ~/.claude/CLAUDE.md included. It also counts where " + f"the transcript shows the agent writing it into {RECORD_PLACES}; writing it into " + "~/.claude/CLAUDE.md does not count. finished=false when work remains that a further run can " + "continue: an open PR, a review not yet run, CI not yet reported, an answer not yet recorded." ) @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, without elisions. Empty otherwise."}) + answer: str = dataclasses.field(metadata={"description": "With interrupt false, the passage of README.md or the records that answers the agent's question, quoted verbatim, without elisions. Empty otherwise."}) evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the one transcript passage the verdict rests on, without elisions: what triggers the interrupt; for a quoted answer, the agent's question; else what shows the chunk finished or the work remaining."}) finished: bool = dataclasses.field(metadata={"description": "Whether the chunk is finished."}) interrupt: bool = dataclasses.field(metadata={"description": "Whether the human must now be interrupted."}) @@ -59,7 +64,7 @@ class Interrupt: @dataclasses.dataclass(frozen=True) class QuotedAnswer: - """The agent asked a question that README.md or the project's records answer. The answer field quotes the passage.""" + """The agent asked a question that README.md or the records answer. The answer field quotes the passage.""" evidence: str question: str answer: str diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index 195643d0..dcf16344 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -68,6 +68,8 @@ def step(cycle: Cycle, state: Active) -> Event | Stop: def work(cycle: Cycle, answered: QuotedAnswer | None) -> WorkerRan | Stop: if answered is not None: print(f"\n=== {QUOTE_SOURCES} answered: {answered.question} ===\n{answered.answer}", flush=True) + if stop := keep_answer(cycle, answered): + return 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), answered), cycle.effects), cycle.effects): return stop @@ -75,6 +77,13 @@ def work(cycle: Cycle, answered: QuotedAnswer | None) -> WorkerRan | Stop: return WorkerRan(path) if path is not None else Stop(1, f"claude left no transcript for session {cycle.session.id}") +def keep_answer(cycle: Cycle, answered: QuotedAnswer) -> Stop | None: + path = transcript_file(cycle.session) + if path and (failure := archive(cycle.project_key, path, cycle.task, f"Verdict: quoted answer\n\n{answered.question}\n\n{QUOTE_SOURCES} says:\n{quoted(answered.answer)}\n\nEvidence:\n{quoted(answered.evidence)}", cycle.effects.now(), cycle.paths)): + return Stop(1, failure.reason) + return None + + def rule(cycle: Cycle, transcript_path: str) -> Ruled | Stop: entries = read_transcript(transcript_path) if isinstance(entries, Failure): diff --git a/bin/loop_claude/cycle/worker.py b/bin/loop_claude/cycle/worker.py index 55775434..c4f2961d 100644 --- a/bin/loop_claude/cycle/worker.py +++ b/bin/loop_claude/cycle/worker.py @@ -1,10 +1,10 @@ +from loop_claude.cycle.judge_reply import ANSWERS_RECORDED, QuotedAnswer from loop_claude.claude_code.entries import assistant_parts, ends_stream, hit_limit, limit_said, parse_entry, rejected_until from loop_claude.effects import Effects from failure import Failure from loop_claude.cycle.retry import Limited from loop_claude.claude_code.transcript import part_line from loop_claude.project.records import QUOTE_SOURCES -from loop_claude.cycle.judge_reply import QuotedAnswer from loop_claude.claude_code.session import Session PRINTED_TOOL_INPUT = 160 @@ -43,7 +43,7 @@ def worker_args(task: str, session: Session, model: str, resuming: bool, answere if answered is not None: 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)] + start = ["-p", f"Continue the task; the previous run stopped before it was finished. The chunk is finished once it is merged, or nothing remains that you could do on your own. Even then, it is finished only once {ANSWERS_RECORDED}.", "--resume", str(session.id)] else: # --session-id creates the session under the id loop-claude keeps; --resume continues that session. 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)] diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 222c63fd..1d8beadf 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -4,13 +4,16 @@ 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 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. The fourth question they answer in one cycle goes to the -human too, with the quote. +the transcript's end, the premises, and the records: the project's AGENTS.md and docs/decisions.md +and the human's ~/.claude/CLAUDE.md, where they exist. It rules whether the chunk, the work of one +PR, is finished. A chunk stays unfinished until each answer the human typed in it that a later chunk +could need is recorded: the premises or the records hold it, or the transcript shows the worker +writing it into the premises, AGENTS.md, docs/decisions.md, todo.md or a code comment. 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. 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. @@ -22,12 +25,12 @@ interrupt, and as every cycle ends, Ctrl-C and a failure included, the session's copied to $LOOP_CLAUDE_TRANSCRIPTS///.jsonl (default ~/.claude/loop-claude-transcripts), named by its hash. is the hash of the transcript's first 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, and why the loop stopped. The -verdict and the stop each open with their 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 -.. +holds the verdict, with the transcript passage the judge rested it on; 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' +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; a project without an entry, as on its first @@ -40,7 +43,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, or AGENTS.md, docs/decisions.md or ~/.claude/CLAUDE.md where they exist, cannot be + read or is not UTF-8 - README.md holds no premises - the models file cannot be read or written - claude leaves no transcript @@ -108,7 +112,7 @@ 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) + records = read_records(loop_run.root, paths.claude_md) if isinstance(records, Stop): return records models = get_or_ask_models(key, paths, env, effects) diff --git a/bin/loop_claude/paths.py b/bin/loop_claude/paths.py index 35ecdbc5..2b4e24eb 100644 --- a/bin/loop_claude/paths.py +++ b/bin/loop_claude/paths.py @@ -7,6 +7,7 @@ import typing class Paths: claude_code_transcripts: pathlib.Path claude_json: pathlib.Path + claude_md: pathlib.Path code: pathlib.Path model_catalog: pathlib.Path models_file: pathlib.Path @@ -18,6 +19,7 @@ def paths_from(home: pathlib.Path, env: typing.Mapping[str, str]) -> Paths: return Paths( claude_code_transcripts=claude / "projects", claude_json=home / ".claude.json", + claude_md=claude / "CLAUDE.md", code=home / "code", model_catalog=claude / "cache" / "model-catalog", models_file=claude / "loop-claude-models.json", diff --git a/bin/loop_claude/project/checkout.py b/bin/loop_claude/project/checkout.py index de5f057d..5b5c396e 100644 --- a/bin/loop_claude/project/checkout.py +++ b/bin/loop_claude/project/checkout.py @@ -29,11 +29,11 @@ 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: +def read_utf8(folder: str, name: str, consequence: str) -> str | Stop: try: - return pathlib.Path(root, name).read_text(encoding="utf-8") + return pathlib.Path(folder, name).read_text(encoding="utf-8") except OSError as failure: - return Stop(1, f"{name} in {root}: {failure.strerror} - {consequence}.") + return Stop(1, f"{name} in {folder}: {failure.strerror} - {consequence}.") except UnicodeDecodeError as failure: line = failure.object.count(b"\n", 0, failure.start) + 1 - return Stop(1, f"{name} in {root} is not UTF-8 on line {line} - {consequence}.") + return Stop(1, f"{name} in {folder} 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 a00b3647..a824c825 100644 --- a/bin/loop_claude/project/premises.py +++ b/bin/loop_claude/project/premises.py @@ -1,10 +1,10 @@ -from loop_claude.project.checkout import read_checkout_file +from loop_claude.project.checkout import read_utf8 from markdown_sections import sections from loop_claude.stop import Stop def read_premises(root: str) -> str | Stop: - text = read_checkout_file(root, "README.md", "no premises") + text = read_utf8(root, "README.md", "no premises") if isinstance(text, Stop): return text found = sections(text) diff --git a/bin/loop_claude/project/records.py b/bin/loop_claude/project/records.py index 42fe7d33..dd9b16d6 100644 --- a/bin/loop_claude/project/records.py +++ b/bin/loop_claude/project/records.py @@ -1,21 +1,23 @@ import pathlib -from loop_claude.project.checkout import read_checkout_file +from loop_claude.project.checkout import read_utf8 from loop_claude.stop import Stop RECORD_FILES = ("AGENTS.md", "docs/decisions.md") +HUMAN_RULES = "~/.claude/CLAUDE.md" # 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) +QUOTE_SOURCES = "README.md's Goals and Audience, " + ", ".join(RECORD_FILES) + " or " + HUMAN_RULES -def read_records(root: str) -> str | Stop: - """The record files, each headed by its path; a file the project lacks is left out.""" +def read_records(root: str, claude_md: pathlib.Path) -> str | Stop: + """The project's record files, then the human's rules for every project, each headed by its name; a file that does not exist is left out.""" + sources = [(root, name, name) for name in RECORD_FILES] + [(str(claude_md.parent), claude_md.name, HUMAN_RULES)] records = [] - for name in RECORD_FILES: - if not pathlib.Path(root, name).exists(): + for folder, name, heading in sources: + if not pathlib.Path(folder, name).exists(): continue - text = read_checkout_file(root, name, "the judge cannot read the project's records") + text = read_utf8(folder, name, "the judge cannot read the records") if isinstance(text, Stop): return text - records.append(f"From {name}:\n{text.strip()}") + records.append(f"From {heading}:\n{text.strip()}") return "\n\n".join(records) diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 9604a58d..7edd9fa5 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -159,7 +159,7 @@ class Transitions(unittest.TestCase): class QuestionFor(unittest.TestCase): def test_puts_an_interrupts_question_as_asked_and_a_quoted_answer_past_the_cap_with_its_quote(self): self.assertEqual(run.question_for(Interrupt("e", "Which one?")), "Which one?") - self.assertEqual(run.question_for(QuotedAnswer("e", "Which one?", "A.")), "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.") + self.assertEqual(run.question_for(QuotedAnswer("e", "Which one?", "A.")), "Which one?\n\nREADME.md's Goals and Audience, AGENTS.md, docs/decisions.md or ~/.claude/CLAUDE.md says:\nA.\n\nThose files have answered 3 questions this cycle, the most allowed, so this one comes to you.") class Quoted(unittest.TestCase): @@ -261,10 +261,20 @@ 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's Goals and Audience, 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, docs/decisions.md or ~/.claude/CLAUDE.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'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()) + self.assertEqual(printed.getvalue().count("=== README.md's Goals and Audience, AGENTS.md, docs/decisions.md or ~/.claude/CLAUDE.md answered: Which one? ===\nUse *A*."), 3) + self.assertIn("Which one?\n\nREADME.md's Goals and Audience, AGENTS.md, docs/decisions.md or ~/.claude/CLAUDE.md says:\nUse *A*.\n\nThose files have answered 3 questions this cycle", said.getvalue()) + quoted = "2026-09-21T14:13:20Z Verdict: quoted answer\n\nWhich one?\n\nREADME.md's Goals and Audience, AGENTS.md, docs/decisions.md or ~/.claude/CLAUDE.md says:\n> Use *A*.\n\nEvidence:\n> working\n" + self.assertEqual(self.archived_outcomes(), [f"Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: interrupt\n\nWhich one?\n\nREADME.md's Goals and Audience, AGENTS.md, docs/decisions.md or ~/.claude/CLAUDE.md says:\nUse *A*.\n\nThose files have answered 3 questions this cycle, the most allowed, so this one comes to you.\n\nEvidence:\n> working\n\n2026-09-21T14:13:20Z Stopped: the human is needed to answer the question above, but the interrupt ended with nothing typed\n", *[f"Task: Do it.\n\n{quoted}"] * 3]) + + def test_stops_when_a_quoted_answer_cannot_be_archived(self): + self.paths.transcript_archive.parent.mkdir(parents=True) + self.paths.transcript_archive.write_text("") + fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("quoted", answer="Use A.")]) + with contextlib.redirect_stdout(io.StringIO()): + self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(1, f"could not archive the transcript: {self.paths.transcript_archive / 'proj'}: Not a directory")) + self.assertEqual(len(fake.made("stream_claude")), 1) 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 ... A.")], on_terminal_claude=[0], git=[ran()]) @@ -388,21 +398,27 @@ class WorkerArgs(unittest.TestCase): class Records(unittest.TestCase): - def test_heads_each_record_the_project_has_by_its_path(self): + def test_heads_each_record_by_its_name_the_humans_rules_last(self): with tempfile.TemporaryDirectory() as root: - self.assertEqual(records.read_records(root), "") + claude_md = pathlib.Path(root, "home", ".claude", "CLAUDE.md") + self.assertEqual(records.read_records(root, claude_md), "") + claude_md.parent.mkdir(parents=True) + claude_md.write_text("# Global\n") + self.assertEqual(records.read_records(root, claude_md), "From ~/.claude/CLAUDE.md:\n# Global") 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.md:\n# Decisions") + self.assertEqual(records.read_records(root, claude_md), "From AGENTS.md:\n# Rules\n\nFrom docs/decisions.md:\n# Decisions\n\nFrom ~/.claude/CLAUDE.md:\n# Global") def test_stops_on_a_record_it_cannot_read(self): with tempfile.TemporaryDirectory() as root: + claude_md = pathlib.Path(root, "home", ".claude", "CLAUDE.md") + claude_md.mkdir(parents=True) + self.assertEqual(records.read_records(root, claude_md), Stop(1, f"CLAUDE.md in {claude_md.parent}: Is a directory - the judge cannot read the records.")) 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.")) + self.assertEqual(records.read_records(root, claude_md), Stop(1, f"docs/decisions.md in {root}: Is a directory - the judge cannot read the records.")) pathlib.Path(root, "AGENTS.md").write_bytes(b"# Rules\n\xff\n") - 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.")) + self.assertEqual(records.read_records(root, claude_md), Stop(1, f"AGENTS.md in {root} is not UTF-8 on line 2 - the judge cannot read the records.")) class Render(unittest.TestCase): @@ -583,7 +599,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 = f"README.md, or {' or '.join(records.RECORD_FILES)} where they exist, cannot be read or is not UTF-8" + unreadable = f"README.md, or {', '.join(records.RECORD_FILES)} or {records.HUMAN_RULES} 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), @@ -592,6 +608,7 @@ class ExitContract(unittest.TestCase): ("cycle/retry.py", "retried", "1", "f'the {who} failed three times running:", "the worker or the judge fails three times running"), ("cycle/run.py", "stopped", "1", "f'{failure.reason}", read), ("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", "ask", "1", "failure.reason", read), ("cycle/run.py", "close", "1", "failure.reason", read), @@ -601,8 +618,8 @@ 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} in {root} is not UTF-8", unreadable), + ("project/checkout.py", "read_utf8", "1", "f'{name} in {folder}:", unreadable), + ("project/checkout.py", "read_utf8", "1", "f'{name} in {folder} 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_), @@ -620,7 +637,7 @@ class ExitContract(unittest.TestCase): for (path, function, code, reason), (want_path, want_function, want_code, reason_start, _) in zip(found, clauses): self.assertEqual((path, function, code), (want_path, want_function, want_code)) self.assertTrue(reason.startswith(reason_start), f"{path} {function}: {reason}") - help_exit_1 = main.__doc__[main.__doc__.index("Exit 1"):main.__doc__.index("Exit 2")] + help_exit_1 = " ".join(main.__doc__[main.__doc__.index("Exit 1"):main.__doc__.index("Exit 2")].split()) self.assertEqual([clause for *_, clause in clauses if f"- {clause}" not in help_exit_1], []) diff --git a/bin/test_loop_claude_black_box.py b/bin/test_loop_claude_black_box.py index caee0b24..0297e37f 100644 --- a/bin/test_loop_claude_black_box.py +++ b/bin/test_loop_claude_black_box.py @@ -326,6 +326,8 @@ class Cycles(unittest.TestCase): (checkout.root / "sub").mkdir() (checkout.root / "docs").mkdir() (checkout.root / "docs" / "decisions.md").write_text("# Decisions\n") + (checkout.home / ".claude").mkdir() + (checkout.home / ".claude" / "CLAUDE.md").write_text("# Global instructions\n") run = checkout.run([ worker(say="started"), judge(evidence="started"), worker(say="landed-it", siblings=True), judge(finished=True, evidence="landed-it"), @@ -342,9 +344,10 @@ class Cycles(unittest.TestCase): self.assertEqual(argument(workers[2], "--session-id"), session) self.assertTrue(argument(workers[0], "-p").startswith(f"{TASK}\n\nContinue any open draft PR")) self.assertNotIn(TASK, argument(workers[1], "-p")) + self.assertIn("Even then, it is finished only once every answer the human typed in it", 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.assertIn("From docs/decisions.md:\n# Decisions\n\nFrom ~/.claude/CLAUDE.md:\n# Global instructions", 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"]) @@ -436,7 +439,7 @@ class Cycles(unittest.TestCase): self.assertIn("LATE", run.calls[1]["stdin"]) 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.")) + self.assertTrue(run.calls[1]["stdin"].rstrip().endswith("CI not yet reported, an answer not yet recorded.")) def test_skips_a_malformed_transcript_or_stream_line(self): checkout = Checkout(self) diff --git a/docs/decisions.md b/docs/decisions.md index 51479ca7..2ca36866 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -4,13 +4,15 @@ 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 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: a judge decides each interrupt and each quoted answer from the transcript, the README's premises, `AGENTS.md`, `docs/decisions.md` and `~/.claude/CLAUDE.md`, and holds a chunk open while an answer the human typed in it is recorded nowhere; 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. 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. 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. -2026-10-03, lilleman: the judge is to read `~/.claude/CLAUDE.md` whole too. The worker follows that file, so a question it answers should not reach the human (goal 4.2). Reading the whole file is safe, because the judge may quote only words that appear in it. A list of sections would need keeping current. `todo.md` item 46 makes it so. Until then, a question only `CLAUDE.md` answers still goes to the human. +2026-10-03, lilleman: the judge is to read `~/.claude/CLAUDE.md` whole too. The worker follows that file, so a question it answers should not reach the human (goal 4.2). Reading the whole file is safe, because the judge may quote only words that appear in it. A list of sections would need keeping current. Implemented the same day. + +2026-10-03, lilleman: the judge rules a chunk finished only once every answer the human typed in it is recorded. A finished chunk's session is deleted, and its answers with it, so an answer recorded nowhere would be asked again in a later chunk (goal 4.2). Implemented the same day by claude, which settled two choices the ruling left open. First, an answer counts as recorded where the files the judge reads hold it, `~/.claude/CLAUDE.md` included, or where the transcript shows the worker writing it into `README.md`'s premises, `AGENTS.md`, `docs/decisions.md`, `todo.md` or a code comment. A worker's write to `~/.claude/CLAUDE.md` does not count: `CLAUDE.md` → "Maintaining this file" leaves new rules in it to the human. The judge cannot read a code comment or `todo.md`. Yet `CLAUDE.md` → "Working loop", "Ask, don't guess" puts a standing choice made in one place in a comment there. And the human's approval of a release's items, which "Working loop" requires, is the set of rows `todo.md` names for that release. The judge also reads the records once a cycle from the main checkout. That checkout may not yet hold an answer the worker wrote and merged. A judge that refused any of these would hold the chunk open every cycle. Second, only an answer a later chunk could need must be recorded, so an approval such as "merge it" holds nothing open. The worker's resume prompt states the rule, so a worker whose chunk is held open knows it. ## 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 624e1426..1a34f75f 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 9` -`Next ID = 58` +`Next ID = 59` | Goal | W | |---|---| @@ -25,10 +25,8 @@ | 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 | -| 56 | 0.1.0 | | **Have the judge rule a chunk finished only once every answer the human typed in it is recorded in `README.md`, `AGENTS.md` or `docs/decisions.md`.** | 3 | 3 | 7 | 8 | 4, 4.2 | 21.0 | -| 46 | 0.1.0 | decision | **Let the judge read and quote `~/.claude/CLAUDE.md` whole, beside the project's records.** | 4 | 3 | 7 | 8 | 4, 4.2 | 20.0 | -| 57 | 0.1.0 | | **Archive each answer the judge quotes from the records, with the question it answers.** | 2 | 2 | 5 | 6 | 2, 4.2 | 18.2 | | 54 | 0.1.0 | | **Give each review pass a fixed name in larv-review §3's table, and count its rounds by that name.** | 2 | 1 | 6 | 6 | 4, 4.1 | 17.8 | +| 58 | 0.1.0 | | **Give the worker of a chunk the judge held open the judge's evidence of what remains.** | 3 | 3 | 6 | 6 | 4, 4.4 | 16.3 | | 55 | 0.1.0 | | **Make larv-review's comprehension floor readable without opening the panel skill, its scoring-run file and `AGENTS.md` in turn.** | 2 | 3 | 5 | 6 | 4, 4.1 | 15.3 | | 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 | @@ -53,22 +51,14 @@ It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost The README line covers the bench's transcripts in `workflow-bench/logs/` too (goal 2). -### 56. Have the judge rule a chunk finished only once every answer the human typed in it is recorded in `README.md`, `AGENTS.md` or `docs/decisions.md`. - -2026-10-03, the human, answering the principles audit on PR #208: a finished chunk's session is deleted, and its `[human]` answers with it, so an answer recorded nowhere is asked again in a later chunk (goal 4.2). - -### 46. Let the judge read and quote `~/.claude/CLAUDE.md` whole, beside the project's records. - -The architecture pass's principles audit against README.md's goals, on PR #208, rated the gap 🔴 against goals 4 and 4.2: the worker follows `CLAUDE.md`, but the judge sees only the premises, `AGENTS.md` and `docs/decisions.md`. A choice `CLAUDE.md` settles therefore reads to the judge as one nothing discriminates, and a question it answers goes to the human. The fix revises the decision "loop-claude: a judge decides each interrupt and each quoted answer from the transcript, the README's premises, `AGENTS.md` and `docs/decisions.md`". - -### 57. Archive each answer the judge quotes from the records, with the question it answers. - -Raised by the product-owner review of PR #210: a quoted answer resumes the worker and leaves no line in `.outcomes.md`, so after an unattended run nothing shows which questions the records settled, or with what quote (goal 4.2). - ### 54. Give each review pass a fixed name in larv-review §3's table, and count its rounds by that name. Named under Shape by the PR #208 scoring runs: "Count" keys on `Answer round :`, but the table's first column names the architecture pass with a whole sentence, so a run can spell one pass two ways and restart its count. +### 58. Give the worker of a chunk the judge held open the judge's evidence of what remains. + +Raised by the product-owner review of PR #211: a verdict that the chunk is unfinished resumes the worker with a generic prompt, so a worker that thinks the chunk done repeats itself, and nothing bounds a run of such verdicts (goal 4.4). + ### 55. Make larv-review's comprehension floor readable without opening the panel skill, its scoring-run file and `AGENTS.md` in turn. Named under Self-sufficiency by the PR #208 scoring runs, as the worst of the skills' leans on other documents.