claude-code-workflow 6.3.37 → 6.3.39

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 (173) hide show
  1. package/.claude/commands/workflow/lite-execute.md +2 -0
  2. package/.codex/agents/action-planning-agent.md +885 -0
  3. package/.codex/agents/ccw-loop-b-complete.md +227 -0
  4. package/.codex/agents/ccw-loop-b-debug.md +172 -0
  5. package/.codex/agents/ccw-loop-b-develop.md +147 -0
  6. package/.codex/agents/ccw-loop-b-init.md +82 -0
  7. package/.codex/agents/ccw-loop-b-validate.md +204 -0
  8. package/.codex/agents/ccw-loop-executor.md +260 -0
  9. package/.codex/agents/cli-discuss-agent.md +391 -0
  10. package/.codex/agents/cli-execution-agent.md +333 -0
  11. package/.codex/agents/cli-explore-agent.md +186 -0
  12. package/.codex/agents/cli-lite-planning-agent.md +736 -0
  13. package/.codex/agents/cli-planning-agent.md +562 -0
  14. package/.codex/agents/code-developer.md +408 -0
  15. package/.codex/agents/conceptual-planning-agent.md +321 -0
  16. package/.codex/agents/context-search-agent.md +585 -0
  17. package/.codex/agents/debug-explore-agent.md +436 -0
  18. package/.codex/agents/doc-generator.md +334 -0
  19. package/.codex/agents/issue-plan-agent.md +417 -0
  20. package/.codex/agents/issue-queue-agent.md +311 -0
  21. package/.codex/agents/memory-bridge.md +96 -0
  22. package/.codex/agents/test-context-search-agent.md +402 -0
  23. package/.codex/agents/test-fix-agent.md +359 -0
  24. package/.codex/agents/ui-design-agent.md +595 -0
  25. package/.codex/agents/universal-executor.md +135 -0
  26. package/.codex/prompts/clean.md +409 -0
  27. package/.codex/prompts/issue-discover-by-prompt.md +364 -0
  28. package/.codex/prompts/issue-discover.md +261 -0
  29. package/.codex/prompts/issue-execute.md +10 -0
  30. package/.codex/prompts/issue-new.md +285 -0
  31. package/.codex/prompts/issue-plan.md +161 -63
  32. package/.codex/prompts/issue-queue.md +298 -288
  33. package/.codex/prompts/lite-execute.md +627 -133
  34. package/.codex/prompts/lite-fix.md +670 -0
  35. package/.codex/prompts/lite-plan-a.md +337 -0
  36. package/.codex/prompts/lite-plan-b.md +485 -0
  37. package/.codex/prompts/{lite-plan.md → lite-plan-c.md} +601 -469
  38. package/.codex/skills/ccw-loop/README.md +171 -0
  39. package/.codex/skills/ccw-loop/SKILL.md +349 -0
  40. package/.codex/skills/ccw-loop/phases/actions/action-complete.md +269 -0
  41. package/.codex/skills/ccw-loop/phases/actions/action-debug.md +286 -0
  42. package/.codex/skills/ccw-loop/phases/actions/action-develop.md +183 -0
  43. package/.codex/skills/ccw-loop/phases/actions/action-init.md +164 -0
  44. package/.codex/skills/ccw-loop/phases/actions/action-menu.md +205 -0
  45. package/.codex/skills/ccw-loop/phases/actions/action-validate.md +250 -0
  46. package/.codex/skills/ccw-loop/phases/orchestrator.md +416 -0
  47. package/.codex/skills/ccw-loop/phases/state-schema.md +388 -0
  48. package/.codex/skills/ccw-loop/specs/action-catalog.md +182 -0
  49. package/.codex/skills/ccw-loop-b/README.md +301 -0
  50. package/.codex/skills/ccw-loop-b/SKILL.md +322 -0
  51. package/.codex/skills/ccw-loop-b/phases/orchestrator.md +257 -0
  52. package/.codex/skills/ccw-loop-b/phases/state-schema.md +181 -0
  53. package/.codex/skills/ccw-loop-b/specs/action-catalog.md +383 -0
  54. package/.codex/skills/parallel-dev-cycle/README.md +382 -0
  55. package/.codex/skills/parallel-dev-cycle/SKILL.md +512 -0
  56. package/.codex/skills/parallel-dev-cycle/phases/agents/code-developer.md +242 -0
  57. package/.codex/skills/parallel-dev-cycle/phases/agents/exploration-planner.md +285 -0
  58. package/.codex/skills/parallel-dev-cycle/phases/agents/requirements-analyst.md +285 -0
  59. package/.codex/skills/parallel-dev-cycle/phases/agents/validation-archivist.md +381 -0
  60. package/.codex/skills/parallel-dev-cycle/phases/orchestrator.md +696 -0
  61. package/.codex/skills/parallel-dev-cycle/phases/state-schema.md +436 -0
  62. package/.codex/skills/parallel-dev-cycle/specs/communication-optimization.md +423 -0
  63. package/.codex/skills/parallel-dev-cycle/specs/coordination-protocol.md +391 -0
  64. package/.codex/skills/parallel-dev-cycle/specs/versioning-strategy.md +330 -0
  65. package/ccw/dist/cli.d.ts.map +1 -1
  66. package/ccw/dist/cli.js +4 -0
  67. package/ccw/dist/cli.js.map +1 -1
  68. package/ccw/dist/commands/install.d.ts.map +1 -1
  69. package/ccw/dist/commands/install.js +39 -8
  70. package/ccw/dist/commands/install.js.map +1 -1
  71. package/ccw/dist/commands/issue.d.ts +3 -0
  72. package/ccw/dist/commands/issue.d.ts.map +1 -1
  73. package/ccw/dist/commands/issue.js +107 -0
  74. package/ccw/dist/commands/issue.js.map +1 -1
  75. package/ccw/dist/commands/upgrade.js +1 -1
  76. package/ccw/dist/commands/upgrade.js.map +1 -1
  77. package/ccw/dist/config/litellm-api-config-manager.d.ts.map +1 -1
  78. package/ccw/dist/config/litellm-api-config-manager.js +3 -2
  79. package/ccw/dist/config/litellm-api-config-manager.js.map +1 -1
  80. package/ccw/dist/core/memory-embedder-bridge.d.ts.map +1 -1
  81. package/ccw/dist/core/memory-embedder-bridge.js +2 -5
  82. package/ccw/dist/core/memory-embedder-bridge.js.map +1 -1
  83. package/ccw/dist/core/routes/cli-routes.js.map +1 -1
  84. package/ccw/dist/core/routes/codexlens/config-handlers.d.ts.map +1 -1
  85. package/ccw/dist/core/routes/codexlens/config-handlers.js +7 -6
  86. package/ccw/dist/core/routes/codexlens/config-handlers.js.map +1 -1
  87. package/ccw/dist/core/routes/codexlens/semantic-handlers.d.ts.map +1 -1
  88. package/ccw/dist/core/routes/codexlens/semantic-handlers.js +2 -2
  89. package/ccw/dist/core/routes/codexlens/semantic-handlers.js.map +1 -1
  90. package/ccw/dist/core/routes/graph-routes.d.ts.map +1 -1
  91. package/ccw/dist/core/routes/graph-routes.js +17 -2
  92. package/ccw/dist/core/routes/graph-routes.js.map +1 -1
  93. package/ccw/dist/core/routes/issue-routes.d.ts.map +1 -1
  94. package/ccw/dist/core/routes/issue-routes.js +280 -33
  95. package/ccw/dist/core/routes/issue-routes.js.map +1 -1
  96. package/ccw/dist/core/routes/loop-v2-routes.d.ts +9 -0
  97. package/ccw/dist/core/routes/loop-v2-routes.d.ts.map +1 -1
  98. package/ccw/dist/core/routes/loop-v2-routes.js +56 -4
  99. package/ccw/dist/core/routes/loop-v2-routes.js.map +1 -1
  100. package/ccw/dist/core/routes/system-routes.d.ts.map +1 -1
  101. package/ccw/dist/core/routes/system-routes.js +3 -2
  102. package/ccw/dist/core/routes/system-routes.js.map +1 -1
  103. package/ccw/dist/core/server.d.ts.map +1 -1
  104. package/ccw/dist/core/server.js +5 -3
  105. package/ccw/dist/core/server.js.map +1 -1
  106. package/ccw/dist/tools/claude-cli-tools.d.ts.map +1 -1
  107. package/ccw/dist/tools/claude-cli-tools.js +4 -3
  108. package/ccw/dist/tools/claude-cli-tools.js.map +1 -1
  109. package/ccw/dist/tools/cli-config-manager.d.ts +1 -0
  110. package/ccw/dist/tools/cli-config-manager.d.ts.map +1 -1
  111. package/ccw/dist/tools/cli-config-manager.js +2 -1
  112. package/ccw/dist/tools/cli-config-manager.js.map +1 -1
  113. package/ccw/dist/tools/codex-lens-lsp.d.ts.map +1 -1
  114. package/ccw/dist/tools/codex-lens-lsp.js +2 -5
  115. package/ccw/dist/tools/codex-lens-lsp.js.map +1 -1
  116. package/ccw/dist/tools/codex-lens.d.ts.map +1 -1
  117. package/ccw/dist/tools/codex-lens.js +22 -32
  118. package/ccw/dist/tools/codex-lens.js.map +1 -1
  119. package/ccw/dist/tools/litellm-client.d.ts +6 -0
  120. package/ccw/dist/tools/litellm-client.d.ts.map +1 -1
  121. package/ccw/dist/tools/litellm-client.js +15 -2
  122. package/ccw/dist/tools/litellm-client.js.map +1 -1
  123. package/ccw/dist/tools/loop-task-manager.d.ts +13 -2
  124. package/ccw/dist/tools/loop-task-manager.d.ts.map +1 -1
  125. package/ccw/dist/tools/loop-task-manager.js.map +1 -1
  126. package/ccw/dist/tools/native-session-discovery.d.ts.map +1 -1
  127. package/ccw/dist/tools/native-session-discovery.js +35 -7
  128. package/ccw/dist/tools/native-session-discovery.js.map +1 -1
  129. package/ccw/dist/utils/codexlens-path.d.ts +36 -0
  130. package/ccw/dist/utils/codexlens-path.d.ts.map +1 -0
  131. package/ccw/dist/utils/codexlens-path.js +56 -0
  132. package/ccw/dist/utils/codexlens-path.js.map +1 -0
  133. package/ccw/dist/utils/uv-manager.d.ts.map +1 -1
  134. package/ccw/dist/utils/uv-manager.js +3 -2
  135. package/ccw/dist/utils/uv-manager.js.map +1 -1
  136. package/ccw/src/cli.ts +4 -0
  137. package/ccw/src/commands/install.ts +51 -8
  138. package/ccw/src/commands/issue.ts +119 -0
  139. package/ccw/src/commands/upgrade.ts +1 -1
  140. package/ccw/src/config/litellm-api-config-manager.ts +3 -2
  141. package/ccw/src/core/memory-embedder-bridge.ts +2 -6
  142. package/ccw/src/core/routes/cli-routes.ts +1 -1
  143. package/ccw/src/core/routes/codexlens/config-handlers.ts +7 -6
  144. package/ccw/src/core/routes/codexlens/semantic-handlers.ts +2 -2
  145. package/ccw/src/core/routes/graph-routes.ts +18 -2
  146. package/ccw/src/core/routes/issue-routes.ts +308 -33
  147. package/ccw/src/core/routes/loop-v2-routes.ts +64 -6
  148. package/ccw/src/core/routes/system-routes.ts +3 -2
  149. package/ccw/src/core/server.ts +6 -3
  150. package/ccw/src/templates/dashboard-css/02-session.css +2 -0
  151. package/ccw/src/templates/dashboard-css/04-lite-tasks.css +103 -1
  152. package/ccw/src/templates/dashboard-css/32-issue-manager.css +32 -0
  153. package/ccw/src/templates/dashboard-js/components/cli-history.js +48 -48
  154. package/ccw/src/templates/dashboard-js/components/navigation.js +6 -0
  155. package/ccw/src/templates/dashboard-js/components/notifications.js +6 -0
  156. package/ccw/src/templates/dashboard-js/components/version-check.js +38 -0
  157. package/ccw/src/templates/dashboard-js/i18n.js +126 -0
  158. package/ccw/src/templates/dashboard-js/state.js +2 -0
  159. package/ccw/src/templates/dashboard-js/views/cli-manager.js +1 -1
  160. package/ccw/src/templates/dashboard-js/views/issue-manager.js +183 -1
  161. package/ccw/src/templates/dashboard-js/views/lite-tasks.js +55 -11
  162. package/ccw/src/templates/dashboard-js/views/loop-monitor.js +112 -11
  163. package/ccw/src/templates/dashboard.html +48 -2
  164. package/ccw/src/tools/claude-cli-tools.ts +4 -3
  165. package/ccw/src/tools/cli-config-manager.ts +3 -1
  166. package/ccw/src/tools/codex-lens-lsp.ts +2 -5
  167. package/ccw/src/tools/codex-lens.ts +27 -38
  168. package/ccw/src/tools/litellm-client.ts +16 -2
  169. package/ccw/src/tools/loop-task-manager.ts +13 -2
  170. package/ccw/src/tools/native-session-discovery.ts +38 -7
  171. package/ccw/src/utils/codexlens-path.ts +60 -0
  172. package/ccw/src/utils/uv-manager.ts +3 -2
  173. package/package.json +1 -1
