From 1839c8a19ef6b9120a34618a9bea3eb76626d99b Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 01:32:22 +0200 Subject: [PATCH] Answer the fourth round: a repeated question goes to the human, three records answers a cycle as the backstop, the quote in the interrupt, the cycle redefined --- CHANGELOG.md | 2 +- CLAUDE.md | 2 +- bin/loop_claude/cycle/judge.py | 2 +- bin/loop_claude/cycle/run.py | 2 +- bin/loop_claude/cycle/states.py | 31 +++++++++++++++++-------------- bin/loop_claude/loop/main.py | 4 ++-- bin/test_loop_claude.py | 29 ++++++++++++++++------------- docs/decisions.md | 2 +- todo.md | 7 ++++++- 9 files changed, 46 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82bf0e2c..9aaf0b70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Unreleased - Unless another Exempt reason fits, larv-review marks a `todo.md` item filed from a 🟑 finding against `~/.claude/principles/` with `principle`, an Exempt reason that keeps it whatever its score. -- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question they answer, the worker resumes with the judge's quote of the answer; the worker's next question in that cycle goes to you. The judge reads the transcript's last 400,000 characters, up from 40,000. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. +- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question they answer, the worker resumes with the judge's quote of the answer, up to three times a cycle; a question asked again after its answer, or a fourth, goes to you, with the quote. The judge reads the transcript's last 400,000 characters, up from 40,000. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8. - A project's decision log is `docs/decisions.md` alone, the one file the judge, `rank_todo.py` and the reviewers read; `CLAUDE.md` no longer allows splitting it into `docs/decisions/`. - `loop-claude` waits out a usage limit and retries: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. A limit is not a failure, and restarts the count of three failures in a row. It prints what claude said about the limit and when the next try is due. - Add the official plugin marketplace and install every plugin `settings.json` enables (README β†’ Install): `claude-security`, `code-review` and `rust-analyzer-lsp`, which needs `rust-analyzer` on `PATH` for Rust projects. With `claude-security`, larv-review's full security scan runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`. diff --git a/CLAUDE.md b/CLAUDE.md index bc1a464b..ce3e71f6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -151,7 +151,7 @@ The rules every project follows, compose-not-entangle first: `~/.claude/principl ## Vocabulary - **chunk** β€” the unit of work, shipped as one PR; "Working loop" says what it holds. -- **cycle** β€” one worker run and the judge's verdict on it, in `loop-claude`. +- **cycle** β€” in `loop-claude`, a worker run and the judge's verdicts on it, with any interrupts and records answers in between, until the chunk closes or continues next cycle. - **gate** β€” the merge gate: the checks a PR passes before it merges. - **interrupt** β€” `loop-claude` handing the terminal to the human, `claude --resume`, for a decision that is theirs. - **judge** β€” the headless claude that reads a worker's transcript each cycle and decides whether to interrupt and whether the chunk is finished. diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index b5031725..b44c125c 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -29,7 +29,7 @@ JUDGE_RULES = ( "where a note goes - is not on its own a reason to interrupt. The human may have replied inside the transcript, on a [human] line: judge only what " "is still open, never a question they already answered there. A [loop] line is what loop-claude told " "the agent, such as an answer quoted from README.md or the project's records; a question it answered " - "is no longer open.\n" + "is no longer open, unless the agent asks it again: then it is the human's, with answer empty.\n" "Where the agent asked or flagged something itself, the question is that one, in the agent's own " "wording; never construct another from facts it stated.\n" "Where README.md or the project's records answer that question, quote the passage that answers it " diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index 861a2c50..47c1e8a4 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -52,7 +52,7 @@ def stopped(cycle: Cycle, stop: Stop, why: str) -> Stop: def step(cycle: Cycle, state: Active) -> Event | Stop: match state: - case Working(answer): + case Working(answer, _): return work(cycle, answer) case Judging(transcript_path, _): return rule(cycle, transcript_path) diff --git a/bin/loop_claude/cycle/states.py b/bin/loop_claude/cycle/states.py index 480a22c7..8d941b2e 100644 --- a/bin/loop_claude/cycle/states.py +++ b/bin/loop_claude/cycle/states.py @@ -2,25 +2,29 @@ import dataclasses from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished, Verdict +# A backstop, so a worker the records' answers do not satisfy cannot loop unattended; the judge sends a repeated question to the human. +RECORDS_ANSWERS_PER_CYCLE = 3 + @dataclasses.dataclass(frozen=True) class Working: """The worker runs, resumed with the records' answer when there is one.""" answer: str | None = None + records_answers: int = 0 @dataclasses.dataclass(frozen=True) class Judging: - """The judge rules; answered_from_records holds once the records answered a question this cycle.""" + """The judge rules; records_answers counts the questions the records answered this cycle.""" transcript_path: str - answered_from_records: bool = False + records_answers: int = 0 @dataclasses.dataclass(frozen=True) class Interrupting: transcript_path: str question: str - answered_from_records: bool = False + records_answers: int = 0 @dataclasses.dataclass(frozen=True) @@ -63,20 +67,19 @@ Event = WorkerRan | Ruled | HumanAnswered | Archived def transition(state: State, event: Event) -> State: match state, event: - case Working(answer), WorkerRan(transcript_path): - return Judging(transcript_path, answer is not None) - case Judging(_, False), Ruled(AnsweredFromRecords(answer=answer)): - return Working(answer) - # One records answer per cycle, so a worker the answer did not satisfy cannot loop unattended. - case Judging(transcript_path, True), Ruled(AnsweredFromRecords(question=question)): - return Interrupting(transcript_path, question, True) - case Judging(transcript_path, answered_from_records), Ruled(Interrupt(question=question)): - return Interrupting(transcript_path, question, answered_from_records) + case Working(_, records_answers), WorkerRan(transcript_path): + return Judging(transcript_path, records_answers) + case Judging(_, records_answers), Ruled(AnsweredFromRecords(answer=answer)) if records_answers < RECORDS_ANSWERS_PER_CYCLE: + return Working(answer, records_answers + 1) + case Judging(transcript_path, records_answers), Ruled(AnsweredFromRecords(question=question, answer=answer)): + return Interrupting(transcript_path, f"{question}\n\nREADME.md or the project's records say:\n{answer}", records_answers) + case Judging(transcript_path, records_answers), Ruled(Interrupt(question=question)): + return Interrupting(transcript_path, question, records_answers) case Judging(transcript_path, _), Ruled(Finished() | Unfinished() as verdict): return Closing(transcript_path, verdict) # The human works in the interrupt's claude session, so the judge rules again on the transcript it leaves. - case Interrupting(transcript_path, _, answered_from_records), HumanAnswered(): - return Judging(transcript_path, answered_from_records) + case Interrupting(transcript_path, _, records_answers), HumanAnswered(): + return Judging(transcript_path, records_answers) case Closing(), Archived(): return Ended() raise ValueError(f"no transition from {state} on {event}") diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 4f5a8505..8d35e331 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -7,8 +7,8 @@ premises; the task runs at the checkout root. Each cycle a worker runs the task; the transcript's last 400,000 characters against the premises and the project's records, AGENTS.md and docs/decisions.md where they exist, and rules whether the chunk, the work of one PR, is finished. A choice the worker made that the premises or the records settle is not asked about. When the worker -asks a question they answer, the judge quotes the answer and the worker resumes with it; the -worker's next question in the cycle goes to the human. +asks a question they answer, the judge quotes the answer and the worker resumes with it, up to three +times a cycle; a question asked again after its answer, or a fourth, goes to the human. A question only the human can answer, or a release ready to cut, is an interrupt: `claude --resume` on the terminal, every worktree first marked trusted in ~/.claude.json. An unfinished chunk resumes its session next cycle; the next chunk starts a fresh session. diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index bb7024aa..5830a512 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -127,26 +127,28 @@ class Streamed: class Transitions(unittest.TestCase): def test_each_state_moves_on_its_events_and_only_on_them(self): + answered = states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")) legal = ( (states.Working(), states.WorkerRan("/t"), states.Judging("/t")), - (states.Working("A."), states.WorkerRan("/t"), states.Judging("/t", True)), + (states.Working("A.", 3), states.WorkerRan("/t"), states.Judging("/t", 3)), (states.Judging("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")), - (states.Judging("/t", True), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", True)), - (states.Judging("/t"), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Working("A.")), - (states.Judging("/t", True), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Interrupting("/t", "Which one?", True)), - (states.Judging("/t", True), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), - (states.Judging("/t", True), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), + (states.Judging("/t", 3), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", 3)), + (states.Judging("/t"), answered, states.Working("A.", 1)), + (states.Judging("/t", 2), answered, states.Working("A.", 3)), + (states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md or the project's records say:\nA.", 3)), (states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), + (states.Judging("/t", 3), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))), (states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), + (states.Judging("/t", 3), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))), (states.Interrupting("/t", "q"), states.HumanAnswered(), states.Judging("/t")), - (states.Interrupting("/t", "q", True), states.HumanAnswered(), states.Judging("/t", True)), + (states.Interrupting("/t", "q", 3), states.HumanAnswered(), states.Judging("/t", 3)), (states.Closing("/t", Finished("e")), states.Archived(), states.Ended()), ) for state, event, after in legal: with self.subTest(state=state, event=event): self.assertEqual(states.transition(state, event), after) - every_state = (states.Working(), states.Working("A."), states.Judging("/t"), states.Judging("/t", True), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", True), states.Closing("/t", Finished("e")), states.Ended()) - every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanAnswered(), states.Archived()) + every_state = (states.Working(), states.Working("A.", 3), states.Judging("/t"), states.Judging("/t", 3), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", 3), states.Closing("/t", Finished("e")), states.Ended()) + every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), answered, states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanAnswered(), states.Archived()) for state in every_state: for event in every_event: if (state, event) not in [(state, event) for state, event, _ in legal]: @@ -242,14 +244,15 @@ class Cycles(unittest.TestCase): self.assertNotIn("the second", prompts[0]) self.assertIn("[human] the second", prompts[1]) - def test_a_question_the_records_answer_resumes_the_worker_with_the_answer_once_per_cycle(self): + def test_a_question_the_records_answer_resumes_the_worker_with_the_answer_three_times_a_cycle(self): answered = judged("interrupt", answer="Use *A*.") - fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 2, claude=[answered, answered, judged("unfinished")], on_terminal_claude=[0], git=[ran()]) - with contextlib.redirect_stderr(io.StringIO()): + fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 4, claude=[answered] * 4, on_terminal_claude=[0], git=[ran()]) + with contextlib.redirect_stderr(io.StringIO()) as said: self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed")) resumed = fake.made("stream_claude")[1] self.assertEqual(resumed[resumed.index("-p") + 1], "README.md or the project's records answer your question:\n\nUse *A*.\n\nContinue the task.") - self.assertEqual(len(fake.made("claude_on_terminal")), 1) + self.assertEqual(len(fake.made("stream_claude")), 4) + self.assertIn("Which one?\n\nREADME.md or the project's records say:\nUse *A*.", said.getvalue()) def test_the_judge_fails_on_an_answer_the_records_do_not_hold(self): invented = judged("interrupt", answer="Use B.") diff --git a/docs/decisions.md b/docs/decisions.md index 037b7d6d..2fdae179 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -6,7 +6,7 @@ ## loop-claude: a judge decides each interrupt from the transcript, the README's premises and the project's records; the worker's own account of which goal settles a choice decides nothing -2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). A question the worker asks that the records answer is answered by the judge's verbatim quote of them, which the judge then sees as a `[loop]` line. That happens at most once per cycle, so a worker the answer did not satisfy cannot loop unattended (goal 4.4); its next question that cycle goes to the human. Valid while the worker's self-report stays unreliable. +2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). A question the worker asks that the records answer is answered by the judge's verbatim quote of them, which the judge then sees as a `[loop]` line; the worker asking it again shows the record did not settle it, and the judge sends it to the human. A backstop of three records answers per cycle keeps a worker the answers do not satisfy from looping unattended (goal 4.4); a fourth goes to the human with the judge's quote, so the cost is one interrupt. Valid while the worker's self-report stays unreliable. ## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it diff --git a/todo.md b/todo.md index c388b5e5..eb5cdd81 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 9` -`Next ID = 39` +`Next ID = 40` | Goal | W | |---|---| @@ -35,6 +35,7 @@ | 29 | 0.1.0 | | **Make the contributor a standing member of every project's audience, unless its `## Audience` says maintainability does not matter.** | 2 | 2 | 3 | 5 | 4.1, 4.4 | 9.1 | | 17 | 0.1.0 | decision | **Make `JUDGE_RULES` and the Claude Code flags `loop-claude` passes readable without `CLAUDE.md` or Claude Code's docs open.** | 1 | 2 | 3 | 4 | 4.1 | 9.0 | | 6 | 0.1.0 | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 5 | 5 | 4 | 5 | 4.1 | 7.4 | +| 39 | 0.1.0 | principle | **Sort each Python file's imports by the first name each binds.** | 2 | 3 | 3 | 3 | 4.1 | 6.6 | ## Details @@ -85,3 +86,7 @@ The 2026-10-02 scoring runs on PR #191 named both under Self-sufficiency: the ju ### 6. Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay. Claude Code owns that file and writes it. `trust` reads it, changes it and writes it back, so a write that lands in between is lost. + +### 39. Sort each Python file's imports by the first name each binds. + +The principle "Deterministic order wherever order carries no meaning" sorts imports on their first binding; `bin/loop_claude/` and `bin/rank_todo.py` sort `from loop_claude…` imports by module path, as in `loop/main.py` and `cycle/run.py`, so moving a module reorders imports in every file that uses it. Filed by the 2026-10-03 principles audit on PR #202.