---
description: Create execution plan from task constraints
agent: plan
---

# Plan: $ARGUMENTS

## For Simple Work (No Task Needed)

**Skip planning if:**

- Single file change
- Clear solution already known
- Low complexity

Just proceed with implementation.

---

## For Task-Based Planning

## MANDATORY GATE: Task Must Exist

Check task exists in Backlog MCP:

```typescript
backlog_task_view({ id: "$ARGUMENTS" });
```

If not found: STOP. Create with `/task-with-spec "$ARGUMENTS"` first.

Then verify files exist in `@backlog/tasks/$ARGUMENTS/`:

- [ ] prd.md with Goal, Scope, and Success Criteria
- [ ] spec.md with Architecture, Constraints, and Edge Cases

**If files missing:** STOP. Complete task setup first.

## Step 1: Extract Task Requirements

Read `@backlog/tasks/$ARGUMENTS/prd.md`:

- **Goal:** What is the primary objective?
- **In-Scope:** What's included?
- **Out-of-Scope:** What's excluded?
- **Success Criteria:** What checkboxes must be [x] marked?

Read `@backlog/tasks/$ARGUMENTS/spec.md`:

- **Architecture:** What's the proposed approach?
- **Constraints:** What rules must be followed?
- **Edge Cases:** What corner cases must be handled?
- **Testing:** How will success be verified?

## Step 2: Assess Complexity

Based on PRD scope and spec architecture, determine:

**Phase Count:**

- 1 phase = trivial (single file, simple change)
- 2 phases = simple (multiple files, straightforward logic)
- 3-4 phases = moderate (significant changes, multiple components)
- 5+ phases = complex (multi-system impact, high coordination)

**Risk Level:**

- LOW = no security/data/user impact
- MEDIUM = some security or data implications
- HIGH = significant security, breaking changes, or user impact

**Agent Assignment:**

- @build = simple tasks (1-2 phases, low risk)
- @oracle = moderate tasks (3-4 phases, medium risk, complex architecture decisions)
- @code-auditor = tasks with security implications
- @orchestrator = complex tasks (5+ phases, multiple agents needed)

## Step 3: Create Phase Breakdown

For each phase, specify:

1. **Phase Name:** What's being delivered?
2. **Agent:** Who executes it?
3. **Deliverables:** What concrete outputs?
4. **Validation:** How is it verified?
5. **Constraints:** Which spec rules apply?
6. **Dependencies:** What must be done first?

**Example phase:**

```
Phase 1: Add API endpoint
- Agent: @build
- Deliverables: New endpoint at POST /api/users, with request validation
- Validation: Endpoint works, handles invalid input, integrates with existing auth
- Constraints: Must use existing patterns, no new dependencies
- Dependencies: None (first phase)
```

## Step 4: Validate Plan Against Constraints

Check that the plan:

- [ ] Achieves PRD goal
- [ ] Respects PRD scope boundaries
- [ ] Follows ALL spec constraints
- [ ] Handles ALL spec edge cases
- [ ] Meets ALL success criteria
- [ ] Uses only spec-allowed approaches
- [ ] Has verification for each phase

**If ANY check fails:** Redesign plan.

## Step 5: Present Plan for Approval

Display:

```
EXECUTION PLAN: Task $ARGUMENTS

Goal: [From PRD]
Complexity: [Phase count and risk level]
Timeline: [Rough estimate]

Phase Breakdown:
- Phase 1: [Name] (Agent: @X)
- Phase 2: [Name] (Agent: @X)
[etc]

Constraint Compliance:
✅ Scope: [How it respects PRD scope]
✅ Constraints: [How it follows spec]
✅ Edge Cases: [How they're handled]
✅ Success Criteria: [How they're achieved]

Options:
1. "approved" → Implement phases in order
2. "revise [feedback]" → Update plan
3. "show spec" → Display task constraints again
4. "cancel" → Stop planning
```

**WAIT FOR EXPLICIT APPROVAL - DO NOT PROCEED WITHOUT USER RESPONSE**

## Step 6: Execute Approved Plan

Once approved, implement each phase using the assigned agent:

```
@[agent-name] Execute Phase [N] of task $ARGUMENTS

PRD: @backlog/tasks/$ARGUMENTS/prd.md
Spec: @backlog/tasks/$ARGUMENTS/spec.md

Phase deliverables: [List from approved plan]
Validation approach: [From approved plan]

Work ONLY within scope. Stop if constraint violation detected.
Complete review.md after ALL phases done.
```

---

**ANTI-HALLUCINATION: Task-based plans validate against constraints; simple work skips planning**
