@adea-ai/app-framework 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +183 -17
  2. package/dist/app/create-application.d.ts +2 -0
  3. package/dist/app/create-application.js +6 -0
  4. package/dist/app/service-registry.js +4 -0
  5. package/dist/appearance/custom-theme-import.js +43 -7
  6. package/dist/appearance/custom-theme-library.d.ts +2 -0
  7. package/dist/appearance/custom-theme-library.js +5 -1
  8. package/dist/appearance/theme-record-adapter.js +4 -2
  9. package/dist/appearance/theme-registry.js +7 -1
  10. package/dist/cli/cef-helper-cli.js +0 -0
  11. package/dist/cli/create-application-cli.js +4 -2
  12. package/dist/cli/electrobun-shortcut-patch-cli.js +0 -0
  13. package/dist/cli/framework-update-cli.js +0 -0
  14. package/dist/cli/macos-signing-cli.js +0 -0
  15. package/dist/cli/release-assets-plan-cli.js +0 -0
  16. package/dist/cli/release-cut-cli.js +0 -0
  17. package/dist/cli/release-descriptor-staging-cli.js +0 -0
  18. package/dist/cli/release-finalize-cli.js +0 -0
  19. package/dist/cli/release-promote-cli.js +0 -0
  20. package/dist/cli/release-publish-cli.js +0 -0
  21. package/dist/cli/release-sign-cli.js +0 -0
  22. package/dist/cli/release-step-cli.js +6 -1
  23. package/dist/cli/toolchain-identity-cli.js +0 -0
  24. package/dist/cli/update-helper-cli.js +28 -6
  25. package/dist/cli/windows-runtime-patch-cli.js +0 -0
  26. package/dist/desktop/client-asset-manifest.d.ts +47 -0
  27. package/dist/desktop/client-asset-manifest.js +114 -0
  28. package/dist/desktop/client-asset-stream.d.ts +10 -0
  29. package/dist/desktop/client-asset-stream.js +138 -33
  30. package/dist/desktop/client-assets.d.ts +20 -0
  31. package/dist/desktop/client-assets.js +132 -22
  32. package/dist/desktop/client-response-lifecycle.d.ts +22 -0
  33. package/dist/desktop/client-response-lifecycle.js +233 -0
  34. package/dist/desktop/desktop-host.d.ts +40 -2
  35. package/dist/desktop/desktop-host.js +159 -9
  36. package/dist/framework-source.json +1 -1
  37. package/dist/installer/command-artifact.d.ts +4 -2
  38. package/dist/installer/command-artifact.js +119 -19
  39. package/dist/installer/installer-identity.d.ts +4 -1
  40. package/dist/installer/installer-identity.js +6 -3
  41. package/dist/installer/installer-layout.d.ts +2 -0
  42. package/dist/installer/installer-layout.js +5 -1
  43. package/dist/installer/linux-process-group.d.ts +13 -0
  44. package/dist/installer/linux-process-group.js +58 -0
  45. package/dist/native/darwin-sync.d.ts +7 -0
  46. package/dist/native/darwin-sync.js +43 -0
  47. package/dist/native/desktop-build-hook.js +7 -0
  48. package/dist/native/directory-exchange.d.ts +10 -0
  49. package/dist/native/directory-exchange.js +90 -0
  50. package/dist/native/electrobun-source-patch.d.ts +5 -0
  51. package/dist/native/electrobun-source-patch.js +19 -1
  52. package/dist/native/posix-launcher-build.d.ts +24 -0
  53. package/dist/native/posix-launcher-build.js +232 -0
  54. package/dist/native/posix-tree-removal.d.ts +36 -0
  55. package/dist/native/posix-tree-removal.js +425 -0
  56. package/dist/release/release-steps.d.ts +5 -0
  57. package/dist/release/release-steps.js +2 -1
  58. package/dist/update-helper.bundle.js +1483 -105
  59. package/dist/updates/channel-update-manager.d.ts +5 -0
  60. package/dist/updates/channel-update-manager.js +13 -1
  61. package/dist/updates/desktop-updater.d.ts +78 -2
  62. package/dist/updates/desktop-updater.js +320 -37
  63. package/dist/updates/launch-environment.d.ts +2 -0
  64. package/dist/updates/launch-environment.js +4 -0
  65. package/dist/updates/native-file-lock.d.ts +15 -0
  66. package/dist/updates/native-file-lock.js +189 -0
  67. package/dist/updates/packaged-launch-admission.d.ts +13 -0
  68. package/dist/updates/packaged-launch-admission.js +45 -0
  69. package/dist/updates/packaged-release-config.d.ts +18 -0
  70. package/dist/updates/packaged-release-config.js +60 -0
  71. package/dist/updates/packaged-update-startup.d.ts +44 -0
  72. package/dist/updates/packaged-update-startup.js +81 -0
  73. package/dist/updates/update-arm.d.ts +9 -8
  74. package/dist/updates/update-arm.js +227 -62
  75. package/dist/updates/update-cleanup-error.d.ts +23 -0
  76. package/dist/updates/update-cleanup-error.js +65 -0
  77. package/dist/updates/update-download-cleanup.d.ts +11 -0
  78. package/dist/updates/update-download-cleanup.js +112 -2
  79. package/dist/updates/update-download-lock.d.ts +20 -0
  80. package/dist/updates/update-download-lock.js +73 -0
  81. package/dist/updates/update-download.d.ts +2 -0
  82. package/dist/updates/update-download.js +7 -3
  83. package/dist/updates/update-generation-lease.d.ts +6 -0
  84. package/dist/updates/update-generation-lease.js +14 -0
  85. package/dist/updates/update-helper.d.ts +11 -2
  86. package/dist/updates/update-helper.js +322 -13
  87. package/dist/updates/update-inherited-launch-lease.d.ts +22 -0
  88. package/dist/updates/update-inherited-launch-lease.js +58 -0
  89. package/dist/updates/update-instance-lease.d.ts +15 -0
  90. package/dist/updates/update-instance-lease.js +25 -0
  91. package/dist/updates/update-launch-gate.d.ts +137 -0
  92. package/dist/updates/update-launch-gate.js +617 -0
  93. package/dist/updates/update-launch.js +3 -1
  94. package/dist/updates/update-lock.d.ts +12 -0
  95. package/dist/updates/update-lock.js +18 -0
  96. package/dist/updates/update-manager.d.ts +2 -0
  97. package/dist/updates/update-manager.js +9 -2
  98. package/dist/updates/update-marker.d.ts +7 -0
  99. package/dist/updates/update-marker.js +62 -0
  100. package/dist/updates/update-preflight-error.d.ts +7 -0
  101. package/dist/updates/update-preflight-error.js +11 -0
  102. package/dist/updates/update-process-fence.d.ts +4 -0
  103. package/dist/updates/update-process-fence.js +85 -73
  104. package/dist/updates/update-process-liveness.d.ts +2 -0
  105. package/dist/updates/update-process-liveness.js +11 -0
  106. package/dist/updates/update-resume.d.ts +37 -3
  107. package/dist/updates/update-resume.js +839 -23
  108. package/dist/updates/update-retention-marker.d.ts +67 -0
  109. package/dist/updates/update-retention-marker.js +165 -0
  110. package/dist/updates/update-retention-plan.d.ts +25 -0
  111. package/dist/updates/update-retention-plan.js +54 -0
  112. package/dist/updates/update-retention-sync.d.ts +34 -0
  113. package/dist/updates/update-retention-sync.js +83 -0
  114. package/dist/updates/update-retirement.d.ts +205 -0
  115. package/dist/updates/update-retirement.js +1485 -0
  116. package/dist/updates/update-shutdown.d.ts +16 -4
  117. package/dist/updates/update-shutdown.js +133 -8
  118. package/dist/updates/update-state-store.d.ts +58 -0
  119. package/dist/updates/update-state-store.js +139 -0
  120. package/dist/updates/update-swap-stage.d.ts +1 -1
  121. package/dist/updates/update-swap-stage.js +85 -14
  122. package/dist/updates/update-swap.d.ts +45 -2
  123. package/dist/updates/update-swap.js +207 -17
  124. package/package.json +31 -1
  125. package/src/appearance/custom-theme-import.ts +96 -14
  126. package/src/appearance/custom-theme-library.ts +5 -0
  127. package/src/appearance/theme-record-adapter.ts +15 -6
  128. package/src/appearance/theme-registry.ts +8 -1
  129. package/src/desktop/client-asset-manifest.ts +207 -0
  130. package/src/desktop/client-asset-stream.ts +193 -32
  131. package/src/desktop/client-assets.ts +210 -19
  132. package/src/desktop/client-response-lifecycle.ts +305 -0
  133. package/src/native/electrobun-posix-launch-lease.patch +398 -0
  134. package/templates/application/README.md +50 -0
  135. package/templates/application/electrobun.config.ts +5 -1
  136. package/templates/application/scripts/build-desktop.ts +4 -0
  137. package/templates/application/src/bun/index.ts +173 -16
  138. package/templates/application/vite.config.ts +112 -6
