@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.
- package/README.md +4 -0
- package/acceptance-admission.mjs +104 -0
- package/acceptance-launch.mjs +234 -0
- package/acceptance-lines.mjs +1254 -0
- package/acceptance-result.mjs +77 -0
- package/acceptance-rows.mjs +47 -0
- package/admission-files.mjs +2 -0
- package/affected-units.mjs +17 -0
- package/app-check.mjs +6 -2
- package/app-closure.mjs +3 -1
- package/bin/rightkit-gate.mjs +552 -124
- package/broker-admission.mjs +45 -2
- package/broker-pins.mjs +11 -1
- package/broker-toolchain.mjs +113 -0
- package/cargo-profile-contract.mjs +7 -2
- package/class-a-cache-history.mjs +170 -0
- package/cli/right-release.mjs +0 -0
- package/code-closure.mjs +24 -0
- package/config-inspect.mjs +6 -0
- package/consumer-contracts.mjs +3 -1
- package/contract-nn.json +166 -0
- package/deterministic-scans.mjs +835 -112
- package/feature-coverage.mjs +109 -82
- package/feature-partition.mjs +76 -0
- package/forbidden-literals.mjs +78 -0
- package/gate/calls.mjs +121 -0
- package/gate/compile.mjs +190 -0
- package/gate/crate-results.mjs +127 -0
- package/gate/run-calls.mjs +241 -0
- package/gate/tests.mjs +234 -0
- package/gate-coverage.mjs +12 -3
- package/gate-release-admission.mjs +200 -0
- package/gate-seam.mjs +100 -4
- package/gate-serve.mjs +179 -34
- package/gate-stages.mjs +59 -0
- package/legacy-contract-receipt.mjs +809 -0
- package/local-publish.mjs +2 -4
- package/local-runtime.mjs +2 -2
- package/nsis-payload.mjs +4 -3
- package/ownership-applicability.mjs +5 -0
- package/ownership-class-rules.mjs +19 -8
- package/ownership-mandatory-set.json +15 -21
- package/ownership-mandatory-set.mjs +19 -4
- package/package.json +14 -8
- package/probe-memo.mjs +252 -0
- package/publication-artifacts.mjs +56 -2
- package/publish-local-npm.mjs +3 -0
- package/publish-update.mjs +2 -2
- package/receipt-signature.mjs +40 -0
- package/release.mjs +47 -29
- package/resident-answers.mjs +66 -0
- package/rightkit-ownership.json +20 -11
- package/rightkit-versions.json +349 -183
- package/runtime-bundle-stage.mjs +146 -0
- package/scan-digest.mjs +28 -4
- package/seam-broker.mjs +8 -1
- package/shell-contract.mjs +23 -2
- package/snapshot-changes.mjs +106 -0
- package/snapshot-check.mjs +17 -13
- package/snapshot-dependency-reuse.mjs +186 -14
- package/snapshot-git.mjs +17 -1
- package/snapshot-metadata.mjs +155 -3
- package/snapshot.mjs +89 -12
- package/spawn-ledger.mjs +21 -2
- package/stage-sidecar.mjs +231 -19
- package/suite-trust-roots.mjs +2 -2
- package/test-env.mjs +26 -0
- package/tool-version-memo.mjs +46 -0
- package/win-package-recipe.mjs +11 -0
- package/bin/darwin/rightkit-swap +0 -0
- package/gate-acceptance.mjs +0 -3362
package/local-publish.mjs
CHANGED
|
@@ -35,6 +35,7 @@ import { exclusionsFor, npmContentDigest } from "./pack-digest.mjs";
|
|
|
35
35
|
import { requireDoorRun, gateStateDir } from "./gate-stages.mjs";
|
|
36
36
|
import { crateRunsOn, crossCompileEnv, crossTargetsFor, oneOutput, scopedCrossTargets } from "./cross-targets.mjs";
|
|
37
37
|
import { crossFeatureSets, defaultCheckFeatureSets, hostFeatureSets } from "./feature-sets.mjs";
|
|
38
|
+
import { testProgramEnv } from "./test-env.mjs";
|
|
38
39
|
|
|
39
40
|
export const LOCAL_OPERATOR = "agent (local-build grant)";
|
|
40
41
|
export const LOCAL_HOST_POLICY_REASON = "Adrian 2026-10-14 local-build grant (.rightkit-local-build.json); Windows covered by the next CI run";
|
|
@@ -668,10 +669,7 @@ const tail = (text, lines = 40) => String(text ?? "").split(/\r?\n/).slice(-line
|
|
|
668
669
|
|
|
669
670
|
// Tests run under hosted-CI conditions: no inherited credentials (a managed host refuses a token from the
|
|
670
671
|
// environment) and no sibling product checkouts (CI holds rightkit alone).
|
|
671
|
-
|
|
672
|
-
const inherited = Object.fromEntries(Object.entries(deps.env ?? process.env).filter(([key]) => !/(TOKEN|SECRET|PASSWORD|API_KEY|PRIVATE_KEY)/i.test(key)));
|
|
673
|
-
return { ...inherited, RIGHTKIT_REQUIRE_ASSETS: isAssetGated ? "0" : "1", RIGHTKIT_ISOLATED_CHECKOUT: "1", CARGO_TERM_COLOR: "never" };
|
|
674
|
-
}
|
|
672
|
+
const testEnv = (deps, isAssetGated) => testProgramEnv(deps.env ?? process.env, isAssetGated);
|
|
675
673
|
|
|
676
674
|
function assertLocalHost(deps, workspaceRoot, kind, { qualifyOnly = false, unit = null } = {}) {
|
|
677
675
|
const platform = deps.platform ?? process.platform;
|
package/local-runtime.mjs
CHANGED
|
@@ -163,8 +163,8 @@ export async function measureRuntimeCrate(options, deps = {}) {
|
|
|
163
163
|
const bindings = {};
|
|
164
164
|
for (const full of [...lsTree([`crates/${crate}/src`]), `crates/${crate}/Cargo.toml`]) bindings[full] = sha256(blob(full));
|
|
165
165
|
Object.assign(bindings, owner.bindHarnessMetadata(crate, prescription, blob));
|
|
166
|
-
//
|
|
167
|
-
for (const full of lsTree([`crates/${crate}/Cargo.toml`,
|
|
166
|
+
// Bind the same context files as the hosted producer. Cargo locks are bound in bindHarnessMetadata.
|
|
167
|
+
for (const full of lsTree([`crates/${crate}/Cargo.toml`, "rust-toolchain.toml", ".cargo", `crates/${crate}/.cargo`, `crates/${crate}/benches`, "crates/rightkit-child-process/src", "crates/rightkit-child-process/Cargo.toml"])) bindings[full] = sha256(blob(full));
|
|
168
168
|
const { specs, problems: scopeProblems = [] } = (deps.measuredPathspecs ?? H.budgets.measuredPathspecs)(crateDir, { base: root });
|
|
169
169
|
if (scopeProblems.length) throw new Error(`cannot bind the measured dependency scope: ${scopeProblems.join("; ")}`);
|
|
170
170
|
for (const full of lsTree(specs)) bindings[full] = sha256(blob(full));
|
package/nsis-payload.mjs
CHANGED
|
@@ -87,7 +87,7 @@ export function listNsisPayload(installer, { sevenZip = resolveSevenZip(), run =
|
|
|
87
87
|
* Extract one payload entry to a temporary directory and return its bytes.
|
|
88
88
|
* The caller owns nothing: the temporary directory is always removed.
|
|
89
89
|
*/
|
|
90
|
-
export function extractNsisEntry(installer, entryName, { sevenZip = resolveSevenZip(), run = runSevenZip, tempRoot = os.tmpdir() } = {}) {
|
|
90
|
+
export function extractNsisEntry(installer, entryName, { sevenZip = resolveSevenZip(), run = runSevenZip, tempRoot = os.tmpdir(), exactMember = false } = {}) {
|
|
91
91
|
const resolvedInstaller = path.resolve(installer);
|
|
92
92
|
const base = path.posix.basename(String(entryName).replace(/\\/g, "/"));
|
|
93
93
|
if (!base || base === "." || base === "..") throw new Error(`invalid NSIS payload entry name: ${entryName}`);
|
|
@@ -100,7 +100,7 @@ export function extractNsisEntry(installer, entryName, { sevenZip = resolveSeven
|
|
|
100
100
|
const requested = String(entryName).replace(/\\/g, "/");
|
|
101
101
|
const members = listNsisPayload(resolvedInstaller, { sevenZip, run });
|
|
102
102
|
const exact = members.filter((member) => member.name.toLowerCase() === requested.toLowerCase());
|
|
103
|
-
const matches = exact.length > 0
|
|
103
|
+
const matches = exactMember || exact.length > 0
|
|
104
104
|
? exact
|
|
105
105
|
: members.filter((member) => path.posix.basename(member.name).toLowerCase() === base.toLowerCase());
|
|
106
106
|
if (matches.length === 0) {
|
|
@@ -134,11 +134,12 @@ export function verifyNsisEmbeddedBinary({
|
|
|
134
134
|
sevenZip = resolveSevenZip(),
|
|
135
135
|
run = runSevenZip,
|
|
136
136
|
tempRoot = os.tmpdir(),
|
|
137
|
+
exactMember = false,
|
|
137
138
|
}) {
|
|
138
139
|
if (!/^[0-9a-f]{64}$/i.test(String(expectedSha256 ?? ""))) {
|
|
139
140
|
throw new Error(`expected a sha256 digest for the signed ${entryName}, received ${JSON.stringify(expectedSha256)}`);
|
|
140
141
|
}
|
|
141
|
-
const { name, bytes } = extractNsisEntry(installer, entryName, { sevenZip, run, tempRoot });
|
|
142
|
+
const { name, bytes } = extractNsisEntry(installer, entryName, { sevenZip, run, tempRoot, exactMember });
|
|
142
143
|
const embeddedSha256 = createHash("sha256").update(bytes).digest("hex");
|
|
143
144
|
if (embeddedSha256.toLowerCase() !== String(expectedSha256).toLowerCase()) {
|
|
144
145
|
throw new Error(
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// #994 keeps M22 mandatory for the active desktop apps. Separate migration scopes
|
|
2
|
+
// retain their own rulings, including Ember's historical amendment.
|
|
3
|
+
export function requiresDesktopAgentSurface(app, profile, data) {
|
|
4
|
+
return profile === "desktop" && (data?.defaultApps ?? []).includes(app);
|
|
5
|
+
}
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
// text the app writes; an entry no ruling covers is a finding.
|
|
31
31
|
import fs from "node:fs";
|
|
32
32
|
import path from "node:path";
|
|
33
|
+
import { requiresDesktopAgentSurface } from "./ownership-applicability.mjs";
|
|
33
34
|
|
|
34
35
|
const readText = (root, rel) => { try { return fs.readFileSync(path.join(root, rel), "utf8"); } catch { return null; } };
|
|
35
36
|
const readJson = (root, rel) => { const text = readText(root, rel); try { return text === null ? null : JSON.parse(text); } catch { return null; } };
|
|
@@ -216,7 +217,8 @@ export function ratifiedNotApplicable(declared, { app, profile, data, details =
|
|
|
216
217
|
const ratified = {}, unratified = {};
|
|
217
218
|
for (const [id, reason] of Object.entries(declared ?? {})) {
|
|
218
219
|
const expires = details[id]?.expires ?? null;
|
|
219
|
-
|
|
220
|
+
const required = id === "M22" && requiresDesktopAgentSurface(app, profile, data);
|
|
221
|
+
if (!required && typeof rulings[id] === "string" && rulings[id].trim() === reason.trim() && !(expires && expires < today)) ratified[id] = reason;
|
|
220
222
|
else unratified[id] = reason;
|
|
221
223
|
}
|
|
222
224
|
return { ratified, unratified, ruled: Boolean(amendment), proposed };
|
|
@@ -239,11 +241,17 @@ function checkAppRoot({ root, dir, evaluator, data, owners = true }) {
|
|
|
239
241
|
const declaration = (evaluator ?? { loadAppDeclaration: declarationOf }).loadAppDeclaration(appRoot, data);
|
|
240
242
|
const app = declaredApp(appRoot);
|
|
241
243
|
const { ratified, unratified, ruled, proposed } = ratifiedNotApplicable(declaration.notApplicable, { app, profile: declaration.profile, data, details: declaration.notApplicableDetail });
|
|
242
|
-
for (const [row, reason] of Object.entries(unratified))
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
244
|
+
for (const [row, reason] of Object.entries(unratified)) {
|
|
245
|
+
if (row === "M22" && requiresDesktopAgentSurface(app, declaration.profile, data)) {
|
|
246
|
+
out.push({ file, subject: "notApplicable:M22", problem: "RightKit #994 requires a headless release CLI for every active desktop app", fix: `remove notApplicable.M22 in ${file} and adopt the release CLI route` });
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
out.push({
|
|
250
|
+
file, subject: `notApplicable:${row}`,
|
|
251
|
+
problem: `notApplicable.${row} ("${reason.slice(0, 80)}${reason.length > 80 ? "..." : ""}") is not a ratified ruling: ${!app ? `${file} names no "app"` : !ruled ? `appAmendments has no entry for "${app}"` : proposed ? `appAmendments.${app} is a proposal (status "proposed") awaiting Adrian's ratification` : `appAmendments.${app} (profile ${data.appAmendments[app].profile}) has no ruling for ${row} with this reason verbatim for profile ${declaration.profile}`}; the row still applies`,
|
|
252
|
+
fix: `ratify the ruling in RightKit (appAmendments.${app ?? "<app>"}.notApplicable.${row}, rightkit#1140) and copy its reason verbatim, or adopt the row's owner`,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
247
255
|
if (!owners) return out;
|
|
248
256
|
const report = evaluator.checkApp(appRoot, { data, declaration: { ...declaration, notApplicable: ratified } });
|
|
249
257
|
for (const owner of report.owners) {
|
|
@@ -253,10 +261,13 @@ function checkAppRoot({ root, dir, evaluator, data, owners = true }) {
|
|
|
253
261
|
}
|
|
254
262
|
if (owner.status !== "missing") continue;
|
|
255
263
|
const devOnly = owner.evidence.some((line) => line.includes("dev-dependencies"));
|
|
264
|
+
const agentSurfaceRequired = owner.rows.includes("M22") && requiresDesktopAgentSurface(app, declaration.profile, data);
|
|
256
265
|
out.push({
|
|
257
266
|
file, subject: owner.owner,
|
|
258
|
-
problem: `profile "${report.profile}" requires the foundation owner ${owner.owner} (${owner.ecosystem}, row${owner.rows.length > 1 ? "s" : ""} ${owner.rows.join(", ")}) and
|
|
259
|
-
fix:
|
|
267
|
+
problem: `profile "${report.profile}" requires the foundation owner ${owner.owner} (${owner.ecosystem}, row${owner.rows.length > 1 ? "s" : ""} ${owner.rows.join(", ")}) and lacks a qualifying runtime dependency declaration${devOnly ? " (declared only as a dev dependency)" : ""}`,
|
|
268
|
+
fix: agentSurfaceRequired
|
|
269
|
+
? `use ${owner.owner} >= ${owner.required} from the registry to expose the release headless CLI through right-ctl (RightKit #1658)`
|
|
270
|
+
: `depend on ${owner.owner} >= ${owner.required} from the registry and use it, or, when the row truly does not apply, declare it under notApplicable in ${file} with the reason RightKit ratified for the app`,
|
|
260
271
|
});
|
|
261
272
|
}
|
|
262
273
|
return out;
|
|
@@ -15,13 +15,17 @@
|
|
|
15
15
|
"postright",
|
|
16
16
|
"viewright",
|
|
17
17
|
"mailright",
|
|
18
|
-
"pulse"
|
|
19
|
-
"ember"
|
|
18
|
+
"pulse"
|
|
20
19
|
],
|
|
20
|
+
"migrationExclusions": {
|
|
21
|
+
"ember": "deferred app",
|
|
22
|
+
"sellright": "release consumer",
|
|
23
|
+
"legion": "tool consumer"
|
|
24
|
+
},
|
|
21
25
|
"appDeclarationFile": "rightkit-mandatory.json",
|
|
22
26
|
"profiles": {
|
|
23
27
|
"desktop": {
|
|
24
|
-
"description": "Default: every desktop app owes every row unless
|
|
28
|
+
"description": "Default: every desktop app owes every row unless a matching central ruling ratifies N/A. M22 is mandatory for every active desktop app under #994."
|
|
25
29
|
},
|
|
26
30
|
"apple": {
|
|
27
31
|
"description": "Table 1-Apple is an unratified draft. Profile is supported by the data model; no Apple rows are shipped.",
|
|
@@ -649,7 +653,7 @@
|
|
|
649
653
|
"both",
|
|
650
654
|
"absent"
|
|
651
655
|
],
|
|
652
|
-
"note": "Declared in <app>/rightkit-mandatory.json as M22: { role, entrypoints }.
|
|
656
|
+
"note": "Declared in <app>/rightkit-mandatory.json as M22: { role, entrypoints }. Role evidence is report-only and does not qualify a release CLI. RightKit #994 requires a headless release CLI host and disallows N/A for the active desktop apps."
|
|
653
657
|
}
|
|
654
658
|
},
|
|
655
659
|
"appAmendments": {
|
|
@@ -670,27 +674,17 @@
|
|
|
670
674
|
"M22": "rightkit-agent-tools needs a daemon-backed app control service. Ember's agent surface is its own MCP server over engine command ids, being ported to rightkit-mcp. Applies to non-daemon apps."
|
|
671
675
|
}
|
|
672
676
|
},
|
|
673
|
-
"cutright": {
|
|
674
|
-
"status": "proposed",
|
|
675
|
-
"issue": "bogusyogi/rightkit#1006",
|
|
676
|
-
"source": "bogusyogi/CutRight RightKit wave-2 port (branch claude/rk-port)",
|
|
677
|
-
"profile": "desktop",
|
|
678
|
-
"note": "DRAFT, not ratified: only Adrian's own words ratify a ruling. The checker ignores an amendment marked status proposed and the key proposedNotApplicable; on ratification Adrian's decision moves the rows to notApplicable and removes status. CutRight keeps both N/A strings, each carrying the issue and the expiry 2026-11-30.",
|
|
679
|
-
"proposedNotApplicable": {
|
|
680
|
-
"M9": "No SQLite app state. Project state is canonical JSON through rightkit-fs and settings are JSON through rightkit-app-settings; rightkit-db arrives only transitively through rightkit-job-queue and no JobStore is used.",
|
|
681
|
-
"M17": "No first-party HTTP client. LLM calls go through rightkit-llm, speech through rightkit-speech-client, model packs through rightkit-models and licence through @rightkit/license; rightkit-http is transitive only."
|
|
682
|
-
}
|
|
683
|
-
},
|
|
684
677
|
"viewright": {
|
|
685
|
-
"status": "proposed",
|
|
686
678
|
"issue": "bogusyogi/rightkit#1140",
|
|
687
|
-
"source": "
|
|
679
|
+
"source": "Adrian's ViewRight ruling recorded in bogusyogi/rightkit#1140 (comment 6961895465)",
|
|
688
680
|
"profile": "desktop",
|
|
689
|
-
"note": "
|
|
681
|
+
"note": "Only M3 and M7 are ratified. M4 remains proposed pending the installed CLI owner decision in #1658. M6, M17 and M22 still apply.",
|
|
690
682
|
"proposedNotApplicable": {
|
|
691
|
-
"
|
|
692
|
-
|
|
693
|
-
|
|
683
|
+
"M4": "Resolve protocol ownership after the installed CLI design in bogusyogi/rightkit#1658."
|
|
684
|
+
},
|
|
685
|
+
"notApplicable": {
|
|
686
|
+
"M3": "ViewRight has no supervised app engine or restart-surviving app jobs. Document work stays local, and rightkit-ocr owns its worker.",
|
|
687
|
+
"M7": "ViewRight has no product local service. rightkit-daemon supplies roots under M6, the shell owns single-instance handoff, and opt-in control belongs to rightkit-qa."
|
|
694
688
|
}
|
|
695
689
|
}
|
|
696
690
|
},
|
|
@@ -24,9 +24,14 @@
|
|
|
24
24
|
// raising minimums is the separate activation step (PK17.activation). The M22 applicability record (PK15-2) is validated and
|
|
25
25
|
// reported under `applicability.M22`; an invalid or contradictory record is a `problem`, which never changes the exit code.
|
|
26
26
|
import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
27
|
+
import { createRequire } from "node:module";
|
|
27
28
|
import path from "node:path";
|
|
28
29
|
import { fileURLToPath } from "node:url";
|
|
29
|
-
import {
|
|
30
|
+
import { requiresDesktopAgentSurface } from "./ownership-applicability.mjs";
|
|
31
|
+
|
|
32
|
+
// Generated-docs preflight imports the declaration helpers before dependencies are installed.
|
|
33
|
+
let smolTomlParse;
|
|
34
|
+
const parseToml = (text) => (smolTomlParse ??= createRequire(import.meta.url)("smol-toml").parse)(text);
|
|
30
35
|
|
|
31
36
|
const packageRoot = path.dirname(fileURLToPath(import.meta.url));
|
|
32
37
|
export const DATA_FILE = "ownership-mandatory-set.json";
|
|
@@ -283,7 +288,11 @@ export function validateApplicabilityRecord(id, raw, { spec, root }) {
|
|
|
283
288
|
}
|
|
284
289
|
|
|
285
290
|
const REAL_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
286
|
-
|
|
291
|
+
function isRealDate(text) {
|
|
292
|
+
if (typeof text !== "string" || !REAL_DATE.test(text)) return false;
|
|
293
|
+
const date = new Date(`${text}T00:00:00Z`);
|
|
294
|
+
return Number.isFinite(date.getTime()) && date.toISOString().slice(0, 10) === text;
|
|
295
|
+
}
|
|
287
296
|
const todayOf = (now) => (now instanceof Date ? now : new Date()).toISOString().slice(0, 10);
|
|
288
297
|
|
|
289
298
|
/**
|
|
@@ -337,7 +346,9 @@ export function ratifyNotApplicable(declaration, { data, now } = {}) {
|
|
|
337
346
|
for (const [id, reason] of Object.entries(declaration.notApplicable)) {
|
|
338
347
|
const expires = declaration.notApplicableDetail?.[id]?.expires ?? null;
|
|
339
348
|
const ruling = live[id];
|
|
340
|
-
const why =
|
|
349
|
+
const why = id === "M22" && requiresDesktopAgentSurface(declaration.app, declaration.profile, data)
|
|
350
|
+
? "RightKit #994 requires a headless release CLI for every active desktop app"
|
|
351
|
+
: !declaration.app ? `${data.appDeclarationFile} names no "app"`
|
|
341
352
|
: !amendment ? `appAmendments has no entry for "${declaration.app}"`
|
|
342
353
|
: proposed ? `appAmendments.${declaration.app} is a proposal (status "proposed"), not a ratified ruling`
|
|
343
354
|
: typeof ruling !== "string" || ruling.trim() !== reason.trim() ? `appAmendments.${declaration.app} (profile ${amendment.profile}) has no ruling for ${id} with this reason verbatim for profile ${declaration.profile}`
|
|
@@ -398,7 +409,11 @@ export function checkApp(root, { data = loadData(), profile, amendments = [], de
|
|
|
398
409
|
applicability[id] = record;
|
|
399
410
|
problems.push(...record.problems);
|
|
400
411
|
const declaredNa = id in declaration.notApplicable;
|
|
401
|
-
if (
|
|
412
|
+
if (id === "M22" && requiresDesktopAgentSurface(declaration.app ?? name, active, data)) {
|
|
413
|
+
if (record.role !== "host" && record.role !== "both") problems.push(`${id}: headless release CLI host is required (RightKit #994); current role is ${record.role ?? "unrecorded"}`);
|
|
414
|
+
} else if (record.role === "absent" && !declaredNa) {
|
|
415
|
+
problems.push(`${id}: applicability role is absent but notApplicable.${id} is not declared; the ${id} row still applies until the app declares it not applicable with a reason`);
|
|
416
|
+
}
|
|
402
417
|
if (record.role && record.role !== "absent" && declaredNa) problems.push(`${id}: notApplicable.${id} is declared but the applicability record says role ${record.role}`);
|
|
403
418
|
}
|
|
404
419
|
const owners = [...requirements(applicable).values()].map((req) => { const result = judge(req, facts); return { ...result, declarationStatus: result.status }; });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rightkit/release",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.62",
|
|
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",
|
|
@@ -17,12 +17,14 @@
|
|
|
17
17
|
"./cargo-contract.mjs": "./cargo-contract.mjs",
|
|
18
18
|
"./cargo-target.mjs": "./cargo-target.mjs",
|
|
19
19
|
"./cli/right-release.mjs": "./cli/right-release.mjs",
|
|
20
|
+
"./config-inspect.mjs": "./config-inspect.mjs",
|
|
20
21
|
"./development.mjs": "./development.mjs",
|
|
21
22
|
"./direct-bootstrap.mjs": "./direct-bootstrap.mjs",
|
|
22
23
|
"./disk-policy.mjs": "./disk-policy.mjs",
|
|
23
24
|
"./dmg-build.mjs": "./dmg-build.mjs",
|
|
24
25
|
"./door.mjs": "./door.mjs",
|
|
25
26
|
"./engine-locator.mjs": "./engine-locator.mjs",
|
|
27
|
+
"./forbidden-literals.mjs": "./forbidden-literals.mjs",
|
|
26
28
|
"./github-release.mjs": "./github-release.mjs",
|
|
27
29
|
"./legal-contract.mjs": "./legal-contract.mjs",
|
|
28
30
|
"./linux-setup.mjs": "./linux-setup.mjs",
|
|
@@ -69,6 +71,7 @@
|
|
|
69
71
|
"files": [
|
|
70
72
|
"cli",
|
|
71
73
|
"bin",
|
|
74
|
+
"gate",
|
|
72
75
|
"templates",
|
|
73
76
|
"*.mjs",
|
|
74
77
|
"*.json",
|
|
@@ -81,11 +84,19 @@
|
|
|
81
84
|
"LICENSE-APACHE",
|
|
82
85
|
"!*.test.mjs",
|
|
83
86
|
"!cli/*.test.mjs",
|
|
87
|
+
"!gate/*.test.mjs",
|
|
84
88
|
"!standalone-clone-evidence.json",
|
|
85
89
|
"!refusals.json",
|
|
86
90
|
"!provenance-real-receipt.fixture.json"
|
|
87
91
|
],
|
|
88
92
|
"sideEffects": false,
|
|
93
|
+
"scripts": {
|
|
94
|
+
"test": "node --test acceptance-admission.test.mjs acceptance-lines.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
|
+
"test:registry-parity": "node registry-parity.mjs --allow-unpublished",
|
|
96
|
+
"test:signer:windows": "node sign-release-manifest.integration.mjs",
|
|
97
|
+
"prepublishOnly": "pnpm test:signer:windows && pnpm test:registry-parity",
|
|
98
|
+
"verify:standalone": "node standalone-clone-verify.mjs"
|
|
99
|
+
},
|
|
89
100
|
"publishConfig": {
|
|
90
101
|
"registry": "https://registry.npmjs.org/",
|
|
91
102
|
"access": "public"
|
|
@@ -95,14 +106,9 @@
|
|
|
95
106
|
"url": "git+https://github.com/bogusyogi/rightkit.git",
|
|
96
107
|
"directory": "packages/release"
|
|
97
108
|
},
|
|
109
|
+
"packageManager": "pnpm@12.16.1",
|
|
98
110
|
"dependencies": {
|
|
99
111
|
"@rightkit/outdated": "0.3.0",
|
|
100
112
|
"smol-toml": "1.9.1"
|
|
101
|
-
},
|
|
102
|
-
"scripts": {
|
|
103
|
-
"test": "node --test gate/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 gate-acceptance.test.mjs stamp-relay.test.mjs install-tauri-authenticode.test.mjs gate-stage-binding.test.mjs tool-output.test.mjs publication-gate.test.mjs",
|
|
104
|
-
"test:registry-parity": "node registry-parity.mjs --allow-unpublished",
|
|
105
|
-
"test:signer:windows": "node sign-release-manifest.integration.mjs",
|
|
106
|
-
"verify:standalone": "node standalone-clone-verify.mjs"
|
|
107
113
|
}
|
|
108
|
-
}
|
|
114
|
+
}
|
package/probe-memo.mjs
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// One answer per question, per gate process (GATE-CONTRACT NN07: no identical child process twice in one run).
|
|
2
|
+
//
|
|
3
|
+
// Many parts of the gate ask git the same fixed questions about the same checkout: its top level, its git directory, its object format, whether a
|
|
4
|
+
// commit id names a commit, the origin URL. Each part asked for itself. Measured on the Dell, 2026-11-17, one `--to check` of the witness fixture
|
|
5
|
+
// in ONE process: 162 child processes, 74 of them repeats of an earlier identical one (git rev-parse --show-toplevel 8 times, --show-object-format
|
|
6
|
+
// 9 times, `where rustright` 7 times), about 5.9 s of a 9 s check.
|
|
7
|
+
//
|
|
8
|
+
// installProbeMemo wraps the synchronous starters of node:child_process. A call is answered from memory only when ALL of this holds:
|
|
9
|
+
// - it is one of the questions listed in `pureQuestion`, whose answer cannot change while a gate process runs;
|
|
10
|
+
// - an identical call (program, arguments, working directory, encoding, the git variables of its environment) already SUCCEEDED in this process.
|
|
11
|
+
// A failed call is never remembered (the thing asked about may appear later: an ephemeral commit, a tool being installed). Anything not listed runs
|
|
12
|
+
// as before. The memo sits above the spawn ledger, so a remembered answer starts no process and writes no ledger line.
|
|
13
|
+
import childProcess from "node:child_process";
|
|
14
|
+
import { createHash } from "node:crypto";
|
|
15
|
+
import fs from "node:fs";
|
|
16
|
+
import module from "node:module";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
|
|
19
|
+
const SHA = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
|
|
20
|
+
const REV_FLAGS = new Set(["--show-toplevel", "--absolute-git-dir", "--show-object-format", "--git-common-dir", "--git-dir"]);
|
|
21
|
+
|
|
22
|
+
/** Whether `cmd args` is a question whose answer is fixed for the life of a gate process. Exported for its test. */
|
|
23
|
+
export function pureQuestion(cmd, args) {
|
|
24
|
+
if (typeof cmd !== "string" || !Array.isArray(args) || !args.every((a) => typeof a === "string")) return false;
|
|
25
|
+
const name = path.basename(cmd.replaceAll("\\", "/")).toLowerCase().replace(/\.(exe|cmd|bat)$/, "");
|
|
26
|
+
if (name === "where" || name === "which") return args.length === 1 && /^[A-Za-z0-9._-]+$/.test(args[0]);
|
|
27
|
+
// A broker job's status, by its id: remembered only once the answer is final (see FINAL_ONLY), never while the job may still change.
|
|
28
|
+
if (name === "rustright") return args.length === 2 && args[0] === "status" && /^[0-9a-f-]{36}$/.test(args[1]);
|
|
29
|
+
if (name !== "git") return false;
|
|
30
|
+
// Leading `-c key=value` pairs configure the call, they are part of the question (and of the key), not a different question.
|
|
31
|
+
let rest = args; while (rest[0] === "-c" && typeof rest[1] === "string" && rest[1].includes("=")) rest = rest.slice(2);
|
|
32
|
+
if (rest[0] === "rev-parse") {
|
|
33
|
+
const tail = rest.slice(1).filter((a) => a !== "--path-format=absolute");
|
|
34
|
+
if (tail.length === 1 && REV_FLAGS.has(tail[0])) return true;
|
|
35
|
+
// Does this id name a commit, or a tree? An object id is content: once it resolves, it always does.
|
|
36
|
+
if (tail.length === 3 && tail[0] === "--verify" && tail[1] === "--quiet") { const m = /^([0-9a-f]+)\^\{(commit|tree)\}$/.exec(tail[2]); return Boolean(m && SHA.test(m[1])); }
|
|
37
|
+
// The app rules' own reading of a commit named by its full id (app-check.mjs): asked again for every stage of a door run (Dell 2026-11-19,
|
|
38
|
+
// crate-edit compile: `rev-parse --verify --end-of-options <id>`, `rev-parse --verify <id>^{}` three times each).
|
|
39
|
+
if (tail.length === 3 && tail[0] === "--verify" && tail[1] === "--end-of-options") return SHA.test(tail[2]);
|
|
40
|
+
if (tail.length === 2 && tail[0] === "--verify") { const m = /^([0-9a-f]+)\^\{\}$/.exec(tail[1]); return Boolean(m && SHA.test(m[1])); }
|
|
41
|
+
// The tree or commit of a full id, asked without --verify (the door, twice per compile run).
|
|
42
|
+
if (tail.length === 1) { const m = /^([0-9a-f]+)\^\{(commit|tree)\}$/.exec(tail[0]); return Boolean(m && SHA.test(m[1])); }
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
// The type of an object named by its full id: content-addressed.
|
|
46
|
+
if (rest[0] === "cat-file") return rest.length === 3 && rest[1] === "-t" && SHA.test(rest[2]);
|
|
47
|
+
if (rest[0] === "config") return rest.length === 3 && rest[1] === "--get" && rest[2] === "remote.origin.url";
|
|
48
|
+
// A file of a commit or tree named by its full id: content-addressed, the same bytes for ever (NN07: `git show <commit>:rk/Cargo.toml` 16 times in
|
|
49
|
+
// one compile of the witness fixture, Dell, 2026-11-17).
|
|
50
|
+
if (rest[0] === "show") return rest.length === 2 && /^[0-9a-f]{40}([0-9a-f]{24})?:[^\0]+$/.test(rest[1]) && !rest[1].includes("..");
|
|
51
|
+
// The file list of a tree named by its full id, names only or with modes and ids (snapshot.mjs treeEntries).
|
|
52
|
+
// Any listing of a tree named by its full id, whatever its listing flags: kept in this process (only the two forms of treeListOf go to disk).
|
|
53
|
+
if (rest[0] === "ls-tree") return treeListOf(args) !== null || (rest.length >= 2 && SHA.test(rest[rest.length - 1]) && rest.slice(1, -1).every((f) => LS_TREE_FLAGS.has(f)));
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const LS_TREE_FLAGS = new Set(["-r", "-z", "-l", "-t", "--name-only", "--full-tree", "--long"]);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* `git grep` over a tree named by its full id (app-check.mjs lists a commit's text files with `grep -z -l -I -e <pattern> <id> --`): the same
|
|
60
|
+
* bytes for ever, so the same answer. Its exit status 1 means "no line matched", which is an answer too; only a pattern given with `-e` and a
|
|
61
|
+
* full id directly before the closing `--` qualify. Exported for its test.
|
|
62
|
+
*/
|
|
63
|
+
export function pureGrep(cmd, args) {
|
|
64
|
+
if (typeof cmd !== "string" || !Array.isArray(args) || !args.every((a) => typeof a === "string")) return false;
|
|
65
|
+
const name = path.basename(cmd.replaceAll("\\", "/")).toLowerCase().replace(/\.(exe|cmd|bat)$/, "");
|
|
66
|
+
if (name !== "git") return false;
|
|
67
|
+
let rest = args; while (rest[0] === "-c" && typeof rest[1] === "string" && rest[1].includes("=")) rest = rest.slice(2);
|
|
68
|
+
if (rest[0] !== "grep" || rest[rest.length - 1] !== "--" || !SHA.test(rest[rest.length - 2] ?? "")) return false;
|
|
69
|
+
const flags = rest.slice(1, -2); const e = flags.indexOf("-e");
|
|
70
|
+
return e >= 0 && e === flags.length - 2 && flags.slice(0, e).every((f) => /^-[A-Za-z]$/.test(f));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* `git cat-file --batch` fed only full object ids on its input: every object is named by its content, so the output is fixed by the input.
|
|
75
|
+
* Returns the sha256 of that input (part of the remembering key), or null when the call is anything else.
|
|
76
|
+
*/
|
|
77
|
+
export function batchInputKey(cmd, args, options) {
|
|
78
|
+
if (typeof cmd !== "string" || !Array.isArray(args) || options?.input === undefined) return null;
|
|
79
|
+
const name = path.basename(cmd.replaceAll("\\", "/")).toLowerCase().replace(/\.(exe|cmd|bat)$/, "");
|
|
80
|
+
if (name !== "git") return null;
|
|
81
|
+
let rest = args; while (rest[0] === "-c" && typeof rest[1] === "string" && rest[1].includes("=")) rest = rest.slice(2);
|
|
82
|
+
if (rest.length !== 2 || rest[0] !== "cat-file" || rest[1] !== "--batch") return null;
|
|
83
|
+
const text = Buffer.isBuffer(options.input) ? options.input.toString("utf8") : typeof options.input === "string" ? options.input : null;
|
|
84
|
+
if (text === null) return null;
|
|
85
|
+
const lines = text.split("\n").filter((l) => l !== "");
|
|
86
|
+
if (!lines.length || !lines.every((l) => SHA.test(l))) return null;
|
|
87
|
+
return createHash("sha256").update(text).digest("hex");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The `ls-tree` question of `args` with its leading `-c` pairs dropped, when it lists a whole tree named by its full id; else null. */
|
|
91
|
+
function treeListOf(args) {
|
|
92
|
+
let rest = args; while (rest[0] === "-c" && typeof rest[1] === "string" && rest[1].includes("=")) rest = rest.slice(2);
|
|
93
|
+
if (rest[0] !== "ls-tree" || !SHA.test(rest[rest.length - 1] ?? "")) return null;
|
|
94
|
+
const flags = rest.slice(1, -1).join(" ");
|
|
95
|
+
return flags === "-r --name-only -z" || flags === "-r -z --full-tree" ? rest : null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* NN22: the file list of a commit named by its full id is the same for ever, so a gate process need not list it again when an earlier one did.
|
|
100
|
+
* Kept on disk under `storeDir` (one file per question, by working directory and the question without its `-c` pairs, which do not change a
|
|
101
|
+
* `-z` listing), only for the two whole-tree listings above. Every warm run listed the witness fixture's commit twice (`ls-tree -r --name-only
|
|
102
|
+
* -z` and the sealed `ls-tree -r -z --full-tree`, Dell, 2026-11-17).
|
|
103
|
+
*/
|
|
104
|
+
export function treeListStore(storeDir, { maxEntries = 256 } = {}) {
|
|
105
|
+
const store = contentStore(storeDir, { maxEntries });
|
|
106
|
+
if (!store) return null;
|
|
107
|
+
const keyOfList = (args, cwd) => { const q = treeListOf(args); return q ? JSON.stringify([path.resolve(cwd ?? process.cwd()), q]) : null; };
|
|
108
|
+
return {
|
|
109
|
+
get(args, cwd) { const k = keyOfList(args, cwd); return k ? store.get(k) : null; },
|
|
110
|
+
put(args, cwd, bytes) { const k = keyOfList(args, cwd); if (k) store.put(k, bytes); },
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Bytes kept on disk under `storeDir` by a string key (one file per key, named by its sha256), for answers that cannot change: a tree listing of a
|
|
116
|
+
* full object id. Each file starts with the sha256 of its key and the bytes it holds together, so a file whose bytes do not match (truncated,
|
|
117
|
+
* half-written, edited) or that sits under another key's name (copied, renamed) is never returned (astra62 review 2, 2026-11-18). The store is
|
|
118
|
+
* the gate user's own state under the gate runs root, the same trust as the result cache beside it.
|
|
119
|
+
*/
|
|
120
|
+
export function contentStore(storeDir, { maxEntries = 256 } = {}) {
|
|
121
|
+
if (typeof storeDir !== "string" || !storeDir) return null;
|
|
122
|
+
const fileOf = (key) => path.join(storeDir, `${createHash("sha256").update(String(key)).digest("hex")}.bin`);
|
|
123
|
+
const seal = (key, body) => createHash("sha256").update(String(key)).update("\0").update(body).digest("hex");
|
|
124
|
+
return {
|
|
125
|
+
get(key) {
|
|
126
|
+
try {
|
|
127
|
+
const raw = fs.readFileSync(fileOf(key)); const body = raw.subarray(65);
|
|
128
|
+
return raw.length >= 65 && raw[64] === 0x0a && raw.subarray(0, 64).toString("latin1") === seal(key, body) ? Buffer.from(body) : null;
|
|
129
|
+
} catch { return null; }
|
|
130
|
+
},
|
|
131
|
+
put(key, bytes) {
|
|
132
|
+
if (!Buffer.isBuffer(bytes)) return;
|
|
133
|
+
const f = fileOf(key);
|
|
134
|
+
try {
|
|
135
|
+
fs.mkdirSync(storeDir, { recursive: true });
|
|
136
|
+
const tmp = `${f}.${process.pid}.tmp`; fs.writeFileSync(tmp, Buffer.concat([Buffer.from(`${seal(key, bytes)}\n`, "latin1"), bytes])); fs.renameSync(tmp, f);
|
|
137
|
+
const names = fs.readdirSync(storeDir).filter((n) => n.endsWith(".bin"));
|
|
138
|
+
if (names.length > maxEntries) {
|
|
139
|
+
const aged = names.map((n) => { try { return [n, fs.statSync(path.join(storeDir, n)).mtimeMs]; } catch { return [n, 0]; } }).sort((a, b) => a[1] - b[1]);
|
|
140
|
+
for (const [n] of aged.slice(0, names.length - maxEntries)) fs.rmSync(path.join(storeDir, n), { force: true });
|
|
141
|
+
}
|
|
142
|
+
} catch { /* a store that cannot be written only means the next run lists again */ }
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const asEncoded = (bytes, encoding) => (encoding && encoding !== "buffer" ? bytes.toString(encoding) : Buffer.from(bytes));
|
|
147
|
+
|
|
148
|
+
/** Whether a successful answer may be kept: always for a git question; for `rustright status` only when the receipt records the job's end. */
|
|
149
|
+
export const FINAL_ONLY = (cmd, out) => {
|
|
150
|
+
const name = path.basename(String(cmd).replaceAll("\\", "/")).toLowerCase().replace(/\.(exe|cmd|bat)$/, "");
|
|
151
|
+
if (name !== "rustright") return true;
|
|
152
|
+
try { const doc = JSON.parse(Buffer.isBuffer(out) ? out.toString("utf8") : String(out)); const r = doc?.receipt ?? doc; return typeof r?.terminalAt === "string" && r.terminalAt.length > 0; } catch { return false; }
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const keyOf = (cmd, args, options) => {
|
|
156
|
+
// The git variables the child sees: its own env's, or this process's when it inherits (NN25: a call with an env and one without asked the same question twice).
|
|
157
|
+
const env = Object.entries(options?.env && typeof options.env === "object" ? options.env : process.env).filter(([k]) => /^GIT_/i.test(k)).sort();
|
|
158
|
+
return JSON.stringify([cmd, args, typeof options?.cwd === "string" ? options.cwd : process.cwd(), options?.encoding ?? null, options?.input === undefined ? null : "has-input", env]);
|
|
159
|
+
};
|
|
160
|
+
const copy = (v) => (Buffer.isBuffer(v) ? Buffer.from(v) : v);
|
|
161
|
+
// NN07 (Dell 2026-11-19, every ledger of the witness fixture): the same question started twice because it was asked two ways. `git config --get
|
|
162
|
+
// remote.origin.url` once as `git` (snapshot.mjs) and once as `C:\Program Files\Git\cmd\git.exe` (the gate's default spawn); `rev-parse
|
|
163
|
+
// --show-toplevel` and `--git-common-dir` the same; and a question asked through spawnSync and again through execFileSync. The contract test keys
|
|
164
|
+
// a start by program name, arguments and directory, so these are one question. Its answer (the bytes of stdout) is kept once under that same key
|
|
165
|
+
// and given to every caller in the form that caller asked for. Only a call that reads stdout through a pipe takes part.
|
|
166
|
+
const programNameOf = (cmd) => path.basename(String(cmd).replaceAll("\\", "/")).toLowerCase().replace(/\.(exe|cmd|bat)$/, "");
|
|
167
|
+
const questionKeyOf = (cmd, args, options) => {
|
|
168
|
+
const env = Object.entries(options?.env && typeof options.env === "object" ? options.env : process.env).filter(([k]) => /^GIT_/i.test(k)).sort();
|
|
169
|
+
return JSON.stringify([programNameOf(cmd), args, path.resolve(typeof options?.cwd === "string" ? options.cwd : process.cwd()), env]);
|
|
170
|
+
};
|
|
171
|
+
const piped = (options) => options?.stdio === undefined || options.stdio === "pipe";
|
|
172
|
+
/** A batch read or a grep answer larger than this is not kept in memory: it is asked again. */
|
|
173
|
+
const KEEP_MAX_BYTES = 8 * 1024 * 1024;
|
|
174
|
+
const bytesOf = (out, encoding) => (Buffer.isBuffer(out) ? Buffer.from(out) : typeof out === "string" ? Buffer.from(out, encoding && encoding !== "buffer" ? encoding : "utf8") : null);
|
|
175
|
+
|
|
176
|
+
let installed = false;
|
|
177
|
+
/**
|
|
178
|
+
* Wrap spawnSync and execFileSync once. Returns the counters object ({ asked, answered, stored }) so a caller can report them; null when already
|
|
179
|
+
* installed. `storeDir`: where whole-tree listings of a full commit id are kept between processes (treeListStore); none when absent.
|
|
180
|
+
*/
|
|
181
|
+
export function installProbeMemo({ storeDir = null } = {}) {
|
|
182
|
+
if (installed) return null;
|
|
183
|
+
installed = true;
|
|
184
|
+
const stats = { asked: 0, answered: 0, stored: 0 };
|
|
185
|
+
const store = treeListStore(storeDir);
|
|
186
|
+
const seenSpawn = new Map(); const seenExec = new Map(); const answers = new Map();
|
|
187
|
+
const spawnSync = childProcess.spawnSync;
|
|
188
|
+
childProcess.spawnSync = function memoSpawnSync(cmd, args, options) {
|
|
189
|
+
const opts = Array.isArray(args) ? options : args; const argv = Array.isArray(args) ? args : [];
|
|
190
|
+
// Two more kinds of fixed answer (NN07, Dell 2026-11-19, compile runs: the app rules read the same commit once per stage). A batch read of
|
|
191
|
+
// objects named by full id is keyed by its input as well; a grep over a full id keeps exit status 1 ("no line matched") as its answer.
|
|
192
|
+
// Both are remembered for the identical call only, never shared between ways of asking, and never when the output is large.
|
|
193
|
+
const batch = opts?.shell ? null : batchInputKey(cmd, argv, opts);
|
|
194
|
+
const grep = !batch && opts?.input === undefined && !opts?.shell && pureGrep(cmd, argv);
|
|
195
|
+
if (!batch && !grep && (opts?.input !== undefined || opts?.shell || !pureQuestion(cmd, argv))) return spawnSync.apply(this, arguments);
|
|
196
|
+
stats.asked += 1; const key = keyOf(cmd, argv, opts) + (batch ? `\u0000${batch}` : ""); const hit = seenSpawn.get(key);
|
|
197
|
+
if (hit) { stats.answered += 1; const stdout = copy(hit.stdout); const stderr = copy(hit.stderr); return { ...hit, stdout, stderr, output: [null, stdout, stderr] }; }
|
|
198
|
+
if (batch || grep) {
|
|
199
|
+
const r = spawnSync.apply(this, arguments);
|
|
200
|
+
const answered = r && !r.error && r.signal === null && (r.status === 0 || (grep && r.status === 1));
|
|
201
|
+
// `git cat-file --batch` exits 0 and prints `<id> missing` for an object the repository does not hold yet: that is not an answer to keep
|
|
202
|
+
// (the object may arrive: an ephemeral commit, a fetch), exactly like a failed question.
|
|
203
|
+
const missing = batch && r && /^[0-9a-f]{40,64} missing$/m.test(Buffer.isBuffer(r.stdout) ? r.stdout.toString("latin1") : String(r.stdout ?? ""));
|
|
204
|
+
if (answered && !missing && (r.stdout?.length ?? 0) <= KEEP_MAX_BYTES) seenSpawn.set(key, { ...r, stdout: copy(r.stdout), stderr: copy(r.stderr) });
|
|
205
|
+
return r;
|
|
206
|
+
}
|
|
207
|
+
const question = piped(opts) ? questionKeyOf(cmd, argv, opts) : null;
|
|
208
|
+
const shared = question ? answers.get(question) : undefined;
|
|
209
|
+
if (shared) {
|
|
210
|
+
stats.answered += 1; const stdout = asEncoded(shared, opts?.encoding); const stderr = asEncoded(Buffer.alloc(0), opts?.encoding);
|
|
211
|
+
const r = { pid: 0, status: 0, signal: null, stdout, stderr, output: [null, stdout, stderr] };
|
|
212
|
+
seenSpawn.set(key, { ...r, stdout: copy(stdout), stderr: copy(stderr) }); return r;
|
|
213
|
+
}
|
|
214
|
+
const kept = store?.get(argv, opts?.cwd);
|
|
215
|
+
if (kept) {
|
|
216
|
+
stats.stored += 1; const stdout = asEncoded(kept, opts?.encoding); const stderr = asEncoded(Buffer.alloc(0), opts?.encoding);
|
|
217
|
+
const r = { pid: 0, status: 0, signal: null, stdout, stderr, output: [null, stdout, stderr] };
|
|
218
|
+
if (question) answers.set(question, Buffer.from(kept));
|
|
219
|
+
seenSpawn.set(key, { ...r, stdout: copy(stdout), stderr: copy(stderr) }); return r;
|
|
220
|
+
}
|
|
221
|
+
const r = spawnSync.apply(this, arguments);
|
|
222
|
+
if (r && !r.error && r.status === 0 && r.signal === null && FINAL_ONLY(cmd, r.stdout)) {
|
|
223
|
+
const bytes = question ? bytesOf(r.stdout, opts?.encoding) : null;
|
|
224
|
+
if (bytes) answers.set(question, bytes);
|
|
225
|
+
seenSpawn.set(key, { ...r, stdout: copy(r.stdout), stderr: copy(r.stderr) });
|
|
226
|
+
if (store) store.put(argv, opts?.cwd, Buffer.isBuffer(r.stdout) ? r.stdout : Buffer.from(String(r.stdout ?? ""), opts?.encoding && opts.encoding !== "buffer" ? opts.encoding : "utf8"));
|
|
227
|
+
}
|
|
228
|
+
return r;
|
|
229
|
+
};
|
|
230
|
+
const execFileSync = childProcess.execFileSync;
|
|
231
|
+
childProcess.execFileSync = function memoExecFileSync(cmd, args, options) {
|
|
232
|
+
const opts = Array.isArray(args) ? options : args; const argv = Array.isArray(args) ? args : [];
|
|
233
|
+
if (opts?.input !== undefined || opts?.shell || !pureQuestion(cmd, argv)) return execFileSync.apply(this, arguments);
|
|
234
|
+
stats.asked += 1; const key = keyOf(cmd, argv, opts);
|
|
235
|
+
if (seenExec.has(key)) { stats.answered += 1; return copy(seenExec.get(key)); }
|
|
236
|
+
const question = piped(opts) ? questionKeyOf(cmd, argv, opts) : null;
|
|
237
|
+
const shared = question ? answers.get(question) : undefined;
|
|
238
|
+
if (shared) { stats.answered += 1; const out = asEncoded(shared, opts?.encoding); seenExec.set(key, copy(out)); return out; }
|
|
239
|
+
const kept = store?.get(argv, opts?.cwd);
|
|
240
|
+
if (kept) { stats.stored += 1; const out = asEncoded(kept, opts?.encoding); if (question) answers.set(question, Buffer.from(kept)); seenExec.set(key, copy(out)); return out; }
|
|
241
|
+
const out = execFileSync.apply(this, arguments); // throws on failure: a failure is never remembered
|
|
242
|
+
if (FINAL_ONLY(cmd, out)) {
|
|
243
|
+
const bytes = question ? bytesOf(out, opts?.encoding) : null;
|
|
244
|
+
if (bytes) answers.set(question, bytes);
|
|
245
|
+
seenExec.set(key, copy(out));
|
|
246
|
+
if (store) store.put(argv, opts?.cwd, Buffer.isBuffer(out) ? out : Buffer.from(String(out), opts?.encoding && opts.encoding !== "buffer" ? opts.encoding : "utf8"));
|
|
247
|
+
}
|
|
248
|
+
return out;
|
|
249
|
+
};
|
|
250
|
+
module.syncBuiltinESMExports();
|
|
251
|
+
return stats;
|
|
252
|
+
}
|