@dommaker/harness 1.1.0 → 1.2.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/CHANGELOG.md +19 -2
- package/README.md +2 -4
- package/bin/harness.js +12 -37
- package/dist/cli/commands/check.d.ts +2 -2
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +7 -32
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/definitions.d.ts +2 -0
- package/dist/cli/commands/definitions.d.ts.map +1 -1
- package/dist/cli/commands/definitions.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +6 -37
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/knowledge.d.ts.map +1 -1
- package/dist/cli/commands/knowledge.js +1 -12
- package/dist/cli/commands/knowledge.js.map +1 -1
- package/dist/cli/commands/report.d.ts.map +1 -1
- package/dist/cli/commands/report.js +0 -2
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +2 -11
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/context/index.d.ts +9 -6
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +18 -20
- package/dist/context/index.js.map +1 -1
- package/dist/core/constraints/capabilities-parser.d.ts +3 -2
- package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
- package/dist/core/constraints/capabilities-parser.js +25 -47
- package/dist/core/constraints/capabilities-parser.js.map +1 -1
- package/dist/core/constraints/checker.d.ts +32 -33
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +38 -128
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/index.d.ts +2 -1
- package/dist/core/constraints/checkers/index.d.ts.map +1 -1
- package/dist/core/constraints/checkers/index.js +3 -0
- package/dist/core/constraints/checkers/index.js.map +1 -1
- package/dist/core/constraints/checkers/types.d.ts +25 -0
- package/dist/core/constraints/checkers/types.d.ts.map +1 -1
- package/dist/core/constraints/checkers/types.js +24 -0
- package/dist/core/constraints/checkers/types.js.map +1 -1
- package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
- package/dist/core/constraints/definitions/guidelines.js +0 -2
- package/dist/core/constraints/definitions/guidelines.js.map +1 -1
- package/dist/core/constraints/definitions/prompts.d.ts.map +1 -1
- package/dist/core/constraints/definitions/prompts.js +0 -5
- package/dist/core/constraints/definitions/prompts.js.map +1 -1
- package/dist/core/constraints/index.d.ts +1 -2
- package/dist/core/constraints/index.d.ts.map +1 -1
- package/dist/core/constraints/index.js +1 -7
- package/dist/core/constraints/index.js.map +1 -1
- package/dist/core/constraints/usage-report.d.ts +1 -2
- package/dist/core/constraints/usage-report.d.ts.map +1 -1
- package/dist/core/constraints/usage-report.js +2 -5
- package/dist/core/constraints/usage-report.js.map +1 -1
- package/dist/core/effective-constraints.d.ts +24 -4
- package/dist/core/effective-constraints.d.ts.map +1 -1
- package/dist/core/effective-constraints.js +28 -7
- package/dist/core/effective-constraints.js.map +1 -1
- package/dist/core/effective-set.d.ts +30 -0
- package/dist/core/effective-set.d.ts.map +1 -0
- package/dist/core/effective-set.js +35 -0
- package/dist/core/effective-set.js.map +1 -0
- package/dist/core/index.d.ts +13 -6
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +44 -21
- package/dist/core/index.js.map +1 -1
- package/dist/core/project-config-loader.d.ts +3 -6
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +47 -61
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/failure/constraint-handler.d.ts +1 -1
- package/dist/failure/constraint-handler.js +1 -1
- package/dist/gates/checker-gate.d.ts +1 -4
- package/dist/gates/checker-gate.d.ts.map +1 -1
- package/dist/gates/checker-gate.js +3 -11
- package/dist/gates/checker-gate.js.map +1 -1
- package/dist/gates/definitions.d.ts +9 -38
- package/dist/gates/definitions.d.ts.map +1 -1
- package/dist/gates/definitions.js +24 -13
- package/dist/gates/definitions.js.map +1 -1
- package/dist/gates/effective-gates.d.ts.map +1 -1
- package/dist/gates/effective-gates.js +14 -18
- package/dist/gates/effective-gates.js.map +1 -1
- package/dist/gates/index.d.ts +1 -1
- package/dist/gates/index.d.ts.map +1 -1
- package/dist/gates/index.js.map +1 -1
- package/dist/hooks/bootstrap.d.ts.map +1 -1
- package/dist/hooks/bootstrap.js +0 -3
- package/dist/hooks/bootstrap.js.map +1 -1
- package/dist/index.d.ts +43 -53
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +180 -138
- package/dist/index.js.map +1 -1
- package/dist/knowledge/query.d.ts +15 -0
- package/dist/knowledge/query.d.ts.map +1 -1
- package/dist/knowledge/query.js +23 -0
- package/dist/knowledge/query.js.map +1 -1
- package/dist/monitoring/analyzer-base.d.ts +0 -4
- package/dist/monitoring/analyzer-base.d.ts.map +1 -1
- package/dist/monitoring/analyzer-base.js +0 -21
- package/dist/monitoring/analyzer-base.js.map +1 -1
- package/dist/monitoring/index.d.ts +6 -12
- package/dist/monitoring/index.d.ts.map +1 -1
- package/dist/monitoring/index.js +13 -29
- package/dist/monitoring/index.js.map +1 -1
- package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
- package/dist/monitoring/trace-analyzer.js +2 -68
- package/dist/monitoring/trace-analyzer.js.map +1 -1
- package/dist/monitoring/traces.d.ts +2 -6
- package/dist/monitoring/traces.d.ts.map +1 -1
- package/dist/monitoring/traces.js +0 -14
- package/dist/monitoring/traces.js.map +1 -1
- package/dist/presets/index.d.ts +2 -2
- package/dist/presets/index.d.ts.map +1 -1
- package/dist/presets/index.js +3 -4
- package/dist/presets/index.js.map +1 -1
- package/dist/presets/standard.d.ts +10 -22
- package/dist/presets/standard.d.ts.map +1 -1
- package/dist/presets/standard.js +15 -75
- package/dist/presets/standard.js.map +1 -1
- package/dist/types/constraint.d.ts +1 -29
- package/dist/types/constraint.d.ts.map +1 -1
- package/dist/types/constraint.js +1 -1
- package/dist/types/constraint.js.map +1 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +0 -4
- package/dist/types/index.js.map +1 -1
- package/dist/types/project-config.d.ts +4 -8
- package/dist/types/project-config.d.ts.map +1 -1
- package/dist/types/trace.d.ts +9 -22
- package/dist/types/trace.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/CONTEXT.md +5 -7
- package/src/__tests__/checker-extra.test.ts +80 -139
- package/src/__tests__/checker.test.ts +0 -376
- package/src/__tests__/project-config-loader-extra.test.ts +42 -29
- package/src/__tests__/public-exports.test.ts +138 -0
- package/src/__tests__/trace-analyzer-extra.test.ts +6 -86
- package/src/__tests__/trace-analyzer.test.ts +4 -5
- package/src/__tests__/trace-collector.test.ts +0 -11
- package/src/__tests__/traces.test.ts +3 -22
- package/src/cli/commands/CONTEXT.md +2 -2
- package/src/cli/commands/__tests__/check-skip-output.test.ts +10 -7
- package/src/cli/commands/__tests__/check.test.ts +29 -69
- package/src/cli/commands/__tests__/constraints-report.test.ts +1 -1
- package/src/cli/commands/__tests__/knowledge.test.ts +90 -1
- package/src/cli/commands/__tests__/registry.test.ts +8 -6
- package/src/cli/commands/__tests__/status-extra.test.ts +6 -28
- package/src/cli/commands/__tests__/status.test.ts +6 -21
- package/src/cli/commands/check.ts +8 -34
- package/src/cli/commands/definitions.ts +2 -0
- package/src/cli/commands/init.ts +6 -37
- package/src/cli/commands/knowledge.ts +1 -16
- package/src/cli/commands/report.ts +0 -2
- package/src/cli/commands/status.ts +2 -12
- package/src/context/index.ts +29 -6
- package/src/core/CONTEXT.md +4 -3
- package/src/core/__tests__/effective-set.test.ts +80 -0
- package/src/core/constraints/capabilities-parser.ts +43 -49
- package/src/core/constraints/checker.ts +56 -147
- package/src/core/constraints/checkers/index.ts +2 -1
- package/src/core/constraints/checkers/types.ts +42 -0
- package/src/core/constraints/definitions/guidelines.ts +0 -2
- package/src/core/constraints/definitions/prompts.ts +0 -5
- package/src/core/constraints/index.ts +2 -17
- package/src/core/constraints/usage-report.ts +5 -8
- package/src/core/effective-constraints.ts +35 -7
- package/src/core/effective-set.ts +56 -0
- package/src/core/index.ts +80 -6
- package/src/core/project-config-loader.ts +53 -68
- package/src/failure/CONTEXT.md +1 -1
- package/src/failure/constraint-handler.ts +1 -1
- package/src/gates/CONTEXT.md +3 -3
- package/src/gates/checker-gate.ts +4 -12
- package/src/gates/definitions.ts +27 -50
- package/src/gates/effective-gates.ts +14 -21
- package/src/gates/index.ts +1 -1
- package/src/hooks/bootstrap.ts +0 -3
- package/src/index.ts +384 -137
- package/src/knowledge/CONTEXT.md +2 -2
- package/src/knowledge/__tests__/query.test.ts +64 -0
- package/src/knowledge/query.ts +28 -0
- package/src/monitoring/CONTEXT.md +7 -13
- package/src/monitoring/__tests__/traces.test.ts +0 -10
- package/src/monitoring/analyzer-base.ts +0 -22
- package/src/monitoring/index.ts +6 -12
- package/src/monitoring/trace-analyzer.ts +2 -73
- package/src/monitoring/traces.ts +2 -22
- package/src/presets/__tests__/standard.test.ts +48 -69
- package/src/presets/index.ts +3 -5
- package/src/presets/standard.ts +14 -79
- package/src/spec/CONTEXT.md +5 -13
- package/src/types/constraint.ts +1 -51
- package/src/types/index.ts +0 -12
- package/src/types/project-config.ts +4 -10
- package/src/types/trace.ts +9 -34
- package/dist/core/constraints/interceptor.d.ts +0 -38
- package/dist/core/constraints/interceptor.d.ts.map +0 -1
- package/dist/core/constraints/interceptor.js +0 -166
- package/dist/core/constraints/interceptor.js.map +0 -1
- package/dist/dashboard/data.d.ts +0 -31
- package/dist/dashboard/data.d.ts.map +0 -1
- package/dist/dashboard/data.js +0 -81
- package/dist/dashboard/data.js.map +0 -1
- package/dist/dashboard/index.d.ts +0 -4
- package/dist/dashboard/index.d.ts.map +0 -1
- package/dist/dashboard/index.js +0 -20
- package/dist/dashboard/index.js.map +0 -1
- package/dist/dashboard/stats.d.ts +0 -20
- package/dist/dashboard/stats.d.ts.map +0 -1
- package/dist/dashboard/stats.js +0 -115
- package/dist/dashboard/stats.js.map +0 -1
- package/dist/dashboard/types.d.ts +0 -110
- package/dist/dashboard/types.d.ts.map +0 -1
- package/dist/dashboard/types.js +0 -8
- package/dist/dashboard/types.js.map +0 -1
- package/dist/monitoring/constraint-doctor.d.ts +0 -82
- package/dist/monitoring/constraint-doctor.d.ts.map +0 -1
- package/dist/monitoring/constraint-doctor.js +0 -191
- package/dist/monitoring/constraint-doctor.js.map +0 -1
- package/dist/monitoring/diagnosis-rules.d.ts +0 -18
- package/dist/monitoring/diagnosis-rules.d.ts.map +0 -1
- package/dist/monitoring/diagnosis-rules.js +0 -119
- package/dist/monitoring/diagnosis-rules.js.map +0 -1
- package/dist/monitoring/knowledge-doctor.d.ts +0 -78
- package/dist/monitoring/knowledge-doctor.d.ts.map +0 -1
- package/dist/monitoring/knowledge-doctor.js +0 -266
- package/dist/monitoring/knowledge-doctor.js.map +0 -1
- package/dist/monitoring/knowledge-evolver.d.ts +0 -72
- package/dist/monitoring/knowledge-evolver.d.ts.map +0 -1
- package/dist/monitoring/knowledge-evolver.js +0 -205
- package/dist/monitoring/knowledge-evolver.js.map +0 -1
- package/dist/monitoring/performance-analyzer.d.ts +0 -92
- package/dist/monitoring/performance-analyzer.d.ts.map +0 -1
- package/dist/monitoring/performance-analyzer.js +0 -343
- package/dist/monitoring/performance-analyzer.js.map +0 -1
- package/dist/monitoring/performance-collector.d.ts +0 -103
- package/dist/monitoring/performance-collector.d.ts.map +0 -1
- package/dist/monitoring/performance-collector.js +0 -298
- package/dist/monitoring/performance-collector.js.map +0 -1
- package/dist/safety/index.d.ts +0 -6
- package/dist/safety/index.d.ts.map +0 -1
- package/dist/safety/index.js +0 -22
- package/dist/safety/index.js.map +0 -1
- package/dist/safety/input-guardrail.d.ts +0 -36
- package/dist/safety/input-guardrail.d.ts.map +0 -1
- package/dist/safety/input-guardrail.js +0 -118
- package/dist/safety/input-guardrail.js.map +0 -1
- package/dist/safety/output-guardrail.d.ts +0 -39
- package/dist/safety/output-guardrail.d.ts.map +0 -1
- package/dist/safety/output-guardrail.js +0 -147
- package/dist/safety/output-guardrail.js.map +0 -1
- package/dist/safety/sandbox.d.ts +0 -45
- package/dist/safety/sandbox.d.ts.map +0 -1
- package/dist/safety/sandbox.js +0 -134
- package/dist/safety/sandbox.js.map +0 -1
- package/dist/safety/tool-guardrail.d.ts +0 -51
- package/dist/safety/tool-guardrail.d.ts.map +0 -1
- package/dist/safety/tool-guardrail.js +0 -147
- package/dist/safety/tool-guardrail.js.map +0 -1
- package/dist/safety/types.d.ts +0 -104
- package/dist/safety/types.d.ts.map +0 -1
- package/dist/safety/types.js +0 -6
- package/dist/safety/types.js.map +0 -1
- package/dist/spec/annotation-checker.d.ts +0 -47
- package/dist/spec/annotation-checker.d.ts.map +0 -1
- package/dist/spec/annotation-checker.js +0 -279
- package/dist/spec/annotation-checker.js.map +0 -1
- package/dist/types/enforcement.d.ts +0 -42
- package/dist/types/enforcement.d.ts.map +0 -1
- package/dist/types/enforcement.js +0 -6
- package/dist/types/enforcement.js.map +0 -1
- package/dist/types/monitoring-types.d.ts +0 -53
- package/dist/types/monitoring-types.d.ts.map +0 -1
- package/dist/types/monitoring-types.js +0 -10
- package/dist/types/monitoring-types.js.map +0 -1
- package/dist/types/performance.d.ts +0 -204
- package/dist/types/performance.d.ts.map +0 -1
- package/dist/types/performance.js +0 -12
- package/dist/types/performance.js.map +0 -1
- package/dist/verification/index.d.ts +0 -4
- package/dist/verification/index.d.ts.map +0 -1
- package/dist/verification/index.js +0 -20
- package/dist/verification/index.js.map +0 -1
- package/dist/verification/loop.d.ts +0 -30
- package/dist/verification/loop.d.ts.map +0 -1
- package/dist/verification/loop.js +0 -114
- package/dist/verification/loop.js.map +0 -1
- package/dist/verification/rules-based.d.ts +0 -40
- package/dist/verification/rules-based.d.ts.map +0 -1
- package/dist/verification/rules-based.js +0 -130
- package/dist/verification/rules-based.js.map +0 -1
- package/dist/verification/types.d.ts +0 -69
- package/dist/verification/types.d.ts.map +0 -1
- package/dist/verification/types.js +0 -6
- package/dist/verification/types.js.map +0 -1
- package/src/__tests__/annotation-checker.test.ts +0 -183
- package/src/__tests__/constraint-doctor.test.ts +0 -271
- package/src/__tests__/doctor-extra.test.ts +0 -155
- package/src/__tests__/extend-exceptions.test.ts +0 -149
- package/src/__tests__/interceptor.test.ts +0 -89
- package/src/__tests__/performance-analyzer.test.ts +0 -499
- package/src/__tests__/performance-collector.test.ts +0 -276
- package/src/__tests__/presets.test.ts +0 -65
- package/src/core/constraints/__tests__/interceptor.test.ts +0 -253
- package/src/core/constraints/interceptor.ts +0 -214
- package/src/dashboard/CONTEXT.md +0 -21
- package/src/dashboard/__tests__/data.test.ts +0 -111
- package/src/dashboard/__tests__/stats.test.ts +0 -159
- package/src/dashboard/data.ts +0 -103
- package/src/dashboard/index.ts +0 -3
- package/src/dashboard/stats.ts +0 -127
- package/src/dashboard/types.ts +0 -130
- package/src/monitoring/__tests__/knowledge-doctor.test.ts +0 -278
- package/src/monitoring/__tests__/knowledge-evolver.test.ts +0 -368
- package/src/monitoring/__tests__/performance-analyzer.test.ts +0 -137
- package/src/monitoring/__tests__/performance-collector.test.ts +0 -331
- package/src/monitoring/constraint-doctor.ts +0 -239
- package/src/monitoring/diagnosis-rules.ts +0 -132
- package/src/monitoring/knowledge-doctor.ts +0 -322
- package/src/monitoring/knowledge-evolver.ts +0 -289
- package/src/monitoring/performance-analyzer.ts +0 -400
- package/src/monitoring/performance-collector.ts +0 -326
- package/src/safety/CONTEXT.md +0 -23
- package/src/safety/__tests__/input-guardrail.test.ts +0 -105
- package/src/safety/__tests__/output-guardrail.test.ts +0 -108
- package/src/safety/__tests__/sandbox.test.ts +0 -158
- package/src/safety/__tests__/tool-guardrail.test.ts +0 -127
- package/src/safety/index.ts +0 -5
- package/src/safety/input-guardrail.ts +0 -133
- package/src/safety/output-guardrail.ts +0 -170
- package/src/safety/sandbox.ts +0 -148
- package/src/safety/tool-guardrail.ts +0 -176
- package/src/safety/types.ts +0 -124
- package/src/spec/__tests__/annotation-checker.test.ts +0 -294
- package/src/spec/annotation-checker.ts +0 -320
- package/src/types/enforcement.ts +0 -48
- package/src/types/monitoring-types.ts +0 -68
- package/src/types/performance.ts +0 -295
- package/src/verification/CONTEXT.md +0 -23
- package/src/verification/__tests__/loop.test.ts +0 -303
- package/src/verification/__tests__/rules-based.test.ts +0 -240
- package/src/verification/index.ts +0 -3
- package/src/verification/loop.ts +0 -137
- package/src/verification/rules-based.ts +0 -152
- package/src/verification/types.ts +0 -81
package/src/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @dommaker/harness - 主入口
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* 通用工程约束框架
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* 约束体系(ADR-0001 kind 二元):
|
|
7
7
|
* - check:可执行检查(Iron Laws 阻断 / Guidelines 告警)
|
|
8
8
|
* - prompt:纯文本注入,不参与检查
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
10
|
* 门禁系统:
|
|
11
11
|
* - PassesGate:测试门控
|
|
12
12
|
* - ReviewGate:审查门禁
|
|
@@ -14,176 +14,423 @@
|
|
|
14
14
|
* - PerformanceGate:性能门禁
|
|
15
15
|
* - ContractGate:契约门禁
|
|
16
16
|
* - CheckpointValidator:检查点验证
|
|
17
|
+
*
|
|
18
|
+
* 公共导出(ADR-0003):显式清单,禁 export *。
|
|
19
|
+
* 收录标准:属 harness 定位(约束数据 / 执行引擎 / 注入工具 / 知识基建)、
|
|
20
|
+
* 实现真实可用、无同名冲突。内部 seam
|
|
21
|
+
* (ConstraintChecker / constraintChecker / ProjectConfigLoader)不进公共清单。
|
|
17
22
|
*/
|
|
18
23
|
|
|
19
24
|
// ========================================
|
|
20
|
-
//
|
|
21
|
-
// ========================================
|
|
22
|
-
export
|
|
25
|
+
// 约束类型(三层体系 + kind 二元)
|
|
26
|
+
// ========================================
|
|
27
|
+
export {
|
|
28
|
+
ConstraintViolationError,
|
|
29
|
+
} from './types/constraint';
|
|
30
|
+
export type {
|
|
31
|
+
Constraint,
|
|
32
|
+
ConstraintId,
|
|
33
|
+
ConstraintKind,
|
|
34
|
+
ConstraintLevel,
|
|
35
|
+
ConstraintTrigger,
|
|
36
|
+
ConstraintContext,
|
|
37
|
+
ConstraintResult,
|
|
38
|
+
ConstraintCheckResult,
|
|
39
|
+
IronLawContext,
|
|
40
|
+
} from './types/constraint';
|
|
23
41
|
|
|
24
42
|
// ========================================
|
|
25
|
-
//
|
|
26
|
-
// ========================================
|
|
27
|
-
export
|
|
43
|
+
// 约束数据(内置定义 + 生效集)
|
|
44
|
+
// ========================================
|
|
45
|
+
export {
|
|
46
|
+
IRON_LAWS,
|
|
47
|
+
GUIDELINES,
|
|
48
|
+
PROMPTS,
|
|
49
|
+
getAllConstraints,
|
|
50
|
+
getConstraint,
|
|
51
|
+
findConstraintsByTrigger,
|
|
52
|
+
} from './core/constraints/definitions';
|
|
53
|
+
export {
|
|
54
|
+
getEffectiveConstraints,
|
|
55
|
+
lintEffectiveConfig,
|
|
56
|
+
} from './core/effective-constraints';
|
|
57
|
+
export type { EffectiveConfigLint } from './core/effective-constraints';
|
|
28
58
|
|
|
29
59
|
// ========================================
|
|
30
|
-
//
|
|
60
|
+
// 约束检查引擎(便捷 API;options 统一签名,ADR-0003)
|
|
31
61
|
// ========================================
|
|
32
|
-
export
|
|
62
|
+
export {
|
|
63
|
+
checkConstraint,
|
|
64
|
+
checkConstraints,
|
|
65
|
+
checkBeforeExecution,
|
|
66
|
+
} from './core/constraints/checker';
|
|
67
|
+
export type { CheckConstraintsOptions } from './core/constraints/checker';
|
|
33
68
|
|
|
34
69
|
// ========================================
|
|
35
|
-
//
|
|
70
|
+
// 约束缓存与注入渲染
|
|
36
71
|
// ========================================
|
|
37
|
-
export
|
|
72
|
+
export { CheckCache } from './core/constraints/check-cache';
|
|
73
|
+
export type { CheckCacheConfig, CheckSamplingConfig } from './core/constraints/check-cache';
|
|
74
|
+
export { renderConstraintsByTrigger } from './core/constraints/agent-prompt-renderer';
|
|
75
|
+
export type { RenderConstraintsByTriggerOptions } from './core/constraints/agent-prompt-renderer';
|
|
76
|
+
export {
|
|
77
|
+
CONSTRAINTS_START_MARKER,
|
|
78
|
+
CONSTRAINTS_END_MARKER,
|
|
79
|
+
renderConstraintsSection,
|
|
80
|
+
} from './core/constraints/injection-renderer';
|
|
38
81
|
|
|
39
82
|
// ========================================
|
|
40
|
-
//
|
|
41
|
-
// ========================================
|
|
42
|
-
export
|
|
83
|
+
// 检查点与验证器
|
|
84
|
+
// ========================================
|
|
85
|
+
export type {
|
|
86
|
+
Checkpoint,
|
|
87
|
+
CheckpointCheck,
|
|
88
|
+
CheckpointContext,
|
|
89
|
+
CheckpointResult,
|
|
90
|
+
CheckConfig,
|
|
91
|
+
CheckResult,
|
|
92
|
+
CheckType,
|
|
93
|
+
} from './types/checkpoint';
|
|
94
|
+
export {
|
|
95
|
+
CheckpointValidator,
|
|
96
|
+
PassesGate,
|
|
97
|
+
createPassesGate,
|
|
98
|
+
CSOValidator,
|
|
99
|
+
} from './core/validators';
|
|
100
|
+
export type { CSOIssue, CSOValidationResult } from './core/validators';
|
|
101
|
+
export type {
|
|
102
|
+
PassesGateConfig,
|
|
103
|
+
PassesGateResult,
|
|
104
|
+
PassesGateCheckResult,
|
|
105
|
+
PassesGateViolation,
|
|
106
|
+
PassesGateExtension,
|
|
107
|
+
TestResult,
|
|
108
|
+
DynamicTask,
|
|
109
|
+
TaskTestResult,
|
|
110
|
+
ExtensionTestResult,
|
|
111
|
+
} from './types/passes-gate';
|
|
112
|
+
export type {
|
|
113
|
+
StepMeta,
|
|
114
|
+
ToolMeta,
|
|
115
|
+
WorkflowMeta,
|
|
116
|
+
} from './types/cso';
|
|
43
117
|
|
|
44
118
|
// ========================================
|
|
45
|
-
//
|
|
46
|
-
// ========================================
|
|
47
|
-
export
|
|
119
|
+
// 会话启动 / 净室状态
|
|
120
|
+
// ========================================
|
|
121
|
+
export {
|
|
122
|
+
SessionStartup,
|
|
123
|
+
createSessionStartup,
|
|
124
|
+
DEFAULT_CODE_CHECKPOINTS,
|
|
125
|
+
MINIMAL_CHECKPOINTS,
|
|
126
|
+
CleanStateManager,
|
|
127
|
+
createCleanStateManager,
|
|
128
|
+
} from './core/session';
|
|
129
|
+
export type {
|
|
130
|
+
StartupCheckpoints,
|
|
131
|
+
StartupCheckpointType,
|
|
132
|
+
StartupCheckpointResult,
|
|
133
|
+
CleanStateConfig,
|
|
134
|
+
CleanStateResult,
|
|
135
|
+
DetectedBug,
|
|
136
|
+
TaskListJson,
|
|
137
|
+
TaskStepStatus,
|
|
138
|
+
SessionInfo,
|
|
139
|
+
} from './types/session';
|
|
140
|
+
// 与 passes-gate 同名类型的 session 版(沿用既有别名)
|
|
141
|
+
export { DynamicTask as ExtendedDynamicTask, TaskTestResult as ExtendedTaskTestResult } from './types/session';
|
|
48
142
|
|
|
49
143
|
// ========================================
|
|
50
|
-
//
|
|
51
|
-
// ========================================
|
|
52
|
-
export
|
|
144
|
+
// Spec 验证(已接线的 spec 故事:validator + SpecAcceptanceGate)
|
|
145
|
+
// ========================================
|
|
146
|
+
export { SpecValidator, validateSpec, validateAllSpecs } from './core/spec/validator';
|
|
147
|
+
export type {
|
|
148
|
+
SpecValidatorConfig,
|
|
149
|
+
SpecValidationResult,
|
|
150
|
+
BatchSpecValidationResult,
|
|
151
|
+
SpecSchemaDefinition,
|
|
152
|
+
SpecType,
|
|
153
|
+
SpecValidationError,
|
|
154
|
+
SchemaLoader,
|
|
155
|
+
} from './types/spec';
|
|
53
156
|
|
|
54
157
|
// ========================================
|
|
55
|
-
//
|
|
56
|
-
// ========================================
|
|
57
|
-
export
|
|
158
|
+
// 门禁系统(公共面 = ./gates 子路径出口)
|
|
159
|
+
// ========================================
|
|
160
|
+
export {
|
|
161
|
+
ReviewGate,
|
|
162
|
+
SecurityGate,
|
|
163
|
+
PerformanceGate,
|
|
164
|
+
ContractGate,
|
|
165
|
+
SpecAcceptanceGate,
|
|
166
|
+
CommandGate,
|
|
167
|
+
createCommandGate,
|
|
168
|
+
getCommandGate,
|
|
169
|
+
isCommandAllowed,
|
|
170
|
+
getCommandRiskLevel,
|
|
171
|
+
DEFAULT_COMMAND_BLACKLIST,
|
|
172
|
+
createReviewGate,
|
|
173
|
+
createSecurityGate,
|
|
174
|
+
createPerformanceGate,
|
|
175
|
+
createContractGate,
|
|
176
|
+
createSpecAcceptanceGate,
|
|
177
|
+
decisionFromResult,
|
|
178
|
+
GATE_DEFINITIONS,
|
|
179
|
+
getGate,
|
|
180
|
+
listRegisteredGates,
|
|
181
|
+
registeredGateCount,
|
|
182
|
+
assertGateRegistryClosed,
|
|
183
|
+
runGates,
|
|
184
|
+
getEffectiveGates,
|
|
185
|
+
createCheckerGate,
|
|
186
|
+
} from './gates';
|
|
187
|
+
export type {
|
|
188
|
+
GateResult,
|
|
189
|
+
GateContext,
|
|
190
|
+
Gate,
|
|
191
|
+
GateDecision,
|
|
192
|
+
GateDecisionStatus,
|
|
193
|
+
GateDefinition,
|
|
194
|
+
GateRunResult,
|
|
195
|
+
GatesConfig,
|
|
196
|
+
PerformanceThresholds,
|
|
197
|
+
ReviewGateConfig,
|
|
198
|
+
SecurityGateConfig,
|
|
199
|
+
PerformanceGateConfig,
|
|
200
|
+
ContractGateConfig,
|
|
201
|
+
SpecAcceptanceGateConfig,
|
|
202
|
+
AcceptanceGateContext,
|
|
203
|
+
AcceptanceCriteria,
|
|
204
|
+
CommandBlacklistRule,
|
|
205
|
+
CommandGateConfig,
|
|
206
|
+
} from './gates';
|
|
58
207
|
|
|
59
208
|
// ========================================
|
|
60
|
-
//
|
|
61
|
-
// ========================================
|
|
62
|
-
export
|
|
209
|
+
// 监控(Execution Trace 收集/分析 + 上下文追踪)
|
|
210
|
+
// ========================================
|
|
211
|
+
export {
|
|
212
|
+
DEFAULT_TRACE_FILE,
|
|
213
|
+
} from './types/trace';
|
|
214
|
+
export type {
|
|
215
|
+
ExecutionTrace,
|
|
216
|
+
TraceFilter,
|
|
217
|
+
TraceSummary,
|
|
218
|
+
TraceAnomaly,
|
|
219
|
+
TraceCollectorConfig,
|
|
220
|
+
TraceAnalyzerConfig,
|
|
221
|
+
} from './types/trace';
|
|
222
|
+
export {
|
|
223
|
+
TraceCollector,
|
|
224
|
+
getTraceCollector,
|
|
225
|
+
configureTraceCollector,
|
|
226
|
+
TraceAnalyzer,
|
|
227
|
+
createAnalyzer,
|
|
228
|
+
ContextTracker,
|
|
229
|
+
} from './monitoring';
|
|
230
|
+
export type { ContextAverages } from './monitoring';
|
|
63
231
|
|
|
64
232
|
// ========================================
|
|
65
|
-
//
|
|
66
|
-
// ========================================
|
|
67
|
-
export
|
|
233
|
+
// 失败处理(错误分类 + 记录 + 违规处理策略)
|
|
234
|
+
// ========================================
|
|
235
|
+
export {
|
|
236
|
+
ErrorType,
|
|
237
|
+
FailureLevel,
|
|
238
|
+
DEFAULT_CLASSIFICATION_RULES,
|
|
239
|
+
DEFAULT_LEVEL_MAPPING,
|
|
240
|
+
ErrorClassifier,
|
|
241
|
+
createErrorClassifier,
|
|
242
|
+
classifyError,
|
|
243
|
+
getFailureLevel,
|
|
244
|
+
FailureRecorder,
|
|
245
|
+
createFailureRecorder,
|
|
246
|
+
ConstraintViolationHandler,
|
|
247
|
+
executeWithBlock,
|
|
248
|
+
executeWithCollect,
|
|
249
|
+
executeWithSafeBoolean,
|
|
250
|
+
} from './failure';
|
|
251
|
+
export type {
|
|
252
|
+
FailureRecord,
|
|
253
|
+
ErrorClassificationRule,
|
|
254
|
+
ClassificationResult,
|
|
255
|
+
ErrorClassifierConfig,
|
|
256
|
+
FailureRecorderConfig,
|
|
257
|
+
ViolationStrategy,
|
|
258
|
+
ViolationHandlingResult,
|
|
259
|
+
} from './failure';
|
|
68
260
|
|
|
69
261
|
// ========================================
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
262
|
+
// 上下文管理(Token 预算 + 会话压缩 + 知识注入)
|
|
263
|
+
// ========================================
|
|
264
|
+
export {
|
|
265
|
+
AdaptiveTokenBudget,
|
|
266
|
+
TokenBudget,
|
|
267
|
+
TokenEstimator,
|
|
268
|
+
DEFAULT_COMPACTION_CONFIG,
|
|
269
|
+
SessionCompaction,
|
|
270
|
+
SessionManager,
|
|
271
|
+
KnowledgeInjector,
|
|
272
|
+
} from './context';
|
|
273
|
+
export type {
|
|
274
|
+
CompactionConfig,
|
|
275
|
+
CompactionLevel,
|
|
276
|
+
CompactionResult,
|
|
277
|
+
ContextSource,
|
|
278
|
+
ContextSourceType,
|
|
279
|
+
ContextUsageSnapshot,
|
|
280
|
+
InjectionConfig,
|
|
281
|
+
InjectionResult,
|
|
282
|
+
SessionCheckpoint,
|
|
283
|
+
SessionEvent,
|
|
284
|
+
SessionEventType,
|
|
285
|
+
SessionHandle,
|
|
286
|
+
SessionMessage,
|
|
287
|
+
} from './context';
|
|
75
288
|
|
|
76
289
|
// ========================================
|
|
77
|
-
//
|
|
78
|
-
// ========================================
|
|
79
|
-
export
|
|
290
|
+
// 知识引擎(Knowledge 基建)
|
|
291
|
+
// ========================================
|
|
292
|
+
export {
|
|
293
|
+
FileKnowledgeStore,
|
|
294
|
+
KnowledgeQuery,
|
|
295
|
+
KnowledgeLifecycle,
|
|
296
|
+
KnowledgeIngest,
|
|
297
|
+
sanitizeExternalContent,
|
|
298
|
+
ReferenceTracker,
|
|
299
|
+
KnowledgeLinter,
|
|
300
|
+
ColdStartImporter,
|
|
301
|
+
KnowledgeHealthScorer,
|
|
302
|
+
KnowledgeLifecycleHooks,
|
|
303
|
+
KnowledgeAudit,
|
|
304
|
+
migrateKnowledgeEntries,
|
|
305
|
+
extractCodeStructure,
|
|
306
|
+
DEFAULT_DECAY_CONFIG,
|
|
307
|
+
} from './knowledge';
|
|
308
|
+
export type {
|
|
309
|
+
KnowledgeEntry,
|
|
310
|
+
KnowledgeStore,
|
|
311
|
+
KnowledgeSubsystem,
|
|
312
|
+
KnowledgeOrigin,
|
|
313
|
+
KnowledgeReference,
|
|
314
|
+
MaturityLevel,
|
|
315
|
+
MaturityChange,
|
|
316
|
+
DecayConfig,
|
|
317
|
+
SourceRef,
|
|
318
|
+
DecisionRecord,
|
|
319
|
+
QueryFilter,
|
|
320
|
+
QueryBudget,
|
|
321
|
+
QueryResult,
|
|
322
|
+
ExecutionResult,
|
|
323
|
+
IndexEntry,
|
|
324
|
+
StorageLayer,
|
|
325
|
+
ConsumptionEvent,
|
|
326
|
+
ConsumptionMode,
|
|
327
|
+
IngestOptions,
|
|
328
|
+
ReferenceRecord,
|
|
329
|
+
LintIssue,
|
|
330
|
+
LintIssueType,
|
|
331
|
+
AuditRuleName,
|
|
332
|
+
AuditAction,
|
|
333
|
+
AuditIssue,
|
|
334
|
+
AuditReport,
|
|
335
|
+
AuditOptions,
|
|
336
|
+
CodeStructure,
|
|
337
|
+
DeclarationInfo,
|
|
338
|
+
ImportInfo,
|
|
339
|
+
} from './knowledge';
|
|
80
340
|
|
|
81
341
|
// ========================================
|
|
82
|
-
//
|
|
342
|
+
// Completion Checkers(T7-E1,studio#160)
|
|
343
|
+
// WU 收尾软观测三纯判定函数:tdd-chain / phase-format / contract-presence。
|
|
344
|
+
// 纯函数直接 export,不进 ConstraintCheck 闭环注册表。
|
|
83
345
|
// ========================================
|
|
84
|
-
export
|
|
346
|
+
export {
|
|
347
|
+
DEFAULT_TEST_GLOBS,
|
|
348
|
+
DEFAULT_NONCODE_GLOBS,
|
|
349
|
+
matchGlob,
|
|
350
|
+
matchAnyGlob,
|
|
351
|
+
classifyCommitFiles,
|
|
352
|
+
resolveGlobs,
|
|
353
|
+
verifyTddChain,
|
|
354
|
+
TESTED_BY_RE,
|
|
355
|
+
TESTS_NONE_RE,
|
|
356
|
+
verifyPhaseFormat,
|
|
357
|
+
PHASE_SUBJECT_RE,
|
|
358
|
+
verifyContractPresence,
|
|
359
|
+
} from './completion-checkers';
|
|
360
|
+
export type {
|
|
361
|
+
CheckerVerdict,
|
|
362
|
+
CommitVerdict,
|
|
363
|
+
CommitInput,
|
|
364
|
+
CommitFileClassification,
|
|
365
|
+
CompletionCheckersConfig,
|
|
366
|
+
ContractPresenceContext,
|
|
367
|
+
ContractPresenceResult,
|
|
368
|
+
PhaseFormatResult,
|
|
369
|
+
TddChainResult,
|
|
370
|
+
} from './completion-checkers';
|
|
85
371
|
|
|
86
372
|
// ========================================
|
|
87
|
-
//
|
|
373
|
+
// 工具路径
|
|
88
374
|
// ========================================
|
|
89
|
-
export
|
|
375
|
+
export { getRegistryPath, getToolsDir } from './tools';
|
|
90
376
|
|
|
91
377
|
// ========================================
|
|
92
|
-
//
|
|
93
|
-
// ========================================
|
|
94
|
-
export
|
|
378
|
+
// Hooks 管线
|
|
379
|
+
// ========================================
|
|
380
|
+
export {
|
|
381
|
+
HookRegistry,
|
|
382
|
+
assertHookRegistryClosed,
|
|
383
|
+
HookPipeline,
|
|
384
|
+
toErrorStrategy,
|
|
385
|
+
bootstrapHarness,
|
|
386
|
+
bootstrapHarnessSync,
|
|
387
|
+
} from './hooks';
|
|
388
|
+
export type {
|
|
389
|
+
HookDefinition,
|
|
390
|
+
HookConfig,
|
|
391
|
+
HookErrorStrategy,
|
|
392
|
+
HookExecutionRecord,
|
|
393
|
+
HookPhase,
|
|
394
|
+
HookResult,
|
|
395
|
+
PipelineResult,
|
|
396
|
+
HarnessBootstrap,
|
|
397
|
+
} from './hooks';
|
|
95
398
|
|
|
96
399
|
// ========================================
|
|
97
|
-
//
|
|
98
|
-
// ========================================
|
|
99
|
-
export
|
|
400
|
+
// Agent 生命周期
|
|
401
|
+
// ========================================
|
|
402
|
+
export {
|
|
403
|
+
AgentLifecycle,
|
|
404
|
+
} from './agents';
|
|
405
|
+
export type {
|
|
406
|
+
AgentConfig,
|
|
407
|
+
AgentEvent,
|
|
408
|
+
AgentState,
|
|
409
|
+
AgentStatus,
|
|
410
|
+
EventHandler,
|
|
411
|
+
FallbackStrategy,
|
|
412
|
+
} from './agents';
|
|
100
413
|
|
|
101
414
|
// ========================================
|
|
102
|
-
//
|
|
103
|
-
// ========================================
|
|
104
|
-
export {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* 拦截操作 — 在操作执行前检查约束
|
|
127
|
-
* @param trigger - 触发条件
|
|
128
|
-
* @param context - 约束上下文
|
|
129
|
-
* @returns 拦截结果(是否通过、违规列表)
|
|
130
|
-
*/
|
|
131
|
-
export async function interceptOperation(
|
|
132
|
-
trigger: ConstraintTrigger,
|
|
133
|
-
context: ConstraintContext
|
|
134
|
-
): Promise<InterceptionResult> {
|
|
135
|
-
return constraintInterceptor.intercept(trigger, context);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* 声明操作意图 — 声明即将执行的操作,但不执行检查
|
|
140
|
-
* @param trigger - 触发条件
|
|
141
|
-
* @param context - 约束上下文
|
|
142
|
-
*/
|
|
143
|
-
export async function claimOperation(
|
|
144
|
-
trigger: ConstraintTrigger,
|
|
145
|
-
context: ConstraintContext
|
|
146
|
-
): Promise<void> {
|
|
147
|
-
return constraintInterceptor.claim(trigger, context);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* 注册 enforcement executor — 将 enforcement ID 连接到实际检查逻辑
|
|
152
|
-
* @param enforcementId - enforcement ID(对应约束定义中的 enforcement 字段)
|
|
153
|
-
* @param executor - 执行器实现
|
|
154
|
-
* @param source - 注册来源(如 'builtin', 'plugin')
|
|
155
|
-
*/
|
|
156
|
-
export function registerExecutor(
|
|
157
|
-
enforcementId: EnforcementId,
|
|
158
|
-
executor: EnforcementExecutor,
|
|
159
|
-
source?: string
|
|
160
|
-
): void {
|
|
161
|
-
constraintInterceptor.register(enforcementId, executor, source);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* 检查约束(check 层)
|
|
166
|
-
*
|
|
167
|
-
* @param context - 约束上下文
|
|
168
|
-
* @param options.onTrace - 每条约束检查后的回调(用于记录 trace 到外部存储)
|
|
169
|
-
*/
|
|
170
|
-
export async function checkConstraints(
|
|
171
|
-
context: ConstraintContext,
|
|
172
|
-
options?: { onTrace?: (result: import('./types/constraint').ConstraintResult) => void }
|
|
173
|
-
): Promise<ConstraintCheckResult> {
|
|
174
|
-
const result = await constraintChecker.checkConstraints(context);
|
|
175
|
-
if (options?.onTrace) {
|
|
176
|
-
for (const r of result.ironLaws) options.onTrace(r);
|
|
177
|
-
for (const r of result.guidelines) options.onTrace(r);
|
|
178
|
-
}
|
|
179
|
-
return result;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* 执行前检查(仅 Iron Laws)
|
|
184
|
-
*/
|
|
185
|
-
export async function checkBeforeExecution(
|
|
186
|
-
context: ConstraintContext
|
|
187
|
-
): Promise<void> {
|
|
188
|
-
return constraintChecker.beforeExecution(context);
|
|
189
|
-
}
|
|
415
|
+
// 项目配置类型(config.yml 形状;Loader 属内部 seam 不公开)
|
|
416
|
+
// ========================================
|
|
417
|
+
export type {
|
|
418
|
+
ProjectConfig,
|
|
419
|
+
MergedConstraintsConfig,
|
|
420
|
+
CustomConstraintDefinition,
|
|
421
|
+
GovernanceConfig,
|
|
422
|
+
CapabilitiesConfig,
|
|
423
|
+
ChangelogConfig,
|
|
424
|
+
ChangelogVersionCheck,
|
|
425
|
+
TestingGovernanceConfig,
|
|
426
|
+
ContextFilesConfig,
|
|
427
|
+
ContextDocsCheck,
|
|
428
|
+
DocsSyncConfig,
|
|
429
|
+
DocFreshnessConfig,
|
|
430
|
+
DocFreshnessCheck,
|
|
431
|
+
DocDirCheck,
|
|
432
|
+
DocRegexCountCheck,
|
|
433
|
+
ConstCountActual,
|
|
434
|
+
DirCountActual,
|
|
435
|
+
GrepCountActual,
|
|
436
|
+
} from './types/project-config';
|
package/src/knowledge/CONTEXT.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
## 核心导出
|
|
20
20
|
- `KnowledgeStore` — 知识条目 CRUD + 结构化存储
|
|
21
|
-
- `KnowledgeQuery` — 语义搜索 + 类型/标签过滤 + `queryByMode()` + `consume(taskContext)`
|
|
21
|
+
- `KnowledgeQuery` — 语义搜索 + 类型/标签过滤 + `queryByMode()` + `consume(taskContext)`;`query()` 是 budget 截断管线(仅用于 prompt 注入),`search()` 是全语料文本搜索(先匹配→排序→limit,交互搜索专用,勿用 query() 代替)
|
|
22
22
|
- `KnowledgeLifecycle` — per-mode 生命周期管理
|
|
23
23
|
- `KnowledgeIngest` — 知识摄取引擎(含 ingest gate 质量门)+ `ingestExternal()` 外部内容摄入
|
|
24
24
|
- `sanitizeExternalContent` — 外部内容安全清洗(过滤注入模式 + 长度限制)
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
## 依赖关系
|
|
34
34
|
- 依赖 `src/types/` 知识相关类型
|
|
35
|
-
- 依赖 `src/monitoring
|
|
35
|
+
- 依赖 `src/context/types`(ContextUsageSnapshot 等类型;不依赖 monitoring——知识健康评分由本目录 doctor.ts 的 KnowledgeHealthScorer 承载)
|
|
36
36
|
- 被 `src/cli/commands/knowledge.ts` CLI 消费(含 `migrate` 子命令)
|
|
37
37
|
|
|
38
38
|
## 约定
|
|
@@ -268,4 +268,68 @@ describe('KnowledgeQuery', () => {
|
|
|
268
268
|
expect(result).toBe('Internal: Details');
|
|
269
269
|
});
|
|
270
270
|
});
|
|
271
|
+
|
|
272
|
+
describe('search', () => {
|
|
273
|
+
it('should match against title, content and tags (case-insensitive)', () => {
|
|
274
|
+
store.save(makeEntry({ id: 'DEC-001', title: 'Autolink Design' }));
|
|
275
|
+
store.save(makeEntry({ id: 'DEC-002', title: 'Other', content: 'mentions AUTOLINK here' }));
|
|
276
|
+
store.save(makeEntry({ id: 'DEC-003', title: 'Tagged', tags: ['autolink'] }));
|
|
277
|
+
store.save(makeEntry({ id: 'DEC-004', title: 'Unrelated', content: 'nothing' }));
|
|
278
|
+
|
|
279
|
+
const result = query.search('autolink');
|
|
280
|
+
expect(result.map(e => e.id).sort()).toEqual(['DEC-001', 'DEC-002', 'DEC-003']);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('should match on the full corpus regardless of token volume (harness#63)', () => {
|
|
284
|
+
// 语料总 token 远超任何 prompt budget;排序队尾的 draft 新条目必须可搜到
|
|
285
|
+
for (let i = 0; i < 25; i++) {
|
|
286
|
+
store.save(makeEntry({
|
|
287
|
+
id: `FILL-${String(i).padStart(3, '0')}`,
|
|
288
|
+
title: `填充 ${i}`,
|
|
289
|
+
content: '填'.repeat(399),
|
|
290
|
+
maturity: 'proven',
|
|
291
|
+
lastReferenced: '2026-08-01T00:00:00.000Z',
|
|
292
|
+
}));
|
|
293
|
+
}
|
|
294
|
+
store.save(makeEntry({ id: 'PIT-020', title: '新条目', content: 'autolink 要点' }));
|
|
295
|
+
|
|
296
|
+
const result = query.search('autolink', { limit: 200 });
|
|
297
|
+
expect(result).toHaveLength(1);
|
|
298
|
+
expect(result[0].id).toBe('PIT-020');
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('should apply limit after matching, not before', () => {
|
|
302
|
+
for (let i = 0; i < 10; i++) {
|
|
303
|
+
store.save(makeEntry({ id: `DEC-${String(i).padStart(3, '0')}`, title: `共同词 ${i}` }));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
expect(query.search('共同词', { limit: 3 })).toHaveLength(3);
|
|
307
|
+
expect(query.search('共同词', { limit: 50 })).toHaveLength(10);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it('should sort matches by maturity desc then lastReferenced desc', () => {
|
|
311
|
+
store.save(makeEntry({ id: 'DEC-001', title: 'kw a', maturity: 'draft' }));
|
|
312
|
+
store.save(makeEntry({ id: 'DEC-002', title: 'kw b', maturity: 'proven', lastReferenced: '2026-01-01' }));
|
|
313
|
+
store.save(makeEntry({ id: 'DEC-003', title: 'kw c', maturity: 'proven', lastReferenced: '2026-08-01' }));
|
|
314
|
+
|
|
315
|
+
const result = query.search('kw');
|
|
316
|
+
expect(result.map(e => e.id)).toEqual(['DEC-003', 'DEC-002', 'DEC-001']);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('should exclude archived entries by default and respect filter overrides', () => {
|
|
320
|
+
store.save(makeEntry({ id: 'DEC-001', title: 'kw active' }));
|
|
321
|
+
store.save(makeEntry({ id: 'DEC-002', title: 'kw archived', maturity: 'archived' }));
|
|
322
|
+
|
|
323
|
+
expect(query.search('kw').map(e => e.id)).toEqual(['DEC-001']);
|
|
324
|
+
expect(query.search('kw', { filter: { excludeArchived: false } })).toHaveLength(2);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('should respect filter.types', () => {
|
|
328
|
+
store.save(makeEntry({ id: 'DEC-001', type: 'decision', title: 'kw' }));
|
|
329
|
+
store.save(makeEntry({ id: 'PIT-001', type: 'pitfall', title: 'kw' }));
|
|
330
|
+
|
|
331
|
+
const result = query.search('kw', { filter: { types: ['pitfall'] } });
|
|
332
|
+
expect(result.map(e => e.id)).toEqual(['PIT-001']);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
271
335
|
});
|
package/src/knowledge/query.ts
CHANGED
|
@@ -86,6 +86,34 @@ export class KnowledgeQuery {
|
|
|
86
86
|
return result;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Full-text search over the entire corpus.
|
|
91
|
+
*
|
|
92
|
+
* Unlike query(), this is NOT budget-constrained: text matching runs on the
|
|
93
|
+
* full (filtered) corpus first, then results are sorted by
|
|
94
|
+
* maturity desc → lastReferenced desc and capped at `limit`.
|
|
95
|
+
* Token budgets only make sense for prompt injection (query()); interactive
|
|
96
|
+
* search must see every entry or low-ranked entries become unfindable.
|
|
97
|
+
*
|
|
98
|
+
* No caching and no recordReference side effect — searching is not citing.
|
|
99
|
+
*/
|
|
100
|
+
search(query: string, options?: { limit?: number; filter?: QueryFilter }): KnowledgeEntry[] {
|
|
101
|
+
const limit = options?.limit ?? 20;
|
|
102
|
+
const candidates = this.store.list({
|
|
103
|
+
excludeArchived: true,
|
|
104
|
+
...options?.filter,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const q = query.toLowerCase();
|
|
108
|
+
const matched = candidates.filter(e =>
|
|
109
|
+
e.title.toLowerCase().includes(q) ||
|
|
110
|
+
e.content.toLowerCase().includes(q) ||
|
|
111
|
+
e.tags.some(t => t.toLowerCase().includes(q))
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
return this.sortEntries(matched).slice(0, limit);
|
|
115
|
+
}
|
|
116
|
+
|
|
89
117
|
/**
|
|
90
118
|
* Estimate token count for a piece of text.
|
|
91
119
|
* Rule of thumb: 1 CJK char ≈ 2 tokens, 1 ASCII char ≈ 0.25 tokens.
|