@adea-ai/app-framework 0.26.0 → 0.28.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 (138) hide show
  1. package/README.md +183 -17
  2. package/dist/app/create-application.d.ts +2 -0
  3. package/dist/app/create-application.js +6 -0
  4. package/dist/app/service-registry.js +4 -0
  5. package/dist/appearance/custom-theme-import.js +43 -7
  6. package/dist/appearance/custom-theme-library.d.ts +2 -0
  7. package/dist/appearance/custom-theme-library.js +5 -1
  8. package/dist/appearance/theme-record-adapter.js +4 -2
  9. package/dist/appearance/theme-registry.js +7 -1
  10. package/dist/cli/cef-helper-cli.js +0 -0
  11. package/dist/cli/create-application-cli.js +4 -2
  12. package/dist/cli/electrobun-shortcut-patch-cli.js +0 -0
  13. package/dist/cli/framework-update-cli.js +0 -0
  14. package/dist/cli/macos-signing-cli.js +0 -0
  15. package/dist/cli/release-assets-plan-cli.js +0 -0
  16. package/dist/cli/release-cut-cli.js +0 -0
  17. package/dist/cli/release-descriptor-staging-cli.js +0 -0
  18. package/dist/cli/release-finalize-cli.js +0 -0
  19. package/dist/cli/release-promote-cli.js +0 -0
  20. package/dist/cli/release-publish-cli.js +0 -0
  21. package/dist/cli/release-sign-cli.js +0 -0
  22. package/dist/cli/release-step-cli.js +6 -1
  23. package/dist/cli/toolchain-identity-cli.js +0 -0
  24. package/dist/cli/update-helper-cli.js +28 -6
  25. package/dist/cli/windows-runtime-patch-cli.js +0 -0
  26. package/dist/desktop/client-asset-manifest.d.ts +47 -0
  27. package/dist/desktop/client-asset-manifest.js +114 -0
  28. package/dist/desktop/client-asset-stream.d.ts +10 -0
  29. package/dist/desktop/client-asset-stream.js +138 -33
  30. package/dist/desktop/client-assets.d.ts +20 -0
  31. package/dist/desktop/client-assets.js +132 -22
  32. package/dist/desktop/client-response-lifecycle.d.ts +22 -0
  33. package/dist/desktop/client-response-lifecycle.js +233 -0
  34. package/dist/desktop/desktop-host.d.ts +40 -2
  35. package/dist/desktop/desktop-host.js +159 -9
  36. package/dist/framework-source.json +1 -1
  37. package/dist/installer/command-artifact.d.ts +4 -2
  38. package/dist/installer/command-artifact.js +119 -19
  39. package/dist/installer/installer-identity.d.ts +4 -1
  40. package/dist/installer/installer-identity.js +6 -3
  41. package/dist/installer/installer-layout.d.ts +2 -0
  42. package/dist/installer/installer-layout.js +5 -1
  43. package/dist/installer/linux-process-group.d.ts +13 -0
  44. package/dist/installer/linux-process-group.js +58 -0
  45. package/dist/native/darwin-sync.d.ts +7 -0
  46. package/dist/native/darwin-sync.js +43 -0
  47. package/dist/native/desktop-build-hook.js +7 -0
  48. package/dist/native/directory-exchange.d.ts +10 -0
  49. package/dist/native/directory-exchange.js +90 -0
  50. package/dist/native/electrobun-source-patch.d.ts +5 -0
  51. package/dist/native/electrobun-source-patch.js +19 -1
  52. package/dist/native/posix-launcher-build.d.ts +24 -0
  53. package/dist/native/posix-launcher-build.js +232 -0
  54. package/dist/native/posix-tree-removal.d.ts +36 -0
  55. package/dist/native/posix-tree-removal.js +425 -0
  56. package/dist/release/release-steps.d.ts +5 -0
  57. package/dist/release/release-steps.js +2 -1
  58. package/dist/update-helper.bundle.js +1483 -105
  59. package/dist/updates/channel-update-manager.d.ts +5 -0
  60. package/dist/updates/channel-update-manager.js +13 -1
  61. package/dist/updates/desktop-updater.d.ts +78 -2
  62. package/dist/updates/desktop-updater.js +320 -37
  63. package/dist/updates/launch-environment.d.ts +2 -0
  64. package/dist/updates/launch-environment.js +4 -0
  65. package/dist/updates/native-file-lock.d.ts +15 -0
  66. package/dist/updates/native-file-lock.js +189 -0
  67. package/dist/updates/packaged-launch-admission.d.ts +13 -0
  68. package/dist/updates/packaged-launch-admission.js +45 -0
  69. package/dist/updates/packaged-release-config.d.ts +18 -0
  70. package/dist/updates/packaged-release-config.js +60 -0
  71. package/dist/updates/packaged-update-startup.d.ts +44 -0
  72. package/dist/updates/packaged-update-startup.js +81 -0
  73. package/dist/updates/update-arm.d.ts +9 -8
  74. package/dist/updates/update-arm.js +227 -62
  75. package/dist/updates/update-cleanup-error.d.ts +23 -0
  76. package/dist/updates/update-cleanup-error.js +65 -0
  77. package/dist/updates/update-download-cleanup.d.ts +11 -0
  78. package/dist/updates/update-download-cleanup.js +112 -2
  79. package/dist/updates/update-download-lock.d.ts +20 -0
  80. package/dist/updates/update-download-lock.js +73 -0
  81. package/dist/updates/update-download.d.ts +2 -0
  82. package/dist/updates/update-download.js +7 -3
  83. package/dist/updates/update-generation-lease.d.ts +6 -0
  84. package/dist/updates/update-generation-lease.js +14 -0
  85. package/dist/updates/update-helper.d.ts +11 -2
  86. package/dist/updates/update-helper.js +322 -13
  87. package/dist/updates/update-inherited-launch-lease.d.ts +22 -0
  88. package/dist/updates/update-inherited-launch-lease.js +58 -0
  89. package/dist/updates/update-instance-lease.d.ts +15 -0
  90. package/dist/updates/update-instance-lease.js +25 -0
  91. package/dist/updates/update-launch-gate.d.ts +137 -0
  92. package/dist/updates/update-launch-gate.js +617 -0
  93. package/dist/updates/update-launch.js +3 -1
  94. package/dist/updates/update-lock.d.ts +12 -0
  95. package/dist/updates/update-lock.js +18 -0
  96. package/dist/updates/update-manager.d.ts +2 -0
  97. package/dist/updates/update-manager.js +9 -2
  98. package/dist/updates/update-marker.d.ts +7 -0
  99. package/dist/updates/update-marker.js +62 -0
  100. package/dist/updates/update-preflight-error.d.ts +7 -0
  101. package/dist/updates/update-preflight-error.js +11 -0
  102. package/dist/updates/update-process-fence.d.ts +4 -0
  103. package/dist/updates/update-process-fence.js +85 -73
  104. package/dist/updates/update-process-liveness.d.ts +2 -0
  105. package/dist/updates/update-process-liveness.js +11 -0
  106. package/dist/updates/update-resume.d.ts +37 -3
  107. package/dist/updates/update-resume.js +839 -23
  108. package/dist/updates/update-retention-marker.d.ts +67 -0
  109. package/dist/updates/update-retention-marker.js +165 -0
  110. package/dist/updates/update-retention-plan.d.ts +25 -0
  111. package/dist/updates/update-retention-plan.js +54 -0
  112. package/dist/updates/update-retention-sync.d.ts +34 -0
  113. package/dist/updates/update-retention-sync.js +83 -0
  114. package/dist/updates/update-retirement.d.ts +205 -0
  115. package/dist/updates/update-retirement.js +1485 -0
  116. package/dist/updates/update-shutdown.d.ts +16 -4
  117. package/dist/updates/update-shutdown.js +133 -8
  118. package/dist/updates/update-state-store.d.ts +58 -0
  119. package/dist/updates/update-state-store.js +139 -0
  120. package/dist/updates/update-swap-stage.d.ts +1 -1
  121. package/dist/updates/update-swap-stage.js +85 -14
  122. package/dist/updates/update-swap.d.ts +45 -2
  123. package/dist/updates/update-swap.js +207 -17
  124. package/package.json +31 -1
  125. package/src/appearance/custom-theme-import.ts +96 -14
  126. package/src/appearance/custom-theme-library.ts +5 -0
  127. package/src/appearance/theme-record-adapter.ts +15 -6
  128. package/src/appearance/theme-registry.ts +8 -1
  129. package/src/desktop/client-asset-manifest.ts +207 -0
  130. package/src/desktop/client-asset-stream.ts +193 -32
  131. package/src/desktop/client-assets.ts +210 -19
  132. package/src/desktop/client-response-lifecycle.ts +305 -0
  133. package/src/native/electrobun-posix-launch-lease.patch +398 -0
  134. package/templates/application/README.md +50 -0
  135. package/templates/application/electrobun.config.ts +5 -1
  136. package/templates/application/scripts/build-desktop.ts +4 -0
  137. package/templates/application/src/bun/index.ts +173 -16
  138. package/templates/application/vite.config.ts +112 -6