@@ -0,0 +1,171 @@
1
+ # CCW Loop Skill (Codex Version)
2
+
3
+ Stateless iterative development loop workflow using Codex subagent pattern.
4
+
5
+ ## Overview
6
+
7
+ CCW Loop is an autonomous development workflow that supports:
8
+ - **Develop**: Task decomposition -> Code implementation -> Progress tracking
9
+ - **Debug**: Hypothesis generation -> Evidence collection -> Root cause analysis
10
+ - **Validate**: Test execution -> Coverage check -> Quality assessment
11
+
12
+ ## Subagent 机制
13
+
14
+ 核心 API: `spawn_agent` / `wait` / `send_input` / `close_agent`
15
+
16
+ 可用模式: 单 agent 深度交互 / 多 agent 并行 / 混合模式
17
+
18
+ ## Installation
19
+
20
+ Files are in `.codex/skills/ccw-loop/`:
21
+
22
+ ```
23
+ .codex/skills/ccw-loop/
24
+ +-- SKILL.md # Main skill definition
25
+ +-- README.md # This file
26
+ +-- phases/
27
+ | +-- orchestrator.md # Orchestration logic
28
+ | +-- state-schema.md # State structure
29
+ | +-- actions/
30
+ | +-- action-init.md # Initialize session
31
+ | +-- action-develop.md # Development task
32
+ | +-- action-debug.md # Hypothesis debugging
33
+ | +-- action-validate.md # Test validation
34
+ | +-- action-complete.md # Complete loop
35
+ | +-- action-menu.md # Interactive menu
36
+ +-- specs/
37
+ | +-- action-catalog.md # Action catalog
38
+ +-- templates/
39
+ +-- (templates)
40
+
41
+ .codex/agents/
42
+ +-- ccw-loop-executor.md # Executor agent role
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ ### Start New Loop
48
+
49
+ ```bash
50
+ # Direct call with task description
51
+ /ccw-loop TASK="Implement user authentication"
52
+
53
+ # Auto-cycle mode
54
+ /ccw-loop --auto TASK="Fix login bug and add tests"
55
+ ```
56
+
57
+ ### Continue Existing Loop
58
+
59
+ ```bash
60
+ # Resume from loop ID
61
+ /ccw-loop --loop-id=loop-v2-20260122-abc123
62
+
63
+ # API triggered (from Dashboard)
64
+ /ccw-loop --loop-id=loop-v2-20260122-abc123 --auto
65
+ ```
66
+
67
+ ## Execution Flow
68
+
69
+ ```
70
+ 1. Parse arguments (task or --loop-id)
71
+ 2. Create/read state from .workflow/.loop/{loopId}.json
72
+ 3. spawn_agent with ccw-loop-executor role
73
+ 4. Main loop:
74
+ a. wait() for agent output
75
+ b. Parse ACTION_RESULT
76
+ c. Handle outcome:
77
+ - COMPLETED/PAUSED/STOPPED: exit loop
78
+ - WAITING_INPUT: collect user input, send_input
79
+ - Next action: send_input to continue
80
+ d. Update state file
81
+ 5. close_agent when done
82
+ ```
83
+
84
+ ## Session Files
85
+
86
+ ```
87
+ .workflow/.loop/
88
+ +-- {loopId}.json # Master state (API + Skill)
89
+ +-- {loopId}.progress/
90
+ +-- develop.md # Development timeline
91
+ +-- debug.md # Understanding evolution
92
+ +-- validate.md # Validation report
93
+ +-- changes.log # Code changes (NDJSON)
94
+ +-- debug.log # Debug log (NDJSON)
95
+ +-- summary.md # Completion summary
96
+ ```
97
+
98
+ ## Codex Pattern Highlights
99
+
100
+ ### Single Agent Deep Interaction
101
+
102
+ Instead of creating multiple agents, use `send_input` for multi-phase:
103
+
104
+ ```javascript
105
+ const agent = spawn_agent({ message: role + task })
106
+
107
+ // Phase 1: INIT
108
+ const initResult = wait({ ids: [agent] })
109
+
110
+ // Phase 2: DEVELOP (via send_input, same agent)
111
+ send_input({ id: agent, message: 'Execute DEVELOP' })
112
+ const devResult = wait({ ids: [agent] })
113
+
114
+ // Phase 3: VALIDATE (via send_input, same agent)
115
+ send_input({ id: agent, message: 'Execute VALIDATE' })
116
+ const valResult = wait({ ids: [agent] })
117
+
118
+ // Only close when all done
119
+ close_agent({ id: agent })
120
+ ```
121
+
122
+ ### Role Path Passing
123
+
124
+ Agent reads role file itself (no content embedding):
125
+
126
+ ```javascript
127
+ spawn_agent({
128
+ message: `
129
+ ### MANDATORY FIRST STEPS
130
+ 1. **Read role definition**: ~/.codex/agents/ccw-loop-executor.md
131
+ 2. Read: .workflow/project-tech.json
132
+ ...
133
+ `
134
+ })
135
+ ```
136
+
137
+ ### Explicit Lifecycle Management
138
+
139
+ - Always use `wait({ ids })` to get results
140
+ - Never assume `close_agent` returns results
141
+ - Only `close_agent` when confirming no more interaction needed
142
+
143
+ ## Error Handling
144
+
145
+ | Situation | Action |
146
+ |-----------|--------|
147
+ | Agent timeout | `send_input` requesting convergence |
148
+ | Session not found | Create new session |
149
+ | State corrupted | Rebuild from progress files |
150
+ | Tests fail | Loop back to DEBUG |
151
+ | >10 iterations | Warn and suggest break |
152
+
153
+ ## Integration
154
+
155
+ ### Dashboard Integration
156
+
157
+ Works with CCW Dashboard Loop Monitor:
158
+ - Dashboard creates loop via API
159
+ - API triggers this skill with `--loop-id`
160
+ - Skill reads/writes `.workflow/.loop/{loopId}.json`
161
+ - Dashboard polls state for real-time updates
162
+
163
+ ### Control Signals
164
+
165
+ - `paused`: Skill exits gracefully, waits for resume
166
+ - `failed`: Skill terminates
167
+ - `running`: Skill continues execution
168
+
169
+ ## License
170
+
171
+ MIT
@@ -0,0 +1,349 @@
1
+ ---
2
+ description: Stateless iterative development loop workflow with documented progress. Supports develop, debug, and validate phases with file-based state tracking. Triggers on "ccw-loop", "dev loop", "development loop".
3
+ argument-hint: TASK="<task description>" [--loop-id=<id>] [--auto]
4
+ ---
5
+
6
+ # CCW Loop - Codex Stateless Iterative Development Workflow
7
+
8
+ Stateless iterative development loop using Codex subagent pattern. Supports develop, debug, and validate phases with file-based state tracking.
9
+
10
+ ## Arguments
11
+
12
+ | Arg | Required | Description |
13
+ |-----|----------|-------------|
14
+ | TASK | No | Task description (for new loop, mutually exclusive with --loop-id) |
15
+ | --loop-id | No | Existing loop ID to continue (from API or previous session) |
16
+ | --auto | No | Auto-cycle mode (develop -> debug -> validate -> complete) |
17
+
18
+ ## Unified Architecture (Codex Subagent Pattern)
19
+
20
+ ```
21
+ +-------------------------------------------------------------+
22
+ | Dashboard (UI) |
23
+ | [Create] [Start] [Pause] [Resume] [Stop] [View Progress] |
24
+ +-------------------------------------------------------------+
25
+ |
26
+ v
27
+ +-------------------------------------------------------------+
28
+ | loop-v2-routes.ts (Control Plane) |
29
+ | |
30
+ | State: .workflow/.loop/{loopId}.json (MASTER) |
31
+ | Tasks: .workflow/.loop/{loopId}.tasks.jsonl |
32
+ | |
33
+ | /start -> Trigger ccw-loop skill with --loop-id |
34
+ | /pause -> Set status='paused' (skill checks before action) |
35
+ | /stop -> Set status='failed' (skill terminates) |
36
+ | /resume -> Set status='running' (skill continues) |
37
+ +-------------------------------------------------------------+
38
+ |
39
+ v
40
+ +-------------------------------------------------------------+
41
+ | ccw-loop Skill (Execution Plane) |
42
+ | |
43
+ | Codex Pattern: spawn_agent -> wait -> send_input -> close |
44
+ | |
45
+ | Reads/Writes: .workflow/.loop/{loopId}.json (unified state) |
46
+ | Writes: .workflow/.loop/{loopId}.progress/* (progress files) |
47
+ | |
48
+ | BEFORE each action: |
49
+ | -> Check status: paused/stopped -> exit gracefully |
50
+ | -> running -> continue with action |
51
+ | |
52
+ | Actions: init -> develop -> debug -> validate -> complete |
53
+ +-------------------------------------------------------------+
54
+ ```
55
+
56
+ ## Key Design Principles (Codex Adaptation)
57
+
58
+ 1. **Unified State**: API and Skill share `.workflow/.loop/{loopId}.json` state file
59
+ 2. **Control Signals**: Skill checks status field before each action (paused/stopped)
60
+ 3. **File-Driven**: All progress documented in `.workflow/.loop/{loopId}.progress/`
61
+ 4. **Resumable**: Continue any loop with `--loop-id`
62
+ 5. **Dual Trigger**: Supports API trigger (`--loop-id`) and direct call (task description)
63
+ 6. **Single Agent Deep Interaction**: Use send_input for multi-phase execution instead of multiple agents
64
+
65
+ ## Subagent 机制
66
+
67
+ ### 核心 API
68
+
69
+ | API | 作用 |
70
+ |-----|------|
71
+ | `spawn_agent({ message })` | 创建 subagent,返回 `agent_id` |
72
+ | `wait({ ids, timeout_ms })` | 等待结果(唯一取结果入口) |
73
+ | `send_input({ id, message })` | 继续交互/追问 |
74
+ | `close_agent({ id })` | 关闭回收(不可逆) |
75
+
76
+ ### 可用模式
77
+
78
+ - **单 Agent 深度交互**: 一个 agent 多阶段,`send_input` 继续
79
+ - **多 Agent 并行**: 主协调器 + 多 worker,`wait({ ids: [...] })` 批量等待
80
+ - **混合模式**: 按需组合
81
+
82
+ ## Execution Modes
83
+
84
+ ### Mode 1: Interactive
85
+
86
+ User manually selects each action, suitable for complex tasks.
87
+
88
+ ```
89
+ User -> Select action -> Execute -> View results -> Select next action
90
+ ```
91
+
92
+ ### Mode 2: Auto-Loop
93
+
94
+ Automatic execution in preset order, suitable for standard development flow.
95
+
96
+ ```
97
+ Develop -> Debug -> Validate -> (if issues) -> Develop -> ...
98
+ ```
99
+
100
+ ## Session Structure (Unified Location)
101
+
102
+ ```
103
+ .workflow/.loop/
104
+ +-- {loopId}.json # Master state file (API + Skill shared)
105
+ +-- {loopId}.tasks.jsonl # Task list (API managed)
106
+ +-- {loopId}.progress/ # Skill progress files
107
+ +-- develop.md # Development progress timeline
108
+ +-- debug.md # Understanding evolution document
109
+ +-- validate.md # Validation report
110
+ +-- changes.log # Code changes log (NDJSON)
111
+ +-- debug.log # Debug log (NDJSON)
112
+ ```
113
+
114
+ ## Implementation (Codex Subagent Pattern)
115
+
116
+ ### Session Setup
117
+
118
+ ```javascript
119
+ // Helper: Get UTC+8 (China Standard Time) ISO string
120
+ const getUtc8ISOString = () => new Date(Date.now() + 8 * 60 * 60 * 1000).toISOString()
121
+
122
+ // loopId source:
123
+ // 1. API trigger: from --loop-id parameter
124
+ // 2. Direct call: generate new loop-v2-{timestamp}-{random}
125
+
126
+ const loopId = args['--loop-id'] || (() => {
127
+ const timestamp = getUtc8ISOString().replace(/[-:]/g, '').split('.')[0]
128
+ const random = Math.random().toString(36).substring(2, 10)
129
+ return `loop-v2-${timestamp}-${random}`
130
+ })()
131
+
132
+ const loopFile = `.workflow/.loop/${loopId}.json`
133
+ const progressDir = `.workflow/.loop/${loopId}.progress`
134
+
135
+ // Create progress directory
136
+ mkdir -p "${progressDir}"
137
+ ```
138
+
139
+ ### Main Execution Flow (Single Agent Deep Interaction)
140
+
141
+ ```javascript
142
+ // ==================== CODEX CCW-LOOP: SINGLE AGENT ORCHESTRATOR ====================
143
+
144
+ // Step 1: Read or create initial state
145
+ let state = null
146
+ if (existingLoopId) {
147
+ state = JSON.parse(Read(`.workflow/.loop/${loopId}.json`))
148
+ if (!state) {
149
+ console.error(`Loop not found: ${loopId}`)
150
+ return
151
+ }
152
+ } else {
153
+ state = createInitialState(loopId, taskDescription)
154
+ Write(`.workflow/.loop/${loopId}.json`, JSON.stringify(state, null, 2))
155
+ }
156
+
157
+ // Step 2: Create orchestrator agent (single agent handles all phases)
158
+ const agent = spawn_agent({
159
+ message: `
160
+ ## TASK ASSIGNMENT
161
+
162
+ ### MANDATORY FIRST STEPS (Agent Execute)
163
+ 1. **Read role definition**: ~/.codex/agents/ccw-loop-executor.md (MUST read first)
164
+ 2. Read: .workflow/project-tech.json
165
+ 3. Read: .workflow/project-guidelines.json
166
+
167
+ ---
168
+
169
+ ## LOOP CONTEXT
170
+
171
+ - **Loop ID**: ${loopId}
172
+ - **State File**: .workflow/.loop/${loopId}.json
173
+ - **Progress Dir**: ${progressDir}
174
+ - **Mode**: ${mode} // 'interactive' or 'auto'
175
+
176
+ ## CURRENT STATE
177
+
178
+ ${JSON.stringify(state, null, 2)}
179
+
180
+ ## TASK DESCRIPTION
181
+
182
+ ${taskDescription}
183
+
184
+ ## EXECUTION INSTRUCTIONS
185
+
186
+ You are executing CCW Loop orchestrator. Your job:
187
+
188
+ 1. **Check Control Signals**
189
+ - Read .workflow/.loop/${loopId}.json
190
+ - If status === 'paused' -> Output "PAUSED" and stop
191
+ - If status === 'failed' -> Output "STOPPED" and stop
192
+ - If status === 'running' -> Continue
193
+
194
+ 2. **Select Next Action**
195
+ Based on skill_state:
196
+ - If not initialized -> Execute INIT
197
+ - If mode === 'interactive' -> Output MENU and wait for input
198
+ - If mode === 'auto' -> Auto-select based on state
199
+
200
+ 3. **Execute Action**
201
+ - Follow action instructions from ~/.codex/skills/ccw-loop/phases/actions/
202
+ - Update progress files in ${progressDir}/
203
+ - Update state in .workflow/.loop/${loopId}.json
204
+
205
+ 4. **Output Format**
206
+ \`\`\`
207
+ ACTION_RESULT:
208
+ - action: {action_name}
209
+ - status: success | failed | needs_input
210
+ - message: {user message}
211
+ - state_updates: {JSON of skill_state updates}
212
+
213
+ NEXT_ACTION_NEEDED: {action_name} | WAITING_INPUT | COMPLETED | PAUSED
214
+ \`\`\`
215
+
216
+ ## FIRST ACTION
217
+
218
+ ${!state.skill_state ? 'Execute: INIT' : mode === 'auto' ? 'Auto-select next action' : 'Show MENU'}
219
+ `
220
+ })
221
+
222
+ // Step 3: Main orchestration loop
223
+ let iteration = 0
224
+ const maxIterations = state.max_iterations || 10
225
+
226
+ while (iteration < maxIterations) {
227
+ iteration++
228
+
229
+ // Wait for agent output
230
+ const result = wait({ ids: [agent], timeout_ms: 600000 })
231
+ const output = result.status[agent].completed
232
+
233
+ // Parse action result
234
+ const actionResult = parseActionResult(output)
235
+
236
+ // Handle different outcomes
237
+ switch (actionResult.next_action) {
238
+ case 'COMPLETED':
239
+ case 'PAUSED':
240
+ case 'STOPPED':
241
+ close_agent({ id: agent })
242
+ return actionResult
243
+
244
+ case 'WAITING_INPUT':
245
+ // Interactive mode: display menu, get user choice
246
+ const userChoice = await displayMenuAndGetChoice(actionResult)
247
+
248
+ // Send user choice back to agent
249
+ send_input({
250
+ id: agent,
251
+ message: `
252
+ ## USER INPUT RECEIVED
253
+
254
+ Action selected: ${userChoice.action}
255
+ ${userChoice.data ? `Additional data: ${JSON.stringify(userChoice.data)}` : ''}
256
+
257
+ ## EXECUTE SELECTED ACTION
258
+
259
+ Follow instructions for: ${userChoice.action}
260
+ Update state and progress files accordingly.
261
+ `
262
+ })
263
+ break
264
+
265
+ default:
266
+ // Auto mode: agent continues to next action
267
+ // Check if we need to prompt for continuation
268
+ if (actionResult.next_action && actionResult.next_action !== 'NONE') {
269
+ send_input({
270
+ id: agent,
271
+ message: `
272
+ ## CONTINUE EXECUTION
273
+
274
+ Previous action completed: ${actionResult.action}
275
+ Result: ${actionResult.status}
276
+
277
+ ## EXECUTE NEXT ACTION
278
+
279
+ Continue with: ${actionResult.next_action}
280
+ `
281
+ })
282
+ }
283
+ }
284
+
285
+ // Update iteration count in state
286
+ const currentState = JSON.parse(Read(`.workflow/.loop/${loopId}.json`))
287
+ currentState.current_iteration = iteration
288
+ currentState.updated_at = getUtc8ISOString()
289
+ Write(`.workflow/.loop/${loopId}.json`, JSON.stringify(currentState, null, 2))
290
+ }
291
+
292
+ // Step 4: Cleanup
293
+ close_agent({ id: agent })
294
+ ```
295
+
296
+ ## Action Catalog
297
+
298
+ | Action | Purpose | Output Files | Trigger |
299
+ |--------|---------|--------------|---------|
300
+ | [action-init](phases/actions/action-init.md) | Initialize loop session | meta.json, state.json | First run |
301
+ | [action-develop](phases/actions/action-develop.md) | Execute development task | progress.md, tasks.json | Has pending tasks |
302
+ | [action-debug](phases/actions/action-debug.md) | Hypothesis-driven debug | understanding.md, hypotheses.json | Needs debugging |
303
+ | [action-validate](phases/actions/action-validate.md) | Test and validate | validation.md, test-results.json | Needs validation |
304
+ | [action-complete](phases/actions/action-complete.md) | Complete loop | summary.md | All done |
305
+ | [action-menu](phases/actions/action-menu.md) | Display action menu | - | Interactive mode |
306
+
307
+ ## Usage
308
+
309
+ ```bash
310
+ # Start new loop (direct call)
311
+ /ccw-loop TASK="Implement user authentication"
312
+
313
+ # Continue existing loop (API trigger or manual resume)
314
+ /ccw-loop --loop-id=loop-v2-20260122-abc123
315
+
316
+ # Auto-cycle mode
317
+ /ccw-loop --auto TASK="Fix login bug and add tests"
318
+
319
+ # API triggered auto-cycle
320
+ /ccw-loop --loop-id=loop-v2-20260122-abc123 --auto
321
+ ```
322
+
323
+ ## Reference Documents
324
+
325
+ | Document | Purpose |
326
+ |----------|---------|
327
+ | [phases/orchestrator.md](phases/orchestrator.md) | Orchestrator: state reading + action selection |
328
+ | [phases/state-schema.md](phases/state-schema.md) | State structure definition |
329
+ | [specs/loop-requirements.md](specs/loop-requirements.md) | Loop requirements specification |
330
+ | [specs/action-catalog.md](specs/action-catalog.md) | Action catalog |
331
+
332
+ ## Error Handling
333
+
334
+ | Situation | Action |
335
+ |-----------|--------|
336
+ | Session not found | Create new session |
337
+ | State file corrupted | Rebuild from file contents |
338
+ | Agent timeout | send_input to request convergence |
339
+ | Agent unexpectedly closed | Re-spawn, paste previous output |
340
+ | Tests fail | Loop back to develop/debug |
341
+ | >10 iterations | Warn user, suggest break |
342
+
343
+ ## Codex Best Practices Applied
344
+
345
+ 1. **Role Path Passing**: Agent reads role file itself (no content embedding)
346
+ 2. **Single Agent Deep Interaction**: Use send_input for multi-phase instead of multiple agents
347
+ 3. **Delayed close_agent**: Only close after confirming no more interaction needed
348
+ 4. **Context Reuse**: Same agent maintains all exploration context automatically
349
+ 5. **Explicit wait()**: Always use wait({ ids }) to get results, not close_agent