v0.7.0 — token-burn: Fix pr-reviewer base-branch detection so diff scopes correctly

Problem

pr-reviewer's spawn prompt does not reliably pass an explicit diff base. In multi-MR sessions (like v0.6.0 release with 11+ in-flight MRs), pr-reviewer has been observed running git diff against the wrong target — comparing the current branch against main when the correct comparison is against dev, or against a stale upstream pointer.

The bigger the diff pr-reviewer ingests, the more tokens burn AND the lower the review quality (signal lost in noise).

Evidence (verified against live source)

  • agents/pr-reviewer.md frontmatter declares tools: Read, Glob, Grep, Bash, Task, mcp__plugin_tmb_trajectory-server and skills: [tmb_review] — pr-reviewer runs as a CC subagent, has Bash access, and loads tmb_review (274 LOC) at spawn.
  • skills/tmb_review/SKILL.md §A "Worktree discipline" and §A Phase 1 reasoning sections cover correctness/design/pattern reasoning, but do not prescribe how to compute the diff base — they assume bro passes commits.
  • skills/tmb_review/SKILL.md §C "Spawning pr-reviewer (bro-side discipline)" — bro's spawn prompt construction lives here but base-ref discipline is implicit.
  • templates/agents/pr-reviewer.md matches agents/pr-reviewer.md exactly (project-local mirror).
  • This was identified as Cause C/D contributor in !2900 (closed in v0.6.0); the workflow doctrine was tightened but diff-base detection itself was not addressed.

Plan

  1. Spawn-prompt contract: extend tmb_review §C so bro MUST pass base_ref (e.g. origin/dev) explicitly. pr-reviewer MUST refuse if base_ref is missing.
  2. Diff scope rule in tmb_review §A: "Compute diff exactly as git diff <base_ref>...HEAD — never git diff main or git diff HEAD~N or git diff origin."
  3. Diff-size cap: if git diff <base>...HEAD | wc -l returns >2000 LOC, pr-reviewer refuses and asks bro to split the push.
  4. Schema column pr_review_runs.diff_loc INTEGER — recorded by pr-reviewer at start of review. Enables post-fix measurement.
  5. L4 simulation: spawn pr-reviewer with intentionally-stale upstream pointer or no base_ref; verify it refuses cleanly.

Acceptance criteria

  • New L4 test: pr-reviewer spawned without base_ref refuses with structured error.
  • New L4 test: pr-reviewer spawned with diff >2000 LOC refuses with "diff too large; split push" message.
  • Schema v3 includes pr_review_runs.diff_loc.
  • L5 dogfood verifies pr-reviewer diff size is bounded.

Out of scope

  • Auto-splitting commits into smaller chunks.
  • Per-file vs per-commit review modes.

Coordination

  • !2900 (closed in v0.6.0) covered workflow/protocol gaps. This covers the diff scope gap that remained.
  • Pairs with #2906 (schema v3) — pr_review_runs.diff_loc would ship in that migration.

Note on source

Verified against agents/pr-reviewer.md, templates/agents/pr-reviewer.md, skills/tmb_review/SKILL.md (sections A, C). Previous description had the right symptom but didn't cite the specific section/file lines.

Edited by Zax Shen