@dommaker/harness 4.0.1 → 5.0.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.
Files changed (117) hide show
  1. package/README.md +7 -8
  2. package/dist/bootstrap/bootstrap.d.ts +15 -0
  3. package/dist/bootstrap/bootstrap.js +18 -1
  4. package/dist/bootstrap/index.d.ts +2 -2
  5. package/dist/bootstrap/index.js +3 -2
  6. package/dist/cli/commands/acceptance.d.ts +8 -0
  7. package/dist/cli/commands/acceptance.js +45 -24
  8. package/dist/cli/commands/check.d.ts +2 -0
  9. package/dist/cli/commands/check.js +36 -5
  10. package/dist/cli/commands/command.js +1 -1
  11. package/dist/cli/commands/definitions.js +4 -1
  12. package/dist/cli/commands/release.d.ts +11 -3
  13. package/dist/cli/commands/release.js +159 -52
  14. package/dist/cli/commands/report.d.ts +2 -0
  15. package/dist/cli/commands/report.js +54 -6
  16. package/dist/cli/commands/security.d.ts +3 -3
  17. package/dist/cli/commands/security.js +3 -2
  18. package/dist/cli/commands/sync-docs/capabilities-syncer.d.ts +3 -40
  19. package/dist/cli/commands/sync-docs/capabilities-syncer.js +5 -159
  20. package/dist/cli/commands/sync-docs/compact.js +2 -2
  21. package/dist/cli/commands/sync-docs/context-syncer.d.ts +4 -36
  22. package/dist/cli/commands/sync-docs/context-syncer.js +4 -221
  23. package/dist/cli/commands/sync-docs/index.d.ts +8 -8
  24. package/dist/cli/commands/sync-docs/index.js +8 -8
  25. package/dist/cli/commands/sync-docs/main-flow.d.ts +5 -4
  26. package/dist/cli/commands/sync-docs/main-flow.js +6 -5
  27. package/dist/cli/commands/sync-docs/sync-output.d.ts +1 -1
  28. package/dist/cli/commands/sync-docs/sync-output.js +4 -0
  29. package/dist/cli/commands/sync-docs/sync-writes.d.ts +1 -1
  30. package/dist/cli/commands/validate.d.ts +2 -0
  31. package/dist/cli/commands/validate.js +40 -1
  32. package/dist/core/command-execution-policy.d.ts +59 -0
  33. package/dist/core/command-execution-policy.js +167 -0
  34. package/dist/core/config-files.d.ts +8 -0
  35. package/dist/core/config-files.js +62 -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 +18 -6
  39. package/dist/core/constraints/checker.js +21 -11
  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/definitions.d.ts +2 -2
  51. package/dist/core/constraints/definitions.js +2 -2
  52. package/dist/core/constraints/injection-writer.d.ts +1 -1
  53. package/dist/core/constraints/injection-writer.js +1 -1
  54. package/dist/core/constraints/project-snapshot.d.ts +43 -0
  55. package/dist/core/constraints/project-snapshot.js +103 -0
  56. package/dist/core/constraints/run-env.d.ts +35 -0
  57. package/dist/core/constraints/run-env.js +36 -0
  58. package/dist/{cli/commands/sync-docs → core/docs-sync}/agents-syncer.d.ts +2 -0
  59. package/dist/{cli/commands/sync-docs → core/docs-sync}/agents-syncer.js +5 -3
  60. package/dist/core/docs-sync/capabilities-table.d.ts +46 -0
  61. package/dist/core/docs-sync/capabilities-table.js +200 -0
  62. package/dist/core/docs-sync/context-collector.d.ts +40 -0
  63. package/dist/core/docs-sync/context-collector.js +227 -0
  64. package/dist/{cli/commands/sync-docs → core/docs-sync}/project-reader.d.ts +5 -1
  65. package/dist/{cli/commands/sync-docs → core/docs-sync}/project-reader.js +10 -6
  66. package/dist/{cli/commands/sync-docs → core/docs-sync}/sync-state.d.ts +15 -9
  67. package/dist/{cli/commands/sync-docs → core/docs-sync}/sync-state.js +26 -29
  68. package/dist/core/effective-constraints.d.ts +1 -1
  69. package/dist/core/effective-constraints.js +1 -1
  70. package/dist/core/validators/check-handlers/command.js +22 -0
  71. package/dist/core/validators/check-handlers/output.js +26 -3
  72. package/dist/core/validators/checkpoint.d.ts +4 -0
  73. package/dist/core/validators/checkpoint.js +10 -2
  74. package/dist/gates/acceptance.d.ts +8 -4
  75. package/dist/gates/acceptance.js +76 -14
  76. package/dist/gates/command.d.ts +3 -4
  77. package/dist/gates/command.js +2 -3
  78. package/dist/gates/contract.d.ts +3 -4
  79. package/dist/gates/contract.js +0 -1
  80. package/dist/gates/definitions.d.ts +2 -4
  81. package/dist/gates/definitions.js +2 -8
  82. package/dist/gates/performance.d.ts +10 -4
  83. package/dist/gates/performance.js +49 -5
  84. package/dist/gates/review.d.ts +3 -4
  85. package/dist/gates/review.js +0 -1
  86. package/dist/gates/security.d.ts +3 -4
  87. package/dist/gates/security.js +26 -19
  88. package/dist/gates/types.d.ts +46 -19
  89. package/dist/index.d.ts +5 -4
  90. package/dist/index.js +9 -6
  91. package/dist/knowledge/index.d.ts +1 -1
  92. package/dist/knowledge/index.js +1 -2
  93. package/dist/knowledge/ingest.d.ts +32 -17
  94. package/dist/knowledge/ingest.js +188 -90
  95. package/dist/knowledge/lifecycle.d.ts +15 -0
  96. package/dist/knowledge/lifecycle.js +62 -0
  97. package/dist/knowledge/query.d.ts +11 -1
  98. package/dist/knowledge/query.js +61 -9
  99. package/dist/knowledge/store.d.ts +56 -3
  100. package/dist/knowledge/store.js +108 -30
  101. package/dist/monitoring/index.d.ts +2 -1
  102. package/dist/monitoring/index.js +3 -1
  103. package/dist/monitoring/traces.d.ts +12 -0
  104. package/dist/monitoring/traces.js +26 -4
  105. package/dist/types/checkpoint.d.ts +28 -1
  106. package/dist/types/command-execution-policy.d.ts +73 -0
  107. package/dist/types/command-execution-policy.js +16 -0
  108. package/dist/types/constraint.d.ts +0 -12
  109. package/dist/utils/exec.d.ts +7 -1
  110. package/dist/utils/exec.js +7 -1
  111. package/package.json +1 -1
  112. package/dist/core/constraints/check-cache.d.ts +0 -43
  113. package/dist/core/constraints/check-cache.js +0 -77
  114. package/dist/core/constraints/checkers/templated/glob.d.ts +0 -8
  115. package/dist/core/constraints/checkers/templated/glob.js +0 -14
  116. /package/dist/{cli/commands/sync-docs → core/docs-sync}/preserve-block.d.ts +0 -0
  117. /package/dist/{cli/commands/sync-docs → core/docs-sync}/preserve-block.js +0 -0
