claude-code-workflow 6.3.44 → 6.3.47
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.
- package/.claude/commands/ccw-coordinator.md +944 -0
- package/.claude/commands/ccw.md +486 -0
- package/ccw/dist/tools/command-registry.d.ts +77 -0
- package/ccw/dist/tools/command-registry.d.ts.map +1 -0
- package/ccw/dist/tools/command-registry.js +265 -0
- package/ccw/dist/tools/command-registry.js.map +1 -0
- package/ccw/dist/tools/command-registry.test.d.ts +14 -0
- package/ccw/dist/tools/command-registry.test.d.ts.map +1 -0
- package/ccw/dist/tools/command-registry.test.js.map +1 -0
- package/ccw/dist/tools/index.d.ts +2 -0
- package/ccw/dist/tools/index.d.ts.map +1 -1
- package/ccw/dist/tools/index.js +2 -0
- package/ccw/dist/tools/index.js.map +1 -1
- package/ccw/src/tools/command-registry.test.ts +669 -0
- package/ccw/src/tools/command-registry.ts +308 -0
- package/ccw/src/tools/index.ts +4 -0
- package/codex-lens/README.md +59 -0
- package/codex-lens/pyproject.toml +1 -1
- package/package.json +1 -1
- package/.claude/skills/ccw/SKILL.md +0 -522
- package/.claude/skills/ccw/command.json +0 -641
- package/.claude/skills/ccw-coordinator/README.md +0 -45
- package/.claude/skills/ccw-coordinator/SKILL.md +0 -320
- package/.claude/skills/ccw-coordinator/phases/actions/action-abort.md +0 -9
- package/.claude/skills/ccw-coordinator/phases/actions/action-command-build.md +0 -40
- package/.claude/skills/ccw-coordinator/phases/actions/action-command-execute.md +0 -124
- package/.claude/skills/ccw-coordinator/phases/actions/action-command-selection.md +0 -48
- package/.claude/skills/ccw-coordinator/phases/actions/action-complete.md +0 -25
- package/.claude/skills/ccw-coordinator/phases/actions/action-init.md +0 -26
- package/.claude/skills/ccw-coordinator/phases/orchestrator.md +0 -59
- package/.claude/skills/ccw-coordinator/phases/state-schema.md +0 -66
- package/.claude/skills/ccw-coordinator/skill-config.json +0 -66
- package/.claude/skills/ccw-coordinator/specs/command-library.md +0 -169
- package/.claude/skills/ccw-coordinator/specs/specs.md +0 -362
- package/.claude/skills/ccw-coordinator/tools/README.md +0 -95
- package/.claude/skills/ccw-coordinator/tools/chain-validate.cjs +0 -320
- package/.claude/skills/ccw-coordinator/tools/command-registry.cjs +0 -255
|
@@ -0,0 +1,944 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ccw-coordinator
|
|
3
|
+
description: Command orchestration tool - analyze requirements, recommend chain, execute sequentially with state persistence
|
|
4
|
+
argument-hint: "[task description]"
|
|
5
|
+
allowed-tools: Task(*), AskUserQuestion(*), Read(*), Write(*), Bash(*), Glob(*), Grep(*)
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# CCW Coordinator Command
|
|
9
|
+
|
|
10
|
+
Interactive orchestration tool: analyze task → discover commands → recommend chain → execute sequentially → track state.
|
|
11
|
+
|
|
12
|
+
**Execution Model**: Pseudocode guidance. Claude intelligently executes each phase based on context.
|
|
13
|
+
|
|
14
|
+
## Core Concept: Minimum Execution Units (最小执行单元)
|
|
15
|
+
|
|
16
|
+
### What is a Minimum Execution Unit?
|
|
17
|
+
|
|
18
|
+
**Definition**: A set of commands that must execute together as an atomic group to achieve a meaningful workflow milestone. Splitting these commands breaks the logical flow and creates incomplete states.
|
|
19
|
+
|
|
20
|
+
**Why This Matters**:
|
|
21
|
+
- **Prevents Incomplete States**: Avoid stopping after task generation without execution
|
|
22
|
+
- **User Experience**: User gets complete results, not intermediate artifacts requiring manual follow-up
|
|
23
|
+
- **Workflow Integrity**: Maintains logical coherence of multi-step operations
|
|
24
|
+
|
|
25
|
+
### Minimum Execution Units
|
|
26
|
+
|
|
27
|
+
**Planning + Execution Units** (规划+执行单元):
|
|
28
|
+
|
|
29
|
+
| Unit Name | Commands | Purpose | Output |
|
|
30
|
+
|-----------|----------|---------|--------|
|
|
31
|
+
| **Quick Implementation** | lite-plan → lite-execute | Lightweight plan and immediate execution | Working code |
|
|
32
|
+
| **Multi-CLI Planning** | multi-cli-plan → lite-execute | Multi-perspective analysis and execution | Working code |
|
|
33
|
+
| **Bug Fix** | lite-fix → lite-execute | Quick bug diagnosis and fix execution | Fixed code |
|
|
34
|
+
| **Full Planning + Execution** | plan → execute | Detailed planning and execution | Working code |
|
|
35
|
+
| **Verified Planning + Execution** | plan → plan-verify → execute | Planning with verification and execution | Working code |
|
|
36
|
+
| **Replanning + Execution** | replan → execute | Update plan and execute changes | Working code |
|
|
37
|
+
| **TDD Planning + Execution** | tdd-plan → execute | Test-driven development planning and execution | Working code |
|
|
38
|
+
| **Test Generation + Execution** | test-gen → execute | Generate test suite and execute | Generated tests |
|
|
39
|
+
|
|
40
|
+
**Testing Units** (测试单元):
|
|
41
|
+
|
|
42
|
+
| Unit Name | Commands | Purpose | Output |
|
|
43
|
+
|-----------|----------|---------|--------|
|
|
44
|
+
| **Test Validation** | test-fix-gen → test-cycle-execute | Generate test tasks and execute test-fix cycle | Tests passed |
|
|
45
|
+
|
|
46
|
+
**Review Units** (审查单元):
|
|
47
|
+
|
|
48
|
+
| Unit Name | Commands | Purpose | Output |
|
|
49
|
+
|-----------|----------|---------|--------|
|
|
50
|
+
| **Code Review (Session)** | review-session-cycle → review-fix | Complete review cycle and apply fixes | Fixed code |
|
|
51
|
+
| **Code Review (Module)** | review-module-cycle → review-fix | Module review cycle and apply fixes | Fixed code |
|
|
52
|
+
|
|
53
|
+
### Command-to-Unit Mapping (命令与最小单元的映射)
|
|
54
|
+
|
|
55
|
+
| Command | Can Precede | Atomic Units |
|
|
56
|
+
|---------|-----------|--------------|
|
|
57
|
+
| lite-plan | lite-execute | Quick Implementation |
|
|
58
|
+
| multi-cli-plan | lite-execute | Multi-CLI Planning |
|
|
59
|
+
| lite-fix | lite-execute | Bug Fix |
|
|
60
|
+
| plan | plan-verify, execute | Full Planning + Execution, Verified Planning + Execution |
|
|
61
|
+
| plan-verify | execute | Verified Planning + Execution |
|
|
62
|
+
| replan | execute | Replanning + Execution |
|
|
63
|
+
| test-gen | execute | Test Generation + Execution |
|
|
64
|
+
| tdd-plan | execute | TDD Planning + Execution |
|
|
65
|
+
| review-session-cycle | review-fix | Code Review (Session) |
|
|
66
|
+
| review-module-cycle | review-fix | Code Review (Module) |
|
|
67
|
+
| test-fix-gen | test-cycle-execute | Test Validation |
|
|
68
|
+
|
|
69
|
+
### Atomic Group Rules
|
|
70
|
+
|
|
71
|
+
1. **Never Split Units**: Coordinator must recommend complete units, not partial chains
|
|
72
|
+
2. **Multi-Unit Participation**: Some commands can participate in multiple units (e.g., plan → execute or plan → plan-verify → execute)
|
|
73
|
+
3. **User Override**: User can explicitly request partial execution (advanced mode)
|
|
74
|
+
4. **Visualization**: Pipeline view shows unit boundaries with `【 】` markers
|
|
75
|
+
5. **Validation**: Before execution, verify all unit commands are included
|
|
76
|
+
|
|
77
|
+
**Example Pipeline with Units**:
|
|
78
|
+
```
|
|
79
|
+
需求 → 【lite-plan → lite-execute】→ 代码 → 【test-fix-gen → test-cycle-execute】→ 测试通过
|
|
80
|
+
└──── Quick Implementation ────┘ └────── Test Validation ──────┘
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 3-Phase Workflow
|
|
84
|
+
|
|
85
|
+
### Phase 1: Analyze Requirements
|
|
86
|
+
|
|
87
|
+
Parse task to extract: goal, scope, constraints, complexity, and task type.
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
function analyzeRequirements(taskDescription) {
|
|
91
|
+
return {
|
|
92
|
+
goal: extractMainGoal(taskDescription), // e.g., "Implement user registration"
|
|
93
|
+
scope: extractScope(taskDescription), // e.g., ["auth", "user_management"]
|
|
94
|
+
constraints: extractConstraints(taskDescription), // e.g., ["no breaking changes"]
|
|
95
|
+
complexity: determineComplexity(taskDescription), // 'simple' | 'medium' | 'complex'
|
|
96
|
+
task_type: detectTaskType(taskDescription) // See task type patterns below
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Task Type Detection Patterns
|
|
101
|
+
function detectTaskType(text) {
|
|
102
|
+
// Priority order (first match wins)
|
|
103
|
+
if (/fix|bug|error|crash|fail|debug|diagnose/.test(text)) return 'bugfix';
|
|
104
|
+
if (/tdd|test-driven|先写测试|test first/.test(text)) return 'tdd';
|
|
105
|
+
if (/测试失败|test fail|fix test|failing test/.test(text)) return 'test-fix';
|
|
106
|
+
if (/generate test|写测试|add test|补充测试/.test(text)) return 'test-gen';
|
|
107
|
+
if (/review|审查|code review/.test(text)) return 'review';
|
|
108
|
+
if (/不确定|explore|研究|what if|brainstorm|权衡/.test(text)) return 'brainstorm';
|
|
109
|
+
if (/多视角|比较方案|cross-verify|multi-cli/.test(text)) return 'multi-cli';
|
|
110
|
+
return 'feature'; // Default
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Complexity Assessment
|
|
114
|
+
function determineComplexity(text) {
|
|
115
|
+
let score = 0;
|
|
116
|
+
if (/refactor|重构|migrate|迁移|architect|架构|system|系统/.test(text)) score += 2;
|
|
117
|
+
if (/multiple|多个|across|跨|all|所有|entire|整个/.test(text)) score += 2;
|
|
118
|
+
if (/integrate|集成|api|database|数据库/.test(text)) score += 1;
|
|
119
|
+
if (/security|安全|performance|性能|scale|扩展/.test(text)) score += 1;
|
|
120
|
+
return score >= 4 ? 'complex' : score >= 2 ? 'medium' : 'simple';
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Display to user**:
|
|
125
|
+
```
|
|
126
|
+
Analysis Complete:
|
|
127
|
+
Goal: [extracted goal]
|
|
128
|
+
Scope: [identified areas]
|
|
129
|
+
Constraints: [identified constraints]
|
|
130
|
+
Complexity: [level]
|
|
131
|
+
Task Type: [detected type]
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Phase 2: Discover Commands & Recommend Chain
|
|
135
|
+
|
|
136
|
+
Dynamic command chain assembly using port-based matching.
|
|
137
|
+
|
|
138
|
+
#### Command Port Definition
|
|
139
|
+
|
|
140
|
+
Each command has input/output ports (tags) for pipeline composition:
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
// Port labels represent data types flowing through the pipeline
|
|
144
|
+
const commandPorts = {
|
|
145
|
+
'lite-plan': {
|
|
146
|
+
name: 'lite-plan',
|
|
147
|
+
input: ['requirement'], // 输入端口:需求
|
|
148
|
+
output: ['plan'], // 输出端口:计划
|
|
149
|
+
tags: ['planning'],
|
|
150
|
+
atomic_group: 'quick-implementation' // 最小单元:与 lite-execute 绑定
|
|
151
|
+
},
|
|
152
|
+
'lite-execute': {
|
|
153
|
+
name: 'lite-execute',
|
|
154
|
+
input: ['plan', 'multi-cli-plan', 'lite-fix'], // 输入端口:可接受多种规划输出
|
|
155
|
+
output: ['code'], // 输出端口:代码
|
|
156
|
+
tags: ['execution'],
|
|
157
|
+
atomic_groups: [ // 可参与多个最小单元
|
|
158
|
+
'quick-implementation', // lite-plan → lite-execute
|
|
159
|
+
'multi-cli-planning', // multi-cli-plan → lite-execute
|
|
160
|
+
'bug-fix' // lite-fix → lite-execute
|
|
161
|
+
]
|
|
162
|
+
},
|
|
163
|
+
'plan': {
|
|
164
|
+
name: 'plan',
|
|
165
|
+
input: ['requirement'],
|
|
166
|
+
output: ['detailed-plan'],
|
|
167
|
+
tags: ['planning'],
|
|
168
|
+
atomic_groups: [ // 可参与多个最小单元
|
|
169
|
+
'full-planning-execution', // plan → execute
|
|
170
|
+
'verified-planning-execution' // plan → plan-verify → execute
|
|
171
|
+
]
|
|
172
|
+
},
|
|
173
|
+
'plan-verify': {
|
|
174
|
+
name: 'plan-verify',
|
|
175
|
+
input: ['detailed-plan'],
|
|
176
|
+
output: ['verified-plan'],
|
|
177
|
+
tags: ['planning'],
|
|
178
|
+
atomic_group: 'verified-planning-execution' // 最小单元:plan → plan-verify → execute
|
|
179
|
+
},
|
|
180
|
+
'replan': {
|
|
181
|
+
name: 'replan',
|
|
182
|
+
input: ['session', 'feedback'], // 输入端口:会话或反馈
|
|
183
|
+
output: ['replan'], // 输出端口:更新后的计划(供 execute 执行)
|
|
184
|
+
tags: ['planning'],
|
|
185
|
+
atomic_group: 'replanning-execution' // 最小单元:与 execute 绑定
|
|
186
|
+
},
|
|
187
|
+
'execute': {
|
|
188
|
+
name: 'execute',
|
|
189
|
+
input: ['detailed-plan', 'verified-plan', 'replan', 'test-tasks', 'tdd-tasks'], // 可接受多种规划输出
|
|
190
|
+
output: ['code'],
|
|
191
|
+
tags: ['execution'],
|
|
192
|
+
atomic_groups: [ // 可参与多个最小单元
|
|
193
|
+
'full-planning-execution', // plan → execute
|
|
194
|
+
'verified-planning-execution', // plan → plan-verify → execute
|
|
195
|
+
'replanning-execution', // replan → execute
|
|
196
|
+
'test-generation-execution', // test-gen → execute
|
|
197
|
+
'tdd-planning-execution' // tdd-plan → execute
|
|
198
|
+
]
|
|
199
|
+
},
|
|
200
|
+
'test-cycle-execute': {
|
|
201
|
+
name: 'test-cycle-execute',
|
|
202
|
+
input: ['test-tasks'], // 输入端口:测试任务(需先test-fix-gen生成)
|
|
203
|
+
output: ['test-passed'], // 输出端口:测试通过
|
|
204
|
+
tags: ['testing'],
|
|
205
|
+
atomic_group: 'test-validation', // 最小单元:与 test-fix-gen 绑定
|
|
206
|
+
note: '需要先执行test-fix-gen生成测试任务,再由此命令执行测试周期'
|
|
207
|
+
},
|
|
208
|
+
'tdd-plan': {
|
|
209
|
+
name: 'tdd-plan',
|
|
210
|
+
input: ['requirement'],
|
|
211
|
+
output: ['tdd-tasks'], // TDD 任务(供 execute 执行)
|
|
212
|
+
tags: ['planning', 'tdd'],
|
|
213
|
+
atomic_group: 'tdd-planning-execution' // 最小单元:与 execute 绑定
|
|
214
|
+
},
|
|
215
|
+
'tdd-verify': {
|
|
216
|
+
name: 'tdd-verify',
|
|
217
|
+
input: ['code'],
|
|
218
|
+
output: ['tdd-verified'],
|
|
219
|
+
tags: ['testing']
|
|
220
|
+
},
|
|
221
|
+
'lite-fix': {
|
|
222
|
+
name: 'lite-fix',
|
|
223
|
+
input: ['bug-report'], // 输入端口:bug 报告
|
|
224
|
+
output: ['lite-fix'], // 输出端口:修复计划(供 lite-execute 执行)
|
|
225
|
+
tags: ['bugfix'],
|
|
226
|
+
atomic_group: 'bug-fix' // 最小单元:与 lite-execute 绑定
|
|
227
|
+
},
|
|
228
|
+
'debug': {
|
|
229
|
+
name: 'debug',
|
|
230
|
+
input: ['bug-report'],
|
|
231
|
+
output: ['debug-log'],
|
|
232
|
+
tags: ['bugfix']
|
|
233
|
+
},
|
|
234
|
+
'test-gen': {
|
|
235
|
+
name: 'test-gen',
|
|
236
|
+
input: ['code', 'session'], // 可接受代码或会话
|
|
237
|
+
output: ['test-tasks'], // 输出测试任务(IMPL-001,IMPL-002),供 execute 执行
|
|
238
|
+
tags: ['testing'],
|
|
239
|
+
atomic_group: 'test-generation-execution' // 最小单元:与 execute 绑定
|
|
240
|
+
},
|
|
241
|
+
'test-fix-gen': {
|
|
242
|
+
name: 'test-fix-gen',
|
|
243
|
+
input: ['failing-tests', 'session'],
|
|
244
|
+
output: ['test-tasks'], // 输出测试任务,针对特定问题生成测试并在测试中修正
|
|
245
|
+
tags: ['testing'],
|
|
246
|
+
atomic_group: 'test-validation', // 最小单元:与 test-cycle-execute 绑定
|
|
247
|
+
note: '生成测试任务供test-cycle-execute执行'
|
|
248
|
+
},
|
|
249
|
+
'review': {
|
|
250
|
+
name: 'review',
|
|
251
|
+
input: ['code', 'session'],
|
|
252
|
+
output: ['review-findings'],
|
|
253
|
+
tags: ['review']
|
|
254
|
+
},
|
|
255
|
+
'review-fix': {
|
|
256
|
+
name: 'review-fix',
|
|
257
|
+
input: ['review-findings', 'review-verified'], // Accept output from review-session-cycle or review-module-cycle
|
|
258
|
+
output: ['fixed-code'],
|
|
259
|
+
tags: ['review'],
|
|
260
|
+
atomic_group: 'code-review' // 最小单元:与 review-session-cycle/review-module-cycle 绑定
|
|
261
|
+
},
|
|
262
|
+
'brainstorm:auto-parallel': {
|
|
263
|
+
name: 'brainstorm:auto-parallel',
|
|
264
|
+
input: ['exploration-topic'], // 输入端口:探索主题
|
|
265
|
+
output: ['brainstorm-analysis'],
|
|
266
|
+
tags: ['brainstorm']
|
|
267
|
+
},
|
|
268
|
+
'multi-cli-plan': {
|
|
269
|
+
name: 'multi-cli-plan',
|
|
270
|
+
input: ['requirement'],
|
|
271
|
+
output: ['multi-cli-plan'], // 对比分析计划(供 lite-execute 执行)
|
|
272
|
+
tags: ['planning', 'multi-cli'],
|
|
273
|
+
atomic_group: 'multi-cli-planning' // 最小单元:与 lite-execute 绑定
|
|
274
|
+
},
|
|
275
|
+
'review-session-cycle': {
|
|
276
|
+
name: 'review-session-cycle',
|
|
277
|
+
input: ['code', 'session'], // 可接受代码或会话
|
|
278
|
+
output: ['review-verified'], // 输出端口:审查通过
|
|
279
|
+
tags: ['review'],
|
|
280
|
+
atomic_group: 'code-review' // 最小单元:与 review-fix 绑定
|
|
281
|
+
},
|
|
282
|
+
'review-module-cycle': {
|
|
283
|
+
name: 'review-module-cycle',
|
|
284
|
+
input: ['module-pattern'], // 输入端口:模块模式
|
|
285
|
+
output: ['review-verified'], // 输出端口:审查通过
|
|
286
|
+
tags: ['review'],
|
|
287
|
+
atomic_group: 'code-review' // 最小单元:与 review-fix 绑定
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
#### Recommendation Algorithm
|
|
293
|
+
|
|
294
|
+
```javascript
|
|
295
|
+
async function recommendCommandChain(analysis) {
|
|
296
|
+
// Step 1: 根据任务类型确定起始端口和目标端口
|
|
297
|
+
const { inputPort, outputPort } = determinePortFlow(analysis.task_type, analysis.constraints);
|
|
298
|
+
|
|
299
|
+
// Step 2: Claude 根据命令端口定义和任务特征,智能选择命令序列
|
|
300
|
+
// 优先级:简单任务 → lite-* 命令,复杂任务 → 完整命令,特殊约束 → 调整流程
|
|
301
|
+
const chain = selectChainByPorts(inputPort, outputPort, analysis);
|
|
302
|
+
|
|
303
|
+
return chain;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// 任务类型对应的端口流
|
|
307
|
+
function determinePortFlow(taskType, constraints) {
|
|
308
|
+
const flows = {
|
|
309
|
+
'bugfix': { inputPort: 'bug-report', outputPort: constraints?.includes('skip-tests') ? 'fixed-code' : 'test-passed' },
|
|
310
|
+
'tdd': { inputPort: 'requirement', outputPort: 'tdd-verified' },
|
|
311
|
+
'test-fix': { inputPort: 'failing-tests', outputPort: 'test-passed' },
|
|
312
|
+
'test-gen': { inputPort: 'code', outputPort: 'test-passed' },
|
|
313
|
+
'review': { inputPort: 'code', outputPort: 'review-verified' },
|
|
314
|
+
'brainstorm': { inputPort: 'exploration-topic', outputPort: 'test-passed' },
|
|
315
|
+
'multi-cli': { inputPort: 'requirement', outputPort: 'test-passed' },
|
|
316
|
+
'feature': { inputPort: 'requirement', outputPort: constraints?.includes('skip-tests') ? 'code' : 'test-passed' }
|
|
317
|
+
};
|
|
318
|
+
return flows[taskType] || flows['feature'];
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Claude 根据端口流选择命令链
|
|
322
|
+
function selectChainByPorts(inputPort, outputPort, analysis) {
|
|
323
|
+
// 参考下面的命令端口定义表和执行示例,Claude 智能选择合适的命令序列
|
|
324
|
+
// 返回值示例: [lite-plan, lite-execute, test-cycle-execute]
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
#### Display to User
|
|
329
|
+
|
|
330
|
+
```
|
|
331
|
+
Recommended Command Chain:
|
|
332
|
+
|
|
333
|
+
Pipeline (管道视图):
|
|
334
|
+
需求 → lite-plan → 计划 → lite-execute → 代码 → test-cycle-execute → 测试通过
|
|
335
|
+
|
|
336
|
+
Commands (命令列表):
|
|
337
|
+
1. /workflow:lite-plan
|
|
338
|
+
2. /workflow:lite-execute
|
|
339
|
+
3. /workflow:test-cycle-execute
|
|
340
|
+
|
|
341
|
+
Proceed? [Confirm / Show Details / Adjust / Cancel]
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Phase 2b: Get User Confirmation
|
|
345
|
+
|
|
346
|
+
```javascript
|
|
347
|
+
async function getUserConfirmation(chain) {
|
|
348
|
+
const response = await AskUserQuestion({
|
|
349
|
+
questions: [{
|
|
350
|
+
question: 'Proceed with this command chain?',
|
|
351
|
+
header: 'Confirm',
|
|
352
|
+
options: [
|
|
353
|
+
{ label: 'Confirm and execute', description: 'Proceed with commands' },
|
|
354
|
+
{ label: 'Show details', description: 'View each command' },
|
|
355
|
+
{ label: 'Adjust chain', description: 'Remove or reorder' },
|
|
356
|
+
{ label: 'Cancel', description: 'Abort' }
|
|
357
|
+
]
|
|
358
|
+
}]
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
if (response.confirm === 'Cancel') throw new Error('Cancelled');
|
|
362
|
+
if (response.confirm === 'Show details') {
|
|
363
|
+
displayCommandDetails(chain);
|
|
364
|
+
return getUserConfirmation(chain);
|
|
365
|
+
}
|
|
366
|
+
if (response.confirm === 'Adjust chain') {
|
|
367
|
+
return await adjustChain(chain);
|
|
368
|
+
}
|
|
369
|
+
return chain;
|
|
370
|
+
}
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Phase 3: Execute Sequential Command Chain
|
|
374
|
+
|
|
375
|
+
```javascript
|
|
376
|
+
async function executeCommandChain(chain, analysis) {
|
|
377
|
+
const sessionId = `ccw-coord-${Date.now()}`;
|
|
378
|
+
const stateDir = `.workflow/.ccw-coordinator/${sessionId}`;
|
|
379
|
+
Bash(`mkdir -p "${stateDir}"`);
|
|
380
|
+
|
|
381
|
+
const state = {
|
|
382
|
+
session_id: sessionId,
|
|
383
|
+
status: 'running',
|
|
384
|
+
created_at: new Date().toISOString(),
|
|
385
|
+
updated_at: new Date().toISOString(),
|
|
386
|
+
analysis: analysis,
|
|
387
|
+
command_chain: chain.map((cmd, idx) => ({ ...cmd, index: idx, status: 'pending' })),
|
|
388
|
+
execution_results: [],
|
|
389
|
+
prompts_used: []
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
// Save initial state immediately after confirmation
|
|
393
|
+
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
|
394
|
+
|
|
395
|
+
for (let i = 0; i < chain.length; i++) {
|
|
396
|
+
const cmd = chain[i];
|
|
397
|
+
console.log(`[${i+1}/${chain.length}] ${cmd.command}`);
|
|
398
|
+
|
|
399
|
+
// Update command_chain status to running
|
|
400
|
+
state.command_chain[i].status = 'running';
|
|
401
|
+
state.updated_at = new Date().toISOString();
|
|
402
|
+
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
|
403
|
+
|
|
404
|
+
// Assemble prompt: Command first, then context
|
|
405
|
+
let promptContent = formatCommand(cmd, state.execution_results, analysis);
|
|
406
|
+
|
|
407
|
+
// Build full prompt: Command → Task → Previous Results
|
|
408
|
+
let prompt = `${promptContent}\n\nTask: ${analysis.goal}`;
|
|
409
|
+
if (state.execution_results.length > 0) {
|
|
410
|
+
prompt += '\n\nPrevious results:\n';
|
|
411
|
+
state.execution_results.forEach(r => {
|
|
412
|
+
if (r.session_id) {
|
|
413
|
+
prompt += `- ${r.command}: ${r.session_id} (${r.artifacts?.join(', ') || 'completed'})\n`;
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// Record prompt used
|
|
419
|
+
state.prompts_used.push({
|
|
420
|
+
index: i,
|
|
421
|
+
command: cmd.command,
|
|
422
|
+
prompt: prompt
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
// Execute CLI command in background and stop
|
|
426
|
+
// Format: ccw cli -p "PROMPT" --tool <tool> --mode <mode>
|
|
427
|
+
// Note: -y is a command parameter INSIDE the prompt, not a ccw cli parameter
|
|
428
|
+
// Example prompt: "/workflow:plan -y \"task description here\""
|
|
429
|
+
try {
|
|
430
|
+
const taskId = Bash(
|
|
431
|
+
`ccw cli -p "${escapePrompt(prompt)}" --tool claude --mode write`,
|
|
432
|
+
{ run_in_background: true }
|
|
433
|
+
).task_id;
|
|
434
|
+
|
|
435
|
+
// Save checkpoint
|
|
436
|
+
state.execution_results.push({
|
|
437
|
+
index: i,
|
|
438
|
+
command: cmd.command,
|
|
439
|
+
status: 'in-progress',
|
|
440
|
+
task_id: taskId,
|
|
441
|
+
session_id: null,
|
|
442
|
+
artifacts: [],
|
|
443
|
+
timestamp: new Date().toISOString()
|
|
444
|
+
});
|
|
445
|
+
state.command_chain[i].status = 'running';
|
|
446
|
+
state.updated_at = new Date().toISOString();
|
|
447
|
+
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
|
448
|
+
|
|
449
|
+
console.log(`[${i+1}/${chain.length}] ${cmd.command}\n`);
|
|
450
|
+
break; // Stop, wait for hook callback
|
|
451
|
+
|
|
452
|
+
} catch (error) {
|
|
453
|
+
state.command_chain[i].status = 'failed';
|
|
454
|
+
state.updated_at = new Date().toISOString();
|
|
455
|
+
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
|
456
|
+
|
|
457
|
+
const action = await AskUserQuestion({
|
|
458
|
+
questions: [{
|
|
459
|
+
question: `${cmd.command} failed to start: ${error.message}. What to do?`,
|
|
460
|
+
header: 'Error',
|
|
461
|
+
options: [
|
|
462
|
+
{ label: 'Retry', description: 'Try again' },
|
|
463
|
+
{ label: 'Skip', description: 'Continue next command' },
|
|
464
|
+
{ label: 'Abort', description: 'Stop execution' }
|
|
465
|
+
]
|
|
466
|
+
}]
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
if (action.error === 'Retry') {
|
|
470
|
+
state.command_chain[i].status = 'pending';
|
|
471
|
+
state.execution_results.pop();
|
|
472
|
+
i--;
|
|
473
|
+
} else if (action.error === 'Skip') {
|
|
474
|
+
state.execution_results[state.execution_results.length - 1].status = 'skipped';
|
|
475
|
+
} else if (action.error === 'Abort') {
|
|
476
|
+
state.status = 'failed';
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// Hook callbacks handle completion
|
|
485
|
+
if (state.status !== 'failed') state.status = 'waiting';
|
|
486
|
+
state.updated_at = new Date().toISOString();
|
|
487
|
+
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
|
488
|
+
|
|
489
|
+
console.log(`\n📋 Orchestrator paused: ${state.session_id}\n`);
|
|
490
|
+
return state;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// Smart parameter assembly
|
|
494
|
+
// Returns prompt content to be used with: ccw cli -p "RETURNED_VALUE" --tool claude --mode write
|
|
495
|
+
function formatCommand(cmd, previousResults, analysis) {
|
|
496
|
+
// Format: /workflow:<command> -y <parameters>
|
|
497
|
+
let prompt = `/workflow:${cmd.name} -y`;
|
|
498
|
+
const name = cmd.name;
|
|
499
|
+
|
|
500
|
+
// Planning commands - take task description
|
|
501
|
+
if (['lite-plan', 'plan', 'tdd-plan', 'multi-cli-plan'].includes(name)) {
|
|
502
|
+
prompt += ` "${analysis.goal}"`;
|
|
503
|
+
|
|
504
|
+
// Lite execution - use --in-memory if plan exists
|
|
505
|
+
} else if (name === 'lite-execute') {
|
|
506
|
+
const hasPlan = previousResults.some(r => r.command.includes('plan'));
|
|
507
|
+
prompt += hasPlan ? ' --in-memory' : ` "${analysis.goal}"`;
|
|
508
|
+
|
|
509
|
+
// Standard execution - resume from planning session
|
|
510
|
+
} else if (name === 'execute') {
|
|
511
|
+
const plan = previousResults.find(r => r.command.includes('plan'));
|
|
512
|
+
if (plan?.session_id) prompt += ` --resume-session="${plan.session_id}"`;
|
|
513
|
+
|
|
514
|
+
// Bug fix commands - take bug description
|
|
515
|
+
} else if (['lite-fix', 'debug'].includes(name)) {
|
|
516
|
+
prompt += ` "${analysis.goal}"`;
|
|
517
|
+
|
|
518
|
+
// Brainstorm - take topic description
|
|
519
|
+
} else if (name === 'brainstorm:auto-parallel' || name === 'auto-parallel') {
|
|
520
|
+
prompt += ` "${analysis.goal}"`;
|
|
521
|
+
|
|
522
|
+
// Test generation from session - needs source session
|
|
523
|
+
} else if (name === 'test-gen') {
|
|
524
|
+
const impl = previousResults.find(r =>
|
|
525
|
+
r.command.includes('execute') || r.command.includes('lite-execute')
|
|
526
|
+
);
|
|
527
|
+
if (impl?.session_id) prompt += ` "${impl.session_id}"`;
|
|
528
|
+
else prompt += ` "${analysis.goal}"`;
|
|
529
|
+
|
|
530
|
+
// Test fix generation - session or description
|
|
531
|
+
} else if (name === 'test-fix-gen') {
|
|
532
|
+
const latest = previousResults.filter(r => r.session_id).pop();
|
|
533
|
+
if (latest?.session_id) prompt += ` "${latest.session_id}"`;
|
|
534
|
+
else prompt += ` "${analysis.goal}"`;
|
|
535
|
+
|
|
536
|
+
// Review commands - take session or use latest
|
|
537
|
+
} else if (name === 'review') {
|
|
538
|
+
const latest = previousResults.filter(r => r.session_id).pop();
|
|
539
|
+
if (latest?.session_id) prompt += ` --session="${latest.session_id}"`;
|
|
540
|
+
|
|
541
|
+
// Review fix - takes session from review
|
|
542
|
+
} else if (name === 'review-fix') {
|
|
543
|
+
const review = previousResults.find(r => r.command.includes('review'));
|
|
544
|
+
const latest = review || previousResults.filter(r => r.session_id).pop();
|
|
545
|
+
if (latest?.session_id) prompt += ` --session="${latest.session_id}"`;
|
|
546
|
+
|
|
547
|
+
// TDD verify - takes execution session
|
|
548
|
+
} else if (name === 'tdd-verify') {
|
|
549
|
+
const exec = previousResults.find(r => r.command.includes('execute'));
|
|
550
|
+
if (exec?.session_id) prompt += ` --session="${exec.session_id}"`;
|
|
551
|
+
|
|
552
|
+
// Session-based commands (test-cycle, review-session, plan-verify)
|
|
553
|
+
} else if (name.includes('test') || name.includes('review') || name.includes('verify')) {
|
|
554
|
+
const latest = previousResults.filter(r => r.session_id).pop();
|
|
555
|
+
if (latest?.session_id) prompt += ` --session="${latest.session_id}"`;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return prompt;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// Hook callback: Called when background CLI completes
|
|
562
|
+
async function handleCliCompletion(sessionId, taskId, output) {
|
|
563
|
+
const stateDir = `.workflow/.ccw-coordinator/${sessionId}`;
|
|
564
|
+
const state = JSON.parse(Read(`${stateDir}/state.json`));
|
|
565
|
+
|
|
566
|
+
const pendingIdx = state.execution_results.findIndex(r => r.task_id === taskId);
|
|
567
|
+
if (pendingIdx === -1) {
|
|
568
|
+
console.error(`Unknown task_id: ${taskId}`);
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const parsed = parseOutput(output);
|
|
573
|
+
const cmdIdx = state.execution_results[pendingIdx].index;
|
|
574
|
+
|
|
575
|
+
// Update result
|
|
576
|
+
state.execution_results[pendingIdx] = {
|
|
577
|
+
...state.execution_results[pendingIdx],
|
|
578
|
+
status: parsed.sessionId ? 'completed' : 'failed',
|
|
579
|
+
session_id: parsed.sessionId,
|
|
580
|
+
artifacts: parsed.artifacts,
|
|
581
|
+
completed_at: new Date().toISOString()
|
|
582
|
+
};
|
|
583
|
+
state.command_chain[cmdIdx].status = parsed.sessionId ? 'completed' : 'failed';
|
|
584
|
+
state.updated_at = new Date().toISOString();
|
|
585
|
+
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
|
586
|
+
|
|
587
|
+
// Trigger next command or complete
|
|
588
|
+
const nextIdx = cmdIdx + 1;
|
|
589
|
+
if (nextIdx < state.command_chain.length) {
|
|
590
|
+
await resumeChainExecution(sessionId, nextIdx);
|
|
591
|
+
} else {
|
|
592
|
+
state.status = 'completed';
|
|
593
|
+
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
|
594
|
+
console.log(`✅ Completed: ${sessionId}\n`);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// Parse command output
|
|
599
|
+
function parseOutput(output) {
|
|
600
|
+
const sessionMatch = output.match(/WFS-[\w-]+/);
|
|
601
|
+
const artifacts = [];
|
|
602
|
+
output.matchAll(/\.workflow\/[^\s]+/g).forEach(m => artifacts.push(m[0]));
|
|
603
|
+
return { sessionId: sessionMatch?.[0] || null, artifacts };
|
|
604
|
+
}
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
## State File Structure
|
|
608
|
+
|
|
609
|
+
**Location**: `.workflow/.ccw-coordinator/{session_id}/state.json`
|
|
610
|
+
|
|
611
|
+
```json
|
|
612
|
+
{
|
|
613
|
+
"session_id": "ccw-coord-20250124-143025",
|
|
614
|
+
"status": "running|waiting|completed|failed",
|
|
615
|
+
"created_at": "2025-01-24T14:30:25Z",
|
|
616
|
+
"updated_at": "2025-01-24T14:35:45Z",
|
|
617
|
+
"analysis": {
|
|
618
|
+
"goal": "Implement user registration",
|
|
619
|
+
"scope": ["authentication", "user_management"],
|
|
620
|
+
"constraints": ["no breaking changes"],
|
|
621
|
+
"complexity": "medium"
|
|
622
|
+
},
|
|
623
|
+
"command_chain": [
|
|
624
|
+
{
|
|
625
|
+
"index": 0,
|
|
626
|
+
"command": "/workflow:plan",
|
|
627
|
+
"name": "plan",
|
|
628
|
+
"description": "Detailed planning",
|
|
629
|
+
"argumentHint": "[--explore] \"task\"",
|
|
630
|
+
"status": "completed"
|
|
631
|
+
},
|
|
632
|
+
{
|
|
633
|
+
"index": 1,
|
|
634
|
+
"command": "/workflow:execute",
|
|
635
|
+
"name": "execute",
|
|
636
|
+
"description": "Execute with state resume",
|
|
637
|
+
"argumentHint": "[--resume-session=\"WFS-xxx\"]",
|
|
638
|
+
"status": "completed"
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
"index": 2,
|
|
642
|
+
"command": "/workflow:test-cycle-execute",
|
|
643
|
+
"name": "test-cycle-execute",
|
|
644
|
+
"status": "pending"
|
|
645
|
+
}
|
|
646
|
+
],
|
|
647
|
+
"execution_results": [
|
|
648
|
+
{
|
|
649
|
+
"index": 0,
|
|
650
|
+
"command": "/workflow:plan",
|
|
651
|
+
"status": "completed",
|
|
652
|
+
"task_id": "task-001",
|
|
653
|
+
"session_id": "WFS-plan-20250124",
|
|
654
|
+
"artifacts": ["IMPL_PLAN.md", "exploration-architecture.json"],
|
|
655
|
+
"timestamp": "2025-01-24T14:30:25Z",
|
|
656
|
+
"completed_at": "2025-01-24T14:30:45Z"
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
"index": 1,
|
|
660
|
+
"command": "/workflow:execute",
|
|
661
|
+
"status": "in-progress",
|
|
662
|
+
"task_id": "task-002",
|
|
663
|
+
"session_id": null,
|
|
664
|
+
"artifacts": [],
|
|
665
|
+
"timestamp": "2025-01-24T14:32:00Z",
|
|
666
|
+
"completed_at": null
|
|
667
|
+
}
|
|
668
|
+
],
|
|
669
|
+
"prompts_used": [
|
|
670
|
+
{
|
|
671
|
+
"index": 0,
|
|
672
|
+
"command": "/workflow:plan",
|
|
673
|
+
"prompt": "/workflow:plan -y \"Implement user registration...\"\n\nTask: Implement user registration..."
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
"index": 1,
|
|
677
|
+
"command": "/workflow:execute",
|
|
678
|
+
"prompt": "/workflow:execute -y --resume-session=\"WFS-plan-20250124\"\n\nTask: Implement user registration\n\nPrevious results:\n- /workflow:plan: WFS-plan-20250124 (IMPL_PLAN.md)"
|
|
679
|
+
}
|
|
680
|
+
]
|
|
681
|
+
}
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
### Status Flow
|
|
685
|
+
|
|
686
|
+
```
|
|
687
|
+
running → waiting → [hook callback] → waiting → [hook callback] → completed
|
|
688
|
+
↓ ↑
|
|
689
|
+
failed ←────────────────────────────────────────────────────────────┘
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
**Status Values**:
|
|
693
|
+
- `running`: Orchestrator actively executing (launching CLI commands)
|
|
694
|
+
- `waiting`: Paused, waiting for hook callbacks to trigger continuation
|
|
695
|
+
- `completed`: All commands finished successfully
|
|
696
|
+
- `failed`: User aborted or unrecoverable error
|
|
697
|
+
|
|
698
|
+
### Field Descriptions
|
|
699
|
+
|
|
700
|
+
**execution_results[] fields**:
|
|
701
|
+
- `index`: Command position in chain (0-indexed)
|
|
702
|
+
- `command`: Full command string (e.g., `/workflow:plan`)
|
|
703
|
+
- `status`: `in-progress` | `completed` | `skipped` | `failed`
|
|
704
|
+
- `task_id`: Background task identifier (from Bash tool)
|
|
705
|
+
- `session_id`: Workflow session ID (e.g., `WFS-*`) or null if failed
|
|
706
|
+
- `artifacts`: Generated files/directories
|
|
707
|
+
- `timestamp`: Command start time (ISO 8601)
|
|
708
|
+
- `completed_at`: Command completion time or null if pending
|
|
709
|
+
|
|
710
|
+
**command_chain[] status values**:
|
|
711
|
+
- `pending`: Not started yet
|
|
712
|
+
- `running`: Currently executing
|
|
713
|
+
- `completed`: Successfully finished
|
|
714
|
+
- `failed`: Failed to execute
|
|
715
|
+
|
|
716
|
+
## CommandRegistry Integration
|
|
717
|
+
|
|
718
|
+
Sole CCW tool for command discovery:
|
|
719
|
+
|
|
720
|
+
```javascript
|
|
721
|
+
import { CommandRegistry } from 'ccw/tools/command-registry';
|
|
722
|
+
|
|
723
|
+
const registry = new CommandRegistry();
|
|
724
|
+
|
|
725
|
+
// Get all commands
|
|
726
|
+
const allCommands = registry.getAllCommandsSummary();
|
|
727
|
+
// Map<"/workflow:lite-plan" => {name, description}>
|
|
728
|
+
|
|
729
|
+
// Get categorized
|
|
730
|
+
const byCategory = registry.getAllCommandsByCategory();
|
|
731
|
+
// {planning, execution, testing, review, other}
|
|
732
|
+
|
|
733
|
+
// Get single command metadata
|
|
734
|
+
const cmd = registry.getCommand('lite-plan');
|
|
735
|
+
// {name, command, description, argumentHint, allowedTools, filePath}
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
## Universal Prompt Template
|
|
739
|
+
|
|
740
|
+
### Standard Format
|
|
741
|
+
|
|
742
|
+
```bash
|
|
743
|
+
ccw cli -p "PROMPT_CONTENT" --tool <tool> --mode <mode>
|
|
744
|
+
```
|
|
745
|
+
|
|
746
|
+
### Prompt Content Template
|
|
747
|
+
|
|
748
|
+
```
|
|
749
|
+
/workflow:<command> -y <command_parameters>
|
|
750
|
+
|
|
751
|
+
Task: <task_description>
|
|
752
|
+
|
|
753
|
+
<optional_previous_results>
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
### Template Variables
|
|
757
|
+
|
|
758
|
+
| Variable | Description | Examples |
|
|
759
|
+
|----------|-------------|----------|
|
|
760
|
+
| `<command>` | Workflow command name | `plan`, `lite-execute`, `test-cycle-execute` |
|
|
761
|
+
| `-y` | Auto-confirm flag (inside prompt) | Always include for automation |
|
|
762
|
+
| `<command_parameters>` | Command-specific parameters | Task description, session ID, flags |
|
|
763
|
+
| `<task_description>` | Brief task description | "Implement user authentication", "Fix memory leak" |
|
|
764
|
+
| `<optional_previous_results>` | Context from previous commands | "Previous results:\n- /workflow:plan: WFS-xxx" |
|
|
765
|
+
|
|
766
|
+
### Command Parameter Patterns
|
|
767
|
+
|
|
768
|
+
| Command Type | Parameter Pattern | Example |
|
|
769
|
+
|--------------|------------------|---------|
|
|
770
|
+
| **Planning** | `"task description"` | `/workflow:plan -y "Implement OAuth2"` |
|
|
771
|
+
| **Execution (with plan)** | `--resume-session="WFS-xxx"` | `/workflow:execute -y --resume-session="WFS-plan-001"` |
|
|
772
|
+
| **Execution (standalone)** | `--in-memory` or `"task"` | `/workflow:lite-execute -y --in-memory` |
|
|
773
|
+
| **Session-based** | `--session="WFS-xxx"` | `/workflow:test-fix-gen -y --session="WFS-impl-001"` |
|
|
774
|
+
| **Fix/Debug** | `"problem description"` | `/workflow:lite-fix -y "Fix timeout bug"` |
|
|
775
|
+
|
|
776
|
+
### Complete Examples
|
|
777
|
+
|
|
778
|
+
**Planning Command**:
|
|
779
|
+
```bash
|
|
780
|
+
ccw cli -p '/workflow:plan -y "Implement user registration with email validation"
|
|
781
|
+
|
|
782
|
+
Task: Implement user registration' --tool claude --mode write
|
|
783
|
+
```
|
|
784
|
+
|
|
785
|
+
**Execution with Context**:
|
|
786
|
+
```bash
|
|
787
|
+
ccw cli -p '/workflow:execute -y --resume-session="WFS-plan-20250124"
|
|
788
|
+
|
|
789
|
+
Task: Implement user registration
|
|
790
|
+
|
|
791
|
+
Previous results:
|
|
792
|
+
- /workflow:plan: WFS-plan-20250124 (IMPL_PLAN.md)' --tool claude --mode write
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
**Standalone Lite Execution**:
|
|
796
|
+
```bash
|
|
797
|
+
ccw cli -p '/workflow:lite-fix -y "Fix login timeout in auth module"
|
|
798
|
+
|
|
799
|
+
Task: Fix login timeout' --tool claude --mode write
|
|
800
|
+
```
|
|
801
|
+
|
|
802
|
+
## Execution Flow
|
|
803
|
+
|
|
804
|
+
```javascript
|
|
805
|
+
// Main entry point
|
|
806
|
+
async function ccwCoordinator(taskDescription) {
|
|
807
|
+
// Phase 1
|
|
808
|
+
const analysis = await analyzeRequirements(taskDescription);
|
|
809
|
+
|
|
810
|
+
// Phase 2
|
|
811
|
+
const chain = await recommendCommandChain(analysis);
|
|
812
|
+
const confirmedChain = await getUserConfirmation(chain);
|
|
813
|
+
|
|
814
|
+
// Phase 3
|
|
815
|
+
const state = await executeCommandChain(confirmedChain, analysis);
|
|
816
|
+
|
|
817
|
+
console.log(`✅ Complete! Session: ${state.session_id}`);
|
|
818
|
+
console.log(`State: .workflow/.ccw-coordinator/${state.session_id}/state.json`);
|
|
819
|
+
}
|
|
820
|
+
```
|
|
821
|
+
|
|
822
|
+
## Key Design Principles
|
|
823
|
+
|
|
824
|
+
1. **No Fixed Logic** - Claude intelligently decides based on analysis
|
|
825
|
+
2. **Dynamic Discovery** - CommandRegistry retrieves available commands
|
|
826
|
+
3. **Smart Parameters** - Command args assembled based on previous results
|
|
827
|
+
4. **Full State Tracking** - All execution recorded to state.json
|
|
828
|
+
5. **User Control** - Confirmation + error handling with user choice
|
|
829
|
+
6. **Context Passing** - Each prompt includes previous results
|
|
830
|
+
7. **Resumable** - Can load state.json to continue
|
|
831
|
+
8. **Serial Blocking** - Commands execute one-by-one with hook-based continuation
|
|
832
|
+
|
|
833
|
+
## CLI Execution Model
|
|
834
|
+
|
|
835
|
+
### CLI Invocation Format
|
|
836
|
+
|
|
837
|
+
**IMPORTANT**: The `ccw cli` command executes prompts through external tools. The format is:
|
|
838
|
+
|
|
839
|
+
```bash
|
|
840
|
+
ccw cli -p "PROMPT_CONTENT" --tool <tool> --mode <mode>
|
|
841
|
+
```
|
|
842
|
+
|
|
843
|
+
**Parameters**:
|
|
844
|
+
- `-p "PROMPT_CONTENT"`: The prompt content to execute (required)
|
|
845
|
+
- `--tool <tool>`: CLI tool to use (e.g., `claude`, `gemini`, `qwen`)
|
|
846
|
+
- `--mode <mode>`: Execution mode (`analysis` or `write`)
|
|
847
|
+
|
|
848
|
+
**Note**: `-y` is a **command parameter inside the prompt**, NOT a `ccw cli` parameter.
|
|
849
|
+
|
|
850
|
+
### Prompt Assembly
|
|
851
|
+
|
|
852
|
+
The prompt content MUST start with the workflow command, followed by task context:
|
|
853
|
+
|
|
854
|
+
```
|
|
855
|
+
/workflow:<command> -y <parameters>
|
|
856
|
+
|
|
857
|
+
Task: <description>
|
|
858
|
+
|
|
859
|
+
<optional_context>
|
|
860
|
+
```
|
|
861
|
+
|
|
862
|
+
**Examples**:
|
|
863
|
+
```bash
|
|
864
|
+
# Planning command
|
|
865
|
+
ccw cli -p '/workflow:plan -y "Implement user registration feature"
|
|
866
|
+
|
|
867
|
+
Task: Implement user registration' --tool claude --mode write
|
|
868
|
+
|
|
869
|
+
# Execution command (with session reference)
|
|
870
|
+
ccw cli -p '/workflow:execute -y --resume-session="WFS-plan-20250124"
|
|
871
|
+
|
|
872
|
+
Task: Implement user registration
|
|
873
|
+
|
|
874
|
+
Previous results:
|
|
875
|
+
- /workflow:plan: WFS-plan-20250124' --tool claude --mode write
|
|
876
|
+
|
|
877
|
+
# Lite execution (in-memory from previous plan)
|
|
878
|
+
ccw cli -p '/workflow:lite-execute -y --in-memory
|
|
879
|
+
|
|
880
|
+
Task: Implement user registration' --tool claude --mode write
|
|
881
|
+
```
|
|
882
|
+
|
|
883
|
+
### Serial Blocking
|
|
884
|
+
|
|
885
|
+
Commands execute one-by-one. After launching CLI in background, orchestrator stops immediately and waits for hook callback.
|
|
886
|
+
|
|
887
|
+
**Prompt Structure**: Command must be first in prompt content
|
|
888
|
+
|
|
889
|
+
```javascript
|
|
890
|
+
// Example: Execute command and stop
|
|
891
|
+
const prompt = '/workflow:plan -y "Implement user authentication"\n\nTask: Implement user auth system';
|
|
892
|
+
const taskId = Bash(`ccw cli -p "${prompt}" --tool claude --mode write`, { run_in_background: true }).task_id;
|
|
893
|
+
state.execution_results.push({ status: 'in-progress', task_id: taskId, ... });
|
|
894
|
+
Write(`${stateDir}/state.json`, JSON.stringify(state, null, 2));
|
|
895
|
+
break; // Stop, wait for hook callback
|
|
896
|
+
|
|
897
|
+
// Hook calls handleCliCompletion(sessionId, taskId, output) when done
|
|
898
|
+
// → Updates state → Triggers next command via resumeChainExecution()
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
## Available Commands
|
|
902
|
+
|
|
903
|
+
All from `~/.claude/commands/workflow/`:
|
|
904
|
+
|
|
905
|
+
**Planning**: lite-plan, plan, multi-cli-plan, plan-verify, tdd-plan
|
|
906
|
+
**Execution**: lite-execute, execute, develop-with-file
|
|
907
|
+
**Testing**: test-cycle-execute, test-gen, test-fix-gen, tdd-verify
|
|
908
|
+
**Review**: review, review-session-cycle, review-module-cycle, review-fix
|
|
909
|
+
**Bug Fixes**: lite-fix, debug, debug-with-file
|
|
910
|
+
**Brainstorming**: brainstorm:auto-parallel, brainstorm:artifacts, brainstorm:synthesis
|
|
911
|
+
**Design**: ui-design:*, animation-extract, layout-extract, style-extract, codify-style
|
|
912
|
+
**Session Management**: session:start, session:resume, session:complete, session:solidify, session:list
|
|
913
|
+
**Tools**: context-gather, test-context-gather, task-generate, conflict-resolution, action-plan-verify
|
|
914
|
+
**Utility**: clean, init, replan
|
|
915
|
+
|
|
916
|
+
### Testing Commands Distinction
|
|
917
|
+
|
|
918
|
+
| Command | Purpose | Output | Follow-up |
|
|
919
|
+
|---------|---------|--------|-----------|
|
|
920
|
+
| **test-gen** | 广泛测试示例生成并进行测试 | test-tasks (IMPL-001, IMPL-002) | `/workflow:execute` |
|
|
921
|
+
| **test-fix-gen** | 针对特定问题生成测试并在测试中修正 | test-tasks | `/workflow:test-cycle-execute` |
|
|
922
|
+
| **test-cycle-execute** | 执行测试周期(迭代测试和修复) | test-passed | N/A (终点) |
|
|
923
|
+
|
|
924
|
+
**流程说明**:
|
|
925
|
+
- **test-gen → execute**: 生成全面的测试套件,execute 执行生成和测试
|
|
926
|
+
- **test-fix-gen → test-cycle-execute**: 针对特定问题生成修复任务,test-cycle-execute 迭代测试和修复直到通过
|
|
927
|
+
|
|
928
|
+
### Task Type Routing (Pipeline Summary)
|
|
929
|
+
|
|
930
|
+
**Note**: `【 】` marks Minimum Execution Units (最小执行单元) - these commands must execute together.
|
|
931
|
+
|
|
932
|
+
| Task Type | Pipeline | Minimum Units |
|
|
933
|
+
|-----------|----------|---|
|
|
934
|
+
| **feature** (simple) | 需求 →【lite-plan → lite-execute】→ 代码 →【test-fix-gen → test-cycle-execute】→ 测试通过 | Quick Implementation + Test Validation |
|
|
935
|
+
| **feature** (complex) | 需求 →【plan → plan-verify】→ validate → execute → 代码 → review → fix | Full Planning + Code Review + Testing |
|
|
936
|
+
| **bugfix** | Bug报告 → lite-fix → 修复代码 →【test-fix-gen → test-cycle-execute】→ 测试通过 | Bug Fix + Test Validation |
|
|
937
|
+
| **tdd** | 需求 → tdd-plan → TDD任务 → execute → 代码 → tdd-verify | TDD Planning + Execution |
|
|
938
|
+
| **test-fix** | 失败测试 →【test-fix-gen → test-cycle-execute】→ 测试通过 | Test Validation |
|
|
939
|
+
| **test-gen** | 代码/会话 →【test-gen → execute】→ 测试通过 | Test Generation + Execution |
|
|
940
|
+
| **review** | 代码 →【review-* → review-fix】→ 修复代码 →【test-fix-gen → test-cycle-execute】→ 测试通过 | Code Review + Testing |
|
|
941
|
+
| **brainstorm** | 探索主题 → brainstorm → 分析 →【plan → plan-verify】→ execute → test | Exploration + Planning + Execution |
|
|
942
|
+
| **multi-cli** | 需求 → multi-cli-plan → 对比分析 → lite-execute → test | Multi-Perspective + Testing |
|
|
943
|
+
|
|
944
|
+
Use `CommandRegistry.getAllCommandsSummary()` to discover all commands dynamically.
|