claude-code-workflow 6.3.42 → 6.3.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.claude/agents/tdd-developer.md +530 -0
  2. package/.claude/commands/issue/discover-by-prompt.md +5 -1
  3. package/.claude/commands/issue/discover.md +472 -468
  4. package/.claude/commands/issue/execute.md +580 -581
  5. package/.claude/commands/issue/new.md +417 -413
  6. package/.claude/commands/issue/plan.md +11 -13
  7. package/.claude/commands/issue/queue.md +445 -441
  8. package/.claude/commands/task/breakdown.md +207 -203
  9. package/.claude/commands/task/replan.md +440 -436
  10. package/.claude/commands/workflow/action-plan-verify.md +485 -447
  11. package/.claude/commands/workflow/brainstorm/artifacts.md +457 -453
  12. package/.claude/commands/workflow/brainstorm/auto-parallel.md +5 -1
  13. package/.claude/commands/workflow/brainstorm/synthesis.md +402 -398
  14. package/.claude/commands/workflow/clean.md +67 -35
  15. package/.claude/commands/workflow/debug-with-file.md +670 -666
  16. package/.claude/commands/workflow/debug.md +331 -327
  17. package/.claude/commands/workflow/develop-with-file.md +5 -1
  18. package/.claude/commands/workflow/execute.md +546 -498
  19. package/.claude/commands/workflow/lite-execute.md +44 -26
  20. package/.claude/commands/workflow/lite-fix.md +780 -730
  21. package/.claude/commands/workflow/lite-lite-lite.md +5 -1
  22. package/.claude/commands/workflow/lite-plan.md +87 -39
  23. package/.claude/commands/workflow/multi-cli-plan.md +572 -568
  24. package/.claude/commands/workflow/plan-verify.md +527 -0
  25. package/.claude/commands/workflow/plan.md +555 -551
  26. package/.claude/commands/workflow/replan.md +572 -515
  27. package/.claude/commands/workflow/review-fix.md +608 -610
  28. package/.claude/commands/workflow/session/complete.md +37 -14
  29. package/.claude/commands/workflow/session/solidify.md +303 -299
  30. package/.claude/commands/workflow/tdd-plan.md +630 -597
  31. package/.claude/commands/workflow/tdd-verify.md +391 -206
  32. package/.claude/commands/workflow/tools/conflict-resolution.md +24 -12
  33. package/.claude/commands/workflow/tools/task-generate-agent.md +583 -563
  34. package/.claude/commands/workflow/tools/task-generate-tdd.md +749 -517
  35. package/.claude/commands/workflow/ui-design/animation-extract.md +1154 -1150
  36. package/.claude/commands/workflow/ui-design/layout-extract.md +792 -788
  37. package/.claude/commands/workflow/ui-design/style-extract.md +777 -773
  38. package/.claude/skills/ccw/command.json +4 -4
  39. package/.claude/skills/ccw-coordinator/README.md +45 -0
  40. package/.claude/skills/ccw-coordinator/SKILL.md +320 -0
  41. package/.claude/skills/ccw-coordinator/phases/actions/action-abort.md +9 -0
  42. package/.claude/skills/ccw-coordinator/phases/actions/action-command-build.md +40 -0
  43. package/.claude/skills/ccw-coordinator/phases/actions/action-command-execute.md +124 -0
  44. package/.claude/skills/ccw-coordinator/phases/actions/action-command-selection.md +48 -0
  45. package/.claude/skills/ccw-coordinator/phases/actions/action-complete.md +25 -0
  46. package/.claude/skills/ccw-coordinator/phases/actions/action-init.md +26 -0
  47. package/.claude/skills/ccw-coordinator/phases/orchestrator.md +59 -0
  48. package/.claude/skills/ccw-coordinator/phases/state-schema.md +66 -0
  49. package/.claude/skills/ccw-coordinator/skill-config.json +66 -0
  50. package/.claude/skills/ccw-coordinator/specs/command-library.md +169 -0
  51. package/.claude/skills/ccw-coordinator/specs/specs.md +362 -0
  52. package/.claude/skills/ccw-coordinator/tools/README.md +95 -0
  53. package/.claude/skills/ccw-coordinator/tools/chain-validate.cjs +320 -0
  54. package/.claude/skills/ccw-coordinator/tools/command-registry.cjs +255 -0
  55. package/.claude/skills/ccw-help/command.json +5 -5
  56. package/.claude/skills/ccw-help/scripts/analyze_commands.py +337 -337
  57. package/.claude/workflows/cli-templates/prompts/workflow-impl-plan-template.txt +1 -1
  58. package/.codex/skills/parallel-dev-cycle/README.md +19 -16
  59. package/.codex/skills/parallel-dev-cycle/phases/agents/code-developer.md +90 -5
  60. package/.codex/skills/parallel-dev-cycle/phases/agents/requirements-analyst.md +89 -4
  61. package/.codex/skills/parallel-dev-cycle/phases/orchestrator.md +696 -696
  62. package/.codex/skills/parallel-dev-cycle/phases/state-schema.md +436 -436
  63. package/.codex/skills/parallel-dev-cycle/skill.md +194 -0
  64. package/.codex/skills/parallel-dev-cycle/specs/communication-optimization.md +423 -423
  65. package/.codex/skills/parallel-dev-cycle/specs/coordination-protocol.md +31 -16
  66. package/.codex/skills/parallel-dev-cycle/specs/versioning-strategy.md +74 -73
  67. package/ccw/dist/commands/issue.d.ts +4 -0
  68. package/ccw/dist/commands/issue.d.ts.map +1 -1
  69. package/ccw/dist/commands/issue.js +73 -6
  70. package/ccw/dist/commands/issue.js.map +1 -1
  71. package/ccw/dist/core/routes/cli-routes.d.ts.map +1 -1
  72. package/ccw/dist/core/routes/cli-routes.js +32 -28
  73. package/ccw/dist/core/routes/cli-routes.js.map +1 -1
  74. package/ccw/dist/tools/claude-cli-tools.d.ts +10 -0
  75. package/ccw/dist/tools/claude-cli-tools.d.ts.map +1 -1
  76. package/ccw/dist/tools/claude-cli-tools.js +45 -0
  77. package/ccw/dist/tools/claude-cli-tools.js.map +1 -1
  78. package/ccw/dist/tools/codex-lens.d.ts.map +1 -1
  79. package/ccw/dist/tools/codex-lens.js +38 -11
  80. package/ccw/dist/tools/codex-lens.js.map +1 -1
  81. package/ccw/src/commands/issue.ts +84 -6
  82. package/ccw/src/core/routes/cli-routes.ts +30 -25
  83. package/ccw/src/templates/dashboard-js/views/help.js +1 -1
  84. package/ccw/src/tools/claude-cli-tools.ts +50 -0
  85. package/ccw/src/tools/codex-lens.ts +40 -11
  86. package/package.json +1 -1
  87. package/.codex/skills/parallel-dev-cycle/SKILL.md +0 -513
