@boyingliu01/xp-gate 0.9.0 → 0.9.2
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/adapters/cpp.sh +3 -3
- package/adapters/dart.sh +2 -2
- package/adapters/flutter.sh +2 -2
- package/adapters/java.sh +4 -4
- package/adapters/kotlin.sh +4 -4
- package/adapters/objectivec.sh +2 -2
- package/adapters/plugins/p3c-java/scripts/install-maven-p3c.sh +3 -3
- package/adapters/plugins/whalecloud-java/scripts/install-maven-whalecloud.sh +3 -3
- package/adapters/powershell.sh +3 -3
- package/adapters/python.sh +2 -2
- package/adapters/shell.sh +3 -3
- package/adapters/swift.sh +2 -2
- package/package.json +1 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/admin-template-guidelines/SKILL.md +6 -797
- package/plugins/claude-code/skills/admin-template-guidelines/references/rule-1.md +91 -0
- package/plugins/claude-code/skills/admin-template-guidelines/references/rule-2.md +155 -0
- package/plugins/claude-code/skills/admin-template-guidelines/references/rule-3.md +70 -0
- package/plugins/claude-code/skills/admin-template-guidelines/references/rule-4.md +154 -0
- package/plugins/claude-code/skills/admin-template-guidelines/references/rule-5.md +126 -0
- package/plugins/claude-code/skills/admin-template-guidelines/references/rule-6.md +180 -0
- package/plugins/claude-code/skills/delphi-review/SKILL.md +59 -361
- package/plugins/claude-code/skills/delphi-review/references/orchestrator-dispatch.md +64 -0
- package/plugins/claude-code/skills/delphi-review/references/round-templates.md +67 -0
- package/plugins/claude-code/skills/ralph-loop/SKILL.md +87 -429
- package/plugins/claude-code/skills/ralph-loop/references/components.md +113 -0
- package/plugins/claude-code/skills/ralph-loop/references/workflow-details.md +99 -0
- package/plugins/claude-code/skills/test-specification-alignment/SKILL.md +97 -599
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/admin-template-guidelines/SKILL.md +6 -797
- package/plugins/opencode/skills/admin-template-guidelines/references/rule-1.md +91 -0
- package/plugins/opencode/skills/admin-template-guidelines/references/rule-2.md +155 -0
- package/plugins/opencode/skills/admin-template-guidelines/references/rule-3.md +70 -0
- package/plugins/opencode/skills/admin-template-guidelines/references/rule-4.md +154 -0
- package/plugins/opencode/skills/admin-template-guidelines/references/rule-5.md +126 -0
- package/plugins/opencode/skills/admin-template-guidelines/references/rule-6.md +180 -0
- package/plugins/opencode/skills/delphi-review/SKILL.md +59 -361
- package/plugins/opencode/skills/delphi-review/references/orchestrator-dispatch.md +64 -0
- package/plugins/opencode/skills/delphi-review/references/round-templates.md +67 -0
- package/plugins/opencode/skills/ralph-loop/SKILL.md +87 -429
- package/plugins/opencode/skills/ralph-loop/references/components.md +113 -0
- package/plugins/opencode/skills/ralph-loop/references/workflow-details.md +99 -0
- package/plugins/opencode/skills/test-specification-alignment/SKILL.md +97 -599
- package/skills/admin-template-guidelines/SKILL.md +6 -797
- package/skills/admin-template-guidelines/references/rule-1.md +91 -0
- package/skills/admin-template-guidelines/references/rule-2.md +155 -0
- package/skills/admin-template-guidelines/references/rule-3.md +70 -0
- package/skills/admin-template-guidelines/references/rule-4.md +154 -0
- package/skills/admin-template-guidelines/references/rule-5.md +126 -0
- package/skills/admin-template-guidelines/references/rule-6.md +180 -0
- package/skills/delphi-review/SKILL.md +59 -361
- package/skills/delphi-review/references/orchestrator-dispatch.md +64 -0
- package/skills/delphi-review/references/round-templates.md +67 -0
- package/skills/ralph-loop/SKILL.md +87 -429
- package/skills/ralph-loop/references/components.md +113 -0
- package/skills/ralph-loop/references/workflow-details.md +99 -0
- package/skills/test-specification-alignment/SKILL.md +97 -599
- package/plugins/claude-code/skills/ralph-loop/references/components/memory.md +0 -55
- package/plugins/claude-code/skills/ralph-loop/references/components/middleware.md +0 -54
- package/plugins/claude-code/skills/ralph-loop/references/components/skill-invocations.md +0 -39
- package/plugins/claude-code/skills/ralph-loop/references/components/system-prompt.md +0 -24
- package/plugins/claude-code/skills/ralph-loop/references/components/tool-descriptions.md +0 -32
- package/plugins/opencode/skills/ralph-loop/references/components/memory.md +0 -55
- package/plugins/opencode/skills/ralph-loop/references/components/middleware.md +0 -54
- package/plugins/opencode/skills/ralph-loop/references/components/skill-invocations.md +0 -39
- package/plugins/opencode/skills/ralph-loop/references/components/system-prompt.md +0 -24
- package/plugins/opencode/skills/ralph-loop/references/components/tool-descriptions.md +0 -32
- package/skills/ralph-loop/references/components/memory.md +0 -55
- package/skills/ralph-loop/references/components/middleware.md +0 -54
- package/skills/ralph-loop/references/components/skill-invocations.md +0 -39
- package/skills/ralph-loop/references/components/system-prompt.md +0 -24
- package/skills/ralph-loop/references/components/tool-descriptions.md +0 -32
|
@@ -6,56 +6,29 @@ maturity: stable
|
|
|
6
6
|
|
|
7
7
|
# Ralph Loop — Default REQ-Level Iterative Build
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
| 原则 | 说明 |
|
|
12
|
-
|------|------|
|
|
13
|
-
| **每次迭代 = 全新上下文** | 每个 REQ dispatch 独立 subagent,不累积历史对话 |
|
|
14
|
-
| **一次只处理一个 REQ** | 小粒度执行,避免大任务吞掉整个 context window |
|
|
15
|
-
| **失败不提交** | 验证不通过的代码不 commit,保持代码库绿色 |
|
|
16
|
-
| **全量回归测试** | 每个 REQ 完成后运行 ALL tests(不只是 @test REQ-XXX),检测跨 REQ 回归 |
|
|
17
|
-
| **Git 持久记忆** | 代码变更 + checkpoint 天然持久,不需要在 prompt 里反复解释 |
|
|
18
|
-
| **浓缩型分类学习** | permanent(架构级)+ contextual(最近 3 条)双层 learnings |
|
|
19
|
-
| **AGENTS.md 统一更新** | orchestrator 统一写,subagent 不直接修改 — 无竞态 |
|
|
20
|
-
|
|
21
|
-
---
|
|
9
|
+
Core principles: **isolated context per REQ**, **TDD-first**, **full regression every iteration**, **token efficiency** (40-67% savings vs parallel).
|
|
22
10
|
|
|
23
11
|
## Triggers
|
|
24
12
|
|
|
25
|
-
|
|
13
|
+
**Keywords**: ralph-loop, process one REQ, Phase 2 BUILD, iterate REQ, isolated REQ build
|
|
26
14
|
|
|
27
|
-
|
|
28
|
-
- 执行 Sprint-Flow Phase 2 BUILD 阶段
|
|
29
|
-
- 从 specification.yaml 读取需求逐个实现
|
|
30
|
-
- 需要控制每个 REQ 的 token 预算
|
|
31
|
-
- 防止上下文污染(前一个 REQ 的实现细节影响后一个 REQ)
|
|
32
|
-
- 需要全量回归测试保证不引入回归
|
|
33
|
-
- 需要持久化 learnings 供后续 REQ 参考
|
|
15
|
+
**Use when**: executing Sprint-Flow Phase 2 BUILD; reading specification.yaml to implement REQs one-by-one; needing controlled token budget per REQ; preventing context pollution between REQs; full regression needed per step.
|
|
34
16
|
|
|
35
|
-
|
|
36
|
-
- 需求数量极少(1-2 个)且相互独立,可以并行
|
|
37
|
-
- 紧急热修复,不需要完整 Sprint Flow
|
|
38
|
-
- 明确使用 `--mode parallel` 切换到并行模式
|
|
17
|
+
**Don't use**: 1-2 simple independent REQs (use parallel); emergency hotfix; `--mode parallel` is explicitly set.
|
|
39
18
|
|
|
40
|
-
##
|
|
19
|
+
## Architecture Overview
|
|
41
20
|
|
|
42
|
-
Ralph Loop
|
|
21
|
+
Ralph Loop is the **default Phase 2 BUILD mode**. Each REQ gets a fresh subagent context:
|
|
43
22
|
|
|
44
23
|
```
|
|
45
|
-
Sprint-Flow Phase 2 (
|
|
46
|
-
ralph-loop →
|
|
24
|
+
Sprint-Flow Phase 2 (default):
|
|
25
|
+
ralph-loop → per-REQ iteration → clean context each time → full regression
|
|
47
26
|
|
|
48
|
-
Sprint-Flow Phase 2 --mode parallel
|
|
49
|
-
dispatching-parallel-agents →
|
|
27
|
+
Sprint-Flow Phase 2 (--mode parallel):
|
|
28
|
+
dispatching-parallel-agents → parallel dispatch → context grows linearly
|
|
50
29
|
```
|
|
51
30
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
**切换回并行模式**: `/sprint-flow "需求" --mode parallel`
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
## 完整流程
|
|
31
|
+
## Full Flow
|
|
59
32
|
|
|
60
33
|
```
|
|
61
34
|
Phase 0: 准备 → 读取 specification.yaml → 构建依赖图 → 拓扑排序
|
|
@@ -65,237 +38,113 @@ Phase 1: 迭代循环 (max_iterations=15 默认)
|
|
|
65
38
|
│
|
|
66
39
|
├── 取下一个 READY REQ(依赖已满足,优先级最高)
|
|
67
40
|
│
|
|
68
|
-
├── 测试基础设施检查
|
|
69
|
-
│
|
|
70
|
-
│
|
|
71
|
-
│ 3. 不存在或接口缺失 → dispatch "生成测试基础设施" subagent
|
|
72
|
-
│ retry max 2 → 仍失败 → BLOCK 或 fallback inline 生成
|
|
73
|
-
│ 4. 与业务代码合并为同一 commit
|
|
41
|
+
├── 测试基础设施检查 (test-utils.ts)
|
|
42
|
+
│ ├── 不存在或接口缺失 → dispatch 生成 subagent (retry max 2)
|
|
43
|
+
│ └── 已存在 → 注入 API 摘要到 subagent context
|
|
74
44
|
│
|
|
75
|
-
├──
|
|
76
|
-
│
|
|
77
|
-
│
|
|
78
|
-
│ - withTestDb(): 测试数据库生命周期(seed + cleanup)
|
|
79
|
-
│ 必须 import 这些函数,禁止重新手搓同名 helper。
|
|
45
|
+
├── Dispatch 独立 subagent (unspecified-high + test-driven-development)
|
|
46
|
+
│ Context: 当前 REQ + AC + permanent learnings + contextual learnings
|
|
47
|
+
│ + AGENTS.md + git log -5 + Mock 边界策略
|
|
80
48
|
│
|
|
81
|
-
├──
|
|
82
|
-
│ 使用: task(category="unspecified-high", load_skills=["test-driven-development"], timeout=300)
|
|
83
|
-
│ Context:
|
|
84
|
-
│ - 当前 REQ + 所有 AC
|
|
85
|
-
│ - permanent learnings(架构决策,始终传入)
|
|
86
|
-
│ - contextual learnings(最近 3 条)
|
|
87
|
-
│ - retry-failures(仅 retry 时注入失败原因)
|
|
88
|
-
│ - AGENTS.md(项目约定)
|
|
89
|
-
│ - git log --oneline -5
|
|
90
|
-
│ - 【TDD 铁律】RED → GREEN → REFACTOR。任何模块必须先写测试再写实现。
|
|
91
|
-
│ - 【Mock 边界】(覆盖 TDD skill 默认策略)
|
|
92
|
-
│ ✅ MOCK: 外部 HTTP API、LLM 调用、第三方平台(钉钉/微信)
|
|
93
|
-
│ ✅ MOCK: 时间/随机数/UUID(注入依赖)
|
|
94
|
-
│ ❌ NO MOCK: 数据库操作(用真实测试库或 sqlite-in-memory)
|
|
95
|
-
│ ❌ NO MOCK: HTTP 路由(用 app.inject() 真实注入)
|
|
96
|
-
│ ❌ NO MOCK: 模板引擎(用真实 Nunjucks/Jinja 渲染)
|
|
97
|
-
│ ❌ NO MOCK: 纯业务逻辑(用真实输入输出)
|
|
98
|
-
│ - 【Mock 密度上限】测试中 mock/spy/fn 引用行数 > 总测试行数 30% 时,
|
|
99
|
-
│ 必须添加 // @mock-justified: <至少10字符理由> 注释说明为何无法用集成测试。
|
|
100
|
-
│
|
|
101
|
-
├── Subagent 完成 → 三层验证
|
|
49
|
+
├── 三层验证
|
|
102
50
|
│ ├── L1: typecheck + lint → FAIL? → retry
|
|
51
|
+
│ ├── L1b: 测试行占比 ≥ 40% → FAIL? → retry
|
|
103
52
|
│ ├── L2: 全量测试(ALL tests)→ FAIL? → retry
|
|
104
53
|
│ └── L3: coverage ≥ 80% → FAIL? → retry
|
|
105
54
|
│
|
|
106
55
|
├── PASS → git commit → 标记 done
|
|
107
|
-
│ → 写 learnings
|
|
108
|
-
│ →
|
|
109
|
-
│ → orchestrator 统一更新 AGENTS.md
|
|
110
|
-
│ → 原子写 checkpoint
|
|
56
|
+
│ → 写 learnings (permanent/contextual)
|
|
57
|
+
│ → orchestrator 更新 AGENTS.md
|
|
111
58
|
│ → 继续下一个 READY REQ
|
|
112
59
|
│
|
|
113
|
-
└── FAIL
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
终止条件:
|
|
118
|
-
- 所有 REQ done → COMPLETE → 返回 Phase 3 REVIEW
|
|
119
|
-
- max_iterations 达到 → PARTIAL → 保留 done commits
|
|
120
|
-
- BLOCK → WAIT_USER → skip/manual/stop/rollback
|
|
60
|
+
└── FAIL (max 3 retry) → BLOCK → 用户决策 (skip/manual/stop/rollback)
|
|
61
|
+
│
|
|
62
|
+
▼
|
|
63
|
+
终止条件: ALL DONE → COMPLETE | max_iterations → PARTIAL | BLOCK → WAIT_USER
|
|
121
64
|
```
|
|
122
65
|
|
|
123
|
-
---
|
|
124
|
-
|
|
125
66
|
## 输入格式 (specification.yaml)
|
|
126
67
|
|
|
127
68
|
```yaml
|
|
128
69
|
specification:
|
|
129
70
|
requirements:
|
|
130
71
|
- id: REQ-001
|
|
131
|
-
description: "
|
|
72
|
+
description: "Create User Model"
|
|
132
73
|
acceptance_criteria:
|
|
133
74
|
- id: AC-001-01
|
|
134
|
-
criteria: "
|
|
135
|
-
- id: AC-001-02
|
|
136
|
-
criteria: "Migration 成功执行"
|
|
75
|
+
criteria: "email (unique), password_hash, created_at"
|
|
137
76
|
priority: 1
|
|
138
77
|
status: pending
|
|
139
|
-
|
|
140
78
|
- id: REQ-002
|
|
141
|
-
description: "
|
|
79
|
+
description: "Password encryption"
|
|
142
80
|
depends_on: [REQ-001]
|
|
143
|
-
acceptance_criteria:
|
|
144
|
-
- id: AC-002-01
|
|
145
|
-
criteria: "hashPassword() 返回 bcrypt hash"
|
|
146
|
-
- id: AC-002-02
|
|
147
|
-
criteria: "verifyPassword() 正确比对明文和 hash"
|
|
148
81
|
priority: 2
|
|
149
82
|
status: pending
|
|
150
83
|
```
|
|
151
84
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
---
|
|
85
|
+
每个 REQ 自动作为迭代单元,所有 AC-XXX-XX 作为验收标准。
|
|
155
86
|
|
|
156
87
|
## 依赖排序
|
|
157
88
|
|
|
158
|
-
1.
|
|
159
|
-
2.
|
|
160
|
-
3.
|
|
161
|
-
4. **循环依赖**:→ BLOCK + 报告循环链(`REQ-A → REQ-B → REQ-C → REQ-A`)
|
|
162
|
-
|
|
163
|
-
---
|
|
164
|
-
|
|
165
|
-
## Learnings 分类
|
|
166
|
-
|
|
167
|
-
| 分类 | 内容 | 传递策略 | 升级条件 |
|
|
168
|
-
|------|------|---------|---------|
|
|
169
|
-
| **permanent** | 架构决策、接口约定、全局约定 | 始终传入(每个 REQ context)| (1) 被 ≥2 个 REQ 引用<br>(2) 涉及模块接口/数据结构<br>(3) 用户手动标记 |
|
|
170
|
-
| **contextual** | 实现细节、一次性 gotchas、临时技巧 | 滑动窗口(最近 3 条) | 满足 permanent 条件自动升级,否则 3 条后过期 |
|
|
171
|
-
|
|
172
|
-
**自动升级示例**:
|
|
173
|
-
- `"migration files must be in src/migrations/"` → 第 2 个 REQ 也引用 → 升级为 permanent
|
|
174
|
-
- `"use bcrypt 不要使用 md5"` → 安全规范 → 自动 permanent
|
|
175
|
-
- `"第 42 行有个 off-by-one"` → 仅影响单个 REQ → 保持 contextual
|
|
176
|
-
|
|
177
|
-
---
|
|
178
|
-
|
|
179
|
-
## AGENTS.md 更新机制
|
|
180
|
-
|
|
181
|
-
**由 orchestrator 统一执行,不由 subagent 各自写**:
|
|
182
|
-
|
|
183
|
-
1. subagent 完成后输出 `agentmd_addition` 字段
|
|
184
|
-
2. orchestrator 读取当前 AGENTS.md
|
|
185
|
-
3. orchestrator append `## ralph-loop: [REQ-XXX title] (auto-added)` 段
|
|
186
|
-
4. orchestrator 将 AGENTS.md 变更纳入 git commit
|
|
187
|
-
|
|
188
|
-
当 AGENTS.md > 500 行时触发归档:保留最近 6 个月 entries,更早的归档到 `.sprint-state/ralph-loop/agents-archive/`。
|
|
189
|
-
|
|
190
|
-
---
|
|
191
|
-
|
|
192
|
-
## 三层验证 Gate
|
|
193
|
-
|
|
194
|
-
每个 REQ 完成后执行:
|
|
195
|
-
|
|
196
|
-
| 层级 | 范围 | 工具 | 失败行为 |
|
|
197
|
-
|------|------|------|---------|
|
|
198
|
-
| L1 | 变更文件 | `lsp_diagnostics` + linter | retry |
|
|
199
|
-
| L1b | 测试先行比率 | 新增测试行数 / (新增测试 + 新增实现) ≥ 40% | retry |
|
|
200
|
-
| L2 | **全量测试**(不只是 @test REQ-XXX) | 项目测试框架 | retry |
|
|
201
|
-
| L3 | 整体覆盖率 ≥ 80% | coverage report | retry |
|
|
202
|
-
|
|
203
|
-
---
|
|
89
|
+
1. 拓扑排序(Kahn's algorithm,基于 `depends_on`)
|
|
90
|
+
2. 同层按 `priority` 升序
|
|
91
|
+
3. 循环依赖 → BLOCK + 报告循环链
|
|
204
92
|
|
|
205
93
|
## 状态机
|
|
206
94
|
|
|
207
95
|
```
|
|
208
96
|
PENDING → test_infra_check → [infra needed?] → test_infra_dispatch
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
│
|
|
220
|
-
│ fail
|
|
221
|
-
▼
|
|
222
|
-
RETRY (n≤3, 注入上次错误)
|
|
223
|
-
│
|
|
224
|
-
│ n≥3
|
|
225
|
-
▼
|
|
226
|
-
BLOCKED → 用户决策 (skip/manual/stop/rollback)
|
|
227
|
-
│
|
|
228
|
-
│ 依赖上游 blocked → 自动 blocked(含依赖链)
|
|
229
|
-
▼
|
|
230
|
-
auto-blocked REQs
|
|
97
|
+
│ │
|
|
98
|
+
│ FAIL (max 2) │ pass
|
|
99
|
+
▼ ▼
|
|
100
|
+
BLOCK/fallback in_progress → done (commit)
|
|
101
|
+
│ │
|
|
102
|
+
│ depend not met │ all done → COMPLETE
|
|
103
|
+
▼ ▼
|
|
104
|
+
PENDING (waiting) RETRY (n≤3, 注入错误)
|
|
105
|
+
│
|
|
106
|
+
n≥3 → BLOCKED
|
|
231
107
|
```
|
|
232
108
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
| 从 | 到 | 触发 |
|
|
236
|
-
|---|---|---|
|
|
237
|
-
| pending | test_infra_check | 拓扑排序轮到 + 依赖已满足 |
|
|
238
|
-
| test_infra_check | test_infra_dispatch | test-utils.ts 不存在或接口缺失 |
|
|
239
|
-
| test_infra_check | in_progress | test-utils.ts 已存在且接口完整 |
|
|
240
|
-
| test_infra_dispatch | test_infra_ready | 测试基础设施生成完成 |
|
|
241
|
-
| test_infra_dispatch | blocked | retry max 2 仍失败 |
|
|
242
|
-
| test_infra_dispatch | test_infra_ready | fallback inline 生成成功(记录 warning)|
|
|
243
|
-
| test_infra_ready | in_progress | 测试基础设施就绪,dispatch 业务代码 subagent |
|
|
244
|
-
| in_progress | done | L1+L1b+L2+L3 全部通过 |
|
|
245
|
-
| in_progress | retry | 验证失败, n<3 |
|
|
246
|
-
| retry | done | 验证通过 |
|
|
247
|
-
| retry | blocked | n≥3 仍失败 |
|
|
248
|
-
| pending | blocked(auto) | 上游依赖 blocked |
|
|
249
|
-
| blocked | skipped | 用户选择跳过 |
|
|
250
|
-
| blocked | done | 用户手动修复后确认 |
|
|
251
|
-
| 任意 | partial | 用户选择停止 |
|
|
252
|
-
| 任意 | rollback | 用户选择回滚 (git reset) |
|
|
253
|
-
|
|
254
|
-
**崩溃恢复**:启动时检测 checkpoint → 跳过已 done REQs → 从下一个 pending 继续。已 commit 的 REQ 不需要重做。
|
|
255
|
-
|
|
256
|
-
---
|
|
109
|
+
**崩溃恢复**:检查 checkpoint → 跳过已 done REQs → 从下一个 pending 继续。
|
|
257
110
|
|
|
258
111
|
## Retry 策略
|
|
259
112
|
|
|
260
113
|
| 轮次 | 注入上下文 | 超时 |
|
|
261
114
|
|------|-----------|------|
|
|
262
|
-
|
|
|
263
|
-
|
|
|
264
|
-
|
|
|
265
|
-
|
|
266
|
-
---
|
|
115
|
+
| 1 | 标准上下文 | 300s |
|
|
116
|
+
| 2 | 标准 + 上次失败摘要 | 300s |
|
|
117
|
+
| 3 | 标准 + 前两次失败 + "请使用不同实现方式" | 300s |
|
|
267
118
|
|
|
268
|
-
##
|
|
119
|
+
## Mock 边界策略
|
|
269
120
|
|
|
270
|
-
|
|
121
|
+
| Mock | No Mock |
|
|
122
|
+
|------|---------|
|
|
123
|
+
| 外部 HTTP API、LLM 调用、第三方平台 | 数据库(真实测试库或 sqlite-in-memory)|
|
|
124
|
+
| 时间/随机数/UUID(注入依赖) | HTTP 路由(app.inject())|
|
|
125
|
+
| — | 模板引擎(真实渲染)|
|
|
126
|
+
| — | 纯业务逻辑(真实输入输出)|
|
|
271
127
|
|
|
272
|
-
|
|
273
|
-
/sprint-flow "开发用户登录"
|
|
274
|
-
# → Phase 2 自动使用 ralph-loop 模式
|
|
128
|
+
Mock 密度上限:mock/spy/fn 行数 > 总测试行 30% → 必须加 `// @mock-justified: <理由>`。
|
|
275
129
|
|
|
276
|
-
|
|
277
|
-
# → 可选:切换回旧有的并行模式
|
|
278
|
-
```
|
|
130
|
+
## Learnings 分类
|
|
279
131
|
|
|
280
|
-
|
|
132
|
+
| 分类 | 内容 | 传递策略 | 升级条件 |
|
|
133
|
+
|------|------|---------|---------|
|
|
134
|
+
| permanent | 架构决策、接口约定 | 始终传入 | ≥2 REQ 引用 / 涉及接口/数据结构 / 用户手动标记 |
|
|
135
|
+
| contextual | 实现细节、一次性 gotchas | 滑动窗口 (最近 3 条) | 满足 permanent 条件自动升级,否则过期 |
|
|
281
136
|
|
|
282
|
-
|
|
283
|
-
- Test alignment 仍解析 specification.yaml (REQ/AC 不变)
|
|
284
|
-
- 仍查找 `@test REQ-XXX` / `@covers AC-XXX-XX`
|
|
285
|
-
- PARTIAL 状态下仅检查已 done REQs
|
|
137
|
+
## AGENTS.md 更新机制
|
|
286
138
|
|
|
287
|
-
|
|
139
|
+
Orchestrator 统一执行,subagent 输出 `agentmd_addition` 字段,orchestrator append。>500 行触发归档到 `.sprint-state/ralph-loop/agents-archive/`。
|
|
288
140
|
|
|
289
|
-
## Output Format
|
|
141
|
+
## Output Format
|
|
290
142
|
|
|
291
143
|
```json
|
|
292
144
|
{
|
|
293
145
|
"skill_name": "ralph-loop",
|
|
294
146
|
"version": "2.0.0",
|
|
295
|
-
"specification_source": "specification.yaml",
|
|
296
|
-
"topology_order": ["REQ-001", "REQ-002", "REQ-003"],
|
|
297
147
|
"requirements": { "total": 6, "done": 4, "pending": 1, "blocked": 1, "skipped": 0 },
|
|
298
|
-
"current_requirement": { "id": "REQ-005", "status": "done", "retry_count": 0 },
|
|
299
148
|
"learnings": {
|
|
300
149
|
"permanent": ["Auth middleware must run before validation"],
|
|
301
150
|
"contextual": ["migration files must be in src/migrations/"]
|
|
@@ -305,236 +154,45 @@ Phase 0, 1, 3-6 行为完全不变。
|
|
|
305
154
|
}
|
|
306
155
|
```
|
|
307
156
|
|
|
308
|
-
**Eval
|
|
309
|
-
|
|
310
|
-
---
|
|
311
|
-
|
|
312
|
-
## Workflow Steps (Mandatory Execution Order)
|
|
313
|
-
|
|
314
|
-
**每个 REQ 必须按以下顺序执行,不得跳过或重排**:
|
|
315
|
-
|
|
316
|
-
1. **Load next READY REQ**
|
|
317
|
-
- 从 specification.yaml 读取下一个依赖已满足的 REQ
|
|
318
|
-
- 检查 priority 和 status (pending 状态)
|
|
319
|
-
- 构建依赖图,确认无循环依赖
|
|
320
|
-
|
|
321
|
-
2. **Create isolated context**
|
|
322
|
-
- 清空前一个 REQ 的对话历史
|
|
323
|
-
- 注入:当前 REQ + AC + permanent learnings + contextual learnings (最近 3 条)
|
|
324
|
-
- 注入:AGENTS.md + git log --oneline -5 + 测试基础设施摘要
|
|
325
|
-
|
|
326
|
-
3. **Pre-REQ snapshot(Issue #137)**
|
|
327
|
-
- 在 dispatch subagent 前记录当前 git HEAD,用于 TDD 合规的基线对比
|
|
328
|
-
```bash
|
|
329
|
-
# 保存当前 HEAD 作为 TDD 验证基线
|
|
330
|
-
PRE_REQ_HASH=$(git rev-parse HEAD)
|
|
331
|
-
echo "[TDD-BASELINE] Pre-REQ snapshot: $PRE_REQ_HASH"
|
|
332
|
-
# 记录到临时文件(subagent 只读基线,避免污染)
|
|
333
|
-
echo "$PRE_REQ_HASH" > .sprint-state/last-req-baseline.txt
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
3. **Dispatch build subagent**
|
|
337
|
-
- 使用 `task(category="unspecified-high", load_skills=["test-driven-development"], timeout=300)`
|
|
338
|
-
- 强制 TDD 流程:RED → GREEN → REFACTOR
|
|
339
|
-
- 强制执行 Mock 边界策略(详见 Mock 边界表)
|
|
340
|
-
|
|
341
|
-
4. **Run full regression tests**
|
|
342
|
-
- L1: typecheck + lint on changed files
|
|
343
|
-
- **L1b: 客观测试先行验证(Issue #137)** — 使用 git diff 验证新增测试行数占总新增行数比例
|
|
344
|
-
```bash
|
|
345
|
-
# 从基线读取 pre-REQ HEAD,支持跨多个 commit 的 REQ
|
|
346
|
-
PRE_BASELINE=$(cat .sprint-state/last-req-baseline.txt 2>/dev/null || echo "HEAD~1")
|
|
347
|
-
GIT_DIFF=$(git diff "$PRE_BASELINE"..HEAD --stat --diff-filter=AM 2>/dev/null)
|
|
348
|
-
# 提取新增测试行数(*.test.*, *.spec.*, __tests__/* 等)
|
|
349
|
-
TEST_LINES=$(echo "$GIT_DIFF" | grep -E '\.(test|spec)\.[a-z]+|__tests__/' | grep -oP '\d+(?= insertion)' | paste -sd+ | bc || echo 0)
|
|
350
|
-
# 提取总新增行数
|
|
351
|
-
TOTAL_LINES=$(echo "$GIT_DIFF" | grep -oP '\d+(?= insertion)' | paste -sd+ | bc || echo 0)
|
|
352
|
-
# 计算比率
|
|
353
|
-
if [ "$TOTAL_LINES" -gt 0 ]; then
|
|
354
|
-
RATIO=$((TEST_LINES * 100 / TOTAL_LINES))
|
|
355
|
-
echo "[TDD-CHECK] Test lines: $TEST_LINES / Total lines: $TOTAL_LINES = ${RATIO}%"
|
|
356
|
-
[ "$RATIO" -ge 40 ] || {
|
|
357
|
-
echo "[TDD-FAIL] Test-first ratio ${RATIO}% < 40% threshold"
|
|
358
|
-
echo "[TDD-FAIL] Expected ≥ 40% test lines. Retry with tests written first."
|
|
359
|
-
exit 1
|
|
360
|
-
}
|
|
361
|
-
else
|
|
362
|
-
echo "[TDD-CHECK] No new lines in diff (possibly no changes or first commit)"
|
|
363
|
-
fi
|
|
364
|
-
```
|
|
365
|
-
- **L1b-alt: 测试文件存在验证** — 当 diff 为空或无新增行时,降级检查测试文件是否出现在 changeset 中
|
|
366
|
-
```bash
|
|
367
|
-
HAS_TEST_FILES=$(echo "$GIT_DIFF" | grep -c -E '\.(test|spec)\.[a-z]+|__tests__/' || echo 0)
|
|
368
|
-
[ "$HAS_TEST_FILES" -gt 0 ] || { echo "[TDD-FAIL] No test files found in changeset"; exit 1; }
|
|
369
|
-
echo "[TDD-CHECK] Test files present in changeset: $HAS_TEST_FILES file(s)"
|
|
370
|
-
```
|
|
371
|
-
- **L2: 全量测试运行**(不只是 @test 当前 REQ 的测试)
|
|
372
|
-
- L3: 检查整体覆盖率 ≥ 80%
|
|
373
|
-
|
|
374
|
-
5. **Fix until green or block**
|
|
375
|
-
- 失败 → retry (max 3 次,每次注入失败摘要)
|
|
376
|
-
- 第 3 次仍失败 → BLOCK → 等待用户决策 (skip/manual/stop/rollback)
|
|
377
|
-
- 通过 → git commit + 标记 done
|
|
378
|
-
|
|
379
|
-
6. **Persist learnings**
|
|
380
|
-
- 分类为 permanent(架构级)或 contextual(临时性)
|
|
381
|
-
- 自动升级条件:被≥2 个 REQ 引用 或 涉及接口/数据结构
|
|
382
|
-
- 调用 `gstack/learn` 总结经验教训
|
|
383
|
-
|
|
384
|
-
7. **Update sprint state**
|
|
385
|
-
- orchestrator 统一更新 AGENTS.md(append `## ralph-loop: [REQ-XXX title]`)
|
|
386
|
-
- 原子写 checkpoint (progress.log)
|
|
387
|
-
- 继续下一个 READY REQ
|
|
388
|
-
|
|
389
|
-
**禁止行为**:
|
|
390
|
-
- ❌ 跳过测试基础设施检查
|
|
391
|
-
- ❌ 只运行部分测试(必须全量回归)
|
|
392
|
-
- ❌ 验证失败仍 commit
|
|
393
|
-
- ❌ 多个 subagent 同时写 AGENTS.md
|
|
394
|
-
- ❌ 修改前一个 REQ 的代码(除非修复回归)
|
|
395
|
-
|
|
396
|
-
---
|
|
157
|
+
**Eval**: `done + pending + blocked + skipped == total`, `iteration <= max_iterations`.
|
|
397
158
|
|
|
398
159
|
## Scope
|
|
399
160
|
|
|
400
|
-
**In Scope
|
|
401
|
-
- Phase 2 BUILD
|
|
402
|
-
- 从 specification.yaml
|
|
403
|
-
-
|
|
404
|
-
- 持久化
|
|
405
|
-
- 依赖排序和循环依赖检测
|
|
406
|
-
- 崩溃恢复(从 checkpoint 继续)
|
|
407
|
-
|
|
408
|
-
**Out of Scope**:
|
|
409
|
-
- Phase 0-1 (THINK/PLAN) 的需求分析和设计
|
|
410
|
-
- Phase 3-6 (REVIEW/USER ACCEPT/FEEDBACK/SHIP) 的后续阶段
|
|
411
|
-
- 并行模式(需显式使用 `--mode parallel` 切换到 `dispatching-parallel-agents`)
|
|
412
|
-
- 紧急热修复(应使用标准 sprint-flow 或手动处理)
|
|
413
|
-
- 非 specification.yaml 定义的需求(临时需求应先纳入 spec 再执行)
|
|
414
|
-
|
|
415
|
-
---
|
|
416
|
-
|
|
417
|
-
## Examples
|
|
418
|
-
|
|
419
|
-
**Example 1: 标准 Sprint Flow 启动**
|
|
420
|
-
```bash
|
|
421
|
-
/sprint-flow "开发用户登录功能,支持 JWT 和 OAuth2" --type web-nextjs
|
|
422
|
-
# → Phase 0-1 完成设计评审后,Phase 2 自动进入 ralph-loop 模式
|
|
423
|
-
# → 按拓扑顺序处理 REQ-001 (User Model) → REQ-002 (Auth Middleware) → REQ-003 (Login API)
|
|
424
|
-
```
|
|
425
|
-
|
|
426
|
-
**Example 2: 单个 REQ 构建**
|
|
427
|
-
```bash
|
|
428
|
-
/ralph-loop
|
|
429
|
-
# → 从 specification.yaml 读取下一个 READY REQ
|
|
430
|
-
# → 创建孤立上下文,dispatch TDD subagent
|
|
431
|
-
# → 全量回归测试通过后 commit
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
**Example 3: 处理阻塞 REQ**
|
|
435
|
-
```
|
|
436
|
-
REQ-005 失败 3 次 → BLOCKED
|
|
437
|
-
→ 用户决策:
|
|
438
|
-
- skip: 跳过此 REQ,继续 REQ-006
|
|
439
|
-
- manual: 手动修复后重新 dispatch
|
|
440
|
-
- stop: 停止整个 ralph-loop,保留已 done commits
|
|
441
|
-
- rollback: git reset 回上一个稳定版本
|
|
442
|
-
```
|
|
443
|
-
|
|
444
|
-
**Example 4: 崩溃恢复**
|
|
445
|
-
```bash
|
|
446
|
-
# 系统崩溃后重新启动
|
|
447
|
-
/ralph-loop --resume
|
|
448
|
-
# → 检测 progress.log → 跳过已 done REQs
|
|
449
|
-
# → 从最后一个 pending REQ 继续,无需重做已完成工作
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
**Example 5: 测试基础设施缺失**
|
|
453
|
-
```
|
|
454
|
-
REQ-001 开始 → 检查 test-utils.ts → 不存在
|
|
455
|
-
→ dispatch "生成测试基础设施" subagent
|
|
456
|
-
→ retry max 2 次 → 仍失败 → BLOCK 或 fallback inline 生成
|
|
457
|
-
→ 基础设施就绪后继续业务代码开发
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
---
|
|
461
|
-
|
|
462
|
-
## Output Contract (Mandatory Checklist)
|
|
463
|
-
|
|
464
|
-
**每个 REQ 完成时必须输出以下结构化检查清单**:
|
|
161
|
+
**In Scope**:
|
|
162
|
+
- Phase 2 BUILD 的 REQ 级迭代构建
|
|
163
|
+
- 从 specification.yaml 读取需求实现
|
|
164
|
+
- TDD + 全量回归测试
|
|
165
|
+
- Learnings 持久化 + 依赖排序 + 崩溃恢复
|
|
465
166
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
**Context Isolation**:
|
|
472
|
-
- [ ] Previous REQ context cleared
|
|
473
|
-
- [ ] Permanent learnings injected (N items)
|
|
474
|
-
- [ ] Contextual learnings injected (≤3 items)
|
|
475
|
-
- [ ] Test infrastructure confirmed ready
|
|
476
|
-
|
|
477
|
-
**TDD Compliance**:
|
|
478
|
-
- [ ] Tests written BEFORE implementation (verified via `git diff HEAD~1 --stat --diff-filter=AM`)
|
|
479
|
-
- [ ] Test/implementation ratio ≥ 40% (L1b check: test_lines / total_lines ≥ 40%)
|
|
480
|
-
- [ ] Mock usage justified (if >30% mock density)
|
|
481
|
-
- [ ] Test files present in changeset (L1b-alt fallback)
|
|
482
|
-
- [ ] **TDD 合规检查**: 验证 test-first 原则(新增源文件必须有对应测试文件,或添加 `@no-test-required` 注解)
|
|
483
|
-
|
|
484
|
-
**Verification Layers**:
|
|
485
|
-
- [ ] L1: typecheck + lint pass
|
|
486
|
-
- [ ] L1b: Test-first ratio check pass
|
|
487
|
-
- [ ] L2: **FULL regression tests** (all tests, not just @test REQ-XXX)
|
|
488
|
-
- [ ] L3: coverage ≥ 80%
|
|
489
|
-
|
|
490
|
-
**Learnings Persisted**:
|
|
491
|
-
- [ ] Permanent: [N items, list key ones]
|
|
492
|
-
- [ ] Contextual: [N items, sliding window]
|
|
493
|
-
- [ ] `gstack/learn` called
|
|
494
|
-
|
|
495
|
-
**State Updated**:
|
|
496
|
-
- [ ] AGENTS.md updated (orchestrator)
|
|
497
|
-
- [ ] progress.log atomically written (includes `test_first_compliant: true/false` — whether the REQ passed test-first validation)
|
|
498
|
-
- [ ] Git commit created (if PASS)
|
|
499
|
-
|
|
500
|
-
**Next Step**: [REQ-YYY title / COMPLETE / BLOCKED]
|
|
501
|
-
```
|
|
502
|
-
|
|
503
|
-
**Eval Criteria** (Issue #120, #121):
|
|
504
|
-
- ✅ L2 pass: Structured execution plan visible (checklist format)
|
|
505
|
-
- ✅ L3 pass: All 7 workflow steps followed, full regression tests run
|
|
506
|
-
- ❌ Fail: Missing checklist, partial tests, context pollution
|
|
507
|
-
|
|
508
|
-
---
|
|
509
|
-
|
|
510
|
-
## Anti-Patterns
|
|
511
|
-
|
|
512
|
-
| ❌ 错误 | ✅ 正确 |
|
|
513
|
-
|---|---|
|
|
514
|
-
| 一个 REQ 包含所有需求 | 每个 REQ ≤ 1 context window |
|
|
515
|
-
| 验证失败仍 commit | 不提交 |
|
|
516
|
-
| 只跑 @test REQ-XXX | 全量回归测试 |
|
|
517
|
-
| priority 排序忽略 depends_on | 拓扑排序 + 同层 priority |
|
|
518
|
-
| retry 不注入失败原因 | 每次 retry 注入上次错误 |
|
|
519
|
-
| subagent 各自写 AGENTS.md | orchestrator 统一更新 |
|
|
520
|
-
| progress.log 写长篇大论 | 3-5 行结构化摘要 |
|
|
521
|
-
|
|
522
|
-
---
|
|
167
|
+
**Out of Scope**:
|
|
168
|
+
- Phase 0-1 (THINK/PLAN) / Phase 3-6 (REVIEW/SHIP/等)
|
|
169
|
+
- 并行模式(`--mode parallel`)
|
|
170
|
+
- 紧急热修复
|
|
171
|
+
- 非 spec 定义的需求
|
|
523
172
|
|
|
524
173
|
## Token Savings
|
|
525
174
|
|
|
526
|
-
|
|
|
527
|
-
|
|
175
|
+
| REQs | Default | Ralph Loop | Savings |
|
|
176
|
+
|------|---------|-----------|---------|
|
|
528
177
|
| 3 | ~15k | ~9k | 40% |
|
|
529
178
|
| 5 | ~50k | ~25k | 50% |
|
|
530
179
|
| 10 | ~150k | ~50k | 67% |
|
|
531
180
|
|
|
532
|
-
|
|
181
|
+
## Anti-Patterns
|
|
533
182
|
|
|
534
|
-
|
|
183
|
+
| ❌ Wrong | ✅ Right |
|
|
184
|
+
|----------|---------|
|
|
185
|
+
| 所有需求一个 REQ | 每个 REQ ≤ 1 context window |
|
|
186
|
+
| 验证失败仍 commit | 不提交 |
|
|
187
|
+
| 只跑当前 REQ 的测试 | 全量回归 |
|
|
188
|
+
| 忽略 depends_on | 拓扑排序 |
|
|
189
|
+
| retry 不注入失败原因 | 每次注入上次错误 |
|
|
190
|
+
| subagent 各自写 AGENTS.md | orchestrator 统一更新 |
|
|
535
191
|
|
|
536
192
|
## References
|
|
537
193
|
|
|
538
|
-
- [
|
|
194
|
+
- [Components](references/components.md) — 系统提示/状态记忆/中间件/技能调用/构建步骤分解
|
|
195
|
+
- [Workflow Details](references/workflow-details.md) — 详细执行步骤 + Output Contract 检查清单
|
|
539
196
|
- [Phase 2 Integration](references/phase-2-build-ralph.md) — Sprint-Flow 集成细节
|
|
540
197
|
- [Progress Log Template](templates/progress-log.md)
|
|
198
|
+
- [Design Doc: ralph-loop v3.0](docs/ralph-loop-design.md)
|