claude-code-workflow 6.3.43 → 6.3.46

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 (78) hide show
  1. package/.claude/agents/tdd-developer.md +530 -0
  2. package/.claude/commands/ccw-coordinator.md +1042 -0
  3. package/.claude/commands/ccw.md +486 -0
  4. package/.claude/commands/issue/discover-by-prompt.md +5 -1
  5. package/.claude/commands/issue/discover.md +472 -468
  6. package/.claude/commands/issue/execute.md +580 -581
  7. package/.claude/commands/issue/new.md +417 -413
  8. package/.claude/commands/issue/plan.md +5 -1
  9. package/.claude/commands/issue/queue.md +445 -441
  10. package/.claude/commands/task/breakdown.md +207 -203
  11. package/.claude/commands/task/replan.md +440 -436
  12. package/.claude/commands/workflow/action-plan-verify.md +485 -447
  13. package/.claude/commands/workflow/brainstorm/artifacts.md +457 -453
  14. package/.claude/commands/workflow/brainstorm/auto-parallel.md +5 -1
  15. package/.claude/commands/workflow/brainstorm/synthesis.md +402 -398
  16. package/.claude/commands/workflow/clean.md +67 -35
  17. package/.claude/commands/workflow/debug-with-file.md +670 -666
  18. package/.claude/commands/workflow/debug.md +331 -327
  19. package/.claude/commands/workflow/develop-with-file.md +5 -1
  20. package/.claude/commands/workflow/execute.md +546 -498
  21. package/.claude/commands/workflow/lite-execute.md +44 -26
  22. package/.claude/commands/workflow/lite-fix.md +780 -730
  23. package/.claude/commands/workflow/lite-lite-lite.md +5 -1
  24. package/.claude/commands/workflow/lite-plan.md +87 -39
  25. package/.claude/commands/workflow/multi-cli-plan.md +572 -568
  26. package/.claude/commands/workflow/plan-verify.md +527 -0
  27. package/.claude/commands/workflow/plan.md +555 -551
  28. package/.claude/commands/workflow/replan.md +572 -515
  29. package/.claude/commands/workflow/review-fix.md +608 -610
  30. package/.claude/commands/workflow/session/complete.md +37 -14
  31. package/.claude/commands/workflow/session/solidify.md +303 -299
  32. package/.claude/commands/workflow/tdd-plan.md +630 -597
  33. package/.claude/commands/workflow/tdd-verify.md +391 -206
  34. package/.claude/commands/workflow/tools/conflict-resolution.md +24 -12
  35. package/.claude/commands/workflow/tools/task-generate-agent.md +583 -563
  36. package/.claude/commands/workflow/tools/task-generate-tdd.md +749 -517
  37. package/.claude/commands/workflow/ui-design/animation-extract.md +1154 -1150
  38. package/.claude/commands/workflow/ui-design/layout-extract.md +792 -788
  39. package/.claude/commands/workflow/ui-design/style-extract.md +777 -773
  40. package/.claude/skills/ccw-help/command.json +5 -5
  41. package/.claude/skills/ccw-help/scripts/analyze_commands.py +337 -337
  42. package/.claude/workflows/cli-templates/prompts/workflow-impl-plan-template.txt +1 -1
  43. package/ccw/dist/commands/issue.d.ts +4 -0
  44. package/ccw/dist/commands/issue.d.ts.map +1 -1
  45. package/ccw/dist/commands/issue.js +73 -6
  46. package/ccw/dist/commands/issue.js.map +1 -1
  47. package/ccw/dist/core/routes/cli-routes.d.ts.map +1 -1
  48. package/ccw/dist/core/routes/cli-routes.js +32 -28
  49. package/ccw/dist/core/routes/cli-routes.js.map +1 -1
  50. package/ccw/dist/tools/claude-cli-tools.d.ts +10 -0
  51. package/ccw/dist/tools/claude-cli-tools.d.ts.map +1 -1
  52. package/ccw/dist/tools/claude-cli-tools.js +45 -0
  53. package/ccw/dist/tools/claude-cli-tools.js.map +1 -1
  54. package/ccw/dist/tools/codex-lens.d.ts.map +1 -1
  55. package/ccw/dist/tools/codex-lens.js +38 -11
  56. package/ccw/dist/tools/codex-lens.js.map +1 -1
  57. package/ccw/dist/tools/command-registry.d.ts +77 -0
  58. package/ccw/dist/tools/command-registry.d.ts.map +1 -0
  59. package/ccw/dist/tools/command-registry.js +265 -0
  60. package/ccw/dist/tools/command-registry.js.map +1 -0
  61. package/ccw/dist/tools/command-registry.test.d.ts +14 -0
  62. package/ccw/dist/tools/command-registry.test.d.ts.map +1 -0
  63. package/ccw/dist/tools/command-registry.test.js.map +1 -0
  64. package/ccw/dist/tools/index.d.ts +2 -0
  65. package/ccw/dist/tools/index.d.ts.map +1 -1
  66. package/ccw/dist/tools/index.js +2 -0
  67. package/ccw/dist/tools/index.js.map +1 -1
  68. package/ccw/src/commands/issue.ts +84 -6
  69. package/ccw/src/core/routes/cli-routes.ts +30 -25
  70. package/ccw/src/templates/dashboard-js/views/help.js +1 -1
  71. package/ccw/src/tools/claude-cli-tools.ts +50 -0
  72. package/ccw/src/tools/codex-lens.ts +40 -11
  73. package/ccw/src/tools/command-registry.test.ts +669 -0
  74. package/ccw/src/tools/command-registry.ts +308 -0
  75. package/ccw/src/tools/index.ts +4 -0
  76. package/package.json +1 -1
  77. package/.claude/skills/ccw/SKILL.md +0 -522
  78. package/.claude/skills/ccw/command.json +0 -641
