@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.
- package/README.md +1 -1
- package/adapter-env.mjs +16 -105
- package/admission-host.mjs +14 -1
- package/bin/darwin/rightkit-swap +0 -0
- package/bin/rightkit-gate.mjs +609 -404
- package/broker-admission.mjs +122 -2
- package/build-launch.mjs +52 -58
- package/build-release.mjs +2 -2
- package/cargo-ledger.mjs +24 -5
- package/cargo-target-shim.mjs +54 -23
- package/cargo-target.mjs +2 -2
- package/carried-adapter-run.mjs +7 -8
- package/carried-cargo-run.mjs +1 -1
- package/ci-compile-admission.mjs +1 -1
- package/clippy-route.mjs +65 -18
- package/compile-inputs.mjs +91 -15
- package/cross-targets.mjs +5 -3
- package/deps-cargo-lock.mjs +1 -1
- package/deterministic-scans.mjs +789 -259
- package/development.mjs +33 -7
- package/direct-receipt.mjs +3 -5
- package/feature-coverage.mjs +45 -9
- package/feature-partition.mjs +204 -0
- package/feature-sets.mjs +113 -0
- package/gate-acceptance.mjs +187 -115
- package/gate-seam.mjs +352 -0
- package/gate-serve.mjs +34 -2
- package/gate-stages.mjs +6 -2
- package/ghsa-audit.mjs +19 -4
- package/heavy-command.mjs +5 -4
- package/install-tauri-authenticode.mjs +73 -4
- package/ios-dev.mjs +3 -3
- package/ios-package-recipe.mjs +6 -6
- package/linux-setup.mjs +3 -2
- package/local-publish.mjs +113 -17
- package/lock-identity.mjs +24 -100
- package/managed-cargo.mjs +3 -3
- package/managed-root-guard.mjs +2 -2
- package/managed-roots.mjs +3 -3
- package/native-adapters.mjs +41 -244
- package/native-helpers.mjs +1 -1
- package/pack-digest.mjs +1 -1
- package/package-recipe-targets.mjs +3 -3
- package/package.json +2 -2
- package/publication-gate.mjs +29 -6
- package/publish-cargo.mjs +4 -5
- package/publish-local-cargo.mjs +77 -1
- package/qualification-verify.mjs +76 -49
- package/receipt-signature.mjs +104 -0
- package/release-switch-registry.json +4 -0
- package/release-switch-scan.mjs +13 -10
- package/rightkit-versions.json +126 -113
- package/scan-digest.mjs +43 -14
- package/seam-broker.mjs +168 -0
- package/snapshot-check.mjs +4 -1
- package/snapshot-dependency-reuse.mjs +1 -1
- package/snapshot-metadata.mjs +24 -35
- package/snapshot.mjs +328 -49
- package/stage-commands.mjs +59 -5
- package/stage-ledger.mjs +2 -2
- package/{carried-cargo.mjs → stage-seam.mjs} +118 -70
- package/stage-sidecar.mjs +3 -3
- package/tauri-bundle-marker.mjs +5 -2
- package/tauri-locked.mjs +1 -1
- package/tool-build.mjs +8 -6
- package/unit-gate.mjs +40 -10
- package/web-build.mjs +6 -0
- package/broker-handshake.mjs +0 -160
- package/broker-wire.mjs +0 -278
- package/build-ownership.mjs +0 -1578
- package/cargo-shapes.mjs +0 -332
- package/cargo-width.mjs +0 -49
- package/carrier-census.mjs +0 -124
- package/clippy-equivalence.mjs +0 -202
- package/freshness-census.mjs +0 -405
- package/handle-revocation.mjs +0 -100
- package/handle-revocation.rust-vector.json +0 -1
- package/handle-revocation.vectors.json +0 -53
- package/legion-freeze-consumer.mjs +0 -241
- package/linux-qualifier.mjs +0 -83
- package/native-tool-planning.mjs +0 -94
- package/owner-process-proof.mjs +0 -14
- package/ownership-mark.mjs +0 -191
- package/ownership-recover.mjs +0 -78
- package/pnpm-adapter-grammar.mjs +0 -226
- package/provenance-verify.mjs +0 -413
- package/snapshot-broker.mjs +0 -808
- package/snapshot-request.mjs +0 -722
- package/unit-list-compile.mjs +0 -356
package/ownership-mark.mjs
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
// The build-ownership record's broker-submit mark and the constants every process under an ownership shares. A LEAF module: it imports
|
|
2
|
-
// only node builtins, so snapshot-broker.mjs (carried sends, in the gate and in its children) and build-ownership.mjs can both use it
|
|
3
|
-
// without an import cycle.
|
|
4
|
-
import crypto from "node:crypto";
|
|
5
|
-
import fs from "node:fs";
|
|
6
|
-
import os from "node:os";
|
|
7
|
-
import { LOCK_SAME_START_MS, lockBootId, lockProcessIdentity, selfLockIdentity } from "./lock-identity.mjs";
|
|
8
|
-
|
|
9
|
-
export const OWNERSHIP_ENV = "RIGHTKIT_BUILD_OWNERSHIP";
|
|
10
|
-
/** The owner record's path, exported beside the handle so every process under the ownership records detached children there. */
|
|
11
|
-
export const OWNERSHIP_FILE_ENV = "RIGHTKIT_BUILD_OWNERSHIP_FILE";
|
|
12
|
-
|
|
13
|
-
export class OwnershipBusy extends Error {
|
|
14
|
-
constructor(message, detail = {}) { super(message); this.code = "busy"; this.detail = detail; }
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const readText = (file) => { try { return fs.readFileSync(file, "utf8"); } catch (e) { if (e.code === "ENOENT") return null; throw e; } };
|
|
18
|
-
|
|
19
|
-
export function holds(file, handle) {
|
|
20
|
-
try { return JSON.parse(fs.readFileSync(file, "utf8")).handle === handle; } catch { return false; }
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Records, immediately before ONE snapshot-bound (carried) request is sent, that broker work may exist under this handle: sets
|
|
25
|
-
* `broker.submitted` and appends the request's sub-handle (`<handle>#<uuid>`) to `broker.handles`. From then on the record is
|
|
26
|
-
* reclaimed only on the broker's REAPED for the bare handle. Nothing else marks it: installing a carrier map, an uncarried probe
|
|
27
|
-
* (`rustc -vV`, `--version`, doctor) and a request that was never sent leave `submitted` false, because the broker has no lease
|
|
28
|
-
* for a handle it never saw a snapshot-bound request under and could never answer REAPED. Replaces the record atomically, only
|
|
29
|
-
* while it is still this handle's, under a short lock beside the record (carried calls of parallel children, in other
|
|
30
|
-
* processes, mark the same record).
|
|
31
|
-
*/
|
|
32
|
-
/** The row id a caller names, else this process's command line (no environment), cut to 240 characters. */
|
|
33
|
-
const carryNote = (note) => (typeof note === "string" && note ? note : process.argv.slice(1).join(" ")).slice(0, 240);
|
|
34
|
-
|
|
35
|
-
export function markBrokerSubmit(file, handle, callHandle, options = {}) {
|
|
36
|
-
if (typeof callHandle !== "string" || callHandle.length <= handle.length + 1 || !callHandle.startsWith(`${handle}#`) || !/^[A-Za-z0-9._-]+$/.test(callHandle.slice(handle.length + 1))) {
|
|
37
|
-
throw new OwnershipBusy(`build ownership ${file}: a broker submit is recorded only for a carried request's sub-handle of ${handle} (<handle>#<id>), not ${JSON.stringify(callHandle ?? null)}`);
|
|
38
|
-
}
|
|
39
|
-
return withMarkLock(file, () => {
|
|
40
|
-
const text = readText(file);
|
|
41
|
-
let owner = null; try { owner = JSON.parse(text ?? ""); } catch { owner = null; }
|
|
42
|
-
if (owner?.handle !== handle) throw new OwnershipBusy(`build ownership ${file} is no longer held by ${handle}; no broker request may be submitted`);
|
|
43
|
-
const seen = Array.isArray(owner.broker?.handles) ? owner.broker.handles : [];
|
|
44
|
-
if (owner.broker?.submitted && seen.includes(callHandle)) return owner;
|
|
45
|
-
// rightkit#1510: which process and which row or command carried each sub-handle, so a sub-handle left UNKNOWN can be traced to its
|
|
46
|
-
// request. Diagnostic only: no reclaim proof reads it, and handle order never maps concurrent rows.
|
|
47
|
-
const sent = { ...(owner.broker?.sent ?? {}), [callHandle]: { at: new Date().toISOString(), pid: process.pid, note: carryNote(options.note) } };
|
|
48
|
-
const next = { ...owner, broker: { ...(owner.broker ?? {}), submitted: true, at: owner.broker?.at ?? new Date().toISOString(), handles: [...seen, callHandle], sent } };
|
|
49
|
-
const tmp = `${file}.${crypto.randomUUID()}.tmp`;
|
|
50
|
-
fs.writeFileSync(tmp, JSON.stringify(next), { flag: "wx", mode: 0o600 });
|
|
51
|
-
try { fs.renameSync(tmp, file); } finally { fs.rmSync(tmp, { force: true }); }
|
|
52
|
-
if (!holds(file, handle)) throw new OwnershipBusy(`build ownership ${file} changed while recording a broker submit`);
|
|
53
|
-
return next;
|
|
54
|
-
}, options);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* GB-21: records, under the same lock, that the carried request `callHandle` was PROVEN never to have started: the gate could not even start the RustRight client
|
|
59
|
-
* (no such executable, not executable, a refused spawn), so no byte reached the broker. Only a sub-handle already marked as sent can be marked unsent (the mark
|
|
60
|
-
* preceded the attempt); the record keeps `submitted` and the handle, and adds `broker.unsent[callHandle] = { reason, at }`. A reclaim then accepts the sub-handle as
|
|
61
|
-
* settled only when the broker also holds no lease or completion for it (it answers UNKNOWN with no members: it never saw it). An ambiguous send (a timeout, a lost
|
|
62
|
-
* connection after the client started) is never marked unsent: its uncertainty is reconciled by the request id, never erased.
|
|
63
|
-
*/
|
|
64
|
-
export function markBrokerUnsent(file, handle, callHandle, reason, options = {}) {
|
|
65
|
-
if (typeof callHandle !== "string" || callHandle.length <= handle.length + 1 || !callHandle.startsWith(`${handle}#`) || !/^[A-Za-z0-9._-]+$/.test(callHandle.slice(handle.length + 1))) {
|
|
66
|
-
throw new OwnershipBusy(`build ownership ${file}: only a sub-handle of ${handle} (<handle>#<id>) can be marked unsent, not ${JSON.stringify(callHandle ?? null)}`);
|
|
67
|
-
}
|
|
68
|
-
if (typeof reason !== "string" || reason === "") throw new OwnershipBusy(`build ownership ${file}: an unsent mark names the local proof that nothing was sent`);
|
|
69
|
-
return withMarkLock(file, () => {
|
|
70
|
-
let owner = null; try { owner = JSON.parse(readText(file) ?? ""); } catch { owner = null; }
|
|
71
|
-
if (owner?.handle !== handle) throw new OwnershipBusy(`build ownership ${file} is no longer held by ${handle}`);
|
|
72
|
-
if (!Array.isArray(owner.broker?.handles) || !owner.broker.handles.includes(callHandle)) throw new OwnershipBusy(`build ownership ${file}: ${callHandle} was never marked as sent, so it cannot be marked unsent`);
|
|
73
|
-
const next = { ...owner, broker: { ...owner.broker, unsent: { ...(owner.broker.unsent ?? {}), [callHandle]: { reason, at: new Date().toISOString() } } } };
|
|
74
|
-
const tmp = `${file}.${crypto.randomUUID()}.tmp`;
|
|
75
|
-
fs.writeFileSync(tmp, JSON.stringify(next), { flag: "wx", mode: 0o600 });
|
|
76
|
-
try { fs.renameSync(tmp, file); } finally { fs.rmSync(tmp, { force: true }); }
|
|
77
|
-
if (!holds(file, handle)) throw new OwnershipBusy(`build ownership ${file} changed while recording an unsent mark`);
|
|
78
|
-
return next;
|
|
79
|
-
}, options);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const MARK_LOCK_WAIT_MS = 15_000;
|
|
83
|
-
export const MARK_LOCK_SCHEMA = "rightkit.build-ownership-mark-lock/1";
|
|
84
|
-
/** The lock beside the record that serializes `broker.handles` updates. Removed with the record (release, reclaim). */
|
|
85
|
-
export const markLockFile = (file) => `${file}.mark.lock`;
|
|
86
|
-
const stealClaimFile = (file, nonce) => `${markLockFile(file)}.steal-${nonce}`;
|
|
87
|
-
|
|
88
|
-
const defaultSleep = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
89
|
-
const parseLock = (text) => { try { const rec = JSON.parse(text); return rec && typeof rec === "object" && rec.schema === MARK_LOCK_SCHEMA && typeof rec.nonce === "string" && /^[0-9a-f-]{36}$/.test(rec.nonce) ? rec : null; } catch { return null; } };
|
|
90
|
-
const readLockText = (lock) => { try { return fs.readFileSync(lock, "utf8"); } catch (e) { if (e.code === "ENOENT") return null; throw e; } };
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Whether the holder recorded in a lock is `"dead"` (proven), `"live"`, or `"unknown"`. Only `"dead"` ever allows a steal: age proves nothing
|
|
94
|
-
* (a suspended live holder can resume), so a lock is taken from its holder only on proof, the same proofs the ownership record uses
|
|
95
|
-
* (build-ownership.mjs judgeOwner): the host rebooted (boot ids differ), the pid is gone, or the pid now runs a process that started at another
|
|
96
|
-
* time. Anything unreadable, another host, or an identity that cannot be read is not proof.
|
|
97
|
-
*/
|
|
98
|
-
export function judgeLockHolder(rec, { identity, host = os.hostname() }) {
|
|
99
|
-
if (!rec || !Number.isInteger(rec.pid) || rec.pid <= 0) return "unknown";
|
|
100
|
-
if (rec.host !== host) return "unknown";
|
|
101
|
-
let boot = null; try { boot = identity.bootId(); } catch { boot = null; }
|
|
102
|
-
if (typeof rec.bootId === "string" && rec.bootId && typeof boot === "string" && boot && rec.bootId !== boot) return "dead";
|
|
103
|
-
let now;
|
|
104
|
-
try { now = identity.probe(rec.pid); } catch { return "unknown"; }
|
|
105
|
-
if (!now.alive) return "dead";
|
|
106
|
-
if (!Number.isFinite(rec.startedMs) || !Number.isFinite(now.startedMs)) return "unknown";
|
|
107
|
-
return Math.abs(now.startedMs - rec.startedMs) <= LOCK_SAME_START_MS ? "live" : "dead";
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** Creates `target` holding `record` atomically and exclusively: the content is complete the moment the name exists (write a temp file, hard-link it). */
|
|
111
|
-
/** Whether `text` is a well-formed mark lock. A lock is published only fully written (createExclusive links a complete file), so an unreadable one is crash debris. */
|
|
112
|
-
export const isMarkLockText = (text) => parseLock(text ?? "") !== null;
|
|
113
|
-
|
|
114
|
-
function createExclusive(target, record) {
|
|
115
|
-
const tmp = `${target}.${record.nonce}.tmp`;
|
|
116
|
-
fs.writeFileSync(tmp, JSON.stringify(record), { flag: "wx", mode: 0o600 });
|
|
117
|
-
try { fs.linkSync(tmp, target); return true; }
|
|
118
|
-
catch (e) { if (e.code === "EEXIST") return false; throw e; }
|
|
119
|
-
finally { fs.rmSync(tmp, { force: true }); }
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Runs `fn` under the lock beside the record. The lock names its holder (pid, start time, boot id) and carries a random nonce:
|
|
124
|
-
* - a holder that is alive is never displaced, however long it holds (it may be suspended and resume);
|
|
125
|
-
* - a holder PROVEN dead is displaced by one claimant per observed lock (a claim file named by the dead lock's nonce), which removes
|
|
126
|
-
* the lock only while it is still the exact one it judged;
|
|
127
|
-
* - when liveness is uncertain the caller waits, and past the deadline fails closed with OwnershipBusy (no request is sent);
|
|
128
|
-
* - release removes the lock only while it still carries this holder's nonce, so a holder that somehow lost it never removes a successor's.
|
|
129
|
-
* `options` are seams for tests: `identity` ({ self(), probe(pid), bootId() }), `sleep`, `waitMs`.
|
|
130
|
-
*/
|
|
131
|
-
export function withMarkLock(file, fn, options = {}) {
|
|
132
|
-
const lock = markLockFile(file);
|
|
133
|
-
const identity = options.identity ?? { self: () => selfLockIdentity(), probe: (pid) => lockProcessIdentity(pid), bootId: () => lockBootId() };
|
|
134
|
-
const sleep = options.sleep ?? defaultSleep;
|
|
135
|
-
const deadline = Date.now() + (options.waitMs ?? MARK_LOCK_WAIT_MS);
|
|
136
|
-
let me;
|
|
137
|
-
try { me = identity.self(); } catch (e) { throw new OwnershipBusy(`build ownership ${file}: this process's identity cannot be read (${e.message}), so it cannot take the submit lock`); }
|
|
138
|
-
const record = { schema: MARK_LOCK_SCHEMA, pid: me.pid, startedMs: me.startedMs, bootId: me.bootId ?? null, host: os.hostname(), nonce: crypto.randomUUID(), at: new Date().toISOString() };
|
|
139
|
-
const take = (target) => {
|
|
140
|
-
try { return createExclusive(target, record); }
|
|
141
|
-
catch (e) { throw new OwnershipBusy(`build ownership ${file}: the submit lock cannot be taken (${e.code ?? e.message})`); }
|
|
142
|
-
};
|
|
143
|
-
let lastVerdict = "unknown";
|
|
144
|
-
for (;;) {
|
|
145
|
-
if (take(lock)) break;
|
|
146
|
-
let text;
|
|
147
|
-
try { text = readLockText(lock); } catch (e) { throw new OwnershipBusy(`build ownership ${file}: the submit lock cannot be read (${e.code ?? e.message})`); }
|
|
148
|
-
if (text === null) continue; // it was released between the create and the read
|
|
149
|
-
const observed = parseLock(text);
|
|
150
|
-
lastVerdict = observed ? judgeLockHolder(observed, { identity }) : "unknown";
|
|
151
|
-
if (lastVerdict === "dead" && stealDeadLock({ file, lock, text, observed, record, identity, take })) continue;
|
|
152
|
-
if (Date.now() > deadline) throw new OwnershipBusy(`build ownership ${file}: the submit lock ${lock} is held${observed ? ` by pid ${observed.pid}` : " by a holder that cannot be read"} and ${lastVerdict === "live" ? "is alive" : "its liveness cannot be proven"}; no broker request is sent`, { holder: observed, verdict: lastVerdict });
|
|
153
|
-
sleep(10);
|
|
154
|
-
}
|
|
155
|
-
try { return fn(); } finally {
|
|
156
|
-
try { const held = parseLock(readLockText(lock) ?? ""); if (held?.nonce === record.nonce) fs.rmSync(lock, { force: true }); } catch { /* the lock stays; a later caller proves its holder dead */ }
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** Removes the lock `text`/`observed`, whose holder is proven dead, if this process wins the one claim for that lock. Returns whether the retry should go straight on. */
|
|
161
|
-
function stealDeadLock({ file, lock, text, observed, record, identity, take }) {
|
|
162
|
-
const claim = stealClaimFile(file, observed.nonce);
|
|
163
|
-
if (!take(claim)) {
|
|
164
|
-
// Another process is stealing the same dead lock, or died doing it: a claim whose holder is proven dead is dropped, anything else waits.
|
|
165
|
-
const claimText = readLockText(claim);
|
|
166
|
-
if (claimText !== null && judgeLockHolder(parseLock(claimText), { identity }) === "dead") fs.rmSync(claim, { force: true });
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
try {
|
|
170
|
-
if (readLockText(lock) === text) fs.rmSync(lock, { force: true });
|
|
171
|
-
} finally {
|
|
172
|
-
try { if (parseLock(readLockText(claim) ?? "")?.nonce === record.nonce) fs.rmSync(claim, { force: true }); } catch { /* a dead claim is dropped by the next claimant */ }
|
|
173
|
-
}
|
|
174
|
-
return true;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Marks the record at `file` as having sent the carried request `callHandle`, for a caller that holds no ownership object (a
|
|
179
|
-
* right-release child of the gate, in another process, which inherits the handle and file in its environment). Throws
|
|
180
|
-
* OwnershipBusy unless `handle` is still the record's owner.
|
|
181
|
-
*/
|
|
182
|
-
export function markCarriedSend({ file, handle, callHandle }) {
|
|
183
|
-
if (typeof file !== "string" || !file || typeof handle !== "string" || !handle) throw new OwnershipBusy("a carried request is marked only under a build ownership file and handle");
|
|
184
|
-
return markBrokerSubmit(file, handle, callHandle);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/** The caller that holds no ownership object (a right-release child): the same unsent mark under the inherited handle and file. */
|
|
188
|
-
export function markCarriedUnsent({ file, handle, callHandle, reason }) {
|
|
189
|
-
if (typeof file !== "string" || !file || typeof handle !== "string" || !handle) throw new OwnershipBusy("an unsent mark is recorded only under a build ownership file and handle");
|
|
190
|
-
return markBrokerUnsent(file, handle, callHandle, reason);
|
|
191
|
-
}
|
package/ownership-recover.mjs
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Recovery for a build-ownership record left by a gate that died or was stopped (rightkit#1513; Adrian, 2026-11-05: "have proper recovery
|
|
3
|
-
// tools for the fucking gate. This recovery avoidance is wrong"; "It should ideally auto recover").
|
|
4
|
-
// The gate's own reclaim recovers automatically (build-ownership.mjs coveredWorkGone): a sub-handle the broker answers UNKNOWN with no member
|
|
5
|
-
// row was never received when the same broker process has run since before the ownership was acquired and no process of the run remains.
|
|
6
|
-
// This tool explains a held record (processes, broker leases, every sub-handle) and, with --apply, runs that reclaim now and releases.
|
|
7
|
-
//
|
|
8
|
-
// node ownership-recover.mjs <owner.json> [--apply] [--wait-ms N]
|
|
9
|
-
// Dry run by default: prints the evidence and the plan, changes nothing. Exit 0 recovered (or nothing to do / plan clean), 2 refused, 64 usage.
|
|
10
|
-
import { spawnSync } from "node:child_process";
|
|
11
|
-
import fs from "node:fs";
|
|
12
|
-
import { fileURLToPath } from "node:url";
|
|
13
|
-
import { acquireBuildOwnership, brokerLeaseState, proveOwnerProcessesGone, runningBrokerProcess } from "./build-ownership.mjs";
|
|
14
|
-
|
|
15
|
-
const SETTLE_MS = 2000;
|
|
16
|
-
|
|
17
|
-
export async function recover({ file, apply = false, waitMs = 600_000, log = console.log, lease = brokerLeaseState, broker = () => runningBrokerProcess(), sleep = (ms) => new Promise((r) => setTimeout(r, ms)) }) {
|
|
18
|
-
const text = (() => { try { return fs.readFileSync(file, "utf8"); } catch (e) { if (e.code === "ENOENT") return null; throw e; } })();
|
|
19
|
-
if (text === null) { log(`recover: ${file}: no record; nothing to recover`); return 0; }
|
|
20
|
-
const owner = JSON.parse(text);
|
|
21
|
-
log(`recover: ${file}: held by ${owner.handle} (pid ${owner.pid}, ${owner.stage ?? "stage"} of ${owner.commit ?? "a commit"}) since ${owner.acquiredAt}`);
|
|
22
|
-
|
|
23
|
-
// 1. Processes: the owner and everything of its run are gone (the reclaim's own process proof, no broker judged).
|
|
24
|
-
let proof;
|
|
25
|
-
try { proof = proveOwnerProcessesGone({ file }); } catch (e) { log(`recover: REFUSED: ${e.message}`); return 2; }
|
|
26
|
-
for (const p of proof.proofs) log(` process: ${p}`);
|
|
27
|
-
|
|
28
|
-
// 2. Broker: every submission settled. Wait for ACTIVE work of the dead run to finish (a stopped gate leaves its last broker jobs running).
|
|
29
|
-
const subs = [...new Set(Array.isArray(owner.broker?.handles) ? owner.broker.handles : [])];
|
|
30
|
-
const unsent = owner.broker?.unsent ?? {};
|
|
31
|
-
const deadline = Date.now() + waitMs;
|
|
32
|
-
let ownerLease;
|
|
33
|
-
for (;;) {
|
|
34
|
-
ownerLease = lease({ snapshot: owner.snapshot, handle: owner.handle });
|
|
35
|
-
if (ownerLease.state !== "ACTIVE") break;
|
|
36
|
-
if (Date.now() > deadline) { log(`recover: REFUSED: broker work under ${owner.handle} is still ACTIVE after ${Math.round(waitMs / 1000)} s`); return 2; }
|
|
37
|
-
log(` broker: ${owner.handle} ACTIVE; waiting`); await sleep(5000);
|
|
38
|
-
}
|
|
39
|
-
log(` broker: owner lease ${ownerLease.state} (${(ownerLease.members ?? []).length} member row(s))`);
|
|
40
|
-
if (!subs.length || !owner.broker?.submitted) log(" broker: no carried request was recorded");
|
|
41
|
-
|
|
42
|
-
const brk = broker();
|
|
43
|
-
const acquiredMs = Date.parse(owner.acquiredAt);
|
|
44
|
-
const brokerSawAll = Boolean(brk && Number.isFinite(acquiredMs) && brk.startedMs + SETTLE_MS < acquiredMs);
|
|
45
|
-
log(` broker process: ${brk ? `pid ${brk.pid} up since ${new Date(brk.startedMs).toISOString()}` : "not established"}; ${brokerSawAll ? "continuously up since before this ownership" : "NOT shown up since before this ownership"}`);
|
|
46
|
-
|
|
47
|
-
const toMark = []; const refused = []; let reaped = 0;
|
|
48
|
-
for (const sub of subs) {
|
|
49
|
-
if (unsent[sub]) continue;
|
|
50
|
-
const one = lease({ snapshot: owner.snapshot, handle: sub });
|
|
51
|
-
const listed = (ownerLease.members ?? []).find((m) => m.handle === sub);
|
|
52
|
-
if (one.state === "REAPED") { reaped += 1; continue; }
|
|
53
|
-
if (one.state === "ACTIVE" || (listed && listed.state !== "REAPED")) { refused.push(`${sub}: ${one.state}${listed ? ` (listed ${listed.state})` : ""}`); continue; }
|
|
54
|
-
if (one.state === "UNKNOWN" && Array.isArray(one.members) && one.members.length === 0 && !listed && brokerSawAll) { toMark.push(sub); continue; }
|
|
55
|
-
refused.push(`${sub}: ${one.state} (${one.why ?? ""})${brokerSawAll ? "" : "; the broker was not up throughout, so UNKNOWN proves nothing"}`);
|
|
56
|
-
}
|
|
57
|
-
log(` sub-handles: ${subs.length} recorded, ${reaped} REAPED, ${Object.keys(unsent).length} already marked unsent, ${toMark.length} never received, ${refused.length} unresolved`);
|
|
58
|
-
if (refused.length) { for (const r of refused.slice(0, 10)) log(` unresolved: ${r}`); log("recover: REFUSED: some broker work cannot be accounted for"); return 2; }
|
|
59
|
-
|
|
60
|
-
// The reclaim itself settles a never-received sub-handle (build-ownership.mjs coveredWorkGone, rightkit#1513): the next gate run recovers this
|
|
61
|
-
// record automatically; --apply runs that same reclaim now and releases.
|
|
62
|
-
if (!apply) { log(`recover: recoverable: ${reaped} REAPED, ${toMark.length} never reached the broker. The next gate run reclaims it automatically; --apply reclaims now.`); return 0; }
|
|
63
|
-
let own;
|
|
64
|
-
try { own = acquireBuildOwnership({ file, stage: "ownership-recover", snapshot: owner.snapshot, commit: owner.commit, exportEnv: false }); }
|
|
65
|
-
catch (e) { log(`recover: REFUSED by the reclaim: ${e.message}`); return 2; }
|
|
66
|
-
for (const p of own.reclaimed?.proofs ?? []) log(` reclaim: ${p.slice(0, 200)}`);
|
|
67
|
-
const rel = own.release();
|
|
68
|
-
log(`recover: recovered ${owner.handle}; released ${rel?.released === true ? "cleanly" : JSON.stringify(rel).slice(0, 200)}`);
|
|
69
|
-
return 0;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (process.argv[1] && fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(import.meta.url))) {
|
|
73
|
-
const args = process.argv.slice(2);
|
|
74
|
-
const file = args.find((a) => !a.startsWith("--"));
|
|
75
|
-
const waitAt = args.indexOf("--wait-ms");
|
|
76
|
-
if (!file) { console.error("usage: ownership-recover.mjs <owner.json> [--apply] [--wait-ms N]"); process.exit(64); }
|
|
77
|
-
recover({ file, apply: args.includes("--apply"), waitMs: waitAt >= 0 ? Number(args[waitAt + 1]) : undefined }).then((code) => process.exit(code), (e) => { console.error(`recover: ${e.stack ?? e}`); process.exit(2); });
|
|
78
|
-
}
|
package/pnpm-adapter-grammar.mjs
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
// The door's mirror of the broker's `rightkit-pnpm` adapter grammar (rustright-policy adapter.rs `scan`, `check_argv`, `snapshot_argv_check`,
|
|
2
|
-
// `check_environment`; GB-03 and GB-04 of the gate-vs-broker audit).
|
|
3
|
-
//
|
|
4
|
-
// RustRight owns the registered grammar; RightKit validates every pnpm argv and every request environment against that registration BEFORE it is
|
|
5
|
-
// sent, and refuses with a typed reason naming the registration, so a refusal never costs a mark, a process or a stage. The reference registration
|
|
6
|
-
// is RustRight's `adapters.pnpm` entry of docs/contracts/adapter-argv.fixtures.json (test-support/vectors/, pinned in vectors-source.json): the
|
|
7
|
-
// operator installs exactly that registration, and every accepted and refused row of the vector is judged by `adapterArgvRefusal` here.
|
|
8
|
-
//
|
|
9
|
-
// Facts the planner depends on (the registration, not RightKit inventions): a global flag that takes a value is registered as a flag AND as a leading
|
|
10
|
-
// subcommand token (`--dir`, `-C`, `--filter`); `--if-present` is a `run` option and goes after `run`; everything after the target of `run` or
|
|
11
|
-
// `exec` belongs to the target and is opaque (`run x --flag` and `run x -- --flag` are both admitted, so the gate never rewrites them); `exec`
|
|
12
|
-
// admits only the targets in `opaqueTargets.exec`, never an arbitrary executable.
|
|
13
|
-
//
|
|
14
|
-
// The door reads the LIVE registration when it can (liveAdapterGrammar) and otherwise judges by PNPM_ADAPTER_GRAMMAR, the reference. A test compares
|
|
15
|
-
// the constant with the vector and, on a host that has the registration, with the live entry, so neither can drift without a failing test.
|
|
16
|
-
import fs, { readFileSync } from "node:fs";
|
|
17
|
-
import path from "node:path";
|
|
18
|
-
import { resolveManagedRoots } from "./managed-roots.mjs";
|
|
19
|
-
|
|
20
|
-
export const PNPM_ADAPTER = "rightkit-pnpm";
|
|
21
|
-
/** The scratch child prefix of a `scratchPackDir` / `scratchPath` value (adapter.rs SCRATCH_CHILD_PREFIX). */
|
|
22
|
-
const SCRATCH_CHILD_PREFIX = "rk-local-publish-";
|
|
23
|
-
|
|
24
|
-
const frozenList = (v) => Object.freeze(Array.isArray(v) ? v.filter((s) => typeof s === "string") : []);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The reference registration of the pnpm adapter, as RustRight's vector carries it (docs/contracts/adapter-argv.fixtures.json `adapter`, minus the
|
|
28
|
-
* host's pinned script and scratch root): `subcommands` are the registered first arguments, `flags` the registered flags with their value kind,
|
|
29
|
-
* `env` the only non-reserved request-environment keys the adapter takes.
|
|
30
|
-
*/
|
|
31
|
-
export const PNPM_ADAPTER_GRAMMAR = Object.freeze({
|
|
32
|
-
subcommands: Object.freeze(["install", "run", "exec", "pack", "-r", "--dir", "-C", "--filter", "--workspace-concurrency=1"]),
|
|
33
|
-
flags: Object.freeze({
|
|
34
|
-
"--dir": "relpathOrScratchPath", "-C": "relpathOrScratchPath", "--filter": "any", "--if-present": "none", "--workspace-concurrency": "int", "--pack-destination": "scratchPackDir",
|
|
35
|
-
}),
|
|
36
|
-
positionals: "relpath",
|
|
37
|
-
env: Object.freeze(["RK_ISOLATED_CHECKOUT", "RIGHTKIT_QA_APP_BINARY", "RIGHTKIT_QA_SIGNING_EVIDENCE"]),
|
|
38
|
-
opaqueAfterTarget: Object.freeze(["run", "exec"]),
|
|
39
|
-
opaqueTargets: Object.freeze({ exec: Object.freeze(["tauri"]) }),
|
|
40
|
-
snapshotSubcommands: Object.freeze(["run", "exec", "pack"]),
|
|
41
|
-
// The host's scratch root is host configuration (the vector's `{scratch}` placeholder): unknown here, so a scratch-kind value is judged by shape and the
|
|
42
|
-
// broker's canonical containment check decides (a live registration, which names its root, is judged canonically too).
|
|
43
|
-
scratchRoot: undefined,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
/** The grammar a registered adapter spec declares (the fields the door uses), or null when `spec` is not a usable registration. */
|
|
47
|
-
export function grammarFromSpec(spec) {
|
|
48
|
-
if (!spec || typeof spec !== "object" || (spec.subcommands !== undefined && spec.subcommands !== null && (!Array.isArray(spec.subcommands) || !spec.subcommands.every((s) => typeof s === "string" && s !== "")))) return null;
|
|
49
|
-
if (!Array.isArray(spec.flags) || !spec.flags.every((f) => f && typeof f.name === "string" && typeof f.value === "string")) return null;
|
|
50
|
-
const targets = spec.opaqueTargets && typeof spec.opaqueTargets === "object" && !Array.isArray(spec.opaqueTargets) ? spec.opaqueTargets : {};
|
|
51
|
-
return Object.freeze({
|
|
52
|
-
subcommands: Array.isArray(spec.subcommands) ? Object.freeze([...spec.subcommands]) : null,
|
|
53
|
-
flags: Object.freeze(Object.fromEntries(spec.flags.map((f) => [f.name, f.value]))),
|
|
54
|
-
positionals: typeof spec.positionals === "string" ? spec.positionals : "none",
|
|
55
|
-
env: frozenList(spec.env),
|
|
56
|
-
opaqueAfterTarget: frozenList(spec.opaqueAfterTarget),
|
|
57
|
-
...(Array.isArray(spec.positionalValues) ? { positionalValues: frozenList(spec.positionalValues) } : {}),
|
|
58
|
-
...(spec.flagPrefixes && typeof spec.flagPrefixes === "object" ? { flagPrefixes: Object.freeze({ ...spec.flagPrefixes }) } : {}),
|
|
59
|
-
opaqueTargets: Object.freeze(Object.fromEntries(Object.entries(targets).map(([command, list]) => [command, frozenList(list)]))),
|
|
60
|
-
snapshotSubcommands: frozenList(spec.snapshotSubcommands),
|
|
61
|
-
scratchRoot: typeof spec.scratchRoot === "string" && spec.scratchRoot !== "" ? spec.scratchRoot : null,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** The live registration on this host (the managed control root's config.json, adapters["rightkit-pnpm"]), or null when it cannot be read. */
|
|
66
|
-
export function liveAdapterGrammar({ env = process.env, platform = process.platform, readFile = (file) => readFileSync(file, "utf8"), adapter = PNPM_ADAPTER } = {}) {
|
|
67
|
-
try {
|
|
68
|
-
const { configPath } = resolveManagedRoots({ env, platform });
|
|
69
|
-
return grammarFromSpec(JSON.parse(readFile(configPath))?.adapters?.[adapter]);
|
|
70
|
-
} catch { return null; }
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// ---- value kinds (adapter.rs value_ok / relpath_ok / scratch_shape_ok) ----
|
|
74
|
-
|
|
75
|
-
const relpathOk = (v) => v !== "" && !v.includes("\0") && !v.startsWith("/") && !v.startsWith("\\") && !(v.length >= 2 && v[1] === ":") && v.split(/[\\/]/).every((part) => part !== "..");
|
|
76
|
-
const isAbsoluteAnywhere = (v) => path.posix.isAbsolute(v) || path.win32.isAbsolute(v) || v.startsWith("\\");
|
|
77
|
-
const scratchShapeOk = (v) => v !== "" && !v.includes("\0") && (path.isAbsolute(v) || path.posix.isAbsolute(v) || path.win32.isAbsolute(v)) && v.split(/[\\/]/).every((part) => part !== "..");
|
|
78
|
-
/** Build settings a caller never sets for an Apple build: they redirect where the build writes (the broker owns the output root) or choose the signing identity (the provisioned signer's). */
|
|
79
|
-
const XCODE_DENIED_SETTINGS = /^(?:SYMROOT|OBJROOT|DSTROOT|BUILD_DIR|BUILD_ROOT|CONFIGURATION_BUILD_DIR|CONFIGURATION_TEMP_DIR|TARGET_BUILD_DIR|SHARED_PRECOMPS_DIR|MODULE_CACHE_DIR|DERIVED_DATA_DIR|CODE_SIGN_IDENTITY|CODE_SIGN_STYLE|OTHER_CODE_SIGN_FLAGS|PROVISIONING_PROFILE(?:_SPECIFIER)?|CODE_SIGN_ENTITLEMENTS|CODE_SIGNING_ALLOWED|CODE_SIGNING_REQUIRED)=/;
|
|
80
|
-
/** CMake cache entries that run or load arbitrary code from a path the caller names. */
|
|
81
|
-
const CMAKE_DENIED_DEFINES = /^(?:CMAKE_COMMAND|CMAKE_MAKE_PROGRAM|CMAKE_PROJECT_INCLUDE(?:_BEFORE)?|CMAKE_MODULE_PATH|CMAKE_PREFIX_PATH|CMAKE_PROGRAM_PATH)[:=]/;
|
|
82
|
-
function valueOk(kind, v) {
|
|
83
|
-
switch (kind) {
|
|
84
|
-
case "identifier": return /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/.test(v);
|
|
85
|
-
case "gradleTask": return /^:?[A-Za-z0-9][A-Za-z0-9_:.-]{0,255}$/.test(v) && !/(?:^|:)(?:publish|upload)|(?:bundle|assemble|install)[A-Za-z0-9]*Release/i.test(v);
|
|
86
|
-
case "actionOrBuildSetting": return v.includes("=") ? valueOk("buildSetting", v) : valueOk("identifier", v);
|
|
87
|
-
case "buildSetting": return /^[A-Z][A-Za-z0-9_]*=[^\0]*$/.test(v) && !XCODE_DENIED_SETTINGS.test(v);
|
|
88
|
-
case "cmakeDefine": return /^[A-Za-z_][A-Za-z0-9_.+-]*(?::[A-Z]+)?=[^\0]*$/.test(v) && !CMAKE_DENIED_DEFINES.test(v);
|
|
89
|
-
case "none": return false;
|
|
90
|
-
case "any": return !v.includes("\0");
|
|
91
|
-
case "int": return v !== "" && /^[0-9]+$/.test(v);
|
|
92
|
-
case "swiftConfiguration": return v === "debug" || v === "release";
|
|
93
|
-
case "swiftArch": return v === "arm64" || v === "x86_64";
|
|
94
|
-
case "relpath": return relpathOk(v);
|
|
95
|
-
case "scratchPath": case "scratchPackDir": return scratchShapeOk(v);
|
|
96
|
-
case "relpathOrScratchPath": return relpathOk(v) || scratchShapeOk(v);
|
|
97
|
-
default: return false;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const needsScratchCheck = (kind, v) => kind === "scratchPath" || kind === "scratchPackDir" || (kind === "relpathOrScratchPath" && !relpathOk(v));
|
|
101
|
-
|
|
102
|
-
/** adapter.rs `scratch_canonical_ok`: the value exists and, resolved, is strictly inside an `rk-local-publish-*` child of the scratch root (a pack dir: an empty-of-tgz directory). */
|
|
103
|
-
function scratchCanonicalProblem(root, value, packDir, { realpath = (p) => fs.realpathSync.native(p), stat = (p) => fs.statSync(p), list = (p) => fs.readdirSync(p) } = {}) {
|
|
104
|
-
if (!scratchShapeOk(value)) return "must be an absolute path with no '..'";
|
|
105
|
-
let canonicalRoot; let canonical;
|
|
106
|
-
try { canonicalRoot = realpath(root); } catch (e) { return `the scratch root cannot be resolved: ${e.message}`; }
|
|
107
|
-
try { canonical = realpath(value); } catch (e) { return `cannot be resolved: ${e.message}`; }
|
|
108
|
-
const rel = path.relative(canonicalRoot, canonical);
|
|
109
|
-
if (rel === "" ) return "is the scratch root itself";
|
|
110
|
-
if (rel.startsWith("..") || path.isAbsolute(rel)) return "resolves outside the scratch root";
|
|
111
|
-
const parts = rel.split(path.sep);
|
|
112
|
-
if (!parts[0].startsWith(SCRATCH_CHILD_PREFIX)) return `is not inside a ${SCRATCH_CHILD_PREFIX}* child of the scratch root`;
|
|
113
|
-
if (parts.length < 2) return "is the scratch child itself; it must be strictly inside it";
|
|
114
|
-
if (packDir) {
|
|
115
|
-
try { if (!stat(canonical).isDirectory()) return "must be an existing directory"; if (list(canonical).some((n) => n.toLowerCase().endsWith(".tgz"))) return "must hold no .tgz yet"; } catch (e) { return `cannot be read: ${e.message}`; }
|
|
116
|
-
}
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const flagNameOf = (word) => (word.startsWith("--") && word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* The pure pass of adapter.rs `scan`: every argument is a registered flag (with its value), a positional of the allowed kind, or the first-argument
|
|
124
|
-
* subcommand. Returns `{ error }` or `{ command, positionals, opaqueTail, flagValues, scratch }`. A subcommand that is also a registered flag
|
|
125
|
-
* (`--dir`) is read as that flag, so its value is judged by the flag's kind and never taken for a positional.
|
|
126
|
-
*/
|
|
127
|
-
export function scanAdapterArgv(argv, grammar = PNPM_ADAPTER_GRAMMAR) {
|
|
128
|
-
const args = [...argv].map(String);
|
|
129
|
-
const found = { command: null, target: null, positionals: [], opaqueTail: [], flagValues: [], scratch: [] };
|
|
130
|
-
let index = 0; let awaiting = false; let opaque = false; let commandSeen = false;
|
|
131
|
-
const first = args[0];
|
|
132
|
-
const name = grammar.adapter ?? PNPM_ADAPTER;
|
|
133
|
-
if (grammar.subcommands === null) {
|
|
134
|
-
// No registered first argument (an adapter whose tool takes flags and positionals only, such as gradle, cmake and xcodebuild): the scan starts at the first word.
|
|
135
|
-
index = 0;
|
|
136
|
-
} else {
|
|
137
|
-
if (first === undefined) return { error: "a subcommand is required" };
|
|
138
|
-
if (!grammar.subcommands.includes(first)) return { error: `subcommand ${JSON.stringify(first)} is not registered for ${name} (registered: ${grammar.subcommands.join(", ")}); a leading flag such as --if-present, --prefix or --config is refused (--if-present goes after \`run\`)` };
|
|
139
|
-
awaiting = grammar.opaqueAfterTarget.includes(first);
|
|
140
|
-
commandSeen = !first.startsWith("-");
|
|
141
|
-
if (commandSeen) found.command = first;
|
|
142
|
-
index = first.startsWith("-") && Object.hasOwn(grammar.flags, first) ? 0 : 1;
|
|
143
|
-
}
|
|
144
|
-
let afterSeparator = false;
|
|
145
|
-
while (index < args.length) {
|
|
146
|
-
const word = args[index]; index += 1;
|
|
147
|
-
if (word.includes("\0")) return { error: "arguments must not contain NUL" };
|
|
148
|
-
if (opaque) { found.opaqueTail.push(word); continue; }
|
|
149
|
-
if (!afterSeparator && word === "--") { afterSeparator = true; continue; }
|
|
150
|
-
if (afterSeparator || !word.startsWith("-") || word === "-") {
|
|
151
|
-
if (grammar.positionals === "none" || !valueOk(grammar.positionals, word)) return { error: `positional argument ${JSON.stringify(word)} is not allowed` };
|
|
152
|
-
if (grammar.positionalValues && !word.includes("=") && !grammar.positionalValues.includes(word)) return { error: `positional argument ${JSON.stringify(word)} is not registered for ${grammar.adapter ?? PNPM_ADAPTER} (registered: ${grammar.positionalValues.join(", ")})` };
|
|
153
|
-
if (needsScratchCheck(grammar.positionals, word)) found.scratch.push(["positional argument", grammar.positionals, word]);
|
|
154
|
-
found.positionals.push(word);
|
|
155
|
-
if (awaiting) {
|
|
156
|
-
awaiting = false; opaque = true; found.target = word;
|
|
157
|
-
const allowed = grammar.opaqueTargets[found.command ?? ""];
|
|
158
|
-
if (allowed && !allowed.includes(word)) return { error: `target ${JSON.stringify(word)} is not registered for ${found.command} (registered targets: ${allowed.join(", ")}); an arbitrary executable is never admitted through exec` };
|
|
159
|
-
} else if (!commandSeen) {
|
|
160
|
-
commandSeen = true; found.command = word; awaiting = grammar.opaqueAfterTarget.includes(word);
|
|
161
|
-
}
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
// A registered flag PREFIX carries its value in the same word (`-DNAME=value`): the rest of the word is the value, judged by the prefix's kind.
|
|
165
|
-
const prefix = grammar.flagPrefixes ? Object.keys(grammar.flagPrefixes).find((p) => word.startsWith(p) && word.length > p.length) : undefined;
|
|
166
|
-
if (prefix !== undefined) {
|
|
167
|
-
const value = word.slice(prefix.length);
|
|
168
|
-
if (!valueOk(grammar.flagPrefixes[prefix], value)) return { error: `flag ${JSON.stringify(prefix)} has a value of the wrong kind or one ${grammar.adapter ?? PNPM_ADAPTER} never admits (${JSON.stringify(value)})` };
|
|
169
|
-
found.flagValues.push([`flag ${JSON.stringify(prefix)}`, grammar.flagPrefixes[prefix], value]);
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
const name = flagNameOf(word);
|
|
173
|
-
const inline = word.startsWith("--") && word.includes("=") ? word.slice(word.indexOf("=") + 1) : null;
|
|
174
|
-
if (!Object.hasOwn(grammar.flags, name)) return { error: `flag ${JSON.stringify(name)} is not registered for ${grammar.adapter ?? PNPM_ADAPTER}` };
|
|
175
|
-
const kind = grammar.flags[name];
|
|
176
|
-
let value;
|
|
177
|
-
if (kind === "none") { if (inline !== null) return { error: `flag ${JSON.stringify(name)} takes no value` }; continue; }
|
|
178
|
-
if (inline !== null) value = inline;
|
|
179
|
-
else {
|
|
180
|
-
value = args[index]; index += 1;
|
|
181
|
-
if (value === undefined) return { error: `flag ${JSON.stringify(name)} needs a value` };
|
|
182
|
-
if (value.includes("\0")) return { error: "arguments must not contain NUL" };
|
|
183
|
-
}
|
|
184
|
-
if (!valueOk(kind, value)) return { error: `flag ${JSON.stringify(name)} has a value of the wrong kind (${kind})` };
|
|
185
|
-
found.flagValues.push([`flag ${JSON.stringify(name)}`, kind, value]);
|
|
186
|
-
if (needsScratchCheck(kind, value)) found.scratch.push([`flag ${JSON.stringify(name)}`, kind, value]);
|
|
187
|
-
}
|
|
188
|
-
if (awaiting) return { error: "launcher subcommand requires a target" };
|
|
189
|
-
return found;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/** The pnpm command token the registration reads from `args` (adapter.rs scan's `command`), or null when the argv does not parse. */
|
|
193
|
-
export function pnpmCommandOf(args, grammar = PNPM_ADAPTER_GRAMMAR) {
|
|
194
|
-
const found = scanAdapterArgv(args, grammar);
|
|
195
|
-
return found.error ? null : found.command;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Why the broker's pnpm adapter would refuse these arguments, or null (adapter.rs `check_argv`; with `snapshot`, also `snapshot_argv_check`'s
|
|
200
|
-
* subcommand and relative-path rules). Judged against `grammar` (the live registration, else the reference). A scratch-kind value is checked canonically
|
|
201
|
-
* against the registration's scratch root when it names one (a value of that kind with no scratch root registered is refused). The tail of an opaque
|
|
202
|
-
* target is the target's own and is never interpreted here.
|
|
203
|
-
*/
|
|
204
|
-
export function adapterArgvRefusal(words, grammar = PNPM_ADAPTER_GRAMMAR, { snapshot = false, fsOps = {} } = {}) {
|
|
205
|
-
const found = scanAdapterArgv(words, grammar);
|
|
206
|
-
if (found.error) return found.error;
|
|
207
|
-
for (const [what, kind, value] of found.scratch) {
|
|
208
|
-
if (grammar.scratchRoot === undefined) continue;
|
|
209
|
-
if (grammar.scratchRoot === null) return `${what}: this adapter registers no scratch root`;
|
|
210
|
-
const problem = scratchCanonicalProblem(grammar.scratchRoot, value, kind === "scratchPackDir", fsOps);
|
|
211
|
-
if (problem) return `${what} ${JSON.stringify(value)}: ${problem}`;
|
|
212
|
-
}
|
|
213
|
-
if (snapshot) {
|
|
214
|
-
if (grammar.snapshotSubcommands.length) {
|
|
215
|
-
if (found.command === null) return "a snapshot-bound call needs a command";
|
|
216
|
-
if (!grammar.snapshotSubcommands.includes(found.command)) return `subcommand ${JSON.stringify(found.command)} is not allowed in a snapshot-bound call (allowed: ${grammar.snapshotSubcommands.join(", ")})`;
|
|
217
|
-
}
|
|
218
|
-
for (const [what, kind, value] of found.flagValues) {
|
|
219
|
-
if ((kind === "relpath" || kind === "relpathOrScratchPath" || kind === "scratchPath") && isAbsoluteAnywhere(value)) return `${what} ${JSON.stringify(value)} must be relative in a snapshot-bound call`;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return null;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/** Kept name of the door's pnpm check: the argv judged by `grammar` (a snapshot-bound call when `snapshot`). */
|
|
226
|
-
export const pnpmGrammarRefusal = (words, grammar = PNPM_ADAPTER_GRAMMAR, options = {}) => adapterArgvRefusal(words, grammar, options);
|