workflow-tdd
npx skills add https://github.com/catlog22/claude-code-workflow --skill workflow-tdd
Agent 安装分布
Skill 文档
Workflow TDD
Unified TDD workflow skill combining TDD planning (Red-Green-Refactor task chain generation with test-first development structure) and TDD verification (compliance validation with quality gate reporting). Produces IMPL_PLAN.md, task JSONs with internal TDD cycles, and TDD_COMPLIANCE_REPORT.md.
Architecture Overview
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â Workflow TDD Orchestrator (SKILL.md) â
â â Route by mode: plan | verify â
â â Pure coordinator: Execute phases, parse outputs, pass context â
ââââââââââââââââââââââââââââââââ¬ââââââââââââââââââââââââââââââââââââ
â
âââââââââââââââââââââââââ´ââââââââââââââââââââââââ
â â
âââââââââââââââ âââââââââââââ
â Plan Mode â â Verify â
â (default) â â Mode â
â Phase 1-6 â â Phase 7 â
ââââââââ¬âââââââ âââââââââââââ
â
âââââââ¼ââââââ¬ââââââ¬ââââââ¬ââââââ
â â â â â â
âââââ âââââ âââââ âââââ âââââ âââââ
â 1 â â 2 â â 3 â â 4 â â 5 â â 6 â
âSesâ âCtxâ âTstâ âConâ âGenâ âValâ
âââââ âââââ âââââ âââââ âââ¬ââ âââââ
â
âââââââââââââ
â Confirm ââââ Verify âââ Phase 7
â (choice) ââââ Execute ââ Skill("workflow-execute")
ââââââââââââââââ Review âââ Display session status inline
Key Design Principles
- Pure Orchestrator: SKILL.md routes and coordinates only; execution detail lives in phase files
- Progressive Phase Loading: Read phase docs ONLY when that phase is about to execute
- Multi-Mode Routing: Single skill handles plan/verify via mode detection
- Task Attachment Model: Sub-command tasks are ATTACHED, executed sequentially, then COLLAPSED
- Auto-Continue: After each phase completes, automatically execute next pending phase
- TDD Iron Law: NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST – enforced in task structure
Interactive Preference Collection
Before dispatching to phase execution, collect workflow preferences via AskUserQuestion:
// â
ç»ä¸ auto mode æ£æµï¼-y/--yes ä» $ARGUMENTS æ ccw ä¼ æ
const autoYes = /\b(-y|--yes)\b/.test($ARGUMENTS)
if (autoYes) {
// èªå¨æ¨¡å¼ï¼è·³è¿ææè¯¢é®ï¼ä½¿ç¨é»è®¤å¼
workflowPreferences = { autoYes: true }
} else {
const prefResponse = AskUserQuestion({
questions: [
{
question: "æ¯å¦è·³è¿ææç¡®è®¤æ¥éª¤ï¼èªå¨æ¨¡å¼ï¼ï¼",
header: "Auto Mode",
multiSelect: false,
options: [
{ label: "Interactive (Recommended)", description: "äº¤äºæ¨¡å¼ï¼å
å«ç¡®è®¤æ¥éª¤" },
{ label: "Auto", description: "è·³è¿ææç¡®è®¤ï¼èªå¨æ§è¡" }
]
}
]
})
workflowPreferences = {
autoYes: prefResponse.autoMode === 'Auto'
}
}
workflowPreferences is passed to phase execution as context variable, referenced as workflowPreferences.autoYes within phases.
Mode Detection
const args = $ARGUMENTS
const mode = detectMode(args)
function detectMode(args) {
// Skill trigger determines mode
if (skillName === 'workflow:tdd-verify') return 'verify'
return 'plan' // default: workflow:tdd-plan
}
Compact Recovery (Phase Persistence)
Multi-phase TDD planning (Phase 1-6/7) spans long conversations. Uses åéä¿é©: TodoWrite è·è¸ª active phase ä¿æ¤å ¶ä¸è¢«å缩ï¼sentinel ä½ä¸ºå åºã
â ï¸ COMPACT DIRECTIVE: Context compression MUST check TodoWrite phase status. The phase currently marked
in_progressis the active execution phase â preserve its FULL content. Only compress phases markedcompletedorpending.
Execution Flow
Plan Mode (default)
Input Parsing:
ââ Convert user input to TDD structured format (GOAL/SCOPE/CONTEXT/TEST_FOCUS)
Phase 1: Session Discovery
ââ Ref: phases/01-session-discovery.md
ââ Output: sessionId (WFS-xxx)
Phase 2: Context Gathering
ââ Ref: phases/02-context-gathering.md
ââ Tasks attached: Analyze structure â Identify integration â Generate package
ââ Output: contextPath + conflictRisk
Phase 3: Test Coverage Analysis
ââ Ref: phases/03-test-coverage-analysis.md
ââ Tasks attached: Detect framework â Analyze coverage â Identify gaps
ââ Output: testContextPath
Phase 4: Conflict Resolution (conditional: conflictRisk ⥠medium)
ââ Decision (conflictRisk check):
ââ conflictRisk ⥠medium â Ref: phases/04-conflict-resolution.md
â ââ Tasks attached: Detect conflicts â Log analysis â Apply strategies
â ââ Output: conflict-resolution.json
ââ conflictRisk < medium â Skip to Phase 5
Phase 5: TDD Task Generation
ââ Ref: phases/05-tdd-task-generation.md
ââ Tasks attached: Discovery â Planning â Output
ââ Output: IMPL_PLAN.md, IMPL-*.json, TODO_LIST.md
Phase 6: TDD Structure Validation
ââ Ref: phases/06-tdd-structure-validation.md
ââ Output: Validation report + Plan Confirmation Gate
Plan Confirmation (User Decision Gate):
ââ Decision (user choice):
ââ "Verify TDD Compliance" (Recommended) â Route to Phase 7 (tdd-verify)
ââ "Start Execution" â Skill(skill="workflow-execute")
ââ "Review Status Only" â Display session status inline
Verify Mode
Phase 7: TDD Verification
ââ Ref: phases/07-tdd-verify.md
ââ Output: TDD_COMPLIANCE_REPORT.md with quality gate recommendation
Phase Reference Documents (read on-demand when phase executes):
| Phase | Document | Purpose | Mode | Compact |
|---|---|---|---|---|
| 1 | phases/01-session-discovery.md | Create or discover TDD workflow session | plan | TodoWrite é©±å¨ |
| 2 | phases/02-context-gathering.md | Gather project context and analyze codebase | plan | TodoWrite é©±å¨ |
| 3 | phases/03-test-coverage-analysis.md | Analyze test coverage and framework detection | plan | TodoWrite é©±å¨ |
| 4 | phases/04-conflict-resolution.md | Detect and resolve conflicts (conditional) | plan | TodoWrite é©±å¨ |
| 5 | phases/05-tdd-task-generation.md | Generate TDD tasks with Red-Green-Refactor cycles | plan | TodoWrite é©±å¨ + ð sentinel |
| 6 | phases/06-tdd-structure-validation.md | Validate TDD structure and present confirmation gate | plan | TodoWrite é©±å¨ + ð sentinel |
| 7 | phases/07-tdd-verify.md | Full TDD compliance verification with quality gate | verify | TodoWrite é©±å¨ |
Compact Rules:
- TodoWrite
in_progressâ ä¿ç宿´å 容ï¼ç¦æ¢å缩 - TodoWrite
completedâ å¯å缩为æè¦ - ð sentinel fallback â Phase 5/6 å
å« compact sentinelï¼è¥ compact åä»
å sentinel èæ å®æ´ Step åè®®ï¼å¿
é¡»ç«å³
Read()æ¢å¤å¯¹åº phase æä»¶
Core Rules
- Start Immediately: First action is mode detection + TaskCreate initialization, second action is phase execution
- No Preliminary Analysis: Do not read files, analyze structure, or gather context before Phase 1
- Parse Every Output: Extract required data from each phase output for next phase
- Auto-Continue via TaskList: Check TaskList status to execute next pending phase automatically
- Track Progress: Update TaskCreate/TaskUpdate dynamically with task attachment/collapse pattern
- Task Attachment Model: Skill execute attaches sub-tasks to current workflow. Orchestrator executes these attached tasks itself, then collapses them after completion
- Progressive Phase Loading: Read phase docs ONLY when that phase is about to execute
- DO NOT STOP: Continuous multi-phase workflow. After executing all attached tasks, immediately collapse them and execute next phase
- TDD Context: All descriptions include “TDD:” prefix
TDD Compliance Requirements
The Iron Law
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
Enforcement Method:
- Phase 5:
implementationincludes test-first steps (Red â Green â Refactor) - Green phase: Includes test-fix-cycle configuration (max 3 iterations)
- Auto-revert: Triggered when max iterations reached without passing tests
Verification: Phase 6 validates Red-Green-Refactor structure in all generated tasks
TDD Compliance Checkpoint
| Checkpoint | Validation Phase | Evidence Required |
|---|---|---|
| Test-first structure | Phase 5 | implementation has 3 steps |
| Red phase exists | Phase 6 | Step 1: tdd_phase: "red" |
| Green phase with test-fix | Phase 6 | Step 2: tdd_phase: "green" + test-fix-cycle |
| Refactor phase exists | Phase 6 | Step 3: tdd_phase: "refactor" |
Core TDD Principles
Red Flags – STOP and Reassess:
- Code written before test
- Test passes immediately (no Red phase witnessed)
- Cannot explain why test should fail
- “Just this once” rationalization
- “Tests after achieve same goals” thinking
Why Order Matters:
- Tests written after code pass immediately â proves nothing
- Test-first forces edge case discovery before implementation
- Tests-after verify what was built, not what’s required
Input Processing
Convert User Input to TDD Structured Format:
-
Simple text â Add TDD context:
User: "Build authentication system" Structured: TDD: Authentication System GOAL: Build authentication system SCOPE: Core authentication features CONTEXT: New implementation TEST_FOCUS: Authentication scenarios -
Detailed text â Extract components with TEST_FOCUS:
User: "Add JWT authentication with email/password login and token refresh" Structured: TDD: JWT Authentication GOAL: Implement JWT-based authentication SCOPE: Email/password login, token generation, token refresh endpoints CONTEXT: JWT token-based security, refresh token rotation TEST_FOCUS: Login flow, token validation, refresh rotation, error cases -
File/Issue â Read and structure with TDD
Data Flow
Plan Mode
User Input (task description)
â
[Convert to TDD Structured Format]
â Structured Description:
â TDD: [Feature Name]
â GOAL: [objective]
â SCOPE: [boundaries]
â CONTEXT: [background]
â TEST_FOCUS: [test scenarios]
â
Phase 1: session:start --auto "TDD: structured-description"
â Output: sessionId
â
Phase 2: context-gather --session sessionId "structured-description"
â Input: sessionId + structured description
â Output: contextPath (context-package.json) + conflictRisk
â
Phase 3: test-context-gather --session sessionId
â Input: sessionId
â Output: testContextPath (test-context-package.json)
â
Phase 4: conflict-resolution [conditional: conflictRisk ⥠medium]
â Input: sessionId + contextPath + conflictRisk
â Output: conflict-resolution.json
â Skip if conflictRisk is none/low â proceed directly to Phase 5
â
Phase 5: task-generate-tdd --session sessionId
â Input: sessionId + all accumulated context
â Output: IMPL_PLAN.md, IMPL-*.json, TODO_LIST.md
â
Phase 6: TDD Structure Validation (internal)
â Validate Red-Green-Refactor structure
â Present Plan Confirmation Gate
â
Plan Confirmation (User Decision Gate):
ââ "Verify TDD Compliance" (Recommended) â Route to Phase 7
ââ "Start Execution" â Skill(skill="workflow-execute")
ââ "Review Status Only" â Display session status inline
Verify Mode
Input: --session sessionId (or auto-detect)
â
Phase 7: Session discovery â Chain validation â Coverage analysis â Report
â Output: TDD_COMPLIANCE_REPORT.md with quality gate
Session Memory Flow: Each phase receives session ID, which provides access to:
- Previous task summaries
- Existing context and analysis
- Session-specific configuration
TodoWrite Pattern
Core Concept: Dynamic task attachment and collapse for real-time visibility into TDD workflow execution.
Implementation Note: Phase files use
TodoWritesyntax to describe the conceptual tracking pattern. At runtime, these are implemented viaTaskCreate/TaskUpdate/TaskListtools. Map as follows:
- Initial list creation â
TaskCreatefor each item- Status changes â
TaskUpdate({ taskId, status })- Sub-task attachment â
TaskCreate+TaskUpdate({ addBlockedBy })- Sub-task collapse â
TaskUpdate({ status: "completed" })+TaskUpdate({ status: "deleted" })for collapsed sub-items
Key Principles
-
Task Attachment (when phase executed):
- Sub-tasks are attached to orchestrator’s TodoWrite
- Phase 3, 4, 5: Multiple sub-tasks attached
- Phase 1, 2, 6: Single task (atomic)
- First attached task marked as
in_progress, others aspending - Orchestrator executes these attached tasks sequentially
-
Task Collapse (after sub-tasks complete):
- Applies to Phase 3, 4, 5: Remove detailed sub-tasks from TodoWrite
- Collapse to high-level phase summary
- Phase 1, 2, 6: No collapse needed (single task, just mark completed)
- Maintains clean orchestrator-level view
-
Continuous Execution: After completion, automatically proceed to next pending phase
Lifecycle: Initial pending â Phase executed (tasks ATTACHED) â Sub-tasks executed sequentially â Phase completed (tasks COLLAPSED for 3/4/5, marked completed for 1/2/6) â Next phase â Repeat
Initial State (Plan Mode):
[
{"content": "Phase 1: Session Discovery", "status": "in_progress", "activeForm": "Executing session discovery"},
{"content": "Phase 2: Context Gathering", "status": "pending", "activeForm": "Executing context gathering"},
{"content": "Phase 3: Test Coverage Analysis", "status": "pending", "activeForm": "Executing test coverage analysis"},
{"content": "Phase 5: TDD Task Generation", "status": "pending", "activeForm": "Executing TDD task generation"},
{"content": "Phase 6: TDD Structure Validation", "status": "pending", "activeForm": "Validating TDD structure"}
]
Note: Phase 4 (Conflict Resolution) is added dynamically after Phase 2 if conflictRisk ⥠medium.
Phase 3 (Tasks Attached):
[
{"content": "Phase 1: Session Discovery", "status": "completed"},
{"content": "Phase 2: Context Gathering", "status": "completed"},
{"content": "Phase 3: Test Coverage Analysis", "status": "in_progress"},
{"content": " â Detect test framework and conventions", "status": "in_progress"},
{"content": " â Analyze existing test coverage", "status": "pending"},
{"content": " â Identify coverage gaps", "status": "pending"},
{"content": "Phase 5: TDD Task Generation", "status": "pending"},
{"content": "Phase 6: TDD Structure Validation", "status": "pending"}
]
Phase 3 (Collapsed):
[
{"content": "Phase 1: Session Discovery", "status": "completed"},
{"content": "Phase 2: Context Gathering", "status": "completed"},
{"content": "Phase 3: Test Coverage Analysis", "status": "completed"},
{"content": "Phase 5: TDD Task Generation", "status": "pending"},
{"content": "Phase 6: TDD Structure Validation", "status": "pending"}
]
Phase 5 (Tasks Attached):
[
{"content": "Phase 1: Session Discovery", "status": "completed"},
{"content": "Phase 2: Context Gathering", "status": "completed"},
{"content": "Phase 3: Test Coverage Analysis", "status": "completed"},
{"content": "Phase 5: TDD Task Generation", "status": "in_progress"},
{"content": " â Discovery - analyze TDD requirements", "status": "in_progress"},
{"content": " â Planning - design Red-Green-Refactor cycles", "status": "pending"},
{"content": " â Output - generate IMPL tasks with internal TDD phases", "status": "pending"},
{"content": "Phase 6: TDD Structure Validation", "status": "pending"}
]
Note: See individual Phase descriptions for detailed TodoWrite Update examples.
Post-Phase Updates
Memory State Check
After heavy phases (Phase 2-3), evaluate context window usage:
- If memory usage is high (>110K tokens or approaching context limits):
Skill(skill="memory-capture") - Memory compaction is particularly important after analysis phases
Planning Notes (Optional)
Similar to workflow-plan, a planning-notes.md can accumulate context across phases if needed. See Phase 1 for initialization.
Error Handling
- Parsing Failure: If output parsing fails, retry command once, then report error
- Validation Failure: Report which file/data is missing or invalid
- Command Failure: Keep phase
in_progress, report error to user, do not proceed - TDD Validation Failure: Report incomplete chains or wrong dependencies
- Session Not Found (verify mode): Report error with available sessions list
Error Handling Quick Reference
| Error Type | Detection | Recovery Action |
|---|---|---|
| Parsing failure | Empty/malformed output | Retry once, then report |
| Missing context-package | File read error | Re-run Phase 2 (context-gathering) |
| Invalid task JSON | jq parse error | Report malformed file path |
| Task count exceeds 18 | Count validation â¥19 | Request re-scope, split into multiple sessions |
| Missing cli_execution.id | All tasks lack ID | Regenerate tasks with phase 0 user config |
| Test-context missing | File not found | Re-run Phase 3 (test-coverage-analysis) |
| Phase timeout | No response | Retry phase, check CLI connectivity |
| CLI tool not available | Tool not in cli-tools.json | Fall back to alternative preferred tool |
TDD Warning Patterns
| Pattern | Warning Message | Recommended Action |
|---|---|---|
| Task count >10 | High task count detected | Consider splitting into multiple sessions |
| Missing test-fix-cycle | Green phase lacks auto-revert | Add max_iterations: 3 to task config |
| Red phase missing test path | Test file path not specified | Add explicit test file paths |
| Generic task names | Vague names like “Add feature” | Use specific behavior descriptions |
| No refactor criteria | Refactor phase lacks completion criteria | Define clear refactor scope |
Non-Blocking Warning Policy
All warnings are advisory – they do not halt execution:
- Warnings logged to
.process/tdd-warnings.log - Summary displayed in Phase 6 output
- User decides whether to address before
workflow-executeskill
Coordinator Checklist
Plan Mode
- Pre-Phase: Convert user input to TDD structured format (TDD/GOAL/SCOPE/CONTEXT/TEST_FOCUS)
- Initialize TaskCreate before any command (Phase 4 added dynamically after Phase 2)
- Execute Phase 1 immediately with structured description
- Parse session ID from Phase 1 output, store in memory
- Pass session ID and structured description to Phase 2 command
- Parse context path from Phase 2 output, store in memory
- Extract conflictRisk from context-package.json: Determine Phase 4 execution
- Execute Phase 3 (test coverage analysis) with sessionId
- Parse testContextPath from Phase 3 output, store in memory
- If conflictRisk ⥠medium: Launch Phase 4 conflict-resolution with sessionId and contextPath
- Wait for Phase 4 to finish executing (if executed), verify conflict-resolution.json created
- If conflictRisk is none/low: Skip Phase 4, proceed directly to Phase 5
- Pass session ID to Phase 5 command (TDD task generation)
- Verify all Phase 5 outputs (IMPL_PLAN.md, IMPL-*.json, TODO_LIST.md)
- Execute Phase 6 (internal TDD structure validation)
- Plan Confirmation Gate: Present user with choice (Verify â Phase 7 / Execute / Review Status)
- If user selects Verify: Read phases/07-tdd-verify.md, execute Phase 7 in-process
- If user selects Execute: Skill(skill=”workflow-execute”)
- If user selects Review: Display session status inline
- Auto mode (workflowPreferences.autoYes): Auto-select “Verify TDD Compliance”, then auto-continue to execute if APPROVED
- Update TaskCreate/TaskUpdate after each phase
- After each phase, automatically continue to next phase based on TaskList status
Verify Mode
- Detect/validate session (from –session flag or auto-detect)
- Initialize TaskCreate with verification tasks
- Execute Phase 7 through all sub-phases (session validation â chain validation â coverage analysis â report generation)
- Present quality gate result and next step options
Related Skills
Prerequisite Skills:
- None – TDD planning is self-contained (can optionally run brainstorm commands before)
Called by Plan Mode (6 phases):
/workflow:session:start– Phase 1: Create or discover TDD workflow sessionphases/02-context-gathering.md– Phase 2: Gather project context and analyze codebase (inline)phases/03-test-coverage-analysis.md– Phase 3: Analyze existing test patterns and coverage (inline)phases/04-conflict-resolution.md– Phase 4: Detect and resolve conflicts (inline, conditional)memory-captureskill – Phase 4: Memory optimization (if context approaching limits)phases/05-tdd-task-generation.md– Phase 5: Generate TDD tasks with Red-Green-Refactor cycles (inline)
Called by Verify Mode:
phases/07-tdd-verify.md– Phase 7: Test coverage and cycle analysis (inline)
Follow-up Skills:
workflow-tddskill (tdd-verify phase) – Verify TDD compliance (can also invoke via verify mode)workflow-planskill (plan-verify phase) – Verify plan quality and dependencies- Display session status inline – Review TDD task breakdown
Skill(skill="workflow-execute")– Begin TDD implementation