@adea-ai/app-framework 0.27.0 → 0.28.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 (125) hide show
  1. package/README.md +177 -15
  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/cli-runner.d.ts +4 -0
  11. package/dist/cli/cli-runner.js +14 -1
  12. package/dist/cli/create-application-cli.js +4 -2
  13. package/dist/cli/release-cut-cli.js +2 -2
  14. package/dist/cli/update-helper-cli.js +28 -6
  15. package/dist/desktop/client-asset-manifest.d.ts +47 -0
  16. package/dist/desktop/client-asset-manifest.js +114 -0
  17. package/dist/desktop/client-asset-stream.d.ts +10 -0
  18. package/dist/desktop/client-asset-stream.js +138 -33
  19. package/dist/desktop/client-assets.d.ts +20 -0
  20. package/dist/desktop/client-assets.js +132 -22
  21. package/dist/desktop/client-response-lifecycle.d.ts +22 -0
  22. package/dist/desktop/client-response-lifecycle.js +233 -0
  23. package/dist/desktop/desktop-host.d.ts +40 -2
  24. package/dist/desktop/desktop-host.js +159 -9
  25. package/dist/framework-source.json +1 -1
  26. package/dist/installer/command-artifact.d.ts +4 -2
  27. package/dist/installer/command-artifact.js +119 -19
  28. package/dist/installer/linux-process-group.d.ts +13 -0
  29. package/dist/installer/linux-process-group.js +58 -0
  30. package/dist/native/darwin-sync.d.ts +7 -0
  31. package/dist/native/darwin-sync.js +43 -0
  32. package/dist/native/desktop-build-hook.js +7 -0
  33. package/dist/native/directory-exchange.d.ts +10 -0
  34. package/dist/native/directory-exchange.js +90 -0
  35. package/dist/native/electrobun-source-patch.d.ts +5 -0
  36. package/dist/native/electrobun-source-patch.js +19 -1
  37. package/dist/native/posix-launcher-build.d.ts +24 -0
  38. package/dist/native/posix-launcher-build.js +232 -0
  39. package/dist/native/posix-tree-removal.d.ts +36 -0
  40. package/dist/native/posix-tree-removal.js +425 -0
  41. package/dist/release/feed-release-cut.js +30 -10
  42. package/dist/release/github-release-cut.js +16 -0
  43. package/dist/release/release-cut.d.ts +8 -1
  44. package/dist/release/release-cut.js +9 -1
  45. package/dist/update-helper.bundle.js +1483 -105
  46. package/dist/updates/channel-update-manager.d.ts +5 -0
  47. package/dist/updates/channel-update-manager.js +13 -1
  48. package/dist/updates/desktop-updater.d.ts +78 -2
  49. package/dist/updates/desktop-updater.js +320 -37
  50. package/dist/updates/launch-environment.d.ts +2 -0
  51. package/dist/updates/launch-environment.js +4 -0
  52. package/dist/updates/native-file-lock.d.ts +15 -0
  53. package/dist/updates/native-file-lock.js +189 -0
  54. package/dist/updates/packaged-launch-admission.d.ts +13 -0
  55. package/dist/updates/packaged-launch-admission.js +45 -0
  56. package/dist/updates/packaged-release-config.d.ts +18 -0
  57. package/dist/updates/packaged-release-config.js +60 -0
  58. package/dist/updates/packaged-update-startup.d.ts +44 -0
  59. package/dist/updates/packaged-update-startup.js +81 -0
  60. package/dist/updates/update-arm.d.ts +9 -8
  61. package/dist/updates/update-arm.js +227 -62
  62. package/dist/updates/update-cleanup-error.d.ts +23 -0
  63. package/dist/updates/update-cleanup-error.js +65 -0
  64. package/dist/updates/update-download-cleanup.d.ts +11 -0
  65. package/dist/updates/update-download-cleanup.js +112 -2
  66. package/dist/updates/update-download-lock.d.ts +20 -0
  67. package/dist/updates/update-download-lock.js +73 -0
  68. package/dist/updates/update-download.d.ts +2 -0
  69. package/dist/updates/update-download.js +7 -3
  70. package/dist/updates/update-generation-lease.d.ts +6 -0
  71. package/dist/updates/update-generation-lease.js +14 -0
  72. package/dist/updates/update-helper.d.ts +11 -2
  73. package/dist/updates/update-helper.js +322 -13
  74. package/dist/updates/update-inherited-launch-lease.d.ts +22 -0
  75. package/dist/updates/update-inherited-launch-lease.js +58 -0
  76. package/dist/updates/update-instance-lease.d.ts +15 -0
  77. package/dist/updates/update-instance-lease.js +25 -0
  78. package/dist/updates/update-launch-gate.d.ts +137 -0
  79. package/dist/updates/update-launch-gate.js +617 -0
  80. package/dist/updates/update-launch.js +3 -1
  81. package/dist/updates/update-lock.d.ts +12 -0
  82. package/dist/updates/update-lock.js +18 -0
  83. package/dist/updates/update-manager.d.ts +2 -0
  84. package/dist/updates/update-manager.js +9 -2
  85. package/dist/updates/update-marker.d.ts +7 -0
  86. package/dist/updates/update-marker.js +62 -0
  87. package/dist/updates/update-preflight-error.d.ts +7 -0
  88. package/dist/updates/update-preflight-error.js +11 -0
  89. package/dist/updates/update-process-fence.d.ts +4 -0
  90. package/dist/updates/update-process-fence.js +85 -73
  91. package/dist/updates/update-process-liveness.d.ts +2 -0
  92. package/dist/updates/update-process-liveness.js +11 -0
  93. package/dist/updates/update-resume.d.ts +37 -3
  94. package/dist/updates/update-resume.js +839 -23
  95. package/dist/updates/update-retention-marker.d.ts +67 -0
  96. package/dist/updates/update-retention-marker.js +165 -0
  97. package/dist/updates/update-retention-plan.d.ts +25 -0
  98. package/dist/updates/update-retention-plan.js +54 -0
  99. package/dist/updates/update-retention-sync.d.ts +34 -0
  100. package/dist/updates/update-retention-sync.js +83 -0
  101. package/dist/updates/update-retirement.d.ts +205 -0
  102. package/dist/updates/update-retirement.js +1485 -0
  103. package/dist/updates/update-shutdown.d.ts +16 -4
  104. package/dist/updates/update-shutdown.js +133 -8
  105. package/dist/updates/update-state-store.d.ts +58 -0
  106. package/dist/updates/update-state-store.js +139 -0
  107. package/dist/updates/update-swap-stage.d.ts +1 -1
  108. package/dist/updates/update-swap-stage.js +85 -14
  109. package/dist/updates/update-swap.d.ts +45 -2
  110. package/dist/updates/update-swap.js +207 -17
  111. package/package.json +31 -1
  112. package/src/appearance/custom-theme-import.ts +96 -14
  113. package/src/appearance/custom-theme-library.ts +5 -0
  114. package/src/appearance/theme-record-adapter.ts +15 -6
  115. package/src/appearance/theme-registry.ts +8 -1
  116. package/src/desktop/client-asset-manifest.ts +207 -0
  117. package/src/desktop/client-asset-stream.ts +193 -32
  118. package/src/desktop/client-assets.ts +210 -19
  119. package/src/desktop/client-response-lifecycle.ts +305 -0
  120. package/src/native/electrobun-posix-launch-lease.patch +398 -0
  121. package/templates/application/README.md +50 -0
  122. package/templates/application/electrobun.config.ts +5 -1
  123. package/templates/application/scripts/build-desktop.ts +4 -0
  124. package/templates/application/src/bun/index.ts +173 -16
  125. package/templates/application/vite.config.ts +112 -6
