@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
@@ -9,41 +9,86 @@
9
9
  * 流程:
10
10
  * 1. Verify package
11
11
  * 2. Check branch (must be master/main) + remote sync + clean tree
12
- * 3. tsc build
12
+ * 3. tsc build(项目本地确定的 TypeScript 可执行文件;缺失即失败,不做隐式下载)
13
13
  * 4. Verify dist files
14
14
  * 5. Bump version (npm version → commit + tag)
15
15
  * 6. Push (protected branch → create release PR instead)
16
16
  * 7. Check private flag
17
17
  * 8. npm publish (or skip if PR flow)
18
- * 9. GitHub Release
18
+ * 9. GitHub Release(非致命告警,既有终态保留)
19
19
  *
20
- * 判定经返回值外溢(架构评审候选7):12 个前置闸门维持**首败即停**,每个闸门失败
20
+ * 判定经返回值外溢(架构评审候选7):前置闸门维持**首败即停**,每个闸门失败
21
21
  * 返回 `gate <id>: <原因>`;退出码映射在 bin/harness.js 唯一一处。输出经注入 io
22
22
  * 流式打印(分钟级子进程阶段不能静默)。
23
+ * 步骤判负统一按子进程退出码(D2):私有 run helper 返回 { code, stdout, stderr },
24
+ * code !== 0 即失败(ENOENT/超时等无数字退出码取非零缺省),不再以 stderr 文本内容
25
+ * 猜测成败——发布链全部会改变状态/取证的命令(git 证据命令、npm version/publish、
26
+ * 各次 git push、PR 流程 checkout)无一例外;仅 GitHub Release 保持既有非致命告警
27
+ * 终态、成功后 remote URL 查询保持装饰性降级。GH006 保护分支识别仍在非零 push 后
28
+ * 查看 stderr。
29
+ * 子进程一律 argv 形状(utils/exec 的 execFileAsync),不拼 shell 字符串;
30
+ * npm publish 自带 --registry,publish 前后不读写用户 npm 配置(P0.3)。
23
31
  */
32
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
33
+ if (k2 === undefined) k2 = k;
34
+ var desc = Object.getOwnPropertyDescriptor(m, k);
35
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
36
+ desc = { enumerable: true, get: function() { return m[k]; } };
37
+ }
38
+ Object.defineProperty(o, k2, desc);
39
+ }) : (function(o, m, k, k2) {
40
+ if (k2 === undefined) k2 = k;
41
+ o[k2] = m[k];
42
+ }));
43
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
44
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
45
+ }) : function(o, v) {
46
+ o["default"] = v;
47
+ });
48
+ var __importStar = (this && this.__importStar) || (function () {
49
+ var ownKeys = function(o) {
50
+ ownKeys = Object.getOwnPropertyNames || function (o) {
51
+ var ar = [];
52
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
53
+ return ar;
54
+ };
55
+ return ownKeys(o);
56
+ };
57
+ return function (mod) {
58
+ if (mod && mod.__esModule) return mod;
59
+ var result = {};
60
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
61
+ __setModuleDefault(result, mod);
62
+ return result;
63
+ };
64
+ })();
24
65
  var __importDefault = (this && this.__importDefault) || function (mod) {
25
66
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
67
  };
27
68
  Object.defineProperty(exports, "__esModule", { value: true });
28
69
  exports.release = release;
29
- const child_process_1 = require("child_process");
70
+ const fs_1 = require("fs");
71
+ const path = __importStar(require("path"));
30
72
  const chalk_1 = __importDefault(require("chalk"));
31
73
  const release_1 = require("../../release");
32
74
  const package_json_1 = require("../../utils/package-json");
33
75
  const error_1 = require("../../utils/error");
76
+ const exec_1 = require("../../utils/exec");
34
77
  const command_contract_1 = require("../command-contract");