@@ -1,498 +1,546 @@
1
- ---
2
- name: execute
3
- description: Coordinate agent execution for workflow tasks with automatic session discovery, parallel task processing, and status tracking
4
- argument-hint: "[--resume-session=\"session-id\"]"
5
- ---
6
-
7
- # Workflow Execute Command
8
-
9
- ## Overview
10
- Orchestrates autonomous workflow execution through systematic task discovery, agent coordination, and progress tracking. **Executes entire workflow without user interruption** (except initial session selection if multiple active sessions exist), providing complete context to agents and ensuring proper flow control execution with comprehensive TodoWrite tracking.
11
-
12
- **Resume Mode**: When called with `--resume-session` flag, skips discovery phase and directly enters TodoWrite generation and agent execution for the specified session.
13
-
14
- ## Performance Optimization Strategy
15
-
16
- **Lazy Loading**: Task JSONs read **on-demand** during execution, not upfront. TODO_LIST.md + IMPL_PLAN.md provide metadata for planning.
17
-
18
- **Loading Strategy**:
19
- - **TODO_LIST.md**: Read in Phase 3 (task metadata, status, dependencies for TodoWrite generation)
20
- - **IMPL_PLAN.md**: Check existence in Phase 2 (normal mode), parse execution strategy in Phase 4A
21
- - **Task JSONs**: Lazy loading - read only when task is about to execute (Phase 4B)
22
-
23
- ## Core Rules
24
- **Complete entire workflow autonomously without user interruption, using TodoWrite for comprehensive progress tracking.**
25
- **Execute all discovered pending tasks until workflow completion or blocking dependency.**
26
- **User-choice completion: When all tasks finished, ask user to choose review or complete.**
27
- **ONE AGENT = ONE TASK JSON: Each agent instance executes exactly one task JSON file - never batch multiple tasks into single agent execution.**
28
-
29
- ## Core Responsibilities
30
- - **Session Discovery**: Identify and select active workflow sessions
31
- - **Execution Strategy Parsing**: Extract execution model from IMPL_PLAN.md
32
- - **TodoWrite Progress Tracking**: Maintain real-time execution status throughout entire workflow
33
- - **Agent Orchestration**: Coordinate specialized agents with complete context
34
- - **Status Synchronization**: Update task JSON files and workflow state
35
- - **Autonomous Completion**: Continue execution until all tasks complete or reach blocking state
36
- - **Session User-Choice Completion**: Ask user to choose review or complete when all tasks finished
37
-
38
- ## Execution Philosophy
39
- - **Progress tracking**: Continuous TodoWrite updates throughout entire workflow execution
40
- - **Autonomous completion**: Execute all tasks without user interruption until workflow complete
41
-
42
- ## Execution Process
43
-
44
- ```
45
- Normal Mode:
46
- Phase 1: Discovery
47
- ├─ Count active sessions
48
- └─ Decision:
49
- ├─ count=0 ERROR: No active sessions
50
- ├─ count=1 Auto-select session Phase 2
51
- └─ count>1 AskUserQuestion (max 4 options) Phase 2
52
-
53
- Phase 2: Planning Document Validation
54
- ├─ Check IMPL_PLAN.md exists
55
- ├─ Check TODO_LIST.md exists
56
- └─ Validate .task/ contains IMPL-*.json files
57
-
58
- Phase 3: TodoWrite Generation
59
- ├─ Update session status to "active" (Step 0)
60
- ├─ Parse TODO_LIST.md for task statuses
61
- ├─ Generate TodoWrite for entire workflow
62
- └─ Prepare session context paths
63
-
64
- Phase 4: Execution Strategy & Task Execution
65
- ├─ Step 4A: Parse execution strategy from IMPL_PLAN.md
66
- └─ Step 4B: Execute tasks with lazy loading
67
- └─ Loop:
68
- ├─ Get next in_progress task from TodoWrite
69
- ├─ Lazy load task JSON
70
- ├─ Launch agent with task context
71
- ├─ Mark task completed (update IMPL-*.json status)
72
- │ # Quick fix: Update task status for ccw dashboard
73
- │ # TS=$(date -Iseconds) && jq --arg ts "$TS" '.status="completed" | .status_history=(.status_history // [])+[{"from":"in_progress","to":"completed","changed_at":$ts}]' IMPL-X.json > tmp.json && mv tmp.json IMPL-X.json
74
- └─ Advance to next task
75
-
76
- Phase 5: Completion
77
- ├─ Update task statuses in JSON files
78
- ├─ Generate summaries
79
- └─ AskUserQuestion: Choose next step
80
- ├─ "Enter Review" /workflow:review
81
- └─ "Complete Session" → /workflow:session:complete
82
-
83
- Resume Mode (--resume-session):
84
- ├─ Skip Phase 1 & Phase 2
85
- └─ Entry Point: Phase 3 (TodoWrite Generation)
86
- ├─ Update session status to "active" (if not already)
87
- └─ Continue: Phase 4 → Phase 5
88
- ```
89
-
90
- ## Execution Lifecycle
91
-
92
- ### Phase 1: Discovery
93
- **Applies to**: Normal mode only (skipped in resume mode)
94
-
95
- **Purpose**: Find and select active workflow session with user confirmation when multiple sessions exist
96
-
97
- **Process**:
98
-
99
- #### Step 1.1: Count Active Sessions
100
- ```bash
101
- bash(find .workflow/active/ -name "WFS-*" -type d 2>/dev/null | wc -l)
102
- ```
103
-
104
- #### Step 1.2: Handle Session Selection
105
-
106
- **Case A: No Sessions** (count = 0)
107
- ```
108
- ERROR: No active workflow sessions found
109
- Run /workflow:plan "task description" to create a session
110
- ```
111
-
112
- **Case B: Single Session** (count = 1)
113
- ```bash
114
- bash(find .workflow/active/ -name "WFS-*" -type d 2>/dev/null | head -1 | xargs basename)
115
- ```
116
- Auto-select and continue to Phase 2.
117
-
118
- **Case C: Multiple Sessions** (count > 1)
119
-
120
- List sessions with metadata and prompt user selection:
121
- ```bash
122
- bash(for dir in .workflow/active/WFS-*/; do [ -d "$dir" ] || continue; session=$(basename "$dir"); project=$(jq -r '.project // "Unknown"' "${dir}workflow-session.json" 2>/dev/null || echo "Unknown"); total=$(grep -c '^\- \[' "${dir}TODO_LIST.md" 2>/dev/null || echo 0); completed=$(grep -c '^\- \[x\]' "${dir}TODO_LIST.md" 2>/dev/null || echo 0); if [ "$total" -gt 0 ]; then progress=$((completed * 100 / total)); else progress=0; fi; echo "$session | $project | $completed/$total tasks ($progress%)"; done)
123
- ```
124
-
125
- Use AskUserQuestion to present formatted options (max 4 options shown):
126
- ```javascript
127
- // If more than 4 sessions, show most recent 4 with "Other" option for manual input
128
- const sessions = getActiveSessions() // sorted by last modified
129
- const displaySessions = sessions.slice(0, 4)
130
-
131
- AskUserQuestion({
132
- questions: [{
133
- question: "Multiple active sessions detected. Select one:",
134
- header: "Session",
135
- multiSelect: false,
136
- options: displaySessions.map(s => ({
137
- label: s.id,
138
- description: `${s.project} | ${s.progress}`
139
- }))
140
- // Note: User can select "Other" to manually enter session ID
141
- }]
142
- })
143
- ```
144
-
145
- **Input Validation**:
146
- - If user selects from options: Use selected session ID
147
- - If user selects "Other" and provides input: Validate session exists
148
- - If validation fails: Show error and re-prompt or suggest available sessions
149
-
150
- Parse user input (supports: number "1", full ID "WFS-auth-system", or partial "auth"), validate selection, and continue to Phase 2.
151
-
152
- #### Step 1.3: Load Session Metadata
153
- ```bash
154
- bash(cat .workflow/active/${sessionId}/workflow-session.json)
155
- ```
156
-
157
- **Output**: Store session metadata in memory
158
- **DO NOT read task JSONs yet** - defer until execution phase (lazy loading)
159
-
160
- **Resume Mode**: This entire phase is skipped when `--resume-session="session-id"` flag is provided.
161
-
162
- ### Phase 2: Planning Document Validation
163
- **Applies to**: Normal mode only (skipped in resume mode)
164
-
165
- **Purpose**: Validate planning artifacts exist before execution
166
-
167
- **Process**:
168
- 1. **Check IMPL_PLAN.md**: Verify file exists (defer detailed parsing to Phase 4A)
169
- 2. **Check TODO_LIST.md**: Verify file exists (defer reading to Phase 3)
170
- 3. **Validate Task Directory**: Ensure `.task/` contains at least one IMPL-*.json file
171
-
172
- **Key Optimization**: Only existence checks here. Actual file reading happens in later phases.
173
-
174
- **Resume Mode**: This phase is skipped when `--resume-session` flag is provided. Resume mode entry point is Phase 3.
175
-
176
- ### Phase 3: TodoWrite Generation
177
- **Applies to**: Both normal and resume modes (resume mode entry point)
178
-
179
- **Step 0: Update Session Status to Active**
180
- Before generating TodoWrite, update session status from "planning" to "active":
181
- ```bash
182
- # Update session status (idempotent - safe to run if already active)
183
- jq '.status = "active" | .execution_started_at = (.execution_started_at // now | todate)' \
184
- .workflow/active/${sessionId}/workflow-session.json > tmp.json && \
185
- mv tmp.json .workflow/active/${sessionId}/workflow-session.json
186
- ```
187
- This ensures the dashboard shows the session as "ACTIVE" during execution.
188
-
189
- **Process**:
190
- 1. **Create TodoWrite List**: Generate task list from TODO_LIST.md (not from task JSONs)
191
- - Parse TODO_LIST.md to extract all tasks with current statuses
192
- - Identify first pending task with met dependencies
193
- - Generate comprehensive TodoWrite covering entire workflow
194
- 2. **Prepare Session Context**: Inject workflow paths for agent use (using provided session-id)
195
- 3. **Validate Prerequisites**: Ensure IMPL_PLAN.md and TODO_LIST.md exist and are valid
196
-
197
- **Resume Mode Behavior**:
198
- - Load existing TODO_LIST.md directly from `.workflow/active/{session-id}/`
199
- - Extract current progress from TODO_LIST.md
200
- - Generate TodoWrite from TODO_LIST.md state
201
- - Proceed immediately to agent execution (Phase 4)
202
-
203
- ### Phase 4: Execution Strategy Selection & Task Execution
204
- **Applies to**: Both normal and resume modes
205
-
206
- **Step 4A: Parse Execution Strategy from IMPL_PLAN.md**
207
-
208
- Read IMPL_PLAN.md Section 4 to extract:
209
- - **Execution Model**: Sequential | Parallel | Phased | TDD Cycles
210
- - **Parallelization Opportunities**: Which tasks can run in parallel
211
- - **Serialization Requirements**: Which tasks must run sequentially
212
- - **Critical Path**: Priority execution order
213
-
214
- If IMPL_PLAN.md lacks execution strategy, use intelligent fallback (analyze task structure).
215
-
216
- **Step 4B: Execute Tasks with Lazy Loading**
217
-
218
- **Key Optimization**: Read task JSON **only when needed** for execution
219
-
220
- **Execution Loop Pattern**:
221
- ```
222
- while (TODO_LIST.md has pending tasks) {
223
- next_task_id = getTodoWriteInProgressTask()
224
- task_json = Read(.workflow/active/{session}/.task/{next_task_id}.json) // Lazy load
225
- executeTaskWithAgent(task_json)
226
- updateTodoListMarkCompleted(next_task_id)
227
- advanceTodoWriteToNextTask()
228
- }
229
- ```
230
-
231
- **Execution Process per Task**:
232
- 1. **Identify Next Task**: From TodoWrite, get the next `in_progress` task ID
233
- 2. **Load Task JSON on Demand**: Read `.task/{task-id}.json` for current task ONLY
234
- 3. **Validate Task Structure**: Ensure all 5 required fields exist (id, title, status, meta, context, flow_control)
235
- 4. **Launch Agent**: Invoke specialized agent with complete context including flow control steps
236
- 5. **Monitor Progress**: Track agent execution and handle errors without user interruption
237
- 6. **Collect Results**: Gather implementation results and outputs
238
- 7. **Continue Workflow**: Identify next pending task from TODO_LIST.md and repeat
239
-
240
- **Note**: TODO_LIST.md updates are handled by agents (e.g., code-developer.md), not by the orchestrator.
241
-
242
-
243
- ### Phase 5: Completion
244
- **Applies to**: Both normal and resume modes
245
-
246
- **Process**:
247
- 1. **Update Task Status**: Mark completed tasks in JSON files
248
- 2. **Generate Summary**: Create task summary in `.summaries/`
249
- 3. **Update TodoWrite**: Mark current task complete, advance to next
250
- 4. **Synchronize State**: Update session state and workflow status
251
- 5. **Check Workflow Complete**: Verify all tasks are completed
252
- 6. **User Choice**: When all tasks finished, ask user to choose next step:
253
-
254
- ```javascript
255
- AskUserQuestion({
256
- questions: [{
257
- question: "All tasks completed. What would you like to do next?",
258
- header: "Next Step",
259
- multiSelect: false,
260
- options: [
261
- {
262
- label: "Enter Review",
263
- description: "Run specialized review (security/architecture/quality/action-items)"
264
- },
265
- {
266
- label: "Complete Session",
267
- description: "Archive session and update manifest"
268
- }
269
- ]
270
- }]
271
- })
272
- ```
273
-
274
- **Based on user selection**:
275
- - **"Enter Review"**: Execute `/workflow:review`
276
- - **"Complete Session"**: Execute `/workflow:session:complete`
277
-
278
- ### Post-Completion Expansion
279
-
280
- 完成后询问用户是否扩展为issue(test/enhance/refactor/doc),选中项调用 `/issue:new "{summary} - {dimension}"`
281
-
282
- ## Execution Strategy (IMPL_PLAN-Driven)
283
-
284
- ### Strategy Priority
285
-
286
- **IMPL_PLAN-Driven Execution (Recommended)**:
287
- 1. **Read IMPL_PLAN.md execution strategy** (Section 4: Implementation Strategy)
288
- 2. **Follow explicit guidance**:
289
- - Execution Model (Sequential/Parallel/Phased/TDD)
290
- - Parallelization Opportunities (which tasks can run in parallel)
291
- - Serialization Requirements (which tasks must run sequentially)
292
- - Critical Path (priority execution order)
293
- 3. **Use TODO_LIST.md for status tracking** only
294
- 4. **IMPL_PLAN decides "HOW"**, execute.md implements it
295
-
296
- **Intelligent Fallback (When IMPL_PLAN lacks execution details)**:
297
- 1. **Analyze task structure**:
298
- - Check `meta.execution_group` in task JSONs
299
- - Analyze `depends_on` relationships
300
- - Understand task complexity and risk
301
- 2. **Apply smart defaults**:
302
- - No dependencies + same execution_group → Parallel
303
- - Has dependencies → Sequential (wait for deps)
304
- - Critical/high-risk tasks Sequential
305
- 3. **Conservative approach**: When uncertain, prefer sequential execution
306
-
307
- ### Execution Models
308
-
309
- #### 1. Sequential Execution
310
- **When**: IMPL_PLAN specifies "Sequential" OR no clear parallelization guidance
311
- **Pattern**: Execute tasks one by one in TODO_LIST order
312
- **TodoWrite**: ONE task marked as `in_progress` at a time
313
-
314
- #### 2. Parallel Execution
315
- **When**: IMPL_PLAN specifies "Parallel" with clear parallelization opportunities
316
- **Pattern**: Execute independent task groups concurrently by launching multiple agent instances
317
- **TodoWrite**: MULTIPLE tasks (in same batch) marked as `in_progress` simultaneously
318
- **Agent Instantiation**: Launch one agent instance per task (respects ONE AGENT = ONE TASK JSON rule)
319
-
320
- #### 3. Phased Execution
321
- **When**: IMPL_PLAN specifies "Phased" with phase breakdown
322
- **Pattern**: Execute tasks in phases, respect phase boundaries
323
- **TodoWrite**: Within each phase, follow Sequential or Parallel rules
324
-
325
- #### 4. Intelligent Fallback
326
- **When**: IMPL_PLAN lacks execution strategy details
327
- **Pattern**: Analyze task structure and apply smart defaults
328
- **TodoWrite**: Follow Sequential or Parallel rules based on analysis
329
-
330
- ### Task Status Logic
331
- ```
332
- pending + dependencies_met → executable
333
- completed → skip
334
- blocked skip until dependencies clear
335
- ```
336
-
337
- ## TodoWrite Coordination
338
-
339
- ### TodoWrite Rules (Unified)
340
-
341
- **Rule 1: Initial Creation**
342
- - **Normal Mode**: Generate TodoWrite from discovered pending tasks for entire workflow
343
- - **Resume Mode**: Generate from existing session state and current progress
344
-
345
- **Rule 2: In-Progress Task Count (Execution-Model-Dependent)**
346
- - **Sequential execution**: Mark ONLY ONE task as `in_progress` at a time
347
- - **Parallel batch execution**: Mark ALL tasks in current batch as `in_progress` simultaneously
348
- - **Execution group indicator**: Show `[execution_group: group-id]` for parallel tasks
349
-
350
- **Rule 3: Status Updates**
351
- - **Immediate Updates**: Update status after each task/batch completion without user interruption
352
- - **Status Synchronization**: Sync with JSON task files after updates
353
- - **Continuous Tracking**: Maintain TodoWrite throughout entire workflow execution until completion
354
-
355
- **Rule 4: Workflow Completion Check**
356
- - When all tasks marked `completed`, prompt user to choose review or complete session
357
-
358
- ### TodoWrite Tool Usage
359
-
360
- **Example 1: Sequential Execution**
361
- ```javascript
362
- TodoWrite({
363
- todos: [
364
- {
365
- content: "Execute IMPL-1.1: Design auth schema [code-developer] [FLOW_CONTROL]",
366
- status: "in_progress", // ONE task in progress
367
- activeForm: "Executing IMPL-1.1: Design auth schema"
368
- },
369
- {
370
- content: "Execute IMPL-1.2: Implement auth logic [code-developer] [FLOW_CONTROL]",
371
- status: "pending",
372
- activeForm: "Executing IMPL-1.2: Implement auth logic"
373
- }
374
- ]
375
- });
376
- ```
377
-
378
- **Example 2: Parallel Batch Execution**
379
- ```javascript
380
- TodoWrite({
381
- todos: [
382
- {
383
- content: "Execute IMPL-1.1: Build Auth API [code-developer] [execution_group: parallel-auth-api]",
384
- status: "in_progress", // Batch task 1
385
- activeForm: "Executing IMPL-1.1: Build Auth API"
386
- },
387
- {
388
- content: "Execute IMPL-1.2: Build User UI [code-developer] [execution_group: parallel-ui-comp]",
389
- status: "in_progress", // Batch task 2 (running concurrently)
390
- activeForm: "Executing IMPL-1.2: Build User UI"
391
- },
392
- {
393
- content: "Execute IMPL-1.3: Setup Database [code-developer] [execution_group: parallel-db-schema]",
394
- status: "in_progress", // Batch task 3 (running concurrently)
395
- activeForm: "Executing IMPL-1.3: Setup Database"
396
- },
397
- {
398
- content: "Execute IMPL-2.1: Integration Tests [test-fix-agent] [depends_on: IMPL-1.1, IMPL-1.2, IMPL-1.3]",
399
- status: "pending", // Next batch (waits for current batch completion)
400
- activeForm: "Executing IMPL-2.1: Integration Tests"
401
- }
402
- ]
403
- });
404
- ```
405
-
406
- ## Agent Execution Pattern
407
-
408
- ### Flow Control Execution
409
- **[FLOW_CONTROL]** marker indicates task JSON contains `flow_control.pre_analysis` steps for context preparation.
410
-
411
- **Note**: Orchestrator does NOT execute flow control steps - Agent interprets and executes them autonomously.
412
-
413
- ### Agent Prompt Template
414
- **Path-Based Invocation**: Pass paths and trigger markers, let agent parse task JSON autonomously.
415
-
416
- ```bash
417
- Task(subagent_type="{meta.agent}",
418
- run_in_background=false,
419
- prompt="Implement task {task.id}: {task.title}
420
-
421
- [FLOW_CONTROL]
422
-
423
- **Input**:
424
- - Task JSON: {session.task_json_path}
425
- - Context Package: {session.context_package_path}
426
-
427
- **Output Location**:
428
- - Workflow: {session.workflow_dir}
429
- - TODO List: {session.todo_list_path}
430
- - Summaries: {session.summaries_dir}
431
-
432
- **Execution**: Read task JSON → Parse flow_control → Execute implementation_approach → Update TODO_LIST.md → Generate summary",
433
- description="Implement: {task.id}")
434
- ```
435
-
436
- **Key Markers**:
437
- - `Implement` keyword: Triggers tech stack detection and guidelines loading
438
- - `[FLOW_CONTROL]`: Triggers flow_control.pre_analysis execution
439
-
440
- **Why Path-Based**: Agent (code-developer.md) autonomously:
441
- - Reads and parses task JSON (requirements, acceptance, flow_control)
442
- - Loads tech stack guidelines based on detected language
443
- - Executes pre_analysis steps and implementation_approach
444
- - Generates structured summary with integration points
445
-
446
- Embedding task content in prompt creates duplication and conflicts with agent's parsing logic.
447
-
448
- ### Agent Assignment Rules
449
- ```
450
- meta.agent specified → Use specified agent
451
- meta.agent missing → Infer from meta.type:
452
- - "feature" → @code-developer
453
- - "test-gen" → @code-developer
454
- - "test-fix" @test-fix-agent
455
- - "review" → @universal-executor
456
- - "docs" @doc-generator
457
- ```
458
-
459
- ## Workflow File Structure Reference
460
- ```
461
- .workflow/active/WFS-[topic-slug]/
462
- ├── workflow-session.json # Session state and metadata
463
- ├── IMPL_PLAN.md # Planning document and requirements
464
- ├── TODO_LIST.md # Progress tracking (updated by agents)
465
- ├── .task/ # Task definitions (JSON only)
466
- │ ├── IMPL-1.json # Main task definitions
467
- │ └── IMPL-1.1.json # Subtask definitions
468
- ├── .summaries/ # Task completion summaries
469
- │ ├── IMPL-1-summary.md # Task completion details
470
- │ └── IMPL-1.1-summary.md # Subtask completion details
471
- └── .process/ # Planning artifacts
472
- ├── context-package.json # Smart context package
473
- └── ANALYSIS_RESULTS.md # Planning analysis results
474
- ```
475
-
476
- ## Error Handling & Recovery
477
-
478
- ### Common Errors & Recovery
479
-
480
- | Error Type | Cause | Recovery Strategy | Max Attempts |
481
- |-----------|-------|------------------|--------------|
482
- | **Discovery Errors** |
483
- | No active session | No sessions in `.workflow/active/` | Create or resume session: `/workflow:plan "project"` | N/A |
484
- | Multiple sessions | Multiple sessions in `.workflow/active/` | Prompt user selection | N/A |
485
- | Corrupted session | Invalid JSON files | Recreate session structure or validate files | N/A |
486
- | **Execution Errors** |
487
- | Agent failure | Agent crash/timeout | Retry with simplified context | 2 |
488
- | Flow control error | Command failure | Skip optional, fail critical | 1 per step |
489
- | Context loading error | Missing dependencies | Reload from JSON, use defaults | 3 |
490
- | JSON file corruption | File system issues | Restore from backup/recreate | 1 |
491
-
492
- ### Error Prevention
493
- - **Pre-flight Checks**: Validate session integrity before execution
494
- - **Backup Strategy**: Create task snapshots before major operations
495
- - **Atomic Updates**: Update JSON files atomically to prevent corruption
496
- - **Dependency Validation**: Check all depends_on references exist
497
- - **Context Verification**: Ensure all required context is available
498
-
1
+ ---
2
+ name: execute
3
+ description: Coordinate agent execution for workflow tasks with automatic session discovery, parallel task processing, and status tracking
4
+ argument-hint: "[-y|--yes] [--resume-session=\"session-id\"]"
5
+ ---
6
+
7
+ # Workflow Execute Command
8
+
9
+ ## Overview
10
+ Orchestrates autonomous workflow execution through systematic task discovery, agent coordination, and progress tracking. **Executes entire workflow without user interruption** (except initial session selection if multiple active sessions exist), providing complete context to agents and ensuring proper flow control execution with comprehensive TodoWrite tracking.
11
+
12
+ **Resume Mode**: When called with `--resume-session` flag, skips discovery phase and directly enters TodoWrite generation and agent execution for the specified session.
13
+
14
+ ## Usage
15
+
16
+ ```bash
17
+ # Interactive mode (with confirmations)
18
+ /workflow:execute
19
+ /workflow:execute --resume-session="WFS-auth"
20
+
21
+ # Auto mode (skip confirmations, use defaults)
22
+ /workflow:execute --yes
23
+ /workflow:execute -y
24
+ /workflow:execute -y --resume-session="WFS-auth"
25
+ ```
26
+
27
+ ## Auto Mode Defaults
28
+
29
+ When `--yes` or `-y` flag is used:
30
+ - **Session Selection**: Automatically selects the first (most recent) active session
31
+ - **Completion Choice**: Automatically completes session (runs `/workflow:session:complete --yes`)
32
+
33
+ **Flag Parsing**:
34
+ ```javascript
35
+ const autoYes = $ARGUMENTS.includes('--yes') || $ARGUMENTS.includes('-y')
36
+ ```
37
+
38
+ ## Performance Optimization Strategy
39
+
40
+ **Lazy Loading**: Task JSONs read **on-demand** during execution, not upfront. TODO_LIST.md + IMPL_PLAN.md provide metadata for planning.
41
+
42
+ **Loading Strategy**:
43
+ - **TODO_LIST.md**: Read in Phase 3 (task metadata, status, dependencies for TodoWrite generation)
44
+ - **IMPL_PLAN.md**: Check existence in Phase 2 (normal mode), parse execution strategy in Phase 4A
45
+ - **Task JSONs**: Lazy loading - read only when task is about to execute (Phase 4B)
46
+
47
+ ## Core Rules
48
+ **Complete entire workflow autonomously without user interruption, using TodoWrite for comprehensive progress tracking.**
49
+ **Execute all discovered pending tasks until workflow completion or blocking dependency.**
50
+ **User-choice completion: When all tasks finished, ask user to choose review or complete.**
51
+ **ONE AGENT = ONE TASK JSON: Each agent instance executes exactly one task JSON file - never batch multiple tasks into single agent execution.**
52
+
53
+ ## Core Responsibilities
54
+ - **Session Discovery**: Identify and select active workflow sessions
55
+ - **Execution Strategy Parsing**: Extract execution model from IMPL_PLAN.md
56
+ - **TodoWrite Progress Tracking**: Maintain real-time execution status throughout entire workflow
57
+ - **Agent Orchestration**: Coordinate specialized agents with complete context
58
+ - **Status Synchronization**: Update task JSON files and workflow state
59
+ - **Autonomous Completion**: Continue execution until all tasks complete or reach blocking state
60
+ - **Session User-Choice Completion**: Ask user to choose review or complete when all tasks finished
61
+
62
+ ## Execution Philosophy
63
+ - **Progress tracking**: Continuous TodoWrite updates throughout entire workflow execution
64
+ - **Autonomous completion**: Execute all tasks without user interruption until workflow complete
65
+
66
+ ## Execution Process
67
+
68
+ ```
69
+ Normal Mode:
70
+ Phase 1: Discovery
71
+ ├─ Count active sessions
72
+ └─ Decision:
73
+ ├─ count=0 ERROR: No active sessions
74
+ ├─ count=1 Auto-select session → Phase 2
75
+ └─ count>1 → AskUserQuestion (max 4 options) → Phase 2
76
+
77
+ Phase 2: Planning Document Validation
78
+ ├─ Check IMPL_PLAN.md exists
79
+ ├─ Check TODO_LIST.md exists
80
+ └─ Validate .task/ contains IMPL-*.json files
81
+
82
+ Phase 3: TodoWrite Generation
83
+ ├─ Update session status to "active" (Step 0)
84
+ ├─ Parse TODO_LIST.md for task statuses
85
+ ├─ Generate TodoWrite for entire workflow
86
+ └─ Prepare session context paths
87
+
88
+ Phase 4: Execution Strategy & Task Execution
89
+ ├─ Step 4A: Parse execution strategy from IMPL_PLAN.md
90
+ └─ Step 4B: Execute tasks with lazy loading
91
+ └─ Loop:
92
+ ├─ Get next in_progress task from TodoWrite
93
+ ├─ Lazy load task JSON
94
+ ├─ Launch agent with task context
95
+ ├─ Mark task completed (update IMPL-*.json status)
96
+ │ # Quick fix: Update task status for ccw dashboard
97
+ │ # TS=$(date -Iseconds) && jq --arg ts "$TS" '.status="completed" | .status_history=(.status_history // [])+[{"from":"in_progress","to":"completed","changed_at":$ts}]' IMPL-X.json > tmp.json && mv tmp.json IMPL-X.json
98
+ └─ Advance to next task
99
+
100
+ Phase 5: Completion
101
+ ├─ Update task statuses in JSON files
102
+ ├─ Generate summaries
103
+ └─ AskUserQuestion: Choose next step
104
+ ├─ "Enter Review" /workflow:review
105
+ └─ "Complete Session" → /workflow:session:complete
106
+
107
+ Resume Mode (--resume-session):
108
+ ├─ Skip Phase 1 & Phase 2
109
+ └─ Entry Point: Phase 3 (TodoWrite Generation)
110
+ ├─ Update session status to "active" (if not already)
111
+ └─ Continue: Phase 4 → Phase 5
112
+ ```
113
+
114
+ ## Execution Lifecycle
115
+
116
+ ### Phase 1: Discovery
117
+ **Applies to**: Normal mode only (skipped in resume mode)
118
+
119
+ **Purpose**: Find and select active workflow session with user confirmation when multiple sessions exist
120
+
121
+ **Process**:
122
+
123
+ #### Step 1.1: Count Active Sessions
124
+ ```bash
125
+ bash(find .workflow/active/ -name "WFS-*" -type d 2>/dev/null | wc -l)
126
+ ```
127
+
128
+ #### Step 1.2: Handle Session Selection
129
+
130
+ **Case A: No Sessions** (count = 0)
131
+ ```
132
+ ERROR: No active workflow sessions found
133
+ Run /workflow:plan "task description" to create a session
134
+ ```
135
+
136
+ **Case B: Single Session** (count = 1)
137
+ ```bash
138
+ bash(find .workflow/active/ -name "WFS-*" -type d 2>/dev/null | head -1 | xargs basename)
139
+ ```
140
+ Auto-select and continue to Phase 2.
141
+
142
+ **Case C: Multiple Sessions** (count > 1)
143
+
144
+ List sessions with metadata and prompt user selection:
145
+ ```bash
146
+ bash(for dir in .workflow/active/WFS-*/; do [ -d "$dir" ] || continue; session=$(basename "$dir"); project=$(jq -r '.project // "Unknown"' "${dir}workflow-session.json" 2>/dev/null || echo "Unknown"); total=$(grep -c '^\- \[' "${dir}TODO_LIST.md" 2>/dev/null || echo 0); completed=$(grep -c '^\- \[x\]' "${dir}TODO_LIST.md" 2>/dev/null || echo 0); if [ "$total" -gt 0 ]; then progress=$((completed * 100 / total)); else progress=0; fi; echo "$session | $project | $completed/$total tasks ($progress%)"; done)
147
+ ```
148
+
149
+ **Parse --yes flag**:
150
+ ```javascript
151
+ const autoYes = $ARGUMENTS.includes('--yes') || $ARGUMENTS.includes('-y')
152
+ ```
153
+
154
+ **Conditional Selection**:
155
+ ```javascript
156
+ if (autoYes) {
157
+ // Auto mode: Select first session (most recent)
158
+ const firstSession = sessions[0]
159
+ console.log(`[--yes] Auto-selecting session: ${firstSession.id}`)
160
+ selectedSessionId = firstSession.id
161
+ // Continue to Phase 2
162
+ } else {
163
+ // Interactive mode: Use AskUserQuestion to present formatted options (max 4 options shown)
164
+ // If more than 4 sessions, show most recent 4 with "Other" option for manual input
165
+ const sessions = getActiveSessions() // sorted by last modified
166
+ const displaySessions = sessions.slice(0, 4)
167
+
168
+ AskUserQuestion({
169
+ questions: [{
170
+ question: "Multiple active sessions detected. Select one:",
171
+ header: "Session",
172
+ multiSelect: false,
173
+ options: displaySessions.map(s => ({
174
+ label: s.id,
175
+ description: `${s.project} | ${s.progress}`
176
+ }))
177
+ // Note: User can select "Other" to manually enter session ID
178
+ }]
179
+ })
180
+ }
181
+ ```
182
+
183
+ **Input Validation**:
184
+ - If user selects from options: Use selected session ID
185
+ - If user selects "Other" and provides input: Validate session exists
186
+ - If validation fails: Show error and re-prompt or suggest available sessions
187
+
188
+ Parse user input (supports: number "1", full ID "WFS-auth-system", or partial "auth"), validate selection, and continue to Phase 2.
189
+
190
+ #### Step 1.3: Load Session Metadata
191
+ ```bash
192
+ bash(cat .workflow/active/${sessionId}/workflow-session.json)
193
+ ```
194
+
195
+ **Output**: Store session metadata in memory
196
+ **DO NOT read task JSONs yet** - defer until execution phase (lazy loading)
197
+
198
+ **Resume Mode**: This entire phase is skipped when `--resume-session="session-id"` flag is provided.
199
+
200
+ ### Phase 2: Planning Document Validation
201
+ **Applies to**: Normal mode only (skipped in resume mode)
202
+
203
+ **Purpose**: Validate planning artifacts exist before execution
204
+
205
+ **Process**:
206
+ 1. **Check IMPL_PLAN.md**: Verify file exists (defer detailed parsing to Phase 4A)
207
+ 2. **Check TODO_LIST.md**: Verify file exists (defer reading to Phase 3)
208
+ 3. **Validate Task Directory**: Ensure `.task/` contains at least one IMPL-*.json file
209
+
210
+ **Key Optimization**: Only existence checks here. Actual file reading happens in later phases.
211
+
212
+ **Resume Mode**: This phase is skipped when `--resume-session` flag is provided. Resume mode entry point is Phase 3.
213
+
214
+ ### Phase 3: TodoWrite Generation
215
+ **Applies to**: Both normal and resume modes (resume mode entry point)
216
+
217
+ **Step 0: Update Session Status to Active**
218
+ Before generating TodoWrite, update session status from "planning" to "active":
219
+ ```bash
220
+ # Update session status (idempotent - safe to run if already active)
221
+ jq '.status = "active" | .execution_started_at = (.execution_started_at // now | todate)' \
222
+ .workflow/active/${sessionId}/workflow-session.json > tmp.json && \
223
+ mv tmp.json .workflow/active/${sessionId}/workflow-session.json
224
+ ```
225
+ This ensures the dashboard shows the session as "ACTIVE" during execution.
226
+
227
+ **Process**:
228
+ 1. **Create TodoWrite List**: Generate task list from TODO_LIST.md (not from task JSONs)
229
+ - Parse TODO_LIST.md to extract all tasks with current statuses
230
+ - Identify first pending task with met dependencies
231
+ - Generate comprehensive TodoWrite covering entire workflow
232
+ 2. **Prepare Session Context**: Inject workflow paths for agent use (using provided session-id)
233
+ 3. **Validate Prerequisites**: Ensure IMPL_PLAN.md and TODO_LIST.md exist and are valid
234
+
235
+ **Resume Mode Behavior**:
236
+ - Load existing TODO_LIST.md directly from `.workflow/active/{session-id}/`
237
+ - Extract current progress from TODO_LIST.md
238
+ - Generate TodoWrite from TODO_LIST.md state
239
+ - Proceed immediately to agent execution (Phase 4)
240
+
241
+ ### Phase 4: Execution Strategy Selection & Task Execution
242
+ **Applies to**: Both normal and resume modes
243
+
244
+ **Step 4A: Parse Execution Strategy from IMPL_PLAN.md**
245
+
246
+ Read IMPL_PLAN.md Section 4 to extract:
247
+ - **Execution Model**: Sequential | Parallel | Phased | TDD Cycles
248
+ - **Parallelization Opportunities**: Which tasks can run in parallel
249
+ - **Serialization Requirements**: Which tasks must run sequentially
250
+ - **Critical Path**: Priority execution order
251
+
252
+ If IMPL_PLAN.md lacks execution strategy, use intelligent fallback (analyze task structure).
253
+
254
+ **Step 4B: Execute Tasks with Lazy Loading**
255
+
256
+ **Key Optimization**: Read task JSON **only when needed** for execution
257
+
258
+ **Execution Loop Pattern**:
259
+ ```
260
+ while (TODO_LIST.md has pending tasks) {
261
+ next_task_id = getTodoWriteInProgressTask()
262
+ task_json = Read(.workflow/active/{session}/.task/{next_task_id}.json) // Lazy load
263
+ executeTaskWithAgent(task_json)
264
+ updateTodoListMarkCompleted(next_task_id)
265
+ advanceTodoWriteToNextTask()
266
+ }
267
+ ```
268
+
269
+ **Execution Process per Task**:
270
+ 1. **Identify Next Task**: From TodoWrite, get the next `in_progress` task ID
271
+ 2. **Load Task JSON on Demand**: Read `.task/{task-id}.json` for current task ONLY
272
+ 3. **Validate Task Structure**: Ensure all 5 required fields exist (id, title, status, meta, context, flow_control)
273
+ 4. **Launch Agent**: Invoke specialized agent with complete context including flow control steps
274
+ 5. **Monitor Progress**: Track agent execution and handle errors without user interruption
275
+ 6. **Collect Results**: Gather implementation results and outputs
276
+ 7. **Continue Workflow**: Identify next pending task from TODO_LIST.md and repeat
277
+
278
+ **Note**: TODO_LIST.md updates are handled by agents (e.g., code-developer.md), not by the orchestrator.
279
+
280
+
281
+ ### Phase 5: Completion
282
+ **Applies to**: Both normal and resume modes
283
+
284
+ **Process**:
285
+ 1. **Update Task Status**: Mark completed tasks in JSON files
286
+ 2. **Generate Summary**: Create task summary in `.summaries/`
287
+ 3. **Update TodoWrite**: Mark current task complete, advance to next
288
+ 4. **Synchronize State**: Update session state and workflow status
289
+ 5. **Check Workflow Complete**: Verify all tasks are completed
290
+ 6. **User Choice**: When all tasks finished, ask user to choose next step:
291
+
292
+ ```javascript
293
+ // Parse --yes flag
294
+ const autoYes = $ARGUMENTS.includes('--yes') || $ARGUMENTS.includes('-y')
295
+
296
+ if (autoYes) {
297
+ // Auto mode: Complete session automatically
298
+ console.log(`[--yes] Auto-selecting: Complete Session`)
299
+ SlashCommand("/workflow:session:complete --yes")
300
+ } else {
301
+ // Interactive mode: Ask user
302
+ AskUserQuestion({
303
+ questions: [{
304
+ question: "All tasks completed. What would you like to do next?",
305
+ header: "Next Step",
306
+ multiSelect: false,
307
+ options: [
308
+ {
309
+ label: "Enter Review",
310
+ description: "Run specialized review (security/architecture/quality/action-items)"
311
+ },
312
+ {
313
+ label: "Complete Session",
314
+ description: "Archive session and update manifest"
315
+ }
316
+ ]
317
+ }]
318
+ })
319
+ }
320
+ ```
321
+
322
+ **Based on user selection**:
323
+ - **"Enter Review"**: Execute `/workflow:review`
324
+ - **"Complete Session"**: Execute `/workflow:session:complete`
325
+
326
+ ### Post-Completion Expansion
327
+
328
+ 完成后询问用户是否扩展为issue(test/enhance/refactor/doc),选中项调用 `/issue:new "{summary} - {dimension}"`
329
+
330
+ ## Execution Strategy (IMPL_PLAN-Driven)
331
+
332
+ ### Strategy Priority
333
+
334
+ **IMPL_PLAN-Driven Execution (Recommended)**:
335
+ 1. **Read IMPL_PLAN.md execution strategy** (Section 4: Implementation Strategy)
336
+ 2. **Follow explicit guidance**:
337
+ - Execution Model (Sequential/Parallel/Phased/TDD)
338
+ - Parallelization Opportunities (which tasks can run in parallel)
339
+ - Serialization Requirements (which tasks must run sequentially)
340
+ - Critical Path (priority execution order)
341
+ 3. **Use TODO_LIST.md for status tracking** only
342
+ 4. **IMPL_PLAN decides "HOW"**, execute.md implements it
343
+
344
+ **Intelligent Fallback (When IMPL_PLAN lacks execution details)**:
345
+ 1. **Analyze task structure**:
346
+ - Check `meta.execution_group` in task JSONs
347
+ - Analyze `depends_on` relationships
348
+ - Understand task complexity and risk
349
+ 2. **Apply smart defaults**:
350
+ - No dependencies + same execution_group → Parallel
351
+ - Has dependencies Sequential (wait for deps)
352
+ - Critical/high-risk tasks Sequential
353
+ 3. **Conservative approach**: When uncertain, prefer sequential execution
354
+
355
+ ### Execution Models
356
+
357
+ #### 1. Sequential Execution
358
+ **When**: IMPL_PLAN specifies "Sequential" OR no clear parallelization guidance
359
+ **Pattern**: Execute tasks one by one in TODO_LIST order
360
+ **TodoWrite**: ONE task marked as `in_progress` at a time
361
+
362
+ #### 2. Parallel Execution
363
+ **When**: IMPL_PLAN specifies "Parallel" with clear parallelization opportunities
364
+ **Pattern**: Execute independent task groups concurrently by launching multiple agent instances
365
+ **TodoWrite**: MULTIPLE tasks (in same batch) marked as `in_progress` simultaneously
366
+ **Agent Instantiation**: Launch one agent instance per task (respects ONE AGENT = ONE TASK JSON rule)
367
+
368
+ #### 3. Phased Execution
369
+ **When**: IMPL_PLAN specifies "Phased" with phase breakdown
370
+ **Pattern**: Execute tasks in phases, respect phase boundaries
371
+ **TodoWrite**: Within each phase, follow Sequential or Parallel rules
372
+
373
+ #### 4. Intelligent Fallback
374
+ **When**: IMPL_PLAN lacks execution strategy details
375
+ **Pattern**: Analyze task structure and apply smart defaults
376
+ **TodoWrite**: Follow Sequential or Parallel rules based on analysis
377
+
378
+ ### Task Status Logic
379
+ ```
380
+ pending + dependencies_met → executable
381
+ completed → skip
382
+ blocked → skip until dependencies clear
383
+ ```
384
+
385
+ ## TodoWrite Coordination
386
+
387
+ ### TodoWrite Rules (Unified)
388
+
389
+ **Rule 1: Initial Creation**
390
+ - **Normal Mode**: Generate TodoWrite from discovered pending tasks for entire workflow
391
+ - **Resume Mode**: Generate from existing session state and current progress
392
+
393
+ **Rule 2: In-Progress Task Count (Execution-Model-Dependent)**
394
+ - **Sequential execution**: Mark ONLY ONE task as `in_progress` at a time
395
+ - **Parallel batch execution**: Mark ALL tasks in current batch as `in_progress` simultaneously
396
+ - **Execution group indicator**: Show `[execution_group: group-id]` for parallel tasks
397
+
398
+ **Rule 3: Status Updates**
399
+ - **Immediate Updates**: Update status after each task/batch completion without user interruption
400
+ - **Status Synchronization**: Sync with JSON task files after updates
401
+ - **Continuous Tracking**: Maintain TodoWrite throughout entire workflow execution until completion
402
+
403
+ **Rule 4: Workflow Completion Check**
404
+ - When all tasks marked `completed`, prompt user to choose review or complete session
405
+
406
+ ### TodoWrite Tool Usage
407
+
408
+ **Example 1: Sequential Execution**
409
+ ```javascript
410
+ TodoWrite({
411
+ todos: [
412
+ {
413
+ content: "Execute IMPL-1.1: Design auth schema [code-developer] [FLOW_CONTROL]",
414
+ status: "in_progress", // ONE task in progress
415
+ activeForm: "Executing IMPL-1.1: Design auth schema"
416
+ },
417
+ {
418
+ content: "Execute IMPL-1.2: Implement auth logic [code-developer] [FLOW_CONTROL]",
419
+ status: "pending",
420
+ activeForm: "Executing IMPL-1.2: Implement auth logic"
421
+ }
422
+ ]
423
+ });
424
+ ```
425
+
426
+ **Example 2: Parallel Batch Execution**
427
+ ```javascript
428
+ TodoWrite({
429
+ todos: [
430
+ {
431
+ content: "Execute IMPL-1.1: Build Auth API [code-developer] [execution_group: parallel-auth-api]",
432
+ status: "in_progress", // Batch task 1
433
+ activeForm: "Executing IMPL-1.1: Build Auth API"
434
+ },
435
+ {
436
+ content: "Execute IMPL-1.2: Build User UI [code-developer] [execution_group: parallel-ui-comp]",
437
+ status: "in_progress", // Batch task 2 (running concurrently)
438
+ activeForm: "Executing IMPL-1.2: Build User UI"
439
+ },
440
+ {
441
+ content: "Execute IMPL-1.3: Setup Database [code-developer] [execution_group: parallel-db-schema]",
442
+ status: "in_progress", // Batch task 3 (running concurrently)
443
+ activeForm: "Executing IMPL-1.3: Setup Database"
444
+ },
445
+ {
446
+ content: "Execute IMPL-2.1: Integration Tests [test-fix-agent] [depends_on: IMPL-1.1, IMPL-1.2, IMPL-1.3]",
447
+ status: "pending", // Next batch (waits for current batch completion)
448
+ activeForm: "Executing IMPL-2.1: Integration Tests"
449
+ }
450
+ ]
451
+ });
452
+ ```
453
+
454
+ ## Agent Execution Pattern
455
+
456
+ ### Flow Control Execution
457
+ **[FLOW_CONTROL]** marker indicates task JSON contains `flow_control.pre_analysis` steps for context preparation.
458
+
459
+ **Note**: Orchestrator does NOT execute flow control steps - Agent interprets and executes them autonomously.
460
+
461
+ ### Agent Prompt Template
462
+ **Path-Based Invocation**: Pass paths and trigger markers, let agent parse task JSON autonomously.
463
+
464
+ ```bash
465
+ Task(subagent_type="{meta.agent}",
466
+ run_in_background=false,
467
+ prompt="Implement task {task.id}: {task.title}
468
+
469
+ [FLOW_CONTROL]
470
+
471
+ **Input**:
472
+ - Task JSON: {session.task_json_path}
473
+ - Context Package: {session.context_package_path}
474
+
475
+ **Output Location**:
476
+ - Workflow: {session.workflow_dir}
477
+ - TODO List: {session.todo_list_path}
478
+ - Summaries: {session.summaries_dir}
479
+
480
+ **Execution**: Read task JSON Parse flow_control Execute implementation_approach Update TODO_LIST.md → Generate summary",
481
+ description="Implement: {task.id}")
482
+ ```
483
+
484
+ **Key Markers**:
485
+ - `Implement` keyword: Triggers tech stack detection and guidelines loading
486
+ - `[FLOW_CONTROL]`: Triggers flow_control.pre_analysis execution
487
+
488
+ **Why Path-Based**: Agent (code-developer.md) autonomously:
489
+ - Reads and parses task JSON (requirements, acceptance, flow_control)
490
+ - Loads tech stack guidelines based on detected language
491
+ - Executes pre_analysis steps and implementation_approach
492
+ - Generates structured summary with integration points
493
+
494
+ Embedding task content in prompt creates duplication and conflicts with agent's parsing logic.
495
+
496
+ ### Agent Assignment Rules
497
+ ```
498
+ meta.agent specified → Use specified agent
499
+ meta.agent missing → Infer from meta.type:
500
+ - "feature" → @code-developer
501
+ - "test-gen" → @code-developer
502
+ - "test-fix" → @test-fix-agent
503
+ - "review" → @universal-executor
504
+ - "docs" → @doc-generator
505
+ ```
506
+
507
+ ## Workflow File Structure Reference
508
+ ```
509
+ .workflow/active/WFS-[topic-slug]/
510
+ ├── workflow-session.json # Session state and metadata
511
+ ├── IMPL_PLAN.md # Planning document and requirements
512
+ ├── TODO_LIST.md # Progress tracking (updated by agents)
513
+ ├── .task/ # Task definitions (JSON only)
514
+ │ ├── IMPL-1.json # Main task definitions
515
+ │ └── IMPL-1.1.json # Subtask definitions
516
+ ├── .summaries/ # Task completion summaries
517
+ │ ├── IMPL-1-summary.md # Task completion details
518
+ │ └── IMPL-1.1-summary.md # Subtask completion details
519
+ └── .process/ # Planning artifacts
520
+ ├── context-package.json # Smart context package
521
+ └── ANALYSIS_RESULTS.md # Planning analysis results
522
+ ```
523
+
524
+ ## Error Handling & Recovery
525
+
526
+ ### Common Errors & Recovery
527
+
528
+ | Error Type | Cause | Recovery Strategy | Max Attempts |
529
+ |-----------|-------|------------------|--------------|
530
+ | **Discovery Errors** |
531
+ | No active session | No sessions in `.workflow/active/` | Create or resume session: `/workflow:plan "project"` | N/A |
532
+ | Multiple sessions | Multiple sessions in `.workflow/active/` | Prompt user selection | N/A |
533
+ | Corrupted session | Invalid JSON files | Recreate session structure or validate files | N/A |
534
+ | **Execution Errors** |
535
+ | Agent failure | Agent crash/timeout | Retry with simplified context | 2 |
536
+ | Flow control error | Command failure | Skip optional, fail critical | 1 per step |
537
+ | Context loading error | Missing dependencies | Reload from JSON, use defaults | 3 |
538
+ | JSON file corruption | File system issues | Restore from backup/recreate | 1 |
539
+
540
+ ### Error Prevention
541
+ - **Pre-flight Checks**: Validate session integrity before execution
542
+ - **Backup Strategy**: Create task snapshots before major operations
543
+ - **Atomic Updates**: Update JSON files atomically to prevent corruption
544
+ - **Dependency Validation**: Check all depends_on references exist
545
+ - **Context Verification**: Ensure all required context is available
546
+