@rightkit/release 0.6.39 → 0.6.42

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.
Files changed (86) hide show
  1. package/README.md +110 -11
  2. package/admission-files.mjs +40 -0
  3. package/admission-host.mjs +2 -1
  4. package/app-check.mjs +303 -16
  5. package/app-closure.mjs +6 -4
  6. package/bin/rightkit-gate.mjs +177 -32
  7. package/cargo-contract.mjs +17 -31
  8. package/cargo-license-notices.mjs +129 -19
  9. package/cargo-target-shim.mjs +14 -0
  10. package/carried-cargo.mjs +2 -4
  11. package/cli/right-release.mjs +24 -2
  12. package/cross-targets.mjs +24 -0
  13. package/deterministic-scans.mjs +167 -58
  14. package/development-signing.mjs +25 -2
  15. package/development.mjs +34 -1
  16. package/direct-release-command.mjs +154 -0
  17. package/disk-policy.mjs +16 -0
  18. package/feature-coverage.mjs +134 -0
  19. package/gate-coverage.mjs +38 -0
  20. package/gate-stages.mjs +1 -0
  21. package/ghsa-audit.mjs +95 -0
  22. package/install-app.mjs +33 -5
  23. package/install-channels.mjs +301 -0
  24. package/interactive-session-run.mjs +105 -0
  25. package/legal-contract.mjs +10 -1
  26. package/legion-freeze-consumer.mjs +241 -0
  27. package/linux-publish.mjs +136 -0
  28. package/local-publish.mjs +31 -7
  29. package/nsis-pack.mjs +95 -0
  30. package/nsis-upgrade-template.mjs +93 -0
  31. package/outdated-command.mjs +19 -0
  32. package/ownership-class-rules.mjs +32 -10
  33. package/ownership-mandatory-set.json +23 -0
  34. package/ownership-mandatory-set.mjs +66 -8
  35. package/package-recipe-targets.mjs +54 -19
  36. package/package.json +1 -1
  37. package/payload-root-install.mjs +123 -0
  38. package/plugin-delivery.mjs +141 -0
  39. package/prebuild-gates.mjs +8 -4
  40. package/preflight.mjs +6 -1
  41. package/provision-model-bundle.mjs +172 -0
  42. package/pub-upload.mjs +1 -1
  43. package/publish-local-npm.mjs +34 -9
  44. package/publish-retention.mjs +106 -0
  45. package/publish-update.mjs +15 -8
  46. package/qa-build-features.mjs +24 -15
  47. package/qa-contract.mjs +5 -6
  48. package/qa-control-scan.mjs +14 -0
  49. package/qa-web-pairing.mjs +76 -0
  50. package/r2-s3-multipart.mjs +190 -0
  51. package/r2-verified-upload.mjs +28 -16
  52. package/recipe-build.mjs +53 -3
  53. package/release-checks.mjs +53 -2
  54. package/release-config.mjs +8 -3
  55. package/release-invocation.mjs +12 -2
  56. package/release-pin-floor.mjs +44 -0
  57. package/release-qa-audit.mjs +18 -2
  58. package/release-qa-command.mjs +17 -1
  59. package/release-qa-policy.mjs +30 -3
  60. package/release-switch-cfg.mjs +271 -0
  61. package/release-switch-registry.json +60 -1
  62. package/release-switch-scan.mjs +398 -23
  63. package/release.mjs +97 -6
  64. package/render-views.mjs +141 -0
  65. package/rightkit-registry-resolver.mjs +1 -1
  66. package/rightkit-versions.json +568 -491
  67. package/runtime-artifact-manifest.mjs +9 -0
  68. package/runtime-manifest-refresh.mjs +88 -0
  69. package/rustright-stage.mjs +197 -0
  70. package/scan-digest.mjs +15 -9
  71. package/scan-tool-enrolment.mjs +1 -1
  72. package/security-policy.mjs +196 -0
  73. package/shell-contract.mjs +32 -0
  74. package/snapshot-broker.mjs +8 -1
  75. package/snapshot-check.mjs +58 -0
  76. package/snapshot-request.mjs +25 -2
  77. package/stage-commands.mjs +33 -4
  78. package/stage-ledger.mjs +6 -1
  79. package/stage-receipt.mjs +115 -0
  80. package/stage-sidecar.mjs +188 -17
  81. package/stage-xcframework.mjs +118 -0
  82. package/suite-api.generated.mjs +16 -1
  83. package/unit-gate.mjs +14 -2
  84. package/upload-large.mjs +4 -4
  85. package/upload-release.mjs +6 -0
  86. package/win-package-recipe.mjs +26 -4
