@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.
- package/bin/xp-gate.js +4 -9
- package/lib/__tests__/audit-log.test.ts +107 -0
- package/lib/__tests__/detect-deps.test.js +212 -42
- package/lib/__tests__/doctor.test.js +1 -0
- package/lib/__tests__/gate-audit.test.ts +59 -0
- package/lib/__tests__/init.test.js +47 -1
- package/lib/__tests__/install-skill.test.js +1 -45
- package/lib/__tests__/ui-detector.test.ts +186 -26
- package/lib/__tests__/ui-review.test.ts +119 -0
- package/lib/__tests__/uninstall.test.js +1 -0
- package/lib/detect-deps.js +180 -37
- package/lib/doctor.js +7 -9
- package/lib/gate-audit.ts +26 -42
- package/lib/init.js +42 -13
- package/lib/install-skill.js +20 -48
- package/lib/rollback.js +1 -16
- package/lib/shared-paths.js +30 -0
- package/lib/shared-utils.js +25 -0
- package/lib/ui-detector.ts +20 -14
- package/lib/ui-review.ts +58 -53
- package/lib/uninstall.js +8 -9
- package/package.json +1 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/admin-template-guidelines/SKILL.md +904 -0
- package/plugins/claude-code/skills/delphi-review/.delphi-config.json.example +45 -0
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +66 -0
- package/plugins/claude-code/skills/delphi-review/INSTALL.md +152 -0
- package/plugins/claude-code/skills/delphi-review/SKILL.md +454 -0
- package/plugins/claude-code/skills/delphi-review/opencode.json.delphi.example +56 -0
- package/plugins/claude-code/skills/delphi-review/references/code-walkthrough.md +486 -0
- package/plugins/claude-code/skills/improve-codebase-architecture/SKILL.md +156 -0
- package/plugins/claude-code/skills/ralph-loop/SKILL.md +501 -0
- package/plugins/claude-code/skills/ralph-loop/references/components/memory.md +55 -0
- package/plugins/claude-code/skills/ralph-loop/references/components/middleware.md +54 -0
- package/plugins/claude-code/skills/ralph-loop/references/components/skill-invocations.md +39 -0
- package/plugins/claude-code/skills/ralph-loop/references/components/system-prompt.md +24 -0
- package/plugins/claude-code/skills/ralph-loop/references/components/tool-descriptions.md +32 -0
- package/plugins/claude-code/skills/ralph-loop/references/phase-2-build-ralph.md +89 -0
- package/plugins/claude-code/skills/ralph-loop/templates/progress-log.md +36 -0
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +68 -0
- package/plugins/claude-code/skills/sprint-flow/SKILL.md +1248 -0
- package/plugins/claude-code/skills/sprint-flow/references/components/memory.md +87 -0
- package/plugins/claude-code/skills/sprint-flow/references/components/middleware.md +72 -0
- package/plugins/claude-code/skills/sprint-flow/references/components/skill-invocations.md +104 -0
- package/plugins/claude-code/skills/sprint-flow/references/components/system-prompt.md +27 -0
- package/plugins/claude-code/skills/sprint-flow/references/components/tool-descriptions.md +96 -0
- package/plugins/claude-code/skills/sprint-flow/references/force-levels.md +203 -0
- package/plugins/claude-code/skills/sprint-flow/references/phase-0-think.md +115 -0
- package/plugins/claude-code/skills/sprint-flow/references/phase-1-plan.md +178 -0
- package/plugins/claude-code/skills/sprint-flow/references/phase-2-build.md +198 -0
- package/plugins/claude-code/skills/sprint-flow/references/phase-3-review.md +213 -0
- package/plugins/claude-code/skills/sprint-flow/references/phase-4-uat.md +125 -0
- package/plugins/claude-code/skills/sprint-flow/references/phase-5-feedback.md +100 -0
- package/plugins/claude-code/skills/sprint-flow/references/phase-6-ship.md +193 -0
- package/plugins/claude-code/skills/sprint-flow/references/phase-7-land.md +140 -0
- package/plugins/claude-code/skills/sprint-flow/references/phase-8-cleanup.md +192 -0
- package/plugins/claude-code/skills/sprint-flow/references/phase-minus-0-5-auto-estimate.md +257 -0
- package/plugins/claude-code/skills/sprint-flow/templates/auto-estimate-learning-log.md +136 -0
- package/plugins/claude-code/skills/sprint-flow/templates/auto-estimate-output-template.md +132 -0
- package/plugins/claude-code/skills/sprint-flow/templates/emergent-issues-template.md +120 -0
- package/plugins/claude-code/skills/sprint-flow/templates/pain-document-template.md +115 -0
- package/plugins/claude-code/skills/sprint-flow/templates/sprint-progress-template.md +151 -0
- package/plugins/claude-code/skills/sprint-flow/templates/sprint-summary-template.md +120 -0
- package/plugins/claude-code/skills/test-driven-development/SKILL.md +71 -0
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +56 -0
- package/plugins/claude-code/skills/test-specification-alignment/SKILL.md +702 -0
- package/plugins/claude-code/skills/test-specification-alignment/references/alignment-verification-algorithm.md +493 -0
- package/plugins/claude-code/skills/test-specification-alignment/references/phase2-constraint-enforcement.md +431 -0
- package/plugins/claude-code/skills/test-specification-alignment/references/specification-format.md +348 -0
- package/plugins/claude-code/skills/to-issues/SKILL.md +277 -0
- package/plugins/opencode/README.md +38 -0
- package/plugins/opencode/index.ts +85 -0
- package/plugins/opencode/package.json +18 -0
- package/plugins/opencode/skills/admin-template-guidelines/SKILL.md +904 -0
- package/plugins/opencode/skills/delphi-review/.delphi-config.json.example +45 -0
- package/plugins/opencode/skills/delphi-review/AGENTS.md +66 -0
- package/plugins/opencode/skills/delphi-review/INSTALL.md +152 -0
- package/plugins/opencode/skills/delphi-review/SKILL.md +454 -0
- package/plugins/opencode/skills/delphi-review/opencode.json.delphi.example +56 -0
- package/plugins/opencode/skills/delphi-review/references/code-walkthrough.md +486 -0
- package/plugins/opencode/skills/improve-codebase-architecture/SKILL.md +156 -0
- package/plugins/opencode/skills/ralph-loop/SKILL.md +501 -0
- package/plugins/opencode/skills/ralph-loop/references/components/memory.md +55 -0
- package/plugins/opencode/skills/ralph-loop/references/components/middleware.md +54 -0
- package/plugins/opencode/skills/ralph-loop/references/components/skill-invocations.md +39 -0
- package/plugins/opencode/skills/ralph-loop/references/components/system-prompt.md +24 -0
- package/plugins/opencode/skills/ralph-loop/references/components/tool-descriptions.md +32 -0
- package/plugins/opencode/skills/ralph-loop/references/phase-2-build-ralph.md +89 -0
- package/plugins/opencode/skills/ralph-loop/templates/progress-log.md +36 -0
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +68 -0
- package/plugins/opencode/skills/sprint-flow/SKILL.md +1248 -0
- package/plugins/opencode/skills/sprint-flow/references/components/memory.md +87 -0
- package/plugins/opencode/skills/sprint-flow/references/components/middleware.md +72 -0
- package/plugins/opencode/skills/sprint-flow/references/components/skill-invocations.md +104 -0
- package/plugins/opencode/skills/sprint-flow/references/components/system-prompt.md +27 -0
- package/plugins/opencode/skills/sprint-flow/references/components/tool-descriptions.md +96 -0
- package/plugins/opencode/skills/sprint-flow/references/force-levels.md +203 -0
- package/plugins/opencode/skills/sprint-flow/references/phase-0-think.md +115 -0
- package/plugins/opencode/skills/sprint-flow/references/phase-1-plan.md +178 -0
- package/plugins/opencode/skills/sprint-flow/references/phase-2-build.md +198 -0
- package/plugins/opencode/skills/sprint-flow/references/phase-3-review.md +213 -0
- package/plugins/opencode/skills/sprint-flow/references/phase-4-uat.md +125 -0
- package/plugins/opencode/skills/sprint-flow/references/phase-5-feedback.md +100 -0
- package/plugins/opencode/skills/sprint-flow/references/phase-6-ship.md +193 -0
- package/plugins/opencode/skills/sprint-flow/references/phase-7-land.md +140 -0
- package/plugins/opencode/skills/sprint-flow/references/phase-8-cleanup.md +192 -0
- package/plugins/opencode/skills/sprint-flow/references/phase-minus-0-5-auto-estimate.md +257 -0
- package/plugins/opencode/skills/sprint-flow/templates/auto-estimate-learning-log.md +136 -0
- package/plugins/opencode/skills/sprint-flow/templates/auto-estimate-output-template.md +132 -0
- package/plugins/opencode/skills/sprint-flow/templates/emergent-issues-template.md +120 -0
- package/plugins/opencode/skills/sprint-flow/templates/pain-document-template.md +115 -0
- package/plugins/opencode/skills/sprint-flow/templates/sprint-progress-template.md +151 -0
- package/plugins/opencode/skills/sprint-flow/templates/sprint-summary-template.md +120 -0
- package/plugins/opencode/skills/test-driven-development/SKILL.md +71 -0
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +56 -0
- package/plugins/opencode/skills/test-specification-alignment/SKILL.md +702 -0
- package/plugins/opencode/skills/test-specification-alignment/references/alignment-verification-algorithm.md +493 -0
- package/plugins/opencode/skills/test-specification-alignment/references/phase2-constraint-enforcement.md +431 -0
- package/plugins/opencode/skills/test-specification-alignment/references/specification-format.md +348 -0
- package/plugins/opencode/skills/to-issues/SKILL.md +277 -0
- package/plugins/opencode/tsconfig.json +15 -0
- package/plugins/qoder/skills/admin-template-guidelines/SKILL.md +904 -0
- package/plugins/qoder/skills/delphi-review/.delphi-config.json.example +45 -0
- package/plugins/qoder/skills/delphi-review/AGENTS.md +66 -0
- package/plugins/qoder/skills/delphi-review/INSTALL.md +152 -0
- package/plugins/qoder/skills/delphi-review/SKILL.md +454 -0
- package/plugins/qoder/skills/delphi-review/opencode.json.delphi.example +56 -0
- package/plugins/qoder/skills/delphi-review/references/code-walkthrough.md +486 -0
- package/plugins/qoder/skills/improve-codebase-architecture/SKILL.md +156 -0
- package/plugins/qoder/skills/ralph-loop/SKILL.md +501 -0
- package/plugins/qoder/skills/ralph-loop/references/components/memory.md +55 -0
- package/plugins/qoder/skills/ralph-loop/references/components/middleware.md +54 -0
- package/plugins/qoder/skills/ralph-loop/references/components/skill-invocations.md +39 -0
- package/plugins/qoder/skills/ralph-loop/references/components/system-prompt.md +24 -0
- package/plugins/qoder/skills/ralph-loop/references/components/tool-descriptions.md +32 -0
- package/plugins/qoder/skills/ralph-loop/references/phase-2-build-ralph.md +89 -0
- package/plugins/qoder/skills/ralph-loop/templates/progress-log.md +36 -0
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +68 -0
- package/plugins/qoder/skills/sprint-flow/SKILL.md +1248 -0
- package/plugins/qoder/skills/sprint-flow/references/components/memory.md +87 -0
- package/plugins/qoder/skills/sprint-flow/references/components/middleware.md +72 -0
- package/plugins/qoder/skills/sprint-flow/references/components/skill-invocations.md +104 -0
- package/plugins/qoder/skills/sprint-flow/references/components/system-prompt.md +27 -0
- package/plugins/qoder/skills/sprint-flow/references/components/tool-descriptions.md +96 -0
- package/plugins/qoder/skills/sprint-flow/references/force-levels.md +203 -0
- package/plugins/qoder/skills/sprint-flow/references/phase-0-think.md +115 -0
- package/plugins/qoder/skills/sprint-flow/references/phase-1-plan.md +178 -0
- package/plugins/qoder/skills/sprint-flow/references/phase-2-build.md +198 -0
- package/plugins/qoder/skills/sprint-flow/references/phase-3-review.md +213 -0
- package/plugins/qoder/skills/sprint-flow/references/phase-4-uat.md +125 -0
- package/plugins/qoder/skills/sprint-flow/references/phase-5-feedback.md +100 -0
- package/plugins/qoder/skills/sprint-flow/references/phase-6-ship.md +193 -0
- package/plugins/qoder/skills/sprint-flow/references/phase-7-land.md +140 -0
- package/plugins/qoder/skills/sprint-flow/references/phase-8-cleanup.md +192 -0
- package/plugins/qoder/skills/sprint-flow/references/phase-minus-0-5-auto-estimate.md +257 -0
- package/plugins/qoder/skills/sprint-flow/templates/auto-estimate-learning-log.md +136 -0
- package/plugins/qoder/skills/sprint-flow/templates/auto-estimate-output-template.md +132 -0
- package/plugins/qoder/skills/sprint-flow/templates/emergent-issues-template.md +120 -0
- package/plugins/qoder/skills/sprint-flow/templates/pain-document-template.md +115 -0
- package/plugins/qoder/skills/sprint-flow/templates/sprint-progress-template.md +151 -0
- package/plugins/qoder/skills/sprint-flow/templates/sprint-summary-template.md +120 -0
- package/plugins/qoder/skills/test-driven-development/SKILL.md +71 -0
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +56 -0
- package/plugins/qoder/skills/test-specification-alignment/SKILL.md +702 -0
- package/plugins/qoder/skills/test-specification-alignment/references/alignment-verification-algorithm.md +493 -0
- package/plugins/qoder/skills/test-specification-alignment/references/phase2-constraint-enforcement.md +431 -0
- package/plugins/qoder/skills/test-specification-alignment/references/specification-format.md +348 -0
- package/plugins/qoder/skills/to-issues/SKILL.md +277 -0
- package/skills/admin-template-guidelines/SKILL.md +904 -0
- package/skills/delphi-review/SKILL.md +112 -77
- package/skills/improve-codebase-architecture/SKILL.md +156 -0
- package/skills/ralph-loop/SKILL.md +165 -34
- package/skills/sprint-flow/SKILL.md +448 -107
- package/skills/sprint-flow/references/components/skill-invocations.md +1 -1
- package/skills/sprint-flow/references/components/tool-descriptions.md +1 -1
- package/skills/sprint-flow/references/force-levels.md +203 -0
- package/skills/sprint-flow/references/phase-1-plan.md +4 -4
- package/skills/sprint-flow/references/phase-minus-0-5-auto-estimate.md +20 -1
- package/skills/sprint-flow/templates/auto-estimate-output-template.md +7 -5
- package/skills/sprint-flow/templates/sprint-progress-template.md +151 -0
- package/skills/test-driven-development/SKILL.md +71 -0
- package/skills/test-specification-alignment/SKILL.md +98 -24
- package/skills/to-issues/SKILL.md +277 -0
- package/plugins/qoder/AGENTS.md +0 -93
- package/plugins/qoder/README.md +0 -87
- package/plugins/qoder/widgets/quality-report.html +0 -163
- package/plugins/qoder/widgets/sprint-dashboard.html +0 -172
- package/skills/delphi-review/evals/evals.json +0 -82
- package/skills/delphi-review/references/qoder-multi-model.md +0 -191
- package/skills/ralph-loop/evals/evals.json +0 -311
- package/skills/ralph-loop/evolution-history.json +0 -59
- package/skills/ralph-loop/evolution-log.md +0 -16
- package/skills/sprint-flow/evals/evals.json +0 -130
- package/skills/sprint-flow/evolution-history.json +0 -39
- package/skills/sprint-flow/evolution-log.md +0 -23
- package/skills/sprint-flow/references/qoder-adaptation.md +0 -173
- package/skills/test-specification-alignment/evals/evals.json +0 -75
|
@@ -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
|
+
```
|