35
- async function run(cmd, cwd, timeout = 60_000) {
78
+ async function run(file, args, cwd, timeout = 60_000) {
36
79
  try {
37
- const stdout = (0, child_process_1.execSync)(cmd, { cwd, encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'], timeout });
38
- return { stdout: stdout.trim(), stderr: '' };
80
+ const { stdout, stderr } = await (0, exec_1.execFileAsync)(file, args, { cwd, encoding: 'utf-8', timeout });
81
+ return { code: 0, stdout: stdout.trim(), stderr: stderr.trim() };
39
82
  }
40
83
  catch (e) {
41
- // execSync 非零退出:rejection 形状 Error & { stdout?, stderr? },逐字段窄化取数
84
+ // 失败 rejection 形状 Error & { code?, stdout?, stderr? },逐字段窄化取数
42
85
  const err = e;
43
86
  const chunk = (v) => (typeof v === 'string' ? v : v != null ? String(v) : '');
44
- const stderr = chunk(err.stderr);
45
87
  const stdout = chunk(err.stdout);
46
- return { stdout: stdout.trim(), stderr: stderr.trim() || (0, error_1.errorMessage)(e) };
88
+ const stderr = chunk(err.stderr);
89
+ const code = typeof err.code === 'number' ? err.code : 1;
90
+ // errorMessage 仅在两路输出都为空时兜底(否则 stdout-only 错误会被通用文案盖掉)
91
+ return { code, stdout: stdout.trim(), stderr: stderr.trim() || (stdout ? '' : (0, error_1.errorMessage)(e)) };
47
92
  }
48
93
  }
49
94
  /** 闸门失败结果:reason 含闸门标识,可被调用方逐闸门断言 */
@@ -78,7 +123,12 @@ async function release(options, io = command_contract_1.processIO) {
78
123
  (0, command_contract_1.log)(io, chalk_1.default.cyan(`📦 ${pkgName}@${oldVersion}`));
79
124
  (0, command_contract_1.log)(io, chalk_1.default.cyan(` bump: ${bumpType}${dryRun ? ' (dry-run)' : ''}`));
80
125
  // ── 2. Check branch (must be on master/main) ──
81
- const branchResult = await run('git rev-parse --abbrev-ref HEAD', pkgPath);
126
+ const branchResult = await run('git', ['rev-parse', '--abbrev-ref', 'HEAD'], pkgPath);
127
+ if (branchResult.code !== 0) {
128
+ const detail = branchResult.stderr || branchResult.stdout;
129
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ Failed to determine current branch:'), detail.slice(0, 300));
130
+ return gateFail('branch', `cannot determine current branch: ${detail.slice(0, 200)}`);
131
+ }
82
132
  const currentBranch = branchResult.stdout.trim();
83
133
  if (currentBranch !== 'master' && currentBranch !== 'main') {
84
134
  (0, command_contract_1.logError)(io, chalk_1.default.red(`❌ Must be on master or main branch to release. Currently on: ${currentBranch}`));
@@ -87,27 +137,49 @@ async function release(options, io = command_contract_1.processIO) {
87
137
  }
88
138
  (0, command_contract_1.log)(io, chalk_1.default.green(`✅ git: on ${currentBranch}`));
89
139
  // ── 2b. Check remote sync ──
90
- await run('git fetch origin', pkgPath, 15_000);
91
- const behind = await run(`git rev-list --count HEAD..origin/${currentBranch}`, pkgPath);
140
+ const fetchResult = await run('git', ['fetch', 'origin'], pkgPath, 15_000);
141
+ if (fetchResult.code !== 0) {
142
+ const detail = fetchResult.stderr || fetchResult.stdout;
143
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ git fetch failed:'), detail.slice(0, 300));
144
+ return gateFail('remote-sync', `git fetch failed: ${detail.slice(0, 200)}`);
145
+ }
146
+ const behind = await run('git', ['rev-list', '--count', `HEAD..origin/${currentBranch}`], pkgPath);
147
+ if (behind.code !== 0) {
148
+ const detail = behind.stderr || behind.stdout;
149
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ Cannot compare with remote:'), detail.slice(0, 300));
150
+ return gateFail('remote-sync', `cannot compare with origin/${currentBranch}: ${detail.slice(0, 200)}`);
151
+ }
92
152
  if (behind.stdout.trim() !== '0') {
93
153
  (0, command_contract_1.logError)(io, chalk_1.default.red(`❌ Local ${currentBranch} is ${behind.stdout.trim()} commits behind origin/${currentBranch}. Pull first.`));
94
154
  return gateFail('remote-sync', `local ${currentBranch} is ${behind.stdout.trim()} commits behind origin/${currentBranch}`);
95
155
  }
96
156
  (0, command_contract_1.log)(io, chalk_1.default.green('✅ git: synced with remote'));
97
157
  // ── 2c. Check clean working tree ──
98
- const stat = await run('git status --porcelain -uno', pkgPath);
158
+ const stat = await run('git', ['status', '--porcelain', '-uno'], pkgPath);
159
+ if (stat.code !== 0) {
160
+ const detail = stat.stderr || stat.stdout;
161
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ git status failed:'), detail.slice(0, 300));
162
+ return gateFail('clean-tree', `git status failed: ${detail.slice(0, 200)}`);
163
+ }
99
164
  if (stat.stdout.length > 0) {
100
165
  (0, command_contract_1.logError)(io, chalk_1.default.red('❌ Uncommitted changes. Commit or stash before releasing.'));
101
166
  (0, command_contract_1.logError)(io, chalk_1.default.gray(stat.stdout.slice(0, 500)));
102
167
  return gateFail('clean-tree', 'working tree has uncommitted changes');
103
168
  }
104
169
  (0, command_contract_1.log)(io, chalk_1.default.green('✅ git: clean'));
105
- // ── 3. tsc build ──
170
+ // ── 3. tsc build(项目本地确定的 TypeScript 可执行文件;缺失即失败,不做隐式下载)──
106
171
  (0, command_contract_1.log)(io, chalk_1.default.cyan('🔨 Building...'));
107
- const build = await run('npx tsc', pkgPath, 60_000);
108
- if (build.stderr && !build.stdout) {
109
- (0, command_contract_1.logError)(io, chalk_1.default.red('❌ tsc failed:'), build.stderr.slice(0, 800));
110
- return gateFail('build', `tsc failed: ${build.stderr.slice(0, 200)}`);
172
+ const tscPath = path.join(pkgPath, 'node_modules', 'typescript', 'bin', 'tsc');
173
+ if (!(0, fs_1.existsSync)(tscPath)) {
174
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ TypeScript not installed:'), tscPath);
175
+ (0, command_contract_1.logError)(io, chalk_1.default.gray(' Install project dependencies first (npm ci).'));
176
+ return gateFail('build', `typescript executable not found: ${tscPath}`);
177
+ }
178
+ const build = await run(process.execPath, [tscPath], pkgPath, 60_000);
179
+ if (build.code !== 0) {
180
+ const detail = build.stderr || build.stdout;
181
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ tsc failed:'), detail.slice(0, 800));
182
+ return gateFail('build', `tsc failed: ${detail.slice(0, 200)}`);
111
183
  }
112
184
  (0, command_contract_1.log)(io, chalk_1.default.green('✅ tsc: built'));
113
185
  // ── 4. Verify dist(发布物完整性自检,harness#77:清单随源码维护,不再本文件硬编码)──
@@ -125,41 +197,64 @@ async function release(options, io = command_contract_1.processIO) {
125
197
  (0, command_contract_1.log)(io, chalk_1.default.cyan('🔢 Bumping version...'));
126
198
  const expectedNew = bumpedVersion(oldVersion, bumpType);
127
199
  const expectedTag = `v${expectedNew}`;
128
- const tagExists = await run(`git tag -l "${expectedTag}"`, pkgPath);
200
+ const tagExists = await run('git', ['tag', '-l', expectedTag], pkgPath);
201
+ if (tagExists.code !== 0) {
202
+ const detail = tagExists.stderr || tagExists.stdout;
203
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ Cannot verify existing tags:'), detail.slice(0, 300));
204
+ return gateFail('tag-conflict', `cannot verify tag ${expectedTag}: ${detail.slice(0, 200)}`);
205
+ }
129
206
  if (tagExists.stdout.trim() === expectedTag) {
130
207
  (0, command_contract_1.logError)(io, chalk_1.default.red(`❌ Tag ${expectedTag} already exists. Version may have been released already.`));
131
208
  return gateFail('tag-conflict', `tag ${expectedTag} already exists`);
132
209
  }
133
- const bump = await run(`npm version ${bumpType} -m "release: %s"`, pkgPath);
134
- if (bump.stderr && !bump.stdout) {
135
- (0, command_contract_1.logError)(io, chalk_1.default.red('❌ npm version failed:'), bump.stderr);
136
- return gateFail('version-bump', `npm version ${bumpType} failed: ${bump.stderr.slice(0, 200)}`);
210
+ const bump = await run('npm', ['version', bumpType, '-m', 'release: %s'], pkgPath);
211
+ if (bump.code !== 0) {
212
+ const detail = bump.stderr || bump.stdout;
213
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ npm version failed:'), detail.slice(0, 500));
214
+ return gateFail('version-bump', `npm version ${bumpType} failed: ${detail.slice(0, 200)}`);
137
215
  }
138
216
  const newVersion = bump.stdout.trim().replace(/^v/, '');
139
217
  const tag = `v${newVersion}`;
140
218
  (0, command_contract_1.log)(io, chalk_1.default.green(`✅ version: ${oldVersion} → ${newVersion} (committed + tagged)`));
141
219
  // ── 6. Push (handle protected branch via PR) ──
142
220
  (0, command_contract_1.log)(io, chalk_1.default.cyan('⬆️ Pushing...'));
143
- const push = await run(`git push origin ${currentBranch}`, pkgPath, 30_000);
144
- const isProtected = push.stderr.includes('GH006') || push.stderr.includes('protected branch');
221
+ const push = await run('git', ['push', 'origin', currentBranch], pkgPath, 30_000);
222
+ const isProtected = push.code !== 0 &&
223
+ (push.stderr.includes('GH006') || push.stderr.includes('protected branch'));
145
224
  if (isProtected) {
146
225
  // Protected branch: create release branch + PR
147
226
  const releaseBranch = `release/v${newVersion}`;
148
227
  (0, command_contract_1.log)(io, chalk_1.default.yellow(`⚠️ ${currentBranch} is protected. Creating PR via ${releaseBranch}...`));
149
- await run(`git checkout -b ${releaseBranch}`, pkgPath);
150
- await run(`git push origin ${releaseBranch}`, pkgPath, 30_000);
228
+ const createBranch = await run('git', ['checkout', '-b', releaseBranch], pkgPath);
229
+ if (createBranch.code !== 0) {
230
+ const detail = createBranch.stderr || createBranch.stdout;
231
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ git checkout failed:'), detail.slice(0, 500));
232
+ return gateFail('pr-branch', `git checkout -b ${releaseBranch} failed: ${detail.slice(0, 200)}`);
233
+ }
234
+ const pushBranch = await run('git', ['push', 'origin', releaseBranch], pkgPath, 30_000);
235
+ if (pushBranch.code !== 0) {
236
+ const detail = pushBranch.stderr || pushBranch.stdout;
237
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ git push failed:'), detail.slice(0, 500));
238
+ return gateFail('git-push', `git push origin ${releaseBranch} failed: ${detail.slice(0, 200)}`);
239
+ }
151
240
  // Create PR
152
241
  const prBody = `## Release ${pkgName}@${newVersion}\n\n- Bump version: ${oldVersion} → ${newVersion}\n- Changelog updated\n\nAfter merge, push tag to trigger npm publish:\n\`\`\`\ngit push origin ${tag}\n\`\`\``;
153
- const pr = await run(`gh pr create --title "release: ${pkgName}@${newVersion}" --body "${prBody}" --base ${currentBranch}`, pkgPath, 30_000);
154
- if (pr.stdout) {
242
+ const pr = await run('gh', ['pr', 'create', '--title', `release: ${pkgName}@${newVersion}`, '--body', prBody, '--base', currentBranch], pkgPath, 30_000);
243
+ if (pr.code === 0 && pr.stdout) {
155
244
  (0, command_contract_1.log)(io, chalk_1.default.green(`✅ PR created: ${pr.stdout.trim()}`));
156
245
  }
157
246
  else {
158
- (0, command_contract_1.logError)(io, chalk_1.default.red('❌ PR creation failed:'), pr.stderr.slice(0, 500));
159
- return gateFail('pr-create', `gh pr create failed: ${pr.stderr.slice(0, 200)}`);
247
+ const detail = pr.stderr || pr.stdout;
248
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ PR creation failed:'), detail.slice(0, 500));
249
+ return gateFail('pr-create', `gh pr create failed: ${detail.slice(0, 200)}`);
160
250
  }
161
251
  // Switch back to original branch
162
- await run(`git checkout ${currentBranch}`, pkgPath);
252
+ const switchBack = await run('git', ['checkout', currentBranch], pkgPath);
253
+ if (switchBack.code !== 0) {
254
+ const detail = switchBack.stderr || switchBack.stdout;
255
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ git checkout failed:'), detail.slice(0, 500));
256
+ return gateFail('pr-branch', `git checkout ${currentBranch} failed: ${detail.slice(0, 200)}`);
257
+ }
163
258
  (0, command_contract_1.log)(io, chalk_1.default.cyan('\n📋 Next steps:'));
164
259
  (0, command_contract_1.log)(io, chalk_1.default.gray(` 1. Merge the PR: ${pr.stdout.trim()}`));
165
260
  (0, command_contract_1.log)(io, chalk_1.default.gray(` 2. After merge, push tag to trigger npm publish:`));
@@ -167,11 +262,17 @@ async function release(options, io = command_contract_1.processIO) {
167
262
  (0, command_contract_1.log)(io, chalk_1.default.gray(` 3. Or run: gh release create ${tag} --generate-notes`));
168
263
  return { kind: 'ok' };
169
264
  }
170
- if (push.stderr && push.stderr.includes('error')) {
171
- (0, command_contract_1.logError)(io, chalk_1.default.red('❌ git push failed:'), push.stderr.slice(0, 500));
172
- return gateFail('git-push', `git push origin ${currentBranch} failed: ${push.stderr.slice(0, 200)}`);
265
+ if (push.code !== 0) {
266
+ const detail = push.stderr || push.stdout;
267
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ git push failed:'), detail.slice(0, 500));
268
+ return gateFail('git-push', `git push origin ${currentBranch} failed: ${detail.slice(0, 200)}`);
269
+ }
270
+ const tagPush = await run('git', ['push', 'origin', tag], pkgPath, 30_000);
271
+ if (tagPush.code !== 0) {
272
+ const detail = tagPush.stderr || tagPush.stdout;
273
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ git push tag failed:'), detail.slice(0, 500));
274
+ return gateFail('git-push', `git push origin ${tag} failed: ${detail.slice(0, 200)}`);
173
275
  }
174
- await run(`git push origin ${tag}`, pkgPath, 30_000);
175
276
  (0, command_contract_1.log)(io, chalk_1.default.green('✅ git: pushed'));
176
277
  // ── 7. Check private flag ──
177
278
  if (pkgJson.private) {
@@ -180,13 +281,19 @@ async function release(options, io = command_contract_1.processIO) {
180
281
  return gateFail('private-flag', 'package.json has "private": true');
181
282
  }
182
283
  (0, command_contract_1.log)(io, chalk_1.default.green('✅ package: not private'));
183
- // ── 8. npm publish ──
184
- const origRegistry = await run('npm config get registry', pkgPath);
185
- await run('npm config set registry https://registry.npmjs.org/', pkgPath);
284
+ // ── 8. npm publish(--registry 随命令携带,不读写用户 npm 配置)──
186
285
  (0, command_contract_1.log)(io, chalk_1.default.cyan('📤 Publishing to npm...'));
187
- await run('npm publish --registry https://registry.npmjs.org/', pkgPath, 180_000);
188
- await run(`npm config set registry ${origRegistry.stdout}`, pkgPath);
189
- const verify = await run(`npm view ${pkgName} version --registry https://registry.npmjs.org/`, pkgPath);
286
+ const publish = await run('npm', ['publish', '--registry', 'https://registry.npmjs.org/'], pkgPath, 180_000);
287
+ if (publish.code !== 0) {
288
+ const detail = publish.stderr || publish.stdout;
289
+ (0, command_contract_1.logError)(io, chalk_1.default.red('❌ npm publish failed:'), detail.slice(0, 500));
290
+ return gateFail('npm-publish', `npm publish failed: ${detail.slice(0, 200)}`);
291
+ }
292
+ const verify = await run('npm', ['view', String(pkgName), 'version', '--registry', 'https://registry.npmjs.org/'], pkgPath);
293
+ if (verify.code !== 0) {
294
+ (0, command_contract_1.logError)(io, chalk_1.default.red(`❌ npm publish verification failed: npm view exited ${verify.code}. Expected ${newVersion}, registry has ${verify.stdout.trim() || '???'}`));
295
+ return gateFail('npm-publish-verify', `npm view exited ${verify.code}; expected ${newVersion}, registry has ${verify.stdout.trim() || '???'}`);
296
+ }
190
297
  if (verify.stdout.trim() === newVersion) {
191
298
  (0, command_contract_1.log)(io, chalk_1.default.green(`✅ npm: published ${pkgName}@${newVersion}`));
192
299
  }
@@ -196,17 +303,11 @@ async function release(options, io = command_contract_1.processIO) {
196
303
  }
197
304
  // ── 9. GitHub Release ──
198
305
  (0, command_contract_1.log)(io, chalk_1.default.cyan('🐙 Creating GitHub Release...'));
199
- const gh = await run(`gh release create ${tag} --generate-notes`, pkgPath, 30_000);
200
- if (gh.stderr && gh.stderr.includes('already exists')) {
201
- (0, command_contract_1.log)(io, chalk_1.default.yellow(`⚠️ gh: release ${tag} already exists`));
202
- }
203
- else if (gh.stderr) {
204
- (0, command_contract_1.log)(io, chalk_1.default.yellow(`⚠️ gh: release may have failed (non-fatal): ${gh.stderr.slice(0, 200)}`));
205
- }
206
- else {
306
+ const gh = await run('gh', ['release', 'create', tag, '--generate-notes'], pkgPath, 30_000);
307
+ if (gh.code === 0) {
207
308
  let repoUrl = '';
208
309
  try {
209
- const remoteUrl = (0, child_process_1.execSync)('git remote get-url origin', { cwd: pkgPath, encoding: 'utf-8', stdio: 'pipe', timeout: 5_000 }).trim();
310
+ const remoteUrl = (await run('git', ['remote', 'get-url', 'origin'], pkgPath, 5_000)).stdout.trim();
210
311
  const m = remoteUrl.match(/github\.com[:/]([^/]+)\/([^/\s.]+?)(?:\.git)?$/);
211
312
  if (m)
212
313
  repoUrl = `https://github.com/${m[1]}/${m[2]}/releases/tag/${tag}`;
@@ -214,6 +315,12 @@ async function release(options, io = command_contract_1.processIO) {
214
315
  catch { /* no remote */ }
215
316
  (0, command_contract_1.log)(io, chalk_1.default.green(`✅ GitHub Release: ${repoUrl || tag}`));
216
317
  }
318
+ else if (gh.stderr.includes('already exists')) {
319
+ (0, command_contract_1.log)(io, chalk_1.default.yellow(`⚠️ gh: release ${tag} already exists`));
320
+ }
321
+ else {
322
+ (0, command_contract_1.log)(io, chalk_1.default.yellow(`⚠️ gh: release may have failed (non-fatal): ${(gh.stderr || gh.stdout).slice(0, 200)}`));
323
+ }
217
324
  (0, command_contract_1.log)(io, chalk_1.default.green(`\n🎉 Released ${pkgName}@${newVersion}`));
218
325
  (0, command_contract_1.log)(io, chalk_1.default.gray(` npm: https://www.npmjs.com/package/${pkgName}/v/${newVersion}`));
219
326
  return { kind: 'ok' };
@@ -11,6 +11,8 @@ export interface ReportOptions {
11
11
  format: 'json' | 'markdown';
12
12
  /** 项目路径 */
13
13
  projectPath?: string;
14
+ /** 只读模式(CLI --read-only;D3 P0.5 Phase 1):跳过项目 YAML 声明的命令执行 */
15
+ readOnly?: boolean;
14
16
  }
15
17
  /**
16
18
  * 生成检查报告
@@ -44,9 +44,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
44
44
  exports.report = report;
45
45
  const chalk_1 = __importDefault(require("chalk"));
46
46
  const fs = __importStar(require("fs/promises"));
47
- const checker_1 = require("../../core/constraints/checker");
47
+ const bootstrap_1 = require("../../bootstrap");
48
48
  const effective_constraints_1 = require("../../core/effective-constraints");
49
- const traces_1 = require("../../monitoring/traces");
49
+ const command_execution_policy_1 = require("../../core/command-execution-policy");
50
50
  const command_contract_1 = require("../command-contract");
51
51
  /**
52
52
  * 生成检查报告
@@ -54,9 +54,12 @@ const command_contract_1 = require("../command-contract");
54
54
  async function report(options, io = command_contract_1.processIO) {
55
55
  (0, command_contract_1.log)(io, chalk_1.default.blue('📊 生成检查报告...'));
56
56
  const projectPath = options.projectPath || process.cwd();
57
- // trace 记录器经构造参数接线(harness#88):本命令是组合根
58
- // #139:收集器锚根构造——不传 projectPath 时 trace 会落进调用方 cwd,B 侧读不到
59
- const checker = new checker_1.ConstraintChecker(new traces_1.TraceCollector({ projectPath }));
57
+ // checker 经唯一装配函数取(P1.1):trace 接线只写一次,收集器锚根构造
58
+ // (#139:不传 projectPath 时 trace 会落进调用方 cwd,B 侧读不到)
59
+ // commandPolicy(D3):本 run 的统一执行策略,read-only 下 exec 模板 checker
60
+ // 三态跳过声明命令;缺省 = 默认执行
61
+ const policy = (0, command_execution_policy_1.createCommandExecutionPolicy)({ readOnly: options.readOnly });
62
+ const checker = (0, bootstrap_1.assembleConstraintChecker)(projectPath, policy);
60
63
  // 生效集口径与 check.ts 同一入口(ADR-0033:应用层约束进 report 面的前提)——
61
64
  // 此前跑的是内置全集(CONSTRAINTS),config.yml 禁用与应用层条目都不进报告
62
65
  const merged = (0, effective_constraints_1.getMergedConstraintsConfig)(projectPath);
@@ -66,15 +69,30 @@ async function report(options, io = command_contract_1.processIO) {
66
69
  operation: 'file_modification',
67
70
  projectPath,
68
71
  };
72
+ // 运行前清单(D3 P0.5 Phase 1):列出本次将执行的项目声明命令;--read-only 下列出被跳过的。
73
+ // 清单按 context 的 operation/extraTriggers 过滤(与 checker 分发同口径)。
74
+ const commandPlan = (0, command_execution_policy_1.planCommandsFromConstraints)(merged.constraints, context);
75
+ if (commandPlan.length > 0) {
76
+ if (options.readOnly) {
77
+ (0, command_contract_1.log)(io, chalk_1.default.gray(`⏭️ --read-only:跳过 ${commandPlan.length} 条项目声明命令(未执行):`));
78
+ }
79
+ else {
80
+ (0, command_contract_1.log)(io, chalk_1.default.yellow(`⚠️ 本次将执行 ${commandPlan.length} 条项目声明命令:`));
81
+ }
82
+ (0, command_execution_policy_1.formatCommandPlan)(commandPlan).forEach(line => (0, command_contract_1.log)(io, chalk_1.default.gray(line)));
83
+ }
69
84
  // 收集模式(架构评审候选1):不抛、全量收集,error 级违规如实进报告
70
85
  const result = await checker.collectConstraints(context, merged);
71
86
  const failedErrors = result.errors.filter(r => !r.satisfied);
72
87
  const failedWarnings = result.warnings.filter(r => !r.satisfied);
88
+ const skippedResults = [...result.errors, ...result.warnings].filter(r => r.skipped);
73
89
  const violations = [...failedErrors, ...failedWarnings].map(r => ({
74
90
  id: r.id,
75
91
  severity: r.severity,
76
92
  message: r.message || '',
77
93
  }));
94
+ // 普通模式:字段集合与 passed 公式逐字保持既有形状(本票契约)。
95
+ // 仅 --read-only 添加 skipped/skippedConstraints,且 passed 不把未评估计成通过(假绿防线)。
78
96
  const reportData = {
79
97
  timestamp: new Date().toISOString(),
80
98
  projectPath,
@@ -82,9 +100,17 @@ async function report(options, io = command_contract_1.processIO) {
82
100
  total: totalConstraints,
83
101
  errors: effectiveConstraints.filter(c => c.severity === 'error').length,
84
102
  warnings: effectiveConstraints.filter(c => c.severity === 'warning').length,
85
- passed: result.passed ? totalConstraints : totalConstraints - violations.length,
103
+ passed: options.readOnly
104
+ ? (result.passed ? totalConstraints : totalConstraints - violations.length) - skippedResults.length
105
+ : result.passed ? totalConstraints : totalConstraints - violations.length,
86
106
  failed: failedErrors.length,
87
107
  warningViolations: failedWarnings.length,
108
+ ...(options.readOnly
109
+ ? {
110
+ skipped: skippedResults.length,
111
+ skippedConstraints: skippedResults.map(r => ({ id: r.id, skipReason: r.skipReason })),
112
+ }
113
+ : {}),
88
114
  violations,
89
115
  },
90
116
  };
@@ -106,6 +132,18 @@ async function report(options, io = command_contract_1.processIO) {
106
132
  else {
107
133
  (0, command_contract_1.log)(io, content);
108
134
  }
135
+ // read-only 且本 run 有声明命令被策略跳过:返回 skip(退出 0)而非 ok——
136
+ // 上层不能把「命令未执行」的报告当完整验证结果
137
+ if (options.readOnly) {
138
+ const planSources = new Set(commandPlan.map(p => p.source));
139
+ const policySkipped = skippedResults.filter(r => planSources.has(r.id));
140
+ if (policySkipped.length > 0) {
141
+ return {
142
+ kind: 'skip',
143
+ reason: `--read-only: ${policySkipped.length} constraints not evaluated (commands not executed)`,
144
+ };
145
+ }
146
+ }
109
147
  return { kind: 'ok' };
110
148
  }
111
149
  function generateMarkdownReport(data) {
@@ -127,6 +165,8 @@ function generateMarkdownReport(data) {
127
165
  `| 通过 | ${data.constraints.passed} |`,
128
166
  `| 失败 (error) | ${data.constraints.failed} |`,
129
167
  `| 警告 (warning) | ${data.constraints.warningViolations} |`,
168
+ // 跳过行只随 --read-only 出现(普通模式行集合保持既有形状)
169
+ ...(data.constraints.skipped !== undefined ? [`| 跳过(未评估) | ${data.constraints.skipped} |`] : []),
130
170
  ``,
131
171
  ];
132
172
  if (data.constraints.violations.length > 0) {
@@ -136,6 +176,14 @@ function generateMarkdownReport(data) {
136
176
  });
137
177
  lines.push(``);
138
178
  }
179
+ const skippedConstraints = data.constraints.skippedConstraints;
180
+ if (skippedConstraints && skippedConstraints.length > 0) {
181
+ lines.push(`### 跳过项`, ``);
182
+ skippedConstraints.forEach(s => {
183
+ lines.push(`- **${s.id}**: ${s.skipReason ?? '未评估'}`);
184
+ });
185
+ lines.push(``);
186
+ }
139
187
  lines.push(`---`, `*报告由 @dommaker/harness 生成*`, ``);
140
188
  return lines.join('\n');
141
189
  }
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 安全门控,检查安全漏洞
5
5
  */
6
- import { execAsync } from '../../utils/exec';
6
+ import { execFileAsync } from '../../utils/exec';
7
7
  import { type CommandIO, type CommandResult } from '../command-contract';
8
8
  export interface SecurityOptions {
9
9
  /** 项目路径 */
@@ -25,8 +25,8 @@ export interface SecretsOptions {
25
25
  /** 项目路径(= 待扫仓库根) */
26
26
  projectPath?: string;
27
27
  }
28
- /** 执行器注入缝(测试不依赖真 gitleaks 二进制) */
29
- type ExecFn = typeof execAsync;
28
+ /** 执行器注入缝(测试不依赖真 gitleaks 二进制):argv 形状,路径不经 shell 字符串 */
29
+ type ExecFn = typeof execFileAsync;
30
30
  /**
31
31
  * 全历史机密扫描(`gitleaks git`,P1-8)。
32
32
  *
@@ -118,7 +118,7 @@ function getSeverityColor(severity) {
118
118
  * 出口纪律:有泄露只列条数与文件(截断 20 条),**不打印密钥原文**
119
119
  * (报告里的 Secret/Match 字段从不进输出与 reason)。
120
120
  */
121
- async function secretsScan(options, io = command_contract_1.processIO, execFn = exec_1.execAsync) {
121
+ async function secretsScan(options, io = command_contract_1.processIO, execFn = exec_1.execFileAsync) {
122
122
  (0, command_contract_1.log)(io, chalk_1.default.blue('🔒 全历史机密扫描(gitleaks)...'));
123
123
  const repoRoot = options.projectPath || process.cwd();
124
124
  const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-gitleaks-'));
@@ -126,7 +126,8 @@ async function secretsScan(options, io = command_contract_1.processIO, execFn =
126
126
  try {
127
127
  let exitCode = 0;
128
128
  try {
129
- await execFn(`gitleaks git --report-format json --report-path "${reportPath}" "${repoRoot}"`, { cwd: repoRoot, maxBuffer: 10 * 1024 * 1024 });
129
+ // repoRoot/reportPath 一律走 argv 元素,不经 shell 字符串(P0.3)
130
+ await execFn('gitleaks', ['git', '--report-format', 'json', '--report-path', reportPath, repoRoot], { cwd: repoRoot, maxBuffer: 10 * 1024 * 1024 });
130
131
  }
131
132
  catch (error) {
132
133
  // gitleaks 退出码:0 = 干净,1 = 发现泄露(报告已落盘);127 = 二进制不存在
@@ -1,18 +1,12 @@
1
1
  /**
2
- * CAPABILITIES.md 文件表格同步器(工单 22)
2
+ * CAPABILITIES.md 写侧(工单 22 / harness#171;P2.8 拆段:文本判定正本下沉
3
+ * core/docs-sync/capabilities-table.ts,本文件只剩落盘维护)
3
4
  *
4
5
  * 只负责文件表格格式:模块/文件/说明三列表格,增删行维护。
5
6
  * 能力清单格式(计数行)的解析与计数已收敛到 core/constraints/capabilities-parser(H2 O10-R3)。
6
7
  */
7
8
  import type { CapabilitiesMode } from '../../../core/constraints/governance-accessors';
8
- import type { ModuleInfo, SyncResult } from './project-reader';
9
- /**
10
- * 解析 CAPABILITIES.md 中的文件路径
11
- *
12
- * 提取所有表格行中提到的 .ts/.tsx/.js/.jsx 文件名(不含路径前缀)
13
- * 用于模糊匹配:只要文档中提到了该文件名就算已记录
14
- */
15
- export declare function parseCapabilitiesFiles(capabilitiesPath: string): Promise<string[]>;
9
+ import type { ModuleInfo, SyncResult } from '../../../core/docs-sync/project-reader';
16
10
  /**
17
11
  * 更新 CAPABILITIES.md 文件
18
12
  *
@@ -20,34 +14,3 @@ export declare function parseCapabilitiesFiles(capabilitiesPath: string): Promis
20
14
  * (目录条目需人工策划登记),幽灵行剔除与「最后更新」刷新保留。
21
15
  */
22
16
  export declare function updateCapabilitiesFile(capabilitiesPath: string, currentModules: ModuleInfo[], existingFiles: string[], result: SyncResult, mode?: CapabilitiesMode): Promise<void>;
23
- export interface TableLayoutNormalization {
24
- /** 收拢后的内容 */
25
- content: string;
26
- /** 被删掉的「表格内空行」行数 */
27
- blankLines: number;
28
- /** 被收掉的「空表」(表头+分隔行且无数据行)张数 */
29
- emptyTables: number;
30
- }
31
- /**
32
- * 收拢 CAPABILITIES.md 的表格排版(harness#171)
33
- *
34
- * 两条规则:① 删掉夹在两个表格行之间的空行(CommonMark 会在此切断表格);
35
- * ② 收掉没有数据行的表头+分隔行。表格外的空行(段落分隔)不动;围栏代码块内的行整体豁免。
36
- *
37
- * 规则互相制造对方的触发点(①把两张空表之间的那个空行吃掉后,②一轮只收得掉后一张),
38
- * 所以跑到不动点:**一次 `sync-docs` 必须把 `--check` 报出来的东西全清掉**,
39
- * 否则下游 CI 修完还是红的。计数 = 各轮合计(每轮只删当轮存在的行,不会重计)。
40
- *
41
- * 幂等,且 `--check` 与写模式共用此正本——判定面就是「返回内容与入参是否不同」,
42
- * 因此不存在「check 报了 fix 修不掉」的不收敛(ADR-0009 口径)。
43
- */
44
- export declare function normalizeCapabilitiesTableLayout(content: string): TableLayoutNormalization;
45
- /**
46
- * 将 CAPABILITIES.md 文件表格折叠为目录条目(--compact 一次性迁移)
47
- *
48
- * 按文件条目(第二列)的 dirname 分组:同组 ≥2 个文件条目折叠为一行目录条目
49
- * (替换组内第一行、删除其余行,说明取组内第一行,为空则用目录名);
50
- * 单独成组的文件行、表头、非表格文本、PRESERVE 块原样保留。
51
- * 已折叠的目录条目行不再匹配文件条目,故幂等。
52
- */
53
- export declare function compactCapabilitiesContent(content: string): string;