"""Each archived case: an outcomes file's first verdict, with the transcript copy the judge read for it.""" import pathlib import sys sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1] / "bin")) from transcript_archive.outcomes import ANY_VERDICT_AT, OUTCOME_AT, task_of from claude_code.entries import AssistantTurn, HumanTurn, LoopPrompt, Text from claude_code.transcript import read_transcript from transcript_archive.location import transcript_of ARCHIVE = pathlib.Path.home() / ".claude/loop-claude-transcripts" def first_block(outcomes: str) -> tuple[str, str, str] | None: """The first verdict's stamp, its heading, such as `Verdict: interrupt`, and its whole block, up to the next outcome.""" found = ANY_VERDICT_AT.search(outcomes) if not found: return None ends = [start.start() for start in OUTCOME_AT.finditer(outcomes) if start.start() > found.start()] return found[1], found[2], outcomes[found.start():ends[0] if ends else len(outcomes)] def cases(): """Each outcomes file in the archive whose task and first verdict can be read, with that verdict and its transcript's entries.""" for outcomes in sorted(ARCHIVE.glob("*/*/*.outcomes.md")): text = outcomes.read_text(encoding="utf-8") block = first_block(text) entries = read_transcript(str(transcript_of(outcomes))) if block is not None and task_of(text) is not None and isinstance(entries, list): yield outcomes, block, entries def worker_texts(entries) -> list[str]: return [part.text for entry in entries if isinstance(entry, AssistantTurn) for part in entry.parts if isinstance(part, Text)] def last_run_text(entries) -> list[str]: """The worker's text after the last prompt loop-claude or the human gave it: what the judge rules on.""" at = max((index for index, entry in enumerate(entries) if isinstance(entry, LoopPrompt | HumanTurn)), default=-1) return worker_texts(entries[at + 1:])