From e7f544368890162514c8f1014c9142bf77d853ed Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 17 Oct 2026 23:41:59 +0200 Subject: [PATCH] =?UTF-8?q?Answer=20principles=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1;=20name=20the=20typed=20answer?= =?UTF-8?q?'s=20two=20parts=20in=20Typed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/claude_code/test_claude_code.py | 2 +- bin/claude_code/transcript.py | 12 +++++++++--- bin/loop_claude/cycle/prompts.py | 7 ++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/claude_code/test_claude_code.py b/bin/claude_code/test_claude_code.py index 4d436dc8..72d68d74 100644 --- a/bin/claude_code/test_claude_code.py +++ b/bin/claude_code/test_claude_code.py @@ -35,7 +35,7 @@ class Render(unittest.TestCase): queued("origin/main moved", "coordinator"), {**human("Continue the task; the previous run stopped before it was finished."), "promptSource": "sdk"}, {**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) + ], lambda prompt: transcript.Typed(*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') diff --git a/bin/claude_code/transcript.py b/bin/claude_code/transcript.py index a14dd904..248d9535 100644 --- a/bin/claude_code/transcript.py +++ b/bin/claude_code/transcript.py @@ -7,6 +7,12 @@ from failure import Failure JUDGED_TOOL_INPUT = 400 +class Typed(typing.NamedTuple): + """A -p prompt of loop-claude's that carries an answer the human typed: loop-claude's words, and that answer.""" + loop_words: str + answer: str + + def read_transcript(path: str) -> list[dict] | Failure: try: with open(path, "rb") as handle: @@ -25,8 +31,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], 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.""" +def render(entries: list[dict], typed_answer: typing.Callable[[str], Typed | 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, 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 +40,7 @@ def render(entries: list[dict], typed_answer: typing.Callable[[str], tuple[str, lines.append("[human] " + text) elif (text := loop_text(entry)) is not None: typed = typed_answer(text) - lines += ["[loop] " + text] if typed is None else ["[loop] " + typed[0], "[human] " + typed[1]] + lines += ["[loop] " + text] if typed is None else ["[loop] " + typed.loop_words, "[human] " + typed.answer] return "\n\n".join(lines) diff --git a/bin/loop_claude/cycle/prompts.py b/bin/loop_claude/cycle/prompts.py index 5ef9de49..9b769945 100644 --- a/bin/loop_claude/cycle/prompts.py +++ b/bin/loop_claude/cycle/prompts.py @@ -3,6 +3,7 @@ from model_routing.route import ESCALATION_MARKER, HIGHEST_ESCAPE_AND_IMPACT, Ro from loop_claude.routing import escalation_rungs from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES from markdown_text import listed, quoted +from claude_code.transcript import Typed # Where the judge may quote an answer from, named as the human and the worker see them; of README.md the judge sees only the premises. QUOTE_SOURCES = listed(("README.md's Goals and Audience", *RECORD_FILES, *HUMAN_RULE_NAMES), "or") @@ -137,13 +138,13 @@ def typed(question: str, answer: str, route: Route, anchor: Rung | None, stepped TYPED_HERE = "The human answered your question at loop-claude's terminal:" -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.""" +def typed_answer(prompt: str) -> Typed | None: + """The answer typed put in prompt, and the rest of that prompt, so the judge reads the answer as the human's; None for any other prompt.""" opening = f"{TYPED_HERE}\n" if not prompt.startswith(opening): return None answer, _, rest = prompt.removeprefix(opening).partition("\n\n") - return rest, answer + return Typed(rest, answer) def stepped_to(route: Route, anchor: Rung | None, stepped: bool) -> str: