claude-code-workflow 6.3.36 → 6.3.38
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/workflow/lite-execute.md +2 -0
- package/.claude/commands/workflow/lite-fix.md +108 -9
- package/.claude/skills/ccw-loop/README.md +303 -0
- package/.claude/skills/ccw-loop/SKILL.md +259 -0
- package/.claude/skills/ccw-loop/phases/actions/action-complete.md +320 -0
- package/.claude/skills/ccw-loop/phases/actions/action-debug-with-file.md +485 -0
- package/.claude/skills/ccw-loop/phases/actions/action-develop-with-file.md +365 -0
- package/.claude/skills/ccw-loop/phases/actions/action-init.md +200 -0
- package/.claude/skills/ccw-loop/phases/actions/action-menu.md +192 -0
- package/.claude/skills/ccw-loop/phases/actions/action-validate-with-file.md +307 -0
- package/.claude/skills/ccw-loop/phases/orchestrator.md +486 -0
- package/.claude/skills/ccw-loop/phases/state-schema.md +474 -0
- package/.claude/skills/ccw-loop/specs/action-catalog.md +300 -0
- package/.claude/skills/ccw-loop/specs/loop-requirements.md +192 -0
- package/.claude/skills/ccw-loop/templates/progress-template.md +175 -0
- package/.claude/skills/ccw-loop/templates/understanding-template.md +303 -0
- package/.claude/skills/ccw-loop/templates/validation-template.md +258 -0
- package/.codex/agents/action-planning-agent.md +885 -0
- package/.codex/agents/ccw-loop-executor.md +260 -0
- package/.codex/agents/cli-discuss-agent.md +391 -0
- package/.codex/agents/cli-execution-agent.md +333 -0
- package/.codex/agents/cli-explore-agent.md +186 -0
- package/.codex/agents/cli-lite-planning-agent.md +736 -0
- package/.codex/agents/cli-planning-agent.md +562 -0
- package/.codex/agents/code-developer.md +408 -0
- package/.codex/agents/conceptual-planning-agent.md +321 -0
- package/.codex/agents/context-search-agent.md +585 -0
- package/.codex/agents/debug-explore-agent.md +436 -0
- package/.codex/agents/doc-generator.md +334 -0
- package/.codex/agents/issue-plan-agent.md +417 -0
- package/.codex/agents/issue-queue-agent.md +311 -0
- package/.codex/agents/memory-bridge.md +96 -0
- package/.codex/agents/test-context-search-agent.md +402 -0
- package/.codex/agents/test-fix-agent.md +359 -0
- package/.codex/agents/ui-design-agent.md +595 -0
- package/.codex/agents/universal-executor.md +135 -0
- package/.codex/prompts/issue-discover-by-prompt.md +364 -0
- package/.codex/prompts/issue-discover.md +261 -0
- package/.codex/prompts/issue-execute.md +10 -0
- package/.codex/prompts/issue-new.md +285 -0
- package/.codex/prompts/issue-plan.md +161 -63
- package/.codex/prompts/issue-queue.md +298 -288
- package/.codex/prompts/lite-execute.md +627 -133
- package/.codex/prompts/lite-fix.md +670 -0
- package/.codex/prompts/lite-plan-a.md +337 -0
- package/.codex/prompts/lite-plan-b.md +485 -0
- package/.codex/prompts/{lite-plan.md → lite-plan-c.md} +601 -469
- package/.codex/skills/ccw-loop/README.md +171 -0
- package/.codex/skills/ccw-loop/SKILL.md +349 -0
- package/.codex/skills/ccw-loop/phases/actions/action-complete.md +269 -0
- package/.codex/skills/ccw-loop/phases/actions/action-debug.md +286 -0
- package/.codex/skills/ccw-loop/phases/actions/action-develop.md +183 -0
- package/.codex/skills/ccw-loop/phases/actions/action-init.md +164 -0
- package/.codex/skills/ccw-loop/phases/actions/action-menu.md +205 -0
- package/.codex/skills/ccw-loop/phases/actions/action-validate.md +250 -0
- package/.codex/skills/ccw-loop/phases/orchestrator.md +416 -0
- package/.codex/skills/ccw-loop/phases/state-schema.md +388 -0
- package/.codex/skills/ccw-loop/specs/action-catalog.md +182 -0
- package/.codex/skills/ccw-loop-b/README.md +102 -0
- package/.codex/skills/ccw-loop-b/SKILL.md +322 -0
- package/.codex/skills/ccw-loop-b/phases/orchestrator.md +257 -0
- package/.codex/skills/ccw-loop-b/phases/state-schema.md +181 -0
- package/ccw/dist/cli.d.ts.map +1 -1
- package/ccw/dist/cli.js +12 -1
- package/ccw/dist/cli.js.map +1 -1
- package/ccw/dist/commands/cli.d.ts.map +1 -1
- package/ccw/dist/commands/cli.js +14 -1
- package/ccw/dist/commands/cli.js.map +1 -1
- package/ccw/dist/commands/install.d.ts.map +1 -1
- package/ccw/dist/commands/install.js +38 -7
- package/ccw/dist/commands/install.js.map +1 -1
- package/ccw/dist/commands/issue.d.ts +3 -0
- package/ccw/dist/commands/issue.d.ts.map +1 -1
- package/ccw/dist/commands/issue.js +107 -0
- package/ccw/dist/commands/issue.js.map +1 -1
- package/ccw/dist/commands/loop.d.ts +10 -0
- package/ccw/dist/commands/loop.d.ts.map +1 -0
- package/ccw/dist/commands/loop.js +289 -0
- package/ccw/dist/commands/loop.js.map +1 -0
- package/ccw/dist/commands/upgrade.js +1 -1
- package/ccw/dist/commands/upgrade.js.map +1 -1
- package/ccw/dist/config/litellm-api-config-manager.d.ts.map +1 -1
- package/ccw/dist/config/litellm-api-config-manager.js +3 -2
- package/ccw/dist/config/litellm-api-config-manager.js.map +1 -1
- package/ccw/dist/core/dashboard-generator.d.ts.map +1 -1
- package/ccw/dist/core/dashboard-generator.js +4 -1
- package/ccw/dist/core/dashboard-generator.js.map +1 -1
- package/ccw/dist/core/memory-embedder-bridge.d.ts.map +1 -1
- package/ccw/dist/core/memory-embedder-bridge.js +2 -5
- package/ccw/dist/core/memory-embedder-bridge.js.map +1 -1
- package/ccw/dist/core/routes/claude-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/claude-routes.js +5 -3
- package/ccw/dist/core/routes/claude-routes.js.map +1 -1
- package/ccw/dist/core/routes/cli-routes.d.ts +6 -0
- package/ccw/dist/core/routes/cli-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/cli-routes.js +42 -13
- package/ccw/dist/core/routes/cli-routes.js.map +1 -1
- package/ccw/dist/core/routes/cli-settings-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/cli-settings-routes.js +44 -0
- package/ccw/dist/core/routes/cli-settings-routes.js.map +1 -1
- package/ccw/dist/core/routes/codexlens/config-handlers.d.ts.map +1 -1
- package/ccw/dist/core/routes/codexlens/config-handlers.js +7 -6
- package/ccw/dist/core/routes/codexlens/config-handlers.js.map +1 -1
- package/ccw/dist/core/routes/codexlens/semantic-handlers.d.ts.map +1 -1
- package/ccw/dist/core/routes/codexlens/semantic-handlers.js +5 -4
- package/ccw/dist/core/routes/codexlens/semantic-handlers.js.map +1 -1
- package/ccw/dist/core/routes/core-memory-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/core-memory-routes.js +4 -2
- package/ccw/dist/core/routes/core-memory-routes.js.map +1 -1
- package/ccw/dist/core/routes/files-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/files-routes.js +4 -2
- package/ccw/dist/core/routes/files-routes.js.map +1 -1
- package/ccw/dist/core/routes/graph-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/graph-routes.js +17 -2
- package/ccw/dist/core/routes/graph-routes.js.map +1 -1
- package/ccw/dist/core/routes/issue-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/issue-routes.js +280 -33
- package/ccw/dist/core/routes/issue-routes.js.map +1 -1
- package/ccw/dist/core/routes/loop-routes.d.ts +24 -0
- package/ccw/dist/core/routes/loop-routes.d.ts.map +1 -0
- package/ccw/dist/core/routes/loop-routes.js +334 -0
- package/ccw/dist/core/routes/loop-routes.js.map +1 -0
- package/ccw/dist/core/routes/loop-v2-routes.d.ts +44 -0
- package/ccw/dist/core/routes/loop-v2-routes.d.ts.map +1 -0
- package/ccw/dist/core/routes/loop-v2-routes.js +1260 -0
- package/ccw/dist/core/routes/loop-v2-routes.js.map +1 -0
- package/ccw/dist/core/routes/memory-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/memory-routes.js +2 -1
- package/ccw/dist/core/routes/memory-routes.js.map +1 -1
- package/ccw/dist/core/routes/system-routes.d.ts.map +1 -1
- package/ccw/dist/core/routes/system-routes.js +3 -2
- package/ccw/dist/core/routes/system-routes.js.map +1 -1
- package/ccw/dist/core/routes/task-routes.d.ts +12 -0
- package/ccw/dist/core/routes/task-routes.d.ts.map +1 -0
- package/ccw/dist/core/routes/task-routes.js +321 -0
- package/ccw/dist/core/routes/task-routes.js.map +1 -0
- package/ccw/dist/core/routes/test-loop-routes.d.ts +11 -0
- package/ccw/dist/core/routes/test-loop-routes.d.ts.map +1 -0
- package/ccw/dist/core/routes/test-loop-routes.js +298 -0
- package/ccw/dist/core/routes/test-loop-routes.js.map +1 -0
- package/ccw/dist/core/server.d.ts.map +1 -1
- package/ccw/dist/core/server.js +47 -5
- package/ccw/dist/core/server.js.map +1 -1
- package/ccw/dist/core/websocket.d.ts +59 -0
- package/ccw/dist/core/websocket.d.ts.map +1 -1
- package/ccw/dist/core/websocket.js +34 -0
- package/ccw/dist/core/websocket.js.map +1 -1
- package/ccw/dist/tools/claude-cli-tools.d.ts +40 -0
- package/ccw/dist/tools/claude-cli-tools.d.ts.map +1 -1
- package/ccw/dist/tools/claude-cli-tools.js +119 -0
- package/ccw/dist/tools/claude-cli-tools.js.map +1 -1
- package/ccw/dist/tools/codex-lens-lsp.d.ts.map +1 -1
- package/ccw/dist/tools/codex-lens-lsp.js +2 -5
- package/ccw/dist/tools/codex-lens-lsp.js.map +1 -1
- package/ccw/dist/tools/codex-lens.d.ts.map +1 -1
- package/ccw/dist/tools/codex-lens.js +22 -32
- package/ccw/dist/tools/codex-lens.js.map +1 -1
- package/ccw/dist/tools/litellm-client.d.ts +6 -0
- package/ccw/dist/tools/litellm-client.d.ts.map +1 -1
- package/ccw/dist/tools/litellm-client.js +15 -2
- package/ccw/dist/tools/litellm-client.js.map +1 -1
- package/ccw/dist/tools/loop-manager.d.ts +84 -0
- package/ccw/dist/tools/loop-manager.d.ts.map +1 -0
- package/ccw/dist/tools/loop-manager.js +425 -0
- package/ccw/dist/tools/loop-manager.js.map +1 -0
- package/ccw/dist/tools/loop-state-manager.d.ts +47 -0
- package/ccw/dist/tools/loop-state-manager.d.ts.map +1 -0
- package/ccw/dist/tools/loop-state-manager.js +149 -0
- package/ccw/dist/tools/loop-state-manager.js.map +1 -0
- package/ccw/dist/tools/loop-task-manager.d.ts +149 -0
- package/ccw/dist/tools/loop-task-manager.d.ts.map +1 -0
- package/ccw/dist/tools/loop-task-manager.js +270 -0
- package/ccw/dist/tools/loop-task-manager.js.map +1 -0
- package/ccw/dist/tools/native-session-discovery.d.ts.map +1 -1
- package/ccw/dist/tools/native-session-discovery.js +35 -7
- package/ccw/dist/tools/native-session-discovery.js.map +1 -1
- package/ccw/dist/types/index.d.ts +1 -0
- package/ccw/dist/types/index.d.ts.map +1 -1
- package/ccw/dist/types/index.js +1 -0
- package/ccw/dist/types/index.js.map +1 -1
- package/ccw/dist/types/loop.d.ts +257 -0
- package/ccw/dist/types/loop.d.ts.map +1 -0
- package/ccw/dist/types/loop.js +17 -0
- package/ccw/dist/types/loop.js.map +1 -0
- package/ccw/dist/utils/codexlens-path.d.ts +36 -0
- package/ccw/dist/utils/codexlens-path.d.ts.map +1 -0
- package/ccw/dist/utils/codexlens-path.js +56 -0
- package/ccw/dist/utils/codexlens-path.js.map +1 -0
- package/ccw/dist/utils/uv-manager.d.ts.map +1 -1
- package/ccw/dist/utils/uv-manager.js +3 -2
- package/ccw/dist/utils/uv-manager.js.map +1 -1
- package/ccw/src/cli.ts +13 -1
- package/ccw/src/commands/cli.ts +14 -1
- package/ccw/src/commands/install.ts +50 -7
- package/ccw/src/commands/issue.ts +119 -0
- package/ccw/src/commands/loop.ts +344 -0
- package/ccw/src/commands/upgrade.ts +1 -1
- package/ccw/src/config/litellm-api-config-manager.ts +3 -2
- package/ccw/src/core/dashboard-generator.ts +4 -1
- package/ccw/src/core/memory-embedder-bridge.ts +2 -6
- package/ccw/src/core/routes/claude-routes.ts +5 -3
- package/ccw/src/core/routes/cli-routes.ts +48 -16
- package/ccw/src/core/routes/cli-settings-routes.ts +47 -0
- package/ccw/src/core/routes/codexlens/config-handlers.ts +7 -6
- package/ccw/src/core/routes/codexlens/semantic-handlers.ts +5 -4
- package/ccw/src/core/routes/core-memory-routes.ts +4 -2
- package/ccw/src/core/routes/files-routes.ts +4 -2
- package/ccw/src/core/routes/graph-routes.ts +18 -2
- package/ccw/src/core/routes/issue-routes.ts +308 -33
- package/ccw/src/core/routes/loop-routes.ts +386 -0
- package/ccw/src/core/routes/loop-v2-routes.ts +1470 -0
- package/ccw/src/core/routes/memory-routes.ts +2 -1
- package/ccw/src/core/routes/system-routes.ts +3 -2
- package/ccw/src/core/routes/task-routes.ts +361 -0
- package/ccw/src/core/routes/test-loop-routes.ts +312 -0
- package/ccw/src/core/server.ts +49 -5
- package/ccw/src/core/websocket.ts +104 -0
- package/ccw/src/templates/dashboard-css/02-session.css +2 -0
- package/ccw/src/templates/dashboard-css/04-lite-tasks.css +103 -1
- package/ccw/src/templates/dashboard-css/12-cli-legacy.css +56 -0
- package/ccw/src/templates/dashboard-css/32-issue-manager.css +32 -0
- package/ccw/src/templates/dashboard-css/33-cli-stream-viewer.css +55 -0
- package/ccw/src/templates/dashboard-css/36-loop-monitor.css +1896 -0
- package/ccw/src/templates/dashboard-css/36-loop-monitor.css.backup +1877 -0
- package/ccw/src/templates/dashboard-js/components/cli-history.js +48 -48
- package/ccw/src/templates/dashboard-js/components/cli-status.js +64 -3
- package/ccw/src/templates/dashboard-js/components/cli-stream-viewer.js +251 -110
- package/ccw/src/templates/dashboard-js/components/navigation.js +16 -0
- package/ccw/src/templates/dashboard-js/components/notifications.js +22 -0
- package/ccw/src/templates/dashboard-js/components/version-check.js +38 -0
- package/ccw/src/templates/dashboard-js/i18n.js +601 -1
- package/ccw/src/templates/dashboard-js/state.js +2 -0
- package/ccw/src/templates/dashboard-js/views/cli-manager.js +4 -3
- package/ccw/src/templates/dashboard-js/views/issue-manager.js +183 -1
- package/ccw/src/templates/dashboard-js/views/lite-tasks.js +55 -11
- package/ccw/src/templates/dashboard-js/views/loop-monitor.js +3345 -0
- package/ccw/src/templates/dashboard.html +68 -4
- package/ccw/src/tools/claude-cli-tools.ts +143 -0
- package/ccw/src/tools/codex-lens-lsp.ts +2 -5
- package/ccw/src/tools/codex-lens.ts +27 -38
- package/ccw/src/tools/litellm-client.ts +16 -2
- package/ccw/src/tools/loop-manager.ts +519 -0
- package/ccw/src/tools/loop-state-manager.ts +173 -0
- package/ccw/src/tools/loop-task-manager.ts +391 -0
- package/ccw/src/tools/native-session-discovery.ts +38 -7
- package/ccw/src/types/index.ts +1 -0
- package/ccw/src/types/loop.ts +316 -0
- package/ccw/src/utils/codexlens-path.ts +60 -0
- package/ccw/src/utils/uv-manager.ts +3 -2
- package/package.json +1 -1
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Hybrid orchestrator pattern for iterative development. Coordinator + specialized workers with batch wait support. Triggers on "ccw-loop-b".
|
|
3
|
+
argument-hint: TASK="<task description>" [--loop-id=<id>] [--mode=<interactive|auto|parallel>]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# CCW Loop-B - Hybrid Orchestrator Pattern
|
|
7
|
+
|
|
8
|
+
协调器 + 专用 worker 的迭代开发工作流。支持单 agent 深度交互、多 agent 并行、混合模式灵活切换。
|
|
9
|
+
|
|
10
|
+
## Arguments
|
|
11
|
+
|
|
12
|
+
| Arg | Required | Description |
|
|
13
|
+
|-----|----------|-------------|
|
|
14
|
+
| TASK | No | Task description (for new loop) |
|
|
15
|
+
| --loop-id | No | Existing loop ID to continue |
|
|
16
|
+
| --mode | No | `interactive` (default) / `auto` / `parallel` |
|
|
17
|
+
|
|
18
|
+
## Architecture
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
+------------------------------------------------------------+
|
|
22
|
+
| Main Coordinator |
|
|
23
|
+
| 职责: 状态管理 + worker 调度 + 结果汇聚 + 用户交互 |
|
|
24
|
+
+------------------------------------------------------------+
|
|
25
|
+
|
|
|
26
|
+
+--------------------+--------------------+
|
|
27
|
+
| | |
|
|
28
|
+
v v v
|
|
29
|
+
+----------------+ +----------------+ +----------------+
|
|
30
|
+
| Worker-Develop | | Worker-Debug | | Worker-Validate|
|
|
31
|
+
| 专注: 代码实现 | | 专注: 问题诊断 | | 专注: 测试验证 |
|
|
32
|
+
+----------------+ +----------------+ +----------------+
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Execution Modes
|
|
36
|
+
|
|
37
|
+
### Mode: Interactive (default)
|
|
38
|
+
|
|
39
|
+
协调器展示菜单,用户选择 action,spawn 对应 worker 执行。
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
Coordinator -> Show menu -> User selects -> spawn worker -> wait -> Display result -> Loop
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Mode: Auto
|
|
46
|
+
|
|
47
|
+
自动按预设顺序执行,worker 完成后自动切换到下一阶段。
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
Init -> Develop -> [if issues] Debug -> Validate -> [if fail] Loop back -> Complete
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Mode: Parallel
|
|
54
|
+
|
|
55
|
+
并行 spawn 多个 worker 分析不同维度,batch wait 汇聚结果。
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
Coordinator -> spawn [develop, debug, validate] in parallel -> wait({ ids: all }) -> Merge -> Decide
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Session Structure
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
.loop/
|
|
65
|
+
+-- {loopId}.json # Master state
|
|
66
|
+
+-- {loopId}.workers/ # Worker outputs
|
|
67
|
+
| +-- develop.output.json
|
|
68
|
+
| +-- debug.output.json
|
|
69
|
+
| +-- validate.output.json
|
|
70
|
+
+-- {loopId}.progress/ # Human-readable progress
|
|
71
|
+
+-- develop.md
|
|
72
|
+
+-- debug.md
|
|
73
|
+
+-- validate.md
|
|
74
|
+
+-- summary.md
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Subagent API
|
|
78
|
+
|
|
79
|
+
| API | 作用 |
|
|
80
|
+
|-----|------|
|
|
81
|
+
| `spawn_agent({ message })` | 创建 agent,返回 `agent_id` |
|
|
82
|
+
| `wait({ ids, timeout_ms })` | 等待结果(唯一取结果入口) |
|
|
83
|
+
| `send_input({ id, message })` | 继续交互 |
|
|
84
|
+
| `close_agent({ id })` | 关闭回收 |
|
|
85
|
+
|
|
86
|
+
## Implementation
|
|
87
|
+
|
|
88
|
+
### Coordinator Logic
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
// ==================== HYBRID ORCHESTRATOR ====================
|
|
92
|
+
|
|
93
|
+
// 1. Initialize
|
|
94
|
+
const loopId = args['--loop-id'] || generateLoopId()
|
|
95
|
+
const mode = args['--mode'] || 'interactive'
|
|
96
|
+
let state = readOrCreateState(loopId, taskDescription)
|
|
97
|
+
|
|
98
|
+
// 2. Mode selection
|
|
99
|
+
switch (mode) {
|
|
100
|
+
case 'interactive':
|
|
101
|
+
await runInteractiveMode(loopId, state)
|
|
102
|
+
break
|
|
103
|
+
|
|
104
|
+
case 'auto':
|
|
105
|
+
await runAutoMode(loopId, state)
|
|
106
|
+
break
|
|
107
|
+
|
|
108
|
+
case 'parallel':
|
|
109
|
+
await runParallelMode(loopId, state)
|
|
110
|
+
break
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Interactive Mode (单 agent 交互或按需 spawn worker)
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
async function runInteractiveMode(loopId, state) {
|
|
118
|
+
while (state.status === 'running') {
|
|
119
|
+
// Show menu, get user choice
|
|
120
|
+
const action = await showMenuAndGetChoice(state)
|
|
121
|
+
|
|
122
|
+
if (action === 'exit') break
|
|
123
|
+
|
|
124
|
+
// Spawn specialized worker for the action
|
|
125
|
+
const workerId = spawn_agent({
|
|
126
|
+
message: buildWorkerPrompt(action, loopId, state)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
// Wait for worker completion
|
|
130
|
+
const result = wait({ ids: [workerId], timeout_ms: 600000 })
|
|
131
|
+
const output = result.status[workerId].completed
|
|
132
|
+
|
|
133
|
+
// Update state and display result
|
|
134
|
+
state = updateState(loopId, action, output)
|
|
135
|
+
displayResult(output)
|
|
136
|
+
|
|
137
|
+
// Cleanup worker
|
|
138
|
+
close_agent({ id: workerId })
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Auto Mode (顺序执行 worker 链)
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
async function runAutoMode(loopId, state) {
|
|
147
|
+
const actionSequence = ['init', 'develop', 'debug', 'validate', 'complete']
|
|
148
|
+
let currentIndex = state.skill_state?.action_index || 0
|
|
149
|
+
|
|
150
|
+
while (currentIndex < actionSequence.length && state.status === 'running') {
|
|
151
|
+
const action = actionSequence[currentIndex]
|
|
152
|
+
|
|
153
|
+
// Spawn worker
|
|
154
|
+
const workerId = spawn_agent({
|
|
155
|
+
message: buildWorkerPrompt(action, loopId, state)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
const result = wait({ ids: [workerId], timeout_ms: 600000 })
|
|
159
|
+
const output = result.status[workerId].completed
|
|
160
|
+
|
|
161
|
+
// Parse worker result to determine next step
|
|
162
|
+
const workerResult = parseWorkerResult(output)
|
|
163
|
+
|
|
164
|
+
// Update state
|
|
165
|
+
state = updateState(loopId, action, output)
|
|
166
|
+
|
|
167
|
+
close_agent({ id: workerId })
|
|
168
|
+
|
|
169
|
+
// Determine next action
|
|
170
|
+
if (workerResult.needs_loop_back) {
|
|
171
|
+
// Loop back to develop or debug
|
|
172
|
+
currentIndex = actionSequence.indexOf(workerResult.loop_back_to)
|
|
173
|
+
} else if (workerResult.status === 'failed') {
|
|
174
|
+
// Stop on failure
|
|
175
|
+
break
|
|
176
|
+
} else {
|
|
177
|
+
currentIndex++
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Parallel Mode (批量 spawn + wait)
|
|
184
|
+
|
|
185
|
+
```javascript
|
|
186
|
+
async function runParallelMode(loopId, state) {
|
|
187
|
+
// Spawn multiple workers in parallel
|
|
188
|
+
const workers = {
|
|
189
|
+
develop: spawn_agent({ message: buildWorkerPrompt('develop', loopId, state) }),
|
|
190
|
+
debug: spawn_agent({ message: buildWorkerPrompt('debug', loopId, state) }),
|
|
191
|
+
validate: spawn_agent({ message: buildWorkerPrompt('validate', loopId, state) })
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Batch wait for all workers
|
|
195
|
+
const results = wait({
|
|
196
|
+
ids: Object.values(workers),
|
|
197
|
+
timeout_ms: 900000 // 15 minutes for all
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
// Collect outputs
|
|
201
|
+
const outputs = {}
|
|
202
|
+
for (const [role, workerId] of Object.entries(workers)) {
|
|
203
|
+
outputs[role] = results.status[workerId].completed
|
|
204
|
+
close_agent({ id: workerId })
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Merge and analyze results
|
|
208
|
+
const mergedAnalysis = mergeWorkerOutputs(outputs)
|
|
209
|
+
|
|
210
|
+
// Update state with merged results
|
|
211
|
+
updateState(loopId, 'parallel-analysis', mergedAnalysis)
|
|
212
|
+
|
|
213
|
+
// Coordinator decides next action based on merged results
|
|
214
|
+
const decision = decideNextAction(mergedAnalysis)
|
|
215
|
+
return decision
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Worker Prompt Builder
|
|
220
|
+
|
|
221
|
+
```javascript
|
|
222
|
+
function buildWorkerPrompt(action, loopId, state) {
|
|
223
|
+
const workerRoles = {
|
|
224
|
+
develop: '~/.codex/agents/ccw-loop-b-develop.md',
|
|
225
|
+
debug: '~/.codex/agents/ccw-loop-b-debug.md',
|
|
226
|
+
validate: '~/.codex/agents/ccw-loop-b-validate.md',
|
|
227
|
+
init: '~/.codex/agents/ccw-loop-b-init.md',
|
|
228
|
+
complete: '~/.codex/agents/ccw-loop-b-complete.md'
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return `
|
|
232
|
+
## TASK ASSIGNMENT
|
|
233
|
+
|
|
234
|
+
### MANDATORY FIRST STEPS (Agent Execute)
|
|
235
|
+
1. **Read role definition**: ${workerRoles[action]} (MUST read first)
|
|
236
|
+
2. Read: .workflow/project-tech.json
|
|
237
|
+
3. Read: .workflow/project-guidelines.json
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## LOOP CONTEXT
|
|
242
|
+
|
|
243
|
+
- **Loop ID**: ${loopId}
|
|
244
|
+
- **Action**: ${action}
|
|
245
|
+
- **State File**: .loop/${loopId}.json
|
|
246
|
+
- **Output File**: .loop/${loopId}.workers/${action}.output.json
|
|
247
|
+
- **Progress File**: .loop/${loopId}.progress/${action}.md
|
|
248
|
+
|
|
249
|
+
## CURRENT STATE
|
|
250
|
+
|
|
251
|
+
${JSON.stringify(state, null, 2)}
|
|
252
|
+
|
|
253
|
+
## TASK DESCRIPTION
|
|
254
|
+
|
|
255
|
+
${state.description}
|
|
256
|
+
|
|
257
|
+
## EXPECTED OUTPUT
|
|
258
|
+
|
|
259
|
+
\`\`\`
|
|
260
|
+
WORKER_RESULT:
|
|
261
|
+
- action: ${action}
|
|
262
|
+
- status: success | failed | needs_input
|
|
263
|
+
- summary: <brief summary>
|
|
264
|
+
- files_changed: [list]
|
|
265
|
+
- next_suggestion: <suggested next action>
|
|
266
|
+
- loop_back_to: <action name if needs loop back>
|
|
267
|
+
|
|
268
|
+
DETAILED_OUTPUT:
|
|
269
|
+
<structured output specific to action type>
|
|
270
|
+
\`\`\`
|
|
271
|
+
|
|
272
|
+
Execute the ${action} action now.
|
|
273
|
+
`
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Worker Roles
|
|
278
|
+
|
|
279
|
+
| Worker | Role File | 专注领域 |
|
|
280
|
+
|--------|-----------|----------|
|
|
281
|
+
| init | ccw-loop-b-init.md | 会话初始化、任务解析 |
|
|
282
|
+
| develop | ccw-loop-b-develop.md | 代码实现、重构 |
|
|
283
|
+
| debug | ccw-loop-b-debug.md | 问题诊断、假设验证 |
|
|
284
|
+
| validate | ccw-loop-b-validate.md | 测试执行、覆盖率 |
|
|
285
|
+
| complete | ccw-loop-b-complete.md | 总结收尾 |
|
|
286
|
+
|
|
287
|
+
## State Schema
|
|
288
|
+
|
|
289
|
+
See [phases/state-schema.md](phases/state-schema.md)
|
|
290
|
+
|
|
291
|
+
## Usage
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
# Interactive mode (default)
|
|
295
|
+
/ccw-loop-b TASK="Implement user authentication"
|
|
296
|
+
|
|
297
|
+
# Auto mode
|
|
298
|
+
/ccw-loop-b --mode=auto TASK="Fix login bug"
|
|
299
|
+
|
|
300
|
+
# Parallel analysis mode
|
|
301
|
+
/ccw-loop-b --mode=parallel TASK="Analyze and improve payment module"
|
|
302
|
+
|
|
303
|
+
# Resume existing loop
|
|
304
|
+
/ccw-loop-b --loop-id=loop-b-20260122-abc123
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## Error Handling
|
|
308
|
+
|
|
309
|
+
| Situation | Action |
|
|
310
|
+
|-----------|--------|
|
|
311
|
+
| Worker timeout | send_input 请求收敛 |
|
|
312
|
+
| Worker failed | Log error, 协调器决策是否重试 |
|
|
313
|
+
| Batch wait partial timeout | 使用已完成结果继续 |
|
|
314
|
+
| State corrupted | 从 progress 文件重建 |
|
|
315
|
+
|
|
316
|
+
## Best Practices
|
|
317
|
+
|
|
318
|
+
1. **协调器保持轻量**: 只做调度和状态管理,具体工作交给 worker
|
|
319
|
+
2. **Worker 职责单一**: 每个 worker 专注一个领域
|
|
320
|
+
3. **结果标准化**: Worker 输出遵循统一 WORKER_RESULT 格式
|
|
321
|
+
4. **灵活模式切换**: 根据任务复杂度选择合适模式
|
|
322
|
+
5. **及时清理**: Worker 完成后 close_agent 释放资源
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# Orchestrator (Hybrid Pattern)
|
|
2
|
+
|
|
3
|
+
协调器负责状态管理、worker 调度、结果汇聚。
|
|
4
|
+
|
|
5
|
+
## Role
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Read state -> Select mode -> Spawn workers -> Wait results -> Merge -> Update state -> Loop/Exit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## State Management
|
|
12
|
+
|
|
13
|
+
### Read State
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
function readState(loopId) {
|
|
17
|
+
const stateFile = `.loop/${loopId}.json`
|
|
18
|
+
return fs.existsSync(stateFile)
|
|
19
|
+
? JSON.parse(Read(stateFile))
|
|
20
|
+
: null
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Create State
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
function createState(loopId, taskDescription, mode) {
|
|
28
|
+
const now = new Date().toISOString()
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
loop_id: loopId,
|
|
32
|
+
title: taskDescription.substring(0, 100),
|
|
33
|
+
description: taskDescription,
|
|
34
|
+
mode: mode,
|
|
35
|
+
status: 'running',
|
|
36
|
+
current_iteration: 0,
|
|
37
|
+
max_iterations: 10,
|
|
38
|
+
created_at: now,
|
|
39
|
+
updated_at: now,
|
|
40
|
+
skill_state: {
|
|
41
|
+
phase: 'init',
|
|
42
|
+
action_index: 0,
|
|
43
|
+
workers_completed: [],
|
|
44
|
+
parallel_results: null
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Mode Handlers
|
|
51
|
+
|
|
52
|
+
### Interactive Mode
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
async function runInteractiveMode(loopId, state) {
|
|
56
|
+
while (state.status === 'running') {
|
|
57
|
+
// 1. Show menu
|
|
58
|
+
const action = await showMenu(state)
|
|
59
|
+
if (action === 'exit') break
|
|
60
|
+
|
|
61
|
+
// 2. Spawn worker
|
|
62
|
+
const worker = spawn_agent({
|
|
63
|
+
message: buildWorkerPrompt(action, loopId, state)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
// 3. Wait for result
|
|
67
|
+
const result = wait({ ids: [worker], timeout_ms: 600000 })
|
|
68
|
+
|
|
69
|
+
// 4. Handle timeout
|
|
70
|
+
if (result.timed_out) {
|
|
71
|
+
send_input({ id: worker, message: 'Please converge and output WORKER_RESULT' })
|
|
72
|
+
const retryResult = wait({ ids: [worker], timeout_ms: 300000 })
|
|
73
|
+
if (retryResult.timed_out) {
|
|
74
|
+
console.log('Worker timeout, skipping')
|
|
75
|
+
close_agent({ id: worker })
|
|
76
|
+
continue
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 5. Process output
|
|
81
|
+
const output = result.status[worker].completed
|
|
82
|
+
state = processWorkerOutput(loopId, action, output, state)
|
|
83
|
+
|
|
84
|
+
// 6. Cleanup
|
|
85
|
+
close_agent({ id: worker })
|
|
86
|
+
|
|
87
|
+
// 7. Display result
|
|
88
|
+
displayResult(output)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Auto Mode
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
async function runAutoMode(loopId, state) {
|
|
97
|
+
const sequence = ['init', 'develop', 'debug', 'validate', 'complete']
|
|
98
|
+
let idx = state.skill_state?.action_index || 0
|
|
99
|
+
|
|
100
|
+
while (idx < sequence.length && state.status === 'running') {
|
|
101
|
+
const action = sequence[idx]
|
|
102
|
+
|
|
103
|
+
// Spawn and wait
|
|
104
|
+
const worker = spawn_agent({ message: buildWorkerPrompt(action, loopId, state) })
|
|
105
|
+
const result = wait({ ids: [worker], timeout_ms: 600000 })
|
|
106
|
+
const output = result.status[worker].completed
|
|
107
|
+
close_agent({ id: worker })
|
|
108
|
+
|
|
109
|
+
// Parse result
|
|
110
|
+
const workerResult = parseWorkerResult(output)
|
|
111
|
+
state = processWorkerOutput(loopId, action, output, state)
|
|
112
|
+
|
|
113
|
+
// Determine next
|
|
114
|
+
if (workerResult.loop_back_to) {
|
|
115
|
+
idx = sequence.indexOf(workerResult.loop_back_to)
|
|
116
|
+
} else if (workerResult.status === 'failed') {
|
|
117
|
+
break
|
|
118
|
+
} else {
|
|
119
|
+
idx++
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Update action index
|
|
123
|
+
state.skill_state.action_index = idx
|
|
124
|
+
saveState(loopId, state)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Parallel Mode
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
async function runParallelMode(loopId, state) {
|
|
133
|
+
// Spawn all workers
|
|
134
|
+
const workers = {
|
|
135
|
+
develop: spawn_agent({ message: buildWorkerPrompt('develop', loopId, state) }),
|
|
136
|
+
debug: spawn_agent({ message: buildWorkerPrompt('debug', loopId, state) }),
|
|
137
|
+
validate: spawn_agent({ message: buildWorkerPrompt('validate', loopId, state) })
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Batch wait
|
|
141
|
+
const results = wait({
|
|
142
|
+
ids: Object.values(workers),
|
|
143
|
+
timeout_ms: 900000
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
// Collect outputs
|
|
147
|
+
const outputs = {}
|
|
148
|
+
for (const [role, id] of Object.entries(workers)) {
|
|
149
|
+
if (results.status[id].completed) {
|
|
150
|
+
outputs[role] = results.status[id].completed
|
|
151
|
+
}
|
|
152
|
+
close_agent({ id })
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Merge analysis
|
|
156
|
+
state.skill_state.parallel_results = outputs
|
|
157
|
+
saveState(loopId, state)
|
|
158
|
+
|
|
159
|
+
// Coordinator analyzes merged results
|
|
160
|
+
return analyzeAndDecide(outputs)
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Worker Prompt Template
|
|
165
|
+
|
|
166
|
+
```javascript
|
|
167
|
+
function buildWorkerPrompt(action, loopId, state) {
|
|
168
|
+
const roleFiles = {
|
|
169
|
+
init: '~/.codex/agents/ccw-loop-b-init.md',
|
|
170
|
+
develop: '~/.codex/agents/ccw-loop-b-develop.md',
|
|
171
|
+
debug: '~/.codex/agents/ccw-loop-b-debug.md',
|
|
172
|
+
validate: '~/.codex/agents/ccw-loop-b-validate.md',
|
|
173
|
+
complete: '~/.codex/agents/ccw-loop-b-complete.md'
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return `
|
|
177
|
+
## TASK ASSIGNMENT
|
|
178
|
+
|
|
179
|
+
### MANDATORY FIRST STEPS
|
|
180
|
+
1. **Read role definition**: ${roleFiles[action]}
|
|
181
|
+
2. Read: .workflow/project-tech.json
|
|
182
|
+
3. Read: .workflow/project-guidelines.json
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## CONTEXT
|
|
187
|
+
- Loop ID: ${loopId}
|
|
188
|
+
- Action: ${action}
|
|
189
|
+
- State: ${JSON.stringify(state, null, 2)}
|
|
190
|
+
|
|
191
|
+
## TASK
|
|
192
|
+
${state.description}
|
|
193
|
+
|
|
194
|
+
## OUTPUT FORMAT
|
|
195
|
+
\`\`\`
|
|
196
|
+
WORKER_RESULT:
|
|
197
|
+
- action: ${action}
|
|
198
|
+
- status: success | failed | needs_input
|
|
199
|
+
- summary: <brief>
|
|
200
|
+
- files_changed: []
|
|
201
|
+
- next_suggestion: <action>
|
|
202
|
+
- loop_back_to: <action or null>
|
|
203
|
+
|
|
204
|
+
DETAILED_OUTPUT:
|
|
205
|
+
<action-specific output>
|
|
206
|
+
\`\`\`
|
|
207
|
+
`
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Result Processing
|
|
212
|
+
|
|
213
|
+
```javascript
|
|
214
|
+
function parseWorkerResult(output) {
|
|
215
|
+
const result = {
|
|
216
|
+
action: 'unknown',
|
|
217
|
+
status: 'unknown',
|
|
218
|
+
summary: '',
|
|
219
|
+
files_changed: [],
|
|
220
|
+
next_suggestion: null,
|
|
221
|
+
loop_back_to: null
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const match = output.match(/WORKER_RESULT:\s*([\s\S]*?)(?:DETAILED_OUTPUT:|$)/)
|
|
225
|
+
if (match) {
|
|
226
|
+
const lines = match[1].split('\n')
|
|
227
|
+
for (const line of lines) {
|
|
228
|
+
const m = line.match(/^-\s*(\w+):\s*(.+)$/)
|
|
229
|
+
if (m) {
|
|
230
|
+
const [, key, value] = m
|
|
231
|
+
if (key === 'files_changed') {
|
|
232
|
+
try { result.files_changed = JSON.parse(value) } catch {}
|
|
233
|
+
} else {
|
|
234
|
+
result[key] = value.trim()
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return result
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Termination Conditions
|
|
245
|
+
|
|
246
|
+
1. User exits (interactive)
|
|
247
|
+
2. Sequence complete (auto)
|
|
248
|
+
3. Worker failed with no recovery
|
|
249
|
+
4. Max iterations reached
|
|
250
|
+
5. API paused/stopped
|
|
251
|
+
|
|
252
|
+
## Best Practices
|
|
253
|
+
|
|
254
|
+
1. **Worker 生命周期**: spawn → wait → close,不保留 worker
|
|
255
|
+
2. **结果持久化**: Worker 输出写入 `.loop/{loopId}.workers/`
|
|
256
|
+
3. **状态同步**: 每次 worker 完成后更新 state
|
|
257
|
+
4. **超时处理**: send_input 请求收敛,再超时则跳过
|