@adea-ai/app-framework 0.39.3 → 0.40.0

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 (199) hide show
  1. package/README.md +160 -53
  2. package/dist/app/application.d.ts +0 -1
  3. package/dist/app/application.js +8 -6
  4. package/dist/app/create-application.js +3 -11
  5. package/dist/app/service-registry.d.ts +0 -1
  6. package/dist/app/service-registry.js +3 -3
  7. package/dist/app/value-guards.d.ts +2 -0
  8. package/dist/app/value-guards.js +6 -1
  9. package/dist/appearance/appearance-host.d.ts +1 -1
  10. package/dist/appearance/appearance-host.js +11 -2
  11. package/dist/appearance/appearance-preferences.d.ts +0 -1
  12. package/dist/appearance/custom-theme-import.d.ts +8 -2
  13. package/dist/appearance/custom-theme-import.js +58 -23
  14. package/dist/appearance/custom-theme-library.d.ts +3 -3
  15. package/dist/appearance/custom-theme-library.js +3 -3
  16. package/dist/appearance/theme-file-importer.d.ts +1 -1
  17. package/dist/appearance/theme-file-importer.js +2 -1
  18. package/dist/appearance/theme-library-mutation.d.ts +7 -0
  19. package/dist/appearance/theme-library-mutation.js +10 -2
  20. package/dist/appearance/theme-library-store.d.ts +17 -13
  21. package/dist/appearance/theme-library-store.js +35 -22
  22. package/dist/appearance/theme-record-adapter.js +1 -2
  23. package/dist/appearance/theme-registry.js +0 -1
  24. package/dist/cli/cli-runner.d.ts +3 -2
  25. package/dist/cli/cli-runner.js +5 -10
  26. package/dist/cli/release-assets-plan-cli.js +2 -2
  27. package/dist/cli/release-cut-cli.js +2 -3
  28. package/dist/cli/release-descriptor-staging-cli.js +2 -2
  29. package/dist/cli/release-finalize-cli.js +3 -3
  30. package/dist/cli/release-promote-cli.js +2 -2
  31. package/dist/cli/release-publish-cli.js +2 -2
  32. package/dist/cli/release-sign-cli.js +2 -1
  33. package/dist/cli/release-step-cli.js +2 -2
  34. package/dist/desktop/channel-proof.js +27 -11
  35. package/dist/desktop/client-assets.d.ts +6 -1
  36. package/dist/desktop/client-assets.js +16 -3
  37. package/dist/desktop/client-dev-proxy.d.ts +0 -2
  38. package/dist/desktop/client-dev-proxy.js +2 -2
  39. package/dist/desktop/desktop-client.js +2 -1
  40. package/dist/desktop/desktop-gateway.js +24 -82
  41. package/dist/desktop/desktop-host-websocket.d.ts +5 -1
  42. package/dist/desktop/desktop-host-websocket.js +9 -7
  43. package/dist/desktop/desktop-host.d.ts +5 -0
  44. package/dist/desktop/desktop-host.js +3 -0
  45. package/dist/desktop/desktop-stream.js +5 -10
  46. package/dist/desktop/typed-array-intrinsics.d.ts +6 -0
  47. package/dist/desktop/typed-array-intrinsics.js +13 -1
  48. package/dist/developer-app/developer-app.d.ts +1 -1
  49. package/dist/developer-app/developer-app.js +26 -13
  50. package/dist/framework-source.json +1 -1
  51. package/dist/installer/command-artifact.d.ts +1 -0
  52. package/dist/installer/command-artifact.js +47 -27
  53. package/dist/installer/installed-payload.js +3 -1
  54. package/dist/installer/installer-ci-bootstrap.js +5 -6
  55. package/dist/installer/installer-ci-preflight.js +3 -3
  56. package/dist/installer/installer-identity.d.ts +0 -22
  57. package/dist/installer/installer-identity.js +3 -53
  58. package/dist/installer/installer-image-mount.d.ts +0 -1
  59. package/dist/installer/installer-image-mount.js +1 -1
  60. package/dist/installer/installer-observation.d.ts +5 -5
  61. package/dist/installer/installer-observation.js +32 -47
  62. package/dist/installer/installer-process-cleanup.js +2 -2
  63. package/dist/installer/installer-renderer-evidence.js +7 -28
  64. package/dist/installer/installer-upgrade-command.js +8 -20
  65. package/dist/installer/installer-worker-guard.js +3 -3
  66. package/dist/native/cef-helper.js +4 -4
  67. package/dist/native/desktop-build.d.ts +0 -3
  68. package/dist/native/desktop-build.js +2 -2
  69. package/dist/native/electrobun-source-patch.d.ts +4 -0
  70. package/dist/native/electrobun-source-patch.js +5 -1
  71. package/dist/native/native-utilities.js +4 -3
  72. package/dist/native/pinned-download.d.ts +16 -0
  73. package/dist/native/pinned-download.js +42 -0
  74. package/dist/native/posix-launcher-build.js +15 -35
  75. package/dist/native/posix-tree-removal.js +21 -33
  76. package/dist/native/sidecar-services.d.ts +0 -2
  77. package/dist/native/sidecar-services.js +1 -1
  78. package/dist/native/sidecar.d.ts +3 -0
  79. package/dist/native/sidecar.js +15 -2
  80. package/dist/native/window-surface-store.js +3 -3
  81. package/dist/native/windows-extractor-build.d.ts +6 -16
  82. package/dist/native/windows-extractor-build.js +11 -14
  83. package/dist/release/feed-release-cut.d.ts +2 -6
  84. package/dist/release/feed-release-cut.js +5 -93
  85. package/dist/release/feed-state.js +1 -5
  86. package/dist/release/github-release-cut.js +5 -66
  87. package/dist/release/github-release-provenance.d.ts +2 -0
  88. package/dist/release/github-release-provenance.js +4 -7
  89. package/dist/release/github-release-publisher.js +2 -2
  90. package/dist/release/github-release-qualification.js +3 -3
  91. package/dist/release/local-release.d.ts +3 -3
  92. package/dist/release/local-release.js +12 -23
  93. package/dist/release/qualification-run.js +1 -1
  94. package/dist/release/release-assets-plan.js +1 -1
  95. package/dist/release/release-config.d.ts +7 -15
  96. package/dist/release/release-config.js +25 -29
  97. package/dist/release/release-cut-command.d.ts +1 -1
  98. package/dist/release/release-cut-command.js +1 -1
  99. package/dist/release/release-cut.d.ts +5 -32
  100. package/dist/release/release-cut.js +9 -55
  101. package/dist/release/release-descriptor-staging.js +3 -8
  102. package/dist/release/release-promotion.js +2 -1
  103. package/dist/release/release-publish-command.js +5 -15
  104. package/dist/release/release-qualification.js +1 -1
  105. package/dist/shared/bounded-body.d.ts +33 -0
  106. package/dist/shared/bounded-body.js +102 -0
  107. package/dist/shared/file-system.d.ts +12 -0
  108. package/dist/shared/file-system.js +40 -0
  109. package/dist/shell/app-shell.js +29 -14
  110. package/dist/shell/app-utilities.d.ts +4 -1
  111. package/dist/shell/app-utilities.js +5 -1
  112. package/dist/shell/application-menu.d.ts +1 -1
  113. package/dist/shell/application-menu.js +7 -3
  114. package/dist/shell/poll.d.ts +27 -0
  115. package/dist/shell/poll.js +88 -0
  116. package/dist/update-helper.bundle.js +268 -144
  117. package/dist/updates/channel-update-manager.js +0 -1
  118. package/dist/updates/desktop-updater.d.ts +9 -0
  119. package/dist/updates/desktop-updater.js +103 -50
  120. package/dist/updates/feed/release-feed.d.ts +7 -4
  121. package/dist/updates/feed/release-feed.js +3 -7
  122. package/dist/updates/feed/release-location.js +6 -26
  123. package/dist/updates/feed/release-version.d.ts +7 -2
  124. package/dist/updates/feed/release-version.js +9 -2
  125. package/dist/updates/feed/signed-release.d.ts +1 -1
  126. package/dist/updates/feed/signed-release.js +2 -2
  127. package/dist/updates/feed/update-discovery.js +2 -6
  128. package/dist/updates/helper/launch-gate-recovery.js +28 -78
  129. package/dist/updates/helper/resume-staging.d.ts +14 -3
  130. package/dist/updates/helper/resume-staging.js +23 -37
  131. package/dist/updates/helper/update-helper.d.ts +6 -2
  132. package/dist/updates/helper/update-helper.js +38 -33
  133. package/dist/updates/helper/update-resume.js +9 -6
  134. package/dist/updates/install/update-extraction.js +28 -8
  135. package/dist/updates/install/update-handoff-plan.d.ts +0 -1
  136. package/dist/updates/install/update-handoff-plan.js +3 -4
  137. package/dist/updates/install/update-swap-stage.js +1 -6
  138. package/dist/updates/install/update-swap.d.ts +5 -2
  139. package/dist/updates/install/update-swap.js +193 -72
  140. package/dist/updates/launch/helper-exit-wait.d.ts +6 -0
  141. package/dist/updates/launch/helper-exit-wait.js +18 -0
  142. package/dist/updates/launch/packaged-update-startup.js +8 -6
  143. package/dist/updates/launch/update-launch-gate.js +7 -14
  144. package/dist/updates/locks/stable-file.js +4 -1
  145. package/dist/updates/locks/update-helper-presence.d.ts +12 -0
  146. package/dist/updates/locks/update-helper-presence.js +27 -0
  147. package/dist/updates/retention/retention-cleanup.js +10 -9
  148. package/dist/updates/retention/retention-maintenance.d.ts +40 -0
  149. package/dist/updates/retention/retention-maintenance.js +95 -0
  150. package/dist/updates/retention/retention-prune-progress.js +4 -5
  151. package/dist/updates/retention/retirement-inventory.d.ts +13 -0
  152. package/dist/updates/retention/retirement-inventory.js +39 -31
  153. package/dist/updates/retention/retirement-records.d.ts +1 -4
  154. package/dist/updates/retention/retirement-records.js +18 -32
  155. package/dist/updates/retention/update-retention-marker.d.ts +4 -0
  156. package/dist/updates/retention/update-retention-marker.js +9 -14
  157. package/dist/updates/retention/update-retirement.d.ts +12 -0
  158. package/dist/updates/retention/update-retirement.js +59 -31
  159. package/dist/updates/update-adapter.d.ts +1 -23
  160. package/dist/updates/update-adapter.js +31 -24
  161. package/dist/updates/update-channel-store.d.ts +2 -1
  162. package/dist/updates/update-channel-store.js +6 -4
  163. package/dist/updates/update-manager.js +2 -2
  164. package/dist/updates/update-services.d.ts +1 -1
  165. package/dist/updates/update-services.js +9 -4
  166. package/dist/updates/update-state-store.d.ts +0 -2
  167. package/dist/updates/update-state-store.js +5 -12
  168. package/dist/updates/update-state.d.ts +6 -10
  169. package/dist/updates/update-state.js +1 -1
  170. package/dist/views/app-help.d.ts +1 -1
  171. package/dist/views/app-help.js +1 -3
  172. package/dist/views/appearance-surface.js +15 -8
  173. package/dist/views/update-surface.d.ts +1 -3
  174. package/dist/views/update-surface.js +2 -2
  175. package/package.json +20 -18
  176. package/src/app/application.tsx +13 -6
  177. package/src/appearance/appearance-host.tsx +17 -7
  178. package/src/appearance/appearance-preferences.ts +0 -1
  179. package/src/appearance/custom-theme-import.ts +99 -26
  180. package/src/appearance/custom-theme-library.ts +3 -2
  181. package/src/appearance/theme-file-importer.ts +3 -2
  182. package/src/appearance/theme-library-mutation.ts +20 -8
  183. package/src/appearance/theme-library-schema.ts +7 -0
  184. package/src/appearance/theme-library-store.ts +41 -26
  185. package/src/desktop/client-assets.ts +27 -12
  186. package/src/shell/app-shell.tsx +33 -13
  187. package/src/shell/app-utilities.tsx +10 -1
  188. package/src/shell/poll.ts +125 -0
  189. package/src/updates/feed/release-version.ts +11 -3
  190. package/src/updates/update-adapter.ts +27 -44
  191. package/src/updates/update-state.ts +7 -13
  192. package/src/views/app-help.tsx +1 -1
  193. package/src/views/appearance-surface.tsx +36 -8
  194. package/src/views/update-surface.tsx +0 -4
  195. package/templates/application/.github/workflows/release-assets.yml +2 -2
  196. package/templates/application/README.md +3 -3
  197. package/dist/native/cef-helper-download.d.ts +0 -1
  198. package/dist/native/cef-helper-download.js +0 -35
  199. package/src/desktop/client-response-lifecycle.ts +0 -305
