@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.
Files changed (102) hide show
  1. package/dist/bootstrap/bootstrap.d.ts +15 -0
  2. package/dist/bootstrap/bootstrap.js +18 -1
  3. package/dist/bootstrap/index.d.ts +2 -2
  4. package/dist/bootstrap/index.js +3 -2
  5. package/dist/cli/commands/acceptance.d.ts +8 -0
  6. package/dist/cli/commands/acceptance.js +45 -24
  7. package/dist/cli/commands/check.d.ts +2 -0
  8. package/dist/cli/commands/check.js +36 -5
  9. package/dist/cli/commands/command.js +1 -1
  10. package/dist/cli/commands/definitions.js +3 -0
  11. package/dist/cli/commands/init/ci-platform.d.ts +3 -5
  12. package/dist/cli/commands/init/ci-platform.js +3 -8
  13. package/dist/cli/commands/init/index.js +78 -11
  14. package/dist/cli/commands/release.d.ts +11 -3
  15. package/dist/cli/commands/release.js +159 -52
  16. package/dist/cli/commands/report.d.ts +2 -0
  17. package/dist/cli/commands/report.js +54 -6
  18. package/dist/cli/commands/security.d.ts +3 -3
  19. package/dist/cli/commands/security.js +3 -2
  20. package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts +3 -40
  21. package/dist/cli/commands/sync-docs/capabilities-syncer.js +5 -159
  22. package/dist/cli/commands/sync-docs/compact.js +2 -2
  23. package/dist/cli/commands/sync-docs/context-syncer.d.ts +4 -36
  24. package/dist/cli/commands/sync-docs/context-syncer.js +4 -221
  25. package/dist/cli/commands/sync-docs/index.d.ts +8 -8
  26. package/dist/cli/commands/sync-docs/index.js +8 -8
  27. package/dist/cli/commands/sync-docs/main-flow.d.ts +5 -4
  28. package/dist/cli/commands/sync-docs/main-flow.js +6 -5
  29. package/dist/cli/commands/sync-docs/sync-output.d.ts +1 -1
  30. package/dist/cli/commands/sync-docs/sync-output.js +4 -0
  31. package/dist/cli/commands/sync-docs/sync-writes.d.ts +1 -1
  32. package/dist/cli/commands/validate.d.ts +2 -0
  33. package/dist/cli/commands/validate.js +40 -1
  34. package/dist/core/command-execution-policy.d.ts +59 -0
  35. package/dist/core/command-execution-policy.js +167 -0
  36. package/dist/core/constraints/capabilities-parser.d.ts +2 -1
  37. package/dist/core/constraints/capabilities-parser.js +2 -1
  38. package/dist/core/constraints/checker.d.ts +17 -5
  39. package/dist/core/constraints/checker.js +20 -10
  40. package/dist/core/constraints/checkers/no-hardcoded-credentials.js +14 -15
  41. package/dist/core/constraints/checkers/no-test-simplification.js +8 -6
  42. package/dist/core/constraints/checkers/templated/exec.d.ts +4 -0
  43. package/dist/core/constraints/checkers/templated/exec.js +11 -48
  44. package/dist/core/constraints/checkers/templated/file-exists.js +7 -4
  45. package/dist/core/constraints/checkers/templated/regex-scan.js +11 -15
  46. package/dist/core/constraints/checkers/types.d.ts +13 -2
  47. package/dist/core/constraints/checkers/types.js +5 -2
  48. package/dist/core/constraints/construction-sites.d.ts +1 -1
  49. package/dist/core/constraints/construction-sites.js +1 -1
  50. package/dist/core/constraints/injection-writer.d.ts +1 -1
  51. package/dist/core/constraints/injection-writer.js +1 -1
  52. package/dist/core/constraints/project-snapshot.d.ts +43 -0
  53. package/dist/core/constraints/project-snapshot.js +103 -0
  54. package/dist/core/constraints/run-env.d.ts +35 -0
  55. package/dist/core/constraints/run-env.js +36 -0
  56. package/dist/{cli/commands/sync-docs → core/docs-sync}/agents-syncer.d.ts +2 -0
  57. package/dist/{cli/commands/sync-docs → core/docs-sync}/agents-syncer.js +5 -3
  58. package/dist/core/docs-sync/capabilities-table.d.ts +46 -0
  59. package/dist/core/docs-sync/capabilities-table.js +200 -0
  60. package/dist/core/docs-sync/context-collector.d.ts +40 -0
  61. package/dist/core/docs-sync/context-collector.js +227 -0
  62. package/dist/{cli/commands/sync-docs → core/docs-sync}/project-reader.d.ts +5 -1
  63. package/dist/{cli/commands/sync-docs → core/docs-sync}/project-reader.js +10 -6
  64. package/dist/{cli/commands/sync-docs → core/docs-sync}/sync-state.d.ts +15 -9
  65. package/dist/{cli/commands/sync-docs → core/docs-sync}/sync-state.js +26 -29
  66. package/dist/core/validators/check-handlers/command.js +22 -0
  67. package/dist/core/validators/check-handlers/output.js +26 -3
  68. package/dist/core/validators/checkpoint.d.ts +4 -0
  69. package/dist/core/validators/checkpoint.js +10 -2
  70. package/dist/gates/acceptance.d.ts +8 -3
  71. package/dist/gates/acceptance.js +76 -13
  72. package/dist/gates/command.d.ts +3 -3
  73. package/dist/gates/command.js +2 -2
  74. package/dist/gates/contract.d.ts +3 -3
  75. package/dist/gates/performance.d.ts +10 -3
  76. package/dist/gates/performance.js +49 -4
  77. package/dist/gates/review.d.ts +3 -3
  78. package/dist/gates/security.d.ts +3 -3
  79. package/dist/gates/security.js +26 -18
  80. package/dist/gates/types.d.ts +45 -16
  81. package/dist/knowledge/ingest.d.ts +31 -0
  82. package/dist/knowledge/ingest.js +192 -52
  83. package/dist/knowledge/lifecycle.d.ts +15 -0
  84. package/dist/knowledge/lifecycle.js +62 -0
  85. package/dist/knowledge/query.d.ts +10 -0
  86. package/dist/knowledge/query.js +60 -8
  87. package/dist/knowledge/store.d.ts +56 -3
  88. package/dist/knowledge/store.js +108 -30
  89. package/dist/types/checkpoint.d.ts +28 -1
  90. package/dist/types/command-execution-policy.d.ts +73 -0
  91. package/dist/types/command-execution-policy.js +16 -0
  92. package/dist/utils/exec.d.ts +7 -1
  93. package/dist/utils/exec.js +7 -1
  94. package/dist/utils/yaml.d.ts +10 -0
  95. package/dist/utils/yaml.js +11 -0
  96. package/package.json +1 -1
  97. package/dist/core/constraints/check-cache.d.ts +0 -43
  98. package/dist/core/constraints/check-cache.js +0 -77
  99. package/dist/core/constraints/checkers/templated/glob.d.ts +0 -8
  100. package/dist/core/constraints/checkers/templated/glob.js +0 -14
  101. /package/dist/{cli/commands/sync-docs → core/docs-sync}/preserve-block.d.ts +0 -0
  102. /package/dist/{cli/commands/sync-docs → core/docs-sync}/preserve-block.js +0 -0