@@ -0,0 +1,398 @@
1
+ Electrobun 2.0.5 (MIT), commit d06abc9edf0b4e55116129cabbfe17bf89e11791.
2
+
3
+ Add an opt-in native inherited shared lease for packaged POSIX launchers. The
4
+ option defaults off and is not wired into framework packaging. Default/off
5
+ builds preserve the upstream signal-forwarding order; only opt-in builds delay
6
+ handler registration until the child PID is set. Build-supported opt-in targets
7
+ are macOS arm64 and Linux x86_64; Linux is compile-only here and its runtime is
8
+ not qualified. Windows and other architectures remain unsupported. Apply this
9
+ exact, digest-pinned source patch with `git apply --unidiff-zero`. Build from
10
+ package/src/launcher with Zig 0.17.0 using:
11
+
12
+ zig build -Doptimize=ReleaseFast -Dadea-launch-lease=true -p <output-dir>
13
+
14
+ The Zig 0.17.0 macOS arm64 archive used for qualification has SHA-256
15
+ b607e9b9234790a008116ae5bdb71c6243b84b9fb42a53a9e70fde41c06c536a.
16
+
17
+ The launcher acquires coordinator EX, checks for an absent gate, and acquires
18
+ instance SH before reading mutable bundle metadata, then passes the same open
19
+ file description to the app through ADEA_INHERITED_LAUNCH_LEASE_FD. Uninstall
20
+ management remains outside the protocol. A transition that completes after OS
21
+ exec begins but before the launcher acquires its first lock is not closed by
22
+ this patch; do not claim that startup interval is protected. The option stays
23
+ off until framework packaging is separately qualified and integrated.
24
+
25
+ diff --git a/package/src/launcher/build.zig b/package/src/launcher/build.zig
26
+ index a3c17e00..f1e4006d 100644
27
+ --- a/package/src/launcher/build.zig
28
+ +++ b/package/src/launcher/build.zig
29
+ @@ -17,0 +18,20 @@ pub fn build(b: *std.Build) void {
30
+ + // The update-launch lease is opt-in and never enabled in Electrobun's
31
+ + // default/dev build. The framework build hook may set it only for an
32
+ + // explicitly qualified packaged POSIX wrapper.
33
+ + const adea_launch_lease = b.option(
34
+ + bool,
35
+ + "adea-launch-lease",
36
+ + "Enable the opt-in POSIX packaged-app update launch lease",
37
+ + ) orelse false;
38
+ + if (adea_launch_lease and optimize == .debug) {
39
+ + @panic("-Dadea-launch-lease=true is only valid for optimized packaged launchers");
40
+ + }
41
+ + if (adea_launch_lease and target.result.os.tag != .macos and target.result.os.tag != .linux) {
42
+ + @panic("-Dadea-launch-lease=true supports POSIX macOS and Linux only");
43
+ + }
44
+ + if (adea_launch_lease and target.result.os.tag == .macos and target.result.cpu.arch != .aarch64) {
45
+ + @panic("-Dadea-launch-lease=true is qualified only for macOS arm64");
46
+ + }
47
+ + if (adea_launch_lease and target.result.os.tag == .linux and target.result.cpu.arch != .x86_64) {
48
+ + @panic("-Dadea-launch-lease=true supports only Linux x86_64");
49
+ + }
50
+ @@ -28,0 +49,3 @@ pub fn build(b: *std.Build) void {
51
+ + const build_options = b.addOptions();
52
+ + build_options.addOption(bool, "adea_launch_lease", adea_launch_lease);
53
+ + exe.root_module.addOptions("adea_build_options", build_options);
54
+ diff --git a/package/src/launcher/launch_lease.zig b/package/src/launcher/launch_lease.zig
55
+ new file mode 100644
56
+ index 00000000..525bb70d
57
+ --- /dev/null
58
+ +++ b/package/src/launcher/launch_lease.zig
59
+ @@ -0,0 +1,254 @@
60
+ +const std = @import("std");
61
+ +const builtin = @import("builtin");
62
+ +
63
+ +pub const environment_variable = "ADEA_INHERITED_LAUNCH_LEASE_FD";
64
+ +
65
+ +const FileIdentity = struct {
66
+ + device_major: u64,
67
+ + device_minor: u64,
68
+ + inode: u64,
69
+ + regular: bool,
70
+ +};
71
+ +
72
+ +const LOCK_SH: c_int = 1;
73
+ +const LOCK_EX: c_int = 2;
74
+ +const LOCK_NB: c_int = 4;
75
+ +
76
+ +/// Resolve the installed app tree from the launcher's physical executable path.
77
+ +/// These are the only layouts supported by the framework's update targets.
78
+ +fn installedTargetPath(allocator: std.mem.Allocator, io: std.Io, executable_path: []const u8) ![]u8 {
79
+ + const physical_executable = try std.Io.Dir.realPathFileAbsoluteAlloc(
80
+ + io,
81
+ + executable_path,
82
+ + allocator,
83
+ + );
84
+ + defer allocator.free(physical_executable);
85
+ +
86
+ + if (!std.mem.eql(u8, std.fs.path.basename(physical_executable), "launcher")) {
87
+ + return error.InvalidInstalledLauncherPath;
88
+ + }
89
+ + const executable_dir = std.fs.path.dirname(physical_executable) orelse
90
+ + return error.InvalidInstalledLauncherPath;
91
+ +
92
+ + if (builtin.os.tag == .macos) {
93
+ + if (!std.mem.eql(u8, std.fs.path.basename(executable_dir), "MacOS")) {
94
+ + return error.InvalidInstalledLauncherPath;
95
+ + }
96
+ + const contents_dir = std.fs.path.dirname(executable_dir) orelse
97
+ + return error.InvalidInstalledLauncherPath;
98
+ + if (!std.mem.eql(u8, std.fs.path.basename(contents_dir), "Contents")) {
99
+ + return error.InvalidInstalledLauncherPath;
100
+ + }
101
+ + const target = std.fs.path.dirname(contents_dir) orelse
102
+ + return error.InvalidInstalledLauncherPath;
103
+ + if (!std.mem.endsWith(u8, std.fs.path.basename(target), ".app")) {
104
+ + return error.InvalidInstalledLauncherPath;
105
+ + }
106
+ + return allocator.dupe(u8, target);
107
+ + }
108
+ +
109
+ + if (builtin.os.tag == .linux) {
110
+ + if (!std.mem.eql(u8, std.fs.path.basename(executable_dir), "bin")) {
111
+ + return error.InvalidInstalledLauncherPath;
112
+ + }
113
+ + const target = std.fs.path.dirname(executable_dir) orelse
114
+ + return error.InvalidInstalledLauncherPath;
115
+ + if (std.fs.path.basename(target).len == 0) {
116
+ + return error.InvalidInstalledLauncherPath;
117
+ + }
118
+ + return allocator.dupe(u8, target);
119
+ + }
120
+ +
121
+ + return error.UnsupportedPlatform;
122
+ +}
123
+ +
124
+ +fn siblingPath(allocator: std.mem.Allocator, target: []const u8, suffix: []const u8) ![]u8 {
125
+ + const parent = std.fs.path.dirname(target) orelse return error.InvalidInstalledLauncherPath;
126
+ + const name = try std.fmt.allocPrint(allocator, ".{s}.{s}", .{
127
+ + std.fs.path.basename(target),
128
+ + suffix,
129
+ + });
130
+ + defer allocator.free(name);
131
+ + return std.fs.path.join(allocator, &.{ parent, name });
132
+ +}
133
+ +
134
+ +fn lockPath(allocator: std.mem.Allocator, target: []const u8) ![]u8 {
135
+ + return siblingPath(allocator, target, "framework-update.lock");
136
+ +}
137
+ +
138
+ +fn gatePath(allocator: std.mem.Allocator, target: []const u8) ![]u8 {
139
+ + return siblingPath(allocator, target, "framework-update-launch-gate.json");
140
+ +}
141
+ +
142
+ +fn instanceLeasePath(allocator: std.mem.Allocator, target: []const u8) ![]u8 {
143
+ + return siblingPath(allocator, target, "framework-instance-lease.lock");
144
+ +}
145
+ +
146
+ +fn openPersistentLockFile(allocator: std.mem.Allocator, path: []const u8) !c_int {
147
+ + const path_z = try allocator.dupeSentinel(u8, path, 0);
148
+ + defer allocator.free(path_z);
149
+ +
150
+ + const flags: std.c.O = .{
151
+ + .ACCMODE = .RDWR,
152
+ + .CREAT = true,
153
+ + .NOFOLLOW = true,
154
+ + .CLOEXEC = true,
155
+ + };
156
+ + const fd = std.c.open(path_z, flags, @as(std.c.mode_t, 0o600));
157
+ + if (fd < 0) return error.LockFileOpenFailed;
158
+ +
159
+ + // The child bootstrap parses this descriptor as an inherited application
160
+ + // lease. Keep it out of the conventional stdin/stdout/stderr descriptor
161
+ + // range even if the launcher was started with a closed standard stream.
162
+ + if (fd >= 3) return fd;
163
+ + const duplicate = std.c.fcntl(fd, std.c.F.DUPFD_CLOEXEC, @as(c_int, 3));
164
+ + if (duplicate < 0) {
165
+ + _ = std.c.close(fd);
166
+ + return error.LockFileDescriptorFailed;
167
+ + }
168
+ + if (std.c.close(fd) != 0) {
169
+ + _ = std.c.close(duplicate);
170
+ + return error.LockFileCloseFailed;
171
+ + }
172
+ + return duplicate;
173
+ +}
174
+ +
175
+ +fn linuxFileIdentity(dir_fd: c_int, path: [*:0]const u8, flags: u32) !FileIdentity {
176
+ + var stat: std.os.linux.Statx = undefined;
177
+ + const result = std.os.linux.statx(
178
+ + dir_fd,
179
+ + path,
180
+ + flags,
181
+ + std.os.linux.STATX.BASIC_STATS,
182
+ + &stat,
183
+ + );
184
+ + if (std.os.linux.errno(result) != .SUCCESS or !stat.mask.INO or !stat.mask.TYPE) {
185
+ + return error.LockFileStatFailed;
186
+ + }
187
+ + return .{
188
+ + .device_major = stat.dev_major,
189
+ + .device_minor = stat.dev_minor,
190
+ + .inode = stat.ino,
191
+ + .regular = stat.mode & 0o170000 == 0o100000,
192
+ + };
193
+ +}
194
+ +
195
+ +fn descriptorIdentity(fd: c_int) !FileIdentity {
196
+ + if (builtin.os.tag == .linux) return linuxFileIdentity(fd, "", 0x1000);
197
+ + if (builtin.os.tag == .macos) {
198
+ + var stat: std.c.Stat = undefined;
199
+ + if (std.c.fstat(fd, &stat) != 0) return error.LockFileStatFailed;
200
+ + return .{
201
+ + .device_major = @intCast(stat.dev),
202
+ + .device_minor = 0,
203
+ + .inode = stat.ino,
204
+ + .regular = std.c.S.ISREG(@intCast(stat.mode)),
205
+ + };
206
+ + }
207
+ + return error.UnsupportedPlatform;
208
+ +}
209
+ +
210
+ +fn pathIdentity(allocator: std.mem.Allocator, path: []const u8) !FileIdentity {
211
+ + const path_z = try allocator.dupeSentinel(u8, path, 0);
212
+ + defer allocator.free(path_z);
213
+ + if (builtin.os.tag == .linux) {
214
+ + return linuxFileIdentity(std.c.AT.FDCWD, path_z, std.c.AT.SYMLINK_NOFOLLOW);
215
+ + }
216
+ + if (builtin.os.tag == .macos) {
217
+ + var stat: std.c.Stat = undefined;
218
+ + if (std.c.fstatat(std.c.AT.FDCWD, path_z, &stat, std.c.AT.SYMLINK_NOFOLLOW) != 0) {
219
+ + return error.LockFileStatFailed;
220
+ + }
221
+ + return .{
222
+ + .device_major = @intCast(stat.dev),
223
+ + .device_minor = 0,
224
+ + .inode = stat.ino,
225
+ + .regular = std.c.S.ISREG(@intCast(stat.mode)),
226
+ + };
227
+ + }
228
+ + return error.UnsupportedPlatform;
229
+ +}
230
+ +
231
+ +/// Match the framework's JS lock opener: validate the opened descriptor as a
232
+ +/// regular file, then check device and inode identity without following links.
233
+ +fn verifyPersistentLockFile(allocator: std.mem.Allocator, path: []const u8, fd: c_int) !void {
234
+ + const descriptor = try descriptorIdentity(fd);
235
+ + if (!descriptor.regular) return error.InvalidLockFile;
236
+ + const current_path = pathIdentity(allocator, path) catch return error.LockFilePathChanged;
237
+ + if (!current_path.regular or
238
+ + current_path.device_major != descriptor.device_major or
239
+ + current_path.device_minor != descriptor.device_minor or
240
+ + current_path.inode != descriptor.inode)
241
+ + {
242
+ + return error.LockFilePathChanged;
243
+ + }
244
+ +}
245
+ +
246
+ +fn flockNonblocking(fd: c_int, operation: c_int, busy_error: anyerror) !void {
247
+ + var result = std.c.flock(fd, operation | LOCK_NB);
248
+ + while (result == -1 and std.c.errno(result) == .INTR) {
249
+ + result = std.c.flock(fd, operation | LOCK_NB);
250
+ + }
251
+ + switch (std.c.errno(result)) {
252
+ + .SUCCESS => return,
253
+ + .AGAIN => return busy_error,
254
+ + else => return error.LockOperationFailed,
255
+ + }
256
+ +}
257
+ +
258
+ +fn checkGateAbsent(io: std.Io, path: []const u8) !void {
259
+ + _ = std.Io.Dir.cwd().statFile(io, path, .{ .follow_symlinks = false }) catch |err| {
260
+ + if (err == error.FileNotFound) return;
261
+ + return error.LaunchGateCheckFailed;
262
+ + };
263
+ + return error.LaunchGatePresent;
264
+ +}
265
+ +
266
+ +/// Acquire the same admission sequence as the updater: transition coordinator
267
+ +/// EX, gate absent, then persistent instance lease SH. The returned descriptor
268
+ +/// remains locked until the application process closes it or exits.
269
+ +pub fn acquire(allocator: std.mem.Allocator, io: std.Io, executable_path: []const u8) !c_int {
270
+ + if (builtin.os.tag != .macos and builtin.os.tag != .linux) return error.UnsupportedPlatform;
271
+ +
272
+ + const target = try installedTargetPath(allocator, io, executable_path);
273
+ + defer allocator.free(target);
274
+ +
275
+ + const coordinator_path = try lockPath(allocator, target);
276
+ + defer allocator.free(coordinator_path);
277
+ + const coordinator_fd = try openPersistentLockFile(allocator, coordinator_path);
278
+ + var coordinator_open = true;
279
+ + defer if (coordinator_open) {
280
+ + _ = std.c.close(coordinator_fd);
281
+ + };
282
+ + try verifyPersistentLockFile(allocator, coordinator_path, coordinator_fd);
283
+ + try flockNonblocking(coordinator_fd, LOCK_EX, error.UpdateCoordinatorBusy);
284
+ + try verifyPersistentLockFile(allocator, coordinator_path, coordinator_fd);
285
+ +
286
+ + const gate_path = try gatePath(allocator, target);
287
+ + defer allocator.free(gate_path);
288
+ + try checkGateAbsent(io, gate_path);
289
+ +
290
+ + const instance_path = try instanceLeasePath(allocator, target);
291
+ + defer allocator.free(instance_path);
292
+ + const instance_fd = try openPersistentLockFile(allocator, instance_path);
293
+ + errdefer _ = std.c.close(instance_fd);
294
+ + try verifyPersistentLockFile(allocator, instance_path, instance_fd);
295
+ + try flockNonblocking(instance_fd, LOCK_SH, error.UpdateWriterActive);
296
+ + try verifyPersistentLockFile(allocator, instance_path, instance_fd);
297
+ + try verifyPersistentLockFile(allocator, coordinator_path, coordinator_fd);
298
+ +
299
+ + if (std.c.close(coordinator_fd) != 0) return error.UpdateCoordinatorCloseFailed;
300
+ + coordinator_open = false;
301
+ + return instance_fd;
302
+ +}
303
+ +
304
+ +/// Close the launcher's descriptor after spawn without issuing LOCK_UN. The
305
+ +/// child holds the same open-file description and therefore keeps the shared
306
+ +/// lease until its own inherited descriptor is closed or the process exits.
307
+ +pub fn closeParentDescriptor(fd: c_int) c_int {
308
+ + return std.c.close(fd);
309
+ +}
310
+ +
311
+ +pub fn inheritedFile(fd: c_int) std.Io.File {
312
+ + return .{ .handle = fd, .flags = .{ .nonblocking = false } };
313
+ +}
314
+ diff --git a/package/src/launcher/main.zig b/package/src/launcher/main.zig
315
+ index 30bb39f5..401e789b 100644
316
+ --- a/package/src/launcher/main.zig
317
+ +++ b/package/src/launcher/main.zig
318
+ @@ -7,0 +8,18 @@ const windows_process_identity = @import("windows_process_identity.zig");
319
+ +const build_options = @import("adea_build_options");
320
+ +const launch_lease_mod = if (builtin.os.tag == .macos or builtin.os.tag == .linux)
321
+ + @import("launch_lease.zig")
322
+ +else struct {
323
+ + pub const environment_variable = "ADEA_INHERITED_LAUNCH_LEASE_FD";
324
+ +
325
+ + pub fn acquire(_: std.mem.Allocator, _: std.Io, _: []const u8) !c_int {
326
+ + return error.UnsupportedPlatform;
327
+ + }
328
+ +
329
+ + pub fn closeParentDescriptor(_: c_int) c_int {
330
+ + return 0;
331
+ + }
332
+ +
333
+ + pub fn inheritedFile(_: c_int) std.Io.File {
334
+ + return undefined;
335
+ + }
336
+ +};
337
+ @@ -398,0 +417,8 @@ pub fn main(init: std.process.Init) !void {
338
+ + const env_map = init.environ_map;
339
+ + // Never accept a descriptor inherited from the launcher of a parent app.
340
+ + // A lease is exported only after this process acquires its own one.
341
+ + _ = env_map.swapRemove(launch_lease_mod.environment_variable);
342
+ + var inherited_lease_fd: ?c_int = null;
343
+ + defer if (inherited_lease_fd) |fd| {
344
+ + _ = launch_lease_mod.closeParentDescriptor(fd);
345
+ + };
346
+ @@ -410,2 +436,3 @@ pub fn main(init: std.process.Init) !void {
347
+ - // Set up signal handlers (not on Windows)
348
+ - if (builtin.os.tag != .windows) {
349
+ + // Preserve stock signal-forwarding order for all default/off builds.
350
+ + // Opt-in lease builds install handlers after spawn so child_pid is valid.
351
+ + if (!build_options.adea_launch_lease and builtin.os.tag != .windows) {
352
+ @@ -427,0 +455,2 @@ pub fn main(init: std.process.Init) !void {
353
+ + // Explicit uninstall is a management command, not an app launch; it
354
+ + // remains outside this opt-in application startup lease protocol.
355
+ @@ -431,0 +461,13 @@ pub fn main(init: std.process.Init) !void {
356
+ + // This is a build-time opt-in. It is deliberately false in stock and dev
357
+ + // builds, so no mutable version/build metadata is read before admission.
358
+ + if (build_options.adea_launch_lease) {
359
+ + inherited_lease_fd = launch_lease_mod.acquire(arena_alloc, io, exe_path) catch |err| {
360
+ + std.debug.print("[LAUNCHER] Update launch admission failed: {}\n", .{err});
361
+ + return error.LaunchLeaseAcquireFailed;
362
+ + };
363
+ + try env_map.put(
364
+ + launch_lease_mod.environment_variable,
365
+ + try std.fmt.allocPrint(arena_alloc, "{d}", .{inherited_lease_fd.?}),
366
+ + );
367
+ + }
368
+ +
369
+ @@ -459 +500,0 @@ pub fn main(init: std.process.Init) !void {
370
+ - const env_map = init.environ_map;
371
+ @@ -647,0 +689,7 @@ pub fn main(init: std.process.Init) !void {
372
+ + var inherited_file_storage: std.Io.File = undefined;
373
+ + var inherited_files: []const std.Io.File = &.{};
374
+ + if (inherited_lease_fd) |fd| {
375
+ + inherited_file_storage = launch_lease_mod.inheritedFile(fd);
376
+ + inherited_files = &.{inherited_file_storage};
377
+ + }
378
+ +
379
+ @@ -653,0 +702 @@ pub fn main(init: std.process.Init) !void {
380
+ + .inherit_files = inherited_files,
381
+ @@ -654,0 +704,6 @@ pub fn main(init: std.process.Init) !void {
382
+ + if (inherited_lease_fd) |fd| {
383
+ + if (launch_lease_mod.closeParentDescriptor(fd) != 0) {
384
+ + return error.LaunchLeaseParentCloseFailed;
385
+ + }
386
+ + inherited_lease_fd = null;
387
+ + }
388
+ @@ -656,0 +712,10 @@ pub fn main(init: std.process.Init) !void {
389
+ + // Install forwarding handlers only after child_pid is initialized.
390
+ + // Before that point the default action exits this launcher, and the
391
+ + // child's inherited shared lease continues to protect its startup.
392
+ + if (build_options.adea_launch_lease and builtin.os.tag != .windows) {
393
+ + _ = c.signal(c.SIGINT, signalHandler);
394
+ + _ = c.signal(c.SIGTERM, signalHandler);
395
+ + _ = c.signal(c.SIGHUP, signalHandler);
396
+ + _ = c.signal(c.SIGALRM, alarmHandler);
397
+ + }
398
+ +
@@ -31,6 +31,56 @@ startup reads in `offlineExpectedReads`. The generated channel policies identify
31
31
  platform's tested full archive; publication fails closed until keys and real
32
32
  installer receipts are present.
33
33
 
34
+ Set `repository` in `release-config.json` to the GitHub `owner/name` that signs
35
+ the descriptors. `create-adea-app` fills it from a canonical GitHub
36
+ `--source-url`; for another source host, pass `--repository OWNER/NAME`. The
37
+ Electrobun package copies this file beside the app worker. Managed startup
38
+ checks its app identity, repository, feed, and public keys against the generated
39
+ app configuration; the saved channel only selects `stable`, `daily`, or `dev`
40
+ within that packaged trust. A missing key or malformed channel or staged update
41
+ stops managed startup and preserves update state.
42
+
43
+ The generated stable package can opt into the native launch lease on macOS
44
+ Apple Silicon:
45
+
46
+ ```sh
47
+ ADEA_ENABLE_POSIX_LAUNCH_LEASE=1 bun run build:release
48
+ ```
49
+
50
+ The build hook verifies Electrobun 2.0.5, checks out its pinned source commit,
51
+ applies the digest-pinned launcher patch, and downloads Zig 0.17.0 from the
52
+ official macOS ARM64 archive after checking its SHA-256. This requires Git and
53
+ network access. The replacement is limited to the stable `.app` launcher and
54
+ happens before release packaging. Without the environment variable, packaging
55
+ keeps Electrobun's default launcher.
56
+
57
+ The lease integration is experimental. It does not cover the interval between
58
+ operating-system execution and the launcher's first lock, uninstall, or native
59
+ renderer descendant lifetime. A gate left by a crashed helper is not recovered
60
+ by generated startup and needs explicit recovery. Linux has only compile
61
+ support and is not enabled by this build integration.
62
+
63
+ The managed recovery and retained-asset startup path runs only when the opt-in
64
+ native launcher supplies its inherited launch lease. Default generated
65
+ packages keep Electrobun's launcher, so ordinary launches remain unmanaged and
66
+ do not run staged-update recovery. The launcher rejects an existing update
67
+ gate before starting the worker; a gate left by a crashed helper is not
68
+ recovered by the generated startup path and needs manual recovery. During an update restart, the
69
+ host pauses new client-asset responses and waits up to five seconds for active
70
+ responses to finish naturally. If that drain times out, the helper must confirm
71
+ cancellation and clear its launch gate before the same visible host resumes
72
+ asset admission. If cancellation cannot be confirmed, startup remains paused
73
+ and the generation lease stays held for recovery. The host's absolute shutdown
74
+ budget is measured conservatively from before helper spawn. Quiescence is
75
+ limited to five seconds and terminal close uses only the remaining budget,
76
+ leaving eleven seconds before the helper's 30-second process fence for a
77
+ confirmed cancellation if shutdown is rejected before host close. If the budget
78
+ expires before terminal close begins, the updater rejects shutdown so it can
79
+ cancel the helper before resuming the same host. Once terminal shutdown starts,
80
+ the app exits by that budget instead of reopening a host whose native close has
81
+ already started. A manually closed native window during quiescence follows that
82
+ terminal shutdown path.
83
+
34
84
  The desktop host stores its loopback port in Electrobun's app-specific data
35
85
  directory so appearance and layout preferences survive restarts. If the saved
36
86
  port is already in use, startup retries briefly and then fails instead of
@@ -15,7 +15,11 @@ export default {
15
15
  mainProcess: 'bun',
16
16
  bun: { entrypoint: 'src/bun/index.ts' },
17
17
  views: {},
18
- copy: { 'build/client': 'client' },
18
+ copy: {
19
+ 'build/client': 'client',
20
+ 'node_modules/@adea-ai/app-framework/dist/update-helper.bundle.js': 'update-helper.js',
21
+ 'release-config.json': 'release-config.json',
22
+ },
19
23
  ...profile.build,
20
24
  mac: { ...profile.build.mac, createDmg: false },
21
25
  },
@@ -6,6 +6,10 @@ const [environment, ...extra] = process.argv.slice(2)
6
6
  if (!environment || !['dev', 'stable'].includes(environment) || extra.length)
7
7
  throw new Error('Expected dev or stable build environment')
8
8
  const env = { ...process.env }
9
+ if (env.ADEA_ENABLE_POSIX_LAUNCH_LEASE === '1') {
10
+ if (environment !== 'stable' || process.platform !== 'darwin' || process.arch !== 'arm64')
11
+ throw new Error('POSIX launch lease integration supports stable macOS arm64 builds only')
12
+ }
9
13
  if (process.platform === 'win32') {
10
14
  const tar = Bun.spawnSync({ cmd: ['tar', '--version'], stdout: 'pipe', stderr: 'pipe', env })
11
15
  if (tar.exitCode !== 0) throw new Error('A working tar executable is required')