claude-code-workflow 6.3.36 → 6.3.37
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-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/ccw/dist/cli.d.ts.map +1 -1
- package/ccw/dist/cli.js +8 -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/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/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/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/semantic-handlers.d.ts.map +1 -1
- package/ccw/dist/core/routes/codexlens/semantic-handlers.js +3 -2
- 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/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 +35 -0
- package/ccw/dist/core/routes/loop-v2-routes.d.ts.map +1 -0
- package/ccw/dist/core/routes/loop-v2-routes.js +1208 -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/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 +43 -3
- 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/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 +138 -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/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/src/cli.ts +9 -1
- package/ccw/src/commands/cli.ts +14 -1
- package/ccw/src/commands/loop.ts +344 -0
- package/ccw/src/core/dashboard-generator.ts +4 -1
- package/ccw/src/core/routes/claude-routes.ts +5 -3
- package/ccw/src/core/routes/cli-routes.ts +47 -15
- package/ccw/src/core/routes/cli-settings-routes.ts +47 -0
- package/ccw/src/core/routes/codexlens/semantic-handlers.ts +3 -2
- 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/loop-routes.ts +386 -0
- package/ccw/src/core/routes/loop-v2-routes.ts +1412 -0
- package/ccw/src/core/routes/memory-routes.ts +2 -1
- 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 +44 -3
- package/ccw/src/core/websocket.ts +104 -0
- package/ccw/src/templates/dashboard-css/12-cli-legacy.css +56 -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-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 +10 -0
- package/ccw/src/templates/dashboard-js/components/notifications.js +16 -0
- package/ccw/src/templates/dashboard-js/i18n.js +475 -1
- package/ccw/src/templates/dashboard-js/views/cli-manager.js +3 -2
- package/ccw/src/templates/dashboard-js/views/loop-monitor.js +3244 -0
- package/ccw/src/templates/dashboard.html +20 -2
- package/ccw/src/tools/claude-cli-tools.ts +143 -0
- 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 +380 -0
- package/ccw/src/types/index.ts +1 -0
- package/ccw/src/types/loop.ts +316 -0
- package/package.json +1 -1
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
# State Schema
|
|
2
|
+
|
|
3
|
+
CCW Loop 的状态结构定义(统一版本)。
|
|
4
|
+
|
|
5
|
+
## 状态文件
|
|
6
|
+
|
|
7
|
+
**位置**: `.loop/{loopId}.json` (统一位置,API + Skill 共享)
|
|
8
|
+
|
|
9
|
+
**旧版本位置** (仅向后兼容): `.workflow/.loop/{session-id}/state.json`
|
|
10
|
+
|
|
11
|
+
## 结构定义
|
|
12
|
+
|
|
13
|
+
### 统一状态接口 (Unified Loop State)
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
/**
|
|
17
|
+
* Unified Loop State - API 和 Skill 共享的状态结构
|
|
18
|
+
* API (loop-v2-routes.ts) 拥有状态的主控权
|
|
19
|
+
* Skill (ccw-loop) 读取和更新此状态
|
|
20
|
+
*/
|
|
21
|
+
interface LoopState {
|
|
22
|
+
// =====================================================
|
|
23
|
+
// API FIELDS (from loop-v2-routes.ts)
|
|
24
|
+
// 这些字段由 API 管理,Skill 只读
|
|
25
|
+
// =====================================================
|
|
26
|
+
|
|
27
|
+
loop_id: string // Loop ID, e.g., "loop-v2-20260122-abc123"
|
|
28
|
+
title: string // Loop 标题
|
|
29
|
+
description: string // Loop 描述
|
|
30
|
+
max_iterations: number // 最大迭代次数
|
|
31
|
+
status: 'created' | 'running' | 'paused' | 'completed' | 'failed'
|
|
32
|
+
current_iteration: number // 当前迭代次数
|
|
33
|
+
created_at: string // 创建时间 (ISO8601)
|
|
34
|
+
updated_at: string // 最后更新时间 (ISO8601)
|
|
35
|
+
completed_at?: string // 完成时间 (ISO8601)
|
|
36
|
+
failure_reason?: string // 失败原因
|
|
37
|
+
|
|
38
|
+
// =====================================================
|
|
39
|
+
// SKILL EXTENSION FIELDS
|
|
40
|
+
// 这些字段由 Skill 管理,API 只读
|
|
41
|
+
// =====================================================
|
|
42
|
+
|
|
43
|
+
skill_state?: {
|
|
44
|
+
// 当前执行动作
|
|
45
|
+
current_action: 'init' | 'develop' | 'debug' | 'validate' | 'complete' | null
|
|
46
|
+
last_action: string | null
|
|
47
|
+
completed_actions: string[]
|
|
48
|
+
mode: 'interactive' | 'auto'
|
|
49
|
+
|
|
50
|
+
// === 开发阶段 ===
|
|
51
|
+
develop: {
|
|
52
|
+
total: number
|
|
53
|
+
completed: number
|
|
54
|
+
current_task?: string
|
|
55
|
+
tasks: DevelopTask[]
|
|
56
|
+
last_progress_at: string | null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// === 调试阶段 ===
|
|
60
|
+
debug: {
|
|
61
|
+
active_bug?: string
|
|
62
|
+
hypotheses_count: number
|
|
63
|
+
hypotheses: Hypothesis[]
|
|
64
|
+
confirmed_hypothesis: string | null
|
|
65
|
+
iteration: number
|
|
66
|
+
last_analysis_at: string | null
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// === 验证阶段 ===
|
|
70
|
+
validate: {
|
|
71
|
+
pass_rate: number // 测试通过率 (0-100)
|
|
72
|
+
coverage: number // 覆盖率 (0-100)
|
|
73
|
+
test_results: TestResult[]
|
|
74
|
+
passed: boolean
|
|
75
|
+
failed_tests: string[]
|
|
76
|
+
last_run_at: string | null
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// === 错误追踪 ===
|
|
80
|
+
errors: Array<{
|
|
81
|
+
action: string
|
|
82
|
+
message: string
|
|
83
|
+
timestamp: string
|
|
84
|
+
}>
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
interface DevelopTask {
|
|
89
|
+
id: string
|
|
90
|
+
description: string
|
|
91
|
+
tool: 'gemini' | 'qwen' | 'codex' | 'bash'
|
|
92
|
+
mode: 'analysis' | 'write'
|
|
93
|
+
status: 'pending' | 'in_progress' | 'completed' | 'failed'
|
|
94
|
+
files_changed: string[]
|
|
95
|
+
created_at: string
|
|
96
|
+
completed_at: string | null
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface Hypothesis {
|
|
100
|
+
id: string // H1, H2, ...
|
|
101
|
+
description: string
|
|
102
|
+
testable_condition: string
|
|
103
|
+
logging_point: string
|
|
104
|
+
evidence_criteria: {
|
|
105
|
+
confirm: string
|
|
106
|
+
reject: string
|
|
107
|
+
}
|
|
108
|
+
likelihood: number // 1 = 最可能
|
|
109
|
+
status: 'pending' | 'confirmed' | 'rejected' | 'inconclusive'
|
|
110
|
+
evidence: Record<string, any> | null
|
|
111
|
+
verdict_reason: string | null
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface TestResult {
|
|
115
|
+
test_name: string
|
|
116
|
+
suite: string
|
|
117
|
+
status: 'passed' | 'failed' | 'skipped'
|
|
118
|
+
duration_ms: number
|
|
119
|
+
error_message: string | null
|
|
120
|
+
stack_trace: string | null
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## 初始状态
|
|
125
|
+
|
|
126
|
+
### 由 API 创建时 (Dashboard 触发)
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"loop_id": "loop-v2-20260122-abc123",
|
|
131
|
+
"title": "Implement user authentication",
|
|
132
|
+
"description": "Add login/logout functionality",
|
|
133
|
+
"max_iterations": 10,
|
|
134
|
+
"status": "created",
|
|
135
|
+
"current_iteration": 0,
|
|
136
|
+
"created_at": "2026-01-22T10:00:00+08:00",
|
|
137
|
+
"updated_at": "2026-01-22T10:00:00+08:00"
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 由 Skill 初始化后 (action-init)
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"loop_id": "loop-v2-20260122-abc123",
|
|
146
|
+
"title": "Implement user authentication",
|
|
147
|
+
"description": "Add login/logout functionality",
|
|
148
|
+
"max_iterations": 10,
|
|
149
|
+
"status": "running",
|
|
150
|
+
"current_iteration": 0,
|
|
151
|
+
"created_at": "2026-01-22T10:00:00+08:00",
|
|
152
|
+
"updated_at": "2026-01-22T10:00:05+08:00",
|
|
153
|
+
|
|
154
|
+
"skill_state": {
|
|
155
|
+
"current_action": "init",
|
|
156
|
+
"last_action": null,
|
|
157
|
+
"completed_actions": [],
|
|
158
|
+
"mode": "auto",
|
|
159
|
+
|
|
160
|
+
"develop": {
|
|
161
|
+
"total": 3,
|
|
162
|
+
"completed": 0,
|
|
163
|
+
"current_task": null,
|
|
164
|
+
"tasks": [
|
|
165
|
+
{ "id": "task-001", "description": "Create auth component", "status": "pending" }
|
|
166
|
+
],
|
|
167
|
+
"last_progress_at": null
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
"debug": {
|
|
171
|
+
"active_bug": null,
|
|
172
|
+
"hypotheses_count": 0,
|
|
173
|
+
"hypotheses": [],
|
|
174
|
+
"confirmed_hypothesis": null,
|
|
175
|
+
"iteration": 0,
|
|
176
|
+
"last_analysis_at": null
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
"validate": {
|
|
180
|
+
"pass_rate": 0,
|
|
181
|
+
"coverage": 0,
|
|
182
|
+
"test_results": [],
|
|
183
|
+
"passed": false,
|
|
184
|
+
"failed_tests": [],
|
|
185
|
+
"last_run_at": null
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
"errors": []
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## 控制信号检查 (Control Signals)
|
|
194
|
+
|
|
195
|
+
Skill 在每个 Action 开始前必须检查控制信号:
|
|
196
|
+
|
|
197
|
+
```javascript
|
|
198
|
+
/**
|
|
199
|
+
* 检查 API 控制信号
|
|
200
|
+
* @returns { continue: boolean, action: 'pause_exit' | 'stop_exit' | 'continue' }
|
|
201
|
+
*/
|
|
202
|
+
function checkControlSignals(loopId) {
|
|
203
|
+
const state = JSON.parse(Read(`.loop/${loopId}.json`))
|
|
204
|
+
|
|
205
|
+
switch (state.status) {
|
|
206
|
+
case 'paused':
|
|
207
|
+
// API 暂停了循环,Skill 应退出等待 resume
|
|
208
|
+
return { continue: false, action: 'pause_exit' }
|
|
209
|
+
|
|
210
|
+
case 'failed':
|
|
211
|
+
// API 停止了循环 (用户手动停止)
|
|
212
|
+
return { continue: false, action: 'stop_exit' }
|
|
213
|
+
|
|
214
|
+
case 'running':
|
|
215
|
+
// 正常继续
|
|
216
|
+
return { continue: true, action: 'continue' }
|
|
217
|
+
|
|
218
|
+
default:
|
|
219
|
+
// 异常状态
|
|
220
|
+
return { continue: false, action: 'stop_exit' }
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 在 Action 中使用
|
|
226
|
+
|
|
227
|
+
```markdown
|
|
228
|
+
## Execution
|
|
229
|
+
|
|
230
|
+
### Step 1: Check Control Signals
|
|
231
|
+
|
|
232
|
+
\`\`\`javascript
|
|
233
|
+
const control = checkControlSignals(loopId)
|
|
234
|
+
if (!control.continue) {
|
|
235
|
+
// 输出退出原因
|
|
236
|
+
console.log(`Loop ${control.action}: status = ${state.status}`)
|
|
237
|
+
|
|
238
|
+
// 如果是 pause_exit,保存当前进度
|
|
239
|
+
if (control.action === 'pause_exit') {
|
|
240
|
+
updateSkillState(loopId, { current_action: 'paused' })
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return // 退出 Action
|
|
244
|
+
}
|
|
245
|
+
\`\`\`
|
|
246
|
+
|
|
247
|
+
### Step 2: Execute Action Logic
|
|
248
|
+
...
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## 状态转换规则
|
|
252
|
+
|
|
253
|
+
### 1. 初始化 (action-init)
|
|
254
|
+
|
|
255
|
+
```javascript
|
|
256
|
+
// Skill 初始化后
|
|
257
|
+
{
|
|
258
|
+
// API 字段更新
|
|
259
|
+
status: 'created' → 'running', // 或保持 'running' 如果 API 已设置
|
|
260
|
+
updated_at: timestamp,
|
|
261
|
+
|
|
262
|
+
// Skill 字段初始化
|
|
263
|
+
skill_state: {
|
|
264
|
+
current_action: 'init',
|
|
265
|
+
mode: 'auto',
|
|
266
|
+
develop: {
|
|
267
|
+
tasks: [...parsed_tasks],
|
|
268
|
+
total: N,
|
|
269
|
+
completed: 0
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### 2. 开发进行中 (action-develop-with-file)
|
|
276
|
+
|
|
277
|
+
```javascript
|
|
278
|
+
// 开发任务执行后
|
|
279
|
+
{
|
|
280
|
+
updated_at: timestamp,
|
|
281
|
+
current_iteration: state.current_iteration + 1,
|
|
282
|
+
|
|
283
|
+
skill_state: {
|
|
284
|
+
current_action: 'develop',
|
|
285
|
+
last_action: 'action-develop-with-file',
|
|
286
|
+
completed_actions: [...state.skill_state.completed_actions, 'action-develop-with-file'],
|
|
287
|
+
develop: {
|
|
288
|
+
current_task: 'task-xxx',
|
|
289
|
+
completed: N+1,
|
|
290
|
+
last_progress_at: timestamp
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### 3. 调试进行中 (action-debug-with-file)
|
|
297
|
+
|
|
298
|
+
```javascript
|
|
299
|
+
// 调试执行后
|
|
300
|
+
{
|
|
301
|
+
updated_at: timestamp,
|
|
302
|
+
current_iteration: state.current_iteration + 1,
|
|
303
|
+
|
|
304
|
+
skill_state: {
|
|
305
|
+
current_action: 'debug',
|
|
306
|
+
last_action: 'action-debug-with-file',
|
|
307
|
+
debug: {
|
|
308
|
+
active_bug: '...',
|
|
309
|
+
hypotheses_count: N,
|
|
310
|
+
hypotheses: [...new_hypotheses],
|
|
311
|
+
iteration: N+1,
|
|
312
|
+
last_analysis_at: timestamp
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### 4. 验证完成 (action-validate-with-file)
|
|
319
|
+
|
|
320
|
+
```javascript
|
|
321
|
+
// 验证执行后
|
|
322
|
+
{
|
|
323
|
+
updated_at: timestamp,
|
|
324
|
+
current_iteration: state.current_iteration + 1,
|
|
325
|
+
|
|
326
|
+
skill_state: {
|
|
327
|
+
current_action: 'validate',
|
|
328
|
+
last_action: 'action-validate-with-file',
|
|
329
|
+
validate: {
|
|
330
|
+
test_results: [...results],
|
|
331
|
+
pass_rate: 95.5,
|
|
332
|
+
coverage: 85.0,
|
|
333
|
+
passed: true | false,
|
|
334
|
+
failed_tests: ['test1', 'test2'],
|
|
335
|
+
last_run_at: timestamp
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### 5. 完成 (action-complete)
|
|
342
|
+
|
|
343
|
+
```javascript
|
|
344
|
+
// 循环完成后
|
|
345
|
+
{
|
|
346
|
+
status: 'running' → 'completed',
|
|
347
|
+
completed_at: timestamp,
|
|
348
|
+
updated_at: timestamp,
|
|
349
|
+
|
|
350
|
+
skill_state: {
|
|
351
|
+
current_action: 'complete',
|
|
352
|
+
last_action: 'action-complete'
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
## 状态派生字段
|
|
358
|
+
|
|
359
|
+
以下字段可从状态计算得出,不需要存储:
|
|
360
|
+
|
|
361
|
+
```javascript
|
|
362
|
+
// 开发完成度
|
|
363
|
+
const developProgress = state.develop.total_count > 0
|
|
364
|
+
? (state.develop.completed_count / state.develop.total_count) * 100
|
|
365
|
+
: 0
|
|
366
|
+
|
|
367
|
+
// 是否有待开发任务
|
|
368
|
+
const hasPendingDevelop = state.develop.tasks.some(t => t.status === 'pending')
|
|
369
|
+
|
|
370
|
+
// 调试是否完成
|
|
371
|
+
const debugCompleted = state.debug.confirmed_hypothesis !== null
|
|
372
|
+
|
|
373
|
+
// 验证是否通过
|
|
374
|
+
const validationPassed = state.validate.passed && state.validate.test_results.length > 0
|
|
375
|
+
|
|
376
|
+
// 整体进度
|
|
377
|
+
const overallProgress = (
|
|
378
|
+
(developProgress * 0.5) +
|
|
379
|
+
(debugCompleted ? 25 : 0) +
|
|
380
|
+
(validationPassed ? 25 : 0)
|
|
381
|
+
)
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
## 文件同步
|
|
385
|
+
|
|
386
|
+
### 统一位置 (Unified Location)
|
|
387
|
+
|
|
388
|
+
状态与文件的对应关系:
|
|
389
|
+
|
|
390
|
+
| 状态字段 | 同步文件 | 同步时机 |
|
|
391
|
+
|----------|----------|----------|
|
|
392
|
+
| 整个 LoopState | `.loop/{loopId}.json` | 每次状态变更 (主文件) |
|
|
393
|
+
| `skill_state.develop` | `.loop/{loopId}.progress/develop.md` | 每次开发操作后 |
|
|
394
|
+
| `skill_state.debug` | `.loop/{loopId}.progress/debug.md` | 每次调试操作后 |
|
|
395
|
+
| `skill_state.validate` | `.loop/{loopId}.progress/validate.md` | 每次验证操作后 |
|
|
396
|
+
| 代码变更日志 | `.loop/{loopId}.progress/changes.log` | 每次文件修改 (NDJSON) |
|
|
397
|
+
| 调试日志 | `.loop/{loopId}.progress/debug.log` | 每次调试日志 (NDJSON) |
|
|
398
|
+
|
|
399
|
+
### 文件结构示例
|
|
400
|
+
|
|
401
|
+
```
|
|
402
|
+
.loop/
|
|
403
|
+
├── loop-v2-20260122-abc123.json # 主状态文件 (API + Skill)
|
|
404
|
+
├── loop-v2-20260122-abc123.tasks.jsonl # 任务列表 (API 管理)
|
|
405
|
+
└── loop-v2-20260122-abc123.progress/ # Skill 进度文件
|
|
406
|
+
├── develop.md # 开发进度
|
|
407
|
+
├── debug.md # 调试理解
|
|
408
|
+
├── validate.md # 验证报告
|
|
409
|
+
├── changes.log # 代码变更 (NDJSON)
|
|
410
|
+
└── debug.log # 调试日志 (NDJSON)
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## 状态恢复
|
|
414
|
+
|
|
415
|
+
如果主状态文件 `.loop/{loopId}.json` 损坏,可以从进度文件重建 skill_state:
|
|
416
|
+
|
|
417
|
+
```javascript
|
|
418
|
+
function rebuildSkillStateFromProgress(loopId) {
|
|
419
|
+
const progressDir = `.loop/${loopId}.progress`
|
|
420
|
+
|
|
421
|
+
// 尝试从进度文件解析状态
|
|
422
|
+
const skill_state = {
|
|
423
|
+
develop: parseProgressFile(`${progressDir}/develop.md`),
|
|
424
|
+
debug: parseProgressFile(`${progressDir}/debug.md`),
|
|
425
|
+
validate: parseProgressFile(`${progressDir}/validate.md`)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return skill_state
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// 解析进度 Markdown 文件
|
|
432
|
+
function parseProgressFile(filePath) {
|
|
433
|
+
const content = Read(filePath)
|
|
434
|
+
if (!content) return null
|
|
435
|
+
|
|
436
|
+
// 从 Markdown 表格和结构中提取数据
|
|
437
|
+
// ... implementation
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### 恢复策略
|
|
442
|
+
|
|
443
|
+
1. **API 字段**: 无法恢复 - 需要从 API 重新获取或用户手动输入
|
|
444
|
+
2. **skill_state 字段**: 可以从 `.progress/` 目录的 Markdown 文件解析
|
|
445
|
+
3. **任务列表**: 从 `.loop/{loopId}.tasks.jsonl` 恢复
|
|
446
|
+
|
|
447
|
+
## 状态验证
|
|
448
|
+
|
|
449
|
+
```javascript
|
|
450
|
+
function validateState(state) {
|
|
451
|
+
const errors = []
|
|
452
|
+
|
|
453
|
+
// 必需字段
|
|
454
|
+
if (!state.session_id) errors.push('Missing session_id')
|
|
455
|
+
if (!state.task_description) errors.push('Missing task_description')
|
|
456
|
+
|
|
457
|
+
// 状态一致性
|
|
458
|
+
if (state.initialized && state.status === 'pending') {
|
|
459
|
+
errors.push('Inconsistent: initialized but status is pending')
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
if (state.status === 'completed' && !state.validate.passed) {
|
|
463
|
+
errors.push('Inconsistent: completed but validation not passed')
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// 开发任务一致性
|
|
467
|
+
const completedTasks = state.develop.tasks.filter(t => t.status === 'completed').length
|
|
468
|
+
if (completedTasks !== state.develop.completed_count) {
|
|
469
|
+
errors.push('Inconsistent: completed_count mismatch')
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
return { valid: errors.length === 0, errors }
|
|
473
|
+
}
|
|
474
|
+
```
|