@@ -0,0 +1,123 @@
1
+ // `development.targets.<platform>.install.kind: "payload-root"` (rightkit#816, #428): install a verified payload folder into exactly one root.
2
+ //
3
+ // { kind: "payload-root", sourceDirectory: "<repo-relative folder>", installRoot: "<absolute folder>", entrypoint: "<file inside the payload>",
4
+ // stopProcesses?: true }
5
+ //
6
+ // The folder `installRoot` is the install: no `current` sub folder, no versions, no setup program run. Like the production installer it owns only the
7
+ // files the payload ships (the same rule as install-app.mjs --installer on Windows, rightkit#348): every other file in the root (user data, a
8
+ // database, logs) is never read, copied, moved or removed. What the install owns is written to `<installRoot>/.rightkit-payload.json`
9
+ // ({ schema: 1, files: [{ path, sha256 }] }); a later install removes exactly the files that manifest listed and the new payload no longer has.
10
+ //
11
+ // Order: hash the source tree (no symlinks, no reparse points) -> stop what runs from the root (`stopProcesses: true`: only processes whose
12
+ // executable is inside `installRoot`, recipe-build killProcessesUnder) -> write each file beside its destination and rename it over -> read every
13
+ // installed file back and require its digest -> remove the old payload's stale files -> write the manifest. No old copy is kept (dev rule,
14
+ // rightkit#348); a failure leaves the files written so far, names them, and the next run of the same install repairs it.
15
+ import { createHash } from "node:crypto";
16
+ import nodeFs from "node:fs";
17
+ import path from "node:path";
18
+ import { killProcessesUnder } from "./recipe-build.mjs";
19
+
20
+ export const PAYLOAD_ROOT_KIND = "payload-root";
21
+ export const PAYLOAD_ROOT_MANIFEST = ".rightkit-payload.json";
22
+ const KEYS = new Set(["kind", "sourceDirectory", "installRoot", "entrypoint", "stopProcesses"]);
23
+
24
+ export class PayloadRootError extends Error {
25
+ constructor(message) { super(message); this.name = "PayloadRootError"; this.code = "RK_PAYLOAD_ROOT"; }
26
+ }
27
+ const fail = (message) => { throw new PayloadRootError(message); };
28
+ const sha256 = (fs, file) => createHash("sha256").update(fs.readFileSync(file)).digest("hex");
29
+ const containedRelative = (value, label) => {
30
+ if (typeof value !== "string" || !value || path.isAbsolute(value) || path.win32.isAbsolute(value) || /^[A-Za-z]:/.test(value) || value.split(/[\\/]/).includes("..")) fail(`${label} must be a contained relative path`);
31
+ return value.replaceAll("\\", "/");
32
+ };
33
+
34
+ /** Validate the descriptor's shape (no file system access). `platform` is the dev target platform (win | mac | linux). */
35
+ export function validatePayloadRootDescriptor(descriptor, platform = "win") {
36
+ if (descriptor === null || typeof descriptor !== "object" || Array.isArray(descriptor) || descriptor.kind !== PAYLOAD_ROOT_KIND) fail(`install.kind must be "${PAYLOAD_ROOT_KIND}"`);
37
+ const unknown = Object.keys(descriptor).filter((key) => !KEYS.has(key));
38
+ if (unknown.length) fail(`install has unknown key(s): ${unknown.join(", ")} (allowed: ${[...KEYS].join(", ")})`);
39
+ const sourceDirectory = containedRelative(descriptor.sourceDirectory, "install.sourceDirectory");
40
+ const entrypoint = containedRelative(descriptor.entrypoint, "install.entrypoint");
41
+ const absolute = platform === "win" ? path.win32.isAbsolute(descriptor.installRoot ?? "") && /^[A-Za-z]:[\\/]/.test(descriptor.installRoot) : path.posix.isAbsolute(descriptor.installRoot ?? "");
42
+ if (typeof descriptor.installRoot !== "string" || !absolute) fail("install.installRoot must be an absolute path");
43
+ if (descriptor.installRoot.replaceAll("\\", "/").split("/").includes("..")) fail("install.installRoot must not contain ..");
44
+ const segments = descriptor.installRoot.replaceAll("\\", "/").split("/").filter(Boolean);
45
+ if (segments.length < 2) fail("install.installRoot must not be a drive or filesystem root (one dedicated folder for the app)");
46
+ if (descriptor.stopProcesses !== undefined && typeof descriptor.stopProcesses !== "boolean") fail("install.stopProcesses must be a boolean");
47
+ return { ...descriptor, sourceDirectory, entrypoint };
48
+ }
49
+
50
+ /** Every regular file under `dir` as sorted forward-slash relative paths; a symlink or special file refuses. */
51
+ export function listPayloadFiles(dir, fs = nodeFs, prefix = "") {
52
+ const out = [];
53
+ for (const name of [...fs.readdirSync(path.join(dir, prefix))].sort()) {
54
+ const relative = prefix ? `${prefix}/${name}` : name;
55
+ const info = fs.lstatSync(path.join(dir, relative));
56
+ if (info.isSymbolicLink()) fail(`${relative} is a symbolic link or reparse point; a payload holds regular files only`);
57
+ if (info.isDirectory()) out.push(...listPayloadFiles(dir, fs, relative));
58
+ else if (info.isFile()) out.push(relative);
59
+ else fail(`${relative} is neither a file nor a directory`);
60
+ }
61
+ return out;
62
+ }
63
+
64
+ function previousFiles(fs, root) {
65
+ let parsed;
66
+ try { parsed = JSON.parse(String(fs.readFileSync(path.join(root, PAYLOAD_ROOT_MANIFEST), "utf8"))); } catch { return []; }
67
+ if (parsed?.schema !== 1 || !Array.isArray(parsed.files)) return [];
68
+ return parsed.files.map((row) => row?.path).filter((file) => { try { return containedRelative(file, "manifest path") === file; } catch { return false; } });
69
+ }
70
+
71
+ /**
72
+ * Install `sourceDirectory` (already resolved, absolute) into `installRoot`. Returns { installRoot, files, removed, entrypoint, entrypointDigest }.
73
+ * Injectable: fs, log, stop(dirs) (default recipe-build killProcessesUnder).
74
+ */
75
+ export function installPayloadRoot(descriptor, { source, fs = nodeFs, log = () => {}, platform = process.platform, stop = (dirs) => killProcessesUnder(dirs, { platform, log }) } = {}) {
76
+ const installRoot = path.resolve(descriptor.installRoot);
77
+ if (!fs.existsSync(source) || !fs.lstatSync(source).isDirectory()) fail(`payload source ${source} is not a directory`);
78
+ const files = listPayloadFiles(source, fs);
79
+ if (!files.length) fail(`payload source ${source} contains no files`);
80
+ if (!files.includes(descriptor.entrypoint)) fail(`the entrypoint ${descriptor.entrypoint} is not in the payload ${source}`);
81
+ if (files.includes(PAYLOAD_ROOT_MANIFEST)) fail(`the payload must not contain ${PAYLOAD_ROOT_MANIFEST}; it is the install's own record`);
82
+ const rows = files.map((file) => ({ path: file, sha256: sha256(fs, path.join(source, ...file.split("/"))) }));
83
+ const old = previousFiles(fs, installRoot);
84
+ fs.mkdirSync(installRoot, { recursive: true });
85
+ const rootInfo = fs.lstatSync(installRoot);
86
+ if (rootInfo.isSymbolicLink() || !rootInfo.isDirectory()) fail(`${installRoot} is not a real directory`);
87
+ if (descriptor.stopProcesses === true) stop([installRoot]);
88
+ for (const row of rows) {
89
+ const to = path.join(installRoot, ...row.path.split("/"));
90
+ // Nothing between the root and a payload file may be a link: a write through one would land outside the install.
91
+ let walk = installRoot;
92
+ for (const segment of row.path.split("/").slice(0, -1)) {
93
+ walk = path.join(walk, segment);
94
+ const info = fs.lstatSync(walk, { throwIfNoEntry: false });
95
+ if (info && (info.isSymbolicLink() || !info.isDirectory())) fail(`${walk} is not a real directory; refusing to write ${row.path} through it`);
96
+ }
97
+ fs.mkdirSync(path.dirname(to), { recursive: true });
98
+ const existing = fs.lstatSync(to, { throwIfNoEntry: false });
99
+ if (existing && (existing.isSymbolicLink() || !existing.isFile())) fail(`${to} is not a regular file; refusing to replace it`);
100
+ if (existing && sha256(fs, to) === row.sha256) continue; // already this payload's bytes
101
+ const temporary = `${to}.rightkit-tmp-${process.pid}`;
102
+ fs.copyFileSync(path.join(source, ...row.path.split("/")), temporary);
103
+ fs.renameSync(temporary, to);
104
+ }
105
+ for (const row of rows) {
106
+ const got = sha256(fs, path.join(installRoot, ...row.path.split("/")));
107
+ if (got !== row.sha256) fail(`installed ${row.path} does not match the payload (sha256 ${got}, expected ${row.sha256}); the install is incomplete, run it again`);
108
+ }
109
+ const wanted = new Set(rows.map((row) => row.path));
110
+ const removed = [];
111
+ for (const file of old) {
112
+ if (wanted.has(file)) continue;
113
+ const target = path.join(installRoot, ...file.split("/"));
114
+ const info = fs.lstatSync(target, { throwIfNoEntry: false });
115
+ if (info?.isFile()) { fs.rmSync(target, { force: true }); removed.push(file); }
116
+ }
117
+ const manifest = path.join(installRoot, PAYLOAD_ROOT_MANIFEST);
118
+ fs.writeFileSync(`${manifest}.tmp-${process.pid}`, `${JSON.stringify({ schema: 1, files: rows }, null, 2)}\n`);
119
+ fs.renameSync(`${manifest}.tmp-${process.pid}`, manifest);
120
+ const entry = rows.find((row) => row.path === descriptor.entrypoint);
121
+ log(`right-release dev: payload-root installed ${rows.length} file(s) into ${installRoot}${removed.length ? `, removed ${removed.length} stale` : ""}`);
122
+ return { installRoot, files: rows.length, removed, entrypoint: path.join(installRoot, ...descriptor.entrypoint.split("/")), entrypointDigest: entry.sha256 };
123
+ }
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+ // Plugin delivery with the app (rightkit#1442): the app's Claude plugin is packaged in the app, installed and updated by the same install transaction, and
3
+ // read back, so no plugin ever depends on a hand copy into a catalog or a dev checkout.
4
+ //
5
+ // packaging `targets.<platform>.plugin: { dir: "plugins/<app>" }` (release.mjs): the plugin must be valid and its version EQUAL the release version. The
6
+ // plugin folder ships inside the app (bundle resources / payload); this check is what keeps the two from drifting.
7
+ // install `right-release install-app ... --plugin-dir <installed app's plugin folder>` and `right-release plugin-install` call registerAppPlugin after the
8
+ // app itself is installed: a local marketplace `<app>-installed` is generated in the user's data folder from the INSTALLED plugin folder, added to
9
+ // every Claude config root (the default one, CLAUDE_CONFIG_DIR, and every profile under `~/ClaudeProfiles`), the plugin is installed or updated
10
+ // there with Claude's own CLI, and the version Claude recorded (`plugins/installed_plugins.json`) is read back and must equal the app's.
11
+ // Codex: no plugin install CLI contract is evidenced in this workspace, so Codex is NOT driven from here (the result reports it as not covered).
12
+ import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
13
+ import os from "node:os";
14
+ import path from "node:path";
15
+ import { pathToFileURL } from "node:url";
16
+ import { spawnSync } from "./background-process.mjs";
17
+
18
+ export class PluginDeliveryError extends Error {
19
+ constructor(message) { super(message); this.name = "PluginDeliveryError"; this.code = "RK_PLUGIN_DELIVERY"; }
20
+ }
21
+ const fail = (message) => { throw new PluginDeliveryError(message); };
22
+ const NAME = /^[a-z][a-z0-9-]{1,40}$/;
23
+ const VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
24
+
25
+ /** `<dir>/.claude-plugin/plugin.json` -> { name, version, description }. Throws when it is missing, unreadable, or its name or version is not valid. */
26
+ export function readPluginManifest(dir, { fs = { existsSync, readFileSync } } = {}) {
27
+ const file = path.join(dir, ".claude-plugin", "plugin.json");
28
+ if (!fs.existsSync(file)) fail(`${dir} is not a Claude plugin: ${file} is missing (right-ax plugin init)`);
29
+ let manifest;
30
+ try { manifest = JSON.parse(String(fs.readFileSync(file, "utf8"))); } catch (error) { fail(`${file} is not JSON: ${error.message}`); }
31
+ if (typeof manifest?.name !== "string" || !NAME.test(manifest.name)) fail(`${file} needs a lowercase plugin name`);
32
+ if (typeof manifest.version !== "string" || !VERSION.test(manifest.version)) fail(`${file} needs a semver version`);
33
+ return { name: manifest.name, version: manifest.version, description: typeof manifest.description === "string" ? manifest.description : manifest.name };
34
+ }
35
+
36
+ /** The release-gate check: the plugin at `root/<dir>` is valid and carries exactly the app's version. */
37
+ export function assertPluginMatchesApp({ root, plugin, version, fs }) {
38
+ if (plugin === null || typeof plugin !== "object" || Array.isArray(plugin) || typeof plugin.dir !== "string" || Object.keys(plugin).some((key) => key !== "dir")) fail("targets.<platform>.plugin must be { dir: \"<app-relative plugin folder>\" }");
39
+ if (path.isAbsolute(plugin.dir) || path.win32.isAbsolute(plugin.dir) || plugin.dir.split(/[\\/]/).includes("..")) fail(`plugin.dir must be a relative path inside the app: ${plugin.dir}`);
40
+ const manifest = readPluginManifest(path.resolve(root, plugin.dir), { fs });
41
+ if (manifest.version !== version) fail(`the plugin ${manifest.name} is ${manifest.version} but the app is ${version}: they ship as one release, so the versions must be equal`);
42
+ return manifest;
43
+ }
44
+
45
+ /** Claude config roots to register in: explicit `roots`, else `~/.claude`, `CLAUDE_CONFIG_DIR`, and the `.claude` folder of each profile under `~/ClaudeProfiles`. Existing directories only, de-duplicated. */
46
+ export function claudeConfigRoots({ home = os.userInfo().homedir, env = process.env, roots, fs = { existsSync, readdirSync } } = {}) {
47
+ const candidates = roots ?? [path.join(home, ".claude"), ...(env.CLAUDE_CONFIG_DIR ? [env.CLAUDE_CONFIG_DIR] : [])];
48
+ if (!roots) {
49
+ const profiles = path.join(home, "ClaudeProfiles");
50
+ if (fs.existsSync(profiles)) for (const name of fs.readdirSync(profiles)) candidates.push(path.join(profiles, name, ".claude"));
51
+ }
52
+ const seen = new Set();
53
+ return candidates.map((root) => path.resolve(root)).filter((root) => fs.existsSync(root) && !seen.has(root) && seen.add(root));
54
+ }
55
+
56
+ /** The marketplace folder for an app, in the user's data folder (never inside the signed app). */
57
+ export function marketplaceDir({ app, home = os.userInfo().homedir, platform = process.platform, env = process.env }) {
58
+ if (!NAME.test(app)) fail(`app ${JSON.stringify(app)} is not an app slug`);
59
+ const base = platform === "win32" ? path.join(env.LOCALAPPDATA || path.join(home, "AppData", "Local"), "RightKit")
60
+ : platform === "darwin" ? path.join(home, "Library", "Application Support", "RightKit")
61
+ : path.join(env.XDG_DATA_HOME || path.join(home, ".local", "share"), "rightkit");
62
+ return path.join(base, "plugin-marketplaces", app);
63
+ }
64
+
65
+ /** Rebuild the local marketplace from the installed plugin folder: a copy of the plugin and its `.claude-plugin/marketplace.json`, swapped in by rename. */
66
+ export function writeLocalMarketplace({ app, pluginDir, dir, fs = { cpSync, mkdirSync, renameSync, rmSync, writeFileSync, existsSync, readFileSync } }) {
67
+ const manifest = readPluginManifest(pluginDir, { fs });
68
+ const name = `${app}-installed`;
69
+ const staging = `${dir}.new`;
70
+ fs.rmSync(staging, { recursive: true, force: true });
71
+ fs.mkdirSync(path.join(staging, ".claude-plugin"), { recursive: true });
72
+ fs.cpSync(pluginDir, path.join(staging, "plugins", manifest.name), { recursive: true, dereference: false, verbatimSymlinks: true });
73
+ fs.writeFileSync(path.join(staging, ".claude-plugin", "marketplace.json"), `${JSON.stringify({ name, owner: { name: "Orthic Labs" }, plugins: [{ name: manifest.name, source: `./plugins/${manifest.name}`, version: manifest.version, description: manifest.description }] }, null, 2)}\n`);
74
+ fs.mkdirSync(path.dirname(dir), { recursive: true });
75
+ fs.rmSync(dir, { recursive: true, force: true });
76
+ fs.renameSync(staging, dir);
77
+ return { marketplace: name, plugin: manifest.name, version: manifest.version, dir };
78
+ }
79
+
80
+ /** The version Claude recorded for `plugin@marketplace` in one config root (user scope first), or null. */
81
+ export function installedPluginVersion({ root, plugin, marketplace, fs = { readFileSync } }) {
82
+ let recorded;
83
+ try { recorded = JSON.parse(String(fs.readFileSync(path.join(root, "plugins", "installed_plugins.json"), "utf8"))); } catch { return null; }
84
+ const entries = recorded?.plugins?.[`${plugin}@${marketplace}`];
85
+ if (!Array.isArray(entries) || !entries.length) return null;
86
+ return (entries.find((entry) => entry?.scope === "user") ?? entries[0])?.version ?? null;
87
+ }
88
+
89
+ /**
90
+ * Register the app's plugin in every Claude config root and read the version back. `pluginDir` is the INSTALLED app's plugin folder; `version` the app's.
91
+ * Returns { roots: [{ root, version }], codex: "not covered" }. Throws PluginDeliveryError listing every root that did not end at `version`.
92
+ * Injectable: run, fs, roots, home, env, claude (the CLI path).
93
+ */
94
+ export function registerAppPlugin({ app, pluginDir, version, roots, claude = "claude", home = os.userInfo().homedir, env = process.env, platform = process.platform, run = spawnSync, fs, log = (line) => console.log(line) }) {
95
+ const local = fs ? { fs } : {};
96
+ const market = writeLocalMarketplace({ app, pluginDir, dir: marketplaceDir({ app, home, platform, env }), ...local });
97
+ if (market.version !== version) fail(`the installed plugin is ${market.version}, the app is ${version}; the plugin folder in the app is stale`);
98
+ const targets = claudeConfigRoots({ home, env, ...(roots ? { roots } : {}), ...(fs ? { fs } : {}) });
99
+ if (!targets.length) fail("no Claude config root exists to register the plugin in");
100
+ const ref = `${market.plugin}@${market.marketplace}`;
101
+ const problems = [];
102
+ const results = [];
103
+ for (const root of targets) {
104
+ // HOME from the password database and this root as the config dir: the registration lands in the root named, never in the invoking shell's profile.
105
+ const childEnv = { ...env, HOME: home, CLAUDE_CONFIG_DIR: root };
106
+ const step = (args) => run(claude, args, { env: childEnv, encoding: "utf8", windowsHide: true, shell: false });
107
+ const added = step(["plugin", "marketplace", "add", market.dir]);
108
+ if ((added?.error || added?.status !== 0) && !/already/i.test(`${added?.stderr}${added?.stdout}`)) { problems.push(`${root}: claude plugin marketplace add failed (${added?.error?.message ?? `exit ${added?.status}`})`); continue; }
109
+ step(["plugin", "marketplace", "update", market.marketplace]);
110
+ const installed = step(["plugin", "install", ref]);
111
+ if ((installed?.error || installed?.status !== 0) && !/already/i.test(`${installed?.stderr}${installed?.stdout}`)) { problems.push(`${root}: claude plugin install ${ref} failed (${installed?.error?.message ?? `exit ${installed?.status}`})`); continue; }
112
+ step(["plugin", "update", ref]);
113
+ const got = installedPluginVersion({ root, plugin: market.plugin, marketplace: market.marketplace, ...(fs ? { fs } : {}) });
114
+ if (got !== version) { problems.push(`${root}: Claude recorded ${got ?? "no install"} for ${ref}, expected ${version}`); continue; }
115
+ results.push({ root, version: got });
116
+ log(`right-release plugin: ${ref} ${got} registered in ${root}`);
117
+ }
118
+ if (problems.length) fail(`plugin delivery did not finish:\n${problems.map((line) => `- ${line}`).join("\n")}`);
119
+ return { marketplace: market.marketplace, plugin: market.plugin, version, roots: results, codex: "not covered: no Codex plugin install contract is evidenced" };
120
+ }
121
+
122
+ export function main(argv = process.argv.slice(2)) {
123
+ const opts = { app: null, pluginDir: null, version: null, roots: [], claude: "claude" };
124
+ const flags = { "--app": "app", "--plugin-dir": "pluginDir", "--version": "version", "--claude-root": "roots", "--claude": "claude" };
125
+ for (let i = 0; i < argv.length; i += 1) {
126
+ const key = flags[argv[i]];
127
+ if (!key || argv[i + 1] === undefined) { console.error(`right-release plugin-install: unknown or incomplete argument ${argv[i]}\nusage: right-release plugin-install --app <slug> --plugin-dir <installed plugin folder> [--version <v>] [--claude-root <dir>]... [--claude <cli>]`); return 2; }
128
+ if (key === "roots") opts.roots.push(argv[i + 1]); else opts[key] = argv[i + 1];
129
+ i += 1;
130
+ }
131
+ try {
132
+ if (!opts.app || !opts.pluginDir) fail("--app and --plugin-dir are required");
133
+ const pluginDir = path.resolve(opts.pluginDir);
134
+ const version = opts.version ?? readPluginManifest(pluginDir).version;
135
+ const result = registerAppPlugin({ app: opts.app, pluginDir, version, ...(opts.roots.length ? { roots: opts.roots } : {}), claude: opts.claude });
136
+ console.log(JSON.stringify(result));
137
+ return 0;
138
+ } catch (error) { console.error(`right-release plugin-install: ${error.message}`); return error instanceof PluginDeliveryError ? 1 : 2; }
139
+ }
140
+
141
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) process.exitCode = main();
@@ -6,7 +6,7 @@ import { spawnSync } from "./background-process.mjs";
6
6
  import { assertReleaseDependencies } from "./release-dependencies.mjs";