@@ -1,5 +1,6 @@
1
1
  import { safeArchivePath } from "./archive-entry.js";
2
- import { lstat, mkdir, mkdtemp, readdir, rm } from "node:fs/promises";
2
+ import { linuxProcessGroupIsExited } from "./linux-process-group.js";
3
+ import { lstat, mkdir, mkdtemp, readFile, readdir, rm } from "node:fs/promises";
3
4
  import { basename, join, relative, sep } from "node:path";
4
5
  import { tmpdir } from "node:os";
5
6
  import { c, t, x } from "tar";
@@ -132,17 +133,91 @@ async function exitedWithin(child, milliseconds) {
132
133
  clearTimeout(timer);
133
134
  }
134
135
  }
136
+ /** Signal remaining processes in the detached Unix qualification service's group. */
137
+ function signalProcessGroup(pid, signal) {
138
+ try {
139
+ process.kill(-pid, signal);
140
+ } catch (error) {
141
+ if (error.code !== "ESRCH") throw error;
142
+ }
143
+ }
144
+ async function serviceExitStatus(path) {
145
+ try {
146
+ const value = await readFile(path, "utf8");
147
+ if (!/^(?:0|[1-9]\d{0,2})\n$/.test(value)) return void 0;
148
+ const status = Number(value);
149
+ return status <= 255 ? status : void 0;
150
+ } catch (error) {
151
+ if (error.code === "ENOENT") return void 0;
152
+ throw error;
153
+ }
154
+ }
155
+ async function serviceExitWithin(path, milliseconds) {
156
+ const deadline = performance.now() + milliseconds;
157
+ for (;;) {
158
+ const status = await serviceExitStatus(path);
159
+ if (status !== void 0) return status;
160
+ const remaining = deadline - performance.now();
161
+ if (remaining <= 0) return void 0;
162
+ await Bun.sleep(Math.min(remaining, 20));
163
+ }
164
+ }
165
+ async function processGroupExited(pid, milliseconds) {
166
+ const deadline = performance.now() + milliseconds;
167
+ for (;;) {
168
+ try {
169
+ process.kill(-pid, 0);
170
+ } catch (error) {
171
+ if (error.code === "ESRCH") return true;
172
+ throw error;
173
+ }
174
+ if (process.platform === "linux" && await linuxProcessGroupIsExited(pid)) return true;
175
+ const remaining = deadline - performance.now();
176
+ if (remaining <= 0) return false;
177
+ await Bun.sleep(Math.min(remaining, 20));
178
+ }
179
+ }
180
+ /**
181
+ * Existing normal-path tree stop on Windows uses taskkill by PID. That lookup
182
+ * can race root exit and PID reuse; strong tree ownership needs a Job Object.
183
+ */
184
+ async function killWindowsProcessTree(pid, env) {
185
+ const taskkill = Bun.spawn({
186
+ cmd: [
187
+ "taskkill.exe",
188
+ "/PID",
189
+ String(pid),
190
+ "/T",
191
+ "/F"
192
+ ],
193
+ env,
194
+ stdin: "ignore",
195
+ stdout: "ignore",
196
+ stderr: "ignore"
197
+ });
198
+ const status = await exitedWithin(taskkill, COMMAND_TIMEOUT_MS);
199
+ if (status === void 0) {
200
+ taskkill.kill("SIGKILL");
201
+ await taskkill.exited;
202
+ }
203
+ return status;
204
+ }
135
205
  /**
136
206
  * Extract the archive into a new private location with its own home and data directories, then
137
207
  * run `--version` (it must print `version`), each probe (each must exit 0), and the service
138
- * (it must stay up through a settle window, then stop on SIGTERM with exit 0; on Windows, where
139
- * no signal reaches a console process, its process tree is terminated).
208
+ * (it must stay up through a settle window, then stop on SIGTERM with exit 0; on POSIX, cleanup
209
+ * covers members of the isolated process group, while descendants that detach from that group
210
+ * can outlive it. Windows normal-path taskkill uses a PID lookup with a check-to-use race and no
211
+ * Job Object ownership; early-exit cleanup only signals the retained direct-child handle).
140
212
  */