@@ -21,10 +21,14 @@
21
21
  * ADR-0040 Phase 3:目录正名 `hooks/` → `bootstrap/`(职责是组合根,目录名不再沿用
22
22
  * 历史);`loadConfigAsync` 假 async(async 壳包纯同步调用)改同步 `loadConfig`,
23
23
  * 两个入口的逐字重复装配并为一枚 `assembleHarness`。
24
+ *
25
+ * P1.1:checker 的 trace 接线收进唯一装配函数 `assembleConstraintChecker`——
26
+ * CLI check/report 与 bootstrapHarness 共用,接线只写一次。
24
27
  */
25
28
  import { ConstraintChecker } from '../core/constraints/checker';
26
29
  import { SessionManager } from '../context/session-manager';
27
30
  import type { MergedConstraintsConfig } from '../types/project-config';
31
+ import type { CommandExecutionPolicy } from '../types/command-execution-policy';
28
32
  /**
29
33
  * Bootstrap 结果
30
34
  *
@@ -42,6 +46,17 @@ export interface HarnessBootstrap {
42
46
  /** 合并后的约束配置 */
43
47
  mergedConstraints: MergedConstraintsConfig;
44
48
  }
49
+ /**
50
+ * 生产侧唯一 checker 装配点(P1.1):trace 记录器锚根接线只写一次
51
+ *
52
+ * harness#88:core 不上行依赖 monitoring,故接线住组合根本层;
53
+ * #139:落点跟根走,不落调用方 cwd。CLI check/report 与 bootstrapHarness
54
+ * 全部经本函数取接线好的 checker——源形状闸见 src/__tests__/unique-assembly.test.ts。
55
+ *
56
+ * commandPolicy(D3 P0.5 Phase 1):一次运行的统一命令执行策略,透传 checker
57
+ * (read-only 下 exec 模板 checker 三态跳过项目声明命令);缺省 = 默认执行。
58
+ */
59
+ export declare function assembleConstraintChecker(projectPath: string, commandPolicy?: CommandExecutionPolicy): ConstraintChecker;
45
60
  /**
46
61
  * 初始化 harness 运行环境(异步面:配置读取是同步 fs,async 仅为公共签名兼容)
47
62
  *
@@ -22,8 +22,12 @@
22
22
  * ADR-0040 Phase 3:目录正名 `hooks/` → `bootstrap/`(职责是组合根,目录名不再沿用
23
23
  * 历史);`loadConfigAsync` 假 async(async 壳包纯同步调用)改同步 `loadConfig`,
24
24
  * 两个入口的逐字重复装配并为一枚 `assembleHarness`。
25
+ *
26
+ * P1.1:checker 的 trace 接线收进唯一装配函数 `assembleConstraintChecker`——
27
+ * CLI check/report 与 bootstrapHarness 共用,接线只写一次。
25
28
  */
26
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.assembleConstraintChecker = assembleConstraintChecker;
27
31
  exports.bootstrapHarness = bootstrapHarness;
28
32
  exports.bootstrapHarnessSync = bootstrapHarnessSync;
29
33
  const checker_1 = require("../core/constraints/checker");
@@ -44,13 +48,26 @@ function loadConfig(projectPath) {
44
48
  mergedConstraints: loader.mergeConstraints(),
45
49
  };
46
50
  }
