xp-gate 0.5.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 (90) hide show
  1. package/adapter-common.sh +192 -0
  2. package/adapters/cpp.sh +76 -0
  3. package/adapters/dart.sh +41 -0
  4. package/adapters/flutter.sh +41 -0
  5. package/adapters/go.sh +59 -0
  6. package/adapters/iac.sh +189 -0
  7. package/adapters/java.sh +191 -0
  8. package/adapters/kotlin.sh +77 -0
  9. package/adapters/objectivec.sh +38 -0
  10. package/adapters/powershell.sh +138 -0
  11. package/adapters/python.sh +104 -0
  12. package/adapters/shell.sh +55 -0
  13. package/adapters/swift.sh +44 -0
  14. package/adapters/typescript.sh +61 -0
  15. package/bin/xp-gate.js +157 -0
  16. package/hooks/adapter-common.sh +192 -0
  17. package/hooks/pre-commit +1667 -0
  18. package/hooks/pre-push +395 -0
  19. package/lib/__tests__/detect-deps.test.js +209 -0
  20. package/lib/__tests__/doctor.test.js +448 -0
  21. package/lib/__tests__/download-skill.test.js +281 -0
  22. package/lib/__tests__/init.test.js +327 -0
  23. package/lib/__tests__/install-skill.test.js +326 -0
  24. package/lib/__tests__/migrate.test.js +212 -0
  25. package/lib/__tests__/rollback.test.js +183 -0
  26. package/lib/__tests__/ui-detector.test.ts +200 -0
  27. package/lib/__tests__/uninstall-skill.test.js +189 -0
  28. package/lib/__tests__/uninstall.test.js +589 -0
  29. package/lib/__tests__/update-skill.test.js +276 -0
  30. package/lib/detect-deps.js +157 -0
  31. package/lib/doctor.js +370 -0
  32. package/lib/download-skill.js +96 -0
  33. package/lib/init.js +367 -0
  34. package/lib/install-skill.js +184 -0
  35. package/lib/migrate.js +120 -0
  36. package/lib/rollback.js +78 -0
  37. package/lib/ui-detector.ts +99 -0
  38. package/lib/uninstall-skill.js +69 -0
  39. package/lib/uninstall.js +401 -0
  40. package/lib/update-skill.js +90 -0
  41. package/package.json +39 -0
  42. package/plugins/claude-code/.claude-plugin/plugin.json +21 -0
  43. package/plugins/claude-code/bin/delphi-review-guard.sh +68 -0
  44. package/plugins/claude-code/bin/xp-gate-check +47 -0
  45. package/plugins/claude-code/hooks/hooks.json +37 -0
  46. package/skills/delphi-review/.delphi-config.json.example +45 -0
  47. package/skills/delphi-review/AGENTS.md +54 -0
  48. package/skills/delphi-review/INSTALL.md +152 -0
  49. package/skills/delphi-review/SKILL.md +371 -0
  50. package/skills/delphi-review/evals/evals.json +82 -0
  51. package/skills/delphi-review/opencode.json.delphi.example +56 -0
  52. package/skills/delphi-review/references/code-walkthrough.md +486 -0
  53. package/skills/ralph-loop/SKILL.md +330 -0
  54. package/skills/ralph-loop/evals/evals.json +311 -0
  55. package/skills/ralph-loop/evolution-history.json +59 -0
  56. package/skills/ralph-loop/evolution-log.md +16 -0
  57. package/skills/ralph-loop/references/components/memory.md +55 -0
  58. package/skills/ralph-loop/references/components/middleware.md +54 -0
  59. package/skills/ralph-loop/references/components/skill-invocations.md +39 -0
  60. package/skills/ralph-loop/references/components/system-prompt.md +24 -0
  61. package/skills/ralph-loop/references/components/tool-descriptions.md +32 -0
  62. package/skills/ralph-loop/references/phase-2-build-ralph.md +89 -0
  63. package/skills/ralph-loop/templates/progress-log.md +36 -0
  64. package/skills/sprint-flow/SKILL.md +600 -0
  65. package/skills/sprint-flow/evals/evals.json +78 -0
  66. package/skills/sprint-flow/evolution-history.json +39 -0
  67. package/skills/sprint-flow/evolution-log.md +23 -0
  68. package/skills/sprint-flow/references/components/memory.md +87 -0
  69. package/skills/sprint-flow/references/components/middleware.md +72 -0
  70. package/skills/sprint-flow/references/components/skill-invocations.md +104 -0
  71. package/skills/sprint-flow/references/components/system-prompt.md +27 -0
  72. package/skills/sprint-flow/references/components/tool-descriptions.md +96 -0
  73. package/skills/sprint-flow/references/phase-0-think.md +115 -0
  74. package/skills/sprint-flow/references/phase-1-plan.md +178 -0
  75. package/skills/sprint-flow/references/phase-2-build.md +198 -0
  76. package/skills/sprint-flow/references/phase-3-review.md +213 -0
  77. package/skills/sprint-flow/references/phase-4-uat.md +125 -0
  78. package/skills/sprint-flow/references/phase-5-feedback.md +100 -0
  79. package/skills/sprint-flow/references/phase-6-ship.md +193 -0
  80. package/skills/sprint-flow/references/phase-7-land.md +140 -0
  81. package/skills/sprint-flow/references/phase-8-cleanup.md +192 -0
  82. package/skills/sprint-flow/templates/emergent-issues-template.md +120 -0
  83. package/skills/sprint-flow/templates/pain-document-template.md +115 -0
  84. package/skills/sprint-flow/templates/sprint-summary-template.md +120 -0
  85. package/skills/test-specification-alignment/AGENTS.md +59 -0
  86. package/skills/test-specification-alignment/SKILL.md +605 -0
  87. package/skills/test-specification-alignment/evals/evals.json +75 -0
  88. package/skills/test-specification-alignment/references/alignment-verification-algorithm.md +493 -0
  89. package/skills/test-specification-alignment/references/phase2-constraint-enforcement.md +431 -0
  90. package/skills/test-specification-alignment/references/specification-format.md +348 -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
+ ```