@adea-ai/app-framework 0.0.0-stage → 0.24.1

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 (358) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +30 -0
  3. package/README.md +1009 -2
  4. package/dist/app/application.d.ts +47 -0
  5. package/dist/app/application.js +115 -0
  6. package/dist/app/create-application.d.ts +13 -0
  7. package/dist/app/create-application.js +178 -0
  8. package/dist/app/service-registry.d.ts +44 -0
  9. package/dist/app/service-registry.js +116 -0
  10. package/dist/appearance/appearance-host.d.ts +62 -0
  11. package/dist/appearance/appearance-host.js +115 -0
  12. package/dist/appearance/appearance-preferences.d.ts +106 -0
  13. package/dist/appearance/appearance-preferences.js +175 -0
  14. package/dist/appearance/composition.d.ts +11 -0
  15. package/dist/appearance/composition.js +16 -0
  16. package/dist/appearance/custom-theme-import.d.ts +14 -0
  17. package/dist/appearance/custom-theme-import.js +315 -0
  18. package/dist/appearance/custom-theme-library.d.ts +146 -0
  19. package/dist/appearance/custom-theme-library.js +378 -0
  20. package/dist/appearance/editor.d.ts +20 -0
  21. package/dist/appearance/editor.js +47 -0
  22. package/dist/appearance/theme-file-importer.d.ts +23 -0
  23. package/dist/appearance/theme-file-importer.js +66 -0
  24. package/dist/appearance/theme-record-adapter.d.ts +26 -0
  25. package/dist/appearance/theme-record-adapter.js +64 -0
  26. package/dist/appearance/theme-registry.d.ts +10 -0
  27. package/dist/appearance/theme-registry.js +16 -0
  28. package/dist/appearance/window-surface.d.ts +5 -0
  29. package/dist/appearance/window-surface.js +9 -0
  30. package/dist/ci/toolchain-identity.d.ts +39 -0
  31. package/dist/ci/toolchain-identity.js +196 -0
  32. package/dist/cli/cef-helper-cli.d.ts +2 -0
  33. package/dist/cli/cef-helper-cli.js +18 -0
  34. package/dist/cli/cli-runner.d.ts +8 -0
  35. package/dist/cli/cli-runner.js +23 -0
  36. package/dist/cli/create-application-cli.d.ts +2 -0
  37. package/dist/cli/create-application-cli.js +40 -0
  38. package/dist/cli/electrobun-shortcut-patch-cli.d.ts +2 -0
  39. package/dist/cli/electrobun-shortcut-patch-cli.js +17 -0
  40. package/dist/cli/framework-update-cli.d.ts +2 -0
  41. package/dist/cli/framework-update-cli.js +40 -0
  42. package/dist/cli/release-assets-plan-cli.d.ts +2 -0
  43. package/dist/cli/release-assets-plan-cli.js +14 -0
  44. package/dist/cli/release-cut-cli.d.ts +2 -0
  45. package/dist/cli/release-cut-cli.js +27 -0
  46. package/dist/cli/release-descriptor-staging-cli.d.ts +2 -0
  47. package/dist/cli/release-descriptor-staging-cli.js +45 -0
  48. package/dist/cli/release-finalize-cli.d.ts +1 -0
  49. package/dist/cli/release-finalize-cli.js +30 -0
  50. package/dist/cli/release-promote-cli.d.ts +2 -0
  51. package/dist/cli/release-promote-cli.js +32 -0
  52. package/dist/cli/release-publish-cli.d.ts +2 -0
  53. package/dist/cli/release-publish-cli.js +48 -0
  54. package/dist/cli/release-sign-cli.d.ts +2 -0
  55. package/dist/cli/release-sign-cli.js +13 -0
  56. package/dist/cli/release-step-cli.d.ts +2 -0
  57. package/dist/cli/release-step-cli.js +44 -0
  58. package/dist/cli/toolchain-identity-cli.d.ts +2 -0
  59. package/dist/cli/toolchain-identity-cli.js +10 -0
  60. package/dist/cli/update-helper-cli.d.ts +1 -0
  61. package/dist/cli/update-helper-cli.js +10 -0
  62. package/dist/cli/windows-runtime-patch-cli.d.ts +2 -0
  63. package/dist/cli/windows-runtime-patch-cli.js +17 -0
  64. package/dist/desktop/application-command-client.d.ts +15 -0
  65. package/dist/desktop/application-command-client.js +21 -0
  66. package/dist/desktop/channel-handshake.d.ts +32 -0
  67. package/dist/desktop/channel-handshake.js +111 -0
  68. package/dist/desktop/channel-proof.d.ts +43 -0
  69. package/dist/desktop/channel-proof.js +85 -0
  70. package/dist/desktop/client-assets.d.ts +7 -0
  71. package/dist/desktop/client-assets.js +59 -0
  72. package/dist/desktop/desktop-client.d.ts +23 -0
  73. package/dist/desktop/desktop-client.js +231 -0
  74. package/dist/desktop/desktop-gateway.d.ts +18 -0
  75. package/dist/desktop/desktop-gateway.js +146 -0
  76. package/dist/desktop/desktop-host.d.ts +48 -0
  77. package/dist/desktop/desktop-host.js +208 -0
  78. package/dist/desktop/desktop-stream.d.ts +36 -0
  79. package/dist/desktop/desktop-stream.js +231 -0
  80. package/dist/desktop/loopback-policy.d.ts +19 -0
  81. package/dist/desktop/loopback-policy.js +23 -0
  82. package/dist/desktop/open-url-channel.d.ts +15 -0
  83. package/dist/desktop/open-url-channel.js +55 -0
  84. package/dist/desktop/string-policy.d.ts +2 -0
  85. package/dist/desktop/string-policy.js +11 -0
  86. package/dist/framework-source.json +1 -0
  87. package/dist/installer/archive-entry.d.ts +6 -0
  88. package/dist/installer/archive-entry.js +14 -0
  89. package/dist/installer/command-artifact.d.ts +47 -0
  90. package/dist/installer/command-artifact.js +261 -0
  91. package/dist/installer/command-qualification-command.d.ts +12 -0
  92. package/dist/installer/command-qualification-command.js +71 -0
  93. package/dist/installer/hosted-runner.d.ts +4 -0
  94. package/dist/installer/hosted-runner.js +10 -0
  95. package/dist/installer/installed-payload.d.ts +29 -0
  96. package/dist/installer/installed-payload.js +312 -0
  97. package/dist/installer/installer-ci-bootstrap.d.ts +26 -0
  98. package/dist/installer/installer-ci-bootstrap.js +160 -0
  99. package/dist/installer/installer-ci-preflight.d.ts +1 -0
  100. package/dist/installer/installer-ci-preflight.js +49 -0
  101. package/dist/installer/installer-ci-worker.d.ts +1 -0
  102. package/dist/installer/installer-ci-worker.js +105 -0
  103. package/dist/installer/installer-extraction.d.ts +14 -0
  104. package/dist/installer/installer-extraction.js +289 -0
  105. package/dist/installer/installer-fetch-guard.d.ts +15 -0
  106. package/dist/installer/installer-fetch-guard.js +50 -0
  107. package/dist/installer/installer-identity.d.ts +23 -0
  108. package/dist/installer/installer-identity.js +286 -0
  109. package/dist/installer/installer-layout.d.ts +21 -0
  110. package/dist/installer/installer-layout.js +89 -0
  111. package/dist/installer/installer-observation.d.ts +64 -0
  112. package/dist/installer/installer-observation.js +473 -0
  113. package/dist/installer/installer-process-cleanup.d.ts +18 -0
  114. package/dist/installer/installer-process-cleanup.js +158 -0
  115. package/dist/installer/installer-qualification-command.d.ts +11 -0
  116. package/dist/installer/installer-qualification-command.js +71 -0
  117. package/dist/installer/installer-renderer-evidence.d.ts +43 -0
  118. package/dist/installer/installer-renderer-evidence.js +136 -0
  119. package/dist/installer/installer-upgrade-command.d.ts +37 -0
  120. package/dist/installer/installer-upgrade-command.js +172 -0
  121. package/dist/installer/installer-worker-guard.d.ts +21 -0
  122. package/dist/installer/installer-worker-guard.js +72 -0
  123. package/dist/installer/native-executable.d.ts +5 -0
  124. package/dist/installer/native-executable.js +21 -0
  125. package/dist/installer/upgrade-asset-download.d.ts +13 -0
  126. package/dist/installer/upgrade-asset-download.js +41 -0
  127. package/dist/installer/write-all.d.ts +6 -0
  128. package/dist/installer/write-all.js +11 -0
  129. package/dist/native/app-bundle.d.ts +28 -0
  130. package/dist/native/app-bundle.js +60 -0
  131. package/dist/native/cef-helper.d.ts +28 -0
  132. package/dist/native/cef-helper.js +402 -0
  133. package/dist/native/desktop-build-hook.d.ts +7 -0
  134. package/dist/native/desktop-build-hook.js +20 -0
  135. package/dist/native/electrobun-source-patch.d.ts +25 -0
  136. package/dist/native/electrobun-source-patch.js +93 -0
  137. package/dist/native/linux-cef-links.d.ts +2 -0
  138. package/dist/native/linux-cef-links.js +15 -0
  139. package/dist/native/native-secret-store.d.ts +27 -0
  140. package/dist/native/native-secret-store.js +70 -0
  141. package/dist/native/native-utilities.d.ts +24 -0
  142. package/dist/native/native-utilities.js +85 -0
  143. package/dist/native/partitioned-window.d.ts +34 -0
  144. package/dist/native/partitioned-window.js +44 -0
  145. package/dist/native/renderer-profile.d.ts +53 -0
  146. package/dist/native/renderer-profile.js +30 -0
  147. package/dist/native/secure-window.d.ts +38 -0
  148. package/dist/native/secure-window.js +77 -0
  149. package/dist/native/sidecar-services.d.ts +23 -0
  150. package/dist/native/sidecar-services.js +46 -0
  151. package/dist/native/sidecar.d.ts +81 -0
  152. package/dist/native/sidecar.js +250 -0
  153. package/dist/native/window-bootstrap.d.ts +24 -0
  154. package/dist/native/window-bootstrap.js +63 -0
  155. package/dist/native/window-options.d.ts +32 -0
  156. package/dist/native/window-options.js +23 -0
  157. package/dist/native/windows-build-hook-internal.d.ts +2 -0
  158. package/dist/native/windows-build-hook-internal.js +32 -0
  159. package/dist/native/windows-build-hook.d.ts +2 -0
  160. package/dist/native/windows-build-hook.js +12 -0
  161. package/dist/native/windows-runtime-patch-internal.d.ts +3 -0
  162. package/dist/native/windows-runtime-patch-internal.js +20 -0
  163. package/dist/native/windows-runtime-patch.d.ts +4 -0
  164. package/dist/native/windows-runtime-patch.js +12 -0
  165. package/dist/release/feed-release-cut.d.ts +23 -0
  166. package/dist/release/feed-release-cut.js +93 -0
  167. package/dist/release/feed-state.d.ts +25 -0
  168. package/dist/release/feed-state.js +81 -0
  169. package/dist/release/framework-package-publish.d.ts +21 -0
  170. package/dist/release/framework-package-publish.js +127 -0
  171. package/dist/release/framework-update.d.ts +30 -0
  172. package/dist/release/framework-update.js +139 -0
  173. package/dist/release/github-cli.d.ts +6 -0
  174. package/dist/release/github-cli.js +16 -0
  175. package/dist/release/github-release-assets.d.ts +3 -0
  176. package/dist/release/github-release-assets.js +24 -0
  177. package/dist/release/github-release-cut.d.ts +14 -0
  178. package/dist/release/github-release-cut.js +174 -0
  179. package/dist/release/github-release-lookup.d.ts +7 -0
  180. package/dist/release/github-release-lookup.js +29 -0
  181. package/dist/release/github-release-promotion.d.ts +10 -0
  182. package/dist/release/github-release-promotion.js +78 -0
  183. package/dist/release/github-release-provenance.d.ts +9 -0
  184. package/dist/release/github-release-provenance.js +27 -0
  185. package/dist/release/github-release-publisher.d.ts +9 -0
  186. package/dist/release/github-release-publisher.js +63 -0
  187. package/dist/release/github-release-qualification.d.ts +12 -0
  188. package/dist/release/github-release-qualification.js +80 -0
  189. package/dist/release/local-provenance.d.ts +24 -0
  190. package/dist/release/local-provenance.js +72 -0
  191. package/dist/release/local-release.d.ts +133 -0
  192. package/dist/release/local-release.js +387 -0
  193. package/dist/release/macos-dmg.d.ts +22 -0
  194. package/dist/release/macos-dmg.js +91 -0
  195. package/dist/release/release-artifact.d.ts +6 -0
  196. package/dist/release/release-artifact.js +38 -0
  197. package/dist/release/release-assets-plan.d.ts +14 -0
  198. package/dist/release/release-assets-plan.js +65 -0
  199. package/dist/release/release-config.d.ts +76 -0
  200. package/dist/release/release-config.js +180 -0
  201. package/dist/release/release-cut-command.d.ts +13 -0
  202. package/dist/release/release-cut-command.js +39 -0
  203. package/dist/release/release-cut.d.ts +54 -0
  204. package/dist/release/release-cut.js +76 -0
  205. package/dist/release/release-descriptor-staging.d.ts +34 -0
  206. package/dist/release/release-descriptor-staging.js +147 -0
  207. package/dist/release/release-finalize.d.ts +16 -0
  208. package/dist/release/release-finalize.js +104 -0
  209. package/dist/release/release-promotion-command.d.ts +12 -0
  210. package/dist/release/release-promotion-command.js +28 -0
  211. package/dist/release/release-promotion.d.ts +29 -0
  212. package/dist/release/release-promotion.js +57 -0
  213. package/dist/release/release-publication.d.ts +33 -0
  214. package/dist/release/release-publication.js +138 -0
  215. package/dist/release/release-publish-command.d.ts +7 -0
  216. package/dist/release/release-publish-command.js +91 -0
  217. package/dist/release/release-qualification.d.ts +106 -0
  218. package/dist/release/release-qualification.js +135 -0
  219. package/dist/release/release-staging.d.ts +9 -0
  220. package/dist/release/release-staging.js +61 -0
  221. package/dist/release/release-steps.d.ts +38 -0
  222. package/dist/release/release-steps.js +147 -0
  223. package/dist/release/retained-release-build.d.ts +19 -0
  224. package/dist/release/retained-release-build.js +122 -0
  225. package/dist/shell/app-shell.d.ts +61 -0
  226. package/dist/shell/app-shell.js +306 -0
  227. package/dist/shell/app-utilities.d.ts +122 -0
  228. package/dist/shell/app-utilities.js +334 -0
  229. package/dist/shell/application-menu-commands.d.ts +5 -0
  230. package/dist/shell/application-menu-commands.js +11 -0
  231. package/dist/shell/application-menu.d.ts +61 -0
  232. package/dist/shell/application-menu.js +208 -0
  233. package/dist/shell/help-shortcuts.d.ts +12 -0
  234. package/dist/shell/help-shortcuts.js +22 -0
  235. package/dist/shell/navigation-drawer.d.ts +12 -0
  236. package/dist/shell/navigation-drawer.js +42 -0
  237. package/dist/shell/settings-sections.d.ts +31 -0
  238. package/dist/shell/settings-sections.js +50 -0
  239. package/dist/shell/shortcut-platform.d.ts +17 -0
  240. package/dist/shell/shortcut-platform.js +25 -0
  241. package/dist/update-helper.bundle.js +260 -0
  242. package/dist/updates/channel-update-manager.d.ts +46 -0
  243. package/dist/updates/channel-update-manager.js +114 -0
  244. package/dist/updates/desktop-updater.d.ts +104 -0
  245. package/dist/updates/desktop-updater.js +345 -0
  246. package/dist/updates/release-feed.d.ts +61 -0
  247. package/dist/updates/release-feed.js +111 -0
  248. package/dist/updates/release-location.d.ts +9 -0
  249. package/dist/updates/release-location.js +80 -0
  250. package/dist/updates/release-version.d.ts +12 -0
  251. package/dist/updates/release-version.js +43 -0
  252. package/dist/updates/signed-release.d.ts +63 -0
  253. package/dist/updates/signed-release.js +162 -0
  254. package/dist/updates/stable-file.d.ts +10 -0
  255. package/dist/updates/stable-file.js +22 -0
  256. package/dist/updates/update-adapter.d.ts +57 -0
  257. package/dist/updates/update-adapter.js +72 -0
  258. package/dist/updates/update-arm.d.ts +24 -0
  259. package/dist/updates/update-arm.js +95 -0
  260. package/dist/updates/update-channel-store.d.ts +8 -0
  261. package/dist/updates/update-channel-store.js +72 -0
  262. package/dist/updates/update-discovery.d.ts +13 -0
  263. package/dist/updates/update-discovery.js +56 -0
  264. package/dist/updates/update-download.d.ts +14 -0
  265. package/dist/updates/update-download.js +67 -0
  266. package/dist/updates/update-exclusive-rename.d.ts +2 -0
  267. package/dist/updates/update-exclusive-rename.js +52 -0
  268. package/dist/updates/update-extraction.d.ts +18 -0
  269. package/dist/updates/update-extraction.js +183 -0
  270. package/dist/updates/update-handoff-plan.d.ts +22 -0
  271. package/dist/updates/update-handoff-plan.js +28 -0
  272. package/dist/updates/update-helper.d.ts +24 -0
  273. package/dist/updates/update-helper.js +56 -0
  274. package/dist/updates/update-launch.d.ts +5 -0
  275. package/dist/updates/update-launch.js +27 -0
  276. package/dist/updates/update-manager.d.ts +40 -0
  277. package/dist/updates/update-manager.js +83 -0
  278. package/dist/updates/update-process-fence.d.ts +10 -0
  279. package/dist/updates/update-process-fence.js +114 -0
  280. package/dist/updates/update-resume.d.ts +13 -0
  281. package/dist/updates/update-resume.js +34 -0
  282. package/dist/updates/update-shutdown.d.ts +15 -0
  283. package/dist/updates/update-shutdown.js +29 -0
  284. package/dist/updates/update-state.d.ts +30 -0
  285. package/dist/updates/update-state.js +18 -0
  286. package/dist/updates/update-swap-stage.d.ts +27 -0
  287. package/dist/updates/update-swap-stage.js +58 -0
  288. package/dist/updates/update-swap.d.ts +10 -0
  289. package/dist/updates/update-swap.js +30 -0
  290. package/dist/views/app-about.d.ts +22 -0
  291. package/dist/views/app-about.js +43 -0
  292. package/dist/views/app-appearance.d.ts +11 -0
  293. package/dist/views/app-appearance.js +42 -0
  294. package/dist/views/app-help.d.ts +17 -0
  295. package/dist/views/app-help.js +42 -0
  296. package/dist/views/app-settings.d.ts +26 -0
  297. package/dist/views/app-settings.js +97 -0
  298. package/dist/views/appearance-surface.d.ts +9 -0
  299. package/dist/views/appearance-surface.js +334 -0
  300. package/dist/views/update-surface.d.ts +34 -0
  301. package/dist/views/update-surface.js +64 -0
  302. package/package.json +374 -4
  303. package/src/app/application.tsx +138 -0
  304. package/src/appearance/appearance-host.tsx +205 -0
  305. package/src/appearance/appearance-preferences.ts +287 -0
  306. package/src/appearance/composition.ts +29 -0
  307. package/src/appearance/custom-theme-import.ts +424 -0
  308. package/src/appearance/custom-theme-library.ts +600 -0
  309. package/src/appearance/editor.ts +94 -0
  310. package/src/appearance/theme-file-importer.ts +103 -0
  311. package/src/appearance/theme-record-adapter.ts +106 -0
  312. package/src/appearance/theme-registry.ts +20 -0
  313. package/src/appearance/window-surface.ts +18 -0
  314. package/src/desktop/client-assets.ts +75 -0
  315. package/src/native/electrobun-cef-main-frame-bridges.patch +63 -0
  316. package/src/native/electrobun-windows-shortcut-com.patch +923 -0
  317. package/src/native/renderer-profile.ts +27 -0
  318. package/src/native/window-options.ts +24 -0
  319. package/src/shell/app-shell.tsx +294 -0
  320. package/src/shell/app-utilities.tsx +437 -0
  321. package/src/shell/help-shortcuts.ts +24 -0
  322. package/src/shell/navigation-drawer.tsx +36 -0
  323. package/src/shell/settings-sections.ts +74 -0
  324. package/src/shell/shortcut-platform.ts +35 -0
  325. package/src/updates/release-version.ts +57 -0
  326. package/src/updates/update-adapter.ts +129 -0
  327. package/src/updates/update-state.ts +34 -0
  328. package/src/views/app-about.tsx +44 -0
  329. package/src/views/app-appearance.tsx +32 -0
  330. package/src/views/app-help.tsx +43 -0
  331. package/src/views/app-settings.tsx +88 -0
  332. package/src/views/appearance-surface.tsx +427 -0
  333. package/src/views/update-surface.tsx +85 -0
  334. package/templates/application/.gitattributes +1 -0
  335. package/templates/application/.github/workflows/release-assets.yml +29 -0
  336. package/templates/application/.github/workflows/release-finalize.yml +29 -0
  337. package/templates/application/.github/workflows/release-please.yml +19 -0
  338. package/templates/application/.github/workflows/release.yml +29 -0
  339. package/templates/application/.github/workflows/validation.yml +28 -0
  340. package/templates/application/.oxfmtrc.json +6 -0
  341. package/templates/application/.oxlintrc.json +48 -0
  342. package/templates/application/.release-please-manifest.json +3 -0
  343. package/templates/application/README.md +47 -0
  344. package/templates/application/electrobun.config.ts +22 -0
  345. package/templates/application/release-please-config.json +12 -0
  346. package/templates/application/scripts/app-version.ts +9 -0
  347. package/templates/application/scripts/build-desktop.ts +34 -0
  348. package/templates/application/scripts/secure-build.ts +1 -0
  349. package/templates/application/scripts/stage-release.ts +21 -0
  350. package/templates/application/src/bun/index.ts +80 -0
  351. package/templates/application/src/electrobun.d.ts +27 -0
  352. package/templates/application/src/web/index.html +12 -0
  353. package/templates/application/src/web/main.tsx +97 -0
  354. package/templates/application/src/web/public/icon.svg +1 -0
  355. package/templates/application/src/web/style.css +3 -0
  356. package/templates/application/tests/app-config.test.ts +9 -0
  357. package/templates/application/tsconfig.json +15 -0
  358. package/templates/application/vite.config.ts +10 -0
