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
+2 -2
View File
@@ -134,7 +134,7 @@ def archived_rounds(reviewer: str, model: str, root: pathlib.Path, home: pathlib
def chunk_rounds(reviewer: str, checkout: str, chunk: pathlib.Path) -> list[Round]:
copies = sorted(chunk.glob("*.jsonl"))
began = parse_entry(first_timestamped_line(copies[0].read_bytes())) if copies else None
if not began or not isinstance(began.get("timestamp"), str):
if not began or not began.timestamp:
return []
found = []
for meta in sorted(chunk.glob("session/*/subagents/*.meta.json")):
@@ -142,7 +142,7 @@ def chunk_rounds(reviewer: str, checkout: str, chunk: pathlib.Path) -> list[Roun
if not isinstance(described, dict) or described.get("agentType") != reviewer:
continue
entries = read_transcript(str(meta.with_name(meta.name.removesuffix(".meta.json") + ".jsonl")))
if not isinstance(entries, Failure) and (one := round_from(reviewer, checkout, stamp_seconds(began["timestamp"]), entries)):
if not isinstance(entries, Failure) and (one := round_from(reviewer, checkout, stamp_seconds(began.timestamp), entries)):
found.append(one)
return found
+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
+12 -7
View File
@@ -16,6 +16,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from review_replay.rounds import authored_by, lost_inputs, recorded_findings, report, reviewed_path, Round, round_from, sample, stamp_seconds
from loop_claude.effects import Effects, system_effects
from claude_code.entries import entry_from
from failure import Failure
from review_replay import main
from rung_replay.search import Miss, Replay, Tried
@@ -32,6 +33,10 @@ def entry(kind, text, **fields):
return {"type": kind, "message": {"content": [{"type": "text", "text": text}]}, **fields}
def kinds(found):
return [entry_from(one) for one in found]
def a_round(at, findings=("🔴 a",)):
return Round("stability-reviewer", "/code/p", "x", f"2026-10-14T10:00:0{at}Z", 0, "Review it.", tuple(findings))
@@ -52,19 +57,19 @@ class RoundFrom(unittest.TestCase):
entry("assistant", "Reading."),
entry("assistant", "BLOCK\n\n🔴 a.py:1 breaks"),
]
self.assertEqual(round_from("stability-reviewer", "/code/p", 5.0, entries), Round("stability-reviewer", "/code/p", "x", "2026-10-14T10:00:00.500Z", 5.0, "Review branch x in /code/p-x.", ("🔴 a.py:1 breaks",)))
self.assertEqual(round_from("stability-reviewer", "/code/p", 5.0, entries).seconds, 1791972000.5)
self.assertEqual(round_from("stability-reviewer", "/code/p", 5.0, kinds(entries)), Round("stability-reviewer", "/code/p", "x", "2026-10-14T10:00:00.500Z", 5.0, "Review branch x in /code/p-x.", ("🔴 a.py:1 breaks",)))
self.assertEqual(round_from("stability-reviewer", "/code/p", 5.0, kinds(entries)).seconds, 1791972000.5)
def test_reads_a_prompt_given_as_a_string(self):
start = {"type": "user", "message": {"content": "Review branch x in /code/p-x."}, "timestamp": "2026-10-14T10:00:00Z", "gitBranch": "x"}
self.assertEqual(round_from("stability-reviewer", "/code/p", 5.0, [start, entry("assistant", "🔴 a")]).prompt, "Review branch x in /code/p-x.")
self.assertEqual(round_from("stability-reviewer", "/code/p", 5.0, kinds([start, entry("assistant", "🔴 a")])).prompt, "Review branch x in /code/p-x.")
def test_skips_a_round_with_no_red_or_yellow_finding_or_no_report(self):
start = entry("user", "Review.", timestamp="2026-10-14T10:00:00Z", cwd="/code/p", gitBranch="x")
self.assertIsNone(round_from("stability-reviewer", "/code/p", 5.0, [start, entry("assistant", "APPROVE\n\n🟢 nit")]))
self.assertIsNone(round_from("stability-reviewer", "/code/p", 5.0, [start]))
self.assertIsNone(round_from("stability-reviewer", "/code/p", 5.0, []))
self.assertIsNone(round_from("stability-reviewer", "/code/p", 5.0, [{**start, "timestamp": "yesterday"}, entry("assistant", "🔴 a")]))
self.assertIsNone(round_from("stability-reviewer", "/code/p", 5.0, kinds([start, entry("assistant", "APPROVE\n\n🟢 nit")])))
self.assertIsNone(round_from("stability-reviewer", "/code/p", 5.0, kinds([start])))
self.assertIsNone(round_from("stability-reviewer", "/code/p", 5.0, kinds([])))
self.assertIsNone(round_from("stability-reviewer", "/code/p", 5.0, kinds([{**start, "timestamp": "yesterday"}, entry("assistant", "🔴 a")])))
class ReviewedPath(unittest.TestCase):