@rightkit/release 0.6.57 → 0.6.62

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 (71) hide show
  1. package/README.md +4 -0
  2. package/acceptance-admission.mjs +104 -0
  3. package/acceptance-launch.mjs +234 -0
  4. package/acceptance-lines.mjs +1254 -0
  5. package/acceptance-result.mjs +77 -0
  6. package/acceptance-rows.mjs +47 -0
  7. package/admission-files.mjs +2 -0
  8. package/affected-units.mjs +17 -0
  9. package/app-check.mjs +6 -2
  10. package/app-closure.mjs +3 -1
  11. package/bin/rightkit-gate.mjs +552 -124
  12. package/broker-admission.mjs +45 -2
  13. package/broker-pins.mjs +11 -1
  14. package/broker-toolchain.mjs +113 -0
  15. package/cargo-profile-contract.mjs +7 -2
  16. package/class-a-cache-history.mjs +170 -0
  17. package/cli/right-release.mjs +0 -0
  18. package/code-closure.mjs +24 -0
  19. package/config-inspect.mjs +6 -0
  20. package/consumer-contracts.mjs +3 -1
  21. package/contract-nn.json +166 -0
  22. package/deterministic-scans.mjs +835 -112
  23. package/feature-coverage.mjs +109 -82
  24. package/feature-partition.mjs +76 -0
  25. package/forbidden-literals.mjs +78 -0
  26. package/gate/calls.mjs +121 -0
  27. package/gate/compile.mjs +190 -0
  28. package/gate/crate-results.mjs +127 -0
  29. package/gate/run-calls.mjs +241 -0
  30. package/gate/tests.mjs +234 -0
  31. package/gate-coverage.mjs +12 -3
  32. package/gate-release-admission.mjs +200 -0
  33. package/gate-seam.mjs +100 -4
  34. package/gate-serve.mjs +179 -34
  35. package/gate-stages.mjs +59 -0
  36. package/legacy-contract-receipt.mjs +809 -0
  37. package/local-publish.mjs +2 -4
  38. package/local-runtime.mjs +2 -2
  39. package/nsis-payload.mjs +4 -3
  40. package/ownership-applicability.mjs +5 -0
  41. package/ownership-class-rules.mjs +19 -8
  42. package/ownership-mandatory-set.json +15 -21
  43. package/ownership-mandatory-set.mjs +19 -4
  44. package/package.json +14 -8
  45. package/probe-memo.mjs +252 -0
  46. package/publication-artifacts.mjs +56 -2
  47. package/publish-local-npm.mjs +3 -0
  48. package/publish-update.mjs +2 -2
  49. package/receipt-signature.mjs +40 -0
  50. package/release.mjs +47 -29
  51. package/resident-answers.mjs +66 -0
  52. package/rightkit-ownership.json +20 -11
  53. package/rightkit-versions.json +349 -183
  54. package/runtime-bundle-stage.mjs +146 -0
  55. package/scan-digest.mjs +28 -4
  56. package/seam-broker.mjs +8 -1
  57. package/shell-contract.mjs +23 -2
  58. package/snapshot-changes.mjs +106 -0
  59. package/snapshot-check.mjs +17 -13
  60. package/snapshot-dependency-reuse.mjs +186 -14
  61. package/snapshot-git.mjs +17 -1
  62. package/snapshot-metadata.mjs +155 -3
  63. package/snapshot.mjs +89 -12
  64. package/spawn-ledger.mjs +21 -2
  65. package/stage-sidecar.mjs +231 -19
  66. package/suite-trust-roots.mjs +2 -2
  67. package/test-env.mjs +26 -0
  68. package/tool-version-memo.mjs +46 -0
  69. package/win-package-recipe.mjs +11 -0
  70. package/bin/darwin/rightkit-swap +0 -0
  71. package/gate-acceptance.mjs +0 -3362
package/snapshot.mjs CHANGED
@@ -42,6 +42,8 @@ import { HostConfigError, hostConfigFile, readSnapshotRootConfig } from "./snaps
42
42
  import { discoveryGit, discoveryRun, sealedRepoInfo, sealedRun, withSealedGit } from "./snapshot-git.mjs";
