@boyingliu01/xp-gate 0.19.2 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/adapters/gate-4.sh +83 -18
  2. package/adapters/gate-8.sh +49 -5
  3. package/adapters/iac.sh +1 -1
  4. package/adapters/typescript.sh +15 -60
  5. package/bin/xp-gate.js +15 -16
  6. package/gate-10.sh +35 -2
  7. package/gate-4.sh +110 -21
  8. package/gate-8.sh +49 -5
  9. package/hooks/gate-10.sh +35 -2
  10. package/hooks/gate-4.sh +110 -21
  11. package/hooks/gate-8.sh +49 -5
  12. package/hooks/lib/jscpd-run.sh +63 -0
  13. package/hooks/lib/sprint-gate-report.sh +58 -0
  14. package/hooks/lib/test-failure.sh +152 -0
  15. package/hooks/lib/typecheck.sh +141 -0
  16. package/hooks/lib/validate-code-walkthrough.cjs +43 -5
  17. package/hooks/post-merge +100 -0
  18. package/hooks/pre-commit +401 -155
  19. package/hooks/pre-push +75 -19
  20. package/lib/__tests__/bootstrap.test.js +23 -41
  21. package/lib/__tests__/check-version.test.js +8 -1
  22. package/lib/__tests__/detect-deps.test.js +16 -0
  23. package/lib/__tests__/doctor-drift-round2.test.js +212 -0
  24. package/lib/__tests__/doctor-executed-surface.test.js +209 -0
  25. package/lib/__tests__/doctor-hook-drift.test.js +329 -0
  26. package/lib/__tests__/doctor-machine-mutation.test.js +116 -0
  27. package/lib/__tests__/doctor-module-drift.test.js +206 -0
  28. package/lib/__tests__/doctor-module-resolution-parity.test.js +314 -0
  29. package/lib/__tests__/doctor-path-equivalence.test.js +59 -0
  30. package/lib/__tests__/doctor-repair-boundary.test.js +52 -0
  31. package/lib/__tests__/doctor-tui-skill-freshness.test.js +105 -0
  32. package/lib/__tests__/doctor.test.js +155 -0
  33. package/lib/__tests__/gate-runner.test.js +19 -3
  34. package/lib/__tests__/helpers/lib-sandbox.cjs +55 -0
  35. package/lib/__tests__/init.test.js +44 -17
  36. package/lib/__tests__/install-skill-full-dir.test.js +151 -0
  37. package/lib/__tests__/install-skill.test.js +51 -132
  38. package/lib/__tests__/language-tools-detect.test.js +158 -0
  39. package/lib/__tests__/phase-transition.test.js +15 -1
  40. package/lib/__tests__/qoder-delphi-agents.test.js +285 -0
  41. package/lib/__tests__/shared-paths.test.js +20 -0
  42. package/lib/__tests__/shared-utils.test.js +69 -0
  43. package/lib/__tests__/skill-flags.test.js +48 -0
  44. package/lib/__tests__/ui-detector.test.ts +6 -2
  45. package/lib/__tests__/uninstall.test.js +20 -0
  46. package/lib/__tests__/update-hooks.test.js +12 -0
  47. package/lib/__tests__/update-skill.test.js +7 -4
  48. package/lib/detect-deps.js +3 -20
  49. package/lib/doctor-tui.js +22 -5
  50. package/lib/doctor.js +1178 -31
  51. package/lib/init.js +184 -33
  52. package/lib/install-cmd.js +7 -4
  53. package/lib/install-skill.js +38 -95
  54. package/lib/language-tools.js +83 -4
  55. package/lib/mattpocock-license-verdict.json +1 -1
  56. package/lib/shared-paths.js +5 -2
  57. package/lib/shared-utils.js +47 -3
  58. package/lib/uninstall.js +12 -0
  59. package/lib/update-hooks.js +4 -4
  60. package/lib/update-skill.js +6 -7
  61. package/mock-policy/AGENTS.md +4 -4
  62. package/mutation/AGENTS.md +4 -4
  63. package/mutation/__tests__/gate-m.test.ts +66 -14
  64. package/mutation/__tests__/mutmut-runner.test.ts +91 -42
  65. package/mutation/__tests__/test-filter-parity.test.ts +37 -0
  66. package/mutation/gate-m.ts +21 -8
  67. package/package.json +1 -1
  68. package/plugins/claude-code/.claude-plugin/plugin.json +2 -2
  69. package/plugins/claude-code/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +0 -1
  70. package/plugins/claude-code/skills/delphi-review/AGENTS.md +4 -4
  71. package/plugins/claude-code/skills/delphi-review/SKILL.md +98 -14
  72. package/plugins/claude-code/skills/delphi-review/references/code-walkthrough.md +36 -3
  73. package/plugins/claude-code/skills/delphi-review/references/requirements.md +6 -6
  74. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +4 -4
  75. package/plugins/claude-code/skills/sprint-flow/references/phase-2-design.md +3 -3
  76. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +4 -4
  77. package/plugins/dsh/README.md +169 -4
  78. package/plugins/dsh/dsh-overlay.patch.yml +67 -0
  79. package/plugins/dsh/package.json +1 -1
  80. package/plugins/dsh/scripts/prepack.cjs +24 -19
  81. package/plugins/dsh/setup-dsh.ps1 +160 -0
  82. package/plugins/dsh/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +0 -1
  83. package/plugins/dsh/skills/delphi-review/AGENTS.md +4 -4
  84. package/plugins/dsh/skills/delphi-review/SKILL.md +98 -14
  85. package/plugins/dsh/skills/delphi-review/references/code-walkthrough.md +36 -3
  86. package/plugins/dsh/skills/delphi-review/references/requirements.md +6 -6
  87. package/plugins/dsh/skills/sprint-flow/AGENTS.md +4 -4
  88. package/plugins/dsh/skills/sprint-flow/references/phase-2-design.md +3 -3
  89. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +4 -4
  90. package/plugins/dsh/src/command.test.ts +66 -2
  91. package/plugins/dsh/src/command.ts +36 -14
  92. package/plugins/dsh/src/contract.test.ts +31 -1
  93. package/plugins/dsh/src/delphi-config.test.ts +190 -0
  94. package/plugins/dsh/src/delphi-config.ts +223 -0
  95. package/plugins/dsh/src/delphi-run.test.ts +181 -0
  96. package/plugins/dsh/src/delphi-run.ts +129 -0
  97. package/plugins/dsh/src/delphi.test.ts +222 -0
  98. package/plugins/dsh/src/delphi.ts +247 -0
  99. package/plugins/dsh/src/dialect.test.ts +59 -0
  100. package/plugins/dsh/src/dialect.ts +40 -0
  101. package/plugins/dsh/src/index.ts +70 -4
  102. package/plugins/dsh/src/skills.test.ts +26 -19
  103. package/plugins/opencode/package.json +1 -1
  104. package/plugins/opencode/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +0 -1
  105. package/plugins/opencode/skills/delphi-review/AGENTS.md +4 -4
  106. package/plugins/opencode/skills/delphi-review/SKILL.md +98 -14
  107. package/plugins/opencode/skills/delphi-review/references/code-walkthrough.md +36 -3
  108. package/plugins/opencode/skills/delphi-review/references/requirements.md +6 -6
  109. package/plugins/opencode/skills/sprint-flow/AGENTS.md +4 -4
  110. package/plugins/opencode/skills/sprint-flow/references/phase-2-design.md +3 -3
  111. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +4 -4
  112. package/plugins/qoder/agents/delphi-architecture.md +1 -1
  113. package/plugins/qoder/agents/delphi-feasibility.md +1 -1
  114. package/plugins/qoder/agents/delphi-technical.md +1 -1
  115. package/plugins/qoder/plugin.json +2 -2
  116. package/plugins/qoder/skills/admin-template-guidelines/SKILL.md +6 -797
  117. package/plugins/qoder/skills/admin-template-guidelines/references/rule-1.md +91 -0
  118. package/plugins/qoder/skills/admin-template-guidelines/references/rule-2.md +155 -0
  119. package/plugins/qoder/skills/admin-template-guidelines/references/rule-3.md +70 -0
  120. package/plugins/qoder/skills/admin-template-guidelines/references/rule-4.md +154 -0
  121. package/plugins/qoder/skills/admin-template-guidelines/references/rule-5.md +126 -0
  122. package/plugins/qoder/skills/admin-template-guidelines/references/rule-6.md +180 -0
  123. package/plugins/qoder/skills/batch-grill-me/SKILL.md +15 -0
  124. package/plugins/qoder/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +0 -1
  125. package/plugins/qoder/skills/clipboard-vision/describe-clipboard.ps1 +115 -0
  126. package/plugins/qoder/skills/clipboard-vision/describe-clipboard.sh +161 -0
  127. package/plugins/qoder/skills/delphi-review/.delphi-config.json.example +61 -28
  128. package/plugins/qoder/skills/delphi-review/AGENTS.md +4 -4
  129. package/plugins/qoder/skills/delphi-review/INSTALL.md +97 -98
  130. package/plugins/qoder/skills/delphi-review/SKILL.md +170 -63
  131. package/plugins/qoder/skills/delphi-review/hooks.md +19 -0
  132. package/plugins/qoder/skills/delphi-review/opencode.json.delphi.example +6 -10
  133. package/plugins/qoder/skills/delphi-review/references/code-walkthrough.md +36 -3
  134. package/plugins/qoder/skills/delphi-review/references/orchestrator-dispatch.md +64 -0
  135. package/plugins/qoder/skills/delphi-review/references/requirements.md +402 -0
  136. package/plugins/qoder/skills/delphi-review/references/round-templates.md +134 -0
  137. package/plugins/qoder/skills/delphi-review/scripts/verify-consensus.sh +43 -0
  138. package/plugins/qoder/skills/delphi-review/tools.md +29 -0
  139. package/plugins/qoder/skills/domain-modeling/ADR-FORMAT.md +64 -0
  140. package/plugins/qoder/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
  141. package/plugins/qoder/skills/domain-modeling/SKILL.md +74 -0
  142. package/plugins/qoder/skills/grill-with-docs/SKILL.md +7 -0
  143. package/plugins/qoder/skills/grilling/SKILL.md +12 -0
  144. package/plugins/qoder/skills/ralph-loop/SKILL.md +87 -428
  145. package/plugins/qoder/skills/ralph-loop/references/components.md +113 -0
  146. package/plugins/qoder/skills/ralph-loop/references/workflow-details.md +99 -0
  147. package/plugins/qoder/skills/sprint-flow/AGENTS.md +5 -5
  148. package/plugins/qoder/skills/sprint-flow/SKILL.md +255 -454
  149. package/plugins/qoder/skills/sprint-flow/__tests__/sprint-flow.test.cjs +457 -0
  150. package/plugins/qoder/skills/sprint-flow/hooks.md +18 -0
  151. package/plugins/qoder/skills/sprint-flow/references/components/memory.md +1 -1
  152. package/plugins/qoder/skills/sprint-flow/references/components/middleware.md +1 -1
  153. package/plugins/qoder/skills/sprint-flow/references/components/skill-invocations.md +21 -20
  154. package/plugins/qoder/skills/sprint-flow/references/components/tool-descriptions.md +22 -23
  155. package/plugins/qoder/skills/sprint-flow/references/force-levels.md +0 -1
  156. package/plugins/qoder/skills/sprint-flow/references/orchestration-rules.md +34 -27
  157. package/plugins/qoder/skills/sprint-flow/references/phase-1-prep.md +1 -1
  158. package/plugins/qoder/skills/sprint-flow/references/phase-2-design.md +160 -123
  159. package/plugins/qoder/skills/sprint-flow/references/phase-3-build.md +203 -2
  160. package/plugins/qoder/skills/sprint-flow/references/phase-4-verify.md +107 -34
  161. package/plugins/qoder/skills/sprint-flow/references/phase-5-ship.md +194 -12
  162. package/plugins/qoder/skills/sprint-flow/references/phase-6-close.md +139 -7
  163. package/plugins/qoder/skills/sprint-flow/references/phase-overview.md +486 -0
  164. package/plugins/qoder/skills/sprint-flow/scripts/verify-sprint-state.sh +38 -0
  165. package/plugins/qoder/skills/sprint-flow/tools.md +29 -0
  166. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +4 -4
  167. package/plugins/qoder/skills/test-specification-alignment/SKILL.md +104 -601
  168. package/plugins/qoder/skills/to-issues/SKILL.md +1 -1
  169. package/principles/AGENTS.md +9 -8
  170. package/principles/__tests__/adapter-metrics.test.ts +292 -0
  171. package/principles/__tests__/analyzer.test.ts +29 -6
  172. package/principles/__tests__/baseline-prune-timeout.test.ts +71 -0
  173. package/principles/__tests__/baseline-prune.test.ts +338 -0
  174. package/principles/__tests__/boy-scout-init-baseline.test.ts +167 -0
  175. package/principles/__tests__/boy-scout-integration.test.ts +97 -6
  176. package/principles/__tests__/boy-scout.test.ts +253 -7
  177. package/principles/__tests__/config-enforcement.test.ts +469 -0
  178. package/principles/__tests__/config-git-timeout.test.ts +66 -0
  179. package/principles/__tests__/direct-execution.test.ts +187 -0
  180. package/principles/__tests__/index.test.ts +16 -3
  181. package/principles/__tests__/warnings-baseline-budgets.test.ts +74 -0
  182. package/principles/adapters/typescript.ts +613 -13
  183. package/principles/analyzer.ts +22 -0
  184. package/principles/baseline-prune.ts +217 -0
  185. package/principles/boy-scout.ts +481 -51
  186. package/principles/config.ts +362 -54
  187. package/principles/direct-execution.ts +60 -0
  188. package/principles/index.ts +40 -17
  189. package/principles/rules/__tests__/clean-code/many-exports.test.ts +16 -10
  190. package/principles/rules/clean-code/code-duplication.ts +8 -8
  191. package/principles/rules/clean-code/deep-nesting.ts +8 -8
  192. package/principles/rules/clean-code/god-class.ts +8 -8
  193. package/principles/rules/clean-code/large-file.ts +15 -11
  194. package/principles/rules/clean-code/long-function.ts +8 -8
  195. package/principles/rules/clean-code/magic-numbers.ts +10 -7
  196. package/principles/rules/clean-code/many-exports.ts +7 -7
  197. package/principles/rules/clean-code/missing-error-handling.ts +5 -5
  198. package/principles/rules/clean-code/too-many-params.ts +8 -8
  199. package/principles/rules/clean-code/unused-imports.ts +5 -5
  200. package/principles/rules/solid/dip.ts +18 -8
  201. package/principles/rules/solid/isp.ts +9 -8
  202. package/principles/rules/solid/lsp.ts +6 -6
  203. package/principles/rules/solid/ocp.ts +6 -5
  204. package/principles/rules/solid/srp.ts +7 -8
  205. package/principles/types.ts +15 -0
  206. package/scripts/__tests__/sync-package-content.test.js +28 -0
  207. package/scripts/delphi-external-review.cjs +193 -10
  208. package/scripts/sync-package-content.js +7 -4
  209. package/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +0 -1
  210. package/skills/delphi-review/AGENTS.md +4 -4
  211. package/skills/delphi-review/SKILL.md +98 -14
  212. package/skills/delphi-review/references/code-walkthrough.md +36 -3
  213. package/skills/delphi-review/references/requirements.md +6 -6
  214. package/skills/sprint-flow/AGENTS.md +4 -4
  215. package/skills/sprint-flow/references/phase-2-design.md +3 -3
  216. package/skills/test-specification-alignment/AGENTS.md +4 -4
  217. package/lib/__tests__/download-skill.test.js +0 -281
  218. package/lib/download-skill.js +0 -96
  219. package/plugins/qoder/skills/ralph-loop/references/components/memory.md +0 -55
  220. package/plugins/qoder/skills/ralph-loop/references/components/middleware.md +0 -54
  221. package/plugins/qoder/skills/ralph-loop/references/components/skill-invocations.md +0 -39
  222. package/plugins/qoder/skills/ralph-loop/references/components/system-prompt.md +0 -24
  223. package/plugins/qoder/skills/ralph-loop/references/components/tool-descriptions.md +0 -32
