"""Count the archived stability rounds of round 2 or later, their BLOCKs, and the rounds the skip in larv-review ยง3 โ†’ "Re-entry" โ†’ "Mechanical answers" could skip, printing each of those for reading by hand.""" import collections import json import pathlib import re import sys ARCHIVE = pathlib.Path.home() / ".claude/loop-claude-transcripts" # The count recorded in README.md and docs/decisions.md read the reports that began before this; later ones would change it. UNTIL = "2026-11-12T10:50:00Z" # A line that opens a ๐Ÿ”ด or ๐ŸŸก finding, after any list, number or heading marks. FINDING = re.compile(r"^\s*(?:[-*]\s*|\d+\.\s*|#+\s*)*(?:\*\*)?(๐Ÿ”ด|๐ŸŸก)") # Wording of a finding that names a surviving mutant or a failing test. It casts wide; the hand reading decides. MECHANICAL = re.compile(r"surviv|mutant|fail(s|ing|ed)? (test|on)|test (fails|failed|failing)|tests? (still )?fail|\bred\b|suite (is red|fails)", re.I) # A report whose verdict line, at the start of a line, says BLOCK. A verdict stated mid-sentence isn't counted, so each printed round shows its opening line too. BLOCK = re.compile(r"^\W*(Verdict:?\s*)?\**BLOCK", re.M) def text_of(message: dict) -> str: """The text parts of a transcript message.""" content = message.get("content") if isinstance(content, str): return content return "\n".join(part.get("text", "") for part in content or [] if isinstance(part, dict) and part.get("type") == "text") def parsed(transcript: str) -> list[dict]: """A transcript's entries, one JSON object a line. str.splitlines would also split at the U+2028 a message may hold. A transcript of a cycle still running may end in a line half written, which is left out.""" lines = [line for line in transcript.split("\n") if line.strip()] try: return [json.loads(line) for line in lines] except json.JSONDecodeError: return [json.loads(line) for line in lines[:-1]] def rounds() -> list[dict]: """Each archived stability-reviewer run: its project, its cycle folder, when it began, the round its launch names, whether its last text opens with BLOCK, and its finding lines.""" found = [] for meta_path in ARCHIVE.glob("*/*/session/*/subagents/*.meta.json"): meta = json.loads(meta_path.read_text()) if meta.get("agentType") != "stability-reviewer": continue entries = parsed(meta_path.with_name(meta_path.name.removesuffix(".meta.json") + ".jsonl").read_text()) users = [entry for entry in entries if entry.get("type") == "user"] prompt = text_of(users[0]["message"]) if users else "" texts = [text_of(entry["message"]) for entry in entries if entry.get("type") == "assistant"] last = next((text for text in reversed(texts) if text.strip()), "") number = re.search(r"[Rr]ound (\d+)", meta.get("description", "") + " " + prompt[:600]) found.append({ "project": meta_path.parts[-6], "cycle": meta_path.parts[-5], "at": entries[0].get("timestamp", "") if entries else "", "round": int(number.group(1)) if number else 0, "block": bool(BLOCK.search(last)), "opens": last.strip().split("\n")[0][:120], "findings": [line.strip() for line in last.splitlines() if FINDING.match(line)], }) return found def main() -> None: """Print the totals, then each report of round 2 or later where the report before it, in the same cycle, held a ๐Ÿ”ด and every ๐Ÿ”ด and ๐ŸŸก line of that report before reads as mechanical.""" if not ARCHIVE.is_dir(): sys.exit(f"No archive at {ARCHIVE}: the count reads loop-claude's transcripts on the machine that ran them.") every = [run for run in rounds() if run["at"] < UNTIL] later = [run for run in every if run["round"] >= 2] print(f"{len(later)} reports of round 2 or later, {sum(run['block'] for run in later)} opening with BLOCK, from {len({run['project'] for run in later})} projects") by_cycle = collections.defaultdict(list) for run in every: by_cycle[(run["project"], run["cycle"])].append(run) for runs in by_cycle.values(): runs.sort(key=lambda run: run["at"]) for before, run in zip(runs, runs[1:]): reds = [line for line in before["findings"] if "๐Ÿ”ด" in line[:12]] if run["round"] >= 2 and reds and all(MECHANICAL.search(line) for line in before["findings"]): print(f"\n{run['project']} {run['at'][:16]} round {run['round']}, opening: {run['opens']}") for line in before["findings"]: print(f" before: {line[:300]}") main()