@rightkit/release 0.6.66 → 0.6.68

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.
@@ -59,9 +59,11 @@ const firstSubmission = (run) => Math.min(...run.jobs.map((j) => j.submitted).fi
59
59
 
60
60
  // ---- the checks one run can be given, whatever the case ---------------------------------------------------------------------------------------------------
61
61
  /** NN01, every run: each broker receipt verifies, names the selected commit and its tree, and says the snapshot was unchanged. */
62
- export function receiptsNameTheCommit(run) {
62
+ /** A job the broker refused before it started (no signed start, not a success) built nothing: a run killed under it leaves one (case 7 on 0.6.67). Skipped in the kill case only: anywhere else an unstarted refusal may be a job sent before Class A, which NN02 must see. */
63
+ export const neverRan = (j) => !Number.isFinite(j.started) && j.status !== "SUCCEEDED";
64
+ export function receiptsNameTheCommit(run, { skipNeverRan = false } = {}) {
63
65
  const fails = [];
64
- for (const j of run.jobs) {
66
+ for (const j of run.jobs.filter((x) => !(skipNeverRan && neverRan(x)))) {
65
67
  if (!j.verified) { fails.push(`${jobName(j)}: its receipt does not verify (${(j.problems ?? []).join("; ") || "no reason given"})`); continue; }
66
68
  if (j.gate?.commit !== run.commit) fails.push(`${jobName(j)} is signed for commit ${String(j.gate?.commit).slice(0, 12)}, not the selected ${String(run.commit).slice(0, 12)}`);
67
69
  if (!run.tree || j.gate?.tree !== run.tree) fails.push(`${jobName(j)} is signed for tree ${String(j.gate?.tree).slice(0, 12)}, not the selected commit's ${String(run.tree).slice(0, 12)}`);
@@ -70,8 +72,8 @@ export function receiptsNameTheCommit(run) {
70
72
  return fails;
71
73
  }
72
74
  /** NN02, a run that reached the broker: the Class A verdict file the receipts name is older than the first signed submission, and every Class A program ended before it. */
73
- export function classABeforeBroker(run) {
74
- const fails = []; if (!run.jobs.length) return ["no broker receipt exists, so the order of Class A and the first submission cannot be shown"];
75
+ export function classABeforeBroker(run, { skipNeverRan = false } = {}) {
76
+ const fails = []; if (skipNeverRan) { run = { ...run, jobs: run.jobs.filter((x) => !neverRan(x)) }; if (!run.jobs.length) return []; } else if (!run.jobs.length) return ["no broker receipt exists, so the order of Class A and the first submission cannot be shown"];
75
77
  const first = firstSubmission(run); if (!Number.isFinite(first)) return ["no broker receipt signs a usable start time and waits, so the first submission time is not known"];
76
78
  // Each job against the verdict file its own receipt names: that file, as the launcher lists it after the run, must be older than the job's signed submission.
77
79
  // A file written later was not this run's verdict when the job was sent (an older run's file of the same name was what the broker read).
@@ -174,7 +176,7 @@ const noCacheWrite = (run, label) => (!Array.isArray(run.cacheWritten) ? [`${lab
174
176
  const LINES = {
175
177
  // Only the selected commit is built.
176
178
  NN01(c, cases) {
177
- const fails = c.runs.flatMap(receiptsNameTheCommit);
179
+ const fails = c.runs.flatMap((r) => receiptsNameTheCommit(r, { skipNeverRan: c.id === 7 }));
178
180
  if (c.id === 1) fails.push(...passedRun(c.runs[0], "the run with an error planted in the checkout that the commit does not hold"));
179
181
  if (c.id === 5) c.runs.forEach((r, i) => fails.push(...failedRun(r, `run ${i + 1} of the commit that holds the error, with a clean checkout`)));
180
182
  return verdict(fails, c.id === 1 ? "an error in the checkout that is not in the commit did not fail the run, and every receipt names the selected commit and tree with the snapshot unchanged" : c.id === 5 ? "an error in the commit failed the run with a clean checkout" : `${c.runs.reduce((n, r) => n + r.jobs.length, 0)} receipt(s), each naming the selected commit and tree with the snapshot unchanged`);
@@ -182,7 +184,7 @@ const LINES = {
182
184
  // Class A finishes before anything goes to the broker. If it fails, nothing goes.
183
185
  NN02(c) {
184
186
  if (c.id === 5) return verdict(c.runs.flatMap((r, i) => [...failedRun(r, `run ${i + 1}`), ...noReceipt(r, `run ${i + 1}`)]), "a failing Class A check ended the run with a failing exit and no broker receipt, twice");
185
- return verdict(c.runs.filter((r) => r.jobs.length).flatMap(classABeforeBroker), "the Class A verdict file is older than the first signed submission, and every Class A program had ended by then");
187
+ return verdict(c.runs.filter((r) => r.jobs.length).flatMap((r) => classABeforeBroker(r, { skipNeverRan: c.id === 7 })), "the Class A verdict file is older than the first signed submission, and every Class A program had ended by then");
186
188
  },
187
189
  // Class A starts ready, independent work whenever an eligible lane is free.
188
190
  NN03(c, cases) {
@@ -231,7 +231,9 @@ export async function launch({ out, commit, kind = null, receiptsDir, limits = n
231
231
  record.cacheStore = { dir: storeDir, beforeKnown: storeBefore !== null, afterKnown: storeAfter !== null }; record.snapshotStat = { root: snaps.root, folders: Object.keys(snaps.dirs), known: snaps.known };
232
232
  save();
233
233
  try { fs.closeSync(logFd); } catch { /* closed */ }
234
- // The operating system's record of the run's programs, a little either side of the gate's own span.
234
+ // The operating system's record of the run's programs, a little either side of the gate's own span. Windows writes an exit event shortly after the
235
+ // process ends; the record is read two seconds after the gate's exit so a late one is in it (case 7 on 0.6.66, 2026-11-24: one git exit was missing).
236
+ if (!exportProcesses && platform === "win32") await new Promise((resolve) => setTimeout(resolve, 2000));
235
237
  const from = new Date(Date.parse(record.startedAt) - 2000).toISOString(); const to = new Date(Date.now() + 2000).toISOString();
236
238
  const exported = exportProcesses ? exportProcesses(from, to) : platform === "win32" ? exportWindowsProcesses(from, to) : { kind: null, from, to, newest: null, continuous: false, events: [], problems: [`no process record is collected on ${platform} yet (eslogger on the Mac)`] };
237
239
  fs.writeFileSync(path.join(out, "processes.json"), `${JSON.stringify(exported)}\n`);
@@ -20,6 +20,8 @@ import { verifierArgv } from "./acceptance-lines.mjs";
20
20
  import { decideAll, decideCase, decideRealBuild, factsOfRun } from "./acceptance-cases.mjs";
21
21
 
22
22
  const here = path.dirname(fileURLToPath(import.meta.url));
23
+ /** The error case 1 plants in the working checkout (never in the commit). */
24
+ const PLANTED = "pub fn leaf() -> u32 { this does not compile\n";
23
25
  const sha256 = (b) => crypto.createHash("sha256").update(b).digest("hex");
24
26
  const git = (repo, args, opts = {}) => String(execFileSync("git", ["-C", repo, ...args], { encoding: "utf8", windowsHide: true, stdio: ["pipe", "pipe", "pipe"], maxBuffer: 64 * 1024 * 1024, ...opts })).trim();
25
27
  const IDENT = { GIT_AUTHOR_NAME: "acceptance", GIT_AUTHOR_EMAIL: "acceptance@rightkit.invalid", GIT_COMMITTER_NAME: "acceptance", GIT_COMMITTER_EMAIL: "acceptance@rightkit.invalid", GIT_AUTHOR_DATE: "2026-11-24T00:00:00Z", GIT_COMMITTER_DATE: "2026-11-24T00:00:00Z" };
@@ -82,6 +84,9 @@ async function main() {
82
84
 
83
85
  if (fixture) {
84
86
  const pinned = cases.fixture.commit; if (git(fixture, ["cat-file", "-t", pinned]) !== "commit") throw new Error(`the fixture has no commit ${pinned}`);
87
+ // A run killed during case 1 cannot put back the error it planted: the next run does, and only when that is the one change (anything else refuses).
88
+ { const planted = path.join(fixture, "rk", "crates", "rk-leaf", "src", "lib.rs"); let body = ""; try { body = fs.readFileSync(planted, "utf8"); } catch { body = ""; }
89
+ if (body === PLANTED && git(fixture, ["status", "--porcelain", "--untracked-files=no"]).trim() === "M rk/crates/rk-leaf/src/lib.rs") { git(fixture, ["checkout", "--", "rk/crates/rk-leaf/src/lib.rs"]); console.log("note: the error a killed case 1 planted was still in the checkout; it was put back"); } }
85
90
  if (git(fixture, ["status", "--porcelain", "--untracked-files=no"])) throw new Error("the fixture's working checkout has changes to tracked files; the cases need it clean to start");
86
91
  const storeDir = cacheStoreDir(fixture); const args = ["--to", cases.fixture.stage];
87
92
  const wanted = (opt("--cases") ?? cases.order.join(",")).split(",").map(Number);
@@ -2032,7 +2032,7 @@ export async function rightkitDoorRule(o, args, root, git, io, { unitsFileFlag,
2032
2032
  const id = option("--all-units-exception");
2033
2033
  let granted;
2034
2034
  try {
2035
- const shown = git("show", `${pinned.commit}:${ALL_UNITS_EXCEPTIONS_FILE}`);
2035
+ const shown = git("show", `${PROTECTED_RECORD_REF}:${ALL_UNITS_EXCEPTIONS_FILE}`); // F2: the protected branch's record, never one an agent's own commit adds
2036
2036
  granted = authorizeAllUnits({ id, record: failed(shown) ? null : text(shown), now: o.now ? o.now() : Date.now() });
2037
2037
  } catch (e) {
2038
2038
  if (!e.code?.startsWith("RK_ALL_UNITS_")) throw e;
@@ -2839,15 +2839,26 @@ export function sidecarSourceDirs({ git, commit, result }) {
2839
2839
  * target, the build mode, the gate's own code, Node, the Cargo and Rust variables, and the installed Rust toolchains' channel manifests (rustup rewrites
2840
2840
  * them on every update). Null when the commit cannot be listed.
2841
2841
  */
2842
- export function sidecarSourceKey({ git, commit, config, target, mode, dirs, env = process.env, gateIdentity, nodeVersion = process.version, toolchains = rustupChannelManifests(env) }) {
2842
+ export function sidecarSourceKey(args) { const p = sidecarSourceKeyParts(args); return p ? createHash("sha256").update(JSON.stringify(p)).digest("hex") : null; }
2843
+ export function sidecarSourceKeyParts({ git, commit, config, target, mode, dirs, env = process.env, gateIdentity, nodeVersion = process.version, toolchains = rustupChannelManifests(env) }) {
2843
2844
  const listed = git("ls-tree", "-r", "-z", commit); if (failed(listed)) return null;
2844
2845
  const ancestors = new Set(); for (const d of dirs) { let a = d; for (;;) { ancestors.add(a); if (a === "." || !a.includes("/")) { ancestors.add("."); break; } a = a.slice(0, a.lastIndexOf("/")); } }
2845
2846
  const rootFiles = ["Cargo.toml", "Cargo.lock", "rust-toolchain", "rust-toolchain.toml", ".cargo/config", ".cargo/config.toml"];
2846
2847
  const named = new Set([...ancestors].flatMap((a) => rootFiles.map((f) => (a === "." ? f : `${a}/${f}`))));
2847
2848
  const files = text(listed).split("\0").filter(Boolean).map((l) => { const tab = l.indexOf("\t"); return [l.slice(tab + 1), l.slice(0, tab).split(" ")[2]]; })
2848
2849
  .filter(([p]) => p === config || named.has(p) || dirs.some((d) => d === "." || p.startsWith(`${d}/`)));
2849
- const rustEnv = Object.entries(env ?? {}).filter(([k]) => /^(CARGO_|RUSTFLAGS$|RUSTDOCFLAGS$|RUSTC|RUSTUP_TOOLCHAIN$)/i.test(k)).sort(([a], [b]) => (a < b ? -1 : 1));
2850
- return createHash("sha256").update(JSON.stringify({ schema: "rightkit.sidecar-source/1", config, target, mode, node: nodeVersion, gate: gateIdentity ?? null, env: rustEnv, toolchains, files })).digest("hex");
2850
+ return sidecarKeyParts({ config, target, mode, nodeVersion, gateIdentity, env, toolchains, files });
2851
+ }
2852
+ /**
2853
+ * The parts of the sidecar key, each digested on its own, so a staging that runs again can say which part changed. Only variables that change what Cargo
2854
+ * builds are read: the flags, the toolchain choice, and the profile and build settings. A path the gate or the run picks (a target or home folder, a
2855
+ * wrapper) is left out: it changes on every run without changing the binary (acceptance cases on 0.6.66, 2026-11-24: the key never matched).
2856
+ */
2857
+ export const SIDECAR_KEY_ENV = /^(RUSTFLAGS|RUSTDOCFLAGS|CARGO_ENCODED_RUSTFLAGS|CARGO_BUILD_RUSTFLAGS|CARGO_BUILD_TARGET|RUSTUP_TOOLCHAIN|CARGO_PROFILE_[A-Z0-9_]+)$/i;
2858
+ export function sidecarKeyParts({ config, target, mode, nodeVersion, gateIdentity, env, toolchains, files }) {
2859
+ const d = (v) => createHash("sha256").update(JSON.stringify(v ?? null)).digest("hex").slice(0, 16);
2860
+ const rustEnv = Object.entries(env ?? {}).filter(([k]) => SIDECAR_KEY_ENV.test(k)).sort(([a], [b]) => (a < b ? -1 : 1));
2861
+ return { schema: "rightkit.sidecar-source/2", config: d(config), target: d(target), mode: d(mode), node: d(nodeVersion), gate: d(gateIdentity), env: d(rustEnv), toolchains: d(toolchains), files: d(files) };
2851
2862
  }
2852
2863
  function rustupChannelManifests(env) {
2853
2864
  const home = env?.RUSTUP_HOME || path.join(env?.USERPROFILE || env?.HOME || os.homedir(), ".rustup");
@@ -2856,6 +2867,8 @@ function rustupChannelManifests(env) {
2856
2867
  /** `<managed root>/sidecar-state/<repo key>/<config, target and mode>.json`, beside the snapshot: the key and receipt of the last staging. */
2857
2868
  const sidecarStateFile = (snapshotPath, { config, target, mode }) => path.join(path.dirname(path.dirname(snapshotPath)), "sidecar-state", path.basename(snapshotPath), `${createHash("sha256").update(JSON.stringify([config, target, mode])).digest("hex").slice(0, 32)}.json`);
2858
2869
  const fileSha256 = (file) => { try { return createHash("sha256").update(fs.readFileSync(file)).digest("hex"); } catch { return null; } };
2870
+ /** What a staging receipt stages: each file's path and sha256, not when it was written (the time changes on every staging; acceptance cases on 0.6.67). Null when unreadable. */
2871
+ export const stagedFilesDigest = (file) => { try { const r = JSON.parse(fs.readFileSync(file, "utf8")); if (!Array.isArray(r?.files)) return null; return createHash("sha256").update(JSON.stringify(r.files.map((x) => [x?.path ?? null, x?.sha256 ?? null]).sort())).digest("hex"); } catch { return null; } };
2859
2872
 
2860
2873
  /**
2861
2874
  * Sidecars are staged ONCE per door run, after the sync and before the first stage that builds the Tauri crate. The step is
@@ -2888,8 +2901,14 @@ export async function stageSidecarsOnce({ o, ds, root, git = null, configs, appD
2888
2901
  // file is still there with its recorded sha256 (--if-stale); nothing is built. Anything else stages as before.
2889
2902
  const mode = stage === "dev" ? "dev" : "release"; const stateFile = sidecarStateFile(ds.path, { config, target: key, mode });
2890
2903
  let prior = null; try { prior = JSON.parse(fs.readFileSync(stateFile, "utf8")); } catch { prior = null; }
2891
- const keyNow = (dirs) => (git && Array.isArray(dirs) ? sidecarSourceKey({ git, commit, config, target: key, mode, dirs, env: o.env, gateIdentity: gatePackageIdentity(o.gatePackage) }) : null);
2892
- const unchanged = Boolean(prior?.schema === 1 && typeof prior.key === "string" && typeof prior.receipt === "string" && keyNow(prior.dirs) === prior.key && fileSha256(path.join(ds.path, prior.receipt)) === prior.receiptSha256);
2904
+ const partsNow = (dirs) => (git && Array.isArray(dirs) ? sidecarSourceKeyParts({ git, commit, config, target: key, mode, dirs, env: o.env, gateIdentity: gatePackageIdentity(o.gatePackage) }) : null);
2905
+ const keyOf = (parts) => (parts ? createHash("sha256").update(JSON.stringify(parts)).digest("hex") : null);
2906
+ const keyNow = (dirs) => keyOf(partsNow(dirs));
2907
+ const nowParts = prior?.schema === 2 ? partsNow(prior.dirs) : null;
2908
+ const receiptNow = prior?.schema === 2 && typeof prior.receipt === "string" ? stagedFilesDigest(path.join(ds.path, prior.receipt)) : null;
2909
+ const unchanged = Boolean(prior?.schema === 2 && nowParts && keyOf(nowParts) === prior.key && receiptNow === prior.receiptSha256);
2910
+ // Why it stages again, in one line, so a missed reuse can be traced from the run's own output.
2911
+ if (!unchanged) o.out(tag + " [" + stage + "] stage-sidecar " + config + " builds: " + (prior?.schema !== 2 ? "no earlier staging is recorded" : !nowParts ? "its sources cannot be read from the commit" : keyOf(nowParts) !== prior.key ? "changed since the last staging: " + (Object.keys(nowParts).filter((k) => nowParts[k] !== prior.parts?.[k]).join(", ") || "unknown part") : "the staged receipt is not the one recorded"));
2893
2912
  let r;
2894
2913
  try {
2895
2914
  o.out(`${tag} [${stage}] right-release stage-sidecar --config ${path.join(ds.path, config)}${target ? ` --target ${target}` : ""}${unchanged ? " --if-stale (its sources are those of the last staging: the staged files are checked, nothing is built)" : ""} (from the snapshot ${ds.path})`);
@@ -2918,8 +2937,8 @@ export async function stageSidecarsOnce({ o, ds, root, git = null, configs, appD
2918
2937
  if (receiptAbs) { try { (ds.stagedReceipts ??= new Map()).set(receiptAbs, fs.readFileSync(path.join(ds.path, receiptAbs), "utf8")); } catch { /* the close names the change without the field diff */ } }
2919
2938
  // The sources this staging was built from, for the next run (NN07). Not recordable (a sidecar not built by Cargo, a package not found): the state is removed.
2920
2939
  try {
2921
- const dirs = git ? sidecarSourceDirs({ git, commit, result }) : null; const k = dirs ? keyNow(dirs) : null; const sha = receiptAbs ? fileSha256(path.join(ds.path, receiptAbs)) : null;
2922
- if (k && sha) { fs.mkdirSync(path.dirname(stateFile), { recursive: true }); const tmp = `${stateFile}.${process.pid}.tmp`; fs.writeFileSync(tmp, `${JSON.stringify({ schema: 1, key: k, dirs, receipt: receiptAbs, receiptSha256: sha })}\n`); fs.renameSync(tmp, stateFile); }
2940
+ const dirs = git ? sidecarSourceDirs({ git, commit, result }) : null; const k = dirs ? keyNow(dirs) : null; const sha = receiptAbs ? stagedFilesDigest(path.join(ds.path, receiptAbs)) : null;
2941
+ if (k && sha) { fs.mkdirSync(path.dirname(stateFile), { recursive: true }); const tmp = `${stateFile}.${process.pid}.tmp`; fs.writeFileSync(tmp, `${JSON.stringify({ schema: 2, key: k, parts: partsNow(dirs), dirs, receipt: receiptAbs, receiptSha256: sha })}\n`); fs.renameSync(tmp, stateFile); }
2923
2942
  else fs.rmSync(stateFile, { force: true });
2924
2943
  } catch (e) { o.out(`${tag} [${stage}] stage-sidecar ${config}: the staging state was not recorded (${e.message}); the next run stages again`); }
2925
2944
  }
@@ -4215,15 +4234,60 @@ export function cargoHomeOf(env, { realpath = fs.realpathSync, homedir = os.home
4215
4234
  return home;
4216
4235
  }
4217
4236
 
4237
+ /** Marks the gate's calls of itself (an io key no command line can set). */
4238
+ export const GATE_SELF = Symbol.for("rightkit-gate.self-call");
4239
+ /** Where Adrian's exception records are read from (F2): the protected branch as last fetched. An agent's commit cannot add one; no fetched branch, no record. */
4240
+ export const PROTECTED_RECORD_REF = "refs/remotes/origin/main";
4241
+ /**
4242
+ * A genuine GitHub-hosted run: GitHub sets all three, and no managed broker runtime is installed on its runners. A variable set by hand on a broker host
4243
+ * does not make one (F3: `GITHUB_ACTIONS=true` alone selected the hosted route, which builds the working checkout with no snapshot).
4244
+ */
4245
+ export function genuineGithubRun({ env = {}, platform = process.platform, exists = fs.existsSync } = {}) {
4246
+ if (env.GITHUB_ACTIONS !== "true" || !env.GITHUB_RUN_ID || !env.RUNNER_OS) return false;
4247
+ const runtime = platform === "win32" ? "D:\\.rustright\\runtime" : platform === "darwin" ? "/Volumes/D/.rustright/runtime" : null;
4248
+ return !(runtime && exists(runtime));
4249
+ }
4250
+ /**
4251
+ * Why a caller's run is refused, or null. `--worktree` reads the working folder, not the commit (F5); `--class-a`, `--all` and `--snapshot` are the gate's
4252
+ * own calls of itself (F6; the git pre-push route, which names none of them, is not touched); `GITHUB_ACTIONS=true` outside a genuine GitHub run selects the
4253
+ * hosted route (F3); `--receipt-in` hands the gate a stage receipt and is the publisher job's only (F7).
4254
+ */
4255
+ export function callerRefusal({ args, env = {}, platform = process.platform, exists = fs.existsSync, selfCall = false }) {
4256
+ if (selfCall) return null;
4257
+ if (args.includes("--worktree")) return "--worktree is refused: the gate checks and builds the selected commit only, never the working folder (GC-A27 NN01)";
4258
+ const own = ["--class-a", "--all", "--snapshot"].filter((f) => args.includes(f));
4259
+ if (own.length) return `${own.join(", ")} ${own.length > 1 ? "are" : "is"} the gate's own call of itself and cannot be passed by a caller; run a stage with --to`;
4260
+ const github = genuineGithubRun({ env, platform, exists });
4261
+ if (env.GITHUB_ACTIONS === "true" && !github) return "GITHUB_ACTIONS=true is refused outside a genuine GitHub-hosted run (GITHUB_RUN_ID and RUNNER_OS set, no managed broker on the host): the hosted route builds the working checkout";
4262
+ if (args.includes("--receipt-in") && !github) return "--receipt-in is refused outside the publisher's GitHub run: a stage receipt is not taken from a caller on this host";
4263
+ return null;
4264
+ }
4265
+ /** Variables the gate drops from a caller's environment: the roots on Mac and Windows (F1), and on every host the scratch root and two guards (step F). */
4266
+ export function ignoredCallerVariable(name, platform = process.platform) {
4267
+ const n = String(name).toUpperCase();
4268
+ if (n === "RIGHTKIT_SCRATCH_ROOT" || n === "RIGHTKIT_STAGE_SIDECAR_ALLOW_NESTED" || n === "RUSTRIGHT_OPERATION_DEADLINE_MS") return true;
4269
+ return (platform === "win32" || platform === "darwin") && /^(RUSTRIGHT|RIGHTKIT)_(DATA_ROOT|MANAGED_ROOT|EXTERNAL_ROOT|GATE_ROOT|CONTROL_ROOT|RUNTIME_ROOT)$/.test(n);
4270
+ }
4218
4271
  export async function main(argv, io = {}) {
4219
4272
  const o = {
4220
- spawn: rememberReads(defaultSpawn), exists: fs.existsSync, readFile: (f) => fs.readFileSync(f, "utf8"), writeFile: fs.writeFileSync, mkdir: fs.mkdirSync, chmod: fs.chmodSync, readdir: fs.readdirSync,
4273
+ spawn: defaultSpawn, exists: fs.existsSync, // remembers its read-only answers itself (deterministic-scans.mjs isRememberedRead); a wrapper here switched off the pnpm answers kept across runs, which test `spawn === defaultSpawn` readFile: (f) => fs.readFileSync(f, "utf8"), writeFile: fs.writeFileSync, mkdir: fs.mkdirSync, chmod: fs.chmodSync, readdir: fs.readdirSync,
4221
4274
  readStdin: () => { try { return process.stdin.isTTY ? "" : fs.readFileSync(0, "utf8"); } catch { return ""; } },
4222
4275
  out: (m) => console.log(m), err: (m) => console.error(m), cwd: process.cwd(), env: process.env, platform: process.platform,
4223
4276
  // Where this gate runs from (the door puts its own shims first on PATH when it is an installed package: doorPath).
4224
4277
  gateFile: fileURLToPath(import.meta.url), ...io,
4225
4278
  };
4226
4279
  const args = [...argv];
4280
+ // Step F of the Dell sequence (status file 11.7, settled with Gemini, 2026-11-24): what a caller may not choose. The gate's own calls of itself carry
4281
+ // GATE_SELF; a caller's do not.
4282
+ const selfCall = io[GATE_SELF] === true;
4283
+ io = { ...io, [GATE_SELF]: true };
4284
+ {
4285
+ const refused = callerRefusal({ args, env: o.env, platform: o.platform, exists: o.exists, selfCall });
4286
+ if (refused) { o.err(`rightkit-gate: ${refused}`); return 2; }
4287
+ // Variables that move the gate's state or loosen a guard are not read from a caller: they are dropped from the run's environment before anything reads it.
4288
+ const dropped = Object.keys(o.env ?? {}).filter((k) => ignoredCallerVariable(k, o.platform));
4289
+ if (dropped.length) { o.env = Object.fromEntries(Object.entries(o.env).filter(([k]) => !ignoredCallerVariable(k, o.platform))); if (!selfCall) o.err(`rightkit-gate: note: ignored from the environment: ${dropped.join(", ")} (the gate's roots and guards are fixed on this host)`); }
4290
+ }
4227
4291
  if (args.includes("--ci-proof-out")) {
4228
4292
  try {
4229
4293
  const problem = stageArgsProblem(args);
@@ -4625,7 +4689,7 @@ export async function main(argv, io = {}) {
4625
4689
  let record = null; let inRightKit = true;
4626
4690
  if (typeof brokerId === "string" && !brokerId.startsWith("--")) {
4627
4691
  const pinned = (await import("../snapshot.mjs")).resolveCommit(root, option("--commit") ?? "HEAD");
4628
- const shown = git("show", `${pinned.commit}:${BROKER_EXCEPTIONS_FILE}`);
4692
+ const shown = git("show", `${PROTECTED_RECORD_REF}:${BROKER_EXCEPTIONS_FILE}`); // F2: the protected branch's record, never one an agent's own commit adds
4629
4693
  record = failed(shown) ? null : text(shown);
4630
4694
  // The repository identity of the commit decides what an exception must name: RightKit's units, or (every other repository, built whole) nothing.
4631
4695
  inRightKit = rightkitIdentityAt(git, pinned.commit);
@@ -5493,11 +5557,18 @@ export async function main(argv, io = {}) {
5493
5557
  const treeId = text(git("rev-parse", `${headSha}^{tree}`)).trim();
5494
5558
  const common = git("rev-parse", "--git-common-dir");
5495
5559
  if (headSha && treeId && !failed(common) && text(common).trim()) {
5560
+ // Every blob and tree id of the commit from one listing, read the first time an id is asked for (GC-A27 "no waste": one `git ls-tree <sha> -- <path>`
5561
+ // per path was 545 processes a fixture run, 23 s on a quiet Dell and three minutes on a busy one; the commit's ids cannot change during the run).
5562
+ let treeIds = null;
5496
5563
  const objectId = (p) => {
5497
- const r = git("ls-tree", headSha, "--", p);
5498
- if (failed(r)) throw new Error(`git ls-tree failed: ${why(r)}`);
5499
- const line = text(r).split(/\r?\n/).find(Boolean);
5500
- return line ? (line.split("\t")[0].split(/\s+/)[2] ?? null) : null;
5564
+ if (!treeIds) {
5565
+ const r = git("ls-tree", "-r", "-t", "-z", headSha);
5566
+ if (failed(r)) throw new Error(`git ls-tree failed: ${why(r)}`);
5567
+ treeIds = new Map();
5568
+ for (const entry of text(r).split("\0").filter(Boolean)) { const tab = entry.indexOf("\t"); treeIds.set(entry.slice(tab + 1), entry.slice(0, tab).split(/\s+/)[2] ?? null); }
5569
+ }
5570
+ const key = String(p).replaceAll("\\", "/").replace(/^\.\//, "").replace(/\/+$/, "");
5571
+ return key === "" || key === "." ? treeId : (treeIds.get(key) ?? null);
5501
5572
  };
5502
5573
  const storeDir = path.join(path.resolve(root, text(common).trim()), "rightkit-gate-cache");
5503
5574
  if (needsForecast) classBHistory = openClassBHistory({ historyRoot: path.join(gateRunsRoot({ env: o.env, platform: o.platform }), "rightkit-class-a-history"), storeDir, onRestart: cacheRestartNote(o) });
@@ -5870,6 +5941,8 @@ export async function main(argv, io = {}) {
5870
5941
  if (notRun.length) o.out(`${tag} class A partial: ${notRun.length} check(s) that execute repository code (tests, typecheck, lint, generated docs) run in the full gate, not in check: ${notRun.slice(0, 8).join(", ")}${notRun.length > 8 ? ", …" : ""}`);
5871
5942
  if (!recordHistory()) return 1;
5872
5943
  o.out(`${tag} class A content pass: ${scanResult.scans.length} deterministic scan(s) over ${changed.length} file(s) of ${base}`);
5944
+ // F4 (step F, 2026-11-24): a check that skipped the scans that execute repository code is not a pass. Exit 3, as --only's partial run does.
5945
+ if (notRun.length) { o.out(`${tag} PARTIAL: ${notRun.length} executing check(s) did not run; run it with --full-a, or run the stage with --to`); return 3; }
5873
5946
  return 0;
5874
5947
  }
5875
5948
  if (!recordHistory()) return 1;
@@ -2287,6 +2287,16 @@ export function cmdShimEntry(shim, { readFile = (f) => fs.readFileSync(f, "utf8"
2287
2287
 
2288
2288
  /** Default spawn: synchronous, no console window, never `shell: true`. */
2289
2289
  export function defaultSpawn(command, args, options = {}) {
2290
+ if (isRememberedRead(command, args) && options.input === undefined && options.stdio === undefined) {
2291
+ const key = readMemoKey(command, args, options);
2292
+ if (READ_MEMO.has(key)) return { ...READ_MEMO.get(key) };
2293
+ const r = rawSpawn(command, args, options);
2294
+ if (r && r.status === 0 && !r.error) READ_MEMO.set(key, { status: 0, signal: null, stdout: r.stdout, stderr: r.stderr });
2295
+ return r;
2296
+ }
2297
+ return rawSpawn(command, args, options);
2298
+ }
2299
+ function rawSpawn(command, args, options = {}) {
2290
2300
  if (options.boundedMs) return boundedSpawn(command, args, options);
2291
2301
  const inv = resolveInvocation(command, args, { env: options.env ?? process.env });
2292
2302
  if (inv.error) return { status: null, stdout: "", stderr: "", error: inv.error };
@@ -2303,7 +2313,11 @@ const READ_MEMO = new Map();
2303
2313
  export function isRememberedRead(command, args) {
2304
2314
  const name = String(command).replaceAll("\\", "/").split("/").pop().replace(/\.(exe|cmd|bat)$/i, "").toLowerCase();
2305
2315
  const a = (args ?? []).map(String);
2306
- if (name === "pnpm") return a.length === 1 && a[0] === "--version";
2316
+ // A tool's own version, asked with nothing else (each lane and pass asked again: acceptance cases on 0.6.66, 2026-11-24).
2317
+ if (a.length === 1 && ["--version", "-version", "-V", "version"].includes(a[0])) return true;
2318
+ if (name === "cargo-audit" && a.length === 2 && a[0] === "audit" && a[1] === "--version") return true;
2319
+ // pnpm's resolved configuration of a folder (its .npmrc chain), which nothing in a run writes.
2320
+ if (name === "pnpm") return (a.length === 2 && a[0] === "config" && a[1] === "list") || (a.length === 3 && a[0] === "config" && a[1] === "list" && a[2] === "--json") || (a.length === 3 && a[0] === "config" && a[1] === "get" && /^[a-z-]+$/i.test(a[2]));
2307
2321
  if (name !== "git") return false;
2308
2322
  // git's own leading options (-c key=value, -C dir) are part of the key; the subcommand is what is judged.
2309
2323
  let i = 0; while (i < a.length && (a[i] === "-c" || a[i] === "-C")) i += 2;
@@ -2313,11 +2327,23 @@ export function isRememberedRead(command, args) {
2313
2327
  if (sub[0] === "ls-tree" && sub.length >= 2 && /^[0-9a-f]{40}$/.test(sub[sub.length - 1]) && sub.slice(1, -1).every((a) => /^-[a-z]$|^--name-only$|^--full-tree$/.test(a))) return true;
2314
2328
  return sub.length === 2 && sub[0] === "rev-parse" && sub[1] === "--show-toplevel";
2315
2329
  }
2330
+ const readMemoKey = (command, args, options = {}) => {
2331
+ const a = (args ?? []).map(String); let i = 0; while (i < a.length && (a[i] === "-c" || a[i] === "-C")) i += 2;
2332
+ const sub = a.slice(i);
2333
+ // git show <sha>:<path>, ls-tree <sha>, cat-file -p <sha>: content-addressed, the same answer wherever it is asked (a repository without the object fails, and a failure is not kept).
2334
+ if (/(^|[\\/])git(\.exe)?$/i.test(String(command)) && sub[0] !== "rev-parse") return sha256(JSON.stringify(["object", sub]));
2335
+ // A tool's own version is the version of the binary that runs: the program as the environment resolves it.
2336
+ if (a.length === 1 || (a.length === 2 && a[1] === "--version")) {
2337
+ let file = String(command); try { file = resolveInvocation(command, args, { env: options.env ?? process.env }).file ?? file; } catch { /* as given */ }
2338
+ return sha256(JSON.stringify(["version", String(file).toLowerCase(), a]));
2339
+ }
2340
+ const env = options.env ? Object.keys(options.env).sort().map((k) => `${k}=${options.env[k]}`).join("\0") : "";
2341
+ return sha256(JSON.stringify([String(command), a, path.resolve(options.cwd ?? process.cwd()), env]));
2342
+ };
2316
2343
  export function rememberReads(spawn, { store = READ_MEMO } = {}) {
2317
2344
  return (command, args, options = {}) => {
2318
2345
  if (!isRememberedRead(command, args) || options.input !== undefined || options.stdio !== undefined) return spawn(command, args, options);
2319
- const env = options.env ? Object.keys(options.env).sort().map((k) => `${k}=${options.env[k]}`).join("\0") : "";
2320
- const key = sha256(JSON.stringify([String(command), args, path.resolve(options.cwd ?? process.cwd()), options.encoding ?? null, env]));
2346
+ const key = readMemoKey(command, args, options);
2321
2347
  if (store.has(key)) return { ...store.get(key) };
2322
2348
  const r = spawn(command, args, options);
2323
2349
  if (r && r.status === 0 && !r.error) store.set(key, { status: 0, signal: null, stdout: r.stdout, stderr: r.stderr });
@@ -2380,6 +2406,15 @@ export function killProcessTree(child, { platform = process.platform, run = spaw
2380
2406
  * With `options.stdoutFile`, stdout is written to that file whole instead of kept in memory.
2381
2407
  */
2382
2408
  export function defaultSpawnAsync(command, args, options = {}) {
2409
+ // GC-A27 NN08: the reads rememberReads keeps are answered from the same memory here, and an answer this path gets is kept for both.
2410
+ if (isRememberedRead(command, args) && options.input === undefined && options.stdio === undefined && !options.stdoutFile && !options.onSpawn && !options.signal) {
2411
+ const key = readMemoKey(command, args, options);
2412
+ if (READ_MEMO.has(key)) return Promise.resolve({ ...READ_MEMO.get(key) });
2413
+ return rawSpawnAsync(command, args, options).then((r) => { if (r && r.status === 0 && !r.error) READ_MEMO.set(key, { status: 0, signal: null, stdout: r.stdout, stderr: r.stderr }); return r; });
2414
+ }
2415
+ return rawSpawnAsync(command, args, options);
2416
+ }
2417
+ function rawSpawnAsync(command, args, options = {}) {
2383
2418
  const { signal, stdoutFile, stdoutKeep = OUTPUT_KEEP, onSpawn, ...rest } = options;
2384
2419
  const inv = resolveInvocation(command, args, { env: rest.env ?? process.env });
2385
2420
  if (inv.error) return Promise.resolve({ status: null, stdout: "", stderr: "", error: inv.error });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rightkit/release",
3
- "version": "0.6.66",
3
+ "version": "0.6.68",
4
4
  "description": "Portable release CLI/SDK with fail-closed public GitHub Releases and private R2 + RightApps distribution.",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "type": "module",
@@ -91,7 +91,7 @@
91
91
  ],
92
92
  "sideEffects": false,
93
93
  "scripts": {
94
- "test": "node --test acceptance-admission.test.mjs acceptance-lines.test.mjs acceptance-cases.test.mjs rule-verdict-cache.test.mjs class-b-dispatch.test.mjs remember-reads.test.mjs sidecar-source.test.mjs class-a-cache-history.test.mjs gate-fixed-levers.test.mjs broker-toolchain.test.mjs snapshot-changes.test.mjs gate-serve-changes.test.mjs gate-serve-helper.test.mjs resident-answers.test.mjs probe-memo-kept.test.mjs class-a-lanes.test.mjs feature-partition-targets.test.mjs class-b-target-groups.test.mjs unit-list-lock.test.mjs cargo-profile-check.test.mjs cargo-home-real-path.test.mjs class-a-cache-admission.test.mjs class-b-cache-admission.test.mjs shellcheck-cache-inputs.test.mjs implicit-features.test.mjs test-group-failure-cache.test.mjs sealed-listing-store.test.mjs gate/gate.test.mjs package-files.test.mjs host-gate.test.mjs publish-local-cargo.test.mjs affected-units.test.mjs batch-workspace.test.mjs unit-list-plan.test.mjs compile-inputs.test.mjs snapshot-dependency-reuse.test.mjs publisher-requirement-scan.test.mjs node-check-cache.test.mjs preparation-diagnostics.test.mjs gate-coverage-timing.test.mjs ci-compile-admission.test.mjs qualification-verify.test.mjs test-run-output.test.mjs feature-partition.test.mjs feature-sets.test.mjs gate-seam.test.mjs serial-row.test.mjs seam-repairs.test.mjs snapshot-lock.test.mjs lock-identity.test.mjs stamp-relay.test.mjs install-tauri-authenticode.test.mjs gate-stage-binding.test.mjs tool-output.test.mjs publication-gate.test.mjs gate-release-admission.test.mjs cache-key-explain.test.mjs external-inputs.test.mjs built-bins.test.mjs probe-memo.test.mjs gate-serve-ask.test.mjs double-pass.test.mjs tool-version-memo.test.mjs workspace-manifests.test.mjs test-failure-cache.test.mjs served-metadata.test.mjs windows-pnpm-identity.test.mjs",
94
+ "test": "node --test acceptance-admission.test.mjs acceptance-lines.test.mjs acceptance-cases.test.mjs rule-verdict-cache.test.mjs class-b-dispatch.test.mjs remember-reads.test.mjs sidecar-source.test.mjs caller-levers.test.mjs class-a-cache-history.test.mjs gate-fixed-levers.test.mjs broker-toolchain.test.mjs snapshot-changes.test.mjs gate-serve-changes.test.mjs gate-serve-helper.test.mjs resident-answers.test.mjs probe-memo-kept.test.mjs class-a-lanes.test.mjs feature-partition-targets.test.mjs class-b-target-groups.test.mjs unit-list-lock.test.mjs cargo-profile-check.test.mjs cargo-home-real-path.test.mjs class-a-cache-admission.test.mjs class-b-cache-admission.test.mjs shellcheck-cache-inputs.test.mjs implicit-features.test.mjs test-group-failure-cache.test.mjs sealed-listing-store.test.mjs gate/gate.test.mjs package-files.test.mjs host-gate.test.mjs publish-local-cargo.test.mjs affected-units.test.mjs batch-workspace.test.mjs unit-list-plan.test.mjs compile-inputs.test.mjs snapshot-dependency-reuse.test.mjs publisher-requirement-scan.test.mjs node-check-cache.test.mjs preparation-diagnostics.test.mjs gate-coverage-timing.test.mjs ci-compile-admission.test.mjs qualification-verify.test.mjs test-run-output.test.mjs feature-partition.test.mjs feature-sets.test.mjs gate-seam.test.mjs serial-row.test.mjs seam-repairs.test.mjs snapshot-lock.test.mjs lock-identity.test.mjs stamp-relay.test.mjs install-tauri-authenticode.test.mjs gate-stage-binding.test.mjs tool-output.test.mjs publication-gate.test.mjs gate-release-admission.test.mjs cache-key-explain.test.mjs external-inputs.test.mjs built-bins.test.mjs probe-memo.test.mjs gate-serve-ask.test.mjs double-pass.test.mjs tool-version-memo.test.mjs workspace-manifests.test.mjs test-failure-cache.test.mjs served-metadata.test.mjs windows-pnpm-identity.test.mjs",
95
95
  "test:registry-parity": "node registry-parity.mjs --allow-unpublished",
96
96
  "test:signer:windows": "node sign-release-manifest.integration.mjs",
97
97
  "prepublishOnly": "pnpm test:signer:windows && pnpm test:registry-parity",
@@ -49,7 +49,7 @@
49
49
  "@rightkit/qa": "0.7.0",
50
50
  "@rightkit/qa-chrome": "0.1.12",
51
51
  "@rightkit/react-shell": "0.7.6",
52
- "@rightkit/release": "0.6.66",
52
+ "@rightkit/release": "0.6.68",
53
53
  "@rightkit/send-ui": "0.1.0",
54
54
  "@rightkit/settings-ui": "0.7.5",
55
55
  "@rightkit/social-ui": "0.2.1",