@dommaker/harness 1.9.0 → 1.11.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 +17 -0
- package/README.md +9 -12
- package/dist/cli/commands/check.d.ts +3 -3
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +41 -78
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/constraints-report.d.ts +2 -10
- package/dist/cli/commands/constraints-report.d.ts.map +1 -1
- package/dist/cli/commands/constraints-report.js +4 -57
- package/dist/cli/commands/constraints-report.js.map +1 -1
- package/dist/cli/commands/constraints-retire.d.ts +9 -23
- package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
- package/dist/cli/commands/constraints-retire.js +39 -121
- package/dist/cli/commands/constraints-retire.js.map +1 -1
- package/dist/cli/commands/constraints.d.ts +3 -8
- package/dist/cli/commands/constraints.d.ts.map +1 -1
- package/dist/cli/commands/constraints.js +8 -23
- package/dist/cli/commands/constraints.js.map +1 -1
- package/dist/cli/commands/definitions.d.ts.map +1 -1
- package/dist/cli/commands/definitions.js +7 -12
- package/dist/cli/commands/definitions.js.map +1 -1
- package/dist/cli/commands/init.d.ts +0 -32
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +7 -149
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/report.d.ts.map +1 -1
- package/dist/cli/commands/report.js +14 -17
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/scaffold-templates.d.ts +1 -3
- package/dist/cli/commands/scaffold-templates.d.ts.map +1 -1
- package/dist/cli/commands/scaffold-templates.js +2 -53
- package/dist/cli/commands/scaffold-templates.js.map +1 -1
- package/dist/cli/commands/scaffold.d.ts +0 -2
- package/dist/cli/commands/scaffold.d.ts.map +1 -1
- package/dist/cli/commands/scaffold.js +0 -10
- package/dist/cli/commands/scaffold.js.map +1 -1
- package/dist/cli/commands/status.js +10 -10
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/sync-docs/agents-syncer.d.ts +0 -2
- package/dist/cli/commands/sync-docs/agents-syncer.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/agents-syncer.js +4 -23
- package/dist/cli/commands/sync-docs/agents-syncer.js.map +1 -1
- package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
- package/dist/core/constraints/capabilities-parser.js +16 -4
- package/dist/core/constraints/capabilities-parser.js.map +1 -1
- package/dist/core/constraints/checker.d.ts +15 -24
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +33 -72
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.js +1 -1
- package/dist/core/constraints/checkers/docs-freshness.js.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.d.ts +2 -1
- package/dist/core/constraints/checkers/governance-presence.d.ts.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.js +4 -3
- package/dist/core/constraints/checkers/governance-presence.js.map +1 -1
- package/dist/core/constraints/checkers/index.d.ts +1 -1
- package/dist/core/constraints/checkers/index.d.ts.map +1 -1
- package/dist/core/constraints/checkers/index.js +4 -8
- package/dist/core/constraints/checkers/index.js.map +1 -1
- package/dist/core/constraints/checkers/iron-flags.d.ts +3 -4
- package/dist/core/constraints/checkers/iron-flags.d.ts.map +1 -1
- package/dist/core/constraints/checkers/iron-flags.js +4 -5
- package/dist/core/constraints/checkers/iron-flags.js.map +1 -1
- package/dist/core/constraints/checkers/no-test-simplification.js +1 -1
- package/dist/core/constraints/checkers/no-test-simplification.js.map +1 -1
- package/dist/core/constraints/checkers/types.d.ts +1 -1
- package/dist/core/constraints/checkers/types.js +1 -1
- package/dist/core/constraints/definitions/guidelines.d.ts +4 -4
- package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
- package/dist/core/constraints/definitions/guidelines.js +9 -25
- package/dist/core/constraints/definitions/guidelines.js.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.d.ts +4 -4
- package/dist/core/constraints/definitions/iron-laws.d.ts.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.js +10 -81
- package/dist/core/constraints/definitions/iron-laws.js.map +1 -1
- package/dist/core/constraints/definitions.d.ts +7 -9
- package/dist/core/constraints/definitions.d.ts.map +1 -1
- package/dist/core/constraints/definitions.js +13 -16
- package/dist/core/constraints/definitions.js.map +1 -1
- package/dist/core/constraints/index.d.ts +2 -5
- package/dist/core/constraints/index.d.ts.map +1 -1
- package/dist/core/constraints/index.js +3 -13
- package/dist/core/constraints/index.js.map +1 -1
- package/dist/core/constraints/injection-writer.d.ts +10 -38
- package/dist/core/constraints/injection-writer.d.ts.map +1 -1
- package/dist/core/constraints/injection-writer.js +17 -54
- package/dist/core/constraints/injection-writer.js.map +1 -1
- package/dist/core/constraints/run-env.d.ts +1 -10
- package/dist/core/constraints/run-env.d.ts.map +1 -1
- package/dist/core/constraints/run-env.js +1 -22
- package/dist/core/constraints/run-env.js.map +1 -1
- package/dist/core/constraints/usage-report.d.ts +6 -8
- package/dist/core/constraints/usage-report.d.ts.map +1 -1
- package/dist/core/constraints/usage-report.js +6 -11
- package/dist/core/constraints/usage-report.js.map +1 -1
- package/dist/core/effective-constraints.d.ts +12 -22
- package/dist/core/effective-constraints.d.ts.map +1 -1
- package/dist/core/effective-constraints.js +13 -30
- package/dist/core/effective-constraints.js.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -9
- package/dist/core/index.js.map +1 -1
- package/dist/core/project-config-loader.d.ts +4 -42
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +16 -125
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/core/validators/passes-gate.d.ts +2 -2
- package/dist/core/validators/passes-gate.js +6 -6
- package/dist/core/validators/passes-gate.js.map +1 -1
- package/dist/index.d.ts +9 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -18
- package/dist/index.js.map +1 -1
- package/dist/knowledge/lint.d.ts +17 -0
- package/dist/knowledge/lint.d.ts.map +1 -1
- package/dist/knowledge/lint.js +52 -0
- package/dist/knowledge/lint.js.map +1 -1
- package/dist/knowledge/store.d.ts +7 -0
- package/dist/knowledge/store.d.ts.map +1 -1
- package/dist/knowledge/store.js +48 -13
- package/dist/knowledge/store.js.map +1 -1
- package/dist/knowledge/types.d.ts +5 -1
- package/dist/knowledge/types.d.ts.map +1 -1
- package/dist/knowledge/types.js +5 -1
- package/dist/knowledge/types.js.map +1 -1
- package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
- package/dist/monitoring/trace-analyzer.js +11 -12
- package/dist/monitoring/trace-analyzer.js.map +1 -1
- package/dist/monitoring/traces.d.ts +4 -4
- package/dist/monitoring/traces.d.ts.map +1 -1
- package/dist/monitoring/traces.js +8 -8
- package/dist/monitoring/traces.js.map +1 -1
- package/dist/presets/standard.d.ts +8 -10
- package/dist/presets/standard.d.ts.map +1 -1
- package/dist/presets/standard.js +10 -16
- package/dist/presets/standard.js.map +1 -1
- package/dist/types/constraint.d.ts +24 -35
- package/dist/types/constraint.d.ts.map +1 -1
- package/dist/types/constraint.js +8 -7
- package/dist/types/constraint.js.map +1 -1
- package/dist/types/passes-gate.d.ts +5 -5
- package/dist/types/passes-gate.d.ts.map +1 -1
- package/dist/types/project-config.d.ts +8 -66
- package/dist/types/project-config.d.ts.map +1 -1
- package/dist/types/project-config.js +3 -2
- package/dist/types/project-config.js.map +1 -1
- package/dist/types/trace.d.ts +8 -10
- package/dist/types/trace.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/CONTEXT.md +2 -2
- package/src/__tests__/checker-extra.test.ts +37 -61
- package/src/__tests__/checker.test.ts +10 -115
- package/src/__tests__/effective-constraints.test.ts +18 -83
- package/src/__tests__/iron-laws.test.ts +71 -90
- package/src/__tests__/passes-gate-check.test.ts +2 -2
- package/src/__tests__/project-config-loader-extra.test.ts +22 -123
- package/src/__tests__/project-config-loader.test.ts +5 -33
- package/src/__tests__/public-exports.test.ts +8 -7
- package/src/__tests__/public-type-surface.test.ts +7 -5
- package/src/__tests__/public-value-surface.test.ts +1 -7
- package/src/__tests__/skip-semantics.test.ts +21 -37
- package/src/__tests__/trace-analyzer-extra.test.ts +14 -14
- package/src/__tests__/trace-analyzer.test.ts +21 -21
- package/src/__tests__/trace-collector.test.ts +22 -22
- package/src/__tests__/traces.test.ts +27 -28
- package/src/__tests__/usage-report-public-export.test.ts +21 -0
- package/src/cli/commands/CONTEXT.md +12 -12
- package/src/cli/commands/__tests__/check-read-count.test.ts +4 -15
- package/src/cli/commands/__tests__/check-skip-output.test.ts +14 -14
- package/src/cli/commands/__tests__/check.test.ts +14 -31
- package/src/cli/commands/__tests__/constraints-report-json-flag.test.ts +101 -0
- package/src/cli/commands/__tests__/constraints-report.test.ts +12 -80
- package/src/cli/commands/__tests__/constraints-retire.test.ts +42 -231
- package/src/cli/commands/__tests__/init-governance-io.test.ts +12 -58
- package/src/cli/commands/__tests__/init-ondisk.test.ts +13 -21
- package/src/cli/commands/__tests__/init.test.ts +1 -16
- package/src/cli/commands/__tests__/numeric-flag-assembly.test.ts +1 -1
- package/src/cli/commands/__tests__/passes-gate-dead-options.test.ts +1 -1
- package/src/cli/commands/__tests__/project-path-anchoring.test.ts +2 -2
- package/src/cli/commands/__tests__/registry.test.ts +1 -1
- package/src/cli/commands/__tests__/report-extra.test.ts +4 -4
- package/src/cli/commands/__tests__/report.test.ts +1 -1
- package/src/cli/commands/__tests__/scaffold.test.ts +4 -14
- package/src/cli/commands/__tests__/status-analysis-wiring.test.ts +3 -3
- package/src/cli/commands/__tests__/status-extra.test.ts +14 -14
- package/src/cli/commands/__tests__/status.test.ts +12 -12
- package/src/cli/commands/__tests__/sync-docs-agents.test.ts +1 -1
- package/src/cli/commands/check.ts +43 -82
- package/src/cli/commands/constraints-report.ts +4 -59
- package/src/cli/commands/constraints-retire.ts +49 -154
- package/src/cli/commands/constraints.ts +11 -26
- package/src/cli/commands/definitions.ts +7 -12
- package/src/cli/commands/init.ts +8 -179
- package/src/cli/commands/report.ts +19 -23
- package/src/cli/commands/scaffold-templates.ts +1 -53
- package/src/cli/commands/scaffold.ts +0 -11
- package/src/cli/commands/status.ts +10 -10
- package/src/cli/commands/sync-docs/agents-syncer.ts +4 -25
- package/src/core/CONTEXT.md +9 -9
- package/src/core/constraints/__tests__/capability-counts.test.ts +5 -5
- package/src/core/constraints/__tests__/collect-constraints.test.ts +13 -8
- package/src/core/constraints/__tests__/git-evidence.test.ts +4 -7
- package/src/core/constraints/__tests__/injection-writer.test.ts +8 -61
- package/src/core/constraints/__tests__/run-env.test.ts +5 -34
- package/src/core/constraints/__tests__/trace-injection.test.ts +1 -1
- package/src/core/constraints/capabilities-parser.ts +17 -5
- package/src/core/constraints/checker.ts +39 -88
- package/src/core/constraints/checkers/__tests__/check-outcome.test.ts +5 -8
- package/src/core/constraints/checkers/__tests__/governance-presence.test.ts +1 -53
- package/src/core/constraints/checkers/__tests__/iron-flags.test.ts +5 -25
- package/src/core/constraints/checkers/docs-freshness.ts +1 -1
- package/src/core/constraints/checkers/governance-presence.ts +4 -3
- package/src/core/constraints/checkers/index.ts +4 -10
- package/src/core/constraints/checkers/iron-flags.ts +3 -12
- package/src/core/constraints/checkers/no-test-simplification.ts +1 -1
- package/src/core/constraints/checkers/types.ts +1 -1
- package/src/core/constraints/definitions/guidelines.ts +8 -25
- package/src/core/constraints/definitions/iron-laws.ts +9 -82
- package/src/core/constraints/definitions.ts +14 -15
- package/src/core/constraints/index.ts +4 -19
- package/src/core/constraints/injection-writer.ts +16 -61
- package/src/core/constraints/run-env.ts +1 -33
- package/src/core/constraints/usage-report.ts +9 -16
- package/src/core/effective-constraints.ts +14 -45
- package/src/core/index.ts +3 -10
- package/src/core/project-config-loader.ts +20 -145
- package/src/core/validators/passes-gate.ts +6 -6
- package/src/failure/CONTEXT.md +1 -1
- package/src/hooks/__tests__/bootstrap.test.ts +3 -5
- package/src/index.ts +28 -18
- package/src/knowledge/CONTEXT.md +4 -3
- package/src/knowledge/__tests__/lint.test.ts +84 -0
- package/src/knowledge/__tests__/store.test.ts +70 -0
- package/src/knowledge/lint.ts +60 -1
- package/src/knowledge/store.ts +48 -11
- package/src/knowledge/types.ts +7 -1
- package/src/monitoring/CONTEXT.md +1 -1
- package/src/monitoring/__tests__/trace-file-anchoring.test.ts +1 -1
- package/src/monitoring/__tests__/traces.test.ts +22 -22
- package/src/monitoring/trace-analyzer.ts +12 -13
- package/src/monitoring/traces.ts +8 -8
- package/src/presets/__tests__/standard.test.ts +12 -16
- package/src/presets/standard.ts +14 -23
- package/src/types/__tests__/types.test.ts +3 -3
- package/src/types/constraint.ts +26 -40
- package/src/types/passes-gate.ts +5 -5
- package/src/types/project-config.ts +8 -77
- package/src/types/trace.ts +8 -11
- package/dist/cli/commands/posteval-plan.d.ts +0 -15
- package/dist/cli/commands/posteval-plan.d.ts.map +0 -1
- package/dist/cli/commands/posteval-plan.js +0 -86
- package/dist/cli/commands/posteval-plan.js.map +0 -1
- package/dist/core/constraints/agent-prompt-renderer.d.ts +0 -32
- package/dist/core/constraints/agent-prompt-renderer.d.ts.map +0 -1
- package/dist/core/constraints/agent-prompt-renderer.js +0 -55
- package/dist/core/constraints/agent-prompt-renderer.js.map +0 -1
- package/dist/core/constraints/checkers/no-bypass-checkpoint.d.ts +0 -6
- package/dist/core/constraints/checkers/no-bypass-checkpoint.d.ts.map +0 -1
- package/dist/core/constraints/checkers/no-bypass-checkpoint.js +0 -40
- package/dist/core/constraints/checkers/no-bypass-checkpoint.js.map +0 -1
- package/dist/core/constraints/definitions/prompts.d.ts +0 -12
- package/dist/core/constraints/definitions/prompts.d.ts.map +0 -1
- package/dist/core/constraints/definitions/prompts.js +0 -400
- package/dist/core/constraints/definitions/prompts.js.map +0 -1
- package/dist/core/constraints/injection-drift.d.ts +0 -61
- package/dist/core/constraints/injection-drift.d.ts.map +0 -1
- package/dist/core/constraints/injection-drift.js +0 -131
- package/dist/core/constraints/injection-drift.js.map +0 -1
- package/dist/core/constraints/injection-renderer.d.ts +0 -23
- package/dist/core/constraints/injection-renderer.d.ts.map +0 -1
- package/dist/core/constraints/injection-renderer.js +0 -44
- package/dist/core/constraints/injection-renderer.js.map +0 -1
- package/src/cli/commands/__tests__/check-drift.test.ts +0 -158
- package/src/cli/commands/__tests__/init-injection.test.ts +0 -466
- package/src/cli/commands/__tests__/posteval-plan.test.ts +0 -204
- package/src/cli/commands/posteval-plan.ts +0 -98
- package/src/core/constraints/__tests__/agent-prompt-renderer.test.ts +0 -129
- package/src/core/constraints/__tests__/injection-drift.test.ts +0 -247
- package/src/core/constraints/agent-prompt-renderer.ts +0 -67
- package/src/core/constraints/checkers/__tests__/no-bypass-checkpoint.test.ts +0 -76
- package/src/core/constraints/checkers/no-bypass-checkpoint.ts +0 -40
- package/src/core/constraints/definitions/prompts.ts +0 -414
- package/src/core/constraints/injection-drift.ts +0 -142
- package/src/core/constraints/injection-renderer.ts +0 -44
|
@@ -1,41 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 标记区间写入器 + 治理正本探测(架构评审候选1,ADR-0011)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* ADR-0029:约束注入段(HARNESS_CONSTRAINTS)已整体关停——本模块不再承担
|
|
5
|
+
* 注入段渲染/落点路由(resolveInjectionTarget / resolveGovernanceLanding 随删),
|
|
6
|
+
* 保留的是通用机制:
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* 「按渲染 body 替换标记区间 + 尾换行规一」的切片数学。形状两种
|
|
9
|
+
* (排版约定不同,非"算哪些"的差异,故合法分叉):
|
|
9
10
|
* - replaceStandaloneRange:区间独立成节,END 标记后折叠为恰好一个空行
|
|
10
|
-
* (CLAUDE.md
|
|
11
|
+
* (CLAUDE.md Output Style 段)
|
|
11
12
|
* - replaceEnclosedRange:区间后紧跟外层收口标记(AGENTS.md PRESERVE 段内
|
|
12
|
-
*
|
|
13
|
+
* 区间)——恰好剥一个换行,手写余文原样落回
|
|
13
14
|
*
|
|
14
15
|
* 半标记守护:单边缺失或顺序颠倒 → 'half',拒写(旧实现此时或追加出双份
|
|
15
16
|
* 正本或产生乱序切片,属二次损坏路径,收紧为告警交人工,见 ADR-0011)。
|
|
16
17
|
*
|
|
17
|
-
* 落点路由同规则一份:
|
|
18
|
-
* - resolveInjectionTarget:读侧(漂移检测/retire 同步)——CLAUDE.md 有完整
|
|
19
|
-
* 标记段优先(旧模型仓豁免),否则 AGENTS.md(新模型仓住 PRESERVE 段内)
|
|
20
|
-
* - resolveGovernanceLanding:写侧(init 落点选择)——额外承认 CLAUDE.md
|
|
21
|
-
* 无标记的 `## Governance Rules` 旧块(续写不制造双份正本)
|
|
22
|
-
*
|
|
23
18
|
* 探测/判定同住本模块(#83,ADR-0011 补注:收口范围含探测器,不只写器)——
|
|
24
|
-
* 「这份文档里有没有治理契约 /
|
|
25
|
-
*
|
|
26
|
-
* hasPreserveBlock。
|
|
19
|
+
* 「这份文档里有没有治理契约 / 有几个正本标题」,见文末 GOVERNANCE_HEADING /
|
|
20
|
+
* hasGovernanceContract / countGovernanceHeadings / hasPreserveBlock。
|
|
27
21
|
*/
|
|
28
22
|
|
|
29
23
|
import * as fs from 'fs';
|
|
30
|
-
import * as path from 'path';
|
|
31
|
-
import {
|
|
32
|
-
CONSTRAINTS_START_MARKER,
|
|
33
|
-
CONSTRAINTS_END_MARKER,
|
|
34
|
-
} from './injection-renderer';
|
|
35
|
-
|
|
36
|
-
/** 注入段落点文件名(检测顺序即路由优先级:旧模型仓 CLAUDE.md 优先) */
|
|
37
|
-
export const INJECTION_FILES = ['CLAUDE.md', 'AGENTS.md'] as const;
|
|
38
|
-
export type InjectionFile = (typeof INJECTION_FILES)[number];
|
|
39
24
|
|
|
40
25
|
/** 标记区间替换结果 */
|
|
41
26
|
export type MarkerWrite =
|
|
@@ -111,40 +96,6 @@ export function replaceEnclosedRange(content: string, begin: string, end: string
|
|
|
111
96
|
};
|
|
112
97
|
}
|
|
113
98
|
|
|
114
|
-
/**
|
|
115
|
-
* 读侧路由:定位含完整 HARNESS_CONSTRAINTS 标记段的文件(studio #307)。
|
|
116
|
-
* detectInjectionDrift 与 retire 注入段同步共用。
|
|
117
|
-
*/
|
|
118
|
-
export function resolveInjectionTarget(
|
|
119
|
-
projectRoot: string
|
|
120
|
-
): { file: InjectionFile; content: string; startIdx: number; endIdx: number } | null {
|
|
121
|
-
for (const file of INJECTION_FILES) {
|
|
122
|
-
const content = readIfExists(path.join(projectRoot, file));
|
|
123
|
-
if (content === null) continue;
|
|
124
|
-
const startIdx = content.indexOf(CONSTRAINTS_START_MARKER);
|
|
125
|
-
const endIdx = content.indexOf(CONSTRAINTS_END_MARKER);
|
|
126
|
-
if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
|
|
127
|
-
return { file, content, startIdx, endIdx };
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* 写侧路由(init 落点选择,原 setupGovernanceConstraints 内联判定收于此):
|
|
135
|
-
* CLAUDE.md 有约束标记段或有旧版 `## Governance Rules` 块 → 续写 CLAUDE.md
|
|
136
|
-
* (旧模型仓豁免,不制造双份正本);否则 AGENTS.md PRESERVE:governance。
|
|
137
|
-
*/
|
|
138
|
-
export function resolveGovernanceLanding(
|
|
139
|
-
projectRoot: string
|
|
140
|
-
): { target: 'claude-md' | 'agents-md'; claudeContent: string | null } {
|
|
141
|
-
const claudeContent = readIfExists(path.join(projectRoot, 'CLAUDE.md'));
|
|
142
|
-
if (claudeContent !== null && hasGovernanceContract(claudeContent)) {
|
|
143
|
-
return { target: 'claude-md', claudeContent };
|
|
144
|
-
}
|
|
145
|
-
return { target: 'agents-md', claudeContent };
|
|
146
|
-
}
|
|
147
|
-
|
|
148
99
|
/**
|
|
149
100
|
* 治理正本标题字面量(单一来源,#83):init 的标题写点与下列两个判定谓词
|
|
150
101
|
* 都由它派生,仓内不再本地拼写。字面量无正则元字符,可直接拼入 RegExp。
|
|
@@ -164,8 +115,12 @@ const GOVERNANCE_HEADING_LOOSE_RE = new RegExp(`^##\\s+${GOVERNANCE_HEADING_TEXT
|
|
|
164
115
|
/** 严格标题正则:精确拼写 + 行尾锚定(行尾仅容忍空白) */
|
|
165
116
|
const GOVERNANCE_HEADING_STRICT_RE = new RegExp(`^${GOVERNANCE_HEADING}[ \\t]*$`, 'gm');
|
|
166
117
|
|
|
167
|
-
/**
|
|
168
|
-
|
|
118
|
+
/**
|
|
119
|
+
* 历史注入段标记裸文本(ADR-0029:注入段已关停,此处仅作历史兼容判据——
|
|
120
|
+
* 旧仓残留的 HARNESS_CONSTRAINTS 段仍算治理契约在场)。宽松谓词按「标记文本
|
|
121
|
+
* 在场」判定,容忍注释壳残缺。
|
|
122
|
+
*/
|
|
123
|
+
const CONSTRAINTS_START_TEXT = 'HARNESS_CONSTRAINTS_START';
|
|
169
124
|
|
|
170
125
|
/**
|
|
171
126
|
* 宽松谓词:内容里是否有治理契约在场——标题宽松匹配或 HARNESS 约束标记
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 运行级观察面(ADR-0023 决策 1)
|
|
3
3
|
*
|
|
4
4
|
* 一次 `harness check` 一份、跑完即弃:把「本项目有哪些源码根」「最近的 trace 记录」
|
|
5
|
-
* 「`.harness/config.yml`
|
|
5
|
+
* 「`.harness/config.yml` 写了什么」这类上行数据的读取收在此处,
|
|
6
6
|
* 同一次运行内每个文件至多读一次。
|
|
7
7
|
*
|
|
8
8
|
* 为什么不是一个对象而是两个:checker 拿到的 `CheckEnv` 里含 `context`,而 `context` 正是
|
|
@@ -20,7 +20,6 @@ import { detectSourceRoots } from '../../utils/detect-source-roots';
|
|
|
20
20
|
import { reconcileCapabilities, type CapabilityVerdict } from './capabilities-reconcile';
|
|
21
21
|
import { readJsonlWindow, type JsonlWindow, type JsonlReadResult } from '../../utils/jsonl';
|
|
22
22
|
import { DEFAULT_TRACE_FILE, type ExecutionTrace } from '../../types/trace';
|
|
23
|
-
import type { CustomConstraintDefinition } from '../../types/project-config';
|
|
24
23
|
|
|
25
24
|
/** config.yml 在项目根下的相对路径(读取口径唯一落点) */
|
|
26
25
|
const CONFIG_FILE_REL = path.join('.harness', 'config.yml');
|
|
@@ -49,14 +48,6 @@ export interface RunEnv {
|
|
|
49
48
|
* 空文件 → `{}`;YAML 解析失败 → **抛出**(兜底与否属各消费方的判定,不在读面上替它决定)。
|
|
50
49
|
*/
|
|
51
50
|
rawConfig(): Record<string, unknown> | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* `.harness/<fileName>` 里的自定义约束定义(一次运行内同名文件至多读一次)
|
|
54
|
-
*
|
|
55
|
-
* 文件名由消费方(ProjectConfigLoader)从合并后的 config 解析后传入——
|
|
56
|
-
* 「`custom_constraints_file` 怎么写才算数」属加载器口径,不在读面上判。
|
|
57
|
-
* 文件缺失或无 `custom_constraints` 段 → `{}`(与改前的直读逐字一致)。
|
|
58
|
-
*/
|
|
59
|
-
customConstraints(fileName: string): Record<string, CustomConstraintDefinition>;
|
|
60
51
|
/**
|
|
61
52
|
* `CAPABILITIES.md` 的读取 + 解析 + 与代码实况的对照判定(ADR-0023 决策 4)
|
|
62
53
|
*
|
|
@@ -97,7 +88,6 @@ export function createRunEnv(projectPath: string): RunEnv {
|
|
|
97
88
|
let sourceRoots: string[] | null = null;
|
|
98
89
|
let configLoaded = false;
|
|
99
90
|
let configRaw: Record<string, unknown> | undefined;
|
|
100
|
-
const customDefs = new Map<string, Record<string, CustomConstraintDefinition>>();
|
|
101
91
|
/** 能力表 memo:undefined = 未算,null = 项目无 CAPABILITIES.md */
|
|
102
92
|
let caps: ProjectCapabilities | null | undefined;
|
|
103
93
|
|
|
@@ -120,14 +110,6 @@ export function createRunEnv(projectPath: string): RunEnv {
|
|
|
120
110
|
}
|
|
121
111
|
return configRaw;
|
|
122
112
|
},
|
|
123
|
-
customConstraints(fileName: string) {
|
|
124
|
-
let defs = customDefs.get(fileName);
|
|
125
|
-
if (!defs) {
|
|
126
|
-
defs = readCustomConstraints(path.join(projectPath, '.harness', fileName));
|
|
127
|
-
customDefs.set(fileName, defs);
|
|
128
|
-
}
|
|
129
|
-
return defs;
|
|
130
|
-
},
|
|
131
113
|
capabilities(populationFiles: string[]) {
|
|
132
114
|
if (caps === undefined) {
|
|
133
115
|
const content = readCapabilitiesContent();
|
|
@@ -164,20 +146,6 @@ export function createRunEnv(projectPath: string): RunEnv {
|
|
|
164
146
|
}
|
|
165
147
|
}
|
|
166
148
|
|
|
167
|
-
/**
|
|
168
|
-
* 读一个自定义约束文件并取出 `custom_constraints` 段
|
|
169
|
-
*
|
|
170
|
-
* 缺失 → `{}`。文档解析成空值(空 yaml 文件)时取段会抛——改前直读就是这个行为,
|
|
171
|
-
* 不在此新增兜底:畸形配置文件该炸在配置上,不该被读面抹平。
|
|
172
|
-
*/
|
|
173
|
-
function readCustomConstraints(absPath: string): Record<string, CustomConstraintDefinition> {
|
|
174
|
-
if (!fs.existsSync(absPath)) return {};
|
|
175
|
-
const loaded = yaml.load(fs.readFileSync(absPath, 'utf-8')) as {
|
|
176
|
-
custom_constraints?: Record<string, CustomConstraintDefinition>;
|
|
177
|
-
};
|
|
178
|
-
return loaded.custom_constraints ?? {};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
149
|
/**
|
|
182
150
|
* 读并解析一个 YAML 配置文件
|
|
183
151
|
*
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* `harness constraints report` 与 `harness constraints retire`(交互模式)共用的
|
|
5
5
|
* 数据层:读取项目 traces.log,与生效集(getEffectiveConstraints)对齐,
|
|
6
|
-
* 产出 check
|
|
6
|
+
* 产出 check 约束统计表与四类退役候选诊断。
|
|
7
7
|
*
|
|
8
8
|
* 只读:不创建目录、不写任何文件。
|
|
9
9
|
*/
|
|
@@ -23,8 +23,6 @@ import type { EffectiveConfigLint } from '../effective-constraints';
|
|
|
23
23
|
*/
|
|
24
24
|
export const FLAG_EVIDENCE_CONSTRAINT_IDS: ReadonlySet<string> = new Set([
|
|
25
25
|
'no_completion_without_verification',
|
|
26
|
-
'incremental_progress',
|
|
27
|
-
'no_implementation_without_requirement',
|
|
28
26
|
]);
|
|
29
27
|
|
|
30
28
|
/**
|
|
@@ -32,7 +30,7 @@ export const FLAG_EVIDENCE_CONSTRAINT_IDS: ReadonlySet<string> = new Set([
|
|
|
32
30
|
*/
|
|
33
31
|
export interface ConstraintUsageStats {
|
|
34
32
|
id: string;
|
|
35
|
-
|
|
33
|
+
severity: Constraint['severity'];
|
|
36
34
|
|
|
37
35
|
/** trace 总行数(含 skip) */
|
|
38
36
|
total: number;
|
|
@@ -98,12 +96,10 @@ export const DEFAULT_DIAGNOSE_THRESHOLDS: DiagnoseThresholds = {
|
|
|
98
96
|
* report 数据模型
|
|
99
97
|
*/
|
|
100
98
|
export interface ConstraintsUsageReport {
|
|
101
|
-
/** check
|
|
99
|
+
/** check 约束统计表(生效集内每条约束一行,零出现 total=0) */
|
|
102
100
|
stats: ConstraintUsageStats[];
|
|
103
101
|
/** 退役候选诊断(按 zero_trigger → unevaluable → high_noise → zero_intercept 排序) */
|
|
104
102
|
candidates: RetireCandidate[];
|
|
105
|
-
/** 当前生效的 prompt 条目 id(注入清单) */
|
|
106
|
-
activePromptIds: string[];
|
|
107
103
|
/** 配置健康诊断(unknownIds 等) */
|
|
108
104
|
lint: EffectiveConfigLint;
|
|
109
105
|
/** trace 文件是否存在 */
|
|
@@ -121,7 +117,7 @@ export interface ConstraintsUsageReport {
|
|
|
121
117
|
*
|
|
122
118
|
* 坏行策略:skip(原语义不变——report 只读,不因单行损坏失败);
|
|
123
119
|
* 计数去向:透传——`skippedLines` 随本方法返回,进 `ConstraintsUsageReport.skippedLines`,
|
|
124
|
-
* 消费面为 `constraints report` 的文本行 / `--json` 字段 / `--export` 摘要。
|
|
120
|
+
* 消费面为 `constraints report` 的文本行 / `--json-output` 字段 / `--export` 摘要。
|
|
125
121
|
*/
|
|
126
122
|
export function readProjectTracesReport(projectRoot: string): { traces: ExecutionTrace[]; skippedLines: number } {
|
|
127
123
|
const { records, skippedLines } = readJsonl<ExecutionTrace>(
|
|
@@ -145,7 +141,7 @@ export function readProjectTraces(projectRoot: string): ExecutionTrace[] {
|
|
|
145
141
|
*/
|
|
146
142
|
export function collectUsageByConstraint(
|
|
147
143
|
traces: ExecutionTrace[]
|
|
148
|
-
): Map<string, Omit<ConstraintUsageStats, 'id' | '
|
|
144
|
+
): Map<string, Omit<ConstraintUsageStats, 'id' | 'severity' | 'evaluated' | 'failRate'>> {
|
|
149
145
|
const map = new Map<string, { total: number; pass: number; fail: number; skip: number; firstAt?: number; lastAt?: number }>();
|
|
150
146
|
for (const t of traces) {
|
|
151
147
|
let agg = map.get(t.constraintId);
|
|
@@ -163,12 +159,12 @@ export function collectUsageByConstraint(
|
|
|
163
159
|
return map;
|
|
164
160
|
}
|
|
165
161
|
|
|
166
|
-
function toStats(id: string,
|
|
162
|
+
function toStats(id: string, severity: Constraint['severity'], agg: { total: number; pass: number; fail: number; skip: number; firstAt?: number; lastAt?: number } | undefined): ConstraintUsageStats {
|
|
167
163
|
const a = agg ?? { total: 0, pass: 0, fail: 0, skip: 0 };
|
|
168
164
|
const evaluated = a.total - a.skip;
|
|
169
165
|
return {
|
|
170
166
|
id,
|
|
171
|
-
|
|
167
|
+
severity,
|
|
172
168
|
total: a.total,
|
|
173
169
|
pass: a.pass,
|
|
174
170
|
fail: a.fail,
|
|
@@ -183,7 +179,7 @@ function toStats(id: string, level: Constraint['level'], agg: { total: number; p
|
|
|
183
179
|
/**
|
|
184
180
|
* 退役候选诊断(纯函数)
|
|
185
181
|
*
|
|
186
|
-
*
|
|
182
|
+
* 每条约束最多归入一个类别,优先级:
|
|
187
183
|
* zero_trigger → unevaluable → high_noise → zero_intercept
|
|
188
184
|
*/
|
|
189
185
|
export function diagnoseRetireCandidates(
|
|
@@ -248,21 +244,18 @@ export function buildConstraintsUsageReport(
|
|
|
248
244
|
thresholds: Partial<DiagnoseThresholds> = {}
|
|
249
245
|
): ConstraintsUsageReport {
|
|
250
246
|
const effective = getEffectiveConstraints(projectRoot);
|
|
251
|
-
const checkConstraints = effective.filter(c => c.kind === 'check');
|
|
252
|
-
const activePromptIds = effective.filter(c => c.kind === 'prompt').map(c => c.id);
|
|
253
247
|
|
|
254
248
|
const tracePath = path.join(projectRoot, DEFAULT_TRACE_FILE);
|
|
255
249
|
const { traces, skippedLines } = readProjectTracesReport(projectRoot);
|
|
256
250
|
const usage = collectUsageByConstraint(traces);
|
|
257
251
|
|
|
258
|
-
const stats =
|
|
252
|
+
const stats = effective.map(c => toStats(c.id, c.severity, usage.get(c.id)));
|
|
259
253
|
const candidates = diagnoseRetireCandidates(stats, thresholds);
|
|
260
254
|
const lint = lintEffectiveConfig(projectRoot);
|
|
261
255
|
|
|
262
256
|
return {
|
|
263
257
|
stats,
|
|
264
258
|
candidates,
|
|
265
|
-
activePromptIds,
|
|
266
259
|
lint,
|
|
267
260
|
traceFileExists: fs.existsSync(tracePath),
|
|
268
261
|
skippedLines,
|
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 生效约束集(ADR-0001)
|
|
2
|
+
* 生效约束集(ADR-0029,链路承自 ADR-0001)
|
|
3
3
|
*
|
|
4
4
|
* `getEffectiveConstraints(projectRoot)` 是全仓唯一的生效集来源:
|
|
5
|
-
* 内置 → preset → config.yml
|
|
6
|
-
*
|
|
7
|
-
* 不再直接读
|
|
5
|
+
* 内置 → preset → config.yml 禁用。
|
|
6
|
+
* `harness check`、外部消费者(studio 等)全部消费它,
|
|
7
|
+
* 不再直接读 CONSTRAINTS 全集。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { Constraint } from '../types/constraint';
|
|
11
11
|
import type { MergedConstraintsConfig } from '../types/project-config';
|
|
12
|
-
import { PROMPTS } from './constraints/definitions';
|
|
13
12
|
import { ProjectConfigLoader } from './project-config-loader';
|
|
14
13
|
import type { RunTarget } from './constraints/run-env';
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
|
-
* 获取项目当前生效的约束集(check
|
|
16
|
+
* 获取项目当前生效的约束集(check 全量,带 kind/severity)
|
|
18
17
|
*
|
|
19
18
|
* 生效集链路同 getMergedConstraintsConfig:内置 → preset 裁剪 → config.yml
|
|
20
|
-
* `constraints.<id>.enabled:false`
|
|
21
|
-
* 追加(禁用/已退役的 custom 不追加)→ scenes 过滤
|
|
22
|
-
* (带 appliesTo 的 prompt 仅当 config.yml `scenes` 与其交集非空时保留,
|
|
23
|
-
* 缺省 scenes=[] 即场景专属 prompt 默认不进入生效集)。
|
|
19
|
+
* `constraints.<id>.enabled:false` 删除。
|
|
24
20
|
*
|
|
25
21
|
* @param target 项目根路径,或本 run 的运行级观察面(缺省 process.cwd())
|
|
26
22
|
* 传观察面 = config.yml 读取与本 run 其余消费方共用同一份(ADR-0023 决策 2)
|
|
@@ -37,22 +33,18 @@ export function getEffectiveConstraints(
|
|
|
37
33
|
/**
|
|
38
34
|
* 从已算好的合并配置取出生效集清单(与 getEffectiveConstraints 同一形状)
|
|
39
35
|
*
|
|
40
|
-
* 给已经持有 `MergedConstraintsConfig` 的消费方复用(CLI check
|
|
41
|
-
*
|
|
36
|
+
* 给已经持有 `MergedConstraintsConfig` 的消费方复用(CLI check 复用这一份,
|
|
37
|
+
* 避免生效集链路在一次运行里算两遍,ADR-0023 步骤 4.5)。
|
|
42
38
|
*/
|
|
43
39
|
export function constraintsFromMerged(merged: MergedConstraintsConfig): Constraint[] {
|
|
44
|
-
return
|
|
45
|
-
...Object.values(merged.ironLaws),
|
|
46
|
-
...Object.values(merged.guidelines),
|
|
47
|
-
...Object.values(merged.prompts ?? {}),
|
|
48
|
-
];
|
|
40
|
+
return Object.values(merged.constraints);
|
|
49
41
|
}
|
|
50
42
|
|
|
51
43
|
/**
|
|
52
|
-
*
|
|
44
|
+
* 获取项目当前生效的合并约束配置(唯一来源的完整形状)
|
|
53
45
|
*
|
|
54
46
|
* 与 getEffectiveConstraints 同一生效集链路,返回完整 MergedConstraintsConfig
|
|
55
|
-
* (含 disabled/
|
|
47
|
+
* (含 disabled/unknownIds),供 check 等需要诊断信息的消费方使用。
|
|
56
48
|
*
|
|
57
49
|
* options.preset(CLI --preset)仅在项目无自定义配置时覆盖 config.yml 的
|
|
58
50
|
* preset(工单 23 语义:项目自定义配置优先于 CLI 预设);不传 preset 时
|
|
@@ -77,24 +69,15 @@ export function getMergedConstraintsConfig(
|
|
|
77
69
|
*/
|
|
78
70
|
export interface EffectiveConfigLint {
|
|
79
71
|
/**
|
|
80
|
-
* config.yml `constraints.<id>`
|
|
72
|
+
* config.yml `constraints.<id>` 中非内置的未知 id
|
|
81
73
|
* (如禁用了已被本版移除的约束的残留配置)。生效集计算静默忽略,
|
|
82
74
|
* 在此列出供 report 提示。
|
|
83
75
|
*/
|
|
84
76
|
unknownIds: string[];
|
|
85
|
-
|
|
86
|
-
/** 项目配置的场景标签(config.yml `scenes`,缺省 []) */
|
|
87
|
-
scenes: string[];
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* 因 scenes 过滤而未进入生效集的场景专属 prompt id
|
|
91
|
-
* (已被 preset/config 禁用的不重复列出)
|
|
92
|
-
*/
|
|
93
|
-
sceneExcluded: string[];
|
|
94
77
|
}
|
|
95
78
|
|
|
96
79
|
/**
|
|
97
|
-
* 诊断项目约束配置:未知 id
|
|
80
|
+
* 诊断项目约束配置:未知 id 残留
|
|
98
81
|
*
|
|
99
82
|
* 不抛错、不修改任何文件,供 report / check 的诊断输出使用。
|
|
100
83
|
*
|
|
@@ -102,23 +85,9 @@ export interface EffectiveConfigLint {
|
|
|
102
85
|
*/
|
|
103
86
|
export function lintEffectiveConfig(projectRoot: string = process.cwd()): EffectiveConfigLint {
|
|
104
87
|
const loader = new ProjectConfigLoader(projectRoot);
|
|
105
|
-
|
|
88
|
+
loader.load();
|
|
106
89
|
const merged = loader.mergeConstraints();
|
|
107
|
-
const scenes = config.scenes ?? [];
|
|
108
|
-
|
|
109
|
-
const sceneExcluded = Object.values(PROMPTS)
|
|
110
|
-
.filter(
|
|
111
|
-
c =>
|
|
112
|
-
c.appliesTo &&
|
|
113
|
-
c.appliesTo.length > 0 &&
|
|
114
|
-
!c.appliesTo.some(scene => scenes.includes(scene)) &&
|
|
115
|
-
!merged.disabled.includes(c.id)
|
|
116
|
-
)
|
|
117
|
-
.map(c => c.id);
|
|
118
|
-
|
|
119
90
|
return {
|
|
120
91
|
unknownIds: merged.unknownIds ?? [],
|
|
121
|
-
scenes,
|
|
122
|
-
sceneExcluded,
|
|
123
92
|
};
|
|
124
93
|
}
|
package/src/core/index.ts
CHANGED
|
@@ -5,11 +5,9 @@
|
|
|
5
5
|
* 不再暴露位置参数版。
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
//
|
|
8
|
+
// 约束系统(severity 显式模型,ADR-0029)
|
|
9
9
|
export {
|
|
10
|
-
|
|
11
|
-
GUIDELINES,
|
|
12
|
-
PROMPTS,
|
|
10
|
+
CONSTRAINTS,
|
|
13
11
|
getAllConstraints,
|
|
14
12
|
findConstraintsByTrigger,
|
|
15
13
|
getConstraint,
|
|
@@ -18,21 +16,16 @@ export {
|
|
|
18
16
|
checkConstraints,
|
|
19
17
|
checkBeforeExecution,
|
|
20
18
|
constraintChecker,
|
|
21
|
-
CONSTRAINTS_START_MARKER,
|
|
22
|
-
CONSTRAINTS_END_MARKER,
|
|
23
|
-
renderConstraintsSection,
|
|
24
19
|
CheckCache,
|
|
25
|
-
renderConstraintsByTrigger,
|
|
26
20
|
ConstraintViolationError,
|
|
27
21
|
} from './constraints';
|
|
28
22
|
export type {
|
|
29
23
|
CheckConstraintsOptions,
|
|
30
24
|
CheckCacheConfig,
|
|
31
25
|
CheckSamplingConfig,
|
|
32
|
-
RenderConstraintsByTriggerOptions,
|
|
33
26
|
ConstraintId,
|
|
34
27
|
ConstraintKind,
|
|
35
|
-
|
|
28
|
+
ConstraintSeverity,
|
|
36
29
|
ConstraintTrigger,
|
|
37
30
|
Constraint,
|
|
38
31
|
ConstraintResult,
|