@boyingliu01/xp-gate 0.18.5 → 0.19.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.
Files changed (254) hide show
  1. package/adapter-common.sh +27 -0
  2. package/adapters/gate-3.sh +0 -0
  3. package/adapters/gate-4.sh +0 -0
  4. package/adapters/gate-7.sh +0 -0
  5. package/adapters/gate-8.sh +0 -0
  6. package/adapters/gate-9.sh +0 -0
  7. package/adapters/powershell.sh +114 -35
  8. package/adapters/typescript.sh +8 -8
  9. package/build-integrity/__tests__/import-resolver.test.ts +22 -0
  10. package/build-integrity/__tests__/orchestrator.test.ts +1 -2
  11. package/build-integrity/gate-10.ts +7 -0
  12. package/gate-12-file-hygiene.sh +230 -0
  13. package/hooks/adapter-common.sh +27 -0
  14. package/hooks/gate-10.sh +105 -0
  15. package/hooks/gate-12-file-hygiene.sh +0 -0
  16. package/hooks/lib/validate-code-walkthrough.cjs +125 -0
  17. package/hooks/pre-commit +130 -33
  18. package/hooks/pre-push +15 -91
  19. package/lib/__tests__/check-version.test.js +67 -46
  20. package/lib/__tests__/doctor.test.js +7 -6
  21. package/lib/__tests__/gate-runner.test.js +267 -0
  22. package/lib/__tests__/init.test.js +32 -0
  23. package/lib/__tests__/npm-package.test.js +13 -0
  24. package/lib/__tests__/phase-transition.test.js +604 -12
  25. package/lib/__tests__/sprint-discovery.test.ts +0 -1
  26. package/lib/__tests__/sprint-status-rework.test.js +100 -1
  27. package/lib/__tests__/update-hooks.test.js +143 -10
  28. package/lib/__tests__/upgrade-exec.test.js +73 -45
  29. package/lib/__tests__/upgrade-skill-sync.test.js +1 -1
  30. package/lib/__tests__/upgrade.test.js +12 -11
  31. package/lib/doctor.js +2 -1
  32. package/lib/gate-runner.js +68 -23
  33. package/lib/init.js +34 -5
  34. package/lib/install-skill.js +1 -0
  35. package/lib/mattpocock-license-verdict.json +1 -1
  36. package/lib/phase-transition.js +203 -23
  37. package/lib/shared-paths.js +2 -0
  38. package/lib/sprint-status.js +15 -4
  39. package/lib/test-alignment.ts +3 -13
  40. package/lib/update-hooks.js +129 -15
  41. package/mock-policy/AGENTS.md +4 -4
  42. package/mock-policy/__tests__/gate-m3.test.ts +0 -5
  43. package/mock-policy/__tests__/scope-scanner.test.ts +8 -2
  44. package/mutation/AGENTS.md +3 -3
  45. package/mutation/__tests__/mutmut-runner.test.ts +443 -2
  46. package/mutation/__tests__/update-baseline.test.ts +0 -2
  47. package/mutation/runners/mutmut-runner.ts +67 -17
  48. package/package.json +9 -3
  49. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  50. package/plugins/claude-code/skills/clipboard-vision/SKILL.md +47 -0
  51. package/plugins/claude-code/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +65 -0
  52. package/plugins/claude-code/skills/clipboard-vision/__tests__/clipboard-vision-security.test.cjs +185 -0
  53. package/plugins/claude-code/skills/clipboard-vision/__tests__/clipboard-vision.Tests.ps1 +138 -0
  54. package/plugins/claude-code/skills/clipboard-vision/__tests__/clipboard-vision.test.cjs +273 -0
  55. package/plugins/claude-code/skills/clipboard-vision/describe-clipboard.ps1 +115 -0
  56. package/plugins/claude-code/skills/clipboard-vision/describe-clipboard.sh +161 -0
  57. package/plugins/claude-code/skills/clipboard-vision/scripts/clipboard-vision.ps1 +86 -0
  58. package/plugins/claude-code/skills/clipboard-vision/scripts/clipboard-vision.sh +137 -0
  59. package/plugins/claude-code/skills/delphi-review/.delphi-config.json.example +24 -27
  60. package/plugins/claude-code/skills/delphi-review/AGENTS.md +12 -11
  61. package/plugins/claude-code/skills/delphi-review/INSTALL.md +15 -17
  62. package/plugins/claude-code/skills/delphi-review/SKILL.md +30 -29
  63. package/plugins/claude-code/skills/delphi-review/opencode.json.delphi.example +6 -10
  64. package/plugins/claude-code/skills/delphi-review/references/code-walkthrough.md +33 -49
  65. package/plugins/claude-code/skills/delphi-review/references/requirements.md +66 -54
  66. package/plugins/claude-code/skills/delphi-review/references/round-templates.md +7 -7
  67. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +4 -4
  68. package/plugins/claude-code/skills/sprint-flow/SKILL.md +4 -4
  69. package/plugins/claude-code/skills/sprint-flow/references/components/skill-invocations.md +2 -2
  70. package/plugins/claude-code/skills/sprint-flow/references/force-levels.md +37 -35
  71. package/plugins/claude-code/skills/sprint-flow/references/orchestration-rules.md +1 -1
  72. package/plugins/claude-code/skills/sprint-flow/references/phase-1-prep.md +1 -1
  73. package/plugins/claude-code/skills/sprint-flow/references/phase-2-design.md +24 -14
  74. package/plugins/claude-code/skills/sprint-flow/references/phase-4-verify.md +6 -6
  75. package/plugins/claude-code/skills/sprint-flow/references/phase-overview.md +2 -2
  76. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +3 -3
  77. package/plugins/dsh/README.md +25 -0
  78. package/plugins/dsh/cordis.patch.yml +7 -0
  79. package/plugins/dsh/package.json +70 -0
  80. package/plugins/dsh/scripts/prepack.cjs +82 -0
  81. package/plugins/dsh/skills/admin-template-guidelines/SKILL.md +113 -0
  82. package/plugins/dsh/skills/admin-template-guidelines/references/rule-1.md +91 -0
  83. package/plugins/dsh/skills/admin-template-guidelines/references/rule-2.md +155 -0
  84. package/plugins/dsh/skills/admin-template-guidelines/references/rule-3.md +70 -0
  85. package/plugins/dsh/skills/admin-template-guidelines/references/rule-4.md +154 -0
  86. package/plugins/dsh/skills/admin-template-guidelines/references/rule-5.md +126 -0
  87. package/plugins/dsh/skills/admin-template-guidelines/references/rule-6.md +180 -0
  88. package/plugins/dsh/skills/batch-grill-me/SKILL.md +15 -0
  89. package/plugins/dsh/skills/clipboard-vision/SKILL.md +47 -0
  90. package/plugins/dsh/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +65 -0
  91. package/plugins/dsh/skills/clipboard-vision/__tests__/clipboard-vision-security.test.cjs +185 -0
  92. package/plugins/dsh/skills/clipboard-vision/__tests__/clipboard-vision.Tests.ps1 +138 -0
  93. package/plugins/dsh/skills/clipboard-vision/__tests__/clipboard-vision.test.cjs +273 -0
  94. package/plugins/dsh/skills/clipboard-vision/describe-clipboard.ps1 +115 -0
  95. package/plugins/dsh/skills/clipboard-vision/describe-clipboard.sh +161 -0
  96. package/plugins/dsh/skills/clipboard-vision/scripts/clipboard-vision.ps1 +86 -0
  97. package/plugins/dsh/skills/clipboard-vision/scripts/clipboard-vision.sh +137 -0
  98. package/plugins/dsh/skills/delphi-review/.delphi-config.json.example +70 -0
  99. package/plugins/dsh/skills/delphi-review/AGENTS.md +67 -0
  100. package/plugins/dsh/skills/delphi-review/INSTALL.md +150 -0
  101. package/plugins/dsh/skills/delphi-review/SKILL.md +559 -0
  102. package/plugins/dsh/skills/delphi-review/hooks.md +19 -0
  103. package/plugins/dsh/skills/delphi-review/opencode.json.delphi.example +52 -0
  104. package/plugins/dsh/skills/delphi-review/references/code-walkthrough.md +470 -0
  105. package/plugins/dsh/skills/delphi-review/references/orchestrator-dispatch.md +64 -0
  106. package/plugins/dsh/skills/delphi-review/references/requirements.md +402 -0
  107. package/plugins/dsh/skills/delphi-review/references/round-templates.md +134 -0
  108. package/plugins/dsh/skills/delphi-review/scripts/verify-consensus.sh +43 -0
  109. package/plugins/dsh/skills/delphi-review/tools.md +29 -0
  110. package/plugins/dsh/skills/domain-modeling/ADR-FORMAT.md +64 -0
  111. package/plugins/dsh/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
  112. package/plugins/dsh/skills/domain-modeling/SKILL.md +74 -0
  113. package/plugins/dsh/skills/grill-with-docs/SKILL.md +7 -0
  114. package/plugins/dsh/skills/grilling/SKILL.md +12 -0
  115. package/plugins/dsh/skills/improve-codebase-architecture/SKILL.md +156 -0
  116. package/plugins/dsh/skills/ralph-loop/SKILL.md +198 -0
  117. package/plugins/dsh/skills/ralph-loop/references/components.md +113 -0
  118. package/plugins/dsh/skills/ralph-loop/references/phase-2-build-ralph.md +89 -0
  119. package/plugins/dsh/skills/ralph-loop/references/workflow-details.md +99 -0
  120. package/plugins/dsh/skills/ralph-loop/templates/progress-log.md +36 -0
  121. package/plugins/dsh/skills/sprint-flow/AGENTS.md +103 -0
  122. package/plugins/dsh/skills/sprint-flow/SKILL.md +411 -0
  123. package/plugins/dsh/skills/sprint-flow/__tests__/sprint-flow.test.cjs +457 -0
  124. package/plugins/dsh/skills/sprint-flow/hooks.md +18 -0
  125. package/plugins/dsh/skills/sprint-flow/references/components/memory.md +87 -0
  126. package/plugins/dsh/skills/sprint-flow/references/components/middleware.md +75 -0
  127. package/plugins/dsh/skills/sprint-flow/references/components/skill-invocations.md +105 -0
  128. package/plugins/dsh/skills/sprint-flow/references/components/system-prompt.md +27 -0
  129. package/plugins/dsh/skills/sprint-flow/references/components/tool-descriptions.md +95 -0
  130. package/plugins/dsh/skills/sprint-flow/references/force-levels.md +204 -0
  131. package/plugins/dsh/skills/sprint-flow/references/orchestration-rules.md +236 -0
  132. package/plugins/dsh/skills/sprint-flow/references/phase-1-prep.md +294 -0
  133. package/plugins/dsh/skills/sprint-flow/references/phase-2-design.md +273 -0
  134. package/plugins/dsh/skills/sprint-flow/references/phase-3-build.md +348 -0
  135. package/plugins/dsh/skills/sprint-flow/references/phase-4-verify.md +225 -0
  136. package/plugins/dsh/skills/sprint-flow/references/phase-5-ship.md +222 -0
  137. package/plugins/dsh/skills/sprint-flow/references/phase-6-close.md +266 -0
  138. package/plugins/dsh/skills/sprint-flow/references/phase-overview.md +486 -0
  139. package/plugins/dsh/skills/sprint-flow/scripts/verify-sprint-state.sh +38 -0
  140. package/plugins/dsh/skills/sprint-flow/templates/auto-estimate-learning-log.md +136 -0
  141. package/plugins/dsh/skills/sprint-flow/templates/auto-estimate-output-template.md +110 -0
  142. package/plugins/dsh/skills/sprint-flow/templates/emergent-issues-template.md +120 -0
  143. package/plugins/dsh/skills/sprint-flow/templates/pain-document-template.md +115 -0
  144. package/plugins/dsh/skills/sprint-flow/templates/sprint-progress-template.md +140 -0
  145. package/plugins/dsh/skills/sprint-flow/templates/sprint-summary-template.md +121 -0
  146. package/plugins/dsh/skills/sprint-flow/tools.md +29 -0
  147. package/plugins/dsh/skills/test-driven-development/SKILL.md +371 -0
  148. package/plugins/dsh/skills/test-driven-development/testing-anti-patterns.md +299 -0
  149. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +56 -0
  150. package/plugins/dsh/skills/test-specification-alignment/SKILL.md +205 -0
  151. package/plugins/dsh/skills/test-specification-alignment/references/alignment-verification-algorithm.md +493 -0
  152. package/plugins/dsh/skills/test-specification-alignment/references/phase2-constraint-enforcement.md +431 -0
  153. package/plugins/dsh/skills/test-specification-alignment/references/specification-format.md +348 -0
  154. package/plugins/dsh/skills/to-issues/SKILL.md +277 -0
  155. package/plugins/dsh/src/command.test.ts +102 -0
  156. package/plugins/dsh/src/command.ts +75 -0
  157. package/plugins/dsh/src/contract.test.ts +62 -0
  158. package/plugins/dsh/src/gate-runner.test.ts +100 -0
  159. package/plugins/dsh/src/gate-runner.ts +58 -0
  160. package/plugins/dsh/src/index.test.ts +97 -0
  161. package/plugins/dsh/src/index.ts +94 -0
  162. package/plugins/dsh/src/skills.test.ts +58 -0
  163. package/plugins/dsh/tsconfig.build.json +13 -0
  164. package/plugins/dsh/tsconfig.json +19 -0
  165. package/plugins/dsh/vitest.config.ts +8 -0
  166. package/plugins/opencode/package.json +1 -1
  167. package/plugins/opencode/scripts/prepack.cjs +1 -0
  168. package/plugins/opencode/skills/clipboard-vision/SKILL.md +47 -0
  169. package/plugins/opencode/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +65 -0
  170. package/plugins/opencode/skills/clipboard-vision/__tests__/clipboard-vision-security.test.cjs +185 -0
  171. package/plugins/opencode/skills/clipboard-vision/__tests__/clipboard-vision.Tests.ps1 +138 -0
  172. package/plugins/opencode/skills/clipboard-vision/__tests__/clipboard-vision.test.cjs +273 -0
  173. package/plugins/opencode/skills/clipboard-vision/describe-clipboard.ps1 +115 -0
  174. package/plugins/opencode/skills/clipboard-vision/describe-clipboard.sh +161 -0
  175. package/plugins/opencode/skills/clipboard-vision/scripts/clipboard-vision.ps1 +86 -0
  176. package/plugins/opencode/skills/clipboard-vision/scripts/clipboard-vision.sh +137 -0
  177. package/plugins/opencode/skills/delphi-review/.delphi-config.json.example +24 -27
  178. package/plugins/opencode/skills/delphi-review/AGENTS.md +12 -11
  179. package/plugins/opencode/skills/delphi-review/INSTALL.md +15 -17
  180. package/plugins/opencode/skills/delphi-review/SKILL.md +30 -29
  181. package/plugins/opencode/skills/delphi-review/opencode.json.delphi.example +6 -10
  182. package/plugins/opencode/skills/delphi-review/references/code-walkthrough.md +33 -49
  183. package/plugins/opencode/skills/delphi-review/references/requirements.md +66 -54
  184. package/plugins/opencode/skills/delphi-review/references/round-templates.md +7 -7
  185. package/plugins/opencode/skills/sprint-flow/AGENTS.md +4 -4
  186. package/plugins/opencode/skills/sprint-flow/SKILL.md +4 -4
  187. package/plugins/opencode/skills/sprint-flow/references/components/skill-invocations.md +2 -2
  188. package/plugins/opencode/skills/sprint-flow/references/force-levels.md +37 -35
  189. package/plugins/opencode/skills/sprint-flow/references/orchestration-rules.md +1 -1
  190. package/plugins/opencode/skills/sprint-flow/references/phase-1-prep.md +1 -1
  191. package/plugins/opencode/skills/sprint-flow/references/phase-2-design.md +24 -14
  192. package/plugins/opencode/skills/sprint-flow/references/phase-4-verify.md +6 -6
  193. package/plugins/opencode/skills/sprint-flow/references/phase-overview.md +2 -2
  194. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +3 -3
  195. package/plugins/qoder/plugin.json +1 -1
  196. package/plugins/qoder/skills/clipboard-vision/SKILL.md +47 -0
  197. package/plugins/qoder/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +65 -0
  198. package/plugins/qoder/skills/clipboard-vision/__tests__/clipboard-vision-security.test.cjs +185 -0
  199. package/plugins/qoder/skills/clipboard-vision/__tests__/clipboard-vision.Tests.ps1 +138 -0
  200. package/plugins/qoder/skills/clipboard-vision/__tests__/clipboard-vision.test.cjs +273 -0
  201. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/SKILL.md +47 -0
  202. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +65 -0
  203. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/__tests__/clipboard-vision-security.test.cjs +185 -0
  204. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/__tests__/clipboard-vision.Tests.ps1 +138 -0
  205. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/__tests__/clipboard-vision.test.cjs +273 -0
  206. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/scripts/clipboard-vision.ps1 +86 -0
  207. package/plugins/qoder/skills/clipboard-vision/clipboard-vision/scripts/clipboard-vision.sh +137 -0
  208. package/plugins/qoder/skills/clipboard-vision/scripts/clipboard-vision.ps1 +86 -0
  209. package/plugins/qoder/skills/clipboard-vision/scripts/clipboard-vision.sh +137 -0
  210. package/plugins/qoder/skills/delphi-review/.delphi-config.json.example +3 -11
  211. package/plugins/qoder/skills/delphi-review/AGENTS.md +14 -16
  212. package/plugins/qoder/skills/delphi-review/INSTALL.md +12 -12
  213. package/plugins/qoder/skills/delphi-review/SKILL.md +58 -25
  214. package/plugins/qoder/skills/delphi-review/opencode.json.delphi.example +1 -1
  215. package/plugins/qoder/skills/delphi-review/references/code-walkthrough.md +33 -49
  216. package/plugins/qoder/skills/sprint-flow/AGENTS.md +4 -4
  217. package/plugins/qoder/skills/sprint-flow/SKILL.md +2 -2
  218. package/plugins/qoder/skills/sprint-flow/references/force-levels.md +38 -35
  219. package/plugins/qoder/skills/sprint-flow/references/phase-1-prep.md +1 -1
  220. package/plugins/qoder/skills/sprint-flow/references/phase-2-design.md +48 -6
  221. package/plugins/qoder/skills/sprint-flow/references/phase-4-verify.md +5 -6
  222. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +3 -3
  223. package/principles/AGENTS.md +3 -3
  224. package/scripts/__tests__/sync-package-content.test.js +30 -0
  225. package/scripts/delphi-external-review.cjs +194 -63
  226. package/scripts/sync-package-content.js +9 -2
  227. package/skills/clipboard-vision/SKILL.md +47 -0
  228. package/skills/clipboard-vision/__tests__/clipboard-vision-distribution.test.cjs +65 -0
  229. package/skills/clipboard-vision/__tests__/clipboard-vision-security.test.cjs +185 -0
  230. package/skills/clipboard-vision/__tests__/clipboard-vision.Tests.ps1 +138 -0
  231. package/skills/clipboard-vision/__tests__/clipboard-vision.test.cjs +273 -0
  232. package/skills/clipboard-vision/describe-clipboard.ps1 +115 -0
  233. package/skills/clipboard-vision/describe-clipboard.sh +161 -0
  234. package/skills/clipboard-vision/scripts/clipboard-vision.ps1 +86 -0
  235. package/skills/clipboard-vision/scripts/clipboard-vision.sh +137 -0
  236. package/skills/delphi-review/.delphi-config.json.example +24 -27
  237. package/skills/delphi-review/AGENTS.md +12 -11
  238. package/skills/delphi-review/INSTALL.md +15 -17
  239. package/skills/delphi-review/SKILL.md +30 -29
  240. package/skills/delphi-review/opencode.json.delphi.example +6 -10
  241. package/skills/delphi-review/references/code-walkthrough.md +33 -49
  242. package/skills/delphi-review/references/requirements.md +66 -54
  243. package/skills/delphi-review/references/round-templates.md +7 -7
  244. package/skills/sprint-flow/AGENTS.md +4 -4
  245. package/skills/sprint-flow/SKILL.md +4 -4
  246. package/skills/sprint-flow/references/components/skill-invocations.md +2 -2
  247. package/skills/sprint-flow/references/force-levels.md +37 -35
  248. package/skills/sprint-flow/references/orchestration-rules.md +1 -1
  249. package/skills/sprint-flow/references/phase-1-prep.md +1 -1
  250. package/skills/sprint-flow/references/phase-2-design.md +24 -14
  251. package/skills/sprint-flow/references/phase-4-verify.md +6 -6
  252. package/skills/sprint-flow/references/phase-overview.md +2 -2
  253. package/skills/test-specification-alignment/AGENTS.md +3 -3
  254. package/sprint-gate.sh +291 -0
