@boyingliu01/xp-gate 0.7.0 → 0.8.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 (197) hide show
  1. package/bin/xp-gate.js +4 -9
  2. package/lib/__tests__/audit-log.test.ts +107 -0
  3. package/lib/__tests__/detect-deps.test.js +212 -42
  4. package/lib/__tests__/doctor.test.js +1 -0
  5. package/lib/__tests__/gate-audit.test.ts +59 -0
  6. package/lib/__tests__/init.test.js +47 -1
  7. package/lib/__tests__/install-skill.test.js +1 -45
  8. package/lib/__tests__/ui-detector.test.ts +186 -26
  9. package/lib/__tests__/ui-review.test.ts +119 -0
  10. package/lib/__tests__/uninstall.test.js +1 -0
  11. package/lib/detect-deps.js +180 -37
  12. package/lib/doctor.js +7 -9
  13. package/lib/gate-audit.ts +26 -42
  14. package/lib/init.js +42 -13
  15. package/lib/install-skill.js +20 -48
  16. package/lib/rollback.js +1 -16
  17. package/lib/shared-paths.js +30 -0
  18. package/lib/shared-utils.js +25 -0
  19. package/lib/ui-detector.ts +20 -14
  20. package/lib/ui-review.ts +58 -53
  21. package/lib/uninstall.js +8 -9
  22. package/package.json +1 -1
  23. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  24. package/plugins/claude-code/skills/admin-template-guidelines/SKILL.md +904 -0
  25. package/plugins/claude-code/skills/delphi-review/.delphi-config.json.example +45 -0
  26. package/plugins/claude-code/skills/delphi-review/AGENTS.md +66 -0
  27. package/plugins/claude-code/skills/delphi-review/INSTALL.md +152 -0
  28. package/plugins/claude-code/skills/delphi-review/SKILL.md +454 -0
  29. package/plugins/claude-code/skills/delphi-review/opencode.json.delphi.example +56 -0
  30. package/plugins/claude-code/skills/delphi-review/references/code-walkthrough.md +486 -0
  31. package/plugins/claude-code/skills/improve-codebase-architecture/SKILL.md +156 -0
  32. package/plugins/claude-code/skills/ralph-loop/SKILL.md +501 -0
  33. package/plugins/claude-code/skills/ralph-loop/references/components/memory.md +55 -0
  34. package/plugins/claude-code/skills/ralph-loop/references/components/middleware.md +54 -0
  35. package/plugins/claude-code/skills/ralph-loop/references/components/skill-invocations.md +39 -0
  36. package/plugins/claude-code/skills/ralph-loop/references/components/system-prompt.md +24 -0
  37. package/plugins/claude-code/skills/ralph-loop/references/components/tool-descriptions.md +32 -0
  38. package/plugins/claude-code/skills/ralph-loop/references/phase-2-build-ralph.md +89 -0
  39. package/plugins/claude-code/skills/ralph-loop/templates/progress-log.md +36 -0
  40. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +68 -0
  41. package/plugins/claude-code/skills/sprint-flow/SKILL.md +1248 -0
  42. package/plugins/claude-code/skills/sprint-flow/references/components/memory.md +87 -0
  43. package/plugins/claude-code/skills/sprint-flow/references/components/middleware.md +72 -0
  44. package/plugins/claude-code/skills/sprint-flow/references/components/skill-invocations.md +104 -0
  45. package/plugins/claude-code/skills/sprint-flow/references/components/system-prompt.md +27 -0
  46. package/plugins/claude-code/skills/sprint-flow/references/components/tool-descriptions.md +96 -0
  47. package/plugins/claude-code/skills/sprint-flow/references/force-levels.md +203 -0
  48. package/plugins/claude-code/skills/sprint-flow/references/phase-0-think.md +115 -0
  49. package/plugins/claude-code/skills/sprint-flow/references/phase-1-plan.md +178 -0
  50. package/plugins/claude-code/skills/sprint-flow/references/phase-2-build.md +198 -0
  51. package/plugins/claude-code/skills/sprint-flow/references/phase-3-review.md +213 -0
  52. package/plugins/claude-code/skills/sprint-flow/references/phase-4-uat.md +125 -0
  53. package/plugins/claude-code/skills/sprint-flow/references/phase-5-feedback.md +100 -0
  54. package/plugins/claude-code/skills/sprint-flow/references/phase-6-ship.md +193 -0
  55. package/plugins/claude-code/skills/sprint-flow/references/phase-7-land.md +140 -0
  56. package/plugins/claude-code/skills/sprint-flow/references/phase-8-cleanup.md +192 -0
  57. package/plugins/claude-code/skills/sprint-flow/references/phase-minus-0-5-auto-estimate.md +257 -0
  58. package/plugins/claude-code/skills/sprint-flow/templates/auto-estimate-learning-log.md +136 -0
  59. package/plugins/claude-code/skills/sprint-flow/templates/auto-estimate-output-template.md +132 -0
  60. package/plugins/claude-code/skills/sprint-flow/templates/emergent-issues-template.md +120 -0
  61. package/plugins/claude-code/skills/sprint-flow/templates/pain-document-template.md +115 -0
  62. package/plugins/claude-code/skills/sprint-flow/templates/sprint-progress-template.md +151 -0
  63. package/plugins/claude-code/skills/sprint-flow/templates/sprint-summary-template.md +120 -0
  64. package/plugins/claude-code/skills/test-driven-development/SKILL.md +71 -0
  65. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +56 -0
  66. package/plugins/claude-code/skills/test-specification-alignment/SKILL.md +702 -0
  67. package/plugins/claude-code/skills/test-specification-alignment/references/alignment-verification-algorithm.md +493 -0
  68. package/plugins/claude-code/skills/test-specification-alignment/references/phase2-constraint-enforcement.md +431 -0
  69. package/plugins/claude-code/skills/test-specification-alignment/references/specification-format.md +348 -0
  70. package/plugins/claude-code/skills/to-issues/SKILL.md +277 -0
  71. package/plugins/opencode/README.md +38 -0
  72. package/plugins/opencode/index.ts +85 -0
  73. package/plugins/opencode/package.json +18 -0
  74. package/plugins/opencode/skills/admin-template-guidelines/SKILL.md +904 -0
  75. package/plugins/opencode/skills/delphi-review/.delphi-config.json.example +45 -0
  76. package/plugins/opencode/skills/delphi-review/AGENTS.md +66 -0
  77. package/plugins/opencode/skills/delphi-review/INSTALL.md +152 -0
  78. package/plugins/opencode/skills/delphi-review/SKILL.md +454 -0
  79. package/plugins/opencode/skills/delphi-review/opencode.json.delphi.example +56 -0
  80. package/plugins/opencode/skills/delphi-review/references/code-walkthrough.md +486 -0
  81. package/plugins/opencode/skills/improve-codebase-architecture/SKILL.md +156 -0
  82. package/plugins/opencode/skills/ralph-loop/SKILL.md +501 -0
  83. package/plugins/opencode/skills/ralph-loop/references/components/memory.md +55 -0
  84. package/plugins/opencode/skills/ralph-loop/references/components/middleware.md +54 -0
  85. package/plugins/opencode/skills/ralph-loop/references/components/skill-invocations.md +39 -0
  86. package/plugins/opencode/skills/ralph-loop/references/components/system-prompt.md +24 -0
  87. package/plugins/opencode/skills/ralph-loop/references/components/tool-descriptions.md +32 -0
  88. package/plugins/opencode/skills/ralph-loop/references/phase-2-build-ralph.md +89 -0
  89. package/plugins/opencode/skills/ralph-loop/templates/progress-log.md +36 -0
  90. package/plugins/opencode/skills/sprint-flow/AGENTS.md +68 -0
  91. package/plugins/opencode/skills/sprint-flow/SKILL.md +1248 -0
  92. package/plugins/opencode/skills/sprint-flow/references/components/memory.md +87 -0
  93. package/plugins/opencode/skills/sprint-flow/references/components/middleware.md +72 -0
  94. package/plugins/opencode/skills/sprint-flow/references/components/skill-invocations.md +104 -0
  95. package/plugins/opencode/skills/sprint-flow/references/components/system-prompt.md +27 -0
  96. package/plugins/opencode/skills/sprint-flow/references/components/tool-descriptions.md +96 -0
  97. package/plugins/opencode/skills/sprint-flow/references/force-levels.md +203 -0
  98. package/plugins/opencode/skills/sprint-flow/references/phase-0-think.md +115 -0
  99. package/plugins/opencode/skills/sprint-flow/references/phase-1-plan.md +178 -0
  100. package/plugins/opencode/skills/sprint-flow/references/phase-2-build.md +198 -0
  101. package/plugins/opencode/skills/sprint-flow/references/phase-3-review.md +213 -0
  102. package/plugins/opencode/skills/sprint-flow/references/phase-4-uat.md +125 -0
  103. package/plugins/opencode/skills/sprint-flow/references/phase-5-feedback.md +100 -0
  104. package/plugins/opencode/skills/sprint-flow/references/phase-6-ship.md +193 -0
  105. package/plugins/opencode/skills/sprint-flow/references/phase-7-land.md +140 -0
  106. package/plugins/opencode/skills/sprint-flow/references/phase-8-cleanup.md +192 -0
  107. package/plugins/opencode/skills/sprint-flow/references/phase-minus-0-5-auto-estimate.md +257 -0
  108. package/plugins/opencode/skills/sprint-flow/templates/auto-estimate-learning-log.md +136 -0
  109. package/plugins/opencode/skills/sprint-flow/templates/auto-estimate-output-template.md +132 -0
  110. package/plugins/opencode/skills/sprint-flow/templates/emergent-issues-template.md +120 -0
  111. package/plugins/opencode/skills/sprint-flow/templates/pain-document-template.md +115 -0
  112. package/plugins/opencode/skills/sprint-flow/templates/sprint-progress-template.md +151 -0
  113. package/plugins/opencode/skills/sprint-flow/templates/sprint-summary-template.md +120 -0
  114. package/plugins/opencode/skills/test-driven-development/SKILL.md +71 -0
  115. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +56 -0
  116. package/plugins/opencode/skills/test-specification-alignment/SKILL.md +702 -0
  117. package/plugins/opencode/skills/test-specification-alignment/references/alignment-verification-algorithm.md +493 -0
  118. package/plugins/opencode/skills/test-specification-alignment/references/phase2-constraint-enforcement.md +431 -0
  119. package/plugins/opencode/skills/test-specification-alignment/references/specification-format.md +348 -0
  120. package/plugins/opencode/skills/to-issues/SKILL.md +277 -0
  121. package/plugins/opencode/tsconfig.json +15 -0
  122. package/plugins/qoder/skills/admin-template-guidelines/SKILL.md +904 -0
  123. package/plugins/qoder/skills/delphi-review/.delphi-config.json.example +45 -0
  124. package/plugins/qoder/skills/delphi-review/AGENTS.md +66 -0
  125. package/plugins/qoder/skills/delphi-review/INSTALL.md +152 -0
  126. package/plugins/qoder/skills/delphi-review/SKILL.md +454 -0
  127. package/plugins/qoder/skills/delphi-review/opencode.json.delphi.example +56 -0
  128. package/plugins/qoder/skills/delphi-review/references/code-walkthrough.md +486 -0
  129. package/plugins/qoder/skills/improve-codebase-architecture/SKILL.md +156 -0
  130. package/plugins/qoder/skills/ralph-loop/SKILL.md +501 -0
  131. package/plugins/qoder/skills/ralph-loop/references/components/memory.md +55 -0
  132. package/plugins/qoder/skills/ralph-loop/references/components/middleware.md +54 -0
  133. package/plugins/qoder/skills/ralph-loop/references/components/skill-invocations.md +39 -0
  134. package/plugins/qoder/skills/ralph-loop/references/components/system-prompt.md +24 -0
  135. package/plugins/qoder/skills/ralph-loop/references/components/tool-descriptions.md +32 -0
  136. package/plugins/qoder/skills/ralph-loop/references/phase-2-build-ralph.md +89 -0
  137. package/plugins/qoder/skills/ralph-loop/templates/progress-log.md +36 -0
  138. package/plugins/qoder/skills/sprint-flow/AGENTS.md +68 -0
  139. package/plugins/qoder/skills/sprint-flow/SKILL.md +1248 -0
  140. package/plugins/qoder/skills/sprint-flow/references/components/memory.md +87 -0
  141. package/plugins/qoder/skills/sprint-flow/references/components/middleware.md +72 -0
  142. package/plugins/qoder/skills/sprint-flow/references/components/skill-invocations.md +104 -0
  143. package/plugins/qoder/skills/sprint-flow/references/components/system-prompt.md +27 -0
  144. package/plugins/qoder/skills/sprint-flow/references/components/tool-descriptions.md +96 -0
  145. package/plugins/qoder/skills/sprint-flow/references/force-levels.md +203 -0
  146. package/plugins/qoder/skills/sprint-flow/references/phase-0-think.md +115 -0
  147. package/plugins/qoder/skills/sprint-flow/references/phase-1-plan.md +178 -0
  148. package/plugins/qoder/skills/sprint-flow/references/phase-2-build.md +198 -0
  149. package/plugins/qoder/skills/sprint-flow/references/phase-3-review.md +213 -0
  150. package/plugins/qoder/skills/sprint-flow/references/phase-4-uat.md +125 -0
  151. package/plugins/qoder/skills/sprint-flow/references/phase-5-feedback.md +100 -0
  152. package/plugins/qoder/skills/sprint-flow/references/phase-6-ship.md +193 -0
  153. package/plugins/qoder/skills/sprint-flow/references/phase-7-land.md +140 -0
  154. package/plugins/qoder/skills/sprint-flow/references/phase-8-cleanup.md +192 -0
  155. package/plugins/qoder/skills/sprint-flow/references/phase-minus-0-5-auto-estimate.md +257 -0
  156. package/plugins/qoder/skills/sprint-flow/templates/auto-estimate-learning-log.md +136 -0
  157. package/plugins/qoder/skills/sprint-flow/templates/auto-estimate-output-template.md +132 -0
  158. package/plugins/qoder/skills/sprint-flow/templates/emergent-issues-template.md +120 -0
  159. package/plugins/qoder/skills/sprint-flow/templates/pain-document-template.md +115 -0
  160. package/plugins/qoder/skills/sprint-flow/templates/sprint-progress-template.md +151 -0
  161. package/plugins/qoder/skills/sprint-flow/templates/sprint-summary-template.md +120 -0
  162. package/plugins/qoder/skills/test-driven-development/SKILL.md +71 -0
  163. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +56 -0
  164. package/plugins/qoder/skills/test-specification-alignment/SKILL.md +702 -0
  165. package/plugins/qoder/skills/test-specification-alignment/references/alignment-verification-algorithm.md +493 -0
  166. package/plugins/qoder/skills/test-specification-alignment/references/phase2-constraint-enforcement.md +431 -0
  167. package/plugins/qoder/skills/test-specification-alignment/references/specification-format.md +348 -0
  168. package/plugins/qoder/skills/to-issues/SKILL.md +277 -0
  169. package/skills/admin-template-guidelines/SKILL.md +904 -0
  170. package/skills/delphi-review/SKILL.md +112 -77
  171. package/skills/improve-codebase-architecture/SKILL.md +156 -0
  172. package/skills/ralph-loop/SKILL.md +165 -34
  173. package/skills/sprint-flow/SKILL.md +448 -107
  174. package/skills/sprint-flow/references/components/skill-invocations.md +1 -1
  175. package/skills/sprint-flow/references/components/tool-descriptions.md +1 -1
  176. package/skills/sprint-flow/references/force-levels.md +203 -0
  177. package/skills/sprint-flow/references/phase-1-plan.md +4 -4
  178. package/skills/sprint-flow/references/phase-minus-0-5-auto-estimate.md +20 -1
  179. package/skills/sprint-flow/templates/auto-estimate-output-template.md +7 -5
  180. package/skills/sprint-flow/templates/sprint-progress-template.md +151 -0
  181. package/skills/test-driven-development/SKILL.md +71 -0
  182. package/skills/test-specification-alignment/SKILL.md +98 -24
  183. package/skills/to-issues/SKILL.md +277 -0
  184. package/plugins/qoder/AGENTS.md +0 -93
  185. package/plugins/qoder/README.md +0 -87
  186. package/plugins/qoder/widgets/quality-report.html +0 -163
  187. package/plugins/qoder/widgets/sprint-dashboard.html +0 -172
  188. package/skills/delphi-review/evals/evals.json +0 -82
  189. package/skills/delphi-review/references/qoder-multi-model.md +0 -191
  190. package/skills/ralph-loop/evals/evals.json +0 -311
  191. package/skills/ralph-loop/evolution-history.json +0 -59
  192. package/skills/ralph-loop/evolution-log.md +0 -16
  193. package/skills/sprint-flow/evals/evals.json +0 -130
  194. package/skills/sprint-flow/evolution-history.json +0 -39
  195. package/skills/sprint-flow/evolution-log.md +0 -23
  196. package/skills/sprint-flow/references/qoder-adaptation.md +0 -173
  197. package/skills/test-specification-alignment/evals/evals.json +0 -75
