Parse each transcript entry once into a typed value naming its kind, and have every consumer read those types

This commit is contained in:
2026-11-09 00:12:13 +01:00
parent bc2d7d6d5e
commit b83c1ddf19
20 changed files with 408 additions and 254 deletions
+8 -9
View File
@@ -5,7 +5,7 @@ import pathlib
import re
import typing
from claude_code.entries import assistant_parts, content, part_text, parts
from claude_code.entries import AssistantTurn, Entry, Text, UserText
from rung_replay.search import Replay
from model_routing.ladder import Rung
@@ -34,20 +34,19 @@ class Round:
return stamp_seconds(self.at)
def round_from(reviewer: str, root: str, began: float, entries: list[dict]) -> Round | None:
def round_from(reviewer: str, root: str, began: float, entries: list[Entry]) -> Round | None:
"""The round a reviewer's transcript holds: its first entry's prompt, and its last text. None without a 🔴 or 🟡 finding to hold a rung to."""
reports = [text for found in entries for part in assistant_parts(found) if (text := part_text(part))]
first = entries[0] if entries else {}
reports = [part.text for entry in entries if isinstance(entry, AssistantTurn) for part in entry.parts if isinstance(part, Text) and part.text]
first = entries[0] if entries else Entry()
if not stamped(first) or not reports or not (findings := recorded_findings(reports[-1])):
return None
prompt = content(first)
prompt = prompt if isinstance(prompt, str) else "".join(part_text(part) or "" for part in parts(first))
return Round(reviewer, root, first.get("gitBranch", ""), first["timestamp"], began, prompt, tuple(findings))
prompt = first.text if isinstance(first, UserText) else ""
return Round(reviewer, root, first.git_branch, first.timestamp, began, prompt, tuple(findings))
def stamped(entry: dict) -> bool:
def stamped(entry: Entry) -> bool:
try:
return isinstance(entry.get("timestamp"), str) and bool(stamp_seconds(entry["timestamp"]))
return bool(entry.timestamp) and bool(stamp_seconds(entry.timestamp))
except ValueError:
return False