"""Replay a review pass's archived rounds on the rungs below the project's, to find which rungs may run its reviewer: docs/decisions.md β†’ `routing: a review pass runs below the project's rung only on a rung whose replay of its rounds finds a share of their πŸ”΄ and 🟑 findings no more than a margin below the project's rung's own replay`. usage: review-replay [--omit-claude-md] is one of architecture, principles, overrides, stability, product-owner or prose. is a project model on the routing ladder, such as claude-opus-5-5. The tool replays the latest 10 archived rounds of the pass whose report holds a πŸ”΄ or 🟑 finding, from the projects that ~/.claude/loop-claude-models.json runs on the model. It replays each round on the code it reviewed: in a throwaway clone of the project's checkout, at the newest commit of origin/HEAD authored by the time the round began, on the branch the reviewer started on. The clone's default branch stands at the newest commit authored before the round's chunk began, so a diff against it shows the chunk's change. The prompt names the clone in place of the worktree it named, which the chunk has since removed. A round whose code it cannot find in this way is not replayed; stderr names it and why. The prompt also names a copy of the chunk's review folder in place of that folder, holding only the reports written after the chunk began and before the round did. A replay fails where its prompt still names the review folder, or names a file there, other than a round's report, that the folder did not hold from the chunk's start until the round's. It replays every round twice on the project's rung. Even that rung finds only part of its own archived findings again, so the bar for a rung below is the mean share of those two replays, less a margin of 10 percentage points. Rounds that either replay failed on are left out, and where fewer than 8 remain, or the bar is zero or below, no rung is tried. It then replays the rounds on each rung below, highest first: the project's model at each lower effort, which the ladder leaves out, then each ladder rung down to the ladder's lowest. It stops at the first rung that doesn't qualify. A rung qualifies where it finds as many findings as reach the bar and misses no πŸ”΄ that both replays on the project's rung found; a replay that failed on it finds none. For each replay, claude on the project's rung matches the report to the archived findings, and counts a finding only where the report raises it as πŸ”΄ or 🟑. The tool prints each rung's count, each πŸ”΄ it missed, and the lowest rung that, like each rung above it, qualifies. That rung is the evidence for running the pass's reviewer on it; the decision above records each run. With --omit-claude-md it tests instead whether the pass's reviewer may start without CLAUDE.md: docs/decisions.md β†’ `agents/: a reviewer starts without CLAUDE.md only where a replay of its pass missed…`. It replays every round four times on the project's rung: three as archived, then once without the instruction files. The unchanged reviewer does not find the same findings twice, so each unchanged replay is a control: the tool prints how many findings it missed that both of the other two found. The replay without CLAUDE.md is held to the findings both of the first two found, and passes where it missed no more of them than the most any unchanged replay missed. It prints how many findings each replay found, how many the replay without CLAUDE.md is held to, and each of those it missed. A round that any of the four replays failed on is left out, and where the first two share no finding the last line says there is no evidence. Claude Code ignores an agent's `omitClaudeMd` where the agent runs the session, as it does in a replay, and runs no SubagentStart hook there. So the replay without CLAUDE.md turns the instruction files off in its settings and opens the prompt with what the hook hands a reviewer, and closes it with the header's line on the project principles. Like the loop, it tries claude three times running before it counts a reply as failed. A failed review or match leaves its round out, except on a rung below the project's, where it finds none. Exit 1, saying why, on bad arguments, an unreadable archive or models file, no archived round to replay, or a usage limit. """ import pathlib import sys import typing from transcript_archive.location import archive_root from review_replay.rounds import archived_rounds, Round, sample from rung_replay.command import arguments_or_exit, failed, limited_exit from review_replay.replay import codes_found, findings_replayed from review_replay.omit_comparison import compared from loop_effects.effects import Effects from failure import Failure from claude_code.reply import Limited from model_routing.ladder import project_rung, Rung from review_replay.recall import recall_report, recalled from review_rules.review_passes import ReviewedPass, REVIEWERS TOOL = "review-replay" OMIT = "--omit-claude-md" USAGE = f"{TOOL} [{OMIT}], one of {', '.join(REVIEWERS)} and a model on the routing ladder" LATEST = 10 def main(argv: list[str], env: typing.Mapping[str, str], home: pathlib.Path, effects: Effects) -> int: read = arguments_or_exit(TOOL, argv, __doc__, USAGE, pass_and_model) if isinstance(read, int): return read reviewed, project, without = read rounds = archived_rounds(REVIEWERS[reviewed], project.model, archive_root(home, env), home) if isinstance(rounds, Failure): return failed(TOOL, rounds.reason) codes = codes_found(rounds, effects) if not codes: return failed(TOOL, f"no archived {reviewed} round of projects on {project.model} in {archive_root(home, env)} holds a πŸ”΄ or 🟑 on code it can find") chosen = sample(list(codes), LATEST) if without: report = compared(reviewed, project, chosen, lambda found, bare: findings_replayed(found, codes[found], project, project, home, effects, bare)) if isinstance(report, Limited): return limited_exit(TOOL, report) print(report) return 0 def replay_one(found: Round, rung: Rung) -> set[int] | Failure | Limited: matched = findings_replayed(found, codes[found], rung, project, home, effects, False) if isinstance(matched, Failure): print(f" {found.root} {found.at} on {rung} failed: {matched.reason}", file=sys.stderr, flush=True) return matched recall = recalled(chosen, project, replay_one, f"{reviewed} rounds") if isinstance(recall, Limited): return limited_exit(TOOL, recall) print(recall_report(reviewed, project, recall)) return 0 def pass_and_model(argv: list[str]) -> tuple[ReviewedPass, Rung, bool] | None: """The pass, the project's rung of the model, and whether OMIT follows, as argv names them in ` [--omit-claude-md]`; None for any other argv.""" if argv[2:] not in ([], [OMIT]) or len(argv) < 2: return None reviewed = next((kind for kind in REVIEWERS if kind == argv[0]), None) project = project_rung(argv[1]) return (reviewed, project, argv[2:] == [OMIT]) if reviewed and project else None