@@ -3,38 +3,220 @@
3
3
  **执行时机**: Phase 4/6 VERIFY 完成后、Phase 6/6 CLOSE 之前。
4
4
  **对应旧模型**: Phase 5 SHIP + Phase 6 LAND
5
5
 
6
- **摘要**: 结构化分支完成决策, 创建 PR, 合并部署, 监控. 生成 Sprint Summary.
6
+ **摘要**: 结构化分支完成决策(原生 4 选项), 创建 PR(原生步骤), 合并部署(原生步骤), 监控. 生成 Sprint Summary.
7
7
 
8
8
  ---
9
9
 
10
10
  ## Part A: SHIP(发布准备)
11
11
 
12
- **完整指令**: @see SKILL.md Phase 5/6 SHIP section.
12
+ **Orchestrator 直接执行**: 分支完成决策和 PR 创建均为交互式步骤(4 选项菜单 + PR 确认),**必须由 orchestrator 直接执行**。
13
13
 
14
- **Orchestrator 直接执行**: `finishing-a-development-branch` 和 `ship` 均为交互式 skill(4 选项菜单 + PR 确认),**必须由 orchestrator 直接调用**。
15
-
16
- **关键链**: PHASE4-GATE → verification → finishing-a-development-branch(4选项) → ship
14
+ **关键链**: VERSION-GATE(MANDATORY) → 分支完成决策(4选项) → push PR
17
15
 