141
213
  async function qualifyCommandArtifact(options) {
142
214
  const { archive, platform, policy, version } = options;
143
215
  const windows = platform === "windows-x64";
144
216
  const location = await mkdtemp(join(tmpdir(), "framework-command-"));
145
217
  let service;
218
+ let unixGroupKilled = false;
219
+ let cleanupFailure;
220
+ let qualification;
146
221
  try {
147
222
  const install = join(location, "install"), home = join(location, "home"), temp = join(location, "tmp");
148
223
  for (const path of [
@@ -216,29 +291,43 @@ async function qualifyCommandArtifact(options) {
216
291
  const reported = await runOnce(["--version"]);
217
292
  if (reported.status !== 0 || reported.text?.trim() !== version) throw new Error("Command artifact version mismatch");
218
293
  for (const probe of policy.qualification.probes) if ((await runOnce(probe)).status !== 0) throw new Error("Command artifact probe failed");
219
- service = spawn(policy.qualification.service, "ignore");
220
- if (await exitedWithin(service, options.settleMs ?? SERVICE_SETTLE_MS) !== void 0) throw new Error("Command artifact service exited early");
221
- if (windows) {
222
- if (await exitedWithin(Bun.spawn({
294
+ let serviceExitFile;
295
+ if (windows) service = spawn(policy.qualification.service, "ignore");
296
+ else {
297
+ serviceExitFile = join(location, "service-exit");
298
+ service = Bun.spawn({
223
299
  cmd: [
224
- "taskkill.exe",
225
- "/PID",
226
- String(service.pid),
227
- "/T",
228
- "/F"
300
+ "/bin/sh",
301
+ "-c",
302
+ "status=$1; shift; \"$@\" </dev/null >/dev/null 2>&1 & child=$!; trap \"\" TERM; wait \"$child\"; result=$?; printf \"%s\\n\" \"$result\" > \"$status\"; while :; do sleep 3600; done",
303
+ "framework-command-supervisor",
304
+ serviceExitFile,
305
+ launcher,
306
+ ...policy.qualification.service
229
307
  ],
308
+ cwd: home,
230
309
  env,
231
310
  stdin: "ignore",
232
311
  stdout: "ignore",
233
- stderr: "ignore"
234
- }), COMMAND_TIMEOUT_MS) !== 0) throw new Error("Command artifact service did not stop");
312
+ stderr: "ignore",
313
+ detached: true
314
+ });
315
+ }
316
+ const settleMs = options.settleMs ?? SERVICE_SETTLE_MS;
317
+ if (windows ? await exitedWithin(service, settleMs) !== void 0 : await serviceExitWithin(serviceExitFile, settleMs) !== void 0) throw new Error("Command artifact service exited early");
318
+ if (windows) {
319
+ if (await killWindowsProcessTree(service.pid, env) !== 0) throw new Error("Command artifact service did not stop");
235
320
  if (await exitedWithin(service, SERVICE_STOP_MS) === void 0) throw new Error("Command artifact service did not stop");
236
321
  } else {
237
- service.kill("SIGTERM");
238
- if (await exitedWithin(service, SERVICE_STOP_MS) !== 0) throw new Error("Command artifact service did not stop cleanly");
322
+ signalProcessGroup(service.pid, "SIGTERM");
323
+ if (await serviceExitWithin(serviceExitFile, SERVICE_STOP_MS) !== 0) throw new Error("Command artifact service did not stop cleanly");
324
+ signalProcessGroup(service.pid, "SIGKILL");
325
+ unixGroupKilled = true;
326
+ if (await exitedWithin(service, SERVICE_STOP_MS) === void 0) throw new Error("Command artifact service did not stop");
327
+ if (!await processGroupExited(service.pid, SERVICE_STOP_MS)) throw new Error("Command artifact service process tree did not stop");
239
328
  }
240
329
  service = void 0;
241
- return {
330
+ qualification = {
242
331
  installed: true,
243
332
  versionMatched: true,
244
333
  probesPassed: true,
@@ -247,8 +336,16 @@ async function qualifyCommandArtifact(options) {
247
336
  };
248
337
  } finally {
249
338
  if (service) {
250
- service.kill("SIGKILL");
251
- await exitedWithin(service, SERVICE_STOP_MS);
339
+ if (windows) {
340
+ try {
341
+ service.kill("SIGKILL");
342
+ } catch {}
343
+ await exitedWithin(service, SERVICE_STOP_MS);
344
+ } else {
345
+ if (!unixGroupKilled) signalProcessGroup(service.pid, "SIGKILL");
346
+ await exitedWithin(service, SERVICE_STOP_MS);
347
+ if (!await processGroupExited(service.pid, SERVICE_STOP_MS)) cleanupFailure = "Command artifact service process tree did not stop";
348
+ }
252
349
  }
253
350
  await rm(location, {
254
351
  recursive: true,
@@ -257,5 +354,8 @@ async function qualifyCommandArtifact(options) {
257
354
  retryDelay: 200
258
355
  });
259
356
  }
357
+ if (cleanupFailure) throw new Error(cleanupFailure);
358
+ if (!qualification) throw new Error("Command artifact qualification did not complete");
359
+ return qualification;
260
360
  }
261
361
  export { commandArtifactRoot, packCommandArtifact, qualifyCommandArtifact, readCommandArtifact };
@@ -23,7 +23,9 @@ export type ImageAttachIo = {
23
23
  */
24
24
  export declare function attachImage(mount: string, image: string, env: Record<string, string>, io?: ImageAttachIo): Promise<void>;
25
25
  /**
26
- * Inspect a shipped installer without executing it, on a matching disposable runner.
26
+ * Inspect a shipped installer without executing it, on a matching disposable runner, or with
27
+ * `local` on the maintainer's own matching machine for a local release (read-only inspection of
28
+ * an installer that machine just built; installer execution stays hosted-runner only).
27
29
  * macOS attach gets up to three attempts at fresh private mountpoints. Failed-attempt
28
30
  * directories remain available for recovery because Disk Arbitration may mount them later.
29
31
  */
@@ -33,6 +35,7 @@ export declare function verifyInstallerPayload(options: {
33
35
  installer: string;
34
36
  archive: string;
35
37
  env?: Record<string, string | undefined>;
38
+ local?: boolean;
36
39
  }): Promise<{
37
40
  installer: Artifact;
38
41
  archive: Artifact;
@@ -1,4 +1,4 @@
1
- import { assertInstallerContext, assertInstallerLayout, assertPortableAppName } from "./installer-layout.js";
1
+ import { assertInstallerContext, assertInstallerHost, assertInstallerLayout, assertPortableAppName } from "./installer-layout.js";
2
2
  import { assertNativeExecutable } from "./native-executable.js";
3
3
  import { InstallerImageLifecycleError, cleanupInstallerDirectoryAfterFailure, defaultInstallerImageMountIo, installerImageMountState, withInstallerImageRetries } from "./installer-image-mount.js";
4
4
  import { runInstallerCommand } from "./installer-command.js";
@@ -166,13 +166,16 @@ function within(root, path) {
166
166
  return rel !== "" && rel !== ".." && !rel.startsWith(".." + sep) && !isAbsolute(rel);
167
167
  }
168
168
  /**
169
- * Inspect a shipped installer without executing it, on a matching disposable runner.
169
+ * Inspect a shipped installer without executing it, on a matching disposable runner, or with
170
+ * `local` on the maintainer's own matching machine for a local release (read-only inspection of
171
+ * an installer that machine just built; installer execution stays hosted-runner only).
170
172
  * macOS attach gets up to three attempts at fresh private mountpoints. Failed-attempt
171
173
  * directories remain available for recovery because Disk Arbitration may mount them later.
172
174
  */
173
175
  async function verifyInstallerPayload(options) {
174
176
  const parent = options.env ?? process.env;
175
- assertInstallerContext(parent, options.platform, process.platform, process.arch);
177
+ if (options.local === true) assertInstallerHost(options.platform, process.platform, process.arch);
178
+ else assertInstallerContext(parent, options.platform, process.platform, process.arch);
176
179
  assertPortableAppName(options.appName);
177
180
  const installerPath = resolve(options.installer), archivePath = resolve(options.archive);
178
181
  const before = {
@@ -4,6 +4,8 @@ export type InstallerPlatform = 'macos-arm64' | 'windows-x64' | 'linux-x64';
4
4
  export type InstallerRenderer = 'native' | 'cef';
5
5
  /** Native installer execution is only allowed on disposable, matching hosted runners. */
6
6
  export declare function assertInstallerContext(env: Record<string, string | undefined>, platform: InstallerPlatform, host: string, arch: string): void;
7
+ /** The installer's platform must match the native OS and architecture handling it. */
8
+ export declare function assertInstallerHost(platform: InstallerPlatform, host: string, arch: string): void;
7
9
  /** A bundle and installer name usable on macOS, Windows and Linux. */
8
10
  export declare function assertPortableAppName(name: string): void;
9
11
  /** Check names before extraction. Callers must also reject unsafe links and archive entry types. */
@@ -5,6 +5,10 @@ import { assertHostedRunner } from "./hosted-runner.js";
5
5
  /** Native installer execution is only allowed on disposable, matching hosted runners. */
6
6
  function assertInstallerContext(env, platform, host, arch) {
7
7
  assertHostedRunner(env, "Installer execution");
8
+ assertInstallerHost(platform, host, arch);
9
+ }
10
+ /** The installer's platform must match the native OS and architecture handling it. */
11
+ function assertInstallerHost(platform, host, arch) {
8
12
  const expected = {
9
13
  "macos-arm64": "darwin/arm64",
10
14
  "windows-x64": "win32/x64",
@@ -86,4 +90,4 @@ function assertBuildMetadata(value, renderer) {
86
90
  ]) if (flags[flag] !== false) throw new Error(`Unsafe CEF flag: ${flag}`);
87
91
  }
88
92
  }
89
- export { assertBuildMetadata, assertInstallerContext, assertInstallerLayout, assertPayloadLayout, assertPortableAppName };
93
+ export { assertBuildMetadata, assertInstallerContext, assertInstallerHost, assertInstallerLayout, assertPayloadLayout, assertPortableAppName };
@@ -0,0 +1,13 @@
1
+ declare const proc: {
2
+ read: (path: string) => Promise<string>;
3
+ list: () => Promise<string[]>;
4
+ self: () => Promise<string>;
5
+ };
6
+ /**
7
+ * Called only after SIGKILL was sent while the supervisor retained the PGID.
8
+ * Zombies cannot execute or fork, but kill(-pgid, 0) still sees them until their
9
+ * ancestor reaps them. Unknown/filtered process visibility must fail closed.
10
+ * The injectable reads keep these Linux-only conditions testable on other hosts.
11
+ */
12
+ export declare function linuxProcessGroupIsExited(pgid: number, reads?: typeof proc): Promise<boolean>;
13
+ export {};
@@ -0,0 +1,58 @@
1
+ import { linuxProcessIsExited } from "../updates/linux-process-state.js";
2
+ import { readFile, readdir, readlink } from "node:fs/promises";
3
+ // src/installer/linux-process-group.ts
4
+ var proc = {
5
+ read: (path) => readFile(path, "utf8"),
6
+ list: () => readdir("/proc"),
7
+ self: () => readlink("/proc/self")
8
+ };
9
+ /** Refuse filtered procfs views: absence there cannot prove a group has stopped. */
10
+ function completeProcfs(mountinfo) {
11
+ let found = false;
12
+ for (const line of mountinfo.trimEnd().split("\n")) {
13
+ const [mount, filesystem] = line.split(" - ");
14
+ const fields = mount?.split(" ");
15
+ const fs = filesystem?.split(" ");
16
+ if (!fields || fields.length < 6 || !fs || fs.length !== 3) return false;
17
+ const path = fields[4].replace(/\\([0-7]{3})/g, (_, octal) => String.fromCharCode(Number.parseInt(octal, 8)));
18
+ if (/^\/proc\/(?:[0-9]+|self|thread-self)(?:\/|$)/.test(path)) return false;
19
+ if (path !== "/proc") continue;
20
+ if (fields[3] !== "/" || fs[0] !== "proc") return false;
21
+ found = true;
22
+ if ([...fields[5].split(","), ...fs[2].split(",")].some((option) => option.startsWith("hidepid=") && option !== "hidepid=0")) return false;
23
+ }
24
+ return found;
25
+ }
26
+ /**
27
+ * Called only after SIGKILL was sent while the supervisor retained the PGID.
28
+ * Zombies cannot execute or fork, but kill(-pgid, 0) still sees them until their
29
+ * ancestor reaps them. Unknown/filtered process visibility must fail closed.
30
+ * The injectable reads keep these Linux-only conditions testable on other hosts.
31
+ */
32
+ async function linuxProcessGroupIsExited(pgid, reads = proc) {
33
+ if (!Number.isSafeInteger(pgid) || pgid < 1) return false;
34
+ try {
35
+ if (await reads.self() !== String(process.pid)) return false;
36
+ const mounts = await reads.read("/proc/self/mountinfo");
37
+ if (!completeProcfs(mounts)) return false;
38
+ const before = (await reads.list()).filter((name) => /^[1-9]\d*$/.test(name));
39
+ let zombies = 0;
40
+ for (const name of before) {
41
+ const stat = await reads.read(`/proc/${name}/stat`);
42
+ const exited = linuxProcessIsExited(stat, Number(name));
43
+ const fields = stat.slice(stat.lastIndexOf(")") + 2).trimEnd().split(" ");
44
+ const group = Number(fields[2]);
45
+ if (!Number.isSafeInteger(group) || group < 0) return false;
46
+ if (group !== pgid) continue;
47
+ if (!exited) return false;
48
+ zombies++;
49
+ }
50
+ const after = (await reads.list()).filter((name) => /^[1-9]\d*$/.test(name));
51
+ const original = new Set(before);
52
+ if (after.length !== original.size || after.some((name) => !original.has(name))) return false;
53
+ return zombies > 0 && mounts === await reads.read("/proc/self/mountinfo");
54
+ } catch {
55
+ return false;
56
+ }
57
+ }
58
+ export { linuxProcessGroupIsExited };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Request the strongest macOS file or directory barrier used by retention
3
+ * pruning. Unsupported platforms and failed F_FULLFSYNC/F_BARRIERFSYNC calls
4
+ * fail closed. These requests improve ordering but cannot prove that a device
5
+ * honored its cache-flush command through a physical power loss.
6
+ */
7
+ export declare function syncDarwinDescriptor(fd: number, kind: 'file' | 'directory'): void;
@@ -0,0 +1,43 @@
1
+ import { FFIType, dlopen, ptr, read } from "bun:ffi";
2
+ // src/native/darwin-sync.ts
3
+ var F_FULLFSYNC_DARWIN = 51;
4
+ var F_BARRIERFSYNC_DARWIN = 85;
5
+ var library;
6
+ function getLibrary() {
7
+ if (!library) library = dlopen("libSystem.B.dylib", {
8
+ fcntl: {
9
+ args: [
10
+ FFIType.i32,
11
+ FFIType.i32,
12
+ FFIType.i32
13
+ ],
14
+ returns: FFIType.i32
15
+ },
16
+ fstatfs: {
17
+ args: [FFIType.i32, FFIType.ptr],
18
+ returns: FFIType.i32
19
+ }
20
+ });
21
+ return library;
22
+ }
23
+ /**
24
+ * Request the strongest macOS file or directory barrier used by retention
25
+ * pruning. Unsupported platforms and failed F_FULLFSYNC/F_BARRIERFSYNC calls
26
+ * fail closed. These requests improve ordering but cannot prove that a device
27
+ * honored its cache-flush command through a physical power loss.
28
+ */
29
+ function syncDarwinDescriptor(fd, kind) {
30
+ if (process.platform !== "darwin" || process.arch !== "arm64" || !Number.isInteger(fd) || fd < 0) throw new Error("Durable update retention synchronization is unsupported on this platform");
31
+ const command = kind === "file" ? F_FULLFSYNC_DARWIN : F_BARRIERFSYNC_DARWIN;
32
+ const system = getLibrary();
33
+ const filesystem = Buffer.alloc(4096);
34
+ if (system.symbols.fstatfs(fd, ptr(filesystem)) !== 0) throw new Error("Could not inspect the update retention filesystem");
35
+ const typeOffset = 72;
36
+ let typeEnd = typeOffset;
37
+ while (typeEnd < 88 && read.u8(ptr(filesystem), typeEnd) !== 0) typeEnd++;
38
+ if (typeEnd === 88) throw new Error("Update retention filesystem type is truncated");
39
+ const filesystemType = Buffer.from(filesystem.subarray(typeOffset, typeEnd)).toString("ascii");
40
+ if (filesystemType !== "apfs" && filesystemType !== "hfs") throw new Error("Update retention synchronization requires APFS or HFS");
41
+ if (system.symbols.fcntl(fd, command, 0) !== 0) throw new Error(`Could not synchronize update retention ${kind} with a Darwin barrier`);
42
+ }
43
+ export { syncDarwinDescriptor };
@@ -1,4 +1,5 @@
1
1
  import { cefHelperFailure, installPatchedCefHelpers } from "./cef-helper.js";
2
+ import { installOptInPosixLaunchLeaseLauncher } from "./posix-launcher-build.js";
2
3
  import secureWindowsBuild from "./windows-build-hook.js";
3
4
  // src/native/desktop-build-hook.ts
4
5
  /**
@@ -16,5 +17,11 @@ async function secureDesktopBuild() {
16
17
  throw new Error(cefHelperFailure(error));
17
18
  }
18
19
  if (helpers) process.stdout.write(`Installed main-frame-only CEF helpers: ${helpers}\n`);
20
+ try {
21
+ const launcher = await installOptInPosixLaunchLeaseLauncher();
22
+ if (launcher) process.stdout.write(`ADEA_POSIX_LAUNCHER_SHA256=${launcher.sha256}\n`);
23
+ } catch {
24
+ throw new Error("Pinned POSIX launcher preparation failed");
25
+ }
19
26
  }
20
27
  export { secureDesktopBuild as default };
@@ -0,0 +1,10 @@
1
+ /** Atomically exchange two existing paths on supported Darwin and Linux filesystems. */
2
+ export declare function exchangeDirectories(source: string, destination: string): void;
3
+ /**
4
+ * Exercise the actual volume using two disposable directories before exchanging
5
+ * an install tree. This qualifies only that same-volume probe pair; it cannot
6
+ * prove a provider will behave identically for every later object or survive a
7
+ * power failure. The caller also verifies the real trees' versions and inode
8
+ * identities immediately after the exchange.
9
+ */
10
+ export declare function probeDirectoryExchange(parent: string, exchange?: typeof exchangeDirectories): Promise<void>;
@@ -0,0 +1,90 @@
1
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
2
+ import { isAbsolute, join, resolve } from "node:path";
3
+ import { FFIType, dlopen, ptr } from "bun:ffi";
4
+ import { randomUUID } from "node:crypto";
5
+ // src/native/directory-exchange.ts
6
+ var RENAME_EXCHANGE = 2;
7
+ /** Atomically exchange two existing paths on supported Darwin and Linux filesystems. */
8
+ function exchangeDirectories(source, destination) {
9
+ if (typeof source !== "string" || typeof destination !== "string" || !isAbsolute(source) || !isAbsolute(destination) || resolve(source) !== source || resolve(destination) !== destination || source === destination || source.includes("\0") || destination.includes("\0")) throw new Error("Invalid atomic directory exchange paths");
10
+ if (process.platform === "darwin") {
11
+ const library = dlopen("libSystem.B.dylib", { renamex_np: {
12
+ args: [
13
+ FFIType.ptr,
14
+ FFIType.ptr,
15
+ FFIType.u32
16
+ ],
17
+ returns: FFIType.i32
18
+ } });
19
+ try {
20
+ const from = Buffer.from(source + "\0"), to = Buffer.from(destination + "\0");
21
+ if (library.symbols.renamex_np(ptr(from), ptr(to), RENAME_EXCHANGE) !== 0) throw new Error("Atomic directory exchange is unsupported or failed");
22
+ } finally {
23
+ library.close();
24
+ }
25
+ } else if (process.platform === "linux") {
26
+ const library = dlopen("libc.so.6", { renameat2: {
27
+ args: [
28
+ FFIType.i32,
29
+ FFIType.ptr,
30
+ FFIType.i32,
31
+ FFIType.ptr,
32
+ FFIType.u32
33
+ ],
34
+ returns: FFIType.i32
35
+ } });
36
+ try {
37
+ const from = Buffer.from(source + "\0"), to = Buffer.from(destination + "\0");
38
+ if (library.symbols.renameat2(-100, ptr(from), -100, ptr(to), RENAME_EXCHANGE) !== 0) throw new Error("Atomic directory exchange is unsupported or failed");
39
+ } finally {
40
+ library.close();
41
+ }
42
+ } else throw new Error("Atomic directory exchange is unsupported on this platform");
43
+ }
44
+ /**
45
+ * Exercise the actual volume using two disposable directories before exchanging
46
+ * an install tree. This qualifies only that same-volume probe pair; it cannot
47
+ * prove a provider will behave identically for every later object or survive a
48
+ * power failure. The caller also verifies the real trees' versions and inode
49
+ * identities immediately after the exchange.
50
+ */
51
+ async function probeDirectoryExchange(parent, exchange = exchangeDirectories) {
52
+ if (typeof parent !== "string" || !isAbsolute(parent) || resolve(parent) !== parent || parent.includes("\0")) throw new Error("Invalid directory exchange probe parent");
53
+ const id = randomUUID();
54
+ const first = join(parent, `.framework-exchange-probe-${id}-a`);
55
+ const second = join(parent, `.framework-exchange-probe-${id}-b`);
56
+ const marker = "exchange-probe";
57
+ const firstValue = `${id}:first`;
58
+ const secondValue = `${id}:second`;
59
+ let firstCreated = false;
60
+ let secondCreated = false;
61
+ try {
62
+ await mkdir(first, { mode: 448 });
63
+ firstCreated = true;
64
+ await mkdir(second, { mode: 448 });
65
+ secondCreated = true;
66
+ await writeFile(join(first, marker), firstValue, {
67
+ flag: "wx",
68
+ mode: 384
69
+ });
70
+ await writeFile(join(second, marker), secondValue, {
71
+ flag: "wx",
72
+ mode: 384
73
+ });
74
+ exchange(first, second);
75
+ const [firstAfter, secondAfter] = await Promise.all([readFile(join(first, marker), "utf8"), readFile(join(second, marker), "utf8")]);
76
+ if (firstAfter !== secondValue || secondAfter !== firstValue) throw new Error("Directory exchange did not exchange both probe trees");
77
+ } finally {
78
+ const cleanup = [];
79
+ if (firstCreated) cleanup.push(rm(first, {
80
+ recursive: true,
81
+ force: true
82
+ }));
83
+ if (secondCreated) cleanup.push(rm(second, {
84
+ recursive: true,
85
+ force: true
86
+ }));
87
+ await Promise.all(cleanup);
88
+ }
89
+ }
90
+ export { exchangeDirectories, probeDirectoryExchange };
@@ -2,14 +2,19 @@
2
2
  export declare const ELECTROBUN_COMMIT = "d06abc9edf0b4e55116129cabbfe17bf89e11791";
3
3
  export declare const SHORTCUT_PATCH_PATH: string;
4
4
  export declare const CEF_BRIDGE_PATCH_PATH: string;
5
+ export declare const POSIX_LAUNCH_LEASE_PATCH_PATH: string;
5
6
  export type ElectrobunPatchPin = Readonly<{
6
7
  patchSha256: string;
8
+ /** Permit a reviewed zero-context patch after exact input hashes were checked. */
9
+ unidiffZero?: boolean;
7
10
  /** Files that must match exactly before patching. */
8
11
  before: Readonly<Record<string, string>>;
9
12
  /** Every file the patch writes, verified after applying it. */
10
13
  after: Readonly<Record<string, string>>;
11
14
  }>;
12
15
  export declare const PINNED_SHORTCUT_PATCH: ElectrobunPatchPin;
16
+ /** Opt-in launcher lease: macOS arm64 runtime-qualified; Linux x86_64 compile-only. */
17
+ export declare const PINNED_POSIX_LAUNCH_LEASE_PATCH: ElectrobunPatchPin;
13
18
  /** The CEF renderer helper sources, one per platform. */
14
19
  export declare const CEF_HELPER_SOURCES: {
15
20
  readonly macos: 'package/src/native/macos/cef_process_helper_mac.cc';
@@ -10,6 +10,7 @@ var ELECTROBUN_COMMIT = "d06abc9edf0b4e55116129cabbfe17bf89e11791";
10
10
  var shippedPatch = (name) => join(dirname(fileURLToPath(import.meta.url)), "..", "..", "src", "native", name);
11
11
  var SHORTCUT_PATCH_PATH = shippedPatch("electrobun-windows-shortcut-com.patch");
12
12
  var CEF_BRIDGE_PATCH_PATH = shippedPatch("electrobun-cef-main-frame-bridges.patch");
13
+ var POSIX_LAUNCH_LEASE_PATCH_PATH = shippedPatch("electrobun-posix-launch-lease.patch");
13
14
  var extractor = "package/src/extractor/";
14
15
  var PINNED_SHORTCUT_PATCH = {
15
16
  patchSha256: "72a4b75bf3a7fe2e27b2bc322e6447bcfa4169e55eda2f536dcf8189b0a94ad5",
@@ -24,6 +25,20 @@ var PINNED_SHORTCUT_PATCH = {
24
25
  [`${extractor}windows_shortcut_test_helper.c`]: "1edccd2789efecfdea43911b89195c86fc95c0dda6ac76c0d1182a4d6fbee904"
25
26
  }
26
27
  };
28
+ /** Opt-in launcher lease: macOS arm64 runtime-qualified; Linux x86_64 compile-only. */
29
+ var PINNED_POSIX_LAUNCH_LEASE_PATCH = {
30
+ patchSha256: "8b22fef44311a2c7151b80701afa1f1822a5b05ec5035d9bf9901b96fc668db6",
31
+ unidiffZero: true,
32
+ before: {
33
+ "package/src/launcher/build.zig": "d56006fddea42684850aa67d7031198b2ded3eabb931b22bf2c25f30627975ba",
34
+ "package/src/launcher/main.zig": "576a728fc40d437c65192dab3d408889ff76a14b0da136386c72184ad619340f"
35
+ },
36
+ after: {
37
+ "package/src/launcher/build.zig": "03fea1fe892bdfa8e109da20dfdbaa09341f236c9b8aa88e89b65831863dbf33",
38
+ "package/src/launcher/main.zig": "b00bb9b2a70fee36c95d254ef54359d28f765cfed1ae3eb4f735053e9a7accb0",
39
+ "package/src/launcher/launch_lease.zig": "0e34290c143b52a6d94be619131566ca90ca6d639c79b340cd918950e61dff79"
40
+ }
41
+ };
27
42
  /** The CEF renderer helper sources, one per platform. */
28
43
  var CEF_HELPER_SOURCES = {
29
44
  macos: "package/src/native/macos/cef_process_helper_mac.cc",
@@ -77,17 +92,20 @@ function applyElectrobunPatch(root, patchPath, pin, git = runGit) {
77
92
  if (sourceTextDigest(readFileSync(patchPath)) !== pin.patchSha256) throw new Error("Unexpected Electrobun patch digest");
78
93
  for (const [path, expected] of Object.entries(pin.before)) if (sourceDigest(root, path) !== expected) throw new Error("Unexpected Electrobun source digest");
79
94
  for (const path of Object.keys(pin.after)) if (!(path in pin.before) && sourceDigest(root, path) !== null) throw new Error("Electrobun patch output already exists");
95
+ const zeroContext = pin.unidiffZero ? ["--unidiff-zero"] : [];
80
96
  git(root, [
81
97
  "apply",
82
98
  "--check",
83
99
  "--whitespace=error-all",
100
+ ...zeroContext,
84
101
  patchPath
85
102
  ]);
86
103
  git(root, [
87
104
  "apply",
88
105
  "--whitespace=error-all",
106
+ ...zeroContext,
89
107
  patchPath
90
108
  ]);
91
109
  for (const [path, expected] of Object.entries(pin.after)) if (sourceDigest(root, path) !== expected) throw new Error("Unexpected patched Electrobun source");
92
110
  }
93
- export { CEF_BRIDGE_PATCH_PATH, CEF_HELPER_SOURCES, ELECTROBUN_COMMIT, PINNED_CEF_BRIDGE_PATCH, PINNED_SHORTCUT_PATCH, SHORTCUT_PATCH_PATH, applyElectrobunPatch };
111
+ export { CEF_BRIDGE_PATCH_PATH, CEF_HELPER_SOURCES, ELECTROBUN_COMMIT, PINNED_CEF_BRIDGE_PATCH, PINNED_POSIX_LAUNCH_LEASE_PATCH, PINNED_SHORTCUT_PATCH, POSIX_LAUNCH_LEASE_PATCH_PATH, SHORTCUT_PATCH_PATH, applyElectrobunPatch };
@@ -0,0 +1,24 @@
1
+ export declare const POSIX_LAUNCH_LEASE_OPT_IN = "ADEA_ENABLE_POSIX_LAUNCH_LEASE";
2
+ export declare const ELECTROBUN_BUILD_DIR = "ELECTROBUN_BUILD_DIR";
3
+ export declare const ELECTROBUN_BUILD_ENV = "ELECTROBUN_BUILD_ENV";
4
+ export declare const ELECTROBUN_OS = "ELECTROBUN_OS";
5
+ export declare const ELECTROBUN_ARCH = "ELECTROBUN_ARCH";
6
+ export declare const ELECTROBUN_APP_NAME = "ELECTROBUN_APP_NAME";
7
+ type PreparedLauncher = Readonly<{
8
+ path: string;
9
+ sha256: string;
10
+ }>;
11
+ type PrepareLauncher = (work: string) => Promise<PreparedLauncher>;
12
+ export type PosixLaunchLeaseInstallOptions = Readonly<{
13
+ env?: Record<string, string | undefined>;
14
+ cwd?: string;
15
+ platform?: string;
16
+ arch?: string;
17
+ prepareLauncher?: PrepareLauncher;
18
+ }>;
19
+ /**
20
+ * Replace the stable macOS arm64 package launcher only when explicitly enabled.
21
+ * Default generated-app builds return before inspecting outputs or downloading tools.
22
+ */
23
+ export declare function installOptInPosixLaunchLeaseLauncher(options?: PosixLaunchLeaseInstallOptions): Promise<PreparedLauncher | undefined>;
24
+ export {};