51
+ /**
52
+ * 生产侧唯一 checker 装配点(P1.1):trace 记录器锚根接线只写一次
53
+ *
54
+ * harness#88:core 不上行依赖 monitoring,故接线住组合根本层;
55
+ * #139:落点跟根走,不落调用方 cwd。CLI check/report 与 bootstrapHarness
56
+ * 全部经本函数取接线好的 checker——源形状闸见 src/__tests__/unique-assembly.test.ts。
57
+ *
58
+ * commandPolicy(D3 P0.5 Phase 1):一次运行的统一命令执行策略,透传 checker
59
+ * (read-only 下 exec 模板 checker 三态跳过项目声明命令);缺省 = 默认执行。
60
+ */
61
+ function assembleConstraintChecker(projectPath, commandPolicy) {
62
+ return new checker_1.ConstraintChecker(new traces_1.TraceCollector({ projectPath }), commandPolicy);
63
+ }
47
64
  /**
48
65
  * 装配 harness 运行环境(两个入口共用的一段):
49
66
  * trace 记录器锚根构造(#139):入口本就收 projectPath,落点必须跟着根走
50
67
  */
51
68
  function assembleHarness(resolvedPath, mergedConstraints) {
52
69
  return {
53
- checker: new checker_1.ConstraintChecker(new traces_1.TraceCollector({ projectPath: resolvedPath })),
70
+ checker: assembleConstraintChecker(resolvedPath),
54
71
  sessions: new session_manager_1.SessionManager(resolvedPath),
55
72
  projectPath: resolvedPath,
56
73
  mergedConstraints,
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * ADR-0027(#170)起本层只剩 `bootstrap.ts` 一个面:通用 hook 管线
5
5
  * (registry / pipeline / config / types 四文件)双仓零生产消费者,整体删除。
6
- * 目录原名 hooks/ 沿用历史,ADR-0040 Phase 3 正名 bootstrap/——职责是
6
+ * 目录原名 hooks/ 沿用历史,ADR-0041 Phase 3 正名 bootstrap/——职责是
7
7
  * harness 运行环境的组合根。
8
8
  */
9
- export { bootstrapHarness, bootstrapHarnessSync } from './bootstrap';
9
+ export { bootstrapHarness, bootstrapHarnessSync, assembleConstraintChecker } from './bootstrap';
10
10
  export type { HarnessBootstrap } from './bootstrap';
@@ -4,11 +4,12 @@
4
4
  *
5
5
  * ADR-0027(#170)起本层只剩 `bootstrap.ts` 一个面:通用 hook 管线
6
6
  * (registry / pipeline / config / types 四文件)双仓零生产消费者,整体删除。
7
- * 目录原名 hooks/ 沿用历史,ADR-0040 Phase 3 正名 bootstrap/——职责是
7
+ * 目录原名 hooks/ 沿用历史,ADR-0041 Phase 3 正名 bootstrap/——职责是
8
8
  * harness 运行环境的组合根。
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.bootstrapHarnessSync = exports.bootstrapHarness = void 0;
11
+ exports.assembleConstraintChecker = exports.bootstrapHarnessSync = exports.bootstrapHarness = void 0;
12
12
  var bootstrap_1 = require("./bootstrap");
13
13
  Object.defineProperty(exports, "bootstrapHarness", { enumerable: true, get: function () { return bootstrap_1.bootstrapHarness; } });
14
14
  Object.defineProperty(exports, "bootstrapHarnessSync", { enumerable: true, get: function () { return bootstrap_1.bootstrapHarnessSync; } });
15
+ Object.defineProperty(exports, "assembleConstraintChecker", { enumerable: true, get: function () { return bootstrap_1.assembleConstraintChecker; } });
@@ -2,6 +2,10 @@
2
2
  * harness acceptance 命令
3
3
  *
4
4
  * 验收标准门控,检查任务是否满足验收标准
5
+ *
6
+ * D5:list 子命令与 SpecAcceptanceGate 共同消费 gates/tasks-file 的
7
+ * parseTasksFile——tasks.yml 的 YAML 解析、形状校验与错误语义只有一份正本。
8
+ * 解析失败 fail-fast(kind:fail,bin 退出 1),不存在静默 skip/空列表。
5
9
  */
6
10
  import { type CommandIO, type CommandResult } from '../command-contract';
7
11
  export interface AcceptanceOptions {
@@ -22,5 +26,9 @@ export interface AcceptanceOptions {
22
26
  export declare function acceptance(options: AcceptanceOptions, io?: CommandIO): Promise<CommandResult>;
23
27
  /**
24
28
  * 列出所有任务及其验收标准
29
+ *
30
+ * 与门禁同一解析契约:读取失败里只有 ENOENT 走「无 tasks.yml 即跳过」(与门禁
31
+ * passed:true 的跳过语义一致,kind:skip → 退出 0);其余读取失败与一切解析/
32
+ * 形状错误一律 fail-fast(kind:fail → 退出 1),不静默 skip、不返回空列表。
25
33
  */
26
34
  export declare function listAcceptanceCriteria(options: AcceptanceOptions, io?: CommandIO): Promise<CommandResult>;
@@ -3,6 +3,10 @@
3
3
  * harness acceptance 命令
4
4
  *
5
5
  * 验收标准门控,检查任务是否满足验收标准
6
+ *
7
+ * D5:list 子命令与 SpecAcceptanceGate 共同消费 gates/tasks-file 的
8
+ * parseTasksFile——tasks.yml 的 YAML 解析、形状校验与错误语义只有一份正本。
9
+ * 解析失败 fail-fast(kind:fail,bin 退出 1),不存在静默 skip/空列表。
6
10
  */
7
11
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
12
  if (k2 === undefined) k2 = k;
@@ -48,6 +52,8 @@ const fs = __importStar(require("fs/promises"));
48
52
  const path = __importStar(require("path"));
49
53
  const yaml = __importStar(require("../../utils/yaml"));
50
54
  const acceptance_1 = require("../../gates/acceptance");
55
+ const tasks_file_1 = require("../../gates/tasks-file");
56
+ const guards_1 = require("../../utils/guards");
51
57
  const error_1 = require("../../utils/error");
52
58
  const command_contract_1 = require("../command-contract");
53
59
  const gate_command_1 = require("../gate-command");
@@ -88,38 +94,53 @@ async function acceptance(options, io = command_contract_1.processIO) {
88
94
  }
89
95
  /**
90
96
  * 列出所有任务及其验收标准
97
+ *
98
+ * 与门禁同一解析契约:读取失败里只有 ENOENT 走「无 tasks.yml 即跳过」(与门禁
99
+ * passed:true 的跳过语义一致,kind:skip → 退出 0);其余读取失败与一切解析/
100
+ * 形状错误一律 fail-fast(kind:fail → 退出 1),不静默 skip、不返回空列表。
91
101
  */
92
102
  async function listAcceptanceCriteria(options, io = command_contract_1.processIO) {
93
103
  (0, command_contract_1.log)(io, chalk_1.default.blue('📋 任务验收标准列表...\n'));
94
104
  const projectPath = options.projectPath || process.cwd();
95
- const tasksPath = options.tasksPath || path.join(projectPath, 'tasks.yml');
105
+ // 与 SpecAcceptanceGate.check() 同一锚定规则:相对值一律锚 projectPath
106
+ const tasksPath = path.resolve(projectPath, options.tasksPath ?? 'tasks.yml');
107
+ let content;
96
108
  try {
97
- const content = await fs.readFile(tasksPath, 'utf-8');
98
- const tasks = yaml.load(content);
99
- if (typeof tasks !== 'object' || tasks === null) {
100
- (0, command_contract_1.log)(io, chalk_1.default.yellow('⚠️ 未找到任务定义'));
101
- return { kind: 'skip', reason: `未找到任务定义: ${tasksPath}` };
102
- }
103
- for (const [taskId, task] of Object.entries(tasks)) {
104
- if (typeof task === 'object' && task !== null) {
105
- (0, command_contract_1.log)(io, chalk_1.default.cyan(`${taskId}:`));
106
- const criteria = task.acceptanceCriteria;
107
- if (Array.isArray(criteria)) {
108
- criteria.forEach((c, i) => {
109
- (0, command_contract_1.log)(io, chalk_1.default.gray(` ${i + 1}. ${String(c)}`));
110
- });
111
- }
112
- else {
113
- (0, command_contract_1.log)(io, chalk_1.default.gray(' (无验收标准)'));
114
- }
115
- (0, command_contract_1.log)(io);
116
- }
117
- }
118
- return { kind: 'ok' };
109
+ content = await fs.readFile(tasksPath, 'utf-8');
119
110
  }
120
111
  catch (error) {
121
112
  const message = (0, error_1.errorMessage)(error);
113
+ if ((0, guards_1.isRecord)(error) && error.code === 'ENOENT') {
114
+ (0, command_contract_1.log)(io, chalk_1.default.yellow(`⚠️ 未找到 tasks.yml: ${tasksPath}`));
115
+ return { kind: 'skip', reason: `未找到 tasks.yml: ${tasksPath}` };
116
+ }
122
117
  (0, command_contract_1.log)(io, chalk_1.default.red(`❌ 读取 tasks.yml 失败: ${message}`));
123
- return { kind: 'skip', reason: `读取 tasks.yml 失败: ${message}` };
118
+ return { kind: 'fail', reason: `读取 tasks.yml 失败: ${message}` };
119
+ }
120
+ // 单一解析正本:非法 YAML/形状/任务/验收条件在此抛错(fail-fast → fail,不静默 skip)
121
+ let tasks;
122
+ try {
123
+ tasks = (0, tasks_file_1.parseTasksFile)(yaml.load(content), tasksPath);
124
+ }
125
+ catch (error) {
126
+ const message = (0, error_1.errorMessage)(error);
127
+ (0, command_contract_1.log)(io, chalk_1.default.red(`❌ tasks.yml 解析失败: ${message}`));
128
+ return { kind: 'fail', reason: `tasks.yml 解析失败: ${message}` };
129
+ }
130
+ for (const task of tasks.tasks) {
131
+ (0, command_contract_1.log)(io, chalk_1.default.cyan(`${task.id}:`));
132
+ if (task.acceptance && task.acceptance.length > 0) {
133
+ task.acceptance.forEach((c, i) => {
134
+ const e2e = c.e2e_test
135
+ ? ` (e2e: ${c.e2e_test}${c.test_name ? `, -g ${c.test_name}` : ''})`
136
+ : '';
137
+ (0, command_contract_1.log)(io, chalk_1.default.gray(` ${i + 1}. ${c.checked ? '[✓]' : '[ ]'} ${c.description}${e2e}`));
138
+ });
139
+ }
140
+ else {
141
+ (0, command_contract_1.log)(io, chalk_1.default.gray(' (无验收标准)'));
142
+ }
143
+ (0, command_contract_1.log)(io);
124
144
  }
145
+ return { kind: 'ok' };
125
146
  }
@@ -42,6 +42,8 @@ export interface CheckOptions {
42
42
  * 走替身,测试据此不碰真文件系统。
43
43
  */
44
44
  stateIO?: StateIO;
45
+ /** 只读模式(CLI --read-only;D3 P0.5 Phase 1):跳过项目 YAML 声明的命令执行 */
46
+ readOnly?: boolean;
45
47
  }
46
48
  /**
47
49
  * 执行约束检查
@@ -49,13 +49,13 @@ exports.check = check;
49
49
  exports.listLaws = listLaws;
50
50
  const chalk_1 = __importDefault(require("chalk"));
51
51
  const path = __importStar(require("path"));
52
- const checker_1 = require("../../core/constraints/checker");
52
+ const bootstrap_1 = require("../../bootstrap");
53
53
  const definitions_1 = require("../../core/constraints/definitions");
54
54
  const effective_constraints_1 = require("../../core/effective-constraints");
55
+ const command_execution_policy_1 = require("../../core/command-execution-policy");
55
56
  const context_builder_1 = require("../../core/constraints/context-builder");
56
57
  const git_evidence_1 = require("../../core/constraints/git-evidence");
57
58
  const run_env_1 = require("../../core/constraints/run-env");
58
- const traces_1 = require("../../monitoring/traces");
59
59
  const jsonl_1 = require("../../utils/jsonl");
60
60
  const trace_1 = require("../../types/trace");
61
61
  const constraint_1 = require("../../types/constraint");
@@ -107,6 +107,8 @@ async function check(options, io = command_contract_1.processIO) {
107
107
  // 构建上下文(工单 23:触发条件与证据检测收敛至 core/constraints/context-builder)
108
108
  // #87:一次 run 一份 git 证据——context-builder 与 checker 层共用同一实例
109
109
  // ADR-0023:一次 run 一份运行级观察面——配置、源根探测全部共用同一份读取
110
+ // 必须先于运行前清单构造:清单按 context 的 operation/extraTriggers 过滤
111
+ // (与 checker 分发同口径,trigger 不匹配的约束不进清单)
110
112
  const context = (0, context_builder_1.buildConstraintContext)({
111
113
  projectPath: options.projectPath,
112
114
  staged: options.staged,
@@ -114,15 +116,30 @@ async function check(options, io = command_contract_1.processIO) {
114
116
  evidence,
115
117
  runEnv,
116
118
  });
119
+ // 运行前清单(D3 P0.5 Phase 1):列出本次将执行的项目声明命令;--read-only 下列出被跳过的。
120
+ // 授权只来自 CLI flag——仓内 YAML 只声明命令,不作为授权来源。
121
+ const commandPlan = (0, command_execution_policy_1.planCommandsFromConstraints)(merged.constraints, context);
122
+ if (commandPlan.length > 0) {
123
+ if (options.readOnly) {
124
+ (0, command_contract_1.log)(io, chalk_1.default.gray(`⏭️ --read-only:跳过 ${commandPlan.length} 条项目声明命令(未执行):`));
125
+ }
126
+ else {
127
+ (0, command_contract_1.log)(io, chalk_1.default.yellow(`⚠️ 本次将执行 ${commandPlan.length} 条项目声明命令:`));
128
+ }
129
+ (0, command_execution_policy_1.formatCommandPlan)(commandPlan).forEach(line => (0, command_contract_1.log)(io, chalk_1.default.gray(line)));
130
+ }
117
131
  const changedFiles = context.changedFiles ?? [];
118
132
  if (changedFiles.length > 0) {
119
133
  (0, command_contract_1.log)(io, chalk_1.default.gray(`变更文件: ${changedFiles.length} 个`));
120
134
  }
121
135
  (0, command_contract_1.log)(io, chalk_1.default.gray(`触发条件: ${[context.operation, ...(context.extraTriggers ?? [])].join(', ')}`));
122
136
  // 执行约束检查(per-request 传 customConfig,避免单例状态污染;证据同 run 同源)
123
- // trace 记录器经构造参数接线(harness#88):一次命令一个 checker 实例
124
- // #139:收集器锚根构造——不传 projectPath 时 trace 会落进调用方 cwd,B 侧读不到
125
- const checker = new checker_1.ConstraintChecker(new traces_1.TraceCollector({ projectPath }));
137
+ // checker 经唯一装配函数取(P1.1):trace 接线只写一次,收集器锚根构造
138
+ // (#139:不传 projectPath 时 trace 会落进调用方 cwd,B 侧读不到)
139
+ // commandPolicy(D3):本 run 的统一执行策略,read-only 下 exec 模板 checker
140
+ // 三态跳过声明命令;缺省 = 默认执行
141
+ const policy = (0, command_execution_policy_1.createCommandExecutionPolicy)({ readOnly: options.readOnly });
142
+ const checker = (0, bootstrap_1.assembleConstraintChecker)(projectPath, policy);
126
143
  const result = await checker.checkConstraints(context, merged, evidence, runEnv);
127
144
  // 输出结果
128
145
  (0, command_contract_1.log)(io);
@@ -182,6 +199,20 @@ async function check(options, io = command_contract_1.processIO) {
182
199
  (0, command_contract_1.log)(io, chalk_1.default.gray(` - ${r.id}${r.skipReason ? `:${r.skipReason}` : ''}`));
183
200
  });
184
201
  }
202
+ // read-only 且本 run 有声明命令被策略跳过:不产出「已检查」结论(假绿防线)。
203
+ // 只认策略跳过(清单来源 ∩ 跳过结果)——其他原因(证据未接线等)的跳过维持原 ok 语义。
204
+ if (options.readOnly) {
205
+ const planSources = new Set(commandPlan.map(p => p.source));
206
+ const policySkipped = skippedResults.filter(r => planSources.has(r.id));
207
+ if (policySkipped.length > 0) {
208
+ (0, command_contract_1.log)(io);
209
+ (0, command_contract_1.log)(io, chalk_1.default.gray(`⏭️ read-only:${policySkipped.length} 条约束未评估(命令未执行),不产出「已检查」结论`));
210
+ return {
211
+ kind: 'skip',
212
+ reason: `--read-only: ${policySkipped.length} constraints not evaluated (commands not executed)`,
213
+ };
214
+ }
215
+ }
185
216
  (0, command_contract_1.log)(io);
186
217
  (0, command_contract_1.log)(io, chalk_1.default.green('✅ 约束检查通过'));
187
218
  // 智能提示
@@ -58,7 +58,7 @@ async function executeCommand(cmd, options, io = command_contract_1.processIO) {
58
58
  return { kind: 'usage-error', reason: '缺少要检查的命令参数' };
59
59
  }
60
60
  const gate = (0, command_1.createCommandGate)();
61
- // 命令门禁只判命令串、不读项目根;GateContext 仍要求项目根——本命令无 -p 旗帜,取真实 cwd
61
+ // 命令门禁只判命令串、不读项目根;CommandGateContext 仍要求项目根——本命令无 -p 旗帜,取真实 cwd
62
62
  const decision = await gate.evaluate({ projectPath: process.cwd(), command: cmd });
63
63
  const result = decision.result;
64
64
  if (options.level) {
@@ -32,6 +32,7 @@ exports.COMMAND_DEFINITIONS = [
32
32
  { flags: '-s, --staged', description: '只检查暂存文件', defaultValue: false },
33
33
  { flags: '-t, --trigger <trigger>', description: '触发条件' },
34
34
  { flags: '--project-path <path>', description: '项目路径' },
35
+ { flags: '--read-only', description: '跳过项目 YAML 声明的命令执行(未评估条目明确列出,不产生「已检查」结论;D3)', defaultValue: false },
35
36
  { flags: '--list', description: '列出所有约束' },
36
37
  ],
37
38
  action: { module: 'check', export: 'check' },
@@ -45,6 +46,7 @@ exports.COMMAND_DEFINITIONS = [
45
46
  options: [
46
47
  { flags: '-f, --file <path>', description: '检查点文件路径' },
47
48
  { flags: '-p, --project-path <path>', description: '项目路径' },
49
+ { flags: '--read-only', description: '跳过检查点声明的命令执行(未评估条目明确列出,不把跳过当验证通过;D3)', defaultValue: false },
48
50
  ],
49
51
  action: { module: 'validate', export: 'validate' },
50
52
  },
@@ -86,6 +88,7 @@ exports.COMMAND_DEFINITIONS = [
86
88
  { flags: '-o, --output <path>', description: '输出文件路径' },
87
89
  { flags: '-f, --format <format>', description: '输出格式 (json/markdown)', defaultValue: 'markdown' },
88
90
  { flags: '-p, --project-path <path>', description: '项目路径' },
91
+ { flags: '--read-only', description: '跳过项目 YAML 声明的命令执行(报告明确标记 skipped/未执行;D3)', defaultValue: false },
89
92
  ],
90
93
  action: { module: 'report', export: 'report' },
91
94
  },
@@ -25,10 +25,8 @@ export declare function resolveCiPlatform(options: {
25
25
  githubActions?: boolean;
26
26
  }, configured: CiPlatform | 'none' | undefined): CiResolution;
27
27
  /**
28
- * 读 config.yml 已持久化的 `ci.platform`(解析链第二级)
28
+ * 从本次 init 已读取的旧 config.yml 取 `ci.platform`(解析链第二级)
29
29
  *
30
- * 缺失 / 形状不符一律按未配置处理;config.yml 解析失败经 attempt 显式降级为未配置——
31
- * init 是用户首次上手入口,存量脏配置不该炸掉初始化(解析失败会真实抛到用户眼前的
32
- * 场景是 check/sync-docs 等执法面,那里不兜)。
30
+ * 缺失 / 形状不符一律按未配置处理;文件只由命令入口读取一次。
33
31
  */
34
- export declare function readConfiguredCiPlatform(projectPath: string): CiPlatform | 'none' | undefined;
32
+ export declare function readConfiguredCiPlatform(raw: Record<string, unknown> | undefined): CiPlatform | 'none' | undefined;
@@ -7,8 +7,6 @@
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.resolveCiPlatform = resolveCiPlatform;
9
9
  exports.readConfiguredCiPlatform = readConfiguredCiPlatform;
10
- const attempt_1 = require("../../../utils/attempt");
11
- const project_config_loader_1 = require("../../../core/project-config-loader");
12
10
  /** `--ci` 的可取值域(`none` = 不创建任何服务端 CI 文件,治理 CI 面亦不建,即旧 `--no-github-actions`) */
13
11
  const CI_FLAG_VALUES = ['github', 'gitlab', 'none'];
14
12
  /**
@@ -42,14 +40,11 @@ function resolveCiPlatform(options, configured) {
42
40
  return { kind: 'ok', platform: flag ?? configured ?? 'github' };
43
41
  }
44
42
  /**
45
- * 读 config.yml 已持久化的 `ci.platform`(解析链第二级)
43
+ * 从本次 init 已读取的旧 config.yml 取 `ci.platform`(解析链第二级)
46
44
  *
47
- * 缺失 / 形状不符一律按未配置处理;config.yml 解析失败经 attempt 显式降级为未配置——
48
- * init 是用户首次上手入口,存量脏配置不该炸掉初始化(解析失败会真实抛到用户眼前的
49
- * 场景是 check/sync-docs 等执法面,那里不兜)。
45
+ * 缺失 / 形状不符一律按未配置处理;文件只由命令入口读取一次。
50
46
  */
51
- function readConfiguredCiPlatform(projectPath) {
52
- const raw = (0, attempt_1.attempt)(() => (0, project_config_loader_1.loadRawProjectConfig)(projectPath), () => undefined);
47
+ function readConfiguredCiPlatform(raw) {
53
48
  const ci = raw?.ci;
54
49
  if (ci === null || typeof ci !== 'object')
55
50
  return undefined;
@@ -68,8 +68,27 @@ const governance_1 = require("./governance");
68
68
  */
69
69
  async function init(options, io = command_contract_1.processIO) {
70
70
  const projectPath = options.projectPath || process.cwd();
71
+ const configPath = path.join(projectPath, '.harness', 'config.yml');
72
+ let existingDocument;
73
+ let existingConfig = {};
74
+ let existingConfigError;
75
+ try {
76
+ const document = yaml.loadDocument(await fs.readFile(configPath, 'utf-8'));
77
+ if (document.errors.length > 0)
78
+ throw document.errors[0];
79
+ const value = document.toJS();
80
+ if (document.contents !== null && (value === null || typeof value !== 'object' || Array.isArray(value))) {
81
+ throw new TypeError('旧 config.yml 根节点必须是 YAML map');
82
+ }
83
+ existingDocument = document;
84
+ existingConfig = (value ?? {});
85
+ }
86
+ catch (error) {
87
+ if (error.code !== 'ENOENT')
88
+ existingConfigError = error;
89
+ }
71
90
  // CI 平台先解析:用法错误不落任何盘,且 `--print-snippets` 也要按解析出的平台出形
72
- const ci = (0, ci_platform_1.resolveCiPlatform)(options, (0, ci_platform_1.readConfiguredCiPlatform)(projectPath));
91
+ const ci = (0, ci_platform_1.resolveCiPlatform)(options, (0, ci_platform_1.readConfiguredCiPlatform)(existingConfig));
73
92
  if (ci.kind === 'error') {
74
93
  (0, command_contract_1.logError)(io, chalk_1.default.red(`❌ 用法错误: ${ci.reason}`));
75
94
  return { kind: 'usage-error', reason: ci.reason };
@@ -91,6 +110,13 @@ async function init(options, io = command_contract_1.processIO) {
91
110
  (0, snippets_1.printSnippets)(io, ci.platform, options.governance);
92
111
  return { kind: 'ok' };
93
112
  }
113
+ // 共享所有权文件读不懂时禁止覆盖;--print-snippets 不落盘,仍可沿用 CI 缺省探测
114
+ if (existingConfigError) {
115
+ const detail = existingConfigError instanceof Error ? existingConfigError.message : String(existingConfigError);
116
+ const reason = `无法读取旧配置 ${configPath}: ${detail}`;
117
+ (0, command_contract_1.logError)(io, chalk_1.default.red(`❌ ${reason}`));
118
+ return { kind: 'fail', reason };
119
+ }
94
120
  (0, command_contract_1.log)(io, chalk_1.default.blue('🚀 初始化 harness 配置...'));
95
121
  const configDir = path.join(projectPath, '.harness');
96
122
  // 创建配置目录
@@ -99,26 +125,67 @@ async function init(options, io = command_contract_1.processIO) {
99
125
  // 选择预设
100
126
  const preset = presets_1.PRESETS[options.preset];
101
127
  (0, command_contract_1.log)(io, chalk_1.default.gray(`预设: ${options.preset}`));
102
- // 合并治理配置
103
- const configData = { ...preset };
128
+ // config.yml 是共享所有权文件:只覆盖本次受管键,消费方扩展原样保留并列名告知
129
+ const ciManaged = options.ci !== undefined || options.githubActions === false;
130
+ const managedKeys = new Set([...Object.keys(preset), 'harness']);
131
+ if (options.governance)
132
+ managedKeys.add('governance');
133
+ if (ciManaged)
134
+ managedKeys.add('ci');
135
+ const preservedKeys = Object.keys(existingConfig).filter(key => !managedKeys.has(key));
136
+ const configData = { ...existingConfig, ...preset };
104
137
  if (options.governance) {
105
138
  configData.governance = presets_1.GOVERNANCE_PRESETS[options.governance];
106
139
  (0, command_contract_1.log)(io, chalk_1.default.gray(`治理级别: ${options.governance}`));
107
140
  }
108
- // 非默认平台才持久化:缺省即 github(旧配置零迁移),裸 init 重写 config.yml 时
109
- // 也因此不会丢掉已选定的平台
141
+ // 非默认平台才持久化;只有显式 CI flag 才接管 ci 段,裸 init 保留消费方扩展
110
142
  if (ci.platform !== 'github') {
111
- configData.ci = { platform: ci.platform };
112
143
  (0, command_contract_1.log)(io, chalk_1.default.gray(`CI 平台: ${ci.platform}`));
113
144
  }
114
- // 写入 harness 版本
145
+ if (ciManaged) {
146
+ if (ci.platform === 'github')
147
+ delete configData.ci;
148
+ else
149
+ configData.ci = { platform: ci.platform };
150
+ }
151
+ // 写入 harness 版本,保留 harness 段内的非受管扩展
115
152
  const pkgVersion = (0, package_version_1.getHarnessPackageVersion)();
116
- configData.harness = { version: pkgVersion };
117
- // 写入配置文件(harness 管理的配置,始终重新生成)
118
- const configPath = path.join(configDir, 'config.yml');
119
- const configContent = yaml.dump(configData, { indent: 2 });
153
+ const existingHarness = existingConfig.harness;
154
+ const harnessConfig = existingHarness !== null && typeof existingHarness === 'object' && !Array.isArray(existingHarness)
155
+ ? existingHarness
156
+ : {};
157
+ configData.harness = { ...harnessConfig, version: pkgVersion };
158
+ if (Object.keys(harnessConfig).some(key => key !== 'version'))
159
+ preservedKeys.push('harness');
160
+ // 旧配置经 Document 原地更新受管键,非受管键与注释(含 AUTO-GENERATED 标记)不失真
161
+ let configContent;
162
+ if (existingDocument) {
163
+ for (const key of Object.keys(preset))
164
+ existingDocument.set(key, configData[key]);
165
+ if (options.governance)
166
+ existingDocument.set('governance', configData.governance);
167
+ if (ciManaged) {
168
+ if (ci.platform === 'github')
169
+ existingDocument.delete('ci');
170
+ else
171
+ existingDocument.set('ci', configData.ci);
172
+ }
173
+ if (existingHarness !== null && typeof existingHarness === 'object' && !Array.isArray(existingHarness)) {
174
+ existingDocument.setIn(['harness', 'version'], pkgVersion);
175
+ }
176
+ else {
177
+ existingDocument.set('harness', configData.harness);
178
+ }
179
+ configContent = yaml.dumpDocument(existingDocument, { indent: 2 });
180
+ }
181
+ else {
182
+ configContent = yaml.dump(configData, { indent: 2 });
183
+ }
120
184
  await fs.writeFile(configPath, configContent, 'utf-8');
121
185
  (0, command_contract_1.log)(io, chalk_1.default.green(`✅ 已创建配置文件: ${configPath} (v${pkgVersion})`));
186
+ if (preservedKeys.length > 0) {
187
+ (0, command_contract_1.log)(io, chalk_1.default.gray(`保留 ${preservedKeys.length} 个非受管键:${preservedKeys.join('、')}`));
188
+ }
122
189
  // 受管示例文件:检查点 / Resolutions(RKB 狗粮)
123
190
  await (0, scaffold_1.runPlan)([(0, scaffold_1.checkpointsFile)(projectPath), (0, scaffold_1.resolutionsFile)(projectPath)], io);
124
191
  // CAPABILITIES.md / CHANGELOG.md 由 sync-docs(AI 治理)管理,init 不创建
@@ -8,17 +8,25 @@
8
8
  * 流程:
9
9
  * 1. Verify package
10
10
  * 2. Check branch (must be master/main) + remote sync + clean tree
11
- * 3. tsc build
11
+ * 3. tsc build(项目本地确定的 TypeScript 可执行文件;缺失即失败,不做隐式下载)
12
12
  * 4. Verify dist files
13
13
  * 5. Bump version (npm version → commit + tag)
14
14
  * 6. Push (protected branch → create release PR instead)
15
15
  * 7. Check private flag
16
16
  * 8. npm publish (or skip if PR flow)
17
- * 9. GitHub Release
17
+ * 9. GitHub Release(非致命告警,既有终态保留)
18
18
  *
19
- * 判定经返回值外溢(架构评审候选7):12 个前置闸门维持**首败即停**,每个闸门失败
19
+ * 判定经返回值外溢(架构评审候选7):前置闸门维持**首败即停**,每个闸门失败
20
20
  * 返回 `gate <id>: <原因>`;退出码映射在 bin/harness.js 唯一一处。输出经注入 io
21
21
  * 流式打印(分钟级子进程阶段不能静默)。
22
+ * 步骤判负统一按子进程退出码(D2):私有 run helper 返回 { code, stdout, stderr },
23
+ * code !== 0 即失败(ENOENT/超时等无数字退出码取非零缺省),不再以 stderr 文本内容
24
+ * 猜测成败——发布链全部会改变状态/取证的命令(git 证据命令、npm version/publish、
25
+ * 各次 git push、PR 流程 checkout)无一例外;仅 GitHub Release 保持既有非致命告警
26
+ * 终态、成功后 remote URL 查询保持装饰性降级。GH006 保护分支识别仍在非零 push 后
27
+ * 查看 stderr。
28
+ * 子进程一律 argv 形状(utils/exec 的 execFileAsync),不拼 shell 字符串;
29
+ * npm publish 自带 --registry,publish 前后不读写用户 npm 配置(P0.3)。
22
30
  */
23
31
  import { type CommandIO, type CommandResult } from '../command-contract';
24
32
  export interface ReleaseOptions {