18
16
  **HARD-GATE**: Phase 4/6 VERIFY 未完成 → BLOCK。验证 `feedback-log.md` 存在。
19
17
 
20
18
  **GITHOOKS-GATE**: 验证 hooks 完整性,缺失则 `githooks/install.sh`
21
19
 
22
- **VERSION-GATE**: bump PATCH/MINOR/MAJOR → `sync-version.sh` → CHANGELOG.md → `git diff VERSION` 验证
20
+ **NETWORK-RESILIENCE**: GitHub API 在大中华区存在间歇性 TLS/超时问题。所有 `gh` CLI 调用应容忍偶尔失败:
21
+ - `gh` 命令失败时等待 2-5 秒后重试(最多 3 次)
22
+ - 优先使用 REST API (`gh api /repos/...`) 而非 GraphQL (`gh pr view --json ...`),REST 更轻量更可靠
23
+ - 验证 CI 状态时使用 `gh run list --branch ... --limit 1 --json status,conclusion` 代替 `gh pr view --json statusCheckRollup`
24
+ - 如果 `gh` 持续超时,fallback 到 `curl + token`:
25
+ ```
26
+ curl -s -H "Authorization: token $(gh auth token)" \
27
+ "https://api.github.com/repos/OWNER/REPO/commits/HEAD/status"
28
+ ```
29
+
30
+ ### Step 0: VERSION-GATE(MANDATORY — 在分支完成决策之前执行)
31
+
32
+ **Purpose**: Ensure version bump, changelog update, and sync before creating PR. This MUST run BEFORE the branch completion decision — the "Create PR" option creates the PR immediately, so version changes must be committed first.
33
+
34
+ **Execution**:
35
+
36
+ ```
37
+ 1. 根据变更类型决定 bump 级别:
38
+ - PATCH (0.14.0 → 0.14.1): bug fixes, docs, minor enhancements
39
+ - MINOR (0.14.0 → 0.15.0): new features, significant enhancements
40
+ - MAJOR (0.14.0 → 1.0.0): breaking changes
41
+
42
+ 2. 更新 VERSION 文件 (MAJOR.MINOR.PATCH.MICRO 格式)
43
+
44
+ 3. 更新 CHANGELOG.md:
45
+ - 添加新版本条目 (## [X.Y.Z.W] - YYYY-MM-DD)
46
+ - 按 ### Added / ### Fixed / ### Changed 分类
47
+
48
+ 4. 运行 sync-version.sh:
49
+ bash scripts/sync-version.sh
50
+
51
+ 5. 验证:
52
+ git diff VERSION # 确认版本号变更
53
+ git diff CHANGELOG.md # 确认 changelog 变更
54
+ git diff --stat # 确认 package.json 版本同步
55
+
56
+ 6. 提交版本变更:
57
+ git add VERSION CHANGELOG.md && git commit -m "release: bump version to X.Y.Z.W"
58
+
59
+ 7. 推送到远程分支:
60
+ git push
61
+
62
+ 8. 验证 CI 流程触发:
63
+ gh pr view <PR_NUMBER> --json state # 确认 CI 已开始
64
+ ```
65
+
66
+ **GATE CHECK** (BEFORE proceeding to branch completion decision):
67
+ ```
68
+ [VERSION-GATE] VERSION bump ✓ # VERSION 文件已更新
69
+ [VERSION-GATE] CHANGELOG ✓ # 新版本条目已添加
70
+ [VERSION-GATE] sync-version ✓ # 所有 package.json 已同步
71
+ [VERSION-GATE] committed ✓ # 版本变更已提交并推送
72
+ [VERSION-GATE] PR updated ✓ # PR 已包含版本变更 commit
73
+ ```
74
+
75
+ **⚠️ ANTI-PATTERN**: 先创建 PR 再 bump VERSION 会导致 PR 不含版本变更 → CI 不触发 release workflow → 无新版本发布。
76
+
77
+ **输出**: 版本变更 commit 包含在 PR 中
78
+
79
+ ### Step 1: 分支完成决策(原生 4 选项 — AskUserQuestion)
80
+
81
+ VERSION-GATE 通过后,orchestrator 向用户展示 4 选项菜单:
82
+
83
+ ```
84
+ ⚠️ Phase 5/6 SHIP: 分支完成决策
85
+
86
+ Sprint 分支已准备就绪。请选择操作:
87
+
88
+ 1. **Merge to main** — 直接合并到主分支(适用于个人项目或已确认无需 PR 审查)
89
+ 2. **Push and create a Pull Request** — 推送并创建 PR(推荐,含 CI 验证)
90
+ 3. **Keep branch** — 保留分支,稍后处理
91
+ 4. **Discard** — 丢弃分支(⚠️ 需要输入确认)
92
+
93
+ 请选择 (1-4):
94
+ ```
95
+
96
+ **Option 4 (Discard) 安全确认**: 要求用户输入分支名确认,防止误删。
97
+
98
+ **默认推荐**: Option 2(Push and create a Pull Request)。
99
+
100
+ ### Step 2: 原生 Ship 步骤序列(选择 Option 2 时执行)
101
+
102
+ ```
103
+ 1. 运行测试:
104
+ npm test # 或项目特定测试命令
105
+
106
+ 2. VERSION-GATE 已通过(Step 0)
107
+
108
+ 3. 提交所有变更:
109
+ git add -A && git commit -m "feat: <sprint-description>"
23
110
 
24
- **输出**: PR URL
111
+ 4. 推送到远程:
112
+ git push -u origin <sprint-branch>
113
+
114
+ 5. 创建 PR:
115
+ gh pr create --title "feat: <description>" --body "<sprint-summary>"
116
+
117
+ 6. 输出 PR URL
118
+ ```
119
+
120
+ **输出**: PR URL (含版本变更 commit)
25
121
 