package/README.md CHANGED
@@ -29,10 +29,10 @@ npx @dommaker/harness check
29
29
  **作为库使用**:
30
30
 
31
31
  ```typescript
32
- import { checkBeforeExecution, getAllConstraints } from '@dommaker/harness';
32
+ import { checkConstraints, getAllConstraints } from '@dommaker/harness';
33
33
 
34
34
  // Agent 启动前检查
35
- await checkBeforeExecution({
35
+ await checkConstraints({
36
36
  operation: 'code_implementation',
37
37
  taskDescription: '重构用户认证模块',
38
38
  projectPath: '/path/to/project',
@@ -85,8 +85,8 @@ harness validate # 检查点验证(读 .harness/checkpoints.yml,失败
85
85
  harness init # 初始化 .harness/ 目录(不覆盖已有运行时配置)
86
86
  harness status # 项目健康状态、统计、异常检测
87
87
  harness constraints # 约束元数据(版本/hash/计数/文本大小)
88
- harness constraints report # 约束使用报告:统计 + 退役候选诊断 + 配置健康 + 注入漂移(--export 脱敏)
89
- harness constraints retire # 约束退役:交互选择 + 人确认 → config.yml + KnowledgeStore + 注入段同步
88
+ harness constraints report # 约束使用报告:统计 + 退役候选诊断 + 配置健康(--export 脱敏)
89
+ harness constraints retire # 约束退役:交互选择 + 人确认 → config.yml + KnowledgeStore
90
90
  harness constraints retire <id> --yes # 直达退役:显式 --yes 人确认(无 --yes 拒绝执行)
91
91
  harness constraints disable <id> --yes # 裸禁用:config.yml enabled:false 无墓碑无沉淀(区别于 retire)
92
92
  harness report # 生成检查报告
@@ -122,11 +122,10 @@ harness release # npm 发布流水线(tsc → dist 验证 → version
122
122
 
123
123
  ```yaml
124
124
  # .harness/config.yml
125
- preset: standard # strict | standard | relaxed(relaxed 仅启用 5 条 check 约束)
126
- scenes: [] # 场景标签,命中场景专属 prompt 才进入生效集
125
+ preset: standard # strict | standard | relaxed(relaxed 仅启用 2 条核心约束)
127
126
  ```
128
127
 
129
- `preset` 真实影响运行时检查与注入;`constraints.<id>.enabled: false` 可单独禁用。
128
+ `preset` 真实影响运行时检查;`constraints.<id>.enabled: false` 可单独禁用。
130
129
 
131
130
  ---
132
131
 
@@ -134,7 +133,7 @@ scenes: [] # 场景标签,命中场景专属 prompt 才进入生效集
134
133
 
135
134
  | 模块 | 说明 |
136
135
  |------|------|
137
- | 约束引擎 | check/prompt 二元约束 + 生效集合并(`getEffectiveConstraints`)+ 注入渲染/漂移校验 |
136
+ | 约束引擎 | severity/channel 显式约束 + 生效集合并(`getEffectiveConstraints`)+ checker 分发 |
138
137
  | 知识引擎 | 约束退役 → KnowledgeStore 沉淀(规则原文 + 原因 + 历史统计),可检索、可追溯 |
139
138
  | 门禁系统 | 6 种门禁:验收/性能/安全/契约/审查/命令(另有测试门控命令 passes-gate) |
140
139
  | 检查点验证 | 项目在 checkpoints.yml 自声明的通用检查项(13 种 check type),由 `harness validate` 执行;与门禁的分工见 ADR-0036 |
@@ -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
  },
@@ -235,7 +238,7 @@ exports.COMMAND_DEFINITIONS = [
235
238
  children: [
236
239
  {
237
240
  command: 'report',
238
- description: '约束使用报告:check 层统计表、退役候选诊断、prompt 注入清单、配置健康(只读)',
241
+ description: '约束使用报告:check 层统计表、退役候选诊断、配置健康(只读)',
239
242
  options: [
240
243
  { flags: '-p, --project-path <path>', description: '项目路径' },
241
244
  { flags: '--export [file]', description: '导出脱敏 markdown 摘要(缺省 .harness/reports/constraints-<YYYYMMDD>.md)' },
@@ -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 {