@rightkit/release 0.6.51 → 0.6.54

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 (89) hide show
  1. package/README.md +1 -1
  2. package/adapter-env.mjs +16 -105
  3. package/admission-host.mjs +14 -1
  4. package/bin/darwin/rightkit-swap +0 -0
  5. package/bin/rightkit-gate.mjs +609 -404
  6. package/broker-admission.mjs +122 -2
  7. package/build-launch.mjs +52 -58
  8. package/build-release.mjs +2 -2
  9. package/cargo-ledger.mjs +24 -5
  10. package/cargo-target-shim.mjs +54 -23
  11. package/cargo-target.mjs +2 -2
  12. package/carried-adapter-run.mjs +7 -8
  13. package/carried-cargo-run.mjs +1 -1
  14. package/ci-compile-admission.mjs +1 -1
  15. package/clippy-route.mjs +65 -18
  16. package/compile-inputs.mjs +91 -15
  17. package/cross-targets.mjs +5 -3
  18. package/deps-cargo-lock.mjs +1 -1
  19. package/deterministic-scans.mjs +789 -259
  20. package/development.mjs +33 -7
  21. package/direct-receipt.mjs +3 -5
  22. package/feature-coverage.mjs +45 -9
  23. package/feature-partition.mjs +204 -0
  24. package/feature-sets.mjs +113 -0
  25. package/gate-acceptance.mjs +187 -115
  26. package/gate-seam.mjs +352 -0
  27. package/gate-serve.mjs +34 -2
  28. package/gate-stages.mjs +6 -2
  29. package/ghsa-audit.mjs +19 -4
  30. package/heavy-command.mjs +5 -4
  31. package/install-tauri-authenticode.mjs +73 -4
  32. package/ios-dev.mjs +3 -3
  33. package/ios-package-recipe.mjs +6 -6
  34. package/linux-setup.mjs +3 -2
  35. package/local-publish.mjs +113 -17
  36. package/lock-identity.mjs +24 -100
  37. package/managed-cargo.mjs +3 -3
  38. package/managed-root-guard.mjs +2 -2
  39. package/managed-roots.mjs +3 -3
  40. package/native-adapters.mjs +41 -244
  41. package/native-helpers.mjs +1 -1
  42. package/pack-digest.mjs +1 -1
  43. package/package-recipe-targets.mjs +3 -3
  44. package/package.json +2 -2
  45. package/publication-gate.mjs +29 -6
  46. package/publish-cargo.mjs +4 -5
  47. package/publish-local-cargo.mjs +77 -1
  48. package/qualification-verify.mjs +76 -49
  49. package/receipt-signature.mjs +104 -0
  50. package/release-switch-registry.json +4 -0
  51. package/release-switch-scan.mjs +13 -10
  52. package/rightkit-versions.json +126 -113
  53. package/scan-digest.mjs +43 -14
  54. package/seam-broker.mjs +168 -0
  55. package/snapshot-check.mjs +4 -1
  56. package/snapshot-dependency-reuse.mjs +1 -1
  57. package/snapshot-metadata.mjs +24 -35
  58. package/snapshot.mjs +328 -49
  59. package/stage-commands.mjs +59 -5
  60. package/stage-ledger.mjs +2 -2
  61. package/{carried-cargo.mjs → stage-seam.mjs} +118 -70
  62. package/stage-sidecar.mjs +3 -3
  63. package/tauri-bundle-marker.mjs +5 -2
  64. package/tauri-locked.mjs +1 -1
  65. package/tool-build.mjs +8 -6
  66. package/unit-gate.mjs +40 -10
  67. package/web-build.mjs +6 -0
  68. package/broker-handshake.mjs +0 -160
  69. package/broker-wire.mjs +0 -278
  70. package/build-ownership.mjs +0 -1578
  71. package/cargo-shapes.mjs +0 -332
  72. package/cargo-width.mjs +0 -49
  73. package/carrier-census.mjs +0 -124
  74. package/clippy-equivalence.mjs +0 -202
  75. package/freshness-census.mjs +0 -405
  76. package/handle-revocation.mjs +0 -100
  77. package/handle-revocation.rust-vector.json +0 -1
  78. package/handle-revocation.vectors.json +0 -53
  79. package/legion-freeze-consumer.mjs +0 -241
  80. package/linux-qualifier.mjs +0 -83
  81. package/native-tool-planning.mjs +0 -94
  82. package/owner-process-proof.mjs +0 -14
  83. package/ownership-mark.mjs +0 -191
  84. package/ownership-recover.mjs +0 -78
  85. package/pnpm-adapter-grammar.mjs +0 -226
  86. package/provenance-verify.mjs +0 -413
  87. package/snapshot-broker.mjs +0 -808
  88. package/snapshot-request.mjs +0 -722
  89. package/unit-list-compile.mjs +0 -356