@@ -0,0 +1,89 @@
1
+ import { containsAsciiControl } from "../desktop/string-policy.js";
2
+ import { assertSidecarNames, sidecarBundlePath } from "../native/app-bundle.js";
3
+ import { assertHostedRunner } from "./hosted-runner.js";
4
+ // src/installer/installer-layout.ts
5
+ /** Native installer execution is only allowed on disposable, matching hosted runners. */
6
+ function assertInstallerContext(env, platform, host, arch) {
7
+ assertHostedRunner(env, "Installer execution");
8
+ const expected = {
9
+ "macos-arm64": "darwin/arm64",
10
+ "windows-x64": "win32/x64",
11
+ "linux-x64": "linux/x64"
12
+ }[platform];
13
+ if (!expected || `${host}/${arch}` !== expected) throw new Error("Installer requires matching native OS and architecture");
14
+ }
15
+ /** A bundle and installer name usable on macOS, Windows and Linux. */
16
+ function assertPortableAppName(name) {
17
+ if (typeof name !== "string" || !name || name !== name.trim() || name.length > 80 || name.endsWith(".") || /^[.]+$/.test(name) || /[<>:"/\\|?*]/.test(name) || containsAsciiControl(name) || /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(name)) throw new Error("Invalid portable application name");
18
+ }
19
+ function paths(entries, fold) {
20
+ if (!Array.isArray(entries) || entries.length > 2e5) throw new Error("Invalid archive listing");
21
+ const normalized = entries.filter((entry) => entry !== "." && entry !== "./" && entry !== ".\\").map((entry) => {
22
+ if (typeof entry !== "string" || !entry || entry.includes("\0")) throw new Error("Invalid archive path");
23
+ const path = entry.replaceAll("\\", "/").replace(/^\.\//, "").replace(/\/$/, "");
24
+ if (!path || path.startsWith("/") || /^[A-Za-z]:/.test(path) || path.split("/").some((part) => part === ".." || part === "" || part === ".")) throw new Error("Unsafe archive path");
25
+ return fold ? path.toLowerCase() : path;
26
+ });
27
+ if (new Set(normalized).size !== normalized.length) throw new Error("Duplicate archive path");
28
+ return normalized;
29
+ }
30
+ /** Check names before extraction. Callers must also reject unsafe links and archive entry types. */
31
+ function assertPayloadLayout(options) {
32
+ const { platform, appName, renderer } = options;
33
+ const sidecars = assertSidecarNames(options.sidecars ?? []);
34
+ assertPortableAppName(appName);
35
+ if (![
36
+ "macos-arm64",
37
+ "windows-x64",
38
+ "linux-x64"
39
+ ].includes(platform) || !["native", "cef"].includes(renderer)) throw new Error("Invalid installer profile");
40
+ const fold = platform === "windows-x64";
41
+ const entries = paths(options.entries, fold);
42
+ const mac = platform === "macos-arm64";
43
+ const root = mac ? `${appName}.app/Contents` : appName.replaceAll(" ", "");
44
+ const bin = mac ? `${root}/MacOS` : `${root}/bin`;
45
+ const resources = `${root}/Resources`;
46
+ const suffix = platform === "windows-x64" ? ".exe" : "";
47
+ for (const name of [
48
+ `${bin}/launcher${suffix}`,
49
+ `${bin}/bun${suffix}`,
50
+ `${resources}/version.json`,
51
+ `${resources}/main.js`,
52
+ `${resources}/app/bun/index.js`,
53
+ `${resources}/build.json`,
54
+ `${resources}/app/client/index.html`,
55
+ ...sidecars.map((sidecar) => `${root}/${sidecarBundlePath(sidecar, platform)}`)
56
+ ]) if (!entries.includes(fold ? name.toLowerCase() : name)) throw new Error(`Payload missing ${name}`);
57
+ if (entries.some((name) => /(?:^|\/)(?:chromium embedded framework|libcef\.dll|libcef\.so)$/i.test(name)) !== (renderer === "cef")) throw new Error("Payload does not match selected renderer");
58
+ }
59
+ /** Check expected installer entries before extraction; links and types require separate validation. */
60
+ function assertInstallerLayout(platform, appName, entries) {
61
+ assertPortableAppName(appName);
62
+ if (platform !== "windows-x64" && platform !== "linux-x64") throw new Error("Unsupported archive installer platform");
63
+ const fold = platform === "windows-x64";
64
+ const names = paths(entries, fold);
65
+ const expected = fold ? [
66
+ `${appName}-Setup.exe`,
67
+ `.installer/${appName}-Setup.metadata.json`,
68
+ `.installer/${appName}-Setup.tar.zst`
69
+ ] : ["installer", "README.txt"];
70
+ for (const name of expected) if (!names.includes(fold ? name.toLowerCase() : name)) throw new Error(`Installer missing ${name}`);
71
+ }
72
+ /** Check the actual packaged renderer metadata, not merely the app's source config. */
73
+ function assertBuildMetadata(value, renderer) {
74
+ if (!["native", "cef"].includes(renderer) || typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("Invalid build metadata");
75
+ const config = value;
76
+ if (config.mainProcess !== "bun" || config.defaultRenderer !== renderer || !Array.isArray(config.availableRenderers) || !config.availableRenderers.includes(renderer) || config.availableRenderers.some((item) => item !== "native" && item !== "cef") || new Set(config.availableRenderers).size !== config.availableRenderers.length) throw new Error("Packaged renderer does not match the application profile");
77
+ if (renderer === "native" && config.availableRenderers.includes("cef")) throw new Error("System webview package must not bundle CEF");
78
+ if (renderer === "cef") {
79
+ if (typeof config.chromiumFlags !== "object" || config.chromiumFlags === null || Array.isArray(config.chromiumFlags)) throw new Error("Missing CEF security policy");
80
+ const flags = config.chromiumFlags;
81
+ for (const flag of [
82
+ "disable-web-security",
83
+ "remote-allow-origins",
84
+ "allow-insecure-localhost",
85
+ "remote-debugging-port"
86
+ ]) if (flags[flag] !== false) throw new Error(`Unsafe CEF flag: ${flag}`);
87
+ }
88
+ }
89
+ export { assertBuildMetadata, assertInstallerContext, assertInstallerLayout, assertPayloadLayout, assertPortableAppName };
@@ -0,0 +1,64 @@
1
+ import { type InstallerPlatform, type InstallerRenderer } from './installer-layout';
2
+ import { type InstallerRendererObservation } from './installer-renderer-evidence';
3
+ import { type Artifact, type OfflinePolicy, type RendererEvidence } from '../release/release-qualification';
4
+ import type { ReleaseTrust, VerifiedRelease } from '../updates/signed-release';
5
+ /** Whether the runner should start the installed app on this loop iteration.
6
+ *
7
+ * Electrobun's Windows and Linux extractors (since 2.0.1, `launchInstalledApp` in
8
+ * package/src/extractor/main.zig, still in 2.0.5) start the installed launcher themselves after
9
+ * a first install, inheriting the runner's isolated environment and guard context. Starting a
10
+ * second launcher there runs two instances against one profile: one Chromium/CEF profile
11
+ * (`root_cache_path`) admits a single process, while the worker guard admits whichever worker
12
+ * writes its identity first. When those two races pick different processes, the guarded worker
13
+ * never gets a renderer and its process exits after the permit. So the runner never starts the
14
+ * app on Windows or Linux. The macOS installer instead asks `open -n`, which the launch shim
15
+ * 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
+ export declare function shouldLaunchInstalledApp(state: {
22
+ platform: InstallerPlatform;
23
+ ready: boolean;
24
+ launched: boolean;
25
+ acknowledged: boolean;
26
+ installerExit: number | null;
27
+ }): boolean;
28
+ /** Execute an installer only on a matching disposable hosted runner and return raw observations.
29
+ * This does not produce a release receipt or establish app-specific offline acceptance. */
30
+ export declare function observeInstalledApp(options: {
31
+ platform: InstallerPlatform;
32
+ renderer: InstallerRenderer;
33
+ appName: string;
34
+ appId: string;
35
+ version: string;
36
+ installer: string;
37
+ archive: string;
38
+ expectedReads?: readonly string[];
39
+ onStage?: (stage: string) => void;
40
+ offlinePolicy?: OfflinePolicy;
41
+ /** Sidecar executables the app bundles; installed copies must match the archive. */
42
+ sidecars?: readonly string[];
43
+ env?: Record<string, string | undefined>;
44
+ /** After observing the installed version, apply this signed update and observe the new version. */
45
+ update?: {
46
+ descriptor: VerifiedRelease;
47
+ trust: ReleaseTrust;
48
+ archive: string;
49
+ maxCompressedBytes: number;
50
+ maxExpandedBytes: number;
51
+ };
52
+ }): Promise<{
53
+ directory: string;
54
+ observation: InstallerRendererObservation;
55
+ blockedReads: number;
56
+ artifacts: Artifact[];
57
+ evidence?: RendererEvidence;
58
+ updated?: {
59
+ version: string;
60
+ observation: InstallerRendererObservation;
61
+ blockedReads: number;
62
+ evidence?: RendererEvidence;
63
+ };
64
+ }>;
@@ -0,0 +1,473 @@
1
+ import { assertInstallerContext, assertPortableAppName } from "./installer-layout.js";
2
+ import { parseOfflinePolicy } from "../release/release-qualification.js";
3
+ import { verifyInstallerPayload } from "./installer-identity.js";
4
+ import { preflightInstallerRuntime, prepareInstallerCiBootstrap } from "./installer-ci-bootstrap.js";
5
+ import { prepareInstallerExecution } from "./installer-extraction.js";
6
+ import { assertInstallerRendererObservation } from "./installer-renderer-evidence.js";
7
+ import { extractCandidateRuntime, verifyInstalledPayload } from "./installed-payload.js";
8
+ import { terminateGuardedWorker } from "./installer-process-cleanup.js";
9
+ import { swapUpdateTree } from "../updates/update-swap.js";
10
+ import { stageUpdateSwap } from "../updates/update-swap-stage.js";
11
+ import { chmod, lstat, mkdir, readFile, realpath, writeFile } from "node:fs/promises";
12
+ import { delimiter, dirname, join } from "node:path";
13
+ import { randomBytes } from "node:crypto";
14
+ import { createServer } from "node:net";
15
+ // src/installer/installer-observation.ts
16
+ function isolatedEnv(parent, profile, platform) {
17
+ const env = {};
18
+ for (const name of [
19
+ "PATH",
20
+ "SystemRoot",
21
+ "WINDIR",
22
+ "COMSPEC",
23
+ "PATHEXT",
24
+ "LANG",
25
+ "LC_ALL",
26
+ "DISPLAY",
27
+ "XAUTHORITY",
28
+ "DBUS_SESSION_BUS_ADDRESS"
29
+ ]) if (parent[name]) env[name] = parent[name];
30
+ Object.assign(env, {
31
+ CI: "true",
32
+ GITHUB_ACTIONS: "true",
33
+ RUNNER_ENVIRONMENT: "github-hosted",
34
+ HOME: profile,
35
+ USERPROFILE: profile,
36
+ LOCALAPPDATA: join(profile, "LocalAppData"),
37
+ XDG_DATA_HOME: join(profile, ".local", "share"),
38
+ TMP: join(profile, "tmp"),
39
+ TEMP: join(profile, "tmp"),
40
+ TMPDIR: join(profile, "tmp"),
41
+ ELECTROBUN_INSTALLER_UI_AUTOCLOSE: "1"
42
+ });
43
+ if (platform === "windows-x64") env.TAR_OPTIONS = "--force-local";
44
+ return env;
45
+ }
46
+ async function choosePort() {
47
+ const server = createServer();
48
+ await new Promise((resolve, reject) => {
49
+ server.once("error", reject);
50
+ server.listen(0, "127.0.0.1", resolve);
51
+ });
52
+ const address = server.address();
53
+ if (!address || typeof address === "string" || address.port < 1024) {
54
+ server.close();
55
+ throw new Error("Cannot reserve test port");
56
+ }
57
+ await new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
58
+ return address.port;
59
+ }
60
+ async function boundedJson(path) {
61
+ const info = await lstat(path);
62
+ if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > 16384) throw new Error("Invalid renderer observation");
63
+ const bytes = await readFile(path);
64
+ if (bytes.length !== info.size) throw new Error("Renderer observation changed");
65
+ return JSON.parse(bytes.toString("utf8"));
66
+ }
67
+ async function exists(path) {
68
+ try {
69
+ await lstat(path);
70
+ return true;
71
+ } catch (error) {
72
+ if (error.code === "ENOENT") return false;
73
+ throw error;
74
+ }
75
+ }
76
+ /** Whether the runner should start the installed app on this loop iteration.
77
+ *
78
+ * Electrobun's Windows and Linux extractors (since 2.0.1, `launchInstalledApp` in
79
+ * package/src/extractor/main.zig, still in 2.0.5) start the installed launcher themselves after
80
+ * a first install, inheriting the runner's isolated environment and guard context. Starting a
81
+ * second launcher there runs two instances against one profile: one Chromium/CEF profile
82
+ * (`root_cache_path`) admits a single process, while the worker guard admits whichever worker
83
+ * writes its identity first. When those two races pick different processes, the guarded worker
84
+ * never gets a renderer and its process exits after the permit. So the runner never starts the
85
+ * app on Windows or Linux. The macOS installer instead asks `open -n`, which the launch shim
86
+ * records without opening anything, so the runner starts the recorded bundle exactly once. */
87
+ /**
88
+ * The installer's last `error: Name` line, for diagnosing a failed install.
89
+ * Only a bounded identifier is returned: never paths, output or credentials.
90
+ */
91
+ function installerErrorName(stderr) {
92
+ let name;
93
+ for (const match of stderr.matchAll(/^error: ([A-Za-z][A-Za-z0-9_]{0,63})\s*$/gm)) name = match[1];
94
+ return name;
95
+ }
96
+ async function boundedStderr(stream, limit = 65536) {
97
+ const decoder = new TextDecoder();
98
+ let text = "";
99
+ for await (const chunk of stream) if (text.length < limit) text += decoder.decode(chunk, { stream: true });
100
+ return text.slice(-limit);
101
+ }
102
+ function shouldLaunchInstalledApp(state) {
103
+ return state.platform === "macos-arm64" && state.ready && !state.launched && !state.acknowledged && state.installerExit === 0;
104
+ }
105
+ var shim = `#!/bin/sh\numask 077\nif [ "\${CI:-}" != true ] || [ "\${GITHUB_ACTIONS:-}" != true ] || [ "\${RUNNER_ENVIRONMENT:-}" != github-hosted ] || [ "$#" -ne 2 ] || [ "$1" != "-n" ] || [ "$2" != "\${FRAMEWORK_CI_EXPECTED_APP:-}" ] || [ -z "\${FRAMEWORK_CI_LAUNCH_RECORD:-}" ] || [ -e "$FRAMEWORK_CI_LAUNCH_RECORD" ]; then exit 1; fi\n(set -C; printf '%s\\n' "$2" > "$FRAMEWORK_CI_LAUNCH_RECORD")\n`;
106
+ /** Execute an installer only on a matching disposable hosted runner and return raw observations.
107
+ * This does not produce a release receipt or establish app-specific offline acceptance. */
108
+ async function observeInstalledApp(options) {
109
+ const parent = options.env ?? process.env;
110
+ const stage = (name) => {
111
+ try {
112
+ options.onStage?.(name);
113
+ } catch {}
114
+ };
115
+ assertInstallerContext(parent, options.platform, process.platform, process.arch);
116
+ assertPortableAppName(options.appName);
117
+ 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" && !parent.DISPLAY) throw new Error("Invalid installer observation context");
118
+ const policy = options.offlinePolicy === void 0 ? void 0 : parseOfflinePolicy(options.offlinePolicy);
119
+ const expectedReads = options.expectedReads ?? [];
120
+ if (!Array.isArray(expectedReads) || expectedReads.length > 32 || new Set(expectedReads).size !== expectedReads.length || JSON.stringify(expectedReads).length > 8192) throw new Error("Invalid expected reads");
121
+ for (const value of expectedReads) {
122
+ if (typeof value !== "string" || value.length > 2048) throw new Error("Invalid expected read");
123
+ const url = new URL(value);
124
+ if (url.protocol !== "https:" || url.username || url.password || url.hash || url.href !== value) throw new Error("Invalid expected read");
125
+ }
126
+ const before = await verifyInstallerPayload({
127
+ platform: options.platform,
128
+ appName: options.appName,
129
+ installer: options.installer,
130
+ archive: options.archive,
131
+ env: parent
132
+ });
133
+ stage("artifacts-verified");
134
+ const prepared = await prepareInstallerExecution({
135
+ platform: options.platform,
136
+ appName: options.appName,
137
+ installer: options.installer,
138
+ archive: options.archive,
139
+ env: parent
140
+ });
141
+ stage("installer-prepared");
142
+ const bootstrap = await prepareInstallerCiBootstrap(parent);
143
+ const candidate = await extractCandidateRuntime({
144
+ platform: options.platform,
145
+ renderer: options.renderer,
146
+ appName: options.appName,
147
+ archive: options.archive,
148
+ profile: prepared.profile,
149
+ env: parent
150
+ });
151
+ stage("runtime-extracted");
152
+ await preflightInstallerRuntime({
153
+ env: parent,
154
+ runtime: candidate.path,
155
+ bootstrap
156
+ });
157
+ stage("runtime-preflight-passed");
158
+ for (const path of [
159
+ join(prepared.profile, "LocalAppData"),
160
+ join(prepared.profile, ".local", "share"),
161
+ join(prepared.profile, "tmp")
162
+ ]) await mkdir(path, {
163
+ recursive: true,
164
+ mode: 448
165
+ });
166
+ const mac = options.platform === "macos-arm64", windows = options.platform === "windows-x64";
167
+ const installedRoot = mac ? join(prepared.incoming, `${options.appName}.app`, "Contents") : join(prepared.profile, windows ? "LocalAppData" : ".local/share", options.appId, "stable", "app");
168
+ const resources = join(installedRoot, "Resources"), binary = join(installedRoot, mac ? "MacOS" : "bin"), launcher = join(binary, windows ? "launcher.exe" : "launcher"), runtime = join(binary, windows ? "bun.exe" : "bun");
169
+ const worker = join(resources, "app", "bun", "index.js");
170
+ const sidecars = options.sidecars ?? [];
171
+ let foreignHits = 0;
172
+ const sentinel = policy ? Bun.serve({
173
+ hostname: "127.0.0.1",
174
+ port: 0,
175
+ fetch: () => {
176
+ foreignHits++;
177
+ return new Response("sentinel");
178
+ }
179
+ }) : void 0;
180
+ const foreignOrigin = sentinel ? `http://127.0.0.1:${sentinel.port}` : void 0;
181
+ const baseEnv = isolatedEnv(parent, prepared.profile, options.platform);
182
+ Object.assign(baseEnv, {
183
+ BUN_OPTIONS: bootstrap.bunOptions,
184
+ FRAMEWORK_CI_WORKER_ENTRY: worker,
185
+ FRAMEWORK_CI_EXPECTED_READS: JSON.stringify(expectedReads),
186
+ FRAMEWORK_CI_ALLOW_EPHEMERAL: "1",
187
+ ...policy ? {
188
+ FRAMEWORK_CI_OFFLINE_POLICY: JSON.stringify(policy),
189
+ FRAMEWORK_CI_FOREIGN_ORIGIN: foreignOrigin
190
+ } : {}
191
+ });
192
+ const installedPayload = (version, archive) => verifyInstalledPayload({
193
+ platform: options.platform,
194
+ renderer: options.renderer,
195
+ appName: options.appName,
196
+ version,
197
+ archive,
198
+ profile: prepared.directory,
199
+ installedRoot,
200
+ sidecars,
201
+ env: parent
202
+ });
203
+ const installerUnchanged = async () => {
204
+ const after = await verifyInstallerPayload({
205
+ platform: options.platform,
206
+ appName: options.appName,
207
+ installer: options.installer,
208
+ archive: options.archive,
209
+ env: parent
210
+ });
211
+ if (JSON.stringify(after) !== JSON.stringify(before)) throw new Error("Installer artifacts changed");
212
+ };
213
+ /** One guarded start of the installed app: by its installer, or by its launcher after an update. */
214
+ async function observeRun(run) {
215
+ const viaInstaller = run.start === "installer";
216
+ if (sentinel && (!(await fetch(foreignOrigin + "/", { signal: AbortSignal.timeout(1e3) })).ok || foreignHits !== 1)) throw new Error("Foreign network sentinel unavailable");
217
+ foreignHits = 0;
218
+ const nonce = randomBytes(24).toString("hex");
219
+ const ack = join(run.directory, "ack"), permit = join(run.directory, "permit"), observation = join(run.directory, "observation"), unexpected = join(run.directory, "unexpected"), pidRecord = join(run.directory, "worker-pid");
220
+ const env = {
221
+ ...baseEnv,
222
+ FRAMEWORK_CI_NONCE: nonce,
223
+ FRAMEWORK_CI_ACK: ack,
224
+ FRAMEWORK_CI_PERMIT: permit,
225
+ FRAMEWORK_CI_ORIGIN: origin,
226
+ FRAMEWORK_CI_OBSERVATION: observation,
227
+ FRAMEWORK_CI_UNEXPECTED: unexpected,
228
+ FRAMEWORK_CI_PID: pidRecord
229
+ };
230
+ let launchRecord, expectedApp;
231
+ if (mac && viaInstaller) {
232
+ const shimDir = join(run.directory, "launch-shim");
233
+ await mkdir(shimDir, { mode: 448 });
234
+ const path = join(shimDir, "open");
235
+ await writeFile(path, shim, {
236
+ flag: "wx",
237
+ mode: 448
238
+ });
239
+ await chmod(path, 448);
240
+ expectedApp = join(await realpath(prepared.incoming), `${options.appName}.app`);
241
+ launchRecord = join(run.directory, "launch-record");
242
+ Object.assign(env, {
243
+ PATH: shimDir + delimiter + (env.PATH ?? ""),
244
+ FRAMEWORK_CI_EXPECTED_APP: expectedApp,
245
+ FRAMEWORK_CI_LAUNCH_RECORD: launchRecord
246
+ });
247
+ }
248
+ function spawnApp() {
249
+ return Bun.spawn({
250
+ cmd: [launcher],
251
+ cwd: prepared.incoming,
252
+ env,
253
+ stdout: "ignore",
254
+ stderr: "ignore",
255
+ signal: AbortSignal.timeout(24e4)
256
+ });
257
+ }
258
+ const installer = viaInstaller ? Bun.spawn({
259
+ cmd: [prepared.executable],
260
+ cwd: prepared.incoming,
261
+ env,
262
+ stdout: "ignore",
263
+ stderr: "pipe",
264
+ signal: AbortSignal.timeout(36e4)
265
+ }) : void 0;
266
+ const installerStderr = installer ? boundedStderr(installer.stderr).catch(() => "") : void 0;
267
+ let app = viaInstaller ? void 0 : spawnApp(), guardedPid;
268
+ stage(viaInstaller ? "installer-started" : "updated-app-started");
269
+ try {
270
+ let deadline = Date.now() + 15e4;
271
+ let granted = false;
272
+ while (Date.now() < deadline) {
273
+ if (installer && installer.exitCode !== null && installer.exitCode !== 0) {
274
+ const error = installerErrorName(await Promise.race([installerStderr, Bun.sleep(2e3).then(() => "")]));
275
+ 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"})`);
276
+ }
277
+ const ready = await exists(worker) && await exists(launcher) && await exists(join(resources, "version.json"));
278
+ if (installer && shouldLaunchInstalledApp({
279
+ platform: options.platform,
280
+ ready,
281
+ launched: app !== void 0,
282
+ acknowledged: await exists(ack),
283
+ installerExit: installer.exitCode
284
+ })) {
285
+ if (!launchRecord || !expectedApp || !await exists(launchRecord) || await readFile(launchRecord, "utf8") !== expectedApp + "\n") throw new Error("Installer launch request mismatch");
286
+ app = spawnApp();
287
+ }
288
+ if (await exists(ack) && !granted) {
289
+ stage("worker-acknowledged");
290
+ if (await readFile(ack, "utf8") !== nonce + "\n") throw new Error("Worker guard acknowledgement mismatch");
291
+ const record = await readFile(pidRecord, "utf8"), match = /^([a-f0-9]{48})\n([1-9]\d{0,9})\n$/.exec(record);
292
+ if (!match || match[1] !== nonce || Number(match[2]) < 2 || Number(match[2]) === process.pid) throw new Error("Worker process identity mismatch");
293
+ guardedPid = Number(match[2]);
294
+ await installedPayload(run.version, run.archive);
295
+ if (viaInstaller) await installerUnchanged();
296
+ stage("installed-files-verified");
297
+ await writeFile(permit, nonce + "\n", {
298
+ flag: "wx",
299
+ mode: 384
300
+ });
301
+ granted = true;
302
+ deadline = Date.now() + 9e4;
303
+ stage("worker-permitted");
304
+ }
305
+ if (granted && await exists(observation)) break;
306
+ await Bun.sleep(250);
307
+ }
308
+ const observed = await exists(observation);
309
+ const unexpectedObserved = await exists(unexpected);
310
+ if (!granted || !observed || unexpectedObserved) {
311
+ let workerState = "unknown";
312
+ if (guardedPid !== void 0) try {
313
+ process.kill(guardedPid, 0);
314
+ workerState = "present";
315
+ } catch (error) {
316
+ workerState = error.code === "ESRCH" ? "exited" : "unknown";
317
+ }
318
+ const appState = app ? app.exitCode ?? "running" : mac ? "not-spawned" : "installer-launched";
319
+ throw new Error(`Installed renderer observation missing or unexpected activity observed (start=${run.start}, permitted=${granted}, observed=${observed}, unexpected=${unexpectedObserved}, workerPid=${workerState}, installerExit=${installer ? installer.exitCode ?? "running" : "none"}, appExit=${appState})`);
320
+ }
321
+ stage("renderer-observed");
322
+ if (installer) {
323
+ const installerDeadline = Date.now() + 3e4;
324
+ while (installer.exitCode === null && Date.now() < installerDeadline) await Bun.sleep(250);
325
+ if (installer.exitCode !== 0) {
326
+ const error = installer.exitCode === null ? void 0 : installerErrorName(await Promise.race([installerStderr, Bun.sleep(2e3).then(() => "")]));
327
+ throw new Error(`Installer did not complete successfully (exit=${installer.exitCode ?? "running"}, error=${error ?? "none"})`);
328
+ }
329
+ stage("installer-completed");
330
+ }
331
+ const proof = await boundedJson(observation);
332
+ if (typeof proof !== "object" || proof === null || Array.isArray(proof)) throw new Error("Invalid renderer observation");
333
+ const { nonce: proofNonce, origin: proofOrigin, blockedReads, unexpectedActivity, offlinePolicy: proofPolicy, bootstrapDenied, ...metrics } = proof;
334
+ assertInstallerRendererObservation(metrics, Boolean(policy));
335
+ if (proofNonce !== nonce || proofOrigin !== origin || !Number.isSafeInteger(blockedReads) || Number(blockedReads) < 0 || unexpectedActivity !== false) throw new Error("Renderer observation identity mismatch");
336
+ 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");
337
+ await Bun.sleep(3e3);
338
+ if (await exists(unexpected) || foreignHits !== 0 || !(await fetch(origin + "/", {
339
+ signal: AbortSignal.timeout(1e3),
340
+ redirect: "error"
341
+ })).ok) throw new Error("Installed app did not remain available");
342
+ await installedPayload(run.version, run.archive);
343
+ if (viaInstaller) await installerUnchanged();
344
+ if (await exists(unexpected) || foreignHits !== 0) throw new Error("Unexpected activity after renderer observation");
345
+ if (guardedPid === void 0) throw new Error("Missing guarded process identity");
346
+ await terminateGuardedWorker({
347
+ pid: guardedPid,
348
+ runtime,
349
+ platform: options.platform,
350
+ env
351
+ });
352
+ guardedPid = void 0;
353
+ stage("worker-cleaned");
354
+ const evidence = policy ? {
355
+ method: "native-dom-raf-v2",
356
+ origin,
357
+ samples: metrics.samples,
358
+ guardInstalled: true,
359
+ bootstrapDenied: Boolean(bootstrapDenied),
360
+ offlineObserved: true,
361
+ unexpectedActivity: false,
362
+ elapsedMs: metrics.elapsedMs,
363
+ visible: metrics.visible,
364
+ readyState: metrics.readyState,
365
+ width: metrics.width,
366
+ height: metrics.height,
367
+ interactiveElements: metrics.interactiveElements,
368
+ textLength: metrics.textLength,
369
+ markerObserved: metrics.markerObserved,
370
+ browserNetworkRestricted: metrics.foreignBlocked === true && foreignHits === 0,
371
+ offlinePolicy: policy
372
+ } : void 0;
373
+ return {
374
+ metrics,
375
+ blockedReads: Number(blockedReads),
376
+ ...evidence ? { evidence } : {}
377
+ };
378
+ } finally {
379
+ for (const child of [installer, app]) if (child && child.exitCode === null) try {
380
+ child.kill("SIGKILL");
381
+ } catch {}
382
+ if (guardedPid !== void 0) try {
383
+ await terminateGuardedWorker({
384
+ pid: guardedPid,
385
+ runtime,
386
+ platform: options.platform,
387
+ env
388
+ });
389
+ } catch {}
390
+ }
391
+ }
392
+ let origin = "";
393
+ try {
394
+ origin = `http://127.0.0.1:${await choosePort()}`;
395
+ const installed = await observeRun({
396
+ directory: prepared.directory,
397
+ version: options.version,
398
+ archive: options.archive,
399
+ start: "installer"
400
+ });
401
+ const result = {
402
+ directory: prepared.directory,
403
+ observation: installed.metrics,
404
+ blockedReads: installed.blockedReads,
405
+ artifacts: [before.installer, before.archive],
406
+ ...installed.evidence ? { evidence: installed.evidence } : {}
407
+ };
408
+ if (!options.update) {
409
+ stage("observation-complete");
410
+ return result;
411
+ }
412
+ const update = options.update;
413
+ const target = mac ? dirname(installedRoot) : installedRoot;
414
+ const staged = await stageUpdateSwap({
415
+ descriptor: update.descriptor,
416
+ trust: update.trust,
417
+ currentVersion: options.version,
418
+ approved: true,
419
+ approvedVersion: update.descriptor.version,
420
+ target,
421
+ appName: options.appName,
422
+ platform: options.platform,
423
+ renderer: options.renderer,
424
+ archive: update.archive,
425
+ maxCompressedBytes: update.maxCompressedBytes,
426
+ maxExpandedBytes: update.maxExpandedBytes,
427
+ sidecars
428
+ });
429
+ stage("update-staged");
430
+ await swapAfterExit(target, staged.staging);
431
+ stage("update-swapped");
432
+ await preflightInstallerRuntime({
433
+ env: parent,
434
+ runtime,
435
+ bootstrap
436
+ });
437
+ const directory = join(prepared.directory, "update");
438
+ await mkdir(directory, { mode: 448 });
439
+ const updated = await observeRun({
440
+ directory,
441
+ version: staged.version,
442
+ archive: update.archive,
443
+ start: "launcher"
444
+ });
445
+ stage("observation-complete");
446
+ return {
447
+ ...result,
448
+ updated: {
449
+ version: staged.version,
450
+ observation: updated.metrics,
451
+ blockedReads: updated.blockedReads,
452
+ ...updated.evidence ? { evidence: updated.evidence } : {}
453
+ }
454
+ };
455
+ } finally {
456
+ sentinel?.stop(true);
457
+ }
458
+ }
459
+ /** The terminated app's processes can hold its files briefly, most visibly on Windows. */
460
+ async function swapAfterExit(target, staging) {
461
+ const deadline = Date.now() + 6e4;
462
+ for (;;) try {
463
+ await swapUpdateTree({
464
+ target,
465
+ staging
466
+ });
467
+ return;
468
+ } catch (error) {
469
+ if (Date.now() > deadline) throw error;
470
+ await Bun.sleep(500);
471
+ }
472
+ }
473
+ export { installerErrorName, observeInstalledApp, shouldLaunchInstalledApp };
@@ -0,0 +1,18 @@
1
+ import { type InstallerPlatform } from './installer-layout';
2
+ /** Terminate only the verified app runtime process on a disposable runner. */
3
+ export declare function terminateGuardedWorker(options: {
4
+ pid: number;
5
+ runtime: string;
6
+ platform: InstallerPlatform;
7
+ env: Record<string, string | undefined>;
8
+ }): Promise<void>;
9
+ declare const EXITING: unique symbol;
10
+ /**
11
+ * Read one `ps -o stat= -o comm=` line. macOS reports the command of a process that is
12
+ * exiting (`E`) or an unreaped zombie (`Z`) as `(bun)` or `<defunct>`, not an executable
13
+ * path. A zombie has already exited and cannot be killed; an exiting process is pending.
14
+ */
15
+ export declare function macosProcess(line: string): string | typeof EXITING | undefined;
16
+ /** An absent or zombie process has exited; an exiting process is still pending. */
17
+ export declare function macosWorkerExited(readState: () => Promise<string | undefined>): Promise<boolean>;
18
+ export {};