@dommaker/harness 0.7.7 → 0.7.9
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/README.md +216 -799
- package/dist/core/constraints/checker.d.ts +24 -0
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +191 -12
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/validators/passes-gate.d.ts +26 -1
- package/dist/core/validators/passes-gate.d.ts.map +1 -1
- package/dist/core/validators/passes-gate.js +60 -0
- package/dist/core/validators/passes-gate.js.map +1 -1
- package/dist/extensions/long-running/constraints.d.ts +38 -0
- package/dist/extensions/long-running/constraints.d.ts.map +1 -0
- package/dist/extensions/long-running/constraints.js +153 -0
- package/dist/extensions/long-running/constraints.js.map +1 -0
- package/dist/extensions/long-running/index.d.ts +30 -0
- package/dist/extensions/long-running/index.d.ts.map +1 -0
- package/dist/extensions/long-running/index.js +50 -0
- package/dist/extensions/long-running/index.js.map +1 -0
- package/dist/extensions/long-running/types.d.ts +154 -0
- package/dist/extensions/long-running/types.d.ts.map +1 -0
- package/dist/extensions/long-running/types.js +9 -0
- package/dist/extensions/long-running/types.js.map +1 -0
- package/dist/presets/long-running.d.ts +33 -0
- package/dist/presets/long-running.d.ts.map +1 -0
- package/dist/presets/long-running.js +52 -0
- package/dist/presets/long-running.js.map +1 -0
- package/dist/types/constraint.d.ts +4 -0
- package/dist/types/constraint.d.ts.map +1 -1
- package/dist/types/constraint.js.map +1 -1
- package/dist/types/passes-gate.d.ts +47 -0
- package/dist/types/passes-gate.d.ts.map +1 -1
- package/dist/utils/exec.d.ts +17 -0
- package/dist/utils/exec.d.ts.map +1 -0
- package/dist/utils/exec.js +42 -0
- package/dist/utils/exec.js.map +1 -0
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -1,922 +1,339 @@
|
|
|
1
1
|
# @dommaker/harness
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> AI Agent 的工程约束框架 — 铁律系统、门禁系统、质量检查
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 一句话
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**harness 让 Agent 不会乱承诺、不会跳过验证、不会简化测试。**
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
| 功能 | 说明 |
|
|
12
|
-
|------|------|
|
|
13
|
-
| **铁律系统** | 16 条内置约束(4 Iron Laws + 10 Guidelines + 2 Tips) |
|
|
14
|
-
| **门禁系统** | 7 种门禁(测试、审查、安全、性能、契约、检查点、验收标准) |
|
|
15
|
-
| **检查点验证** | 验证工作流步骤的结果是否符合预期 |
|
|
16
|
-
| **拦截器** | 抽象拦截框架,自动执行 enforcement |
|
|
17
|
-
| **Session 管理** | 启动检查点 + 结束状态管理 |
|
|
18
|
-
| **预设系统** | 提供 strict/standard/relaxed 三种预设 |
|
|
19
|
-
| **Execution Trace** | 轻量记录约束检查,异常检测,诊断系统 |
|
|
20
|
-
| **Performance Trace** | 性能日志收集,统计分析,异常检测(🆕) |
|
|
21
|
-
| **Failure Classification** | 错误分类,失败记录,等级映射(🆕) |
|
|
22
|
-
| **Spec 验证** | 验证架构文档、模块定义、API 定义 |
|
|
23
|
-
| **项目级自定义约束** | 扩展/覆盖内置约束,无需 fork |
|
|
24
|
-
| **CLI 工具** | 命令行工具执行检查 |
|
|
25
|
-
|
|
26
|
-
## 安装
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
npm install @dommaker/harness
|
|
30
|
-
```
|
|
9
|
+
---
|
|
31
10
|
|
|
32
|
-
##
|
|
11
|
+
## 快速上手
|
|
33
12
|
|
|
34
|
-
###
|
|
13
|
+
### CLI 命令速查
|
|
35
14
|
|
|
36
15
|
```bash
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
这会创建:
|
|
41
|
-
- `.harness/config.yml` - 预设配置
|
|
42
|
-
- `.harness/checkpoints.yml` - 示例检查点
|
|
43
|
-
- `CAPABILITIES.md` - 功能清单模板
|
|
44
|
-
- `.git/hooks/pre-commit` - Git 钩子(可选)
|
|
45
|
-
- `.github/workflows/harness-check.yml` - CI 检查(可选)
|
|
46
|
-
|
|
47
|
-
### 2. CLI 命令
|
|
16
|
+
# 安装
|
|
17
|
+
npm install @dommaker/harness
|
|
48
18
|
|
|
49
|
-
|
|
50
|
-
# 初始化项目配置
|
|
19
|
+
# 初始化项目
|
|
51
20
|
harness init --preset standard
|
|
52
21
|
|
|
53
|
-
#
|
|
54
|
-
harness init --print-snippets
|
|
55
|
-
|
|
56
|
-
# 检查铁律
|
|
22
|
+
# 检查铁律(开发前后必用)
|
|
57
23
|
harness check
|
|
58
24
|
|
|
59
|
-
#
|
|
60
|
-
harness check --list
|
|
61
|
-
|
|
62
|
-
# 查看状态(统计、异常、建议)
|
|
25
|
+
# 查看状态(异常、统计)
|
|
63
26
|
harness status
|
|
64
27
|
|
|
65
|
-
# 查看详细状态
|
|
66
|
-
harness status --detail
|
|
67
|
-
|
|
68
|
-
# 只显示异常
|
|
69
|
-
harness status --anomalies
|
|
70
|
-
|
|
71
|
-
# 一键执行诊断+提案流程
|
|
72
|
-
harness flow
|
|
73
|
-
|
|
74
28
|
# 验证检查点
|
|
75
29
|
harness validate
|
|
76
30
|
|
|
77
31
|
# 测试门控
|
|
78
32
|
harness passes-gate
|
|
79
33
|
|
|
80
|
-
#
|
|
81
|
-
harness
|
|
34
|
+
# Spec 验证
|
|
35
|
+
harness spec
|
|
82
36
|
|
|
83
|
-
#
|
|
84
|
-
harness
|
|
85
|
-
harness traces summary
|
|
86
|
-
harness traces anomalies
|
|
37
|
+
# 一键诊断
|
|
38
|
+
harness flow
|
|
87
39
|
```
|
|
88
40
|
|
|
89
|
-
###
|
|
41
|
+
### 最小工作流
|
|
90
42
|
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
43
|
+
```
|
|
44
|
+
开始开发
|
|
45
|
+
↓
|
|
46
|
+
harness check (检查铁律)
|
|
47
|
+
↓
|
|
48
|
+
写代码 + 写测试
|
|
49
|
+
↓
|
|
50
|
+
harness passes-gate (验证通过)
|
|
51
|
+
↓
|
|
52
|
+
提交
|
|
101
53
|
```
|
|
102
54
|
|
|
103
|
-
|
|
55
|
+
---
|
|
104
56
|
|
|
105
|
-
|
|
57
|
+
## Agent 工作流程
|
|
106
58
|
|
|
107
|
-
|
|
108
|
-
# 验证所有 Spec 文件
|
|
109
|
-
harness spec
|
|
59
|
+
### 1. Session 启动检查
|
|
110
60
|
|
|
111
|
-
|
|
112
|
-
harness spec --staged
|
|
61
|
+
Agent 开始工作前,自动检查:
|
|
113
62
|
|
|
114
|
-
|
|
115
|
-
|
|
63
|
+
| 检查项 | 说明 |
|
|
64
|
+
|--------|------|
|
|
65
|
+
| 工作目录干净? | 无未提交变更 |
|
|
66
|
+
| Roadmap 存在? | 知道要做什么 |
|
|
67
|
+
| Spec 存在? | 知道怎么做 |
|
|
68
|
+
| 依赖满足? | 前置任务完成 |
|
|
116
69
|
|
|
117
|
-
|
|
118
|
-
harness
|
|
119
|
-
|
|
120
|
-
# 列出支持的 Spec 类型
|
|
121
|
-
harness spec list
|
|
70
|
+
```bash
|
|
71
|
+
harness status
|
|
122
72
|
```
|
|
123
73
|
|
|
124
|
-
|
|
74
|
+
### 2. 开发中铁律检查
|
|
125
75
|
|
|
126
|
-
|
|
76
|
+
**Iron Laws(绝对禁止)**:
|
|
127
77
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
export async function validate(content: string, filePath: string) {
|
|
139
|
-
// 解析并验证内容
|
|
140
|
-
// 返回 SpecValidationResult
|
|
141
|
-
}
|
|
78
|
+
| ID | 规则 | Agent 不能做 |
|
|
79
|
+
|---|------|-------------|
|
|
80
|
+
| `no_bypass_checkpoint` | 禁止跳过检查点 | ❌ "先跳过验证" |
|
|
81
|
+
| `no_self_approval` | 禁止自评通过 | ❌ "应该没问题" |
|
|
82
|
+
| `no_completion_without_verification` | 完成必须有验证 | ❌ "任务完成了"(未测试)|
|
|
83
|
+
| `no_test_simplification` | 禁止简化测试 | ❌ "测试太难,先删掉" |
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
harness check
|
|
142
87
|
```
|
|
143
88
|
|
|
144
|
-
###
|
|
89
|
+
### 3. 完成前验证
|
|
145
90
|
|
|
146
|
-
|
|
147
|
-
import {
|
|
148
|
-
IronLawChecker,
|
|
149
|
-
CheckpointValidator,
|
|
150
|
-
PassesGate,
|
|
151
|
-
SessionStartup,
|
|
152
|
-
CleanStateManager
|
|
153
|
-
} from '@dommaker/harness';
|
|
154
|
-
|
|
155
|
-
// 检查铁律
|
|
156
|
-
const checker = IronLawChecker.getInstance();
|
|
157
|
-
const results = await checker.checkAll(context);
|
|
91
|
+
Agent 声明完成前,必须通过门禁:
|
|
158
92
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
93
|
+
| 门禁 | 检查内容 |
|
|
94
|
+
|------|---------|
|
|
95
|
+
| PassesGate | 测试必须通过 |
|
|
96
|
+
| ReviewGate | PR 必须有人审核 |
|
|
97
|
+
| SecurityGate | 无高危漏洞 |
|
|
98
|
+
| PerformanceGate | 性能达标 |
|
|
162
99
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const testResult = await gate.setPasses(taskId, true, workDir);
|
|
166
|
-
|
|
167
|
-
// Session 启动检查
|
|
168
|
-
const startup = new SessionStartup(workDir, checkpoints);
|
|
169
|
-
const { success, results } = await startup.run();
|
|
170
|
-
|
|
171
|
-
// Session 结束清理
|
|
172
|
-
const cleaner = new CleanStateManager();
|
|
173
|
-
const cleanResult = await cleaner.onSessionEnd(workDir, sessionInfo);
|
|
100
|
+
```bash
|
|
101
|
+
harness passes-gate
|
|
174
102
|
```
|
|
175
103
|
|
|
176
|
-
###
|
|
104
|
+
### 4. Spec 验证
|
|
177
105
|
|
|
178
|
-
|
|
106
|
+
验证架构文档、API 定义等 Spec 文件:
|
|
179
107
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
| 性能门禁 | `PerformanceGate` | 响应时间、覆盖率、打包大小检查 |
|
|
186
|
-
| 契约门禁 | `ContractGate` | OpenAPI 契约验证 |
|
|
187
|
-
| 检查点验证 | `CheckpointValidator` | 验证工作流步骤结果 |
|
|
188
|
-
| 验收标准门禁 | `SpecAcceptanceGate` | 验证任务是否满足验收标准 |
|
|
189
|
-
|
|
190
|
-
**使用门禁**:
|
|
108
|
+
```bash
|
|
109
|
+
harness spec # 验证所有 Spec
|
|
110
|
+
harness spec --staged # 验证暂存文件
|
|
111
|
+
harness spec list # 支持的 Spec 类型
|
|
112
|
+
```
|
|
191
113
|
|
|
192
|
-
|
|
193
|
-
import {
|
|
194
|
-
PassesGate,
|
|
195
|
-
ReviewGate,
|
|
196
|
-
SecurityGate,
|
|
197
|
-
PerformanceGate,
|
|
198
|
-
ContractGate,
|
|
199
|
-
CheckpointValidator,
|
|
200
|
-
SpecAcceptanceGate,
|
|
201
|
-
} from '@dommaker/harness';
|
|
114
|
+
---
|
|
202
115
|
|
|
203
|
-
|
|
204
|
-
const passesGate = new PassesGate({ requireEvidence: true });
|
|
205
|
-
const testResult = await passesGate.runTests();
|
|
206
|
-
|
|
207
|
-
// 审查门禁
|
|
208
|
-
const reviewGate = new ReviewGate({ minReviewers: 2 });
|
|
209
|
-
const reviewResult = await reviewGate.check({
|
|
210
|
-
projectId: 'my-project',
|
|
211
|
-
projectPath: '/path/to/project',
|
|
212
|
-
prNumber: 123,
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
// 安全门禁
|
|
216
|
-
const securityGate = new SecurityGate({ severityThreshold: 'high' });
|
|
217
|
-
const securityResult = await securityGate.scan({
|
|
218
|
-
projectId: 'my-project',
|
|
219
|
-
projectPath: '/path/to/project',
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
// 性能门禁(带超时)
|
|
223
|
-
const performanceGate = new PerformanceGate({
|
|
224
|
-
thresholds: {
|
|
225
|
-
maxResponseTime: 500,
|
|
226
|
-
minCoverage: 80,
|
|
227
|
-
maxBundleSize: 1024,
|
|
228
|
-
},
|
|
229
|
-
coverageTimeout: 120000, // 2分钟超时
|
|
230
|
-
});
|
|
231
|
-
const perfResult = await performanceGate.check({
|
|
232
|
-
projectId: 'my-project',
|
|
233
|
-
projectPath: '/path/to/project',
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
// 契约门禁
|
|
237
|
-
const contractGate = new ContractGate({ strict: true });
|
|
238
|
-
const contractResult = await contractGate.check({
|
|
239
|
-
projectId: 'my-project',
|
|
240
|
-
projectPath: '/path/to/project',
|
|
241
|
-
newContractPath: '/path/to/openapi.yaml',
|
|
242
|
-
});
|
|
116
|
+
## 核心概念
|
|
243
117
|
|
|
244
|
-
|
|
245
|
-
const checkpointValidator = CheckpointValidator.getInstance();
|
|
246
|
-
const checkpointResult = await checkpointValidator.validate(checkpoints, {
|
|
247
|
-
workdir: '/path/to/project',
|
|
248
|
-
});
|
|
249
|
-
```
|
|
118
|
+
### 三层约束体系
|
|
250
119
|
|
|
251
|
-
|
|
120
|
+
| 层级 | 名称 | 严重性 | 举例 |
|
|
121
|
+
|------|------|:------:|------|
|
|
122
|
+
| **Iron Law** | 铁律 | 🔴 error | 禁止跳过检查点 |
|
|
123
|
+
| **Guideline** | 指导 | 🟡 warning | 写代码前写测试 |
|
|
124
|
+
| **Tip** | 提示 | 🔵 info | 新模块要有 README |
|
|
252
125
|
|
|
253
|
-
|
|
254
|
-
interface GateResult {
|
|
255
|
-
gate: string; // 门禁类型
|
|
256
|
-
passed: boolean; // 是否通过
|
|
257
|
-
message: string; // 结果消息
|
|
258
|
-
details?: { // 详细信息
|
|
259
|
-
metrics?: object; // 性能指标
|
|
260
|
-
failures?: string[]; // 失败项
|
|
261
|
-
warnings?: string[]; // 警告项
|
|
262
|
-
};
|
|
263
|
-
timestamp: string; // 时间戳
|
|
264
|
-
duration?: number; // 执行时长(毫秒)
|
|
265
|
-
}
|
|
266
|
-
```
|
|
126
|
+
### 16 条内置约束
|
|
267
127
|
|
|
268
|
-
**
|
|
128
|
+
**Iron Laws(4 条)**:
|
|
269
129
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
// 动态设置超时
|
|
278
|
-
gate.setTimeouts({ coverage: 120000 });
|
|
279
|
-
```
|
|
130
|
+
| ID | 规则 |
|
|
131
|
+
|---|------|
|
|
132
|
+
| `no_bypass_checkpoint` | 禁止跳过检查点 |
|
|
133
|
+
| `no_self_approval` | 禁止自评通过 |
|
|
134
|
+
| `no_completion_without_verification` | 完成必须验证 |
|
|
135
|
+
| `no_test_simplification` | 禁止简化测试 |
|
|
280
136
|
|
|
281
|
-
|
|
137
|
+
**Guidelines(10 条)**:
|
|
282
138
|
|
|
283
|
-
|
|
139
|
+
| ID | 规则 |
|
|
140
|
+
|---|------|
|
|
141
|
+
| `no_fix_without_root_cause` | 修复前找根因 |
|
|
142
|
+
| `no_code_without_test` | 先写测试 |
|
|
143
|
+
| `no_any_type` | 禁止 any |
|
|
144
|
+
| `simplest_solution_first` | 最简方案优先 |
|
|
145
|
+
| `no_creation_without_reuse_check` | 创建前检查复用 |
|
|
146
|
+
| `capability_sync` | 代码变更更新 CAPABILITIES |
|
|
147
|
+
| `no_simplification_without_approval` | 禁止擅自简化 |
|
|
148
|
+
| `no_skill_without_test` | 技能要有测试 |
|
|
149
|
+
| `test_coverage_required` | 覆盖率达标 |
|
|
150
|
+
| `design_decision_requires_discussion` | 设计决策先讨论 |
|
|
284
151
|
|
|
285
|
-
|
|
286
|
-
import {
|
|
287
|
-
interceptor,
|
|
288
|
-
registerExecutor,
|
|
289
|
-
interceptOperation,
|
|
290
|
-
claimOperation,
|
|
291
|
-
type EnforcementExecutor,
|
|
292
|
-
type ConstraintContext,
|
|
293
|
-
} from '@dommaker/harness';
|
|
152
|
+
**Tips(2 条)**:
|
|
294
153
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
async execute(context) {
|
|
300
|
-
// 使用者自定义验证逻辑
|
|
301
|
-
const result = await exec('npm test', { cwd: context.projectPath });
|
|
302
|
-
return {
|
|
303
|
-
passed: result.success,
|
|
304
|
-
evidence: result.stdout,
|
|
305
|
-
};
|
|
306
|
-
},
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
// 2. 在关键操作前拦截
|
|
310
|
-
try {
|
|
311
|
-
// 拦截 task_completion_claim 操作
|
|
312
|
-
// 自动查找适用的约束并执行对应的 enforcement
|
|
313
|
-
await claimOperation('task_completion_claim', {
|
|
314
|
-
operation: 'task_completion_claim',
|
|
315
|
-
projectPath: '/path/to/project',
|
|
316
|
-
sessionId: 'session-123',
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
// 拦截通过,可以宣布完成
|
|
320
|
-
await announceCompletion();
|
|
321
|
-
} catch (e) {
|
|
322
|
-
// 拦截失败,铁律违规
|
|
323
|
-
console.error('必须先验证才能完成');
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// 3. 查询拦截结果(不抛异常)
|
|
327
|
-
const result = await interceptOperation('task_completion_claim', context);
|
|
328
|
-
if (result.passed) {
|
|
329
|
-
console.log('✅ 通过拦截');
|
|
330
|
-
} else {
|
|
331
|
-
console.log('❌ 约束违规:', result.violations);
|
|
332
|
-
}
|
|
333
|
-
```
|
|
154
|
+
| ID | 规则 |
|
|
155
|
+
|---|------|
|
|
156
|
+
| `readme_required` | 新模块有 README |
|
|
157
|
+
| `doc_required_for_public_api` | 公共 API 有文档 |
|
|
334
158
|
|
|
335
|
-
|
|
159
|
+
---
|
|
336
160
|
|
|
337
|
-
|
|
338
|
-
|------|------|
|
|
339
|
-
| 手动检查 | `checkConstraints()` 需要手动调用 API |
|
|
340
|
-
| 拦截器 | 自动执行 enforcement,抽象框架,使用者实现逻辑 |
|
|
161
|
+
## 7 种门禁
|
|
341
162
|
|
|
342
|
-
|
|
163
|
+
| 门禁 | 类 | 用途 |
|
|
164
|
+
|------|-----|------|
|
|
165
|
+
| PassesGate | 测试门控 | 禁止自评通过 |
|
|
166
|
+
| ReviewGate | 审查门控 | PR 审核检查 |
|
|
167
|
+
| SecurityGate | 安全门控 | npm audit |
|
|
168
|
+
| PerformanceGate | 性能门控 | 响应时间、覆盖率 |
|
|
169
|
+
| ContractGate | 契约门控 | OpenAPI 验证 |
|
|
170
|
+
| CheckpointValidator | 检查点验证 | 步骤结果验证 |
|
|
171
|
+
| SpecAcceptanceGate | 验收门控 | 验收标准检查 |
|
|
343
172
|
|
|
344
|
-
|
|
345
|
-
|-------------|------|
|
|
346
|
-
| verify-completion | 验证完成声明:运行测试 |
|
|
347
|
-
| verify-e2e | 验证端到端测试 |
|
|
348
|
-
| debug-systematic | 系统性调试检查 |
|
|
349
|
-
| reuse-first | 复用优先检查 |
|
|
350
|
-
| update-capabilities | CAPABILITIES.md 同步检查 |
|
|
351
|
-
| tdd-cycle | TDD 循环检查 |
|
|
352
|
-
| passes-gate | 测试门控 |
|
|
353
|
-
| checkpoint-required | 检查点必须通过 |
|
|
354
|
-
| check-coverage | 覆盖率检查 |
|
|
355
|
-
| require-discussion | 设计决策讨论检查 |
|
|
356
|
-
|
|
357
|
-
## 内置约束(16 条)
|
|
358
|
-
|
|
359
|
-
| ID | 规则 | 层级 | 严重性 |
|
|
360
|
-
|---|------|------|:------:|
|
|
361
|
-
| `no_bypass_checkpoint` | 禁止跳过检查点 | iron_law | 🔴 error |
|
|
362
|
-
| `no_self_approval` | 禁止自评通过 | iron_law | 🔴 error |
|
|
363
|
-
| `no_completion_without_verification` | 完成必须有验证证据 | iron_law | 🔴 error |
|
|
364
|
-
| `no_test_simplification` | 禁止擅自简化测试 | iron_law | 🔴 error |
|
|
365
|
-
| `no_fix_without_root_cause` | 修复前必须找到根因 | guideline | 🔴 error |
|
|
366
|
-
| `no_code_without_test` | 写代码前必须有测试 | guideline | 🔴 error |
|
|
367
|
-
| `no_any_type` | 禁止使用 any 类型 | guideline | 🟡 warning |
|
|
368
|
-
| `simplest_solution_first` | 优先选择最简方案 | guideline | 🟡 warning |
|
|
369
|
-
| `no_creation_without_reuse_check` | 创建前必须检查可复用 | guideline | 🟡 warning |
|
|
370
|
-
| `capability_sync` | 代码变更必须更新 CAPABILITIES.md | guideline | 🟡 warning |
|
|
371
|
-
| `no_simplification_without_approval` | 不能擅自简化逻辑 | guideline | 🟡 warning |
|
|
372
|
-
| `no_skill_without_test` | 创建技能前必须有测试 | guideline | 🟡 warning |
|
|
373
|
-
| `test_coverage_required` | 测试覆盖率必须达标 | guideline | 🟡 warning |
|
|
374
|
-
| `design_decision_requires_discussion` | 设计决策必须先讨论 | guideline | 🟡 warning |
|
|
375
|
-
| `readme_required` | 新模块必须有 README | tip | 🔵 info |
|
|
376
|
-
| `doc_required_for_public_api` | 公共 API 必须有文档 | tip | 🔵 info |
|
|
173
|
+
---
|
|
377
174
|
|
|
378
175
|
## 预设系统
|
|
379
176
|
|
|
380
177
|
| 预设 | 说明 |
|
|
381
178
|
|------|------|
|
|
382
|
-
| `strict` |
|
|
383
|
-
| `standard` |
|
|
384
|
-
| `relaxed` |
|
|
179
|
+
| `strict` | 所有检查启用 |
|
|
180
|
+
| `standard` | 推荐使用 |
|
|
181
|
+
| `relaxed` | 警告不阻止 |
|
|
385
182
|
|
|
386
|
-
|
|
183
|
+
```bash
|
|
184
|
+
harness init --preset standard
|
|
185
|
+
```
|
|
387
186
|
|
|
388
|
-
|
|
187
|
+
---
|
|
389
188
|
|
|
390
|
-
|
|
189
|
+
## 高级功能
|
|
391
190
|
|
|
392
|
-
|
|
393
|
-
# .harness/custom-constraints.yml
|
|
394
|
-
custom_constraints:
|
|
395
|
-
no_fix_without_root_cause:
|
|
396
|
-
extend_exceptions:
|
|
397
|
-
- my_special_case_1
|
|
398
|
-
- my_special_case_2
|
|
399
|
-
```
|
|
191
|
+
### CLI 详细命令
|
|
400
192
|
|
|
401
|
-
|
|
193
|
+
```bash
|
|
194
|
+
# 初始化(输出代码片段)
|
|
195
|
+
harness init --print-snippets
|
|
402
196
|
|
|
403
|
-
|
|
197
|
+
# 铁律检查
|
|
198
|
+
harness check --list # 列出所有铁律
|
|
199
|
+
harness check --json # JSON 输出
|
|
404
200
|
|
|
405
|
-
|
|
201
|
+
# 状态查看
|
|
202
|
+
harness status --detail # 详细状态
|
|
203
|
+
harness status --anomalies # 只显示异常
|
|
406
204
|
|
|
407
|
-
|
|
408
|
-
#
|
|
409
|
-
|
|
410
|
-
no_fix_without_root_cause:
|
|
411
|
-
level: guideline
|
|
412
|
-
rule: Do not fix without root cause
|
|
413
|
-
message: 禁止没有根因分析就修复
|
|
414
|
-
trigger: bug_fix
|
|
415
|
-
exceptions:
|
|
416
|
-
- my_only_exception
|
|
417
|
-
```
|
|
205
|
+
# Trace 分析(已弃用,用 status)
|
|
206
|
+
harness traces stats # 统计
|
|
207
|
+
harness traces anomalies # 异常检测
|
|
418
208
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
209
|
+
# 诊断流程
|
|
210
|
+
harness diagnose run --hours 24 --save
|
|
211
|
+
harness diagnose list
|
|
212
|
+
harness propose generate --save
|
|
213
|
+
harness propose review --diagnosis <id> --accept
|
|
214
|
+
```
|
|
422
215
|
|
|
423
|
-
|
|
216
|
+
### 项目自定义约束
|
|
424
217
|
|
|
425
218
|
```yaml
|
|
219
|
+
# .harness/custom-constraints.yml
|
|
426
220
|
custom_constraints:
|
|
427
221
|
no_fix_without_root_cause:
|
|
428
|
-
|
|
429
|
-
- my_new_exception
|
|
222
|
+
# 追加例外(保留内置)
|
|
430
223
|
extend_exceptions:
|
|
431
|
-
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
## 项目模板
|
|
437
|
-
|
|
438
|
-
提供多种项目模板:
|
|
439
|
-
|
|
440
|
-
- `node-api` - Node.js API 项目
|
|
441
|
-
- `nextjs-app` - Next.js 应用
|
|
442
|
-
- `python-api` - Python API 项目
|
|
443
|
-
|
|
444
|
-
```bash
|
|
445
|
-
# 指定项目类型
|
|
446
|
-
harness init --type node-api
|
|
447
|
-
```
|
|
448
|
-
|
|
449
|
-
## API 文档
|
|
450
|
-
|
|
451
|
-
### IronLawChecker
|
|
452
|
-
|
|
453
|
-
```typescript
|
|
454
|
-
class IronLawChecker {
|
|
455
|
-
static getInstance(): IronLawChecker;
|
|
456
|
-
|
|
457
|
-
checkAll(context: IronLawContext): Promise<IronLawResult[]>;
|
|
458
|
-
beforeExecution(context: IronLawContext): Promise<void>;
|
|
459
|
-
checkIronLaw(lawId: string, context: IronLawContext): Promise<IronLawResult>;
|
|
460
|
-
}
|
|
461
|
-
```
|
|
462
|
-
|
|
463
|
-
### CheckpointValidator
|
|
464
|
-
|
|
465
|
-
```typescript
|
|
466
|
-
class CheckpointValidator {
|
|
467
|
-
validate(checkpoints: Checkpoint[], context: CheckpointContext): Promise<CheckpointResult>;
|
|
468
|
-
}
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
### PassesGate
|
|
472
|
-
|
|
473
|
-
```typescript
|
|
474
|
-
class PassesGate {
|
|
475
|
-
constructor(config: PassesGateConfig);
|
|
476
|
-
|
|
477
|
-
setPasses(taskId: string, value: boolean, workDir: string): Promise<PassesGateResult>;
|
|
478
|
-
runTests(): Promise<TestResult>;
|
|
479
|
-
}
|
|
480
|
-
```
|
|
481
|
-
|
|
482
|
-
### ReviewGate
|
|
483
|
-
|
|
484
|
-
```typescript
|
|
485
|
-
class ReviewGate {
|
|
486
|
-
constructor(config: ReviewGateConfig);
|
|
487
|
-
|
|
488
|
-
check(context: GateContext): Promise<GateResult>;
|
|
489
|
-
setMinReviewers(count: number): void;
|
|
490
|
-
}
|
|
224
|
+
- my_special_case
|
|
225
|
+
# 或完全覆盖
|
|
226
|
+
exceptions:
|
|
227
|
+
- my_only_exception
|
|
491
228
|
```
|
|
492
229
|
|
|
493
|
-
###
|
|
230
|
+
### 在代码中使用
|
|
494
231
|
|
|
495
232
|
```typescript
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
233
|
+
import {
|
|
234
|
+
IronLawChecker,
|
|
235
|
+
PassesGate,
|
|
236
|
+
CheckpointValidator,
|
|
237
|
+
SessionStartup,
|
|
238
|
+
interceptOperation,
|
|
239
|
+
} from '@dommaker/harness';
|
|
502
240
|
|
|
503
|
-
|
|
241
|
+
// 铁律检查
|
|
242
|
+
const checker = IronLawChecker.getInstance();
|
|
243
|
+
const results = await checker.checkAll(context);
|
|
504
244
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
check(context: GateContext): Promise<GateResult>;
|
|
510
|
-
runBenchmark(context: GateContext): Promise<BenchmarkResult>;
|
|
511
|
-
setThresholds(thresholds: Partial<PerformanceThresholds>): void;
|
|
512
|
-
setTimeouts(options: { coverage?: number; benchmark?: number }): void;
|
|
513
|
-
}
|
|
514
|
-
```
|
|
245
|
+
// 测试门控
|
|
246
|
+
const gate = new PassesGate({ requireEvidence: true });
|
|
247
|
+
const passed = await gate.runTests();
|
|
515
248
|
|
|
516
|
-
|
|
249
|
+
// 检查点验证
|
|
250
|
+
const validator = CheckpointValidator.getInstance();
|
|
251
|
+
const result = await validator.validate(checkpoints, context);
|
|
517
252
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
constructor(config: ContractGateConfig);
|
|
521
|
-
|
|
522
|
-
check(context: GateContext): Promise<GateResult>;
|
|
523
|
-
}
|
|
253
|
+
// 拦截器(自动执行 enforcement)
|
|
254
|
+
await interceptOperation('task_completion_claim', context);
|
|
524
255
|
```
|
|
525
256
|
|
|
526
|
-
###
|
|
257
|
+
### 拦截器 Enforcement IDs
|
|
527
258
|
|
|
528
|
-
|
|
259
|
+
| enforcement | 说明 |
|
|
260
|
+
|-------------|------|
|
|
261
|
+
| `verify-completion` | 验证完成:运行测试 |
|
|
262
|
+
| `verify-e2e` | E2E 测试验证 |
|
|
263
|
+
| `debug-systematic` | 系统性调试 |
|
|
264
|
+
| `reuse-first` | 复用优先检查 |
|
|
265
|
+
| `update-capabilities` | CAPABILITIES 同步 |
|
|
266
|
+
| `tdd-cycle` | TDD 循环检查 |
|
|
267
|
+
| `passes-gate` | 测试门控 |
|
|
268
|
+
| `checkpoint-required` | 检查点必须通过 |
|
|
529
269
|
|
|
530
|
-
|
|
531
|
-
import { SpecAcceptanceGate } from '@dommaker/harness';
|
|
532
|
-
|
|
533
|
-
// 创建验收门禁
|
|
534
|
-
const acceptanceGate = new SpecAcceptanceGate({
|
|
535
|
-
tasksPath: './tasks.yml',
|
|
536
|
-
checkAllTasks: false,
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
// 检查单个任务
|
|
540
|
-
const result = await acceptanceGate.check({
|
|
541
|
-
projectPath: '/path/to/project',
|
|
542
|
-
taskId: 'task-001',
|
|
543
|
-
tasksPath: './tasks.yml',
|
|
544
|
-
});
|
|
545
|
-
|
|
546
|
-
// 检查所有任务
|
|
547
|
-
const allResults = await acceptanceGate.check({
|
|
548
|
-
projectPath: '/path/to/project',
|
|
549
|
-
checkAllTasks: true,
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
// 自定义验收条件
|
|
553
|
-
const customGate = new SpecAcceptanceGate({
|
|
554
|
-
customAcceptanceCriteria: {
|
|
555
|
-
'has-tests': async (task) => {
|
|
556
|
-
// 自定义验证逻辑
|
|
557
|
-
return true;
|
|
558
|
-
},
|
|
559
|
-
},
|
|
560
|
-
});
|
|
561
|
-
```
|
|
270
|
+
---
|
|
562
271
|
|
|
563
|
-
|
|
272
|
+
## CI 配置
|
|
564
273
|
|
|
565
274
|
```yaml
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
-
|
|
575
|
-
description: 登录失败显示错误提示
|
|
576
|
-
type: manual
|
|
577
|
-
required: true
|
|
578
|
-
```
|
|
579
|
-
|
|
580
|
-
### SessionStartup
|
|
581
|
-
|
|
582
|
-
```typescript
|
|
583
|
-
class SessionStartup {
|
|
584
|
-
constructor(workDir: string, checkpoints: StartupCheckpoints);
|
|
585
|
-
|
|
586
|
-
run(): Promise<{ success: boolean; results: StartupCheckpointResult[] }>;
|
|
587
|
-
getCurrentTask(): Promise<{ task: any; index: number } | null>;
|
|
588
|
-
generateReport(results: StartupCheckpointResult[]): string;
|
|
589
|
-
}
|
|
590
|
-
```
|
|
591
|
-
|
|
592
|
-
### CleanStateManager
|
|
593
|
-
|
|
594
|
-
```typescript
|
|
595
|
-
class CleanStateManager {
|
|
596
|
-
constructor(config: CleanStateConfig);
|
|
597
|
-
|
|
598
|
-
onSessionEnd(workDir: string, sessionInfo: SessionInfo): Promise<CleanStateResult>;
|
|
599
|
-
}
|
|
600
|
-
```
|
|
601
|
-
|
|
602
|
-
## 开发
|
|
603
|
-
|
|
604
|
-
```bash
|
|
605
|
-
# 安装依赖
|
|
606
|
-
npm install
|
|
607
|
-
|
|
608
|
-
# 构建
|
|
609
|
-
npm run build
|
|
610
|
-
|
|
611
|
-
# 测试
|
|
612
|
-
npm test
|
|
275
|
+
# .github/workflows/harness-check.yml
|
|
276
|
+
jobs:
|
|
277
|
+
harness-check:
|
|
278
|
+
runs-on: ubuntu-latest
|
|
279
|
+
steps:
|
|
280
|
+
- uses: actions/checkout@v4
|
|
281
|
+
- run: npm ci
|
|
282
|
+
- run: npx harness check
|
|
283
|
+
- run: npx harness passes-gate
|
|
613
284
|
```
|
|
614
285
|
|
|
615
|
-
## 许可证
|
|
616
|
-
|
|
617
|
-
MIT © dommaker
|
|
618
|
-
|
|
619
286
|
---
|
|
620
287
|
|
|
621
|
-
##
|
|
288
|
+
## Trace 系统
|
|
622
289
|
|
|
623
|
-
###
|
|
290
|
+
### Execution Trace
|
|
624
291
|
|
|
625
|
-
|
|
626
|
-
-
|
|
627
|
-
-
|
|
628
|
-
- 为 Agent 诊断提供数据基础
|
|
629
|
-
|
|
630
|
-
### 设计原则
|
|
631
|
-
|
|
632
|
-
| 原则 | 说明 |
|
|
633
|
-
|------|------|
|
|
634
|
-
| **零 Token 成本** | 记录和统计都不调用 LLM |
|
|
635
|
-
| **轻量记录** | 只记录核心字段,不记录代码片段 |
|
|
636
|
-
| **异步分析** | 统计每小时执行,异常检测每日执行 |
|
|
637
|
-
| **按需诊断** | Agent 仅在检测到异常时才介入 |
|
|
638
|
-
|
|
639
|
-
### Trace 数据结构
|
|
640
|
-
|
|
641
|
-
```typescript
|
|
642
|
-
interface ExecutionTrace {
|
|
643
|
-
constraintId: string; // 约束 ID
|
|
644
|
-
level: 'iron_law' | 'guideline' | 'tip';
|
|
645
|
-
timestamp: number; // Unix timestamp
|
|
646
|
-
result: 'pass' | 'fail' | 'bypassed';
|
|
647
|
-
operation?: string; // 触发条件
|
|
648
|
-
exceptionApplied?: string; // 例外类型
|
|
649
|
-
}
|
|
650
|
-
```
|
|
651
|
-
|
|
652
|
-
### 自动记录
|
|
653
|
-
|
|
654
|
-
约束检查时自动记录:
|
|
655
|
-
|
|
656
|
-
```typescript
|
|
657
|
-
import { checkConstraints } from '@dommaker/harness';
|
|
658
|
-
|
|
659
|
-
// 每次检查都会自动记录 trace
|
|
660
|
-
const result = await checkConstraints(context);
|
|
661
|
-
// Trace 已写入 .harness/traces/execution.log
|
|
662
|
-
```
|
|
663
|
-
|
|
664
|
-
### Trace 文件位置
|
|
292
|
+
记录约束检查结果,用于:
|
|
293
|
+
- 统计触发频率
|
|
294
|
+
- 检测异常(高绕过率、失败上升)
|
|
665
295
|
|
|
666
296
|
```
|
|
667
297
|
.harness/traces/
|
|
668
|
-
├── execution.log
|
|
669
|
-
├──
|
|
670
|
-
├── summary.json # 统计汇总
|
|
671
|
-
```
|
|
672
|
-
|
|
673
|
-
### 统计汇总
|
|
674
|
-
|
|
675
|
-
每小时自动执行:
|
|
676
|
-
|
|
677
|
-
```typescript
|
|
678
|
-
import { TraceAnalyzer } from '@dommaker/harness';
|
|
679
|
-
|
|
680
|
-
const analyzer = new TraceAnalyzer();
|
|
681
|
-
const summaries = analyzer.runHourlySummary();
|
|
682
|
-
|
|
683
|
-
// 输出:
|
|
684
|
-
// [
|
|
685
|
-
// { constraintId: 'no_fix_without_root_cause', passRate: 0.7, bypassRate: 0.1 },
|
|
686
|
-
// { constraintId: 'no_code_without_test', passRate: 0.9, bypassRate: 0 },
|
|
687
|
-
// ]
|
|
298
|
+
├── execution.log # 当前 trace
|
|
299
|
+
├── summary.json # 统计汇总
|
|
688
300
|
```
|
|
689
301
|
|
|
690
|
-
###
|
|
302
|
+
### Performance Trace
|
|
691
303
|
|
|
692
|
-
|
|
304
|
+
记录操作耗时,用于:
|
|
305
|
+
- 监控慢操作
|
|
306
|
+
- 检测超阈值
|
|
693
307
|
|
|
694
|
-
```typescript
|
|
695
|
-
const anomalies = analyzer.runDailyAnomalyCheck();
|
|
696
|
-
|
|
697
|
-
// 检测类型:
|
|
698
|
-
// - high_bypass_rate:绕过率 > 30%
|
|
699
|
-
// - rising_fail_rate:失败率上升趋势
|
|
700
|
-
// - exception_overuse:例外使用率 > 40%
|
|
701
308
|
```
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
```bash
|
|
706
|
-
# 查看 trace 文件统计
|
|
707
|
-
harness traces stats
|
|
708
|
-
|
|
709
|
-
# 查看最近 24 小时的约束汇总
|
|
710
|
-
harness traces summary --hours 24
|
|
711
|
-
|
|
712
|
-
# 检测异常
|
|
713
|
-
harness traces anomalies
|
|
714
|
-
|
|
715
|
-
# JSON 格式输出
|
|
716
|
-
harness traces summary --format json
|
|
717
|
-
|
|
718
|
-
# 运行诊断
|
|
719
|
-
harness diagnose run --hours 24 --save
|
|
720
|
-
|
|
721
|
-
# 查看诊断列表
|
|
722
|
-
harness diagnose list
|
|
723
|
-
|
|
724
|
-
# 生成提案
|
|
725
|
-
harness propose generate --save
|
|
726
|
-
|
|
727
|
-
# 审核提案
|
|
728
|
-
harness propose review --diagnosis <id> --accept
|
|
729
|
-
|
|
730
|
-
# 查看实施指导
|
|
731
|
-
harness propose implement --diagnosis <id>
|
|
309
|
+
.harness/logs/
|
|
310
|
+
├── performance.log # 性能日志
|
|
311
|
+
├── tokens.log # Token 使用
|
|
732
312
|
```
|
|
733
313
|
|
|
734
|
-
###
|
|
735
|
-
|
|
736
|
-
| 活动 | 频率 | Token 成本 |
|
|
737
|
-
|------|------|:----------:|
|
|
738
|
-
| Trace 记录 | 每次检查 | 0 |
|
|
739
|
-
| 统计汇总 | 每小时 | 0 |
|
|
740
|
-
| 异常检测 | 每日 | 0(未触发)~500(触发) |
|
|
741
|
-
| Agent 诊断 | 按需 | ~2000 |
|
|
314
|
+
### Failure Classification
|
|
742
315
|
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
---
|
|
316
|
+
错误分级(L1-L4):
|
|
746
317
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
### 概念
|
|
750
|
-
|
|
751
|
-
Performance Trace 是性能数据的轻量记录,用于:
|
|
752
|
-
- 监控关键操作耗时
|
|
753
|
-
- 检测性能异常(慢操作、超阈值)
|
|
754
|
-
- 统计 Token 使用和上下文大小
|
|
755
|
-
- 为性能优化提供数据基础
|
|
756
|
-
|
|
757
|
-
### 设计原则
|
|
758
|
-
|
|
759
|
-
| 原则 | 说明 |
|
|
318
|
+
| 等级 | 处理 |
|
|
760
319
|
|------|------|
|
|
761
|
-
|
|
|
762
|
-
|
|
|
763
|
-
|
|
|
764
|
-
|
|
|
765
|
-
|
|
766
|
-
### Trace 数据结构
|
|
767
|
-
|
|
768
|
-
```typescript
|
|
769
|
-
interface PerformanceTrace {
|
|
770
|
-
operation: string; // 操作名称
|
|
771
|
-
startTime: number; // 开始时间戳
|
|
772
|
-
duration: number; // 耗时(毫秒)
|
|
773
|
-
status: 'ok' | 'exceeded' | 'error';
|
|
774
|
-
threshold?: number; // 配置的阈值
|
|
775
|
-
metadata?: Record<string, unknown>;
|
|
776
|
-
}
|
|
777
|
-
```
|
|
778
|
-
|
|
779
|
-
### API 使用
|
|
780
|
-
|
|
781
|
-
```typescript
|
|
782
|
-
import { PerformanceCollector, PerformanceAnalyzer } from '@dommaker/harness';
|
|
783
|
-
|
|
784
|
-
// 创建收集器
|
|
785
|
-
const collector = new PerformanceCollector({
|
|
786
|
-
logFile: '.harness/logs/performance.log',
|
|
787
|
-
thresholds: {
|
|
788
|
-
extract: 1000, // 提取操作阈值 1s
|
|
789
|
-
transform: 500, // 转换操作阈值 500ms
|
|
790
|
-
invoke: 10000, // 调用操作阈值 10s
|
|
791
|
-
},
|
|
792
|
-
});
|
|
793
|
-
|
|
794
|
-
// 记录操作
|
|
795
|
-
await collector.recordOk('extract', 150, { contextSize: 5000 });
|
|
796
|
-
await collector.recordExceeded('invoke', 12000, 10000, { agent: 'skill-agent' });
|
|
797
|
-
|
|
798
|
-
// 分析统计
|
|
799
|
-
const analyzer = new PerformanceAnalyzer();
|
|
800
|
-
const summaries = analyzer.summarize(traces);
|
|
801
|
-
const anomalies = analyzer.detectAnomalies(traces);
|
|
802
|
-
|
|
803
|
-
// 生成报告
|
|
804
|
-
const report = analyzer.generateReport(summaries, anomalies);
|
|
805
|
-
```
|
|
806
|
-
|
|
807
|
-
### 文件位置
|
|
808
|
-
|
|
809
|
-
```
|
|
810
|
-
.harness/logs/
|
|
811
|
-
├── performance.log # 性能日志
|
|
812
|
-
├── performance-summary.json # 统计汇总
|
|
813
|
-
└── tokens.log # Token 使用日志
|
|
814
|
-
```
|
|
815
|
-
|
|
816
|
-
### 与 TraceCollector 对比
|
|
817
|
-
|
|
818
|
-
| 能力 | TraceCollector | PerformanceCollector |
|
|
819
|
-
|------|----------------|---------------------|
|
|
820
|
-
| **监控目标** | 约束检查结果 | 操作耗时 |
|
|
821
|
-
| **监控"什么"** | 对不对 | 快不快 |
|
|
822
|
-
| **异常类型** | 高绕过率、失败率上升 | 慢操作、超阈值 |
|
|
823
|
-
| **存储路径** | `.harness/logs/traces.log` | `.harness/logs/performance.log` |
|
|
320
|
+
| L1 | 自动重试 |
|
|
321
|
+
| L2 | 人工审核 |
|
|
322
|
+
| L3 | 开会讨论 |
|
|
323
|
+
| L4 | 回滚 |
|
|
824
324
|
|
|
825
325
|
---
|
|
826
326
|
|
|
827
|
-
##
|
|
828
|
-
|
|
829
|
-
### 概念
|
|
830
|
-
|
|
831
|
-
Failure Classification 提供通用的错误分类和记录能力,用于:
|
|
832
|
-
- 统一错误分类标准
|
|
833
|
-
- 分级处理失败(L1-L4)
|
|
834
|
-
- 记录失败历史供分析
|
|
835
|
-
|
|
836
|
-
### 设计原则
|
|
837
|
-
|
|
838
|
-
| 原则 | 说明 |
|
|
839
|
-
|------|------|
|
|
840
|
-
| **零业务逻辑** | 只提供类型 + 分类 + 记录能力 |
|
|
841
|
-
| **可扩展规则** | 支持自定义分类规则 |
|
|
842
|
-
| **文件存储** | 追加写入,单行 JSON 格式 |
|
|
843
|
-
|
|
844
|
-
### 错误类型
|
|
327
|
+
## 开发
|
|
845
328
|
|
|
846
|
-
```
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
DEPENDENCY_BLOCKED = 'DEPENDENCY_BLOCKED', // 依赖阻塞
|
|
851
|
-
CONTEXT_OVERFLOW = 'CONTEXT_OVERFLOW', // 上下文溢出
|
|
852
|
-
TIMEOUT = 'TIMEOUT', // 超时
|
|
853
|
-
NETWORK_ERROR = 'NETWORK_ERROR', // 网络错误
|
|
854
|
-
AGENT_ERROR = 'AGENT_ERROR', // Agent 错误
|
|
855
|
-
TOOL_ERROR = 'TOOL_ERROR', // 工具错误
|
|
856
|
-
VALIDATION_ERROR = 'VALIDATION_ERROR', // 验证错误
|
|
857
|
-
UNKNOWN = 'UNKNOWN', // 未知错误
|
|
858
|
-
}
|
|
329
|
+
```bash
|
|
330
|
+
npm install
|
|
331
|
+
npm run build
|
|
332
|
+
npm test
|
|
859
333
|
```
|
|
860
334
|
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
| 等级 | 说明 | 处理策略 |
|
|
864
|
-
|------|------|---------|
|
|
865
|
-
| L1 | 自动重试 | 重试、降级 |
|
|
866
|
-
| L2 | 需要干预 | 人工审核 |
|
|
867
|
-
| L3 | 严重问题 | 开会讨论 |
|
|
868
|
-
| L4 | 致命错误 | 回滚 |
|
|
869
|
-
|
|
870
|
-
### API 使用
|
|
871
|
-
|
|
872
|
-
```typescript
|
|
873
|
-
import {
|
|
874
|
-
ErrorClassifier,
|
|
875
|
-
FailureRecorder,
|
|
876
|
-
ErrorType,
|
|
877
|
-
FailureLevel,
|
|
878
|
-
classifyError,
|
|
879
|
-
} from '@dommaker/harness';
|
|
880
|
-
|
|
881
|
-
// 快速分类
|
|
882
|
-
const type = classifyError(new Error('test failed'));
|
|
883
|
-
// type === ErrorType.TEST_FAILED
|
|
884
|
-
|
|
885
|
-
// 完整分类器
|
|
886
|
-
const classifier = new ErrorClassifier({
|
|
887
|
-
rules: [
|
|
888
|
-
{
|
|
889
|
-
type: ErrorType.CUSTOM_ERROR,
|
|
890
|
-
keywords: ['custom', 'specific'],
|
|
891
|
-
level: FailureLevel.L2,
|
|
892
|
-
},
|
|
893
|
-
],
|
|
894
|
-
});
|
|
895
|
-
|
|
896
|
-
const result = classifier.classify(new Error('custom error'));
|
|
897
|
-
// result.type, result.level, result.matchedRule
|
|
898
|
-
|
|
899
|
-
// 失败记录
|
|
900
|
-
const recorder = new FailureRecorder({
|
|
901
|
-
logFile: '.harness/logs/failures.log',
|
|
902
|
-
});
|
|
903
|
-
|
|
904
|
-
await recorder.record({
|
|
905
|
-
type: ErrorType.TEST_FAILED,
|
|
906
|
-
level: FailureLevel.L1,
|
|
907
|
-
message: 'Test failed',
|
|
908
|
-
timestamp: Date.now(),
|
|
909
|
-
});
|
|
910
|
-
|
|
911
|
-
// 获取统计
|
|
912
|
-
const stats = await recorder.getStats();
|
|
913
|
-
// { total, byType, byLevel }
|
|
914
|
-
```
|
|
335
|
+
---
|
|
915
336
|
|
|
916
|
-
|
|
337
|
+
## 许可证
|
|
917
338
|
|
|
918
|
-
|
|
919
|
-
|------|---------------------|-----------------|
|
|
920
|
-
| **监控目标** | 操作耗时 | 错误分类 |
|
|
921
|
-
| **存储内容** | 性能指标 | 失败记录 |
|
|
922
|
-
| **分析维度** | 慢操作、超阈值 | 错误类型分布、失败等级 |
|
|
339
|
+
MIT © dommaker
|