26
122
  ---
27
123
 
28
- ## Part B: LAND(合并 + 部署)
124
+ ## Part B: LAND(合并 + 部署 — 原生步骤)
29
125
 
30
- **Orchestrator 直接执行**: `land-and-deploy` 包含 merge 确认和 rollback 决策,**必须由 orchestrator 直接调用** `skill(name="land-and-deploy")`
126
+ **Orchestrator 直接执行**: 合并确认和 rollback 决策均为用户交互点,**必须由 orchestrator 直接执行**。
31
127
 
32
128
  **输入**: PR URL → 输出: 部署状态 + Canary 报告
33
129
 
34
- **流程**: Merge PR → 等待 CI (10min) → 等待 Deploy (10min) → Canary Health Check (5min)
130
+ ### Step 1: Merge 确认
131
+
132
+ ```
133
+ ⚠️ 确认合并 PR #<number> 到 main?
134
+
135
+ PR: <PR URL>
136
+ 变更: <files changed> 个文件, +<additions>/-<deletions>
137
+
138
+ 确认合并? (yes/no):
139
+ ```
140
+
141
+ ### Step 2: 等待 CI
142
+
143
+ ```
144
+ # 等待 CI 完成(最多 10 分钟)
145
+ gh run list --branch main --limit 1 --json status,conclusion
146
+
147
+ # 轮询直到完成
148
+ WHILE status != "completed":
149
+ 等待 30 秒
150
+ 重新查询
151
+ ```
152
+
153
+ ### Step 3: 等待 Deploy(如适用)
154
+
155
+ ```
156
+ # 等待部署完成(最多 10 分钟)
157
+ # 检测部署平台(Fly.io/Render/Vercel/Netlify/Heroku/GitHub Actions)
158
+ # 查询部署状态
159
+ ```
160
+
161
+ **条件跳过**: 无部署配置时仅 merge + CI。
162
+
163
+ ### Step 4: Canary Health Check(如适用,最多 5 分钟)
164
+
165
+ ```
166
+ # 健康检查端点
167
+ curl -s <health-check-url>
168
+ # 验证返回 200 + 预期响应
169
+ ```
35
170
 
