# Feature: Dev Critic (Phase 3 Step 3.5 Evaluator-Optimizer)

**Pattern**: Anthropic's evaluator-optimizer from "Building Effective Agents" (Dec 2024). Generator (Phase 3 Dev) and critic (`agents/dev-critic.md`) loop on deterministic criteria already written in `rules/*.md` before any Phase 4 reviewer call.

**Gated by `prefs.global.devCritic.enabled`** (default: `false`). When enabled, after the generator's last edit and BEFORE Phase 4:

1. Dispatch `dev-critic` sub-agent (Sonnet by default, tools: `Read, Grep, Glob, Bash`).
2. Critic runs 4 deterministic gates (build / lint / test / secrets)  -  failure of any → `pass: false` with `blocking` finding.
3. If gates green, critic walks the platform checklist (iOS 13-item / Android Kotlin / Backend generic  -  selected by Phase 1 `detectedStack`).
4. Returns schema-validated JSON (`$HOME/.claude/schemas/dev-critic-output.schema.json`): `{pass, iteration, gates, findings[], escalate}`.

## Loop cap (STRICT)  -  max 2 iterations

| Round | Behavior |
|---|---|
| 1 | Full critic pass  -  all gates + full checklist |
| 2 | Re-check only round-1 failures. No new findings allowed (scope creep prevention) |
| 3+ | NOT ALLOWED. Critic returns `escalate: true`; orchestrator pauses (interactive) or proceeds to Phase 4 with logged failure (autopilot) |

## Action by severity

- `blocking` → generator MUST fix; another Dev iteration before re-critic
- `important` → generator SHOULD fix; if skipped, pass through to Phase 4 (legitimate reviewer ground)
- `suggestion` → generator's judgement; never blocks round 2

## Telemetry

Each critic call emits `dev_critic.call` with `iteration`, `pass`, `gates_failed`, `blocking`, `important`, `duration_ms`, `tokens_in/out`. Phase 7 cost rollup lists these as `phase 3.5` line items so the net saving (Phase 4 reviewer/triage calls avoided) is measurable.

## Off by default reason

Introduces ~1× Sonnet call per Dev iteration. On simple bug fixes the cost outweighs the benefit (Phase 4 would have caught the same thing for similar cost). Recommended on:

- Feature work (≥200 LOC diff)
- Security-touching paths (auth, keychain, network)
- Multi-file refactors where rule violations compound

## Why this fits orchestrator-workers + evaluator-optimizer hybrid

Phase 4 is parallelization-with-voting  -  good for *adversarial* perspectives (security, architecture). Phase 3.5 is evaluator-optimizer  -  good for *deterministic* criteria (build, tests, checklists). Sending failing builds into Phase 4 wastes 2-3 reviewer calls + Fable triage; Phase 3.5 absorbs that cost at one Sonnet call.

## Reference

See `$HOME/.claude/agents/dev-critic.md` for the full agent specification (gates, checklist enumeration, output schema, severity semantics).