@@ -0,0 +1,232 @@
1
+ import { ELECTROBUN_COMMIT, PINNED_POSIX_LAUNCH_LEASE_PATCH, POSIX_LAUNCH_LEASE_PATCH_PATH, applyElectrobunPatch } from "./electrobun-source-patch.js";
2
+ import { chmod, copyFile, lstat, mkdir, mkdtemp, open, readFile, rename, rm } from "node:fs/promises";
3
+ import { basename, dirname, isAbsolute, join, resolve } from "node:path";
4
+ import { execFileSync, spawnSync } from "node:child_process";
5
+ import { createHash, randomUUID } from "node:crypto";
6
+ import { tmpdir } from "node:os";
7
+ // src/native/posix-launcher-build.ts
8
+ var POSIX_LAUNCH_LEASE_OPT_IN = "ADEA_ENABLE_POSIX_LAUNCH_LEASE";
9
+ var ELECTROBUN_BUILD_DIR = "ELECTROBUN_BUILD_DIR";
10
+ var ELECTROBUN_BUILD_ENV = "ELECTROBUN_BUILD_ENV";
11
+ var ELECTROBUN_OS = "ELECTROBUN_OS";
12
+ var ELECTROBUN_ARCH = "ELECTROBUN_ARCH";
13
+ var ELECTROBUN_APP_NAME = "ELECTROBUN_APP_NAME";
14
+ var ELECTROBUN_REPOSITORY = "https://github.com/blackboardsh/electrobun.git";
15
+ var ELECTROBUN_TAG = "v2.0.5";
16
+ var ELECTROBUN_PACKAGE_VERSION = "2.0.5";
17
+ var ZIG_VERSION = "0.17.0";
18
+ var ZIG_ARCHIVE_URL = "https://ziglang.org/download/0.17.0/zig-aarch64-macos-0.17.0.tar.xz";
19
+ var ZIG_ARCHIVE_SHA256 = "b607e9b9234790a008116ae5bdb71c6243b84b9fb42a53a9e70fde41c06c536a";
20
+ var ZIG_ARCHIVE_MAX_BYTES = 67108864;
21
+ var BUILD_TIMEOUT_MILLISECONDS = 9e5;
22
+ var sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
23
+ function step(name, command, args, cwd) {
24
+ if (spawnSync(command, args, {
25
+ cwd,
26
+ stdio: "ignore",
27
+ timeout: BUILD_TIMEOUT_MILLISECONDS
28
+ }).status !== 0) throw new Error(`Pinned POSIX launcher ${name} failed`);
29
+ }
30
+ function sourceHead(source) {
31
+ return execFileSync("git", ["rev-parse", "HEAD"], {
32
+ cwd: source,
33
+ encoding: "utf8",
34
+ stdio: [
35
+ "ignore",
36
+ "pipe",
37
+ "ignore"
38
+ ],
39
+ timeout: 6e4
40
+ }).trim();
41
+ }
42
+ async function downloadPinnedZigArchive(destination) {
43
+ const hash = createHash("sha256");
44
+ const file = await open(destination, "wx");
45
+ let size = 0;
46
+ try {
47
+ let response;
48
+ try {
49
+ response = await fetch(ZIG_ARCHIVE_URL, { signal: AbortSignal.timeout(BUILD_TIMEOUT_MILLISECONDS) });
50
+ } catch (error) {
51
+ throw new Error("Pinned POSIX launcher Zig download failed", { cause: error });
52
+ }
53
+ if (!response.ok || !response.body) {
54
+ try {
55
+ response.body?.cancel().catch(() => {});
56
+ } catch {}
57
+ throw new Error("Pinned POSIX launcher Zig download failed");
58
+ }
59
+ for await (const chunk of response.body) {
60
+ size += chunk.byteLength;
61
+ if (size > ZIG_ARCHIVE_MAX_BYTES) throw new Error("Pinned POSIX launcher Zig archive is too large");
62
+ hash.update(chunk);
63
+ await file.writeFile(chunk);
64
+ }
65
+ } finally {
66
+ await file.close();
67
+ }
68
+ if (hash.digest("hex") !== ZIG_ARCHIVE_SHA256) throw new Error("Unexpected pinned POSIX launcher Zig archive digest");
69
+ }
70
+ async function preparePinnedLauncher(work) {
71
+ const source = join(work, "electrobun");
72
+ step("source checkout", "git", [
73
+ "clone",
74
+ "--depth=1",
75
+ "--filter=blob:none",
76
+ "--no-checkout",
77
+ "--branch",
78
+ ELECTROBUN_TAG,
79
+ ELECTROBUN_REPOSITORY,
80
+ source
81
+ ]);
82
+ step("source selection", "git", [
83
+ "sparse-checkout",
84
+ "init",
85
+ "--cone"
86
+ ], source);
87
+ step("source selection", "git", [
88
+ "sparse-checkout",
89
+ "set",
90
+ "package/src/launcher"
91
+ ], source);
92
+ step("source checkout", "git", [
93
+ "checkout",
94
+ "--detach",
95
+ ELECTROBUN_COMMIT
96
+ ], source);
97
+ if (sourceHead(source) !== "d06abc9edf0b4e55116129cabbfe17bf89e11791") throw new Error("Unexpected pinned Electrobun source revision");
98
+ try {
99
+ applyElectrobunPatch(source, POSIX_LAUNCH_LEASE_PATCH_PATH, PINNED_POSIX_LAUNCH_LEASE_PATCH);
100
+ } catch (error) {
101
+ throw new Error("Pinned POSIX launcher source patch check failed", { cause: error });
102
+ }
103
+ const zigArchive = join(work, "zig.tar.xz");
104
+ await downloadPinnedZigArchive(zigArchive);
105
+ const zigRoot = join(work, "zig");
106
+ const outputRoot = join(work, "output");
107
+ const launcherSource = join(source, "package", "src", "launcher");
108
+ await Promise.all([mkdir(zigRoot), mkdir(outputRoot)]);
109
+ step("Zig extraction", "tar", [
110
+ "-xf",
111
+ zigArchive,
112
+ "-C",
113
+ zigRoot
114
+ ]);
115
+ const zig = join(zigRoot, `zig-aarch64-macos-${ZIG_VERSION}`, "zig");
116
+ const zigInfo = await lstat(zig);
117
+ if (!zigInfo.isFile() || zigInfo.isSymbolicLink() || (zigInfo.mode & 73) === 0) throw new Error("Invalid pinned POSIX launcher Zig executable");
118
+ let version;
119
+ try {
120
+ version = execFileSync(zig, ["version"], {
121
+ encoding: "utf8",
122
+ stdio: [
123
+ "ignore",
124
+ "pipe",
125
+ "ignore"
126
+ ],
127
+ timeout: 6e4
128
+ }).trim();
129
+ } catch (error) {
130
+ throw new Error("Pinned POSIX launcher Zig version check failed", { cause: error });
131
+ }
132
+ if (version !== ZIG_VERSION) throw new Error("Unexpected pinned POSIX launcher Zig version");
133
+ step("build", zig, [
134
+ "build",
135
+ "-Doptimize=ReleaseFast",
136
+ "-Dadea-launch-lease=true",
137
+ "-p",
138
+ outputRoot
139
+ ], launcherSource);
140
+ const path = join(outputRoot, "bin", "launcher");
141
+ const outputInfo = await lstat(path);
142
+ if (!outputInfo.isFile() || outputInfo.isSymbolicLink() || (outputInfo.mode & 73) === 0) throw new Error("Invalid pinned POSIX launcher build output");
143
+ const bytes = await readFile(path);
144
+ if (!isMacosArm64MachO(bytes)) throw new Error("Pinned POSIX launcher output is not macOS arm64");
145
+ return {
146
+ path,
147
+ sha256: sha256(bytes)
148
+ };
149
+ }
150
+ function isMacosArm64MachO(bytes) {
151
+ return bytes.length >= 8 && bytes.readUInt32LE(0) === 4277009103 && bytes.readUInt32LE(4) === 16777228;
152
+ }
153
+ async function regularDirectory(path) {
154
+ try {
155
+ const info = await lstat(path);
156
+ return info.isDirectory() && !info.isSymbolicLink();
157
+ } catch {
158
+ return false;
159
+ }
160
+ }
161
+ async function packagedLauncher(cwd, environment, buildDirectory, appName) {
162
+ if (environment !== "stable") throw new Error("POSIX launch lease supports stable builds only");
163
+ if (!buildDirectory || !isAbsolute(buildDirectory) || !appName) throw new Error("Missing Electrobun build output identity");
164
+ if (basename(appName) !== appName || appName === "." || appName === ".." || appName.includes("\\") || appName.includes("\0")) throw new Error("Invalid Electrobun app name");
165
+ const buildRoot = resolve(buildDirectory);
166
+ if (!await regularDirectory(buildRoot)) throw new Error("Missing pinned POSIX launcher package output");
167
+ const bundle = join(buildRoot, `${appName}.app`);
168
+ const contents = join(bundle, "Contents");
169
+ const macos = join(contents, "MacOS");
170
+ if (!await regularDirectory(bundle) || !await regularDirectory(contents) || !await regularDirectory(macos)) throw new Error("Invalid pinned POSIX launcher package layout");
171
+ const launcher = join(macos, "launcher");
172
+ const info = await lstat(launcher).catch(() => void 0);
173
+ if (!info?.isFile() || info.isSymbolicLink() || (info.mode & 73) === 0) throw new Error("Invalid packaged POSIX launcher");
174
+ return launcher;
175
+ }
176
+ async function replacePackagedLauncher(source, destination) {
177
+ const staged = join(dirname(destination), `.launcher-${randomUUID()}.tmp`);
178
+ try {
179
+ await copyFile(source.path, staged);
180
+ await chmod(staged, 493);
181
+ const stagedInfo = await lstat(staged);
182
+ if (!stagedInfo.isFile() || stagedInfo.isSymbolicLink()) throw new Error("Invalid staged POSIX launcher");
183
+ const stagedBytes = await readFile(staged);
184
+ if (sha256(stagedBytes) !== source.sha256 || !isMacosArm64MachO(stagedBytes)) throw new Error("Staged POSIX launcher identity mismatch");
185
+ await rename(staged, destination);
186
+ if (sha256(await readFile(destination)) !== source.sha256) throw new Error("Packaged POSIX launcher identity mismatch");
187
+ } finally {
188
+ await rm(staged, { force: true }).catch(() => {});
189
+ }
190
+ }
191
+ async function verifyElectrobunPackage(cwd) {
192
+ let manifest;
193
+ try {
194
+ manifest = JSON.parse(await readFile(join(cwd, "node_modules", "electrobun", "package.json"), "utf8"));
195
+ } catch (error) {
196
+ throw new Error("Missing pinned Electrobun 2.0.5 package", { cause: error });
197
+ }
198
+ if (manifest.version !== ELECTROBUN_PACKAGE_VERSION) throw new Error("Unexpected pinned Electrobun package version");
199
+ }
200
+ /**
201
+ * Replace the stable macOS arm64 package launcher only when explicitly enabled.
202
+ * Default generated-app builds return before inspecting outputs or downloading tools.
203
+ */
204
+ async function installOptInPosixLaunchLeaseLauncher(options = {}) {
205
+ const env = options.env ?? process.env;
206
+ const enabled = env[POSIX_LAUNCH_LEASE_OPT_IN];
207
+ if (enabled === void 0 || enabled === "" || enabled === "0") return void 0;
208
+ if (enabled !== "1") throw new Error(`Set ${POSIX_LAUNCH_LEASE_OPT_IN} to 1 to opt in`);
209
+ const platform = options.platform ?? process.platform;
210
+ const arch = options.arch ?? process.arch;
211
+ const cwd = options.cwd ?? process.cwd();
212
+ if (env["ELECTROBUN_OS"] !== "macos" || env["ELECTROBUN_ARCH"] !== "arm64" || platform !== "darwin" || arch !== "arm64") throw new Error("POSIX launch lease is qualified only for macOS arm64");
213
+ const environment = env[ELECTROBUN_BUILD_ENV];
214
+ if (environment !== "stable") throw new Error("POSIX launch lease supports stable builds only");
215
+ const buildDirectory = env[ELECTROBUN_BUILD_DIR];
216
+ const appName = env[ELECTROBUN_APP_NAME];
217
+ const destination = await packagedLauncher(cwd, environment, buildDirectory, appName);
218
+ await verifyElectrobunPackage(cwd);
219
+ const work = await mkdtemp(join(tmpdir(), "adea-posix-launcher-"));
220
+ try {
221
+ const prepared = await (options.prepareLauncher ?? preparePinnedLauncher)(work);
222
+ if (await packagedLauncher(cwd, environment, buildDirectory, appName) !== destination) throw new Error("Electrobun build output path changed during launcher build");
223
+ await replacePackagedLauncher(prepared, destination);
224
+ return prepared;
225
+ } finally {
226
+ await rm(work, {
227
+ recursive: true,
228
+ force: true
229
+ });
230
+ }
231
+ }
232
+ export { ELECTROBUN_APP_NAME, ELECTROBUN_ARCH, ELECTROBUN_BUILD_DIR, ELECTROBUN_BUILD_ENV, ELECTROBUN_OS, POSIX_LAUNCH_LEASE_OPT_IN, installOptInPosixLaunchLeaseLauncher };
@@ -0,0 +1,36 @@
1
+ import type { UpdateTreeIdentity } from '../updates/update-swap';
2
+ export type PosixTreeRemovalResult = Readonly<{
3
+ status: 'more' | 'empty';
4
+ removed: number;
5
+ }>;
6
+ /**
7
+ * Remove at most `maxOperations` entries from a directory tree without
8
+ * following symlinks. The root directory remains in place and its device/inode
9
+ * must match the caller's validated ownership record. Repeated calls resume by
10
+ * walking the remaining entries. An optional version marker is removed and
11
+ * barrier-synced before generic traversal can remove any other entry. The
12
+ * caller must hold the install update lock and this generation's exclusive
13
+ * lease for the entire sequence of calls.
14
+ *
15
+ * This POSIX primitive uses directory descriptors and no-follow opens. It
16
+ * requests F_BARRIERFSYNC on each containing directory after unlinking an
17
+ * entry and on an emptied child before removing that directory. It supports
18
+ * only macOS arm64, and
19
+ * unknown or special entry types fail closed. It compares the device and
20
+ * complete `f_mntonname` values on opened directories, but does not claim
21
+ * protection from concurrent mount changes. Sync calls request persistence
22
+ * through the OS and filesystem; they are not hardware power-loss proof. This
23
+ * primitive also cannot stop a same-user process that ignores the caller's
24
+ * locks and races directory names.
25
+ */
26
+ export declare function removeDirectoryContentsChunk(options: {
27
+ root: string;
28
+ expectedRootIdentity: UpdateTreeIdentity;
29
+ maxOperations: number;
30
+ prioritizeVersionMarker?: Readonly<{
31
+ path: readonly string[];
32
+ version: string;
33
+ }>;
34
+ /** Test-only fault injection; it can only make a barrier fail closed. */
35
+ testOnlyFailBarrierAtCall?: number;
36
+ }): Promise<PosixTreeRemovalResult>;