36
- **回滚**: `git revert` 最后一次 merge commit
171
+ ### Step 5: 失败回滚
37
172
 
38
- **条件跳过**: 无部署配置时仅 merge + CI
173
+ ```
174
+ IF CI 失败 OR 部署失败 OR canary 异常:
175
+ git revert <merge-commit-sha>
176
+ git push
177
+ 输出 "[ROLLBACK] 已回滚 merge commit"
178
+ ```
39
179
 
40
180
  **输出**: 部署状态 (success/failure/skipped), Canary 报告
181
+
182
+ ---
183
+
184
+ ## SHIP COMPLETION GATE (MANDATORY — v0.14.3+)
185
+
186
+ **Purpose**: Ensure merge to main + release is complete before Phase 6/6 CLOSE. Without this gate, worktree cleanup fails (uncommitted changes + unmerged branch) and UAT happens on the wrong version (PR branch, not main).
187
+
188
+ **Execution** (BEFORE transitioning to Phase 6/6):
189
+
190
+ ```
191
+ 1. Verify PR is merged:
192
+ gh pr list --head <sprint-branch> --state merged --json number
193
+ → If no merged PR: BLOCK. Do NOT proceed to Phase 6/6.
194
+
195
+ 2. Verify current branch is main:
196
+ CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
197
+ → If not main/master: BLOCK. Switch to main first.
198
+
199
+ 3. Verify git status is clean:
200
+ git status --porcelain
201
+ → If not empty: BLOCK. Stash or commit changes first.
202
+
203
+ 4. Verify release exists:
204
+ gh release view v<X.Y.Z> --json tagName
205
+ → If not found: WARNING (manual release may have failed). Ask user.
206
+
207
+ 5. Pull latest main:
208
+ git checkout main && git pull
209
+ ```
210
+
211
+ **GATE CHECK** (BEFORE Phase 6/6 CLOSE):
212
+ ```
213
+ [SHIP→CLOSE GATE] PR merged ✓ # PR is in merged state
214
+ [SHIP→CLOSE GATE] on main branch ✓ # Current branch is main/master
215
+ [SHIP→CLOSE GATE] clean status ✓ # No uncommitted changes
216
+ [SHIP→CLOSE GATE] release exists ✓ # GitHub Release created
217
+ [SHIP→CLOSE GATE] main up-to-date ✓ # Pulled latest
218
+ ```
219
+
220
+ **IF GATE FAILS**: Orchestrator MUST complete the merge/release steps BEFORE proceeding to Phase 6/6. Do NOT skip to CLOSE.
221
+
222
+ **Output**: SHIP completion confirmation, ready for Phase 6/6.
@@ -1,8 +1,51 @@
1
1
  # Phase 6/6: CLOSE(收尾 — ⚠️ 人工验收 + 清理)
