Give the judge what the project records and ten times more of the chunk's transcript

This commit is contained in:
2026-10-03 00:25:24 +02:00
parent 1568b3888d
commit 6d5d19bd69
10 changed files with 76 additions and 28 deletions
+11 -8
View File
@@ -10,18 +10,20 @@ from loop_claude.failure import Failure
from loop_claude.limited import Limited
from loop_claude.stop import Stop
JUDGED_TRANSCRIPT_TAIL = 40000
# About 100,000 tokens, so the prompt fits a 200,000-token context; the largest session rendered here was 364,000 on 2026-10-03.
JUDGED_TRANSCRIPT_TAIL = 400000
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\n"
"- it carried on under an assumption that decides the deliverable and that the human could "
"reasonably reject; a caveat about transient state it then handled is not one\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 "
"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 release "
"ready to cut, a choice outside the repo\n"
"- it flags that the goals, the plan or the task itself is unclear, missing or in need of change\n"
"- it chose between alternatives the README text does not discriminate between - it does not "
"rule the rejected one out - and the choice materially changes the deliverable\n"
"- it chose between alternatives that neither README.md nor the project's 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.\n"
@@ -49,7 +51,7 @@ JUDGE_SCHEMA = {
}
def judge(root: str, task: str, premises: str, rendered_transcript: str, model: str, effects: Effects) -> Verdict | Stop:
def judge(root: str, task: str, premises: str, records: str, rendered_transcript: str, model: str, effects: Effects) -> Verdict | Stop:
# No tools, so the verdict rests on the transcript grounded() checks it against; no persistence, so its runs stay out of the session picker.
args = [
"-p",
@@ -60,7 +62,7 @@ def judge(root: str, task: str, premises: str, rendered_transcript: str, model:
"--permission-mode", "bypassPermissions",
"--tools", "",
]
prompt = judge_prompt(task, premises, rendered_transcript)
prompt = judge_prompt(task, premises, records, rendered_transcript)
return retried("judge", lambda: run_judge(root, args, prompt, rendered_transcript, effects), effects)
@@ -83,9 +85,10 @@ def run_judge(root: str, args: list[str], prompt: str, rendered_transcript: str,
return verdict
def judge_prompt(task: str, premises: str, rendered_transcript: str) -> str:
def judge_prompt(task: str, premises: str, records: str, rendered_transcript: str) -> str:
return (
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 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"
+2 -1
View File
@@ -24,6 +24,7 @@ class Cycle:
paths: Paths
premises: str
project_key: str
records: str
root: str
session: Session
task: str
@@ -75,7 +76,7 @@ def rule(cycle: Cycle, transcript_path: str) -> Ruled | Stop:
entries = read_transcript(transcript_path)
if isinstance(entries, Failure):
return Stop(1, entries.reason)
verdict = judge(cycle.root, cycle.task, cycle.premises, render(entries), cycle.models.judge, cycle.effects)
verdict = judge(cycle.root, cycle.task, cycle.premises, cycle.records, render(entries), cycle.models.judge, cycle.effects)
return verdict if isinstance(verdict, Stop) else Ruled(verdict)
+9 -2
View File
@@ -4,7 +4,9 @@ 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 against the premises and rules whether the chunk, the work of one PR, is finished.
the transcript's last 400,000 characters against the premises and the project's records, AGENTS.md,
docs/decisions.md and docs/decisions/*.md where they exist, and rules whether the chunk, the work of
one PR, is finished. A choice the premises or the records settle is not asked again.
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.
@@ -34,6 +36,7 @@ Exit 1, saying why, when:
- no task is given
- git cannot start or finds no checkout
- README.md holds no premises
- AGENTS.md or a decision file cannot be read, or is not UTF-8
- the models file cannot be read or written
- claude leaves no transcript
- a transcript cannot be read or archived
@@ -71,6 +74,7 @@ from loop_claude.paths import Paths
from loop_claude.project.checkout import checkout_root, project_key
from loop_claude.project.model_choice import get_or_ask_models
from loop_claude.project.premises import read_premises
from loop_claude.project.records import read_records
from loop_claude.stop import Stop
@@ -98,11 +102,14 @@ 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)
if isinstance(records, Stop):
return records
models = get_or_ask_models(key, paths, env, effects)
if isinstance(models, Stop):
return models
print(f"\n=== cycle {loop_run.cycle_number} ===", flush=True)
if stop := run_cycle(Cycle(effects=effects, models=models, paths=paths, premises=premises, project_key=key, root=loop_run.root, session=session, task=loop_run.task)):
if stop := run_cycle(Cycle(effects=effects, models=models, paths=paths, premises=premises, project_key=key, records=records, root=loop_run.root, session=session, task=loop_run.task)):
return stop
+23
View File
@@ -0,0 +1,23 @@
import pathlib
from loop_claude.stop import Stop
def read_records(root: str) -> str | Stop:
"""AGENTS.md and the decision log, each headed by its path; a file the project lacks is left out."""
project = pathlib.Path(root)
paths = [project / "AGENTS.md", project / "docs" / "decisions.md", *sorted(project.glob("docs/decisions/*.md"))]
records = []
for path in paths:
name = path.relative_to(project)
try:
text = path.read_text(encoding="utf-8")
except FileNotFoundError:
continue
except OSError as failure:
return Stop(1, f"{name} in {root}: {failure.strerror} - the judge cannot read the project's records.")
except UnicodeDecodeError as failure:
line = failure.object.count(b"\n", 0, failure.start) + 1
return Stop(1, f"{name} is not UTF-8 on line {line} - the judge cannot read the project's records.")
records.append(f"From {name}:\n{text.strip()}")
return "\n\n".join(records)