From 4b2d4a17349ba3189fb433b621d868619517dfa3 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 17 Oct 2026 23:32:21 +0200 Subject: [PATCH] =?UTF-8?q?Answer=20principles=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=206=20=F0=9F=9F=A1;=20correct=20the=20interrupt's?= =?UTF-8?q?=20definition,=20show=20the=20judge=20the=20question=20beside?= =?UTF-8?q?=20the=20typed=20answer,=20ask=20in=20one=20call=20returning=20?= =?UTF-8?q?Talk,=20add=20a=20Talking=20state,=20give=20the=20worker=20its?= =?UTF-8?q?=20own=20question=20past=20the=20cap,=20assert=20the=20prompts'?= =?UTF-8?q?=20facts,=20and=20keep=20stepped=5Ffrom=20as=20the=20step's=20o?= =?UTF-8?q?ne=20owner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CLAUDE.md | 2 +- bin/claude_code/test_claude_code.py | 6 +- bin/claude_code/transcript.py | 6 +- bin/judge_replay/test_judge_replay.py | 2 +- bin/loop_claude/cycle/interrupt.py | 25 ++++-- bin/loop_claude/cycle/prompts.py | 11 ++- bin/loop_claude/cycle/run.py | 24 +++--- bin/loop_claude/cycle/states.py | 22 ++++- bin/loop_claude/effects.py | 4 + bin/loop_claude/loop/main.py | 4 +- bin/loop_claude/test_black_box.py | 42 +++++----- bin/loop_claude/test_loop_claude.py | 81 ++++++++++++------- bin/stability_replay/test_stability_replay.py | 2 +- todo.md | 14 +++- 14 files changed, 153 insertions(+), 92 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 4c1215dd..360357df 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -96,7 +96,7 @@ The rules only reviewers apply, for quality, comments, READMEs and prose, live i - **chunk** — the unit of work, shipped as one PR; "Working loop" says what it holds. - **cycle** — in `loop-claude`, worker runs and the judge's verdict on each, until the chunk closes or is left for the next cycle. In between, the human answers any interrupt, or the worker resumes with an answer the judge quoted from `README.md`, `AGENTS.md`, `docs/decisions.md`, `~/.claude/CLAUDE.md`, `~/.claude/rules/` or `~/.claude/skills/larv-review/standards/`. - **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. +- **interrupt** — `loop-claude` asking the human, on its terminal, for a decision that is theirs; typing `/talk` there, or a release ready to cut, opens the worker's session with `claude --resume`. - **judge** — the headless claude that reads a worker's transcript each cycle and decides whether to interrupt and whether the chunk is finished. - **pass** — one kind of review a chunk may take, run in rounds by its reviewers until clean; `larv-review` §3 lists them. - **plan** — `todo.md`. diff --git a/bin/claude_code/test_claude_code.py b/bin/claude_code/test_claude_code.py index bd18d1e2..4d436dc8 100644 --- a/bin/claude_code/test_claude_code.py +++ b/bin/claude_code/test_claude_code.py @@ -34,9 +34,9 @@ class Render(unittest.TestCase): queued("B, while you work", "human"), queued("origin/main moved", "coordinator"), {**human("Continue the task; the previous run stopped before it was finished."), "promptSource": "sdk"}, - {**human("Answered: use B"), "promptSource": "sdk"}, - ], lambda prompt: prompt.removeprefix("Answered: ") if prompt.startswith("Answered: ") else None) - 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.\n\n[human] use B') + {**human("Answered: use B\nYour question: A or B?"), "promptSource": "sdk"}, + ], lambda prompt: tuple(reversed(prompt.removeprefix("Answered: ").split("\n"))) if prompt.startswith("Answered: ") else None) + 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.\n\n[loop] Your question: A or B?\n\n[human] use B') class FirstTimestampedLine(unittest.TestCase): diff --git a/bin/claude_code/transcript.py b/bin/claude_code/transcript.py index 07ce9fde..a14dd904 100644 --- a/bin/claude_code/transcript.py +++ b/bin/claude_code/transcript.py @@ -25,8 +25,8 @@ def human_turns(entries: list[dict]) -> int: return sum(1 for entry in entries if human_text(entry) is not None) -def render(entries: list[dict], typed_answer: typing.Callable[[str], str | None]) -> str: - """The transcript as the judge reads it. typed_answer finds an answer the human typed in a -p prompt of loop-claude's, which reads as the human's, like one typed in claude.""" +def render(entries: list[dict], typed_answer: typing.Callable[[str], tuple[str, str] | None]) -> str: + """The transcript as the judge reads it. typed_answer splits a -p prompt of loop-claude's that carries an answer the human typed into loop-claude's words and that answer, which reads as the human's, like one typed in claude.""" lines = [] for entry in entries: lines += [line for part in assistant_parts(entry) if (line := part_line(part, JUDGED_TOOL_INPUT))] @@ -34,7 +34,7 @@ def render(entries: list[dict], typed_answer: typing.Callable[[str], str | None] lines.append("[human] " + text) elif (text := loop_text(entry)) is not None: typed = typed_answer(text) - lines.append("[loop] " + text if typed is None else "[human] " + typed) + lines += ["[loop] " + text] if typed is None else ["[loop] " + typed[0], "[human] " + typed[1]] return "\n\n".join(lines) diff --git a/bin/judge_replay/test_judge_replay.py b/bin/judge_replay/test_judge_replay.py index a30aa1a5..9bef31d2 100644 --- a/bin/judge_replay/test_judge_replay.py +++ b/bin/judge_replay/test_judge_replay.py @@ -114,7 +114,7 @@ class Main(unittest.TestCase): result = reply(Rung(args[args.index("--model") + 1], args[args.index("--effort") + 1]), "said Verdict: interrupt" in prompt.rsplit("latest last:", 1)[-1]) return subprocess.CompletedProcess(args, 0, json.dumps(result), "") - effects = Effects(claude=claude, claude_on_terminal=unused, execv=unused, git=unused, input=unused, local_time=unused, now=unused, on_terminal=unused, python=unused, sleep=unused, stream_claude=unused) + effects = Effects(claude=claude, claude_on_terminal=unused, discard_typed=unused, execv=unused, git=unused, input=unused, local_time=unused, now=unused, on_terminal=unused, python=unused, sleep=unused, stream_claude=unused) out, err = io.StringIO(), io.StringIO() with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err): code = main.main(argv, {}, self.home, effects) diff --git a/bin/loop_claude/cycle/interrupt.py b/bin/loop_claude/cycle/interrupt.py index 65b10c9b..d73820f9 100644 --- a/bin/loop_claude/cycle/interrupt.py +++ b/bin/loop_claude/cycle/interrupt.py @@ -1,3 +1,4 @@ +import dataclasses import sys import uuid @@ -16,20 +17,28 @@ TALK = "/talk" ASK_ANSWER = f"Answer ({TALK} opens claude, Enter stops the loop): " -def put_question(question: str, effects: Effects) -> Stop | None: - """Prints question for the human; a Stop where loop-claude is off a terminal, so no one can answer it.""" +@dataclasses.dataclass(frozen=True) +class Talk: + """The human answers in the worker's claude session, which talk opens.""" + + +def put_question(question: str, answer_here: bool, effects: Effects) -> str | Talk | Stop: + """Prints question for the human. Where answer_here, returns the line they type at loop-claude's terminal, stripped, or Talk where they type TALK; else Talk at once. A Stop where loop-claude is off a terminal, or they type nothing, or the input ends.""" print(f"\n{question}", file=sys.stderr) - return needs_terminal(ANSWER_QUESTION, effects.on_terminal()) - - -def read_answer(effects: Effects) -> str | Stop: - """The line the human types at loop-claude's terminal, stripped: their answer, or TALK where they ask for claude's session; a Stop where they type nothing or the input ends.""" + if stop := needs_terminal(ANSWER_QUESTION, effects.on_terminal()): + return stop + if not answer_here: + return Talk() + # Keys typed while the worker ran wait on the terminal, so they would answer a question no one has read. A paste's lines after the first are dropped with them at the next question, never taken as its answer; a longer answer goes through TALK. + effects.discard_typed() try: answer = effects.input(ASK_ANSWER).strip() except EOFError: print(file=sys.stderr) return needs_human(ANSWER_QUESTION, "the input ended") - return answer or needs_human(ANSWER_QUESTION, "nothing was typed") + if not answer: + return needs_human(ANSWER_QUESTION, "nothing was typed") + return Talk() if answer == TALK else answer def talk(root: str, session_id: uuid.UUID, worker: Rung, path: str, paths: Paths, env: dict[str, str], effects: Effects) -> Stop | None: diff --git a/bin/loop_claude/cycle/prompts.py b/bin/loop_claude/cycle/prompts.py index c1661be4..5ef9de49 100644 --- a/bin/loop_claude/cycle/prompts.py +++ b/bin/loop_claude/cycle/prompts.py @@ -130,17 +130,20 @@ def answered(question: str, answer: str, route: Route, anchor: Rung | None, step def typed(question: str, answer: str, route: Route, anchor: Rung | None, stepped: bool) -> str: """Resumes the worker with the human's answer to an interrupt. answer is one line, as the terminal reads it.""" - return f"{TYPED_HERE}\n{answer}\n\nYour question was: {question}\n\nContinue the task.{stepped_to(route, anchor, stepped)}" + return f"{TYPED_HERE}\n{answer}\n\nYour question was: {question}\n\nContinue the task. The chunk is finished only once {ANSWERS_RECORDED}.{stepped_to(route, anchor, stepped)}" # Opens typed's prompt, and the answer is the line after it, so typed_answer reads the answer from the prompt's start alone. TYPED_HERE = "The human answered your question at loop-claude's terminal:" -def typed_answer(prompt: str) -> str | None: - """The answer typed put in prompt, so the judge reads it as the human's; None for any other prompt.""" +def typed_answer(prompt: str) -> tuple[str, str] | None: + """The rest of the prompt typed made, and the answer it put there, so the judge reads the answer as the human's; None for any other prompt.""" opening = f"{TYPED_HERE}\n" - return prompt.removeprefix(opening).split("\n", 1)[0] if prompt.startswith(opening) else None + if not prompt.startswith(opening): + return None + answer, _, rest = prompt.removeprefix(opening).partition("\n\n") + return rest, answer def stepped_to(route: Route, anchor: Rung | None, stepped: bool) -> str: diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index 6354b15f..79d26764 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -2,7 +2,7 @@ import dataclasses import pathlib import typing -from loop_claude.cycle.states import Active, Archived, Closing, Ended, Event, HumanTalked, HumanTyped, Interrupting, Judging, QUOTED_ANSWERS_PER_CYCLE, Ruled, State, transition, TypedAnswer, WorkerRan, Working +from loop_claude.cycle.states import Active, Archived, Closing, Ended, Event, HumanTalked, HumanTyped, Interrupting, Judging, QUOTED_ANSWERS_PER_CYCLE, Ruled, State, TalkChosen, Talking, transition, TypedAnswer, WorkerRan, Working from transcript_archive.write import archive from claude_code.session import delete_session, Session, session_open, transcript_file from loop_claude.effects import Effects @@ -12,7 +12,7 @@ from loop_claude.routing import judge_rung, stepped_by_ruling from transcript_archive import outcomes from loop_claude.paths import Paths from loop_claude.cycle import prompts -from loop_claude.cycle.interrupt import put_question, read_answer, talk, TALK +from loop_claude.cycle.interrupt import put_question, talk, Talk from claude_code.transcript import read_transcript from loop_claude.cycle.retry import retried from model_routing.route import Route @@ -69,7 +69,7 @@ def run_cycle(cycle: Cycle) -> Stop | Concluded: def escalated(cycle: Cycle, event: Event) -> Cycle: - """The cycle after event. Where the judge interrupted or quoted an answer with an escalation, its route steps up before the human is asked or the worker resumes, so the work after the answer runs on it. stepped_from holds through the answer the human types, so the worker resuming with it is told of the step.""" + """The cycle after event. Where the judge interrupted or quoted an answer with an escalation, its route steps up before the human is asked or the worker resumes, so the work after the answer runs on it. stepped_from holds through the answer the human types, so the worker resuming with it is told of the step; a copy on TypedAnswer would give the step a second owner.""" if isinstance(event, HumanTyped): return cycle cycle = dataclasses.replace(cycle, stepped_from=None) @@ -99,6 +99,8 @@ def step(cycle: Cycle, state: Active) -> Event | Stop: return rule(cycle, transcript_path) case Interrupting(transcript_path, ruling, _): return ask(cycle, transcript_path, ruling) + case Talking(transcript_path, _): + return talk(cycle.root, cycle.session.id, cycle.route.rung, transcript_path, cycle.paths, worker_environment(cycle), cycle.effects) or HumanTalked() case Closing(transcript_path, verdict): return close(cycle, transcript_path, verdict) case _: @@ -165,23 +167,19 @@ def keep_rejection(cycle: Cycle, transcript_path: str, rejected: Rejected) -> St return None -def ask(cycle: Cycle, transcript_path: str, ruling: Interrupt | QuotedAnswer) -> HumanTyped | HumanTalked | Stop: +def ask(cycle: Cycle, transcript_path: str, ruling: Interrupt | QuotedAnswer) -> HumanTyped | TalkChosen | Stop: question = question_for(ruling) # Archived now, so the transcript the question was asked on is kept with it; the human's answer then grows the transcript. # The interrupt names the rung the worker ran on before it; a step-up archived after it names the stepped rung, so the figures charge each stretch to its own rung. interrupted = outcomes.interrupted(question, ruling.evidence, str(judge_of(cycle)), ruling.escalation, str(cycle.stepped_from or cycle.route)) if failure := archive_stepped(cycle, transcript_path, interrupted): return Stop(1, failure.reason) - if stop := put_question(question, cycle.effects): - return stop # Only the human may cut a release, so a release ready to cut opens claude's session at once. - if not (isinstance(ruling, Interrupt) and ruling.release_ready): - answer = read_answer(cycle.effects) - if isinstance(answer, Stop): - return answer - if answer != TALK: - return HumanTyped(TypedAnswer(question, answer)) - return talk(cycle.root, cycle.session.id, cycle.route.rung, transcript_path, cycle.paths, worker_environment(cycle), cycle.effects) or HumanTalked() + answer = put_question(question, not (isinstance(ruling, Interrupt) and ruling.release_ready), cycle.effects) + if isinstance(answer, Stop): + return answer + # The worker gets the question it asked, not the one put to the human past the cap. + return TalkChosen() if isinstance(answer, Talk) else HumanTyped(TypedAnswer(ruling.question, answer)) def archive_stepped(cycle: Cycle, transcript_path: str, outcome: str) -> Failure | None: diff --git a/bin/loop_claude/cycle/states.py b/bin/loop_claude/cycle/states.py index 27e8fc13..05227e67 100644 --- a/bin/loop_claude/cycle/states.py +++ b/bin/loop_claude/cycle/states.py @@ -35,6 +35,13 @@ class Interrupting: quoted_answers: int = 0 +@dataclasses.dataclass(frozen=True) +class Talking: + """The human answers in the worker's claude session, on the terminal.""" + transcript_path: str + quoted_answers: int = 0 + + @dataclasses.dataclass(frozen=True) class Closing: transcript_path: str @@ -46,7 +53,7 @@ class Ended: verdict: Finished | Unfinished -Active = Working | Judging | Interrupting | Closing +Active = Working | Judging | Interrupting | Talking | Closing State = Active | Ended @@ -65,6 +72,11 @@ class HumanTyped: typed: TypedAnswer +@dataclasses.dataclass(frozen=True) +class TalkChosen: + """The human typed /talk, or the question is a release ready to cut, which only the human may cut.""" + + @dataclasses.dataclass(frozen=True) class HumanTalked: """The human typed in the interrupt's claude session.""" @@ -75,7 +87,7 @@ class Archived: pass -Event = WorkerRan | Ruled | HumanTyped | HumanTalked | Archived +Event = WorkerRan | Ruled | HumanTyped | TalkChosen | HumanTalked | Archived def transition(state: State, event: Event) -> State: @@ -92,8 +104,10 @@ def transition(state: State, event: Event) -> State: return Closing(transcript_path, verdict) case Interrupting(_, _, quoted_answers), HumanTyped(typed): return Working(typed, quoted_answers) - # The human worked in the interrupt's claude session, so the judge rules again on the transcript it leaves. - case Interrupting(transcript_path, _, quoted_answers), HumanTalked(): + case Interrupting(transcript_path, _, quoted_answers), TalkChosen(): + return Talking(transcript_path, quoted_answers) + # The human worked in the worker's claude session, so the judge rules again on the transcript it leaves. + case Talking(transcript_path, quoted_answers), HumanTalked(): return Judging(transcript_path, quoted_answers) case Closing(_, verdict), Archived(): return Ended(verdict) diff --git a/bin/loop_claude/effects.py b/bin/loop_claude/effects.py index 760444e9..1ba2bf22 100644 --- a/bin/loop_claude/effects.py +++ b/bin/loop_claude/effects.py @@ -2,6 +2,7 @@ import dataclasses import os import subprocess import sys +import termios import time import typing @@ -21,6 +22,8 @@ class Streaming(typing.Protocol): class Effects: claude: typing.Callable[[list[str], str, str], subprocess.CompletedProcess[str]] claude_on_terminal: typing.Callable[[list[str], str, dict[str, str]], int] + # Drops what was typed on the terminal and not yet read. + discard_typed: typing.Callable[[], None] execv: typing.Callable[[str, list[str]], None] git: typing.Callable[[list[str], str], subprocess.CompletedProcess[str]] input: typing.Callable[[str], str] @@ -49,6 +52,7 @@ def system_effects() -> Effects: return Effects( claude=lambda args, cwd, stdin: subprocess.run(["claude", *args], capture_output=True, cwd=cwd, input=stdin, text=True), claude_on_terminal=lambda args, cwd, env: subprocess.run(["claude", *args], cwd=cwd, env={**os.environ, **env}).returncode, + discard_typed=lambda: termios.tcflush(sys.stdin, termios.TCIFLUSH), execv=os.execv, git=lambda args, cwd: subprocess.run(["git", *args], capture_output=True, cwd=cwd, text=True), input=input, diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index ccf921dc..22e2cd07 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -153,8 +153,8 @@ Exit 1, saying why, when: 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's answer is empty or the input ends, or the claude that /talk opened ends with - nothing typed +- an interrupt's answer is empty or the input ends, or the claude opened for /talk or a release + ready to cut ends with nothing typed Rerunning resumes any open session. """ diff --git a/bin/loop_claude/test_black_box.py b/bin/loop_claude/test_black_box.py index 50f0a268..57f04ce1 100644 --- a/bin/loop_claude/test_black_box.py +++ b/bin/loop_claude/test_black_box.py @@ -121,6 +121,10 @@ TODO = "## Items\n\n| ID | Release | Exempt | Item | L | E | I | R | S | Moves | CHEAP = TODO.replace("| 4 | 2 | 3 | 7 |", "| 2 | 1 | 2 | 3 |") +# Waits for the interrupt's prompt before typing the answer, since loop-claude drops what was typed before it. +ANSWERING = ("Answer (", lambda: None) + + def worker(**step): return {"role": "worker", **step} @@ -196,7 +200,7 @@ class Checkout: self.git("add", "todo.md") self.git("commit", "--quiet", "-m", "plan") - def run(self, steps, argv=(TASK,), cwd=None, terminal_input=None, stdout_on_terminal=True, before_typing=None): + def run(self, steps, argv=(TASK,), cwd=None, terminal_input=None, stdout_on_terminal=True, before_typing=None, typed_early=""): for name in ("FAKE_CLAUDE_LOG", "LOOP_TEST_LOG"): pathlib.Path(self.env[name]).unlink(missing_ok=True) pathlib.Path(self.env["FAKE_CLAUDE_SCENARIO"]).write_text(json.dumps(steps)) @@ -206,7 +210,7 @@ class Checkout: done = subprocess.run(command, capture_output=True, cwd=cwd, env=self.env, stdin=subprocess.DEVNULL, text=True, timeout=60) code, stdout, stderr = done.returncode, done.stdout, done.stderr else: - code, stdout, stderr = self.run_on_terminal(command, cwd, terminal_input, stdout_on_terminal, before_typing) + code, stdout, stderr = self.run_on_terminal(command, cwd, terminal_input, stdout_on_terminal, before_typing, typed_early) started = lines(pathlib.Path(self.env["LOOP_TEST_LOG"])) return Run( calls=lines(pathlib.Path(self.env["FAKE_CLAUDE_LOG"])), @@ -217,8 +221,8 @@ class Checkout: stdout=stdout, ) - def run_on_terminal(self, command, cwd, typed, stdout_on_terminal, before_typing): - """Types the input at once, or once stderr shows before_typing's text and its callback has run.""" + def run_on_terminal(self, command, cwd, typed, stdout_on_terminal, before_typing, typed_early): + """Types typed_early at once, then the input at once, or once stderr shows before_typing's text and its callback has run.""" controller, terminal = pty.openpty() with tempfile.TemporaryFile() as stderr, tempfile.TemporaryFile() as stdout: try: @@ -226,6 +230,7 @@ class Checkout: finally: os.close(terminal) try: + os.write(controller, typed_early.encode()) prompt, callback = before_typing or (None, None) if prompt is None: os.write(controller, typed.encode()) @@ -467,7 +472,7 @@ class Cycles(unittest.TestCase): worker(say=f"{cited} Trigger 3 fired; I ask for a higher rung. Shall I use A or B?"), judge(interrupt=True, evidence="Shall I use A or B?", question="A or B?", escalation=cited), interrupt(type="B"), judge(evidence="B", escalation="Trigger 3 fired; I ask for a higher rung."), worker(say="carrying on"), - ], terminal_input="/talk\n") + ], terminal_input="/talk\n", before_typing=ANSWERING) self.assertEqual(run.code, 130) self.assertEqual(run.roles(), ["worker", "judge", "interrupt", "judge", "worker", "judge"]) self.assertEqual([(argument(call, "--model"), argument(call, "--effort")) for call in run.calls if call["role"] != "judge"], [("claude-opus-5-5", "high"), ("claude-opus-5-5", "xhigh"), ("claude-opus-5-5", "xhigh")]) @@ -655,23 +660,16 @@ class Interrupt(unittest.TestCase): self.assertEqual(run.code, 2) self.assertEqual(len(checkout.archived()), 2) - def test_resumes_the_worker_headless_with_the_answer_typed_at_its_terminal_and_has_the_judge_read_it_as_the_humans(self): + def test_resumes_the_worker_headless_with_the_answer_typed_at_its_terminal_not_with_keys_typed_before_it(self): checkout = Checkout(self) asked = [worker(say="Shall I use A or B?"), judge(interrupt=True, evidence="Shall I use A or B?", question="A or B?")] - run = checkout.run([*asked, worker(say="Using B."), judge(evidence="Using B.")], terminal_input="B\n") + run = checkout.run([*asked, worker(say="Using B."), judge(evidence="Using B.")], terminal_input="B\n", before_typing=ANSWERING, typed_early="stray\n") self.assertEqual(run.code, 130) self.assertEqual(run.roles(), ["worker", "judge", "worker", "judge", "worker"]) self.assertIn("A or B?\nAnswer (/talk opens claude, Enter stops the loop): ", run.stderr) - resumed = run.calls[2]["argv"] self.assertEqual(argument(run.calls[2], "--resume"), argument(run.calls[0], "--session-id")) - self.assertEqual(resumed[resumed.index("-p") + 1], "The human answered your question at loop-claude's terminal:\nB\n\nYour question was: A or B?\n\nContinue the task.") self.assertIn("[human] B\n\nUsing B.", run.calls[3]["stdin"]) - - for transcript in checkout.transcripts(): - transcript.unlink() - run = checkout.run(asked, terminal_input="\n") - self.assertEqual((run.code, run.roles()), (2, ["worker", "judge"])) - self.assertTrue(run.stderr.strip().endswith("Answer (/talk opens claude, Enter stops the loop): the human is needed to answer the question above, but nothing was typed")) + self.assertNotIn("stray", run.calls[3]["stdin"]) def test_hands_the_terminal_over_and_exits_2_when_nothing_is_typed(self): checkout = Checkout(self) @@ -681,7 +679,7 @@ class Interrupt(unittest.TestCase): checkout.claude_json().chmod(0o644) asked = [worker(say="Shall I use A or B?"), judge(interrupt=True, evidence="Shall I use A or B?", question="A or B?")] (checkout.root / "sub").mkdir() - run = checkout.run([*asked, interrupt(type="B"), judge(evidence="B"), worker()], cwd=checkout.root / "sub", terminal_input="/talk\n") + run = checkout.run([*asked, interrupt(type="B"), judge(evidence="B"), worker()], cwd=checkout.root / "sub", terminal_input="/talk\n", before_typing=ANSWERING) self.assertEqual(run.code, 130) self.assertEqual(run.roles(), ["worker", "judge", "interrupt", "judge", "worker", "judge"]) handed = run.calls[2]["argv"] @@ -699,11 +697,11 @@ class Interrupt(unittest.TestCase): for transcript in checkout.transcripts(): transcript.unlink() - run = checkout.run([*asked, interrupt()], terminal_input="/talk\n") + run = checkout.run([*asked, interrupt()], terminal_input="/talk\n", before_typing=ANSWERING) self.assertEqual((run.code, run.roles()), (2, ["worker", "judge", "interrupt"])) self.assertTrue(run.stderr.strip().endswith("the human is needed to answer the question above, but the interrupt ended with nothing typed")) - run = checkout.run([worker(say="A or B?"), judge(interrupt=True, evidence="A or B?", question="A or B?", vanish=True)], terminal_input="/talk\n") + run = checkout.run([worker(say="A or B?"), judge(interrupt=True, evidence="A or B?", question="A or B?", vanish=True)], terminal_input="/talk\n", before_typing=ANSWERING) self.assertEqual((run.code, run.roles()), (1, ["worker", "judge"])) self.assertTrue(run.stderr.strip().endswith("could not start claude for the interrupt: No such file or directory")) @@ -723,14 +721,14 @@ class Interrupt(unittest.TestCase): checkout.claude_json().unlink(missing_ok=True) if text is not None: checkout.claude_json().write_text(text) - run = checkout.run(asked, terminal_input="/talk\n") + run = checkout.run(asked, terminal_input="/talk\n", before_typing=ANSWERING) self.assertEqual(run.code, 2) self.assertIn(f"could not read {checkout.claude_json()}: {said}\n", run.stderr) self.assertEqual(checkout.claude_json().read_text() if checkout.claude_json().exists() else None, text) trusted = json.dumps({"projects": {str(checkout.root): {"hasTrustDialogAccepted": True}}}) checkout.claude_json().write_text(trusted) - run = checkout.run(asked, terminal_input="/talk\n") + run = checkout.run(asked, terminal_input="/talk\n", before_typing=ANSWERING) self.assertNotIn(str(checkout.claude_json()), run.stderr) self.assertNotIn("trusted for the interrupt", run.stderr) self.assertEqual(checkout.claude_json().read_text(), trusted) @@ -743,7 +741,7 @@ class Interrupt(unittest.TestCase): checkout.run(asked[:2]) checkout.home.chmod(0o500) self.addCleanup(checkout.home.chmod, 0o700) - run = checkout.run([worker(), *asked[1:]], terminal_input="/talk\n") + run = checkout.run([worker(), *asked[1:]], terminal_input="/talk\n", before_typing=ANSWERING) self.assertEqual(run.code, 2) self.assertIn(f"could not write {checkout.claude_json()}: Permission denied\n", run.stderr) self.assertEqual(checkout.claude_json().read_text(), "{}") @@ -751,7 +749,7 @@ class Interrupt(unittest.TestCase): @unittest.skipIf(os.geteuid() == 0, "root reads an unreadable file") def test_exits_1_when_the_transcript_cannot_be_read_after_the_interrupt(self): checkout = Checkout(self) - run = checkout.run([worker(say="A or B?"), judge(interrupt=True, evidence="A or B?", question="A or B?"), interrupt(type="B", unreadable=True)], terminal_input="/talk\n") + run = checkout.run([worker(say="A or B?"), judge(interrupt=True, evidence="A or B?", question="A or B?"), interrupt(type="B", unreadable=True)], terminal_input="/talk\n", before_typing=ANSWERING) self.assertEqual((run.code, run.roles()), (1, ["worker", "judge", "interrupt"])) self.assertRegex(run.stderr.strip().splitlines()[-1], r"^could not tell whether you typed anything: could not read the transcript .*\.jsonl: Permission denied$") diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index e0a4d7b8..23346e03 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -61,6 +61,7 @@ class FakeEffects: return Effects( claude=lambda args, cwd, stdin: self.answer("claude", (args, stdin)), claude_on_terminal=self.on_terminal_claude, + discard_typed=lambda: self.calls.append(("discard_typed", None)), execv=self.execv, git=lambda args, cwd: self.answer("git", args), input=lambda prompt: self.answer("input", prompt), @@ -161,8 +162,10 @@ class Transitions(unittest.TestCase): (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", Interrupt("e", "q")), states.HumanTalked(), states.Judging("/t")), - (states.Interrupting("/t", Interrupt("e", "q"), 3), states.HumanTalked(), states.Judging("/t", 3)), + (states.Interrupting("/t", Interrupt("e", "q")), states.TalkChosen(), states.Talking("/t")), + (states.Interrupting("/t", Interrupt("e", "q"), 3), states.TalkChosen(), states.Talking("/t", 3)), + (states.Talking("/t"), states.HumanTalked(), states.Judging("/t")), + (states.Talking("/t", 3), states.HumanTalked(), states.Judging("/t", 3)), (states.Interrupting("/t", Interrupt("e", "q")), states.HumanTyped(TYPED), states.Working(TYPED)), (states.Interrupting("/t", Interrupt("e", "q"), 3), states.HumanTyped(TYPED), states.Working(TYPED, 3)), (states.Working(TYPED, 3), states.WorkerRan("/t"), states.Judging("/t", 3)), @@ -172,8 +175,8 @@ class Transitions(unittest.TestCase): 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(QuotedAnswer("e", "Which one?", "A."), 3), states.Working(TYPED, 3), states.Judging("/t"), states.Judging("/t", 3), states.Interrupting("/t", Interrupt("e", "q")), states.Interrupting("/t", Interrupt("e", "q"), 3), states.Closing("/t", Finished("e")), states.Ended(Finished("e"))) - every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), answered, states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanTalked(), states.HumanTyped(TYPED), states.Archived()) + every_state = (states.Working(), states.Working(QuotedAnswer("e", "Which one?", "A."), 3), states.Working(TYPED, 3), states.Judging("/t"), states.Judging("/t", 3), states.Interrupting("/t", Interrupt("e", "q")), states.Interrupting("/t", Interrupt("e", "q"), 3), states.Talking("/t"), states.Talking("/t", 3), states.Closing("/t", Finished("e")), states.Ended(Finished("e"))) + every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), answered, states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.TalkChosen(), states.HumanTalked(), states.HumanTyped(TYPED), states.Archived()) for state in every_state: for event in every_event: if (state, event) not in [(state, event) for state, event, _ in legal]: @@ -384,10 +387,13 @@ class Cycles(unittest.TestCase): self.assertEqual(fake.made("claude_on_terminal"), []) resumed = fake.made("stream_claude")[1] self.assertEqual(resumed[resumed.index("--resume") + 1], str(self.session.id)) - self.assertEqual(resumed[resumed.index("-p") + 1], "The human answered your question at loop-claude's terminal:\nUse B.\n\nYour question was: Which one?\n\nContinue the task.") + typed = resumed[resumed.index("-p") + 1] + self.assertEqual(prompts.typed_answer(typed)[1], "Use B.") + self.assertIn("Which one?", typed) + self.assertIn("Continue the task. The chunk is finished only once every answer the human typed in it", typed) judge_prompts = [stdin for args, stdin in fake.made("claude")] - self.assertTrue(judge_prompts[1].split("\n\nDecide whether")[0].endswith("[human] Use B.\n\nworking")) - self.assertNotIn("[loop] The human answered", judge_prompts[1]) + self.assertRegex(judge_prompts[1], r"(?s)\[loop\] Your question was: Which one\?.*\n\n\[human\] Use B\.\n\nworking\n\nDecide whether") + self.assertNotIn("The human answered", judge_prompts[1]) def test_an_interrupt_that_steps_the_worker_up_names_its_new_rung_in_the_prompt_that_resumes_it_with_the_typed_answer(self): fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 2, claude=[judged("interrupt", escalation="working"), judged("finished")], inputs=["Use B."]) @@ -397,7 +403,19 @@ class Cycles(unittest.TestCase): self.assertEqual(concluded.route, Route(Routing.OPUS, 179, 2, 5)) first, resumed = fake.made("stream_claude") self.assertEqual([args[args.index("--effort") + 1] for args in (first, resumed)], ["high", "medium"]) - self.assertEqual(resumed[resumed.index("-p") + 1], f"The human answered your question at loop-claude's terminal:\nUse B.\n\nYour question was: Which one?\n\nContinue the task. Your request for a higher rung went through: loop-claude runs you on {Routing.OPUS}.{prompts.rungs_held(concluded.route, Routing.OPUS)} A further request for a higher rung steps you up no more in this cycle.") + typed = resumed[resumed.index("-p") + 1] + self.assertIn("Your request for a higher rung went through: loop-claude runs you on claude-opus-5-5 at medium effort.", typed) + self.assertIn(" Launch each reviewer with the Agent tool set to model opus, effort high, the rung item 179's E + I of 5 picks.", typed) + self.assertNotIn("went through", first[first.index("-p") + 1]) + + def test_a_typed_answer_past_the_quoted_answers_cap_reaches_the_worker_with_its_own_question(self): + worker = Worker(self.paths.claude_code_transcripts.parent) + fake = FakeEffects(streams=[worker] * 5, claude=[judged("quoted", answer="Use A.")] * 4 + [judged("finished")], inputs=["Use B."]) + with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()): + self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")).verdict, Finished("working")) + typed = fake.made("stream_claude")[4] + self.assertIn("Your question was: Which one?\n\nContinue the task.", typed[typed.index("-p") + 1]) + self.assertNotIn("Those files have answered", typed[typed.index("-p") + 1]) def test_a_release_ready_to_cut_opens_claudes_session_without_asking_for_an_answer(self): def answer(args): @@ -513,27 +531,32 @@ class Limits(unittest.TestCase): class Interrupts(unittest.TestCase): - def test_puts_the_question_and_stops_off_a_terminal(self): - for on_terminal, want in ((False, Stop(2, "the human is needed to answer the question above, but stdin or stdout is not a terminal; rerun loop-claude on a terminal")), (True, None)): - with self.subTest(on_terminal=on_terminal): - fake = FakeEffects(on_terminal=on_terminal) - with contextlib.redirect_stderr(io.StringIO()) as said: - self.assertEqual(interrupt.put_question("Which one?", fake.effects()), want) - self.assertEqual(said.getvalue(), "\nWhich one?\n") - self.assertEqual(fake.calls, []) + def put(self, fake, answer_here=True): + with contextlib.redirect_stderr(io.StringIO()) as said: + put = interrupt.put_question("Which one?", answer_here, fake.effects()) + return put, said.getvalue() - def test_reads_the_line_typed_at_the_terminal_stripped(self): - for typed, want in ((" Use B. ", "Use B."), (" /talk ", "/talk")): + def test_stops_off_a_terminal_before_asking(self): + fake = FakeEffects(on_terminal=False) + self.assertEqual(self.put(fake), (Stop(2, "the human is needed to answer the question above, but stdin or stdout is not a terminal; rerun loop-claude on a terminal"), "\nWhich one?\n")) + self.assertEqual(fake.calls, []) + + def test_returns_the_line_typed_after_the_question_stripped_dropping_what_was_typed_before(self): + fake = FakeEffects(inputs=[" Use B. "]) + self.assertEqual(self.put(fake), ("Use B.", "\nWhich one?\n")) + self.assertEqual(fake.calls, [("discard_typed", None), ("input", "Answer (/talk opens claude, Enter stops the loop): ")]) + + def test_talks_on_talk_or_at_once_where_the_answer_is_not_asked_for_here(self): + for typed, answer_here in (([" /talk "], True), ([], False)): with self.subTest(typed=typed): - fake = FakeEffects(inputs=[typed]) - self.assertEqual(interrupt.read_answer(fake.effects()), want) - self.assertEqual(fake.made("input"), ["Answer (/talk opens claude, Enter stops the loop): "]) + fake = FakeEffects(inputs=typed) + self.assertEqual(self.put(fake, answer_here)[0], interrupt.Talk()) + self.assertEqual(len(fake.made("input")), len(typed)) def test_stops_on_an_empty_answer_or_the_inputs_end(self): for typed, why, said in ((" ", "nothing was typed", ""), (EOFError(), "the input ended", "\n")): - with self.subTest(why=why), contextlib.redirect_stderr(io.StringIO()) as printed: - self.assertEqual(interrupt.read_answer(FakeEffects(inputs=[typed]).effects()), Stop(2, f"the human is needed to answer the question above, but {why}")) - self.assertEqual(printed.getvalue(), said) + with self.subTest(why=why): + self.assertEqual(self.put(FakeEffects(inputs=[typed])), (Stop(2, f"the human is needed to answer the question above, but {why}"), f"\nWhich one?\n{said}")) def test_stops_when_nothing_was_typed_in_the_session(self): with tempfile.TemporaryDirectory() as home: @@ -961,12 +984,14 @@ class PythonEffect(unittest.TestCase): class TypedAnswers(unittest.TestCase): - def test_finds_the_answer_on_the_line_after_the_marker_that_opens_the_prompt_handing_it_over_and_in_no_other_prompt(self): + def test_splits_the_prompt_handing_over_the_answer_into_the_answer_on_the_line_after_its_marker_and_the_rest_and_no_other_prompt(self): route = Route(Rung("worker-model")) marked = "The human answered your question at loop-claude's terminal:\nB" - self.assertEqual(prompts.typed_answer(prompts.typed("Which one?", "Use B.", route, None, False)), "Use B.") - self.assertEqual(prompts.typed_answer(prompts.typed(f"Which one?\n{marked}", "Use B.", route, None, False)), "Use B.") - self.assertEqual(prompts.typed_answer(prompts.typed("Which one?", "Use B.", Route(Routing.SONNET, 179, 2, 5), Routing.OPUS, True)), "Use B.") + rest, answer = prompts.typed_answer(prompts.typed("Which one?", "Use B.", route, None, False)) + self.assertEqual(answer, "Use B.") + self.assertTrue(rest.startswith("Your question was: Which one?\n\nContinue the task.")) + self.assertEqual(prompts.typed_answer(prompts.typed(f"Which one?\n{marked}", "Use B.", route, None, False))[1], "Use B.") + self.assertEqual(prompts.typed_answer(prompts.typed("Which one?", "Use B.", Route(Routing.SONNET, 179, 2, 5), Routing.OPUS, True))[1], "Use B.") self.assertIsNone(prompts.typed_answer(prompts.answered("Which one?", marked, route, None, False))) self.assertIsNone(prompts.typed_answer(prompts.resumed(marked, route, None))) diff --git a/bin/stability_replay/test_stability_replay.py b/bin/stability_replay/test_stability_replay.py index d1012e4a..f854167f 100644 --- a/bin/stability_replay/test_stability_replay.py +++ b/bin/stability_replay/test_stability_replay.py @@ -213,7 +213,7 @@ class Main(unittest.TestCase): result = result if "api_error_status" in result else {"type": "result", "structured_output": {"found": [n + 1 for n in result["found"]]}} return subprocess.CompletedProcess(args, 0, json.dumps(result), "") - effects = Effects(claude=claude, claude_on_terminal=unused, execv=unused, git=system_effects().git, input=unused, local_time=unused, now=unused, on_terminal=unused, python=unused, sleep=unused, stream_claude=unused) + effects = Effects(claude=claude, claude_on_terminal=unused, discard_typed=unused, execv=unused, git=system_effects().git, input=unused, local_time=unused, now=unused, on_terminal=unused, python=unused, sleep=unused, stream_claude=unused) out, err = io.StringIO(), io.StringIO() with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err): code = main.main(argv, {}, self.home, effects) diff --git a/todo.md b/todo.md index d0b522e8..a6a023ed 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 0.1` -`Next ID = 181` +`Next ID = 183` ## Items @@ -39,7 +39,9 @@ | 173 | 0.3.0 | | | **Have rule-hook's `todo-rank-check` run a worktree's own `bin/rank_todo.py` when the worktree is of this repo, so a branch that changes `todo.md`'s shape commits without an override.** | 2 | 1 | 3 | 4 | 2 | 1.1 by 2, 1.4 by 2 | 5.5 | | 162 | 0.3.0 | | owner | **Script each step that 0.2.0's chunks repeated by hand and a program can compute, filing one item per step, and file this audit again for the next release.** | 2 | 2 | 1 | 3 | 3 | 1.4 by 4, 1.5 by 4 | 4.9 | | 175 | 0.3.0 | | | **Compare the first five chunks loop-claude starts with `chunk-preflight` against the five before them, and file an item where the preflight did not pay off.** | 1 | 2 | 1 | 2 | 2 | 1.4 by 3, 1.5 by 3 | 4.9 | +| 181 | 0.3.0 | | principle | **Have the test of a quoted answer's step-up assert the stepped rung's facts as literals, not through `prompts.rungs_held`.** | 1 | 1 | 1 | 1 | 1 | 1.1 by 2 | 4.4 | | 177 | 0.3.0 | | | **Move the next chunk's pick, from `LastCut` and `standing` to `chunk_item` and `default_plan`, into one module named for it, so `git_repo` only runs git and `todo_table` only parses the plan.** | 3 | 1 | 3 | 5 | 4 | 1.1 by 4 | 3.6 | +| 182 | 0.3.0 | | | **Give the answer line of loop-claude's interrupts line editing, so an arrow key moves the cursor instead of typing an escape code into the human's answer.** | 2 | 2 | 1 | 3 | 2 | 1.1 by 2 | 3.6 | | 171 | 0.3.0 | | decision | **Group the routing figures' review rounds by the reviewers' rung as well as the worker's, so a call blames a rung only for rounds its own reviews raised.** | 3 | 2 | 2 | 5 | 4 | 1.2 by 3, 1.4 by 3 | 3.2 | | 165 | 0.3.0 | | | **Make this repo's tests assert the facts a prompt or help text carries in place of its sentences, and drop the tests that scan source or assert a constant.** | 3 | 2 | 1 | 4 | 5 | 1.1 by 4, 1.4 by 3 | 3.0 | | 169 | 0.3.0 | | | **Have rule-hook's `todo-rank-check` catch a `todo.md` that the same Bash call edits and then commits.** | 3 | 1 | 3 | 5 | 3 | 1.1 by 2 | 2.7 | @@ -85,7 +87,7 @@ ### 180. Settle how a trigger that fires after a step-up at an interrupt or a quoted answer steps the worker, which today it never does. -`docs/decisions.md` → `routing: a worker whose run ends asking for a higher rung…` says a trigger that fires after the human's answer waits for the next cycle. Today it steps nothing: once an interrupt or a quoted answer has taken an escalation, `unspent` in `bin/loop_claude/cycle/run.py` drops the escalation of every later ruling of the cycle. The dropped request stays in the transcript, so in the next cycle the judge finds no trigger that fired since the worker's last request, and the worker cannot be stepped for it. Since a quoted answer resumes the worker headless up to three times a cycle, the loss is now reachable unattended. +`docs/decisions.md` → `routing: a worker whose run ends asking for a higher rung…` says a trigger that fires after the human's answer waits for the next cycle. Today it steps nothing: once an interrupt or a quoted answer has taken an escalation, `unspent` in `bin/loop_claude/cycle/run.py` drops the escalation of every later ruling of the cycle. The dropped request stays in the transcript, so in the next cycle the judge finds no trigger that fired since the worker's last request, and the worker cannot be stepped for it. A quoted answer resumes the worker headless up to three times a cycle, and an answer the human types on loop-claude's terminal resumes it headless in the same cycle too, so the loss is now reachable unattended. Options: @@ -215,6 +217,10 @@ The chunk that ships this item files a copy of it in the release after the one i Item 161 put `chunk-preflight`'s facts into a fresh worker's prompt, so the worker no longer finds them itself. Before that, in item 140's chunk, the worker spent 5 min 46 s of 30 min, 16 of its 68 messages and 226k of its 491k fresh tokens before its first edit, through 12 Bash and 5 Read calls. Measure those figures from loop-claude's archive, as medians over the first five chunks that started with the preflight and the five before them: one chunk is too noisy a baseline, as `docs/decisions.md` → `reading cost: a rise is …` records. Measure the counter-signals beside them: goal 1.4's review rounds and unfinished verdicts, and goal 1.5's 🔴 findings, per chunk, since a worker that reads less may start sooner and need more rounds or let more defects through. Where time or tokens did not fall, or a counter-signal rose, file an item naming the facts the workers still found by hand, or what the preflight got wrong. +### 181. Have the test of a quoted answer's step-up assert the stepped rung's facts as literals, not through `prompts.rungs_held`. + +`bin/loop_claude/test_loop_claude.py`'s `test_a_quoted_answer_that_cites_an_escalation_trigger_steps_the_worker_up_before_it_resumes_and_archives_the_step` builds its expected prompt from `prompts.rungs_held`, the code under test, so a bug there passes it. The technical principles' test bullet bans that shape. Assert the new rung and one review launch as literals, as the typed answer's step-up test does. Raised by the principles audit of PR #308. + ### 177. Move the next chunk's pick, from `LastCut` and `standing` to `chunk_item` and `default_plan`, into one module named for it, so `git_repo` only runs git and `todo_table` only parses the plan. Raised by PR #302's paired ruling, where two of four seats read the project as worse at these places. Item 161 put the pick in `bin/todo_table.py` (`Standing`, `LastCut`, `unreleased_entries`, `landed`, `named_releases`, `standing`, `chunk_item`) and its reader in `bin/git_repo.py` (`DefaultPlan`, `default_plan`, `todos_since`), so the git module now imports the plan model and the table parser decides how a release stands. Make each of those places easier to read: @@ -225,6 +231,10 @@ Raised by PR #302's paired ruling, where two of four seats read the project as w - `bin/loop_claude/loop/main.py` → `run_loop`: routing reads the plan as chunk-preflight's fetch left it, an order only a comment states. - `bin/chunk_preflight/gathered.py`: the name covers the data, not the pure choices it also holds. +### 182. Give the answer line of loop-claude's interrupts line editing, so an arrow key moves the cursor instead of typing an escape code into the human's answer. + +`bin/loop_claude/cycle/interrupt.py`'s `put_question` reads the answer with `input()`, and nothing under `bin/` imports `readline`, so Left types `^[[D` into the answer the worker gets. Importing `readline` gives line editing, but it writes the prompt to stdout rather than stderr, and its bracketed paste can return several lines, which `prompts.typed_answer` reads only the first of. Raised by the product-owner review of PR #308. + ### 171. Group the routing figures' review rounds by the reviewers' rung as well as the worker's, so a call blames a rung only for rounds its own reviews raised. Raised by the goals audit of PR #296. `bin/routing_figures/measure.py` groups a chunk's review rounds by the rung its worker started on, and calls for a routing change when a lower rung took more of them. Since PR #296 the reviewers may run above the worker's rung, on the one their item's E + I picks, and no figure groups rounds by it, though the archived worker line names the E + I it follows from. A cheap worker on an item of high E + I gets stronger reviewers, who may raise more rounds, and a call could then blame the worker's rung for them: an interrupt of lilleman that settles nothing (goal 1.2).