@boyingliu01/xp-gate 0.14.0 → 0.14.1

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.
@@ -347,10 +347,12 @@ describe('updateHooks', () => {
347
347
 
348
348
  describe('getProjectHooksDir', () => {
349
349
  it('returns .git/hooks path under cwd', () => {
350
+ const gitDir = path.join(tmpProject, '.git');
351
+ fs.mkdirSync(gitDir, { recursive: true });
352
+ vi.spyOn(process, 'cwd').mockReturnValue(tmpProject);
350
353
  const mod = getModule();
351
- const cwd = process.cwd();
352
354
  const result = mod.getProjectHooksDir();
353
- expect(result).toBe(path.join(cwd, '.git', 'hooks'));
355
+ expect(result).toBe(path.join(tmpProject, '.git', 'hooks'));
354
356
  });
355
357
 
356
358
  it('throws when .git/ does not exist', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/xp-gate",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "AI-driven development workflow: 6 quality gates + Delphi review + Sprint Flow",
5
5
  "bin": {
6
6
  "xp-gate": "./bin/xp-gate.js"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-gate",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "displayName": "XP-Gate",
5
5
  "description": "Extreme Programming quality gates + AI workflow skills for Claude Code. Includes 10 quality gates (Gate 0-9), Sprint Flow (11 phases), and Delphi multi-expert review (>=90% consensus).",
6
6
  "author": {
@@ -274,8 +274,9 @@ Sprint Flow: PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE
274
274
  **详细指令**: 参见 `references/phase-2-design.md` — 完整流程、条件分支、HARD-GATE。
275
275
 
276
276
  **快速参考**:
277
+ - **Step 0.5: DESIGN 路由分叉 (v0.14.0+)**: 根据 PREP 的 `change_type` 决定路径。`修改已存在代码` → SKIP autoplan, 直接 lightweight delphi-review (2 专家, 1 轮)。`新增功能` 或 undefined → 标准 autoplan 路径。详见 `references/phase-2-design.md#step-05-design-路由分叉`。
277
278
  - **Step 1: brainstorming** — `skill(name="brainstorming")` — 输出设计文档 + CONTEXT.md + ADR。**HARD-GATE**: 设计未批准 → 不可进入实现
278
- - **Step 2: autoplan** — `skill(name="autoplan")` — CEO/设计/工程自动评审 → 用户确认 taste_decisions
279
+ - **Step 2: autoplan** — `skill(name="autoplan")` — CEO/设计/工程自动评审 → 用户确认 taste_decisions(仅标准路径)
279
280
  - **Step 3: delphi-review** — `skill(name="delphi-review")` — 等待 APPROVED(非 APPROVED 暂停等待用户确认)
280
281
  - **Step 4: to-issues** — `skill(name="to-issues")` — 垂直切片 Issue 拆分 → slices-manifest.json
281
282
  - **Step 5: specification.yaml** — 从 APPROVED 设计文档自动提取
@@ -304,10 +305,11 @@ Sprint Flow: PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE
304
305
 
305
306
  **快速参考**:
306
307
  1. **DELPHI-GATE**: 验证 `.sprint-state/delphi-reviewed.json` 存在且 `verdict = "APPROVED"` → 否则 BLOCK
307
- 2. **输入**: `slices-manifest.json`(Phase 2/6 生成),按 `execution_order` 逐个执行
308
- 3. **模式**: 默认 `ralph-loop`(逐 REQ 迭代,token 节约 40-67%),可选 `--mode parallel`
309
- 4. **Skill 步骤**: hooks-install dispatching-parallel-agents TDD (RED/GREEN/REFACTOR) → freeze → blind-review unfreeze → verification-before-completion → 成本监控
310
- 5. **Mock Minimization**: integration-first, mock 仅限 external services, 密度 > 30% `@mock-justified`
308
+ 2. **TDD-GATE (MANDATORY — v0.14.0+)**: 在 delegation 前验证每个 REQ 存在 failing test。无 test → mark `[TDD-RED]`(ralph-loop 创建)。有 test 且 GREEN 且无实现 → BLOCK(TDD bypass)。详见 `references/phase-3-build.md#tdd-gate-pre-implementation-tdd-check-mandatory`。
309
+ 3. **输入**: `slices-manifest.json`(Phase 2/6 生成),按 `execution_order` 逐个执行
310
+ 4. **模式**: 默认 `ralph-loop`(逐 REQ 迭代,token 节约 40-67%),可选 `--mode parallel`
311
+ 5. **Skill 步骤**: hooks-install TDD-GATE dispatching-parallel-agents TDD (RED/GREEN/REFACTOR) freeze → blind-review → unfreeze → verification-before-completion → 成本监控
312
+ 6. **Mock Minimization**: integration-first, mock 仅限 external services, 密度 > 30% 需 `@mock-justified`
311
313
 
312
314
  ### Phase 4/6: VERIFY (验证 — 代码走查 + QA + 反馈获取)
313
315
 
@@ -336,17 +338,20 @@ Sprint Flow: PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE
336
338
 
337
339
  **对应旧模型**: Phase 5 SHIP + Phase 6 LAND
338
340
 
339
- **详细指令**: 参见 `references/phase-5-ship.md` — GITHOOKS-GATE / VERSION-GATE / VERSION CHANGESET (Issue #142) / changeset schema。
341
+ **详细指令**: 参见 `references/phase-5-ship.md` — VERSION-GATE (MANDATORY) / finishing-a-development-branch / VERSION CHANGESET (Issue #142) / changeset schema。
340
342
 
341
343
  **快速参考**:
342
- - **Orchestrator 直接执行**: `finishing-a-development-branch` `ship` 均为交互式 skill(4 选项菜单 + PR 确认),**必须由 orchestrator 直接调用** `skill(name="finishing-a-development-branch")` 和 `skill(name="ship")`
343
- - 输入: phase-4-summary.md + feedback-log.md 输出: PR URL
344
+ - **Step 0: VERSION-GATE (MANDATORY — 必须在 finishing-a-development-branch 之前)**: bump VERSION update CHANGELOG.md → run sync-version.sh → commit + push verify PR updated。详见 `references/phase-5-ship.md#step-0-version-gate`
345
+ - **Step 1: finishing-a-development-branch**: 4 选项菜单,选择 "Push and create a Pull Request"
346
+ - **Orchestrator 直接执行**: `finishing-a-development-branch` 和 `ship` 均为交互式 skill,**必须由 orchestrator 直接调用** `skill(name="finishing-a-development-branch")` 和 `skill(name="ship")`
347
+ - 输入: phase-4-summary.md + feedback-log.md → 输出: PR URL (含版本变更 commit)
344
348
  - **HARD-GATE**: Phase 4/6 未完成 → BLOCK。验证 `feedback-log.md` 存在。
345
349
  - **GITHOOKS-GATE**: 验证 hooks 完整性,缺失则 `githooks/install.sh`
346
- - **VERSION-GATE**: bump PATCH/MINOR/MAJOR → `sync-version.sh` → CHANGELOG.md → `git diff VERSION` 验证
347
350
  - **LAND**: `land-and-deploy` — merge PR → 等待 CI (10min) → 等待 Deploy (10min) → Canary Health Check (5min)
348
351
  - **回滚**: `git revert` 最后一次 merge commit
349
352
 
353
+ **⚠️ VERSION-GATE 必须在 finishing-a-development-branch 之前执行。顺序反了会导致 PR 不含版本变更 → CI release workflow 不触发 → 无新版本发布。**
354
+
350
355
  ### Phase 6/6: CLOSE (收尾 — ⚠️ 人工验收 + 清理)
351
356
 
352
357
  **对应旧模型**: Phase 7 USER ACCEPTANCE + Phase 8 CLEANUP
@@ -102,7 +102,33 @@ skill(name="brainstorming", user_message="[需求描述]")
102
102
  skill(name="design-shotgun", user_message="[Pain Document 内容 + 需求描述]")
103
103
  ```
104
104
 
105
- #### Step 1: 调用 autoplan skill
105
+ #### Step 0.5: DESIGN 路由分叉(v0.14.0+ — Issue #306)
106
+
107
+ 根据 Phase 1/6 PREP (AUTO-ESTIMATE) 的 `change_type` 决定走哪条路径:
108
+
109
+ ```
110
+ 读取 .sprint-state/sprint-state.json → auto_estimate.change_type
111
+
112
+ IF change_type == "修改已存在代码":
113
+ → 增量优化路径: SKIP autoplan
114
+ → 直接进入 Step 2b: delphi-review (lightweight: 2 专家, 1 轮)
115
+ ELSE (change_type == "新增功能" 或 未定义):
116
+ → 标准路径: 继续 Step 1 (autoplan) → Step 2
117
+ ```
118
+
119
+ **路由决策表**:
120
+
121
+ | change_type | 路径 | autoplan | delphi-review |
122
+ |------------|------|----------|---------------|
123
+ | `修改已存在代码` | 增量优化 | ❌ SKIP | lightweight (2 专家, 1 轮) |
124
+ | `新增功能` | 标准 | ✅ 执行 | 标准 (3 专家) |
125
+ | `undefined` / 缺失 | 标准 (fail-safe) | ✅ 执行 | 标准 (3 专家) |
126
+
127
+ **HARD-GATE 不变**: 两条路径最终都必须产出 APPROVED 的 delphi-reviewed.json。
128
+
129
+ #### Step 1: 调用 autoplan skill(仅标准路径)
130
+
131
+ **仅当 change_type != "修改已存在代码" 时执行。**
106
132
 
107
133
  ```
108
134
  skill(name="autoplan", user_message="[Pain Document 内容]")
@@ -140,10 +166,15 @@ autoplan_result:
140
166
  #### Step 2b: 调用 delphi-review(强制,orchestrator 直接执行)
141
167
 
142
168
  ```
169
+ # 标准路径(3 专家)
143
170
  skill(name="delphi-review", user_message="[设计文档 + taste_decisions 确认结果]")
171
+
172
+ # 增量优化路径(2 专家, 1 轮 — 来自 Step 0.5 路由)
173
+ skill(name="delphi-review", user_message="[设计文档]", experts=2, max_rounds=1)
144
174
  ```
145
175
 
146
- - Round 1: 3 专家匿名独立评审
176
+ - **标准路径**: Round 1: 3 专家匿名独立评审
177
+ - **增量优化路径**: 2 专家, 1 轮 (来自 Step 0.5 DESIGN 路由分叉)
147
178
  - Round 2+: 交换意见直到共识
148
179
  - 输出: APPROVED / REQUEST_CHANGES
149
180
 
@@ -81,6 +81,69 @@ SKIP_UNCOMMITTED_GATE=1
81
81
 
82
82
  ---
83
83
 
84
+ ## TDD-GATE: Pre-Implementation TDD Check (MANDATORY — v0.14.0+)
85
+
86
+ **Purpose**: Enforce RED → GREEN → REFACTOR discipline at BUILD entry before any delegation.
87
+
88
+ **Execution**: Before dispatching to ralph-loop or parallel agents, the orchestrator MUST verify for each REQ:
89
+
90
+ ### Gate Logic
91
+
92
+ ```
93
+ FOR each REQ in slices-manifest.json:
94
+ IF test file exists for this REQ:
95
+ IF test passes (GREEN state) AND no implementation exists:
96
+ → BLOCK: TDD bypass detected. Test is passing before implementation.
97
+ ELSE IF test fails (RED state):
98
+ → ALLOW: Proceed to implementation (GREEN phase).
99
+ ELSE (no test file exists):
100
+ → ALLOW: Mark REQ as [TDD-RED]. ralph-loop creates the test as step 0.
101
+ ```
102
+
103
+ ### Todo Prefix Convention
104
+
105
+ Each todo item MUST carry a TDD phase prefix in the content field:
106
+ - `[TDD-RED]`: Write failing test first. No implementation yet.
107
+ - `[TDD-GREEN]`: Write minimal implementation to make test pass.
108
+ - `[TDD-REFACTOR]`: Refactor while keeping tests green.
109
+
110
+ The priority field (high/medium/low) is separate and unchanged.
111
+
112
+ Example:
113
+ ```
114
+ "[TDD-RED] src/lib/auth.ts: Add validateToken() test for expired tokens - expect test to fail"
115
+ "[TDD-GREEN] src/lib/auth.ts: Implement validateToken() to pass test - expect test passes"
116
+ "[TDD-REFACTOR] src/lib/auth.ts: Extract token parsing into parseToken() helper - expect tests stay green"
117
+ ```
118
+
119
+ ### Deadlock Prevention
120
+
121
+ The TDD-GATE is a PRE-RALPH-LOOP check, NOT a replacement for ralph-loop's internal TDD:
122
+ - If no test exists → ralph-loop IS allowed to proceed (creates test as step 0)
123
+ - If test exists and is GREEN without implementation → BLOCK (TDD bypass)
124
+ - The gate verifies TDD DISCIPLINE was followed, not that TDD was skipped
125
+
126
+ ### Limitation
127
+
128
+ This enforcement is instructional (LLM follows SKILL.md instructions), not programmatic. For stronger enforcement, consider a future automated pre-commit hook that checks git staging order (test file must be staged before source file).
129
+
130
+ ### Log Format (`.sprint-state/tdd-gate-log.json`)
131
+
132
+ ```json
133
+ {
134
+ "checked": true,
135
+ "blocked": false,
136
+ "skipped": false,
137
+ "reqs_checked": 4,
138
+ "reqs_blocked": 0,
139
+ "timestamp": "2026-07-09T00:00:00Z"
140
+ }
141
+ ```
142
+
143
+ **Log location**: `.sprint-state/tdd-gate-log.json` — written on every gate execution for audit trail.
144
+
145
+ ---
146
+
84
147
  ## TDD 强制执行
85
148
 
86
149
  ### Gate 5a-BLOCK: 新增文件测试强制
@@ -13,15 +13,70 @@
13
13
 
14
14
  **Orchestrator 直接执行**: `finishing-a-development-branch` 和 `ship` 均为交互式 skill(4 选项菜单 + PR 确认),**必须由 orchestrator 直接调用**。
15
15
 
16
- **关键链**: PHASE4-GATE → verification → finishing-a-development-branch(4选项) → ship
16
+ **关键链**: VERSION-GATE(MANDATORY) → finishing-a-development-branch(4选项) → push PR
17
17
 
18
18
  **HARD-GATE**: Phase 4/6 VERIFY 未完成 → BLOCK。验证 `feedback-log.md` 存在。
19
19
 
20
20
  **GITHOOKS-GATE**: 验证 hooks 完整性,缺失则 `githooks/install.sh`
21
21
 
22
- **VERSION-GATE**: bump PATCH/MINOR/MAJOR `sync-version.sh` CHANGELOG.md → `git diff VERSION` 验证
22
+ **NETWORK-RESILIENCE**: GitHub API 在大中华区存在间歇性 TLS/超时问题。所有 `gh` CLI 调用应容忍偶尔失败:
23
+ - `gh` 命令失败时等待 2-5 秒后重试(最多 3 次)
24
+ - 优先使用 REST API (`gh api /repos/...`) 而非 GraphQL (`gh pr view --json ...`),REST 更轻量更可靠
25
+ - 验证 CI 状态时使用 `gh run list --branch ... --limit 1 --json status,conclusion` 代替 `gh pr view --json statusCheckRollup`
26
+ - 如果 `gh` 持续超时,fallback 到 `curl + token`:
27
+ ```
28
+ curl -s -H "Authorization: token $(gh auth token)" \
29
+ "https://api.github.com/repos/OWNER/REPO/commits/HEAD/status"
30
+ ```
23
31
 
24
- **输出**: PR URL
32
+ ### Step 0: VERSION-GATE(MANDATORY — 在 finishing-a-development-branch 之前执行)
33
+
34
+ **Purpose**: Ensure version bump, changelog update, and sync before creating PR. This MUST run BEFORE calling `finishing-a-development-branch` — the skill's "Create PR" option creates the PR immediately, so version changes must be committed first.
35
+
36
+ **Execution**:
37
+
38
+ ```
39
+ 1. 根据变更类型决定 bump 级别:
40
+ - PATCH (0.14.0 → 0.14.1): bug fixes, docs, minor enhancements
41
+ - MINOR (0.14.0 → 0.15.0): new features, significant enhancements
42
+ - MAJOR (0.14.0 → 1.0.0): breaking changes
43
+
44
+ 2. 更新 VERSION 文件 (MAJOR.MINOR.PATCH.MICRO 格式)
45
+
46
+ 3. 更新 CHANGELOG.md:
47
+ - 添加新版本条目 (## [X.Y.Z.W] - YYYY-MM-DD)
48
+ - 按 ### Added / ### Fixed / ### Changed 分类
49
+
50
+ 4. 运行 sync-version.sh:
51
+ bash scripts/sync-version.sh
52
+
53
+ 5. 验证:
54
+ git diff VERSION # 确认版本号变更
55
+ git diff CHANGELOG.md # 确认 changelog 变更
56
+ git diff --stat # 确认 package.json 版本同步
57
+
58
+ 6. 提交版本变更:
59
+ git add VERSION CHANGELOG.md && git commit -m "release: bump version to X.Y.Z.W"
60
+
61
+ 7. 推送到远程分支:
62
+ git push
63
+
64
+ 8. 验证 CI 流程触发:
65
+ gh pr view <PR_NUMBER> --json state # 确认 CI 已开始
66
+ ```
67
+
68
+ **GATE CHECK** (BEFORE proceeding to finishing-a-development-branch):
69
+ ```
70
+ [VERSION-GATE] VERSION bump ✓ # VERSION 文件已更新
71
+ [VERSION-GATE] CHANGELOG ✓ # 新版本条目已添加
72
+ [VERSION-GATE] sync-version ✓ # 所有 package.json 已同步
73
+ [VERSION-GATE] committed ✓ # 版本变更已提交并推送
74
+ [VERSION-GATE] PR updated ✓ # PR 已包含版本变更 commit
75
+ ```
76
+
77
+ **⚠️ ANTI-PATTERN**: 先调用 finishing-a-development-branch 创建 PR,再 bump VERSION 会导致 PR 不含版本变更 → CI 不触发 release workflow → 无新版本发布。
78
+
79
+ **输出**: 版本变更 commit 包含在 PR 中
25
80
 
26
81
  ---
27
82
 
@@ -3,6 +3,8 @@
3
3
  **执行时机**: Phase 5/6 SHIP 完成后。
4
4
  **对应旧模型**: Phase 7 USER ACCEPTANCE + Phase 8 CLEANUP
5
5
 
6
+ **NETWORK-RESILIENCE**: 与 Phase 5/6 相同,GitHub API 在大中华区存在间歇性超时。CLEANUP 中的 `gh pr list` 和 `git push --delete` 需容忍重试。详见 `phase-5-ship.md` NETWORK-RESILIENCE 指南。
7
+
6
8
  ---
7
9
 
8
10
  ## Part A: USER ACCEPTANCE(⚠️ 人工验收)
@@ -100,7 +102,64 @@ Phase 6/6 CLOSE 完成时:
100
102
  ### 输出
101
103
 
102
104
  - Emergent Issues List (`emergent-issues.md`)
103
- - 进入 Part B CLEANUP 自动执行(如果用户确认验收)
105
+ - 进入 Part A.5 ARCHIVE 自动执行(如果用户确认验收)
106
+
107
+ ---
108
+
109
+ ## Part A.5: ARCHIVE(归档 — v0.14.0+ Issue #308)
110
+
111
+ **Purpose**: Preserve sprint decision records before cleanup. `.sprint-state/` is gitignored and deleted during CLEANUP; this step copies structured outputs to `.sprint-history/` which is tracked by git.
112
+
113
+ **Execution**: After USER ACCEPTANCE (Part A) confirms continuation, BEFORE CLEANUP (Part B).
114
+
115
+ ### Step 1: Read Sprint ID
116
+
117
+ Read `sprint-state.json` → `id` field (e.g., `sprint-2026-07-09-01`).
118
+
119
+ ### Step 2: Check for Conflicts
120
+
121
+ ```
122
+ IF .sprint-history/<sprint-id>/ already exists:
123
+ → Append timestamp suffix: <sprint-id>-20260709T120000
124
+ → Log warning: "Sprint archive conflict, using timestamp suffix"
125
+ ```
126
+
127
+ ### Step 3: Archive Files
128
+
129
+ Copy from `.sprint-state/` to `.sprint-history/<sprint-id>/`:
130
+
131
+ **Included** (all `.yaml`, `.json`, `.md` files under `.sprint-state/`):
132
+ - `specification.yaml` (if in phase-outputs/)
133
+ - `delphi-reviewed.json`
134
+ - `sprint-state.json`
135
+ - `phase-outputs/*.yaml`, `phase-outputs/*.json`, `phase-outputs/*.md`
136
+ - `tdd-gate-log.json`, `uncommitted-gate-log.json`
137
+
138
+ **Excluded** (temporary/cache):
139
+ - `*.tmp`, `*.cache` files
140
+ - `sprint.lock` (session lock file)
141
+
142
+ ### Step 4: Verify Git Tracking
143
+
144
+ ```bash
145
+ # .sprint-history/ is NOT in .gitignore (verified — no change needed)
146
+ # Verify files are trackable:
147
+ git status .sprint-history/
148
+ ```
149
+
150
+ **No `.gitignore` change needed**: `.sprint-history/` is NOT currently listed in `.gitignore`. The `.sprint-state/` ignore (line 59) only matches `.sprint-state/` exactly — it does NOT match `.sprint-history/`.
151
+
152
+ ### Step 5: Commit Archive (Optional)
153
+
154
+ The orchestrator MAY commit the archive:
155
+ ```
156
+ git add .sprint-history/<sprint-id>/ && git commit -m "archive: sprint <sprint-id>"
157
+ ```
158
+
159
+ ### Output
160
+
161
+ - `.sprint-history/<sprint-id>/` directory with archived sprint state
162
+ - Git-tracked sprint decision records for future retro/review
104
163
 
105
164
  ---
106
165
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/opencode-plugin",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "description": "XP-Gate quality gates + AI workflow skills + Sprint Flow TUI sidebar for OpenCode",
@@ -274,8 +274,9 @@ Sprint Flow: PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE
274
274
  **详细指令**: 参见 `references/phase-2-design.md` — 完整流程、条件分支、HARD-GATE。
275
275
 
276
276
  **快速参考**:
277
+ - **Step 0.5: DESIGN 路由分叉 (v0.14.0+)**: 根据 PREP 的 `change_type` 决定路径。`修改已存在代码` → SKIP autoplan, 直接 lightweight delphi-review (2 专家, 1 轮)。`新增功能` 或 undefined → 标准 autoplan 路径。详见 `references/phase-2-design.md#step-05-design-路由分叉`。
277
278
  - **Step 1: brainstorming** — `skill(name="brainstorming")` — 输出设计文档 + CONTEXT.md + ADR。**HARD-GATE**: 设计未批准 → 不可进入实现
278
- - **Step 2: autoplan** — `skill(name="autoplan")` — CEO/设计/工程自动评审 → 用户确认 taste_decisions
279
+ - **Step 2: autoplan** — `skill(name="autoplan")` — CEO/设计/工程自动评审 → 用户确认 taste_decisions(仅标准路径)
279
280
  - **Step 3: delphi-review** — `skill(name="delphi-review")` — 等待 APPROVED(非 APPROVED 暂停等待用户确认)
280
281
  - **Step 4: to-issues** — `skill(name="to-issues")` — 垂直切片 Issue 拆分 → slices-manifest.json
281
282
  - **Step 5: specification.yaml** — 从 APPROVED 设计文档自动提取
@@ -304,10 +305,11 @@ Sprint Flow: PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE
304
305
 
305
306
  **快速参考**:
306
307
  1. **DELPHI-GATE**: 验证 `.sprint-state/delphi-reviewed.json` 存在且 `verdict = "APPROVED"` → 否则 BLOCK
307
- 2. **输入**: `slices-manifest.json`(Phase 2/6 生成),按 `execution_order` 逐个执行
308
- 3. **模式**: 默认 `ralph-loop`(逐 REQ 迭代,token 节约 40-67%),可选 `--mode parallel`
309
- 4. **Skill 步骤**: hooks-install dispatching-parallel-agents TDD (RED/GREEN/REFACTOR) → freeze → blind-review unfreeze → verification-before-completion → 成本监控
310
- 5. **Mock Minimization**: integration-first, mock 仅限 external services, 密度 > 30% `@mock-justified`
308
+ 2. **TDD-GATE (MANDATORY — v0.14.0+)**: 在 delegation 前验证每个 REQ 存在 failing test。无 test → mark `[TDD-RED]`(ralph-loop 创建)。有 test 且 GREEN 且无实现 → BLOCK(TDD bypass)。详见 `references/phase-3-build.md#tdd-gate-pre-implementation-tdd-check-mandatory`。
309
+ 3. **输入**: `slices-manifest.json`(Phase 2/6 生成),按 `execution_order` 逐个执行
310
+ 4. **模式**: 默认 `ralph-loop`(逐 REQ 迭代,token 节约 40-67%),可选 `--mode parallel`
311
+ 5. **Skill 步骤**: hooks-install TDD-GATE dispatching-parallel-agents TDD (RED/GREEN/REFACTOR) freeze → blind-review → unfreeze → verification-before-completion → 成本监控
312
+ 6. **Mock Minimization**: integration-first, mock 仅限 external services, 密度 > 30% 需 `@mock-justified`
311
313
 
312
314
  ### Phase 4/6: VERIFY (验证 — 代码走查 + QA + 反馈获取)
313
315
 
@@ -336,17 +338,20 @@ Sprint Flow: PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE
336
338
 
337
339
  **对应旧模型**: Phase 5 SHIP + Phase 6 LAND
338
340
 
339
- **详细指令**: 参见 `references/phase-5-ship.md` — GITHOOKS-GATE / VERSION-GATE / VERSION CHANGESET (Issue #142) / changeset schema。
341
+ **详细指令**: 参见 `references/phase-5-ship.md` — VERSION-GATE (MANDATORY) / finishing-a-development-branch / VERSION CHANGESET (Issue #142) / changeset schema。
340
342
 
341
343
  **快速参考**:
342
- - **Orchestrator 直接执行**: `finishing-a-development-branch` `ship` 均为交互式 skill(4 选项菜单 + PR 确认),**必须由 orchestrator 直接调用** `skill(name="finishing-a-development-branch")` 和 `skill(name="ship")`
343
- - 输入: phase-4-summary.md + feedback-log.md 输出: PR URL
344
+ - **Step 0: VERSION-GATE (MANDATORY — 必须在 finishing-a-development-branch 之前)**: bump VERSION update CHANGELOG.md → run sync-version.sh → commit + push verify PR updated。详见 `references/phase-5-ship.md#step-0-version-gate`
345
+ - **Step 1: finishing-a-development-branch**: 4 选项菜单,选择 "Push and create a Pull Request"
346
+ - **Orchestrator 直接执行**: `finishing-a-development-branch` 和 `ship` 均为交互式 skill,**必须由 orchestrator 直接调用** `skill(name="finishing-a-development-branch")` 和 `skill(name="ship")`
347
+ - 输入: phase-4-summary.md + feedback-log.md → 输出: PR URL (含版本变更 commit)
344
348
  - **HARD-GATE**: Phase 4/6 未完成 → BLOCK。验证 `feedback-log.md` 存在。
345
349
  - **GITHOOKS-GATE**: 验证 hooks 完整性,缺失则 `githooks/install.sh`
346
- - **VERSION-GATE**: bump PATCH/MINOR/MAJOR → `sync-version.sh` → CHANGELOG.md → `git diff VERSION` 验证
347
350
  - **LAND**: `land-and-deploy` — merge PR → 等待 CI (10min) → 等待 Deploy (10min) → Canary Health Check (5min)
348
351
  - **回滚**: `git revert` 最后一次 merge commit
349
352
 
353
+ **⚠️ VERSION-GATE 必须在 finishing-a-development-branch 之前执行。顺序反了会导致 PR 不含版本变更 → CI release workflow 不触发 → 无新版本发布。**
354
+
350
355
  ### Phase 6/6: CLOSE (收尾 — ⚠️ 人工验收 + 清理)
351
356
 
352
357
  **对应旧模型**: Phase 7 USER ACCEPTANCE + Phase 8 CLEANUP
@@ -102,7 +102,33 @@ skill(name="brainstorming", user_message="[需求描述]")
102
102
  skill(name="design-shotgun", user_message="[Pain Document 内容 + 需求描述]")
103
103
  ```
104
104
 
105
- #### Step 1: 调用 autoplan skill
105
+ #### Step 0.5: DESIGN 路由分叉(v0.14.0+ — Issue #306)
106
+
107
+ 根据 Phase 1/6 PREP (AUTO-ESTIMATE) 的 `change_type` 决定走哪条路径:
108
+
109
+ ```
110
+ 读取 .sprint-state/sprint-state.json → auto_estimate.change_type
111
+
112
+ IF change_type == "修改已存在代码":
113
+ → 增量优化路径: SKIP autoplan
114
+ → 直接进入 Step 2b: delphi-review (lightweight: 2 专家, 1 轮)
115
+ ELSE (change_type == "新增功能" 或 未定义):
116
+ → 标准路径: 继续 Step 1 (autoplan) → Step 2
117
+ ```
118
+
119
+ **路由决策表**:
120
+
121
+ | change_type | 路径 | autoplan | delphi-review |
122
+ |------------|------|----------|---------------|
123
+ | `修改已存在代码` | 增量优化 | ❌ SKIP | lightweight (2 专家, 1 轮) |
124
+ | `新增功能` | 标准 | ✅ 执行 | 标准 (3 专家) |
125
+ | `undefined` / 缺失 | 标准 (fail-safe) | ✅ 执行 | 标准 (3 专家) |
126
+
127
+ **HARD-GATE 不变**: 两条路径最终都必须产出 APPROVED 的 delphi-reviewed.json。
128
+
129
+ #### Step 1: 调用 autoplan skill(仅标准路径)
130
+
131
+ **仅当 change_type != "修改已存在代码" 时执行。**
106
132
 
107
133
  ```
108
134
  skill(name="autoplan", user_message="[Pain Document 内容]")
@@ -140,10 +166,15 @@ autoplan_result:
140
166
  #### Step 2b: 调用 delphi-review(强制,orchestrator 直接执行)
141
167
 
142
168
  ```
169
+ # 标准路径(3 专家)
143
170
  skill(name="delphi-review", user_message="[设计文档 + taste_decisions 确认结果]")
171
+
172
+ # 增量优化路径(2 专家, 1 轮 — 来自 Step 0.5 路由)
173
+ skill(name="delphi-review", user_message="[设计文档]", experts=2, max_rounds=1)
144
174
  ```
145
175
 
146
- - Round 1: 3 专家匿名独立评审
176
+ - **标准路径**: Round 1: 3 专家匿名独立评审
177
+ - **增量优化路径**: 2 专家, 1 轮 (来自 Step 0.5 DESIGN 路由分叉)
147
178
  - Round 2+: 交换意见直到共识
148
179
  - 输出: APPROVED / REQUEST_CHANGES
149
180
 
@@ -81,6 +81,69 @@ SKIP_UNCOMMITTED_GATE=1
81
81
 
82
82
  ---
83
83
 
84
+ ## TDD-GATE: Pre-Implementation TDD Check (MANDATORY — v0.14.0+)
85
+
86
+ **Purpose**: Enforce RED → GREEN → REFACTOR discipline at BUILD entry before any delegation.
87
+
88
+ **Execution**: Before dispatching to ralph-loop or parallel agents, the orchestrator MUST verify for each REQ:
89
+
90
+ ### Gate Logic
91
+
92
+ ```
93
+ FOR each REQ in slices-manifest.json:
94
+ IF test file exists for this REQ:
95
+ IF test passes (GREEN state) AND no implementation exists:
96
+ → BLOCK: TDD bypass detected. Test is passing before implementation.
97
+ ELSE IF test fails (RED state):
98
+ → ALLOW: Proceed to implementation (GREEN phase).
99
+ ELSE (no test file exists):
100
+ → ALLOW: Mark REQ as [TDD-RED]. ralph-loop creates the test as step 0.
101
+ ```
102
+
103
+ ### Todo Prefix Convention
104
+
105
+ Each todo item MUST carry a TDD phase prefix in the content field:
106
+ - `[TDD-RED]`: Write failing test first. No implementation yet.
107
+ - `[TDD-GREEN]`: Write minimal implementation to make test pass.
108
+ - `[TDD-REFACTOR]`: Refactor while keeping tests green.
109
+
110
+ The priority field (high/medium/low) is separate and unchanged.
111
+
112
+ Example:
113
+ ```
114
+ "[TDD-RED] src/lib/auth.ts: Add validateToken() test for expired tokens - expect test to fail"
115
+ "[TDD-GREEN] src/lib/auth.ts: Implement validateToken() to pass test - expect test passes"
116
+ "[TDD-REFACTOR] src/lib/auth.ts: Extract token parsing into parseToken() helper - expect tests stay green"
117
+ ```
118
+
119
+ ### Deadlock Prevention
120
+
121
+ The TDD-GATE is a PRE-RALPH-LOOP check, NOT a replacement for ralph-loop's internal TDD:
122
+ - If no test exists → ralph-loop IS allowed to proceed (creates test as step 0)
123
+ - If test exists and is GREEN without implementation → BLOCK (TDD bypass)
124
+ - The gate verifies TDD DISCIPLINE was followed, not that TDD was skipped
125
+
126
+ ### Limitation
127
+
128
+ This enforcement is instructional (LLM follows SKILL.md instructions), not programmatic. For stronger enforcement, consider a future automated pre-commit hook that checks git staging order (test file must be staged before source file).
129
+
130
+ ### Log Format (`.sprint-state/tdd-gate-log.json`)
131
+
132
+ ```json
133
+ {
134
+ "checked": true,
135
+ "blocked": false,
136
+ "skipped": false,
137
+ "reqs_checked": 4,
138
+ "reqs_blocked": 0,
139
+ "timestamp": "2026-07-09T00:00:00Z"
140
+ }
141
+ ```
142
+
143
+ **Log location**: `.sprint-state/tdd-gate-log.json` — written on every gate execution for audit trail.
144
+
145
+ ---
146
+
84
147
  ## TDD 强制执行
85
148
 
86
149
  ### Gate 5a-BLOCK: 新增文件测试强制
@@ -13,15 +13,70 @@
13
13
 
14
14
  **Orchestrator 直接执行**: `finishing-a-development-branch` 和 `ship` 均为交互式 skill(4 选项菜单 + PR 确认),**必须由 orchestrator 直接调用**。
15
15
 
16
- **关键链**: PHASE4-GATE → verification → finishing-a-development-branch(4选项) → ship
16
+ **关键链**: VERSION-GATE(MANDATORY) → finishing-a-development-branch(4选项) → push PR
17
17
 
18
18
  **HARD-GATE**: Phase 4/6 VERIFY 未完成 → BLOCK。验证 `feedback-log.md` 存在。
19
19
 
20
20
  **GITHOOKS-GATE**: 验证 hooks 完整性,缺失则 `githooks/install.sh`
21
21
 
22
- **VERSION-GATE**: bump PATCH/MINOR/MAJOR `sync-version.sh` CHANGELOG.md → `git diff VERSION` 验证
22
+ **NETWORK-RESILIENCE**: GitHub API 在大中华区存在间歇性 TLS/超时问题。所有 `gh` CLI 调用应容忍偶尔失败:
23
+ - `gh` 命令失败时等待 2-5 秒后重试(最多 3 次)
24
+ - 优先使用 REST API (`gh api /repos/...`) 而非 GraphQL (`gh pr view --json ...`),REST 更轻量更可靠
25
+ - 验证 CI 状态时使用 `gh run list --branch ... --limit 1 --json status,conclusion` 代替 `gh pr view --json statusCheckRollup`
26
+ - 如果 `gh` 持续超时,fallback 到 `curl + token`:
27
+ ```
28
+ curl -s -H "Authorization: token $(gh auth token)" \
29
+ "https://api.github.com/repos/OWNER/REPO/commits/HEAD/status"
30
+ ```
23
31
 
24
- **输出**: PR URL
32
+ ### Step 0: VERSION-GATE(MANDATORY — 在 finishing-a-development-branch 之前执行)
33
+
34
+ **Purpose**: Ensure version bump, changelog update, and sync before creating PR. This MUST run BEFORE calling `finishing-a-development-branch` — the skill's "Create PR" option creates the PR immediately, so version changes must be committed first.
35
+
36
+ **Execution**:
37
+
38
+ ```
39
+ 1. 根据变更类型决定 bump 级别:
40
+ - PATCH (0.14.0 → 0.14.1): bug fixes, docs, minor enhancements
41
+ - MINOR (0.14.0 → 0.15.0): new features, significant enhancements
42
+ - MAJOR (0.14.0 → 1.0.0): breaking changes
43
+
44
+ 2. 更新 VERSION 文件 (MAJOR.MINOR.PATCH.MICRO 格式)
45
+
46
+ 3. 更新 CHANGELOG.md:
47
+ - 添加新版本条目 (## [X.Y.Z.W] - YYYY-MM-DD)
48
+ - 按 ### Added / ### Fixed / ### Changed 分类
49
+
50
+ 4. 运行 sync-version.sh:
51
+ bash scripts/sync-version.sh
52
+
53
+ 5. 验证:
54
+ git diff VERSION # 确认版本号变更
55
+ git diff CHANGELOG.md # 确认 changelog 变更
56
+ git diff --stat # 确认 package.json 版本同步
57
+
58
+ 6. 提交版本变更:
59
+ git add VERSION CHANGELOG.md && git commit -m "release: bump version to X.Y.Z.W"
60
+
61
+ 7. 推送到远程分支:
62
+ git push
63
+
64
+ 8. 验证 CI 流程触发:
65
+ gh pr view <PR_NUMBER> --json state # 确认 CI 已开始
66
+ ```
67
+
68
+ **GATE CHECK** (BEFORE proceeding to finishing-a-development-branch):
69
+ ```
70
+ [VERSION-GATE] VERSION bump ✓ # VERSION 文件已更新
71
+ [VERSION-GATE] CHANGELOG ✓ # 新版本条目已添加
72
+ [VERSION-GATE] sync-version ✓ # 所有 package.json 已同步
73
+ [VERSION-GATE] committed ✓ # 版本变更已提交并推送
74
+ [VERSION-GATE] PR updated ✓ # PR 已包含版本变更 commit
75
+ ```
76
+
77
+ **⚠️ ANTI-PATTERN**: 先调用 finishing-a-development-branch 创建 PR,再 bump VERSION 会导致 PR 不含版本变更 → CI 不触发 release workflow → 无新版本发布。
78
+
79
+ **输出**: 版本变更 commit 包含在 PR 中
25
80
 
26
81
  ---
27
82
 
@@ -3,6 +3,8 @@
3
3
  **执行时机**: Phase 5/6 SHIP 完成后。
4
4
  **对应旧模型**: Phase 7 USER ACCEPTANCE + Phase 8 CLEANUP
5
5
 
6
+ **NETWORK-RESILIENCE**: 与 Phase 5/6 相同,GitHub API 在大中华区存在间歇性超时。CLEANUP 中的 `gh pr list` 和 `git push --delete` 需容忍重试。详见 `phase-5-ship.md` NETWORK-RESILIENCE 指南。
7
+
6
8
  ---
7
9
 
8
10
  ## Part A: USER ACCEPTANCE(⚠️ 人工验收)
@@ -100,7 +102,64 @@ Phase 6/6 CLOSE 完成时:
100
102
  ### 输出
101
103
 
102
104
  - Emergent Issues List (`emergent-issues.md`)
103
- - 进入 Part B CLEANUP 自动执行(如果用户确认验收)
105
+ - 进入 Part A.5 ARCHIVE 自动执行(如果用户确认验收)
106
+
107
+ ---
108
+
109
+ ## Part A.5: ARCHIVE(归档 — v0.14.0+ Issue #308)
110
+
111
+ **Purpose**: Preserve sprint decision records before cleanup. `.sprint-state/` is gitignored and deleted during CLEANUP; this step copies structured outputs to `.sprint-history/` which is tracked by git.
112
+
113
+ **Execution**: After USER ACCEPTANCE (Part A) confirms continuation, BEFORE CLEANUP (Part B).
114
+
115
+ ### Step 1: Read Sprint ID
116
+
117
+ Read `sprint-state.json` → `id` field (e.g., `sprint-2026-07-09-01`).
118
+
119
+ ### Step 2: Check for Conflicts
120
+
121
+ ```
122
+ IF .sprint-history/<sprint-id>/ already exists:
123
+ → Append timestamp suffix: <sprint-id>-20260709T120000
124
+ → Log warning: "Sprint archive conflict, using timestamp suffix"
125
+ ```
126
+
127
+ ### Step 3: Archive Files
128
+
129
+ Copy from `.sprint-state/` to `.sprint-history/<sprint-id>/`:
130
+
131
+ **Included** (all `.yaml`, `.json`, `.md` files under `.sprint-state/`):
132
+ - `specification.yaml` (if in phase-outputs/)
133
+ - `delphi-reviewed.json`
134
+ - `sprint-state.json`
135
+ - `phase-outputs/*.yaml`, `phase-outputs/*.json`, `phase-outputs/*.md`
136
+ - `tdd-gate-log.json`, `uncommitted-gate-log.json`
137
+
138
+ **Excluded** (temporary/cache):
139
+ - `*.tmp`, `*.cache` files
140
+ - `sprint.lock` (session lock file)
141
+
142
+ ### Step 4: Verify Git Tracking
143
+
144
+ ```bash
145
+ # .sprint-history/ is NOT in .gitignore (verified — no change needed)
146
+ # Verify files are trackable:
147
+ git status .sprint-history/
148
+ ```
149
+
150
+ **No `.gitignore` change needed**: `.sprint-history/` is NOT currently listed in `.gitignore`. The `.sprint-state/` ignore (line 59) only matches `.sprint-state/` exactly — it does NOT match `.sprint-history/`.
151
+
152
+ ### Step 5: Commit Archive (Optional)
153
+
154
+ The orchestrator MAY commit the archive:
155
+ ```
156
+ git add .sprint-history/<sprint-id>/ && git commit -m "archive: sprint <sprint-id>"
157
+ ```
158
+
159
+ ### Output
160
+
161
+ - `.sprint-history/<sprint-id>/` directory with archived sprint state
162
+ - Git-tracked sprint decision records for future retro/review
104
163
 
105
164
  ---
106
165
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-gate",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "displayName": "XP-Gate",
5
5
  "description": "Extreme Programming quality gates + AI workflow skills for Qoder. Includes 10 quality gates (Gate 0-9), Sprint Flow (11 phases), and Delphi multi-expert review (>=90% consensus).",
6
6
  "author": {
@@ -1,9 +1,9 @@
1
1
  # SKILLS/DELPHI-REVIEW KNOWLEDGE BASE
2
2
 
3
- **Generated:** 2026-07-08
4
- **Commit:** 229cf7d
5
- **Branch:** main
6
- **Version:** 0.14.0.0
3
+ **Generated:** 2026-07-09
4
+ **Commit:** e53b728
5
+ **Branch:** sprint/2026-07-09-01
6
+ **Version:** 0.14.1.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, 3 experts from ≥2 providers, domestic models only). Supports design + code-walkthrough modes.
@@ -1,9 +1,9 @@
1
1
  # SKILLS/SPRINT-FLOW KNOWLEDGE BASE
2
2
 
3
- **Generated:** 2026-07-08
4
- **Commit:** 229cf7d
5
- **Branch:** main
6
- **Version:** 0.14.0.0
3
+ **Generated:** 2026-07-09
4
+ **Commit:** e53b728
5
+ **Branch:** sprint/2026-07-09-01
6
+ **Version:** 0.14.1.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration, 40-67% token savings vs parallel). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -1,9 +1,9 @@
1
1
  # SKILLS/TEST-SPECIFICATION-ALIGNMENT KNOWLEDGE BASE
2
2
 
3
- **Generated:** 2026-07-08
4
- **Commit:** 229cf7d
5
- **Branch:** main
6
- **Version:** 0.14.0.0
3
+ **Generated:** 2026-07-09
4
+ **Commit:** e53b728
5
+ **Branch:** sprint/2026-07-09-01
6
+ **Version:** 0.14.1.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -274,8 +274,9 @@ Sprint Flow: PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE
274
274
  **详细指令**: 参见 `references/phase-2-design.md` — 完整流程、条件分支、HARD-GATE。
275
275
 
276
276
  **快速参考**:
277
+ - **Step 0.5: DESIGN 路由分叉 (v0.14.0+)**: 根据 PREP 的 `change_type` 决定路径。`修改已存在代码` → SKIP autoplan, 直接 lightweight delphi-review (2 专家, 1 轮)。`新增功能` 或 undefined → 标准 autoplan 路径。详见 `references/phase-2-design.md#step-05-design-路由分叉`。
277
278
  - **Step 1: brainstorming** — `skill(name="brainstorming")` — 输出设计文档 + CONTEXT.md + ADR。**HARD-GATE**: 设计未批准 → 不可进入实现
278
- - **Step 2: autoplan** — `skill(name="autoplan")` — CEO/设计/工程自动评审 → 用户确认 taste_decisions
279
+ - **Step 2: autoplan** — `skill(name="autoplan")` — CEO/设计/工程自动评审 → 用户确认 taste_decisions(仅标准路径)
279
280
  - **Step 3: delphi-review** — `skill(name="delphi-review")` — 等待 APPROVED(非 APPROVED 暂停等待用户确认)
280
281
  - **Step 4: to-issues** — `skill(name="to-issues")` — 垂直切片 Issue 拆分 → slices-manifest.json
281
282
  - **Step 5: specification.yaml** — 从 APPROVED 设计文档自动提取
@@ -304,10 +305,11 @@ Sprint Flow: PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE
304
305
 
305
306
  **快速参考**:
306
307
  1. **DELPHI-GATE**: 验证 `.sprint-state/delphi-reviewed.json` 存在且 `verdict = "APPROVED"` → 否则 BLOCK
307
- 2. **输入**: `slices-manifest.json`(Phase 2/6 生成),按 `execution_order` 逐个执行
308
- 3. **模式**: 默认 `ralph-loop`(逐 REQ 迭代,token 节约 40-67%),可选 `--mode parallel`
309
- 4. **Skill 步骤**: hooks-install dispatching-parallel-agents TDD (RED/GREEN/REFACTOR) → freeze → blind-review unfreeze → verification-before-completion → 成本监控
310
- 5. **Mock Minimization**: integration-first, mock 仅限 external services, 密度 > 30% `@mock-justified`
308
+ 2. **TDD-GATE (MANDATORY — v0.14.0+)**: 在 delegation 前验证每个 REQ 存在 failing test。无 test → mark `[TDD-RED]`(ralph-loop 创建)。有 test 且 GREEN 且无实现 → BLOCK(TDD bypass)。详见 `references/phase-3-build.md#tdd-gate-pre-implementation-tdd-check-mandatory`。
309
+ 3. **输入**: `slices-manifest.json`(Phase 2/6 生成),按 `execution_order` 逐个执行
310
+ 4. **模式**: 默认 `ralph-loop`(逐 REQ 迭代,token 节约 40-67%),可选 `--mode parallel`
311
+ 5. **Skill 步骤**: hooks-install TDD-GATE dispatching-parallel-agents TDD (RED/GREEN/REFACTOR) freeze → blind-review → unfreeze → verification-before-completion → 成本监控
312
+ 6. **Mock Minimization**: integration-first, mock 仅限 external services, 密度 > 30% 需 `@mock-justified`
311
313
 
312
314
  ### Phase 4/6: VERIFY (验证 — 代码走查 + QA + 反馈获取)
313
315
 
@@ -336,17 +338,20 @@ Sprint Flow: PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE
336
338
 
337
339
  **对应旧模型**: Phase 5 SHIP + Phase 6 LAND
338
340
 
339
- **详细指令**: 参见 `references/phase-5-ship.md` — GITHOOKS-GATE / VERSION-GATE / VERSION CHANGESET (Issue #142) / changeset schema。
341
+ **详细指令**: 参见 `references/phase-5-ship.md` — VERSION-GATE (MANDATORY) / finishing-a-development-branch / VERSION CHANGESET (Issue #142) / changeset schema。
340
342
 
341
343
  **快速参考**:
342
- - **Orchestrator 直接执行**: `finishing-a-development-branch` `ship` 均为交互式 skill(4 选项菜单 + PR 确认),**必须由 orchestrator 直接调用** `skill(name="finishing-a-development-branch")` 和 `skill(name="ship")`
343
- - 输入: phase-4-summary.md + feedback-log.md 输出: PR URL
344
+ - **Step 0: VERSION-GATE (MANDATORY — 必须在 finishing-a-development-branch 之前)**: bump VERSION update CHANGELOG.md → run sync-version.sh → commit + push verify PR updated。详见 `references/phase-5-ship.md#step-0-version-gate`
345
+ - **Step 1: finishing-a-development-branch**: 4 选项菜单,选择 "Push and create a Pull Request"
346
+ - **Orchestrator 直接执行**: `finishing-a-development-branch` 和 `ship` 均为交互式 skill,**必须由 orchestrator 直接调用** `skill(name="finishing-a-development-branch")` 和 `skill(name="ship")`
347
+ - 输入: phase-4-summary.md + feedback-log.md → 输出: PR URL (含版本变更 commit)
344
348
  - **HARD-GATE**: Phase 4/6 未完成 → BLOCK。验证 `feedback-log.md` 存在。
345
349
  - **GITHOOKS-GATE**: 验证 hooks 完整性,缺失则 `githooks/install.sh`
346
- - **VERSION-GATE**: bump PATCH/MINOR/MAJOR → `sync-version.sh` → CHANGELOG.md → `git diff VERSION` 验证
347
350
  - **LAND**: `land-and-deploy` — merge PR → 等待 CI (10min) → 等待 Deploy (10min) → Canary Health Check (5min)
348
351
  - **回滚**: `git revert` 最后一次 merge commit
349
352
 
353
+ **⚠️ VERSION-GATE 必须在 finishing-a-development-branch 之前执行。顺序反了会导致 PR 不含版本变更 → CI release workflow 不触发 → 无新版本发布。**
354
+
350
355
  ### Phase 6/6: CLOSE (收尾 — ⚠️ 人工验收 + 清理)
351
356
 
352
357
  **对应旧模型**: Phase 7 USER ACCEPTANCE + Phase 8 CLEANUP
@@ -102,7 +102,33 @@ skill(name="brainstorming", user_message="[需求描述]")
102
102
  skill(name="design-shotgun", user_message="[Pain Document 内容 + 需求描述]")
103
103
  ```
104
104
 
105
- #### Step 1: 调用 autoplan skill
105
+ #### Step 0.5: DESIGN 路由分叉(v0.14.0+ — Issue #306)
106
+
107
+ 根据 Phase 1/6 PREP (AUTO-ESTIMATE) 的 `change_type` 决定走哪条路径:
108
+
109
+ ```
110
+ 读取 .sprint-state/sprint-state.json → auto_estimate.change_type
111
+
112
+ IF change_type == "修改已存在代码":
113
+ → 增量优化路径: SKIP autoplan
114
+ → 直接进入 Step 2b: delphi-review (lightweight: 2 专家, 1 轮)
115
+ ELSE (change_type == "新增功能" 或 未定义):
116
+ → 标准路径: 继续 Step 1 (autoplan) → Step 2
117
+ ```
118
+
119
+ **路由决策表**:
120
+
121
+ | change_type | 路径 | autoplan | delphi-review |
122
+ |------------|------|----------|---------------|
123
+ | `修改已存在代码` | 增量优化 | ❌ SKIP | lightweight (2 专家, 1 轮) |
124
+ | `新增功能` | 标准 | ✅ 执行 | 标准 (3 专家) |
125
+ | `undefined` / 缺失 | 标准 (fail-safe) | ✅ 执行 | 标准 (3 专家) |
126
+
127
+ **HARD-GATE 不变**: 两条路径最终都必须产出 APPROVED 的 delphi-reviewed.json。
128
+
129
+ #### Step 1: 调用 autoplan skill(仅标准路径)
130
+
131
+ **仅当 change_type != "修改已存在代码" 时执行。**
106
132
 
107
133
  ```
108
134
  skill(name="autoplan", user_message="[Pain Document 内容]")
@@ -140,10 +166,15 @@ autoplan_result:
140
166
  #### Step 2b: 调用 delphi-review(强制,orchestrator 直接执行)
141
167
 
142
168
  ```
169
+ # 标准路径(3 专家)
143
170
  skill(name="delphi-review", user_message="[设计文档 + taste_decisions 确认结果]")
171
+
172
+ # 增量优化路径(2 专家, 1 轮 — 来自 Step 0.5 路由)
173
+ skill(name="delphi-review", user_message="[设计文档]", experts=2, max_rounds=1)
144
174
  ```
145
175
 
146
- - Round 1: 3 专家匿名独立评审
176
+ - **标准路径**: Round 1: 3 专家匿名独立评审
177
+ - **增量优化路径**: 2 专家, 1 轮 (来自 Step 0.5 DESIGN 路由分叉)
147
178
  - Round 2+: 交换意见直到共识
148
179
  - 输出: APPROVED / REQUEST_CHANGES
149
180
 
@@ -81,6 +81,69 @@ SKIP_UNCOMMITTED_GATE=1
81
81
 
82
82
  ---
83
83
 
84
+ ## TDD-GATE: Pre-Implementation TDD Check (MANDATORY — v0.14.0+)
85
+
86
+ **Purpose**: Enforce RED → GREEN → REFACTOR discipline at BUILD entry before any delegation.
87
+
88
+ **Execution**: Before dispatching to ralph-loop or parallel agents, the orchestrator MUST verify for each REQ:
89
+
90
+ ### Gate Logic
91
+
92
+ ```
93
+ FOR each REQ in slices-manifest.json:
94
+ IF test file exists for this REQ:
95
+ IF test passes (GREEN state) AND no implementation exists:
96
+ → BLOCK: TDD bypass detected. Test is passing before implementation.
97
+ ELSE IF test fails (RED state):
98
+ → ALLOW: Proceed to implementation (GREEN phase).
99
+ ELSE (no test file exists):
100
+ → ALLOW: Mark REQ as [TDD-RED]. ralph-loop creates the test as step 0.
101
+ ```
102
+
103
+ ### Todo Prefix Convention
104
+
105
+ Each todo item MUST carry a TDD phase prefix in the content field:
106
+ - `[TDD-RED]`: Write failing test first. No implementation yet.
107
+ - `[TDD-GREEN]`: Write minimal implementation to make test pass.
108
+ - `[TDD-REFACTOR]`: Refactor while keeping tests green.
109
+
110
+ The priority field (high/medium/low) is separate and unchanged.
111
+
112
+ Example:
113
+ ```
114
+ "[TDD-RED] src/lib/auth.ts: Add validateToken() test for expired tokens - expect test to fail"
115
+ "[TDD-GREEN] src/lib/auth.ts: Implement validateToken() to pass test - expect test passes"
116
+ "[TDD-REFACTOR] src/lib/auth.ts: Extract token parsing into parseToken() helper - expect tests stay green"
117
+ ```
118
+
119
+ ### Deadlock Prevention
120
+
121
+ The TDD-GATE is a PRE-RALPH-LOOP check, NOT a replacement for ralph-loop's internal TDD:
122
+ - If no test exists → ralph-loop IS allowed to proceed (creates test as step 0)
123
+ - If test exists and is GREEN without implementation → BLOCK (TDD bypass)
124
+ - The gate verifies TDD DISCIPLINE was followed, not that TDD was skipped
125
+
126
+ ### Limitation
127
+
128
+ This enforcement is instructional (LLM follows SKILL.md instructions), not programmatic. For stronger enforcement, consider a future automated pre-commit hook that checks git staging order (test file must be staged before source file).
129
+
130
+ ### Log Format (`.sprint-state/tdd-gate-log.json`)
131
+
132
+ ```json
133
+ {
134
+ "checked": true,
135
+ "blocked": false,
136
+ "skipped": false,
137
+ "reqs_checked": 4,
138
+ "reqs_blocked": 0,
139
+ "timestamp": "2026-07-09T00:00:00Z"
140
+ }
141
+ ```
142
+
143
+ **Log location**: `.sprint-state/tdd-gate-log.json` — written on every gate execution for audit trail.
144
+
145
+ ---
146
+
84
147
  ## TDD 强制执行
85
148
 
86
149
  ### Gate 5a-BLOCK: 新增文件测试强制
@@ -13,15 +13,70 @@
13
13
 
14
14
  **Orchestrator 直接执行**: `finishing-a-development-branch` 和 `ship` 均为交互式 skill(4 选项菜单 + PR 确认),**必须由 orchestrator 直接调用**。
15
15
 
16
- **关键链**: PHASE4-GATE → verification → finishing-a-development-branch(4选项) → ship
16
+ **关键链**: VERSION-GATE(MANDATORY) → finishing-a-development-branch(4选项) → push PR
17
17
 
18
18
  **HARD-GATE**: Phase 4/6 VERIFY 未完成 → BLOCK。验证 `feedback-log.md` 存在。
19
19
 
20
20
  **GITHOOKS-GATE**: 验证 hooks 完整性,缺失则 `githooks/install.sh`
21
21
 
22
- **VERSION-GATE**: bump PATCH/MINOR/MAJOR `sync-version.sh` CHANGELOG.md → `git diff VERSION` 验证
22
+ **NETWORK-RESILIENCE**: GitHub API 在大中华区存在间歇性 TLS/超时问题。所有 `gh` CLI 调用应容忍偶尔失败:
23
+ - `gh` 命令失败时等待 2-5 秒后重试(最多 3 次)
24
+ - 优先使用 REST API (`gh api /repos/...`) 而非 GraphQL (`gh pr view --json ...`),REST 更轻量更可靠
25
+ - 验证 CI 状态时使用 `gh run list --branch ... --limit 1 --json status,conclusion` 代替 `gh pr view --json statusCheckRollup`
26
+ - 如果 `gh` 持续超时,fallback 到 `curl + token`:
27
+ ```
28
+ curl -s -H "Authorization: token $(gh auth token)" \
29
+ "https://api.github.com/repos/OWNER/REPO/commits/HEAD/status"
30
+ ```
23
31
 
24
- **输出**: PR URL
32
+ ### Step 0: VERSION-GATE(MANDATORY — 在 finishing-a-development-branch 之前执行)
33
+
34
+ **Purpose**: Ensure version bump, changelog update, and sync before creating PR. This MUST run BEFORE calling `finishing-a-development-branch` — the skill's "Create PR" option creates the PR immediately, so version changes must be committed first.
35
+
36
+ **Execution**:
37
+
38
+ ```
39
+ 1. 根据变更类型决定 bump 级别:
40
+ - PATCH (0.14.0 → 0.14.1): bug fixes, docs, minor enhancements
41
+ - MINOR (0.14.0 → 0.15.0): new features, significant enhancements
42
+ - MAJOR (0.14.0 → 1.0.0): breaking changes
43
+
44
+ 2. 更新 VERSION 文件 (MAJOR.MINOR.PATCH.MICRO 格式)
45
+
46
+ 3. 更新 CHANGELOG.md:
47
+ - 添加新版本条目 (## [X.Y.Z.W] - YYYY-MM-DD)
48
+ - 按 ### Added / ### Fixed / ### Changed 分类
49
+
50
+ 4. 运行 sync-version.sh:
51
+ bash scripts/sync-version.sh
52
+
53
+ 5. 验证:
54
+ git diff VERSION # 确认版本号变更
55
+ git diff CHANGELOG.md # 确认 changelog 变更
56
+ git diff --stat # 确认 package.json 版本同步
57
+
58
+ 6. 提交版本变更:
59
+ git add VERSION CHANGELOG.md && git commit -m "release: bump version to X.Y.Z.W"
60
+
61
+ 7. 推送到远程分支:
62
+ git push
63
+
64
+ 8. 验证 CI 流程触发:
65
+ gh pr view <PR_NUMBER> --json state # 确认 CI 已开始
66
+ ```
67
+
68
+ **GATE CHECK** (BEFORE proceeding to finishing-a-development-branch):
69
+ ```
70
+ [VERSION-GATE] VERSION bump ✓ # VERSION 文件已更新
71
+ [VERSION-GATE] CHANGELOG ✓ # 新版本条目已添加
72
+ [VERSION-GATE] sync-version ✓ # 所有 package.json 已同步
73
+ [VERSION-GATE] committed ✓ # 版本变更已提交并推送
74
+ [VERSION-GATE] PR updated ✓ # PR 已包含版本变更 commit
75
+ ```
76
+
77
+ **⚠️ ANTI-PATTERN**: 先调用 finishing-a-development-branch 创建 PR,再 bump VERSION 会导致 PR 不含版本变更 → CI 不触发 release workflow → 无新版本发布。
78
+
79
+ **输出**: 版本变更 commit 包含在 PR 中
25
80
 
26
81
  ---
27
82
 
@@ -3,6 +3,8 @@
3
3
  **执行时机**: Phase 5/6 SHIP 完成后。
4
4
  **对应旧模型**: Phase 7 USER ACCEPTANCE + Phase 8 CLEANUP
5
5
 
6
+ **NETWORK-RESILIENCE**: 与 Phase 5/6 相同,GitHub API 在大中华区存在间歇性超时。CLEANUP 中的 `gh pr list` 和 `git push --delete` 需容忍重试。详见 `phase-5-ship.md` NETWORK-RESILIENCE 指南。
7
+
6
8
  ---
7
9
 
8
10
  ## Part A: USER ACCEPTANCE(⚠️ 人工验收)
@@ -100,7 +102,64 @@ Phase 6/6 CLOSE 完成时:
100
102
  ### 输出
101
103
 
102
104
  - Emergent Issues List (`emergent-issues.md`)
103
- - 进入 Part B CLEANUP 自动执行(如果用户确认验收)
105
+ - 进入 Part A.5 ARCHIVE 自动执行(如果用户确认验收)
106
+
107
+ ---
108
+
109
+ ## Part A.5: ARCHIVE(归档 — v0.14.0+ Issue #308)
110
+
111
+ **Purpose**: Preserve sprint decision records before cleanup. `.sprint-state/` is gitignored and deleted during CLEANUP; this step copies structured outputs to `.sprint-history/` which is tracked by git.
112
+
113
+ **Execution**: After USER ACCEPTANCE (Part A) confirms continuation, BEFORE CLEANUP (Part B).
114
+
115
+ ### Step 1: Read Sprint ID
116
+
117
+ Read `sprint-state.json` → `id` field (e.g., `sprint-2026-07-09-01`).
118
+
119
+ ### Step 2: Check for Conflicts
120
+
121
+ ```
122
+ IF .sprint-history/<sprint-id>/ already exists:
123
+ → Append timestamp suffix: <sprint-id>-20260709T120000
124
+ → Log warning: "Sprint archive conflict, using timestamp suffix"
125
+ ```
126
+
127
+ ### Step 3: Archive Files
128
+
129
+ Copy from `.sprint-state/` to `.sprint-history/<sprint-id>/`:
130
+
131
+ **Included** (all `.yaml`, `.json`, `.md` files under `.sprint-state/`):
132
+ - `specification.yaml` (if in phase-outputs/)
133
+ - `delphi-reviewed.json`
134
+ - `sprint-state.json`
135
+ - `phase-outputs/*.yaml`, `phase-outputs/*.json`, `phase-outputs/*.md`
136
+ - `tdd-gate-log.json`, `uncommitted-gate-log.json`
137
+
138
+ **Excluded** (temporary/cache):
139
+ - `*.tmp`, `*.cache` files
140
+ - `sprint.lock` (session lock file)
141
+
142
+ ### Step 4: Verify Git Tracking
143
+
144
+ ```bash
145
+ # .sprint-history/ is NOT in .gitignore (verified — no change needed)
146
+ # Verify files are trackable:
147
+ git status .sprint-history/
148
+ ```
149
+
150
+ **No `.gitignore` change needed**: `.sprint-history/` is NOT currently listed in `.gitignore`. The `.sprint-state/` ignore (line 59) only matches `.sprint-state/` exactly — it does NOT match `.sprint-history/`.
151
+
152
+ ### Step 5: Commit Archive (Optional)
153
+
154
+ The orchestrator MAY commit the archive:
155
+ ```
156
+ git add .sprint-history/<sprint-id>/ && git commit -m "archive: sprint <sprint-id>"
157
+ ```
158
+
159
+ ### Output
160
+
161
+ - `.sprint-history/<sprint-id>/` directory with archived sprint state
162
+ - Git-tracked sprint decision records for future retro/review
104
163
 
105
164
  ---
106
165