@boyingliu01/xp-gate 0.6.0 → 0.6.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.
@@ -1,13 +1,6 @@
1
1
  ---
2
2
  name: ralph-loop
3
- description: >
4
- Default Phase 2 BUILD mode for Sprint-Flow. Processes ONE REQ at a time from
5
- specification.yaml with clean isolated context per subagent dispatch, persists
6
- memory via git history + classified learnings, runs full regression tests on each
7
- REQ, and only commits on verification pass. Designed to reduce token consumption
8
- from linear context accumulation to per-REQ fixed budgets (40-67% savings).
9
- Token-constraint is the default — every Phase 2 uses this mode automatically.
10
- Use `--mode parallel` to opt into the legacy all-at-once mode if needed.
3
+ description: Use when executing Sprint-Flow Phase 2 BUILD, processing one REQ, building the next requirement, iterating with clean context, or requiring full regression per requirement.
11
4
  maturity: stable
12
5
  ---
13
6
 
@@ -25,6 +18,25 @@ maturity: stable
25
18
  | **浓缩型分类学习** | permanent(架构级)+ contextual(最近 3 条)双层 learnings |
26
19
  | **AGENTS.md 统一更新** | orchestrator 统一写,subagent 不直接修改 — 无竞态 |
27
20
 
21
+ ---
22
+
23
+ ## Triggers
24
+
25
+ **关键词触发**:ralph-loop, process one REQ, build next requirement, Phase 2 BUILD, iterate REQ, isolated REQ build, clean context, full regression
26
+
27
+ **使用场景**:
28
+ - 执行 Sprint-Flow Phase 2 BUILD 阶段
29
+ - 从 specification.yaml 读取需求逐个实现
30
+ - 需要控制每个 REQ 的 token 预算
31
+ - 防止上下文污染(前一个 REQ 的实现细节影响后一个 REQ)
32
+ - 需要全量回归测试保证不引入回归
33
+ - 需要持久化 learnings 供后续 REQ 参考
34
+
35
+ **何时不使用**:
36
+ - 需求数量极少(1-2 个)且相互独立,可以并行
37
+ - 紧急热修复,不需要完整 Sprint Flow
38
+ - 明确使用 `--mode parallel` 切换到并行模式
39
+
28
40
  ## 作为 Phase 2 默认行为
29
41
 
30
42
  Ralph Loop 是 Sprint-Flow **Phase 2 BUILD 的默认模式**:
@@ -297,6 +309,165 @@ Phase 0, 1, 3-6 行为完全不变。
297
309
 
298
310
  ---
