@dommaker/harness 1.1.1 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- 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 +8 -33
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/constraints-report.js +1 -1
- package/dist/cli/commands/constraints-report.js.map +1 -1
- package/dist/cli/commands/constraints-retire.d.ts +6 -3
- package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
- package/dist/cli/commands/constraints-retire.js +34 -25
- package/dist/cli/commands/constraints-retire.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 +21 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +118 -40
- 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.js +2 -2
- 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 +29 -32
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +34 -126
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.d.ts +20 -0
- package/dist/core/constraints/checkers/governance-presence.d.ts.map +1 -0
- package/dist/core/constraints/checkers/governance-presence.js +76 -0
- package/dist/core/constraints/checkers/governance-presence.js.map +1 -0
- 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 +5 -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 +21 -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/injection-drift.d.ts +29 -4
- package/dist/core/constraints/injection-drift.d.ts.map +1 -1
- package/dist/core/constraints/injection-drift.js +52 -20
- package/dist/core/constraints/injection-drift.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 -60
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +180 -143
- 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 +0 -4
- 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 +5 -18
- package/dist/types/trace.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/CONTEXT.md +4 -5
- package/src/__tests__/checker-extra.test.ts +33 -139
- package/src/__tests__/checker.test.ts +0 -376
- package/src/__tests__/governance-presence.test.ts +129 -0
- package/src/__tests__/iron-laws.test.ts +7 -7
- 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 +6 -3
- 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 +3 -3
- package/src/cli/commands/__tests__/constraints-retire.test.ts +45 -4
- package/src/cli/commands/__tests__/init-injection.test.ts +202 -0
- 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 -6
- package/src/cli/commands/__tests__/status.test.ts +6 -6
- package/src/cli/commands/__tests__/sync-docs-agents.test.ts +28 -0
- package/src/cli/commands/check.ts +9 -35
- package/src/cli/commands/constraints-report.ts +1 -1
- package/src/cli/commands/constraints-retire.ts +38 -27
- package/src/cli/commands/definitions.ts +2 -0
- package/src/cli/commands/init.ts +129 -40
- package/src/cli/commands/knowledge.ts +1 -16
- package/src/cli/commands/report.ts +0 -2
- package/src/cli/commands/status.ts +2 -2
- 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/__tests__/injection-drift.test.ts +90 -0
- package/src/core/constraints/capabilities-parser.ts +43 -49
- package/src/core/constraints/checker.ts +51 -145
- package/src/core/constraints/checkers/governance-presence.ts +74 -0
- package/src/core/constraints/checkers/index.ts +4 -1
- package/src/core/constraints/checkers/types.ts +42 -0
- package/src/core/constraints/definitions/guidelines.ts +22 -2
- package/src/core/constraints/definitions/prompts.ts +0 -5
- package/src/core/constraints/index.ts +2 -17
- package/src/core/constraints/injection-drift.ts +60 -21
- 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 -148
- 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 +0 -20
- 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 +5 -30
- package/dist/core/constraints/interceptor.d.ts +0 -39
- 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 -76
- package/dist/monitoring/constraint-doctor.d.ts.map +0 -1
- package/dist/monitoring/constraint-doctor.js +0 -189
- 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 -267
- package/src/core/constraints/interceptor.ts +0 -217
- 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 -228
- 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
|
@@ -26,6 +26,48 @@ export interface CheckEnv {
|
|
|
26
26
|
srcScan(root: string): string[];
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* 证据提供者组:git diff / 源码扫描的 memoized I/O
|
|
31
|
+
*
|
|
32
|
+
* 由调用方绑定后传入 buildCheckEnv(如 ConstraintChecker 绑实例级
|
|
33
|
+
* run 缓存的方法);工厂本身不做 memoization。
|
|
34
|
+
*/
|
|
35
|
+
export interface EvidenceProviders {
|
|
36
|
+
/** staged 全量 diff */
|
|
37
|
+
stagedDiff(): Promise<string>;
|
|
38
|
+
/** staged 变更文件名列表 */
|
|
39
|
+
stagedDiffNames(): Promise<string>;
|
|
40
|
+
/** 源码根相对路径文件列表 */
|
|
41
|
+
srcScan(root: string): string[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 构造 CheckEnv:生产侧唯一构造点
|
|
46
|
+
*
|
|
47
|
+
* - providers 传入 = 证据接线,checker 正常评估
|
|
48
|
+
* - 'none' = 显式不接证据:证据函数返回空;evidence flag 未接线的
|
|
49
|
+
* checker 按契约返回 'skip'(见 contextEvidenceFlag),直接读空
|
|
50
|
+
* 证据的 checker 在自然输入下判定
|
|
51
|
+
*
|
|
52
|
+
* studio 侧若需 git 证据(#129),传真实 providers 即可。
|
|
53
|
+
*/
|
|
54
|
+
export function buildCheckEnv(
|
|
55
|
+
context: ConstraintContext,
|
|
56
|
+
evidence: EvidenceProviders | 'none'
|
|
57
|
+
): CheckEnv {
|
|
58
|
+
const projectPath = context.projectPath || process.cwd();
|
|
59
|
+
if (evidence === 'none') {
|
|
60
|
+
return {
|
|
61
|
+
context,
|
|
62
|
+
projectPath,
|
|
63
|
+
stagedDiff: async () => '',
|
|
64
|
+
stagedDiffNames: async () => '',
|
|
65
|
+
srcScan: () => [],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return { context, projectPath, ...evidence };
|
|
69
|
+
}
|
|
70
|
+
|
|
29
71
|
/**
|
|
30
72
|
* 检查结果三态(ADR-0001 存在性探测 / flag 未接线):
|
|
31
73
|
* - true = 满足(pass)
|
|
@@ -68,7 +68,6 @@ export const GUIDELINES: Record<string, Constraint> = {
|
|
|
68
68
|
- 性能优化不改变接口
|
|
69
69
|
|
|
70
70
|
支持模块级目录条目登记:governance.capabilities.mode=module 时按目录覆盖判定(如 src/core/ 一条目录条目覆盖该目录下所有源文件)。`,
|
|
71
|
-
exceptions: ['internal_refactor', 'bug_fix_only', 'performance_optimization'],
|
|
72
71
|
},
|
|
73
72
|
|
|
74
73
|
/**
|
|
@@ -97,6 +96,27 @@ export const GUIDELINES: Record<string, Constraint> = {
|
|
|
97
96
|
- 临时目录(tmp、temp)
|
|
98
97
|
- 测试目录(__tests__、test)
|
|
99
98
|
- 生成代码目录(dist、build、generated)`,
|
|
100
|
-
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 治理契约在场守护(studio #302,ADR 2026-08-21 落点模型)
|
|
103
|
+
* 原因:PRESERVE 只保「存在」不保「在场」——AGENTS.md 治理段被删除/掏空后
|
|
104
|
+
* sync-docs 重新生成会静默丢失约束正本
|
|
105
|
+
*/
|
|
106
|
+
governance_presence: {
|
|
107
|
+
id: 'governance_presence',
|
|
108
|
+
kind: 'check',
|
|
109
|
+
rule: 'GOVERNANCE CONTRACT MUST BE PRESENT (AGENTS.MD PRESERVE:GOVERNANCE BLOCK OR CLAUDE.MD GOVERNANCE RULES)',
|
|
110
|
+
message: '治理契约缺失:AGENTS.md 缺少非空 PRESERVE:governance 段,且 CLAUDE.md 无 Governance Rules 块',
|
|
111
|
+
level: 'guideline',
|
|
112
|
+
trigger: ['file_modification', 'module_creation', 'module_modification', 'doc_update', 'config_change', 'commit'],
|
|
113
|
+
enforcement: 'governance-presence-check',
|
|
114
|
+
description: `治理契约(约束清单正本)必须在场,两处居其一:
|
|
115
|
+
- 新模型:AGENTS.md 手写 \`<!-- PRESERVE:governance -->\` 段(块体非空)
|
|
116
|
+
- 旧模型:CLAUDE.md 的 \`## Governance Rules\` 块 / HARNESS_CONSTRAINTS 注入段
|
|
117
|
+
|
|
118
|
+
PRESERVE 机制只保证「存在的段重新生成时保留」,不保证「段在场」——段被删除或掏空后,
|
|
119
|
+
sync-docs 重新生成会静默丢弃治理契约。本检查在 harness check 时校验在场性,防静默丢失。
|
|
120
|
+
未采用 harness 治理(无 .harness/config.yml)的项目跳过评估(skip)。`,
|
|
101
121
|
},
|
|
102
122
|
};
|
|
@@ -76,7 +76,6 @@ export const PROMPTS: Record<string, Constraint> = {
|
|
|
76
76
|
- 用 fallback/兜底值掩盖上游数据异常而不追根因
|
|
77
77
|
- Read 定位后直接 Edit,不对照设计原型确认意图
|
|
78
78
|
- 从"数字异常"直接跳到根因结论,不验证假设的含义与量纲`,
|
|
79
|
-
exceptions: ['simple_typo', 'config_value_error', 'missing_config'],
|
|
80
79
|
promptInjection: '修复问题前必须先诊断根因——不止"哪里出错",而是"为什么设计成这样":用 Read/Grep 定位后禁止直接 Edit,先对照设计原型(CLAUDE.md、类型定义、commit message)确认原设计意图,呈现确认的根因+方案草案后才能动手。遇到空值/异常/不完整数据,禁止用 fallback/兜底/try-catch 掩盖——先追上游:数据谁产生的?为什么是空的?选择防御性兜底时必须在注释中说明根因;同一位置连续兜底 2+ 次是上游 bug 信号,停止修下游、追踪源头。从数据到结论必须先验证关键假设:数字的含义(累积/单次?量纲?)、正常范围、同类场景对比与反例,禁止"数字异常→直接定根因→直接改"的跳级推理。不绕过问题、不遮掩症状、不用临时方案代替根本修复。',
|
|
81
80
|
},
|
|
82
81
|
|
|
@@ -107,7 +106,6 @@ export const PROMPTS: Record<string, Constraint> = {
|
|
|
107
106
|
- reliability_required: 需要持久化/高可用
|
|
108
107
|
|
|
109
108
|
YAGNI:不为"未来可能需要"添加抽象层、接口、配置项或插件系统;一个抽象只有一个实现者时删除该抽象。`,
|
|
110
|
-
exceptions: ['scalability_required', 'security_required', 'performance_required', 'reliability_required'],
|
|
111
109
|
promptInjection: '最简方案优先:用最少代码解决当前问题,不添加"以防万一"的冗余功能,不为仅用一次的代码强行设计抽象。创建新模块/文件/能力前,先查现有能力索引确认无可复用——优先级:直接复用 > 扩展现有 > 组合现有 > 新建。遵循 YAGNI:不为"未来可能需要"添加抽象层、接口、配置项或插件系统;一个 interface/abstract class 只有一个实现者时,删除这个抽象。自检:资深工程师是否会认为此实现过度复杂?若是,立即简化。',
|
|
112
110
|
injectPrompt: true,
|
|
113
111
|
},
|
|
@@ -137,7 +135,6 @@ YAGNI:不为"未来可能需要"添加抽象层、接口、配置项或插件
|
|
|
137
135
|
- 类型定义文件(.d.ts、interface)
|
|
138
136
|
- 简单 getter/setter
|
|
139
137
|
- 纯展示 UI 组件(无交互逻辑)`,
|
|
140
|
-
exceptions: ['config_file', 'type_definition', 'simple_accessor', 'pure_display_component'],
|
|
141
138
|
promptInjection: '新代码必须同时编写测试。实现功能前先写测试用例(RED),然后实现让测试通过(GREEN)。不得提交无测试覆盖的实现代码。',
|
|
142
139
|
},
|
|
143
140
|
|
|
@@ -164,7 +161,6 @@ YAGNI:不为"未来可能需要"添加抽象层、接口、配置项或插件
|
|
|
164
161
|
- 发现冗余代码后的重构优化
|
|
165
162
|
- 用更简洁的实现达到相同效果
|
|
166
163
|
- 删除不再使用的遗留代码`,
|
|
167
|
-
exceptions: ['redundant_code_cleanup', 'same_effect_refactor', 'unused_code_removal'],
|
|
168
164
|
promptInjection: '不得擅自简化或删除测试、lint 规则、类型检查或约束。如需降低检查标准,必须先提案并获明确批准。',
|
|
169
165
|
},
|
|
170
166
|
|
|
@@ -272,7 +268,6 @@ YAGNI:不为"未来可能需要"添加抽象层、接口、配置项或插件
|
|
|
272
268
|
- 用户明确说"直接做"、"不用问"
|
|
273
269
|
- 紧急修复
|
|
274
270
|
- 已有明确设计文档`,
|
|
275
|
-
exceptions: ['explicit_instruction', 'emergency_fix', 'existing_design'],
|
|
276
271
|
promptInjection: '涉及架构变更、新增依赖、API 设计等重大决策时,必须先提出讨论获得确认,再开始实现。不要凭单方面判断做架构决策。',
|
|
277
272
|
},
|
|
278
273
|
|
|
@@ -20,6 +20,7 @@ export {
|
|
|
20
20
|
checkBeforeExecution,
|
|
21
21
|
constraintChecker,
|
|
22
22
|
} from './checker';
|
|
23
|
+
export type { CheckConstraintsOptions, TraceRecorder } from './checker';
|
|
23
24
|
|
|
24
25
|
// CLAUDE.md 约束注入段渲染(纯函数,init 注入与漂移校验共用)
|
|
25
26
|
export {
|
|
@@ -51,20 +52,4 @@ export type {
|
|
|
51
52
|
IronLawContext,
|
|
52
53
|
} from '../../types/constraint';
|
|
53
54
|
|
|
54
|
-
export { ConstraintViolationError } from '../../types/constraint';
|
|
55
|
-
|
|
56
|
-
// 约束拦截器
|
|
57
|
-
export {
|
|
58
|
-
ConstraintInterceptor,
|
|
59
|
-
constraintInterceptor,
|
|
60
|
-
interceptOperation,
|
|
61
|
-
claimOperation,
|
|
62
|
-
} from './interceptor';
|
|
63
|
-
|
|
64
|
-
export type {
|
|
65
|
-
EnforcementId,
|
|
66
|
-
EnforcementExecutor,
|
|
67
|
-
EnforcementContext,
|
|
68
|
-
EnforcementResult,
|
|
69
|
-
InterceptionResult,
|
|
70
|
-
} from '../../types/enforcement';
|
|
55
|
+
export { ConstraintViolationError } from '../../types/constraint';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 治理约束注入段漂移校验(ADR-0001 决策 7)
|
|
3
3
|
*
|
|
4
4
|
* 检测三类漂移:
|
|
5
5
|
* 1. 版本漂移:标记段内 `<!-- version: x -->` ≠ 当前 harness 包版本
|
|
@@ -9,8 +9,12 @@
|
|
|
9
9
|
* 3. 重复章节:标记段之外还存在另一个 `## Governance Rules` 标题
|
|
10
10
|
* (init 旧版本在无标记时追加第二个同名章节的历史问题)
|
|
11
11
|
*
|
|
12
|
+
* 落点路由(studio #307,ADR 2026-08-21 落点模型):注入段可能在
|
|
13
|
+
* CLAUDE.md(旧模型仓)或 AGENTS.md `PRESERVE:governance` 段内(新模型仓),
|
|
14
|
+
* 与 init 的 setupGovernanceConstraints 路由一致——CLAUDE.md 有标记优先。
|
|
15
|
+
*
|
|
12
16
|
* 纯检测、只读:不改任何文件。check 仅警告不阻断,详细差异进 report。
|
|
13
|
-
*
|
|
17
|
+
* 两处均无标记段 = 未注入,不算漂移(report 一句话提示,check 不警告)。
|
|
14
18
|
*/
|
|
15
19
|
|
|
16
20
|
import * as fs from 'fs';
|
|
@@ -22,12 +26,18 @@ import {
|
|
|
22
26
|
renderConstraintsSection,
|
|
23
27
|
} from './injection-renderer';
|
|
24
28
|
|
|
29
|
+
/** 注入段落点文件名(检测顺序即路由优先级:旧模型仓 CLAUDE.md 豁免优先) */
|
|
30
|
+
const INJECTION_FILES = ['CLAUDE.md', 'AGENTS.md'] as const;
|
|
31
|
+
export type InjectionFile = (typeof INJECTION_FILES)[number];
|
|
32
|
+
|
|
25
33
|
/** 注入漂移检测结果 */
|
|
26
34
|
export interface InjectionDrift {
|
|
27
35
|
/** 是否存在任一漂移(版本/内容/重复章节) */
|
|
28
36
|
hasDrift: boolean;
|
|
29
|
-
/** CLAUDE.md
|
|
37
|
+
/** CLAUDE.md / AGENTS.md 均无约束标记段(未注入,不算漂移) */
|
|
30
38
|
notInjected: boolean;
|
|
39
|
+
/** 注入段落点文件(未注入时 undefined) */
|
|
40
|
+
injectionFile?: InjectionFile;
|
|
31
41
|
/** 版本漂移:注入段版本 ≠ 当前 harness 版本 */
|
|
32
42
|
versionDrift?: { expected: string; actual: string };
|
|
33
43
|
/**
|
|
@@ -73,8 +83,41 @@ function significantLines(section: string): string[] {
|
|
|
73
83
|
.filter(l => ENTRY_LINE_RE.test(l) || GROUP_HEADING_RE.test(l));
|
|
74
84
|
}
|
|
75
85
|
|
|
86
|
+
function readIfExists(filePath: string): string | null {
|
|
87
|
+
try {
|
|
88
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
89
|
+
return typeof content === 'string' ? content : null;
|
|
90
|
+
} catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 解析治理约束注入段落点(studio #307,ADR 2026-08-21 落点模型)
|
|
97
|
+
*
|
|
98
|
+
* 与 init 的 setupGovernanceConstraints 路由一致:CLAUDE.md 含标记段优先
|
|
99
|
+
* (旧模型仓豁免),否则看 AGENTS.md(新模型仓注入段在 PRESERVE:governance 内);
|
|
100
|
+
* 两处均无完整标记段 → null(未注入)。
|
|
101
|
+
*
|
|
102
|
+
* detectInjectionDrift 与 constraints retire 的注入段同步共用本路由。
|
|
103
|
+
*/
|
|
104
|
+
export function resolveInjectionTarget(
|
|
105
|
+
projectRoot: string
|
|
106
|
+
): { file: InjectionFile; content: string; startIdx: number; endIdx: number } | null {
|
|
107
|
+
for (const file of INJECTION_FILES) {
|
|
108
|
+
const content = readIfExists(path.join(projectRoot, file));
|
|
109
|
+
if (content === null) continue;
|
|
110
|
+
const startIdx = content.indexOf(CONSTRAINTS_START_MARKER);
|
|
111
|
+
const endIdx = content.indexOf(CONSTRAINTS_END_MARKER);
|
|
112
|
+
if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
|
|
113
|
+
return { file, content, startIdx, endIdx };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
76
119
|
/**
|
|
77
|
-
*
|
|
120
|
+
* 检测约束注入段漂移
|
|
78
121
|
*
|
|
79
122
|
* @param projectRoot 项目根路径
|
|
80
123
|
* @param currentVersion 当前 harness 版本(缺省读 package.json;测试可显式传入)
|
|
@@ -90,31 +133,27 @@ export function detectInjectionDrift(
|
|
|
90
133
|
fixHint: INJECTION_DRIFT_FIX_HINT,
|
|
91
134
|
};
|
|
92
135
|
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
136
|
+
const target = resolveInjectionTarget(projectRoot);
|
|
137
|
+
if (!target) {
|
|
138
|
+
// 两处均无标记段 = 未注入,不算漂移(check 不警告)。
|
|
139
|
+
// 重复章节仍如实记录供 report 提示:旧落点 CLAUDE.md 优先,其次 AGENTS.md。
|
|
140
|
+
const legacy =
|
|
141
|
+
readIfExists(path.join(projectRoot, 'CLAUDE.md')) ??
|
|
142
|
+
readIfExists(path.join(projectRoot, 'AGENTS.md'));
|
|
143
|
+
if (legacy !== null) {
|
|
144
|
+
result.duplicateHeading = (legacy.match(GOVERNANCE_HEADING_RE) ?? []).length > 1;
|
|
145
|
+
}
|
|
102
146
|
result.notInjected = true;
|
|
103
147
|
return result;
|
|
104
148
|
}
|
|
105
149
|
|
|
150
|
+
result.injectionFile = target.file;
|
|
151
|
+
const { content, startIdx, endIdx } = target;
|
|
152
|
+
|
|
106
153
|
// 重复章节:全文统计 `## Governance Rules` 标题数(含标记段所属的合法标题)
|
|
107
154
|
const headingCount = (content.match(GOVERNANCE_HEADING_RE) ?? []).length;
|
|
108
155
|
result.duplicateHeading = headingCount > 1;
|
|
109
156
|
|
|
110
|
-
const startIdx = content.indexOf(CONSTRAINTS_START_MARKER);
|
|
111
|
-
const endIdx = content.indexOf(CONSTRAINTS_END_MARKER);
|
|
112
|
-
if (startIdx === -1 || endIdx === -1 || endIdx <= startIdx) {
|
|
113
|
-
// 无标记段 = 未注入,不算漂移(check 不警告;duplicateHeading 仍如实记录供 report 提示)
|
|
114
|
-
result.notInjected = true;
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
157
|
const actualSection = content.slice(startIdx, endIdx + CONSTRAINTS_END_MARKER.length);
|
|
119
158
|
|
|
120
159
|
// 1. 版本漂移
|
|
@@ -33,12 +33,11 @@ export interface ConstraintUsageStats {
|
|
|
33
33
|
id: string;
|
|
34
34
|
level: Constraint['level'];
|
|
35
35
|
|
|
36
|
-
/** trace 总行数(含 skip
|
|
36
|
+
/** trace 总行数(含 skip) */
|
|
37
37
|
total: number;
|
|
38
38
|
pass: number;
|
|
39
39
|
fail: number;
|
|
40
40
|
skip: number;
|
|
41
|
-
bypassed: number;
|
|
42
41
|
|
|
43
42
|
/** 实际评估次数(total - skip;skip 未评估不计入,与 TraceAnalyzer 一致) */
|
|
44
43
|
evaluated: number;
|
|
@@ -129,26 +128,25 @@ export function readProjectTraces(projectRoot: string): ExecutionTrace[] {
|
|
|
129
128
|
export function collectUsageByConstraint(
|
|
130
129
|
traces: ExecutionTrace[]
|
|
131
130
|
): Map<string, Omit<ConstraintUsageStats, 'id' | 'level' | 'evaluated' | 'failRate'>> {
|
|
132
|
-
const map = new Map<string, { total: number; pass: number; fail: number; skip: number;
|
|
131
|
+
const map = new Map<string, { total: number; pass: number; fail: number; skip: number; firstAt?: number; lastAt?: number }>();
|
|
133
132
|
for (const t of traces) {
|
|
134
133
|
let agg = map.get(t.constraintId);
|
|
135
134
|
if (!agg) {
|
|
136
|
-
agg = { total: 0, pass: 0, fail: 0, skip: 0
|
|
135
|
+
agg = { total: 0, pass: 0, fail: 0, skip: 0 };
|
|
137
136
|
map.set(t.constraintId, agg);
|
|
138
137
|
}
|
|
139
138
|
agg.total++;
|
|
140
139
|
if (t.result === 'pass') agg.pass++;
|
|
141
140
|
else if (t.result === 'fail') agg.fail++;
|
|
142
141
|
else if (t.result === 'skip') agg.skip++;
|
|
143
|
-
else if (t.result === 'bypassed') agg.bypassed++;
|
|
144
142
|
if (agg.firstAt === undefined || t.timestamp < agg.firstAt) agg.firstAt = t.timestamp;
|
|
145
143
|
if (agg.lastAt === undefined || t.timestamp > agg.lastAt) agg.lastAt = t.timestamp;
|
|
146
144
|
}
|
|
147
145
|
return map;
|
|
148
146
|
}
|
|
149
147
|
|
|
150
|
-
function toStats(id: string, level: Constraint['level'], agg: { total: number; pass: number; fail: number; skip: number;
|
|
151
|
-
const a = agg ?? { total: 0, pass: 0, fail: 0, skip: 0
|
|
148
|
+
function toStats(id: string, level: Constraint['level'], agg: { total: number; pass: number; fail: number; skip: number; firstAt?: number; lastAt?: number } | undefined): ConstraintUsageStats {
|
|
149
|
+
const a = agg ?? { total: 0, pass: 0, fail: 0, skip: 0 };
|
|
152
150
|
const evaluated = a.total - a.skip;
|
|
153
151
|
return {
|
|
154
152
|
id,
|
|
@@ -157,7 +155,6 @@ function toStats(id: string, level: Constraint['level'], agg: { total: number; p
|
|
|
157
155
|
pass: a.pass,
|
|
158
156
|
fail: a.fail,
|
|
159
157
|
skip: a.skip,
|
|
160
|
-
bypassed: a.bypassed,
|
|
161
158
|
evaluated,
|
|
162
159
|
failRate: evaluated > 0 ? a.fail / evaluated : 0,
|
|
163
160
|
firstAt: a.firstAt,
|
|
@@ -8,24 +8,28 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { Constraint } from '../types/constraint';
|
|
11
|
+
import type { MergedConstraintsConfig } from '../types/project-config';
|
|
11
12
|
import { PROMPTS } from './constraints/definitions';
|
|
12
13
|
import { ProjectConfigLoader } from './project-config-loader';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* 获取项目当前生效的约束集(check + prompt,带 kind)
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
* 删除(内置与 custom 同效)→ custom-constraints
|
|
19
|
-
*
|
|
18
|
+
* 生效集链路同 getMergedConstraintsConfig:内置 → preset 裁剪 → config.yml
|
|
19
|
+
* `constraints.<id>.enabled:false` 删除(内置与 custom 同效)→ custom-constraints
|
|
20
|
+
* 追加(禁用/已退役的 custom 不追加)→ scenes 过滤
|
|
20
21
|
* (带 appliesTo 的 prompt 仅当 config.yml `scenes` 与其交集非空时保留,
|
|
21
22
|
* 缺省 scenes=[] 即场景专属 prompt 默认不进入生效集)。
|
|
22
23
|
*
|
|
23
24
|
* @param projectRoot 项目根路径(缺省 process.cwd())
|
|
25
|
+
* @param options.preset 覆盖 config.yml 的 preset;仅在项目无自定义配置时生效
|
|
26
|
+
* (与 getMergedConstraintsConfig 同一优先级规则),不传则尊重 config.yml
|
|
24
27
|
*/
|
|
25
|
-
export function getEffectiveConstraints(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
export function getEffectiveConstraints(
|
|
29
|
+
projectRoot: string = process.cwd(),
|
|
30
|
+
options?: { preset?: string }
|
|
31
|
+
): Constraint[] {
|
|
32
|
+
const merged = getMergedConstraintsConfig(projectRoot, options);
|
|
29
33
|
return [
|
|
30
34
|
...Object.values(merged.ironLaws),
|
|
31
35
|
...Object.values(merged.guidelines),
|
|
@@ -33,6 +37,30 @@ export function getEffectiveConstraints(projectRoot: string = process.cwd()): Co
|
|
|
33
37
|
];
|
|
34
38
|
}
|
|
35
39
|
|
|
40
|
+
/**
|
|
41
|
+
* 获取项目当前生效的合并约束配置(ADR-0001 唯一来源的完整形状)
|
|
42
|
+
*
|
|
43
|
+
* 与 getEffectiveConstraints 同一生效集链路,返回完整 MergedConstraintsConfig
|
|
44
|
+
* (含 disabled/custom/unknownIds),供 check 等需要诊断信息的消费方使用。
|
|
45
|
+
*
|
|
46
|
+
* options.preset(CLI --preset)仅在项目无自定义配置时覆盖 config.yml 的
|
|
47
|
+
* preset(工单 23 语义:项目自定义配置优先于 CLI 预设);不传 preset 时
|
|
48
|
+
* 完全尊重 config.yml 的 preset 键。
|
|
49
|
+
*
|
|
50
|
+
* @param projectRoot 项目根路径(缺省 process.cwd())
|
|
51
|
+
*/
|
|
52
|
+
export function getMergedConstraintsConfig(
|
|
53
|
+
projectRoot: string = process.cwd(),
|
|
54
|
+
options?: { preset?: string }
|
|
55
|
+
): MergedConstraintsConfig {
|
|
56
|
+
const loader = new ProjectConfigLoader(projectRoot);
|
|
57
|
+
loader.load();
|
|
58
|
+
if (loader.hasCustomConfig() || !options?.preset) {
|
|
59
|
+
return loader.mergeConstraints();
|
|
60
|
+
}
|
|
61
|
+
return loader.mergeConstraints({ preset: options.preset });
|
|
62
|
+
}
|
|
63
|
+
|
|
36
64
|
/**
|
|
37
65
|
* 生效集配置诊断结果
|
|
38
66
|
*/
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生效集共享筛选器(ADR-0001 收口)
|
|
3
|
+
*
|
|
4
|
+
* 「config.yml 引用了哪些 id、哪些被禁用」的判定,约束侧与门禁侧共用一份:
|
|
5
|
+
* - 约束侧(ProjectConfigLoader.mergeConstraints):未知 id 静默忽略,
|
|
6
|
+
* 收集进结果 unknownIds 供诊断(历史配置可能存在已移除约束的禁用残留)
|
|
7
|
+
* - 门禁侧(getEffectiveGates):未知 id 抛错(闭环校验;gates 配置段为
|
|
8
|
+
* 新增面,不存在历史残留配置)
|
|
9
|
+
*
|
|
10
|
+
* 行为差异仅收敛为 onUnknownId 一个开关,筛选语义两侧一致。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export interface FilterEnabledEntriesOptions {
|
|
14
|
+
/** 未知 id 处理:'collect' 收集进结果 unknownIds;'throw' 立即抛错 */
|
|
15
|
+
onUnknownId: 'collect' | 'throw';
|
|
16
|
+
|
|
17
|
+
/** onUnknownId='throw' 时的错误消息定制(如附带可用 id 清单) */
|
|
18
|
+
unknownIdError?: (id: string) => string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface FilterEnabledEntriesResult {
|
|
22
|
+
/** enabled === false 的 id(未知 id 若带 enabled:false 同样计入,与历史行为一致) */
|
|
23
|
+
disabledIds: string[];
|
|
24
|
+
|
|
25
|
+
/** 未知 id(仅 onUnknownId='collect' 时非空) */
|
|
26
|
+
unknownIds: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 按 config 条目筛选:未知 id 按 onUnknownId 处理,enabled:false 收进 disabledIds
|
|
31
|
+
*/
|
|
32
|
+
export function filterEnabledEntries(
|
|
33
|
+
knownIds: ReadonlySet<string>,
|
|
34
|
+
entries: Record<string, { enabled?: boolean } | undefined>,
|
|
35
|
+
options: FilterEnabledEntriesOptions
|
|
36
|
+
): FilterEnabledEntriesResult {
|
|
37
|
+
const disabledIds: string[] = [];
|
|
38
|
+
const unknownIds: string[] = [];
|
|
39
|
+
|
|
40
|
+
for (const [id, entry] of Object.entries(entries)) {
|
|
41
|
+
if (!knownIds.has(id)) {
|
|
42
|
+
if (options.onUnknownId === 'throw') {
|
|
43
|
+
throw new Error(
|
|
44
|
+
options.unknownIdError?.(id) ??
|
|
45
|
+
`[harness] 配置引用了未注册的 id "${id}"。`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
unknownIds.push(id);
|
|
49
|
+
}
|
|
50
|
+
if (entry?.enabled === false) {
|
|
51
|
+
disabledIds.push(id);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { disabledIds, unknownIds };
|
|
56
|
+
}
|
package/src/core/index.ts
CHANGED
|
@@ -1,13 +1,78 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 核心模块导出(ADR-0003:显式清单,禁 export *)
|
|
3
|
+
*
|
|
4
|
+
* checkConstraints 与包根统一为 options 对象签名(CheckConstraintsOptions),
|
|
5
|
+
* 不再暴露位置参数版。
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
// 约束系统(三层:Iron Laws / Guidelines / Tips)
|
|
9
|
+
export {
|
|
10
|
+
IRON_LAWS,
|
|
11
|
+
GUIDELINES,
|
|
12
|
+
PROMPTS,
|
|
13
|
+
getAllConstraints,
|
|
14
|
+
findConstraintsByTrigger,
|
|
15
|
+
getConstraint,
|
|
16
|
+
ConstraintChecker,
|
|
17
|
+
checkConstraint,
|
|
18
|
+
checkConstraints,
|
|
19
|
+
checkBeforeExecution,
|
|
20
|
+
constraintChecker,
|
|
21
|
+
CONSTRAINTS_START_MARKER,
|
|
22
|
+
CONSTRAINTS_END_MARKER,
|
|
23
|
+
renderConstraintsSection,
|
|
24
|
+
CheckCache,
|
|
25
|
+
renderConstraintsByTrigger,
|
|
26
|
+
ConstraintViolationError,
|
|
27
|
+
} from './constraints';
|
|
28
|
+
export type {
|
|
29
|
+
CheckConstraintsOptions,
|
|
30
|
+
CheckCacheConfig,
|
|
31
|
+
CheckSamplingConfig,
|
|
32
|
+
RenderConstraintsByTriggerOptions,
|
|
33
|
+
ConstraintId,
|
|
34
|
+
ConstraintKind,
|
|
35
|
+
ConstraintLevel,
|
|
36
|
+
ConstraintTrigger,
|
|
37
|
+
Constraint,
|
|
38
|
+
ConstraintResult,
|
|
39
|
+
ConstraintContext,
|
|
40
|
+
ConstraintCheckResult,
|
|
41
|
+
IronLawContext,
|
|
42
|
+
} from './constraints';
|
|
6
43
|
|
|
7
|
-
|
|
44
|
+
// 验证器(检查点 / PassesGate / CSO)
|
|
45
|
+
export {
|
|
46
|
+
CheckpointValidator,
|
|
47
|
+
PassesGate,
|
|
48
|
+
createPassesGate,
|
|
49
|
+
CSOValidator,
|
|
50
|
+
} from './validators';
|
|
51
|
+
export type {
|
|
52
|
+
CSOValidationResult,
|
|
53
|
+
CSOIssue,
|
|
54
|
+
Checkpoint,
|
|
55
|
+
CheckpointCheck,
|
|
56
|
+
CheckpointResult,
|
|
57
|
+
CheckResult,
|
|
58
|
+
CheckpointContext,
|
|
59
|
+
CheckType,
|
|
60
|
+
CheckConfig,
|
|
61
|
+
PassesGateConfig,
|
|
62
|
+
PassesGateResult,
|
|
63
|
+
TaskTestResult,
|
|
64
|
+
DynamicTask,
|
|
65
|
+
} from './validators';
|
|
8
66
|
|
|
9
|
-
|
|
10
|
-
export
|
|
67
|
+
// 会话启动 / 净室状态
|
|
68
|
+
export {
|
|
69
|
+
SessionStartup,
|
|
70
|
+
createSessionStartup,
|
|
71
|
+
DEFAULT_CODE_CHECKPOINTS,
|
|
72
|
+
MINIMAL_CHECKPOINTS,
|
|
73
|
+
CleanStateManager,
|
|
74
|
+
createCleanStateManager,
|
|
75
|
+
} from './session';
|
|
11
76
|
|
|
12
77
|
// Spec 验证器
|
|
13
78
|
export { SpecValidator } from './spec/validator';
|
|
@@ -20,7 +85,16 @@ export type {
|
|
|
20
85
|
} from '../types/spec';
|
|
21
86
|
|
|
22
87
|
// 项目配置加载器
|
|
23
|
-
export
|
|
88
|
+
export {
|
|
89
|
+
ProjectConfigLoader,
|
|
90
|
+
loadRawProjectConfig,
|
|
91
|
+
getCapabilitiesMode,
|
|
92
|
+
} from './project-config-loader';
|
|
93
|
+
export type { CapabilitiesMode } from './project-config-loader';
|
|
24
94
|
|
|
25
95
|
// 生效约束集(ADR-0001:唯一生效集来源)
|
|
26
|
-
export
|
|
96
|
+
export {
|
|
97
|
+
getEffectiveConstraints,
|
|
98
|
+
lintEffectiveConfig,
|
|
99
|
+
} from './effective-constraints';
|
|
100
|
+
export type { EffectiveConfigLint } from './effective-constraints';
|