@/.claude/get-shit-done/references/ui-brand.md
@/.claude/get-shit-done/references/revision-loop.md
@/.claude/get-shit-done/references/gate-prompts.md
@/.claude/get-shit-done/references/agent-contracts.md
@~/.claude/get-shit-done/references/gates.md
0. Git Branch Invariant
Do not create, rename, or switch git branches during plan-phase. Branch identity is established at discuss-phase and is owned by the user's git workflow. A phase rename in ROADMAP.md is a plan-level change only — it does not mutate git branch names. If phase_slug in the init JSON differs from the current branch name, that is expected and correct; leave the branch unchanged.
1. Initialize
Load all context in one call (paths only to minimize orchestrator context):
INIT=$(gsd-sdk query init.plan-phase "$PHASE")
if [[ "$INIT" == @file:* ]]; then INIT=$(cat "${INIT#@file:}"); fi
AGENT_SKILLS_RESEARCHER=$(gsd-sdk query agent-skills gsd-researcher 2>/dev/null)
AGENT_SKILLS_PLANNER=$(gsd-sdk query agent-skills gsd-planner 2>/dev/null)
AGENT_SKILLS_CHECKER=$(gsd-sdk query agent-skills gsd-checker 2>/dev/null)
CONTEXT_WINDOW=$(gsd-sdk query config-get context_window 2>/dev/null || echo "200000")
TDD_MODE=$(gsd-sdk query config-get workflow.tdd_mode 2>/dev/null || echo "false")
When TDD_MODE is true, the planner agent is instructed to apply type: tdd to eligible tasks using heuristics from references/tdd.md. The planner's <required_reading> is extended to include @~/.claude/get-shit-done/references/tdd.md so gate enforcement rules are available during planning.
When CONTEXT_WINDOW >= 500000, the planner prompt includes the 3 most recent prior phase CONTEXT.md and SUMMARY.md files PLUS any phases explicitly listed in the current phase's Depends on: field in ROADMAP.md. Explicit dependencies always load regardless of recency (e.g., Phase 7 declaring Depends on: Phase 2 always sees Phase 2's context). Bounded recency keeps the planner's context budget focused on recent work.
Parse JSON for: researcher_model, planner_model, checker_model, research_enabled, plan_checker_enabled, nyquist_validation_enabled, commit_docs, text_mode, phase_found, phase_dir, phase_number, phase_name, phase_slug, padded_phase, has_research, has_context, has_reviews, has_plans, plan_count, planning_exists, roadmap_exists, phase_req_ids, response_language.
If response_language is set: Include response_language: {value} in all spawned subagent prompts so any user-facing output stays in the configured language.
File paths (for blocks): state_path, roadmap_path, requirements_path, context_path, research_path, verification_path, uat_path, reviews_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, --skip-ui, --prd <filepath>, --reviews, --text, --bounce, --skip-bounce, --chunked).
Set TEXT_MODE=true if --text is present in $ARGUMENTS OR text_mode from init JSON is true. When TEXT_MODE is active, replace every AskUserQuestion call with a plain-text numbered list and ask the user to type their choice number. This is required for Claude Code remote sessions (/rc mode) where TUI menus don't work through the Claude App.
Extract --prd <filepath> from $ARGUMENTS. If present, set PRD_FILE to the filepath.
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:
mkdir -p ".planning/phases/${padded_phase}-${phase_slug}"
Existing artifacts from init: has_research, has_plans, plan_count.
Set CHUNKED_MODE from flag or config:
CHUNKED_CFG=$(gsd-sdk query config-get workflow.plan_chunked 2>/dev/null || echo "false")
CHUNKED_MODE=false
if [[ "$ARGUMENTS" =~ --chunked ]] || [[ "$CHUNKED_CFG" == "true" ]]; then
CHUNKED_MODE=true
fi
2.5. Validate --reviews Prerequisite
Skip if: No --reviews flag.
If --reviews AND --gaps: Error — cannot combine --reviews with --gaps. These are conflicting modes.
If --reviews AND has_reviews is false (no REVIEWS.md in phase dir):
Error:
No REVIEWS.md found for Phase {N}. Run reviews first:
/gsd-review --phase {N}
Then re-run /gsd-plan-phase {N} --reviews
Exit workflow.
3. Validate Phase
PHASE_INFO=$(gsd-sdk query roadmap.get-phase "${PHASE}")
If found is false: Error with available phases. If found is true: Extract phase_number, phase_name, goal from JSON.
3.5. Handle PRD Express Path
Skip if: No --prd flag in arguments.
If --prd <filepath> provided:
- Read the PRD file:
PRD_CONTENT=$(cat "$PRD_FILE" 2>/dev/null)
if [ -z "$PRD_CONTENT" ]; then
echo "Error: PRD file not found: $PRD_FILE"
exit 1
fi
- Display banner:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GSD ► PRD EXPRESS PATH
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Using PRD: {PRD_FILE}
Generating CONTEXT.md from requirements...
Parse the PRD content and generate CONTEXT.md. The orchestrator should:
- Extract all requirements, user stories, acceptance criteria, and constraints from the PRD
- Map each to a locked decision (everything in the PRD is treated as a locked decision)
- Identify any areas the PRD doesn't cover and mark as "Claude's Discretion"
- Extract canonical refs from ROADMAP.md for this phase, plus any specs/ADRs referenced in the PRD — expand to full file paths (MANDATORY)
- Create CONTEXT.md in the phase directory
Write CONTEXT.md:
# Phase [X]: [Name] - Context
**Gathered:** [date]
**Status:** Ready for planning
**Source:** PRD Express Path ({PRD_FILE})
<domain>
## Phase Boundary
[Extracted from PRD — what this phase delivers]
</domain>
<decisions>
## Implementation Decisions
{For each requirement/story/criterion in the PRD:}
### [Category derived from content]
- [Requirement as locked decision]
### Claude's Discretion
[Areas not covered by PRD — implementation details, technical choices]
</decisions>
<canonical_refs>
## Canonical References
**Downstream agents MUST read these before planning or implementing.**
[MANDATORY. Extract from ROADMAP.md and any docs referenced in the PRD.
Use full relative paths. Group by topic area.]
### [Topic area]
- `path/to/spec-or-adr.md` — [What it decides/defines]
[If no external specs: "No external specs — requirements fully captured in decisions above"]
</canonical_refs>
<specifics>
## Specific Ideas
[Any specific references, examples, or concrete requirements from PRD]
</specifics>
<deferred>
## Deferred Ideas
[Items in PRD explicitly marked as future/v2/out-of-scope]
[If none: "None — PRD covers phase scope"]
</deferred>
---
*Phase: XX-name*
*Context gathered: [date] via PRD Express Path*
- Commit:
gsd-sdk query commit "docs(${padded_phase}): generate context from PRD" "${phase_dir}/${padded_phase}-CONTEXT.md"
- Set
context_contentto the generated CONTEXT.md content and continue to step 5 (Handle Research).
Effect: This completely bypasses step 4 (Load CONTEXT.md) since we just created it. The rest of the workflow (research, planning, verification) proceeds normally with the PRD-derived context.
4. Load CONTEXT.md
Skip if: PRD express path was used (CONTEXT.md already created in step 3.5).
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):
Read discuss mode for context gate label:
DISCUSS_MODE=$(gsd-sdk query config-get workflow.discuss_mode 2>/dev/null || echo "discuss")
If TEXT_MODE is true, present as a plain-text numbered list:
No CONTEXT.md found for Phase {X}. Plans will use research and requirements only — your design preferences won't be included.
1. Continue without context — Plan using research + requirements only
[If DISCUSS_MODE is "assumptions":]
2. Gather context (assumptions mode) — Analyze codebase and surface assumptions before planning
[If DISCUSS_MODE is "discuss" or unset:]
2. Run discuss-phase first — Capture design decisions before planning
Enter number:
Otherwise 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
If
DISCUSS_MODEis"assumptions": - "Gather context (assumptions mode)" — Analyze codebase and surface assumptions before planning
If
DISCUSS_MODEis"discuss"(or unset): - "Run discuss-phase first" — Capture design decisions before planning
- "Continue without context" — Plan using research + requirements only
If
If "Continue without context": Proceed to step 5. If "Run discuss-phase first": IMPORTANT: Do NOT invoke discuss-phase as a nested Skill/Task call — AskUserQuestion does not work correctly in nested subcontexts (#1009). Instead, display the command and exit so the user runs it as a top-level command:
Run this command first, then re-run /gsd-plan-phase {X} ${GSD_WS}:
/gsd-discuss-phase {X} ${GSD_WS}
Exit the plan-phase workflow. Do not continue.
4.5. Check AI-SPEC
Skip if: ai_integration_phase_enabled from config is false, or --skip-ai-spec flag provided.
AI_SPEC_FILE=$(ls "${PHASE_DIR}"/*-AI-SPEC.md 2>/dev/null | head -1)
AI_PHASE_CFG=$(gsd-sdk query config-get workflow.ai_integration_phase 2>/dev/null || echo "true")
Skip if AI_PHASE_CFG is false.
If AI_SPEC_FILE is empty: Check phase goal for AI keywords:
echo "${phase_goal}" | grep -qi "agent\|llm\|rag\|chatbot\|embedding\|langchain\|llamaindex\|crewai\|langgraph\|openai\|anthropic\|vector\|eval\|ai system"
If AI keywords detected AND no AI-SPEC.md:
◆ Note: This phase appears to involve AI system development.
Consider running /gsd-ai-integration-phase {N} before planning to:
- Select the right framework for your use case
- Research its docs and best practices
- Design an evaluation strategy
Continue planning without AI-SPEC? (non-blocking — /gsd-ai-integration-phase can be run after)
Use AskUserQuestion with options:
- "Continue — plan without AI-SPEC"
- "Stop — I'll run /gsd-ai-integration-phase {N} first"
If "Stop": Exit with /gsd-ai-integration-phase {N} reminder.
If "Continue": Proceed. (Non-blocking — planner will note AI-SPEC is absent.)
If AI_SPEC_FILE is non-empty: Extract framework for planner context:
FRAMEWORK_LINE=$(grep "Selected Framework:" "${AI_SPEC_FILE}" | head -1)
Pass ai_spec_path and framework_line to planner in step 7 so it can reference the AI design contract.
5. Handle Research
Skip if: --gaps flag or --skip-research flag or --reviews flag.
If has_research is true (from init) AND no --research flag: Use existing, skip to step 6.
If RESEARCH.md missing OR --research flag:
If no explicit flag (--research or --skip-research) and not --auto:
Ask the user whether to research, with a contextual recommendation based on the phase:
If TEXT_MODE is true, present as a plain-text numbered list:
Research before planning Phase {X}: {phase_name}?
1. Research first (Recommended) — Investigate domain, patterns, and dependencies before planning. Best for new features, unfamiliar integrations, or architectural changes.
2. Skip research — Plan directly from context and requirements. Best for bug fixes, simple refactors, or well-understood tasks.
Enter number:
Otherwise use AskUserQuestion:
AskUserQuestion([
{
question: "Research before planning Phase {X}: {phase_name}?",
header: "Research",
multiSelect: false,
options: [
{ label: "Research first (Recommended)", description: "Investigate domain, patterns, and dependencies before planning. Best for new features, unfamiliar integrations, or architectural changes." },
{ label: "Skip research", description: "Plan directly from context and requirements. Best for bug fixes, simple refactors, or well-understood tasks." }
]
}
])
If user selects "Skip research": skip to step 6.
If --auto and research_enabled is false: Skip research silently (preserves automated behavior).
Display banner:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GSD ► RESEARCHING PHASE {X}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
◆ Spawning researcher...
Spawn gsd-phase-researcher
PHASE_DESC=$(gsd-sdk query roadmap.get-phase "${PHASE}" --pick section)
Research prompt:
<objective>
Research how to implement Phase {phase_number}: {phase_name}
Answer: "What do I need to know to PLAN this phase well?"
</objective>
<files_to_read>
- {context_path} (USER DECISIONS from /gsd-discuss-phase)
- {requirements_path} (Project requirements)
- {state_path} (Project decisions and history)
</files_to_read>
${AGENT_SKILLS_RESEARCHER}
<additional_context>
**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 .claude/skills/ or .agents/skills/ directory (if either exists) — read SKILL.md files, research should account for project skill patterns
</additional_context>
<output>
Write to: {phase_dir}/{phase_num}-RESEARCH.md
</output>
Task(
prompt=research_prompt,
subagent_type="gsd-phase-researcher",
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
5.5. Create Validation Strategy
Skip if nyquist_validation_enabled is false OR research_enabled is false.
If research_enabled is false and nyquist_validation_enabled is true: warn "Nyquist validation enabled but research disabled — VALIDATION.md cannot be created without RESEARCH.md. Plans will lack validation requirements (Dimension 8)." Continue to step 6.
But Nyquist is not applicable for this run when all of the following are true:
research_enabledis falsehas_researchis false- no
--researchflag was provided
In that case: skip validation-strategy creation entirely. Do not expect RESEARCH.md or VALIDATION.md for this run, and continue to Step 6.
grep -l "## Validation Architecture" "${PHASE_DIR}"/*-RESEARCH.md 2>/dev/null || true
If found:
- Read template:
~/.claude/get-shit-done/templates/VALIDATION.md - Write to
${PHASE_DIR}/${PADDED_PHASE}-VALIDATION.md(use Write tool) - Fill frontmatter:
{N}→ phase number,{phase-slug}→ slug,{date}→ current date - Verify:
test -f "${PHASE_DIR}/${PADDED_PHASE}-VALIDATION.md" && echo "VALIDATION_CREATED=true" || echo "VALIDATION_CREATED=false"
- If
VALIDATION_CREATED=false: STOP — do not proceed to Step 6 - If
commit_docs:commit "docs(phase-${PHASE}): add validation strategy"
If not found: Warn and continue — plans may fail Dimension 8.
5.55. Security Threat Model Gate
Skip if
workflow.security_enforcementis explicitlyfalse. Absent = enabled.
SECURITY_CFG=$(gsd-sdk query config-get workflow.security_enforcement --raw 2>/dev/null || echo "true")
SECURITY_ASVS=$(gsd-sdk query config-get workflow.security_asvs_level --raw 2>/dev/null || echo "1")
SECURITY_BLOCK=$(gsd-sdk query config-get workflow.security_block_on --raw 2>/dev/null || echo "high")
If SECURITY_CFG is false: Skip to step 5.6.
If SECURITY_CFG is true: Display banner:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GSD ► SECURITY THREAT MODEL REQUIRED (ASVS L{SECURITY_ASVS})
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Each PLAN.md must include a <threat_model> block.
Block on: {SECURITY_BLOCK} severity threats.
Opt out: set security_enforcement: false in .planning/config.json
Continue to step 5.6. Security config is passed to the planner in step 8.
5.6. UI Design Contract Gate
Skip if
workflow.ui_phaseis explicitlyfalseANDworkflow.ui_safety_gateis explicitlyfalsein.planning/config.json. If keys are absent, treat as enabled.
UI_PHASE_CFG=$(gsd-sdk query config-get workflow.ui_phase 2>/dev/null || echo "true")
UI_GATE_CFG=$(gsd-sdk query config-get workflow.ui_safety_gate 2>/dev/null || echo "true")
If both are false: Skip to step 6.
Check if phase has frontend indicators:
PHASE_SECTION=$(gsd-sdk query roadmap.get-phase "${PHASE}" 2>/dev/null)
echo "$PHASE_SECTION" | grep -iE "UI|interface|frontend|component|layout|page|screen|view|form|dashboard|widget" > /dev/null 2>&1
HAS_UI=$?
If HAS_UI is 0 (frontend indicators found):
Check for existing UI-SPEC:
UI_SPEC_FILE=$(ls "${PHASE_DIR}"/*-UI-SPEC.md 2>/dev/null | head -1)
If UI-SPEC.md found: Set UI_SPEC_PATH=$UI_SPEC_FILE. Display: Using UI design contract: ${UI_SPEC_PATH}
If UI-SPEC.md missing AND --skip-ui flag is present in $ARGUMENTS: Skip silently to step 6.
If UI-SPEC.md missing AND UI_GATE_CFG is true:
Read ephemeral chain flag (same field as check.auto-mode → auto_chain_active):
AUTO_CHAIN=$(gsd-sdk query check auto-mode --pick auto_chain_active 2>/dev/null || echo "false")
If AUTO_CHAIN is true (running inside a --chain or --auto pipeline):
Auto-generate UI-SPEC without prompting:
Skill(skill="gsd-ui-phase", args="${PHASE} --auto ${GSD_WS}")
After gsd-ui-phase returns, re-read:
UI_SPEC_FILE=$(ls "${PHASE_DIR}"/*-UI-SPEC.md 2>/dev/null | head -1)
UI_SPEC_PATH="${UI_SPEC_FILE}"
Continue to step 6.
If AUTO_CHAIN is false (manual invocation):
Output this markdown directly (not as a code block):
## ⚠ UI-SPEC.md missing for Phase {N}
▶ Recommended next step:
`/gsd-ui-phase {N} ${GSD_WS}` — generate UI design contract before planning
───────────────────────────────────────────────
Also available:
- `/gsd-plan-phase {N} --skip-ui ${GSD_WS}` — plan without UI-SPEC (not recommended for frontend phases)
Exit the plan-phase workflow. Do not continue.
If HAS_UI is 1 (no frontend indicators): Skip silently to step 5.7.
5.7. Schema Push Detection Gate
Detects schema-relevant files in the phase scope and injects a mandatory
[BLOCKING]schema push task into the plan. Prevents false-positive verification where build/types pass because TypeScript types come from config, not the live database.
Check if any files in the phase scope match schema patterns:
PHASE_SECTION=$(gsd-sdk query roadmap.get-phase "${PHASE}" --pick section 2>/dev/null)
Scan PHASE_SECTION, CONTEXT.md (if loaded), and RESEARCH.md (if exists) for file paths matching these ORM patterns:
| ORM | File Patterns |
|---|---|
| Payload CMS | src/collections/**/*.ts, src/globals/**/*.ts |
| Prisma | prisma/schema.prisma, prisma/schema/*.prisma |
| Drizzle | drizzle/schema.ts, src/db/schema.ts, drizzle/*.ts |
| Supabase | supabase/migrations/*.sql |
| TypeORM | src/entities/**/*.ts, src/migrations/**/*.ts |
Also check if any existing PLAN.md files for this phase already reference these file patterns in files_modified.
If schema-relevant files detected:
Set SCHEMA_PUSH_REQUIRED=true and SCHEMA_ORM={detected_orm}.
Determine the push command for the detected ORM:
| ORM | Push Command | Non-TTY Workaround |
|---|---|---|
| Payload CMS | npx payload migrate |
CI=true PAYLOAD_MIGRATING=true npx payload migrate |
| Prisma | npx prisma db push |
npx prisma db push --accept-data-loss (if destructive) |
| Drizzle | npx drizzle-kit push |
npx drizzle-kit push |
| Supabase | supabase db push |
Set SUPABASE_ACCESS_TOKEN env var |
| TypeORM | npx typeorm migration:run |
npx typeorm migration:run -d src/data-source.ts |
Inject the following into the planner prompt (step 8) as an additional constraint:
<schema_push_requirement>
**[BLOCKING] Schema Push Required**
This phase modifies schema-relevant files ({detected_files}). The planner MUST include
a `[BLOCKING]` task that runs the database schema push command AFTER all schema file
modifications are complete but BEFORE verification.
- ORM detected: {SCHEMA_ORM}
- Push command: {push_command}
- Non-TTY workaround: {env_hint}
- If push requires interactive prompts that cannot be suppressed, flag the task for
manual intervention with `autonomous: false`
This task is mandatory — the phase CANNOT pass verification without it. Build and
type checks will pass without the push (types come from config, not the live database),
creating a false-positive verification state.
</schema_push_requirement>
Display: Schema files detected ({SCHEMA_ORM}) — [BLOCKING] push task will be injected into plans
If no schema-relevant files detected: Skip silently to step 6.
6. Check Existing Plans
ls "${PHASE_DIR}"/*-PLAN.md 2>/dev/null || true
If exists AND --reviews flag: Skip prompt — go straight to replanning (the purpose of --reviews is to replan with review feedback).
If exists AND no --reviews flag: Offer: 1) Add more plans, 2) View existing, 3) Replan from scratch.
7. Use Context Paths from INIT
Extract from INIT JSON:
_gsd_field() { node -e "const o=JSON.parse(process.argv[1]); const v=o[process.argv[2]]; process.stdout.write(v==null?'':String(v))" "$1" "$2"; }
STATE_PATH=$(_gsd_field "$INIT" state_path)
ROADMAP_PATH=$(_gsd_field "$INIT" roadmap_path)
REQUIREMENTS_PATH=$(_gsd_field "$INIT" requirements_path)
RESEARCH_PATH=$(_gsd_field "$INIT" research_path)
VERIFICATION_PATH=$(_gsd_field "$INIT" verification_path)
UAT_PATH=$(_gsd_field "$INIT" uat_path)
CONTEXT_PATH=$(_gsd_field "$INIT" context_path)
REVIEWS_PATH=$(_gsd_field "$INIT" reviews_path)
PATTERNS_PATH=$(_gsd_field "$INIT" patterns_path)
# Detect spike/sketch findings skills (project-local)
SPIKE_FINDINGS_PATH=$(ls ./.claude/skills/spike-findings-*/SKILL.md 2>/dev/null | head -1)
SKETCH_FINDINGS_PATH=$(ls ./.claude/skills/sketch-findings-*/SKILL.md 2>/dev/null | head -1)
7.5. Verify Nyquist Artifacts
Skip if nyquist_validation_enabled is false OR research_enabled is false.
Also skip if all of the following are true:
research_enabledis falsehas_researchis false- no
--researchflag was provided
In that no-research path, Nyquist artifacts are not required for this run.
VALIDATION_EXISTS=$(ls "${PHASE_DIR}"/*-VALIDATION.md 2>/dev/null | head -1)
If missing and Nyquist is still enabled/applicable — ask user:
- Re-run:
/gsd-plan-phase {PHASE} --research ${GSD_WS} - Disable Nyquist with the exact command:
gsd-sdk query config-set workflow.nyquist_validation false - Continue anyway (plans fail Dimension 8)
Proceed to Step 7.8 (or Step 8 if pattern mapper is disabled) only if user selects 2 or 3.
7.8. Spawn gsd-pattern-mapper Agent (Optional)
Skip if workflow.pattern_mapper is explicitly set to false in config.json (absent key = enabled). Also skip if no CONTEXT.md and no RESEARCH.md exist for this phase (nothing to extract file lists from).
Check config:
PATTERN_MAPPER_CFG=$(gsd-sdk query config-get workflow.pattern_mapper 2>/dev/null || echo "true")
If PATTERN_MAPPER_CFG is false: Skip to step 8.
If PATTERNS.md already exists (PATTERNS_PATH is non-empty from step 7): Skip to step 8 (use existing).
Display banner:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GSD ► PATTERN MAPPING PHASE {X}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
◆ Spawning pattern mapper...
Pattern mapper prompt:
<pattern_mapping_context>
**Phase:** {phase_number} - {phase_name}
**Phase directory:** {phase_dir}
**Padded phase:** {padded_phase}
<files_to_read>
- {context_path} (USER DECISIONS from /gsd-discuss-phase)
- {research_path} (Technical Research)
</files_to_read>
**Output file:** {phase_dir}/{padded_phase}-PATTERNS.md
Extract the list of files to be created/modified from CONTEXT.md and RESEARCH.md. For each file, classify by role and data flow, find the closest existing analog in the codebase, extract concrete code excerpts, and produce PATTERNS.md.
</pattern_mapping_context>
Spawn with:
Task(
prompt="{above}",
subagent_type="gsd-pattern-mapper",
model="{researcher_model}",
)
Handle return:
## PATTERN MAPPING COMPLETE: UpdatePATTERNS_PATHto the created file path, continue to step 8.- Any error or empty return: Log warning, continue to step 8 without patterns (non-blocking).
After pattern mapper completes, update the path variable:
PATTERNS_PATH="${PHASE_DIR}/${PADDED_PHASE}-PATTERNS.md"
8. Spawn gsd-planner Agent
Display banner:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
GSD ► PLANNING PHASE {X}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
◆ Spawning planner...
Planner prompt:
<planning_context>
**Phase:** {phase_number}
**Mode:** {standard | gap_closure | reviews}
<files_to_read>
- {state_path} (Project State)
- {roadmap_path} (Roadmap)
- {requirements_path} (Requirements)
- {context_path} (USER DECISIONS from /gsd-discuss-phase)
- {research_path} (Technical Research)
- {PATTERNS_PATH} (Pattern Map — analog files and code excerpts, if exists)
- {verification_path} (Verification Gaps - if --gaps)
- {uat_path} (UAT Gaps - if --gaps)
- {reviews_path} (Cross-AI Review Feedback - if --reviews)
- {UI_SPEC_PATH} (UI Design Contract — visual/interaction specs, if exists)
- {SPIKE_FINDINGS_PATH} (Spike Findings — validated patterns, constraints, landmines from experiments, if exists)
- {SKETCH_FINDINGS_PATH} (Sketch Findings — validated design decisions, CSS patterns, visual direction, if exists)
${CONTEXT_WINDOW >= 500000 ? `
**Cross-phase context (1M model enrichment):**
- CONTEXT.md files from the 3 most recent completed phases (locked decisions — maintain consistency)
- SUMMARY.md files from the 3 most recent completed phases (what was built — reuse patterns, avoid duplication)
- LEARNINGS.md files from the 3 most recent completed phases (structured decisions, patterns, lessons, surprises — skip silently if a phase has no LEARNINGS.md; prefix each block with \`[from Phase N LEARNINGS]\` for source attribution; if total size exceeds 15% of context budget, drop oldest first)
- CONTEXT.md, SUMMARY.md, and LEARNINGS.md from any phases listed in the current phase's "Depends on:" field in ROADMAP.md (regardless of recency — explicit dependencies always load, deduplicated against the 3 most recent)
- Skip all other prior phases to stay within context budget
` : ''}
</files_to_read>
${AGENT_SKILLS_PLANNER}
**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 .claude/skills/ or .agents/skills/ directory (if either exists) — read SKILL.md files, plans should account for project skill rules
${TDD_MODE === 'true' ? `
<tdd_mode_active>
**TDD Mode is ENABLED.** Apply TDD heuristics from @~/.claude/get-shit-done/references/tdd.md to all eligible tasks:
- Business logic with defined I/O → type: tdd
- API endpoints with request/response contracts → type: tdd
- Data transformations, validation, algorithms → type: tdd
- UI, config, glue code, CRUD → standard plan (type: execute)
Each TDD plan gets one feature with RED/GREEN/REFACTOR gate sequence.
</tdd_mode_active>
` : ''}
</planning_context>
<downstream_consumer>
Output consumed by /gsd-execute-phase. Plans need:
- Frontmatter (wave, depends_on, files_modified, autonomous)
- Tasks in XML format with read_first and acceptance_criteria fields (MANDATORY on every task)
- Verification criteria
- must_haves for goal-backward verification
</downstream_consumer>
<deep_work_rules>
## Anti-Shallow Execution Rules (MANDATORY)
Every task MUST include these fields — they are NOT optional:
1. **`<read_first>`** — Files the executor MUST read before touching anything. Always include:
- The file being modified (so executor sees current state, not assumptions)
- Any "source of truth" file referenced in CONTEXT.md (reference implementations, existing patterns, config files, schemas)
- Any file whose patterns, signatures, types, or conventions must be replicated or respected
2. **`<acceptance_criteria>`** — Verifiable conditions that prove the task was done correctly. Rules:
- Every criterion must be checkable with grep, file read, test command, or CLI output
- NEVER use subjective language ("looks correct", "properly configured", "consistent with")
- ALWAYS include exact strings, patterns, values, or command outputs that must be present
- Examples:
- Code: `auth.py contains def verify_token(` / `test_auth.py exits 0`
- Config: `.env.example contains DATABASE_URL=` / `Dockerfile contains HEALTHCHECK`
- Docs: `README.md contains '## Installation'` / `API.md lists all endpoints`
- Infra: `deploy.yml has rollback step` / `docker-compose.yml has healthcheck for db`
3. **`<action>`** — Must include CONCRETE values, not references. Rules:
- NEVER say "align X with Y", "match X to Y", "update to be consistent" without specifying the exact target state
- ALWAYS include the actual values: config keys, function signatures, SQL statements, class names, import paths, env vars, etc.
- If CONTEXT.md has a comparison table or expected values, copy them into the action verbatim
- The executor should be able to complete the task from the action text alone, without needing to read CONTEXT.md or reference files (read_first is for verification, not discovery)
**Why this matters:** Executor agents work from the plan text. Vague instructions like "update the config to match production" produce shallow one-line changes. Concrete instructions like "add DATABASE_URL=postgresql://... , set POOL_SIZE=20, add REDIS_URL=redis://..." produce complete work. The cost of verbose plans is far less than the cost of re-doing shallow execution.
</deep_work_rules>
<quality_gate>
- [ ] PLAN.md files created in phase directory
- [ ] Each plan has valid frontmatter
- [ ] Tasks are specific and actionable
- [ ] Every task has `<read_first>` with at least the file being modified
- [ ] Every task has `<acceptance_criteria>` with grep-verifiable conditions
- [ ] Every `<action>` contains concrete values (no "align X with Y" without specifying what)
- [ ] Dependencies correctly identified
- [ ] Waves assigned for parallel execution
- [ ] must_haves derived from phase goal
</quality_gate>
If CHUNKED_MODE is false (default): Spawn the planner as a single long-lived Task:
Task(
prompt=filled_prompt,
subagent_type="gsd-planner",
model="{planner_model}",
description="Plan Phase {phase}"
)
If CHUNKED_MODE is true: Skip the Task() call above — proceed to step 8.5 instead.
8.5. Chunked Planning Mode
Skip if CHUNKED_MODE is false.
Chunked mode splits the single long-lived planner Task into a short outline Task followed by
N short per-plan Tasks. Each Task is bounded to ~3–5 min; each plan is committed individually
for crash resilience. If any Task hangs and the terminal is force-killed, rerunning
/gsd-plan-phase {N} --chunked resumes from the last successfully committed plan.
Intended for new or in-progress chunked runs. To recover plans already written by a prior
non-chunked run, use step 6's "Add more plans" or proceed directly to /gsd-execute-phase
— don't start a fresh chunked run over existing non-chunked plans.
8.5.1 Outline Phase (outline-only mode, ~2 min)
Resume detection: If ${PHASE_DIR}/${PADDED_PHASE}-PLAN-OUTLINE.md already exists and
is valid (contains the ## OUTLINE COMPLETE marker), skip this sub-step — the outline
already exists from a previous run. Proceed directly to 8.5.2.
OUTLINE_FILE="${PHASE_DIR}/${PADDED_PHASE}-PLAN-OUTLINE.md"
if [[ -f "$OUTLINE_FILE" ]] && grep -q "^## OUTLINE COMPLETE" "$OUTLINE_FILE"; then
# reuse existing outline — skip to 8.5.2
fi
Display:
◆ Chunked mode: spawning outline planner...
Spawn the planner in outline-only mode — it must write only the outline manifest, not any PLAN.md files:
Task(
prompt="{same planning_context as step 8, plus:}
**Chunked mode: outline-only.**
Do NOT write any PLAN.md files in this Task.
Write only: {PHASE_DIR}/{PADDED_PHASE}-PLAN-OUTLINE.md
The outline must be a markdown table with columns:
Plan ID | Objective | Wave | Depends On | Requirements
Return: ## OUTLINE COMPLETE with plan count.",
subagent_type="gsd-planner",
model="{planner_model}",
description="Outline Phase {phase} (chunked)"
)
Handle return:
## OUTLINE COMPLETE: ReadPLAN-OUTLINE.md, extract plan list. Continue to 8.5.2.- Any other return or empty: Display error. Offer: 1) Retry outline, 2) Stop.
8.5.2 Per-Plan Tasks (single-plan mode, ~3-5 min each)
For each plan entry extracted from PLAN-OUTLINE.md:
Resume check: If
${PHASE_DIR}/{plan_id}-PLAN.mdalready exists on disk and has valid YAML frontmatter (opening---delimiter present), skip this plan (do not overwrite completed work — resume safety).PLAN_FILE="${PHASE_DIR}/${plan_id}-PLAN.md" if [[ -f "$PLAN_FILE" ]] && head -1 "$PLAN_FILE" | grep -q '^---'; then continue # plan already written, skip fiDisplay:
◆ Chunked mode: planning {plan_id} ({k}/{N})...Spawn the planner in single-plan mode — it must write exactly one PLAN.md file:
Task( prompt="{same planning_context as step 8, plus:} **Chunked mode: single-plan.** Write exactly ONE plan file: {PHASE_DIR}/{plan_id}-PLAN.md Plan to write: {plan_id} — {objective} Wave: {wave} | Depends on: {depends_on} Phase requirement IDs to cover in this plan: {plan_requirements} Return: ## PLAN COMPLETE with the plan ID.", subagent_type="gsd-planner", model="{planner_model}", description="Plan {plan_id} (chunked {k}/{N})" )Verify disk: Check
${PHASE_DIR}/{plan_id}-PLAN.mdexists. If missing: offer 1) Retry, 2) Stop.Commit per-plan:
gsd-sdk query commit "docs(${PADDED_PHASE}): plan ${plan_id} (chunked)" "${PHASE_DIR}/${plan_id}-PLAN.md"
After all N plans are written and committed, treat this as ## PLANNING COMPLETE and continue
to step 9.
9. Handle Planner Return
## PLANNING COMPLETE: Display plan count. If--skip-verifyorplan_checker_enabledis false (from init): skip to step 13. Otherwise: step 10.## PHASE SPLIT RECOMMENDED: The planner determined the phase exceeds the context budget for full-fidelity implementation of all source items. Handle in step 9b.## ⚠ Source Audit: Unplanned Items Found: The planner's multi-source coverage audit found items from REQUIREMENTS.md, RESEARCH.md, ROADMAP goal, or CONTEXT.md decisions that are not covered by any plan. Handle in step 9c.## CHECKPOINT REACHED: Present to user, get response, spawn continuation (step 12)## PLANNING INCONCLUSIVE: Show attempts, offer: Add context / Retry / Manual- Empty / truncated / no recognized marker: → Filesystem fallback (step 9a).
9a. Filesystem Fallback (Planner)
Triggered when: Task() returns but the return contains no recognized marker (## PLANNING COMPLETE, ## PHASE SPLIT RECOMMENDED, ## ⚠ Source Audit, ## CHECKPOINT REACHED, ## PLANNING INCONCLUSIVE).
DISK_PLANS=$(ls "${PHASE_DIR}"/*-PLAN.md 2>/dev/null | wc -l | tr -d ' ')
If DISK_PLANS > 0: The planner wrote plans to disk but the Task() return was empty or
truncated (the Windows stdio hang pattern — the subagent finished but the return never
arrived). Display:
◆ Planner wrote {DISK_PLANS} plan(s) to disk but did not emit a PLANNING COMPLETE marker.
This is a known Windows stdio hang pattern — work is likely recoverable.
Plans found on disk:
{ls output of *-PLAN.md}
Offer 3 options:
- Accept plans — treat as
## PLANNING COMPLETEand continue through step 9## PLANNING COMPLETEhandling (so--skip-verify/plan_checker_enabled=falseare honored — may skip to step 13 rather than step 10) - Retry planner — re-spawn the planner with the same prompt (return to step 8)
- Stop — exit; user can re-run
/gsd-plan-phase {N}to resume
If DISK_PLANS is 0 and no marker: The planner produced no output. Treat as
## PLANNING INCONCLUSIVE and handle accordingly.
9b. Handle Phase Split Recommendation
When the planner returns ## PHASE SPLIT RECOMMENDED, it means the phase's source items exceed the context budget for full-fidelity implementation. The planner proposes groupings.
Extract from planner return:
- Proposed sub-phases (e.g., "17a: processing core (D-01 to D-19)", "17b: billing + config UX (D-20 to D-27)")
- Which source items (REQ-IDs, D-XX decisions, RESEARCH items) go in each sub-phase
- Why the split is necessary (context cost estimate, file count)
Present to user:
## Phase {X} exceeds context budget for full-fidelity implementation
The planner found {N} source items that exceed the context budget when
planned at full fidelity. Instead of reducing scope, we recommend splitting:
**Option 1: Split into sub-phases**
- Phase {X}a: {name} — {items} ({N} source items, ~{P}% context)
- Phase {X}b: {name} — {items} ({M} source items, ~{Q}% context)
**Option 2: Proceed anyway** (planner will attempt all, quality may degrade past 50% context)
**Option 3: Prioritize** — you choose which items to implement now,
rest become a follow-up phase
Use AskUserQuestion with these 3 options.
If "Split": Use /gsd-insert-phase to create the sub-phases, then replan each.
If "Proceed": Return to planner with instruction to attempt all items at full fidelity, accepting more plans/tasks.
If "Prioritize": Use AskUserQuestion (multiSelect) to let user pick which items are "now" vs "later". Create CONTEXT.md for each sub-phase with the selected items.
9c. Handle Source Audit Gaps
When the planner returns ## ⚠ Source Audit: Unplanned Items Found, it means items from REQUIREMEN
…(truncated)