@rightkit/release 0.6.85 → 0.6.87

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 CHANGED
@@ -61,9 +61,10 @@ The module imports node builtins only (preflight runs with no `node_modules`), r
61
61
  ```
62
62
 
63
63
  - `name` (required, unique): environment variable, argument flag, settings key or `VITE_*` name.
64
- - `class` (required): `S1`..`S6`. `channel` (required): `env`, `argv`, `settings`, `preference` or `frontend`.
64
+ - `class` (required): `S1`..`S7`. `channel` (required): `env`, `argv`, `settings`, `preference` or `frontend`.
65
65
  - S1-S4 need `compiledOut`: `feature:<name>`, `cfg:test`, `cfg:debug_assertions` or, for Swift, `swift:<CONDITION>` (`swift:DEBUG`, `swift:PULSE_QA`: the read sits inside `#if <CONDITION>`; the read exists only there). The source walk skips test directories, including Swift bundles named `Tests`, `UITests`, `<App>Tests` and `<App>UITests`. S5 needs `userGesture: true`. S6 needs `valueType` of `bool`, `int` or `enum`.
66
66
  - `swift:<CONDITION>` (#1169) is any Swift compilation condition (`swift:DEBUG`, or the app's own, e.g. `swift:PULSE_QA`), and it is checked, not trusted: every read of the name must sit in a Swift file inside an `#if <CONDITION>` (or `#elseif`) branch that requires it (`A && COND` does; `#else`, `COND || A` and `!COND` do not), and the project must not define the condition for Release (`SWIFT_ACTIVE_COMPILATION_CONDITIONS` in a Release `buildSettings` block of a `project.pbxproj`, a Release or unscoped `.xcconfig` line, or a SwiftPM `.define("X")` not limited to `.when(configuration: .debug)`). A condition a separate QA build adds on the command line is in no project file and passes; the finding is `not-compiled-out`.
67
+ - **S7, a handoff.** A one-time value (a token, a nonce) the app's own code sets in the environment of a child process it starts, which the child reads and then removes. It selects no test mode, data root, executable, library or identity, so it stays in release; both ends are checked in source instead. The entry needs `channel: "env"` and `handoff: { "setBy": "<path>:<line>", "clearedAt": "<path>:<line>" }`: the first line must show the name being set on a child (`.env(`, `.envs(`, `set_var(`, an `env…insert(` into the child's environment map), the second must show it being removed (`remove_var(`, `env_remove(`, `unsetenv(`). Where the code names it through a constant, add `"nameConst": "<path>:<line>"` pointing at `const X: &str = "NAME";`; the two ends may then show `X`. An entry whose lines do not show this is `inventory-invalid`. S7 names are not on the binary deny list. Example: `{ "name": "PULSE_AGENT_RUN_TOKEN", "class": "S7", "channel": "env", "handoff": { "nameConst": "engine/src/journal/agent_act.rs:170", "setBy": "engine/src/journal/agent_act.rs:1419", "clearedAt": "engine/src/journal/agent_act.rs:2225" } }`.
67
68
  - `anchor` and `note` are informational (except a `releasePresence` anchor, below). Fixtures: `fixtures/release-switches/` (`app/` is a clean example).