2
2
 
3
- **执行时机**: Phase 5/6 SHIP 完成后。
3
+ **执行时机**: Phase 5/6 SHIP 完成后(merge to main + release 已完成)。
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
+
8
+ ---
9
+
10
+ ## ⚠️ HARD-GATE: SHIP→CLOSE GATE (MANDATORY — v0.14.3+)
11
+
12
+ **Purpose**: Verify that Phase 5/6 SHIP fully completed (merge to main + release) before entering Phase 6/6 CLOSE. This gate prevents:
13
+ - Worktree cleanup failure (uncommitted changes prevent `git worktree remove`)
14
+ - UAT on wrong version (PR branch instead of merged main)
15
+
16
+ **Execution**: Before ANY Phase 6/6 step, run the SHIP→CLOSE GATE checks defined in `phase-5-ship.md#ship-completion-gate`.
17
+
18
+ **If gate fails**: Return to Phase 5/6 SHIP to complete merge/release. Do NOT proceed with CLOSE.
19
+
20
+ ---
21
+
22
+ ## Backup Sprint State (MANDATORY — v0.14.3+)
23
+
24
+ **Purpose**: `.sprint-state/` is gitignored and lives inside the worktree. When the worktree is removed during CLEANUP, all sprint state is lost. This step copies it into the main repository before cleanup.
25
+
26
+ **Execution** (immediately after SHIP→CLOSE GATE passes):
27
+
28
+ ```bash
29
+ # 1. Read sprint ID
30
+ SPRINT_ID=$(cat .sprint-state/sprint-state.json | grep '"id"' | head -1 | sed 's/.*"id": *"\([^"]*\)".*/\1/')
31
+
32
+ # 2. Backup to repo-tracked path (.sprint-history is NOT in .gitignore)
33
+ BACKUP_DIR=".sprint-history/${SPRINT_ID}"
34
+ mkdir -p "$BACKUP_DIR"
35
+ cp -r .sprint-state/* "$BACKUP_DIR/"
36
+
37
+ # 3. Verify backup
38
+ ls "$BACKUP_DIR/sprint-state.json" && echo "✅ Sprint state backed up to $BACKUP_DIR"
39
+ ```
40
+
41
+ **GATE CHECK**:
42
+ ```
43
+ [BACKUP] sprint-state.json copied ✓
44
+ [BACKUP] phase-outputs/ preserved ✓
45
+ ```
46
+
47
+ **Output**: `.sprint-history/<sprint-id>/` contains full sprint state, safely outside the worktree.
48
+
6
49
  ---