@@ -0,0 +1,486 @@
1
+ # Code Walkthrough Mode Reference
2
+
3
+ > Extracted from `SKILL.md`. This file contains ALL content specific to the `code-walkthrough` mode of Delphi Review.
4
+
5
+ ---
6
+
7
+ ## Overview
8
+
9
+ 代码走查模式,用于 git push 前对代码变更进行多专家 Delphi 评审。
10
+
11
+ **触发命令**: `/code-walkthrough` (等价于 `/delphi-review --mode code-walkthrough`)
12
+
13
+ ---
14
+
15
+ ## Five Core Properties
16
+
17
+ 1. **匿名性** — Expert A/B 互不知道对方意见
18
+ 2. **迭代共识** — 多轮直到 APPROVED
19
+ 3. **零容忍** — Critical Issues 必须修复
20
+ 4. **零降级** — 环境/资源问题必须阻断,通知用户解决
21
+ 5. **强制覆盖** — 超过阈值必须 BLOCK,不能跳过
22
+
23
+ ---
24
+
25
+ ## 触发条件
26
+
27
+ - **自动触发**:`git push` 前(通过 pre-push hook 验证结果文件)
28
+ - **手动触发**:`/code-walkthrough` 命令(等价于 `/delphi-review --mode code-walkthrough`)
29
+
30
+ **⚠️ 重要调用方式说明**:
31
+
32
+ - ✅ **正确**: 在 Agent session 中执行 `/code-walkthrough`
33
+ - ❌ **错误**: Shell 脚本调用 `opencode code-walkthrough` (OpenCode CLI 不支持 skill 子命令)
34
+ - ❌ **错误**: CLI 子命令 `opencode run --skill code-walkthrough --diff` (不支持)
35
+
36
+ **设计决策**: code-walkthrough 是 **强制但手动触发** 的质量门禁:
37
+ - **强制**: push 必须有有效的 `.code-walkthrough-result.json` 文件
38
+ - **手动**: Skill 执行由用户在 Agent session 内触发
39
+ - **理由**: 避免 OpenCode CLI 架构限制,保持正常工作模式
40
+
41
+ **⚠️ 门禁零容忍声明**:
42
+
43
+ code-walkthrough 是强制性质控门禁,以下行为严格禁止:
44
+ - ❌ 使用 `git push --no-verify` 绕过 pre-push hook 验证
45
+ - ❌ 伪造 `.code-walkthrough-result.json` 文件
46
+ - ❌ 因为"时间紧急"或"变更很小"而跳过评审
47
+ - ❌ 修改门禁阈值让告警消失
48
+
49
+ **门禁工具检测出的问题 = 必须修复,不允许绕过。**
50
+
51
+ 详见: [质量门禁行为准则](../../githooks/QUALITY-GATES-CODE-OF-CONDUCT.md)
52
+
53
+ ---
54
+
55
+ ## 流程概览
56
+
57
+ ```
58
+ git push
59
+
60
+
61
+ pre-push hook
62
+
63
+ ├─→ 获取 git diff main...HEAD
64
+
65
+ ├─→ 提取变更摘要
66
+
67
+ ├─→ 运行 Principles Checker (Clean Code + SOLID)
68
+
69
+ ├─→ 触发 Delphi 评审 (code-walkthrough mode)
70
+ │ │
71
+ │ ├─→ Expert A (架构 + 设计) 匿名评审 (含 principles_findings)
72
+ │ │
73
+ │ ├─→ Expert B (实现 + 代码质量) 匿名评审 (含 principles_findings)
74
+ │ │
75
+ │ ├─→ 共识检查
76
+ │ │ │
77
+ │ │ ├─→ 2/2 APPROVED → 允许推送
78
+ │ │ │
79
+ │ │ ├─→ 分歧 → Expert C 仲裁
80
+ │ │ │
81
+ │ │ └─→ REQUEST_CHANGES → 阻塞推送
82
+ │ │
83
+ │ └─→ 写入 .code-walkthrough-result.json
84
+
85
+ └─→ 允许/阻塞推送
86
+ ```
87
+
88
+ ---
89
+
90
+ ## 专家角色
91
+
92
+ | 专家 | 视角 | 配置 |
93
+ |------|------|------|
94
+ | Expert A | 架构 + 设计评审 | `.delphi-config.json` → `experts.architecture` |
95
+ | Expert B | 实现 + 代码质量 | `.delphi-config.json` → `experts.technical` |
96
+ | Expert C (仲裁) | 冲突裁决 | `.delphi-config.json` → `experts.feasibility` |
97
+
98
+ > ⚠️ **注意**: 至少配置 **两个不同 provider** 的模型。详见 [INSTALL.md](./INSTALL.md)。
99
+
100
+ ---
101
+
102
+ ## 评审维度
103
+
104
+ **必检项**:
105
+
106
+ | 维度 | 检查内容 |
107
+ |------|---------|
108
+ | **正确性** | 逻辑是否正确,边界条件是否处理 |
109
+ | **安全性** | 是否有注入、泄露、越权风险 |
110
+ | **可维护性** | 命名、结构、注释是否清晰 |
111
+ | **测试覆盖** | 是否有足够的测试 |
112
+
113
+ **选检项**(根据变更类型):
114
+
115
+ | 变更类型 | 额外检查 |
116
+ |---------|---------|
117
+ | API 变更 | 接口兼容性、文档更新 |
118
+ | 数据库变更 | 迁移脚本、回滚方案 |
119
+ | 性能敏感 | 性能测试、基准对比 |
120
+
121
+ ---
122
+
123
+ ## Principles Module Integration
124
+
125
+ 作为代码走查的一部分,自动运行 principles checker 分析:
126
+
127
+ ```yaml
128
+ principles_module:
129
+ enabled: true
130
+ trigger: pre-push
131
+ rules:
132
+ - clean-code.all # 9 rules
133
+ - solid.all # 5 rules
134
+ integration_point: expert_prompt
135
+ output_format: principles_findings section
136
+ ```
137
+
138
+ **Principles 检查流程**:
139
+
140
+ ```
141
+ git push
142
+
143
+
144
+ pre-push hook
145
+
146
+ ├─→ Step 1: Principles Checker
147
+ │ │
148
+ │ ├─→ 检测变更文件语言
149
+ │ ├─→ 选择对应 Adapter
150
+ │ ├─→ 运行 14 个规则
151
+ │ │ │
152
+ │ │ ├─→ Clean Code (9 rules)
153
+ │ │ │ - long-function (>50 lines)
154
+ │ │ │ - large-file (>500 lines)
155
+ │ │ │ - magic-numbers (非语义数字)
156
+ │ │ │ - god-class (>15 methods)
157
+ │ │ │ - deep-nesting (>4 levels)
158
+ │ │ │ - too-many-params (>7)
159
+ │ │ │ - missing-error-handling (IO 无 try-catch)
160
+ │ │ │ - unused-imports (未使用的导入)
161
+ │ │ │ - code-duplication (>15% 相似度)
162
+ │ │ │
163
+ │ │ ├─→ SOLID (5 rules)
164
+ │ │ │ - srp (单一职责)
165
+ │ │ │ - ocp (开闭原则)
166
+ │ │ │ - lsp (里氏替换)
167
+ │ │ │ - isp (接口隔离)
168
+ │ │ │ - dip (依赖倒置)
169
+ │ │ │
170
+ │ │ └─→ 输出 violations
171
+ │ │
172
+ │ └─→ Step 2: Delphi Code Walkthrough
173
+ │ │
174
+ │ ├─→ Expert A 评审 (含 principles_findings)
175
+ │ ├─→ Expert B 评审 (含 principles_findings)
176
+ │ └─→ 共识检查
177
+
178
+ └─→ 允许/阻塞推送
179
+ ```
180
+
181
+ **Principles Findings 输出格式**(在 Expert 评审报告中添加):
182
+
183
+ ```markdown
184
+ ## Principles Findings
185
+
186
+ ### Clean Code Violations
187
+
188
+ | Rule | Severity | File | Line | Description |
189
+ |------|----------|------|------|-------------|
190
+ | clean-code.long-function | warning | src/api.ts | 45 | Function "processData" exceeds 50 lines |
191
+ | clean-code.deep-nesting | warning | src/utils.ts | 12 | Nesting depth 5 > threshold 4 |
192
+
193
+ ### SOLID Violations
194
+
195
+ | Rule | Severity | File | Line | Description |
196
+ |------|----------|------|------|-------------|
197
+ | solid.srp | warning | src/user.ts | 1 | Class has 18 methods (>15 threshold) |
198
+ | solid.dip | warning | src/service.ts | 23 | Direct instantiation of UserRepository |
199
+
200
+ ### Summary
201
+ - Total violations: [N]
202
+ - Errors: [N]
203
+ - Warnings: [N]
204
+ - Infos: [N]
205
+ ```
206
+
207
+ **Principles 检查与 Delphi 评审的关系**:
208
+
209
+ | Principles 结果 | Delphi 评审行为 |
210
+ |-----------------|-----------------|
211
+ | 无 violations | Expert 正常评审,无额外关注点 |
212
+ | 有 info 级别 | Expert 评审时参考,不阻塞 |
213
+ | 有 warning 级别 | Expert 必须在评审中提及并给出意见 |
214
+ | 有 error 级别 | **自动阻塞推送**,无需 Delphi 评审 |
215
+
216
+ **阈值配置**:项目级配置文件 `.principlesrc` 可覆盖默认阈值:
217
+
218
+ ```json
219
+ {
220
+ "rules": {
221
+ "clean-code": {
222
+ "long-function": { "threshold": 50 },
223
+ "god-class": { "threshold": 15 },
224
+ "deep-nesting": { "threshold": 4 }
225
+ },
226
+ "solid": {
227
+ "srp": { "methodThreshold": 15 },
228
+ "isp": { "methodThreshold": 10 }
229
+ }
230
+ }
231
+ }
232
+ ```
233
+
234
+ ---
235
+
236
+ ## 共识标准
237
+
238
+ | 条件 | 结果 |
239
+ |------|------|
240
+ | 2/2 APPROVED + 无 Critical Issues | ✅ 允许推送 |
241
+ | 2/2 APPROVED + 有 Minor Issues | ✅ 允许推送(记录问题) |
242
+ | 1/2 APPROVED | ⚠️ 需要 Expert C 仲裁 |
243
+ | 0/2 APPROVED | ❌ 阻塞推送 |
244
+ | 有 Critical Issues | ❌ 阻塞推送 |
245
+ | 有 Major Issues 且未处理 | ❌ 阻塞推送 |
246
+
247
+ ---
248
+
249
+ ## 成本控制 (零降级原则)
250
+
251
+ | 指标 | 阈值 | 处理 |
252
+ |------|------|------|
253
+ | 单次走查成本 | ~$0.03 | 正常执行 |
254
+ | 最大评审文件数 | 20 个文件 | 超过 → **BLOCK** |
255
+ | 最大 diff 行数 | 500 行 | 超过 → **BLOCK** |
256
+
257
+ **超过阈值处理 (零降级)**:
258
+
259
+ ```
260
+ IF 超过阈值:
261
+ → BLOCK 推送
262
+ → 通知用户:变更过大,无法有效评审
263
+ → 用户选项:
264
+ A. 拆分变更(推荐)
265
+ B. 用户明确授权跳过走查(需书面确认风险)
266
+
267
+ ❌ 禁止自动跳过走查
268
+ ❌ 禁止自动分批并批准
269
+ ```
270
+
271
+ **设计原则**:
272
+ - 大变更跳过评审 = 质量风险泄露到生产环境
273
+ - 用户有权决定是否接受风险,AI 不能自动跳过
274
+
275
+ ---
276
+
277
+ ## Agent 可用性检查 (MANDATORY)
278
+
279
+ **启动前检查**:
280
+
281
+ ```
282
+ BEFORE code walkthrough:
283
+ ├─ 检查 Expert A 模型可用性
284
+ ├─ 检查 Expert B 模型可用性
285
+ ├─ 检查 Expert C 模型可用性(仲裁时需要)
286
+ └─ 检查 OpenCode CLI 可用性
287
+
288
+ IF 任何检查失败:
289
+ → BLOCK 推送
290
+ → 通知用户具体缺失项
291
+ → 提供修复指引
292
+ → ❌ 禁止跳过走查直接推送
293
+ ```
294
+
295
+ **模型不可用处理**:
296
+
297
+ | 情况 | 处理 |
298
+ |------|------|
299
+ | Expert A API 错误 | BLOCK + 提示用户检查 API key |
300
+ | Expert B API 错误 | BLOCK + 提示用户检查 API key |
301
+ | OpenCode CLI 缺失 | BLOCK + 提示用户安装 OpenCode |
302
+
303
+ ---
304
+
305
+ ## Expert 评审输出格式
306
+
307
+ ```markdown
308
+ ## Code Walkthrough - Expert [A/B]
309
+
310
+ ### 变更摘要
311
+ [变更的主要内容]
312
+
313
+ ### 发现问题
314
+
315
+ | ID | 严重程度 | 问题描述 | 代码位置 | 修复建议 |
316
+ |----|----------|----------|---------|---------|
317
+ | ... | ... | ... | ... | ... |
318
+
319
+ ### 裁决
320
+ [APPROVED / REQUEST_CHANGES]
321
+
322
+ ### 置信度
323
+ [X/10]
324
+ ```
325
+
326
+ ---
327
+
328
+ ## 共识报告格式
329
+
330
+ ```markdown
331
+ ## Code Walkthrough 共识报告
332
+
333
+ ### 变更信息
334
+ - 分支: [branch name]
335
+ - 提交数: [N]
336
+ - 文件数: [N]
337
+ - 新增行数: +[N]
338
+ - 删除行数: -[N]
339
+
340
+ ### 专家意见汇总
341
+ - Expert A: [APPROVED / REQUEST_CHANGES]
342
+ - Expert B: [APPROVED / REQUEST_CHANGES]
343
+
344
+ ### 共识结果
345
+ [CONSENSUS / DISAGREEMENT]
346
+
347
+ ### 最终裁决
348
+ [APPROVED / REQUEST_CHANGES / NEED_ARBITRATION]
349
+
350
+ ### 问题清单(如有)
351
+ [需要修复的问题]
352
+ ```
353
+
354
+ ---
355
+
356
+ ## 结果输出文件 (MANDATORY)
357
+
358
+ 完成评审后,Skill 必须写入结果文件以供 Hook 验证:
359
+
360
+ **输出文件位置**:`.code-walkthrough-result.json`
361
+
362
+ **输出文件格式**:
363
+
364
+ ```json
365
+ {
366
+ "commit": "abc123def456",
367
+ "branch": "feature/xp-rewrite",
368
+ "timestamp": "2026-04-14T10:30:00Z",
369
+ "expires": "2026-04-14T11:30:00Z",
370
+ "verdict": "APPROVED",
371
+ "confidence": 9,
372
+ "experts": [
373
+ { "id": "Expert A", "verdict": "APPROVED", "confidence": 9 },
374
+ { "id": "Expert B", "verdict": "APPROVED", "confidence": 8 }
375
+ ],
376
+ "issues": [],
377
+ "consensus_ratio": 1.0,
378
+ "files_reviewed": 5,
379
+ "lines_added": 120,
380
+ "lines_deleted": 45
381
+ }
382
+ ```
383
+
384
+ **字段说明**:
385
+
386
+ | 字段 | 类型 | 说明 |
387
+ |------|------|------|
388
+ | `commit` | string | 当前 HEAD commit hash (git rev-parse HEAD) |
389
+ | `branch` | string | 当前分支名 |
390
+ | `timestamp` | string | 评审完成时间 (ISO 8601 UTC) |
391
+ | `expires` | string | 过期时间 (timestamp + 1小时) |
392
+ | `verdict` | string | 最终裁决: APPROVED / REQUEST_CHANGES |
393
+ | `confidence` | number | 整体置信度 (1-10) |
394
+ | `experts` | array | 专家评审结果 |
395
+ | `issues` | array | 未解决的问题(如有) |
396
+ | `consensus_ratio` | number | 问题共识比例 (≥0.95 为共识) |
397
+
398
+ **有效期机制**:
399
+
400
+ - **有效期**: 1小时
401
+ - **过期后**: Hook 将提示重新执行 `/code-walkthrough`
402
+ - **commit 必须匹配**: 文件中的 commit 必须等于当前 HEAD
403
+
404
+ **Hook 验证逻辑**:
405
+
406
+ Hook 验证以下条件(全部满足才允许 push):
407
+
408
+ 1. 文件存在
409
+ 2. JSON 格式有效
410
+ 3. commit hash 匹配当前 HEAD
411
+ 4. verdict = APPROVED
412
+ 5. timestamp 未过期 (< 1小时)
413
+
414
+ ---
415
+
416
+ ## 与现有系统集成
417
+
418
+ | 集成点 | 说明 |
419
+ |--------|------|
420
+ | `pre-push` hook | 验证 `.code-walkthrough-result.json` 文件(不调用 Skill) |
421
+ | `gstack-ship` | 推送后进入发布流程 |
422
+ | `verification-loop` | 走查通过后运行验证 |
423
+
424
+ ---
425
+
426
+ ## Anti-Patterns
427
+
428
+ **只在 `--mode code-walkthrough` 时适用:**
429
+
430
+ | 错误 | 正确 |
431
+ |------|------|
432
+ | Expert 不可用时跳过走查 | BLOCK + 提示用户修复环境 |
433
+ | 超过阈值自动跳过走查 | BLOCK + 提示用户拆分变更 |
434
+ | 超过阈值自动分批评审 | BLOCK + 用户决定是否拆分或授权跳过 |
435
+ | OpenCode CLI 缺失时允许推送 | BLOCK + 提示用户安装 OpenCode |
436
+ | 模型 API 错误时降级单模型 | BLOCK + 提示用户检查 API 配置 |
437
+ | 未写入 `.code-walkthrough-result.json` 就声明完成 | MUST 写入结果文件后才能完成 |
438
+ | 结果文件 commit hash 不匹配 | MUST 重新执行走查 |
439
+
440
+ ---
441
+
442
+ ## Terminal State Checklist (code-walkthrough mode)
443
+
444
+ **Pre-requisites (MANDATORY - BLOCK if missing):**
445
+ - [ ] OpenCode CLI 已安装且可用
446
+ - [ ] Expert A 模型 API 可用
447
+ - [ ] Expert B 模型 API 可用
448
+ - [ ] 变更大小在阈值内(文件 ≤20,行数 ≤500)
449
+ - [ ] Expert A 完成匿名评审
450
+ - [ ] Expert B 完成匿名评审
451
+ - [ ] 共识检查完成
452
+
453
+ **CRITICAL - 共识验证 (code-walkthrough):**
454
+ - [ ] 至少 2/2 或 2/3 专家 APPROVED
455
+ - [ ] 无 Critical Issues 未解决
456
+ - [ ] 无 Major Issues 未处理(或有处理计划)
457
+
458
+ **Final Requirements (code-walkthrough):**
459
+ - [ ] 共识报告已生成
460
+ - [ ] 问题已记录(如有)
461
+ - [ ] `.code-walkthrough-result.json` 已写入项目根目录
462
+ - [ ] 结果文件 commit hash 匹配当前 HEAD
463
+ - [ ] 结果文件未过期 (< 1小时)
464
+
465
+ **IF 任何 Pre-requisite 缺失:**
466
+ - **CANNOT 允许推送**
467
+ - **MUST BLOCK 并通知用户**
468
+ - **用户必须修复环境问题后重试**
469
+
470
+ **IF 有 Critical Issues:**
471
+ - **CANNOT 允许推送**
472
+ - **MUST 修复后重新走查**
473
+
474
+ **IF 超过大小阈值:**
475
+ - **CANNOT 允许推送**
476
+ - **MUST BLOCK 并提示拆分变更**
477
+ - **用户可明确授权跳过(需确认风险)**
478
+
479
+ **⭐ APPROVED 后必做 (code-walkthrough mode):写入结果文件**
480
+
481
+ IF mode == `code-walkthrough` AND 最终裁决是 APPROVED,评审完成后必须:
482
+
483
+ 1. 写入 `.code-walkthrough-result.json` 到项目根目录
484
+ 2. 验证 JSON 格式有效
485
+ 3. 验证 commit hash 匹配当前 HEAD
486
+ 4. 验证 expires 字段 = timestamp + 1小时
@@ -0,0 +1,156 @@
1
+ ---
2
+ name: improve-codebase-architecture
3
+ description: Find deepening opportunities in a codebase, informed by domain language in CONTEXT.md and decisions in ADRs. Use when user wants to improve architecture, find refactoring opportunities, consolidate tightly-coupled modules, or make a codebase more AI-navigable. Run periodically (weekly or after surges of development).
4
+ ---
5
+
6
+ # Improve Codebase Architecture
7
+
8
+ 周期性架构健康检查:发现 **shallow module → deep module** 的深度化机会。目标是提升可测试性、AI 可导航性、模块边界清晰度。
9
+
10
+ 与 XP-Gate 质量门禁的分工:
11
+ | 机制 | 时机 | 作用 |
12
+ |------|------|------|
13
+ | **6 道门禁** | 每次 commit | 被动拦截明显问题(函数过长、重复代码等) |
14
+ | **improve-codebase-architecture** | 每周/开发潮后 | 主动深度化改进(seam 识别、模块合并、接口提炼) |
15
+
16
+ ---
17
+
18
+ ## 术语(与 XP-Gate Principles 一致)
19
+
20
+ | 术语 | 定义 |
21
+ |------|------|
22
+ | **Module** | 任何有接口和实现的东西(函数、类、包、slice) |
23
+ | **Interface** | 调用者使用前必须知道的一切:类型、不变量、错误模式、顺序、配置 |
24
+ | **Implementation** | 接口背后的代码 |
25
+ | **Depth** | 接口的杠杆率:大量行为隐藏在简单接口后。**Deep = 高杠杆**。**Shallow = 接口几乎与实现一样复杂** |
26
+ | **Seam** | 接口所在位置;可以在不修改实现的情况下改变行为的地方 |
27
+ | **Adapter** | 在 seam 处满足接口的具体实现 |
28
+ | **Locality** | 深度带来的可维护性收益:变更、bug、知识集中在一处 |
29
+
30
+ ---
31
+
32
+ ## 核心判断工具
33
+
34
+ ### Deletion Test
35
+ 想象删除某个模块:
36
+ - 如果复杂性消失 → 它是 pass-through,不值得保留
37
+ - 如果复杂性在 N 个调用方中重新出现 → **它真正提供了价值**
38
+ - **"Yes, concentrates" = 你想发现的信号**
39
+
40
+ ### The Interface Is the Test Surface
41
+ 接口就是测试的边界。如果测试需要深入实现细节,说明接口太浅。
42
+
43
+ ### One Adapter = Hypothetical Seam. Two Adapters = Real Seam.
44
+ 只有一个实现满足接口 → 可能过度抽象。两个以上 → 真正的可替换边界。
45
+
46
+ ---
47
+
48
+ ## 流程
49
+
50
+ ### 1. 探索
51
+
52
+ 先读项目的 `CONTEXT.md`(领域语言)和 `docs/adr/`(架构决策)。
53
+
54
+ 然后有机地走查代码库(不要遵循死板启发式),注意你在哪里感受到摩擦:
55
+
56
+ - 理解一个概念是否需要在多个小文件间跳来跳去?
57
+ - 模块是否 **shallow** — 接口几乎与实现一样复杂?
58
+ - 纯函数是否仅仅为了可测试性而被提取,但真正的 bug 隐藏在调用方式中?(缺乏 **locality**)
59
+ - 紧密耦合的模块是否在其 seams 之处泄漏?
60
+ - 哪些部分难以通过当前接口进行测试?
61
+
62
+ 对任何怀疑 shallow 的模块执行 **Deletion Test**:删除它会让复杂性集中还是分散?"是的,会集中"就是你要的信号。
63
+
64
+ ### 2. 呈现候选项
65
+
66
+ 以编号列表呈现深度化机会。每项包含:
67
+
68
+ - **Files** — 涉及哪些文件/模块
69
+ - **Problem** — 当前架构为何造成摩擦(使用 CONTEXT.md 中的领域术语)
70
+ - **Solution** — 自然语言描述会怎样改变
71
+ - **Benefits** — 用 locality 和 leverage 解释收益,以及测试会怎样改善
72
+
73
+ **使用 CONTEXT.md 领域术语。如果与 ADR 冲突**,仅在摩擦值得重新讨论 ADR 时才标注:
74
+ > *"Contradicts ADR-0007 — 但值得重新打开,因为…"*
75
+
76
+ 不要列出 ADR 禁止的每个理论重构。
77
+
78
+ **此时不要提出接口设计**。先问用户:"你想探索哪个候选项?"
79
+
80
+ ### 3. 用户选择候选项
81
+
82
+ 仅当用户明确选择某个候选项时,才进入步骤 4。
83
+
84
+ ### 4. Grilling 循环(设计树遍历)
85
+
86
+ 用户选中某个候选项后,进入 grilling 对话:
87
+ - 遍历约束、依赖、深度化模块的形状
88
+ - seam 背后放什么、什么不放在 seam 背后
89
+ - 哪些测试能在深度化后存活/新增
90
+
91
+ **对话中的副作用**(决策固化时立即执行):
92
+ - 命名不在 CONTEXT.md 中的新概念 → **新增到 CONTEXT.md**
93
+ - 模糊术语在对话中变清晰 → **更新 CONTEXT.md**
94
+ - 用户拒绝候选项且有有理由 → **提议记录为 ADR**(避免未来重复建议)
95
+ - 需要探索替代接口 → **按接口设计原则引导**
96
+
97
+ ### 5. 输出(可选)
98
+
99
+ 如果用户在 grilling 后决定执行重构:
100
+ - 生成重构计划(含文件列表、步骤顺序、风险点)
101
+ - 调用 test-driven-development skill 执行重构(保持行为不变)
102
+
103
+ ---
104
+
105
+ ## 与 XP-Gate 集成
106
+
107
+ ### 触发时机
108
+ ```
109
+ Phase 5 (FEEDBACK) 后推荐调用:
110
+ → learn + retro + **improve-codebase-architecture**
111
+ → 发现架构摩擦 → 记录到 retro → 下一 Sprint 纳入 backlog
112
+
113
+ 或作为独立周期性任务:
114
+ → /improve-codebase-architecture → 每周/开发潮后
115
+ ```
116
+
117
+ ### 与 ralph-loop 的关系
118
+ 架构改进本身可以作为一个独立的 REQ 通过 ralph-loop 执行:
119
+ - REQ: "深度化 Order 模块(从 N 个散文件合并为 deep module)"
120
+ - 通过 test-driven-development 保证行为不变
121
+
122
+ ### 与质量门禁的关系
123
+ 架构改进后,质量门禁的 violation 数量应减少:
124
+ - God class → 拆分为 deep modules → SOLID-001 (SRP) 告警消失
125
+ - Deep nesting → 封装为简单接口 → CC-002 告警消失
126
+ - Code duplication → 提取公共 deep module → Gate 2 (Dup Code) 改善
127
+
128
+ ---
129
+
130
+ ## Anti-Patterns
131
+
132
+ | ❌ 错误 | ✅ 正确 |
133
+ |---------|---------|
134
+ | 仅在文件层面重构(拆分大文件) | 在概念边界处重构(deep module 封装行为) |
135
+ | 为了测试而提取纯函数 | 为了 locality 和组织行为边界而重构 |
136
+ | 过度设计接口(只有一个 adapter) | 发现真实 seam(≥2 adapters 或需要可测试性)后再抽象 |
137
+ | 忽视现有 ADR 提出重构 | 尊重 ADR,仅在摩擦值得重新讨论时标注冲突 |
138
+ | 一次性重构整个模块 | 逐个候选项执行,使用 TDD 保证行为不变 |
139
+ | 与 ADR 冲突但不记录决策 | 记录为 ADR,避免未来重复建议 |
140
+
141
+ ---
142
+
143
+ ## 使用示例
144
+
145
+ ```
146
+ /improve-codebase-architecture
147
+
148
+ → Explore: 读取 CONTEXT.md, 走查代码库
149
+ → 发现 3 个浅模块候选项
150
+ → 呈现: #1 Order 模块过浅 / #2 Auth 适配器泄漏 / #3 支付领域缺乏 locality
151
+ → 用户选中 #1
152
+ → Grilling: 讨论 Order 的 seam 应该在哪
153
+ → 更新 CONTEXT.md: 新增 "Order Intake" 术语
154
+ → 提议 ADR: "Order 状态机封装" → 用户同意 → 创建 docs/adr/000X.md
155
+ → 输出: 重构计划 → TDD 执行
156
+ ```