@rightkit/release 0.6.89 → 0.6.90

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.
@@ -2113,7 +2113,8 @@ async function runStages(o, args, root, git, io) {
2113
2113
  try { decided = routePlan(o, { to, stages: devTest ? [] : stages, devTest, executor: routeExecutor, stagePlatform: platform, appConfig: selected && to !== "check" ? routeAppConfig({ git, commit: selected.commit, appDir, platform: devTestPlatform(args) }) : null }); }
2114
2114
  catch (e) { o.err(`${tag} ${e.message}`); return 2; }
2115
2115
  if (decided.refusal) { o.err(`${tag} BLOCKED: ${decided.refusal.code}: ${decided.refusal.message}; nothing ran${decided.route === "snapshot" ? " and the checkout is never built" : ""}`); return 1; }
2116
- const notPublisher = decided.route === "snapshot" ? releaseRouteRefusal(o, { stages, platform }) : null;
2116
+ const sealedProvider = () => (selected?.commit ? sealedProviderOf((o.sealedFor ?? sealedFor)({ root, commit: selected.commit, platform })) : null);
2117
+ const notPublisher = decided.route === "snapshot" ? releaseRouteRefusal(o, { stages, platform, sealedProvider }) : null;
2117
2118
  if (notPublisher) { o.err(`${tag} BLOCKED: ${notPublisher.code}: ${notPublisher.message}; nothing ran and the checkout is never built`); return 1; }
2118
2119
  // The declared Linux broker admits snapshots only under its own data root: refused before any ownership or sync when the gate's root is elsewhere.
2119
2120
  if (decided.route === "snapshot" && !hosted) {
@@ -2182,7 +2183,10 @@ async function runStages(o, args, root, git, io) {
2182
2183
  // Release writes to R2. The write credential lives only in the trusted publisher: a GitHub Actions job in the protected
2183
2184
  // publication environment, which sets RIGHTKIT_PUBLISHER=github-environment. Hosts and agents never hold it, so the door refuses the
2184
2185
  // stage anywhere else rather than fail half way through an upload.
2185
- if (stages.includes("release") && !mobile && !(o.env.GITHUB_ACTIONS === "true" && o.env.RIGHTKIT_PUBLISHER === "github-environment")) {
2186
+ // rightkit#1754: an app whose sealed set declares r2-rightapps publishes from this host through publish-update (the release stage re-reads
2187
+ // the provider from the manifest bytes the receipt vouches for); a github-releases app still publishes only from the trusted publisher.
2188
+ const r2LocalRelease = stages.includes("release") && !mobile && sealedProviderOf((o.sealedFor ?? sealedFor)({ root, commit, platform })) === "r2-rightapps";
2189
+ if (stages.includes("release") && !mobile && !r2LocalRelease && !(o.env.GITHUB_ACTIONS === "true" && o.env.RIGHTKIT_PUBLISHER === "github-environment")) {
2186
2190
  o.err(`${tag} BLOCKED: --to release runs only in the trusted publisher (the release workflow's protected publication job). Run --to qualify here, then dispatch the release workflow for ${commit.slice(0, 12)}`);
2187
2191
  return 1;
2188
2192
  }
@@ -2236,6 +2240,22 @@ async function runStages(o, args, root, git, io) {
2236
2240
  const carriedOk = await carrier.finish({ stage });
2237
2241
  return childOk && carriedOk;
2238
2242
  };
2243
+ // rightkit#1754: publish-update runs from the primary checkout, never the snapshot: it reads the checkout's clean HEAD (assertPrimaryReleaseCheckout,
2244
+ // assertCleanSource), so its door run carries no source split and the CLI's checkout guard applies (HEAD must be the sealed commit). It stays out
2245
+ // of SPLIT_COMMANDS. It uploads in process (r2-verified-upload.mjs), so no credential is carried to a broker job.
2246
+ const rightReleaseFromCheckout = async (stage, cliArgs) => {
2247
+ const carrier = await carrierForChildren({ o, ds, root, git, executor, stage, tag, appDir });
2248
+ if (carrier.refusal) { o.err(`${tag} BLOCKED: ${carrier.refusal}; nothing ran`); return false; }
2249
+ const run = startRun({ commonDir, commit, tree, stage });
2250
+ let childOk = false;
2251
+ try {
2252
+ o.out(`${tag} [${stage}] right-release ${cliArgs.join(" ")} (from the primary checkout ${appRoot})`);
2253
+ const r = (o.spawnInherit ?? inheritLaunch)(process.execPath, [cli, ...cliArgs], { cwd: appRoot, env: carriedEnv(carrier, { ...o.env, ...run.env }) });
2254
+ childOk = r.status === 0;
2255
+ } finally { endRun(run); }
2256
+ const carriedOk = await carrier.finish({ stage });
2257
+ return childOk && carriedOk;
2258
+ };
2239
2259
 
2240
2260
  o.out(`${tag} --to ${to} for ${commit.slice(0, 12)}${appDir === "." ? "" : ` (app ${appDir})`}: ${stages.join(" -> ")}; executor ${executor.kind}`);
2241
2261
  // A later stage on the sealed bytes: check, compile and package already passed for them (in this receipt) and the bytes on disk are
@@ -2549,6 +2569,10 @@ async function runStages(o, args, root, git, io) {
2549
2569
  } else {
2550
2570
  if (!receipt.stages.qualify?.ok || receipt.stages.qualify.manifestSha256 !== sealed.manifestSha256) { o.err(`${tag} BLOCKED: [release] the sealed set was not qualified (installed QA) in this door run's receipt`); ok = false; }
2551
2571
  else if (qualifyRecordProblem(receipt.stages.qualify)) { o.err(`${tag} BLOCKED: [release] the recorded qualification no longer stands: ${qualifyRecordProblem(receipt.stages.qualify)}; nothing was uploaded`); ok = false; }
2572
+ else if (sealedProviderOf(sealedNow) === "r2-rightapps" && sealedNow?.digest === sealed.manifestSha256 && !(o.env.GITHUB_ACTIONS === "true" && o.env.RIGHTKIT_PUBLISHER === "github-environment")) {
2573
+ // rightkit#1754: the provider is re-read from the manifest bytes this receipt vouches for; GC-T22 still needs Adrian's words for the build.
2574
+ ok = await rightReleaseFromCheckout(stage, ["publish-update", "--release", sealed.sealed, "--platform", platform, "--tier", tier]); extra = { sealed: sealed.sealed, manifestSha256: sealed.manifestSha256, tier, route: "r2-local" };
2575
+ }
2552
2576
  else { ok = await rightRelease(stage, ["upload", "--release", sealed.sealed, "--platform", platform, "--tier", tier]); extra = { sealed: sealed.sealed, manifestSha256: sealed.manifestSha256, tier }; }
2553
2577
  }
2554
2578
  }
@@ -3705,12 +3729,27 @@ export const ROUTE_SCHEMA = "rightkit-gate.route/1";
3705
3729
  * protected publication job (GITHUB_ACTIONS with RIGHTKIT_PUBLISHER=github-environment); a mobile platform's store upload has its own tier-less route. Asked by a real
3706
3730
  * run before it takes ownership or syncs the snapshot (E2E L3-03); the probe has no release route, so this is not a probe code.
3707
3731
  */
3708
- export function releaseRouteRefusal(o, { stages, platform }) {
3732
+ export function releaseRouteRefusal(o, { stages, platform, sealedProvider = () => null }) {
3709
3733
  if (!stages.includes("release") || MOBILE_PLATFORMS.has(platform)) return null;
3710
3734
  if (o.env.GITHUB_ACTIONS === "true" && o.env.RIGHTKIT_PUBLISHER === "github-environment") return null;
3735
+ // rightkit#1754: an app whose sealed manifest declares r2-rightapps publishes from the host through publish-update; the release stage
3736
+ // re-reads the provider from the manifest bytes the receipt vouches for before anything is uploaded.
3737
+ if (sealedProvider() === "r2-rightapps") return null;
3711
3738
  return { code: "RK_RELEASE_PUBLISHER_ONLY", message: "--to release runs only in the trusted publisher (the release workflow's protected publication job). Run --to qualify on the native host, then dispatch the release workflow for the commit" };
3712
3739
  }
3713
3740
 
3741
+ /** The distribution provider a sealed set declares (`manifest.distribution.provider`), read from the manifest bytes whose sha256 is `sealed.digest`;
3742
+ * null for no sealed set, unreadable or changed bytes, or a manifest sealed before the field existed. */
3743
+ export function sealedProviderOf(sealed, { readFile = (f) => fs.readFileSync(f) } = {}) {
3744
+ if (!sealed?.manifest) return null;
3745
+ try {
3746
+ const bytes = readFile(sealed.manifest);
3747
+ if (createHash("sha256").update(bytes).digest("hex") !== sealed.digest) return null;
3748
+ const provider = JSON.parse(String(bytes)).distribution?.provider;
3749
+ return typeof provider === "string" ? provider : null;
3750
+ } catch { return null; }
3751
+ }
3752
+
3714
3753
  /**
3715
3754
  * Which route this host's door takes for `--to <stage>` and whether it refuses, WITHOUT running anything: the decisions of `runStages`
3716
3755
  * in the order it makes them. `runStages` takes its own pre-ownership route and refusal from this very function (rightkit#1297 L1), so
package/build-release.mjs CHANGED
@@ -942,6 +942,9 @@ function sealRelease({ configRoot, managedCargoTarget, artifactPaths = null, and
942
942
  // DevTools allowance (owner's fixed design): { mode: "denied" } for every app; content-only only for an allow-listed app.
943
943
  devtools: devtoolsEvidence(resolveDevtoolsAllowance({ config, root: configRoot })),
944
944
  platform,
945
+ // The app's distribution provider, sealed with the bytes (rightkit#1754): the door decides a desktop release's route from the verified sealed
946
+ // manifest (r2-rightapps may publish from a broker host; github-releases only from the trusted publisher), never by executing app code.
947
+ ...(typeof config.distribution?.provider === "string" ? { distribution: { provider: config.distribution.provider } } : {}),
945
948
  ...(mediaSidecars ? { mediaSidecars } : {}),
946
949
  cacheKey,
947
950
  // Portable contracts sign only raw executables — installer/embedding
@@ -823,9 +823,10 @@ export const FAILURE_UNCACHEABLE_INTERNAL = new Set(["ghsa-audit", "advisory-exc
823
823
  /** NN41: the key namespace of a cached failure, so a failure never shares a key with a pass of the same scan. */
824
824
  // /2: a broker-authenticated compile failure is stored only when its output shows compiler diagnostics and no tool or environment failure (a build-script tool panic is environmental; Dell pulse-hub, 2026-11-06).
825
825
  // /3 (2026-11-06): a missing system library (pkg-config, system-deps) is the host, not the inputs; failures stored under /2 may be one.
826
+ // /4 (2026-11-27): a dependency-resolution failure (the host's registry index lacks a version the lock names) is the host, not the inputs; failures stored under /3 may be one (Pulse Mac 97de4c70, rightkit-tauri-shell 0.8.11).
826
827
  /** planScans file digests by file identity (path, inode, size, mtime) for this process: one run plans its stages over the same snapshot. */
827
828
  const PLAN_DIGEST_MEMO = new Map();
828
- export const FAILURE_KEY_SCHEMA = "deterministic-failure/3";
829
+ export const FAILURE_KEY_SCHEMA = "deterministic-failure/4";
829
830
  /** NN23: the version of the internal (file-only) rules; bump when any internal rule's verdict for the same inputs changes. */
830
831
  export const INTERNAL_RULES_SCHEMA = "rightkit.internal-rules/1";
831
832
  /** Why a row's cache key moved, from the stored pass's key parts to this run's: the input entries that differ (paths and the like), the tool
@@ -909,7 +910,7 @@ export const isFailureCacheableCompileId = (id) => /^(?:check|check-features|che
909
910
  export function isDeterministicCompileDiagnostics(text) {
910
911
  const t = String(text ?? "");
911
912
  const diagnostics = /(?:^|\n)\s*error(?:\[[A-Za-z]\d+\])?: /.test(t) || /could not compile|aborting due to/.test(t);
912
- const environmental = /failed to (?:download|fetch|get|update|load source|create|write|open|remove)|network|spurious|timed out|No space left|Too many open files|Permission denied|Resource temporarily|Text file busy|internal compiler error|panicked at|pkg-config|PKG_CONFIG|system library|was not found in the pkg-config search path|Package [^\n]* was not found|linker `[^`]*` not found|unable to find library|cannot find -l|signal: |SIGKILL|SIGSEGV|Killed/i.test(t);
913
+ const environmental = /failed to (?:download|fetch|get|update|load source|create|write|open|remove)|network|spurious|timed out|No space left|Too many open files|Permission denied|Resource temporarily|Text file busy|internal compiler error|panicked at|pkg-config|PKG_CONFIG|system library|was not found in the pkg-config search path|Package [^\n]* was not found|linker `[^`]*` not found|unable to find library|cannot find -l|signal: |SIGKILL|SIGSEGV|Killed|failed to select a version for|no matching package named|location searched:|candidate versions found which didn't match/i.test(t);
913
914
  return diagnostics && !environmental;
914
915
  }
915
916
  export const isLiveScan = (id) => LIVE_SCAN_IDS.some((p) => id === p || String(id).startsWith(`${p}:`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rightkit/release",
3
- "version": "0.6.89",
3
+ "version": "0.6.90",
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",
@@ -13,7 +13,7 @@ import { defaultReleaseConfigFile, importReleaseConfig } from "./release-config.
13
13
  import { assertPrimaryReleaseCheckout } from "./release-invocation.mjs";
14
14
  import { assertCleanSource } from "./source-gate.mjs";
15
15
  import { verifyPublicationRelease, PublicationError, assertArtifactUnchanged, digestBytes } from "./publication-artifacts.mjs";
16
- import { uploadVerifiedR2Artifact } from "./r2-verified-upload.mjs";
16
+ import { putVerifiedR2Artifact } from "./r2-verified-upload.mjs";
17
17
  import { verifyPlatformTrust } from "./github-release.mjs";
18
18
  import { admitInstalledQa } from "./release-qa-audit.mjs";
19
19
  import { RIGHT_SUITE_API_ORIGIN, RIGHT_SUITE_GATED_ARTIFACT_HOST, RIGHT_SUITE_PUBLIC_INSTALLER_BASE } from "./suite-api.generated.mjs";
@@ -212,7 +212,7 @@ if (tier === "patch") {
212
212
  if (!appInstallerKind) artifactFile(artifact.signature);
213
213
  if (!uploadedKeys.has(installerKey)) {
214
214
  console.log(`${dryRun ? "[dry-run] " : ""}UPLOAD public/${installerKey}`);
215
- if (!dryRun) uploadVerifiedR2Artifact(verifiedArtifact(file), installerKey, "public", { cwd: root });
215
+ if (!dryRun) await putVerifiedR2Artifact(verifiedArtifact(file), installerKey, "public");
216
216
  uploadedKeys.add(installerKey);
217
217
  }
218
218
  const signature = dryRun ? `<signature:${artifact.signature ?? "msix-authenticode"}>` : signatureFor(artifact);
@@ -234,7 +234,7 @@ if (tier === "patch") {
234
234
  const file = artifactFile(installer.file);
235
235
  if (!uploadedKeys.has(installer.key)) {
236
236
  console.log(`${dryRun ? "[dry-run] " : ""}UPLOAD public/${installer.key}`);
237
- if (!dryRun) uploadVerifiedR2Artifact(verifiedArtifact(file), installer.key, "public", { cwd: root });
237
+ if (!dryRun) await putVerifiedR2Artifact(verifiedArtifact(file), installer.key, "public");
238
238
  uploadedKeys.add(installer.key);
239
239
  }
240
240
  const metadata = dryRun ? { sha256: null, sizeBytes: null } : await fileMetadata(file);
@@ -248,7 +248,7 @@ if (tier === "patch") {
248
248
  // package came from, so it must outlive the version that replaces it.
249
249
  if (installer.versionedKey && !uploadedKeys.has(installer.versionedKey)) {
250
250
  console.log(`${dryRun ? "[dry-run] " : ""}UPLOAD public/${installer.versionedKey}`);
251
- if (!dryRun) uploadVerifiedR2Artifact(verifiedArtifact(file), installer.versionedKey, "public", { cwd: root });
251
+ if (!dryRun) await putVerifiedR2Artifact(verifiedArtifact(file), installer.versionedKey, "public");
252
252
  uploadedKeys.add(installer.versionedKey);
253
253
  }
254
254
  }
@@ -317,7 +317,7 @@ for (const artifact of artifacts) {
317
317
  if (!appInstallerKind) artifactFile(artifact.signature);
318
318
  if (!uploadedKeys.has(artifact.key)) {
319
319
  console.log(`${dryRun ? "[dry-run] " : ""}UPLOAD private/${artifact.key}`);
320
- if (!dryRun) uploadVerifiedR2Artifact(verifiedArtifact(file), artifact.key, "private", { cwd: root });
320
+ if (!dryRun) await putVerifiedR2Artifact(verifiedArtifact(file), artifact.key, "private");
321
321
  uploadedKeys.add(artifact.key);
322
322
  }
323
323
  const signature = dryRun ? `<signature:${artifact.signature ?? "msix-authenticode"}>` : signatureFor(artifact);
@@ -170,6 +170,23 @@ export async function uploadMultipart({ file, evidence, bucket, key, credentials
170
170
  } finally { closeSync(fd); }
171
171
  }
172
172
 
173
+ /**
174
+ * Upload `body` (a Buffer below R2_MULTIPART_THRESHOLD_BYTES) to `bucket/key` in one signed PutObject. Its sha256 and size must equal `evidence`
175
+ * before anything is sent, so an object that does not match the evidence is never created; the caller still reads the remote bytes back with
176
+ * streamObjectDigest. This replaces `pnpm dlx wrangler r2 object put` on the publication path: no child process, no credential leaves this process,
177
+ * nothing is downloaded at publish time. Returns { sizeBytes }.
178
+ */
179
+ export async function putObject({ body, evidence, bucket, key, credentials, account, fetchImpl, sleep }) {
180
+ if (!Buffer.isBuffer(body)) throw new PublicationError("PUBLICATION_ROUTE_INVALID", "putObject takes the verified bytes as a Buffer");
181
+ if (body.length >= R2_MULTIPART_THRESHOLD_BYTES) throw new PublicationError("PUBLICATION_ROUTE_INVALID", `an object of ${body.length} bytes goes up as a multipart upload`);
182
+ if (evidence.sizeBytes !== undefined && body.length !== evidence.sizeBytes) throw new PublicationError("PUBLICATION_SIZE_MISMATCH", `artifact size mismatch: ${key}`);
183
+ const digest = sha256Hex(body);
184
+ if (digest !== evidence.sha256) throw new PublicationError("PUBLICATION_HASH_MISMATCH", `artifact sha256 mismatch: ${key}`);
185
+ const client = s3Client({ bucket, credentials, account, fetchImpl, sleep });
186
+ await client.send("PUT", key, { body, payloadHash: digest });
187
+ return { sizeBytes: body.length };
188
+ }
189
+
173
190
  /** One signed GetObject response (optionally `range: "bytes=N-"`): the body is streamed by the caller. Throws with the HTTP status only. */
174
191
  export async function getObject({ bucket, key, credentials, account, fetchImpl, sleep, range }) {
175
192
  const client = s3Client({ bucket, credentials, account, fetchImpl, sleep });
@@ -1,7 +1,46 @@
1
1
  import path from "node:path";
2
2
  import { spawnSync } from "./background-process.mjs";
3
- import { assertArtifactUnchanged, PublicationError, verifyArtifactFile } from "./publication-artifacts.mjs";
4
- import { deriveR2S3Credentials, R2_ACCOUNT_ID, R2_MULTIPART_THRESHOLD_BYTES, streamObjectDigest, uploadMultipart } from "./r2-s3-multipart.mjs";
3
+ import { assertArtifactUnchanged, PublicationError, readVerifiedArtifact, verifyArtifactFile } from "./publication-artifacts.mjs";
4
+ import { deriveR2S3Credentials, putObject, R2_ACCOUNT_ID, R2_MULTIPART_THRESHOLD_BYTES, streamObjectDigest, uploadMultipart } from "./r2-s3-multipart.mjs";
5
+
6
+ const validRoute = (key, bucket) => ["public", "private"].includes(bucket) && /^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(key ?? "") && !key.includes("..");
7
+
8
+ // One in-process transport for every object (rightkit#1754): no child process, so no credential is carried to a broker job (BROKER-CONTRACT D4)
9
+ // and nothing is downloaded at publish time. `bytes` (already verified) go up in one PutObject; without them the file goes up as a multipart
10
+ // upload. Either way the remote bytes are read back through a sha256 and a byte counter and must equal the evidence.
11
+ async function inProcessUpload({ file, bytes, artifact, key, bucket, env, fetchImpl, sleep }) {
12
+ const bucketName = bucket === "public" ? "rightapps-downloads" : "rightapps-updates";
13
+ const target = `${bucketName}/${key}`;
14
+ const cleanEnv = { ...env, CLOUDFLARE_ACCOUNT_ID: env.CLOUDFLARE_ACCOUNT_ID || R2_ACCOUNT_ID };
15
+ for (const name of ["CLOUDFLARE_API_KEY", "CLOUDFLARE_EMAIL", "CF_API_KEY", "CF_EMAIL"]) delete cleanEnv[name];
16
+ const credentials = await deriveR2S3Credentials(cleanEnv.CLOUDFLARE_API_TOKEN, { account: cleanEnv.CLOUDFLARE_ACCOUNT_ID, fetchImpl });
17
+ const transport = { bucket: bucketName, key, credentials, account: cleanEnv.CLOUDFLARE_ACCOUNT_ID, fetchImpl, sleep };
18
+ try {
19
+ if (bytes) await putObject({ body: bytes, evidence: artifact, ...transport });
20
+ else await uploadMultipart({ file: path.resolve(file), evidence: artifact, ...transport });
21
+ } catch (error) {
22
+ if (error instanceof PublicationError && error.code !== "PUBLICATION_UPLOAD_FAILED") throw error;
23
+ throw new PublicationError("PUBLICATION_UPLOAD_FAILED", `R2 upload failed (${error.message}); inspect remote key ${target}`);
24
+ }
25
+ try {
26
+ const remote = await streamObjectDigest(transport);
27
+ if (remote.sha256 !== artifact.sha256) throw new Error("remote sha256 differs from the evidence");
28
+ if (remote.sizeBytes !== artifact.sizeBytes) throw new Error(`remote size ${remote.sizeBytes} differs from ${artifact.sizeBytes}`);
29
+ } catch (error) {
30
+ throw new PublicationError("PUBLICATION_REMOTE_MISMATCH", `R2 verification failed (${error.message}); remove remote key ${target}`);
31
+ }
32
+ }
33
+
34
+ /**
35
+ * The publication path's upload of one verified artifact (publish-update): the bytes read and hashed at verification go up in process and are
36
+ * read back. An artifact at or above R2_MULTIPART_THRESHOLD_BYTES goes up from its file as a multipart upload after the file is checked unchanged.
37
+ */
38
+ export async function putVerifiedR2Artifact(artifact, key, bucket, { env = process.env, fetchImpl, sleep } = {}) {
39
+ if (!validRoute(key, bucket)) throw new PublicationError("PUBLICATION_ROUTE_INVALID", "invalid R2 publication route");
40
+ const bytes = assertArtifactUnchanged(artifact);
41
+ await inProcessUpload({ file: artifact.file, bytes: bytes.length < R2_MULTIPART_THRESHOLD_BYTES ? bytes : null, artifact, key, bucket, env, fetchImpl, sleep });
42
+ return artifact;
43
+ }
5
44
 
6
45
  // Wrangler's pipe input transports the verified buffer, with no path lookup by its child.
7
46
  export function uploadVerifiedR2Artifact(artifact, key, bucket, { run = spawnSync, env = process.env, cwd } = {}) {
@@ -16,38 +55,17 @@ export function uploadVerifiedR2Artifact(artifact, key, bucket, { run = spawnSyn
16
55
  }
17
56
 
18
57
  // Path-only large-file transport: success requires remote bytes matching captured evidence. Objects below R2_MULTIPART_THRESHOLD_BYTES go up in
19
- // one wrangler request; larger ones (wrangler stops at 300 MiB) go through the S3-compatible endpoint as a multipart upload (r2-s3-multipart.mjs,
20
- // #902). Either way the readback streams GetObject through a sha256 and a byte counter, because `wrangler r2 object get` aborts mid-stream on
21
- // large objects (docs/rules/cloudflare-access.md Rule 6). The S3 credentials are derived in memory from CLOUDFLARE_API_TOKEN and never printed.
58
+ // one PutObject; larger ones go up as a multipart upload (r2-s3-multipart.mjs, #902), both through the S3-compatible endpoint in this process
59
+ // (rightkit#1754: wrangler, a child process, is off this path). Either way the readback streams GetObject through a sha256 and a byte counter
60
+ // (docs/rules/cloudflare-access.md Rule 6). The S3 credentials are derived in memory from CLOUDFLARE_API_TOKEN and never printed.
22
61
  // The order the callers keep is immutable object -> signed envelope -> pointer, and a readback that differs from the evidence is
23
62
  // PUBLICATION_REMOTE_MISMATCH.
24
63
  export async function uploadVerifiedR2File(file, evidence, key, bucket, { run = spawnSync, env = process.env, cwd, dryRun = false, fetchImpl, sleep } = {}) {
25
64
  if (!["public", "private"].includes(bucket) || !/^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(key ?? "") || key.includes("..")) throw new PublicationError("PUBLICATION_ROUTE_INVALID", "invalid R2 publication route");
26
65
  const artifact = verifyArtifactFile(file, evidence);
27
66
  if (dryRun) return artifact;
28
- const bucketName = bucket === "public" ? "rightapps-downloads" : "rightapps-updates";
29
- const target = `${bucketName}/${key}`;
30
- const cleanEnv = { ...env, CLOUDFLARE_ACCOUNT_ID: env.CLOUDFLARE_ACCOUNT_ID || R2_ACCOUNT_ID };
31
- for (const name of ["CLOUDFLARE_API_KEY", "CLOUDFLARE_EMAIL", "CF_API_KEY", "CF_EMAIL"]) delete cleanEnv[name];
32
- const credentials = await deriveR2S3Credentials(cleanEnv.CLOUDFLARE_API_TOKEN, { account: cleanEnv.CLOUDFLARE_ACCOUNT_ID, fetchImpl });
33
- const transport = { bucket: bucketName, key, credentials, account: cleanEnv.CLOUDFLARE_ACCOUNT_ID, fetchImpl, sleep };
34
- if (artifact.sizeBytes >= R2_MULTIPART_THRESHOLD_BYTES) {
35
- try { await uploadMultipart({ file: path.resolve(file), evidence: artifact, ...transport }); }
36
- catch (error) {
37
- if (error instanceof PublicationError && error.code !== "PUBLICATION_UPLOAD_FAILED") throw error;
38
- throw new PublicationError("PUBLICATION_UPLOAD_FAILED", `R2 multipart upload failed (${error.message}); inspect remote key ${target}`);
39
- }
40
- } else {
41
- const options = { cwd, env: cleanEnv, windowsHide: true, shell: process.platform === "win32", encoding: "utf8" };
42
- const result = run("pnpm", ["dlx", "wrangler@4", "r2", "object", "put", target, "--file", path.resolve(file), "--remote"], { ...options, stdio: "inherit" });
43
- if (result.error || result.status !== 0) throw new PublicationError("PUBLICATION_UPLOAD_FAILED", `R2 upload failed; inspect remote key ${target}`);
44
- }
45
- try {
46
- const remote = await streamObjectDigest(transport);
47
- if (remote.sha256 !== artifact.sha256) throw new Error("remote sha256 differs from the evidence");
48
- if (remote.sizeBytes !== artifact.sizeBytes) throw new Error(`remote size ${remote.sizeBytes} differs from ${artifact.sizeBytes}`);
49
- } catch (error) {
50
- throw new PublicationError("PUBLICATION_REMOTE_MISMATCH", `R2 verification failed (${error.message}); remove remote key ${target}`);
51
- }
67
+ // Below the multipart threshold the bytes are read once and verified again, then go up in one PutObject; above it the file goes up multipart.
68
+ const bytes = artifact.sizeBytes < R2_MULTIPART_THRESHOLD_BYTES ? readVerifiedArtifact(file, evidence).bytes : null;
69
+ await inProcessUpload({ file, bytes, artifact, key, bucket, env, fetchImpl, sleep });
52
70
  return artifact;
53
71
  }
@@ -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.89",
52
+ "@rightkit/release": "0.6.90",
53
53
  "@rightkit/send-ui": "0.1.0",
54
54
  "@rightkit/settings-ui": "0.7.7",
55
55
  "@rightkit/social-ui": "0.2.1",
@@ -455,7 +455,8 @@
455
455
  "0.6.85",
456
456
  "0.6.86",
457
457
  "0.6.87",
458
- "0.6.88"
458
+ "0.6.88",
459
+ "0.6.89"
459
460
  ],
460
461
  "@rightkit/settings-ui": [
461
462
  "0.1.0",
@@ -583,7 +584,7 @@
583
584
  "rightkit-agent-tools": "0.4.4",
584
585
  "rightkit-agent-transcript": "0.1.4",
585
586
  "rightkit-agents": "0.2.8",
586
- "rightkit-ai-accounts": "0.1.3",
587
+ "rightkit-ai-accounts": "0.1.4",
587
588
  "rightkit-ai-keys": "0.1.1",
588
589
  "rightkit-android": "0.3.3",
589
590
  "rightkit-app-host": "0.1.3",
@@ -732,7 +733,7 @@
732
733
  "rightkit-profile": "0.1.0",
733
734
  "rightkit-prompt-recipes": "0.2.1",
734
735
  "rightkit-pty": "0.1.3",
735
- "rightkit-qa": "0.10.15",
736
+ "rightkit-qa": "0.10.16",
736
737
  "rightkit-record": "0.4.1",
737
738
  "rightkit-reframe": "0.2.1",
738
739
  "rightkit-remote-compute": "0.2.2",
@@ -758,8 +759,8 @@
758
759
  "rightkit-sync-keys": "0.1.0",
759
760
  "rightkit-sysmem": "0.1.0",
760
761
  "rightkit-system-monitor": "0.3.2",
761
- "rightkit-tauri-shell": "0.8.10",
762
- "rightkit-terminal-ui": "0.1.9",
762
+ "rightkit-tauri-shell": "0.8.11",
763
+ "rightkit-terminal-ui": "0.2.0",
763
764
  "rightkit-text-polish": "0.1.4",
764
765
  "rightkit-theme": "0.1.1",
765
766
  "rightkit-time": "0.1.5",
@@ -923,7 +924,7 @@
923
924
  "@rightkit/qa": "0.7.0",
924
925
  "@rightkit/qa-chrome": "0.1.12",
925
926
  "@rightkit/react-shell": "0.7.7",
926
- "@rightkit/release": "0.6.88",
927
+ "@rightkit/release": "0.6.89",
927
928
  "@rightkit/settings-ui": "0.7.4",
928
929
  "@rightkit/shell": "0.1.1",
929
930
  "@rightkit/tauri": "0.4.3",
@@ -977,7 +978,8 @@
977
978
  ],
978
979
  "rightkit-ai-accounts": [
979
980
  "0.1.1",
980
- "0.1.2"
981
+ "0.1.2",
982
+ "0.1.3"
981
983
  ],
982
984
  "rightkit-ai-keys": [
983
985
  "0.1.0"
@@ -1539,7 +1541,8 @@
1539
1541
  "0.10.11",
1540
1542
  "0.10.12",
1541
1543
  "0.10.13",
1542
- "0.10.14"
1544
+ "0.10.14",
1545
+ "0.10.15"
1543
1546
  ],
1544
1547
  "rightkit-qa-driver": [
1545
1548
  "0.3.0",
@@ -1678,7 +1681,8 @@
1678
1681
  "0.6.0",
1679
1682
  "0.8.2",
1680
1683
  "0.8.7",
1681
- "0.8.9"
1684
+ "0.8.9",
1685
+ "0.8.10"
1682
1686
  ],
1683
1687
  "rightkit-text-polish": [
1684
1688
  "0.1.1",
@@ -1902,7 +1906,8 @@
1902
1906
  "0.1.5",
1903
1907
  "0.1.6",
1904
1908
  "0.1.7",
1905
- "0.1.8"
1909
+ "0.1.8",
1910
+ "0.1.9"
1906
1911
  ],
1907
1912
  "rightkit-timeline": [
1908
1913
  "0.1.1"