7
50
 
8
51
  ## Part A: USER ACCEPTANCE(⚠️ 人工验收)
@@ -100,13 +143,101 @@ Phase 6/6 CLOSE 完成时:
100
143
  ### 输出
101
144
 
102
145
  - Emergent Issues List (`emergent-issues.md`)
103
- - 进入 Part B CLEANUP 自动执行(如果用户确认验收)
146
+ - 进入 Part A.5 ARCHIVE 自动执行(如果用户确认验收)
147
+
148
+ ---
149
+
150
+ ## Part A.5: ARCHIVE(归档 — v0.14.0+ Issue #308)
151
+
152
+ **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.
153
+
154
+ **Execution**: After USER ACCEPTANCE (Part A) confirms continuation, BEFORE CLEANUP (Part B).
155
+
156
+ ### Step 1: Read Sprint ID
157
+
158
+ Read `sprint-state.json` → `id` field (e.g., `sprint-2026-07-09-01`).
159
+
160
+ ### Step 2: Check for Conflicts
161
+
162
+ ```
163
+ IF .sprint-history/<sprint-id>/ already exists:
164
+ → Append timestamp suffix: <sprint-id>-20260709T120000
165
+ → Log warning: "Sprint archive conflict, using timestamp suffix"
166
+ ```
167
+
168
+ ### Step 3: Archive Files
169
+
170
+ Copy from `.sprint-state/` to `.sprint-history/<sprint-id>/`:
171
+
172
+ **Included** (all `.yaml`, `.json`, `.md` files under `.sprint-state/`):
173
+ - `specification.yaml` (if in phase-outputs/)
174
+ - `delphi-reviewed.json`
175
+ - `sprint-state.json`
176
+ - `phase-outputs/*.yaml`, `phase-outputs/*.json`, `phase-outputs/*.md`
177
+ - `tdd-gate-log.json`, `uncommitted-gate-log.json`
178
+
179
+ **Excluded** (temporary/cache):
180
+ - `*.tmp`, `*.cache` files
181
+ - `sprint.lock` (session lock file)
182
+
183
+ ### Step 4: Verify Git Tracking
184
+
185
+ ```bash
186
+ # .sprint-history/ is NOT in .gitignore (verified — no change needed)
187
+ # Verify files are trackable:
188
+ git status .sprint-history/
189
+ ```
190
+
191
+ **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/`.
192
+
193
+ ### Step 5: Commit Archive (Optional)
194
+
195
+ The orchestrator MAY commit the archive:
196
+ ```
197
+ git add .sprint-history/<sprint-id>/ && git commit -m "archive: sprint <sprint-id>"
198
+ ```
199
+
200
+ ### Output
201
+
202
+ - `.sprint-history/<sprint-id>/` directory with archived sprint state
203
+ - Git-tracked sprint decision records for future retro/review
104
204
 
105
205
  ---
106
206
 
107
- ## Part B: CLEANUP(清理 + 总结)
207
+ ## Part B: CLEANUP(清理 + 总结 + 返工追踪)
208
+
209
+ **摘要**: 写入 #369 返工指标, 自动清理 worktree, 更新 sprint-state.json, 输出 Sprint Summary, 处理 emergent issues.
210
+
211
+ ### Step 0: #369 返工追踪指标写入(v0.18.0+)
212
+
213
+ **Purpose**: Sprint 完成后追踪返工率,暴露"门禁全过但仍返工"的质量问题。
214
+
215
+ **Execution** (CLEANUP 开始时,worktree 清理前):
216
+
217
+ ```
218
+ 1. 写入 metrics.completed_at:
219
+ ISO 8601 时间戳 → sprint-state.json metrics.completed_at
220
+
221
+ 2. 计算 metrics.total_sprint_commits:
222
+ 精确定义: sprint 分支 base(merge-base)到 sprint 合并点的提交数
223
+ CLOSE 时由 CLI 计算写入:
224
+ npx xp-gate sprint-status --rework-check
225
+
226
+ 3. 写入 metrics.merge_base_sha:
227
+ merge-base SHA → sprint-state.json metrics.merge_base_sha
228
+ (SHIP 阶段存入,供删分支后 rework-check 使用 — C5 澄清)
229
+ ```
230
+
231
+ **返工率计算** (`xp-gate sprint-status --rework-check [--window-days N]`):
232
+ - 默认窗口: 7 天(可配置)
233
+ - 扫描范围: **仓库范围**(不限同一分支 — 主工作流"合并 PR + 删除分支"下同分支判定恒为 0)
234
+ - fix 提交匹配: conventional commits 优先 `^fix(\(.+\))?:`,辅以词边界关键词 `\b(fix|bugfix|hotfix|patch|修复)\b`
235
+ - 计算: `rework_rate = fix_commits_in_window / total_sprint_commits`
236
+ - 写回 `metrics.rework_rate`
237
+
238
+ **告警**: `rework_rate > 30%` → 告警输出(并纳入 `xp-gate retro` 报告区块)
108
239
 
109
- **摘要**: 自动清理 worktree, 更新 sprint-state.json, 输出 Sprint Summary, 处理 emergent issues.
240
+ **注意**: "重新打开的 issue 数"指标已删除(Round 1 修订:零依赖原则下无可靠数据源)。
110
241
 
111
242
  ### 执行步骤
112
243
 
@@ -117,10 +248,11 @@ Phase 6/6 CLOSE 完成时:
117
248
  3. **删除本地分支**: `git branch -D sprint/YYYY-MM-DD-NN`
118
249
  4. **删除远程分支**: `git push origin --delete sprint/YYYY-MM-DD-NN`
119
250
  5. **关闭遗留 OPEN PR**: `gh pr list --head sprint/YYYY-MM-DD-NN --state open`
120
- 6. **更新 sprint-state.json**: 设置 `phase: 6`, `status: "completed"`
251
+ 6. **更新 sprint-state.json**: 设置 `phase: 6`, `status: "completed"`, 写入 `metrics.completed_at` + `metrics.total_sprint_commits`(#369)
121
252
  7. **释放 Sprint Lock** (Issue #144): 删除 `.sprint-state/sprint.lock`
122
- 8. **Sprint Summary**: 使用 `templates/sprint-summary-template.md` 生成总结
123
- 9. **处理 Emergent Issues**: 如 Part A 发现 emergent issues → 触发 Sprint 2 逻辑
253
+ 8. **Learnings 写入**(原生): 将 Sprint 中发现的模式/教训追加到 `.sprint-history/learnings.md`
254
+ 9. **Sprint Summary**: 使用 `templates/sprint-summary-template.md` 生成总结
255
+ 10. **处理 Emergent Issues**: 如 Part A 发现 emergent issues → 触发 Sprint 2 逻辑
124
256
 
125
257
  ### 输出
126
258