Keep every answer on record: the judge reads CLAUDE.md, holds a chunk open for an unrecorded answer, and archives each answer it quotes

This commit is contained in:
2026-10-03 20:57:24 +02:00
parent c28f4ecf6b
commit a48ac5c16a
13 changed files with 85 additions and 66 deletions
+1 -1
View File
@@ -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"
)
+11 -9
View File
@@ -3,39 +3,41 @@ import typing
from failure import Failure
ANSWERS_RECORDED = "every answer the human typed in it that a later chunk could need is recorded: in README.md's Goals or Audience, in AGENTS.md or docs/decisions.md, or in a comment 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, and {ANSWERS_RECORDED}. Judge that from the files above; a comment counts only where the "
"transcript shows the agent writing it. 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 +61,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
+9
View File
@@ -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):
+2 -2
View File
@@ -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 and {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)]
+18 -15
View File
@@ -4,13 +4,15 @@ usage: loop-claude <task>
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. It is not while an answer the human typed in it, that a later chunk could need, is
recorded nowhere: not in the premises, AGENTS.md or docs/decisions.md, nor in a code comment the
transcript shows the worker writing. 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 +24,12 @@ interrupt, and as every cycle ends, Ctrl-C and a failure included, the session's
copied to $LOOP_CLAUDE_TRANSCRIPTS/<key>/<chunk>/<sha256>.jsonl (default
~/.claude/loop-claude-transcripts), named by its hash. <chunk> is the hash of the transcript's first
line with a timestamp, the same for every cycle of a chunk. Beside the copy, <sha256>.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 <chunk>/session/. A file there
is replaced only by a version that grew from it. A file Claude Code rewrote lands beside its copy as
<name>.<hash of its content>.
holds the verdict, with the transcript passage the judge rested it on; each answer quoted from the
records, 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 <chunk>/session/. A file there is replaced only by a version that
grew from it. A file Claude Code rewrote lands beside its copy as <name>.<hash of its content>.
Every claude loop-claude starts runs the project's model, saved per <key> in
~/.claude/loop-claude-models.json and read each cycle; a project without an entry, as on its first
@@ -40,7 +42,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 +111,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)
+2
View File
@@ -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",
+8 -7
View File
@@ -4,18 +4,19 @@ from loop_claude.project.checkout import read_checkout_file
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."""
records = []
for name in RECORD_FILES:
if not pathlib.Path(root, name).exists():
for folder, name, heading in (*((root, name, name) for name in RECORD_FILES), (str(claude_md.parent), claude_md.name, HUMAN_RULES)):
if not pathlib.Path(folder, name).exists():
continue
text = read_checkout_file(root, name, "the judge cannot read the project's records")
text = read_checkout_file(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)