43
43
  import { SOURCE_IDENTITY_FILE, sourceIdentityBytes } from "./snapshot-identity.mjs";
44
44
  import { parseIdentity, processIdentity } from "./gate-seam.mjs";
45
+ import { serveRequest } from "./gate-serve.mjs";
46
+ import { treeStandsAfterChanges } from "./snapshot-changes.mjs";
45
47
  // The error class and the managed-root guard live in managed-root-guard.mjs (decision D4 rule 1).
46
48
  import { SnapshotError, requireManagedRoot } from "./managed-root-guard.mjs";
47
49
 
@@ -237,7 +239,50 @@ export function resolveCommit(checkout, rev = "HEAD") {
237
239
  * object database and ignore rules; writes only objects (into the checkout's object database) and a temporary index kept outside the
238
240
  * checkout's `.git`, always removed.
239
241
  */
242
+ /** How often this process hashed a snapshot's tree, walked it to verify it, and took the resident gate's proof instead (NN11): one line per run. */
243
+ export const SNAPSHOT_PROOF_COUNTS = { treeHashes: 0, verifyWalks: 0, residentProofs: 0, changedFileProofs: 0, changeSource: null };
244
+ /** NN28: remembers how the open gate process said it learns of changes (`source` of its answers), for the run's `snapshot proof:` line. */
245
+ export function noteChangeSource(reply) { if (typeof reply?.source === "string" && reply.source) SNAPSHOT_PROOF_COUNTS.changeSource = reply.source; return reply; }
246
+ /** The `snapshot proof:` line the contract test reads (NN11, NN28). `changeSource`: how the resident gate learns of changes. */
247
+ export const snapshotProofLine = (changeSource) => `snapshot proof: tree-hashes=${SNAPSHOT_PROOF_COUNTS.treeHashes} verify-walks=${SNAPSHOT_PROOF_COUNTS.verifyWalks} resident-proofs=${SNAPSHOT_PROOF_COUNTS.residentProofs} changed-file-proofs=${SNAPSHOT_PROOF_COUNTS.changedFileProofs} change-source=${changeSource}`;
248
+
249
+ /**
250
+ * NN11: whether the tree the open gate process last saw proven in `dir` still stands, judged from its record of what changed since
251
+ * (`reply`: its answer to "check"; snapshot-changes.mjs). True only after the caller's own walk of the snapshot has passed: then the tree id
252
+ * depends on the commit's files alone, and each one the changes could have touched is compared with the commit's blob here. False on any
253
+ * doubt, and the caller hashes the tree.
254
+ */
255
+ export function treeProvenByChanges({ reply, dir, tree, entries, objectFormat }) {
256
+ const base = reply?.base;
257
+ if (!base || base.tree !== tree) return false;
258
+ if (!treeStandsAfterChanges({ dir, entries, changes: { changed: base.changed, renamed: base.renamed }, objectFormat }).ok) return false;
259
+ SNAPSHOT_PROOF_COUNTS.changedFileProofs += 1;
260
+ return true;
261
+ }
262
+ /**
263
+ * The open gate process's change generation for `dir`, taken before a proof begins (gate-serve.mjs "begin"), or null. When the process was
264
+ * not running it is started (for the host's own snapshot root only) and asked again for a short while: a proof recorded now saves every later
265
+ * hash of this run.
266
+ */
267
+ export function beginResidentProof(dir, { env = process.env, ask = serveRequest, waitMs = 8000 } = {}) {
268
+ const root = path.dirname(path.resolve(dir));
269
+ // Only the first question may start the process (each start is a launcher of its own on Windows); the ones after it only ask.
270
+ let r = noteChangeSource(ask({ op: "begin", dir }, { env, root }));
271
+ if (Number.isInteger(r?.generation)) return r.generation;
272
+ if (residentWaitFailed) return null; // it did not come up within the wait once already in this process: not waited for again
273
+ const until = Date.now() + waitMs;
274
+ while (Date.now() < until) {
275
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 200);
276
+ r = noteChangeSource(ask({ op: "begin", dir }, { env }));
277
+ if (Number.isInteger(r?.generation)) return r.generation;
278
+ }
279
+ residentWaitFailed = true;
280
+ return null;
281
+ }
282
+ let residentWaitFailed = false;
283
+
240
284
  export function snapshotTree({ checkout, dir, baseTree, repo = repositoryOf(checkout), indexStore = treeIndexStoreOf(dir) }) {
285
+ SNAPSHOT_PROOF_COUNTS.treeHashes += 1;
241
286
  // The sealed runner (snapshot-git.mjs): a private git directory T holds the index and receives every object written; the
242
287
  // checkout's git directory is not written at all (row 5.13), and its configuration, attributes, hooks and filters cannot reach the id.
243
288
  const once = (stored) => withSealedGit({ commonDir: repo.commonDir, objectFormat: repo.objectFormat, snapshot: dir }, (git) => {
@@ -255,8 +300,14 @@ export function snapshotTree({ checkout, dir, baseTree, repo = repositoryOf(chec
255
300
  throw e instanceof SnapshotError ? e : new SnapshotError("error", e.message);
256
301
  }
257
302
  });
303
+ // The stored index is a cache of the last run's stat data. Its answer is taken only when it is the tree the caller expects (`baseTree`):
304
+ // on Windows a file's executable bit lives in the index alone (core.fileMode=false), so a path that became 100755 since the stored index
305
+ // was written is hashed as 100644 and the id is wrong though every byte is right (Dell, 2026-11-17: rightkit 09aaf01e1 -> 4b23c9870, two
306
+ // files renamed and made executable; the run stopped with "is tree 26f549d1 after sync, not tree 2df67580"). Any other id is recomputed
307
+ // from the commit's own tree, which is the contract's method, and that result is the one returned.
258
308
  if (indexStore && fs.existsSync(indexStore)) {
259
- try { return once(indexStore); } catch { try { fs.rmSync(indexStore, { force: true }); } catch { /* best effort */ } }
309
+ try { const id = once(indexStore); if (id === baseTree) return id; } catch { /* recomputed below */ }
310
+ try { fs.rmSync(indexStore, { force: true }); } catch { /* best effort */ }
260
311
  }
261
312
  return once(null);
262
313
  }
@@ -277,7 +328,7 @@ export function treeIndexStoreOf(dir) {
277
328
  * input even though the seeded tree id cannot see it. Never follows a link (only real directories are entered); names compare
278
329
  * case-insensitively where the host filesystem does (Mac, Windows; colliding names were refused before this runs).
279
330
  */
280
- function pruneToTree(dir, entries, platform = process.platform, keepRoot = new Set(), keepDirs = new Set()) {
331
+ function pruneToTree(dir, entries, platform = process.platform, keepRoot = new Set(), keepDirs = new Set(), removedPaths = null) {
281
332
  const fold = platform === "darwin" || platform === "win32" ? (n) => n.toLowerCase() : (n) => n;
282
333
  const files = new Set(entries.map((e) => fold(e.path)));
283
334
  const dirs = new Set();
@@ -289,8 +340,8 @@ function pruneToTree(dir, entries, platform = process.platform, keepRoot = new S
289
340
  const p = path.join(d, e.name);
290
341
  // keepDirs: the commit's own generated pnpm dependency directories (dependencyDirs), real directories only, kept whole for the
291
342
  // dependency step, which reuses them only when every installed byte matches its last completed install and otherwise removes them.
292
- if (e.isDirectory()) { if (keepDirs.has(fold(r))) continue; if (dirs.has(fold(r))) walk(p, r); else { fs.rmSync(p, { recursive: true, force: true }); removed++; } }
293
- else if (!files.has(fold(r)) && !(rel === "" && keepRoot.has(fold(r)))) { fs.unlinkSync(p); removed++; }
343
+ if (e.isDirectory()) { if (keepDirs.has(fold(r))) continue; if (dirs.has(fold(r))) walk(p, r); else { fs.rmSync(p, { recursive: true, force: true }); removed++; removedPaths?.push(`${r}/`); } }
344
+ else if (!files.has(fold(r)) && !(rel === "" && keepRoot.has(fold(r)))) { fs.unlinkSync(p); removed++; removedPaths?.push(r); }
294
345
  }
295
346
  };
296
347
  walk(dir, "");
@@ -677,7 +728,8 @@ const statKey = (s) => `${s.size}:${s.mtimeNs}:${s.ctimeNs}:${s.ino}`;
677
728
  // and the broker's SNAPSHOT_STATUS proof covers only broker jobs. So while this process holds a snapshot lock, every detached child it starts is recorded beside
678
729
  // the lock (`<lock>.children/group-<pid>.json`, removed only once the whole group is gone), and a dead holder's lock is never reclaimed while a recorded group still answers.
679
730
  // Windows children are contained by the lock holder's named job instead (below). Residual, named: a crash between the spawn returning and the record being written
680
- // leaves that one group unrecorded.
731
+ // leaves that one group unrecorded. Second residual, named: the record follows the group, not the tree. A process that leaves the group (setsid, setpgid)
732
+ // is not seen by it, so "the group is gone" is never proof that everything the child started is gone (gate/tests.mjs treats a timed-out program as unreaped for this reason).
681
733
  let heldLockFile = null;
682
734
  const childrenDirOf = (lockFile) => `${lockFile}.children`;
683
735
  /** The variable that hands the held lock's record directory to this process's own children (right-release, heavy-command), which record their detached children there. */
@@ -688,7 +740,7 @@ export function recordLockChild(child, { platform = process.platform, env = proc
688
740
  if (!dir || platform === "win32" || !child || !Number.isInteger(child.pid) || child.pid <= 0) return child;
689
741
  const file = path.join(dir, `group-${child.pid}.json`);
690
742
  try { fs.mkdirSync(dir, { recursive: true, mode: 0o700 }); fs.writeFileSync(file, JSON.stringify({ group: child.pid, by: process.pid, at: new Date().toISOString() }), { mode: 0o600 }); }
691
- catch (error) { try { process.kill(-child.pid, "SIGKILL"); } catch { /* already gone */ } throw new SnapshotError("error", `the snapshot lock's child record ${file} cannot be written (${error.message}); the child was stopped`); }
743
+ catch (error) { try { process.kill(-child.pid, "SIGKILL"); } catch { /* already gone */ } throw new SnapshotError("error", `the snapshot lock's child record ${file} cannot be written (${error.message}); a stop was sent to its group and is not confirmed`); }
692
744
  // The root's exit does not end the group: a descendant it started (a backgrounded process with its own stdio) can outlive it in the same group.
693
745
  // The record goes only on proof the whole group is gone (kill(-group, 0) is ESRCH); otherwise it stays and liveLockChildren keeps seeing the group.
694
746
  const forget = () => {
@@ -1090,7 +1142,7 @@ export const lockView = (release) => ({ token: release.token, lockFile: release.
1090
1142
  // `lock`: the snapshot lock of this sync (reset plan section 3). `held` is a lock the caller already took with `takeSnapshotLock` for this same snapshot: the sync
1091
1143
  // uses it, re-checks it before every write and never releases it (the caller holds it through the batch). Without `held` the sync takes the lock itself, for the sync
1092
1144
  // alone: `body` is the seam's lock body the broker reads (gate-seam.mjs snapshotLockBody) and `judge` decides a dead holder's reclaim on the broker's proof.
1093
- export function syncSnapshot({ checkout, rev = "HEAD", root = snapshotRoot(), managedRoot = hostManagedRootFor(root), device, now = () => Date.now(), lock = {} } = {}) {
1145
+ export function syncSnapshot({ checkout, rev = "HEAD", root = snapshotRoot(), managedRoot = hostManagedRootFor(root), device, now = () => Date.now(), lock = {}, resident = managedRoot ? serveRequest : null } = {}) {
1094
1146
  const started = now();
1095
1147
  const repo = repositoryOf(checkout);
1096
1148
  const { commit, tree } = resolveCommit(repo.checkout, rev);
@@ -1251,7 +1303,9 @@ export function syncSnapshot({ checkout, rev = "HEAD", root = snapshotRoot(), ma
1251
1303
  })();
1252
1304
  const keepDeps = dependencyDirs(entries, process.platform);
1253
1305
  if (keepGit) keepDeps.add(foldFor(process.platform)(".git"));
1254
- removed += pruneToTree(dir, entries, process.platform, keepIdentity ? new Set([foldFor(process.platform)(SOURCE_IDENTITY_FILE)]) : new Set(), keepDeps);
1306
+ // NN22: what was removed is named (the first 8), so a warm sync that removes anything says what (the sync line in rightkit-gate).
1307
+ const removedPaths = [];
1308
+ removed += pruneToTree(dir, entries, process.platform, keepIdentity ? new Set([foldFor(process.platform)(SOURCE_IDENTITY_FILE)]) : new Set(), keepDeps, removedPaths);
1255
1309
  if (identityBytes) {
1256
1310
  // Written only when the commit's own ignore rules ignore the name (they are in the snapshot now): an unignored file would change the
1257
1311
  // tree id the broker computes too, so the gate would break every build of that repository. Then nothing is written and the reason is reported.
@@ -1277,12 +1331,17 @@ export function syncSnapshot({ checkout, rev = "HEAD", root = snapshotRoot(), ma
1277
1331
  }
1278
1332
 
1279
1333
  assertLockHeld();
1334
+ // NN11: this walk and hash are a proof like any other, and the first of the run. The open gate process is told (its change generation is
1335
+ // taken before the walk, so a change during the proof refuses the record), and every later proof of this run starts from it instead of
1336
+ // hashing the tree again. On a host's managed root only: a test's temporary root has no such process (`resident` is the transport, for tests).
1337
+ const residentGeneration = resident ? beginResidentProof(dir, { ask: resident }) : null;
1280
1338
  const extra = snapshotProblem({ dir, entries, checkout: repo.checkout, commit });
1281
1339
  if (extra) throw new SnapshotError("mismatch", `snapshot ${dir} is not exactly commit ${commit} after sync: ${extra}`);
1282
1340
  const actual = snapshotTree({ checkout: repo.checkout, dir, baseTree: tree, repo });
1283
1341
  if (actual !== tree) throw new SnapshotError("mismatch", `snapshot ${dir} is tree ${actual} after sync, not tree ${tree} of commit ${commit}`);
1342
+ if (residentGeneration !== null) resident({ op: "record", dir, tree, generation: residentGeneration });
1284
1343
  writeState(stateFile, { schema: STATE_SCHEMA, repo: repo.checkout, repoKey: repo.key, commit, tree, paths: [...wanted.keys()], stat: nextStat, syncedAt: new Date(now()).toISOString() });
1285
- return { schema: SNAPSHOT_SCHEMA, path: dir, repoKey: repo.key, commit, tree, written, removed, modesFixed, unchanged, linksRemoved, hardLinksReplaced, casesFixed, identity, ms: now() - started };
1344
+ return { schema: SNAPSHOT_SCHEMA, path: dir, repoKey: repo.key, commit, tree, written, removed, removedPaths: removedPaths.slice(0, 8), modesFixed, unchanged, linksRemoved, hardLinksReplaced, casesFixed, identity, ms: now() - started };
1286
1345
  } finally {
1287
1346
  // A lock the caller took is the caller's to release; a lock this sync took ends with it.
1288
1347
  if (!joined) release();
@@ -1305,7 +1364,7 @@ export function syncSnapshot({ checkout, rev = "HEAD", root = snapshotRoot(), ma
1305
1364
  * result carry `ledger: [{ path, type, size, sha256, execBit }]`, every admitted entry. The tree id is still the commit's tree:
1306
1365
  * an ignored output does not change it. With neither option nothing beyond the commit (and 5.09's allowances) is accepted.
1307
1366
  */
1308
- export function verifySnapshot({ checkout, rev = "HEAD", root = snapshotRoot(), dir, managedRoot = hostManagedRootFor(root), device, environment, ledger, admitNew } = {}) {
1367
+ export function verifySnapshot({ checkout, rev = "HEAD", root = snapshotRoot(), dir, managedRoot = hostManagedRootFor(root), device, environment, ledger, admitNew, resident = serveRequest } = {}) {
1309
1368
  const repo = repositoryOf(checkout);
1310
1369
  const { commit, tree } = resolveCommit(repo.checkout, rev);
1311
1370
  if (managedRoot) requireManagedRoot(managedRoot, { device });
@@ -1313,12 +1372,30 @@ export function verifySnapshot({ checkout, rev = "HEAD", root = snapshotRoot(),
1313
1372
  // The root the snapshot sits directly in is private to this user, as at sync (a root another principal can use proves nothing).
1314
1373
  if (path.resolve(path.dirname(at)) === path.resolve(root)) requirePrivateRoot(root, lstat(root));
1315
1374
  if (!lstat(at)?.isDirectory()) throw new SnapshotError("mismatch", `no snapshot directory at ${at}`);
1375
+ // NN11 (Dell 2026-11-19, every warm run of the witness fixture: tree-hashes=3): the door verifies at each stage's start and end, and each
1376
+ // verify walked and hashed the snapshot again although the check's own verify of the same directory took the resident gate's proof. When
1377
+ // nothing beyond the commit is admitted (no ledger entry to match) and no environment is asked for, the resident gate's answer is the same
1378
+ // proof as in snapshot-check.mjs verifySnapshotDir: this directory was proven to be exactly this tree and nothing under it changed since.
1379
+ // Clean means no stage output exists, so the admitted ledger is empty. Any doubt (no resident gate, another tree, a change) is the full verify.
1380
+ const nothingAdmitted = (ledger === undefined || (Array.isArray(ledger) && ledger.length === 0)) && environment === undefined;
1381
+ let residentGeneration = null;
1382
+ // Asked in every case: with outputs admitted the answer is never "nothing changed", but it still says what changed since the tree was proven.
1383
+ const c = noteChangeSource(resident({ op: "check", dir: at, tree }, { root: path.dirname(path.resolve(at)) }));
1384
+ if (nothingAdmitted && c?.clean === true) { SNAPSHOT_PROOF_COUNTS.residentProofs += 1; return { schema: SNAPSHOT_SCHEMA, path: at, repoKey: repo.key, commit, tree, ...(ledger !== undefined || admitNew ? { ledger: [] } : {}) }; }
1385
+ if (Number.isInteger(c?.generation)) residentGeneration = c.generation;
1316
1386
  // The seeded tree id cannot see an ignored file or follow a link, so the directory itself is walked first (E6, §1 exact snapshot).
1317
- const inspected = snapshotProblem({ dir: at, entries: treeEntries(repo.checkout, commit), checkout: repo.checkout, commit, ledger, admitNew });
1387
+ const entries = treeEntries(repo.checkout, commit);
1388
+ const inspected = snapshotProblem({ dir: at, entries, checkout: repo.checkout, commit, ledger, admitNew });
1318
1389
  const extra = ledger !== undefined || admitNew ? inspected.problem : inspected;
1319
1390
  if (extra) throw new SnapshotError("mismatch", `the snapshot at ${at} is not exactly commit ${commit}${ledger !== undefined || admitNew ? " plus its stage-output ledger" : ""}: ${extra}`);
1320
- const actual = snapshotTree({ checkout: repo.checkout, dir: at, baseTree: tree, repo });
1391
+ // NN11: the walk passed. When the open gate process knows what changed since this tree was proven, only the commit's files those changes
1392
+ // could have touched are compared (treeProvenByChanges); otherwise the tree is hashed.
1393
+ const actual = treeProvenByChanges({ reply: c, dir: at, tree, entries }) ? tree : snapshotTree({ checkout: repo.checkout, dir: at, baseTree: tree, repo });
1321
1394
  if (actual !== tree) throw new SnapshotError("mismatch", `the snapshot at ${at} is tree ${actual}, not tree ${tree} of commit ${commit}`);
1395
+ // "record" (exactly this tree, nothing else) only after a verify that could admit nothing: no ledger, no admitNew, no environment. A walk
1396
+ // with a ledger, even an empty one, passes over an ignored empty directory without listing it (inspectSnapshot), which a plain walk
1397
+ // refuses; so its proof is "tree-record": the commit's files are this tree, which is what a later proof starts from (review 2026-11-19).
1398
+ if (residentGeneration !== null) resident({ op: ledger === undefined && admitNew !== true && environment === undefined ? "record" : "tree-record", dir: at, tree, generation: residentGeneration });
1322
1399
  if (environment !== undefined) {
1323
1400
  if (!environment || !/^[0-9a-f]{64}$/.test(String(environment.expected ?? "")) || typeof environment.compute !== "function") throw new SnapshotError("error", "verify with an environment needs { expected: <64 hex env digest>, compute: <function> }");
1324
1401
  let now;
package/spawn-ledger.mjs CHANGED
@@ -7,6 +7,24 @@ import childProcess from "node:child_process";
7
7
  import fs from "node:fs";
8
8
  import module from "node:module";
9
9
 
10
+ /**
11
+ * A Windows shell-shim start as the process it really starts: `cmd.exe /d /s /c ""<shim>" <args>"` (the only form the gate
12
+ * builds, deterministic-scans.mjs resolveInvocation: every argument matched SAFE_SHIM_ARG, so none holds a space and the
13
+ * split is exact) records as `<shim>` with its arguments, so the acceptance judges see the rustright/cargo/pnpm start the
14
+ * shim carried instead of an opaque cmd.exe string (NN40 saw no `cargo doc` start on Dell although six ran, run
15
+ * muse-fulldev-4). Anything else is returned unchanged. Exported for its test.
16
+ */
17
+ export function unwrapCmdShim(cmd, args) {
18
+ if (!/(^|[\\/])cmd\.exe$/i.test(String(cmd)) || !Array.isArray(args)) return { cmd: String(cmd), args };
19
+ const at = args.findIndex((a) => /^\/c$/i.test(String(a)));
20
+ if (at < 0 || at + 1 >= args.length) return { cmd: String(cmd), args };
21
+ let line = String(args[at + 1]);
22
+ if (line.startsWith('""') && line.endsWith('"') && line.length >= 3) line = line.slice(1, -1);
23
+ const m = /^"([^"]+)"(?:\s+(.*))?$/.exec(line) ?? /^(\S+)(?:\s+(.*))?$/.exec(line);
24
+ if (!m) return { cmd: String(cmd), args };
25
+ return { cmd: m[1], args: m[2] ? m[2].split(/\s+/).filter(Boolean) : [] };
26
+ }
27
+
10
28
  let installed = false;
11
29
 
12
30
  /** Patch node:child_process once so every caller (default or named import) is recorded. No-op without RK_GATE_SPAWN_LEDGER. */
@@ -16,9 +34,10 @@ export function installSpawnLedger(env = process.env) {
16
34
  installed = true;
17
35
  const write = (entry) => { try { fs.appendFileSync(file, `${JSON.stringify(entry)}\n`); } catch { /* the ledger never fails a run */ } };
18
36
  const describe = (cmd, args, options) => {
19
- const argv = Array.isArray(args) ? args.map(String) : [];
37
+ const raw = Array.isArray(args) ? args.map(String) : [];
38
+ const { cmd: logical, args: argv } = unwrapCmdShim(cmd, raw);
20
39
  const opts = Array.isArray(args) ? options : args;
21
- return { cmd: String(cmd), args: argv.join("\u0000").length > 4000 ? [...argv.slice(0, 40), `... ${argv.length} args`] : argv, cwd: typeof opts?.cwd === "string" ? opts.cwd : process.cwd() };
40
+ return { cmd: logical, args: argv.join("\u0000").length > 4000 ? [...argv.slice(0, 40), `... ${argv.length} args`] : argv, cwd: typeof opts?.cwd === "string" ? opts.cwd : process.cwd() };
22
41
  };
23
42
  for (const name of ["spawnSync", "execFileSync", "execSync"]) {
24
43
  const orig = childProcess[name];