@rightkit/release 0.6.52 → 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 +585 -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/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/cargo-shapes.mjs
DELETED
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
// The ONE versioned command-shape table of the gate's Cargo calls (GB-01, GB-02; audit gate-broker-2026-10-30).
|
|
2
|
-
//
|
|
3
|
-
// RustRight owns the admitted grammar (rustright-policy command_policy.rs `ThinCommandPolicy::classify`, `snapshot_read_only`,
|
|
4
|
-
// `grant_command`, `carried_refusal`, and `normalize_build_request` for the standard aliases). RightKit owns the callers. Both read one
|
|
5
|
-
// vector: docs/contracts/cargo-shapes.fixtures.json of RustRight (schema `rustright.cargo-shapes.fixtures.v1`), copied byte for byte into
|
|
6
|
-
// test-support/vectors/ with its source identity pinned (vectors-source.json). Every row of it is judged here by `classifyCargoArgv`, so
|
|
7
|
-
// the wrapper (cargo-target-shim.mjs), the carried call (snapshot-request.mjs) and the planners (stage-commands.mjs) decide from the same
|
|
8
|
-
// function and cannot drift from the broker: an accepted row reaches the broker's parser, a refused row launches zero processes.
|
|
9
|
-
//
|
|
10
|
-
// `argv` is cargo's argument list without the `cargo` word. Nothing here rewrites a caller's arguments except the five standard aliases at
|
|
11
|
-
// the subcommand position (`b c d r t`), which the broker expands before it classifies (a committed `.cargo/config.toml` `[alias]` can
|
|
12
|
-
// otherwise redefine what was classified). A `fmt` argument is never changed and a plugin restriction is never weakened.
|
|
13
|
-
|
|
14
|
-
export const COMMAND_SHAPES_SCHEMA = "rightkit.command-shapes/1";
|
|
15
|
-
export const COMMAND_SHAPES_VERSION = 1;
|
|
16
|
-
/** The RustRight vector this table is exercised against (its `schema`); a change of either side is a failing test, not a silent drift. */
|
|
17
|
-
export const COMMAND_SHAPES_VECTOR_SCHEMA = "rustright.cargo-shapes.fixtures.v1";
|
|
18
|
-
|
|
19
|
-
/** Cargo's standard aliases (rustright cargo_argv.rs CARGO_ALIASES), expanded at the subcommand position before classification. */
|
|
20
|
-
export const CARGO_COMMAND_ALIASES = Object.freeze({ b: "build", c: "check", d: "doc", r: "run", t: "test" });
|
|
21
|
-
export const canonicalCargoCommand = (name) => (typeof name === "string" && Object.hasOwn(CARGO_COMMAND_ALIASES, name) ? CARGO_COMMAND_ALIASES[name] : name);
|
|
22
|
-
|
|
23
|
-
const VALUE_GLOBALS = new Set(["--manifest-path", "--config", "-C", "-Z", "--color", "--target-dir"]);
|
|
24
|
-
const PLAIN_GLOBALS = new Set(["--locked", "--frozen", "--offline", "--quiet", "-q", "--verbose", "-v"]);
|
|
25
|
-
const VERSION_FLAGS = new Set(["--version", "-V", "-vV"]);
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Where the subcommand sits in `argv` (rustright command_policy.rs `command_index`): after an optional `+toolchain` and the global options (the
|
|
29
|
-
* ones that take a value are skipped with it), before any `--`. `--version`, `-V` and `-vV` are the command. null when there is none.
|
|
30
|
-
*/
|
|
31
|
-
export function cargoCommandIndex(argv) {
|
|
32
|
-
let i = 0;
|
|
33
|
-
while (i < argv.length) {
|
|
34
|
-
const v = argv[i];
|
|
35
|
-
i += 1;
|
|
36
|
-
if (v === "--") break;
|
|
37
|
-
if (v.startsWith("+") && v.length > 1) continue;
|
|
38
|
-
if (VERSION_FLAGS.has(v)) return i - 1;
|
|
39
|
-
if (VALUE_GLOBALS.has(v)) { i += 1; continue; }
|
|
40
|
-
if (PLAIN_GLOBALS.has(v)) continue;
|
|
41
|
-
if (v.startsWith("--manifest-path=") || v.startsWith("--config=") || v.startsWith("--color=") || v.startsWith("-Z")) continue;
|
|
42
|
-
if (v.startsWith("-")) continue;
|
|
43
|
-
return i - 1;
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* The cargo subcommand of an argv as sent (an alias stays an alias), read the way Cargo reads it: the broker's reading (`cargoCommandIndex`) plus
|
|
50
|
-
* Cargo's own `--explain <code>` global, whose value is skipped here (the broker reads that value as the command and refuses it, so this
|
|
51
|
-
* only ever makes the gate demand MORE evidence, never less). null when there is none.
|
|
52
|
-
*/
|
|
53
|
-
export function cargoSubcommandOf(argv) {
|
|
54
|
-
const words = [...argv];
|
|
55
|
-
const end = words.indexOf("--");
|
|
56
|
-
const own = [];
|
|
57
|
-
for (let i = 0; i < words.length; i += 1) {
|
|
58
|
-
if ((end < 0 || i < end) && words[i] === "--explain") { i += 1; continue; }
|
|
59
|
-
own.push(words[i]);
|
|
60
|
-
}
|
|
61
|
-
const i = cargoCommandIndex(own);
|
|
62
|
-
return i === null ? null : own[i];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** `argv` with the standard alias at the subcommand position replaced by its canonical command; every other word is kept as sent. */
|
|
66
|
-
export function expandCargoAliases(argv) {
|
|
67
|
-
const out = [...argv];
|
|
68
|
-
const i = cargoCommandIndex(out);
|
|
69
|
-
if (i !== null) out[i] = canonicalCargoCommand(out[i]);
|
|
70
|
-
return out;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const hasFlag = (argv, flag) => { const end = argv.indexOf("--"); return (end < 0 ? argv : argv.slice(0, end)).includes(flag); };
|
|
74
|
-
const lockPinnedOffline = (argv) => hasFlag(argv, "--frozen") || (hasFlag(argv, "--locked") && hasFlag(argv, "--offline"));
|
|
75
|
-
|
|
76
|
-
/** Whether a short-flag cluster reaches `-Z` or `-C` (`-Zx`, `-vZx`, `-qvC/dir`); `-j`, `-p`, `-F` take the rest as their value. */
|
|
77
|
-
function shortClusterCarriesZorC(arg) {
|
|
78
|
-
if (!arg.startsWith("-") || arg.startsWith("--")) return false;
|
|
79
|
-
for (const c of arg.slice(1)) {
|
|
80
|
-
if (c === "Z" || c === "C") return true;
|
|
81
|
-
if (c === "j" || c === "p" || c === "F") return false;
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
function hasConfigOrUnstable(argv) {
|
|
86
|
-
const end = argv.indexOf("--");
|
|
87
|
-
return (end < 0 ? argv : argv.slice(0, end)).some((v) => v === "--config" || v.startsWith("--config=") || shortClusterCarriesZorC(v));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// ---- external subcommands the gate sends (only when the host registers them) ----
|
|
91
|
-
|
|
92
|
-
const DENY_FLAGS = new Set(["--metadata-path", "--config"]);
|
|
93
|
-
/** `deny [--frozen] [--metadata-path <file>] [--config <file>] check`: each option once, spaced, nothing after `check`. Returns the file options or null. */
|
|
94
|
-
function denyCheckFiles(argv) {
|
|
95
|
-
const index = cargoCommandIndex(argv);
|
|
96
|
-
if (index === null || argv[index] !== "deny") return null;
|
|
97
|
-
const files = []; let frozen = false;
|
|
98
|
-
const rest = argv.slice(index + 1);
|
|
99
|
-
for (let i = 0; i < rest.length; i += 1) {
|
|
100
|
-
const arg = rest[i];
|
|
101
|
-
if (arg === "check") return i === rest.length - 1 ? files : null;
|
|
102
|
-
if (arg === "--frozen" && !frozen) { frozen = true; continue; }
|
|
103
|
-
if (DENY_FLAGS.has(arg)) {
|
|
104
|
-
if (files.some(([seen]) => seen === arg)) return null;
|
|
105
|
-
const value = rest[i + 1];
|
|
106
|
-
if (typeof value !== "string" || value === "" || value.startsWith("-")) return null;
|
|
107
|
-
i += 1; files.push([arg, value]); continue;
|
|
108
|
-
}
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
/** `audit --db <dir> --no-fetch`, either order, nothing else. Returns the database directory or null. */
|
|
114
|
-
function auditOfflineDb(argv) {
|
|
115
|
-
const index = cargoCommandIndex(argv);
|
|
116
|
-
if (index === null || argv[index] !== "audit") return null;
|
|
117
|
-
let db = null; let noFetch = false;
|
|
118
|
-
const rest = argv.slice(index + 1);
|
|
119
|
-
for (let i = 0; i < rest.length; i += 1) {
|
|
120
|
-
const arg = rest[i];
|
|
121
|
-
if (arg === "--no-fetch" && !noFetch) { noFetch = true; continue; }
|
|
122
|
-
if (arg === "--db" && db === null) {
|
|
123
|
-
const value = rest[i + 1];
|
|
124
|
-
if (typeof value !== "string" || value === "" || value.startsWith("-")) return null;
|
|
125
|
-
i += 1; db = value; continue;
|
|
126
|
-
}
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
return db !== null && noFetch ? db : null;
|
|
130
|
-
}
|
|
131
|
-
/** `about generate --frozen --fail [--config f] [--manifest-path f] [--all-features | --features l] <template>` exactly as the licence notices send it. */
|
|
132
|
-
function aboutNoticesShape(argv) {
|
|
133
|
-
const index = cargoCommandIndex(argv);
|
|
134
|
-
if (index === null) return false;
|
|
135
|
-
const tail = argv.slice(index + 1);
|
|
136
|
-
if (argv[index] !== "about" || tail.length < 4 || tail[0] !== "generate" || tail[1] !== "--frozen" || tail[2] !== "--fail") return false;
|
|
137
|
-
const seen = []; let template = false; let features = false;
|
|
138
|
-
const rest = tail.slice(3);
|
|
139
|
-
for (let i = 0; i < rest.length; i += 1) {
|
|
140
|
-
const arg = rest[i];
|
|
141
|
-
if (arg === "--config" || arg === "--manifest-path" || arg === "--features") {
|
|
142
|
-
const isFeature = arg === "--features";
|
|
143
|
-
const value = rest[i + 1];
|
|
144
|
-
if (seen.includes(arg) || (isFeature && features) || typeof value !== "string" || value === "" || value.startsWith("-")) return false;
|
|
145
|
-
i += 1; features ||= isFeature; seen.push(arg); continue;
|
|
146
|
-
}
|
|
147
|
-
if (arg === "--all-features" && !features) { features = true; continue; }
|
|
148
|
-
if (!arg.startsWith("-") && !template) { template = true; continue; }
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
return template;
|
|
152
|
-
}
|
|
153
|
-
/** The part of `argv` cargo itself parses: before the subcommand for the deny and about shapes (the rest is the tool's own), all of it otherwise. */
|
|
154
|
-
function cargoOwnArgs(argv) {
|
|
155
|
-
const index = cargoCommandIndex(argv);
|
|
156
|
-
return index !== null && (denyCheckFiles(argv) !== null || aboutNoticesShape(argv)) ? argv.slice(0, index) : argv;
|
|
157
|
-
}
|
|
158
|
-
function fmtCheckShape(tail) {
|
|
159
|
-
if (tail.length === 3 && tail[0] === "-p" && tail[1] !== "" && !tail[1].startsWith("-") && tail[2] === "--check") return true;
|
|
160
|
-
return tail.length === 2 && tail[0] === "--all" && tail[1] === "--check";
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// ---- the package observation (rustright build_rules.rs observation_only_cargo, package arm) ----
|
|
164
|
-
|
|
165
|
-
const PACKAGE_PLAIN_FLAGS = new Set(["--list", "--locked", "--allow-dirty"]);
|
|
166
|
-
/**
|
|
167
|
-
* Whether `argv` is the one package form the broker admits as an observation that compiles nothing: no `--`, no `+toolchain`, the subcommand as
|
|
168
|
-
* the one positional, `-p`/`--package` once with a value that is not a flag (`--package=x` is read, `-p=x` is not), and only `--list`,
|
|
169
|
-
* `--locked` and `--allow-dirty` besides; it must carry `--list`, `--locked` and one package. Anything else is a compiling package.
|
|
170
|
-
*/
|
|
171
|
-
export function isPackageObservation(argv) {
|
|
172
|
-
const words = [...argv];
|
|
173
|
-
if (words.includes("--") || words.some((w) => w.startsWith("+"))) return false;
|
|
174
|
-
const first = words.find((w) => !w.startsWith("-"));
|
|
175
|
-
if (first !== "package") return false;
|
|
176
|
-
let seen = false; let list = false; let locked = false; let packages = 0;
|
|
177
|
-
for (let i = 0; i < words.length; i += 1) {
|
|
178
|
-
const w = words[i];
|
|
179
|
-
if (!w.startsWith("-")) { if (seen || w !== "package") return false; seen = true; continue; }
|
|
180
|
-
const eq = w.startsWith("--") ? w.indexOf("=") : -1;
|
|
181
|
-
const name = eq >= 0 ? w.slice(0, eq) : w; const inline = eq >= 0 ? w.slice(eq + 1) : null;
|
|
182
|
-
if (name === "-p" || name === "--package") {
|
|
183
|
-
const value = inline ?? words[++i];
|
|
184
|
-
if (typeof value !== "string" || value === "" || value.startsWith("-")) return false;
|
|
185
|
-
packages += 1; if (packages > 1) return false;
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
if (!PACKAGE_PLAIN_FLAGS.has(name) || inline !== null) return false;
|
|
189
|
-
if (name === "--list") list = true; else if (name === "--locked") locked = true;
|
|
190
|
-
}
|
|
191
|
-
return seen && list && locked && packages === 1;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// ---- classification (command_policy.rs cargo_capability) ----
|
|
195
|
-
|
|
196
|
-
const CONTROL_COMMANDS = new Set(["--version", "-V", "-vV", "version", "help", "locate-project", "read-manifest", "logout", "owner", "yank", "login"]);
|
|
197
|
-
const ANALYSIS_COMMANDS = new Set(["search", "info", "pkgid", "verify-project", "report", "config"]);
|
|
198
|
-
const WORKSPACE_WRITE_COMMANDS = new Set(["new", "init", "update", "vendor", "generate-lockfile", "add", "remove"]);
|
|
199
|
-
/** The built-in commands the broker classifies as compiling (a Capability with `compile: true`): `package` only when it is not the observation. */
|
|
200
|
-
export const BROKER_COMPILE_COMMANDS = Object.freeze(["fix", "run", "package", "publish", "build", "check", "test", "bench", "clippy", "doc", "rustc", "rustdoc"]);
|
|
201
|
-
const CARGO_BUILTINS = new Set(["build", "check", "test", "bench", "clippy", "doc", "run", "install", "rustc", "rustdoc", "clean", "update", "vendor", "generate-lockfile", "add", "remove", "metadata", "tree", "fetch", "fix", "publish", "package", "login", "logout", "owner", "yank", "uninstall", "init", "new", "info", "config", "report", "pkgid", "verify-project", "locate-project", "read-manifest", "search", "help", "version", "fmt", "--version", "-V"]);
|
|
202
|
-
/** External subcommands and their classification once the host registers them (command_policy.rs external_policy). */
|
|
203
|
-
const EXTERNAL = Object.freeze({ about: { compile: false }, outdated: { compile: false }, audit: { compile: false }, deny: { compile: false }, machete: { compile: false }, upgrade: { compile: false }, "set-version": { compile: false }, nextest: { compile: true }, ndk: { compile: true } });
|
|
204
|
-
/** The external subcommands the gate itself sends through the broker: the host registers each (rustright adapter/external registrations). */
|
|
205
|
-
export const GATE_EXTERNAL_COMMANDS = Object.freeze(["deny", "audit", "about", "ndk", "nextest"]);
|
|
206
|
-
|
|
207
|
-
const MANAGED_TOOL_NAMES = new Set(["cargo", "rustup", "rustc", "rustdoc", "swift", "cmake", "make", "cc", "clang", "gcc", "node", "node-gyp", "pnpm", "npm"]);
|
|
208
|
-
const REDIRECT_LONG = ["--target-dir", "--config", "--cache-dir", "--build-dir", "--toolchain", "--temp-dir", "-Zbuild-std", "-Zconfig"];
|
|
209
|
-
const isRedirectArgument = (a) => REDIRECT_LONG.some((flag) => a === flag || a.startsWith(`${flag}=`));
|
|
210
|
-
const isUnmanagedToolPath = (a) => {
|
|
211
|
-
const abs = a.startsWith("/") || /^[A-Za-z]:[\\/]/.test(a) || a.startsWith("\\\\");
|
|
212
|
-
const name = a.split(/[\\/]/).at(-1).toLowerCase().replace(/\.exe$/, "");
|
|
213
|
-
return abs && MANAGED_TOOL_NAMES.has(name);
|
|
214
|
-
};
|
|
215
|
-
const OWN_FLAG_SUBCOMMANDS = new Set(["about", "outdated", "audit", "deny", "machete"]);
|
|
216
|
-
|
|
217
|
-
/** rustright request.rs `reject_managed_agent_redirects` for an argv: a redirecting option, a `+toolchain` or an unmanaged tool path before any `--`. */
|
|
218
|
-
function redirectRefused(argv) {
|
|
219
|
-
const at = argv.findIndex((a) => !a.startsWith("-"));
|
|
220
|
-
const ownFrom = at >= 0 && OWN_FLAG_SUBCOMMANDS.has(argv[at]) ? at : null;
|
|
221
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
222
|
-
if (argv[i] === "--") break;
|
|
223
|
-
const cargoFlag = ownFrom === null || i < ownFrom;
|
|
224
|
-
if ((cargoFlag && isRedirectArgument(argv[i])) || argv[i].startsWith("+") || isUnmanagedToolPath(argv[i])) return true;
|
|
225
|
-
}
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/** The refusal rows: code is the broker's own typed code. */
|
|
230
|
-
const refused = (code, message) => ({ refused: { code, message } });
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* What the broker's production parser decides for `argv` (cargo's arguments without `cargo`), in rustright's order: normalisation (the standard
|
|
234
|
-
* aliases, redirect refusals), classification (command, compile) and the carried, grant and carried-refusal predicates.
|
|
235
|
-
* - `{ refused: { code, message } }`: the broker answers the typed code and runs zero processes;
|
|
236
|
-
* - `{ normalizedArgv, command, compile, carriedReadOnly, grant, carriedRefusal }` (the vector's columns).
|
|
237
|
-
* `registered` lists the external subcommands the host registers (default none, as in the vector); `deny`, `audit`, `about`, `ndk` and
|
|
238
|
-
* `nextest` are classified only when registered, as on the broker.
|
|
239
|
-
*/
|
|
240
|
-
export function classifyCargoArgv(argv, { registered = [] } = {}) {
|
|
241
|
-
const words = [...argv];
|
|
242
|
-
if (!words.every((w) => typeof w === "string" && w !== "")) return refused("RK_ARGV_INVALID", "Cargo argv must contain non-empty strings");
|
|
243
|
-
if (redirectRefused(words)) return refused("RK_REDIRECT_REFUSED", "managed agent request cannot redirect cache, build, toolchain, temp, or tool path");
|
|
244
|
-
const normalizedArgv = expandCargoAliases(words);
|
|
245
|
-
const index = cargoCommandIndex(normalizedArgv);
|
|
246
|
-
const command = index === null ? null : normalizedArgv[index];
|
|
247
|
-
if (command === null) return refused("RK_UNKNOWN_COMMAND", `unregistered managed command: cargo ${normalizedArgv.join(" ")}`.trim());
|
|
248
|
-
if (command === "install" || command === "uninstall") return refused("RK_COMMAND_DENIED", `agent tool ${command === "install" ? "installation" : "removal"} is denied; managed tools are digest-registered by the operator`);
|
|
249
|
-
if (command === "clean") return refused("RR_CLEAN_REFUSED", "denied managed command: cargo clean");
|
|
250
|
-
let compile;
|
|
251
|
-
if (CONTROL_COMMANDS.has(command) || ANALYSIS_COMMANDS.has(command) || WORKSPACE_WRITE_COMMANDS.has(command) || command === "metadata" || command === "tree" || command === "fetch" || command === "fmt") compile = false;
|
|
252
|
-
else if (command === "package") compile = !isPackageObservation(normalizedArgv);
|
|
253
|
-
else if (BROKER_COMPILE_COMMANDS.includes(command)) compile = true;
|
|
254
|
-
else if (registered.includes(command) && Object.hasOwn(EXTERNAL, command)) compile = EXTERNAL[command].compile;
|
|
255
|
-
else return refused("RK_UNKNOWN_COMMAND", `unregistered managed command: cargo ${normalizedArgv.join(" ")}`.trim());
|
|
256
|
-
const carriedRefusalText = hasConfigOrUnstable(cargoOwnArgs(normalizedArgv)) ? "a snapshot-bound request does not carry cargo --config or -Z" : null;
|
|
257
|
-
return { normalizedArgv, command, compile, carriedReadOnly: snapshotReadOnly(normalizedArgv), grant: grantCommand(normalizedArgv).ok, carriedRefusal: carriedRefusalText !== null, carriedRefusalText };
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function offlineReadOnly(argv) {
|
|
261
|
-
if (hasConfigOrUnstable(cargoOwnArgs(argv))) return false;
|
|
262
|
-
const index = cargoCommandIndex(argv);
|
|
263
|
-
if (index === null) return false;
|
|
264
|
-
switch (canonicalCargoCommand(argv[index])) {
|
|
265
|
-
case "--version": case "-V": case "version": case "locate-project": case "read-manifest": return true;
|
|
266
|
-
case "metadata": return hasFlag(argv, "--no-deps") || lockPinnedOffline(argv);
|
|
267
|
-
case "about": {
|
|
268
|
-
const end = argv.indexOf("--");
|
|
269
|
-
const after = argv.slice(index + 1, end < 0 ? undefined : end);
|
|
270
|
-
const at = after.findIndex((v) => !v.startsWith("-"));
|
|
271
|
-
return at >= 0 && after[at] === "generate" && lockPinnedOffline(after.slice(at + 1));
|
|
272
|
-
}
|
|
273
|
-
default: return false;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
function classAScan(argv) {
|
|
277
|
-
if (hasConfigOrUnstable(cargoOwnArgs(argv))) return null;
|
|
278
|
-
const index = cargoCommandIndex(argv);
|
|
279
|
-
if (index === null) return null;
|
|
280
|
-
switch (canonicalCargoCommand(argv[index])) {
|
|
281
|
-
case "deny": return denyCheckFiles(argv);
|
|
282
|
-
case "audit": { const db = auditOfflineDb(argv); return db === null ? null : [["--db", db]]; }
|
|
283
|
-
case "fetch": case "metadata": return hasFlag(argv, "--locked") || hasFlag(argv, "--frozen") ? [] : null;
|
|
284
|
-
case "fmt": return fmtCheckShape(argv.slice(index + 1)) ? [] : null;
|
|
285
|
-
case "package": return isPackageObservation(argv) ? [] : null;
|
|
286
|
-
default: return null;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
/** What a snapshot-bound (carried) cargo request that compiles nothing may be (command_policy.rs `snapshot_read_only`). */
|
|
290
|
-
export const snapshotReadOnly = (argv) => offlineReadOnly(argv) || classAScan(argv) !== null;
|
|
291
|
-
|
|
292
|
-
/** What a stage grant's allowlist accepts (command_policy.rs `grant_command`): `{ ok: true }` or `{ ok: false, reason }`. */
|
|
293
|
-
export function grantCommand(argv) {
|
|
294
|
-
if (hasConfigOrUnstable(argv)) return { ok: false, reason: "a stage grant does not carry cargo --config or -Z" };
|
|
295
|
-
const index = cargoCommandIndex(argv);
|
|
296
|
-
if (index === null) return { ok: false, reason: "a stage grant needs a cargo subcommand" };
|
|
297
|
-
const command = canonicalCargoCommand(argv[index]);
|
|
298
|
-
if (command === "build" || command === "run") return hasFlag(argv, "--locked") || hasFlag(argv, "--frozen") ? { ok: true } : { ok: false, reason: `a stage grant carries cargo ${argv[index]} only with --locked or --frozen` };
|
|
299
|
-
if (command === "about") return { ok: false, reason: "a stage grant does not carry cargo about" };
|
|
300
|
-
if (offlineReadOnly(argv)) return { ok: true };
|
|
301
|
-
return { ok: false, reason: `a stage grant does not carry cargo ${command} with these arguments` };
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/** The version spellings the broker answers uncarried inside a snapshot (command_policy.rs VERSION_ARGUMENTS and `version`), matched as the WHOLE argv. */
|
|
305
|
-
export const VERSION_PROBES = Object.freeze([["-V"], ["--version"], ["-vV"], ["-Vv"], ["--version", "--verbose"], ["-V", "--verbose"], ["-v", "-V"], ["version"]]);
|
|
306
|
-
export const isVersionProbe = (argv) => VERSION_PROBES.some((probe) => probe.length === argv.length && probe.every((w, i) => w === argv[i]));
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* The decision for a CARRIED call (a snapshot-bound request through the broker): the shape the wrapper, the carried seam and the planners
|
|
310
|
-
* share. `{ ok: true, argv, compile }` (`argv` with the aliases expanded, the one rewrite) or `{ ok: false, code, message }`, decided
|
|
311
|
-
* before anything is submitted, so a refused shape launches no process. A carried call must compile or be a carried read-only shape; the
|
|
312
|
-
* broker refuses everything else (`tree`, `pkgid`, `verify-project`, a bare `metadata`, a `fmt` write form, `help`), so it is never sent.
|
|
313
|
-
*/
|
|
314
|
-
export function carriedShapeDecision(argv, options = {}) {
|
|
315
|
-
const row = classifyCargoArgv(argv, { registered: GATE_EXTERNAL_COMMANDS, ...options });
|
|
316
|
-
if (row.refused) return { ok: false, code: row.refused.code, message: `the broker refuses \`cargo ${[...argv].join(" ")}\` (${row.refused.code}: ${row.refused.message}); it is not sent` };
|
|
317
|
-
if (row.carriedRefusal) return { ok: false, code: "RK_CARGO_BROKER_CARRIED_REFUSED", message: `\`cargo ${[...argv].join(" ")}\`: ${row.carriedRefusalText}; it is not sent` };
|
|
318
|
-
if (!row.compile && !row.carriedReadOnly) return { ok: false, code: "RK_CARGO_BROKER_READ_ONLY_SHAPE", message: `\`cargo ${[...argv].join(" ")}\` is neither a compile nor a carried read-only shape (metadata --no-deps or --locked/--frozen, fetch --locked, fmt --check, locate-project, read-manifest, deny, audit, package --list); the broker refuses it inside a snapshot, so it is not sent` };
|
|
319
|
-
return { ok: true, argv: row.normalizedArgv, compile: row.compile };
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Whether the broker classifies this argv (cargo's arguments) as a compile: the receipt then carries freshness, attribution and toolchain
|
|
324
|
-
* evidence (or typed unavailable evidence), and absence is never a success. An argv the broker refuses outright never produces a receipt; if one
|
|
325
|
-
* is presented anyway it still owes the evidence its compile command names (more evidence is demanded, never less).
|
|
326
|
-
*/
|
|
327
|
-
export function isCompileCommand(argv) {
|
|
328
|
-
const row = classifyCargoArgv(argv, { registered: GATE_EXTERNAL_COMMANDS });
|
|
329
|
-
if (!row.refused) return row.compile === true;
|
|
330
|
-
const sub = canonicalCargoCommand(cargoSubcommandOf(argv));
|
|
331
|
-
return BROKER_COMPILE_COMMANDS.includes(sub) && !(sub === "package" && isPackageObservation(argv));
|
|
332
|
-
}
|
package/cargo-width.mjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// Cargo argv width is explicit so broker admission, cache keys and signed receipts see the same request.
|
|
2
|
-
const COMPILE = new Set(["build", "check", "clippy", "doc", "rustdoc", "test", "bench"]);
|
|
3
|
-
|
|
4
|
-
export function parseCargoWidth(value) {
|
|
5
|
-
if (typeof value !== "string" || !/^[1-9][0-9]*$/.test(value)) throw new Error("--cargo-jobs needs a positive decimal integer");
|
|
6
|
-
const width = Number(value);
|
|
7
|
-
if (!Number.isSafeInteger(width) || width > 0xffffffff) throw new Error("--cargo-jobs is out of range");
|
|
8
|
-
return width;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function cargoWidthArgs(argv, width) {
|
|
12
|
-
if (!Array.isArray(argv) || !argv.every((x) => typeof x === "string") || !COMPILE.has(argv[0])) throw new Error("--cargo-jobs cannot control this Cargo command");
|
|
13
|
-
if (!Number.isSafeInteger(width) || width < 1 || width > 0xffffffff) throw new Error("invalid Cargo width");
|
|
14
|
-
const end = argv.indexOf("--");
|
|
15
|
-
if (argv.slice(1, end < 0 ? undefined : end).some((arg) => arg === "--jobs" || arg.startsWith("--jobs=") || arg === "-j" || arg.startsWith("-j"))) throw new Error("--cargo-jobs conflicts with an existing Cargo jobs flag");
|
|
16
|
-
return [argv[0], "--jobs", String(width), ...argv.slice(1)];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function validateCargoWidthPool(width, status) {
|
|
20
|
-
const size = status?.type === "LIST" && status?.broker?.phase === "READY" ? status.broker.tokens?.size : null;
|
|
21
|
-
if (!Number.isSafeInteger(size) || size < 1) throw new Error("broker does not report a ready compile-token pool");
|
|
22
|
-
if (width > size) throw new Error(`--cargo-jobs ${width} exceeds broker token pool ${size}`);
|
|
23
|
-
return size;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Width is supported only on the shared Cargo unit-list door, never on command or app routes. */
|
|
27
|
-
export function cargoWidthRouteProblem(args) {
|
|
28
|
-
if (!Array.isArray(args) || !args[0]?.startsWith("--") || args.includes("--")) return "--cargo-jobs needs a controlled unit-list compile";
|
|
29
|
-
const at = args.indexOf("--to");
|
|
30
|
-
if (at < 0 || args[at + 1] !== "compile" || !(args.includes("--units-file") || args.includes("--changed")) || ["--route", "--unit", "--all", "--all-units-exception", "--no-broker"].some((flag) => args.includes(flag))) return "--cargo-jobs needs a controlled unit-list compile";
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function cargoWidthUnitsProblem(selected) {
|
|
35
|
-
if (!Array.isArray(selected) || selected.some((unit) => typeof unit?.selector !== "string" || !/^cargo:rightkit-[a-z0-9-]+$/.test(unit.selector))) return "--cargo-jobs supports Cargo-only unit lists; nested npm, native and custom adapters are uncontrolled";
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function cargoWidthScanProblem(scan, cargoCommand, width) {
|
|
40
|
-
const prefix = cargoCommand.slice(1);
|
|
41
|
-
if (scan?.tool !== cargoCommand[0] || !Array.isArray(scan.args) || prefix.some((word, i) => scan.args[i] !== word)) return 'uncontrolled Class B command';
|
|
42
|
-
const args = scan.args.slice(prefix.length);
|
|
43
|
-
if (!COMPILE.has(args[0])) return 'uncontrolled Cargo subcommand';
|
|
44
|
-
const end = args.indexOf('--');
|
|
45
|
-
const own = args.slice(1, end < 0 ? undefined : end);
|
|
46
|
-
const flags = own.flatMap((word, i) => word === '--jobs' || word.startsWith('--jobs=') || word === '-j' || word.startsWith('-j') ? [i] : []);
|
|
47
|
-
if (flags.length !== 1 || own[flags[0]] !== '--jobs' || own[flags[0] + 1] !== String(width)) return 'uncontrolled Cargo width';
|
|
48
|
-
return null;
|
|
49
|
-
}
|
package/carrier-census.mjs
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
// GB-76: owner-aware retirement of the snapshot-request carriers a crashed gate left behind (BR16, B34; BROKER-CONTRACT section 16).
|
|
2
|
-
//
|
|
3
|
-
// A carrier is written under `<control root>/snapshot-requests/<name>.json` and removed by its caller's `finally`; a gate that crashed between the write, the send and the cleanup left the file.
|
|
4
|
-
// RustRight's wire for the creator record: BEFORE the carrier the gate writes `<name>.json.owner.json`
|
|
5
|
-
// { "schema": "rustright.carrier-owner/1", "gate": { "pid", "startTimeMs" }, "nonce", "handle", "createdAtMs" }
|
|
6
|
-
// (its own process identity as RustRight reads it, the call's attestation nonce and ownership handle, the creation time in UNIX epoch milliseconds), then the carrier, and removes both in its `finally`.
|
|
7
|
-
// The broker's maintenance pass (`carrier_sweep::sweep_carriers`) retires a carrier only when its owner record parses and names this schema, its gate identity is read as gone or reused (a live gate
|
|
8
|
-
// keeps its carrier until the call has been finished for an hour, an unreadable identity keeps it for ever) and the broker holds no active or unknown submission under its handle. Age alone never
|
|
9
|
-
// retires anything. `sweepSnapshotRequests` is the gate's own sweep over the same wire and the same rules: nothing is deleted without proof, every entry is accounted for, `grant-*.json` and the
|
|
10
|
-
// owner records themselves are never carriers, links are never followed, and removal is compare-token (the owner record and the carrier must still be byte-identical to what was judged).
|
|
11
|
-
import crypto from "node:crypto";
|
|
12
|
-
import fs from "node:fs";
|
|
13
|
-
import path from "node:path";
|
|
14
|
-
import { processStartTimeMs, selfStartTimeMs } from "./lock-identity.mjs";
|
|
15
|
-
|
|
16
|
-
export const CARRIER_OWNER_SCHEMA = "rustright.carrier-owner/1";
|
|
17
|
-
export const CARRIER_DIR = "snapshot-requests";
|
|
18
|
-
/** A carrier whose call has been finished this long is retired even when its gate lives, when the broker holds nothing under it (RustRight FINISHED_CARRIER_RETENTION_MS). */
|
|
19
|
-
export const FINISHED_CARRIER_RETENTION_MS = 60 * 60 * 1000;
|
|
20
|
-
/** A carrier of a dead gate that the broker never saw stays this long before the gate retires it (the client the gate started may still be finishing). */
|
|
21
|
-
export const CARRIER_RETENTION_MS = 15 * 60 * 1000;
|
|
22
|
-
const MAX_CARRIER_BYTES = 4 * 1024 * 1024;
|
|
23
|
-
const MAX_OWNER_BYTES = 64 * 1024;
|
|
24
|
-
const OWNER_SUFFIX = ".owner.json";
|
|
25
|
-
const OWNER_KEYS = ["createdAtMs", "gate", "handle", "nonce", "schema"];
|
|
26
|
-
const digest = (data) => crypto.createHash("sha256").update(data).digest("hex");
|
|
27
|
-
/** The owner record's file: the carrier's own name, extension included, then `.owner.json`. */
|
|
28
|
-
export const ownerFileOf = (carrierFile) => `${carrierFile}${OWNER_SUFFIX}`;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Writes the creator record for the carrier at `file` (owner-only, exclusive, BEFORE the carrier itself) and returns it. `identity()` is `{ pid, startTimeMs }` (startTimeMs null when this host cannot
|
|
32
|
-
* read it: the broker then keeps the carrier for ever, which is safe).
|
|
33
|
-
*/
|
|
34
|
-
export function writeCarrierOwner({ file, handle, nonce, identity = () => ({ pid: process.pid, startTimeMs: selfStartTimeMs() }), now = Date.now() }) {
|
|
35
|
-
const me = identity();
|
|
36
|
-
const record = { schema: CARRIER_OWNER_SCHEMA, gate: { pid: me.pid, startTimeMs: me.startTimeMs ?? null }, nonce, handle, createdAtMs: now };
|
|
37
|
-
fs.writeFileSync(ownerFileOf(file), JSON.stringify(record), { flag: "wx", mode: 0o600 });
|
|
38
|
-
return record;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Removes a carrier and its owner record after its call (the normal path: nothing is left for a sweep). */
|
|
42
|
-
export function removeCarrier(file) {
|
|
43
|
-
fs.rmSync(file, { force: true });
|
|
44
|
-
fs.rmSync(ownerFileOf(file), { force: true });
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const readBounded = (file, max) => {
|
|
48
|
-
const meta = fs.lstatSync(file);
|
|
49
|
-
if (meta.isSymbolicLink() || !meta.isFile()) return { problem: "not a regular file" };
|
|
50
|
-
if (meta.size > max) return { problem: `larger than ${max} bytes` };
|
|
51
|
-
return { bytes: fs.readFileSync(file) };
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/** The owner record `bytes` hold, exactly RustRight's shape (it denies unknown fields), or `{ problem }`. */
|
|
55
|
-
function parseOwner(bytes) {
|
|
56
|
-
let value; try { value = JSON.parse(bytes.toString("utf8")); } catch { return { problem: "not JSON" }; }
|
|
57
|
-
const object = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
58
|
-
if (!object(value) || Object.keys(value).sort().join() !== OWNER_KEYS.join()) return { problem: "not the fields of rustright.carrier-owner/1" };
|
|
59
|
-
if (value.schema !== CARRIER_OWNER_SCHEMA) return { problem: "not a rustright.carrier-owner/1 record" };
|
|
60
|
-
if (!object(value.gate) || Object.keys(value.gate).sort().join() !== "pid,startTimeMs" || !Number.isInteger(value.gate.pid) || value.gate.pid < 1 || value.gate.pid > 0xffffffff || !(value.gate.startTimeMs === null || (Number.isSafeInteger(value.gate.startTimeMs) && value.gate.startTimeMs >= 0))) return { problem: "the gate identity is not {pid, startTimeMs}" };
|
|
61
|
-
if (typeof value.nonce !== "string" || value.nonce === "" || typeof value.handle !== "string" || value.handle === "" || !Number.isSafeInteger(value.createdAtMs) || value.createdAtMs < 0) return { problem: "nonce, handle or createdAtMs is not valid" };
|
|
62
|
-
return { owner: value };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Whether the gate a record names is the same process, gone, reused (the pid runs a process that started at another time) or unreadable, as RustRight's `identity_state` judges it. */
|
|
66
|
-
export function gateState(gate, probe) {
|
|
67
|
-
let seen; try { seen = probe(gate.pid); } catch { return "unverifiable"; }
|
|
68
|
-
if (!seen?.alive) return "gone";
|
|
69
|
-
if (gate.startTimeMs === null) return "unverifiable";
|
|
70
|
-
if (!Number.isFinite(seen.startTimeMs)) return "unverifiable";
|
|
71
|
-
return seen.startTimeMs === gate.startTimeMs ? "same" : "reused";
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const livePid = (pid) => { try { process.kill(pid, 0); return true; } catch (e) { return e.code === "EPERM"; } };
|
|
75
|
-
const hostProbe = (pid) => (livePid(pid) ? { alive: true, startTimeMs: pid === process.pid ? selfStartTimeMs() : processStartTimeMs(pid) } : { alive: false, startTimeMs: null });
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Sweeps one carrier directory. `lease({ snapshot, handle })` is the broker's lease status (build-ownership.mjs brokerLeaseState) and must answer for the exact sub-handle; `identity.probe(pid)`
|
|
79
|
-
* is `{ alive, startTimeMs }`. Returns `{ retired: [file], retained: [{ file, why }], corrupt: [{ file, why }], examined }`: every entry is accounted for; nothing is deleted without proof.
|
|
80
|
-
*/
|
|
81
|
-
export function sweepSnapshotRequests({ controlRoot, lease, snapshot = null, now = Date.now(), retentionMs = CARRIER_RETENTION_MS, limit = 256, identity = { probe: hostProbe } }) {
|
|
82
|
-
const dir = path.join(controlRoot, CARRIER_DIR);
|
|
83
|
-
const out = { retired: [], retained: [], corrupt: [], examined: 0 };
|
|
84
|
-
let dirMeta; try { dirMeta = fs.lstatSync(dir); } catch (e) { if (e.code === "ENOENT") return out; throw e; }
|
|
85
|
-
if (dirMeta.isSymbolicLink() || !dirMeta.isDirectory()) { out.corrupt.push({ file: dir, why: "the carrier directory is not a real directory" }); return out; }
|
|
86
|
-
const names = fs.readdirSync(dir).filter((n) => n.endsWith(".json") && !n.endsWith(OWNER_SUFFIX) && !n.startsWith(".") && !n.startsWith("grant-")).sort().slice(0, limit);
|
|
87
|
-
for (const name of names) {
|
|
88
|
-
const file = path.join(dir, name);
|
|
89
|
-
out.examined += 1;
|
|
90
|
-
const keep = (why) => out.retained.push({ file, why });
|
|
91
|
-
const corrupt = (why) => out.corrupt.push({ file, why });
|
|
92
|
-
let carrier; let ownerBytes;
|
|
93
|
-
try {
|
|
94
|
-
carrier = readBounded(file, MAX_CARRIER_BYTES);
|
|
95
|
-
if (carrier.problem) { corrupt(`carrier ${carrier.problem}`); continue; }
|
|
96
|
-
if (!fs.lstatSync(ownerFileOf(file), { throwIfNoEntry: false })) { keep("no owner record: its creator cannot be known"); continue; }
|
|
97
|
-
const o = readBounded(ownerFileOf(file), MAX_OWNER_BYTES);
|
|
98
|
-
if (o.problem) { corrupt(`owner record ${o.problem}`); continue; }
|
|
99
|
-
ownerBytes = o.bytes;
|
|
100
|
-
} catch (e) { corrupt(`unreadable (${e.code ?? e.message})`); continue; }
|
|
101
|
-
const parsed = parseOwner(ownerBytes);
|
|
102
|
-
if (parsed.problem) { corrupt(`the owner record is not one this gate wrote (${parsed.problem})`); continue; }
|
|
103
|
-
const { owner } = parsed;
|
|
104
|
-
const gate = gateState(owner.gate, identity.probe);
|
|
105
|
-
if (gate === "unverifiable") { keep("its gate's identity cannot be read, so it cannot be proven dead"); continue; }
|
|
106
|
-
const finished = now - owner.createdAtMs >= FINISHED_CARRIER_RETENTION_MS;
|
|
107
|
-
if (gate === "same" && !finished) { keep("its gate is alive"); continue; }
|
|
108
|
-
let doc = null; try { doc = JSON.parse(carrier.bytes.toString("utf8")); } catch { /* the snapshot comes from the broker's view below */ }
|
|
109
|
-
const answer = lease({ snapshot: doc?.snapshot?.path ?? snapshot, handle: owner.handle });
|
|
110
|
-
const members = Array.isArray(answer.members) ? answer.members : null;
|
|
111
|
-
const old = now - owner.createdAtMs >= retentionMs;
|
|
112
|
-
const settled = answer.state === "REAPED" || (answer.state === "UNKNOWN" && members !== null && members.length === 0 && old);
|
|
113
|
-
if (!settled) { keep(answer.state === "ACTIVE" ? "the broker holds it ACTIVE" : answer.state === "UNKNOWN" && members?.length ? "the broker knows it UNKNOWN" : `the broker's answer (${answer.state}) does not settle it${old ? "" : " and it is younger than the retention"}`); continue; }
|
|
114
|
-
// Compare-token removal: the carrier and the owner record are exactly what was judged, and still not links.
|
|
115
|
-
try {
|
|
116
|
-
const again = readBounded(file, MAX_CARRIER_BYTES); const ownerAgain = readBounded(ownerFileOf(file), MAX_OWNER_BYTES);
|
|
117
|
-
if (again.problem || ownerAgain.problem || digest(again.bytes) !== digest(carrier.bytes) || digest(ownerAgain.bytes) !== digest(ownerBytes)) { keep("changed while it was judged"); continue; }
|
|
118
|
-
fs.rmSync(file, { force: true });
|
|
119
|
-
fs.rmSync(ownerFileOf(file), { force: true });
|
|
120
|
-
out.retired.push(file);
|
|
121
|
-
} catch (e) { keep(`not removed (${e.code ?? e.message})`); }
|
|
122
|
-
}
|
|
123
|
-
return out;
|
|
124
|
-
}
|