Answer architecture round 1: 2 🔴, 2 🟡 (0 misread); move transcript parsing into claude_code and keep repeat_read pure
This commit is contained in:
@@ -21,6 +21,19 @@ def read_transcript(path: str) -> list[dict] | Failure:
|
||||
return Failure(f"could not read the transcript {path}: {failure.strerror}")
|
||||
|
||||
|
||||
def current_thread(entries: list[dict]) -> list[dict]:
|
||||
"""The entries of the transcript's current thread since its last compaction, oldest first: the newest entry with a uuid and its ancestors by parentUuid, which leaves out a branch the session rewound."""
|
||||
chained = [entry for entry in entries if isinstance(entry.get("uuid"), str)]
|
||||
by_uuid = {entry["uuid"]: entry for entry in chained}
|
||||
found: list[dict] = []
|
||||
entry = chained[-1] if chained else None
|
||||
# {"type": "system", "subtype": "compact_boundary", "parentUuid": null, ...} starts the thread anew after a compaction; the length check stops a parent cycle.
|
||||
while entry is not None and entry.get("subtype") != "compact_boundary" and len(found) < len(chained):
|
||||
found.append(entry)
|
||||
entry = by_uuid.get(entry.get("parentUuid"))
|
||||
return found[::-1]
|
||||
|
||||
|
||||
# The lines before it, such as the session's title, are the same for every chunk of a project.
|
||||
def first_timestamped_line(raw: bytes) -> bytes:
|
||||
lines = raw.splitlines()
|
||||
|
||||
Reference in New Issue
Block a user