68
69
  - **Minimal inventory and opt-out (#397).** Every release build reads one inventory (`switches.json`, or the file `releaseSwitches.inventory` names); a missing file fails a non-dry-run release. An app with no source switches commits the smallest valid one, and that is its explicit opt-out: `{ "schema": 1, "app": "<name>", "switches": [] }`. The walk then still refuses any environment read the app source makes, so the empty list is a claim the source proves. Names the operating system or Cargo supply are not selectors and need no entry (below).
69
70
  - **OS-provided and Cargo-provided variables (#1045).** The registry's `osProvided` list (`HOME`, `HOMEDRIVE`, `HOMEPATH`, `USERPROFILE`, `APPDATA`, `LOCALAPPDATA`, `PROGRAMDATA`, `ALLUSERSPROFILE`, `PATH`, `PATHEXT`, `SystemRoot`, `SystemDrive`, `windir`, `COMSPEC`, `ProgramFiles`, `ProgramFiles(x86)`, `ProgramW6432`, `TEMP`, `TMP`, `TMPDIR`, `USER`, `USERNAME`, `LOGNAME`, the `XDG_*` base directories) is read by the walk as not-a-switch; an app cannot add to it (that list is a registry change, so a selector cannot be declared "OS provided"), and an app that registers one of these names keeps its entry checked. In a file named `build.rs` the variables Cargo sets for a build script (`OUT_DIR`, `TARGET`, `HOST`, `PROFILE`, `DEBUG`, `OPT_LEVEL`, `NUM_JOBS`, `RUSTC*`, `CARGO_CFG_*`, `CARGO_FEATURE_*`, `DEP_*`, `CARGO_MANIFEST_DIR`, `CARGO_PKG_*`) are exempt as well; `env!`/`option_env!` keep the Cargo-set list.
@@ -0,0 +1,11 @@
1
+ {
2
+ "schema": 1,
3
+ "description": "Repositories RightKit does not bind: each may use RightKit packages but owes none, so every finding of its ownership scan is advice. An entry needs the owner's ruling, quoted, in ratifiedBy. Read by ownership.mjs (adviseOnlyFindings).",
4
+ "repositories": [
5
+ {
6
+ "repositoryIdentity": "https://github.com/orthic-labs/legion",
7
+ "issue": "bogusyogi/rightkit#1754",
8
+ "ratifiedBy": "Adrian, 2026-11-26 06:28 UTC, typed in the Legion chat (pulse chat said; Orthic-Labs/legion#149): \"Legion can use a few Rk packages and crates but no mandatory and doesn't have to.\""
9
+ }
10
+ ]
11
+ }
package/ownership.mjs CHANGED
@@ -793,6 +793,26 @@ export function exceptionMatches(entry, finding) {
793
793
  if (entry.path !== undefined && !(finding.file === entry.path || finding.file?.startsWith(`${entry.path.replace(/\/$/, "")}/`))) return false;
794
794
  return true;
795
795
  }
796
+ /**
797
+ * A repository RightKit does not bind (listed in the shipped ownership-advise-only.json with the owner's ruling in `ratifiedBy`): it
798
+ * may use RightKit packages but owes none, so every finding of its scan is advice. Violations lose their
799
+ * blocking tier and any `banned` policy; they are still reported in full. Coverage gaps and scan problems are not findings and still refuse.
800
+ */
801
+ let adviseOnlyList;
802
+ function adviseOnlyRepositories() {
803
+ if (adviseOnlyList === undefined) {
804
+ try { const data = JSON.parse(readFileSync(new URL("./ownership-advise-only.json", import.meta.url), "utf8")); adviseOnlyList = Array.isArray(data?.repositories) ? data.repositories : []; }
805
+ catch { adviseOnlyList = []; }
806
+ }
807
+ return adviseOnlyList;
808
+ }
809
+ export function adviseOnlyFindings(result, repositoryIdentity, registry = adviseOnlyRepositories()) {
810
+ const entry = repositoryIdentity ? registry.find((e) => e?.repositoryIdentity === repositoryIdentity && typeof e.ratifiedBy === "string" && e.ratifiedBy.trim()) : null;
811
+ if (!entry) return result;
812
+ const advise = ({ policy, ...finding }) => ({ ...finding, tier: "advise" });
813
+ return { ...result, violations: result.violations.map(advise), warnings: [...(result.warnings ?? []), `ownership findings are advice for ${repositoryIdentity}: ${entry.ratifiedBy}`] };
814
+ }
815
+
796
816
  export function evaluate(findings, exceptions, options = {}) {
797
817
  const problems = [], covered = [], violations = [], warnings = [];
798
818
  for (const e of exceptions) {
@@ -846,7 +866,7 @@ function checkAppInternal(appRoot, manifest, options, readAuthority) {
846
866
  const scanned = scanInternal(appRoot, manifest, { inventory: fileInventory(appRoot, trust, location.prefix, location.root), trust, repositoryIdentity, repositoryRoot: location.root, pathPrefix: location.prefix, allowlistPolicy: dependencyAllowlistPolicy(trust, repositoryIdentity, { pending: enrollmentPending(trust, enrollment), shipped: options.shippedAllowlist }) });
847
867
  const metadata = { ...scanMetadata(appRoot, manifest, scanned.coverage, scanned.contentDigests, repositoryIdentity, location.commit), pathBase: location.pathBase, pathPrefix: location.prefix, provenance: scanned.provenance, ...Object.fromEntries(Object.entries(resolved).filter(([key]) => key !== "trust")) };
848
868
  if (trust?.rootFingerprint && Array.isArray(trust.ownershipKeys) && !trust.ownershipKeys.length) throw new Error("protected ownership key log has no active approval keys");
849
- const result = evaluate(scanned.findings, loadExceptions(appRoot), { ...options, manifest, trust, trustEnrollment: enrollment, metadata });
869
+ const result = adviseOnlyFindings(evaluate(scanned.findings, loadExceptions(appRoot), { ...options, manifest, trust, trustEnrollment: enrollment, metadata }), repositoryIdentity);
850
870
  const coverage = [...new Map(metadata.coverage.map((x) => [`${x.path}\0${x.reason}`, x])).values()];
851
871
  const rows = capabilityTable(manifest, scanned.deps, { ...result, coverage });
852
872
  return { ok: !result.violations.some(isBlockingFinding) && !result.problems.length && !coverage.length, rows, ...result, findings: scanned.findings, coverage, metadata };
@@ -927,9 +947,9 @@ function checkCommitted(appRoot, manifest, options, acquire, readAuthority = rea
927
947
  ...(scope ? { ownershipScopeClosed: scope } : {}),
928
948
  source: "committed-git-tree", ...(keyLogDigest ? { keyLogDigest, keyCheckpoint, rootFingerprint: trust.rootFingerprint, ...(keyAuthorityBinding ? { keyAuthority: keyAuthorityBinding } : {}) } : {}),
929
949
  };
930
- const result = evaluate(scanned.findings, exceptions, { ...options, manifest, trust, trustEnrollment: trust?.rootFingerprint
950
+ const result = adviseOnlyFindings(evaluate(scanned.findings, exceptions, { ...options, manifest, trust, trustEnrollment: trust?.rootFingerprint
931
951
  ? { enrolled: trust.enrollmentComplete === true, pending: trust.enrollmentComplete !== true }
932
- : trustState?.pending !== undefined || trustState?.enrolled !== undefined ? trustState : undefined, metadata });
952
+ : trustState?.pending !== undefined || trustState?.enrolled !== undefined ? trustState : undefined, metadata }), repositoryIdentity);
933
953
  const coverage = [...new Map(metadata.coverage.map((x) => [`${x.path}\0${x.reason}`, x])).values()];
934
954
  const rows = capabilityTable(manifest, scanned.deps, { ...result, coverage });
935
955
  return { ok: !result.violations.some(isBlockingFinding) && !result.problems.length && !coverage.length, rows, ...result, findings: scanned.findings, coverage, metadata };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rightkit/release",
3
- "version": "0.6.85",
3
+ "version": "0.6.87",
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",
@@ -44,8 +44,19 @@ export function fetchVersionDocument(run, name, version) {
44
44
  const cut = text.lastIndexOf("\n");
45
45
  const status = Number(text.slice(cut + 1).trim());
46
46
  if (!Number.isInteger(status) || status === 0) return { status: 0, error: "curl returned no HTTP status" };
47
- if (status !== 200) return { status, error: `HTTP ${status}` };
48
- try { return { status, body: JSON.parse(text.slice(0, cut)) }; } catch (e) { return { status, error: `HTTP 200 with an unreadable body: ${e.message}` }; }
47
+ if (status === 200) {
48
+ try { return { status, body: JSON.parse(text.slice(0, cut)) }; } catch (e) { return { status, error: `HTTP 200 with an unreadable body: ${e.message}` }; }
49
+ }
50
+ // The per-version address can keep answering a cached 404 for minutes after the registry has the version (seen on 0.6.84 and
51
+ // 0.6.85: 20 tries of 404 while the package document already listed it). Ask the package document before calling it absent.
52
+ const all = run("curl", ["-sS", "--max-time", "30", "-H", "cache-control: no-cache", "-H", "pragma: no-cache", "-H", "accept: application/vnd.npm.install-v1+json", `${REGISTRY}${name.replace("/", "%2f")}`], { encoding: "utf8", maxBuffer: 1 << 26 });
53
+ if (!all.error && all.status === 0) {
54
+ try {
55
+ const listed = JSON.parse(String(all.stdout ?? ""))?.versions?.[version];
56
+ if (listed?.dist) return { status: 200, body: listed };
57
+ } catch { /* not a package document: the version address's answer stands */ }
58
+ }
59
+ return { status, error: `HTTP ${status}` };
49
60
  }
50
61
 
51
62
  /** The pnpm store the checkout installed from (`storeDir` in its node_modules/.modules.yaml, e.g. /Volumes/D/.pnpm-store/v11), as a `--store-dir` value (its parent). */
@@ -83,7 +94,7 @@ export function toolCommand(command, args, platform = process.platform, comspec
83
94
  return [command, args];
84
95
  }
85
96
 
86
- export function publishLocalNpm(argv, { run = spawnSync, log = console.log, platform = process.platform, readToken = () => readKeychainToken(run), npmrc = accountNpmrc, exists = fs.existsSync, verifyTries = 20, verifyDelaySeconds = 15 } = {}) {
97
+ export function publishLocalNpm(argv, { run = spawnSync, log = console.log, platform = process.platform, readToken = () => readKeychainToken(run), npmrc = accountNpmrc, exists = fs.existsSync, verifyTries = 60, verifyDelaySeconds = 15 } = {}) {
87
98
  const o = parseArgs(argv);
88
99
  if (platform !== "darwin" && platform !== "win32") fail(`publish-local npm runs on the Mac (the token is the Keychain item ${NPM_KEYCHAIN_SERVICE}) or Windows (the account's own npm sign-in); this host is ${platform}`);
89
100
  const userNpmrc = platform === "win32" ? npmrc() : null;
@@ -203,12 +203,13 @@ export async function runQa({ stage, platform, releaseIdArg, configPath, deps =
203
203
  const sourceListing = split && journeysConfig && !journeysConfig.receipt
204
204
  ? (deps.writeSourceListing ?? writeQaSourceListing)({ source: release, dir: path.join(repoRoot, ".right-release", "qa-source"), git: gitRunner })
205
205
  : null;
206
- // The journeys runner builds with `rustright cargo` in the app root, not through the seam, so the broker checks the stage's Class A
207
- // verdict against that directory (its workspace is the cwd relative to the snapshot). Hand it the verdict for that directory, derived
208
- // from the stage's root verdict exactly as the seam derives one for each of its own calls (seam-broker.mjs verdictForCwd).
206
+ // The journeys runner builds with `rustright cargo` itself, not through the seam, so the broker checks the stage's Class A verdict
207
+ // against the directory rustright selects for that build: the directory of the build's `--manifest-path`, or the app root without
208
+ // one (journeysBuildWorkspace). Hand it the verdict for that directory, derived from the stage's root verdict exactly as the seam
209
+ // derives one for each of its own calls (seam-broker.mjs verdictForCwd).
209
210
  const runCwd = appRoot;
210
211
  const stageEnv = deps.env ?? process.env;
211
- const classAForRoot = sourceListing && stageEnv[CLASS_A_ENV] ? (deps.verdictForCwd ?? verdictForCwd)(stageEnv, runCwd) : null;
212
+ const classAForRoot = sourceListing && stageEnv[CLASS_A_ENV] ? (deps.verdictForCwd ?? verdictForCwd)(stageEnv, journeysBuildWorkspace({ manifestFile: path.resolve(appRoot, journeysConfig.manifest ?? "journeys.toml"), appRoot, args: (journeysConfig.args?.[stage] ?? []).map(String) })) : null;
212
213
  const runEnv = {
213
214
  ...process.env, ...(sourceListing ? { [QA_SOURCE_LISTING_ENV]: sourceListing } : {}), ...(classAForRoot ? { [CLASS_A_ENV]: classAForRoot } : {}), RIGHT_RELEASE_QA_STAGE: stage, RIGHT_RELEASE_QA_COMMIT: source.commit, RIGHT_RELEASE_QA_RELEASE_ID: releaseId,
214
215
  ...(sealed ? { RIGHT_RELEASE_QA_SEALED_DIR: sealed.sealedDir } : {}), ...(installedDirs.length ? { RIGHTKIT_QA_INSTALLED_DIRS: installedDirs.join(";") } : {}), ...(installedQa?.env ?? {}),
@@ -274,6 +275,44 @@ function usage(code) {
274
275
  process.exit(code);
275
276
  }
276
277
 
278
+ /**
279
+ * The directory `rustright cargo` selects as its workspace for the journeys build the runner is about to make. rustright does not
280
+ * take the process cwd when the command names `--manifest-path`: it takes the manifest's directory (rustright-cli shims.rs
281
+ * normalized_invocation), and the broker checks the Class A verdict against that directory. The build commands are the `build`
282
+ * arrays of the manifest's `[[adapter]]` tables (and `[app_build].command`); `--id` values in the journeys arguments narrow them to
283
+ * the adapters of the named journeys. A build without `--manifest-path` selects the app root. Builds that select different
284
+ * directories cannot share one verdict, so that is refused by name.
285
+ */
286
+ export function journeysBuildWorkspace({ manifestFile, appRoot, args = [] }) {
287
+ if (!existsSync(manifestFile)) return appRoot;
288
+ const doc = createRequire(import.meta.url)("smol-toml").parse(readFileSync(manifestFile, "utf8"));
289
+ const ids = new Set();
290
+ for (let index = 0; index < args.length; index += 1) {
291
+ if (args[index] === "--id" && args[index + 1]) ids.add(String(args[index + 1]));
292
+ else if (String(args[index]).startsWith("--id=")) ids.add(String(args[index]).slice("--id=".length));
293
+ }
294
+ const journeys = (Array.isArray(doc.journey) ? doc.journey : []).filter((journey) => ids.size === 0 || ids.has(String(journey.id)));
295
+ const wanted = new Set(journeys.filter((journey) => journey.adapter).map((journey) => String(journey.adapter)));
296
+ const builds = (Array.isArray(doc.adapter) ? doc.adapter : [])
297
+ .filter((adapter) => Array.isArray(adapter.build) && (ids.size === 0 || wanted.has(String(adapter.name))))
298
+ .map((adapter) => ({ name: `adapter ${adapter.name}`, command: adapter.build.map(String) }));
299
+ if (Array.isArray(doc.app_build?.command) && journeys.some((journey) => !journey.adapter)) builds.push({ name: "app_build", command: doc.app_build.command.map(String) });
300
+ const dirOf = (command) => {
301
+ const separator = command.indexOf("--");
302
+ const index = command.findIndex((value, at) => (separator < 0 || at < separator) && (value === "--manifest-path" || value.startsWith("--manifest-path=")));
303
+ if (index < 0) return appRoot;
304
+ const manifest = command[index] === "--manifest-path" ? command[index + 1] : command[index].slice("--manifest-path=".length);
305
+ return manifest ? path.dirname(path.resolve(appRoot, manifest)) : appRoot;
306
+ };
307
+ const dirs = new Map();
308
+ for (const build of builds) { const dir = dirOf(build.command); dirs.set(dir, [...(dirs.get(dir) ?? []), build.name]); }
309
+ if (dirs.size === 0) return appRoot;
310
+ if (dirs.size > 1) {
311
+ throw new Error(`${manifestFile}: the journeys builds of this run select different rustright workspaces (${[...dirs].map(([dir, names]) => `${dir}: ${names.join(", ")}`).join("; ")}); one run carries one Class A verdict, so name one journey set per run with --id`);
312
+ }
313
+ return [...dirs.keys()][0];
314
+ }
315
+
277
316
  export async function main(args) {
278
317
  if (args[0] === "audit") process.exit(auditMain(args.slice(1)));
279
318
  if (args[0] === "policy") process.exit(policyMain(args.slice(1), { program: "right-release qa policy" }));
@@ -66,7 +66,13 @@ import { WIN_PACKAGE_DEFAULT_TRIPLE } from "./win-package-recipe.mjs";
66
66
  export const TEST_MODE_MARKER = "RIGHTKIT-TEST-MODE-COMPILED"; // identical to `TEST_MODE_MARKER_TEXT` in rightkit-daemon/src/mode.rs
67
67
  const CHUNK = 4 * 1024 * 1024;
68
68
  const FORBIDDEN_CLASSES = new Set(["S1", "S2", "S3", "S4"]);
69
- const CLASSES = new Set(["S1", "S2", "S3", "S4", "S5", "S6"]);
69
+ const CLASSES = new Set(["S1", "S2", "S3", "S4", "S5", "S6", "S7"]);
70
+ // S7, a handoff: a one-time value (a token, a nonce) the app's own code sets on a child process it starts, which the child reads and
71
+ // removes. It selects no test mode, data root, executable, library or identity (M23 names those), so it is not compiled out; both ends
72
+ // are checked in source instead (handoffFindings): the line that sets it on the child and the line that removes it after the read.
73
+ const ANCHOR = /^[^:\s][^:]*:[1-9][0-9]*$/;
74
+ const HANDOFF_SET = /(?:\.envs?\s*\(|\bset_var\s*\(|\bsetenv\s*\(|\benvironment\s*\[|\benv\w*\s*\.\s*insert\s*\()/;
75
+ const HANDOFF_CLEAR = /(?:\benv_remove\s*\(|\bremove_var\s*\(|\bunsetenv\s*\(|\bremoveValue\s*\()/;
70
76
  const CHANNELS = new Set(["env", "argv", "settings", "preference", "frontend"]);
71
77
  // `swift:<CONDITION>`: the read sits inside `#if <CONDITION>`, a Swift compilation condition the Release build does not define
72
78
  // (`DEBUG`, or the app's own, e.g. `PULSE_QA`); the source walk confirms the enclosure and the project's Release settings.
@@ -337,7 +343,7 @@ export function parseInventory(text, label = "switches.json") {
337
343
  if (typeof entry?.name !== "string" || !entry.name) { bad("every switch needs a `name`"); continue; }
338
344
  if (names.has(entry.name)) bad(`${where} is listed twice`);
339
345
  names.add(entry.name);
340
- if (!CLASSES.has(entry.class)) bad(`${where}: \`class\` must be one of S1..S6`);
346
+ if (!CLASSES.has(entry.class)) bad(`${where}: \`class\` must be one of S1..S7`);
341
347
  if (!CHANNELS.has(entry.channel)) bad(`${where}: \`channel\` must be one of ${[...CHANNELS].join(", ")}`);
342
348
  if (FORBIDDEN_CLASSES.has(entry.class)) {
343
349
  if (typeof entry.compiledOut !== "string" || !COMPILED_OUT.test(entry.compiledOut)) {
@@ -355,6 +361,12 @@ export function parseInventory(text, label = "switches.json") {
355
361
  }
356
362
  } else if (entry.class === "S6") {
357
363
  if (!["bool", "int", "enum"].includes(entry.valueType)) bad(`${where}: class S6 needs a bounded \`valueType\` (bool, int or enum)`);
364
+ } else if (entry.class === "S7") {
365
+ if (entry.channel !== "env") bad(`${where}: class S7 is a value handed to a child process in its environment; \`channel\` must be env`);
366
+ const handoff = entry.handoff;
367
+ if (!handoff || typeof handoff !== "object" || Array.isArray(handoff) || !ANCHOR.test(handoff.setBy ?? "") || !ANCHOR.test(handoff.clearedAt ?? "")) {
368
+ bad(`${where}: class S7 needs \`handoff\`: { setBy: "<path>:<line>", clearedAt: "<path>:<line>" } (where the app sets it on its child, and where the child removes it after reading)`);
369
+ }
358
370
  } else if (entry.class === "S5") {
359
371
  if (entry.userGesture !== true) bad(`${where}: class S5 needs \`userGesture: true\` (chosen by a picker, saved preference or the user's own argument)`);
360
372
  }
@@ -588,6 +600,7 @@ export function sourceSwitchFindings({ sourceRoot, sourceRoots, inventoryText, i
588
600
  if (swift) swiftConditions.add(swift[1]);
589
601
  }
590
602
  findings.push(...swiftReleaseConditionFindings(walkRoots, skipAbs, sourceRoot, swiftConditions));
603
+ findings.push(...handoffFindings(doc, sourceRoot, inventoryLabel));
591
604
  return findings;
592
605
  }
593
606
 
@@ -599,6 +612,61 @@ const ownerNameMatches = (pattern, name) => (pattern.endsWith("*") ? name.starts
599
612
  const treeHasCrate = (treeText, crate) => typeof treeText === "string" && new RegExp(`(^|[^A-Za-z0-9_-])${escapeRegExp(crate)} v[0-9]`, "m").test(treeText);
600
613
  const PRESENCE_CALL = { scrub: /(?:env_remove|remove_var|env_clear|scrub\w*|clear\w*|retain)/, clear: /(?:env_remove|remove_var|env_clear|scrub\w*|clear\w*|retain)/, set: /(?:set_var|\.envs?\s*\(|\bset\w*\s*\()/ };
601
614
 
615
+ // Does `<path>:<line>` under the source root show the literal name beside a call matching `call` (two lines either side)? null when it does.
616
+ function anchorCallProblem(sourceRoot, name, anchor, call, what, alias = null) {
617
+ if (!sourceRoot) return "has no source root to read its anchor from";
618
+ const [rel, line] = [anchor.slice(0, anchor.lastIndexOf(":")), Number(anchor.slice(anchor.lastIndexOf(":") + 1))];
619
+ const base = path.resolve(sourceRoot);
620
+ const abs = path.resolve(base, rel);
621
+ if (!within(base, abs)) return `anchor ${anchor} escapes the app root`;
622
+ let lines;
623
+ try { lines = readFileSync(abs, "utf8").split(/\r?\n/); } catch { return `anchor ${anchor}: the file does not exist`; }
624
+ if (line > lines.length) return `anchor ${anchor}: the file has only ${lines.length} lines`;
625
+ const window = lines.slice(Math.max(0, line - 3), line + 2).join("\n");
626
+ const named = window.includes(`"${name}"`) || (alias && new RegExp(`\\b${alias}\\b`).test(window));
627
+ if (!named) return `anchor ${anchor} does not show the literal "${name}"${alias ? ` or its constant ${alias}` : ""} within two lines`;
628
+ if (!call.test(window)) return `anchor ${anchor} shows the name but no ${what} (${call.source})`;
629
+ return null;
630
+ }
631
+
632
+ // The identifier a `<path>:<line>` line declares as a constant equal to "name" (`const X: &str = "name";`, `static`, `let`), or null.
633
+ function constantNamed(sourceRoot, anchor, name) {
634
+ if (!sourceRoot) return null;
635
+ const [rel, line] = [anchor.slice(0, anchor.lastIndexOf(":")), Number(anchor.slice(anchor.lastIndexOf(":") + 1))];
636
+ const base = path.resolve(sourceRoot);
637
+ const abs = path.resolve(base, rel);
638
+ if (!within(base, abs)) return null;
639
+ let text;
640
+ try { text = readFileSync(abs, "utf8").split(/\r?\n/)[line - 1] ?? ""; } catch { return null; }
641
+ const m = /\b(?:const|static|let)\s+([A-Za-z_][A-Za-z0-9_]*)\b[^=]*=\s*"([^"]*)"/.exec(text);
642
+ return m && m[2] === name ? m[1] : null;
643
+ }
644
+
645
+ /**
646
+ * Class S7 (handoff): both ends of each entry are read from source. `handoff.setBy` must show the app setting the name on a child
647
+ * process, and `handoff.clearedAt` must show the name being removed from the environment (the reader clears it once read). An entry
648
+ * whose anchors do not show that is `inventory-invalid`: the name is then an ordinary runtime read with no class.
649
+ */
650
+ export function handoffFindings(doc, sourceRoot, inventoryLabel = "switches.json") {
651
+ const findings = [];
652
+ for (const entry of doc?.switches ?? []) {
653
+ if (entry?.class !== "S7" || !ANCHOR.test(entry.handoff?.setBy ?? "") || !ANCHOR.test(entry.handoff?.clearedAt ?? "")) continue;
654
+ // `handoff.nameConst` (optional): the line declaring the constant the code uses for the name (`const X: &str = "NAME";`). When it
655
+ // is given and shows that, the two ends may name the constant instead of the literal.
656
+ let alias = null;
657
+ if (entry.handoff.nameConst !== undefined) {
658
+ const declared = ANCHOR.test(entry.handoff.nameConst ?? "") ? constantNamed(sourceRoot, entry.handoff.nameConst, entry.name) : null;
659
+ if (!declared) { findings.push({ layer: "inventory", rule: "inventory-invalid", file: inventoryLabel, reason: `inventory-invalid: switch \`${entry.name}\` (class S7 handoff): handoff.nameConst ${entry.handoff.nameConst} does not declare a constant equal to "${entry.name}"` }); continue; }
660
+ alias = declared;
661
+ }
662
+ for (const [anchor, call, what] of [[entry.handoff.setBy, HANDOFF_SET, "call that sets it on a child process"], [entry.handoff.clearedAt, HANDOFF_CLEAR, "call that removes it from the environment"]]) {
663
+ const problem = anchorCallProblem(sourceRoot, entry.name, anchor, call, what, alias);
664
+ if (problem) findings.push({ layer: "inventory", rule: "inventory-invalid", file: inventoryLabel, reason: `inventory-invalid: switch \`${entry.name}\` (class S7 handoff): ${problem}` });
665
+ }
666
+ }
667
+ return findings;
668
+ }
669
+
602
670
  // Does the app anchor `<path>:<line>` show the name inside a call of the claimed mechanism (a window of two lines either side)?
603
671
  function presenceAnchorProblem(sourceRoot, entry) {
604
672
  const presence = entry.releasePresence;
@@ -49,7 +49,7 @@
49
49
  "@rightkit/qa": "0.7.0",
50
50
  "@rightkit/qa-chrome": "0.1.12",
51
51
  "@rightkit/react-shell": "0.7.9",
52
- "@rightkit/release": "0.6.85",
52
+ "@rightkit/release": "0.6.87",
53
53
  "@rightkit/send-ui": "0.1.0",
54
54
  "@rightkit/settings-ui": "0.7.7",
55
55
  "@rightkit/social-ui": "0.2.1",
@@ -450,7 +450,9 @@
450
450
  "0.6.81",
451
451
  "0.6.82",
452
452
  "0.6.83",
453
- "0.6.84"
453
+ "0.6.84",
454
+ "0.6.85",
455
+ "0.6.86"
454
456
  ],
455
457
  "@rightkit/settings-ui": [
456
458
  "0.1.0",
@@ -596,7 +598,7 @@
596
598
  "rightkit-automation": "0.7.6",
597
599
  "rightkit-autostart": "0.1.1",
598
600
  "rightkit-bench": "0.2.1",
599
- "rightkit-bot-messaging": "0.3.1",
601
+ "rightkit-bot-messaging": "0.3.2",
600
602
  "rightkit-browser": "0.3.12",
601
603
  "rightkit-cache": "0.2.5",
602
604
  "rightkit-captions": "0.1.1",
@@ -754,7 +756,7 @@
754
756
  "rightkit-sysmem": "0.1.0",
755
757
  "rightkit-system-monitor": "0.3.2",
756
758
  "rightkit-tauri-shell": "0.8.10",
757
- "rightkit-terminal-ui": "0.1.4",
759
+ "rightkit-terminal-ui": "0.1.8",
758
760
  "rightkit-text-polish": "0.1.4",
759
761
  "rightkit-theme": "0.1.1",
760
762
  "rightkit-time": "0.1.5",
@@ -918,7 +920,7 @@
918
920
  "@rightkit/qa": "0.7.0",
919
921
  "@rightkit/qa-chrome": "0.1.12",
920
922
  "@rightkit/react-shell": "0.7.7",
921
- "@rightkit/release": "0.6.84",
923
+ "@rightkit/release": "0.6.86",
922
924
  "@rightkit/settings-ui": "0.7.4",
923
925
  "@rightkit/shell": "0.1.1",
924
926
  "@rightkit/tauri": "0.4.3",
@@ -1036,6 +1038,9 @@
1036
1038
  "0.7.3",
1037
1039
  "0.7.4"
1038
1040
  ],
1041
+ "rightkit-bot-messaging": [
1042
+ "0.3.1"
1043
+ ],
1039
1044
  "rightkit-browser": [
1040
1045
  "0.2.0",
1041
1046
  "0.2.1",
@@ -1882,7 +1887,11 @@
1882
1887
  "0.2.0"
1883
1888
  ],
1884
1889
  "rightkit-terminal-ui": [
1885
- "0.1.3"
1890
+ "0.1.3",
1891
+ "0.1.4",
1892
+ "0.1.5",
1893
+ "0.1.6",
1894
+ "0.1.7"
1886
1895
  ],
1887
1896
  "rightkit-timeline": [
1888
1897
  "0.1.1"