---
name: forge:verify
description: Verify all phase plans against requirements and generate gap closure plans.
argument-hint: <phase-name>
allowed-tools:
  - Read
  - Write
  - Glob
  - Grep
  - Bash
  - Task
---

Verify phase $ARGUMENTS plans cover all requirements via goal-backward analysis. If gaps are found, generate numbered gap closure plan files (same format as regular plans) that can be executed with `/forge:execute {phase} --gaps`.

**Read:** All `.planning/phases/{phase}/*-PLAN.md` files, all `*-SUMMARY.md` files (if execution happened), REQUIREMENTS.md, ROADMAP.md, state/STATE.json

**Steps:**

1. **Discover all plan and summary files:**
   - Glob `.planning/phases/{phase}/*-PLAN.md` → parse each plan's frontmatter and tasks
   - Glob `.planning/phases/{phase}/*-SUMMARY.md` → check execution results
   - Build complete picture: what was planned, what was executed, what succeeded

2. **Requirements coverage** — Map each requirement from REQUIREMENTS.md → plans/tasks that cover it. Mark each as:
   - **Covered** — task exists and (if executed) summary confirms completion
   - **Planned** — task exists but not yet executed
   - **Gap** — no task addresses this requirement

3. **Goal-backward analysis** — For each milestone goal from ROADMAP.md:
   - Trace: goal → plans → tasks → acceptance criteria
   - Flag missing links in the chain

4. **Integration completeness** — Check cross-plan contracts defined, integration points covered, no conflicting file modifications across plans in the same wave.

5. **Dependency validation** — Verify plan dependency graph is acyclic, all depends_on references are valid plan numbers, wave assignments are correct.

6. **Scope validation** — Cross-reference with CONTEXT.md:
   - Deferred ideas should NOT appear in any plan
   - Locked decisions should be implemented as specified
   - Claude's discretion areas should have reasonable choices

7. **Write VERIFICATION.md** — `.planning/phases/{phase}/VERIFICATION.md` with:
   ```markdown
   # {Phase} Verification
   **Verified:** [timestamp]
   **Result:** {PASS | GAPS FOUND}

   ## Requirements Coverage
   | Requirement | Status | Covered By |
   |-------------|--------|------------|
   | REQ-001     | Covered | Plan 01, Task 1 |
   | REQ-003     | GAP    | — |

   ## Goal-Backward Analysis
   [Results per goal]

   ## Integration Check
   [Results]

   ## Dependency Validation
   [Results]

   ## Scope Validation
   [Results]

   ## Gaps Summary
   {count} gaps identified requiring remediation.
   ```

8. **If gaps found — generate gap closure plan files:**
   - Determine next plan number (highest existing + 1)
   - Create `.planning/phases/{phase}/{phase}-{next}-PLAN.md` for each gap cluster
   - Each gap closure plan uses the same format as regular plans with frontmatter:
     ```yaml
     ---
     phase: {phase-name}
     plan: {next-number}
     wave: 1
     depends_on: []
     files_modified: [...]
     autonomous: true
     gap_closure: true
     ---
     ```
   - Gap closure plans contain 2-3 remediation tasks each (same XML task format)
   - Number sequentially after existing plans
   - Gap plan limit: max 3 gap closure plans. If more gaps exist, recommend breaking into sub-phases.

9. **Routing:**
   - If **no gaps:** "All requirements covered. Ready to execute." → Offer `/forge:execute {phase}`
   - If **gaps found:** Show gap summary, list generated gap closure plans → Offer `/forge:execute {phase} --gaps` to run only gap closure plans
   - If **already executed and gaps in results:** Generate plans targeting execution failures

**Pass criteria:** All requirements covered, goals achievable, deps valid, scope aligned with CONTEXT.md.