@@ -216,9 +216,18 @@ async function runDeveloperApp(config, options = {}) {
216
216
  child.on("exit", () => children.delete(child));
217
217
  return child;
218
218
  };
219
+ let stopping = false;
219
220
  const shutdown = (code) => {
220
- for (const child of children) stopGroup(child);
221
- process.exit(code);
221
+ if (stopping) return;
222
+ stopping = true;
223
+ let running = children.size;
224
+ if (running === 0) process.exit(code);
225
+ for (const child of children) {
226
+ child.once("exit", () => {
227
+ if (--running === 0) process.exit(code);
228
+ });
229
+ stopGroupWithin(child);
230
+ }
222
231
  };
223
232
  process.on("SIGINT", () => shutdown(0));
224
233
  process.on("SIGTERM", () => shutdown(0));
@@ -234,17 +243,19 @@ async function runDeveloperApp(config, options = {}) {
234
243
  shutdown(code ?? 1);
235
244
  });
236
245
  const origin = `http://127.0.0.1:${config.ui.port}`;
237
- log("developer app: starting the UI dev server…");
238
- for (;;) {
239
- try {
240
- const response = await fetch(origin + "/", { signal: AbortSignal.timeout(2e3) });
241
- await response.body?.cancel();
242
- if (response.status < 500) break;
243
- } catch {}
244
- await new Promise((done) => setTimeout(done, 100));
245
- }
246
- await Promise.all((config.ui.warm ?? []).map((path) => fetch(origin + path, { signal: AbortSignal.timeout(12e4) }).then((response) => response.arrayBuffer()).catch(() => void 0)));
247
- log(`developer app: UI on ${origin} (hot reload); starting ${identity.name}`);
246
+ log(`developer app: starting the UI dev server and ${identity.name} together…`);
247
+ const uiReady = (async () => {
248
+ for (;;) {
249
+ try {
250
+ const response = await fetch(origin + "/", { signal: AbortSignal.timeout(2e3) });
251
+ await response.body?.cancel();
252
+ if (response.status < 500) break;
253
+ } catch {}
254
+ await new Promise((done) => setTimeout(done, 100));
255
+ }
256
+ await Promise.all((config.ui.warm ?? []).map((path) => fetch(origin + path, { signal: AbortSignal.timeout(12e4) }).then((response) => response.arrayBuffer()).catch(() => void 0)));
257
+ log(`developer app: UI on ${origin} (hot reload)`);
258
+ })();
248
259
  let shell;
