@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
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
* retired: { at, reason, stats: { total, fail, failRate } }
|
|
21
21
|
*
|
|
22
22
|
* 每条同时写一条 KnowledgeStore 记录(consumptionMode: 'signal'),
|
|
23
|
-
*
|
|
23
|
+
* 并同步治理注入段(CLAUDE.md 或 AGENTS.md,存在 HARNESS_CONSTRAINTS 标记时;
|
|
24
|
+
* 落点路由与 init 一致,见 core/constraints/injection-drift resolveInjectionTarget)。
|
|
24
25
|
*
|
|
25
26
|
* retire 不是删除——恢复方法:内置删 config.yml 中 constraints.<id> 段;
|
|
26
27
|
* custom 删 custom-constraints.yml 中 custom_constraints.<id>.retired 段。
|
|
@@ -35,7 +36,8 @@ import * as readline from 'readline';
|
|
|
35
36
|
import * as yaml from 'js-yaml';
|
|
36
37
|
import chalk from 'chalk';
|
|
37
38
|
import { getConstraint } from '../../core/constraints/definitions';
|
|
38
|
-
import { renderConstraintsSection,
|
|
39
|
+
import { renderConstraintsSection, CONSTRAINTS_END_MARKER } from '../../core/constraints/injection-renderer';
|
|
40
|
+
import { resolveInjectionTarget } from '../../core/constraints/injection-drift';
|
|
39
41
|
import { getEffectiveConstraints } from '../../core/effective-constraints';
|
|
40
42
|
import { loadRawProjectConfig, ProjectConfigLoader } from '../../core/project-config-loader';
|
|
41
43
|
import { FileKnowledgeStore } from '../../knowledge/store';
|
|
@@ -65,8 +67,10 @@ export interface RetireResult {
|
|
|
65
67
|
/** 退役落点:custom 约束落 custom-constraints.yml(#82 D6),内置落 config.yml */
|
|
66
68
|
landing: 'config.yml' | 'custom-constraints.yml';
|
|
67
69
|
stats: { total: number; fail: number; failRate: number };
|
|
68
|
-
/** CLAUDE.md
|
|
69
|
-
|
|
70
|
+
/** 治理注入段(CLAUDE.md / AGENTS.md)是否已同步 */
|
|
71
|
+
injectionSynced: boolean;
|
|
72
|
+
/** 实际同步的落点文件(injectionSynced 时存在) */
|
|
73
|
+
injectionFile?: string;
|
|
70
74
|
/** KnowledgeStore 条目 id(status='retired' 时存在) */
|
|
71
75
|
knowledgeEntryId?: string;
|
|
72
76
|
}
|
|
@@ -265,27 +269,25 @@ function saveRetireKnowledge(
|
|
|
265
269
|
}
|
|
266
270
|
|
|
267
271
|
/**
|
|
268
|
-
*
|
|
272
|
+
* 同步治理注入段(CLAUDE.md 或 AGENTS.md,存在 HARNESS_CONSTRAINTS 标记时)
|
|
269
273
|
*
|
|
274
|
+
* 落点路由复用 resolveInjectionTarget(studio #307:新模型仓注入段在
|
|
275
|
+
* AGENTS.md PRESERVE:governance 内;旧模型仓 CLAUDE.md 优先)。
|
|
270
276
|
* 复用 renderConstraintsSection(P3 导出纯函数)按退役后生效集重渲染。
|
|
271
277
|
* 无标记段不动(不追加——retire 不承担 init 职责)。
|
|
272
278
|
*/
|
|
273
|
-
function
|
|
274
|
-
const
|
|
275
|
-
if (!
|
|
276
|
-
|
|
277
|
-
const content = fs.readFileSync(claudeMdPath, 'utf-8');
|
|
278
|
-
const startIdx = content.indexOf(CONSTRAINTS_START_MARKER);
|
|
279
|
-
const endIdx = content.indexOf(CONSTRAINTS_END_MARKER);
|
|
280
|
-
if (startIdx === -1 || endIdx === -1 || endIdx <= startIdx) return false;
|
|
279
|
+
function syncGovernanceInjection(projectRoot: string): { synced: boolean; file?: string } {
|
|
280
|
+
const target = resolveInjectionTarget(projectRoot);
|
|
281
|
+
if (!target) return { synced: false };
|
|
281
282
|
|
|
283
|
+
const filePath = path.join(projectRoot, target.file);
|
|
282
284
|
const body = renderConstraintsSection(getEffectiveConstraints(projectRoot), getHarnessVersion());
|
|
283
|
-
const after = content.slice(endIdx + CONSTRAINTS_END_MARKER.length).replace(/^\n+/, '');
|
|
284
|
-
const newContent = content.slice(0, startIdx) + body + (after ? '\n' + after : '');
|
|
285
|
-
if (newContent !== content) {
|
|
286
|
-
fs.writeFileSync(
|
|
285
|
+
const after = target.content.slice(target.endIdx + CONSTRAINTS_END_MARKER.length).replace(/^\n+/, '');
|
|
286
|
+
const newContent = target.content.slice(0, target.startIdx) + body + (after ? '\n' + after : '');
|
|
287
|
+
if (newContent !== target.content) {
|
|
288
|
+
fs.writeFileSync(filePath, newContent, 'utf-8');
|
|
287
289
|
}
|
|
288
|
-
return true;
|
|
290
|
+
return { synced: true, file: target.file };
|
|
289
291
|
}
|
|
290
292
|
|
|
291
293
|
/**
|
|
@@ -307,7 +309,7 @@ export function retireConstraint(
|
|
|
307
309
|
const landing: RetireResult['landing'] =
|
|
308
310
|
target?.source === 'custom' ? 'custom-constraints.yml' : 'config.yml';
|
|
309
311
|
if (!target) {
|
|
310
|
-
return { id, status: 'unknown_id', isIronLaw: false, landing, stats: emptyStats,
|
|
312
|
+
return { id, status: 'unknown_id', isIronLaw: false, landing, stats: emptyStats, injectionSynced: false };
|
|
311
313
|
}
|
|
312
314
|
|
|
313
315
|
// 已退役保护:内置看 config.yml constraints.<id>.enabled === false;
|
|
@@ -318,10 +320,10 @@ export function retireConstraint(
|
|
|
318
320
|
const loader = new ProjectConfigLoader(projectRoot);
|
|
319
321
|
loader.load();
|
|
320
322
|
if (loader.getCustomConstraints()[id]?.retired || existing?.enabled === false) {
|
|
321
|
-
return { id, status: 'already_retired', isIronLaw: target.isIronLaw, landing, stats: emptyStats,
|
|
323
|
+
return { id, status: 'already_retired', isIronLaw: target.isIronLaw, landing, stats: emptyStats, injectionSynced: false };
|
|
322
324
|
}
|
|
323
325
|
} else if (existing?.enabled === false) {
|
|
324
|
-
return { id, status: 'already_retired', isIronLaw: target.isIronLaw, landing, stats: emptyStats,
|
|
326
|
+
return { id, status: 'already_retired', isIronLaw: target.isIronLaw, landing, stats: emptyStats, injectionSynced: false };
|
|
325
327
|
}
|
|
326
328
|
|
|
327
329
|
// 历史统计(来自 traces.log)
|
|
@@ -346,10 +348,19 @@ export function retireConstraint(
|
|
|
346
348
|
// 2. KnowledgeStore
|
|
347
349
|
const knowledgeEntryId = saveRetireKnowledge(projectRoot, id, target, reason, stats, iso);
|
|
348
350
|
|
|
349
|
-
// 3. CLAUDE.md
|
|
350
|
-
const
|
|
351
|
+
// 3. 治理注入段同步(CLAUDE.md / AGENTS.md,路由见 syncGovernanceInjection)
|
|
352
|
+
const injection = syncGovernanceInjection(projectRoot);
|
|
351
353
|
|
|
352
|
-
return {
|
|
354
|
+
return {
|
|
355
|
+
id,
|
|
356
|
+
status: 'retired',
|
|
357
|
+
isIronLaw: target.isIronLaw,
|
|
358
|
+
landing,
|
|
359
|
+
stats,
|
|
360
|
+
injectionSynced: injection.synced,
|
|
361
|
+
injectionFile: injection.file,
|
|
362
|
+
knowledgeEntryId,
|
|
363
|
+
};
|
|
353
364
|
}
|
|
354
365
|
|
|
355
366
|
/**
|
|
@@ -367,8 +378,8 @@ export function printRetireResult(result: RetireResult): void {
|
|
|
367
378
|
console.log(chalk.green(`✅ ${result.id}: 已退役`));
|
|
368
379
|
console.log(` 历史统计: total=${result.stats.total} fail=${result.stats.fail} fail率=${Math.round(result.stats.failRate * 100)}%`);
|
|
369
380
|
console.log(` 知识沉淀: ${result.knowledgeEntryId}(.harness/knowledge)`);
|
|
370
|
-
if (result.
|
|
371
|
-
console.log(
|
|
381
|
+
if (result.injectionSynced) {
|
|
382
|
+
console.log(` 已同步 ${result.injectionFile ?? '治理文档'} 注入段`);
|
|
372
383
|
}
|
|
373
384
|
const recovery =
|
|
374
385
|
result.landing === 'custom-constraints.yml'
|
|
@@ -485,7 +496,7 @@ export async function runRetireInteractive(
|
|
|
485
496
|
}
|
|
486
497
|
console.log(` - KnowledgeStore: 写入 constraint-retired-${p.id}`);
|
|
487
498
|
}
|
|
488
|
-
console.log(' - CLAUDE.md: 若含 HARNESS_CONSTRAINTS 标记段则同步重渲染');
|
|
499
|
+
console.log(' - CLAUDE.md / AGENTS.md: 若含 HARNESS_CONSTRAINTS 标记段则同步重渲染');
|
|
489
500
|
const finalConfirm = await ask('确认执行?(y/N) ');
|
|
490
501
|
if (finalConfirm.toLowerCase() !== 'y' && finalConfirm.toLowerCase() !== 'yes') {
|
|
491
502
|
console.log('已取消');
|
|
@@ -81,6 +81,8 @@ export interface CommandDefinition {
|
|
|
81
81
|
subcommands?: Record<string, CommandSubcommand>;
|
|
82
82
|
/** false = 未知位置参数不报错、落回默认 action(spec 的文件参数用法) */
|
|
83
83
|
subcommandStrict?: boolean;
|
|
84
|
+
/** true = 有 subcommands 但无位置参数时运行默认 action 而非显示帮助(门禁命令语义) */
|
|
85
|
+
bareRunsAction?: boolean;
|
|
84
86
|
/** 选项条件路由(匹配时替代默认 action 执行) */
|
|
85
87
|
optionRoutes?: CommandOptionRoute[];
|
|
86
88
|
/** 默认 action 实参构造(缺省为 [options]) */
|
package/src/cli/commands/init.ts
CHANGED
|
@@ -37,19 +37,15 @@ export interface InitOptions {
|
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* 默认配置
|
|
40
|
+
*
|
|
41
|
+
* 只写有运行时消费者的字段:preset(ADR-0001 生效集链路由 mergeConstraints 消费)。
|
|
42
|
+
* 历史模板里的 enabled / ironLaws.enforceErrors / ironLaws.warnWarnings /
|
|
43
|
+
* validators.{checkpoint,passesGate,cso} 均为零消费者的死字段,不再写入;
|
|
44
|
+
* strict/standard/relaxed 三档差异曾只存在于这些死字段上(实为两档),
|
|
45
|
+
* 现在三档差异完全由 preset 键经生效集链路体现。
|
|
40
46
|
*/
|
|
41
47
|
const DEFAULT_CONFIG = {
|
|
42
48
|
preset: 'standard',
|
|
43
|
-
enabled: true,
|
|
44
|
-
ironLaws: {
|
|
45
|
-
enforceErrors: true,
|
|
46
|
-
warnWarnings: true,
|
|
47
|
-
},
|
|
48
|
-
validators: {
|
|
49
|
-
checkpoint: true,
|
|
50
|
-
passesGate: true,
|
|
51
|
-
cso: false,
|
|
52
|
-
},
|
|
53
49
|
};
|
|
54
50
|
|
|
55
51
|
/**
|
|
@@ -59,15 +55,6 @@ const PRESETS = {
|
|
|
59
55
|
strict: {
|
|
60
56
|
...DEFAULT_CONFIG,
|
|
61
57
|
preset: 'strict',
|
|
62
|
-
ironLaws: {
|
|
63
|
-
enforceErrors: true,
|
|
64
|
-
warnWarnings: true,
|
|
65
|
-
},
|
|
66
|
-
validators: {
|
|
67
|
-
checkpoint: true,
|
|
68
|
-
passesGate: true,
|
|
69
|
-
cso: true,
|
|
70
|
-
},
|
|
71
58
|
},
|
|
72
59
|
standard: {
|
|
73
60
|
...DEFAULT_CONFIG,
|
|
@@ -76,10 +63,6 @@ const PRESETS = {
|
|
|
76
63
|
relaxed: {
|
|
77
64
|
...DEFAULT_CONFIG,
|
|
78
65
|
preset: 'relaxed',
|
|
79
|
-
ironLaws: {
|
|
80
|
-
enforceErrors: true,
|
|
81
|
-
warnWarnings: false,
|
|
82
|
-
},
|
|
83
66
|
},
|
|
84
67
|
};
|
|
85
68
|
|
|
@@ -483,7 +466,6 @@ custom_constraints:
|
|
|
483
466
|
# rule: "NO MOMENT.JS IMPORTS"
|
|
484
467
|
# message: "禁止使用 moment.js,请使用 date-fns 或 dayjs"
|
|
485
468
|
# trigger: ["code_implementation"]
|
|
486
|
-
# exceptions: ["legacy_migration"]
|
|
487
469
|
|
|
488
470
|
# 示例 3:要求特定的文件命名
|
|
489
471
|
# my_project_component_naming:
|
|
@@ -492,19 +474,6 @@ custom_constraints:
|
|
|
492
474
|
# rule: "REACT COMPONENTS SHOULD BE PASCAL CASE"
|
|
493
475
|
# message: "React 组件文件名应使用 PascalCase"
|
|
494
476
|
# trigger: ["file_creation"]
|
|
495
|
-
|
|
496
|
-
# ========================================
|
|
497
|
-
# 扩展内置约束的例外
|
|
498
|
-
# ========================================
|
|
499
|
-
|
|
500
|
-
# 如果需要为内置约束添加项目特定的例外,
|
|
501
|
-
# 可以在 .harness/config.yml 中配置:
|
|
502
|
-
|
|
503
|
-
# constraints:
|
|
504
|
-
# no_fix_without_root_cause:
|
|
505
|
-
# # 添加项目特定的例外
|
|
506
|
-
# exceptions:
|
|
507
|
-
# - my_custom_exception
|
|
508
477
|
`;
|
|
509
478
|
|
|
510
479
|
await fs.writeFile(customConstraintsPath, content, 'utf-8');
|
|
@@ -600,7 +569,102 @@ export async function setupClaudeMdOutputStyle(projectPath: string): Promise<voi
|
|
|
600
569
|
}
|
|
601
570
|
|
|
602
571
|
/**
|
|
603
|
-
*
|
|
572
|
+
* 治理契约 PRESERVE 段标记(studio #302,ADR 2026-08-21 落点模型:
|
|
573
|
+
* 治理契约正本住 AGENTS.md 手写 PRESERVE 段,sync-docs 重新生成时原样保留)
|
|
574
|
+
*/
|
|
575
|
+
const GOVERNANCE_PRESERVE_BEGIN = '<!-- PRESERVE:governance -->';
|
|
576
|
+
const GOVERNANCE_PRESERVE_END = '<!-- /PRESERVE:governance -->';
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* 在 AGENTS.md 的 PRESERVE:governance 段写入/更新 Governance Rules 约束段(新落点模型)
|
|
580
|
+
*
|
|
581
|
+
* - AGENTS.md 不存在:创建最小骨架(标题 + 说明 + PRESERVE:governance 段),
|
|
582
|
+
* 完整导读由 `harness sync-docs --agents` 生成,PRESERVE 段在重新生成时原样保留
|
|
583
|
+
* - 已有 PRESERVE:governance 段:段内机器管理的只有 HARNESS_CONSTRAINTS 标记区间——
|
|
584
|
+
* 有标记则只替换标记区间,段内其余手写内容(治理契约引言/流程/纪律等)原样保留;
|
|
585
|
+
* 无标记(纯手写段)则在段尾追加注入段,不动手写内容
|
|
586
|
+
* - 无该段:在文件末尾追加
|
|
587
|
+
* - 段标记残缺(只有单边标记):不写入,告警交由人工修复(防二次损坏)
|
|
588
|
+
*/
|
|
589
|
+
export async function setupAgentsMdConstraints(projectPath: string): Promise<void> {
|
|
590
|
+
const agentsMdPath = path.join(projectPath, 'AGENTS.md');
|
|
591
|
+
const version = getPackageVersion();
|
|
592
|
+
|
|
593
|
+
const constraints = getEffectiveConstraints(projectPath);
|
|
594
|
+
const bodyOnly = renderConstraintsSection(constraints, version);
|
|
595
|
+
const block = `${GOVERNANCE_PRESERVE_BEGIN}\n## Governance Rules\n${bodyOnly}${GOVERNANCE_PRESERVE_END}\n`;
|
|
596
|
+
|
|
597
|
+
let existingContent: string | null = null;
|
|
598
|
+
try {
|
|
599
|
+
existingContent = await fs.readFile(agentsMdPath, 'utf-8');
|
|
600
|
+
} catch {
|
|
601
|
+
// AGENTS.md 不存在
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
if (existingContent === null) {
|
|
605
|
+
const skeleton = [
|
|
606
|
+
'# AGENTS.md',
|
|
607
|
+
'',
|
|
608
|
+
'> 机器生成部分由 `harness sync-docs --agents` 维护;`PRESERVE:governance` 段是治理契约正本(手写/治理变更流程管控),重新生成时原样保留。',
|
|
609
|
+
'',
|
|
610
|
+
block,
|
|
611
|
+
].join('\n');
|
|
612
|
+
await fs.writeFile(agentsMdPath, skeleton, 'utf-8');
|
|
613
|
+
console.log(chalk.green(`✅ 已创建 AGENTS.md 并写入治理契约 PRESERVE:governance 段 (v${version})`));
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
const startIdx = existingContent.indexOf(GOVERNANCE_PRESERVE_BEGIN);
|
|
618
|
+
const endIdx = existingContent.indexOf(GOVERNANCE_PRESERVE_END);
|
|
619
|
+
|
|
620
|
+
if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
|
|
621
|
+
// 段内机器管理的只有 HARNESS_CONSTRAINTS 标记区间;其余手写内容原样保留
|
|
622
|
+
const before = existingContent.slice(0, startIdx);
|
|
623
|
+
const blockContent = existingContent.slice(startIdx + GOVERNANCE_PRESERVE_BEGIN.length, endIdx);
|
|
624
|
+
const after = existingContent.slice(endIdx + GOVERNANCE_PRESERVE_END.length).replace(/^\n+/, '');
|
|
625
|
+
|
|
626
|
+
const csIdx = blockContent.indexOf(CONSTRAINTS_START_MARKER);
|
|
627
|
+
const ceIdx = blockContent.indexOf(CONSTRAINTS_END_MARKER);
|
|
628
|
+
let newBlockContent: string;
|
|
629
|
+
if (csIdx !== -1 && ceIdx !== -1 && ceIdx > csIdx) {
|
|
630
|
+
// 只替换标记区间。bodyOnly 自带结尾换行,故剥掉尾部恰好一个前导换行
|
|
631
|
+
// (END 标记行的行尾换行),其余手写内容逐字保留,保证幂等。
|
|
632
|
+
newBlockContent =
|
|
633
|
+
blockContent.slice(0, csIdx) +
|
|
634
|
+
bodyOnly +
|
|
635
|
+
blockContent.slice(ceIdx + CONSTRAINTS_END_MARKER.length).replace(/^\n/, '');
|
|
636
|
+
} else {
|
|
637
|
+
// 纯手写段(无约束标记):段尾追加注入段,手写内容不动
|
|
638
|
+
newBlockContent = blockContent.trimEnd() + '\n\n## Governance Rules\n' + bodyOnly;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
const newContent =
|
|
642
|
+
before +
|
|
643
|
+
GOVERNANCE_PRESERVE_BEGIN +
|
|
644
|
+
newBlockContent +
|
|
645
|
+
GOVERNANCE_PRESERVE_END +
|
|
646
|
+
'\n' +
|
|
647
|
+
(after ? '\n' + after : '');
|
|
648
|
+
if (newContent !== existingContent) {
|
|
649
|
+
await fs.writeFile(agentsMdPath, newContent, 'utf-8');
|
|
650
|
+
console.log(chalk.green(`✅ 已更新 AGENTS.md 治理契约 PRESERVE:governance 段 (v${version})`));
|
|
651
|
+
}
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
if (startIdx !== -1 || endIdx !== -1) {
|
|
656
|
+
console.log(chalk.yellow('⚠️ AGENTS.md 中 PRESERVE:governance 标记残缺(只有单边),跳过治理契约写入,请人工修复'));
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// 无该段:文件末尾追加
|
|
661
|
+
const newContent = existingContent.trimEnd() + '\n\n' + block;
|
|
662
|
+
await fs.writeFile(agentsMdPath, newContent, 'utf-8');
|
|
663
|
+
console.log(chalk.green(`✅ 已追加治理契约 PRESERVE:governance 段到 AGENTS.md (v${version})`));
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* 在 CLAUDE.md 中写入/更新 Governance Rules 约束段(旧落点模型,向后兼容保留)
|
|
604
668
|
*
|
|
605
669
|
* - 约束集来自 getEffectiveConstraints(ADR-0001):preset 裁剪、config.yml
|
|
606
670
|
* 禁用、custom 追加、scenes 过滤全部反映在注入文本里
|
|
@@ -663,6 +727,30 @@ export async function setupClaudeMdConstraints(projectPath: string): Promise<voi
|
|
|
663
727
|
}
|
|
664
728
|
}
|
|
665
729
|
|
|
730
|
+
/**
|
|
731
|
+
* 治理约束段写入落点路由(studio #302,ADR 2026-08-21 落点模型)
|
|
732
|
+
*
|
|
733
|
+
* - 旧模型仓(CLAUDE.md 已有 HARNESS_CONSTRAINTS 标记或 `## Governance Rules` 块):
|
|
734
|
+
* 继续写 CLAUDE.md——init 幂等重跑不破坏既有仓,不制造双份约束正本
|
|
735
|
+
* - 其余(新仓初始化):写 AGENTS.md PRESERVE:governance 段(入库公共面正本)
|
|
736
|
+
*/
|
|
737
|
+
export async function setupGovernanceConstraints(projectPath: string): Promise<void> {
|
|
738
|
+
let claudeContent: string | null = null;
|
|
739
|
+
try {
|
|
740
|
+
claudeContent = await fs.readFile(path.join(projectPath, 'CLAUDE.md'), 'utf-8');
|
|
741
|
+
} catch {
|
|
742
|
+
// CLAUDE.md 不存在 → 新仓
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
if (
|
|
746
|
+
claudeContent !== null &&
|
|
747
|
+
(claudeContent.includes(CONSTRAINTS_START_MARKER) || /^##\s+Governance Rules/m.test(claudeContent))
|
|
748
|
+
) {
|
|
749
|
+
return setupClaudeMdConstraints(projectPath);
|
|
750
|
+
}
|
|
751
|
+
return setupAgentsMdConstraints(projectPath);
|
|
752
|
+
}
|
|
753
|
+
|
|
666
754
|
/**
|
|
667
755
|
* 设置治理相关文件
|
|
668
756
|
*/
|
|
@@ -679,8 +767,9 @@ async function setupGovernance(projectPath: string, level: string): Promise<void
|
|
|
679
767
|
// 2. 在 CLAUDE.md 中写入 Output Style 段(仅在不存在时创建)
|
|
680
768
|
await setupClaudeMdOutputStyle(projectPath);
|
|
681
769
|
|
|
682
|
-
// 3.
|
|
683
|
-
|
|
770
|
+
// 3. 写入/更新 Governance Rules 约束段(新仓 → AGENTS.md PRESERVE:governance;
|
|
771
|
+
// 旧模型仓 → CLAUDE.md,落点路由见 setupGovernanceConstraints)
|
|
772
|
+
await setupGovernanceConstraints(projectPath);
|
|
684
773
|
|
|
685
774
|
// 4. 生成 CONTEXT.md 文件
|
|
686
775
|
const contextConfig = governance.context_files as Record<string, unknown> | undefined;
|
|
@@ -81,22 +81,7 @@ export async function knowledgeSearch(
|
|
|
81
81
|
const store = new KnowledgeStore({ baseDir: getKnowledgeDir(options.projectPath) });
|
|
82
82
|
const queryEngine = new KnowledgeQuery(store);
|
|
83
83
|
|
|
84
|
-
const
|
|
85
|
-
phase: 'cli',
|
|
86
|
-
maxTokens: 10000,
|
|
87
|
-
maxEntries: options.limit || 20,
|
|
88
|
-
focusTypes: [] as KnowledgeSubsystem[],
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const result = queryEngine.query(budget);
|
|
92
|
-
|
|
93
|
-
// 简单文本匹配过滤
|
|
94
|
-
const q = query.toLowerCase();
|
|
95
|
-
const matched = result.entries.filter(e =>
|
|
96
|
-
e.title.toLowerCase().includes(q) ||
|
|
97
|
-
e.content.toLowerCase().includes(q) ||
|
|
98
|
-
e.tags.some(t => t.toLowerCase().includes(q))
|
|
99
|
-
);
|
|
84
|
+
const matched = queryEngine.search(query, { limit: options.limit || 20 });
|
|
100
85
|
|
|
101
86
|
if (options.json) {
|
|
102
87
|
console.log(JSON.stringify({ query, total: matched.length, entries: matched }, null, 2));
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
import chalk from 'chalk';
|
|
8
8
|
import * as fs from 'fs/promises';
|
|
9
9
|
import { ConstraintChecker } from '../../core/constraints/checker';
|
|
10
|
-
import { getTraceCollector } from '../../monitoring/traces';
|
|
11
10
|
import { IRON_LAWS, GUIDELINES, PROMPTS } from '../../core/constraints/definitions';
|
|
12
11
|
import { executeWithCollect } from '../../failure/constraint-handler';
|
|
13
12
|
import type { ConstraintContext } from '../../types/constraint';
|
|
@@ -48,7 +47,6 @@ export async function report(options: ReportOptions): Promise<void> {
|
|
|
48
47
|
|
|
49
48
|
const projectPath = options.projectPath || process.cwd();
|
|
50
49
|
const checker = ConstraintChecker.getInstance();
|
|
51
|
-
checker.setTraceRecorder(getTraceCollector());
|
|
52
50
|
|
|
53
51
|
const allConstraints = { ...IRON_LAWS, ...GUIDELINES, ...PROMPTS };
|
|
54
52
|
const totalConstraints = Object.keys(allConstraints).length;
|
|
@@ -109,7 +109,7 @@ export async function status(options: StatusOptions): Promise<void> {
|
|
|
109
109
|
const status = s.passRate >= 1 ? '✅' : '❌';
|
|
110
110
|
console.log(` ${status} ${s.constraintId}`);
|
|
111
111
|
if (options.detail) {
|
|
112
|
-
console.log(chalk.gray(` 检查: ${s.totalChecks} | 通过: ${(s.passRate * 100).toFixed(0)}% |
|
|
112
|
+
console.log(chalk.gray(` 检查: ${s.totalChecks} | 通过: ${(s.passRate * 100).toFixed(0)}% | 失败: ${(s.failRate * 100).toFixed(0)}%`));
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
115
|
console.log();
|
|
@@ -123,7 +123,7 @@ export async function status(options: StatusOptions): Promise<void> {
|
|
|
123
123
|
const status = s.passRate >= 0.8 ? '✅' : s.passRate >= 0.5 ? '⚠️' : '❌';
|
|
124
124
|
console.log(` ${status} ${s.constraintId}`);
|
|
125
125
|
if (options.detail) {
|
|
126
|
-
console.log(chalk.gray(` 检查: ${s.totalChecks} | 通过: ${(s.passRate * 100).toFixed(0)}% |
|
|
126
|
+
console.log(chalk.gray(` 检查: ${s.totalChecks} | 通过: ${(s.passRate * 100).toFixed(0)}% | 失败: ${(s.failRate * 100).toFixed(0)}%`));
|
|
127
127
|
}
|
|
128
128
|
});
|
|
129
129
|
console.log();
|
package/src/context/index.ts
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 上下文管理模块(ADR-0003:显式清单,禁 export *)
|
|
3
3
|
*
|
|
4
4
|
* Token 预算 + 会话压缩 + 知识注入
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
// 类型
|
|
8
|
+
export type {
|
|
9
|
+
CompactionConfig,
|
|
10
|
+
CompactionLevel,
|
|
11
|
+
ContextSource,
|
|
12
|
+
ContextSourceType,
|
|
13
|
+
ContextUsageSnapshot,
|
|
14
|
+
SessionCheckpoint,
|
|
15
|
+
SessionEvent,
|
|
16
|
+
SessionEventType,
|
|
17
|
+
SessionHandle,
|
|
18
|
+
SessionMessage,
|
|
19
|
+
} from './types';
|
|
20
|
+
export { DEFAULT_COMPACTION_CONFIG } from './types';
|
|
21
|
+
|
|
22
|
+
// Token 预算
|
|
23
|
+
export { AdaptiveTokenBudget, TokenBudget, TokenEstimator } from './token-budget';
|
|
24
|
+
|
|
25
|
+
// 会话压缩
|
|
26
|
+
export { SessionCompaction } from './compaction';
|
|
27
|
+
export type { CompactionResult } from './compaction';
|
|
28
|
+
|
|
29
|
+
// 会话管理
|
|
30
|
+
export { SessionManager } from './session-manager';
|
|
31
|
+
|
|
32
|
+
// 知识注入
|
|
33
|
+
export { KnowledgeInjector } from './knowledge-injector';
|
|
34
|
+
export type { InjectionConfig, InjectionResult } from './knowledge-injector';
|
package/src/core/CONTEXT.md
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
约束引擎核心:check/prompt 二元约束系统(ADR-0001)、生效集合并(effective-constraints)、检查点验证器(CSO/passes-gate)、会话管理、Spec 验证器、项目配置加载。
|
|
5
5
|
|
|
6
6
|
## 核心导出
|
|
7
|
-
- `constraints/` — 约束定义(IRON_LAWS/GUIDELINES/PROMPTS) + 检查引擎(ConstraintChecker
|
|
8
|
-
- `effective-constraints.ts` — `getEffectiveConstraints(projectRoot)`:全仓唯一生效集来源(内置 → preset → config.yml 禁用(内置与 custom 同效)→ custom 追加(禁用/已退役的不追加)→ scenes 过滤);`lintEffectiveConfig` 配置诊断
|
|
7
|
+
- `constraints/` — 约束定义(IRON_LAWS/GUIDELINES/PROMPTS) + 检查引擎(ConstraintChecker,拦截统一由 checkBeforeExecution 承担,ADR-0004) + 缓存(CheckCache:TTL 缓存 + 计数采样,H6/G5 起公开导出) + 注入渲染(injection-renderer) + Agent prompt 渲染(agent-prompt-renderer:trigger 参数化分组渲染,role 路由留 studio,H6/G6)/漂移校验(injection-drift:含注入段落点路由 resolveInjectionTarget,CLAUDE.md 有标记优先、否则 AGENTS.md PRESERVE:governance,studio #307)/使用统计(usage-report);CheckEnv 生产侧唯一构造点 `buildCheckEnv(context, providers|'none')`(checkers/types.ts:providers = 证据接线,'none' = 显式不接 → evidence flag checker 按契约 skip)
|
|
8
|
+
- `effective-constraints.ts` — `getEffectiveConstraints(projectRoot, {preset?})`:全仓唯一生效集来源(内置 → preset → config.yml 禁用(内置与 custom 同效)→ custom 追加(禁用/已退役的不追加)→ scenes 过滤);`getMergedConstraintsConfig(projectRoot, {preset?})`:同链路的完整 MergedConstraintsConfig 形状(含 disabled/custom/unknownIds),内置工单 23 优先级规则(--preset 仅在无项目自定义配置时生效),check 命令经此入口;`lintEffectiveConfig` 配置诊断
|
|
9
|
+
- `effective-set.ts` — `filterEnabledEntries(knownIds, entries, {onUnknownId})`:约束侧(collect)与门禁侧(throw)共用的 config 条目筛选器
|
|
9
10
|
- `validators/` — checkpoints、passes-gate、CSO 验证器
|
|
10
11
|
- `session/` — 会话管理
|
|
11
12
|
- `spec/validator` — SpecValidator
|
|
12
|
-
- `project-config-loader` — 项目配置加载 +
|
|
13
|
+
- `project-config-loader` — 项目配置加载 + 约束合并(mergeConstraints 内含 preset 裁剪:presets/ 纯数据 + 未知名回落 standard,禁用到未知 id 经 effective-set 共享筛选器 collect 模式)
|
|
13
14
|
|
|
14
15
|
## 依赖关系
|
|
15
16
|
- 被所有模块依赖(基础层,无上层依赖)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* effective-set 共享筛选器测试
|
|
3
|
+
*
|
|
4
|
+
* 覆盖约束侧(collect)与门禁侧(throw)两种 onUnknownId 模式。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { filterEnabledEntries } from '../effective-set';
|
|
8
|
+
|
|
9
|
+
const KNOWN = new Set(['a', 'b', 'c']);
|
|
10
|
+
|
|
11
|
+
describe('filterEnabledEntries', () => {
|
|
12
|
+
describe('onUnknownId: collect(约束侧)', () => {
|
|
13
|
+
it('已知 id 全部通过,enabled:false 收进 disabledIds', () => {
|
|
14
|
+
const result = filterEnabledEntries(
|
|
15
|
+
KNOWN,
|
|
16
|
+
{ a: { enabled: false }, b: { enabled: true }, c: {} },
|
|
17
|
+
{ onUnknownId: 'collect' }
|
|
18
|
+
);
|
|
19
|
+
expect(result.disabledIds).toEqual(['a']);
|
|
20
|
+
expect(result.unknownIds).toEqual([]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('未知 id 静默忽略并收集进 unknownIds', () => {
|
|
24
|
+
const result = filterEnabledEntries(
|
|
25
|
+
KNOWN,
|
|
26
|
+
{ a: {}, ghost: { enabled: false } },
|
|
27
|
+
{ onUnknownId: 'collect' }
|
|
28
|
+
);
|
|
29
|
+
expect(result.unknownIds).toEqual(['ghost']);
|
|
30
|
+
// 未知 id 带 enabled:false 同样计入 disabledIds(历史行为:delete 空桶为 no-op)
|
|
31
|
+
expect(result.disabledIds).toEqual(['ghost']);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('未知 id 无 enabled 标记时只收集不进 disabledIds', () => {
|
|
35
|
+
const result = filterEnabledEntries(
|
|
36
|
+
KNOWN,
|
|
37
|
+
{ ghost: {} },
|
|
38
|
+
{ onUnknownId: 'collect' }
|
|
39
|
+
);
|
|
40
|
+
expect(result.unknownIds).toEqual(['ghost']);
|
|
41
|
+
expect(result.disabledIds).toEqual([]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('空 entries → 空结果', () => {
|
|
45
|
+
const result = filterEnabledEntries(KNOWN, {}, { onUnknownId: 'collect' });
|
|
46
|
+
expect(result).toEqual({ disabledIds: [], unknownIds: [] });
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('onUnknownId: throw(门禁侧)', () => {
|
|
51
|
+
it('未知 id 抛错(默认消息)', () => {
|
|
52
|
+
expect(() =>
|
|
53
|
+
filterEnabledEntries(KNOWN, { nope: { enabled: false } }, { onUnknownId: 'throw' })
|
|
54
|
+
).toThrow(/未注册的 id "nope"/);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('未知 id 抛错(unknownIdError 定制消息)', () => {
|
|
58
|
+
expect(() =>
|
|
59
|
+
filterEnabledEntries(
|
|
60
|
+
KNOWN,
|
|
61
|
+
{ nope: {} },
|
|
62
|
+
{
|
|
63
|
+
onUnknownId: 'throw',
|
|
64
|
+
unknownIdError: id => `gates.${id} 引用了未注册的门禁。可用门禁: a, b, c。`,
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
).toThrow(/gates\.nope 引用了未注册的门禁/);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('已知 id 的 enabled:false 正常收集,不抛错', () => {
|
|
71
|
+
const result = filterEnabledEntries(
|
|
72
|
+
KNOWN,
|
|
73
|
+
{ a: { enabled: false }, b: { enabled: true } },
|
|
74
|
+
{ onUnknownId: 'throw' }
|
|
75
|
+
);
|
|
76
|
+
expect(result.disabledIds).toEqual(['a']);
|
|
77
|
+
expect(result.unknownIds).toEqual([]);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|