Create executable phase prompts (PLAN.md files) for a roadmap phase with integrated research and verification. Default flow: Research (if needed) -> Plan -> Verify -> Done. Orchestrates gsd-phase-researcher, gsd-planner, and gsd-plan-checker agents with a revision loop (max 3 iterations). Read all files referenced by the invoking prompt's execution_context before starting. @~/.claude/get-shit-done/references/ui-brand.md ## 1. Initialize Load all context in one call (paths only to minimize orchestrator context): ```bash INIT=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs init plan-phase "$PHASE") ``` Parse JSON for: `researcher_model`, `planner_model`, `checker_model`, `research_enabled`, `plan_checker_enabled`, `commit_docs`, `phase_found`, `phase_dir`, `phase_number`, `phase_name`, `phase_slug`, `padded_phase`, `has_research`, `has_context`, `has_plans`, `plan_count`, `planning_exists`, `roadmap_exists`. **File paths (for blocks):** `state_path`, `roadmap_path`, `requirements_path`, `context_path`, `research_path`, `verification_path`, `uat_path`. These are null if files don't exist. **If `planning_exists` is false:** Error — run `/gsd:new-project` first. ## 2. Parse and Normalize Arguments Extract from $ARGUMENTS: phase number (integer or decimal like `2.1`), flags (`--research`, `--skip-research`, `--gaps`, `--skip-verify`). **If no phase number:** Detect next unplanned phase from roadmap. **If `phase_found` is false:** Validate phase exists in ROADMAP.md. If valid, create the directory using `phase_slug` and `padded_phase` from init: ```bash mkdir -p ".planning/phases/${padded_phase}-${phase_slug}" ``` **Existing artifacts from init:** `has_research`, `has_plans`, `plan_count`. ## 3. Validate Phase ```bash PHASE_INFO=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs roadmap get-phase "${PHASE}") ``` **If `found` is false:** Error with available phases. **If `found` is true:** Extract `phase_number`, `phase_name`, `goal` from JSON. ## 4. Load CONTEXT.md Check `context_path` from init JSON. If `context_path` is not null, display: `Using phase context from: ${context_path}` **If `context_path` is null (no CONTEXT.md exists):** Use AskUserQuestion: - header: "No context" - question: "No CONTEXT.md found for Phase {X}. Plans will use research and requirements only — your design preferences won't be included. Continue or capture context first?" - options: - "Continue without context" — Plan using research + requirements only - "Run discuss-phase first" — Capture design decisions before planning If "Continue without context": Proceed to step 5. If "Run discuss-phase first": Display `/gsd:discuss-phase {X}` and exit workflow. ## 5. Handle Research **Skip if:** `--gaps` flag, `--skip-research` flag, or `research_enabled` is false (from init) without `--research` override. **If `has_research` is true (from init) AND no `--research` flag:** Use existing, skip to step 6. **If RESEARCH.md missing OR `--research` flag:** Display banner: ``` ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ GSD ► RESEARCHING PHASE {X} ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ◆ Spawning researcher... ``` ### Spawn gsd-phase-researcher ```bash PHASE_DESC=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs roadmap get-phase "${PHASE}" | jq -r '.section') PHASE_REQ_IDS=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs roadmap get-phase "${PHASE}" | jq -r '.section // empty' | grep -i "Requirements:" | head -1 | sed 's/.*Requirements:\*\*\s*//' | sed 's/[\[\]]//g' | tr ',' '\n' | sed 's/^ *//;s/ *$//' | grep -v '^$' | tr '\n' ',' | sed 's/,$//') ``` Research prompt: ```markdown Research how to implement Phase {phase_number}: {phase_name} Answer: "What do I need to know to PLAN this phase well?" - {context_path} (USER DECISIONS from /gsd:discuss-phase) - {requirements_path} (Project requirements) - {state_path} (Project decisions and history) **Phase description:** {phase_description} **Phase requirement IDs (MUST address):** {phase_req_ids} **Project instructions:** Read ./CLAUDE.md if exists — follow project-specific guidelines **Project skills:** Check .agents/skills/ directory (if exists) — read SKILL.md files, research should account for project skill patterns Write to: {phase_dir}/{phase_num}-RESEARCH.md ``` ``` Task( prompt="First, read ~/.claude/agents/gsd-phase-researcher.md for your role and instructions.\n\n" + research_prompt, subagent_type="general-purpose", model="{researcher_model}", description="Research Phase {phase}" ) ``` ### Handle Researcher Return - **`## RESEARCH COMPLETE`:** Display confirmation, continue to step 6 - **`## RESEARCH BLOCKED`:** Display blocker, offer: 1) Provide context, 2) Skip research, 3) Abort ## 6. Check Existing Plans ```bash ls "${PHASE_DIR}"/*-PLAN.md 2>/dev/null ``` **If exists:** Offer: 1) Add more plans, 2) View existing, 3) Replan from scratch. ## 7. Use Context Paths from INIT Extract from INIT JSON: ```bash STATE_PATH=$(echo "$INIT" | jq -r '.state_path // empty') ROADMAP_PATH=$(echo "$INIT" | jq -r '.roadmap_path // empty') REQUIREMENTS_PATH=$(echo "$INIT" | jq -r '.requirements_path // empty') RESEARCH_PATH=$(echo "$INIT" | jq -r '.research_path // empty') VERIFICATION_PATH=$(echo "$INIT" | jq -r '.verification_path // empty') UAT_PATH=$(echo "$INIT" | jq -r '.uat_path // empty') CONTEXT_PATH=$(echo "$INIT" | jq -r '.context_path // empty') ``` ## 8. Spawn gsd-planner Agent Display banner: ``` ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ GSD ► PLANNING PHASE {X} ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ◆ Spawning planner... ``` Planner prompt: ```markdown **Phase:** {phase_number} **Mode:** {standard | gap_closure} - {state_path} (Project State) - {roadmap_path} (Roadmap) - {requirements_path} (Requirements) - {context_path} (USER DECISIONS from /gsd:discuss-phase) - {research_path} (Technical Research) - {verification_path} (Verification Gaps - if --gaps) - {uat_path} (UAT Gaps - if --gaps) **Phase requirement IDs (every ID MUST appear in a plan's `requirements` field):** {phase_req_ids} **Project instructions:** Read ./CLAUDE.md if exists — follow project-specific guidelines **Project skills:** Check .agents/skills/ directory (if exists) — read SKILL.md files, plans should account for project skill rules Output consumed by /gsd:execute-phase. Plans need: - Frontmatter (wave, depends_on, files_modified, autonomous) - Tasks in XML format - Verification criteria - must_haves for goal-backward verification - [ ] PLAN.md files created in phase directory - [ ] Each plan has valid frontmatter - [ ] Tasks are specific and actionable - [ ] Dependencies correctly identified - [ ] Waves assigned for parallel execution - [ ] must_haves derived from phase goal ``` ``` Task( prompt="First, read ~/.claude/agents/gsd-planner.md for your role and instructions.\n\n" + filled_prompt, subagent_type="general-purpose", model="{planner_model}", description="Plan Phase {phase}" ) ``` ## 9. Handle Planner Return - **`## PLANNING COMPLETE`:** Display plan count. If `--skip-verify` or `plan_checker_enabled` is false (from init): skip to step 13. Otherwise: step 10. - **`## CHECKPOINT REACHED`:** Present to user, get response, spawn continuation (step 12) - **`## PLANNING INCONCLUSIVE`:** Show attempts, offer: Add context / Retry / Manual ## 10. Spawn gsd-plan-checker Agent Display banner: ``` ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ GSD ► VERIFYING PLANS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ◆ Spawning plan checker... ``` Checker prompt: ```markdown **Phase:** {phase_number} **Phase Goal:** {goal from ROADMAP} - {PHASE_DIR}/*-PLAN.md (Plans to verify) - {roadmap_path} (Roadmap) - {requirements_path} (Requirements) - {context_path} (USER DECISIONS from /gsd:discuss-phase) **Phase requirement IDs (MUST ALL be covered):** {phase_req_ids} **Project instructions:** Read ./CLAUDE.md if exists — verify plans honor project guidelines **Project skills:** Check .agents/skills/ directory (if exists) — verify plans account for project skill rules - ## VERIFICATION PASSED — all checks pass - ## ISSUES FOUND — structured issue list ``` ``` Task( prompt=checker_prompt, subagent_type="gsd-plan-checker", model="{checker_model}", description="Verify Phase {phase} plans" ) ``` ## 11. Handle Checker Return - **`## VERIFICATION PASSED`:** Display confirmation, proceed to step 13. - **`## ISSUES FOUND`:** Display issues, check iteration count, proceed to step 12. ## 12. Revision Loop (Max 3 Iterations) Track `iteration_count` (starts at 1 after initial plan + check). **If iteration_count < 3:** Display: `Sending back to planner for revision... (iteration {N}/3)` Revision prompt: ```markdown **Phase:** {phase_number} **Mode:** revision - {PHASE_DIR}/*-PLAN.md (Existing plans) - {context_path} (USER DECISIONS from /gsd:discuss-phase) **Checker issues:** {structured_issues_from_checker} Make targeted updates to address checker issues. Do NOT replan from scratch unless issues are fundamental. Return what changed. ``` ``` Task( prompt="First, read ~/.claude/agents/gsd-planner.md for your role and instructions.\n\n" + revision_prompt, subagent_type="general-purpose", model="{planner_model}", description="Revise Phase {phase} plans" ) ``` After planner returns -> spawn checker again (step 10), increment iteration_count. **If iteration_count >= 3:** Display: `Max iterations reached. {N} issues remain:` + issue list Offer: 1) Force proceed, 2) Provide guidance and retry, 3) Abandon ## 13. Present Final Status Route to `` OR `auto_advance` depending on flags/config. ## 14. Auto-Advance Check Check for auto-advance trigger: 1. Parse `--auto` flag from $ARGUMENTS 2. Read `workflow.auto_advance` from config: ```bash AUTO_CFG=$(node ~/.claude/get-shit-done/bin/gsd-tools.cjs config-get workflow.auto_advance 2>/dev/null || echo "false") ``` **If `--auto` flag present OR `AUTO_CFG` is true:** Display banner: ``` ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ GSD ► AUTO-ADVANCING TO EXECUTE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Plans ready. Spawning execute-phase... ``` Spawn execute-phase as Task: ``` Task( prompt="Run /gsd:execute-phase ${PHASE} --auto", subagent_type="general-purpose", description="Execute Phase ${PHASE}" ) ``` **Handle execute-phase return:** - **PHASE COMPLETE** → Display final summary: ``` ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ GSD ► PHASE ${PHASE} COMPLETE ✓ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Auto-advance pipeline finished. Next: /gsd:discuss-phase ${NEXT_PHASE} --auto ``` - **GAPS FOUND / VERIFICATION FAILED** → Display result, stop chain: ``` Auto-advance stopped: Execution needs review. Review the output above and continue manually: /gsd:execute-phase ${PHASE} ``` **If neither `--auto` nor config enabled:** Route to `` (existing behavior). Output this markdown directly (not as a code block): ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ GSD ► PHASE {X} PLANNED ✓ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ **Phase {X}: {Name}** — {N} plan(s) in {M} wave(s) | Wave | Plans | What it builds | |------|-------|----------------| | 1 | 01, 02 | [objectives] | | 2 | 03 | [objective] | Research: {Completed | Used existing | Skipped} Verification: {Passed | Passed with override | Skipped} ─────────────────────────────────────────────────────────────── ## ▶ Next Up **Execute Phase {X}** — run all {N} plans /gsd:execute-phase {X} /clear first → fresh context window ─────────────────────────────────────────────────────────────── **Also available:** - cat .planning/phases/{phase-dir}/*-PLAN.md — review plans - /gsd:plan-phase {X} --research — re-research first ─────────────────────────────────────────────────────────────── - [ ] .planning/ directory validated - [ ] Phase validated against roadmap - [ ] Phase directory created if needed - [ ] CONTEXT.md loaded early (step 4) and passed to ALL agents - [ ] Research completed (unless --skip-research or --gaps or exists) - [ ] gsd-phase-researcher spawned with CONTEXT.md - [ ] Existing plans checked - [ ] gsd-planner spawned with CONTEXT.md + RESEARCH.md - [ ] Plans created (PLANNING COMPLETE or CHECKPOINT handled) - [ ] gsd-plan-checker spawned with CONTEXT.md - [ ] Verification passed OR user override OR max iterations with user decision - [ ] User sees status between agent spawns - [ ] User knows next steps