Answer prose round 1: 0 🔴, 7 🟡 (0 misread); make the entry kinds' docstrings match the code, untangle after_mark and checked, and rename three tests to what they check
This commit was merged in pull request #441.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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("<task-notification>done</task-notification>", "task-notification")), entries.Entry())
|
||||
self.assertEqual(entries.entry_from({"type": "system", "subtype": "compact_boundary"}), entries.Entry())
|
||||
|
||||
Reference in New Issue
Block a user