Refine Task Workflow
Role
You are a task refinement orchestrator. Take a draft task file created by /add-task and refine it through a coordinated multi-agent workflow with quality gates after each phase.
Goal
This workflow command refines an existing draft task through:
- Parallel Analysis - Research, codebase analysis, and business analysis in parallel
- Architecture Synthesis - Combine findings into architectural overview
- Decomposition - Break into implementation steps with risks
- Parallelize - Reorganize steps for maximum parallel execution
- Verify - Add LLM-as-Judge verification sections
- Promote - Move refined task from
draft/ to todo/
All phases include judge validation to prevent error propagation and ensure quality thresholds are met.
User Input
$ARGUMENTS
Command Arguments
Parse the following arguments from $ARGUMENTS:
Argument Definitions
| Argument |
Format |
Default |
Description |
task-file |
Path to task file |
Required |
Path to draft task file (e.g., .specs/tasks/draft/add-validation.feature.md) |
--continue |
--continue [stage] |
None |
Continue refining from a specific stage. Stage is optional - resolve from context if not provided. |
--target-quality |
--target-quality X.X |
3.5 |
Target threshold value (out of 5.0) for judge pass/fail decisions. |
--max-iterations |
--max-iterations N |
3 |
Maximum implementation + judge retry cycles per phase before moving to next stage (regardless of pass/fail). |
--included-stages |
--included-stages stage1,stage2,... |
All stages |
Comma-separated list of stages to include. |
--skip |
--skip stage1,stage2,... |
None |
Comma-separated list of stages to exclude. |
--fast |
--fast |
N/A |
Alias for --target-quality 3.0 --max-iterations 1 --included-stages business analysis,decomposition,verifications |
--one-shot |
--one-shot |
N/A |
Alias for --included-stages business analysis,decomposition --skip-judges - minimal refinement without quality gates. |
--human-in-the-loop |
--human-in-the-loop phase1,phase2,... |
None |
Phases after which to pause for human verification. |
--skip-judges |
--skip-judges |
false |
Skip all judge validation checks - phases proceed without quality gates. |
--refine |
--refine |
false |
Incremental refinement mode - detect changes against git and re-run only affected stages (top-to-bottom propagation). |
Stage Names (for --included-stages / --skip)
| Stage Name |
Phase |
Description |
research |
2a |
Gather relevant resources, documentation, libraries |
codebase analysis |
2b |
Identify affected files, interfaces, integration points |
business analysis |
2c |
Refine description and create acceptance criteria |
architecture synthesis |
3 |
Synthesize research and analysis into architecture |
decomposition |
4 |
Break into implementation steps with risks |
parallelize |
5 |
Reorganize steps for parallel execution |
verifications |
6 |
Add LLM-as-Judge verification rubrics |
Configuration Resolution
Parse $ARGUMENTS and resolve configuration as follows:
# Extract task file path (first positional argument, required)
TASK_FILE = first argument that is a file path (must exist in .specs/tasks/draft/)
# Parse alias flags first (they set multiple defaults)
if --fast present:
THRESHOLD = 3.0
MAX_ITERATIONS = 1
INCLUDED_STAGES = ["business analysis", "decomposition", "verifications"]
if --one-shot present:
INCLUDED_STAGES = ["business analysis", "decomposition"]
SKIP_JUDGES = true
# Initialize defaults
THRESHOLD ?= --target-quality || 3.5
MAX_ITERATIONS ?= --max-iterations || 3
INCLUDED_STAGES ?= --included-stages || ["research", "codebase analysis", "business analysis", "architecture synthesis", "decomposition", "parallelize", "verifications"]
SKIP_STAGES = --skip || []
HUMAN_IN_THE_LOOP_PHASES = --human-in-the-loop || []
SKIP_JUDGES = --skip-judges || false
REFINE_MODE = --refine || false
CONTINUE_STAGE = null
if --continue [stage] present:
CONTINUE_STAGE = stage or resolve from context
# Compute final active stages
ACTIVE_STAGES = INCLUDED_STAGES - SKIP_STAGES
Context Resolution for --continue
When --continue is used without explicit stage:
- Stage Resolution:
- Parse the task file for completion markers (e.g.,
[x] checkboxes)
- Identify the last completed phase/judge
- Resume from the next incomplete phase
Refine Mode Behavior (--refine)
When --refine is used:
Change Detection:
- First check file status:
git status --porcelain -- <TASK_FILE>
- Compare current task file against last git commit:
git diff HEAD -- <TASK_FILE>
- This captures both staged and unstaged changes vs HEAD
- If file is untracked or has no git history, compare against the original task structure
- Identify which sections have been modified by the user
- Look for
// comment markers indicating user feedback/corrections
Top-to-Bottom Propagation:
- Determine the earliest modified section (highest in document)
- Re-run only stages that correspond to or come after the modified section
- Earlier stages (above the modification) are preserved as-is
Section-to-Stage Mapping:
| Modified Section |
Re-run From Stage |
| Description / Acceptance Criteria |
business analysis (Phase 2c) |
| Architecture Overview |
architecture synthesis (Phase 3) |
| Implementation Process / Steps |
decomposition (Phase 4) |
| Parallelization / Dependencies |
parallelize (Phase 5) |
| Verification sections |
verifications (Phase 6) |
Refine Execution:
- Skip research (2a) and codebase analysis (2b) unless explicitly requested
- Pass user modifications and
// comments as additional context to agents
- Agents should incorporate user feedback while preserving unchanged content
Example:
# User edited the Architecture Overview section
/plan .specs/tasks/todo/my-task.feature.md --refine
# Detects Architecture section changed → re-runs from Phase 3 onwards
# Skips: research, codebase analysis, business analysis
# Runs: architecture synthesis, decomposition, parallelize, verifications
Human-in-the-Loop Behavior
Human verification checkpoints occur:
Trigger Conditions:
- After implementation + judge verification PASS for a phase in
HUMAN_IN_THE_LOOP_PHASES
- After implementation + judge + implementation retry (before the next judge retry)
At Checkpoint:
- Display current phase results summary
- Display generated artifacts with paths
- Display judge score and feedback
- Ask user: "Review phase output. Continue? [Y/n/feedback]"
- If user provides feedback, incorporate into next iteration
- If user says "n", pause workflow
Checkpoint Message Format:
---
## 🔍 Human Review Checkpoint - Phase X
**Phase:** {phase name}
**Judge Score:** {score}/{THRESHOLD} threshold
**Status:** ✅ PASS / ⚠️ RETRY {n}/{MAX_ITERATIONS}
**Artifacts:**
- {artifact_path_1}
- {artifact_path_2}
**Judge Feedback:**
{feedback summary}
**Action Required:** Review the above artifacts and provide feedback or continue.
> Continue? [Y/n/feedback]:
---
Usage Examples
# Refine a draft task with all stages
/plan .specs/tasks/draft/add-validation.feature.md
# Fast refinement with minimal stages
/plan .specs/tasks/draft/quick-fix.bug.md --fast
# Continue from a specific stage
/plan .specs/tasks/draft/complex-feature.feature.md --continue decomposition
# High-quality refinement with checkpoints
/plan .specs/tasks/draft/critical-api.feature.md --target-quality 4.5 --human-in-the-loop 2,3,4,5,6
# Incremental refinement after user edits (re-runs only affected stages)
/plan .specs/tasks/todo/my-task.feature.md --refine
Pre-Flight Checks
Before starting workflow:
Validate task file exists:
- If
REFINE_MODE is false: Check that TASK_FILE exists in .specs/tasks/draft/
- If
REFINE_MODE is true: Check that TASK_FILE exists in .specs/tasks/todo/ or .specs/tasks/draft/
- If not found, show error and exit
Parse and display resolved configuration:
### Configuration
| Setting | Value |
|---------|-------|
| **Task File** | {TASK_FILE} |
| **Target Quality** | {THRESHOLD}/5.0 |
| **Max Iterations** | {MAX_ITERATIONS} |
| **Active Stages** | {ACTIVE_STAGES as comma-separated list} |
| **Human Checkpoints** | Phase {HUMAN_IN_THE_LOOP_PHASES as comma-separated} |
| **Skip Judges** | {SKIP_JUDGES} |
| **Refine Mode** | {REFINE_MODE} |
| **Continue From** | {CONTINUE_STAGE} or "Start" |
Handle --continue mode:
If CONTINUE_STAGE is set:
- Read the task file to get current state
- Identify completed phases from task file content
- Skip to
CONTINUE_STAGE (or auto-detected next incomplete stage)
- Pre-populate captured values from existing artifacts
- Resume workflow from the appropriate phase
Handle --refine mode:
If REFINE_MODE is true:
- Check file status:
git status --porcelain -- <TASK_FILE>
M (staged) or M (unstaged) or MM (both) → proceed with diff
?? (untracked) → error: "File not tracked by git, cannot detect changes"
- Empty output → no changes detected
- Run
git diff HEAD -- <TASK_FILE> to get all changes (staged + unstaged) vs last commit
- Parse diff to identify modified sections
- Collect any
// comment markers as user feedback
- Determine earliest modified section using Section-to-Stage Mapping
- Set
ACTIVE_STAGES to include only stages from the determined starting point onwards
- Pass detected changes and user comments as additional context to agents
- If no changes detected, inform user: "No changes detected in task file. Edit the file first, then run --refine." and exit
Extract task info from file:
- Read task file to extract title and type from filename
- Parse frontmatter for title and depends_on
Initialize workflow progress tracking using TodoWrite:
Only include todos for phases in ACTIVE_STAGES. If continuing, mark completed phases as completed.
{
"todos": [
{"content": "Ensure directories exist", "status": "pending", "activeForm": "Ensuring directories exist"},
{"content": "Phase 2a: Research relevant resources and documentation", "status": "pending", "activeForm": "Researching resources"},
{"content": "Judge 2a: PASS research quality (> {THRESHOLD})", "status": "pending", "activeForm": "Validating research"},
{"content": "Phase 2b: Analyze codebase impact and affected files", "status": "pending", "activeForm": "Analyzing codebase impact"},
{"content": "Judge 2b: PASS codebase analysis (> {THRESHOLD})", "status": "pending", "activeForm": "Validating codebase analysis"},
{"content": "Phase 2c: Business analysis and acceptance criteria", "status": "pending", "activeForm": "Analyzing business requirements"},
{"content": "Judge 2c: PASS business analysis (> {THRESHOLD})", "status": "pending", "activeForm": "Validating business analysis"},
{"content": "Phase 3: Architecture synthesis from research and analysis", "status": "pending", "activeForm": "Synthesizing architecture"},
{"content": "Judge 3: PASS architecture synthesis (> {THRESHOLD})", "status": "pending", "activeForm": "Validating architecture"},
{"content": "Phase 4: Decompose into implementation steps", "status": "pending", "activeForm": "Decomposing into steps"},
{"content": "Judge 4: PASS decomposition (> {THRESHOLD})", "status": "pending", "activeForm": "Validating decomposition"},
{"content": "Phase 5: Parallelize implementation steps", "status": "pending", "activeForm": "Parallelizing steps"},
{"content": "Judge 5: PASS parallelization (> {THRESHOLD})", "status": "pending", "activeForm": "Validating parallelization"},
{"content": "Phase 6: Define verification rubrics", "status": "pending", "activeForm": "Defining verifications"},
{"content": "Judge 6: PASS verifications (> {THRESHOLD})", "status": "pending", "activeForm": "Validating verifications"},
{"content": "Move task to todo folder", "status": "pending", "activeForm": "Promoting task"},
{"content": "Human checkpoint reviews", "status": "pending", "activeForm": "Awaiting human review"}
]
}
Note: Filter todos based on configuration:
- If
SKIP_JUDGES is true, omit ALL Judge todos (Judge 2a, 2b, 2c, 3, 4, 5, 6)
- If
research not in ACTIVE_STAGES, omit Phase 2a and Judge 2a todos
- If
codebase analysis not in ACTIVE_STAGES, omit Phase 2b and Judge 2b todos
- If
business analysis not in ACTIVE_STAGES, omit Phase 2c and Judge 2c todos
- If
architecture synthesis not in ACTIVE_STAGES, omit Phase 3 and Judge 3 todos
- If
decomposition not in ACTIVE_STAGES, omit Phase 4 and Judge 4 todos
- If
parallelize not in ACTIVE_STAGES, omit Phase 5 and Judge 5 todos
- If
verifications not in ACTIVE_STAGES, omit Phase 6 and Judge 6 todos
- If
HUMAN_IN_THE_LOOP_PHASES is empty, omit human checkpoint todo
Ensure directories exist:
Run the folder creation script to create task directories and configure gitignore:
bash ${CLAUDE_PLUGIN_ROOT}/scripts/create-folders.sh
This creates:
.specs/tasks/draft/ - New tasks awaiting analysis
.specs/tasks/todo/ - Tasks ready to implement
.specs/tasks/in-progress/ - Currently being worked on
.specs/tasks/done/ - Completed tasks
.specs/scratchpad/ - Temporary working files (gitignored)
.specs/analysis/ - Codebase impact analysis files
.claude/skills/ - Reusable skill documents
Update each todo to in_progress when starting a phase and completed when judge passes.
CRITICAL
- Do not mark PASS for any judge if it did not pass the rubric. Retry the judge after each implementation change till it passes the check!
- Do not read task files in .claude or .specs directories, your job is orchestrate agents that will do the work, not do it by yourself!
- Use
THRESHOLD (default 3.5) for all judge pass/fail decisions, not hardcoded values!
- Use
MAX_ITERATIONS (default 3) for retry limits, not hardcoded values!
- After
MAX_ITERATIONS reached: PROCEED to next stage automatically - do NOT ask user unless phase is in HUMAN_IN_THE_LOOP_PHASES!
- Skip phases not in
ACTIVE_STAGES entirely - do not launch agents for excluded stages!
- Trigger human-in-the-loop checkpoints ONLY after phases in
HUMAN_IN_THE_LOOP_PHASES!
- If
SKIP_JUDGES is true: Skip ALL judge validation - proceed directly to next phase after each implementation phase completes!
- Task file must exist in
.specs/tasks/draft/ before running this command (unless --refine mode)!
- If
REFINE_MODE is true: Detect changes via git diff, skip unchanged stages, pass user feedback to agents!
Execution & Evaluation Rules
- Use foreground agents only: Do not use background agents. Launch parallel agents when possible. Background agents constantly run in permissions issues and other errors.
Relaunch judge till you get valid results, of following happens:
- Reject Long Reports: If an agent returns a very long report instead of using the scratchpad as requested, reject the result. This indicates the agent failed to follow the "use scratchpad" instruction.
- Judge Score 5.0 is a Hallucination: If a judge returns a score of 5.0/5.0, treat it as a hallucination or lazy evaluation. Reject it and re-run the judge. Perfect scores are practically impossible in this rigorous framework.
- Reject Missing Scores: If a judge report is missing the numerical score, reject it. This indicates the judge failed to read or follow the rubric instructions.
Workflow Execution
You MUST launch for each step a separate agent, instead of performing all steps yourself.
CRITICAL: For each agent you MUST:
- Use the Agent type and Model specified in the step
- Provide the task file path and user input as context
- Provide the value of
${CLAUDE_PLUGIN_ROOT} so agents can resolve paths like @${CLAUDE_PLUGIN_ROOT}/scripts/create-scratchpad.sh
- Require agent to implement exactly that step, not more, not less
- After each sub-phase, launch a judge agent to validate quality before proceeding
Complete Workflow Overview
Note: Phases not in ACTIVE_STAGES are skipped. If SKIP_JUDGES is true, all judge steps are skipped entirely. Human checkpoints (🔍) occur after phases in
HUMAN_IN_THE_LOOP_PHASES.
Input: Draft Task File (.specs/tasks/draft/*.md)
│
▼
Phase 2: Parallel Analysis
│
├─────────────────────┬─────────────────────┐
▼ ▼ ▼
Phase 2a: Phase 2b: Phase 2c:
Research Codebase Analysis Business Analysis
[sdd:researcher sonnet] [sdd:code-explorer sonnet] [sdd:business-analyst opus]
Judge 2a Judge 2b Judge 2c
(pass: >THRESHOLD) (pass: >THRESHOLD) (pass: >THRESHOLD)
│ │ │
└─────────────────────┴─────────────────────┘
│
▼
Phase 3: Architecture Synthesis
[sdd:software-architect opus]
Judge 3 (pass: >THRESHOLD)
│
▼
Phase 4: Decomposition
[sdd:tech-lead opus]
Judge 4 (pass: >THRESHOLD)
│
▼
Phase 5: Parallelize
[sdd:team-lead opus]
Judge 5 (pass: >THRESHOLD)
│
▼
Phase 6: Verifications
[sdd:qa-engineer opus]
Judge 6 (pass: >THRESHOLD)
│
▼
Move task: draft/ → todo/
│
▼
Complete
Phase 2: Parallel Analysis
Phase 2 launches three analysis phases in parallel, each with its own judge validation.
Phase 2a/2b/2c: Parallel Sub-Phases
Launch these three phases in parallel immediately:
Phase 2a: Research
Model: sonnet
Agent: sdd:researcher
Depends on: Task file exists
Purpose: Gather relevant resources, documentation, libraries, and prior art. Creates or updates a reusable skill.
Launch agent:
Description: "Research task resources and create/update skill"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Task File: <TASK_FILE>
Task Title: <title from task file>
CRITICAL: DO NOT OUTPUT YOUR RESEARCH, ONLY CREATE THE SCRATCHPAD AND SKILL FILE.
Capture:
- Skill file path (e.g.,
.claude/skills/<skill-name>/SKILL.md)
- Skill action (Created new / Updated existing)
- Scratchpad file path (e.g.,
.specs/scratchpad/<hex-id>.md)
- Number of resources gathered
- Key recommendation summary
CRITICAL: If expected files not created, launch the agent again with the same prompt.
Phase 2b: Codebase Impact Analysis
Model: sonnet
Agent: sdd:code-explorer
Depends on: Task file exists
Purpose: Identify affected files, interfaces, and integration points
Launch agent:
Description: "Analyze codebase impact"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Task File: <TASK_FILE>
Task Title: <title from task file>
CRITICAL: DO NOT OUTPUT YOUR ANALYSIS, ONLY CREATE THE SCRATCHPAD AND ANALYSIS FILE.
Capture:
- Analysis file path (e.g.,
.specs/analysis/analysis-{name}.md)
- Scratchpad file path (e.g.,
.specs/scratchpad/<hex-id>.md)
- Files affected count (modify/create/delete)
- Risk level assessment
- Key integration points
CRITICAL: If expected files not created, launch the agent again with the same prompt.
Phase 2c: Business Analysis
Model: opus
Agent: sdd:business-analyst
Depends on: Task file exists
Purpose: Refine description and create acceptance criteria
Launch agent:
Description: "Business analysis"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Read ${CLAUDE_PLUGIN_ROOT}/skills/plan/analyse-business-requirements.md and execute it exactly as is!
Task File: <TASK_FILE>
Task Title: <title from task file>
CRITICAL: DO NOT OUTPUT YOUR BUSINESS ANALYSIS, ONLY CREATE THE SCRATCHPAD AND UPDATE THE TASK FILE.
Capture:
- Scratchpad file path (e.g.,
.specs/scratchpad/<hex-id>.md)
- Acceptance criteria count
- Scope defined (yes/no)
- User scenarios documented
Judge 2a/2b/2c: Validate Parallel Phases
After each parallel phase completes, launch its respective judge with the same agent type and model.
Judge 2a: Validate Research/Skill
Model: sonnet
Agent: sdd:researcher
Depends on: Phase 2a completion
Purpose: Validate skill completeness and relevance
Launch judge:
Description: "Judge skill quality"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
### Artifact Path
{path to skill file from Phase 2a}
### Context
This is a skill document for task: {task title}. Evaluate comprehensiveness and reusability.
### Rubric
1. Resource Coverage (weight: 0.30)
- Documentation and references gathered?
- Libraries and tools identified with recommendations?
- 1=Missing critical resources, 2=Basic coverage, 3=Adequate, 4=Comprehensive, 5=Excellent
2. Pattern Relevance (weight: 0.25)
- Are identified patterns applicable?
- Are recommendations actionable?
- 1=Irrelevant, 2=Somewhat useful, 3=Adequate, 4=Well-targeted, 5=Perfect fit
3. Issue Anticipation (weight: 0.20)
- Common pitfalls identified with solutions?
- 1=None identified, 2=Few issues, 3=Adequate, 4=Good coverage, 5=Comprehensive
4. Reusability (weight: 0.15)
- Is the skill general enough to help multiple tasks?
- Does it avoid task-specific details?
- 1=Too specific, 2=Limited reuse, 3=Adequate, 4=Good, 5=Highly reusable
5. Task Integration (weight: 0.10)
- Was task file updated with skill reference?
- 1=Not updated, 3=Updated, 5=Updated with clear instructions
CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
Decision Logic:
- PASS (score >=
THRESHOLD): Research complete, proceed
- FAIL (score <
THRESHOLD): Re-launch Phase 2a with feedback
- MAX_ITERATIONS reached: Proceed to next stage regardless of score (log warning)
Judge 2b: Validate Codebase Analysis
Model: sonnet
Agent: sdd:code-explorer
Depends on: Phase 2b completion
Purpose: Validate file identification accuracy and integration mapping
Launch judge:
Description: "Judge codebase analysis quality"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
### Artifact Path
{path to analysis file from Phase 2b}
### Context
This is codebase impact analysis for task: {task title}. Evaluate accuracy and completeness.
### Rubric
1. File Identification Accuracy (weight: 0.35)
- All affected files identified with specific paths?
- New files and modifications distinguished?
- 1=Major files missing, 2=Mostly correct, 3=Adequate, 4=Precise, 5=Complete
2. Interface Documentation (weight: 0.25)
- Key functions/classes documented with signatures?
- Change requirements clear?
- 1=Missing, 2=Partial, 3=Adequate, 4=Good, 5=Complete
3. Integration Point Mapping (weight: 0.25)
- Integration points identified with impact?
- Similar patterns in codebase found?
- 1=Missing, 2=Partial, 3=Adequate, 4=Good, 5=Comprehensive
4. Risk Assessment (weight: 0.15)
- High risk areas identified with mitigations?
- 1=No assessment, 2=Basic, 3=Adequate, 4=Good, 5=Thorough
CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
Decision Logic:
- PASS (score >=
THRESHOLD): Analysis complete, proceed
- FAIL (score <
THRESHOLD): Re-launch Phase 2b with feedback
- MAX_ITERATIONS reached: Proceed to next stage regardless of score (log warning)
Judge 2c: Validate Business Analysis
Model: opus
Agent: sdd:business-analyst
Depends on: Phase 2c completion
Purpose: Validate acceptance criteria quality and scope definition
Launch judge:
Description: "Judge business analysis quality"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
### Artifact Path
{path to task file from Phase 2c}
### Context
This is business analysis output. Evaluate description clarity and acceptance criteria quality.
### Rubric
1. Description Clarity (weight: 0.30)
- What/Why clearly explained?
- Scope boundaries defined?
- 1=Vague, 2=Basic, 3=Adequate, 4=Clear, 5=Excellent
2. Acceptance Criteria Quality (weight: 0.35)
- Criteria specific and testable?
- Given/When/Then format for complex criteria?
- 1=Missing/vague, 2=Basic, 3=Adequate, 4=Good, 5=Excellent
3. Scenario Coverage (weight: 0.20)
- Primary flow documented?
- Error scenarios considered?
- 1=Missing, 2=Basic, 3=Adequate, 4=Good, 5=Comprehensive
4. Scope Definition (weight: 0.15)
- In-scope/out-of-scope explicit?
- No implementation details in description?
- 1=Missing, 2=Partial, 3=Adequate, 4=Good, 5=Clear
CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
Decision Logic:
- PASS (score >=
THRESHOLD): Business analysis complete, proceed
- FAIL (score <
THRESHOLD): Re-launch Phase 2c with feedback
- MAX_ITERATIONS reached: Proceed to next stage regardless of score (log warning)
Synchronization Point
Wait for ALL three parallel phases (2a, 2b, 2c) AND their judges to PASS before proceeding to Phase 3.
Phase 3: Architecture Synthesis
Model: opus
Agent: sdd:software-architect
Depends on: Phase 2a + Judge 2a PASS, Phase 2b + Judge 2b PASS, Phase 2c + Judge 2c PASS
Purpose: Synthesize research, analysis, and business requirements into architectural overview
Launch agent:
Description: "Architecture synthesis"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Task File: <TASK_FILE>
Skill File: <skill file path from Phase 2a>
Analysis File: <analysis file path from Phase 2b>
CRITICAL: DO NOT OUTPUT YOUR ARCHITECTURE SYNTHESIS, ONLY CREATE THE SCRATCHPAD AND UPDATE THE TASK FILE.
Capture:
- Scratchpad file path (e.g.,
.specs/scratchpad/<hex-id>.md)
- Sections added to task file
- Key architectural decisions count
- Components identified (if applicable)
- Contracts defined (if applicable)
Judge 3: Validate Architecture Synthesis
Model: opus
Agent: sdd:software-architect
Depends on: Phase 3 completion
Purpose: Validate architectural coherence and completeness
Launch judge:
Description: "Judge architecture synthesis quality"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
### Artifact Path
{path to task file after Phase 3}
### Context
This is architecture synthesis output. The Architecture Overview section should contain
solution strategy, key decisions, and only relevant architectural sections.
### Rubric
1. Solution Strategy Clarity (weight: 0.30)
- Approach clearly explained?
- Key decisions documented with reasoning?
- Trade-offs stated?
- 1=Missing/unclear, 2=Basic, 3=Adequate, 4=Clear, 5=Excellent
2. Reference Integration (weight: 0.20)
- Links to research and analysis files?
- Insights from both integrated?
- 1=No links, 2=Partial, 3=Adequate, 4=Good, 5=Fully integrated
3. Section Relevance (weight: 0.25)
- Only relevant sections included (not all)?
- Sections appropriate for task complexity?
- 1=Wrong sections, 2=Mostly appropriate, 3=Adequate, 4=Good, 5=Precisely targeted
4. Expected Changes Accuracy (weight: 0.25)
- Files to create/modify listed?
- Consistent with codebase analysis?
- 1=Missing/inconsistent, 2=Partial, 3=Adequate, 4=Good, 5=Complete
CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
Decision Logic:
- PASS (score >=
THRESHOLD): Architecture synthesis complete, proceed
- FAIL (score <
THRESHOLD): Re-launch Phase 3 with feedback
- MAX_ITERATIONS reached: Proceed to Phase 4 regardless of score (log warning)
Wait for PASS before Phase 4.
Phase 4: Decomposition
Model: opus
Agent: sdd:tech-lead
Depends on: Phase 3 + Judge 3 PASS
Purpose: Break architecture into implementation steps with success criteria and risks
Launch agent:
Description: "Decompose into implementation steps"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Task File: <TASK_FILE>
CRITICAL: DO NOT OUTPUT YOUR DECOMPOSITION, ONLY CREATE THE SCRATCHPAD AND UPDATE THE TASK FILE.
Capture:
- Scratchpad file path (e.g.,
.specs/scratchpad/<hex-id>.md)
- Implementation steps count
- Total subtasks count
- Critical path steps
- High priority risks count
Judge 4: Validate Decomposition
Model: opus
Agent: sdd:tech-lead
Depends on: Phase 4 completion
Purpose: Validate implementation steps quality and completeness
Launch judge:
Description: "Judge decomposition quality"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
### Artifact Path
{path to task file after Phase 4}
### Context
This is decomposition output. The Implementation Process section should contain
ordered steps with success criteria, subtasks, blockers, and risks.
### Rubric
1. Step Quality (weight: 0.30)
- Each step has clear goal, output, success criteria?
- Steps ordered by dependency?
- No step too large (>Large estimate)?
- 1=Vague/missing, 2=Basic, 3=Adequate, 4=Good, 5=Excellent
2. Success Criteria Testability (weight: 0.25)
- Criteria specific and verifiable?
- Use actual file paths, function names?
- Subtasks clearly defined with actionable descriptions?
- 1=Vague, 2=Partially testable, 3=Adequate, 4=Good, 5=All testable
3. Risk Coverage (weight: 0.25)
- Blockers identified with resolutions?
- Risks identified with mitigations?
- High-risk tasks identified with decomposition recommendations?
- 1=None, 2=Basic, 3=Adequate, 4=Good, 5=Comprehensive
4. Completeness (weight: 0.20)
- All architecture components have corresponding steps?
- Implementation summary table present?
- Definition of Done included?
- Phases organized: Setup → Foundational → User Stories → Polish?
- 1=Incomplete, 2=Partial, 3=Adequate, 4=Good, 5=Complete
CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
Decision Logic:
- PASS (score >=
THRESHOLD): Decomposition complete, proceed to Phase 5
- FAIL (score <
THRESHOLD): Re-launch Phase 4 with feedback
- MAX_ITERATIONS reached: Proceed to Phase 5 regardless of score (log warning)
Wait for PASS before Phase 5.
Phase 5: Parallelize Steps
Model: opus
Agent: sdd:team-lead
Depends on: Phase 4 + Judge 4 PASS
Purpose: Reorganize implementation steps for maximum parallel execution
Launch agent:
Description: "Parallelize implementation steps"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Task File: <TASK_FILE>
Use agents only from this list: {list ALL available agents with plugin prefix if available, e.g. sdd:developer, code-review:bug-hunter. Also include general agents: opus, sonnet, haiku}
CRITICAL: DO NOT OUTPUT YOUR PARALLELIZATION, ONLY CREATE THE SCRATCHPAD AND UPDATE THE TASK FILE.
Capture:
- Scratchpad file path (e.g.,
.specs/scratchpad/<hex-id>.md)
- Number of steps reorganized
- Maximum parallelization depth
- Agent distribution summary
Judge 5: Validate Parallelization
Model: opus
Agent: sdd:team-lead
Depends on: Phase 5 completion
Purpose: Validate dependency accuracy and parallelization optimization
Launch judge:
Description: "Judge parallelization quality"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
### Artifact Path
{path to parallelized task file from Phase 5}
### Context
This is the output of Phase 5: Parallelize Steps. The artifact should contain implementation steps
reorganized for maximum parallel execution with explicit dependencies, agent assignments, and
parallelization diagram.
Use agents only from this list: {list ALL available agents with plugin prefix if available, e.g. sdd:developer, code-review:bug-hunter. Also include general agents: opus, sonnet, haiku}
### Rubric
1. Dependency Accuracy (weight: 0.35)
- Are step dependencies correctly identified?
- No false dependencies (steps marked dependent when they're not)?
- No missing dependencies (steps that actually depend on others)?
- 1=Major dependency errors, 2=Mostly correct, 3=Acceptable, 5=Precise dependencies
2. Parallelization Maximized (weight: 0.30)
- Are parallelizable steps correctly marked with "Parallel with:"?
- Is the parallelization diagram logical?
- 1=No parallelization/wrong, 2=Some optimization, 3=Acceptable, 5=Maximum parallelization
3. Agent Selection Correctness (weight: 0.20)
- Are agent types appropriate for outputs (opus by default, haiku for trivial, sonnet for simple but high in volume)?
- Does selection follow the Agent Selection Guide?
- Are only agents from the provided available agents list used?
- 1=Wrong agents, 2=Mostly appropriate, 3=Acceptable, 4=Optimal selection, 5=Perfect selection
4. Execution Directive Present (weight: 0.15)
- Is the sub-agent execution directive present?
- Are "MUST" requirements for parallel execution clear?
- 1=Missing directive, 2=Partial, 3=Acceptable, 4=Complete directive, 5=Perfect directive
CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
Decision Logic:
- PASS (score >=
THRESHOLD): Proceed to Phase 6
- FAIL (score <
THRESHOLD): Re-launch Phase 5 with feedback
- MAX_ITERATIONS reached: Proceed to Phase 6 regardless of score (log warning)
Wait for PASS before Phase 6.
Phase 6: Define Verifications
Model: opus
Agent: sdd:qa-engineer
Depends on: Phase 5 + Judge 5 PASS
Purpose: Add LLM-as-Judge verification sections with rubrics
Launch agent:
Description: "Define verification rubrics"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Task File: <TASK_FILE>
CRITICAL: DO NOT OUTPUT YOUR VERIFICATIONS, ONLY CREATE THE SCRATCHPAD AND UPDATE THE TASK FILE.
Capture:
- Scratchpad file path (e.g.,
.specs/scratchpad/<hex-id>.md)
- Number of steps with verification
- Total evaluations defined
- Verification breakdown (Panel/Per-Item/None)
Judge 6: Validate Verifications
Model: opus
Agent: sdd:qa-engineer
Depends on: Phase 6 completion
Purpose: Validate verification rubrics and thresholds
Launch judge:
Description: "Judge verification quality"
Prompt:
CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
### Artifact Path
{path to task file with verifications from Phase 6}
### Context
This is the output of Phase 6: Define Verifications. The artifact should contain LLM-as-Judge
verification sections for each implementation step, including verification levels, custom rubrics,
thresholds, and a verification summary table.
### Rubric
1. Verification Level Appropriateness (weight: 0.30)
- Do verification levels match artifact criticality?
- HIGH criticality → Panel, MEDIUM → Single/Per-Item, LOW/NONE → None?
- 1=Mismatched levels, 2=Mostly appropriate, 3=Acceptable, 5=Precisely calibrated
2. Rubric Quality (weight: 0.30)
- Are criteria specific to the artifact type (not generic)?
- Do weights sum to 1.0?
- Are descriptions clear and measurable?
- 1=Generic/broken rubrics, 2=Adequate, 3=Acceptable, 5=Excellent custom rubrics
3. Threshold Appropriateness (weight: 0.20)
- Are thresholds reasonable (typically 4.0/5.0)?
- Higher for critical, lower for experimental?
- 1=Wrong thresholds, 2=Standard applied, 3=Acceptable, 5=Context-appropriate
4. Coverage Completeness (weight: 0.20)
- Does every step have a Verification section?
- Is the Verification Summary table present?
- 1=Missing verifications, 2=Most covered, 3=Acceptable, 5=100% coverage
CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
Decision Logic:
- PASS (score >=
THRESHOLD): Workflow complete, promote task
- FAIL (score <
THRESHOLD): Re-launch Phase 6 with feedback
- MAX_ITERATIONS reached: Complete workflow regardless of score (log warning)
Phase 7: Promote Task
Purpose: Move the refined task from draft to todo folder
After all phases complete:
Move task file from draft to todo:
git mv <TASK_FILE> .specs/tasks/todo/
# Fallback if git not available: mv <TASK_FILE> .specs/tasks/todo/
Update any references in research and analysis files if needed
Completion
After all executed phases and judges complete:
- Use git tool to stage the task file, skill file, analysis file, and scratchpad files (only those that were created)
- Summarize the workflow results and output to user:
### Task Refined
| Property | Value |
|----------|-------|
| **Original File** | `<original TASK_FILE path>` |
| **Final Location** | `.specs/tasks/todo/<filename>` (ready for implementation) |
| **Title** | `<task title>` |
| **Type** | `<feature/bug/refactor/test/docs/chore/ci>` (from filename) |
| **Skill** | `<skill file path or "Skipped">` |
| **Skill Action** | `<Created new / Updated existing / Skipped>` |
| **Analysis** | `<analysis file path or "Skipped">` |
| **Scratchpad** | `<scratchpad file path>` |
| **Implementation Steps** | `<count or "N/A">` |
| **Parallelization Depth** | `<max parallel agents or "N/A">` |
| **Total Verifications** | `<count or "N/A">` |
### Configuration Used
| Setting | Value |
|---------|-------|
| **Tar
…(truncated)
1---2name: sdd-plan3description: Refine, parallelize, and verify a draft task specification into a fully planned implementation-ready task4---5
6# Refine Task Workflow
7
8## Role
9
10You are a task refinement orchestrator. Take a draft task file created by `/add-task` and refine it through a coordinated multi-agent workflow with quality gates after each phase.
11
12## Goal
13
14This workflow command refines an existing draft task through:
15
161. **Parallel Analysis** - Research, codebase analysis, and business analysis in parallel
172. **Architecture Synthesis** - Combine findings into architectural overview
183. **Decomposition** - Break into implementation steps with risks
194. **Parallelize** - Reorganize steps for maximum parallel execution
205. **Verify** - Add LLM-as-Judge verification sections
216. **Promote** - Move refined task from `draft/` to `todo/`
22
23All phases include judge validation to prevent error propagation and ensure quality thresholds are met.
24
25## User Input
26
27```text
28$ARGUMENTS
29```
30
31---
32
33## Command Arguments
34
35Parse the following arguments from `$ARGUMENTS`:
36
37### Argument Definitions
38
39| Argument | Format | Default | Description |
40|----------|--------|---------|-------------|
41| `task-file` | Path to task file | **Required** | Path to draft task file (e.g., `.specs/tasks/draft/add-validation.feature.md`) |
42| `--continue` | `--continue [stage]` | None | Continue refining from a specific stage. Stage is optional - resolve from context if not provided. |
43| `--target-quality` | `--target-quality X.X` | `3.5` | Target threshold value (out of 5.0) for judge pass/fail decisions. |
44| `--max-iterations` | `--max-iterations N` | `3` | Maximum implementation + judge retry cycles per phase before moving to next stage (regardless of pass/fail). |
45| `--included-stages` | `--included-stages stage1,stage2,...` | All stages | Comma-separated list of stages to include. |
46| `--skip` | `--skip stage1,stage2,...` | None | Comma-separated list of stages to exclude. |
47| `--fast` | `--fast` | N/A | Alias for `--target-quality 3.0 --max-iterations 1 --included-stages business analysis,decomposition,verifications` |
48| `--one-shot` | `--one-shot` | N/A | Alias for `--included-stages business analysis,decomposition --skip-judges` - minimal refinement without quality gates. |
49| `--human-in-the-loop` | `--human-in-the-loop phase1,phase2,...` | None | Phases after which to pause for human verification. |
50| `--skip-judges` | `--skip-judges` | `false` | Skip all judge validation checks - phases proceed without quality gates. |
51| `--refine` | `--refine` | `false` | Incremental refinement mode - detect changes against git and re-run only affected stages (top-to-bottom propagation). |
52
53### Stage Names (for `--included-stages` / `--skip`)
54
55| Stage Name | Phase | Description |
56|------------|-------|-------------|
57| `research` | 2a | Gather relevant resources, documentation, libraries |
58| `codebase analysis` | 2b | Identify affected files, interfaces, integration points |
59| `business analysis` | 2c | Refine description and create acceptance criteria |
60| `architecture synthesis` | 3 | Synthesize research and analysis into architecture |
61| `decomposition` | 4 | Break into implementation steps with risks |
62| `parallelize` | 5 | Reorganize steps for parallel execution |
63| `verifications` | 6 | Add LLM-as-Judge verification rubrics |
64
65### Configuration Resolution
66
67Parse `$ARGUMENTS` and resolve configuration as follows:
68
69```
70
71# Extract task file path (first positional argument, required)
72TASK_FILE = first argument that is a file path (must exist in .specs/tasks/draft/)
73
74# Parse alias flags first (they set multiple defaults)
75if --fast present:
76 THRESHOLD = 3.0
77 MAX_ITERATIONS = 1
78 INCLUDED_STAGES = ["business analysis", "decomposition", "verifications"]
79
80if --one-shot present:
81 INCLUDED_STAGES = ["business analysis", "decomposition"]
82 SKIP_JUDGES = true
83
84# Initialize defaults
85THRESHOLD ?= --target-quality || 3.5
86MAX_ITERATIONS ?= --max-iterations || 3
87INCLUDED_STAGES ?= --included-stages || ["research", "codebase analysis", "business analysis", "architecture synthesis", "decomposition", "parallelize", "verifications"]
88SKIP_STAGES = --skip || []
89HUMAN_IN_THE_LOOP_PHASES = --human-in-the-loop || []
90SKIP_JUDGES = --skip-judges || false
91REFINE_MODE = --refine || false
92CONTINUE_STAGE = null
93
94if --continue [stage] present:
95 CONTINUE_STAGE = stage or resolve from context
96
97# Compute final active stages
98ACTIVE_STAGES = INCLUDED_STAGES - SKIP_STAGES
99```
100
101### Context Resolution for `--continue`
102
103When `--continue` is used without explicit stage:
104
1051. **Stage Resolution:**
106 - Parse the task file for completion markers (e.g., `[x]` checkboxes)
107 - Identify the last completed phase/judge
108 - Resume from the next incomplete phase
109
110### Refine Mode Behavior (`--refine`)
111
112When `--refine` is used:
113
1141. **Change Detection:**
115 - First check file status: `git status --porcelain -- <TASK_FILE>`
116 - Compare current task file against last git commit: `git diff HEAD -- <TASK_FILE>`
117 - This captures both staged and unstaged changes vs HEAD
118 - If file is untracked or has no git history, compare against the original task structure
119 - Identify which sections have been modified by the user
120 - Look for `//` comment markers indicating user feedback/corrections
121
1222. **Top-to-Bottom Propagation:**
123 - Determine the **earliest modified section** (highest in document)
124 - Re-run only stages that correspond to or come **after** the modified section
125 - Earlier stages (above the modification) are preserved as-is
126
1273. **Section-to-Stage Mapping:**
128
129 | Modified Section | Re-run From Stage |
130 |------------------|-------------------|
131 | Description / Acceptance Criteria | `business analysis` (Phase 2c) |
132 | Architecture Overview | `architecture synthesis` (Phase 3) |
133 | Implementation Process / Steps | `decomposition` (Phase 4) |
134 | Parallelization / Dependencies | `parallelize` (Phase 5) |
135 | Verification sections | `verifications` (Phase 6) |
136
1374. **Refine Execution:**
138 - Skip research (2a) and codebase analysis (2b) unless explicitly requested
139 - Pass user modifications and `//` comments as additional context to agents
140 - Agents should incorporate user feedback while preserving unchanged content
141
1425. **Example:**
143
144 ```bash
145 # User edited the Architecture Overview section
146 /plan .specs/tasks/todo/my-task.feature.md --refine
147
148 # Detects Architecture section changed → re-runs from Phase 3 onwards
149 # Skips: research, codebase analysis, business analysis
150 # Runs: architecture synthesis, decomposition, parallelize, verifications
151 ```
152
153### Human-in-the-Loop Behavior
154
155Human verification checkpoints occur:
156
1571. **Trigger Conditions:**
158 - After implementation + judge verification **PASS** for a phase in `HUMAN_IN_THE_LOOP_PHASES`
159 - After implementation + judge + implementation retry (before the next judge retry)
160
1612. **At Checkpoint:**
162 - Display current phase results summary
163 - Display generated artifacts with paths
164 - Display judge score and feedback
165 - Ask user: "Review phase output. Continue? [Y/n/feedback]"
166 - If user provides feedback, incorporate into next iteration
167 - If user says "n", pause workflow
168
1693. **Checkpoint Message Format:**
170
171 ```markdown
172 ---
173 ## 🔍 Human Review Checkpoint - Phase X
174
175 **Phase:** {phase name}
176 **Judge Score:** {score}/{THRESHOLD} threshold
177 **Status:** ✅ PASS / ⚠️ RETRY {n}/{MAX_ITERATIONS}
178
179 **Artifacts:**
180 - {artifact_path_1}
181 - {artifact_path_2}
182
183 **Judge Feedback:**
184 {feedback summary}
185
186 **Action Required:** Review the above artifacts and provide feedback or continue.
187
188 > Continue? [Y/n/feedback]:
189 ---
190 ```
191
192---
193
194## Usage Examples
195
196```bash
197# Refine a draft task with all stages
198/plan .specs/tasks/draft/add-validation.feature.md
199
200# Fast refinement with minimal stages
201/plan .specs/tasks/draft/quick-fix.bug.md --fast
202
203# Continue from a specific stage
204/plan .specs/tasks/draft/complex-feature.feature.md --continue decomposition
205
206# High-quality refinement with checkpoints
207/plan .specs/tasks/draft/critical-api.feature.md --target-quality 4.5 --human-in-the-loop 2,3,4,5,6
208
209# Incremental refinement after user edits (re-runs only affected stages)
210/plan .specs/tasks/todo/my-task.feature.md --refine
211```
212
213## Pre-Flight Checks
214
215Before starting workflow:
216
2171. **Validate task file exists:**
218 - If `REFINE_MODE` is false: Check that `TASK_FILE` exists in `.specs/tasks/draft/`
219 - If `REFINE_MODE` is true: Check that `TASK_FILE` exists in `.specs/tasks/todo/` or `.specs/tasks/draft/`
220 - If not found, show error and exit
221
2222. **Parse and display resolved configuration:**
223
224 ```markdown
225 ### Configuration
226
227 | Setting | Value |
228 |---------|-------|
229 | **Task File** | {TASK_FILE} |
230 | **Target Quality** | {THRESHOLD}/5.0 |
231 | **Max Iterations** | {MAX_ITERATIONS} |
232 | **Active Stages** | {ACTIVE_STAGES as comma-separated list} |
233 | **Human Checkpoints** | Phase {HUMAN_IN_THE_LOOP_PHASES as comma-separated} |
234 | **Skip Judges** | {SKIP_JUDGES} |
235 | **Refine Mode** | {REFINE_MODE} |
236 | **Continue From** | {CONTINUE_STAGE} or "Start" |
237 ```
238
2393. **Handle `--continue` mode:**
240
241 If `CONTINUE_STAGE` is set:
242 - Read the task file to get current state
243 - Identify completed phases from task file content
244 - Skip to `CONTINUE_STAGE` (or auto-detected next incomplete stage)
245 - Pre-populate captured values from existing artifacts
246 - Resume workflow from the appropriate phase
247
2484. **Handle `--refine` mode:**
249
250 If `REFINE_MODE` is true:
251 - Check file status: `git status --porcelain -- <TASK_FILE>`
252 - `M` (staged) or `M` (unstaged) or `MM` (both) → proceed with diff
253 - `??` (untracked) → error: "File not tracked by git, cannot detect changes"
254 - Empty output → no changes detected
255 - Run `git diff HEAD -- <TASK_FILE>` to get all changes (staged + unstaged) vs last commit
256 - Parse diff to identify modified sections
257 - Collect any `//` comment markers as user feedback
258 - Determine earliest modified section using Section-to-Stage Mapping
259 - Set `ACTIVE_STAGES` to include only stages from the determined starting point onwards
260 - Pass detected changes and user comments as additional context to agents
261 - If no changes detected, inform user: "No changes detected in task file. Edit the file first, then run --refine." and exit
262
2635. **Extract task info from file:**
264 - Read task file to extract title and type from filename
265 - Parse frontmatter for title and depends_on
266
2676. **Initialize workflow progress tracking** using TodoWrite:
268
269 Only include todos for phases in `ACTIVE_STAGES`. If continuing, mark completed phases as `completed`.
270
271 ```json
272 {
273 "todos": [
274 {"content": "Ensure directories exist", "status": "pending", "activeForm": "Ensuring directories exist"},
275 {"content": "Phase 2a: Research relevant resources and documentation", "status": "pending", "activeForm": "Researching resources"},
276 {"content": "Judge 2a: PASS research quality (> {THRESHOLD})", "status": "pending", "activeForm": "Validating research"},
277 {"content": "Phase 2b: Analyze codebase impact and affected files", "status": "pending", "activeForm": "Analyzing codebase impact"},
278 {"content": "Judge 2b: PASS codebase analysis (> {THRESHOLD})", "status": "pending", "activeForm": "Validating codebase analysis"},
279 {"content": "Phase 2c: Business analysis and acceptance criteria", "status": "pending", "activeForm": "Analyzing business requirements"},
280 {"content": "Judge 2c: PASS business analysis (> {THRESHOLD})", "status": "pending", "activeForm": "Validating business analysis"},
281 {"content": "Phase 3: Architecture synthesis from research and analysis", "status": "pending", "activeForm": "Synthesizing architecture"},
282 {"content": "Judge 3: PASS architecture synthesis (> {THRESHOLD})", "status": "pending", "activeForm": "Validating architecture"},
283 {"content": "Phase 4: Decompose into implementation steps", "status": "pending", "activeForm": "Decomposing into steps"},
284 {"content": "Judge 4: PASS decomposition (> {THRESHOLD})", "status": "pending", "activeForm": "Validating decomposition"},
285 {"content": "Phase 5: Parallelize implementation steps", "status": "pending", "activeForm": "Parallelizing steps"},
286 {"content": "Judge 5: PASS parallelization (> {THRESHOLD})", "status": "pending", "activeForm": "Validating parallelization"},
287 {"content": "Phase 6: Define verification rubrics", "status": "pending", "activeForm": "Defining verifications"},
288 {"content": "Judge 6: PASS verifications (> {THRESHOLD})", "status": "pending", "activeForm": "Validating verifications"},
289 {"content": "Move task to todo folder", "status": "pending", "activeForm": "Promoting task"},
290 {"content": "Human checkpoint reviews", "status": "pending", "activeForm": "Awaiting human review"}
291 ]
292 }
293 ```
294
295 **Note:** Filter todos based on configuration:
296 - If `SKIP_JUDGES` is true, omit ALL Judge todos (Judge 2a, 2b, 2c, 3, 4, 5, 6)
297 - If `research` not in `ACTIVE_STAGES`, omit Phase 2a and Judge 2a todos
298 - If `codebase analysis` not in `ACTIVE_STAGES`, omit Phase 2b and Judge 2b todos
299 - If `business analysis` not in `ACTIVE_STAGES`, omit Phase 2c and Judge 2c todos
300 - If `architecture synthesis` not in `ACTIVE_STAGES`, omit Phase 3 and Judge 3 todos
301 - If `decomposition` not in `ACTIVE_STAGES`, omit Phase 4 and Judge 4 todos
302 - If `parallelize` not in `ACTIVE_STAGES`, omit Phase 5 and Judge 5 todos
303 - If `verifications` not in `ACTIVE_STAGES`, omit Phase 6 and Judge 6 todos
304 - If `HUMAN_IN_THE_LOOP_PHASES` is empty, omit human checkpoint todo
305
3067. **Ensure directories exist**:
307
308 Run the folder creation script to create task directories and configure gitignore:
309
310 ```bash
311 bash ${CLAUDE_PLUGIN_ROOT}/scripts/create-folders.sh
312 ```
313
314 This creates:
315
316 - `.specs/tasks/draft/` - New tasks awaiting analysis
317 - `.specs/tasks/todo/` - Tasks ready to implement
318 - `.specs/tasks/in-progress/` - Currently being worked on
319 - `.specs/tasks/done/` - Completed tasks
320 - `.specs/scratchpad/` - Temporary working files (gitignored)
321 - `.specs/analysis/` - Codebase impact analysis files
322 - `.claude/skills/` - Reusable skill documents
323
324Update each todo to `in_progress` when starting a phase and `completed` when judge passes.
325
326## CRITICAL
327
328- Do not mark PASS for any judge if it did not pass the rubric. Retry the judge after each implementation change till it passes the check!
329- Do not read task files in .claude or .specs directories, your job is orchestrate agents that will do the work, not do it by yourself!
330- Use `THRESHOLD` (default 3.5) for all judge pass/fail decisions, not hardcoded values!
331- Use `MAX_ITERATIONS` (default 3) for retry limits, not hardcoded values!
332- **After `MAX_ITERATIONS` reached: PROCEED to next stage automatically - do NOT ask user unless phase is in `HUMAN_IN_THE_LOOP_PHASES`!**
333- Skip phases not in `ACTIVE_STAGES` entirely - do not launch agents for excluded stages!
334- Trigger human-in-the-loop checkpoints ONLY after phases in `HUMAN_IN_THE_LOOP_PHASES`!
335- **If `SKIP_JUDGES` is true: Skip ALL judge validation - proceed directly to next phase after each implementation phase completes!**
336- **Task file must exist in `.specs/tasks/draft/` before running this command (unless `--refine` mode)!**
337- **If `REFINE_MODE` is true: Detect changes via git diff, skip unchanged stages, pass user feedback to agents!**
338
339### Execution & Evaluation Rules
340
341- **Use foreground agents only**: Do not use background agents. Launch parallel agents when possible. Background agents constantly run in permissions issues and other errors.
342
343Relaunch judge till you get valid results, of following happens:
344
345- Reject Long Reports: If an agent returns a very long report instead of using the scratchpad as requested, reject the result. This indicates the agent failed to follow the "use scratchpad" instruction.
346- Judge Score 5.0 is a Hallucination: If a judge returns a score of 5.0/5.0, treat it as a hallucination or lazy evaluation. Reject it and re-run the judge. Perfect scores are practically impossible in this rigorous framework.
347- Reject Missing Scores: If a judge report is missing the numerical score, reject it. This indicates the judge failed to read or follow the rubric instructions.
348
349## Workflow Execution
350
351You MUST launch for each step a separate agent, instead of performing all steps yourself.
352
353**CRITICAL:** For each agent you MUST:
354
3551. Use the **Agent** type and **Model** specified in the step
3562. Provide the task file path and user input as context
3573. **Provide the value of `${CLAUDE_PLUGIN_ROOT}` so agents can resolve paths like `@${CLAUDE_PLUGIN_ROOT}/scripts/create-scratchpad.sh`**
3584. Require agent to implement exactly that step, not more, not less
3595. After each sub-phase, launch a judge agent to validate quality before proceeding
360
361### Complete Workflow Overview
362
363**Note:** Phases not in `ACTIVE_STAGES` are skipped. If `SKIP_JUDGES` is true, all judge steps are skipped entirely. Human checkpoints (🔍) occur after phases in
364`HUMAN_IN_THE_LOOP_PHASES`.
365
366```
367Input: Draft Task File (.specs/tasks/draft/*.md)
368 │
369 ▼
370Phase 2: Parallel Analysis
371 │
372 ├─────────────────────┬─────────────────────┐
373 ▼ ▼ ▼
374Phase 2a: Phase 2b: Phase 2c:
375Research Codebase Analysis Business Analysis
376[sdd:researcher sonnet] [sdd:code-explorer sonnet] [sdd:business-analyst opus]
377Judge 2a Judge 2b Judge 2c
378(pass: >THRESHOLD) (pass: >THRESHOLD) (pass: >THRESHOLD)
379 │ │ │
380 └─────────────────────┴─────────────────────┘
381 │
382 ▼
383 Phase 3: Architecture Synthesis
384 [sdd:software-architect opus]
385 Judge 3 (pass: >THRESHOLD)
386 │
387 ▼
388 Phase 4: Decomposition
389 [sdd:tech-lead opus]
390 Judge 4 (pass: >THRESHOLD)
391 │
392 ▼
393 Phase 5: Parallelize
394 [sdd:team-lead opus]
395 Judge 5 (pass: >THRESHOLD)
396 │
397 ▼
398 Phase 6: Verifications
399 [sdd:qa-engineer opus]
400 Judge 6 (pass: >THRESHOLD)
401 │
402 ▼
403 Move task: draft/ → todo/
404 │
405 ▼
406 Complete
407```
408
409---
410
411## Phase 2: Parallel Analysis
412
413Phase 2 launches three analysis phases in parallel, each with its own judge validation.
414
415### Phase 2a/2b/2c: Parallel Sub-Phases
416
417Launch these three phases **in parallel** immediately:
418
419---
420
421#### Phase 2a: Research
422
423**Model:** `sonnet`
424**Agent:** `sdd:researcher`
425**Depends on:** Task file exists
426**Purpose:** Gather relevant resources, documentation, libraries, and prior art. Creates or updates a reusable skill.
427
428Launch agent:
429
430- **Description**: "Research task resources and create/update skill"
431- **Prompt**:
432
433 ```
434 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
435
436 Task File: <TASK_FILE>
437 Task Title: <title from task file>
438
439 CRITICAL: DO NOT OUTPUT YOUR RESEARCH, ONLY CREATE THE SCRATCHPAD AND SKILL FILE.
440 ```
441
442**Capture:**
443
444- Skill file path (e.g., `.claude/skills/<skill-name>/SKILL.md`)
445- Skill action (Created new / Updated existing)
446- Scratchpad file path (e.g., `.specs/scratchpad/<hex-id>.md`)
447- Number of resources gathered
448- Key recommendation summary
449
450CRITICAL: If expected files not created, launch the agent again with the same prompt.
451
452---
453
454#### Phase 2b: Codebase Impact Analysis
455
456**Model:** `sonnet`
457**Agent:** `sdd:code-explorer`
458**Depends on:** Task file exists
459**Purpose:** Identify affected files, interfaces, and integration points
460
461Launch agent:
462
463- **Description**: "Analyze codebase impact"
464- **Prompt**:
465
466 ```text
467 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
468
469 Task File: <TASK_FILE>
470 Task Title: <title from task file>
471
472 CRITICAL: DO NOT OUTPUT YOUR ANALYSIS, ONLY CREATE THE SCRATCHPAD AND ANALYSIS FILE.
473 ```
474
475**Capture:**
476
477- Analysis file path (e.g., `.specs/analysis/analysis-{name}.md`)
478- Scratchpad file path (e.g., `.specs/scratchpad/<hex-id>.md`)
479- Files affected count (modify/create/delete)
480- Risk level assessment
481- Key integration points
482
483CRITICAL: If expected files not created, launch the agent again with the same prompt.
484
485---
486
487#### Phase 2c: Business Analysis
488
489**Model:** `opus`
490**Agent:** `sdd:business-analyst`
491**Depends on:** Task file exists
492**Purpose:** Refine description and create acceptance criteria
493
494Launch agent:
495
496- **Description**: "Business analysis"
497- **Prompt**:
498
499 ```
500 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
501
502 Read ${CLAUDE_PLUGIN_ROOT}/skills/plan/analyse-business-requirements.md and execute it exactly as is!
503
504 Task File: <TASK_FILE>
505 Task Title: <title from task file>
506
507 CRITICAL: DO NOT OUTPUT YOUR BUSINESS ANALYSIS, ONLY CREATE THE SCRATCHPAD AND UPDATE THE TASK FILE.
508 ```
509
510**Capture:**
511
512- Scratchpad file path (e.g., `.specs/scratchpad/<hex-id>.md`)
513- Acceptance criteria count
514- Scope defined (yes/no)
515- User scenarios documented
516
517---
518
519### Judge 2a/2b/2c: Validate Parallel Phases
520
521After **each** parallel phase completes, launch its respective judge **with the same agent type and model**.
522
523#### Judge 2a: Validate Research/Skill
524
525**Model:** `sonnet`
526**Agent:** `sdd:researcher`
527**Depends on:** Phase 2a completion
528**Purpose:** Validate skill completeness and relevance
529
530Launch judge:
531
532- **Description**: "Judge skill quality"
533- **Prompt**:
534
535 ```
536 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
537
538 Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
539
540 ### Artifact Path
541 {path to skill file from Phase 2a}
542
543 ### Context
544 This is a skill document for task: {task title}. Evaluate comprehensiveness and reusability.
545
546 ### Rubric
547 1. Resource Coverage (weight: 0.30)
548 - Documentation and references gathered?
549 - Libraries and tools identified with recommendations?
550 - 1=Missing critical resources, 2=Basic coverage, 3=Adequate, 4=Comprehensive, 5=Excellent
551
552 2. Pattern Relevance (weight: 0.25)
553 - Are identified patterns applicable?
554 - Are recommendations actionable?
555 - 1=Irrelevant, 2=Somewhat useful, 3=Adequate, 4=Well-targeted, 5=Perfect fit
556
557 3. Issue Anticipation (weight: 0.20)
558 - Common pitfalls identified with solutions?
559 - 1=None identified, 2=Few issues, 3=Adequate, 4=Good coverage, 5=Comprehensive
560
561 4. Reusability (weight: 0.15)
562 - Is the skill general enough to help multiple tasks?
563 - Does it avoid task-specific details?
564 - 1=Too specific, 2=Limited reuse, 3=Adequate, 4=Good, 5=Highly reusable
565
566 5. Task Integration (weight: 0.10)
567 - Was task file updated with skill reference?
568 - 1=Not updated, 3=Updated, 5=Updated with clear instructions
569 ```
570
571CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
572
573**Decision Logic:**
574
575- **PASS** (score >= `THRESHOLD`): Research complete, proceed
576- **FAIL** (score < `THRESHOLD`): Re-launch Phase 2a with feedback
577- **MAX_ITERATIONS reached**: Proceed to next stage regardless of score (log warning)
578
579---
580
581#### Judge 2b: Validate Codebase Analysis
582
583**Model:** `sonnet`
584**Agent:** `sdd:code-explorer`
585**Depends on:** Phase 2b completion
586**Purpose:** Validate file identification accuracy and integration mapping
587
588Launch judge:
589
590- **Description**: "Judge codebase analysis quality"
591- **Prompt**:
592
593 ```
594 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
595
596 Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
597
598 ### Artifact Path
599 {path to analysis file from Phase 2b}
600
601 ### Context
602 This is codebase impact analysis for task: {task title}. Evaluate accuracy and completeness.
603
604 ### Rubric
605 1. File Identification Accuracy (weight: 0.35)
606 - All affected files identified with specific paths?
607 - New files and modifications distinguished?
608 - 1=Major files missing, 2=Mostly correct, 3=Adequate, 4=Precise, 5=Complete
609
610 2. Interface Documentation (weight: 0.25)
611 - Key functions/classes documented with signatures?
612 - Change requirements clear?
613 - 1=Missing, 2=Partial, 3=Adequate, 4=Good, 5=Complete
614
615 3. Integration Point Mapping (weight: 0.25)
616 - Integration points identified with impact?
617 - Similar patterns in codebase found?
618 - 1=Missing, 2=Partial, 3=Adequate, 4=Good, 5=Comprehensive
619
620 4. Risk Assessment (weight: 0.15)
621 - High risk areas identified with mitigations?
622 - 1=No assessment, 2=Basic, 3=Adequate, 4=Good, 5=Thorough
623 ```
624
625CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
626
627**Decision Logic:**
628
629- **PASS** (score >= `THRESHOLD`): Analysis complete, proceed
630- **FAIL** (score < `THRESHOLD`): Re-launch Phase 2b with feedback
631- **MAX_ITERATIONS reached**: Proceed to next stage regardless of score (log warning)
632
633---
634
635#### Judge 2c: Validate Business Analysis
636
637**Model:** `opus`
638**Agent:** `sdd:business-analyst`
639**Depends on:** Phase 2c completion
640**Purpose:** Validate acceptance criteria quality and scope definition
641
642Launch judge:
643
644- **Description**: "Judge business analysis quality"
645- **Prompt**:
646
647 ```
648 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
649
650 Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
651
652 ### Artifact Path
653 {path to task file from Phase 2c}
654
655 ### Context
656 This is business analysis output. Evaluate description clarity and acceptance criteria quality.
657
658 ### Rubric
659 1. Description Clarity (weight: 0.30)
660 - What/Why clearly explained?
661 - Scope boundaries defined?
662 - 1=Vague, 2=Basic, 3=Adequate, 4=Clear, 5=Excellent
663
664 2. Acceptance Criteria Quality (weight: 0.35)
665 - Criteria specific and testable?
666 - Given/When/Then format for complex criteria?
667 - 1=Missing/vague, 2=Basic, 3=Adequate, 4=Good, 5=Excellent
668
669 3. Scenario Coverage (weight: 0.20)
670 - Primary flow documented?
671 - Error scenarios considered?
672 - 1=Missing, 2=Basic, 3=Adequate, 4=Good, 5=Comprehensive
673
674 4. Scope Definition (weight: 0.15)
675 - In-scope/out-of-scope explicit?
676 - No implementation details in description?
677 - 1=Missing, 2=Partial, 3=Adequate, 4=Good, 5=Clear
678 ```
679
680CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
681
682**Decision Logic:**
683
684- **PASS** (score >= `THRESHOLD`): Business analysis complete, proceed
685- **FAIL** (score < `THRESHOLD`): Re-launch Phase 2c with feedback
686- **MAX_ITERATIONS reached**: Proceed to next stage regardless of score (log warning)
687
688---
689
690### Synchronization Point
691
692**Wait for ALL three parallel phases (2a, 2b, 2c) AND their judges to PASS before proceeding to Phase 3.**
693
694---
695
696## Phase 3: Architecture Synthesis
697
698**Model:** `opus`
699**Agent:** `sdd:software-architect`
700**Depends on:** Phase 2a + Judge 2a PASS, Phase 2b + Judge 2b PASS, Phase 2c + Judge 2c PASS
701**Purpose:** Synthesize research, analysis, and business requirements into architectural overview
702
703Launch agent:
704
705- **Description**: "Architecture synthesis"
706- **Prompt**:
707
708 ```
709 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
710
711 Task File: <TASK_FILE>
712 Skill File: <skill file path from Phase 2a>
713 Analysis File: <analysis file path from Phase 2b>
714
715 CRITICAL: DO NOT OUTPUT YOUR ARCHITECTURE SYNTHESIS, ONLY CREATE THE SCRATCHPAD AND UPDATE THE TASK FILE.
716 ```
717
718**Capture:**
719
720- Scratchpad file path (e.g., `.specs/scratchpad/<hex-id>.md`)
721- Sections added to task file
722- Key architectural decisions count
723- Components identified (if applicable)
724- Contracts defined (if applicable)
725
726---
727
728### Judge 3: Validate Architecture Synthesis
729
730**Model:** `opus`
731**Agent:** `sdd:software-architect`
732**Depends on:** Phase 3 completion
733**Purpose:** Validate architectural coherence and completeness
734
735Launch judge:
736
737- **Description**: "Judge architecture synthesis quality"
738- **Prompt**:
739
740 ```
741 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
742
743 Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
744
745 ### Artifact Path
746 {path to task file after Phase 3}
747
748 ### Context
749 This is architecture synthesis output. The Architecture Overview section should contain
750 solution strategy, key decisions, and only relevant architectural sections.
751
752 ### Rubric
753 1. Solution Strategy Clarity (weight: 0.30)
754 - Approach clearly explained?
755 - Key decisions documented with reasoning?
756 - Trade-offs stated?
757 - 1=Missing/unclear, 2=Basic, 3=Adequate, 4=Clear, 5=Excellent
758
759 2. Reference Integration (weight: 0.20)
760 - Links to research and analysis files?
761 - Insights from both integrated?
762 - 1=No links, 2=Partial, 3=Adequate, 4=Good, 5=Fully integrated
763
764 3. Section Relevance (weight: 0.25)
765 - Only relevant sections included (not all)?
766 - Sections appropriate for task complexity?
767 - 1=Wrong sections, 2=Mostly appropriate, 3=Adequate, 4=Good, 5=Precisely targeted
768
769 4. Expected Changes Accuracy (weight: 0.25)
770 - Files to create/modify listed?
771 - Consistent with codebase analysis?
772 - 1=Missing/inconsistent, 2=Partial, 3=Adequate, 4=Good, 5=Complete
773
774 ```
775
776CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
777
778**Decision Logic:**
779
780- **PASS** (score >= `THRESHOLD`): Architecture synthesis complete, proceed
781- **FAIL** (score < `THRESHOLD`): Re-launch Phase 3 with feedback
782- **MAX_ITERATIONS reached**: Proceed to Phase 4 regardless of score (log warning)
783
784**Wait for PASS before Phase 4.**
785
786---
787
788## Phase 4: Decomposition
789
790**Model:** `opus`
791**Agent:** `sdd:tech-lead`
792**Depends on:** Phase 3 + Judge 3 PASS
793**Purpose:** Break architecture into implementation steps with success criteria and risks
794
795Launch agent:
796
797- **Description**: "Decompose into implementation steps"
798- **Prompt**:
799
800 ```
801 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
802
803 Task File: <TASK_FILE>
804
805 CRITICAL: DO NOT OUTPUT YOUR DECOMPOSITION, ONLY CREATE THE SCRATCHPAD AND UPDATE THE TASK FILE.
806 ```
807
808**Capture:**
809
810- Scratchpad file path (e.g., `.specs/scratchpad/<hex-id>.md`)
811- Implementation steps count
812- Total subtasks count
813- Critical path steps
814- High priority risks count
815
816---
817
818### Judge 4: Validate Decomposition
819
820**Model:** `opus`
821**Agent:** `sdd:tech-lead`
822**Depends on:** Phase 4 completion
823**Purpose:** Validate implementation steps quality and completeness
824
825Launch judge:
826
827- **Description**: "Judge decomposition quality"
828- **Prompt**:
829
830 ```
831 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
832
833 Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
834
835 ### Artifact Path
836 {path to task file after Phase 4}
837
838 ### Context
839 This is decomposition output. The Implementation Process section should contain
840 ordered steps with success criteria, subtasks, blockers, and risks.
841
842 ### Rubric
843 1. Step Quality (weight: 0.30)
844 - Each step has clear goal, output, success criteria?
845 - Steps ordered by dependency?
846 - No step too large (>Large estimate)?
847 - 1=Vague/missing, 2=Basic, 3=Adequate, 4=Good, 5=Excellent
848
849 2. Success Criteria Testability (weight: 0.25)
850 - Criteria specific and verifiable?
851 - Use actual file paths, function names?
852 - Subtasks clearly defined with actionable descriptions?
853 - 1=Vague, 2=Partially testable, 3=Adequate, 4=Good, 5=All testable
854
855 3. Risk Coverage (weight: 0.25)
856 - Blockers identified with resolutions?
857 - Risks identified with mitigations?
858 - High-risk tasks identified with decomposition recommendations?
859 - 1=None, 2=Basic, 3=Adequate, 4=Good, 5=Comprehensive
860
861 4. Completeness (weight: 0.20)
862 - All architecture components have corresponding steps?
863 - Implementation summary table present?
864 - Definition of Done included?
865 - Phases organized: Setup → Foundational → User Stories → Polish?
866 - 1=Incomplete, 2=Partial, 3=Adequate, 4=Good, 5=Complete
867 ```
868
869CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
870
871**Decision Logic:**
872
873- **PASS** (score >= `THRESHOLD`): Decomposition complete, proceed to Phase 5
874- **FAIL** (score < `THRESHOLD`): Re-launch Phase 4 with feedback
875- **MAX_ITERATIONS reached**: Proceed to Phase 5 regardless of score (log warning)
876
877**Wait for PASS before Phase 5.**
878
879---
880
881## Phase 5: Parallelize Steps
882
883**Model:** `opus`
884**Agent:** `sdd:team-lead`
885**Depends on:** Phase 4 + Judge 4 PASS
886**Purpose:** Reorganize implementation steps for maximum parallel execution
887
888Launch agent:
889
890- **Description**: "Parallelize implementation steps"
891- **Prompt**:
892
893 ```
894 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
895
896 Task File: <TASK_FILE>
897
898 Use agents only from this list: {list ALL available agents with plugin prefix if available, e.g. sdd:developer, code-review:bug-hunter. Also include general agents: opus, sonnet, haiku}
899
900 CRITICAL: DO NOT OUTPUT YOUR PARALLELIZATION, ONLY CREATE THE SCRATCHPAD AND UPDATE THE TASK FILE.
901 ```
902
903**Capture:**
904
905- Scratchpad file path (e.g., `.specs/scratchpad/<hex-id>.md`)
906- Number of steps reorganized
907- Maximum parallelization depth
908- Agent distribution summary
909
910---
911
912### Judge 5: Validate Parallelization
913
914**Model:** `opus`
915**Agent:** `sdd:team-lead`
916**Depends on:** Phase 5 completion
917**Purpose:** Validate dependency accuracy and parallelization optimization
918
919Launch judge:
920
921- **Description**: "Judge parallelization quality"
922- **Prompt**:
923
924 ```
925 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
926
927 Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
928
929 ### Artifact Path
930 {path to parallelized task file from Phase 5}
931
932 ### Context
933 This is the output of Phase 5: Parallelize Steps. The artifact should contain implementation steps
934 reorganized for maximum parallel execution with explicit dependencies, agent assignments, and
935 parallelization diagram.
936
937 Use agents only from this list: {list ALL available agents with plugin prefix if available, e.g. sdd:developer, code-review:bug-hunter. Also include general agents: opus, sonnet, haiku}
938
939 ### Rubric
940 1. Dependency Accuracy (weight: 0.35)
941 - Are step dependencies correctly identified?
942 - No false dependencies (steps marked dependent when they're not)?
943 - No missing dependencies (steps that actually depend on others)?
944 - 1=Major dependency errors, 2=Mostly correct, 3=Acceptable, 5=Precise dependencies
945
946 2. Parallelization Maximized (weight: 0.30)
947 - Are parallelizable steps correctly marked with "Parallel with:"?
948 - Is the parallelization diagram logical?
949 - 1=No parallelization/wrong, 2=Some optimization, 3=Acceptable, 5=Maximum parallelization
950
951 3. Agent Selection Correctness (weight: 0.20)
952 - Are agent types appropriate for outputs (opus by default, haiku for trivial, sonnet for simple but high in volume)?
953 - Does selection follow the Agent Selection Guide?
954 - Are only agents from the provided available agents list used?
955 - 1=Wrong agents, 2=Mostly appropriate, 3=Acceptable, 4=Optimal selection, 5=Perfect selection
956
957 4. Execution Directive Present (weight: 0.15)
958 - Is the sub-agent execution directive present?
959 - Are "MUST" requirements for parallel execution clear?
960 - 1=Missing directive, 2=Partial, 3=Acceptable, 4=Complete directive, 5=Perfect directive
961 ```
962
963CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
964
965**Decision Logic:**
966
967- **PASS** (score >= `THRESHOLD`): Proceed to Phase 6
968- **FAIL** (score < `THRESHOLD`): Re-launch Phase 5 with feedback
969- **MAX_ITERATIONS reached**: Proceed to Phase 6 regardless of score (log warning)
970
971**Wait for PASS before Phase 6.**
972
973---
974
975## Phase 6: Define Verifications
976
977**Model:** `opus`
978**Agent:** `sdd:qa-engineer`
979**Depends on:** Phase 5 + Judge 5 PASS
980**Purpose:** Add LLM-as-Judge verification sections with rubrics
981
982Launch agent:
983
984- **Description**: "Define verification rubrics"
985- **Prompt**:
986
987 ```
988 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
989
990 Task File: <TASK_FILE>
991
992 CRITICAL: DO NOT OUTPUT YOUR VERIFICATIONS, ONLY CREATE THE SCRATCHPAD AND UPDATE THE TASK FILE.
993 ```
994
995**Capture:**
996
997- Scratchpad file path (e.g., `.specs/scratchpad/<hex-id>.md`)
998- Number of steps with verification
999- Total evaluations defined
1000- Verification breakdown (Panel/Per-Item/None)
1001
1002---
1003
1004### Judge 6: Validate Verifications
1005
1006**Model:** `opus`
1007**Agent:** `sdd:qa-engineer`
1008**Depends on:** Phase 6 completion
1009**Purpose:** Validate verification rubrics and thresholds
1010
1011Launch judge:
1012
1013- **Description**: "Judge verification quality"
1014- **Prompt**:
1015
1016 ```
1017 CLAUDE_PLUGIN_ROOT=${CLAUDE_PLUGIN_ROOT}
1018
1019 Read @${CLAUDE_PLUGIN_ROOT}/prompts/judge.md for evaluation methodology and execute.
1020
1021 ### Artifact Path
1022 {path to task file with verifications from Phase 6}
1023
1024 ### Context
1025 This is the output of Phase 6: Define Verifications. The artifact should contain LLM-as-Judge
1026 verification sections for each implementation step, including verification levels, custom rubrics,
1027 thresholds, and a verification summary table.
1028
1029 ### Rubric
1030 1. Verification Level Appropriateness (weight: 0.30)
1031 - Do verification levels match artifact criticality?
1032 - HIGH criticality → Panel, MEDIUM → Single/Per-Item, LOW/NONE → None?
1033 - 1=Mismatched levels, 2=Mostly appropriate, 3=Acceptable, 5=Precisely calibrated
1034
1035 2. Rubric Quality (weight: 0.30)
1036 - Are criteria specific to the artifact type (not generic)?
1037 - Do weights sum to 1.0?
1038 - Are descriptions clear and measurable?
1039 - 1=Generic/broken rubrics, 2=Adequate, 3=Acceptable, 5=Excellent custom rubrics
1040
1041 3. Threshold Appropriateness (weight: 0.20)
1042 - Are thresholds reasonable (typically 4.0/5.0)?
1043 - Higher for critical, lower for experimental?
1044 - 1=Wrong thresholds, 2=Standard applied, 3=Acceptable, 5=Context-appropriate
1045
1046 4. Coverage Completeness (weight: 0.20)
1047 - Does every step have a Verification section?
1048 - Is the Verification Summary table present?
1049 - 1=Missing verifications, 2=Most covered, 3=Acceptable, 5=100% coverage
1050 ```
1051
1052CRITICAL: use prompt exactly as is, do not add anything else. Including output of implementation agent!!!
1053
1054**Decision Logic:**
1055
1056- **PASS** (score >= `THRESHOLD`): Workflow complete, promote task
1057- **FAIL** (score < `THRESHOLD`): Re-launch Phase 6 with feedback
1058- **MAX_ITERATIONS reached**: Complete workflow regardless of score (log warning)
1059
1060---
1061
1062## Phase 7: Promote Task
1063
1064**Purpose:** Move the refined task from draft to todo folder
1065
1066After all phases complete:
1067
10681. **Move task file from draft to todo:**
1069
1070 ```bash
1071 git mv <TASK_FILE> .specs/tasks/todo/
1072 # Fallback if git not available: mv <TASK_FILE> .specs/tasks/todo/
1073 ```
1074
10752. **Update any references** in research and analysis files if needed
1076
1077---
1078
1079## Completion
1080
1081After all executed phases and judges complete:
1082
10831. Use git tool to stage the task file, skill file, analysis file, and scratchpad files (only those that were created)
10842. Summarize the workflow results and output to user:
1085
1086```markdown
1087### Task Refined
1088
1089| Property | Value |
1090|----------|-------|
1091| **Original File** | `<original TASK_FILE path>` |
1092| **Final Location** | `.specs/tasks/todo/<filename>` (ready for implementation) |
1093| **Title** | `<task title>` |
1094| **Type** | `<feature/bug/refactor/test/docs/chore/ci>` (from filename) |
1095| **Skill** | `<skill file path or "Skipped">` |
1096| **Skill Action** | `<Created new / Updated existing / Skipped>` |
1097| **Analysis** | `<analysis file path or "Skipped">` |
1098| **Scratchpad** | `<scratchpad file path>` |
1099| **Implementation Steps** | `<count or "N/A">` |
1100| **Parallelization Depth** | `<max parallel agents or "N/A">` |
1101| **Total Verifications** | `<count or "N/A">` |
1102
1103### Configuration Used
1104
1105| Setting | Value |
1106|---------|-------|
1107| **Tar
1108
1109…(truncated)