Answer the stability, product-owner and prose reviews' first round

This commit is contained in:
2026-10-02 09:17:16 +02:00
parent 6bd150c820
commit 57ddf715b3
11 changed files with 41 additions and 38 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ 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}, nothing in the transcript" + (f", for the question: {verdict.question}" if isinstance(verdict, Interrupt) else ""))
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) else ""))
return verdict
+2 -4
View File
@@ -5,8 +5,6 @@ from loop_claude.effects import Effects
from loop_claude.failure import Failure
from loop_claude.stop import Stop
ATTEMPTS = 3
RETRY_DELAY_SECONDS = 60
T = typing.TypeVar("T")
@@ -17,7 +15,7 @@ def retried(who: str, attempt: typing.Callable[[], T | Failure], effects: Effect
result = attempt()
if not isinstance(result, Failure):
return result
if failures == ATTEMPTS:
if failures == 3:
return Stop(1, f"the {who} failed three times running: {result.reason}")
print(f"retrying the {who} in a minute: {result.reason}", file=sys.stderr)
effects.sleep(RETRY_DELAY_SECONDS)
effects.sleep(60)
+1 -1
View File
@@ -66,7 +66,7 @@ def transition(state: State, event: Event) -> State:
return Finishing(transcript_path)
case Judging(), Ruled(Unfinished()):
return Ended()
# The interrupt is a whole claude session on the terminal, so the judge rules again on what it left.
# 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 Finishing(), Archived():
+1 -1
View File
@@ -3,5 +3,5 @@ import dataclasses
@dataclasses.dataclass(frozen=True)
class Failure:
"""A step failed, for reason; its caller decides what follows."""
"""A step failed with reason; its caller decides what follows."""
reason: str
+24 -19
View File
@@ -4,12 +4,26 @@ 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 them and rules whether the chunk, the work of one PR, is finished.
the transcript against the premises and rules whether the chunk, the work of one PR, is finished.
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.
Cycles continue until an exit below or Ctrl-C. Words: ~/.claude/CLAUDE.md → "Vocabulary".
Each project has one session, named "A <key> loop-claude", where <key> is the checkout's path
relative to ~/code, or to / outside it. The session is deleted when its chunk finishes. At every
interrupt, and when the chunk finishes, the session's transcript is copied to
$LOOP_CLAUDE_TRANSCRIPTS/<key>/<sha256>.jsonl (default ~/.claude/loop-claude-transcripts), the
verdict beside it in <sha256>.verdict.md.
Every claude it 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 run, is asked for one.
LOOP_CLAUDE_JUDGE_MODEL overrides it for the judge, LOOP_CLAUDE_WORKER_MODEL for the worker and the
interrupt; with both set, nothing is asked.
A change to bin/loop-claude or bin/loop_claude/**/*.py takes effect at the next cycle boundary, once
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
@@ -20,28 +34,19 @@ Exit 1, saying why, when:
- a finished chunk's session cannot be deleted
- claude cannot start for an interrupt
- python cannot start for a reload
- a reload cannot read the cycle number, checkout root and task the edited script was handed, as
when the edit changed what one script hands the next
- a reload cannot read the cycle number, checkout root and task the running script handed it,
likely because the edit changed that handover
- the worker or the judge fails three times running, retried a minute apart within the cycle. A
worker fails when claude cannot start, exits non-zero, is killed, or ends without a result event;
a judge when claude cannot start or exits non-zero, or its reply misses or mistypes a field,
interrupts without a question, or quotes nothing in the transcript.
Exit 2: the human is needed, to pick the model or answer an interrupt, and stdin or stdout is not a
terminal, the input ends, or the interrupt ended with nothing typed. Rerunning resumes any
open session.
interrupts without a question, or quotes a line the transcript does not hold.
Each project has one session, "A <key> loop-claude", <key> being the checkout relative to ~/code,
or to / outside it, deleted when the chunk finishes. At every interrupt and when the chunk finishes
its transcript is copied to $LOOP_CLAUDE_TRANSCRIPTS/<key>/<sha256>.jsonl (default
~/.claude/loop-claude-transcripts), the verdict beside it in <sha256>.verdict.md.
Exit 2, when the human is needed and cannot answer:
- stdin or stdout is not a terminal, when a model must be picked or an interrupt answered
- the input ends while a model is picked
- an interrupt ends with nothing typed
Rerunning resumes any open session.
Every claude it 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 run, is asked for one.
LOOP_CLAUDE_JUDGE_MODEL overrides it for the judge, LOOP_CLAUDE_WORKER_MODEL for the worker and the
interrupt; with both set, nothing is asked.
A change to bin/loop-claude or bin/loop_claude/**/*.py takes effect at the next cycle boundary, once
loop-claude --help succeeds.
"""
import dataclasses
import pathlib
@@ -100,5 +105,5 @@ def loop_run_from(argv: list[str], cwd: pathlib.Path, effects: Effects) -> LoopR
return root if isinstance(root, Stop) else LoopRun(0, root, task)
loop_run = decode_handed(argv[1], LoopRun) if len(argv) == 2 else None
if not (loop_run and loop_run.root and loop_run.task):
return Stop(1, f"the reload cannot read the cycle number, checkout root and task the edited script was handed in {argv[1:]}, as when the edit changed what one script hands the next; rerun loop-claude <task>")
return Stop(1, f"the edited loop-claude cannot read the cycle number, checkout root and task the running one handed it, likely because the edit changed that handover; rerun loop-claude <task>. Handed: {' '.join(argv[1:])}")
return loop_run
+1 -1
View File
@@ -15,7 +15,7 @@ T = typing.TypeVar("T")
# A field change stops a running loop at its next reload: the new script rejects the old fields.
@dataclasses.dataclass(frozen=True)
class LoopRun:
"""What a reload hands the edited script, as JSON on argv: the cycle number, checkout root and task."""
"""What a reload hands the edited script, as JSON on argv."""
cycle_number: int
root: str
task: str
+3 -3
View File
@@ -348,7 +348,7 @@ class LoopRuns(unittest.TestCase):
def test_stops_naming_the_reload_when_it_hands_over_anything_but_the_state_with_a_task(self):
for handed in (["3", "2", "/r", "do it"], ["3"], ["[1]"], [json.dumps({"cycle_number": 3, "root": "/r"})], [json.dumps({"cycle_number": 3, "root": "/r", "task": ""})], [json.dumps({"cycle_number": "3", "root": "/r", "task": "do it"})], [json.dumps({"cycle_number": 3, "root": "", "task": "do it"})], [json.dumps({"cycle_number": 3, "root": "/r", "task": "do it", "turns": 1})], [json.dumps({"cycle_number": 3, "failures": 0, "root": "/r", "task": "do it"})]):
with self.subTest(handed=handed):
self.assertEqual(main.loop_run_from([main.RELOAD_FLAG, *handed], CWD, FakeEffects().effects()), Stop(1, f"the reload cannot read the cycle number, checkout root and task the edited script was handed in {handed}, as when the edit changed what one script hands the next; rerun loop-claude <task>"))
self.assertEqual(main.loop_run_from([main.RELOAD_FLAG, *handed], CWD, FakeEffects().effects()), Stop(1, f"the edited loop-claude cannot read the cycle number, checkout root and task the running one handed it, likely because the edit changed that handover; rerun loop-claude <task>. Handed: {' '.join(handed)}"))
def test_decodes_a_state_whose_annotations_are_strings(self):
@dataclasses.dataclass(frozen=True)
@@ -370,7 +370,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"
# Each Stop with an exit code other than 0, 2 or 130, in source order, by its code and the start of its reason, with its --help clause.
# 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),
("cycle/interrupt.py", "interrupt", "1", "f'could not start claude for the interrupt:", "claude cannot start for an interrupt"),
@@ -382,7 +382,7 @@ class ExitContract(unittest.TestCase):
("cycle/run.py", "close", "1", "failure.reason", read),
("cycle/run.py", "close", "1", "failure.reason", "a finished chunk's session cannot be deleted"),
("loop/main.py", "loop_run_from", "0 if task else 1", "__doc__.strip()", "no task is given"),
("loop/main.py", "loop_run_from", "1", "f'the reload cannot read the cycle number,", "a reload cannot read the cycle number, checkout root and task"),
("loop/main.py", "loop_run_from", "1", 'f"the edited loop-claude cannot read the cycle number,', "a reload cannot read the cycle number, checkout root and task"),
("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),
+2 -2
View File
@@ -397,8 +397,8 @@ class Cycles(unittest.TestCase):
self.assertEqual(run.code, 130)
self.assertEqual(run.roles(), ["worker", "judge", "judge", "judge", "worker", "judge"])
self.assertEqual(run.sleeps, [60, 60])
self.assertIn("the judge quoted 'never said', nothing in the transcript, for the question: A or B?", run.stderr)
self.assertIn("retrying the judge in a minute: the judge quoted '', nothing in the transcript\n", run.stderr)
self.assertIn("the judge quoted 'never said', which is not in the transcript, for the question: A or B?", run.stderr)
self.assertIn("retrying the judge in a minute: the judge quoted '', which is not in the transcript\n", run.stderr)
def test_retries_a_judge_claude_cannot_start(self):
checkout = Checkout(self)