# Verifier — Context Loading (Steps 0–2)

## Step 0: Check for Previous Verification

```bash
cat "$PHASE_DIR"/*-VERIFICATION.md 2>/dev/null
```

**If previous verification exists with `gaps:` section → RE-VERIFICATION MODE:**

1. Parse previous VERIFICATION.md frontmatter
2. Extract `must_haves` (truths, artifacts, key_links)
3. Extract `gaps` (items that failed)
4. Set `is_re_verification = true`
5. **Skip to Step 3** with optimization:
   - **Failed items:** Full 3-level verification (exists, substantive, wired)
   - **Passed items:** Quick regression check (existence + basic sanity only)

**If no previous verification OR no `gaps:` section → INITIAL MODE:**

Set `is_re_verification = false`, proceed with Step 1.

## Step 1: Load Context (Initial Mode Only)

```bash
ls "$PHASE_DIR"/*-SPRINT.md 2>/dev/null
ls "$PHASE_DIR"/*-SUMMARY.md 2>/dev/null
node ".rcode/bin/rcode-tools.cjs" roadmap get-phase "$PHASE_NUMBER"
grep -E "^| $PHASE_NUMBER" .rcode/REQUIREMENTS.md 2>/dev/null
```

Extract phase goal from ROADMAP.md — this is the outcome to verify, not the tasks.

## Step 2: Establish Must-Haves (Initial Mode Only)

In re-verification mode, must-haves come from Step 0.

### Option A: Must-haves in PLAN frontmatter

```bash
grep -l "must_haves:" "$PHASE_DIR"/*-SPRINT.md 2>/dev/null
```

If found, extract and use:

```yaml
must_haves:
  truths:
    - "User can see existing messages"
    - "User can send a message"
  artifacts:
    - path: "src/components/Chat.tsx"
      provides: "Message list rendering"
  key_links:
    - from: "Chat.tsx"
      to: "api/chat"
      via: "fetch in useEffect"
```

### Option B: Use Success Criteria from ROADMAP.md

If no must_haves in frontmatter, check for Success Criteria:

```bash
PHASE_DATA=$(node ".rcode/bin/rcode-tools.cjs" roadmap get-phase "$PHASE_NUMBER" --raw)
```

Parse the `success_criteria` array from the JSON output. If non-empty:
1. **Use each Success Criterion directly as a truth** (they are already observable, testable behaviors)
2. **Derive artifacts:** For each truth, "What must EXIST?" — map to concrete file paths
3. **Derive key links:** For each artifact, "What must be CONNECTED?" — this is where stubs hide
4. **Document must-haves** before proceeding

Success Criteria from ROADMAP.md are the contract — they take priority over Goal-derived truths.

### Option C: Derive from phase goal (fallback)

If no must_haves in frontmatter AND no Success Criteria in ROADMAP:

1. **State the goal** from ROADMAP.md
2. **Derive truths:** "What must be TRUE?" — list 3-7 observable, testable behaviors
3. **Derive artifacts:** For each truth, "What must EXIST?" — map to concrete file paths
4. **Derive key links:** For each artifact, "What must be CONNECTED?" — this is where stubs hide
5. **Document derived must-haves** before proceeding