@@ -1,517 +1,749 @@
1
- ---
2
- name: task-generate-tdd
3
- description: Autonomous TDD task generation using action-planning-agent with Red-Green-Refactor cycles, test-first structure, and cycle validation
4
- argument-hint: "--session WFS-session-id"
5
- examples:
6
- - /workflow:tools:task-generate-tdd --session WFS-auth
7
- ---
8
-
9
- # Autonomous TDD Task Generation Command
10
-
11
- ## Overview
12
- Autonomous TDD task JSON and IMPL_PLAN.md generation using action-planning-agent with two-phase execution: discovery and document generation. Generates complete Red-Green-Refactor cycles contained within each task.
13
-
14
- ## Core Philosophy
15
- - **Agent-Driven**: Delegate execution to action-planning-agent for autonomous operation
16
- - **Two-Phase Flow**: Discovery (context gathering) → Output (document generation)
17
- - **Memory-First**: Reuse loaded documents from conversation memory
18
- - **MCP-Enhanced**: Use MCP tools for advanced code analysis and research
19
- - **Semantic CLI Selection**: CLI tool usage determined from user's task description, not flags
20
- - **Agent Simplicity**: Agent generates content with semantic CLI detection
21
- - **Path Clarity**: All `focus_paths` prefer absolute paths (e.g., `D:\\project\\src\\module`), or clear relative paths from project root (e.g., `./src/module`)
22
- - **TDD-First**: Every feature starts with a failing test (Red phase)
23
- - **Feature-Complete Tasks**: Each task contains complete Red-Green-Refactor cycle
24
- - **Quantification-Enforced**: All test cases, coverage requirements, and implementation scope MUST include explicit counts and enumerations
25
-
26
- ## Task Strategy & Philosophy
27
-
28
- ### Optimized Task Structure (Current)
29
- - **1 feature = 1 task** containing complete TDD cycle internally
30
- - Each task executes Red-Green-Refactor phases sequentially
31
- - Task count = Feature count (typically 5 features = 5 tasks)
32
-
33
- **Previous Approach** (Deprecated):
34
- - 1 feature = 3 separate tasks (TEST-N.M, IMPL-N.M, REFACTOR-N.M)
35
- - 5 features = 15 tasks with complex dependency chains
36
- - High context switching cost between phases
37
-
38
- ### When to Use Subtasks
39
- - Feature complexity >2500 lines or >6 files per TDD cycle
40
- - Multiple independent sub-features needing parallel execution
41
- - Strong technical dependency blocking (e.g., API before UI)
42
- - Different tech stacks or domains within feature
43
-
44
- ### Task Limits
45
- - **Maximum 18 tasks** (hard limit for TDD workflows)
46
- - **Feature-based**: Complete functional units with internal TDD cycles
47
- - **Hierarchy**: Flat (≤5 simple features) | Two-level (6-10 for complex features with sub-features)
48
- - **Re-scope**: If >18 tasks needed, break project into multiple TDD workflow sessions
49
-
50
- ### TDD Cycle Mapping
51
- - **Old approach**: 1 feature = 3 tasks (TEST-N.M, IMPL-N.M, REFACTOR-N.M)
52
- - **Current approach**: 1 feature = 1 task (IMPL-N with internal Red-Green-Refactor phases)
53
- - **Complex features**: 1 container (IMPL-N) + subtasks (IMPL-N.M) when necessary
54
-
55
- ## Execution Process
56
-
57
- ```
58
- Input Parsing:
59
- ├─ Parse flags: --session
60
- └─ Validation: session_id REQUIRED
61
-
62
- Phase 1: Discovery & Context Loading (Memory-First)
63
- ├─ Load session context (if not in memory)
64
- ├─ Load context package (if not in memory)
65
- ├─ Load test context package (if not in memory)
66
- ├─ Extract & load role analyses from context package
67
- ├─ Load conflict resolution (if exists)
68
- └─ Optional: MCP external research
69
-
70
- Phase 2: Agent Execution (Document Generation)
71
- ├─ Pre-agent template selection (semantic CLI detection)
72
- ├─ Invoke action-planning-agent
73
- ├─ Generate TDD Task JSON Files (.task/IMPL-*.json)
74
- │ └─ Each task: complete Red-Green-Refactor cycle internally
75
- ├─ Create IMPL_PLAN.md (TDD variant)
76
- └─ Generate TODO_LIST.md with TDD phase indicators
77
- ```
78
-
79
- ## Execution Lifecycle
80
-
81
- ### Phase 1: Discovery & Context Loading
82
- **⚡ Memory-First Rule**: Skip file loading if documents already in conversation memory
83
-
84
- **Agent Context Package**:
85
- ```javascript
86
- {
87
- "session_id": "WFS-[session-id]",
88
- "workflow_type": "tdd",
89
- // Note: CLI tool usage is determined semantically by action-planning-agent based on user's task description
90
- "session_metadata": {
91
- // If in memory: use cached content
92
- // Else: Load from .workflow/active//{session-id}/workflow-session.json
93
- },
94
- "brainstorm_artifacts": {
95
- // Loaded from context-package.json brainstorm_artifacts section
96
- "role_analyses": [
97
- {
98
- "role": "system-architect",
99
- "files": [{"path": "...", "type": "primary|supplementary"}]
100
- }
101
- ],
102
- "guidance_specification": {"path": "...", "exists": true},
103
- "synthesis_output": {"path": "...", "exists": true},
104
- "conflict_resolution": {"path": "...", "exists": true} // if conflict_risk >= medium
105
- },
106
- "context_package_path": ".workflow/active//{session-id}/.process/context-package.json",
107
- "context_package": {
108
- // If in memory: use cached content
109
- // Else: Load from .workflow/active//{session-id}/.process/context-package.json
110
- },
111
- "test_context_package_path": ".workflow/active//{session-id}/.process/test-context-package.json",
112
- "test_context_package": {
113
- // Existing test patterns and coverage analysis
114
- },
115
- "mcp_capabilities": {
116
- "codex_lens": true,
117
- "exa_code": true,
118
- "exa_web": true
119
- }
120
- }
121
- ```
122
-
123
- **Discovery Actions**:
124
- 1. **Load Session Context** (if not in memory)
125
- ```javascript
126
- if (!memory.has("workflow-session.json")) {
127
- Read(.workflow/active//{session-id}/workflow-session.json)
128
- }
129
- ```
130
-
131
- 2. **Load Context Package** (if not in memory)
132
- ```javascript
133
- if (!memory.has("context-package.json")) {
134
- Read(.workflow/active//{session-id}/.process/context-package.json)
135
- }
136
- ```
137
-
138
- 3. **Load Test Context Package** (if not in memory)
139
- ```javascript
140
- if (!memory.has("test-context-package.json")) {
141
- Read(.workflow/active//{session-id}/.process/test-context-package.json)
142
- }
143
- ```
144
-
145
- 4. **Extract & Load Role Analyses** (from context-package.json)
146
- ```javascript
147
- // Extract role analysis paths from context package
148
- const roleAnalysisPaths = contextPackage.brainstorm_artifacts.role_analyses
149
- .flatMap(role => role.files.map(f => f.path));
150
-
151
- // Load each role analysis file
152
- roleAnalysisPaths.forEach(path => Read(path));
153
- ```
154
-
155
- 5. **Load Conflict Resolution** (from conflict-resolution.json, if exists)
156
- ```javascript
157
- // Check for new conflict-resolution.json format
158
- if (contextPackage.conflict_detection?.resolution_file) {
159
- Read(contextPackage.conflict_detection.resolution_file) // .process/conflict-resolution.json
160
- }
161
- // Fallback: legacy brainstorm_artifacts path
162
- else if (contextPackage.brainstorm_artifacts?.conflict_resolution?.exists) {
163
- Read(contextPackage.brainstorm_artifacts.conflict_resolution.path)
164
- }
165
- ```
166
-
167
- 6. **Code Analysis with Native Tools** (optional - enhance understanding)
168
- ```bash
169
- # Find relevant test files and patterns
170
- find . -name "*test*" -type f
171
- rg "describe|it\(|test\(" -g "*.ts"
172
- ```
173
-
174
- 7. **MCP External Research** (optional - gather TDD best practices)
175
- ```javascript
176
- // Get external TDD examples and patterns
177
- mcp__exa__get_code_context_exa(
178
- query="TypeScript TDD best practices Red-Green-Refactor",
179
- tokensNum="dynamic"
180
- )
181
- ```
182
-
183
- ### Phase 2: Agent Execution (Document Generation)
184
-
185
- **Pre-Agent Template Selection** (Command decides path before invoking agent):
186
- ```javascript
187
- // Command checks flag and selects template PATH (not content)
188
- const templatePath = hasCliExecuteFlag
189
- ? "~/.claude/workflows/cli-templates/prompts/workflow/task-json-cli-mode.txt"
190
- : "~/.claude/workflows/cli-templates/prompts/workflow/task-json-agent-mode.txt";
191
- ```
192
-
193
- **Agent Invocation**:
194
- ```javascript
195
- Task(
196
- subagent_type="action-planning-agent",
197
- run_in_background=false,
198
- description="Generate TDD task JSON and implementation plan",
199
- prompt=`
200
- ## Execution Context
201
-
202
- **Session ID**: WFS-{session-id}
203
- **Workflow Type**: TDD
204
- **Note**: CLI tool usage is determined semantically from user's task description
205
-
206
- ## Phase 1: Discovery Results (Provided Context)
207
-
208
- ### Session Metadata
209
- {session_metadata_content}
210
-
211
- ### Role Analyses (Enhanced by Synthesis)
212
- {role_analyses_content}
213
- - Includes requirements, design specs, enhancements, and clarifications from synthesis phase
214
-
215
- ### Artifacts Inventory
216
- - **Guidance Specification**: {guidance_spec_path}
217
- - **Role Analyses**: {role_analyses_list}
218
-
219
- ### Context Package
220
- {context_package_summary}
221
- - Includes conflict_risk assessment
222
-
223
- ### Test Context Package
224
- {test_context_package_summary}
225
- - Existing test patterns, framework config, coverage analysis
226
-
227
- ### Conflict Resolution (Conditional)
228
- If conflict_risk was medium/high, modifications have been applied to:
229
- - **guidance-specification.md**: Design decisions updated to resolve conflicts
230
- - **Role analyses (*.md)**: Recommendations adjusted for compatibility
231
- - **context-package.json**: Marked as "resolved" with conflict IDs
232
- - Conflict resolution results stored in conflict-resolution.json
233
-
234
- ### MCP Analysis Results (Optional)
235
- **Code Structure**: {mcp_code_index_results}
236
- **External Research**: {mcp_exa_research_results}
237
-
238
- ## Phase 2: TDD Document Generation Task
239
-
240
- **Agent Configuration Reference**: All TDD task generation rules, quantification requirements, Red-Green-Refactor cycle structure, quality standards, and execution details are defined in action-planning-agent.
241
-
242
- ### TDD-Specific Requirements Summary
243
-
244
- #### Task Structure Philosophy
245
- - **1 feature = 1 task** containing complete TDD cycle internally
246
- - Each task executes Red-Green-Refactor phases sequentially
247
- - Task count = Feature count (typically 5 features = 5 tasks)
248
- - Subtasks only when complexity >2500 lines or >6 files per cycle
249
- - **Maximum 18 tasks** (hard limit for TDD workflows)
250
-
251
- #### TDD Cycle Mapping
252
- - **Simple features**: IMPL-N with internal Red-Green-Refactor phases
253
- - **Complex features**: IMPL-N (container) + IMPL-N.M (subtasks)
254
- - Each cycle includes: test_count, test_cases array, implementation_scope, expected_coverage
255
-
256
- #### Required Outputs Summary
257
-
258
- ##### 1. TDD Task JSON Files (.task/IMPL-*.json)
259
- - **Location**: `.workflow/active//{session-id}/.task/`
260
- - **Schema**: 5-field structure with TDD-specific metadata
261
- - `meta.tdd_workflow`: true (REQUIRED)
262
- - `meta.max_iterations`: 3 (Green phase test-fix cycle limit)
263
- - `context.tdd_cycles`: Array with quantified test cases and coverage
264
- - `flow_control.implementation_approach`: Exactly 3 steps with `tdd_phase` field
265
- 1. Red Phase (`tdd_phase: "red"`): Write failing tests
266
- 2. Green Phase (`tdd_phase: "green"`): Implement to pass tests
267
- 3. Refactor Phase (`tdd_phase: "refactor"`): Improve code quality
268
- - CLI tool usage determined semantically (add `command` field when user requests CLI execution)
269
- - **Details**: See action-planning-agent.md § TDD Task JSON Generation
270
-
271
- ##### 2. IMPL_PLAN.md (TDD Variant)
272
- - **Location**: `.workflow/active//{session-id}/IMPL_PLAN.md`
273
- - **Template**: `~/.claude/workflows/cli-templates/prompts/workflow/impl-plan-template.txt`
274
- - **TDD-Specific Frontmatter**: workflow_type="tdd", tdd_workflow=true, feature_count, task_breakdown
275
- - **TDD Implementation Tasks Section**: Feature-by-feature with internal Red-Green-Refactor cycles
276
- - **Details**: See action-planning-agent.md § TDD Implementation Plan Creation
277
-
278
- ##### 3. TODO_LIST.md
279
- - **Location**: `.workflow/active//{session-id}/TODO_LIST.md`
280
- - **Format**: Hierarchical task list with internal TDD phase indicators (Red → Green → Refactor)
281
- - **Status**: ▸ (container), [ ] (pending), [x] (completed)
282
- - **Details**: See action-planning-agent.md § TODO List Generation
283
-
284
- ### Quantification Requirements (MANDATORY)
285
-
286
- **Core Rules**:
287
- 1. **Explicit Test Case Counts**: Red phase specifies exact number with enumerated list
288
- 2. **Quantified Coverage**: Acceptance includes measurable percentage (e.g., ">=85%")
289
- 3. **Detailed Implementation Scope**: Green phase enumerates files, functions, line counts
290
- 4. **Enumerated Refactoring Targets**: Refactor phase lists specific improvements with counts
291
-
292
- **TDD Phase Formats**:
293
- - **Red Phase**: "Write N test cases: [test1, test2, ...]"
294
- - **Green Phase**: "Implement N functions in file lines X-Y: [func1() X1-Y1, func2() X2-Y2, ...]"
295
- - **Refactor Phase**: "Apply N refactorings: [improvement1 (details), improvement2 (details), ...]"
296
- - **Acceptance**: "All N tests pass with >=X% coverage: verify by [test command]"
297
-
298
- **Validation Checklist**:
299
- - [ ] Every Red phase specifies exact test case count with enumerated list
300
- - [ ] Every Green phase enumerates files, functions, and estimated line counts
301
- - [ ] Every Refactor phase lists specific improvements with counts
302
- - [ ] Every acceptance criterion includes measurable coverage percentage
303
- - [ ] tdd_cycles array contains test_count and test_cases for each cycle
304
- - [ ] No vague language ("comprehensive", "complete", "thorough")
305
-
306
- ### Agent Execution Summary
307
-
308
- **Key Steps** (Detailed instructions in action-planning-agent.md):
309
- 1. Load task JSON template from provided path
310
- 2. Extract and decompose features with TDD cycles
311
- 3. Generate TDD task JSON files enforcing quantification requirements
312
- 4. Create IMPL_PLAN.md using TDD template variant
313
- 5. Generate TODO_LIST.md with TDD phase indicators
314
- 6. Update session state with TDD metadata
315
-
316
- **Quality Gates** (Full checklist in action-planning-agent.md):
317
- - ✓ Quantification requirements enforced (explicit counts, measurable acceptance, exact targets)
318
- - ✓ Task count ≤18 (hard limit)
319
- - ✓ Each task has meta.tdd_workflow: true
320
- - Each task has exactly 3 implementation steps with tdd_phase field
321
- - ✓ Green phase includes test-fix cycle logic
322
- - Artifact references mapped correctly
323
- - ✓ MCP tool integration added
324
- - ✓ Documents follow TDD template structure
325
-
326
- ## Output
327
-
328
- Generate all three documents and report completion status:
329
- - TDD task JSON files created: N files (IMPL-*.json)
330
- - TDD cycles configured: N cycles with quantified test cases
331
- - Artifacts integrated: synthesis-spec, guidance-specification, N role analyses
332
- - Test context integrated: existing patterns and coverage
333
- - MCP enhancements: CodexLens, exa-research
334
- - Session ready for TDD execution: /workflow:execute
335
- `
336
- )
337
- ```
338
-
339
- ### Agent Context Passing
340
-
341
- **Memory-Aware Context Assembly**:
342
- ```javascript
343
- // Assemble context package for agent
344
- const agentContext = {
345
- session_id: "WFS-[id]",
346
- workflow_type: "tdd",
347
-
348
- // Use memory if available, else load
349
- session_metadata: memory.has("workflow-session.json")
350
- ? memory.get("workflow-session.json")
351
- : Read(.workflow/active/WFS-[id]/workflow-session.json),
352
-
353
- context_package_path: ".workflow/active/WFS-[id]/.process/context-package.json",
354
-
355
- context_package: memory.has("context-package.json")
356
- ? memory.get("context-package.json")
357
- : Read(".workflow/active/WFS-[id]/.process/context-package.json"),
358
-
359
- test_context_package_path: ".workflow/active/WFS-[id]/.process/test-context-package.json",
360
-
361
- test_context_package: memory.has("test-context-package.json")
362
- ? memory.get("test-context-package.json")
363
- : Read(".workflow/active/WFS-[id]/.process/test-context-package.json"),
364
-
365
- // Extract brainstorm artifacts from context package
366
- brainstorm_artifacts: extractBrainstormArtifacts(context_package),
367
-
368
- // Load role analyses using paths from context package
369
- role_analyses: brainstorm_artifacts.role_analyses
370
- .flatMap(role => role.files)
371
- .map(file => Read(file.path)),
372
-
373
- // Load conflict resolution if exists (prefer new JSON format)
374
- conflict_resolution: context_package.conflict_detection?.resolution_file
375
- ? Read(context_package.conflict_detection.resolution_file) // .process/conflict-resolution.json
376
- : (brainstorm_artifacts?.conflict_resolution?.exists
377
- ? Read(brainstorm_artifacts.conflict_resolution.path)
378
- : null),
379
-
380
- // Optional MCP enhancements
381
- mcp_analysis: executeMcpDiscovery()
382
- }
383
- ```
384
-
385
- ## TDD Task Structure Reference
386
-
387
- This section provides quick reference for TDD task JSON structure. For complete implementation details, see the agent invocation prompt in Phase 2 above.
388
-
389
- **Quick Reference**:
390
- - Each TDD task contains complete Red-Green-Refactor cycle
391
- - Task ID format: `IMPL-N` (simple) or `IMPL-N.M` (complex subtasks)
392
- - Required metadata: `meta.tdd_workflow: true`, `meta.max_iterations: 3`
393
- - Flow control: Exactly 3 steps with `tdd_phase` field (red, green, refactor)
394
- - Context: `tdd_cycles` array with quantified test cases and coverage
395
- - See Phase 2 agent prompt for full schema and requirements
396
-
397
- ## Output Files Structure
398
- ```
399
- .workflow/active//{session-id}/
400
- ├── IMPL_PLAN.md # Unified plan with TDD Implementation Tasks section
401
- ├── TODO_LIST.md # Progress tracking with internal TDD phase indicators
402
- ├── .task/
403
- │ ├── IMPL-1.json # Complete TDD task (Red-Green-Refactor internally)
404
- │ ├── IMPL-2.json # Complete TDD task
405
- │ ├── IMPL-3.json # Complex feature container (if needed)
406
- │ ├── IMPL-3.1.json # Complex feature subtask (if needed)
407
- │ ├── IMPL-3.2.json # Complex feature subtask (if needed)
408
- │ └── ...
409
- └── .process/
410
- ├── conflict-resolution.json # Conflict resolution results (if conflict_risk medium)
411
- ├── test-context-package.json # Test coverage analysis
412
- ├── context-package.json # Input from context-gather
413
- ├── context_package_path # Path to smart context package
414
- └── green-fix-iteration-*.md # Fix logs from Green phase test-fix cycles
415
- ```
416
-
417
- **File Count**:
418
- - **Old approach**: 5 features = 15 task JSON files (TEST/IMPL/REFACTOR × 5)
419
- - **New approach**: 5 features = 5 task JSON files (IMPL-N × 5)
420
- - **Complex feature**: 1 feature = 1 container + M subtasks (IMPL-N + IMPL-N.M)
421
-
422
- ## Validation Rules
423
-
424
- ### Task Completeness
425
- - Every IMPL-N must contain complete TDD workflow in `flow_control.implementation_approach`
426
- - Each task must have 3 steps with `tdd_phase`: "red", "green", "refactor"
427
- - Every task must have `meta.tdd_workflow: true`
428
-
429
- ### Dependency Enforcement
430
- - Sequential features: IMPL-N depends_on ["IMPL-(N-1)"] if needed
431
- - Complex feature subtasks: IMPL-N.M depends_on ["IMPL-N.(M-1)"] or parent dependencies
432
- - No circular dependencies allowed
433
-
434
- ### Task Limits
435
- - Maximum 10 total tasks (simple + subtasks)
436
- - Flat hierarchy (≤5 tasks) or two-level (6-10 tasks with containers)
437
- - Re-scope requirements if >10 tasks needed
438
-
439
- ### TDD Workflow Validation
440
- - `meta.tdd_workflow` must be true
441
- - `flow_control.implementation_approach` must have exactly 3 steps
442
- - Each step must have `tdd_phase` field ("red", "green", or "refactor")
443
- - Green phase step must include test-fix cycle logic
444
- - `meta.max_iterations` must be present (default: 3)
445
-
446
- ## Error Handling
447
-
448
- ### Input Validation Errors
449
- | Error | Cause | Resolution |
450
- |-------|-------|------------|
451
- | Session not found | Invalid session ID | Verify session exists |
452
- | Context missing | Incomplete planning | Run context-gather first |
453
-
454
- ### TDD Generation Errors
455
- | Error | Cause | Resolution |
456
- |-------|-------|------------|
457
- | Task count exceeds 10 | Too many features or subtasks | Re-scope requirements or merge features |
458
- | Missing test framework | No test config | Configure testing first |
459
- | Invalid TDD workflow | Missing tdd_phase or incomplete flow_control | Fix TDD structure in ANALYSIS_RESULTS.md |
460
- | Missing tdd_workflow flag | Task doesn't have meta.tdd_workflow: true | Add TDD workflow metadata |
461
-
462
- ## Integration & Usage
463
-
464
- **Command Chain**:
465
- - Called by: `/workflow:tdd-plan` (Phase 4)
466
- - Invokes: `action-planning-agent` for autonomous task generation
467
- - Followed by: `/workflow:execute`, `/workflow:tdd-verify`
468
-
469
- **Basic Usage**:
470
- ```bash
471
- # Standard execution
472
- /workflow:tools:task-generate-tdd --session WFS-auth
473
-
474
- # With semantic CLI request (include in task description)
475
- # e.g., "Generate TDD tasks for auth module, use Codex for implementation"
476
- ```
477
-
478
- **CLI Tool Selection**: Determined semantically from user's task description. Include "use Codex/Gemini/Qwen" in your request for CLI execution.
479
-
480
- **Output**:
481
- - TDD task JSON files in `.task/` directory (IMPL-N.json format)
482
- - IMPL_PLAN.md with TDD Implementation Tasks section
483
- - TODO_LIST.md with internal TDD phase indicators
484
- - Session state updated with task count and TDD metadata
485
- - MCP enhancements integrated (if available)
486
-
487
- ## Test Coverage Analysis Integration
488
-
489
- The TDD workflow includes test coverage analysis (via `/workflow:tools:test-context-gather`) to:
490
- - Detect existing test patterns and conventions
491
- - Identify current test coverage gaps
492
- - Discover test framework and configuration
493
- - Enable integration with existing tests
494
-
495
- This makes TDD workflow context-aware instead of assuming greenfield scenarios.
496
-
497
- ## Iterative Green Phase with Test-Fix Cycle
498
-
499
- IMPL (Green phase) tasks include automatic test-fix cycle:
500
-
501
- **Process Flow**:
502
- 1. **Initial Implementation**: Write minimal code to pass tests
503
- 2. **Test Execution**: Run test suite
504
- 3. **Success Path**: Tests pass Complete task
505
- 4. **Failure Path**: Tests fail Enter iterative fix cycle:
506
- - **Gemini Diagnosis**: Analyze failures with bug-fix template
507
- - **Fix Application**: Agent (default) or CLI (if `command` field present)
508
- - **Retest**: Verify fix resolves failures
509
- - **Repeat**: Up to max_iterations (default: 3)
510
- 5. **Safety Net**: Auto-revert all changes if max iterations reached
511
-
512
-
513
-
514
- ## Configuration Options
515
- - **meta.max_iterations**: Number of fix attempts (default: 3 for TDD, 5 for test-gen)
516
- - **CLI tool usage**: Determined semantically from user's task description via `command` field in implementation_approach
517
-
1
+ ---
2
+ name: task-generate-tdd
3
+ description: Autonomous TDD task generation using action-planning-agent with Red-Green-Refactor cycles, test-first structure, and cycle validation
4
+ argument-hint: "[-y|--yes] --session WFS-session-id"
5
+ examples:
6
+ - /workflow:tools:task-generate-tdd --session WFS-auth
7
+ - /workflow:tools:task-generate-tdd -y --session WFS-auth
8
+ ---
9
+
10
+ ## Auto Mode
11
+
12
+ When `--yes` or `-y`: Skip user questions, use defaults (no materials, Agent executor).
13
+
14
+ # Autonomous TDD Task Generation Command
15
+
16
+ ## Overview
17
+ Autonomous TDD task JSON and IMPL_PLAN.md generation using action-planning-agent with two-phase execution: discovery and document generation. Generates complete Red-Green-Refactor cycles contained within each task.
18
+
19
+ ## Core Philosophy
20
+ - **Agent-Driven**: Delegate execution to action-planning-agent for autonomous operation
21
+ - **Two-Phase Flow**: Discovery (context gathering) Output (document generation)
22
+ - **Memory-First**: Reuse loaded documents from conversation memory
23
+ - **MCP-Enhanced**: Use MCP tools for advanced code analysis and research
24
+ - **Semantic CLI Selection**: CLI tool usage determined from user's task description, not flags
25
+ - **Agent Simplicity**: Agent generates content with semantic CLI detection
26
+ - **Path Clarity**: All `focus_paths` prefer absolute paths (e.g., `D:\\project\\src\\module`), or clear relative paths from project root (e.g., `./src/module`)
27
+ - **TDD-First**: Every feature starts with a failing test (Red phase)
28
+ - **Feature-Complete Tasks**: Each task contains complete Red-Green-Refactor cycle
29
+ - **Quantification-Enforced**: All test cases, coverage requirements, and implementation scope MUST include explicit counts and enumerations
30
+
31
+ ## Task Strategy & Philosophy
32
+
33
+ ### Optimized Task Structure (Current)
34
+ - **1 feature = 1 task** containing complete TDD cycle internally
35
+ - Each task executes Red-Green-Refactor phases sequentially
36
+ - Task count = Feature count (typically 5 features = 5 tasks)
37
+
38
+ **Previous Approach** (Deprecated):
39
+ - 1 feature = 3 separate tasks (TEST-N.M, IMPL-N.M, REFACTOR-N.M)
40
+ - 5 features = 15 tasks with complex dependency chains
41
+ - High context switching cost between phases
42
+
43
+ ### When to Use Subtasks
44
+ - Feature complexity >2500 lines or >6 files per TDD cycle
45
+ - Multiple independent sub-features needing parallel execution
46
+ - Strong technical dependency blocking (e.g., API before UI)
47
+ - Different tech stacks or domains within feature
48
+
49
+ ### Task Limits
50
+ - **Maximum 18 tasks** (hard limit for TDD workflows)
51
+ - **Feature-based**: Complete functional units with internal TDD cycles
52
+ - **Hierarchy**: Flat (≤5 simple features) | Two-level (6-10 for complex features with sub-features)
53
+ - **Re-scope**: If >18 tasks needed, break project into multiple TDD workflow sessions
54
+
55
+ ### TDD Cycle Mapping
56
+ - **Old approach**: 1 feature = 3 tasks (TEST-N.M, IMPL-N.M, REFACTOR-N.M)
57
+ - **Current approach**: 1 feature = 1 task (IMPL-N with internal Red-Green-Refactor phases)
58
+ - **Complex features**: 1 container (IMPL-N) + subtasks (IMPL-N.M) when necessary
59
+
60
+ ## Execution Process
61
+
62
+ ```
63
+ Input Parsing:
64
+ ├─ Parse flags: --session
65
+ └─ Validation: session_id REQUIRED
66
+
67
+ Phase 1: Discovery & Context Loading (Memory-First)
68
+ ├─ Load session context (if not in memory)
69
+ ├─ Load context package (if not in memory)
70
+ ├─ Load test context package (if not in memory)
71
+ ├─ Extract & load role analyses from context package
72
+ ├─ Load conflict resolution (if exists)
73
+ └─ Optional: MCP external research
74
+
75
+ Phase 2: Agent Execution (Document Generation)
76
+ ├─ Pre-agent template selection (semantic CLI detection)
77
+ ├─ Invoke action-planning-agent
78
+ ├─ Generate TDD Task JSON Files (.task/IMPL-*.json)
79
+ │ └─ Each task: complete Red-Green-Refactor cycle internally
80
+ ├─ Create IMPL_PLAN.md (TDD variant)
81
+ └─ Generate TODO_LIST.md with TDD phase indicators
82
+ ```
83
+
84
+ ## Execution Lifecycle
85
+
86
+ ### Phase 0: User Configuration (Interactive)
87
+
88
+ **Purpose**: Collect user preferences before TDD task generation to ensure generated tasks match execution expectations and provide necessary supplementary context.
89
+
90
+ **User Questions**:
91
+ ```javascript
92
+ AskUserQuestion({
93
+ questions: [
94
+ {
95
+ question: "Do you have supplementary materials or guidelines to include?",
96
+ header: "Materials",
97
+ multiSelect: false,
98
+ options: [
99
+ { label: "No additional materials", description: "Use existing context only" },
100
+ { label: "Provide file paths", description: "I'll specify paths to include" },
101
+ { label: "Provide inline content", description: "I'll paste content directly" }
102
+ ]
103
+ },
104
+ {
105
+ question: "Select execution method for generated TDD tasks:",
106
+ header: "Execution",
107
+ multiSelect: false,
108
+ options: [
109
+ { label: "Agent (Recommended)", description: "Claude agent executes Red-Green-Refactor cycles directly" },
110
+ { label: "Hybrid", description: "Agent orchestrates, calls CLI for complex steps (Red/Green phases)" },
111
+ { label: "CLI Only", description: "All TDD cycles via CLI tools (codex/gemini/qwen)" }
112
+ ]
113
+ },
114
+ {
115
+ question: "If using CLI, which tool do you prefer?",
116
+ header: "CLI Tool",
117
+ multiSelect: false,
118
+ options: [
119
+ { label: "Codex (Recommended)", description: "Best for TDD Red-Green-Refactor cycles" },
120
+ { label: "Gemini", description: "Best for analysis and large context" },
121
+ { label: "Qwen", description: "Alternative analysis tool" },
122
+ { label: "Auto", description: "Let agent decide per-task" }
123
+ ]
124
+ }
125
+ ]
126
+ })
127
+ ```
128
+
129
+ **Handle Materials Response**:
130
+ ```javascript
131
+ if (userConfig.materials === "Provide file paths") {
132
+ // Follow-up question for file paths
133
+ const pathsResponse = AskUserQuestion({
134
+ questions: [{
135
+ question: "Enter file paths to include (comma-separated or one per line):",
136
+ header: "Paths",
137
+ multiSelect: false,
138
+ options: [
139
+ { label: "Enter paths", description: "Provide paths in text input" }
140
+ ]
141
+ }]
142
+ })
143
+ userConfig.supplementaryPaths = parseUserPaths(pathsResponse)
144
+ }
145
+ ```
146
+
147
+ **Build userConfig**:
148
+ ```javascript
149
+ const userConfig = {
150
+ supplementaryMaterials: {
151
+ type: "none|paths|inline",
152
+ content: [...], // Parsed paths or inline content
153
+ },
154
+ executionMethod: "agent|hybrid|cli",
155
+ preferredCliTool: "codex|gemini|qwen|auto",
156
+ enableResume: true // Always enable resume for CLI executions
157
+ }
158
+ ```
159
+
160
+ **Pass to Agent**: Include `userConfig` in agent prompt for Phase 2.
161
+
162
+ ---
163
+
164
+ ### Phase 1: Context Preparation & Discovery
165
+
166
+ **Command Responsibility**: Command prepares session paths and metadata, provides to agent for autonomous context loading.
167
+
168
+ **⚡ Memory-First Rule**: Skip file loading if documents already in conversation memory
169
+
170
+ **📊 Progressive Loading Strategy**: Load context incrementally due to large analysis.md file sizes:
171
+ - **Core**: session metadata + context-package.json (always load)
172
+ - **Selective**: synthesis_output OR (guidance + relevant role analyses) - NOT all role analyses
173
+ - **On-Demand**: conflict resolution (if conflict_risk >= medium), test context
174
+
175
+ **🛤️ Path Clarity Requirement**: All `focus_paths` prefer absolute paths (e.g., `D:\\project\\src\\module`), or clear relative paths from project root (e.g., `./src/module`)
176
+
177
+ **Session Path Structure** (Provided by Command to Agent):
178
+ ```
179
+ .workflow/active/WFS-{session-id}/
180
+ ├── workflow-session.json # Session metadata
181
+ ├── .process/
182
+ │ ├── context-package.json # Context package with artifact catalog
183
+ │ ├── test-context-package.json # Test coverage analysis
184
+ │ └── conflict-resolution.json # Conflict resolution (if exists)
185
+ ├── .task/ # Output: Task JSON files
186
+ │ ├── IMPL-1.json
187
+ │ ├── IMPL-2.json
188
+ │ └── ...
189
+ ├── IMPL_PLAN.md # Output: TDD implementation plan
190
+ └── TODO_LIST.md # Output: TODO list with TDD phases
191
+ ```
192
+
193
+ **Command Preparation**:
194
+ 1. **Assemble Session Paths** for agent prompt:
195
+ - `session_metadata_path`: `.workflow/active/{session-id}/workflow-session.json`
196
+ - `context_package_path`: `.workflow/active/{session-id}/.process/context-package.json`
197
+ - `test_context_package_path`: `.workflow/active/{session-id}/.process/test-context-package.json`
198
+ - Output directory paths
199
+
200
+ 2. **Provide Metadata** (simple values):
201
+ - `session_id`: WFS-{session-id}
202
+ - `workflow_type`: "tdd"
203
+ - `mcp_capabilities`: {exa_code, exa_web, code_index}
204
+
205
+ 3. **Pass userConfig** from Phase 0
206
+
207
+ **Agent Context Package** (Agent loads autonomously):
208
+ ```javascript
209
+ {
210
+ "session_id": "WFS-[session-id]",
211
+ "workflow_type": "tdd",
212
+
213
+ // Core (ALWAYS load)
214
+ "session_metadata": {
215
+ // If in memory: use cached content
216
+ // Else: Load from workflow-session.json
217
+ },
218
+ "context_package": {
219
+ // If in memory: use cached content
220
+ // Else: Load from context-package.json
221
+ },
222
+
223
+ // Selective (load based on progressive strategy)
224
+ "brainstorm_artifacts": {
225
+ // Loaded from context-package.json brainstorm_artifacts section
226
+ "synthesis_output": {"path": "...", "exists": true}, // Load if exists (highest priority)
227
+ "guidance_specification": {"path": "...", "exists": true}, // Load if no synthesis
228
+ "role_analyses": [ // Load SELECTIVELY based on task relevance
229
+ {
230
+ "role": "system-architect",
231
+ "files": [{"path": "...", "type": "primary|supplementary"}]
232
+ }
233
+ ]
234
+ },
235
+
236
+ // On-Demand (load if exists)
237
+ "test_context_package": {
238
+ // Load from test-context-package.json
239
+ // Contains existing test patterns and coverage analysis
240
+ },
241
+ "conflict_resolution": {
242
+ // Load from conflict-resolution.json if conflict_risk >= medium
243
+ // Check context-package.conflict_detection.resolution_file
244
+ },
245
+
246
+ // Capabilities
247
+ "mcp_capabilities": {
248
+ "exa_code": true,
249
+ "exa_web": true,
250
+ "code_index": true
251
+ },
252
+
253
+ // User configuration from Phase 0
254
+ "user_config": {
255
+ // From Phase 0 AskUserQuestion
256
+ }
257
+ }
258
+ ```
259
+
260
+ **Discovery Actions**:
261
+ 1. **Load Session Context** (if not in memory)
262
+ ```javascript
263
+ if (!memory.has("workflow-session.json")) {
264
+ Read(.workflow/active/{session-id}/workflow-session.json)
265
+ }
266
+ ```
267
+
268
+ 2. **Load Context Package** (if not in memory)
269
+ ```javascript
270
+ if (!memory.has("context-package.json")) {
271
+ Read(.workflow/active/{session-id}/.process/context-package.json)
272
+ }
273
+ ```
274
+
275
+ 3. **Load Test Context Package** (if not in memory)
276
+ ```javascript
277
+ if (!memory.has("test-context-package.json")) {
278
+ Read(.workflow/active/{session-id}/.process/test-context-package.json)
279
+ }
280
+ ```
281
+
282
+ 4. **Extract & Load Role Analyses** (from context-package.json)
283
+ ```javascript
284
+ // Extract role analysis paths from context package
285
+ const roleAnalysisPaths = contextPackage.brainstorm_artifacts.role_analyses
286
+ .flatMap(role => role.files.map(f => f.path));
287
+
288
+ // Load each role analysis file
289
+ roleAnalysisPaths.forEach(path => Read(path));
290
+ ```
291
+
292
+ 5. **Load Conflict Resolution** (from conflict-resolution.json, if exists)
293
+ ```javascript
294
+ // Check for new conflict-resolution.json format
295
+ if (contextPackage.conflict_detection?.resolution_file) {
296
+ Read(contextPackage.conflict_detection.resolution_file) // .process/conflict-resolution.json
297
+ }
298
+ // Fallback: legacy brainstorm_artifacts path
299
+ else if (contextPackage.brainstorm_artifacts?.conflict_resolution?.exists) {
300
+ Read(contextPackage.brainstorm_artifacts.conflict_resolution.path)
301
+ }
302
+ ```
303
+
304
+ 6. **Code Analysis with Native Tools** (optional - enhance understanding)
305
+ ```bash
306
+ # Find relevant test files and patterns
307
+ find . -name "*test*" -type f
308
+ rg "describe|it\(|test\(" -g "*.ts"
309
+ ```
310
+
311
+ 7. **MCP External Research** (optional - gather TDD best practices)
312
+ ```javascript
313
+ // Get external TDD examples and patterns
314
+ mcp__exa__get_code_context_exa(
315
+ query="TypeScript TDD best practices Red-Green-Refactor",
316
+ tokensNum="dynamic"
317
+ )
318
+ ```
319
+
320
+ ### Phase 2: Agent Execution (TDD Document Generation)
321
+
322
+ **Purpose**: Generate TDD planning documents (IMPL_PLAN.md, task JSONs, TODO_LIST.md) - planning only, NOT code implementation.
323
+
324
+ **Agent Invocation**:
325
+ ```javascript
326
+ Task(
327
+ subagent_type="action-planning-agent",
328
+ run_in_background=false,
329
+ description="Generate TDD planning documents (IMPL_PLAN.md, task JSONs, TODO_LIST.md)",
330
+ prompt=`
331
+ ## TASK OBJECTIVE
332
+ Generate TDD implementation planning documents (IMPL_PLAN.md, task JSONs, TODO_LIST.md) for workflow session
333
+
334
+ IMPORTANT: This is PLANNING ONLY - you are generating planning documents, NOT implementing code.
335
+
336
+ CRITICAL: Follow the progressive loading strategy (load analysis.md files incrementally due to file size):
337
+ - **Core**: session metadata + context-package.json (always)
338
+ - **Selective**: synthesis_output OR (guidance + relevant role analyses) - NOT all
339
+ - **On-Demand**: conflict resolution (if conflict_risk >= medium), test context
340
+
341
+ ## SESSION PATHS
342
+ Input:
343
+ - Session Metadata: .workflow/active/{session-id}/workflow-session.json
344
+ - Context Package: .workflow/active/{session-id}/.process/context-package.json
345
+ - Test Context: .workflow/active/{session-id}/.process/test-context-package.json
346
+
347
+ Output:
348
+ - Task Dir: .workflow/active/{session-id}/.task/
349
+ - IMPL_PLAN: .workflow/active/{session-id}/IMPL_PLAN.md
350
+ - TODO_LIST: .workflow/active/{session-id}/TODO_LIST.md
351
+
352
+ ## CONTEXT METADATA
353
+ Session ID: {session-id}
354
+ Workflow Type: TDD
355
+ MCP Capabilities: {exa_code, exa_web, code_index}
356
+
357
+ ## USER CONFIGURATION (from Phase 0)
358
+ Execution Method: ${userConfig.executionMethod} // agent|hybrid|cli
359
+ Preferred CLI Tool: ${userConfig.preferredCliTool} // codex|gemini|qwen|auto
360
+ Supplementary Materials: ${userConfig.supplementaryMaterials}
361
+
362
+ ## CLI TOOL SELECTION
363
+ Based on userConfig.executionMethod:
364
+ - "agent": No command field in implementation_approach steps
365
+ - "hybrid": Add command field to complex steps only (Red/Green phases recommended for CLI)
366
+ - "cli": Add command field to ALL Red-Green-Refactor steps
367
+
368
+ CLI Resume Support (MANDATORY for all CLI commands):
369
+ - Use --resume parameter to continue from previous task execution
370
+ - Read previous task's cliExecutionId from session state
371
+ - Format: ccw cli -p "[prompt]" --resume [previousCliId] --tool [tool] --mode write
372
+
373
+ ## EXPLORATION CONTEXT (from context-package.exploration_results)
374
+ - Load exploration_results from context-package.json
375
+ - Use aggregated_insights.critical_files for focus_paths generation
376
+ - Apply aggregated_insights.constraints to acceptance criteria
377
+ - Reference aggregated_insights.all_patterns for implementation approach
378
+ - Use aggregated_insights.all_integration_points for precise modification locations
379
+ - Use conflict_indicators for risk-aware task sequencing
380
+
381
+ ## CONFLICT RESOLUTION CONTEXT (if exists)
382
+ - Check context-package.conflict_detection.resolution_file for conflict-resolution.json path
383
+ - If exists, load .process/conflict-resolution.json:
384
+ - Apply planning_constraints as task constraints (for brainstorm-less workflows)
385
+ - Reference resolved_conflicts for implementation approach alignment
386
+ - Handle custom_conflicts with explicit task notes
387
+
388
+ ## TEST CONTEXT INTEGRATION
389
+ - Load test-context-package.json for existing test patterns and coverage analysis
390
+ - Extract test framework configuration (Jest/Pytest/etc.)
391
+ - Identify existing test conventions and patterns
392
+ - Map coverage gaps to TDD Red phase test targets
393
+
394
+ ## TDD DOCUMENT GENERATION TASK
395
+
396
+ **Agent Configuration Reference**: All TDD task generation rules, quantification requirements, Red-Green-Refactor cycle structure, quality standards, and execution details are defined in action-planning-agent.
397
+
398
+ ### TDD-Specific Requirements Summary
399
+
400
+ #### Task Structure Philosophy
401
+ - **1 feature = 1 task** containing complete TDD cycle internally
402
+ - Each task executes Red-Green-Refactor phases sequentially
403
+ - Task count = Feature count (typically 5 features = 5 tasks)
404
+ - Subtasks only when complexity >2500 lines or >6 files per cycle
405
+ - **Maximum 18 tasks** (hard limit for TDD workflows)
406
+
407
+ #### TDD Cycle Mapping
408
+ - **Simple features**: IMPL-N with internal Red-Green-Refactor phases
409
+ - **Complex features**: IMPL-N (container) + IMPL-N.M (subtasks)
410
+ - Each cycle includes: test_count, test_cases array, implementation_scope, expected_coverage
411
+
412
+ #### Required Outputs Summary
413
+
414
+ ##### 1. TDD Task JSON Files (.task/IMPL-*.json)
415
+ - **Location**: `.workflow/active/{session-id}/.task/`
416
+ - **Schema**: 6-field structure with TDD-specific metadata
417
+ - `id, title, status, context_package_path, meta, context, flow_control`
418
+ - `meta.tdd_workflow`: true (REQUIRED)
419
+ - `meta.max_iterations`: 3 (Green phase test-fix cycle limit)
420
+ - `meta.cli_execution_id`: Unique CLI execution ID (format: `{session_id}-{task_id}`)
421
+ - `meta.cli_execution`: Strategy object (new|resume|fork|merge_fork)
422
+ - `context.tdd_cycles`: Array with quantified test cases and coverage
423
+ - `context.focus_paths`: Absolute or clear relative paths (enhanced with exploration critical_files)
424
+ - `flow_control.implementation_approach`: Exactly 3 steps with `tdd_phase` field
425
+ 1. Red Phase (`tdd_phase: "red"`): Write failing tests
426
+ 2. Green Phase (`tdd_phase: "green"`): Implement to pass tests
427
+ 3. Refactor Phase (`tdd_phase: "refactor"`): Improve code quality
428
+ - `flow_control.pre_analysis`: Include exploration integration_points analysis
429
+ - CLI tool usage based on userConfig (add `command` field per executionMethod)
430
+ - **Details**: See action-planning-agent.md § TDD Task JSON Generation
431
+
432
+ ##### 2. IMPL_PLAN.md (TDD Variant)
433
+ - **Location**: `.workflow/active/{session-id}/IMPL_PLAN.md`
434
+ - **Template**: `~/.claude/workflows/cli-templates/prompts/workflow/impl-plan-template.txt`
435
+ - **TDD-Specific Frontmatter**: workflow_type="tdd", tdd_workflow=true, feature_count, task_breakdown
436
+ - **TDD Implementation Tasks Section**: Feature-by-feature with internal Red-Green-Refactor cycles
437
+ - **Context Analysis**: Artifact references and exploration insights
438
+ - **Details**: See action-planning-agent.md § TDD Implementation Plan Creation
439
+
440
+ ##### 3. TODO_LIST.md
441
+ - **Location**: `.workflow/active/{session-id}/TODO_LIST.md`
442
+ - **Format**: Hierarchical task list with internal TDD phase indicators (Red Green → Refactor)
443
+ - **Status**: (container), [ ] (pending), [x] (completed)
444
+ - **Links**: Task JSON references and summaries
445
+ - **Details**: See action-planning-agent.md § TODO List Generation
446
+
447
+ ### CLI EXECUTION ID REQUIREMENTS (MANDATORY)
448
+
449
+ Each task JSON MUST include:
450
+ - **meta.cli_execution_id**: Unique ID for CLI execution (format: `{session_id}-{task_id}`)
451
+ - **meta.cli_execution**: Strategy object based on depends_on:
452
+ - No deps `{ "strategy": "new" }`
453
+ - 1 dep (single child) → `{ "strategy": "resume", "resume_from": "parent-cli-id" }`
454
+ - 1 dep (multiple children) → `{ "strategy": "fork", "resume_from": "parent-cli-id" }`
455
+ - N deps `{ "strategy": "merge_fork", "resume_from": ["id1", "id2", ...] }`
456
+ - **Type**: `resume_from: string | string[]` (string for resume/fork, array for merge_fork)
457
+
458
+ **CLI Execution Strategy Rules**:
459
+ 1. **new**: Task has no dependencies - starts fresh CLI conversation
460
+ 2. **resume**: Task has 1 parent AND that parent has only this child - continues same conversation
461
+ 3. **fork**: Task has 1 parent BUT parent has multiple children - creates new branch with parent context
462
+ 4. **merge_fork**: Task has multiple parents - merges all parent contexts into new conversation
463
+
464
+ **Execution Command Patterns**:
465
+ - new: `ccw cli -p "[prompt]" --tool [tool] --mode write --id [cli_execution_id]`
466
+ - resume: `ccw cli -p "[prompt]" --resume [resume_from] --tool [tool] --mode write`
467
+ - fork: `ccw cli -p "[prompt]" --resume [resume_from] --id [cli_execution_id] --tool [tool] --mode write`
468
+ - merge_fork: `ccw cli -p "[prompt]" --resume [resume_from.join(',')] --id [cli_execution_id] --tool [tool] --mode write` (resume_from is array)
469
+
470
+ ### Quantification Requirements (MANDATORY)
471
+
472
+ **Core Rules**:
473
+ 1. **Explicit Test Case Counts**: Red phase specifies exact number with enumerated list
474
+ 2. **Quantified Coverage**: Acceptance includes measurable percentage (e.g., ">=85%")
475
+ 3. **Detailed Implementation Scope**: Green phase enumerates files, functions, line counts
476
+ 4. **Enumerated Refactoring Targets**: Refactor phase lists specific improvements with counts
477
+
478
+ **TDD Phase Formats**:
479
+ - **Red Phase**: "Write N test cases: [test1, test2, ...]"
480
+ - **Green Phase**: "Implement N functions in file lines X-Y: [func1() X1-Y1, func2() X2-Y2, ...]"
481
+ - **Refactor Phase**: "Apply N refactorings: [improvement1 (details), improvement2 (details), ...]"
482
+ - **Acceptance**: "All N tests pass with >=X% coverage: verify by [test command]"
483
+
484
+ **Validation Checklist**:
485
+ - [ ] Every Red phase specifies exact test case count with enumerated list
486
+ - [ ] Every Green phase enumerates files, functions, and estimated line counts
487
+ - [ ] Every Refactor phase lists specific improvements with counts
488
+ - [ ] Every acceptance criterion includes measurable coverage percentage
489
+ - [ ] tdd_cycles array contains test_count and test_cases for each cycle
490
+ - [ ] No vague language ("comprehensive", "complete", "thorough")
491
+ - [ ] cli_execution_id and cli_execution strategy assigned to each task
492
+
493
+ ### Agent Execution Summary
494
+
495
+ **Key Steps** (Detailed instructions in action-planning-agent.md):
496
+ 1. Load task JSON template from provided path
497
+ 2. Extract and decompose features with TDD cycles
498
+ 3. Generate TDD task JSON files enforcing quantification requirements
499
+ 4. Create IMPL_PLAN.md using TDD template variant
500
+ 5. Generate TODO_LIST.md with TDD phase indicators
501
+ 6. Update session state with TDD metadata
502
+
503
+ **Quality Gates** (Full checklist in action-planning-agent.md):
504
+ - Quantification requirements enforced (explicit counts, measurable acceptance, exact targets)
505
+ - Task count ≤18 (hard limit)
506
+ - Each task has meta.tdd_workflow: true
507
+ - Each task has exactly 3 implementation steps with tdd_phase field ("red", "green", "refactor")
508
+ - Each task has meta.cli_execution_id and meta.cli_execution strategy
509
+ - Green phase includes test-fix cycle logic with max_iterations
510
+ - focus_paths are absolute or clear relative paths (from exploration critical_files)
511
+ - ✓ Artifact references mapped correctly from context package
512
+ - ✓ Exploration context integrated (critical_files, constraints, patterns, integration_points)
513
+ - ✓ Conflict resolution context applied (if conflict_risk >= medium)
514
+ - Test context integrated (existing test patterns and coverage analysis)
515
+ - Documents follow TDD template structure
516
+ - CLI tool selection based on userConfig.executionMethod
517
+
518
+ ## SUCCESS CRITERIA
519
+ - All planning documents generated successfully:
520
+ - Task JSONs valid and saved to .task/ directory with cli_execution_id
521
+ - IMPL_PLAN.md created with complete TDD structure
522
+ - TODO_LIST.md generated matching task JSONs
523
+ - CLI execution strategies assigned based on task dependencies
524
+ - Return completion status with document count and task breakdown summary
525
+
526
+ ## OUTPUT SUMMARY
527
+ Generate all three documents and report:
528
+ - TDD task JSON files created: N files (IMPL-*.json) with cli_execution_id assigned
529
+ - TDD cycles configured: N cycles with quantified test cases
530
+ - CLI execution strategies: new/resume/fork/merge_fork assigned per dependency graph
531
+ - Artifacts integrated: synthesis-spec/guidance-specification, relevant role analyses
532
+ - Exploration context: critical_files, constraints, patterns, integration_points
533
+ - Test context integrated: existing patterns and coverage
534
+ - Conflict resolution: applied (if conflict_risk >= medium)
535
+ - Session ready for TDD execution: /workflow:execute
536
+ `
537
+ )
538
+ ```
539
+
540
+ ### Agent Context Passing
541
+
542
+ **Context Delegation Model**: Command provides paths and metadata, agent loads context autonomously using progressive loading strategy.
543
+
544
+ **Command Provides** (in agent prompt):
545
+ ```javascript
546
+ // Command assembles these simple values and paths for agent
547
+ const commandProvides = {
548
+ // Session paths
549
+ session_metadata_path: ".workflow/active/WFS-{id}/workflow-session.json",
550
+ context_package_path: ".workflow/active/WFS-{id}/.process/context-package.json",
551
+ test_context_package_path: ".workflow/active/WFS-{id}/.process/test-context-package.json",
552
+ output_task_dir: ".workflow/active/WFS-{id}/.task/",
553
+ output_impl_plan: ".workflow/active/WFS-{id}/IMPL_PLAN.md",
554
+ output_todo_list: ".workflow/active/WFS-{id}/TODO_LIST.md",
555
+
556
+ // Simple metadata
557
+ session_id: "WFS-{id}",
558
+ workflow_type: "tdd",
559
+ mcp_capabilities: { exa_code: true, exa_web: true, code_index: true },
560
+
561
+ // User configuration from Phase 0
562
+ user_config: {
563
+ supplementaryMaterials: { type: "...", content: [...] },
564
+ executionMethod: "agent|hybrid|cli",
565
+ preferredCliTool: "codex|gemini|qwen|auto",
566
+ enableResume: true
567
+ }
568
+ }
569
+ ```
570
+
571
+ **Agent Loads Autonomously** (progressive loading):
572
+ ```javascript
573
+ // Agent executes progressive loading based on memory state
574
+ const agentLoads = {
575
+ // Core (ALWAYS load if not in memory)
576
+ session_metadata: loadIfNotInMemory(session_metadata_path),
577
+ context_package: loadIfNotInMemory(context_package_path),
578
+
579
+ // Selective (based on progressive strategy)
580
+ // Priority: synthesis_output > guidance + relevant_role_analyses
581
+ brainstorm_content: loadSelectiveBrainstormArtifacts(context_package),
582
+
583
+ // On-Demand (load if exists and relevant)
584
+ test_context: loadIfExists(test_context_package_path),
585
+ conflict_resolution: loadConflictResolution(context_package),
586
+
587
+ // Optional (if MCP available)
588
+ exploration_results: extractExplorationResults(context_package),
589
+ external_research: executeMcpResearch() // If needed
590
+ }
591
+ ```
592
+
593
+ **Progressive Loading Implementation** (agent responsibility):
594
+ 1. **Check memory first** - skip if already loaded
595
+ 2. **Load core files** - session metadata + context-package.json
596
+ 3. **Smart selective loading** - synthesis_output OR (guidance + task-relevant role analyses)
597
+ 4. **On-demand loading** - test context, conflict resolution (if conflict_risk >= medium)
598
+ 5. **Extract references** - exploration results, artifact paths from context package
599
+
600
+ ## TDD Task Structure Reference
601
+
602
+ This section provides quick reference for TDD task JSON structure. For complete implementation details, see the agent invocation prompt in Phase 2 above.
603
+
604
+ **Quick Reference**:
605
+ - Each TDD task contains complete Red-Green-Refactor cycle
606
+ - Task ID format: `IMPL-N` (simple) or `IMPL-N.M` (complex subtasks)
607
+ - Required metadata:
608
+ - `meta.tdd_workflow: true`
609
+ - `meta.max_iterations: 3`
610
+ - `meta.cli_execution_id: "{session_id}-{task_id}"`
611
+ - `meta.cli_execution: { "strategy": "new|resume|fork|merge_fork", ... }`
612
+ - Context: `tdd_cycles` array with quantified test cases and coverage:
613
+ ```javascript
614
+ tdd_cycles: [
615
+ {
616
+ test_count: 5, // Number of test cases to write
617
+ test_cases: ["case1", "case2"], // Enumerated test scenarios
618
+ implementation_scope: "...", // Files and functions to implement
619
+ expected_coverage: ">=85%" // Coverage target
620
+ }
621
+ ]
622
+ ```
623
+ - Context: `focus_paths` use absolute or clear relative paths
624
+ - Flow control: Exactly 3 steps with `tdd_phase` field ("red", "green", "refactor")
625
+ - Flow control: `pre_analysis` includes exploration integration_points analysis
626
+ - Command field: Added per `userConfig.executionMethod` (agent/hybrid/cli)
627
+ - See Phase 2 agent prompt for full schema and requirements
628
+
629
+ ## Output Files Structure
630
+ ```
631
+ .workflow/active/{session-id}/
632
+ ├── IMPL_PLAN.md # Unified plan with TDD Implementation Tasks section
633
+ ├── TODO_LIST.md # Progress tracking with internal TDD phase indicators
634
+ ├── .task/
635
+ │ ├── IMPL-1.json # Complete TDD task (Red-Green-Refactor internally)
636
+ │ ├── IMPL-2.json # Complete TDD task
637
+ │ ├── IMPL-3.json # Complex feature container (if needed)
638
+ │ ├── IMPL-3.1.json # Complex feature subtask (if needed)
639
+ │ ├── IMPL-3.2.json # Complex feature subtask (if needed)
640
+ │ └── ...
641
+ └── .process/
642
+ ├── conflict-resolution.json # Conflict resolution results (if conflict_risk ≥ medium)
643
+ ├── test-context-package.json # Test coverage analysis
644
+ ├── context-package.json # Input from context-gather
645
+ ├── context_package_path # Path to smart context package
646
+ └── green-fix-iteration-*.md # Fix logs from Green phase test-fix cycles
647
+ ```
648
+
649
+ **File Count**:
650
+ - **Old approach**: 5 features = 15 task JSON files (TEST/IMPL/REFACTOR × 5)
651
+ - **New approach**: 5 features = 5 task JSON files (IMPL-N × 5)
652
+ - **Complex feature**: 1 feature = 1 container + M subtasks (IMPL-N + IMPL-N.M)
653
+
654
+ ## Validation Rules
655
+
656
+ ### Task Completeness
657
+ - Every IMPL-N must contain complete TDD workflow in `flow_control.implementation_approach`
658
+ - Each task must have 3 steps with `tdd_phase`: "red", "green", "refactor"
659
+ - Every task must have `meta.tdd_workflow: true`
660
+
661
+ ### Dependency Enforcement
662
+ - Sequential features: IMPL-N depends_on ["IMPL-(N-1)"] if needed
663
+ - Complex feature subtasks: IMPL-N.M depends_on ["IMPL-N.(M-1)"] or parent dependencies
664
+ - No circular dependencies allowed
665
+
666
+ ### Task Limits
667
+ - Maximum 18 total tasks (simple + subtasks) - hard limit for TDD workflows
668
+ - Flat hierarchy (≤5 tasks) or two-level (6-18 tasks with containers)
669
+ - Re-scope requirements if >18 tasks needed
670
+
671
+ ### TDD Workflow Validation
672
+ - `meta.tdd_workflow` must be true
673
+ - `flow_control.implementation_approach` must have exactly 3 steps
674
+ - Each step must have `tdd_phase` field ("red", "green", or "refactor")
675
+ - Green phase step must include test-fix cycle logic
676
+ - `meta.max_iterations` must be present (default: 3)
677
+
678
+ ## Error Handling
679
+
680
+ ### Input Validation Errors
681
+ | Error | Cause | Resolution |
682
+ |-------|-------|------------|
683
+ | Session not found | Invalid session ID | Verify session exists |
684
+ | Context missing | Incomplete planning | Run context-gather first |
685
+
686
+ ### TDD Generation Errors
687
+ | Error | Cause | Resolution |
688
+ |-------|-------|------------|
689
+ | Task count exceeds 18 | Too many features or subtasks | Re-scope requirements or merge features into multiple TDD sessions |
690
+ | Missing test framework | No test config | Configure testing first |
691
+ | Invalid TDD workflow | Missing tdd_phase or incomplete flow_control | Fix TDD structure in ANALYSIS_RESULTS.md |
692
+ | Missing tdd_workflow flag | Task doesn't have meta.tdd_workflow: true | Add TDD workflow metadata |
693
+
694
+ ## Integration & Usage
695
+
696
+ **Command Chain**:
697
+ - Called by: `/workflow:tdd-plan` (Phase 4)
698
+ - Invokes: `action-planning-agent` for autonomous task generation
699
+ - Followed by: `/workflow:execute`, `/workflow:tdd-verify`
700
+
701
+ **Basic Usage**:
702
+ ```bash
703
+ # Standard execution
704
+ /workflow:tools:task-generate-tdd --session WFS-auth
705
+
706
+ # With semantic CLI request (include in task description)
707
+ # e.g., "Generate TDD tasks for auth module, use Codex for implementation"
708
+ ```
709
+
710
+ **CLI Tool Selection**: Determined semantically from user's task description. Include "use Codex/Gemini/Qwen" in your request for CLI execution.
711
+
712
+ **Output**:
713
+ - TDD task JSON files in `.task/` directory (IMPL-N.json format)
714
+ - IMPL_PLAN.md with TDD Implementation Tasks section
715
+ - TODO_LIST.md with internal TDD phase indicators
716
+ - Session state updated with task count and TDD metadata
717
+ - MCP enhancements integrated (if available)
718
+
719
+ ## Test Coverage Analysis Integration
720
+
721
+ The TDD workflow includes test coverage analysis (via `/workflow:tools:test-context-gather`) to:
722
+ - Detect existing test patterns and conventions
723
+ - Identify current test coverage gaps
724
+ - Discover test framework and configuration
725
+ - Enable integration with existing tests
726
+
727
+ This makes TDD workflow context-aware instead of assuming greenfield scenarios.
728
+
729
+ ## Iterative Green Phase with Test-Fix Cycle
730
+
731
+ IMPL (Green phase) tasks include automatic test-fix cycle:
732
+
733
+ **Process Flow**:
734
+ 1. **Initial Implementation**: Write minimal code to pass tests
735
+ 2. **Test Execution**: Run test suite
736
+ 3. **Success Path**: Tests pass → Complete task
737
+ 4. **Failure Path**: Tests fail → Enter iterative fix cycle:
738
+ - **Gemini Diagnosis**: Analyze failures with bug-fix template
739
+ - **Fix Application**: Agent (default) or CLI (if `command` field present)
740
+ - **Retest**: Verify fix resolves failures
741
+ - **Repeat**: Up to max_iterations (default: 3)
742
+ 5. **Safety Net**: Auto-revert all changes if max iterations reached
743
+
744
+
745
+
746
+ ## Configuration Options
747
+ - **meta.max_iterations**: Number of fix attempts in Green phase (default: 3)
748
+ - **CLI tool usage**: Determined semantically from user's task description via `command` field in implementation_approach
749
+