7
7
  import { assertNoForbiddenBuildFeatures } from "./qa-build-features.mjs";
8
8
  import { expandRecipeBuildCommands } from "./recipe-build.mjs";
9
- import { assertNoReleaseSwitches, commandTokens, localCrateDirsFromTree, resolveFeatureClosure, shippedRustTriples, validateNonShipped } from "./release-switch-scan.mjs";
9
+ import { assertNoReleaseSwitches, commandTokens, localCrateDirsFromTree, releasePresenceFindings, resolveFeatureClosure, shippedRustTriples, validateNonShipped } from "./release-switch-scan.mjs";
10
10
  import { iosOwnershipScope } from "./ownership-scope.mjs";
11
11
  import { devtoolsEvidence, resolveDevtoolsAllowance } from "./devtools-policy.mjs";
12
12
  import { releaseSwitchInputs } from "./ios-build-context.mjs";
@@ -53,11 +53,12 @@ function thrownText(name, error) {
53
53
  * `detail` is the exact refusal text the build prints (after "right-release: ").
54
54
  * `strict` is true for a real release build (a missing switches.json or an unrunnable feature closure fails);
55
55
  * a dry run passes false and only reports the closure problem.
56
- * Also returns `devtoolsAllowance` and `inventoryText` (the switches.json text or null) for the later binary scans.
56
+ * Also returns `devtoolsAllowance`, `inventoryText` (the switches.json text or null) and `presenceAccepted` (S1-S4 names whose `releasePresence` claim the
57
+ * source proved, #937) for the later binary scans.
57
58
  * @returns {{ findings: { name: string, detail: string }[], treeText: string | undefined, devtoolsAllowance: object, inventoryText: string | null }}
58
59
  */
59
60
  export function evaluatePrebuildGates({ root, config, target, platform, iosSpec, nativeIos, nativeAssembly, nativeFinalizer, strict = true }) {
60
- const state = { devtoolsAllowance: { mode: "denied" }, inventoryText: null };
61
+ const state = { devtoolsAllowance: { mode: "denied" }, inventoryText: null, presenceAccepted: [] };
61
62
  const findings = [];
62
63
  const failed = new Set();
63
64
  // Run one gate: `after` names the gates it depends on. Returns { ok, value }; a blocked or failed gate is a finding.
@@ -177,7 +178,10 @@ export function evaluatePrebuildGates({ root, config, target, platform, iosSpec,
177
178
  gate("release-switches", scanAfter, () => {
178
179
  const closureInput = { treeText, devtools: state.devtoolsAllowance, remoteHost: config.releaseSwitches?.remoteHost, remoteLoopback: config.releaseSwitches?.remoteLoopback, commands: closureCommands.map((c) => commandTokens(c)) };
179
180
  if (releaseSwitchInventoryText != null) {
180
- assertNoReleaseSwitches({ ...closureInput, sourceRoot: root, sourceRoots, skipRoots, inventoryText: releaseSwitchInventoryText, appForbid: config.releaseSwitches?.forbid ?? [] }, "source switch inventory");
181
+ const envHelpers = config.releaseSwitches?.envHelpers;
182
+ assertNoReleaseSwitches({ ...closureInput, sourceRoot: root, sourceRoots, skipRoots, inventoryText: releaseSwitchInventoryText, appForbid: config.releaseSwitches?.forbid ?? [], envHelpers }, "source switch inventory");
183
+ // Names that release code only scrubs, clears or sets stay allowed in the binary scan after the build (rightkit#937).
184
+ state.presenceAccepted = [...releasePresenceFindings({ inventoryText: releaseSwitchInventoryText, treeText, sourceRoot: root, sourceRoots, skipRoots, envHelpers }).accepted];
181
185
  } else if (treeText != null || closureInput.commands.length) {
182
186
  assertNoReleaseSwitches({ ...closureInput, appForbid: config.releaseSwitches?.forbid ?? [] }, "feature closure");
183
187
  }
package/preflight.mjs CHANGED
@@ -369,7 +369,12 @@ export function ownershipCheck(repoRoot, options = {}) {
369
369
  let checked;
370
370
  const split = options.releaseSource?.mode === "snapshot" ? options.releaseSource : null;
371
371
  try { checked = (options.evidenceFactory ?? createOwnershipEvidence)(repoRoot, options.scanRoot ?? repoRoot, options.scope ?? null, ...(split ? [split] : [])); }
372
- catch (error) { return fail("ownership", `ownership evidence failed: ${error.message}`, "restore protected RightKit ownership trust and catalog"); }
372
+ catch (error) {
373
+ // A dirty release checkout is the app's own tree, not a RightKit trust problem (#974): name the files and the real fix.
374
+ const dirtyPaths = error?.blocked?.check === "clean-checkout" && Array.isArray(error.blocked.paths) ? error.blocked.paths : null;
375
+ if (dirtyPaths) return fail("ownership", `ownership evidence failed: ${error.message}: ${dirtyPaths.join(", ")}`, "commit or park these files; a release builds only from a clean committed tree");
376
+ return fail("ownership", `ownership evidence failed: ${error.message}`, "restore protected RightKit ownership trust and catalog");
377
+ }
373
378
  const { result, evidence, floor } = checked;
374
379
  // R4: evidence for another commit or tree than the selected one is refused whatever produced it (a factory that read HEAD, a stale one).
375
380
  if (split && (evidence?.commit !== split.commit || (evidence?.tree !== undefined && evidence.tree !== split.tree))) {
@@ -0,0 +1,172 @@
1
+ #!/usr/bin/env node
2
+ // `right-release provision-model [--config <file>] [--id <bundle>] [--dry-run]`: the pinned, verified build-time fetch of a catalog model
3
+ // bundle (#993), replacing the per-app fetch scripts. The app declares what to provision:
4
+ //
5
+ // modelBundles: [{
6
+ // id: "embeddinggemma2-q4", // the bundle id in the rightkit-models catalog
7
+ // dest: "src-tauri/resources/embed_model", // app-relative directory the files are provisioned into
8
+ // pins: [{ path: "model.onnx", sha256: "<64 hex>", size: 123 }, ...], // the catalog's own pins for the bundle: nothing is fetched unpinned
9
+ // source: { baseUrl: "https://host/models" } // https; each file is <baseUrl>/<id>/<path> (a pin may carry its own `url`)
10
+ // | { r2: { bucket: "rightsites-updates", prefix: "models" } } // S3-signed GET of <prefix>/<id>/<path>; credentials derived in memory from CLOUDFLARE_API_TOKEN
11
+ // }]
12
+ //
13
+ // Every file is downloaded into `<file>.part` (resumed with a Range request when a partial copy exists), then its size and sha256 are checked
14
+ // against the pin before it is renamed into place; a file that already matches its pin is not fetched again; a mismatch deletes the partial copy
15
+ // and fails, and a file in place is never replaced by unverified bytes. The pins come from the app's config, which takes them from the
16
+ // `rightkit-models` catalog spec for the bundle (crates/rightkit-models/src/suite/catalog.rs): this module judges bytes against pins, it does
17
+ // not read the catalog. Nothing is signed, uploaded or written outside `dest`.
18
+ import { createHash } from "node:crypto";
19
+ import { createReadStream, createWriteStream, existsSync, mkdirSync, renameSync, rmSync, statSync } from "node:fs";
20
+ import path from "node:path";
21
+ import { pathToFileURL } from "node:url";
22
+ import { once } from "node:events";
23
+ import { CommandSpecError, loadAppConfig, relativeInside } from "./command-spec.mjs";
24
+ import { defaultReleaseConfigFile } from "./release-config.mjs";
25
+ import { deriveR2S3Credentials, getObject } from "./r2-s3-multipart.mjs";
26
+
27
+ const fail = (message) => { throw new CommandSpecError(message); };
28
+ const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
29
+ const SHA256 = /^[0-9a-f]{64}$/;
30
+ const BUNDLE_KEYS = ["id", "dest", "pins", "source"];
31
+ const PIN_KEYS = ["path", "sha256", "size", "url"];
32
+ const SAFE_ID = /^[a-z0-9][a-z0-9._-]*$/;
33
+ const R2_NAME = /^[a-z0-9][a-z0-9.-]{2,62}$/;
34
+
35
+ /** Validate one bundle declaration; returns it with pins' paths normalised. Throws CommandSpecError. */
36
+ export function validateModelBundle(bundle, label = "modelBundles entry") {
37
+ if (!isObject(bundle)) fail(`${label} must be an object`);
38
+ const unknown = Object.keys(bundle).filter((key) => !BUNDLE_KEYS.includes(key));
39
+ if (unknown.length) fail(`${label} has unknown key(s): ${unknown.join(", ")} (allowed: ${BUNDLE_KEYS.join(", ")})`);
40
+ if (typeof bundle.id !== "string" || !SAFE_ID.test(bundle.id)) fail(`${label}.id must be a bundle id (lowercase letters, digits, . _ -)`);
41
+ const dest = relativeInside(bundle.dest, `${label}.dest`);
42
+ if (["", ".", "./"].includes(dest) || /^(?:\.git|src|src-tauri|node_modules)\/?$/.test(dest)) fail(`${label}.dest ${dest} is not a dedicated model directory`);
43
+ if (!Array.isArray(bundle.pins) || bundle.pins.length === 0) fail(`${label}.pins must list every file of the bundle with its sha256 and size`);
44
+ const seen = new Set();
45
+ const pins = bundle.pins.map((pin, index) => {
46
+ const where = `${label}.pins[${index}]`;
47
+ if (!isObject(pin)) fail(`${where} must be an object`);
48
+ const bad = Object.keys(pin).filter((key) => !PIN_KEYS.includes(key));
49
+ if (bad.length) fail(`${where} has unknown key(s): ${bad.join(", ")} (allowed: ${PIN_KEYS.join(", ")})`);
50
+ const file = relativeInside(pin.path, `${where}.path`);
51
+ if (seen.has(file)) fail(`${where}.path ${file} is pinned twice`);
52
+ seen.add(file);
53
+ if (typeof pin.sha256 !== "string" || !SHA256.test(pin.sha256)) fail(`${where}.sha256 must be 64 lowercase hex characters`);
54
+ if (!Number.isSafeInteger(pin.size) || pin.size < 1) fail(`${where}.size must be a positive integer (bytes)`);
55
+ if (pin.url !== undefined && !/^https:\/\/[^\s]+$/.test(pin.url)) fail(`${where}.url must be an https URL`);
56
+ return { ...pin, path: file };
57
+ });
58
+ const source = bundle.source;
59
+ if (!isObject(source)) fail(`${label}.source must be { baseUrl } or { r2: { bucket, prefix } }`);
60
+ if (source.baseUrl !== undefined && source.r2 !== undefined) fail(`${label}.source: give baseUrl or r2, not both`);
61
+ if (source.baseUrl !== undefined) {
62
+ if (typeof source.baseUrl !== "string" || !/^https:\/\/[^\s?#]+$/.test(source.baseUrl)) fail(`${label}.source.baseUrl must be an https URL without a query`);
63
+ } else if (source.r2 !== undefined) {
64
+ if (!isObject(source.r2) || typeof source.r2.bucket !== "string" || !R2_NAME.test(source.r2.bucket)) fail(`${label}.source.r2.bucket must be an R2 bucket name`);
65
+ if (source.r2.prefix !== undefined) relativeInside(source.r2.prefix, `${label}.source.r2.prefix`);
66
+ } else fail(`${label}.source must be { baseUrl } or { r2: { bucket, prefix } }`);
67
+ return { id: bundle.id, dest, pins, source };
68
+ }
69
+
70
+ async function digestOfFile(file) {
71
+ const hash = createHash("sha256");
72
+ let size = 0;
73
+ for await (const chunk of createReadStream(file)) { hash.update(chunk); size += chunk.length; }
74
+ return { sha256: hash.digest("hex"), size };
75
+ }
76
+
77
+ async function appendBody(response, part, append) {
78
+ const out = createWriteStream(part, { flags: append ? "a" : "w" });
79
+ try {
80
+ for await (const piece of response.body) if (!out.write(piece)) await once(out, "drain");
81
+ } finally {
82
+ out.end();
83
+ await once(out, "close");
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Provision `bundle` (validated) under `appRoot`. `fetchImpl` is fetch; `env` carries CLOUDFLARE_API_TOKEN for an r2 source. Resolves to
89
+ * { id, dest, files: [{ path, sha256, size, status: "present" | "fetched" }] }.
90
+ */
91
+ export async function provisionModelBundle({ id, pins, dest, source }, { appRoot = process.cwd(), env = process.env, fetchImpl = fetch, log = () => {}, dryRun = false } = {}) {
92
+ const bundle = validateModelBundle({ id, pins, dest, source });
93
+ const root = path.resolve(appRoot, bundle.dest);
94
+ const files = [];
95
+ let credentials = null;
96
+ for (const pin of bundle.pins) {
97
+ const target = path.join(root, ...pin.path.split("/"));
98
+ const part = `${target}.part`;
99
+ if (existsSync(target) && statSync(target).size === pin.size && (await digestOfFile(target)).sha256 === pin.sha256) {
100
+ log(`model ${bundle.id}: ${pin.path} present and verified`);
101
+ files.push({ path: pin.path, sha256: pin.sha256, size: pin.size, status: "present" });
102
+ continue;
103
+ }
104
+ if (dryRun) { files.push({ path: pin.path, sha256: pin.sha256, size: pin.size, status: "would-fetch" }); continue; }
105
+ mkdirSync(path.dirname(target), { recursive: true });
106
+ const have = existsSync(part) ? statSync(part).size : 0;
107
+ if (have > pin.size) rmSync(part, { force: true });
108
+ const offset = existsSync(part) ? statSync(part).size : 0;
109
+ if (offset < pin.size) {
110
+ let response;
111
+ try {
112
+ if (bundle.source.r2) {
113
+ credentials ??= await deriveR2S3Credentials(env.CLOUDFLARE_API_TOKEN);
114
+ const key = [bundle.source.r2.prefix, bundle.id, pin.path].filter(Boolean).join("/");
115
+ response = await getObject({ bucket: bundle.source.r2.bucket, key, credentials, fetchImpl, ...(offset ? { range: `bytes=${offset}-` } : {}) });
116
+ } else {
117
+ const url = pin.url ?? `${bundle.source.baseUrl.replace(/\/+$/, "")}/${[bundle.id, ...pin.path.split("/")].map(encodeURIComponent).join("/")}`;
118
+ response = await fetchImpl(url, { headers: offset ? { range: `bytes=${offset}-` } : {} });
119
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
120
+ }
121
+ } catch (error) { throw new Error(`model ${bundle.id}: fetching ${pin.path} failed (${error.message})`); }
122
+ if (!response.body) throw new Error(`model ${bundle.id}: fetching ${pin.path} returned no body`);
123
+ // A server that ignored the Range header sends the whole file: start the partial copy over.
124
+ await appendBody(response, part, offset > 0 && response.status === 206);
125
+ }
126
+ const got = await digestOfFile(part);
127
+ if (got.size !== pin.size || got.sha256 !== pin.sha256) {
128
+ rmSync(part, { force: true });
129
+ throw new Error(`model ${bundle.id}: ${pin.path} does not match its pin (size ${got.size} of ${pin.size}, sha256 ${got.sha256.slice(0, 16)}... of ${pin.sha256.slice(0, 16)}...); the partial copy was removed`);
130
+ }
131
+ renameSync(part, target);
132
+ log(`model ${bundle.id}: ${pin.path} fetched and verified (${pin.size} bytes)`);
133
+ files.push({ path: pin.path, sha256: pin.sha256, size: pin.size, status: "fetched" });
134
+ }
135
+ return { id: bundle.id, dest: bundle.dest, files };
136
+ }
137
+
138
+ export function parseProvisionArgs(argv) {
139
+ const opts = { config: defaultReleaseConfigFile(), id: undefined, dryRun: false };
140
+ for (let i = 0; i < argv.length; i += 1) {
141
+ const arg = argv[i];
142
+ if (arg === "--config" || arg === "--id") {
143
+ const value = argv[i + 1];
144
+ if (!value || value.startsWith("--")) throw new Error(`${arg} needs a value`);
145
+ opts[arg.slice(2)] = value;
146
+ i += 1;
147
+ } else if (arg === "--dry-run") opts.dryRun = true;
148
+ else throw new Error(`unknown provision-model argument: ${arg}`);
149
+ }
150
+ return opts;
151
+ }
152
+
153
+ export async function main(argv = process.argv.slice(2)) {
154
+ const opts = parseProvisionArgs(argv);
155
+ const { config, appRoot } = await loadAppConfig(opts.config);
156
+ if (!Array.isArray(config.modelBundles) || config.modelBundles.length === 0) fail("the release config declares no modelBundles");
157
+ const bundles = config.modelBundles.map((entry, index) => validateModelBundle(entry, `modelBundles[${index}]`));
158
+ const chosen = opts.id ? bundles.filter((bundle) => bundle.id === opts.id) : bundles;
159
+ if (chosen.length === 0) fail(`no modelBundles entry has id ${opts.id}`);
160
+ for (const bundle of chosen) {
161
+ const result = await provisionModelBundle(bundle, { appRoot, log: (line) => console.log(line), dryRun: opts.dryRun });
162
+ console.log(`provision-model ${result.id}: ${result.files.length} file(s) in ${result.dest}${opts.dryRun ? " (dry run: nothing fetched)" : ""}`);
163
+ }
164
+ return 0;
165
+ }
166
+
167
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
168
+ main().then((code) => { process.exitCode = code; }, (error) => {
169
+ console.error(`right-release provision-model: ${error.code ? `[${error.code}] ` : ""}${error.message}`);
170
+ process.exitCode = 1;
171
+ });
172
+ }
package/pub-upload.mjs CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  import { runLargeUpload } from "./upload-large.mjs";
3
- try { runLargeUpload(process.argv.slice(2)); }
3
+ try { await runLargeUpload(process.argv.slice(2)); }
4
4
  catch (error) { console.error(`pub-upload: ${error.message}`); process.exitCode = 1; }
@@ -26,6 +26,23 @@ const GATE = fileURLToPath(new URL("./bin/rightkit-gate.mjs", import.meta.url));
26
26
 
27
27
  function fail(message) { throw new Error(message); }
28
28
 
29
+ /**
30
+ * The registry's version document for `name@version`, asked directly (not through `npm view`, which can answer from its own cache and
31
+ * hides the status and stderr of a failed try, rightkit#1487) with cache-control: no-cache. Returns { status, body, error }: `status` is
32
+ * the HTTP status (0 when no response came), `body` the parsed JSON on a 200, `error` the reason when there is no usable answer.
33
+ */
34
+ export function fetchVersionDocument(run, name, version) {
35
+ const url = `${REGISTRY}${name.replace("/", "%2f")}/${version}`;
36
+ const r = run("curl", ["-sS", "--max-time", "30", "-H", "cache-control: no-cache", "-H", "pragma: no-cache", "-H", "accept: application/json", "-w", "\n%{http_code}", url], { encoding: "utf8", maxBuffer: 1 << 24 });
37
+ if (r.error || r.status !== 0) return { status: 0, error: `curl ${r.error ? r.error.message : `exited ${r.status}: ${String(r.stderr ?? "").trim()}`}` };
38
+ const text = String(r.stdout ?? "");
39
+ const cut = text.lastIndexOf("\n");
40
+ const status = Number(text.slice(cut + 1).trim());
41
+ if (!Number.isInteger(status) || status === 0) return { status: 0, error: "curl returned no HTTP status" };
42
+ if (status !== 200) return { status, error: `HTTP ${status}` };
43
+ try { return { status, body: JSON.parse(text.slice(0, cut)) }; } catch (e) { return { status, error: `HTTP 200 with an unreadable body: ${e.message}` }; }
44
+ }
45
+
29
46
  /** 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). */
30
47
  export function checkoutStoreDir(repo, readFile = (f) => fs.readFileSync(f, "utf8")) {
31
48
  let text;
@@ -50,7 +67,7 @@ export function parseArgs(argv) {
50
67
  return out;
51
68
  }
52
69
 
53
- export function publishLocalNpm(argv, { run = spawnSync, log = console.log, platform = process.platform, readToken = () => readKeychainToken(run) } = {}) {
70
+ export function publishLocalNpm(argv, { run = spawnSync, log = console.log, platform = process.platform, readToken = () => readKeychainToken(run), verifyTries = 20, verifyDelaySeconds = 15 } = {}) {
54
71
  const o = parseArgs(argv);
55
72
  if (platform !== "darwin") fail(`publish-local npm runs on the Mac (the token is the Keychain item ${NPM_KEYCHAIN_SERVICE}); this host is ${platform}`);
56
73
  const git = (args) => {
@@ -66,8 +83,9 @@ export function publishLocalNpm(argv, { run = spawnSync, log = console.log, plat
66
83
  if (manifest.name !== o.pkg) fail(`${dir}/package.json at ${commit} names ${manifest.name}, not ${o.pkg}`);
67
84
  const version = manifest.version;
68
85
 
69
- const already = run("npm", ["view", `${o.pkg}@${version}`, "version", "--prefer-online", "--registry", REGISTRY], { encoding: "utf8" });
70
- if (String(already.stdout ?? "").trim() === version) fail(`${o.pkg}@${version} is already on npm; bump the version`);
86
+ const already = fetchVersionDocument(run, o.pkg, version);
87
+ if (already.status === 200 && already.body?.version === version) fail(`${o.pkg}@${version} is already on npm; bump the version`);
88
+ if (already.status !== 404) fail(`cannot tell whether ${o.pkg}@${version} is on npm (${already.error ?? `HTTP ${already.status}`}); nothing published`);
71
89
 
72
90
  log(`publish-local: Class A for npm:${o.pkg} on ${commit.slice(0, 12)}`);
73
91
  const classA = run(process.execPath, [GATE, "--to", "check", "--unit", `npm:${o.pkg}`, "--commit", commit], { cwd: o.repo, stdio: ["ignore", "inherit", "inherit"] });
@@ -106,14 +124,21 @@ export function publishLocalNpm(argv, { run = spawnSync, log = console.log, plat
106
124
  { encoding: "utf8", env: { ...process.env, RIGHTKIT_NPM_TOKEN: token } });
107
125
  if (pub.status !== 0) fail(`npm publish failed:\n${redact(`${pub.stdout ?? ""}${pub.stderr ?? ""}`).trim()}`);
108
126
 
109
- // The registry may take a moment to serve a new version.
127
+ // The registry may take a moment to serve a new version. Every try asks the registry directly, logs its status when it has no answer, and the
128
+ // command fails only after the whole wait (verifyTries x verifyDelaySeconds); a served version with another shasum fails at once.
110
129
  let shasum = "";
111
- for (let i = 0; i < 20 && !shasum; i += 1) {
112
- const view = run("npm", ["view", `${o.pkg}@${version}`, "dist.shasum", "--prefer-online", "--registry", REGISTRY], { encoding: "utf8" });
113
- shasum = String(view.stdout ?? "").trim();
114
- if (!shasum) run("sleep", ["15"]);
130
+ let last = "no try ran";
131
+ for (let i = 1; i <= verifyTries && !shasum; i += 1) {
132
+ const doc = fetchVersionDocument(run, o.pkg, version);
133
+ if (doc.status === 200 && typeof doc.body?.dist?.shasum === "string" && doc.body.dist.shasum) shasum = doc.body.dist.shasum;
134
+ else {
135
+ last = doc.error ?? `HTTP ${doc.status} without dist.shasum`;
136
+ log(`publish-local: registry try ${i}/${verifyTries} for ${o.pkg}@${version}: ${last}${i < verifyTries ? `; retrying in ${verifyDelaySeconds}s` : ""}`);
137
+ if (i < verifyTries) run("sleep", [String(verifyDelaySeconds)]);
138
+ }
115
139
  }
116
- if (shasum !== sha1) fail(`registry shasum ${shasum || "(not served yet)"} != packed ${sha1} for ${o.pkg}@${version}`);
140
+ if (!shasum) fail(`registry never served ${o.pkg}@${version} after ${verifyTries} tries ${verifyDelaySeconds}s apart (last: ${last}); the publish itself succeeded, so check ${REGISTRY}${o.pkg.replace("/", "%2f")}/${version} before publishing again`);
141
+ if (shasum !== sha1) fail(`registry shasum ${shasum} != packed ${sha1} for ${o.pkg}@${version}`);
117
142
  log(`publish-local: ${o.pkg}@${version} published from ${commit.slice(0, 12)}; registry shasum ${shasum} matches`);
118
143
  return { name: o.pkg, version, commit, shasum };
119
144
  } finally {