@@ -0,0 +1,431 @@
1
+ # Phase 2 约束执行机制
2
+
3
+ ## 核心原则
4
+
5
+ **Phase 2 使用 freeze skill 主动锁定测试目录,而非事后检测。**
6
+
7
+ ---
8
+
9
+ ## freeze skill 集成
10
+
11
+ ### Pre-Phase 2: 锁定测试目录
12
+
13
+ ```yaml
14
+ step: "pre_phase2_freeze"
15
+ action: "INVOKE freeze skill"
16
+ timing: "Phase 1 完成,Alignment Score >= 80% 之后"
17
+
18
+ parameters:
19
+ freeze_boundary:
20
+ # 测试目录
21
+ - "tests/"
22
+ - "test/"
23
+ - "__tests__/"
24
+ - "spec/"
25
+ - "cypress/"
26
+ - "playwright/"
27
+
28
+ # 测试文件模式
29
+ - "*.test.ts"
30
+ - "*.test.tsx"
31
+ - "*.test.js"
32
+ - "*.test.jsx"
33
+ - "*.spec.ts"
34
+ - "*.spec.tsx"
35
+ - "*.spec.js"
36
+ - "*.spec.jsx"
37
+ - "*_test.py"
38
+ - "*_test.go"
39
+ - "test_*.py"
40
+ - "*_test.rb"
41
+
42
+ # Mock/fixture 文件 (可选)
43
+ - "**/__mocks__/**"
44
+ - "**/__fixtures__/**"
45
+ - "**/fixtures/**"
46
+
47
+ mode: "strict"
48
+ error_message: |
49
+ ❌ TEST FILE MODIFICATION BLOCKED
50
+
51
+ Phase 2 禁止修改测试文件。
52
+ 测试目录已被 freeze skill 锁定。
53
+
54
+ 允许的操作:
55
+ - 修改业务代码
56
+ - 修改配置文件
57
+
58
+ 如果需要修改测试,请:
59
+ 1. 先完成 Phase 2
60
+ 2. 或者请求用户授权退出 Phase 2
61
+ ```
62
+
63
+ ### OpenCode 调用方式
64
+
65
+ ```typescript
66
+ // 在 OpenCode 环境中调用 freeze skill
67
+ async function prePhase2Freeze(): Promise<void> {
68
+ const freezeBoundary = [
69
+ "tests/",
70
+ "test/",
71
+ "__tests__/",
72
+ "*.test.ts",
73
+ "*.test.js",
74
+ "*.spec.ts",
75
+ "*.spec.js",
76
+ "*_test.py",
77
+ "*_test.go"
78
+ ].join(",");
79
+
80
+ // 调用 freeze skill
81
+ await skill({
82
+ name: "freeze",
83
+ user_message: freezeBoundary
84
+ });
85
+
86
+ // 记录状态
87
+ state = "PRE_PHASE2_FREEZE";
88
+ log("✅ 测试目录已冻结,Phase 2 约束生效");
89
+ }
90
+ ```
91
+
92
+ ---
93
+
94
+ ## Phase 2 执行期间的约束
95
+
96
+ ### 约束规则
97
+
98
+ ```yaml
99
+ phase2_constraints:
100
+ # 禁止的操作
101
+ forbidden:
102
+ - operation: "EDIT"
103
+ target_pattern: "test/**, *.test.*, *.spec.*, *_test.*"
104
+ response: "BLOCK"
105
+ error_code: "TEST_EDIT_BLOCKED"
106
+
107
+ - operation: "WRITE"
108
+ target_pattern: "test/**, *.test.*, *.spec.*, *_test.*"
109
+ response: "BLOCK"
110
+ error_code: "TEST_WRITE_BLOCKED"
111
+
112
+ - operation: "DELETE"
113
+ target_pattern: "test/**, *.test.*, *.spec.*, *_test.*"
114
+ response: "BLOCK"
115
+ error_code: "TEST_DELETE_BLOCKED"
116
+
117
+ - operation: "EDIT"
118
+ detection_pattern: "test\\.skip|\\.skip\\(|xit\\(|@skip"
119
+ response: "BLOCK"
120
+ error_code: "TEST_SKIP_BLOCKED"
121
+
122
+ # 允许的操作
123
+ allowed:
124
+ - operation: "EDIT"
125
+ target_pattern: "src/**, app/**, lib/**"
126
+ response: "ALLOW"
127
+
128
+ - operation: "WRITE"
129
+ target_pattern: "src/**, app/**, lib/**"
130
+ response: "ALLOW"
131
+
132
+ - operation: "EDIT"
133
+ target_pattern: "*.config.*, *.json, *.yaml"
134
+ response: "ALLOW"
135
+ ```
136
+
137
+ ### 违规检测
138
+
139
+ ```typescript
140
+ interface ViolationAttempt {
141
+ timestamp: Date;
142
+ operation: 'EDIT' | 'WRITE' | 'DELETE';
143
+ target: string;
144
+ blocked: boolean;
145
+ agentId: string;
146
+ }
147
+
148
+ const violationLog: ViolationAttempt[] = [];
149
+
150
+ // freeze skill 会自动拦截,但我们也记录日志
151
+ function logViolation(attempt: ViolationAttempt): void {
152
+ violationLog.push(attempt);
153
+
154
+ // 如果有多次违规尝试,升级警告
155
+ const recentViolations = violationLog.filter(
156
+ v => Date.now() - v.timestamp.getTime() < 60000
157
+ );
158
+
159
+ if (recentViolations.length >= 3) {
160
+ escalateToHuman({
161
+ severity: "CRITICAL",
162
+ message: "Agent 多次尝试修改测试文件",
163
+ violations: recentViolations
164
+ });
165
+ }
166
+ }
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Post-Phase 2: 解锁测试目录
172
+
173
+ ```yaml
174
+ step: "post_phase2_unfreeze"
175
+ action: "INVOKE unfreeze skill"
176
+ timing: "Phase 2 完成,所有测试通过之后"
177
+ ```
178
+
179
+ ```typescript
180
+ async function postPhase2Unfreeze(): Promise<void> {
181
+ // 调用 unfreeze skill
182
+ await skill({
183
+ name: "unfreeze",
184
+ user_message: ""
185
+ });
186
+
187
+ state = "POST_PHASE2_UNFREEZE";
188
+ log("✅ 测试目录已解冻,恢复正常编辑");
189
+ }
190
+ ```
191
+
192
+ ---
193
+
194
+ ## 异常情况处理
195
+
196
+ ### 测试失败需要修改测试数据
197
+
198
+ ```yaml
199
+ scenario: "test_data_error"
200
+ condition: "测试失败原因是测试数据问题,而非业务代码"
201
+
202
+ flow:
203
+ - step: 1
204
+ action: "分析失败原因"
205
+ output: "TEST_DATA_ERROR"
206
+
207
+ - step: 2
208
+ action: "BLOCK Phase 2"
209
+ message: "测试数据问题需要回到 Phase 1 修复"
210
+
211
+ - step: 3
212
+ action: "调用 unfreeze skill"
213
+ reason: "需要修改测试数据"
214
+
215
+ - step: 4
216
+ action: "状态回退到 PHASE1_FIXING_TESTS"
217
+
218
+ - step: 5
219
+ action: "修复测试数据"
220
+
221
+ - step: 6
222
+ action: "重新执行 Phase 1 → Phase 2 流程"
223
+ ```
224
+
225
+ ### Specification 问题需要用户确认
226
+
227
+ ```yaml
228
+ scenario: "specification_error"
229
+ condition: "测试失败揭示 Specification 问题"
230
+
231
+ flow:
232
+ - step: 1
233
+ action: "分析失败原因"
234
+ output: "SPECIFICATION_ERROR"
235
+
236
+ - step: 2
237
+ action: "生成 Specification Issue Report"
238
+ content:
239
+ - 失败的测试名称
240
+ - 测试期望行为
241
+ - 业务代码实际行为
242
+ - 可能的 Specification 问题
243
+
244
+ - step: 3
245
+ action: "BLOCK Phase 2"
246
+ state: "BLOCKED_SPECIFICATION_ISSUE"
247
+
248
+ - step: 4
249
+ action: "通知用户并提供选项"
250
+ options:
251
+ A: "修正 Specification → 重新 Phase 1"
252
+ B: "确认 Specification 正确 → 修改业务代码"
253
+ C: "补充 Specification 澄清"
254
+
255
+ - step: 5
256
+ action: "等待用户决策"
257
+ # 用户选择 A 或 C: unfreeze → Phase 1
258
+ # 用户选择 B: 继续 Phase 2 修改业务代码
259
+ ```
260
+
261
+ ### 最大重试次数超出
262
+
263
+ ```yaml
264
+ scenario: "max_retries_exceeded"
265
+ condition: "Phase 2 重试次数超过 5 次"
266
+
267
+ flow:
268
+ - step: 1
269
+ action: "BLOCK"
270
+ state: "BLOCKED_MAX_RETRIES_EXCEEDED"
271
+
272
+ - step: 2
273
+ action: "调用 unfreeze skill"
274
+
275
+ - step: 3
276
+ action: "通知用户"
277
+ message: |
278
+ ⚠️ Phase 2 已重试 5 次仍未通过所有测试
279
+
280
+ 最后失败的测试: [test_names]
281
+
282
+ 可能的原因:
283
+ 1. 业务代码存在难以修复的问题
284
+ 2. 测试环境配置问题
285
+ 3. Specification 与实际需求不符
286
+
287
+ 用户选项:
288
+ A. 手动排查问题
289
+ B. 暂时跳过失败的测试 (需要确认风险)
290
+ C. 重新设计实现方案
291
+ ```
292
+
293
+ ---
294
+
295
+ ## 状态转换图
296
+
297
+ ```
298
+ ┌─────────────────────────────────────────────────────────────┐
299
+ │ Phase 2 Constraint State Machine │
300
+ ├─────────────────────────────────────────────────────────────┤
301
+ │ │
302
+ │ PHASE1_COMPLETE │
303
+ │ ├─ Alignment Score >= 80% │
304
+ │ └────────────────────────────────────────────────┘ │
305
+ │ │ │
306
+ │ ▼ │
307
+ │ PRE_PHASE2_FREEZE │
308
+ │ ├─ 调用 freeze skill │
309
+ │ ├─ 记录冻结边界 │
310
+ │ └────────────────────────────────────────────────┘ │
311
+ │ │ │
312
+ │ ▼ │
313
+ │ PHASE2_EXECUTING_TESTS │
314
+ │ ├─ 运行测试 │
315
+ │ ├─ IF 违规 → freeze 拦截 → 记录日志 │
316
+ │ └────────────────────────────────────────────────┘ │
317
+ │ │ │
318
+ │ ┌───────────┴───────────┐ │
319
+ │ │ │ │
320
+ │ 全部通过 测试失败 │
321
+ │ │ │ │
322
+ │ ▼ ▼ │
323
+ │ PHASE2_COMPLETE PHASE2_FAILURE_ANALYSIS │
324
+ │ ├─ 调用 unfreeze ├─ 分析失败原因 │
325
+ │ └────────────────────────────────────────────────┘ │
326
+ │ │ │
327
+ │ ┌───────────┼───────────┐ │
328
+ │ │ │ │ │
329
+ │ 业务代码 测试数据 Specification │
330
+ │ 错误 错误 问题 │
331
+ │ │ │ │ │
332
+ │ ▼ ▼ ▼ │
333
+ │ 修复代码 ROLLBACK BLOCKED │
334
+ │ 重试测试 到 Phase1 SPEC_ISSUE │
335
+ │ │
336
+ └─────────────────────────────────────────────────────────────┘
337
+ ```
338
+
339
+ ---
340
+
341
+ ## 违规日志格式
342
+
343
+ ```yaml
344
+ violation_log:
345
+ session_id: "session-xxx"
346
+ phase: "PHASE2_EXECUTING_TESTS"
347
+
348
+ violations:
349
+ - timestamp: "2026-04-06T10:30:00Z"
350
+ operation: "EDIT"
351
+ target: "tests/auth/login.test.ts"
352
+ blocked: true
353
+ agent_action: "尝试修改测试断言"
354
+ response: "BLOCKED: 测试文件已冻结"
355
+
356
+ - timestamp: "2026-04-06T10:31:00Z"
357
+ operation: "WRITE"
358
+ target: "tests/auth/new-test.test.ts"
359
+ blocked: true
360
+ agent_action: "尝试创建新测试文件"
361
+ response: "BLOCKED: 测试目录已冻结"
362
+
363
+ summary:
364
+ total_attempts: 2
365
+ all_blocked: true
366
+ escalated_to_human: false
367
+ ```
368
+
369
+ ---
370
+
371
+ ## 与 freeze skill 的契约
372
+
373
+ ### freeze skill 职责
374
+
375
+ 1. 接收冻结边界参数
376
+ 2. 拦截所有匹配边界的 Edit/Write/Delete 操作
377
+ 3. 返回明确的错误信息
378
+ 4. 记录所有拦截尝试
379
+
380
+ ### test-specification-alignment skill 职责
381
+
382
+ 1. 在正确时机调用 freeze/unfreeze
383
+ 2. 提供完整的冻结边界列表
384
+ 3. 处理 freeze 返回的错误
385
+ 4. 记录违规日志
386
+ 5. 在异常情况下正确解除冻结
387
+
388
+ ---
389
+
390
+ ## 测试验证
391
+
392
+ ```typescript
393
+ // 验证 freeze 集成是否正确
394
+ async function testFreezeIntegration(): Promise<void> {
395
+ // 1. 调用 freeze
396
+ await prePhase2Freeze();
397
+
398
+ // 2. 尝试编辑测试文件 (应该被拦截)
399
+ try {
400
+ await edit({
401
+ filePath: "tests/auth/login.test.ts",
402
+ oldString: "test content",
403
+ newString: "modified content"
404
+ });
405
+ throw new Error("freeze 未正确拦截编辑操作");
406
+ } catch (error) {
407
+ if (!error.message.includes("BLOCKED")) {
408
+ throw new Error("freeze 返回的错误信息不正确");
409
+ }
410
+ }
411
+
412
+ // 3. 尝试编辑业务代码 (应该成功)
413
+ await edit({
414
+ filePath: "src/auth/service.ts",
415
+ oldString: "old code",
416
+ newString: "new code"
417
+ });
418
+
419
+ // 4. 调用 unfreeze
420
+ await postPhase2Unfreeze();
421
+
422
+ // 5. 再次尝试编辑测试文件 (应该成功)
423
+ await edit({
424
+ filePath: "tests/auth/login.test.ts",
425
+ oldString: "test content",
426
+ newString: "modified content"
427
+ });
428
+
429
+ console.log("✅ freeze 集成验证通过");
430
+ }
431
+ ```