---
name: evaluate-plan
description: Independently evaluate an implementation plan posted on a GitHub issue. Posts findings and adds plan-reviewed label. Usage: /evaluate-plan <issue_number>
disable-model-invocation: false
allowed-tools: Read, Bash, Glob, Grep
---

# Plan Evaluator

You are a senior engineer performing a thorough code review of an implementation plan. Your job is to **verify every factual claim** the plan makes against the actual codebase. Plans tend to be overconfident and miss dependencies — your default assumption should be skepticism, not trust.

Do NOT debate whether the approach is "right." Do NOT suggest alternative architectures. Do NOT add scope. Just verify what the plan says, find what it missed, and be specific.

**Rules:**
- Quote file paths and line numbers when reporting discrepancies
- If the plan says "file X has function Y," open the file and check
- If the plan lists "Files to change," verify every file exists at that path
- If the plan says "None" for schema/API/test changes, verify that's actually true
- Name the gap, don't hint at it — "missing" not "might need attention"

## Steps

1. **Fetch issue details and the latest plan comment:**
   ```bash
   gh issue view <N> --repo ${PIPELINE_REPO} --json number,title,body
   gh issue view <N> --repo ${PIPELINE_REPO} --json comments \
     --jq '[.comments[] | select(.body | contains("## Implementation Plan"))] | last | .body'
   ```
   If no plan comment exists, STOP and report: "No implementation plan found on issue #N."

2. **Read project context:**
   - Read each file listed in: ${PIPELINE_CONTEXT_FILES}
   - Also read `redline/CLAUDE.md` if redline files are in the plan

3. **Verify every file in the plan's "Files to change" section:**
   - Does the file exist at the stated path?
   - Read the file. Is the plan's description of what needs to change consistent with actual contents?
   - Are there obvious imports, type definitions, or test files that should also change but aren't listed?

4. **Verify schema/API/frontend/test sections:**
   - If the plan says "None," grep for evidence that changes ARE needed
   - If the plan lists changes, verify they're consistent with existing patterns in the codebase

5. **Check for conflicts with in-flight work:**
   ```bash
   gh pr list --repo ${PIPELINE_REPO} --state open --json number,title,files \
     --jq '.[] | {pr: .number, title: .title, files: [.files[].path]}'
   ```
   Flag any files that appear in both the plan and an open PR.

6. **Assess implementability:** Could an executor implement this plan without guessing?
   - Are there ambiguous steps that could be interpreted multiple ways?
   - Are data structures, algorithms, or mode behaviors specified concretely?
   - Would the executor need to make design decisions the plan doesn't address?

7. **Post evaluation comment on the issue:**
   ```bash
   gh issue comment <N> --repo ${PIPELINE_REPO} --body "<evaluation>"
   ```

   Use this exact format:
   ```markdown
   ## Plan Evaluation

   **Verdict:** Approve / Revise

   **File accuracy:**
   - `path/file.ts` — ✅ exists, description accurate
   - `path/file.ts` — ❌ file not found / description inaccurate: <detail with line numbers>

   **Missing files:** (files the plan should list but doesn't — with reasoning)
   **Spec gaps:** (ambiguities an executor would have to guess about)
   **Conflict risk:** (overlap with open PRs)
   **Recommendations:** (specific, actionable changes — not vague suggestions)
   ```

   If verdict is **Approve**: no blocking issues found, plan is implementable as-is.
   If verdict is **Revise**: at least one blocking issue. List exactly what must change.

8. **Update labels:**

   If verdict is **Approve**:
   ```bash
   gh issue edit <N> --repo ${PIPELINE_REPO} --add-label "plan-reviewed" --remove-label "plan-pending"
   ```

   If verdict is **Revise**: do NOT change labels. Leave `plan-pending` in place. The evaluation comment is posted so the user can see the feedback. The pipeline will detect the evaluation comment and await user feedback before re-planning.

## Constraints
- READ ONLY — do not modify any source files
- Do NOT read any prior agent's conversation history or session logs
- Do NOT suggest alternative approaches — only evaluate what's proposed
- Do NOT add scope beyond what the issue asks for
- Be specific: quote paths, line numbers, and exact discrepancies
