Answer the third round: show the judge loop-claude's prompts, one records answer per cycle through an interrupt, name the answer's two sources apart

This commit is contained in:
2026-10-03 00:54:16 +02:00
parent 160b1dae5f
commit 2f46a13e5d
10 changed files with 53 additions and 38 deletions
+1
View File
@@ -3,6 +3,7 @@
## Unreleased
- `loop-claude`'s judge reads the project's `AGENTS.md` and `docs/decisions.md` beside the README's goals and audience, and does not interrupt for a choice they settle. When the worker asks a question they answer, the worker resumes with the judge's quote of the answer; the worker's next question in that cycle goes to you. The judge reads the transcript's last 400,000 characters, up from 40,000. `loop-claude` exits 1 when `AGENTS.md` or `docs/decisions.md` cannot be read or is not UTF-8.
- A project's decision log is `docs/decisions.md` alone, the one file the judge, `rank_todo.py` and the reviewers read; `CLAUDE.md` no longer allows splitting it into `docs/decisions/`.
- `loop-claude` waits out a usage limit and retries: 2 minutes past the reset, or every 10 minutes when the reset time is unknown. A limit is not a failure, and restarts the count of three failures in a row. It prints what claude said about the limit and when the next try is due.
- Add the official plugin marketplace and install every plugin `settings.json` enables (README → Install): `claude-security`, `code-review` and `rust-analyzer-lsp`, which needs `rust-analyzer` on `PATH` for Rust projects. With `claude-security`, larv-review's full security scan runs once you confirm its cost; an unattended larv-review reports the scan as not run. `settings.json` silences the plugin's scan tip after `git push`.
- systems-architect and product-owner-reviewer can no longer edit what they review; stability-reviewer keeps its shell to run tests, and loses Claude Code's file-editing tools.
+1 -1
View File
@@ -87,7 +87,7 @@ Prose describing the code as it stands — a comment, a README, an `AGENTS.md`,
### Decisions: one home, each linked to a goal or a technical principle
**A choice that shapes what the code does, made in one place, is a comment there, with its reason. Made in more than one place, it is a decision, and the decision log owns it.** A decision's rejected alternative, or what it deliberately does not cover, stays out of every call site. **The decision log has one home: `docs/decisions.md`**, or `docs/decisions/` split by area once it outgrows one file. A title states the whole decision in one line: what holds at the commit it ships in, in words a reader finds in the code or the plan. `AGENTS.md` lists every title, so a session works by the decisions without loading their background. A session reads the entry under a title only to question, revise or add a decision. The entry holds the background: its date, who made it, the reasoning, and the premise it rests on ("valid while X") so it can expire honestly when that premise dies. A choice found anywhere else — an `AGENTS.md` body, a comment, or a README section that is neither a goal nor how one is met — moves: to a comment at its one place, or, once made in more than one place, to the log, leaving its title in `AGENTS.md`'s list. A goal stays a goal in the README; the log records only what the goal leaves open.
**A choice that shapes what the code does, made in one place, is a comment there, with its reason. Made in more than one place, it is a decision, and the decision log owns it.** A decision's rejected alternative, or what it deliberately does not cover, stays out of every call site. **The decision log has one home: `docs/decisions.md`**. A title states the whole decision in one line: what holds at the commit it ships in, in words a reader finds in the code or the plan. `AGENTS.md` lists every title, so a session works by the decisions without loading their background. A session reads the entry under a title only to question, revise or add a decision. The entry holds the background: its date, who made it, the reasoning, and the premise it rests on ("valid while X") so it can expire honestly when that premise dies. A choice found anywhere else — an `AGENTS.md` body, a comment, or a README section that is neither a goal nor how one is met — moves: to a comment at its one place, or, once made in more than one place, to the log, leaving its title in `AGENTS.md`'s list. A goal stays a goal in the README; the log records only what the goal leaves open.
**Every decision links to a goal or a technical principle.** An entry names the goal it serves or the technical principle under `~/.claude/principles/` it applies; one that can do neither is a missing goal, and an entry already in the repo with neither behind it is a finding. Propose the goal, never a reason of your own — "Ask, don't guess" under "Working loop" says how. An entry working against a goal or a technical principle stands only while it names the `todo.md` item that ends it.
+7
View File
@@ -65,6 +65,13 @@ def human_text(entry: dict) -> str | None:
return text if isinstance(text, str) else "".join(part_text(part) or "" for part in parts(entry))
# {"type": "user", "promptSource": "sdk", "message": {"content": "Continue the task; the previous run stopped before it was finished."}}
def loop_text(entry: dict) -> str | None:
"""What a -p prompt of loop-claude's told the agent."""
text = content(entry)
return text if entry.get("type") == "user" and entry.get("promptSource") == "sdk" and isinstance(text, str) else None
# What the human types while claude works, written only as this entry:
# {"type": "attachment", "attachment": {"type": "queued_command", "commandMode": "prompt", "origin": {"kind": "human"}, "prompt": "B"}}
def queued_human_text(entry: dict) -> str | None:
+3 -1
View File
@@ -1,6 +1,6 @@
import json
from loop_claude.claude_code.entries import assistant_parts, human_text, parse_entry, part_text, tool_call
from loop_claude.claude_code.entries import assistant_parts, human_text, loop_text, parse_entry, part_text, tool_call
from loop_claude.failure import Failure
JUDGED_TOOL_INPUT = 400
@@ -30,6 +30,8 @@ def render(entries: list[dict]) -> str:
lines += [line for part in assistant_parts(entry) if (line := part_line(part, JUDGED_TOOL_INPUT))]
if (text := human_text(entry)) is not None:
lines.append("[human] " + text)
elif (text := loop_text(entry)) is not None:
lines.append("[loop] " + text)
return "\n\n".join(lines)
+10 -8
View File
@@ -4,13 +4,13 @@ import typing
from loop_claude.claude_code.entries import hit_limit, limit_said, parse_entry, structured_output
from loop_claude.cycle.retry import retried
from loop_claude.cycle.verdicts import Finished, Interrupt, Recorded, Unfinished, Verdict
from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished, Verdict
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from loop_claude.limited import Limited
from loop_claude.stop import Stop
# About 100,000 tokens, leaving a 200,000-token context room for the rest of the prompt; the largest session rendered here was 364,000 characters on 2026-10-03.
# About 100,000 tokens, half a 200,000-token context; the largest session rendered here was 364,000 characters on 2026-10-03.
JUDGED_TRANSCRIPT_TAIL = 400000
JUDGE_RULES = (
@@ -27,7 +27,9 @@ JUDGE_RULES = (
"between - neither rules the rejected one out - and the choice materially changes the deliverable\n"
"interrupt=false otherwise. Bookkeeping the agent settled silently - what to document, wording, "
"where a note goes - is not on its own a reason to interrupt. The human may have replied inside the transcript, on a [human] line: judge only what "
"is still open, never a question they already answered there.\n"
"is still open, never a question they already answered there. A [loop] line is what loop-claude told "
"the agent, such as an answer quoted from README.md or the project's records; a question it answered "
"is no longer open.\n"
"Where the agent asked or flagged something itself, the question is that one, in the agent's own "
"wording; never construct another from facts it stated.\n"
"Where README.md or the project's records answer that question, quote the passage that answers it "
@@ -85,8 +87,8 @@ def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str,
if isinstance(verdict, Failure):
return Failure(f"{verdict.reason}; it replied: {proc.stdout.strip() or 'nothing'}")
if not grounded(verdict.evidence, rendered_transcript):
return Failure(f"the judge quoted {verdict.evidence!r}, which is not in the transcript" + (f", for the question: {verdict.question}" if isinstance(verdict, Interrupt | Recorded) else ""))
if isinstance(verdict, Recorded) and not grounded(verdict.answer, recorded):
return Failure(f"the judge quoted {verdict.evidence!r}, which is not in the transcript" + (f", for the question: {verdict.question}" if isinstance(verdict, Interrupt | AnsweredFromRecords) else ""))
if isinstance(verdict, AnsweredFromRecords) and not grounded(verdict.answer, recorded):
return Failure(f"the judge answered {verdict.question!r} with {verdict.answer!r}, which README.md and the project's records do not hold")
return verdict
@@ -97,7 +99,7 @@ def judge_prompt(task: str, premises: str, records: str, rendered_transcript: st
f"The project's records, its working rules and decisions:\n{records or 'none'}\n\n"
f"The task an agent was given:\n{task}\n\n"
# The tail, where an interrupt or a finish lands; the session's transcript grows cycle over cycle.
f"What the agent did and said, and what the human typed on [human] lines, latest last:\n{rendered_transcript[-JUDGED_TRANSCRIPT_TAIL:]}\n\n"
f"What the agent did and said, what the human typed on [human] lines and what loop-claude told it on [loop] lines, latest last:\n{rendered_transcript[-JUDGED_TRANSCRIPT_TAIL:]}\n\n"
f"{JUDGE_RULES}"
)
@@ -108,14 +110,14 @@ def verdict_from(output: object) -> Verdict | Failure:
for name, kind in REPLY_TYPES.items():
if not isinstance(output.get(name), kind):
return Failure(f"the judge's reply has no {name} of type {JSON_TYPES[kind]}")
# An interrupt outranks finished: the human answers before the chunk can close.
if output["answer"].strip() and not output["interrupt"]:
return Failure("the judge answered without interrupting")
# An interrupt outranks finished: the human answers before the chunk can close.
if output["interrupt"]:
if not output["question"].strip():
return Failure("the judge interrupted without a question")
if output["answer"].strip():
return Recorded(output["evidence"], output["question"], output["answer"])
return AnsweredFromRecords(output["evidence"], output["question"], output["answer"])
return Interrupt(output["evidence"], output["question"])
return Finished(output["evidence"]) if output["finished"] else Unfinished(output["evidence"])
+4 -4
View File
@@ -7,7 +7,7 @@ from loop_claude.cycle.archive import archive
from loop_claude.cycle.interrupt import interrupt
from loop_claude.cycle.judge import judge
from loop_claude.cycle.retry import retried
from loop_claude.cycle.states import Active, Answered, Archived, Closing, Ended, Event, Interrupting, Judging, Ruled, State, WorkerRan, Working, transition
from loop_claude.cycle.states import Active, Archived, Closing, Ended, Event, HumanAnswered, Interrupting, Judging, Ruled, State, WorkerRan, Working, transition
from loop_claude.cycle.verdicts import Finished, Unfinished
from loop_claude.cycle.worker import run_worker, worker_args
from loop_claude.effects import Effects
@@ -56,7 +56,7 @@ def step(cycle: Cycle, state: Active) -> Event | Stop:
return work(cycle, answer)
case Judging(transcript_path, _):
return rule(cycle, transcript_path)
case Interrupting(transcript_path, question):
case Interrupting(transcript_path, question, _):
return ask(cycle, transcript_path, question)
case Closing(transcript_path, verdict):
return close(cycle, transcript_path, verdict)
@@ -80,11 +80,11 @@ def rule(cycle: Cycle, transcript_path: str) -> Ruled | Stop:
return verdict if isinstance(verdict, Stop) else Ruled(verdict)
def ask(cycle: Cycle, transcript_path: str, question: str) -> Answered | Stop:
def ask(cycle: Cycle, transcript_path: str, question: str) -> HumanAnswered | Stop:
# Archived now, so the transcript the question was asked on is kept with it; the human's answer then grows the transcript.
if failure := archive(cycle.project_key, transcript_path, cycle.task, f"Verdict: interrupt\n\n{question}", cycle.paths):
return Stop(1, failure.reason)
return interrupt(cycle.root, cycle.session.id, cycle.models.worker, transcript_path, question, cycle.paths, cycle.effects) or Answered()
return interrupt(cycle.root, cycle.session.id, cycle.models.worker, transcript_path, question, cycle.paths, cycle.effects) or HumanAnswered()
def close(cycle: Cycle, transcript_path: str, verdict: Finished | Unfinished) -> Archived | Stop:
+13 -11
View File
@@ -1,6 +1,6 @@
import dataclasses
from loop_claude.cycle.verdicts import Finished, Interrupt, Recorded, Unfinished, Verdict
from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished, Verdict
@dataclasses.dataclass(frozen=True)
@@ -11,6 +11,7 @@ class Working:
@dataclasses.dataclass(frozen=True)
class Judging:
"""The judge rules; answered_from_records holds once the records answered a question this cycle."""
transcript_path: str
answered_from_records: bool = False
@@ -19,6 +20,7 @@ class Judging:
class Interrupting:
transcript_path: str
question: str
answered_from_records: bool = False
@dataclasses.dataclass(frozen=True)
@@ -47,7 +49,7 @@ class Ruled:
@dataclasses.dataclass(frozen=True)
class Answered:
class HumanAnswered:
pass
@@ -56,25 +58,25 @@ class Archived:
pass
Event = WorkerRan | Ruled | Answered | Archived
Event = WorkerRan | Ruled | HumanAnswered | Archived
def transition(state: State, event: Event) -> State:
match state, event:
case Working(answer), WorkerRan(transcript_path):
return Judging(transcript_path, answer is not None)
case Judging(_, False), Ruled(Recorded(answer=answer)):
case Judging(_, False), Ruled(AnsweredFromRecords(answer=answer)):
return Working(answer)
# The worker asked again after the records' answer, so the answer did not settle it.
case Judging(transcript_path, True), Ruled(Recorded(question=question)):
return Interrupting(transcript_path, question)
case Judging(transcript_path, _), Ruled(Interrupt(question=question)):
return Interrupting(transcript_path, question)
# One records answer per cycle, so a worker the answer did not satisfy cannot loop unattended.
case Judging(transcript_path, True), Ruled(AnsweredFromRecords(question=question)):
return Interrupting(transcript_path, question, True)
case Judging(transcript_path, answered_from_records), Ruled(Interrupt(question=question)):
return Interrupting(transcript_path, question, answered_from_records)
case Judging(transcript_path, _), Ruled(Finished() | Unfinished() as verdict):
return Closing(transcript_path, verdict)
# The human works in the interrupt's claude session, so the judge rules again on the transcript it leaves.
case Interrupting(transcript_path), Answered():
return Judging(transcript_path)
case Interrupting(transcript_path, _, answered_from_records), HumanAnswered():
return Judging(transcript_path, answered_from_records)
case Closing(), Archived():
return Ended()
raise ValueError(f"no transition from {state} on {event}")
+2 -2
View File
@@ -8,7 +8,7 @@ class Interrupt:
@dataclasses.dataclass(frozen=True)
class Recorded:
class AnsweredFromRecords:
"""The agent asked a question that README.md or the project's records answer, quoted in answer."""
evidence: str
question: str
@@ -25,4 +25,4 @@ class Unfinished:
evidence: str
Verdict = Interrupt | Recorded | Finished | Unfinished
Verdict = Interrupt | AnsweredFromRecords | Finished | Unfinished
+11 -10
View File
@@ -19,7 +19,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from loop_claude import file_writes, paths
from loop_claude.claude_code import entries, session, transcript, trust
from loop_claude.cycle import archive, interrupt, judge, retry, run, states, worker
from loop_claude.cycle.verdicts import Finished, Interrupt, Recorded, Unfinished
from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished
from loop_claude.effects import Effects
from loop_claude.failure import Failure
from loop_claude.limited import Limited
@@ -131,21 +131,22 @@ class Transitions(unittest.TestCase):
(states.Working(), states.WorkerRan("/t"), states.Judging("/t")),
(states.Working("A."), states.WorkerRan("/t"), states.Judging("/t", True)),
(states.Judging("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")),
(states.Judging("/t", True), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")),
(states.Judging("/t"), states.Ruled(Recorded("e", "Which one?", "A.")), states.Working("A.")),
(states.Judging("/t", True), states.Ruled(Recorded("e", "Which one?", "A.")), states.Interrupting("/t", "Which one?")),
(states.Judging("/t", True), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", True)),
(states.Judging("/t"), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Working("A.")),
(states.Judging("/t", True), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Interrupting("/t", "Which one?", True)),
(states.Judging("/t", True), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))),
(states.Judging("/t", True), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))),
(states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))),
(states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))),
(states.Interrupting("/t", "q"), states.Answered(), states.Judging("/t")),
(states.Interrupting("/t", "q"), states.HumanAnswered(), states.Judging("/t")),
(states.Interrupting("/t", "q", True), states.HumanAnswered(), states.Judging("/t", True)),
(states.Closing("/t", Finished("e")), states.Archived(), states.Ended()),
)
for state, event, after in legal:
with self.subTest(state=state, event=event):
self.assertEqual(states.transition(state, event), after)
every_state = (states.Working(), states.Working("A."), states.Judging("/t"), states.Judging("/t", True), states.Interrupting("/t", "q"), states.Closing("/t", Finished("e")), states.Ended())
every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Ruled(Recorded("e", "Which one?", "A.")), states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.Answered(), states.Archived())
every_state = (states.Working(), states.Working("A."), states.Judging("/t"), states.Judging("/t", True), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", True), states.Closing("/t", Finished("e")), states.Ended())
every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanAnswered(), states.Archived())
for state in every_state:
for event in every_event:
if (state, event) not in [(state, event) for state, event, _ in legal]:
@@ -399,7 +400,7 @@ class Sections(unittest.TestCase):
class Render(unittest.TestCase):
def test_joins_assistant_text_and_tool_calls_and_human_turns_and_skips_the_rest(self):
def test_joins_assistant_text_tool_calls_human_turns_and_loop_prompts_and_skips_the_rest(self):
said = transcript.render([
human("do it"),
assistant({"type": "text", "text": "Starting."}, {"type": "tool_use", "name": "Bash", "input": {"command": "ls"}}),
@@ -411,7 +412,7 @@ class Render(unittest.TestCase):
queued("origin/main moved", "coordinator"),
{**human("Continue the task; the previous run stopped before it was finished."), "promptSource": "sdk"},
])
self.assertEqual(said, '[human] do it\n\nStarting.\n\n[tool Bash] {"command": "ls"}\n\n[human] yes, merge it\n\n[human] B, while you work')
self.assertEqual(said, '[human] do it\n\nStarting.\n\n[tool Bash] {"command": "ls"}\n\n[human] yes, merge it\n\n[human] B, while you work\n\n[loop] Continue the task; the previous run stopped before it was finished.')
class CopyFor(unittest.TestCase):
@@ -495,7 +496,7 @@ class Verdict(unittest.TestCase):
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": "e", "finished": True, "question": ""}), Finished("e"))
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": "e", "finished": False, "question": "ignored"}), Unfinished("e"))
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": True, "evidence": "e", "finished": True, "question": "Which one?"}), Interrupt("e", "Which one?"))
self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"}), Recorded("e", "Which one?", "A."))
self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"}), AnsweredFromRecords("e", "Which one?", "A."))
self.assertEqual(judge.verdict_from({"answer": "A.", "interrupt": False, "evidence": "e", "finished": False, "question": ""}), Failure("the judge answered without interrupting"))
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": "no", "evidence": "", "finished": True, "question": ""}), Failure("the judge's reply has no interrupt of type boolean"))
self.assertEqual(judge.verdict_from({"answer": "", "interrupt": False, "evidence": None, "finished": True, "question": ""}), Failure("the judge's reply has no evidence of type string"))
+1 -1
View File
@@ -6,7 +6,7 @@
## loop-claude: a judge decides each interrupt from the transcript, the README's premises and the project's records; the worker's own account of which goal settles a choice decides nothing
2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). A question the worker asks that the records answer is answered by the judge's verbatim quote of them, once per cycle: the worker asking again shows the record did not settle it, and that goes to the human. Valid while the worker's self-report stays unreliable.
2026-09-21, lilleman. Serves goal 4. Asked to name the goal behind each choice, the worker cites a real goal for a choice that goal does not settle, and under-reports its own decisions; the judge's bar is whether the README discriminates between the alternatives. On 2026-10-01 lilleman decided the judge is to read `docs/decisions.md` and `AGENTS.md` too, so an answer recorded there is not asked again (goal 4.2). A question the worker asks that the records answer is answered by the judge's verbatim quote of them, which the judge then sees as a `[loop]` line. That happens at most once per cycle, so a worker the answer did not satisfy cannot loop unattended (goal 4.4); its next question that cycle goes to the human. Valid while the worker's self-report stays unreliable.
## loop-claude: one session per project, its id derived from the checkout's path relative to `~/code`, or to `/` outside it