@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,425 @@
1
+ import { lstat, open } from "node:fs/promises";
2
+ import { isAbsolute, resolve } from "node:path";
3
+ import { FFIType, dlopen, ptr, read } from "bun:ffi";
4
+ import { constants as constants$1 } from "node:fs";
5
+ // src/native/posix-tree-removal.ts
6
+ var AT_SYMLINK_NOFOLLOW_DARWIN = 32;
7
+ var AT_REMOVEDIR_DARWIN = 128;
8
+ var O_CLOEXEC_DARWIN = 16777216;
9
+ var F_SETFD_DARWIN = 2;
10
+ var F_BARRIERFSYNC_DARWIN = 85;
11
+ var FD_CLOEXEC_DARWIN = 1;
12
+ var DT_UNKNOWN = 0;
13
+ var DT_FIFO = 1;
14
+ var DT_CHR = 2;
15
+ var DT_DIR = 4;
16
+ var DT_BLK = 6;
17
+ var DT_REG = 8;
18
+ var DT_LNK = 10;
19
+ var DT_SOCK = 12;
20
+ function loadLibrary() {
21
+ return dlopen("libSystem.B.dylib", {
22
+ dup: {
23
+ args: [FFIType.i32],
24
+ returns: FFIType.i32
25
+ },
26
+ fcntl: {
27
+ args: [
28
+ FFIType.i32,
29
+ FFIType.i32,
30
+ FFIType.i32
31
+ ],
32
+ returns: FFIType.i32
33
+ },
34
+ fdopendir: {
35
+ args: [FFIType.i32],
36
+ returns: FFIType.ptr
37
+ },
38
+ readdir_r: {
39
+ args: [
40
+ FFIType.ptr,
41
+ FFIType.ptr,
42
+ FFIType.ptr
43
+ ],
44
+ returns: FFIType.i32
45
+ },
46
+ closedir: {
47
+ args: [FFIType.ptr],
48
+ returns: FFIType.i32
49
+ },
50
+ openat: {
51
+ args: [
52
+ FFIType.i32,
53
+ FFIType.ptr,
54
+ FFIType.i32
55
+ ],
56
+ returns: FFIType.i32
57
+ },
58
+ fstatat: {
59
+ args: [
60
+ FFIType.i32,
61
+ FFIType.ptr,
62
+ FFIType.ptr,
63
+ FFIType.i32
64
+ ],
65
+ returns: FFIType.i32
66
+ },
67
+ fstat: {
68
+ args: [FFIType.i32, FFIType.ptr],
69
+ returns: FFIType.i32
70
+ },
71
+ fstatfs: {
72
+ args: [FFIType.i32, FFIType.ptr],
73
+ returns: FFIType.i32
74
+ },
75
+ unlinkat: {
76
+ args: [
77
+ FFIType.i32,
78
+ FFIType.ptr,
79
+ FFIType.i32
80
+ ],
81
+ returns: FFIType.i32
82
+ },
83
+ read: {
84
+ args: [
85
+ FFIType.i32,
86
+ FFIType.ptr,
87
+ FFIType.i32
88
+ ],
89
+ returns: FFIType.i32
90
+ },
91
+ close: {
92
+ args: [FFIType.i32],
93
+ returns: FFIType.i32
94
+ }
95
+ });
96
+ }
97
+ function identityFromStat(stat, darwin) {
98
+ return darwin ? {
99
+ device: read.i32(ptr(stat), 0).toString(),
100
+ inode: read.u64(ptr(stat), 8).toString()
101
+ } : {
102
+ device: read.u64(ptr(stat), 0).toString(),
103
+ inode: read.u64(ptr(stat), 8).toString()
104
+ };
105
+ }
106
+ function modeFromStat(stat, darwin) {
107
+ return darwin ? read.u16(ptr(stat), 4) : read.u32(ptr(stat), 24);
108
+ }
109
+ function direntLayout(darwin) {
110
+ return darwin ? {
111
+ recordLengthOffset: 16,
112
+ typeOffset: 20,
113
+ inodeOffset: 0,
114
+ nameOffset: 21
115
+ } : {
116
+ recordLengthOffset: 16,
117
+ typeOffset: 18,
118
+ inodeOffset: 0,
119
+ nameOffset: 19
120
+ };
121
+ }
122
+ function fileType(mode) {
123
+ return mode & 61440;
124
+ }
125
+ function entryType(type, statMode) {
126
+ const modeType = fileType(statMode);
127
+ if (type === DT_UNKNOWN) {
128
+ if (modeType === 32768) return "file";
129
+ if (modeType === 16384) return "directory";
130
+ if (modeType === 40960) return "symlink";
131
+ throw new Error("Unsupported filesystem entry type");
132
+ }
133
+ if (type === DT_REG && modeType === 32768 || type === DT_DIR && modeType === 16384 || type === DT_LNK && modeType === 40960) return type === DT_REG ? "file" : type === DT_DIR ? "directory" : "symlink";
134
+ if ([
135
+ DT_FIFO,
136
+ DT_CHR,
137
+ DT_BLK,
138
+ DT_SOCK
139
+ ].includes(type)) throw new Error("Unsupported filesystem entry type");
140
+ throw new Error("Filesystem entry type changed during removal");
141
+ }
142
+ function sameInode(left, right) {
143
+ return left.device === right.device && left.inode === right.inode;
144
+ }
145
+ function barrierDirectory(context, fd, operation) {
146
+ context.barrierCalls++;
147
+ if (context.barrierCalls === context.testOnlyFailBarrierAtCall) throw new Error("Injected F_BARRIERFSYNC failure");
148
+ if (context.library.symbols.fcntl(fd, F_BARRIERFSYNC_DARWIN, 0) !== 0) throw new Error(`Could not persist directory ordering after ${operation}`);
149
+ }
150
+ function mountPointForDescriptor(context, fd) {
151
+ const output = Buffer.alloc(4096);
152
+ if (context.library.symbols.fstatfs(fd, ptr(output)) !== 0) throw new Error("Could not inspect directory mount boundary");
153
+ const typeStart = 72;
154
+ let typeEnd = typeStart;
155
+ while (typeEnd < 88 && read.u8(ptr(output), typeEnd) !== 0) typeEnd++;
156
+ if (typeEnd === 88) throw new Error("Filesystem type is truncated");
157
+ const filesystemType = Buffer.from(output.subarray(typeStart, typeEnd)).toString("ascii");
158
+ if (filesystemType !== "apfs" && filesystemType !== "hfs") throw new Error("Tree removal requires APFS or HFS ordering support");
159
+ const start = 88;
160
+ const endLimit = 1112;
161
+ let end = start;
162
+ while (end < endLimit && read.u8(ptr(output), end) !== 0) end++;
163
+ if (end === endLimit) throw new Error("Directory mount name is truncated");
164
+ if (read.u8(ptr(output), start) !== 47) throw new Error("Filesystem returned an invalid mount name");
165
+ const mountPoint = Buffer.alloc(end - start + 1);
166
+ for (let index = start; index <= end; index++) mountPoint[index - start] = read.u8(ptr(output), index);
167
+ return mountPoint;
168
+ }
169
+ function statAt(context, directory, name) {
170
+ const output = Buffer.alloc(256);
171
+ if (context.library.symbols.fstatat(directory, ptr(name), ptr(output), AT_SYMLINK_NOFOLLOW_DARWIN) !== 0) throw new Error("Could not inspect filesystem entry during tree removal");
172
+ const identity = identityFromStat(output, context.darwin);
173
+ if (identity.device !== context.rootDevice) throw new Error("Tree removal refused to cross a device boundary");
174
+ return {
175
+ identity,
176
+ mode: modeFromStat(output, context.darwin)
177
+ };
178
+ }
179
+ function openDirectoryAt(context, parent, name) {
180
+ const flags = constants$1.O_RDONLY | constants$1.O_DIRECTORY | constants$1.O_NOFOLLOW | O_CLOEXEC_DARWIN;
181
+ const fd = context.library.symbols.openat(parent, ptr(name), flags);
182
+ if (fd < 0) throw new Error("Could not open directory without following links");
183
+ return fd;
184
+ }
185
+ function withClosedDescriptor(context, fd, operation) {
186
+ let value;
187
+ let operationFailed = false;
188
+ let operationError;
189
+ try {
190
+ value = operation();
191
+ } catch (error) {
192
+ operationFailed = true;
193
+ operationError = error;
194
+ }
195
+ const closeFailed = context.library.symbols.close(fd) !== 0;
196
+ if (operationFailed) {
197
+ if (closeFailed) throw new AggregateError([operationError, /* @__PURE__ */ new Error("Could not close directory descriptor")], "Directory operation and descriptor cleanup failed");
198
+ throw operationError;
199
+ }
200
+ if (closeFailed) throw new Error("Could not close directory descriptor");
201
+ return value;
202
+ }
203
+ function removeDirectoryContents(context, directory, depth) {
204
+ if (depth > 128) throw new Error("Directory tree exceeds the supported traversal depth");
205
+ const scanFd = context.library.symbols.dup(directory);
206
+ if (scanFd < 0) throw new Error("Could not duplicate directory descriptor");
207
+ if (context.library.symbols.fcntl(scanFd, F_SETFD_DARWIN, FD_CLOEXEC_DARWIN) !== 0) {
208
+ if (context.library.symbols.close(scanFd) !== 0) throw new Error("Could not close directory descriptor after flag failure");
209
+ throw new Error("Could not mark directory descriptor close-on-exec");
210
+ }
211
+ const stream = context.library.symbols.fdopendir(scanFd);
212
+ if (!stream) {
213
+ if (context.library.symbols.close(scanFd) !== 0) throw new Error("Could not close failed directory descriptor");
214
+ throw new Error("Could not read directory descriptor");
215
+ }
216
+ let empty = true;
217
+ let outcome = "empty";
218
+ let operationFailed = false;
219
+ let operationError;
220
+ try {
221
+ for (;;) {
222
+ const entry = Buffer.alloc(4096);
223
+ const result = Buffer.alloc(8);
224
+ const readStatus = context.library.symbols.readdir_r(stream, ptr(entry), ptr(result));
225
+ if (readStatus !== 0) throw new Error("Could not read directory entry (errno " + readStatus + ")");
226
+ if (read.ptr(ptr(result), 0) === 0) {
227
+ outcome = empty ? "empty" : "more";
228
+ break;
229
+ }
230
+ const layout = direntLayout(context.darwin);
231
+ const recordLength = read.u16(ptr(entry), layout.recordLengthOffset);
232
+ if (recordLength < layout.nameOffset + 1 || recordLength > 4096) throw new Error("Invalid directory entry returned by the filesystem");
233
+ let nameLength = 0;
234
+ while (layout.nameOffset + nameLength < recordLength && read.u8(ptr(entry), layout.nameOffset + nameLength) !== 0) nameLength++;
235
+ if (layout.nameOffset + nameLength >= recordLength) throw new Error("Directory entry name is not terminated");
236
+ if (nameLength === 0) throw new Error("Filesystem returned an empty directory entry");
237
+ if (nameLength === 1 && read.u8(ptr(entry), layout.nameOffset) === 46) continue;
238
+ if (nameLength === 2 && read.u8(ptr(entry), layout.nameOffset) === 46 && read.u8(ptr(entry), layout.nameOffset + 1) === 46) continue;
239
+ if (++context.inspected > context.maxInspectedEntries) {
240
+ outcome = "more";
241
+ break;
242
+ }
243
+ empty = false;
244
+ if (context.removed >= context.maxOperations) {
245
+ outcome = "more";
246
+ break;
247
+ }
248
+ const name = Buffer.alloc(nameLength + 1);
249
+ for (let index = 0; index < nameLength; index++) {
250
+ const byte = read.u8(ptr(entry), layout.nameOffset + index);
251
+ if (byte === 47) throw new Error("Filesystem returned a path separator in a name");
252
+ name[index] = byte;
253
+ }
254
+ const enumeratedInode = read.u64(ptr(entry), layout.inodeOffset).toString();
255
+ const before = statAt(context, directory, name);
256
+ if (before.identity.inode !== enumeratedInode) throw new Error("Filesystem entry changed during tree removal");
257
+ const kind = entryType(read.u8(ptr(entry), layout.typeOffset), before.mode);
258
+ if (kind === "directory") {
259
+ const child = openDirectoryAt(context, directory, name);
260
+ if (withClosedDescriptor(context, child, () => {
261
+ const childStat = Buffer.alloc(256);
262
+ if (context.library.symbols.fstat(child, ptr(childStat)) !== 0) throw new Error("Could not verify opened directory");
263
+ const opened = identityFromStat(childStat, context.darwin);
264
+ if (!sameInode(opened, before.identity)) throw new Error("Opened directory identity changed during tree removal");
265
+ if (opened.device !== context.rootDevice) throw new Error("Tree removal refused to cross a device boundary");
266
+ if (!mountPointForDescriptor(context, child).equals(context.rootMountPoint)) throw new Error("Tree removal refused to cross a mount boundary");
267
+ const status = removeDirectoryContents(context, child, depth + 1);
268
+ if (status === "empty") barrierDirectory(context, child, "emptying a child directory");
269
+ return status;
270
+ }) === "more") {
271
+ outcome = "more";
272
+ break;
273
+ }
274
+ const after = statAt(context, directory, name);
275
+ if (!sameInode(after.identity, before.identity) || fileType(after.mode) !== 16384) throw new Error("Directory entry changed before removal");
276
+ if (context.library.symbols.unlinkat(directory, ptr(name), AT_REMOVEDIR_DARWIN) !== 0) throw new Error("Could not remove empty directory");
277
+ barrierDirectory(context, directory, "removing a child directory");
278
+ } else {
279
+ const after = statAt(context, directory, name);
280
+ if (!sameInode(after.identity, before.identity) || fileType(after.mode) !== (kind === "file" ? 32768 : 40960)) throw new Error("File entry changed before removal");
281
+ if (context.library.symbols.unlinkat(directory, ptr(name), 0) !== 0) throw new Error("Could not unlink filesystem entry");
282
+ barrierDirectory(context, directory, "unlinking an entry");
283
+ }
284
+ context.removed++;
285
+ }
286
+ } catch (error) {
287
+ operationFailed = true;
288
+ operationError = error;
289
+ }
290
+ const closeFailed = context.library.symbols.closedir(stream) !== 0;
291
+ if (operationFailed) {
292
+ if (closeFailed) throw new AggregateError([operationError, /* @__PURE__ */ new Error("Could not close directory stream")], "Directory traversal and stream cleanup failed");
293
+ throw operationError;
294
+ }
295
+ if (closeFailed) throw new Error("Could not close directory stream");
296
+ return outcome;
297
+ }
298
+ function versionFromDescriptor(context, fd) {
299
+ const chunks = [];
300
+ let total = 0;
301
+ for (;;) {
302
+ const buffer = Buffer.alloc(Math.min(4096, 8193 - total));
303
+ const count = context.library.symbols.read(fd, ptr(buffer), buffer.length);
304
+ if (count < 0) throw new Error("Could not read the retained tree version marker");
305
+ if (count === 0) break;
306
+ total += count;
307
+ if (total > 8192) throw new Error("Retained tree version marker is too large");
308
+ chunks.push(buffer.subarray(0, count));
309
+ }
310
+ const value = JSON.parse(Buffer.concat(chunks).toString("utf8"));
311
+ if (typeof value !== "object" || value === null || typeof value.version !== "string") throw new Error("Retained tree version marker is invalid");
312
+ return value.version;
313
+ }
314
+ function removePrioritizedVersionMarker(context, root, relativePath, expectedVersion) {
315
+ const visit = (parent, index) => {
316
+ const name = Buffer.from(`${relativePath[index]}\0`);
317
+ const before = statAt(context, parent, name);
318
+ if (index < relativePath.length - 1) {
319
+ if (fileType(before.mode) !== 16384) throw new Error("Retained tree version marker path contains a non-directory");
320
+ const child = openDirectoryAt(context, parent, name);
321
+ withClosedDescriptor(context, child, () => {
322
+ const stat = Buffer.alloc(256);
323
+ if (context.library.symbols.fstat(child, ptr(stat)) !== 0) throw new Error("Could not verify retained tree version marker directory");
324
+ const opened = identityFromStat(stat, context.darwin);
325
+ if (!sameInode(opened, before.identity) || fileType(modeFromStat(stat, context.darwin)) !== 16384) throw new Error("Retained tree version marker directory changed");
326
+ if (opened.device !== context.rootDevice || !mountPointForDescriptor(context, child).equals(context.rootMountPoint)) throw new Error("Retained tree version marker crossed a filesystem boundary");
327
+ visit(child, index + 1);
328
+ });
329
+ return;
330
+ }
331
+ if (fileType(before.mode) !== 32768) throw new Error("Retained tree version marker is not a regular file");
332
+ const descriptor = context.library.symbols.openat(parent, ptr(name), constants$1.O_RDONLY | constants$1.O_NOFOLLOW | constants$1.O_NONBLOCK | O_CLOEXEC_DARWIN);
333
+ if (descriptor < 0) throw new Error("Could not open retained tree version marker safely");
334
+ withClosedDescriptor(context, descriptor, () => {
335
+ const stat = Buffer.alloc(256);
336
+ if (context.library.symbols.fstat(descriptor, ptr(stat)) !== 0) throw new Error("Could not verify opened retained tree version marker");
337
+ const opened = identityFromStat(stat, context.darwin);
338
+ if (!sameInode(opened, before.identity) || fileType(modeFromStat(stat, context.darwin)) !== 32768) throw new Error("Opened retained tree version marker changed");
339
+ if (versionFromDescriptor(context, descriptor) !== expectedVersion) throw new Error("Retained tree version marker no longer matches its owner");
340
+ const after = statAt(context, parent, name);
341
+ if (!sameInode(after.identity, opened) || fileType(after.mode) !== 32768) throw new Error("Retained tree version marker changed before removal");
342
+ if (context.library.symbols.unlinkat(parent, ptr(name), 0) !== 0) throw new Error("Could not invalidate retained tree version marker");
343
+ barrierDirectory(context, parent, "invalidating the retained tree version marker");
344
+ context.removed++;
345
+ });
346
+ };
347
+ if (relativePath.length < 1 || relativePath.some((segment) => segment.length === 0 || segment === "." || segment === ".." || segment.includes("/") || segment.includes("\0")) || !/^\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(expectedVersion)) throw new Error("Invalid prioritized retained tree version marker request");
348
+ visit(root, 0);
349
+ }
350
+ /**
351
+ * Remove at most `maxOperations` entries from a directory tree without
352
+ * following symlinks. The root directory remains in place and its device/inode
353
+ * must match the caller's validated ownership record. Repeated calls resume by
354
+ * walking the remaining entries. An optional version marker is removed and
355
+ * barrier-synced before generic traversal can remove any other entry. The
356
+ * caller must hold the install update lock and this generation's exclusive
357
+ * lease for the entire sequence of calls.
358
+ *
359
+ * This POSIX primitive uses directory descriptors and no-follow opens. It
360
+ * requests F_BARRIERFSYNC on each containing directory after unlinking an
361
+ * entry and on an emptied child before removing that directory. It supports
362
+ * only macOS arm64, and
363
+ * unknown or special entry types fail closed. It compares the device and
364
+ * complete `f_mntonname` values on opened directories, but does not claim
365
+ * protection from concurrent mount changes. Sync calls request persistence
366
+ * through the OS and filesystem; they are not hardware power-loss proof. This
367
+ * primitive also cannot stop a same-user process that ignores the caller's
368
+ * locks and races directory names.
369
+ */
370
+ async function removeDirectoryContentsChunk(options) {
371
+ const { root, expectedRootIdentity, maxOperations, prioritizeVersionMarker, testOnlyFailBarrierAtCall } = options;
372
+ const darwin = process.platform === "darwin";
373
+ if (!darwin || process.arch !== "arm64") throw new Error("Safe directory-relative removal is unsupported on this platform");
374
+ if (typeof root !== "string" || !isAbsolute(root) || resolve(root) !== root || root.includes("\0") || !expectedRootIdentity || !/^[1-9]\d{0,19}$/.test(expectedRootIdentity.device) || !/^[1-9]\d{0,19}$/.test(expectedRootIdentity.inode) || !Number.isSafeInteger(maxOperations) || maxOperations < 1 || maxOperations > 4096 || testOnlyFailBarrierAtCall !== void 0 && (!Number.isSafeInteger(testOnlyFailBarrierAtCall) || testOnlyFailBarrierAtCall < 1)) throw new Error("Invalid bounded tree removal request");
375
+ const rootInfo = await lstat(root, { bigint: true });
376
+ if (!rootInfo.isDirectory() || rootInfo.isSymbolicLink()) throw new Error("Tree removal root is not a directory");
377
+ if (rootInfo.dev.toString() !== expectedRootIdentity.device || rootInfo.ino.toString() !== expectedRootIdentity.inode) throw new Error("Tree removal root identity changed");
378
+ const library = loadLibrary();
379
+ let handle;
380
+ try {
381
+ handle = await open(root, constants$1.O_RDONLY | constants$1.O_DIRECTORY | constants$1.O_NOFOLLOW | O_CLOEXEC_DARWIN);
382
+ } catch (error) {
383
+ library.close();
384
+ throw error;
385
+ }
386
+ const context = {
387
+ library,
388
+ inspected: 0,
389
+ removed: 0,
390
+ maxOperations,
391
+ maxInspectedEntries: Math.max(256, maxOperations * 64),
392
+ barrierCalls: 0,
393
+ testOnlyFailBarrierAtCall,
394
+ darwin,
395
+ rootDevice: "",
396
+ rootMountPoint: Buffer.alloc(0)
397
+ };
398
+ try {
399
+ const descriptorStat = Buffer.alloc(256);
400
+ if (library.symbols.fstat(handle.fd, ptr(descriptorStat)) !== 0) throw new Error("Could not verify opened tree removal root");
401
+ const descriptorIdentity = identityFromStat(descriptorStat, darwin);
402
+ if (descriptorIdentity.device !== expectedRootIdentity.device || descriptorIdentity.inode !== expectedRootIdentity.inode) throw new Error("Opened tree removal root identity changed");
403
+ context.rootDevice = descriptorIdentity.device;
404
+ context.rootMountPoint = mountPointForDescriptor(context, handle.fd);
405
+ if (prioritizeVersionMarker) {
406
+ removePrioritizedVersionMarker(context, handle.fd, prioritizeVersionMarker.path, prioritizeVersionMarker.version);
407
+ if (context.removed >= context.maxOperations) return Object.freeze({
408
+ status: "more",
409
+ removed: context.removed
410
+ });
411
+ }
412
+ const status = removeDirectoryContents(context, handle.fd, 0);
413
+ return Object.freeze({
414
+ status,
415
+ removed: context.removed
416
+ });
417
+ } finally {
418
+ try {
419
+ library.close();
420
+ } finally {
421
+ await handle.close();
422
+ }
423
+ }
424
+ }
425
+ export { removeDirectoryContentsChunk };
@@ -7,6 +7,11 @@ export type ReleaseStepContext = {
7
7
  } & Record<string, unknown>;
8
8
  tag: string;
9
9
  platform: InstallerPlatform;
10
+ /**
11
+ * A local release on the maintainer's own matching machine: the staged installer is inspected
12
+ * read-only there instead of on a disposable hosted runner. Qualification never runs locally.
13
+ */
14
+ local?: boolean;
10
15
  };
11
16
  export declare function releasePlatform(value: string | undefined): InstallerPlatform;
12
17
  /** Reuse this tag's payload from an earlier trusted attempt; writes `reuse`, `artifactId` and `runId` to `GITHUB_OUTPUT`. */
@@ -115,7 +115,8 @@ async function inspectStagedStep(context, directory) {
115
115
  appName: context.config.appName,
116
116
  installer,
117
117
  archive,
118
- env: context.env
118
+ env: context.env,
119
+ local: context.local === true
119
120
  })
120
121
  };
121
122
  }