```yaml
version: 1
meta:
  name: code-review
  description: >
    Review the diff of a branch against its base and produce a typed,
    severity-rated review report grounded in the actual changes. Read-only:
    the loop never modifies the target repository.
  author: looper-pattern-library
  created: 2026-07-05

goal:
  statement: >
    Review the changes on branch {{BRANCH}} relative to {{BASE_BRANCH}} in the
    repository at {{REPO_DIR}} for correctness bugs, security issues, and
    maintainability problems, and produce REVIEW.md where every finding is
    typed (bug / security / maintainability), severity-rated (critical /
    major / minor), located at file:line in the new code, and justified by a
    rationale grounded in the diff - not in speculation about unseen code.
  context_sources:
    # The diff and the commit list are captured into the host prompt directly.
    - cmd: "git -C {{REPO_DIR}} diff {{BASE_BRANCH}}...{{BRANCH}}"
      timeout_sec: 60
    - cmd: "git -C {{REPO_DIR}} log --oneline {{BASE_BRANCH}}..{{BRANCH}}"
      timeout_sec: 60
  definition_of_done: >
    REVIEW.md exists, names the reviewed range, and (1) every finding carries
    type, severity, file:line, and rationale, (2) every hunk that changes
    behavior has been examined - anything skipped is listed with a reason,
    (3) there is no TBD or placeholder text, and (4) a report with zero
    findings says so explicitly and states what was checked.
  verification:
    - id: review-schema
      type: programmatic
      # Structural check: findings carry type/severity/location/rationale; no TBDs.
      check: ["python", "scripts/check-review.py", "loop-workspace/REVIEW.md"]
      expect: exit_zero
    - id: plan-sound
      type: judge
      rubric: >
        The review-plan.md lists the files and hunks in the diff, flags which
        ones are behavior-changing and therefore need close review, and
        depends only on the captured diff and log. Verdict revise if any
        changed file is absent from the plan or the plan invents files not
        in the diff.
    - id: findings-grounded
      type: judge
      rubric: >
        Judge REVIEW.md against the diff in the context. Every finding must
        point at lines that exist in the diff and describe a defect visible
        there. Mark verdict revise for any finding that is speculative,
        mislocated, restates a style preference as a defect, or pads the
        report with nits while a behavior-changing hunk goes unexamined.

host:
  cli: claude
  model: default
  invoke: ["claude", "-p"]
  timeout_sec: 600

council:
  # Local-family judge - gates the plan and the report.
  - id: judge-1
    role: judge
    cli: claude
    model: default
    invoke: ["claude", "-p"]
    timeout_sec: 600
    scope: [plan, delivery]
    local: false
  # Cross-vendor second opinion - NOTES ONLY, cannot clean a gate. First send
  # is consent-gated at runtime; redaction-glob files never reach it.
  - id: second-opinion
    role: reviewer
    cli: codex
    model: default
    invoke: ["codex", "exec"]
    timeout_sec: 600
    scope: [delivery]
    local: false

gates:
  plan_gate:
    when: after_plan
    members: [judge-1]
    verdict_policy: revise_until_clean
    verdict_source: judge-1
    criteria: [plan-sound]
    max_revisions: 2
  delivery_gate:
    when: after_each_delivery
    members: [judge-1, second-opinion]
    verdict_policy: revise_until_clean
    verdict_source: judge-1
    criteria: [review-schema, findings-grounded]
    max_revisions: 3

loop_control:
  max_iterations: 8
  budget:
    usd: 5.0
    tokens: 1500000
    wall_clock_min: 30
  no_progress:
    max_stalled_iterations: 2
    signals:
      - same blocking issue repeats across iterations
      - REVIEW.md has no material change after a revise verdict
      - the same hunk stays unexamined
    action: stop
  human_checkpoints:
    - before first cross-vendor send to second-opinion
  stop_conditions:
    - delivery_gate passes clean on REVIEW.md
    - max_iterations reached
    - same blocker repeats for 2 iterations
    - any budget cap exceeded

execution:
  mode: in_session
  # The loop writes only inside ./loop-workspace; the reviewed repo is
  # untouched (diff and log are read via git, no checkout changes).
  isolation: current_workspace
  side_effects:
    requires_approval: true
    duplicate_action_check: true
    notes: >
      Only side effect is the consent-gated cross-vendor send. The reviewed
      repository is never modified.

observability:
  state_file: state.json
  run_log: run-log.md
  checkpoint_granularity: gate

privacy:
  egress:
    - to: judge-1
      sends: [plan, review-report]
      redact: [".env", ".env.*", "secrets/**", "**/*.key"]
      consent: required
    - to: second-opinion
      # The diff under review plus the draft findings - never redaction-glob files.
      sends: [diff, review-report]
      redact: [".env", ".env.*", "secrets/**", "**/*.key"]
      consent: required

workspace:
  dir: ./loop-workspace
  layout:
    - review-plan.md        # host plan, gated by plan_gate
    - "review-draft-{n}.md"
    - "review-{n}.md"       # judge + reviewer notes per iteration
    - REVIEW.md             # final deliverable
    - state.json
    - run-log.md
```

---

Copyright (c) 2026 Kevin Simback License files are attached. [MIT](https://knowen.md/f/0cf2b407-a5a2-4840-bbfc-2450c7693b96)

### MIT notice

````text
MIT License

Copyright (c) 2026 Kevin Simback

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
````