249
260
  let restarting = false;
250
261
  const shellEnv = developerAppShellEnv(config);
@@ -271,6 +282,7 @@ async function runDeveloperApp(config, options = {}) {
271
282
  restarting = true;
272
283
  running.once("exit", () => {
273
284
  restarting = false;
285
+ if (stopping) return;
274
286
  startShell();
275
287
  started();
276
288
  });
@@ -279,6 +291,7 @@ async function runDeveloperApp(config, options = {}) {
279
291
  });
280
292
  for (const folder of config.watch ?? ["src"]) watch(join(config.shellDirectory, folder), { recursive: true }, (_event, file) => onChange(file ? String(file) : null));
281
293
  startShell();
294
+ await uiReady;
282
295
  return new Promise(() => {});
283
296
  }
284
297
  var quote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
@@ -1 +1 @@
1
- {"version":"0.39.3","commit":"40dae0c01efd4e361693b913d2e525b9e84b40e9"}
1
+ {"version":"0.40.0","commit":"78c0ab11d4263006947a1a45a9c4156d1e53e66a"}
@@ -52,4 +52,5 @@ export declare function qualifyCommandArtifact(options: {
52
52
  version: string;
53
53
  env: Record<string, string | undefined>;
54
54
  settleMs?: number;
55
+ outputDrainMs?: number;
55
56
  }): Promise<CommandQualification>;
@@ -10,6 +10,7 @@ var MAX_ENTRIES = 1e5;
10
10
  var MAX_EXPANDED_BYTES = 2147483648;
11
11
  var MAX_ARCHIVE_BYTES = 1073741824;
12
12
  var COMMAND_TIMEOUT_MS = 6e4;
13
+ var OUTPUT_DRAIN_MS = 1e3;
13
14
  var SERVICE_SETTLE_MS = 5e3;
14
15
  var SERVICE_STOP_MS = 3e4;
15
16
  /** The archive's one root directory: the asset name without `.tar.gz`. */
@@ -114,12 +115,22 @@ async function readCommandArtifact(options) {
114
115
  bytes
115
116
  };
116
117
  }
