> Agent-ready spec from Diff of the Day (2026-12-01, idea 1). Give this file to your coding agent (Claude Code, Codex, Cursor) and ask it to build the P0 requirements first.

# Spec: Verification funnel for an agent loop

## Problem Statement
An agent loop that calls a large model as a judge after every change is slow and expensive. Most rejections are for simple reasons that a script or a small model can find. Nobody measures which share of judge calls a cheaper check could have answered.

## Goals
- Cut judge tokens per accepted change by at least 50% on a replay of one day of changes.
- Keep the final verdict equal to the judge-only verdict on at least 95% of the replayed changes.
- Report the median wait before the first rejection, before and after.

## Non-Goals
- Replacing the judge: it stays as the last stage, because it catches what the cheap stages cannot.
- Training a custom classifier: a small hosted or local model with a prompt is enough for one evening.
- A dashboard: a Markdown report is enough.

## User Stories
- As a developer, I want a simple miss rejected in seconds so that the loop does not wait for the judge.
- As the owner of the bill, I want to see how many judge calls each stage saved so that I can tune the funnel.
- Edge case: as a developer, I want a stage that crashes to count as "pass to the next stage" and be logged, so that a broken check never accepts or rejects a change by itself.

## Requirements
### P0
- A runner that takes a change (a diff and the task text) and runs three stages in order: deterministic checks, small-model check, judge.
  - [ ] A stage can answer reject or pass on; only the judge can accept.
  - [ ] Each call is logged with stage, verdict, seconds and tokens.
- A replay command that runs the funnel and the judge alone on a folder of recorded changes.
  - [ ] The report shows agreement, tokens and wait time for both paths.

### P1
- Stage 1 rules in a config file (required files, forbidden paths, test command).
  - [ ] A rule can be added without a code change.

### P2
- A sample audit: send 5% of stage rejections to the judge and report the disagreements.
  - [ ] The report lists each disagreement with the change id.

## Success Metrics
- Judge tokens per accepted change, before and after.
- Share of rejections made by stage 1 and by stage 2.
- Agreement with the judge-only verdict.

## Open Questions
- Which small model is fast enough and cheap enough for stage 2?
- How many recorded changes are needed for a fair replay?

## Timeline
One evening: runner and logging first, replay second, config and audit if time remains.

## Agent Instructions
- Suggested stack: Python or TypeScript, the test and lint commands the repository already has, one small model and one large model through the same client.
- Build order: log format, stage interface, stage 1, stage 2, judge, replay report.
- Safety: run the checks in the project sandbox, never send secrets or environment files to a model, and do not change the repository under test.
- Done when: the replay report shows tokens, wait time and agreement for both paths on at least 30 recorded changes.

## Sources
- https://lnkd.in/p/d-Dy6Mrf
- https://github.blog/ai-and-ml/github-copilot/more-agents-fewer-blind-spots-inside-github-copilot-code-review/
