@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,80 @@
1
+ // src/updates/release-location.ts
2
+ /** `value` as a URL inside `scope`: the same https origin, under its path prefix, with no
3
+ * credentials, port, fragment or dot segments. */
4
+ function releaseUrl(value, scope) {
5
+ const url = new URL(value);
6
+ if (url.protocol !== "https:" || url.origin !== scope.origin || url.port || url.username || url.password || url.hash || !url.pathname.startsWith(scope.pathname) || /(?:^|\/)\.{1,2}(?:\/|$)|%2e|%2f|%5c/i.test(url.pathname)) throw new Error("Untrusted release location");
7
+ return url;
8
+ }
9
+ /** GET a release feed object without credentials, following at most five redirects that
10
+ * stay under `scope`, the app's feed URL. The caller reads or cancels the response body. */
11
+ async function fetchReleaseLocation(location, scope, fetcher, signal) {
12
+ const root = new URL(scope);
13
+ if (root.protocol !== "https:" || root.href !== scope || !root.pathname.endsWith("/") || root.search || root.hash) throw new Error("Untrusted release location");
14
+ let url = releaseUrl(location, root);
15
+ for (let redirects = 0;; redirects++) {
16
+ const response = await fetcher(url, {
17
+ method: "GET",
18
+ redirect: "manual",
19
+ credentials: "omit",
20
+ headers: { "accept-encoding": "identity" },
21
+ signal
22
+ });
23
+ if (![
24
+ 301,
25
+ 302,
26
+ 303,
27
+ 307,
28
+ 308
29
+ ].includes(response.status)) return response;
30
+ const next = response.headers.get("location");
31
+ await response.body?.cancel();
32
+ if (!next || redirects === 5) throw new Error("Invalid release redirect");
33
+ url = releaseUrl(new URL(next, url).href, root);
34
+ }
35
+ }
36
+ /** Read a 200 response body of at most `maximum` bytes. */
37
+ async function readReleaseBytes(response, maximum) {
38
+ if (response.status !== 200 || !response.body) {
39
+ await response.body?.cancel();
40
+ throw new Error("Release feed request failed");
41
+ }
42
+ const length = response.headers.get("content-length");
43
+ if (length !== null && (!/^\d+$/.test(length) || Number(length) > maximum)) {
44
+ await response.body.cancel();
45
+ throw new Error("Release feed response exceeds bound");
46
+ }
47
+ const reader = response.body.getReader(), chunks = [];
48
+ let total = 0;
49
+ try {
50
+ for (;;) {
51
+ const { value, done } = await reader.read();
52
+ if (done) break;
53
+ total += value.length;
54
+ if (total > maximum) {
55
+ await reader.cancel();
56
+ throw new Error("Release feed response exceeds bound");
57
+ }
58
+ chunks.push(value);
59
+ }
60
+ } finally {
61
+ reader.releaseLock();
62
+ }
63
+ const bytes = new Uint8Array(total);
64
+ let offset = 0;
65
+ for (const chunk of chunks) {
66
+ bytes.set(chunk, offset);
67
+ offset += chunk.length;
68
+ }
69
+ return bytes;
70
+ }
71
+ /** Parse a 200 response of at most `maximum` bytes as UTF-8 JSON. */
72
+ async function readReleaseJson(response, maximum) {
73
+ const bytes = await readReleaseBytes(response, maximum);
74
+ try {
75
+ return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
76
+ } catch {
77
+ throw new Error("Invalid release feed response");
78
+ }
79
+ }
80
+ export { fetchReleaseLocation, readReleaseBytes, readReleaseJson };
@@ -0,0 +1,12 @@
1
+ /** The update channel an installation follows. */
2
+ export type UpdateChannel = 'stable' | 'pre-release' | 'dev';
3
+ export declare function isUpdateChannel(value: unknown): value is UpdateChannel;
4
+ /**
5
+ * Semver ordering for everything the update grammar produces: `x.y.z` and the
6
+ * dev builds `x.y.z-dev.N`. A dev build sorts below its own release
7
+ * (`0.75.0-dev.1 < 0.75.0`) and above every earlier release, which is why dev
8
+ * builds are numbered for the next unreleased version. The order is the same on
9
+ * every channel. Unparseable versions fall back to the historic numeric-triple
10
+ * comparison — a malformed version must never wedge the state machine.
11
+ */
12
+ export declare function versionLessThan(a: string, b: string): boolean;
@@ -0,0 +1,43 @@
1
+ // src/updates/release-version.ts
2
+ function isUpdateChannel(value) {
3
+ return value === "stable" || value === "pre-release" || value === "dev";
4
+ }
5
+ /**
6
+ * Parse a version in the update grammar into `[major, minor, patch, dev]`,
7
+ * where a release carries no dev counter and sorts after every dev build of
8
+ * its own triple. Components use exact integers, including the dev counter.
9
+ * Unparseable versions return null so the caller can fall back.
10
+ */
11
+ function parseUpdateVersion(version) {
12
+ const match = /^v?(\d+)\.(\d+)\.(\d+)(?:-dev\.(\d+))?$/.exec(version.trim());
13
+ if (!match) return null;
14
+ return [
15
+ BigInt(match[1]),
16
+ BigInt(match[2]),
17
+ BigInt(match[3]),
18
+ match[4] === void 0 ? null : BigInt(match[4])
19
+ ];
20
+ }
21
+ /**
22
+ * Semver ordering for everything the update grammar produces: `x.y.z` and the
23
+ * dev builds `x.y.z-dev.N`. A dev build sorts below its own release
24
+ * (`0.75.0-dev.1 < 0.75.0`) and above every earlier release, which is why dev
25
+ * builds are numbered for the next unreleased version. The order is the same on
26
+ * every channel. Unparseable versions fall back to the historic numeric-triple
27
+ * comparison — a malformed version must never wedge the state machine.
28
+ */
29
+ function versionLessThan(a, b) {
30
+ const pa = parseUpdateVersion(a);
31
+ const pb = parseUpdateVersion(b);
32
+ if (pa && pb) {
33
+ for (let i = 0; i < 3; i++) if (pa[i] !== pb[i]) return pa[i] < pb[i];
34
+ if (pa[3] === null) return false;
35
+ if (pb[3] === null) return true;
36
+ return pa[3] < pb[3];
37
+ }
38
+ const fallbackA = a.replace(/^v/, "").split(".").map((n) => parseInt(n, 10) || 0);
39
+ const fallbackB = b.replace(/^v/, "").split(".").map((n) => parseInt(n, 10) || 0);
40
+ for (let i = 0; i < 3; i++) if ((fallbackB[i] ?? 0) !== (fallbackA[i] ?? 0)) return (fallbackB[i] ?? 0) > (fallbackA[i] ?? 0);
41
+ return false;
42
+ }
43
+ export { isUpdateChannel, versionLessThan };
@@ -0,0 +1,63 @@
1
+ import { type KeyObject } from 'node:crypto';
2
+ export type ReleaseDescriptor = Readonly<{
3
+ schema: 2;
4
+ appId: string;
5
+ repository: string;
6
+ channel: 'dev' | 'daily' | 'stable';
7
+ tag: string;
8
+ version: string;
9
+ sourceSha: string;
10
+ workflowSha: string;
11
+ runId: string;
12
+ runAttempt: number;
13
+ platform: 'darwin' | 'win32' | 'linux';
14
+ arch: 'arm64' | 'x64';
15
+ asset: Readonly<{
16
+ name: string;
17
+ url: string;
18
+ size: number;
19
+ sha256: string;
20
+ }>;
21
+ keyId: string;
22
+ }>;
23
+ declare const verifiedBrand: unique symbol;
24
+ export type VerifiedRelease = ReleaseDescriptor & {
25
+ readonly [verifiedBrand]: true;
26
+ };
27
+ export type SignedRelease = Readonly<{
28
+ descriptor: ReleaseDescriptor;
29
+ signature: string;
30
+ }>;
31
+ export type ReleaseTrust = Readonly<{
32
+ appId: string;
33
+ repository: string;
34
+ channel: ReleaseDescriptor['channel'];
35
+ platform: ReleaseDescriptor['platform'];
36
+ arch: ReleaseDescriptor['arch'];
37
+ /** The app's release feed URL, ending in `/`; every asset URL is `<feed><tag>/<name>`. */
38
+ feed: string;
39
+ keys: ReadonlyMap<string, string>;
40
+ }>;
41
+ /** A GitHub `owner/name` slug that is safe to place in API and download paths. */
42
+ export declare function isRepositorySlug(value: string): boolean;
43
+ export declare function assertRepositorySlug(value: string): void;
44
+ /** Sign canonical release metadata with an application-owned Ed25519 private key. */
45
+ export declare function signReleaseDescriptor(descriptor: ReleaseDescriptor, privateKey: KeyObject): SignedRelease;
46
+ /** Authenticate the entire descriptor against an application-owned trust policy. */
47
+ export declare function verifyReleaseDescriptor(value: unknown, trust: ReleaseTrust): {
48
+ ok: true;
49
+ descriptor: VerifiedRelease;
50
+ } | {
51
+ ok: false;
52
+ };
53
+ /** A verified descriptor remains valid only in the process that authenticated it. */
54
+ export declare function isVerifiedRelease(value: unknown): value is VerifiedRelease;
55
+ /** Check that an authenticated descriptor used this exact application's current trust key. */
56
+ export declare function isVerifiedReleaseForTrust(value: unknown, trust: ReleaseTrust): value is VerifiedRelease;
57
+ /** Return the authenticated signed envelope for re-verification in another process. */
58
+ export declare function exportVerifiedRelease(value: VerifiedRelease, trust: ReleaseTrust): SignedRelease;
59
+ /** Check exact archive bytes after the descriptor has been authenticated. */
60
+ export declare function verifyReleaseBytes(bytes: Uint8Array, descriptor: VerifiedRelease): boolean;
61
+ /** Check a streamed archive without buffering the whole artifact. */
62
+ export declare function verifyReleaseStream(chunks: AsyncIterable<Uint8Array>, descriptor: VerifiedRelease): Promise<boolean>;
63
+ export {};
@@ -0,0 +1,162 @@
1
+ import { createHash, createPublicKey, sign, timingSafeEqual, verify } from "node:crypto";
2
+ // src/updates/signed-release.ts
3
+ var verifiedDescriptors = /* @__PURE__ */ new WeakMap();
4
+ /** A GitHub `owner/name` slug that is safe to place in API and download paths. */
5
+ function isRepositorySlug(value) {
6
+ return /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(value) && value.length <= 200 && value.split("/").every((part) => part !== "." && part !== "..");
7
+ }
8
+ function assertRepositorySlug(value) {
9
+ if (!isRepositorySlug(value)) throw new Error("Invalid GitHub repository");
10
+ }
11
+ var keys = [
12
+ "schema",
13
+ "appId",
14
+ "repository",
15
+ "channel",
16
+ "tag",
17
+ "version",
18
+ "sourceSha",
19
+ "workflowSha",
20
+ "runId",
21
+ "runAttempt",
22
+ "platform",
23
+ "arch",
24
+ "asset",
25
+ "keyId"
26
+ ];
27
+ var assetKeys = [
28
+ "name",
29
+ "url",
30
+ "size",
31
+ "sha256"
32
+ ];
33
+ var record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
34
+ var exactKeys = (value, expected) => Object.keys(value).length === expected.length && expected.every((key) => Object.hasOwn(value, key));
35
+ function valid(value) {
36
+ if (!record(value) || !exactKeys(value, keys) || !record(value.asset) || !exactKeys(value.asset, assetKeys)) return false;
37
+ if (value.schema !== 2 || typeof value.appId !== "string" || !/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/.test(value.appId) || value.appId.length > 255) return false;
38
+ if (typeof value.repository !== "string" || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(value.repository) || value.repository.length > 200) return false;
39
+ if (value.channel !== "dev" && value.channel !== "daily" && value.channel !== "stable") return false;
40
+ if (typeof value.version !== "string" || value.version.length > 64 || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(value.version) || value.tag !== `v${value.version}` || value.channel === "dev" !== /-dev\.\d+$/.test(value.version)) return false;
41
+ if (typeof value.sourceSha !== "string" || !/^[a-f0-9]{40}$/.test(value.sourceSha) || typeof value.workflowSha !== "string" || !/^[a-f0-9]{40}$/.test(value.workflowSha)) return false;
42
+ if (typeof value.runId !== "string" || !/^[1-9]\d{0,19}$/.test(value.runId) || !Number.isSafeInteger(value.runAttempt) || Number(value.runAttempt) < 1) return false;
43
+ if (![
44
+ "darwin",
45
+ "win32",
46
+ "linux"
47
+ ].includes(String(value.platform)) || !["arm64", "x64"].includes(String(value.arch))) return false;
48
+ if (typeof value.keyId !== "string" || !/^[a-z0-9][a-z0-9._-]{0,63}$/.test(value.keyId)) return false;
49
+ const asset = value.asset;
50
+ if (typeof asset.name !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,199}$/.test(asset.name) || typeof asset.url !== "string" || asset.url.length > 2048 || typeof asset.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(asset.sha256) || !Number.isSafeInteger(asset.size) || Number(asset.size) < 1) return false;
51
+ try {
52
+ const url = new URL(asset.url);
53
+ return url.protocol === "https:" && url.href === asset.url && !url.port && !url.username && !url.password && !url.search && !url.hash && url.pathname.endsWith(`/${value.tag}/${asset.name}`);
54
+ } catch {
55
+ return false;
56
+ }
57
+ }
58
+ /** Whether the asset URL is exactly this release's object in the trusted feed. */
59
+ var inFeed = (value, feed) => typeof feed === "string" && feed.startsWith("https://") && feed.endsWith("/") && value.asset.url === `${feed}${value.tag}/${value.asset.name}`;
60
+ function message(value) {
61
+ return Buffer.from(JSON.stringify([
62
+ "adea-app-framework-release-v2",
63
+ value.schema,
64
+ value.appId,
65
+ value.repository,
66
+ value.channel,
67
+ value.tag,
68
+ value.version,
69
+ value.sourceSha,
70
+ value.workflowSha,
71
+ value.runId,
72
+ value.runAttempt,
73
+ value.platform,
74
+ value.arch,
75
+ value.asset.name,
76
+ value.asset.url,
77
+ value.asset.size,
78
+ value.asset.sha256,
79
+ value.keyId
80
+ ]), "utf8");
81
+ }
82
+ /** Sign canonical release metadata with an application-owned Ed25519 private key. */
83
+ function signReleaseDescriptor(descriptor, privateKey) {
84
+ if (!valid(descriptor) || privateKey.type !== "private" || privateKey.asymmetricKeyType !== "ed25519") throw new Error("Invalid release descriptor or signing key");
85
+ return {
86
+ descriptor,
87
+ signature: sign(null, message(descriptor), privateKey).toString("base64url")
88
+ };
89
+ }
90
+ /** Authenticate the entire descriptor against an application-owned trust policy. */
91
+ function verifyReleaseDescriptor(value, trust) {
92
+ try {
93
+ if (!record(value) || !exactKeys(value, ["descriptor", "signature"]) || typeof value.signature !== "string" || !/^[A-Za-z0-9_-]{86}$/.test(value.signature)) return { ok: false };
94
+ if (!valid(value.descriptor)) return { ok: false };
95
+ const descriptor = structuredClone(value.descriptor);
96
+ if (!valid(descriptor)) return { ok: false };
97
+ if (descriptor.appId !== trust.appId || descriptor.repository !== trust.repository || descriptor.channel !== trust.channel || descriptor.platform !== trust.platform || descriptor.arch !== trust.arch || !inFeed(descriptor, trust.feed)) return { ok: false };
98
+ const encoded = trust.keys.get(descriptor.keyId);
99
+ if (!encoded) return { ok: false };
100
+ const raw = Buffer.from(encoded, "base64");
101
+ const signature = Buffer.from(value.signature, "base64url");
102
+ if (raw.length !== 32 || signature.length !== 64 || signature.toString("base64url") !== value.signature) return { ok: false };
103
+ const key = createPublicKey({
104
+ key: Buffer.concat([Buffer.from("302a300506032b6570032100", "hex"), raw]),
105
+ format: "der",
106
+ type: "spki"
107
+ });
108
+ if (!verify(null, message(descriptor), key, signature)) return { ok: false };
109
+ Object.freeze(descriptor.asset);
110
+ Object.freeze(descriptor);
111
+ verifiedDescriptors.set(descriptor, {
112
+ key: encoded,
113
+ signature: value.signature
114
+ });
115
+ return {
116
+ ok: true,
117
+ descriptor
118
+ };
119
+ } catch {
120
+ return { ok: false };
121
+ }
122
+ }
123
+ /** A verified descriptor remains valid only in the process that authenticated it. */
124
+ function isVerifiedRelease(value) {
125
+ return typeof value === "object" && value !== null && verifiedDescriptors.has(value);
126
+ }
127
+ /** Check that an authenticated descriptor used this exact application's current trust key. */
128
+ function isVerifiedReleaseForTrust(value, trust) {
129
+ return isVerifiedRelease(value) && value.appId === trust.appId && value.repository === trust.repository && value.channel === trust.channel && value.platform === trust.platform && value.arch === trust.arch && inFeed(value, trust.feed) && verifiedDescriptors.get(value)?.key === trust.keys.get(value.keyId);
130
+ }
131
+ /** Return the authenticated signed envelope for re-verification in another process. */
132
+ function exportVerifiedRelease(value, trust) {
133
+ if (!isVerifiedReleaseForTrust(value, trust)) throw new Error("Untrusted release descriptor");
134
+ return Object.freeze({
135
+ descriptor: value,
136
+ signature: verifiedDescriptors.get(value).signature
137
+ });
138
+ }
139
+ /** Check exact archive bytes after the descriptor has been authenticated. */
140
+ function verifyReleaseBytes(bytes, descriptor) {
141
+ if (!(bytes instanceof Uint8Array) || !verifiedDescriptors.has(descriptor) || bytes.byteLength !== descriptor.asset.size) return false;
142
+ const actual = createHash("sha256").update(bytes).digest();
143
+ return timingSafeEqual(actual, Buffer.from(descriptor.asset.sha256, "hex"));
144
+ }
145
+ /** Check a streamed archive without buffering the whole artifact. */
146
+ async function verifyReleaseStream(chunks, descriptor) {
147
+ if (!verifiedDescriptors.has(descriptor)) return false;
148
+ const hash = createHash("sha256");
149
+ let size = 0;
150
+ try {
151
+ for await (const chunk of chunks) {
152
+ if (!(chunk instanceof Uint8Array)) return false;
153
+ size += chunk.byteLength;
154
+ if (!Number.isSafeInteger(size) || size > descriptor.asset.size) return false;
155
+ hash.update(chunk);
156
+ }
157
+ return size === descriptor.asset.size && timingSafeEqual(hash.digest(), Buffer.from(descriptor.asset.sha256, "hex"));
158
+ } catch {
159
+ return false;
160
+ }
161
+ }
162
+ export { assertRepositorySlug, exportVerifiedRelease, isRepositorySlug, isVerifiedRelease, isVerifiedReleaseForTrust, signReleaseDescriptor, verifyReleaseBytes, verifyReleaseDescriptor, verifyReleaseStream };
@@ -0,0 +1,10 @@
1
+ import type { Stats } from 'node:fs';
2
+ import { type FileHandle } from 'node:fs/promises';
3
+ /** Whether two stats describe the same, unmodified file. */
4
+ export declare function sameFile(left: Stats, right: Stats): boolean;
5
+ /** Open the regular file `info` (from lstat) described, without following a link or
6
+ * blocking on a FIFO, and only if it has not been swapped or modified since. */
7
+ export declare function openUnchangedFile(path: string, info: Stats, message: string): Promise<{
8
+ file: FileHandle;
9
+ before: Stats;
10
+ }>;
@@ -0,0 +1,22 @@
1
+ import { open } from "node:fs/promises";
2
+ import { constants as constants$1 } from "node:fs";
3
+ // src/updates/stable-file.ts
4
+ /** Whether two stats describe the same, unmodified file. */
5
+ function sameFile(left, right) {
6
+ return left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs;
7
+ }
8
+ /** Open the regular file `info` (from lstat) described, without following a link or
9
+ * blocking on a FIFO, and only if it has not been swapped or modified since. */
10
+ async function openUnchangedFile(path, info, message) {
11
+ const file = await open(path, constants$1.O_RDONLY | (constants$1.O_NOFOLLOW ?? 0) | (constants$1.O_NONBLOCK ?? 0));
12
+ const before = await file.stat();
13
+ if (!before.isFile() || !sameFile(before, info)) {
14
+ await file.close();
15
+ throw new Error(message);
16
+ }
17
+ return {
18
+ file,
19
+ before
20
+ };
21
+ }
22
+ export { openUnchangedFile, sameFile };
@@ -0,0 +1,57 @@
1
+ import type { UpdateAdapter, UpdateChannel, UpdateState } from '@adea-ai/ui/components/composites/update-dialog';
2
+ export type { UpdateAdapter, UpdateChannel, UpdateState };
3
+ /** Channel persistence as a `read`/`persist` pair. */
4
+ export type UpdateChannelStore = Readonly<{
5
+ read(): Promise<UpdateChannel>;
6
+ /** Persist a selection; resolves with the channel that actually stuck. */
7
+ persist(channel: UpdateChannel): Promise<UpdateChannel>;
8
+ }>;
9
+ /** Channel persistence as a service exposing `channel`/`setChannel`. */
10
+ export type UpdateChannelService = Readonly<{
11
+ channel(): Promise<UpdateChannel>;
12
+ setChannel(channel: UpdateChannel): Promise<UpdateChannel>;
13
+ }>;
14
+ /** Either channel shape the update surface accepts. */
15
+ export type UpdateChannelSource = UpdateChannelStore | UpdateChannelService;
16
+ /** Normalize either channel shape to `read`/`persist`. */
17
+ export declare function updateChannelStore(source: UpdateChannelSource): UpdateChannelStore;
18
+ /**
19
+ * Report every snapshot the updater answers with, for a pending-update badge that
20
+ * must not run a second checker. The wrapped adapter otherwise behaves identically.
21
+ */
22
+ export declare function mirrorUpdateState(adapter: UpdateAdapter, onState: (state: UpdateState) => void): UpdateAdapter;
23
+ /** A native updater snapshot in snake_case, as Rust and older desktop hosts report it. */
24
+ export type NativeUpdateSnapshot = Readonly<{
25
+ available_version: string | null;
26
+ changelog: string;
27
+ current_version: string;
28
+ downloaded_bytes: number;
29
+ error: string | null;
30
+ github_url: string | null;
31
+ phase: UpdateState['phase'];
32
+ release_date: string | null;
33
+ release_notes?: string | null;
34
+ restart_required: boolean;
35
+ total_bytes: number | null;
36
+ }>;
37
+ /** A native updater that answers with snake_case snapshots. */
38
+ export type NativeUpdateAdapter = Readonly<{
39
+ check(): Promise<NativeUpdateSnapshot>;
40
+ getStatus(): Promise<NativeUpdateSnapshot>;
41
+ install(expectedVersion: string): Promise<NativeUpdateSnapshot>;
42
+ isDesktopRuntime(): boolean;
43
+ pollIntervalMs?: number;
44
+ }>;
45
+ /** Map a snake_case native snapshot to the shared update state. */
46
+ export declare function updateStateFromNative(update: NativeUpdateSnapshot, options?: {
47
+ releaseNotes?: boolean;
48
+ }): UpdateState;
49
+ /**
50
+ * Bridge a snake_case native updater to the shared adapter. Release notes are dropped
51
+ * unless requested, which keeps the dialog's per-release notes section hidden.
52
+ */
53
+ export declare function nativeUpdateAdapter(native: NativeUpdateAdapter | (() => NativeUpdateAdapter), options?: {
54
+ releaseNotes?: boolean;
55
+ }): UpdateAdapter;
56
+ /** The adapter for a build with no installer: the dialog explains updates are desktop-only. */
57
+ export declare function browserUpdateAdapter(currentVersion?: string): UpdateAdapter;
@@ -0,0 +1,72 @@
1
+ // src/updates/update-adapter.ts
2
+ /** Normalize either channel shape to `read`/`persist`. */
3
+ function updateChannelStore(source) {
4
+ if ("read" in source) return source;
5
+ return {
6
+ read: () => source.channel(),
7
+ persist: (channel) => source.setChannel(channel)
8
+ };
9
+ }
10
+ /**
11
+ * Report every snapshot the updater answers with, for a pending-update badge that
12
+ * must not run a second checker. The wrapped adapter otherwise behaves identically.
13
+ */
14
+ function mirrorUpdateState(adapter, onState) {
15
+ const note = async (pending) => {
16
+ const state = await pending;
17
+ onState(state);
18
+ return state;
19
+ };
20
+ const cancel = adapter.cancel;
21
+ return {
22
+ ...adapter,
23
+ check: () => note(adapter.check()),
24
+ getStatus: () => note(adapter.getStatus()),
25
+ install: (expectedVersion) => note(adapter.install(expectedVersion)),
26
+ ...cancel ? { cancel: () => note(cancel.call(adapter)) } : {}
27
+ };
28
+ }
29
+ /** Map a snake_case native snapshot to the shared update state. */
30
+ function updateStateFromNative(update, options = {}) {
31
+ return {
32
+ availableVersion: update.available_version,
33
+ changelog: update.changelog,
34
+ currentVersion: update.current_version,
35
+ downloadedBytes: update.downloaded_bytes,
36
+ error: update.error,
37
+ phase: update.phase,
38
+ releaseDate: update.release_date,
39
+ releaseNotes: options.releaseNotes ? update.release_notes ?? null : null,
40
+ releaseUrl: update.github_url,
41
+ restartRequired: update.restart_required,
42
+ totalBytes: update.total_bytes
43
+ };
44
+ }
45
+ /**
46
+ * Bridge a snake_case native updater to the shared adapter. Release notes are dropped
47
+ * unless requested, which keeps the dialog's per-release notes section hidden.
48
+ */
49
+ function nativeUpdateAdapter(native, options = {}) {
50
+ const current = typeof native === "function" ? native : () => native;
51
+ return {
52
+ check: async () => updateStateFromNative(await current().check(), options),
53
+ getStatus: async () => updateStateFromNative(await current().getStatus(), options),
54
+ install: async (expectedVersion) => updateStateFromNative(await current().install(expectedVersion), options),
55
+ isDesktopRuntime: () => current().isDesktopRuntime(),
56
+ pollIntervalMs: current().pollIntervalMs
57
+ };
58
+ }
59
+ /** The adapter for a build with no installer: the dialog explains updates are desktop-only. */
60
+ function browserUpdateAdapter(currentVersion = "") {
61
+ const state = {
62
+ phase: "unavailable",
63
+ currentVersion
64
+ };
65
+ return {
66
+ check: async () => state,
67
+ getStatus: async () => state,
68
+ install: async () => state,
69
+ isDesktopRuntime: () => false
70
+ };
71
+ }
72
+ export { browserUpdateAdapter, mirrorUpdateState, nativeUpdateAdapter, updateChannelStore, updateStateFromNative };
@@ -0,0 +1,24 @@
1
+ import type { UpdateHelperRequest } from './update-helper';
2
+ /**
3
+ * Start the post-exit update helper for a staged update, then resolve once the
4
+ * helper has verified this app's processes. The helper runs from copies of the
5
+ * app's Bun runtime and bundled helper script inside the private staging
6
+ * directory, because the install tree is about to move.
7
+ *
8
+ * Use it as the `arm` step of `scheduleUpdateShutdown`: quit only after it
9
+ * resolves, and call `cancel()` if the quit is vetoed.
10
+ */
11
+ export declare function armUpdateHelper(options: {
12
+ target: string;
13
+ platform: UpdateHelperRequest['platform'];
14
+ version: string;
15
+ /** Absolute path of the bundled helper script shipped with the app. */
16
+ helperScript: string;
17
+ /** Processes that must exit before the swap. Defaults to this process and its launcher parent. */
18
+ processes?: UpdateHelperRequest['processes'];
19
+ processTimeoutMs?: number;
20
+ armTimeoutMs?: number;
21
+ env?: Record<string, string | undefined>;
22
+ }): Promise<{
23
+ cancel(): Promise<void>;
24
+ }>;
@@ -0,0 +1,95 @@
1
+ import { updateStagingFor } from "./update-swap.js";
2
+ import { updateLauncherPath } from "./update-launch.js";
3
+ import { copyFile, lstat, mkdir, realpath, rm, unlink, writeFile } from "node:fs/promises";
4
+ import { basename, dirname, isAbsolute, join, resolve } from "node:path";
5
+ import { spawn } from "node:child_process";
6
+ // src/updates/update-arm.ts
7
+ function exited(child) {
8
+ return child.exitCode !== null || child.signalCode !== null;
9
+ }
10
+ /** The Bun runtime inside an installed app tree, which the helper copy runs on. */
11
+ function updateRuntimePath(platform, target) {
12
+ const launcher = updateLauncherPath(platform, target);
13
+ return join(dirname(launcher), platform === "windows-x64" ? "bun.exe" : "bun");
14
+ }
15
+ /**
16
+ * Start the post-exit update helper for a staged update, then resolve once the
17
+ * helper has verified this app's processes. The helper runs from copies of the
18
+ * app's Bun runtime and bundled helper script inside the private staging
19
+ * directory, because the install tree is about to move.
20
+ *
21
+ * Use it as the `arm` step of `scheduleUpdateShutdown`: quit only after it
22
+ * resolves, and call `cancel()` if the quit is vetoed.
23
+ */
24
+ async function armUpdateHelper(options) {
25
+ const staging = updateStagingFor(options.target);
26
+ if (!isAbsolute(options.helperScript) || resolve(options.helperScript) !== options.helperScript) throw new Error("Invalid update helper script");
27
+ const info = await lstat(staging);
28
+ if (!info.isDirectory() || info.isSymbolicLink() || await realpath(staging) !== staging) throw new Error("Invalid update staging directory");
29
+ const helper = join(staging, "helper");
30
+ const runtime = join(helper, basename(updateRuntimePath(options.platform, options.target)));
31
+ const script = join(helper, "update-helper.js");
32
+ const request = {
33
+ schema: 1,
34
+ target: options.target,
35
+ platform: options.platform,
36
+ version: options.version,
37
+ processes: options.processes ?? [{
38
+ pid: process.pid,
39
+ executable: process.execPath
40
+ }, ...process.ppid > 1 ? [{
41
+ pid: process.ppid,
42
+ executable: updateLauncherPath(options.platform, options.target)
43
+ }] : []],
44
+ processTimeoutMs: options.processTimeoutMs ?? 3e4
45
+ };
46
+ const armed = join(staging, "helper-armed");
47
+ let child;
48
+ async function reset() {
49
+ if (child && !exited(child) && child.pid !== void 0) try {
50
+ process.kill(child.pid);
51
+ } catch {}
52
+ for (const name of ["request.json", "helper-armed"]) await unlink(join(staging, name)).catch(() => void 0);
53
+ await rm(helper, {
54
+ recursive: true,
55
+ force: true
56
+ });
57
+ }
58
+ try {
59
+ await mkdir(helper, { mode: 448 });
60
+ await copyFile(updateRuntimePath(options.platform, options.target), runtime);
61
+ await copyFile(options.helperScript, script);
62
+ await writeFile(join(staging, "request.json"), JSON.stringify(request) + "\n", {
63
+ flag: "wx",
64
+ mode: 384
65
+ });
66
+ const started = spawn(runtime, [
67
+ script,
68
+ "--staging",
69
+ staging
70
+ ], {
71
+ cwd: helper,
72
+ detached: true,
73
+ stdio: "ignore",
74
+ env: options.env ?? process.env,
75
+ windowsHide: true
76
+ });
77
+ child = started;
78
+ await new Promise((done, reject) => {
79
+ started.once("spawn", () => done());
80
+ started.once("error", reject);
81
+ });
82
+ started.unref();
83
+ const deadline = Date.now() + (options.armTimeoutMs ?? 15e3);
84
+ while (!await lstat(armed).catch(() => void 0)) {
85
+ if (exited(started)) throw new Error("Update helper exited before arming");
86
+ if (Date.now() >= deadline) throw new Error("Update helper did not arm in time");
87
+ await Bun.sleep(50);
88
+ }
89
+ } catch (error) {
90
+ await reset();
91
+ throw error;
92
+ }
93
+ return { cancel: reset };
94
+ }
95
+ export { armUpdateHelper };
@@ -0,0 +1,8 @@
1
+ import { type UpdateChannel } from './release-version';
2
+ /** Persist one app-owned update channel; the caller must supply a private state directory. */
3
+ export declare function createUpdateChannelStore(directory: string): {
4
+ read: () => Promise<UpdateChannel>;
5
+ save: (channel: UpdateChannel) => Promise<UpdateChannel>;
6
+ };
7
+ /** Shared UI uses pre-release; release descriptors use daily. */
8
+ export declare function releaseChannelForUpdate(channel: UpdateChannel): 'stable' | 'daily' | 'dev';