@dommaker/harness 1.12.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/cli/commands/check.js +3 -3
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/security.d.ts +19 -0
- package/dist/cli/commands/security.d.ts.map +1 -1
- package/dist/cli/commands/security.js +105 -0
- package/dist/cli/commands/security.js.map +1 -1
- package/dist/core/app-constraints-loader.d.ts +5 -3
- package/dist/core/app-constraints-loader.d.ts.map +1 -1
- package/dist/core/app-constraints-loader.js +20 -7
- package/dist/core/app-constraints-loader.js.map +1 -1
- package/dist/core/constraints/checker.d.ts +5 -3
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +31 -10
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.js +21 -8
- package/dist/core/constraints/checkers/capability-sync.js.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.js +7 -1
- package/dist/core/constraints/checkers/context-doc-sync.js.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.d.ts.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.js +41 -26
- package/dist/core/constraints/checkers/docs-freshness.js.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.d.ts +3 -0
- package/dist/core/constraints/checkers/governance-presence.d.ts.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.js +7 -10
- package/dist/core/constraints/checkers/governance-presence.js.map +1 -1
- package/dist/core/constraints/checkers/index.d.ts +6 -6
- package/dist/core/constraints/checkers/index.d.ts.map +1 -1
- package/dist/core/constraints/checkers/index.js +14 -9
- package/dist/core/constraints/checkers/index.js.map +1 -1
- package/dist/core/constraints/checkers/iron-flags.js +1 -1
- package/dist/core/constraints/checkers/iron-flags.js.map +1 -1
- package/dist/core/constraints/checkers/no-hardcoded-credentials.d.ts +11 -4
- package/dist/core/constraints/checkers/no-hardcoded-credentials.d.ts.map +1 -1
- package/dist/core/constraints/checkers/no-hardcoded-credentials.js +117 -30
- package/dist/core/constraints/checkers/no-hardcoded-credentials.js.map +1 -1
- package/dist/core/constraints/checkers/no-test-simplification.d.ts +16 -2
- package/dist/core/constraints/checkers/no-test-simplification.d.ts.map +1 -1
- package/dist/core/constraints/checkers/no-test-simplification.js +115 -15
- package/dist/core/constraints/checkers/no-test-simplification.js.map +1 -1
- package/dist/core/constraints/checkers/templated/exec.d.ts +19 -0
- package/dist/core/constraints/checkers/templated/exec.d.ts.map +1 -0
- package/dist/core/constraints/checkers/templated/exec.js +124 -0
- package/dist/core/constraints/checkers/templated/exec.js.map +1 -0
- package/dist/core/constraints/checkers/templated/index.d.ts +1 -0
- package/dist/core/constraints/checkers/templated/index.d.ts.map +1 -1
- package/dist/core/constraints/checkers/templated/index.js +3 -1
- package/dist/core/constraints/checkers/templated/index.js.map +1 -1
- package/dist/core/constraints/checkers/templates-registry.d.ts +2 -1
- package/dist/core/constraints/checkers/templates-registry.d.ts.map +1 -1
- package/dist/core/constraints/checkers/templates-registry.js +3 -1
- package/dist/core/constraints/checkers/templates-registry.js.map +1 -1
- package/dist/core/constraints/checkers/types.d.ts +67 -6
- package/dist/core/constraints/checkers/types.d.ts.map +1 -1
- package/dist/core/constraints/checkers/types.js +51 -6
- package/dist/core/constraints/checkers/types.js.map +1 -1
- package/dist/core/constraints/definitions/guidelines.d.ts +1 -0
- package/dist/core/constraints/definitions/guidelines.d.ts.map +1 -1
- package/dist/core/constraints/definitions/guidelines.js +4 -0
- package/dist/core/constraints/definitions/guidelines.js.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.d.ts +1 -0
- package/dist/core/constraints/definitions/iron-laws.d.ts.map +1 -1
- package/dist/core/constraints/definitions/iron-laws.js +6 -1
- package/dist/core/constraints/definitions/iron-laws.js.map +1 -1
- package/dist/core/constraints/definitions.d.ts +7 -0
- package/dist/core/constraints/definitions.d.ts.map +1 -1
- package/dist/core/constraints/definitions.js +10 -0
- package/dist/core/constraints/definitions.js.map +1 -1
- package/dist/core/constraints/git-evidence.d.ts +10 -0
- package/dist/core/constraints/git-evidence.d.ts.map +1 -1
- package/dist/core/constraints/git-evidence.js +2 -0
- package/dist/core/constraints/git-evidence.js.map +1 -1
- package/dist/core/constraints/index.d.ts +3 -1
- package/dist/core/constraints/index.d.ts.map +1 -1
- package/dist/core/constraints/index.js +8 -1
- package/dist/core/constraints/index.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 +6 -1
- package/dist/core/index.js.map +1 -1
- package/dist/gates/checker-gate.d.ts +5 -1
- package/dist/gates/checker-gate.d.ts.map +1 -1
- package/dist/gates/checker-gate.js +10 -3
- package/dist/gates/checker-gate.js.map +1 -1
- package/dist/gates/command.d.ts +5 -1
- package/dist/gates/command.d.ts.map +1 -1
- package/dist/gates/command.js +6 -2
- package/dist/gates/command.js.map +1 -1
- package/dist/gates/definitions.d.ts.map +1 -1
- package/dist/gates/definitions.js +6 -1
- package/dist/gates/definitions.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/pretool-use-hook.d.ts +13 -4
- package/dist/pretool-use-hook.d.ts.map +1 -1
- package/dist/pretool-use-hook.js +89 -8
- package/dist/pretool-use-hook.js.map +1 -1
- package/dist/types/constraint.d.ts +32 -3
- package/dist/types/constraint.d.ts.map +1 -1
- package/dist/types/constraint.js +6 -1
- package/dist/types/constraint.js.map +1 -1
- package/dist/types/trace.d.ts +7 -0
- package/dist/types/trace.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/CONTEXT.md +2 -2
- package/src/__tests__/app-constraints-loader.test.ts +86 -3
- package/src/__tests__/checker-extra.test.ts +80 -4
- package/src/__tests__/checker-primitives-sdk.test.ts +70 -0
- package/src/__tests__/exec-checker-full-chain.test.ts +118 -0
- package/src/__tests__/layering.test.ts +3 -1
- package/src/__tests__/pretool-use-hook.test.ts +211 -4
- package/src/__tests__/public-exports.test.ts +5 -0
- package/src/__tests__/public-type-surface.test.ts +22 -0
- package/src/__tests__/public-value-surface.test.ts +5 -0
- package/src/cli/commands/CONTEXT.md +1 -1
- package/src/cli/commands/__tests__/check-skip-output.test.ts +4 -4
- package/src/cli/commands/__tests__/check.test.ts +2 -0
- package/src/cli/commands/__tests__/security.test.ts +89 -1
- package/src/cli/commands/check.ts +3 -3
- package/src/cli/commands/security.ts +99 -0
- package/src/core/CONTEXT.md +6 -6
- package/src/core/app-constraints-loader.ts +23 -8
- package/src/core/constraints/__tests__/git-evidence.test.ts +20 -0
- package/src/core/constraints/__tests__/run-env.test.ts +2 -0
- package/src/core/constraints/checker.ts +35 -12
- package/src/core/constraints/checkers/__tests__/capability-sync.test.ts +21 -3
- package/src/core/constraints/checkers/__tests__/context-doc-sync.test.ts +20 -12
- package/src/core/constraints/checkers/__tests__/docs-freshness-degraded.test.ts +89 -0
- package/src/core/constraints/checkers/__tests__/docs-freshness.test.ts +4 -2
- package/src/core/constraints/checkers/__tests__/exec-checker.test.ts +99 -0
- package/src/core/constraints/checkers/__tests__/fixtures/public-repo-sanitization.mjs +40 -0
- package/src/core/constraints/checkers/__tests__/governance-presence.test.ts +23 -2
- package/src/core/constraints/checkers/__tests__/input-contract.test.ts +135 -0
- package/src/core/constraints/checkers/__tests__/iron-flags.test.ts +15 -2
- package/src/core/constraints/checkers/__tests__/no-hardcoded-credentials.test.ts +110 -5
- package/src/core/constraints/checkers/__tests__/no-test-simplification.test.ts +144 -21
- package/src/core/constraints/checkers/__tests__/three-state-consistency.test.ts +6 -2
- package/src/core/constraints/checkers/capability-sync.ts +24 -10
- package/src/core/constraints/checkers/context-doc-sync.ts +8 -1
- package/src/core/constraints/checkers/docs-freshness.ts +44 -26
- package/src/core/constraints/checkers/governance-presence.ts +7 -8
- package/src/core/constraints/checkers/index.ts +22 -10
- package/src/core/constraints/checkers/iron-flags.ts +1 -1
- package/src/core/constraints/checkers/no-hardcoded-credentials.ts +135 -29
- package/src/core/constraints/checkers/no-test-simplification.ts +128 -17
- package/src/core/constraints/checkers/templated/exec.ts +138 -0
- package/src/core/constraints/checkers/templated/index.ts +1 -0
- package/src/core/constraints/checkers/templates-registry.ts +4 -2
- package/src/core/constraints/checkers/types.ts +106 -9
- package/src/core/constraints/definitions/guidelines.ts +4 -0
- package/src/core/constraints/definitions/iron-laws.ts +6 -1
- package/src/core/constraints/definitions.ts +10 -0
- package/src/core/constraints/git-evidence.ts +13 -0
- package/src/core/constraints/index.ts +22 -0
- package/src/core/index.ts +16 -0
- package/src/gates/CONTEXT.md +3 -3
- package/src/gates/__tests__/checker-gate.test.ts +19 -2
- package/src/gates/checker-gate.ts +11 -4
- package/src/gates/command.ts +6 -2
- package/src/gates/definitions.ts +6 -1
- package/src/index.ts +26 -0
- package/src/pretool-use-hook.ts +104 -10
- package/src/types/constraint.ts +35 -3
- package/src/types/trace.ts +8 -0
|
@@ -45,9 +45,9 @@ export const capabilitySync: ConstraintCheck = {
|
|
|
45
45
|
id: 'capability_sync',
|
|
46
46
|
async evaluate(env) {
|
|
47
47
|
const projectPath = env.projectPath;
|
|
48
|
-
// ADR-0001 存在性探测:项目未采用 CAPABILITIES.md 约定 → skip(不计 pass/fail
|
|
48
|
+
// ADR-0001 存在性探测:项目未采用 CAPABILITIES.md 约定 → skip(不计 pass/fail,原因进结果面)
|
|
49
49
|
if (!existsSync(join(projectPath, CAPABILITIES_FILE_REL))) {
|
|
50
|
-
return
|
|
50
|
+
return { skip: true, reason: '项目未采用 CAPABILITIES.md 约定(无 CAPABILITIES.md)' };
|
|
51
51
|
}
|
|
52
52
|
try {
|
|
53
53
|
const capabilitiesMode = getCapabilitiesMode(env);
|
|
@@ -55,7 +55,7 @@ export const capabilitySync: ConstraintCheck = {
|
|
|
55
55
|
const caps = env.capabilities(
|
|
56
56
|
collectPopulationFiles(projectPath, env.sourceRoots(), (root) => env.srcScan(root))
|
|
57
57
|
);
|
|
58
|
-
if (!caps) return
|
|
58
|
+
if (!caps) return { skip: true, reason: '评估期间 CAPABILITIES.md 消失(探测与取数之间被删除)' };
|
|
59
59
|
const verdict = caps.verdict;
|
|
60
60
|
|
|
61
61
|
// 清单格式(计数行)没有文件表可核对,计数由 sync-docs 维护,直接放行
|
|
@@ -63,14 +63,25 @@ export const capabilitySync: ConstraintCheck = {
|
|
|
63
63
|
return true;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
// 增量维度的输入可得性(harness#182):git 取证失败时 stagedDiffNames 归空串不抛错,
|
|
67
|
+
// uncoveredChanges 恒空 = Step 1 静默失效——放行路径必须带降级提示,不假「已核对」。
|
|
68
|
+
// 不声明 needs 改走编排层 skip:全量扫描(Step 2)不依赖 git,非 git 项目照出漂移提示
|
|
69
|
+
const diffNamesAvailable = env.evidenceAvailable?.('stagedDiffNames') ?? true;
|
|
70
|
+
const degradedNote = diffNamesAvailable
|
|
71
|
+
? []
|
|
72
|
+
: ['增量检查降级:staged 变更清单不可得(git 取证失败),本次未核对变更文件的文档登记'];
|
|
73
|
+
const diffNames = diffNamesAvailable
|
|
74
|
+
? (await env.stagedDiffNames()).split('\n').filter(Boolean)
|
|
75
|
+
: [];
|
|
67
76
|
// 增量覆盖判定留在本文件:变更清单属 git 证据(#87),不在上行数据面
|
|
68
77
|
const uncoveredChanges = significantCodeChanges(diffNames).filter(
|
|
69
78
|
(f) => !isCoveredByEntries(verdict.coverageEntries, f)
|
|
70
79
|
);
|
|
71
80
|
|
|
72
81
|
// 无表格的散文文档:历史放行语义
|
|
73
|
-
if (!verdict.hasTable)
|
|
82
|
+
if (!verdict.hasTable) {
|
|
83
|
+
return degradedNote.length > 0 ? { pass: true, evidence: degradedNote } : true;
|
|
84
|
+
}
|
|
74
85
|
|
|
75
86
|
// 文档退化门:有表格却什么都没登记(限定「源码根下确有文件」——空仓 + 空表没有可登记
|
|
76
87
|
// 对象,历史行为是放行,本票不顺手扩大 fail 面)
|
|
@@ -98,14 +109,17 @@ export const capabilitySync: ConstraintCheck = {
|
|
|
98
109
|
const kind = capabilitiesMode === 'module' ? '未登记模块目录' : '未登记源文件';
|
|
99
110
|
return {
|
|
100
111
|
pass: true,
|
|
101
|
-
evidence:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
112
|
+
evidence: [
|
|
113
|
+
...formatEvidence(
|
|
114
|
+
`CAPABILITIES.md ${kind} ${gaps.length} 项(仓库级漂移,与本次变更无关;修复: harness sync-docs)`,
|
|
115
|
+
gaps
|
|
116
|
+
),
|
|
117
|
+
...degradedNote,
|
|
118
|
+
],
|
|
105
119
|
};
|
|
106
120
|
}
|
|
107
121
|
|
|
108
|
-
return true;
|
|
122
|
+
return degradedNote.length > 0 ? { pass: true, evidence: degradedNote } : true;
|
|
109
123
|
} catch (err) {
|
|
110
124
|
// fail-open 语义保留,但异常放行也要落地可见:warn 只进本地 stderr,
|
|
111
125
|
// 进不了 trace——静默吞错会让解析 bug 变成「永远通过」(harness#119 同族问题)
|
|
@@ -18,7 +18,14 @@ export const contextDocSync: ConstraintCheck = {
|
|
|
18
18
|
const projectPath = env.projectPath;
|
|
19
19
|
const resolution = resolveContextFiles(env);
|
|
20
20
|
if (resolution.state !== 'enabled') {
|
|
21
|
-
|
|
21
|
+
// 未配置或约定已立但无目标,跳过评估(harness#182:原因进结果面)
|
|
22
|
+
return {
|
|
23
|
+
skip: true,
|
|
24
|
+
reason:
|
|
25
|
+
resolution.state === 'enabled-empty'
|
|
26
|
+
? 'context_files 约定已启用但 required_dirs 为空'
|
|
27
|
+
: '项目未配置 governance.context_files 约定',
|
|
28
|
+
};
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
// 证据随判定一并返回(ADR-0016 补迁):此前只回裸 false,
|
|
@@ -36,19 +36,18 @@ function getBuiltInDocFreshnessConfig(): DocFreshnessCheck[] {
|
|
|
36
36
|
* 判定逻辑与取数都在 run 级:文档原文、源码根、代码实况清单、对照判定一次算好,
|
|
37
37
|
* 与 capability_sync 共用同一份(ADR-0023 决策 4;此前两边各读一遍、各解析一遍)。
|
|
38
38
|
* 无表格(能力清单格式)时自然零幽灵。
|
|
39
|
+
*
|
|
40
|
+
* 不吞异常(harness#182):取数/解析失败由调用方统一走 fail-open 发声路径,
|
|
41
|
+
* 静默返回 [] 会把「检查器失效」读成「零幽灵 = 合规」。
|
|
39
42
|
*/
|
|
40
43
|
function findDeadCapabilityEntries(env: CheckEnv): string[] {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return caps ? caps.verdict.deadEntries : [];
|
|
49
|
-
} catch {
|
|
50
|
-
return [];
|
|
51
|
-
}
|
|
44
|
+
// 先探存在性再取数:只有 CHANGELOG 而无 CAPABILITIES.md 的项目不该为此扫一遍源码树
|
|
45
|
+
if (!existsSync(join(env.projectPath, CAPABILITIES_FILE_REL))) return [];
|
|
46
|
+
const population = collectPopulationFiles(env.projectPath, env.sourceRoots(), (root) =>
|
|
47
|
+
env.srcScan(root)
|
|
48
|
+
);
|
|
49
|
+
const caps = env.capabilities(population);
|
|
50
|
+
return caps ? caps.verdict.deadEntries : [];
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
/**
|
|
@@ -82,21 +81,37 @@ export const docsFreshness: ConstraintCheck = {
|
|
|
82
81
|
async evaluate(env) {
|
|
83
82
|
const projectPath = env.projectPath;
|
|
84
83
|
|
|
85
|
-
// ADR-0001 存在性探测:项目无任何 freshness 配置/目标 → skip(不计 pass/fail
|
|
86
|
-
if (!hasFreshnessTargets(env))
|
|
87
|
-
|
|
88
|
-
// Step 1: 文件表格式 — 登记的条目(文件+目录)是否仍存在(ADR-0009)
|
|
89
|
-
const deadEntries = findDeadCapabilityEntries(env);
|
|
90
|
-
if (deadEntries.length > 0) {
|
|
91
|
-
// 证据通道点名条目(harness#119):此前是 console.error 侧信道(2026-08-08 studio
|
|
92
|
-
// CI 4 连红时的临时办法),CLI 结构化输出与 trace 两头都拿不到,
|
|
93
|
-
// error 级拦截时用户只看到一句通用提示,basename 碰撞下无从定位
|
|
84
|
+
// ADR-0001 存在性探测:项目无任何 freshness 配置/目标 → skip(不计 pass/fail,原因进结果面)
|
|
85
|
+
if (!hasFreshnessTargets(env)) {
|
|
94
86
|
return {
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
skip: true,
|
|
88
|
+
reason: '项目未采用文档新鲜度约定(无 CAPABILITIES.md / CHANGELOG / freshness 配置)',
|
|
97
89
|
};
|
|
98
90
|
}
|
|
99
91
|
|
|
92
|
+
// Step 1(文件表幽灵)与 Step 2(FreshnessRunner)各自 fail-open 发声(harness#182,
|
|
93
|
+
// 对齐 capability_sync 姿势):任一步异常 → console.warn + 降级提示累积进 evidence,
|
|
94
|
+
// 不吞错、也不让一步的异常吞掉另一步的 fail 面
|
|
95
|
+
const degraded: string[] = [];
|
|
96
|
+
const reasonOf = (err: unknown) => (err instanceof Error ? err.message : String(err));
|
|
97
|
+
|
|
98
|
+
// Step 1: 文件表格式 — 登记的条目(文件+目录)是否仍存在(ADR-0009)
|
|
99
|
+
try {
|
|
100
|
+
const deadEntries = findDeadCapabilityEntries(env);
|
|
101
|
+
if (deadEntries.length > 0) {
|
|
102
|
+
// 证据通道点名条目(harness#119):此前是 console.error 侧信道(2026-08-08 studio
|
|
103
|
+
// CI 4 连红时的临时办法),CLI 结构化输出与 trace 两头都拿不到,
|
|
104
|
+
// error 级拦截时用户只看到一句通用提示,basename 碰撞下无从定位
|
|
105
|
+
return {
|
|
106
|
+
pass: false,
|
|
107
|
+
evidence: formatEvidence('CAPABILITIES.md 登记的条目不存在', deadEntries),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
} catch (err) {
|
|
111
|
+
console.warn('[docs_freshness] 文件表新鲜度检查异常:', err);
|
|
112
|
+
degraded.push(`文件表幽灵检查异常,本次未核对: ${reasonOf(err)}(不代表登记条目均在场)`);
|
|
113
|
+
}
|
|
114
|
+
|
|
100
115
|
// Step 2: 能力清单格式 + CLAUDE.md + CHANGELOG — 通过 FreshnessRunner
|
|
101
116
|
try {
|
|
102
117
|
const freshnessConfig = getGovernanceConfig(env)?.doc_freshness;
|
|
@@ -104,7 +119,9 @@ export const docsFreshness: ConstraintCheck = {
|
|
|
104
119
|
// context_files 三态统一口径(工单 84):约定已立但无目标(enabled 但
|
|
105
120
|
// required_dirs 缺失/空)→ skip,与 context_doc_sync 同构;不再静默放行
|
|
106
121
|
const contextFiles = resolveContextFiles(env);
|
|
107
|
-
if (contextFiles.state === 'enabled-empty')
|
|
122
|
+
if (contextFiles.state === 'enabled-empty') {
|
|
123
|
+
return { skip: true, reason: 'context_files 约定已启用但 required_dirs 为空' };
|
|
124
|
+
}
|
|
108
125
|
const requiredDirs = contextFiles.state === 'enabled' ? contextFiles.dirs : undefined;
|
|
109
126
|
|
|
110
127
|
const runner = new FreshnessRunner();
|
|
@@ -129,10 +146,11 @@ export const docsFreshness: ConstraintCheck = {
|
|
|
129
146
|
),
|
|
130
147
|
};
|
|
131
148
|
}
|
|
132
|
-
} catch {
|
|
133
|
-
|
|
149
|
+
} catch (err) {
|
|
150
|
+
console.warn('[docs_freshness] FreshnessRunner 检查异常,默认放行:', err);
|
|
151
|
+
degraded.push(`FreshnessRunner 检查异常,按 fail-open 放行: ${reasonOf(err)}(本次结果不代表文档新鲜度已验证)`);
|
|
134
152
|
}
|
|
135
153
|
|
|
136
|
-
return true;
|
|
154
|
+
return degraded.length > 0 ? { pass: true, evidence: degraded } : true;
|
|
137
155
|
},
|
|
138
156
|
};
|
|
@@ -7,12 +7,15 @@
|
|
|
7
7
|
* 段被删除/掏空后 sync-docs 重新生成会静默丢失,此处补「在场」校验。
|
|
8
8
|
*
|
|
9
9
|
* ADR-0001 存在性探测:项目未采用 harness 治理(无 .harness/config.yml)→ skip。
|
|
10
|
+
* 探测按**文件存在**而非解析成功(harness#182):此前按 loadRawProjectConfig 解析
|
|
11
|
+
* 判定,config.yml YAML 损坏 → 解析抛错 → 误判「未采用」→ skip——恰在配置出问题
|
|
12
|
+
* 时闭嘴。文件在 = 已采用,解析坏不坏都照查治理契约在场性。
|
|
10
13
|
* 向后兼容:旧模型仓(CLAUDE.md 有治理块、AGENTS.md 无 PRESERVE:governance)→ pass,
|
|
11
14
|
* 不强制迁移;两处都没有才报违规。
|
|
12
15
|
*/
|
|
13
16
|
|
|
17
|
+
import { existsSync } from 'fs';
|
|
14
18
|
import { join } from 'path';
|
|
15
|
-
import { loadRawProjectConfig } from '../../project-config-loader';
|
|
16
19
|
import { hasGovernanceContract, hasPreserveBlock, readIfExists } from '../injection-writer';
|
|
17
20
|
import type { ConstraintCheck } from './types';
|
|
18
21
|
|
|
@@ -36,14 +39,10 @@ export const governancePresence: ConstraintCheck = {
|
|
|
36
39
|
async evaluate(env) {
|
|
37
40
|
const projectPath = env.projectPath;
|
|
38
41
|
|
|
39
|
-
// 存在性探测:无 harness 配置 = 未采用治理约定 → skip(不计 pass/fail
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
adopted = loadRawProjectConfig(env) !== undefined;
|
|
43
|
-
} catch {
|
|
44
|
-
adopted = false;
|
|
42
|
+
// 存在性探测:无 harness 配置 = 未采用治理约定 → skip(不计 pass/fail,原因进结果面)
|
|
43
|
+
if (!existsSync(join(projectPath, '.harness', 'config.yml'))) {
|
|
44
|
+
return { skip: true, reason: '项目未采用 harness 治理(无 .harness/config.yml)' };
|
|
45
45
|
}
|
|
46
|
-
if (!adopted) return 'skip';
|
|
47
46
|
|
|
48
47
|
if (hasGovernancePreserveBlock(join(projectPath, 'AGENTS.md'))) return true;
|
|
49
48
|
if (hasClaudeGovernance(join(projectPath, 'CLAUDE.md'))) return true;
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* checker.ts 编排层通过 getConstraintCheck() 查找实现。
|
|
5
5
|
*
|
|
6
6
|
* 两层注册表:
|
|
7
|
-
* - 内置 checker(registry,按约束 id):模块加载时校验全部
|
|
8
|
-
* 都有已注册 checker
|
|
9
|
-
*
|
|
7
|
+
* - 内置 checker(registry,按约束 id):模块加载时校验全部 channel='gate' 的内置约束
|
|
8
|
+
* 都有已注册 checker(ADR-0035 闭环收窄:非 gate 条目不要求 checker),且注册表中
|
|
9
|
+
* 没有无对应 gate 定义的孤儿实现;任一不满足即抛错(加载期失败,不许静默 pass,ADR-0001)。
|
|
10
10
|
* - 模板 checker(TEMPLATES,按模板 id):填空式参数化模板,供应用层约束
|
|
11
11
|
* (source='app',`.harness/constraints.yml`)按 checker + params 实例化。
|
|
12
12
|
* 闭环语义扩展而非开口:应用层约束在加载期(app-constraints-loader)校验
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import type { Constraint } from '../../../types/constraint';
|
|
17
17
|
import type { ConstraintCheck } from './types';
|
|
18
|
-
import { getAllConstraints } from '../definitions';
|
|
18
|
+
import { getAllConstraints, isGateConstraint } from '../definitions';
|
|
19
19
|
|
|
20
20
|
import {
|
|
21
21
|
noCompletionWithoutVerification,
|
|
@@ -54,13 +54,13 @@ export { TEMPLATES } from './templates-registry';
|
|
|
54
54
|
// 注册表闭环校验(加载期)
|
|
55
55
|
// ========================================
|
|
56
56
|
|
|
57
|
-
const checkConstraints = getAllConstraints().filter(c => c.kind === 'check');
|
|
57
|
+
const checkConstraints = getAllConstraints().filter(c => c.kind === 'check' && isGateConstraint(c));
|
|
58
58
|
|
|
59
59
|
for (const c of checkConstraints) {
|
|
60
60
|
if (!registry.has(c.id)) {
|
|
61
61
|
throw new Error(
|
|
62
|
-
`[harness] 约束注册表闭环校验失败:
|
|
63
|
-
`请在 checkers/
|
|
62
|
+
`[harness] 约束注册表闭环校验失败:channel='gate' 的约束 "${c.id}" 未注册 checker。` +
|
|
63
|
+
`请在 checkers/ 中实现并注册;无 checker 的纪律/流程规则须标非 gate 通道(ADR-0035)。`
|
|
64
64
|
);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -68,7 +68,7 @@ for (const c of checkConstraints) {
|
|
|
68
68
|
for (const id of registry.keys()) {
|
|
69
69
|
if (!checkConstraints.some(c => c.id === id)) {
|
|
70
70
|
throw new Error(
|
|
71
|
-
`[harness] 约束注册表闭环校验失败:checker "${id}" 没有对应的
|
|
71
|
+
`[harness] 约束注册表闭环校验失败:checker "${id}" 没有对应的 channel='gate' 约束定义。` +
|
|
72
72
|
`请在 definitions/ 中补齐定义,或从注册表移除。`
|
|
73
73
|
);
|
|
74
74
|
}
|
|
@@ -78,7 +78,7 @@ for (const id of registry.keys()) {
|
|
|
78
78
|
* 查找检查实现
|
|
79
79
|
*
|
|
80
80
|
* - 传字符串 id 或内置约束:按 id 查内置注册表,未注册返回 undefined
|
|
81
|
-
* (编排层对
|
|
81
|
+
* (编排层对 channel='gate' 未注册的情况抛错)
|
|
82
82
|
* - 传 source='app' 的约束:按 checker 模板 id + params 实例化;
|
|
83
83
|
* 模板 id 未注册 → 抛错(闭环保留,不许静默 pass)
|
|
84
84
|
*/
|
|
@@ -107,13 +107,25 @@ export function registeredCheckCount(): number {
|
|
|
107
107
|
return registry.size;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
export {
|
|
110
|
+
export {
|
|
111
|
+
buildCheckEnv,
|
|
112
|
+
normalizeCheckOutcome,
|
|
113
|
+
findMissingInputs,
|
|
114
|
+
degradeForMissingInputs,
|
|
115
|
+
formatEvidence,
|
|
116
|
+
contextFlag,
|
|
117
|
+
contextEvidenceFlag,
|
|
118
|
+
} from './types';
|
|
111
119
|
export type {
|
|
112
120
|
ConstraintCheck,
|
|
113
121
|
TemplatedCheckerFactory,
|
|
114
122
|
CheckEnv,
|
|
115
123
|
CheckOutcome,
|
|
116
124
|
CheckDetail,
|
|
125
|
+
CheckSkip,
|
|
126
|
+
CheckInputNeeds,
|
|
127
|
+
CheckEvidenceInput,
|
|
128
|
+
ContextEvidenceFlag,
|
|
117
129
|
NormalizedOutcome,
|
|
118
130
|
EvidenceProviders,
|
|
119
131
|
} from './types';
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* no_hardcoded_credentials:硬编码凭证扫描(ADR-0001:shell 扫描逻辑接入真 checker
|
|
2
|
+
* no_hardcoded_credentials:硬编码凭证扫描(ADR-0001:shell 扫描逻辑接入真 checker;
|
|
3
|
+
* harness#184:收窄正则版 + fail 证据行)
|
|
3
4
|
*
|
|
4
5
|
* 扫描 staged diff 的新增行(无 staged diff 时退化为变更文件内容),
|
|
5
|
-
*
|
|
6
|
+
* 命中私钥指纹/口令赋值/URL 内嵌凭证即 fail,证据行带 文件:行号(harness#119)。
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
+
* 分工:本 checker 是 commit 时增量快速反馈;全历史专业扫描走 gitleaks
|
|
9
|
+
* (`security secrets`,ADR-0031)。文档类文件(.md 等)不参与增量扫描——
|
|
10
|
+
* 文档里的密钥样例是误报大户,真实泄露由全历史扫描兜底。
|
|
11
|
+
*
|
|
12
|
+
* 模板文件(.example/.sample/.template/.dist)与占位符值(your_xxx、process.env
|
|
13
|
+
* 引用、变量插值等)豁免;占位符判定作用于「值」而非整行,行内出现 test/example
|
|
14
|
+
* 等词不再豁免真实值。
|
|
8
15
|
*/
|
|
9
16
|
|
|
10
17
|
import { readFileSync } from 'fs';
|
|
11
18
|
import { join } from 'path';
|
|
12
|
-
import type
|
|
19
|
+
import { formatEvidence, type CheckDetail, type ConstraintCheck } from './types';
|
|
13
20
|
|
|
14
21
|
/** 私钥/令牌指纹模式(命中即违规,无例外) */
|
|
15
22
|
const FINGERPRINT_PATTERNS: RegExp[] = [
|
|
@@ -24,53 +31,149 @@ const FINGERPRINT_PATTERNS: RegExp[] = [
|
|
|
24
31
|
/\bxox[baprs]-[A-Za-z0-9-]{10,}\b/,
|
|
25
32
|
// Google API key
|
|
26
33
|
/\bAIza[0-9A-Za-z_-]{35}\b/,
|
|
34
|
+
// JWT(三段 base64url,header 恒以 eyJ 开头)
|
|
35
|
+
/\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{5,}\b/,
|
|
27
36
|
];
|
|
28
37
|
|
|
29
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* 通用赋值模式:口令类变量 = 字面量,键名两侧允许引号(JSON),值允许无引号
|
|
40
|
+
* (.env 裸值 / 无引号 YAML)。捕获组 1 = 引号值,2 = 裸值。
|
|
41
|
+
* 不要求前词边界,覆盖 dbPassword 等 camelCase。
|
|
42
|
+
*/
|
|
30
43
|
const ASSIGNMENT_PATTERN =
|
|
31
|
-
/(?:password|passwd|secret|api[_-]?key|access[_-]?token|auth[_-]?token)\b
|
|
44
|
+
/["']?(?:password|passwd|secret|api[_-]?key|access[_-]?token|auth[_-]?token|token|credential|private[_-]?key|signing[_-]?key)\b["']?\s*[:=]\s*(?:['"]([^'"\n]{8,})['"]|([^\s'"]{8,}))/i;
|
|
45
|
+
|
|
46
|
+
/** URL 内嵌凭证(userinfo 带口令的 URL) */
|
|
47
|
+
const URL_CREDENTIAL_PATTERN = /\b[a-z][a-z0-9+.-]{1,20}:\/\/[^/\s:@'"]+:[^/\s@'"]+@/i;
|
|
32
48
|
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
49
|
+
/**
|
|
50
|
+
* 占位符值(判定作用于值本身,不再整行豁免):
|
|
51
|
+
* 环境变量引用 / your_xxx / <placeholder> / ${...} / xxx / 明显假值 /
|
|
52
|
+
* TS 类型注解(token: string|undefined 的值是类型名而非字面量)
|
|
53
|
+
*/
|
|
54
|
+
const PLACEHOLDER_VALUE =
|
|
55
|
+
/^(?:process\.env\b|your[_-]|<|\$\{|xxx+$|placeholder|changeme|dummy|fake|redacted|string\b|number\b|boolean\b|unknown\b|any\b)/i;
|
|
56
|
+
|
|
57
|
+
/** URL 匹配串内的占位符(变量插值、尖括号、your_xxx) */
|
|
58
|
+
const URL_PLACEHOLDER = /\$\{|<|your[_-]|xxx+/i;
|
|
36
59
|
|
|
37
60
|
/** 允许占位符的模板文件后缀 */
|
|
38
61
|
const TEMPLATE_SUFFIXES = ['.example', '.sample', '.template', '.dist'];
|
|
39
62
|
|
|
40
|
-
|
|
41
|
-
|
|
63
|
+
/** 文档文件后缀:增量扫描豁免(样例误报大户;真实泄露由 gitleaks 全历史扫描兜底) */
|
|
64
|
+
const DOC_SUFFIXES = ['.md', '.mdx', '.rst', '.adoc'];
|
|
65
|
+
|
|
66
|
+
function scannableFile(file: string): boolean {
|
|
67
|
+
return ![...TEMPLATE_SUFFIXES, ...DOC_SUFFIXES].some(s => file.endsWith(s));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 命中规则名(进证据行;密钥原文一律不外显) */
|
|
71
|
+
type HitRule = '私钥/令牌指纹' | '口令类赋值' | 'URL 内嵌凭证';
|
|
72
|
+
|
|
73
|
+
interface Hit {
|
|
74
|
+
file: string;
|
|
75
|
+
line: number;
|
|
76
|
+
rule: HitRule;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 判定单行是否命中,返回规则名 */
|
|
80
|
+
function classifyLine(line: string): HitRule | null {
|
|
81
|
+
for (const pattern of FINGERPRINT_PATTERNS) {
|
|
82
|
+
if (pattern.test(line)) return '私钥/令牌指纹';
|
|
83
|
+
}
|
|
84
|
+
const assign = line.match(ASSIGNMENT_PATTERN);
|
|
85
|
+
if (assign) {
|
|
86
|
+
const value = assign[1] ?? assign[2];
|
|
87
|
+
if (!PLACEHOLDER_VALUE.test(value)) return '口令类赋值';
|
|
88
|
+
}
|
|
89
|
+
const url = line.match(URL_CREDENTIAL_PATTERN);
|
|
90
|
+
if (url && !URL_PLACEHOLDER.test(url[0])) return 'URL 内嵌凭证';
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 扫描文本(file 仅用于证据行),返回全部命中 */
|
|
95
|
+
function scanText(text: string, file: string): Hit[] {
|
|
96
|
+
const hits: Hit[] = [];
|
|
97
|
+
const lines = text.split('\n');
|
|
98
|
+
for (let i = 0; i < lines.length; i++) {
|
|
99
|
+
const rule = classifyLine(lines[i]);
|
|
100
|
+
if (rule) hits.push({ file, line: i + 1, rule });
|
|
101
|
+
}
|
|
102
|
+
return hits;
|
|
42
103
|
}
|
|
43
104
|
|
|
44
105
|
/** 判定一段文本是否包含硬编码凭证 */
|
|
45
106
|
export function containsHardcodedCredential(text: string): boolean {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
107
|
+
return scanText(text, '(text)').length > 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
interface AddedLine {
|
|
111
|
+
file: string;
|
|
112
|
+
lineNo: number;
|
|
113
|
+
text: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** 从 unified diff 中取新增行:按 +++ b/<path> 归属文件,按 @@ +n @@ 推算新文件行号 */
|
|
117
|
+
function collectAddedLines(diff: string): AddedLine[] {
|
|
118
|
+
const out: AddedLine[] = [];
|
|
119
|
+
let file = '';
|
|
120
|
+
let newLine = 0;
|
|
121
|
+
for (const raw of diff.split('\n')) {
|
|
122
|
+
if (raw.startsWith('diff --git')) {
|
|
123
|
+
file = '';
|
|
124
|
+
newLine = 0;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (raw.startsWith('+++ b/')) {
|
|
128
|
+
file = raw.slice('+++ b/'.length);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (raw.startsWith('+++')) {
|
|
132
|
+
file = '';
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (raw.startsWith('@@')) {
|
|
136
|
+
const m = raw.match(/@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
|
|
137
|
+
newLine = m ? parseInt(m[1], 10) : 0;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (!file || newLine === 0) continue;
|
|
141
|
+
if (raw.startsWith('+')) {
|
|
142
|
+
out.push({ file, lineNo: newLine, text: raw.slice(1) });
|
|
143
|
+
newLine++;
|
|
144
|
+
} else if (!raw.startsWith('-') && !raw.startsWith('\\')) {
|
|
145
|
+
newLine++;
|
|
51
146
|
}
|
|
52
|
-
if (ASSIGNMENT_PATTERN.test(line)) return true;
|
|
53
147
|
}
|
|
54
|
-
return
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function failDetail(hits: Hit[]): CheckDetail {
|
|
152
|
+
return {
|
|
153
|
+
pass: false,
|
|
154
|
+
evidence: formatEvidence(
|
|
155
|
+
'发现疑似硬编码凭证(原文不外显;确认后吊销轮换,改走环境变量/加密配置)',
|
|
156
|
+
hits.map(h => `${h.file}:${h.line} — ${h.rule}`)
|
|
157
|
+
),
|
|
158
|
+
};
|
|
55
159
|
}
|
|
56
160
|
|
|
57
161
|
export const noHardcodedCredentials: ConstraintCheck = {
|
|
58
162
|
id: 'no_hardcoded_credentials',
|
|
59
163
|
evaluate: async (env) => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// 1) staged diff 新增行
|
|
164
|
+
// 1) staged diff 新增行(按文件过滤:模板/文档豁免在 diff 路径同样生效)
|
|
63
165
|
let scanned = false;
|
|
64
166
|
try {
|
|
65
167
|
const diff = await env.stagedDiff();
|
|
66
|
-
const added = diff
|
|
67
|
-
|
|
68
|
-
.filter(l => l.startsWith('+') && !l.startsWith('+++'))
|
|
69
|
-
.map(l => l.slice(1))
|
|
70
|
-
.join('\n');
|
|
71
|
-
if (added.trim().length > 0) {
|
|
168
|
+
const added = collectAddedLines(diff).filter(a => scannableFile(a.file));
|
|
169
|
+
if (added.length > 0) {
|
|
72
170
|
scanned = true;
|
|
73
|
-
|
|
171
|
+
const hits: Hit[] = [];
|
|
172
|
+
for (const a of added) {
|
|
173
|
+
const rule = classifyLine(a.text);
|
|
174
|
+
if (rule) hits.push({ file: a.file, line: a.lineNo, rule });
|
|
175
|
+
}
|
|
176
|
+
if (hits.length > 0) return failDetail(hits);
|
|
74
177
|
}
|
|
75
178
|
} catch {
|
|
76
179
|
// diff 不可用 → 退化为文件内容扫描
|
|
@@ -78,14 +181,17 @@ export const noHardcodedCredentials: ConstraintCheck = {
|
|
|
78
181
|
|
|
79
182
|
// 2) 变更文件内容(diff 为空或不可用时)
|
|
80
183
|
if (!scanned) {
|
|
184
|
+
const files = (env.context.changedFiles || []).filter(scannableFile);
|
|
185
|
+
const hits: Hit[] = [];
|
|
81
186
|
for (const file of files) {
|
|
82
187
|
try {
|
|
83
188
|
const content = readFileSync(join(env.projectPath, file), 'utf-8');
|
|
84
|
-
|
|
189
|
+
hits.push(...scanText(content, file));
|
|
85
190
|
} catch {
|
|
86
191
|
// 文件不可读(已删除/二进制)→ 跳过
|
|
87
192
|
}
|
|
88
193
|
}
|
|
194
|
+
if (hits.length > 0) return failDetail(hits);
|
|
89
195
|
}
|
|
90
196
|
|
|
91
197
|
return true;
|