117
- async function boundedText(stream, maximum) {
118
+ /** Read a pipe until it closes or `stop` aborts; a stopped read keeps what arrived. */
119
+ async function boundedText(stream, maximum, stop) {
118
120
  const chunks = [];
119
121
  let size = 0;
120
- for await (const chunk of stream) {
121
- size += chunk.length;
122
- if (size <= maximum) chunks.push(chunk);
122
+ const reader = stream.getReader();
123
+ const cancel = () => void reader.cancel().catch(() => void 0);
124
+ stop.addEventListener("abort", cancel, { once: true });
125
+ try {
126
+ for (;;) {
127
+ const { done, value } = await reader.read();
128
+ if (done) break;
129
+ size += value.length;
130
+ if (size <= maximum) chunks.push(value);
131
+ }
132
+ } finally {
133
+ stop.removeEventListener("abort", cancel);
123
134
  }
124
135
  return size > maximum ? void 0 : Buffer.concat(chunks).toString("utf8");
125
136
  }
@@ -284,18 +295,24 @@ async function qualifyCommandArtifact(options) {
284
295
  });
285
296
  const runOnce = async (args) => {
286
297
  const child = spawn(args, "pipe");
287
- const stdout = boundedText(child.stdout, 65536);
288
- const stderr = boundedText(child.stderr, 65536);
298
+ const drained = new AbortController();
299
+ const stdout = boundedText(child.stdout, 65536, drained.signal);
300
+ const stderr = boundedText(child.stderr, 65536, drained.signal);
289
301
  const status = await exitedWithin(child, COMMAND_TIMEOUT_MS);
290
302
  if (status === void 0) {
291
303
  child.kill("SIGKILL");
292
304
  await child.exited;
293
305
  }
294
- const [text] = await Promise.all([stdout, stderr]);
295
- return {
296
- status,
297
- text
298
- };
306
+ const timer = setTimeout(() => drained.abort(), options.outputDrainMs ?? OUTPUT_DRAIN_MS);
307
+ try {
308
+ const [text] = await Promise.all([stdout, stderr]);
309
+ return {
310
+ status,
311
+ text
312
+ };
313
+ } finally {
314
+ clearTimeout(timer);
315
+ }
299
316
  };
300
317
  const reported = await runOnce(["--version"]);
301
318
  if (reported.status !== 0 || reported.text?.trim() !== version) throw new Error("Command artifact version mismatch");
@@ -344,24 +361,27 @@ async function qualifyCommandArtifact(options) {
344
361
  serviceStopped: windows ? "process-tree" : "sigterm"
345
362
  };
346
363
  } finally {
347
- if (service) {
348
- if (windows) {
349
- try {
350
- service.kill("SIGKILL");
351
- } catch {}
352
- await exitedWithin(service, SERVICE_STOP_MS);
353
- } else {
354
- if (!unixGroupKilled) signalProcessGroup(service.pid, "SIGKILL");
355
- await exitedWithin(service, SERVICE_STOP_MS);
356
- if (!await processGroupExited(service.pid, SERVICE_STOP_MS)) cleanupFailure = "Command artifact service process tree did not stop";
364
+ try {
365
+ if (service) {
366
+ if (windows) {
367
+ try {
368
+ service.kill("SIGKILL");
369
+ } catch {}
370
+ await exitedWithin(service, SERVICE_STOP_MS);
371
+ } else {
372
+ if (!unixGroupKilled) signalProcessGroup(service.pid, "SIGKILL");
373
+ await exitedWithin(service, SERVICE_STOP_MS);
374
+ if (!await processGroupExited(service.pid, SERVICE_STOP_MS)) cleanupFailure = "Command artifact service process tree did not stop";
375
+ }
357
376
  }
377
+ } finally {
378
+ await rm(location, {
379
+ recursive: true,
380
+ force: true,
381
+ maxRetries: 5,
382
+ retryDelay: 200
383
+ });
358
384
  }
359
- await rm(location, {
360
- recursive: true,
361
- force: true,
362
- maxRetries: 5,
363
- retryDelay: 200
364
- });
365
385
  }
366
386
  if (cleanupFailure) throw new Error(cleanupFailure);
367
387
  if (!qualification) throw new Error("Command artifact qualification did not complete");
@@ -119,10 +119,12 @@ async function readMembers(archive, limits, collect) {
119
119
  }
120
120
  });
121
121
  const ended = once(parser, "end");
122
+ ended.catch(() => void 0);
122
123
  const file = await open(archive, "r");