@@ -0,0 +1,168 @@
1
+ // The seam's one broker control query from the gate side (reset plan section 3): where the broker listens and what identity a query carries, and the
2
+ // reclaim judge built on it, and the broker protocol name and runtime identity the control query carries. It imports only kept modules.
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { resolveBrokerClient } from "./broker-client.mjs";
6
+ import { discoverBrokerSocket } from "./managed-roots.mjs";
7
+ import { CLASS_A_ENV, CLASS_A_VERDICT_SCHEMA, GATE_COMMIT_ENV, classAVerdict, judgeSeamOutcome, seamSettled, snapshotStatusAllowsReclaim, snapshotStatusMessage, snapshotStatusSync, writeClassAVerdict } from "./gate-seam.mjs";
8
+ import { spawnSync as nodeSpawnSync } from "node:child_process";
9
+
10
+ /** `rustright_protocol::BUILD_CONTROL_PROTOCOL`: carried in every request envelope, the seam's SNAPSHOT_STATUS query included. */
11
+ export const BUILD_CONTROL_PROTOCOL = "rustright.build-control.client.v2";
12
+ /** The runtime manifest beside the installed client, whose identity every control request carries. */
13
+ export const RUNTIME_MANIFEST_FILE = "runtime-manifest.json";
14
+ /** The id of the client's own health probe (`rustright-cli` doctor: PROBE_ID), a by-id STATUS the front gate answers; the declared Linux route reads the answering roots with it. */
15
+ export const HANDSHAKE_PROBE_ID = "runtime-health-probe";
16
+ export const RUNTIME_MANIFEST_SCHEMA = "rustright.build-control.runtime.v2";
17
+ const LEGACY_RUNTIME_MANIFEST_SCHEMA = "rightkit.build-control.runtime.v2";
18
+ const isDigest = (v) => typeof v === "string" && /^[0-9a-f]{64}$/.test(v);
19
+
20
+ /** The runtime identity of a parsed object (`schema` current or legacy, a version, both digests lowercase 64-hex), as RustRight's `RuntimeIdentity::new` validates it; else null. */
21
+ export function normalizeRuntimeIdentity(raw) {
22
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw) || ![RUNTIME_MANIFEST_SCHEMA, LEGACY_RUNTIME_MANIFEST_SCHEMA].includes(raw.schema) || typeof raw.version !== "string" || raw.version === "" || !isDigest(raw.clientDigest) || !isDigest(raw.brokerDigest)) return null;
23
+ return { schema: RUNTIME_MANIFEST_SCHEMA, version: raw.version, clientDigest: raw.clientDigest, brokerDigest: raw.brokerDigest };
24
+ }
25
+
26
+ /** The runtime identity a `runtime-manifest.json` text holds: `{ ok: true, identity }` or `{ ok: false, problem }`. */
27
+ export function parseRuntimeIdentity(text) {
28
+ let doc;
29
+ try { doc = JSON.parse(text); } catch { return { ok: false, problem: "the runtime manifest is not JSON" }; }
30
+ const identity = normalizeRuntimeIdentity(doc);
31
+ return identity ? { ok: true, identity } : { ok: false, problem: "the runtime manifest is not a runtime identity (schema, version, clientDigest and brokerDigest are required)" };
32
+ }
33
+
34
+ /** Whether an environment carries the seam (both variables set): a stage child's adapter call then goes through the seam, never the carrier. */
35
+ export function seamEnvPresent(env) {
36
+ return Boolean(env && typeof env[GATE_COMMIT_ENV] === "string" && /^[0-9a-f]{40}$/.test(env[GATE_COMMIT_ENV]) && typeof env[CLASS_A_ENV] === "string" && path.isAbsolute(env[CLASS_A_ENV]));
37
+ }
38
+
39
+ /**
40
+ * One seam call from a stage child (reset plan section 3), synchronous like the step that makes it: `<client> <argv>` in `cwd` with the inherited
41
+ * environment (the two seam variables already in it). The result line and the durable receipt are judged exactly as a class B row's
42
+ * (judgeSeamOutcome); the tree is not compared, since a stage child knows only the commit. The returned status is never 0 unless the judge passed
43
+ * (a child exiting 0 whose receipt fails its check is a failure). `ledger` is the record the caller files for its parent: `status` "verified"
44
+ * (passed), "refused" (refused before admission), "failed" (executed and failed) or "unsettled" (no settled outcome: no or a bad result line,
45
+ * no durable receipt, a client failure after admission, a spawn error); `settled` is the positive evidence the door's lock release needs.
46
+ */
47
+ function runSeamCall(argv, { cwd, env, stdio = "pipe", client = "rustright", spawnSync = nodeSpawnSync, maxBuffer = 1 << 28, fsApi = fs }) {
48
+ const isAdapter = argv[0] === "run";
49
+ const expect = { argv: isAdapter ? argv.slice(3) : argv.slice(1), cwd, adapter: isAdapter ? argv[1] : null };
50
+ if (!seamEnvPresent(env)) throw new TypeError("seam call: the environment carries no seam (RUSTRIGHT_GATE_COMMIT and RUSTRIGHT_CLASS_A)");
51
+ // The broker binds the verdict's workspace to this call's own directory (rustright gate_admission.rs passing_class_a: workspace == cwd relative to the snapshot). The
52
+ // stage hands the root verdict of its scope; a call made in another directory names that directory's verdict, derived from it (fresh review of badf93c, D1).
53
+ let classA;
54
+ try { classA = verdictForCwd(env, cwd, { fsApi }); }
55
+ catch (error) { const message = `the Class A verdict for ${cwd} cannot be named (${error.message}); nothing was submitted`; return { result: { status: 125, signal: null, stdout: "", stderr: `rightkit-gate: RK_SEAM_VERDICT: ${message}\n`, error: null, refusal: { code: "RK_SEAM_VERDICT", message } }, ledger: { status: "refused", settled: true, code: "RK_SEAM_VERDICT", message } }; }
56
+ env = { ...env, [CLASS_A_ENV]: classA };
57
+ const r = spawnSync(client, argv, { cwd, env, stdio: stdio === "inherit" ? ["ignore", "inherit", "pipe"] : "pipe", encoding: "utf8", maxBuffer });
58
+ if (r.error) return { result: { status: 1, signal: null, stdout: "", stderr: String(r.error.message ?? r.error), error: r.error, refusal: { code: "SPAWN_ERROR", message: String(r.error.message ?? r.error) } }, ledger: { status: "unsettled", settled: false, code: "SPAWN_ERROR" } };
59
+ const judged = judgeSeamOutcome({ child: r, stderr: r.stderr ?? "", commit: env[GATE_COMMIT_ENV], tree: null, classA, expect });
60
+ const pass = judged.status === "pass";
61
+ const preAdmissionRefusal = Boolean(judged.result) && !judged.evidence && judged.receiptRead !== true && judged.result.requestId === null;
62
+ const settled = seamSettled(judged);
63
+ const status = pass ? (r.status ?? 0) : (Number.isInteger(r.status) && r.status !== 0 ? r.status : (preAdmissionRefusal ? 125 : 1));
64
+ const evidence = judged.evidence ? { outputDir: judged.evidence.outputDir, targetTriple: judged.evidence.targetTriple, requestId: judged.evidence.requestId, receipt: judged.evidence.receiptPath, receiptSha256: judged.evidence.receiptSha256 } : {};
65
+ return {
66
+ result: { status, signal: r.signal ?? null, stdout: r.stdout ?? "", stderr: r.stderr ?? "", error: null, ...evidence, ...(pass ? {} : { refusal: { code: judged.code, message: judged.detail } }) },
67
+ ledger: { status: pass ? "verified" : !settled ? "unsettled" : preAdmissionRefusal ? "refused" : "failed", settled, ...(pass ? {} : { code: judged.code, message: String(judged.detail ?? "").slice(0, 2000) }), ...evidence },
68
+ };
69
+ }
70
+
71
+ /**
72
+ * The Class A verdict a seam call from `cwd` names: the verdict the environment hands (the root verdict of the door's scope) when its workspace is already `cwd`'s, else
73
+ * the verdict of `cwd`'s snapshot-relative directory derived from it (same commit, tree, repository, scans and scope; gate-seam.mjs verdictForRun derives a nested
74
+ * workspace's verdict the same way). The snapshot is the ancestor of `cwd` named by the verdict's repository key, under the same data root as the verdict directory
75
+ * (`<data>/<snapshots>/<repoKey>` beside `<data>/class-a-verdicts`). A verdict that cannot be read, or is not a passing root verdict of this commit, is returned as handed: the broker refuses it.
76
+ */
77
+ export function verdictForCwd(env, cwd, { fsApi = fs } = {}) {
78
+ const file = env[CLASS_A_ENV];
79
+ let v; try { v = JSON.parse(fsApi.readFileSync(file, "utf8")); } catch { return file; } // unreadable: the broker refuses it (RK_CLASS_A_INVALID), with its own code
80
+ if (v?.schema !== CLASS_A_VERDICT_SCHEMA || v.status !== "pass" || v.commit !== env[GATE_COMMIT_ENV] || v.workspace !== "." || typeof v.repoKey !== "string") return file;
81
+ const real = (p) => { try { return fsApi.realpathSync.native(p); } catch { return path.resolve(p); } };
82
+ const dataRoot = real(path.dirname(path.dirname(file)));
83
+ let at = real(cwd); let snapshot = null;
84
+ for (;;) {
85
+ if (path.basename(at) === v.repoKey && path.dirname(path.dirname(at)) === dataRoot) { snapshot = at; break; }
86
+ const up = path.dirname(at); if (up === at) break; at = up;
87
+ }
88
+ if (!snapshot) throw new Error(`${cwd} is not inside the snapshot of repository ${v.repoKey} under ${dataRoot}`);
89
+ const rel = path.relative(snapshot, real(cwd)).split(path.sep).filter(Boolean).join("/");
90
+ const ws = rel || ".";
91
+ if (ws === ".") return file;
92
+ return writeClassAVerdict(path.dirname(file), classAVerdict({ commit: v.commit, tree: v.tree, repoKey: v.repoKey, workspace: ws, scans: v.scans, scope: v.scope ?? "full" }), { fsApi });
93
+ }
94
+
95
+ /** One adapter run through the seam from a stage child: `rustright run <adapter> -- <args>`. Returns `{ result, ledger }` (runSeamCall). */
96
+ export function runSeamAdapterCall(adapter, args, options = {}) {
97
+ if (typeof adapter !== "string" || !/^[a-z][a-z0-9-]*$/.test(adapter)) throw new TypeError(`runSeamAdapter: ${JSON.stringify(adapter)} is not an adapter id`);
98
+ return runSeamCall(["run", adapter, "--", ...args], options);
99
+ }
100
+ /** One cargo call through the seam from a stage child: `rustright cargo <words>`. Returns `{ result, ledger }` (runSeamCall). */
101
+ export function runSeamCargoCall(words, options = {}) { return runSeamCall(["cargo", ...words], options); }
102
+
103
+ /** The spawnSync-shaped result of one seam adapter run (runSeamAdapterCall without the ledger record). */
104
+ export function runSeamAdapter(adapter, args, options = {}) {
105
+ if (!seamEnvPresent(options.env ?? process.env)) throw new TypeError("runSeamAdapter: the environment carries no seam (RUSTRIGHT_GATE_COMMIT and RUSTRIGHT_CLASS_A)");
106
+ return runSeamAdapterCall(adapter, args, { ...options, env: options.env ?? process.env, cwd: options.cwd ?? process.cwd() }).result;
107
+ }
108
+
109
+ const isPipe = (endpoint) => /^\\\\\.\\pipe\\/i.test(String(endpoint));
110
+
111
+ /**
112
+ * Where a control query to the broker goes and what identity it carries: the endpoint RustRight's discovery names (a user-owned socket, or a pipe) and the
113
+ * runtime identity of the manifest beside the installed `client`. `{ ok, endpoint, identity }` or `{ ok: false, problem }`.
114
+ */
115
+ export function brokerControlTarget(o, { client = o?.client } = {}) {
116
+ const platform = o?.platform ?? process.platform;
117
+ const env = o?.env ?? process.env;
118
+ const read = o?.readFile ?? ((file) => fs.readFileSync(file, "utf8"));
119
+ if (typeof client !== "string" || !client) return { ok: false, problem: "the RustRight client is not on PATH, so its runtime identity cannot be read" };
120
+ let exe;
121
+ try { exe = resolveBrokerClient(client, { platform, readFile: read }).file; } catch (error) { return { ok: false, problem: `the RustRight client cannot be resolved (${error.message})` }; }
122
+ let real = exe;
123
+ if (platform !== "win32") { try { real = (o?.realpath ?? fs.realpathSync.native)(exe); } catch { real = exe; } }
124
+ const paths = platform === "win32" ? path.win32 : path.posix;
125
+ const manifest = paths.join(paths.dirname(real), RUNTIME_MANIFEST_FILE);
126
+ let text;
127
+ try { text = read(manifest); } catch (error) { return { ok: false, problem: `cannot read the runtime manifest ${manifest} beside the client (${error?.message ?? error})` }; }
128
+ const identity = parseRuntimeIdentity(text);
129
+ if (!identity.ok) return { ok: false, problem: `${manifest}: ${identity.problem}` };
130
+ let endpoint;
131
+ try { endpoint = (o?.discoverEndpoint ?? discoverBrokerSocket)(env, { platform, exists: fs.existsSync }); } catch (error) { return { ok: false, problem: `the broker endpoint cannot be discovered (${error.message})` }; }
132
+ if (!endpoint) return { ok: false, problem: "no broker endpoint is configured (no explicit socket variable and no broker.sock under a managed control root)" };
133
+ if (platform !== "win32" && !isPipe(endpoint)) {
134
+ try {
135
+ const stat = (o?.lstat ?? fs.lstatSync)(endpoint);
136
+ const uid = typeof (o?.uid ?? process.getuid?.()) === "number" ? (o?.uid ?? process.getuid()) : null;
137
+ if (!stat.isSocket()) return { ok: false, problem: `${endpoint} is not a socket, so it is not the broker's endpoint` };
138
+ if (uid !== null && stat.uid !== uid) return { ok: false, problem: `${endpoint} is owned by another user (uid ${stat.uid}), so it is not this user's broker` };
139
+ } catch (error) { return { ok: false, problem: `cannot connect to the broker at ${endpoint} (${error?.code ?? error?.message ?? error})` }; }
140
+ }
141
+ return { ok: true, endpoint, identity: identity.identity };
142
+ }
143
+
144
+ /**
145
+ * The seam's reclaim judge (snapshot.mjs acquireSnapshotLock `judge`): asks the broker SNAPSHOT_STATUS for the dead holder's lock and returns true only on
146
+ * an exact IDLE echo. Everything it needs is bound here, at construction, from values that exist at that moment (`o`, the resolved `client`, the snapshot
147
+ * path): nothing is read from an outer scope at call time (two closure bugs of 2026-11-09 read a const that was out of scope or not yet initialized, and the
148
+ * catch turned them into "no proof"). `query` is injectable for tests; the default crosses the real socket.
149
+ */
150
+ /**
151
+ * How long the reclaim judge waits for the broker's SNAPSHOT_STATUS. The broker answers it from a census of every durable completion proof
152
+ * (about 20k on the Mac, 2026-11-09): a direct query answered IDLE in 8.1 s and the former 10 s deadline read as "no proof", which kept a dead
153
+ * holder's lock for good (rightkit#1548). Bounded, never retried: a deadline is still no proof.
154
+ */
155
+ export const RECLAIM_QUERY_MS = 60_000;
156
+ export function snapshotReclaimJudge({ o, client, snapshotPath, query = snapshotStatusSync, timeoutMs = RECLAIM_QUERY_MS }) {
157
+ if (typeof snapshotPath !== "string" || !path.isAbsolute(snapshotPath)) throw new TypeError("snapshotReclaimJudge: snapshotPath must be absolute");
158
+ const bound = { o, client: typeof client === "string" && client ? client : null, snapshotPath };
159
+ return (holder) => {
160
+ try {
161
+ if (!bound.client) return false;
162
+ const target = brokerControlTarget(bound.o, { client: bound.client });
163
+ if (!target.ok) return false;
164
+ const message = snapshotStatusMessage({ protocol: BUILD_CONTROL_PROTOCOL, runtime: target.identity, snapshot: bound.snapshotPath, owner: holder });
165
+ return snapshotStatusAllowsReclaim(query({ endpoint: target.endpoint, message, timeoutMs }), { snapshot: bound.snapshotPath, owner: holder });
166
+ } catch { return false; }
167
+ };
168
+ }
@@ -428,11 +428,14 @@ export function verifySnapshotStore({ checkout, snapshot, commit, tree, ledger,
428
428
  if (!version) throw new CheckError("pnpm is not runnable on this host; the snapshot's dependencies cannot be checked against the store");
429
429
  if (pin && version !== pin) throw new CheckError(`pnpm ${version} is on PATH, but root ${root} of the commit pins pnpm@${pin} (packageManager); install the pinned pnpm`);
430
430
  fs.mkdirSync(tmpRoot, { recursive: true });
431
+ // Both the virtual store and the modules directory are throwaway: pnpm 12.16.1 prunes the root's own node_modules when only
432
+ // --virtual-store-dir points elsewhere, which emptied the snapshot's installed dependencies (the exports import probe then
433
+ // could not resolve smol-toml).
431
434
  const virtualStore = fs.mkdtempSync(path.join(tmpRoot, "rightkit-store-check-"));
432
435
  const started = now();
433
436
  let r;
434
437
  try {
435
- r = spawn("pnpm", ["fetch", "--offline", "--ignore-scripts", "--ignore-pnpmfile", "--store-dir", storeDir, "--virtual-store-dir", path.join(virtualStore, ".pnpm"), "--config.enable-global-virtual-store=false", "--reporter", "append-only"], {
438
+ r = spawn("pnpm", ["fetch", "--offline", "--ignore-scripts", "--ignore-pnpmfile", "--store-dir", storeDir, "--virtual-store-dir", path.join(virtualStore, ".pnpm"), "--modules-dir", path.join(virtualStore, "node_modules"), "--config.enable-global-virtual-store=false", "--reporter", "append-only"], {
436
439
  cwd: dir, env: { ...env, COREPACK_ENABLE_AUTO_PIN: "0", CI: "true" }, maxBuffer: 1 << 28,
437
440
  });
438
441
  } catch (error) { r = { error }; } finally { fs.rmSync(virtualStore, { recursive: true, force: true }); }
@@ -165,7 +165,7 @@ function pnpmConfigIdentity({ dir, env, spawn }) {
165
165
  export function preparationInputComponents({ source, toolchain, config, store, env }) {
166
166
  // The per-run ownership handle is a gate lock token, not pnpm input. Keep
167
167
  // every other non-scheduling variable, including the ownership file path.
168
- const excluded = new Set(['RK_GATE_JOBS', 'RK_GATE_TEST_JOBS', 'RK_GATE_CLASS_B_JOBS', 'RIGHTKIT_BUILD_OWNERSHIP']);
168
+ const excluded = new Set(['RK_GATE_JOBS', 'RK_GATE_CLASS_B_JOBS', 'RIGHTKIT_BUILD_OWNERSHIP']);
169
169
  const environment = Object.entries(env).filter(([name]) => !excluded.has(name)).sort(([a], [b]) => a.localeCompare(b));
170
170
  return Object.fromEntries(Object.entries({ source, toolchain, config, store, environment }).map(([name, value]) => [name, hash(JSON.stringify(value))]));
171
171
  }
@@ -3,11 +3,10 @@
3
3
  // RustRight refuses a ROOT request whose workspace is inside a managed snapshot ("a root request cannot run inside a managed snapshot",
4
4
  // rustright job_service/service.rs). The gate reads the snapshot's Cargo metadata to discover units, and every Class A Cargo scan of a
5
5
  // snapshot (metadata, fetch, cargo-deny, cargo-audit) reads the snapshot too, never the primary checkout (docs/GATE-CONTRACT.md: no
6
- // dirty-tree condition; class A for a build reads the snapshot). So on a broker host each such call is a CARRIED read-only request: the
7
- // same carrier, nonce, signed-receipt verification and ownership mark as every other carried call (snapshot-broker.mjs carryBrokerCargo).
8
- // The broker admits a carried call that compiles nothing only for the exact shapes below (rustright_policy::command_policy::
9
- // snapshot_read_only). This module carries exactly those and refuses every other call inside the snapshot with RK_SNAPSHOT_CARRIED_REFUSED,
10
- // never running it as a root request.
6
+ // dirty-tree condition; class A for a build reads the snapshot). So on a broker host each such call runs DIRECTLY with the host's toolchain cargo
7
+ // (GATE-CONTRACT GC-A11, directReadSpawn below), never as a broker request; the exact read-only shapes below (the broker's snapshot_read_only
8
+ // shapes, rustright_policy::command_policy) are the only ones, and every other call inside the snapshot is refused with RK_SNAPSHOT_CARRIED_REFUSED,
9
+ // never run as a root request.
11
10
  //
12
11
  // cargo metadata [--no-deps] [--locked] [--frozen] [--offline] [--format-version 1] (with dependencies: --locked or --frozen)
13
12
  // cargo fetch --locked
@@ -19,7 +18,8 @@
19
18
  // the database directory audit reads are absolute, exist (a file; a directory) and lie outside the live checkout.
20
19
  import fs from "node:fs";
21
20
  import path from "node:path";
22
- import { BROKER_REFUSAL_STATUS, brokerSection, carryBrokerCargo } from "./snapshot-broker.mjs";
21
+ import { CARGO_REFUSAL_STATUS } from "./cargo-ledger.mjs";
22
+ import { GATE_COMMIT_ENV } from "./gate-seam.mjs";
23
23
 
24
24
  export const CARRIED_METADATA_REFUSED = "RK_SNAPSHOT_CARRIED_REFUSED";
25
25
 
@@ -89,39 +89,25 @@ export function carriedScanRefusal(words, { checkout = null } = {}) {
89
89
  const shapeOk = rest[0] === "-p" && typeof unit === "string" && unit !== "" && !unit.startsWith("-") && new Set(tail).size === tail.length && tail.every((w) => ["--list", "--locked", "--allow-dirty"].includes(w)) && tail.includes("--list") && tail.includes("--locked");
90
90
  return shapeOk ? null : "`package` is admitted as `package -p <unit> --list --locked [--allow-dirty]` only";
91
91
  }
92
- return `\`cargo ${words.join(" ")}\` is not one of the carried read-only shapes (metadata, fetch --locked, deny, audit --db --no-fetch, fmt --check, package -p <unit> --list --locked)`;
92
+ // The feature-equivalence partition's read (feature-partition.mjs treeArgs; GC-A18): resolves features, compiles nothing, writes only to the scratch target it is given.
93
+ if (sub === "tree") {
94
+ const own = []; let packages = 0; let targets = 0;
95
+ for (let i = 0; i < rest.length; i += 1) {
96
+ const w = rest[i]; const v = rest[i + 1];
97
+ if (w === "-p") { if (typeof v !== "string" || !/^[A-Za-z0-9_-]+$/.test(v)) return "`tree` takes -p <crate> with a plain crate name"; packages += 1; i += 1; }
98
+ else if (w === "--target") { if (typeof v !== "string" || !/^[A-Za-z0-9_-]+$/.test(v)) return "`tree` takes --target <triple> with a plain triple"; targets += 1; i += 1; }
99
+ else own.push(w);
100
+ }
101
+ const f = flagsOf(own, { "--locked": "flag", "--prefix": "value", "-e": "value", "-f": "value", "--all-features": "flag", "--no-default-features": "flag", "--features": "value", "-F": "value" });
102
+ const shapeOk = f !== null && f.has("--locked") && f.get("--prefix") === "none" && ["normal,build", "normal,build,dev"].includes(f.get("-e") ?? "") && f.get("-f") === "{p}\t{f}" && packages >= 1 && targets <= 1;
103
+ return shapeOk ? null : "`tree` is admitted as `tree --locked --prefix none -e normal,build[,dev] -f '{p}<tab>{f}' [--all-features] [--no-default-features] [--features <list>] [--target <triple>] -p <crate>...` only (the feature-equivalence partition)";
104
+ }
105
+ return `\`cargo ${words.join(" ")}\` is not one of the carried read-only shapes (metadata, fetch --locked, deny, audit --db --no-fetch, fmt --check, package -p <unit> --list --locked, tree)`;
93
106
  }
94
107
 
95
108
  /** Whether the broker admits `words` as a carried read-only request (see carriedScanRefusal). */
96
109
  export const carriedReadOnlyScan = (words, options) => carriedScanRefusal(words, options) === null;
97
110
 
98
- /**
99
- * A `spawn(cmd, args, opts)` for the gate's Cargo calls in `snapshotRoot` on a broker host. A call to `cargoCommand` whose cwd is inside the
100
- * snapshot becomes one carried read-only request (capture mode, a spawnSync-shaped result; `status` is non-zero when the call was refused or
101
- * its signed receipt did not verify). Any other call passes to `spawn` unchanged (git, and Cargo in the primary checkout).
102
- * `broker()` returns the gate's snapshot broker (built once); `records` collects each call's ledger record. `carrySpawn` (default `spawn`) is
103
- * the synchronous spawn that starts the RustRight client and reads its receipt; `spawn` may be asynchronous for the pass-through calls.
104
- */
105
- export function snapshotCargoSpawn({ spawn, carrySpawn = spawn, cargoCommand, snapshotRoot, broker, env, err = () => {}, records = [] }) {
106
- const prefix = cargoCommand.slice(1);
107
- const refused = (code, message) => { err(`rightkit-gate: ${code}: ${message}`); return { status: BROKER_REFUSAL_STATUS, signal: null, error: null, stdout: "", stderr: `rightkit-gate: ${code}: ${message}\n` }; };
108
- return (cmd, args, opts = {}) => {
109
- const cargo = cmd === cargoCommand[0] && prefix.every((w, i) => args[i] === w);
110
- if (!cargo || typeof opts.cwd !== "string" || !within(real(opts.cwd), real(snapshotRoot))) return spawn(cmd, args, opts);
111
- const words = args.slice(prefix.length);
112
- const shape = carriedScanRefusal(words);
113
- if (shape !== null) return refused(CARRIED_METADATA_REFUSED, `\`cargo ${words.join(" ")}\` would run inside the managed snapshot ${snapshotRoot}, and the broker admits only the carried read-only shapes there (${shape}); it is never sent as a root request`);
114
- try {
115
- const sb = broker();
116
- // The named files are checked against the live checkout before anything is sent (absolute, existing, of the right kind, outside it).
117
- const placed = carriedScanRefusal(words, { checkout: sb.checkout });
118
- if (placed !== null) return refused(CARRIED_METADATA_REFUSED, `\`cargo ${words.join(" ")}\` names a path the broker would not admit (${placed}); it is not sent`);
119
- const r = carryBrokerCargo({ words, cwd: opts.cwd, env: { ...env, ...(opts.env ?? {}) }, section: brokerSection(sb), workspace: real(snapshotRoot), checkoutWorkspace: sb.checkout, record: (e) => records.push(e), spawn: carrySpawn, err, stdio: "capture" });
120
- return { status: r.status, signal: null, error: null, stdout: r.stdout, stderr: r.stderr };
121
- } catch (e) { return refused(e.code ?? "RK_SNAPSHOT_BROKER", e.message); }
122
- };
123
- }
124
-
125
111
  /**
126
112
  * GATE-CONTRACT GC-A11 (Adrian, 2026-11-02: "Class a never in the broker. Any cargo things that are cheap and non compiling are in class a,
127
113
  * can run outside the broker."): the same read-only shapes as above, run DIRECTLY with the host's real toolchain cargo, never carried to the
@@ -139,10 +125,13 @@ export function snapshotCargoSpawn({ spawn, carrySpawn = spawn, cargoCommand, sn
139
125
  */
140
126
  export function directReadSpawn({ spawn, cargoCommand, snapshotRoot, directPath, pathKey = "PATH", tmpRoot, env, err = () => {}, memo = null, isAsync = false }) {
141
127
  const prefix = cargoCommand.slice(1);
142
- const refused = (code, message) => { err(`rightkit-gate: ${code}: ${message}`); return { status: BROKER_REFUSAL_STATUS, signal: null, error: null, stdout: "", stderr: `rightkit-gate: ${code}: ${message}\n` }; };
128
+ const refused = (code, message) => { err(`rightkit-gate: ${code}: ${message}`); return { status: CARGO_REFUSAL_STATUS, signal: null, error: null, stdout: "", stderr: `rightkit-gate: ${code}: ${message}\n` }; };
143
129
  return (cmd, args, opts = {}) => {
144
130
  const cargo = cmd === cargoCommand[0] && prefix.every((w, i) => args[i] === w);
145
131
  if (!cargo || typeof opts.cwd !== "string" || !within(real(opts.cwd), real(snapshotRoot))) return spawn(cmd, args, opts);
132
+ // A seam request (reset plan section 3: RUSTRIGHT_GATE_COMMIT set) is a class B compile the broker admits; it runs in the snapshot by design and is never a
133
+ // class A direct read, so it goes to the declared client untouched (rightkit#1542: this wrapper refused every seam compile as "not a read-only shape").
134
+ if (opts.env && typeof opts.env[GATE_COMMIT_ENV] === "string" && opts.env[GATE_COMMIT_ENV]) return spawn(cmd, args, opts);
146
135
  const words = args.slice(prefix.length);
147
136
  const shape = words.length === 1 && words[0] === "--version" ? null : carriedScanRefusal(words);
148
137
  if (shape !== null) return refused(CARRIED_METADATA_REFUSED, `\`cargo ${words.join(" ")}\` would run inside the managed snapshot ${snapshotRoot} and is not one of the read-only shapes Class A runs directly (GC-A11): ${shape}`);