From 09159d7158f6f3980310ce3ba71973a828a96f98 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 9 Nov 2026 00:52:37 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20prose=20round=201:=200=20=F0=9F=94=B4,?= =?UTF-8?q?=207=20=F0=9F=9F=A1=20(0=20misread);=20make=20the=20entry=20kin?= =?UTF-8?q?ds'=20docstrings=20match=20the=20code,=20untangle=20after=5Fmar?= =?UTF-8?q?k=20and=20checked,=20and=20rename=20three=20tests=20to=20what?= =?UTF-8?q?=20they=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/claude_code/entries.py | 12 ++++++------ bin/claude_code/test_claude_code.py | 6 +++--- bin/loop_claude/cycle/judge.py | 2 +- bin/loop_claude/escalation_mark.py | 4 ++-- bin/reading_cost/measure.py | 1 - bin/routing_figures/dollars.py | 2 +- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/bin/claude_code/entries.py b/bin/claude_code/entries.py index 3f3f0372..d7c06744 100644 --- a/bin/claude_code/entries.py +++ b/bin/claude_code/entries.py @@ -5,7 +5,7 @@ import typing def json_object(raw: str | bytes) -> dict | None: - """A line of stream-json, or claude's json reply, where it is a JSON object.""" + """A line of JSON, such as a transcript line, a stream-json line or claude's json reply, where it is an object; None otherwise.""" try: found = json.loads(raw) except ValueError: @@ -15,7 +15,7 @@ def json_object(raw: str | bytes) -> dict | None: @dataclasses.dataclass(frozen=True, kw_only=True) class Entry: - """A transcript entry, with the fields every entry may carry, each "" where it has none. Entry itself is an entry of a kind no consumer reads, such as a compaction's boundary; its subclasses name the kinds consumers read.""" + """A transcript entry, with the fields every entry may carry, each "" where it has none. Kinds no consumer tells apart, such as a compaction's boundary, parse as Entry itself. Each subclass names a kind consumers tell apart.""" uuid: str = "" parent_uuid: str = "" timestamp: str = "" @@ -25,7 +25,7 @@ class Entry: @dataclasses.dataclass(frozen=True, kw_only=True) class UserText(Entry): - """The text a "user" entry holds, its blocks joined. HumanTurn, LoopPrompt and InjectedText say who wrote it.""" + """The text of a "user" entry, its text blocks joined, or of a prompt the human queued while claude worked. HumanTurn, LoopPrompt and InjectedText say who wrote it.""" text: str @@ -59,7 +59,7 @@ class ToolResult(typing.NamedTuple): @dataclasses.dataclass(frozen=True, kw_only=True) class AssistantTurn(Entry): - """A content block of an assistant message, kept where it is text or a tool call, with the message's id, model and usage. Claude Code writes one entry per block of a message, each with the message's usage.""" + """An assistant entry's text and tool-call blocks, with its message's id, model and usage. Claude Code writes one entry per block of a message, so one message's usage repeats across several entries.""" parts: tuple[Text | ToolCall, ...] = () message_id: str = "" model: str = "" @@ -85,7 +85,7 @@ def parse_entry(raw: str | bytes) -> Entry | None: def entry_from(found: dict) -> Entry: - """An entry of a transcript, or an event of stream-json, which writes assistant messages alike, as its kind.""" + """A transcript entry, or a stream-json event, as its kind.""" carried = Carried(uuid=field(found, "uuid"), parent_uuid=field(found, "parentUuid"), timestamp=field(found, "timestamp"), cwd=field(found, "cwd"), git_branch=field(found, "gitBranch")) match found.get("type"): case "assistant": @@ -94,7 +94,7 @@ def entry_from(found: dict) -> Entry: return user_entry(found, carried) case "cost-state": return cost_state(found, carried) - # Claude Code logs each API request's last message again, its tool results too, some held nowhere else, so their text counts here: {"type": "api-request-blob", "hash": "…", "message": {"role": "user", "content": [{"type": "tool_result", …}, {"type": "text", …}]}} + # Claude Code logs each API request's last message again, and some of its tool results appear nowhere else: {"type": "api-request-blob", "hash": "…", "message": {"role": "user", "content": [{"type": "tool_result", …}, {"type": "text", …}]}} case "api-request-blob": return ToolResults(**carried, results=results_in(found)) if (queued := queued_human_text(found)) is not None: diff --git a/bin/claude_code/test_claude_code.py b/bin/claude_code/test_claude_code.py index f20a1c93..bb6aea1e 100644 --- a/bin/claude_code/test_claude_code.py +++ b/bin/claude_code/test_claude_code.py @@ -90,7 +90,7 @@ class HumanTurns(unittest.TestCase): class PartLine(unittest.TestCase): - def test_renders_text_and_tool_calls_and_nothing_else(self): + def test_renders_text_and_tool_calls_but_blank_text_as_nothing(self): self.assertEqual(transcript.part_line(entries.Text("hi"), 20), "hi") self.assertEqual(transcript.part_line(entries.Text(" \n"), 20), "") self.assertEqual(transcript.part_line(entries.ToolCall("toolu_1", "Bash", {"command": "x" * 500}), 20), '[tool Bash] {"command": "xxxxxxx') @@ -109,7 +109,7 @@ class Parse(unittest.TestCase): class EntryKinds(unittest.TestCase): - def test_names_whose_text_a_user_entry_holds(self): + def test_names_who_wrote_each_user_entry_and_queued_prompt(self): self.assertEqual([entries.entry_from(found) for found in [ human("typed"), human([{"type": "text", "text": "typed "}, {"type": "text", "text": "as blocks"}]), @@ -148,7 +148,7 @@ class EntryKinds(unittest.TestCase): uuid="u", parts=(entries.Text("Starting."), entries.ToolCall("toolu_1", "Bash", {"command": "ls"})), message_id="msg_1", model="claude-opus-5-5", usage={"input_tokens": 2}, )) - def test_tool_results_queued_notifications_and_other_kinds(self): + def test_parses_tool_results_and_cost_states_and_reads_queued_notifications_and_other_kinds_as_plain_entries(self): self.assertEqual(entries.entry_from(human([{"type": "tool_result", "tool_use_id": "toolu_1", "content": "hi", "is_error": True}])), entries.ToolResults(results=(entries.ToolResult("toolu_1", "hi", True),))) self.assertEqual(entries.entry_from(queued("done", "task-notification")), entries.Entry()) self.assertEqual(entries.entry_from({"type": "system", "subtype": "compact_boundary"}), entries.Entry()) diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index c0edffdd..879fe958 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -108,7 +108,7 @@ class Grounds(typing.NamedTuple): """The texts quotes_checked checks the judge's quotes against. A quote must appear in its text as written, since a quote reworded or stitched together can say what its source does not; only the evidence may join passages with an ellipsis, each passage in order.""" # The transcript as the judge saw it. shown: str - # The worker's own lines after the escalation mark, as escalation_mark.after_mark renders them, however much of the transcript shown holds. + # The worker's own lines after the escalation mark, as escalation_mark.after_mark renders them, including those the tail in shown cuts off. after_mark: str # README.md's premises and the records. quotable: str diff --git a/bin/loop_claude/escalation_mark.py b/bin/loop_claude/escalation_mark.py index 2a0d9767..165d07d4 100644 --- a/bin/loop_claude/escalation_mark.py +++ b/bin/loop_claude/escalation_mark.py @@ -37,12 +37,12 @@ def transcript(entries: list[Entry], at: int, typed_answer: typing.Callable[[str def after_mark(entries: list[Entry], at: int) -> str: - """The worker's own lines after the mark, its assistant turns, all of them, however much of the transcript the judge is shown. loop-claude's prompts and the human's lines are left out, since they repeat earlier passages, such as the judge's evidence or the worker's question.""" + """All the text and tool calls of the worker's assistant turns after the mark, even where the judge is shown only the transcript's tail. loop-claude's prompts and the human's lines are left out, since they repeat earlier passages, such as the judge's evidence or the worker's question.""" return "\n\n".join(line for entry in entries[at:] if isinstance(entry, AssistantTurn) for line in assistant_lines(entry)) def checked(verdict: Verdict, *, after: str, shown: str) -> Verdict: - """The verdict without its escalation unless the escalation quotes both texts: after, the worker's lines after the mark as after_mark renders them, and shown, the transcript the judge was shown. A misquote, or a quote of a passage before the mark, drops the escalation, so the worker's rung holds.""" + """The verdict without its escalation unless the escalation quotes both texts: the argument after, which holds the worker's lines after the mark as after_mark renders them, and the argument shown, the transcript the judge was shown. A misquote, or a quote of a passage before the mark, drops the escalation, so the worker's rung holds.""" if isinstance(verdict, Escalating) and verdict.escalation and not (verbatim(verdict.escalation, after) and verbatim(verdict.escalation, shown)): return dataclasses.replace(verdict, escalation="") return verdict diff --git a/bin/reading_cost/measure.py b/bin/reading_cost/measure.py index 4f436df0..9bc83e80 100644 --- a/bin/reading_cost/measure.py +++ b/bin/reading_cost/measure.py @@ -46,7 +46,6 @@ def commit_time(worker: list[Entry], home: str) -> str | None: def tokens_in(turns: list[AssistantTurn]) -> int: - # Each turn is one content block of a message, and carries the message's usage. usages = {turn.message_id or turn.uuid: turn.usage for turn in turns} return sum(usage_count(usage, "input_tokens") + usage_count(usage, "cache_creation_input_tokens") for usage in usages.values()) diff --git a/bin/routing_figures/dollars.py b/bin/routing_figures/dollars.py index 0abe05ee..f360efcd 100644 --- a/bin/routing_figures/dollars.py +++ b/bin/routing_figures/dollars.py @@ -33,7 +33,7 @@ class Spent(typing.NamedTuple): def messages(entries: list[Entry]) -> list[Message]: """The assistant messages, counted once each, each with the tools whose results it took in, or `prompt` where it took none in.""" - # Claude Code writes one entry per content block of a message, each with the message's usage. The usage is the same in every entry (none of 1,681 multi-entry messages in the archive of 2026-10-28 differed), so the first is kept, where reading_cost's tokens_in keeps the last. + # A message's usage is the same in each of its entries (none of 1,681 multi-entry messages in the archive of 2026-10-28 differed), so the first is kept, where reading_cost's tokens_in keeps the last. kept: dict[str, tuple[AssistantTurn, list[str]]] = {} for entry in entries: if isinstance(entry, AssistantTurn):