@dommaker/harness 4.0.0 → 4.0.2
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/dist/bootstrap/bootstrap.d.ts +15 -0
- package/dist/bootstrap/bootstrap.js +18 -1
- package/dist/bootstrap/index.d.ts +2 -2
- package/dist/bootstrap/index.js +3 -2
- package/dist/cli/commands/acceptance.d.ts +8 -0
- package/dist/cli/commands/acceptance.js +45 -24
- package/dist/cli/commands/check.d.ts +2 -0
- package/dist/cli/commands/check.js +36 -5
- package/dist/cli/commands/command.js +1 -1
- package/dist/cli/commands/definitions.js +3 -0
- package/dist/cli/commands/init/ci-platform.d.ts +3 -5
- package/dist/cli/commands/init/ci-platform.js +3 -8
- package/dist/cli/commands/init/index.js +78 -11
- package/dist/cli/commands/release.d.ts +11 -3
- package/dist/cli/commands/release.js +159 -52
- package/dist/cli/commands/report.d.ts +2 -0
- package/dist/cli/commands/report.js +54 -6
- package/dist/cli/commands/security.d.ts +3 -3
- package/dist/cli/commands/security.js +3 -2
- package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts +3 -40
- package/dist/cli/commands/sync-docs/capabilities-syncer.js +5 -159
- package/dist/cli/commands/sync-docs/compact.js +2 -2
- package/dist/cli/commands/sync-docs/context-syncer.d.ts +4 -36
- package/dist/cli/commands/sync-docs/context-syncer.js +4 -221
- package/dist/cli/commands/sync-docs/index.d.ts +8 -8
- package/dist/cli/commands/sync-docs/index.js +8 -8
- package/dist/cli/commands/sync-docs/main-flow.d.ts +5 -4
- package/dist/cli/commands/sync-docs/main-flow.js +6 -5
- package/dist/cli/commands/sync-docs/sync-output.d.ts +1 -1
- package/dist/cli/commands/sync-docs/sync-output.js +4 -0
- package/dist/cli/commands/sync-docs/sync-writes.d.ts +1 -1
- package/dist/cli/commands/validate.d.ts +2 -0
- package/dist/cli/commands/validate.js +40 -1
- package/dist/core/command-execution-policy.d.ts +59 -0
- package/dist/core/command-execution-policy.js +167 -0
- package/dist/core/constraints/capabilities-parser.d.ts +2 -1
- package/dist/core/constraints/capabilities-parser.js +2 -1
- package/dist/core/constraints/checker.d.ts +17 -5
- package/dist/core/constraints/checker.js +20 -10
- package/dist/core/constraints/checkers/no-hardcoded-credentials.js +14 -15
- package/dist/core/constraints/checkers/no-test-simplification.js +8 -6
- package/dist/core/constraints/checkers/templated/exec.d.ts +4 -0
- package/dist/core/constraints/checkers/templated/exec.js +11 -48
- package/dist/core/constraints/checkers/templated/file-exists.js +7 -4
- package/dist/core/constraints/checkers/templated/regex-scan.js +11 -15
- package/dist/core/constraints/checkers/types.d.ts +13 -2
- package/dist/core/constraints/checkers/types.js +5 -2
- package/dist/core/constraints/construction-sites.d.ts +1 -1
- package/dist/core/constraints/construction-sites.js +1 -1
- package/dist/core/constraints/injection-writer.d.ts +1 -1
- package/dist/core/constraints/injection-writer.js +1 -1
- package/dist/core/constraints/project-snapshot.d.ts +43 -0
- package/dist/core/constraints/project-snapshot.js +103 -0
- package/dist/core/constraints/run-env.d.ts +35 -0
- package/dist/core/constraints/run-env.js +36 -0
- package/dist/{cli/commands/sync-docs → core/docs-sync}/agents-syncer.d.ts +2 -0
- package/dist/{cli/commands/sync-docs → core/docs-sync}/agents-syncer.js +5 -3
- package/dist/core/docs-sync/capabilities-table.d.ts +46 -0
- package/dist/core/docs-sync/capabilities-table.js +200 -0
- package/dist/core/docs-sync/context-collector.d.ts +40 -0
- package/dist/core/docs-sync/context-collector.js +227 -0
- package/dist/{cli/commands/sync-docs → core/docs-sync}/project-reader.d.ts +5 -1
- package/dist/{cli/commands/sync-docs → core/docs-sync}/project-reader.js +10 -6
- package/dist/{cli/commands/sync-docs → core/docs-sync}/sync-state.d.ts +15 -9
- package/dist/{cli/commands/sync-docs → core/docs-sync}/sync-state.js +26 -29
- package/dist/core/validators/check-handlers/command.js +22 -0
- package/dist/core/validators/check-handlers/output.js +26 -3
- package/dist/core/validators/checkpoint.d.ts +4 -0
- package/dist/core/validators/checkpoint.js +10 -2
- package/dist/gates/acceptance.d.ts +8 -3
- package/dist/gates/acceptance.js +76 -13
- package/dist/gates/command.d.ts +3 -3
- package/dist/gates/command.js +2 -2
- package/dist/gates/contract.d.ts +3 -3
- package/dist/gates/performance.d.ts +10 -3
- package/dist/gates/performance.js +49 -4
- package/dist/gates/review.d.ts +3 -3
- package/dist/gates/security.d.ts +3 -3
- package/dist/gates/security.js +26 -18
- package/dist/gates/types.d.ts +45 -16
- package/dist/knowledge/ingest.d.ts +31 -0
- package/dist/knowledge/ingest.js +192 -52
- package/dist/knowledge/lifecycle.d.ts +15 -0
- package/dist/knowledge/lifecycle.js +62 -0
- package/dist/knowledge/query.d.ts +10 -0
- package/dist/knowledge/query.js +60 -8
- package/dist/knowledge/store.d.ts +56 -3
- package/dist/knowledge/store.js +108 -30
- package/dist/types/checkpoint.d.ts +28 -1
- package/dist/types/command-execution-policy.d.ts +73 -0
- package/dist/types/command-execution-policy.js +16 -0
- package/dist/utils/exec.d.ts +7 -1
- package/dist/utils/exec.js +7 -1
- package/dist/utils/yaml.d.ts +10 -0
- package/dist/utils/yaml.js +11 -0
- package/package.json +1 -1
- package/dist/core/constraints/check-cache.d.ts +0 -43
- package/dist/core/constraints/check-cache.js +0 -77
- package/dist/core/constraints/checkers/templated/glob.d.ts +0 -8
- package/dist/core/constraints/checkers/templated/glob.js +0 -14
- /package/dist/{cli/commands/sync-docs → core/docs-sync}/preserve-block.d.ts +0 -0
- /package/dist/{cli/commands/sync-docs → core/docs-sync}/preserve-block.js +0 -0
|
@@ -47,6 +47,7 @@ const fs = __importStar(require("fs/promises"));
|
|
|
47
47
|
const path = __importStar(require("path"));
|
|
48
48
|
const yaml = __importStar(require("../../utils/yaml"));
|
|
49
49
|
const checkpoint_1 = require("../../core/validators/checkpoint");
|
|
50
|
+
const command_execution_policy_1 = require("../../core/command-execution-policy");
|
|
50
51
|
const command_contract_1 = require("../command-contract");
|
|
51
52
|
const scaffold_templates_1 = require("./scaffold-templates");
|
|
52
53
|
/**
|
|
@@ -89,10 +90,23 @@ async function validate(options, io = command_contract_1.processIO) {
|
|
|
89
90
|
(0, command_contract_1.log)(io, chalk_1.default.gray(`检查点文件: ${checkpointFile}`));
|
|
90
91
|
(0, command_contract_1.log)(io, chalk_1.default.gray(`检查点数量: ${checkpoints.length}`));
|
|
91
92
|
(0, command_contract_1.log)(io);
|
|
93
|
+
// 运行前清单(D3 P0.5 Phase 1):列出本次将执行的项目声明命令;--read-only 下列出被跳过的。
|
|
94
|
+
// 清单只收会执行的族(command_* / 带 command 的 output_*;json_path 不执行 command 不纳入)。
|
|
95
|
+
const commandPlan = (0, command_execution_policy_1.planCommandsFromCheckpoints)(checkpoints);
|
|
96
|
+
if (commandPlan.length > 0) {
|
|
97
|
+
if (options.readOnly) {
|
|
98
|
+
(0, command_contract_1.log)(io, chalk_1.default.gray(`⏭️ --read-only:跳过 ${commandPlan.length} 条项目声明命令(未执行):`));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
(0, command_contract_1.log)(io, chalk_1.default.yellow(`⚠️ 本次将执行 ${commandPlan.length} 条项目声明命令:`));
|
|
102
|
+
}
|
|
103
|
+
(0, command_execution_policy_1.formatCommandPlan)(commandPlan).forEach(line => (0, command_contract_1.log)(io, chalk_1.default.gray(line)));
|
|
104
|
+
}
|
|
92
105
|
// 构建上下文
|
|
93
106
|
const context = {
|
|
94
107
|
projectPath,
|
|
95
108
|
workdir: projectPath,
|
|
109
|
+
commandPolicy: (0, command_execution_policy_1.createCommandExecutionPolicy)({ readOnly: options.readOnly }),
|
|
96
110
|
};
|
|
97
111
|
// 执行验证
|
|
98
112
|
const validator = new checkpoint_1.CheckpointValidator();
|
|
@@ -104,9 +118,23 @@ async function validate(options, io = command_contract_1.processIO) {
|
|
|
104
118
|
if (result.passed) {
|
|
105
119
|
(0, command_contract_1.log)(io, chalk_1.default.green(`✅ ${checkpoint.id}: 通过`));
|
|
106
120
|
}
|
|
121
|
+
else if (result.skipped) {
|
|
122
|
+
// 未完整验证(read-only:声明命令未执行)——不算通过也不算失败,单独列出
|
|
123
|
+
(0, command_contract_1.log)(io, chalk_1.default.gray(`⏭️ ${checkpoint.id}: 跳过评估(命令未执行)`));
|
|
124
|
+
result.checks.forEach(check => {
|
|
125
|
+
if (check.skipped) {
|
|
126
|
+
(0, command_contract_1.log)(io, chalk_1.default.gray(` - ${check.checkId}: ${check.message}${check.skipReason ? `(${check.skipReason})` : ''}`));
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
107
130
|
else {
|
|
108
131
|
(0, command_contract_1.log)(io, chalk_1.default.red(`❌ ${checkpoint.id}: 失败`));
|
|
109
132
|
result.checks.forEach(check => {
|
|
133
|
+
// read-only 跳过的检查不以红色失败出现:跳过明细 + 原因(与真实失败同 checkpoint 并存时同样可见)
|
|
134
|
+
if (check.skipped) {
|
|
135
|
+
(0, command_contract_1.log)(io, chalk_1.default.gray(` - ${check.checkId}: ${check.message}${check.skipReason ? `(${check.skipReason})` : ''}`));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
110
138
|
if (!check.passed) {
|
|
111
139
|
(0, command_contract_1.log)(io, chalk_1.default.red(` - ${check.checkId}: ${check.message || check.error}`));
|
|
112
140
|
// error 与 message 不同即带了额外信息(退出码、输出末段),打出来。
|
|
@@ -123,14 +151,25 @@ async function validate(options, io = command_contract_1.processIO) {
|
|
|
123
151
|
}
|
|
124
152
|
// 统计结果
|
|
125
153
|
const passed = results.filter(r => r.passed).length;
|
|
126
|
-
const failed = results.filter(r => !r.passed).length;
|
|
154
|
+
const failed = results.filter(r => !r.passed && !r.skipped).length;
|
|
155
|
+
const skippedCount = results.filter(r => r.skipped).length;
|
|
127
156
|
(0, command_contract_1.log)(io);
|
|
128
157
|
(0, command_contract_1.log)(io, chalk_1.default.gray(`通过: ${passed}/${results.length}`));
|
|
158
|
+
if (skippedCount > 0) {
|
|
159
|
+
(0, command_contract_1.log)(io, chalk_1.default.gray(`跳过: ${skippedCount} 个检查点(命令未执行)`));
|
|
160
|
+
}
|
|
129
161
|
if (failed > 0) {
|
|
130
162
|
(0, command_contract_1.log)(io, chalk_1.default.red(`\n🛑 ${failed} 个检查点未通过`));
|
|
131
163
|
// 工单 23:门控语义——检查点失败一律非零退出(此前仅 --strict 退出,钩子/CI 形同虚设)
|
|
132
164
|
return { kind: 'fail', reason: `${failed} 个检查点未通过: ${failedIds.join(', ')}` };
|
|
133
165
|
}
|
|
166
|
+
if (skippedCount > 0) {
|
|
167
|
+
// read-only 无实际失败但有未评估:返回 skip(退出 0)而非 ok——不把「未完整验证」当验证通过
|
|
168
|
+
return {
|
|
169
|
+
kind: 'skip',
|
|
170
|
+
reason: `--read-only: ${skippedCount} 个检查点未完整验证(命令未执行)`,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
134
173
|
(0, command_contract_1.log)(io, chalk_1.default.green('\n✅ 所有检查点验证通过'));
|
|
135
174
|
return { kind: 'ok' };
|
|
136
175
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 统一命令执行策略(D3,P0.5 Phase 1 副作用授权)
|
|
3
|
+
*
|
|
4
|
+
* check / validate / report 三命令共用同一授权与跳过语义:
|
|
5
|
+
* - createCommandExecutionPolicy:CLI 组合根唯一创建点。readOnly 缺省 false =
|
|
6
|
+
* 默认执行(Phase 1 不改默认行为);execute 缺省 = 真实 spawn 执行
|
|
7
|
+
* (由 exec 模板迁入,detached 进程组、超时 SIGKILL、8KiB 流截断语义逐字不动)
|
|
8
|
+
* - skipReason:read-only 跳过原因唯一措辞来源(消费方只透传)
|
|
9
|
+
* - 命令发现(plan*):项目 YAML 声明命令的清单数据源 + 人读渲染(formatCommandPlan),
|
|
10
|
+
* 三命令共享,不各抄一份。清单只收**会执行**的声明命令:
|
|
11
|
+
* 约束侧 = gate 通道 checker=exec + params.command;检查点侧 = command_success /
|
|
12
|
+
* command_output 的 config.command + 带 command 的 output_contains /
|
|
13
|
+
* output_not_contains / output_matches(json_path 当前不执行 command,不纳入)
|
|
14
|
+
* - HTTP(http_status/http_body 的 fetch)是网络请求不是命令执行通道,不纳入清单、
|
|
15
|
+
* 不受 read-only 跳过;custom handlers 与 harness 自身 git 取证同理不混入
|
|
16
|
+
*/
|
|
17
|
+
import type { CommandExecutionPolicy, CommandExecutor, CommandPlanItem, ExecutedCommand } from '../types/command-execution-policy';
|
|
18
|
+
import type { Constraint, ConstraintContext } from '../types/constraint';
|
|
19
|
+
import type { Checkpoint } from '../types/checkpoint';
|
|
20
|
+
/**
|
|
21
|
+
* 真实 shell 命令执行(缺省执行缝)
|
|
22
|
+
*
|
|
23
|
+
* 语义自 exec 模板原样迁入(harness#181 保护面):detached 成组,超时整组 SIGKILL
|
|
24
|
+
* (shell 的子孙进程一并终止,不留孤儿),stdout/stderr 各至多留 MAX_STREAM_CHARS。
|
|
25
|
+
*/
|
|
26
|
+
export declare function runShellCommand(command: string, cwd: string, timeoutMs: number): Promise<ExecutedCommand>;
|
|
27
|
+
/**
|
|
28
|
+
* 创建统一命令执行策略(CLI 组合根唯一创建点)
|
|
29
|
+
*
|
|
30
|
+
* - readOnly 缺省 false:默认执行(Phase 1 不改变默认行为)
|
|
31
|
+
* - execute 注入 = 执行缝(测试注入计数替身,证明 read-only 下零调用;
|
|
32
|
+
* 普通模式证明经替身真实执行)
|
|
33
|
+
* - 库调用方不创建策略 = 消费方缺省默认执行(行为兼容)
|
|
34
|
+
*/
|
|
35
|
+
export declare function createCommandExecutionPolicy(options?: {
|
|
36
|
+
readOnly?: boolean;
|
|
37
|
+
execute?: CommandExecutor;
|
|
38
|
+
}): CommandExecutionPolicy;
|
|
39
|
+
/**
|
|
40
|
+
* 从生效约束集提取声明命令清单(check / report 的运行前清单数据源)
|
|
41
|
+
*
|
|
42
|
+
* 只收 gate 通道 checker=exec 且 params.command 非空的条目;workflow/discipline
|
|
43
|
+
* 通道不进入检查分发,不执行,不进清单。
|
|
44
|
+
*
|
|
45
|
+
* **触发域过滤与 checker 分发同口径**(review 回修):context 必填,按
|
|
46
|
+
* `[operation, ...extraTriggers]` 过 `matchesTrigger`——清单只列本次真正会
|
|
47
|
+
* 分发(将执行/跳过)的命令,trigger 不匹配的约束不进清单也不执行。
|
|
48
|
+
*/
|
|
49
|
+
export declare function planCommandsFromConstraints(constraints: Record<string, Constraint> | undefined, context: ConstraintContext): CommandPlanItem[];
|
|
50
|
+
/**
|
|
51
|
+
* 从检查点列表提取声明命令清单(validate 的运行前清单数据源)
|
|
52
|
+
*
|
|
53
|
+
* 只收会执行 config.command 的族:command_success / command_output(command 必填)
|
|
54
|
+
* 与带 command 的 output_contains / output_not_contains / output_matches。
|
|
55
|
+
* json_path 当前不执行 command(未裁决不改),不纳入清单也不被 read-only 跳过。
|
|
56
|
+
*/
|
|
57
|
+
export declare function planCommandsFromCheckpoints(checkpoints: Checkpoint[]): CommandPlanItem[];
|
|
58
|
+
/** 清单渲染(人读行形状对外可见,由测试钉住) */
|
|
59
|
+
export declare function formatCommandPlan(plan: CommandPlanItem[]): string[];
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 统一命令执行策略(D3,P0.5 Phase 1 副作用授权)
|
|
4
|
+
*
|
|
5
|
+
* check / validate / report 三命令共用同一授权与跳过语义:
|
|
6
|
+
* - createCommandExecutionPolicy:CLI 组合根唯一创建点。readOnly 缺省 false =
|
|
7
|
+
* 默认执行(Phase 1 不改默认行为);execute 缺省 = 真实 spawn 执行
|
|
8
|
+
* (由 exec 模板迁入,detached 进程组、超时 SIGKILL、8KiB 流截断语义逐字不动)
|
|
9
|
+
* - skipReason:read-only 跳过原因唯一措辞来源(消费方只透传)
|
|
10
|
+
* - 命令发现(plan*):项目 YAML 声明命令的清单数据源 + 人读渲染(formatCommandPlan),
|
|
11
|
+
* 三命令共享,不各抄一份。清单只收**会执行**的声明命令:
|
|
12
|
+
* 约束侧 = gate 通道 checker=exec + params.command;检查点侧 = command_success /
|
|
13
|
+
* command_output 的 config.command + 带 command 的 output_contains /
|
|
14
|
+
* output_not_contains / output_matches(json_path 当前不执行 command,不纳入)
|
|
15
|
+
* - HTTP(http_status/http_body 的 fetch)是网络请求不是命令执行通道,不纳入清单、
|
|
16
|
+
* 不受 read-only 跳过;custom handlers 与 harness 自身 git 取证同理不混入
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.runShellCommand = runShellCommand;
|
|
20
|
+
exports.createCommandExecutionPolicy = createCommandExecutionPolicy;
|
|
21
|
+
exports.planCommandsFromConstraints = planCommandsFromConstraints;
|
|
22
|
+
exports.planCommandsFromCheckpoints = planCommandsFromCheckpoints;
|
|
23
|
+
exports.formatCommandPlan = formatCommandPlan;
|
|
24
|
+
const child_process_1 = require("child_process");
|
|
25
|
+
const definitions_1 = require("./constraints/definitions");
|
|
26
|
+
const triggers_1 = require("./constraints/triggers");
|
|
27
|
+
/** stdout/stderr 各自保留的字符上限(超出只记截断标记,不拖垮证据面与 trace) */
|
|
28
|
+
const MAX_STREAM_CHARS = 8_192;
|
|
29
|
+
/**
|
|
30
|
+
* 真实 shell 命令执行(缺省执行缝)
|
|
31
|
+
*
|
|
32
|
+
* 语义自 exec 模板原样迁入(harness#181 保护面):detached 成组,超时整组 SIGKILL
|
|
33
|
+
* (shell 的子孙进程一并终止,不留孤儿),stdout/stderr 各至多留 MAX_STREAM_CHARS。
|
|
34
|
+
*/
|
|
35
|
+
function runShellCommand(command, cwd, timeoutMs) {
|
|
36
|
+
return new Promise((resolve) => {
|
|
37
|
+
// detached 成组:超时整组 SIGKILL,shell 的子孙进程一并终止,不留孤儿拖住机器
|
|
38
|
+
const child = (0, child_process_1.spawn)(command, { cwd, shell: true, detached: true });
|
|
39
|
+
let stdout = '';
|
|
40
|
+
let stderr = '';
|
|
41
|
+
let truncated = false;
|
|
42
|
+
let timedOut = false;
|
|
43
|
+
let settled = false;
|
|
44
|
+
const collect = (chunk, current) => {
|
|
45
|
+
if (current.length >= MAX_STREAM_CHARS) {
|
|
46
|
+
truncated = true;
|
|
47
|
+
return current;
|
|
48
|
+
}
|
|
49
|
+
const next = current + chunk.toString('utf-8');
|
|
50
|
+
if (next.length > MAX_STREAM_CHARS)
|
|
51
|
+
truncated = true;
|
|
52
|
+
return next.slice(0, MAX_STREAM_CHARS);
|
|
53
|
+
};
|
|
54
|
+
const finish = (partial) => {
|
|
55
|
+
if (settled)
|
|
56
|
+
return;
|
|
57
|
+
settled = true;
|
|
58
|
+
clearTimeout(timer);
|
|
59
|
+
resolve({ ...partial, timedOut, stdout, stderr, truncated });
|
|
60
|
+
};
|
|
61
|
+
const timer = setTimeout(() => {
|
|
62
|
+
timedOut = true;
|
|
63
|
+
try {
|
|
64
|
+
if (child.pid !== undefined)
|
|
65
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// 进程组 kill 失败(竞态:子进程已退,ESRCH)→ 退化单进程 kill,best-effort 收尾
|
|
69
|
+
child.kill('SIGKILL');
|
|
70
|
+
}
|
|
71
|
+
}, timeoutMs);
|
|
72
|
+
timer.unref();
|
|
73
|
+
child.stdout.on('data', (chunk) => { stdout = collect(chunk, stdout); });
|
|
74
|
+
child.stderr.on('data', (chunk) => { stderr = collect(chunk, stderr); });
|
|
75
|
+
child.on('error', (err) => finish({ code: null, signal: null, spawnError: err.message }));
|
|
76
|
+
child.on('close', (code, signal) => finish({ code, signal }));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 创建统一命令执行策略(CLI 组合根唯一创建点)
|
|
81
|
+
*
|
|
82
|
+
* - readOnly 缺省 false:默认执行(Phase 1 不改变默认行为)
|
|
83
|
+
* - execute 注入 = 执行缝(测试注入计数替身,证明 read-only 下零调用;
|
|
84
|
+
* 普通模式证明经替身真实执行)
|
|
85
|
+
* - 库调用方不创建策略 = 消费方缺省默认执行(行为兼容)
|
|
86
|
+
*/
|
|
87
|
+
function createCommandExecutionPolicy(options) {
|
|
88
|
+
return {
|
|
89
|
+
readOnly: options?.readOnly ?? false,
|
|
90
|
+
skipReason: (command) => `--read-only:跳过命令执行(未执行):${command}`,
|
|
91
|
+
execute: options?.execute ?? runShellCommand,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 检查点侧会执行声明命令的 check type(判别联合收窄)
|
|
96
|
+
*
|
|
97
|
+
* json_path 刻意不在列:当前实现不执行 config.command(未裁决不改),
|
|
98
|
+
* 不纳入清单也不被 read-only 跳过。
|
|
99
|
+
*/
|
|
100
|
+
function checkpointCheckCommand(check) {
|
|
101
|
+
switch (check.type) {
|
|
102
|
+
case 'command_success':
|
|
103
|
+
case 'command_output':
|
|
104
|
+
// command 是这两族的必填字段(加载期 assertCheckpointShape 校验)
|
|
105
|
+
return check.config.command;
|
|
106
|
+
case 'output_contains':
|
|
107
|
+
case 'output_not_contains':
|
|
108
|
+
case 'output_matches': {
|
|
109
|
+
const command = check.config.command;
|
|
110
|
+
return typeof command === 'string' && command.length > 0 ? command : undefined;
|
|
111
|
+
}
|
|
112
|
+
default:
|
|
113
|
+
// file_* / json_path / http_* / custom:不执行项目声明命令
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 从生效约束集提取声明命令清单(check / report 的运行前清单数据源)
|
|
119
|
+
*
|
|
120
|
+
* 只收 gate 通道 checker=exec 且 params.command 非空的条目;workflow/discipline
|
|
121
|
+
* 通道不进入检查分发,不执行,不进清单。
|
|
122
|
+
*
|
|
123
|
+
* **触发域过滤与 checker 分发同口径**(review 回修):context 必填,按
|
|
124
|
+
* `[operation, ...extraTriggers]` 过 `matchesTrigger`——清单只列本次真正会
|
|
125
|
+
* 分发(将执行/跳过)的命令,trigger 不匹配的约束不进清单也不执行。
|
|
126
|
+
*/
|
|
127
|
+
function planCommandsFromConstraints(constraints, context) {
|
|
128
|
+
// 与 ConstraintChecker.findApplicableConstraints 同一 operations 口径
|
|
129
|
+
const operations = [context.operation, ...(context.extraTriggers ?? [])];
|
|
130
|
+
const plan = [];
|
|
131
|
+
for (const constraint of Object.values(constraints ?? {})) {
|
|
132
|
+
if (!(0, definitions_1.isGateConstraint)(constraint))
|
|
133
|
+
continue;
|
|
134
|
+
if (!(0, triggers_1.matchesTrigger)(constraint, operations))
|
|
135
|
+
continue;
|
|
136
|
+
if (constraint.checker !== 'exec')
|
|
137
|
+
continue;
|
|
138
|
+
const command = constraint.params?.command;
|
|
139
|
+
if (typeof command === 'string' && command.length > 0) {
|
|
140
|
+
plan.push({ source: constraint.id, command });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return plan;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 从检查点列表提取声明命令清单(validate 的运行前清单数据源)
|
|
147
|
+
*
|
|
148
|
+
* 只收会执行 config.command 的族:command_success / command_output(command 必填)
|
|
149
|
+
* 与带 command 的 output_contains / output_not_contains / output_matches。
|
|
150
|
+
* json_path 当前不执行 command(未裁决不改),不纳入清单也不被 read-only 跳过。
|
|
151
|
+
*/
|
|
152
|
+
function planCommandsFromCheckpoints(checkpoints) {
|
|
153
|
+
const plan = [];
|
|
154
|
+
for (const checkpoint of checkpoints) {
|
|
155
|
+
for (const check of checkpoint.checks ?? []) {
|
|
156
|
+
const command = checkpointCheckCommand(check);
|
|
157
|
+
if (command !== undefined) {
|
|
158
|
+
plan.push({ source: `${checkpoint.id}/${check.id}`, command });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return plan;
|
|
163
|
+
}
|
|
164
|
+
/** 清单渲染(人读行形状对外可见,由测试钉住) */
|
|
165
|
+
function formatCommandPlan(plan) {
|
|
166
|
+
return plan.map(item => ` - ${item.command}(${item.source})`);
|
|
167
|
+
}
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* 此前 checker.parseCapabilitiesFiles 与 sync-docs.parseCapabilitiesFiles
|
|
5
5
|
* 各持一份正则,收敛到此处。H2 起能力清单计数(checkCapabilityCounts /
|
|
6
6
|
* updateCapabilityCounts)也从 sync-docs/capabilities-syncer 收敛到此,
|
|
7
|
-
* 使本模块成为 CAPABILITIES.md 解析 +
|
|
7
|
+
* 使本模块成为 CAPABILITIES.md 解析 + 计数唯一入口
|
|
8
|
+
* (file-table 文本判定正本见 core/docs-sync/capabilities-table.ts,P2.8 下沉)。
|
|
8
9
|
*
|
|
9
10
|
* 计数所需的命令/门禁定义由调用方注入(harness#88:core 不值导入上层定义表)。
|
|
10
11
|
*/
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* 此前 checker.parseCapabilitiesFiles 与 sync-docs.parseCapabilitiesFiles
|
|
6
6
|
* 各持一份正则,收敛到此处。H2 起能力清单计数(checkCapabilityCounts /
|
|
7
7
|
* updateCapabilityCounts)也从 sync-docs/capabilities-syncer 收敛到此,
|
|
8
|
-
* 使本模块成为 CAPABILITIES.md 解析 +
|
|
8
|
+
* 使本模块成为 CAPABILITIES.md 解析 + 计数唯一入口
|
|
9
|
+
* (file-table 文本判定正本见 core/docs-sync/capabilities-table.ts,P2.8 下沉)。
|
|
9
10
|
*
|
|
10
11
|
* 计数所需的命令/门禁定义由调用方注入(harness#88:core 不值导入上层定义表)。
|
|
11
12
|
*/
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* ADR-0035),非 gate 条目(workflow/discipline)不进入检查分发。
|
|
9
9
|
*/
|
|
10
10
|
import { Constraint, ConstraintContext, ConstraintResult, ConstraintCheckResult } from '../../types/constraint';
|
|
11
|
+
import type { CommandExecutionPolicy } from '../../types/command-execution-policy';
|
|
11
12
|
import type { ExecutionTrace } from '../../types/trace';
|
|
12
13
|
import type { MergedConstraintsConfig } from '../../types/project-config';
|
|
13
14
|
import { type GitEvidence } from './git-evidence';
|
|
@@ -16,8 +17,9 @@ import { type RunEnv } from './run-env';
|
|
|
16
17
|
* trace 记录器最小接口(工单 15 decycle 收尾,harness#88)
|
|
17
18
|
*
|
|
18
19
|
* core 不上行依赖 monitoring:记录器经**构造参数**注入,未注入 = no-op
|
|
19
|
-
*
|
|
20
|
-
*
|
|
20
|
+
* (默认无副作用)。真实收集器由组合根接线——生产侧唯一装配函数
|
|
21
|
+
* `assembleConstraintChecker(projectPath)`(src/bootstrap/,P1.1),
|
|
22
|
+
* CLI check/report 与 bootstrapHarness 共用。
|
|
21
23
|
*/
|
|
22
24
|
export interface TraceRecorder {
|
|
23
25
|
record(trace: ExecutionTrace): void;
|
|
@@ -27,13 +29,23 @@ export interface TraceRecorder {
|
|
|
27
29
|
*/
|
|
28
30
|
export declare class ConstraintChecker {
|
|
29
31
|
private static instance;
|
|
30
|
-
/** 检查结果缓存(S7:src 扫描等重复 I/O,TTL=1s 防跨测试污染) */
|
|
31
|
-
private cache;
|
|
32
32
|
/** trace 记录器(构造注入;缺省 no-op) */
|
|
33
33
|
private readonly traceRecorder;
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* 命令执行策略(D3 P0.5 Phase 1;构造注入,缺省 = 默认执行)
|
|
36
|
+
*
|
|
37
|
+
* 一次运行一份,经 checkPrecondition 挂上本次 CheckEnv.commandPolicy:
|
|
38
|
+
* read-only 下 exec 模板 checker 三态跳过项目声明命令。库直调不注入 =
|
|
39
|
+
* 行为兼容(默认执行)。
|
|
40
|
+
*/
|
|
41
|
+
private readonly commandPolicy?;
|
|
42
|
+
constructor(traceRecorder?: TraceRecorder, commandPolicy?: CommandExecutionPolicy);
|
|
35
43
|
/**
|
|
36
44
|
* 获取单例实例(未接线记录器的默认实例:不写 trace)
|
|
45
|
+
*
|
|
46
|
+
* 本实例不再持有任何 run 级缓存(srcScan 缓存已归属 RunEnv,P1.1)——
|
|
47
|
+
* 单例只剩「免构造的默认评估器」职责,跨调用隔离由调用链上的
|
|
48
|
+
* RunEnv(一次 run 一份)保证。
|
|
37
49
|
*/
|
|
38
50
|
static getInstance(): ConstraintChecker;
|
|
39
51
|
/**
|
|
@@ -16,9 +16,6 @@ exports.collectConstraints = collectConstraints;
|
|
|
16
16
|
const constraint_1 = require("../../types/constraint");
|
|
17
17
|
const definitions_1 = require("./definitions");
|
|
18
18
|
const triggers_1 = require("./triggers");
|
|
19
|
-
const path_1 = require("path");
|
|
20
|
-
const check_cache_1 = require("./check-cache");
|
|
21
|
-
const file_walk_1 = require("../../utils/file-walk");
|
|
22
19
|
const checkers_1 = require("./checkers");
|
|
23
20
|
const git_evidence_1 = require("./git-evidence");
|
|
24
21
|
const run_env_1 = require("./run-env");
|
|
@@ -29,15 +26,26 @@ const NOOP_TRACE_RECORDER = { record: () => undefined };
|
|
|
29
26
|
*/
|
|
30
27
|
class ConstraintChecker {
|
|
31
28
|
static instance;
|
|
32
|
-
/** 检查结果缓存(S7:src 扫描等重复 I/O,TTL=1s 防跨测试污染) */
|
|
33
|
-
cache = new check_cache_1.CheckCache({ ttlMs: 1000 });
|
|
34
29
|
/** trace 记录器(构造注入;缺省 no-op) */
|
|
35
30
|
traceRecorder;
|
|
36
|
-
|
|
31
|
+
/**
|
|
32
|
+
* 命令执行策略(D3 P0.5 Phase 1;构造注入,缺省 = 默认执行)
|
|
33
|
+
*
|
|
34
|
+
* 一次运行一份,经 checkPrecondition 挂上本次 CheckEnv.commandPolicy:
|
|
35
|
+
* read-only 下 exec 模板 checker 三态跳过项目声明命令。库直调不注入 =
|
|
36
|
+
* 行为兼容(默认执行)。
|
|
37
|
+
*/
|
|
38
|
+
commandPolicy;
|
|
39
|
+
constructor(traceRecorder = NOOP_TRACE_RECORDER, commandPolicy) {
|
|
37
40
|
this.traceRecorder = traceRecorder;
|
|
41
|
+
this.commandPolicy = commandPolicy;
|
|
38
42
|
}
|
|
39
43
|
/**
|
|
40
44
|
* 获取单例实例(未接线记录器的默认实例:不写 trace)
|
|
45
|
+
*
|
|
46
|
+
* 本实例不再持有任何 run 级缓存(srcScan 缓存已归属 RunEnv,P1.1)——
|
|
47
|
+
* 单例只剩「免构造的默认评估器」职责,跨调用隔离由调用链上的
|
|
48
|
+
* RunEnv(一次 run 一份)保证。
|
|
41
49
|
*/
|
|
42
50
|
static getInstance() {
|
|
43
51
|
if (!ConstraintChecker.instance) {
|
|
@@ -129,17 +137,20 @@ class ConstraintChecker {
|
|
|
129
137
|
}
|
|
130
138
|
const projectPath = context.projectPath || process.cwd();
|
|
131
139
|
const git = evidence ?? (0, git_evidence_1.createGitEvidence)(projectPath);
|
|
140
|
+
// 本 run 的观察面:srcScan 缓存挂在它上面(一次 run 一份、跑完即弃,P1.1),
|
|
141
|
+
// 不再用本实例上的 TTL 缓存 + 手工 invalidate 掩盖 run 边界
|
|
142
|
+
const run = runEnv ?? (0, run_env_1.createRunEnv)(projectPath);
|
|
132
143
|
const env = (0, checkers_1.buildCheckEnv)(context, {
|
|
133
144
|
stagedDiff: async () => git.stagedDiff(),
|
|
134
145
|
stagedDiffNames: async () => git.changedFileNames(true),
|
|
135
|
-
srcScan: (root) =>
|
|
146
|
+
srcScan: (root) => run.srcScan(root),
|
|
136
147
|
available: (input) => {
|
|
137
148
|
switch (input) {
|
|
138
149
|
case 'stagedDiff': return git.stagedDiffAvailable();
|
|
139
150
|
case 'stagedDiffNames': return git.changedFileNamesAvailable(true);
|
|
140
151
|
}
|
|
141
152
|
},
|
|
142
|
-
},
|
|
153
|
+
}, run, this.commandPolicy);
|
|
143
154
|
// 输入契约(harness#182):checker 声明的输入环境给不了 → 带原因的 skipped,
|
|
144
155
|
// 不进入 evaluate(「检查器失效 ≠ 对象合规」,不再对空证据假 pass / 无声 skip)
|
|
145
156
|
const degraded = (0, checkers_1.degradeForMissingInputs)(impl, env);
|
|
@@ -195,8 +206,7 @@ class ConstraintChecker {
|
|
|
195
206
|
* mode='block' 首个 error 级违规即抛,mode='collect' 全量跑完不抛
|
|
196
207
|
*/
|
|
197
208
|
async runAllConstraints(context, customConfig, evidence, runEnv, mode) {
|
|
198
|
-
//
|
|
199
|
-
this.cache.invalidate();
|
|
209
|
+
// git 证据 = 本 run 独占的 adapter 实例(工单 18 → #87)
|
|
200
210
|
const projectPath = context.projectPath || process.cwd();
|
|
201
211
|
const run = evidence ?? (0, git_evidence_1.createGitEvidence)(projectPath);
|
|
202
212
|
// 观察面同一形状(ADR-0023):调用方传了就共用,没传也只造一枚——逐条 checker 不再各读一遍配置
|
|
@@ -19,10 +19,8 @@
|
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.noHardcodedCredentials = void 0;
|
|
22
|
-
const fs_1 = require("fs");
|
|
23
|
-
const path_1 = require("path");
|
|
24
22
|
const types_1 = require("./types");
|
|
25
|
-
const
|
|
23
|
+
const run_env_1 = require("../run-env");
|
|
26
24
|
/** 私钥/令牌指纹模式(命中即违规,无例外) */
|
|
27
25
|
const FINGERPRINT_PATTERNS = [
|
|
28
26
|
// PEM 私钥头
|
|
@@ -42,9 +40,11 @@ const FINGERPRINT_PATTERNS = [
|
|
|
42
40
|
/**
|
|
43
41
|
* 通用赋值模式:口令类变量 = 字面量,键名两侧允许引号(JSON),值允许无引号
|
|
44
42
|
* (.env 裸值 / 无引号 YAML)。捕获组 1 = 引号值,2 = 裸值。
|
|
45
|
-
* 不要求前词边界,覆盖 dbPassword 等 camelCase
|
|
43
|
+
* 不要求前词边界,覆盖 dbPassword 等 camelCase;
|
|
44
|
+
* secret 一族另带 secret[_-]?key / secret[_-]access[_-]key(_ 是单词字符,
|
|
45
|
+
* secret\b 抓不到 SECRET_KEY、secret-key、AWS_SECRET_ACCESS_KEY,P0.4)。
|
|
46
46
|
*/
|
|
47
|
-
const ASSIGNMENT_PATTERN = /["']?(?:password|passwd|secret|api[_-]?key|access[_-]?token|auth[_-]?token|token|credential|private[_-]?key|signing[_-]?key)\b["']?\s*[:=]\s*(?:['"]([^'"\n]{8,})['"]|([^\s'"]{8,}))/i;
|
|
47
|
+
const ASSIGNMENT_PATTERN = /["']?(?:password|passwd|secret\b|secret(?:[_-]access)?[_-]?key|api[_-]?key|access[_-]?token|auth[_-]?token|token|credential|private[_-]?key|signing[_-]?key)\b["']?\s*[:=]\s*(?:['"]([^'"\n]{8,})['"]|([^\s'"]{8,}))/i;
|
|
48
48
|
/** URL 内嵌凭证(userinfo 带口令的 URL) */
|
|
49
49
|
const URL_CREDENTIAL_PATTERN = /\b[a-z][a-z0-9+.-]{1,20}:\/\/[^/\s:@'"]+:[^/\s@'"]+@/i;
|
|
50
50
|
/**
|
|
@@ -105,8 +105,8 @@ function scanText(text, file) {
|
|
|
105
105
|
return hits;
|
|
106
106
|
}
|
|
107
107
|
/** 从 unified diff 中取新增行:文件归属与行号推算见 utils/diff-parse 正本 */
|
|
108
|
-
function collectAddedLines(
|
|
109
|
-
return
|
|
108
|
+
function collectAddedLines(lines) {
|
|
109
|
+
return lines
|
|
110
110
|
.filter(l => l.kind === 'added' && l.file !== '' && l.newLineNo !== 0)
|
|
111
111
|
.map(l => ({ file: l.file, lineNo: l.newLineNo, text: l.text }));
|
|
112
112
|
}
|
|
@@ -123,7 +123,8 @@ exports.noHardcodedCredentials = {
|
|
|
123
123
|
let scanned = false;
|
|
124
124
|
try {
|
|
125
125
|
const diff = await env.stagedDiff();
|
|
126
|
-
|
|
126
|
+
// diff 解析经 run 级快照:同 run 内多条解析类约束共享同一解析
|
|
127
|
+
const added = collectAddedLines((0, run_env_1.projectSnapshotFor)(env).parseDiff(diff)).filter(a => scannableFile(a.file));
|
|
127
128
|
if (added.length > 0) {
|
|
128
129
|
scanned = true;
|
|
129
130
|
const hits = [];
|
|
@@ -144,13 +145,11 @@ exports.noHardcodedCredentials = {
|
|
|
144
145
|
const files = (env.context.changedFiles || []).filter(scannableFile);
|
|
145
146
|
const hits = [];
|
|
146
147
|
for (const file of files) {
|
|
147
|
-
try
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
// 文件不可读(已删除/二进制)→ 跳过
|
|
153
|
-
}
|
|
148
|
+
// 经 run 级快照读内容:同 run 内多条约束共享同一文件读取;读不出 = 跳过(口径同旧 try/catch)
|
|
149
|
+
const content = (0, run_env_1.projectSnapshotFor)(env).content(file);
|
|
150
|
+
if (content === undefined)
|
|
151
|
+
continue; // 文件不可读(已删除/二进制)→ 跳过
|
|
152
|
+
hits.push(...scanText(content, file));
|
|
154
153
|
}
|
|
155
154
|
if (hits.length > 0)
|
|
156
155
|
return failDetail(hits);
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.noTestSimplification = void 0;
|
|
21
21
|
const types_1 = require("./types");
|
|
22
|
-
const diff_parse_1 = require("../../../utils/diff-parse");
|
|
23
22
|
const error_1 = require("../../../utils/error");
|
|
23
|
+
const run_env_1 = require("../run-env");
|
|
24
24
|
/** 测试文件判定:`.test.`/`.spec.` 后缀段或 `__tests__/` 目录段 */
|
|
25
25
|
function isTestFile(path) {
|
|
26
26
|
return /__tests__\//.test(path) || /\.(?:test|spec)\.[^/]+$/.test(path);
|
|
@@ -38,8 +38,9 @@ const UNATTRIBUTED = '(无文件归属的 diff 行)';
|
|
|
38
38
|
/**
|
|
39
39
|
* 按文件归集 diff 增删行:文件归属(含 `+++ /dev/null` 回落旧文件名)见
|
|
40
40
|
* utils/diff-parse 正本;无归属行挂兜底键(fail-closed 照判),`\` 行正本已忽略。
|
|
41
|
+
* 入参 = 快照解析后的行(同 run 内多条解析类约束共享同一解析)。
|
|
41
42
|
*/
|
|
42
|
-
function tallyDiff(
|
|
43
|
+
function tallyDiff(lines) {
|
|
43
44
|
const tallies = new Map();
|
|
44
45
|
const tally = (file) => {
|
|
45
46
|
const key = file || UNATTRIBUTED;
|
|
@@ -50,7 +51,7 @@ function tallyDiff(diff) {
|
|
|
50
51
|
}
|
|
51
52
|
return t;
|
|
52
53
|
};
|
|
53
|
-
for (const line of
|
|
54
|
+
for (const line of lines) {
|
|
54
55
|
if (line.kind === 'context')
|
|
55
56
|
continue;
|
|
56
57
|
const t = tally(line.file);
|
|
@@ -68,9 +69,9 @@ function tallyDiff(diff) {
|
|
|
68
69
|
return tallies;
|
|
69
70
|
}
|
|
70
71
|
/** 汇总违规证据;空数组 = 通过 */
|
|
71
|
-
function violations(
|
|
72
|
+
function violations(lines) {
|
|
72
73
|
const out = [];
|
|
73
|
-
for (const [file, t] of tallyDiff(
|
|
74
|
+
for (const [file, t] of tallyDiff(lines)) {
|
|
74
75
|
if (file !== UNATTRIBUTED && !isTestFile(file))
|
|
75
76
|
continue;
|
|
76
77
|
for (const line of t.skipOnlyLines) {
|
|
@@ -96,7 +97,8 @@ exports.noTestSimplification = {
|
|
|
96
97
|
needs: { evidence: ['stagedDiff'] },
|
|
97
98
|
async evaluate(env) {
|
|
98
99
|
try {
|
|
99
|
-
|
|
100
|
+
// diff 解析经 run 级快照:同 run 内多条解析类约束共享同一解析
|
|
101
|
+
const items = violations((0, run_env_1.projectSnapshotFor)(env).parseDiff(await env.stagedDiff()));
|
|
100
102
|
return items.length > 0 ? failDetail(items) : true;
|
|
101
103
|
}
|
|
102
104
|
catch (err) {
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
* - 超时:到点杀整个进程组(含 shell 的子孙进程)并判违规
|
|
11
11
|
* - 截断:stdout/stderr 各至多留 MAX_STREAM_CHARS,超出只记「已截断」标记
|
|
12
12
|
*
|
|
13
|
+
* 命令执行策略(D3 P0.5 Phase 1):env.commandPolicy.readOnly = true 时不执行
|
|
14
|
+
* 命令,返回三态 CheckSkip(原因由策略统一措辞);普通模式经策略执行缝执行
|
|
15
|
+
* (缺省真实 spawn 执行,语义如上;无策略 = 默认执行,库调用兼容)。
|
|
16
|
+
*
|
|
13
17
|
* 参数:
|
|
14
18
|
* - command(必填):命令行(经 shell 执行,cwd = 项目根)
|
|
15
19
|
* - timeoutMs(可选):超时毫秒数,缺省 DEFAULT_TIMEOUT_MS,上限 MAX_TIMEOUT_MS
|