299
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. **Dispatch build subagent**
327
+ - 使用 `task(category="unspecified-high", load_skills=["test-driven-development"], timeout=300)`
328
+ - 强制 TDD 流程:RED → GREEN → REFACTOR
329
+ - 强制执行 Mock 边界策略(详见 Mock 边界表)
330
+
331
+ 4. **Run full regression tests**
332
+ - L1: typecheck + lint on changed files
333
+ - L1b: 检查测试先行比率 (新增测试行数 / 总新增行数 ≥ 40%)
334
+ - **L2: 全量测试运行**(不只是 @test 当前 REQ 的测试)
335
+ - L3: 检查整体覆盖率 ≥ 80%
336
+
337
+ 5. **Fix until green or block**
338
+ - 失败 → retry (max 3 次,每次注入失败摘要)
339
+ - 第 3 次仍失败 → BLOCK → 等待用户决策 (skip/manual/stop/rollback)
340
+ - 通过 → git commit + 标记 done
341
+
342
+ 6. **Persist learnings**
343
+ - 分类为 permanent(架构级)或 contextual(临时性)
344
+ - 自动升级条件:被≥2 个 REQ 引用 或 涉及接口/数据结构
345
+ - 调用 `gstack/learn` 总结经验教训
346
+
347
+ 7. **Update sprint state**
348
+ - orchestrator 统一更新 AGENTS.md(append `## ralph-loop: [REQ-XXX title]`)
349
+ - 原子写 checkpoint (progress.log)
350
+ - 继续下一个 READY REQ
351
+
352
+ **禁止行为**:
353
+ - ❌ 跳过测试基础设施检查
354
+ - ❌ 只运行部分测试(必须全量回归)
355
+ - ❌ 验证失败仍 commit
356
+ - ❌ 多个 subagent 同时写 AGENTS.md
357
+ - ❌ 修改前一个 REQ 的代码(除非修复回归)
358
+
359
+ ---
360
+
361
+ ## Scope
362
+
363
+ **In Scope**:
364
+ - Phase 2 BUILD 阶段的 REQ 级迭代构建
365
+ - 从 specification.yaml 读取需求并逐个实现
366
+ - 测试先行(TDD)+ 全量回归测试
367
+ - 持久化 learnings 供后续 REQ 参考
368
+ - 依赖排序和循环依赖检测
369
+ - 崩溃恢复(从 checkpoint 继续)
370
+
371
+ **Out of Scope**:
372
+ - Phase 0-1 (THINK/PLAN) 的需求分析和设计
373
+ - Phase 3-6 (REVIEW/USER ACCEPT/FEEDBACK/SHIP) 的后续阶段
374
+ - 并行模式(需显式使用 `--mode parallel` 切换到 `dispatching-parallel-agents`)
375
+ - 紧急热修复(应使用标准 sprint-flow 或手动处理)
376
+ - 非 specification.yaml 定义的需求(临时需求应先纳入 spec 再执行)
377
+
378
+ ---
379
+
380
+ ## Examples
381
+
382
+ **Example 1: 标准 Sprint Flow 启动**
383
+ ```bash
384
+ /sprint-flow "开发用户登录功能,支持 JWT 和 OAuth2" --type web-nextjs
385
+ # → Phase 0-1 完成设计评审后,Phase 2 自动进入 ralph-loop 模式
386
+ # → 按拓扑顺序处理 REQ-001 (User Model) → REQ-002 (Auth Middleware) → REQ-003 (Login API)
387
+ ```
388
+
389
+ **Example 2: 单个 REQ 构建**
390
+ ```bash
391
+ /ralph-loop
392
+ # → 从 specification.yaml 读取下一个 READY REQ
393
+ # → 创建孤立上下文,dispatch TDD subagent
394
+ # → 全量回归测试通过后 commit
395
+ ```
396
+
397
+ **Example 3: 处理阻塞 REQ**
398
+ ```
399
+ REQ-005 失败 3 次 → BLOCKED
400
+ → 用户决策:
401
+ - skip: 跳过此 REQ,继续 REQ-006
402
+ - manual: 手动修复后重新 dispatch
403
+ - stop: 停止整个 ralph-loop,保留已 done commits
404
+ - rollback: git reset 回上一个稳定版本
405
+ ```
406
+
407
+ **Example 4: 崩溃恢复**
408
+ ```bash
409
+ # 系统崩溃后重新启动
410
+ /ralph-loop --resume
411
+ # → 检测 progress.log → 跳过已 done REQs
412
+ # → 从最后一个 pending REQ 继续,无需重做已完成工作
413
+ ```
414
+
415
+ **Example 5: 测试基础设施缺失**
416
+ ```
417
+ REQ-001 开始 → 检查 test-utils.ts → 不存在
418
+ → dispatch "生成测试基础设施" subagent
419
+ → retry max 2 次 → 仍失败 → BLOCK 或 fallback inline 生成
420
+ → 基础设施就绪后继续业务代码开发
421
+ ```
422
+
423
+ ---
424
+
425
+ ## Output Contract (Mandatory Checklist)
426
+
427
+ **每个 REQ 完成时必须输出以下结构化检查清单**:
428
+
429
+ ```markdown
430
+ ## REQ-XXX: [Title] - Execution Summary
431
+
432
+ **Status**: ✅ PASS / ❌ FAIL (retry n/3) / 🚫 BLOCKED
433
+
434
+ **Context Isolation**:
435
+ - [ ] Previous REQ context cleared
436
+ - [ ] Permanent learnings injected (N items)
437
+ - [ ] Contextual learnings injected (≤3 items)
438
+ - [ ] Test infrastructure confirmed ready
439
+
440
+ **TDD Compliance**:
441
+ - [ ] Tests written BEFORE implementation
442
+ - [ ] Test/implementation ratio ≥ 40%
443
+ - [ ] Mock usage justified (if >30% mock density)
444
+
445
+ **Verification Layers**:
446
+ - [ ] L1: typecheck + lint pass
447
+ - [ ] L1b: Test-first ratio check pass
448
+ - [ ] L2: **FULL regression tests** (all tests, not just @test REQ-XXX)
449
+ - [ ] L3: coverage ≥ 80%
450
+
451
+ **Learnings Persisted**:
452
+ - [ ] Permanent: [N items, list key ones]
453
+ - [ ] Contextual: [N items, sliding window]
454
+ - [ ] `gstack/learn` called
455
+
456
+ **State Updated**:
457
+ - [ ] AGENTS.md updated (orchestrator)
458
+ - [ ] progress.log atomically written
459
+ - [ ] Git commit created (if PASS)
460
+
461
+ **Next Step**: [REQ-YYY title / COMPLETE / BLOCKED]
462
+ ```
463
+
464
+ **Eval Criteria** (Issue #120, #121):
465
+ - ✅ L2 pass: Structured execution plan visible (checklist format)
466
+ - ✅ L3 pass: All 7 workflow steps followed, full regression tests run
467
+ - ❌ Fail: Missing checklist, partial tests, context pollution
468
+
469
+ ---
470
+
300
471
  ## Anti-Patterns
301
472
 
302
473
  | ❌ 错误 | ✅ 正确 |