123
124
  try {
124
125
  const input = file.createReadStream({ autoClose: false }), inflate = createZstdDecompress();
125
126
  input.on("error", (error) => inflate.destroy(error));
127
+ parser.on("error", (error) => inflate.destroy(error));
126
128
  for await (const chunk of input.pipe(inflate)) if (!parser.write(chunk)) await once(parser, "drain");
127
129
  parser.end();
128
130
  await ended;
@@ -155,7 +157,7 @@ async function verifyInstalledPayload(options) {
155
157
  assertInstallerContext(env, options.platform, process.platform, process.arch);
156
158
  assertPortableAppName(options.appName);
157
159
  const sidecars = assertSidecarNames(options.sidecars ?? [], options.platform).map((name) => sidecarBundlePath(name, options.platform));
158
- if (!/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(options.version) || options.version.length > 64) throw new Error("Invalid installed version");
160
+ if (!/^\d+\.\d+\.\d+$/.test(options.version) || options.version.length > 64) throw new Error("Invalid installed version");
159
161
  const profile = await realpath(options.profile), root = await realpath(options.installedRoot), archive = resolve(options.archive);
160
162
  if (!(await lstat(profile)).isDirectory() || !(await lstat(root)).isDirectory() || !isWithin(profile, root)) throw new Error("Installed root escapes isolated profile");
161
163
  const { archiveInfo, entries } = await listArchive(archive, options.platform, env);
@@ -1,6 +1,7 @@
1
1
  import { errorCode } from "../app/value-guards.js";
2
2
  import { isHostedRunner, runnerTemp } from "./hosted-runner.js";
3
- import { lstat, mkdir, mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";
3
+ import { readBoundedFile } from "../shared/file-system.js";
4
+ import { lstat, mkdir, mkdtemp, realpath, rm, writeFile } from "node:fs/promises";
4
5
  import { dirname, isAbsolute, join, relative, sep } from "node:path";
5
6
  import { randomBytes } from "node:crypto";
6
7
  import { fileURLToPath } from "node:url";
@@ -16,7 +17,8 @@ var bootstrapModules = [
16
17
  "installer/hosted-runner.js",
17
18
  "release/release-qualification.js",
18
19
  "desktop/string-policy.js",
19
- "shared/discard-stream.js"
20
+ "shared/discard-stream.js",
21
+ "shared/bounded-body.js"
20
22
  ];
21
23
  /** Copy a bounded external preload into the current disposable runner's temp directory. */
22
24
  async function prepareInstallerCiBootstrap(env = process.env) {
@@ -28,10 +30,7 @@ async function prepareInstallerCiBootstrap(env = process.env) {
28
30
  const directory = await mkdtemp(join(parent, "framework-ci-"));
29
31
  try {
30
32
  for (const name of bootstrapModules) {
31
- const file = join(source, name), info = await lstat(file);
32
- if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > 2097152) throw new Error("Invalid installer bootstrap module");
33
- const contents = await readFile(file);
34
- if (contents.length !== info.size) throw new Error("Installer bootstrap module changed");
33
+ const contents = await readBoundedFile(join(source, name), 2097152, "installer bootstrap module");
35
34
  await mkdir(dirname(join(directory, name)), {
36
35
  recursive: true,
37
36
  mode: 448
@@ -7,9 +7,9 @@ async function drivePreflight() {
7
7
  if (!entry || !nonce || !ack || !permit) throw new Error("Missing preflight context");
8
8
  const worker = new Worker(entry, {});
9
9
  const result = new Promise((resolve) => worker.addEventListener("message", (event) => resolve(event.data), { once: true }));
10
- const deadline = Date.now() + 1e4;
10
+ const deadline = performance.now() + 1e4;
11
11
  let acknowledged = false;
12
- while (!acknowledged && Date.now() < deadline) {
12
+ while (!acknowledged && performance.now() < deadline) {
13
13
  try {
14
14
  acknowledged = await readFile(ack, "utf8") === nonce + "\n";
15
15
  } catch {}
@@ -22,7 +22,7 @@ async function drivePreflight() {
22
22
  });
23
23
  let timer;
24
24
  const timeout = new Promise((resolve) => {
25
- timer = setTimeout(() => resolve(null), Math.max(0, deadline - Date.now()));
25
+ timer = setTimeout(() => resolve(null), Math.max(0, deadline - performance.now()));
26
26
  });
27
27
  const value = await Promise.race([result, timeout]);
28
28
  clearTimeout(timer);
@@ -1,27 +1,5 @@
1
1
  import { type InstallerPlatform } from './installer-layout';
2
- import { type InstallerImageMountState } from './installer-image-mount';
3
2
  import type { Artifact } from '../release/release-qualification';
4
- export type ImageAttachIo = {
5
- run(args: string[], env: Record<string, string>): Promise<unknown>;
6
- mounted(mount: string): Promise<boolean>;
7
- /** Optional tri-state probe; unknown is never treated as ownership proof. */
8
- state?(mount: string): Promise<InstallerImageMountState>;
9
- /** Kept for adapter compatibility; retries are unsafe after an indeterminate attach. */
10
- wait(ms: number): Promise<unknown>;
11
- };
12
- /**
13
- * Attach once at a caller-provided mountpoint. The caller must create and reserve a fresh,
14
- * empty mountpoint exclusively for this image operation, and keep it exclusive until this
15
- * call finishes. The state probe rejects paths that are already mounted or whose state is
16
- * unknown, but a mounted-state probe does not identify which image owns a volume; this API
17
- * trusts the caller's exclusivity precondition and does not claim to verify image identity.
18
- *
19
- * A failed attach is indeterminate, so this function never retries or detaches by path and
20
- * the caller must retain its temporary directory for recovery. This changes the former
21
- * three-attempt, five-second retry behavior; internal verification and extraction preserve
22
- * three attempts by using fresh private mountpoints and retaining failed-attempt directories.
23
- */
24
- export declare function attachImage(mount: string, image: string, env: Record<string, string>, io?: ImageAttachIo): Promise<void>;
25
3
  /**
26
4
  * Inspect a shipped installer without executing it, on a matching disposable runner, or with
27
5
  * `local` on the maintainer's own matching machine for a local release (read-only inspection of
@@ -1,10 +1,10 @@
1
1
  import { assertEmbeddedArchive, assertInstallerExecutable, extractArchiveMember, findArchiveMember, isWithin, normalizeArchiveMember } from "./installer-archive-members.js";
2
2
  import { hashFileAt } from "../updates/locks/stable-file.js";
3
3
  import { assertInstallerContext, assertInstallerHost, assertInstallerLayout, assertPortableAppName } from "./installer-layout.js";
4
- import { InstallerImageLifecycleError, cleanupInstallerDirectoryAfterFailure, defaultInstallerImageMountIo, installerImageMountState, withInstallerImageRetries } from "./installer-image-mount.js";
4
+ import { cleanupInstallerDirectoryAfterFailure, defaultInstallerImageMountIo, withInstallerImageRetries } from "./installer-image-mount.js";
5
5
  import { runInstallerCommand } from "./installer-command.js";
6
6
  import { lstat, mkdtemp, readdir, realpath } from "node:fs/promises";
7
- import { basename, dirname, join, resolve, win32 } from "node:path";
7
+ import { basename, join, resolve, win32 } from "node:path";
8
8
  import { tmpdir } from "node:os";
9
9
  // src/installer/installer-identity.ts
10
10
  async function identity(path) {
@@ -31,56 +31,6 @@ function environment(parent) {
31
31
  ]) if (parent[name]) env[name] = parent[name];
32
32
  return env;
33
33
  }
34
- /** Whether a volume is mounted at a directory; unknown counts as mounted. */
35
- async function volumeAt(mount) {
36
- return await installerImageMountState(mount) !== "unmounted";
37
- }
38
- /**
39
- * Attach once at a caller-provided mountpoint. The caller must create and reserve a fresh,
40
- * empty mountpoint exclusively for this image operation, and keep it exclusive until this
41
- * call finishes. The state probe rejects paths that are already mounted or whose state is
42
- * unknown, but a mounted-state probe does not identify which image owns a volume; this API
43
- * trusts the caller's exclusivity precondition and does not claim to verify image identity.
44
- *
45
- * A failed attach is indeterminate, so this function never retries or detaches by path and
46
- * the caller must retain its temporary directory for recovery. This changes the former
47
- * three-attempt, five-second retry behavior; internal verification and extraction preserve
48
- * three attempts by using fresh private mountpoints and retaining failed-attempt directories.
49
- */
50
- async function attachImage(mount, image, env, io = {
51
- run: command,
52
- mounted: volumeAt,
53
- state: installerImageMountState,
54
- wait: Bun.sleep
55
- }) {
56
- let initialState;
57
- try {
58
- initialState = io.state ? await io.state(mount) : await io.mounted(mount) ? "mounted" : "unmounted";
59
- } catch (error) {
60
- throw new InstallerImageLifecycleError([error, /* @__PURE__ */ new Error("Attach was not attempted because the caller-provided mount state is unknown")], true, dirname(mount), "attach", `Installer image attach refused because mountpoint state is unknown at ${mount}`);
61
- }
62
- if (initialState !== "unmounted") throw new InstallerImageLifecycleError([/* @__PURE__ */ new Error(`Attach was not attempted because the caller-provided mount path is ${initialState}`)], true, dirname(mount), "attach", `Installer image attach refused because mountpoint is ${initialState} at ${mount}`);
63
- try {
64
- await io.run([
65
- "/usr/bin/hdiutil",
66
- "attach",
67
- "-readonly",
68
- "-nobrowse",
69
- "-mountpoint",
70
- mount,
71
- image
72
- ], env);
73
- } catch (error) {
74
- throw new InstallerImageLifecycleError([error, /* @__PURE__ */ new Error("Attach completion is indeterminate; do not retry or detach the caller-provided mount path")], true, dirname(mount), "attach", `Installer image attach failed; caller-provided mount path state is indeterminate at ${mount}`);
75
- }
76
- let state;
77
- try {
78
- state = io.state ? await io.state(mount) : await io.mounted(mount) ? "mounted" : "unmounted";
79
- } catch (error) {
80
- throw new InstallerImageLifecycleError([error, /* @__PURE__ */ new Error("Attach returned success but the mount state is unknown")], true, dirname(mount), "attach", `Installer image attach returned success without a confirmed mount at ${mount}`);
81
- }
82
- if (state !== "mounted") throw new InstallerImageLifecycleError([/* @__PURE__ */ new Error(`Attach returned success but the requested mountpoint is ${state}`)], true, dirname(mount), "attach", `Installer image attach returned success without a confirmed mount at ${mount}`);
83
- }
84
34
  async function command(args, env) {
85
35
  return runInstallerCommand(args, env, {
86
36
  outputLimit: 8388608,
@@ -196,4 +146,4 @@ async function verifyInstallerPayload(options) {
196
146
  throw error;
197
147
  }
198
148
  }
199
- export { attachImage, verifyInstallerPayload };
149
+ export { verifyInstallerPayload };
@@ -6,7 +6,6 @@ export type InstallerImageMountIo = {
6
6
  wait(ms: number): Promise<unknown>;
7
7
  remove(directory: string): Promise<void>;
8
8
  };
9
- export declare function installerImageMountState(mount: string): Promise<InstallerImageMountState>;
10
9
  export declare function defaultInstallerImageMountIo(run: InstallerImageMountIo['run']): InstallerImageMountIo;
11
10
  /** Skip only cleanup already owned by this exact lifecycle attempt. */
12
11
  export declare function cleanupInstallerDirectoryAfterFailure(directory: string, error: unknown, io: InstallerImageMountIo): Promise<void>;
@@ -344,4 +344,4 @@ async function withInstallerImageRetries(options) {
344
344
  }
345
345
  throw new Error("Installer image attach attempts exhausted");
346
346
  }
347
- export { InstallerImageLifecycleError, cleanupInstallerDirectoryAfterFailure, defaultInstallerImageMountIo, installerImageMountState, withInstallerImage, withInstallerImageRetries };
347
+ export { InstallerImageLifecycleError, cleanupInstallerDirectoryAfterFailure, defaultInstallerImageMountIo, withInstallerImage, withInstallerImageRetries };
@@ -2,6 +2,11 @@ import { type InstallerPlatform, type InstallerRenderer } from './installer-layo
2
2
  import { type InstallerRendererObservation } from './installer-renderer-evidence';
3
3
  import { type Artifact, type OfflinePolicy, type RendererEvidence } from '../release/release-qualification';
4
4
  import type { ReleaseTrust, VerifiedRelease } from '../updates/feed/signed-release';
5
+ /**
6
+ * The installer's last `error: Name` line, for diagnosing a failed install.
7
+ * Only a bounded identifier is returned: never paths, output or credentials.
8
+ */
9
+ export declare function installerErrorName(stderr: string): string | undefined;
5
10
  /** Whether the runner should start the installed app on this loop iteration.
6
11
  *
7
12
  * Electrobun's Windows and Linux extractors (since 2.0.1, `launchInstalledApp` in
@@ -13,11 +18,6 @@ import type { ReleaseTrust, VerifiedRelease } from '../updates/feed/signed-relea
13
18
  * never gets a renderer and its process exits after the permit. So the runner never starts the
14
19
  * app on Windows or Linux. The macOS installer instead asks `open -n`, which the launch shim
15
20
  * records without opening anything, so the runner starts the recorded bundle exactly once. */
16
- /**
17
- * The installer's last `error: Name` line, for diagnosing a failed install.
18
- * Only a bounded identifier is returned: never paths, output or credentials.
19
- */
20
- export declare function installerErrorName(stderr: string): string | undefined;
21
21
  export declare function shouldLaunchInstalledApp(state: {
22
22
  platform: InstallerPlatform;
23
23
  ready: boolean;
@@ -1,4 +1,5 @@
1
1
  import { errorCode } from "../app/value-guards.js";
2
+ import { pathExists, readJsonFile } from "../shared/file-system.js";
2
3
  import { preflightInstallerRuntime, prepareInstallerCiBootstrap } from "./installer-ci-bootstrap.js";
3
4
  import { prepareInstallerExecution } from "./installer-extraction.js";
4
5
  import { verifyInstallerPayload } from "./installer-identity.js";
@@ -9,7 +10,7 @@ import { parseOfflinePolicy } from "../release/release-qualification.js";
9
10
  import { terminateGuardedWorker } from "./installer-process-cleanup.js";
10
11
  import { stageUpdateSwap } from "../updates/install/update-swap-stage.js";
11
12
  import { swapUpdateTree } from "../updates/install/update-swap.js";
12
- import { chmod, lstat, mkdir, readFile, realpath, writeFile } from "node:fs/promises";
13
+ import { chmod, mkdir, readFile, realpath, writeFile } from "node:fs/promises";
13
14
  import { delimiter, dirname, join } from "node:path";
14
15
  import { randomBytes } from "node:crypto";
15
16
  import { createServer } from "node:net";
@@ -58,33 +59,6 @@ async function choosePort() {
58
59
  await new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
59
60
  return address.port;
60
61
  }
61
- async function boundedJson(path) {
62
- const info = await lstat(path);
63
- if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > 16384) throw new Error("Invalid renderer observation");
64
- const bytes = await readFile(path);
65
- if (bytes.length !== info.size) throw new Error("Renderer observation changed");
66
- return JSON.parse(bytes.toString("utf8"));
67
- }
68
- async function exists(path) {
69
- try {
70
- await lstat(path);
71
- return true;
72
- } catch (error) {
73
- if (errorCode(error) === "ENOENT") return false;
74
- throw error;
75
- }
76
- }
77
- /** Whether the runner should start the installed app on this loop iteration.
78
- *
79
- * Electrobun's Windows and Linux extractors (since 2.0.1, `launchInstalledApp` in
80
- * package/src/extractor/main.zig, still in 2.0.5) start the installed launcher themselves after
81
- * a first install, inheriting the runner's isolated environment and guard context. Starting a
82
- * second launcher there runs two instances against one profile: one Chromium/CEF profile
83
- * (`root_cache_path`) admits a single process, while the worker guard admits whichever worker
84
- * writes its identity first. When those two races pick different processes, the guarded worker
85
- * never gets a renderer and its process exits after the permit. So the runner never starts the
86
- * app on Windows or Linux. The macOS installer instead asks `open -n`, which the launch shim
87
- * records without opening anything, so the runner starts the recorded bundle exactly once. */
88
62
  /**
89
63
  * The installer's last `error: Name` line, for diagnosing a failed install.
90
64
  * Only a bounded identifier is returned: never paths, output or credentials.
@@ -100,6 +74,17 @@ async function boundedStderr(stream, limit = 65536) {
100
74
  for await (const chunk of stream) if (text.length < limit) text += decoder.decode(chunk, { stream: true });
101
75
  return text.slice(-limit);
102
76
  }
77
+ /** Whether the runner should start the installed app on this loop iteration.
78
+ *
79
+ * Electrobun's Windows and Linux extractors (since 2.0.1, `launchInstalledApp` in
80
+ * package/src/extractor/main.zig, still in 2.0.5) start the installed launcher themselves after
81
+ * a first install, inheriting the runner's isolated environment and guard context. Starting a
82
+ * second launcher there runs two instances against one profile: one Chromium/CEF profile
83
+ * (`root_cache_path`) admits a single process, while the worker guard admits whichever worker
84
+ * writes its identity first. When those two races pick different processes, the guarded worker
85
+ * never gets a renderer and its process exits after the permit. So the runner never starts the
86
+ * app on Windows or Linux. The macOS installer instead asks `open -n`, which the launch shim
87
+ * records without opening anything, so the runner starts the recorded bundle exactly once. */
103
88
  function shouldLaunchInstalledApp(state) {
104
89
  return state.platform === "macos-arm64" && state.ready && !state.launched && !state.acknowledged && state.installerExit === 0;
105
90
  }
@@ -115,7 +100,7 @@ async function observeInstalledApp(options) {
115
100
  };
116
101
  assertInstallerContext(parent, options.platform, process.platform, process.arch);
117
102
  assertPortableAppName(options.appName);
118
- if (!/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/.test(options.appId) || options.appId.length > 255 || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(options.version) || options.version.length > 64 || (options.platform === "linux-x64" || options.platform === "linux-arm64") && !parent.DISPLAY) throw new Error("Invalid installer observation context");
103
+ if (!/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/.test(options.appId) || options.appId.length > 255 || !/^\d+\.\d+\.\d+$/.test(options.version) || options.version.length > 64 || (options.platform === "linux-x64" || options.platform === "linux-arm64") && !parent.DISPLAY) throw new Error("Invalid installer observation context");
119
104
  const policy = options.offlinePolicy === void 0 ? void 0 : parseOfflinePolicy(options.offlinePolicy);
120
105
  const expectedReads = options.expectedReads ?? [];
121
106
  if (!Array.isArray(expectedReads) || expectedReads.length > 32 || new Set(expectedReads).size !== expectedReads.length || JSON.stringify(expectedReads).length > 8192) throw new Error("Invalid expected reads");
@@ -268,25 +253,25 @@ async function observeInstalledApp(options) {
268
253
  let app = viaInstaller ? void 0 : spawnApp(), guardedPid;
269
254
  stage(viaInstaller ? "installer-started" : "updated-app-started");
270
255
  try {
271
- let deadline = Date.now() + 15e4;
256
+ let deadline = performance.now() + 15e4;
272
257
  let granted = false;
273
- while (Date.now() < deadline) {
258
+ while (performance.now() < deadline) {
274
259
  if (installer && installer.exitCode !== null && installer.exitCode !== 0) {
275
260
  const error = installerErrorName(await Promise.race([installerStderr, Bun.sleep(2e3).then(() => "")]));
276
- throw new Error(`Installer exited unsuccessfully (exit=${installer.exitCode}, signal=${installer.signalCode ?? "none"}, ready=${await exists(worker) && await exists(launcher)}, acknowledged=${await exists(ack)}, error=${error ?? "none"})`);
261
+ throw new Error(`Installer exited unsuccessfully (exit=${installer.exitCode}, signal=${installer.signalCode ?? "none"}, ready=${await pathExists(worker) && await pathExists(launcher)}, acknowledged=${await pathExists(ack)}, error=${error ?? "none"})`);
277
262
  }
278
- const ready = await exists(worker) && await exists(launcher) && await exists(join(resources, "version.json"));
263
+ const ready = await pathExists(worker) && await pathExists(launcher) && await pathExists(join(resources, "version.json"));
279
264
  if (installer && shouldLaunchInstalledApp({
280
265
  platform: options.platform,
281
266
  ready,
282
267
  launched: app !== void 0,
283
- acknowledged: await exists(ack),
268
+ acknowledged: await pathExists(ack),
284
269
  installerExit: installer.exitCode
285
270
  })) {
286
- if (!launchRecord || !expectedApp || !await exists(launchRecord) || await readFile(launchRecord, "utf8") !== expectedApp + "\n") throw new Error("Installer launch request mismatch");
271
+ if (!launchRecord || !expectedApp || !await pathExists(launchRecord) || await readFile(launchRecord, "utf8") !== expectedApp + "\n") throw new Error("Installer launch request mismatch");
287
272
  app = spawnApp();
288
273
  }
289
- if (await exists(ack) && !granted) {
274
+ if (await pathExists(ack) && !granted) {
290
275
  stage("worker-acknowledged");
291
276
  if (await readFile(ack, "utf8") !== nonce + "\n") throw new Error("Worker guard acknowledgement mismatch");
292
277
  const record = await readFile(pidRecord, "utf8"), match = /^([a-f0-9]{48})\n([1-9]\d{0,9})\n$/.exec(record);
@@ -300,14 +285,14 @@ async function observeInstalledApp(options) {
300
285
  mode: 384
301
286
  });
302
287
  granted = true;
303
- deadline = Date.now() + 9e4;
288
+ deadline = performance.now() + 9e4;
304
289
  stage("worker-permitted");
305
290
  }
306
- if (granted && await exists(observation)) break;
291
+ if (granted && await pathExists(observation)) break;
307
292
  await Bun.sleep(250);
308
293
  }
309
- const observed = await exists(observation);
310
- const unexpectedObserved = await exists(unexpected);
294
+ const observed = await pathExists(observation);
295
+ const unexpectedObserved = await pathExists(unexpected);
311
296
  if (!granted || !observed || unexpectedObserved) {
312
297
  let workerState = "unknown";
313
298
  if (guardedPid !== void 0) try {
@@ -321,28 +306,28 @@ async function observeInstalledApp(options) {
321
306
  }
322
307
  stage("renderer-observed");
323
308
  if (installer) {
324
- const installerDeadline = Date.now() + 3e4;
325
- while (installer.exitCode === null && Date.now() < installerDeadline) await Bun.sleep(250);
309
+ const installerDeadline = performance.now() + 3e4;
310
+ while (installer.exitCode === null && performance.now() < installerDeadline) await Bun.sleep(250);
326
311
  if (installer.exitCode !== 0) {
327
312
  const error = installer.exitCode === null ? void 0 : installerErrorName(await Promise.race([installerStderr, Bun.sleep(2e3).then(() => "")]));
328
313
  throw new Error(`Installer did not complete successfully (exit=${installer.exitCode ?? "running"}, error=${error ?? "none"})`);
329
314
  }
330
315
  stage("installer-completed");
331
316
  }
332
- const proof = await boundedJson(observation);
317
+ const proof = await readJsonFile(observation, 16384, "renderer observation");
333
318
  if (typeof proof !== "object" || proof === null || Array.isArray(proof)) throw new Error("Invalid renderer observation");
334
319
  const { nonce: proofNonce, origin: proofOrigin, blockedReads, unexpectedActivity, offlinePolicy: proofPolicy, bootstrapDenied, ...metrics } = proof;
335
320
  assertInstallerRendererObservation(metrics, Boolean(policy));
336
321
  if (proofNonce !== nonce || proofOrigin !== origin || !Number.isSafeInteger(blockedReads) || Number(blockedReads) < 0 || unexpectedActivity !== false) throw new Error("Renderer observation identity mismatch");
337
322
  if (policy && (JSON.stringify(parseOfflinePolicy(proofPolicy)) !== JSON.stringify(policy) || bootstrapDenied !== (policy.kind === "local-bootstrap") || foreignHits !== 0)) throw new Error("Offline observation does not match policy");
338
323
  await Bun.sleep(3e3);
339
- if (await exists(unexpected) || foreignHits !== 0 || !(await fetch(origin + "/", {
324
+ if (await pathExists(unexpected) || foreignHits !== 0 || !(await fetch(origin + "/", {
340
325
  signal: AbortSignal.timeout(1e3),
341
326
  redirect: "error"
342
327
  })).ok) throw new Error("Installed app did not remain available");
343
328
  await installedPayload(run.version, run.archive);
344
329
  if (viaInstaller) await installerUnchanged();
345
- if (await exists(unexpected) || foreignHits !== 0) throw new Error("Unexpected activity after renderer observation");
330
+ if (await pathExists(unexpected) || foreignHits !== 0) throw new Error("Unexpected activity after renderer observation");
346
331
  if (guardedPid === void 0) throw new Error("Missing guarded process identity");
347
332
  await terminateGuardedWorker({
348
333
  pid: guardedPid,
@@ -459,7 +444,7 @@ async function observeInstalledApp(options) {
459
444
  }
460
445
  /** The terminated app's processes can hold its files briefly, most visibly on Windows. */
461
446
  async function swapAfterExit(target, staging) {
462
- const deadline = Date.now() + 6e4;
447
+ const deadline = performance.now() + 6e4;
463
448
  for (;;) try {
464
449
  await swapUpdateTree({
465
450
  target,
@@ -467,7 +452,7 @@ async function swapAfterExit(target, staging) {
467
452
  });
468
453
  return;
469
454
  } catch (error) {
470
- if (Date.now() > deadline) throw error;
455
+ if (performance.now() > deadline) throw error;
471
456
  await Bun.sleep(500);
472
457
  }
473
458
  }
@@ -30,8 +30,8 @@ async function terminateGuardedWorker(options) {
30
30
  if (platform === "windows-x64" ? actual.toLowerCase() !== expected.toLowerCase() : actual !== expected) throw new Error("Guarded process executable mismatch");
31
31
  process.kill(pid, "SIGKILL");
32
32
  }
33
- const deadline = Date.now() + 5e3;
34
- while (Date.now() < deadline) {
33
+ const deadline = performance.now() + 5e3;
34
+ while (performance.now() < deadline) {
35
35
  if (platform === "macos-arm64" ? await macosWorkerExited(() => readMacosState(pid, env)) : await runningExecutable(pid, platform, env) === void 0) return;
36
36
  await Bun.sleep(100);
37
37
  }