@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
@@ -3,7 +3,13 @@ import { versionLessThan } from "./release-version.js";
3
3
  import { discoverSignedRelease } from "./update-discovery.js";
4
4
  import { downloadVerifiedRelease } from "./update-download.js";
5
5
  import { selectUpdateDownloadDiscard } from "./update-download-cleanup.js";
6
+ import { UpdatePreflightError } from "./update-preflight-error.js";
6
7
  // src/updates/update-manager.ts
8
+ var UPDATE_PREFLIGHT_MESSAGES = {
9
+ "previous-update-in-progress": "A previous update is still running. Try again shortly.",
10
+ "previous-update-staged": "A previous update is ready. Restart the app before downloading another update.",
11
+ "recovery-required": "A previous update needs attention. Reinstall the app or contact support before trying again."
12
+ };
7
13
  /**
8
14
  * Coordinates discovery and download with point-in-time trust checks. The
9
15
  * stage callback owns safe application, including trust at its own commit
@@ -65,6 +71,7 @@ function createUpdateManager(options) {
65
71
  const descriptor = pending;
66
72
  try {
67
73
  if (!isVerifiedReleaseForTrust(descriptor, options.trust)) throw new Error("Untrusted update");
74
+ await options.beforeDownload?.();
68
75
  set("downloading");
69
76
  const downloaded = await (download ?? downloadVerifiedRelease)({
70
77
  descriptor,
@@ -89,9 +96,9 @@ function createUpdateManager(options) {
89
96
  await options.stage(stageInput);
90
97
  pending = void 0;
91
98
  return set("staged", descriptor.version);
92
- } catch {
99
+ } catch (error) {
93
100
  pending = void 0;
94
- return set("failed", null, "Update staging failed. Please try again.");
101
+ return set("failed", null, error instanceof UpdatePreflightError ? UPDATE_PREFLIGHT_MESSAGES[error.reason] : "Update staging failed. Please try again.");
95
102
  }
96
103
  } finally {
97
104
  busy = false;
@@ -0,0 +1,7 @@
1
+ export type UpdateMarkerName = 'cancel.json' | 'cancel-ack.json' | 'helper-ready';
2
+ export declare function isUpdateHelperReadyMarker(value: Readonly<Record<string, unknown>> | undefined, generation: string, helperOwner: string): boolean;
3
+ /** Publish a complete marker synchronously when a process fence requires a synchronous acknowledgement. */
4
+ export declare function publishExclusiveUpdateMarkerSync(staging: string, name: UpdateMarkerName, value: Readonly<Record<string, unknown>>): void;
5
+ /** Publish an immutable JSON marker atomically without replacing an existing owner. */
6
+ export declare function publishExclusiveUpdateMarker(staging: string, name: UpdateMarkerName, value: Readonly<Record<string, unknown>>): Promise<void>;
7
+ export declare function readUpdateMarker(staging: string, name: UpdateMarkerName): Promise<Readonly<Record<string, unknown>> | undefined>;
@@ -0,0 +1,62 @@
1
+ import { link, open, unlink, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { closeSync, constants as constants$1, linkSync, openSync, unlinkSync, writeFileSync } from "node:fs";
4
+ import { randomUUID } from "node:crypto";
5
+ // src/updates/update-marker.ts
6
+ function isUpdateHelperReadyMarker(value, generation, helperOwner) {
7
+ return value?.schema === 1 && value.generation === generation && value.helperOwner === helperOwner;
8
+ }
9
+ /** Publish a complete marker synchronously when a process fence requires a synchronous acknowledgement. */
10
+ function publishExclusiveUpdateMarkerSync(staging, name, value) {
11
+ const marker = join(staging, name);
12
+ const temporary = join(staging, "helper", `.${name}.${randomUUID()}.tmp`);
13
+ let descriptor;
14
+ try {
15
+ descriptor = openSync(temporary, constants$1.O_WRONLY | constants$1.O_CREAT | constants$1.O_EXCL, 384);
16
+ writeFileSync(descriptor, JSON.stringify(value) + "\n");
17
+ closeSync(descriptor);
18
+ descriptor = void 0;
19
+ linkSync(temporary, marker);
20
+ } finally {
21
+ if (descriptor !== void 0) try {
22
+ closeSync(descriptor);
23
+ } catch {}
24
+ try {
25
+ unlinkSync(temporary);
26
+ } catch {}
27
+ }
28
+ }
29
+ /** Publish an immutable JSON marker atomically without replacing an existing owner. */
30
+ async function publishExclusiveUpdateMarker(staging, name, value) {
31
+ const marker = join(staging, name);
32
+ const temporary = join(staging, "helper", `.${name}.${randomUUID()}.tmp`);
33
+ try {
34
+ await writeFile(temporary, JSON.stringify(value) + "\n", {
35
+ flag: "wx",
36
+ mode: 384
37
+ });
38
+ await link(temporary, marker);
39
+ } finally {
40
+ await unlink(temporary).catch(() => {});
41
+ }
42
+ }
43
+ async function readUpdateMarker(staging, name) {
44
+ const path = join(staging, name);
45
+ let file;
46
+ try {
47
+ file = await open(path, constants$1.O_RDONLY | (constants$1.O_NOFOLLOW ?? 0));
48
+ } catch (error) {
49
+ if (error.code === "ENOENT") return void 0;
50
+ throw error;
51
+ }
52
+ try {
53
+ const info = await file.stat();
54
+ if (!info.isFile() || info.size < 1 || info.size > 1024) throw new Error(`Invalid ${name} marker`);
55
+ const value = JSON.parse(await file.readFile("utf8"));
56
+ if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error(`Invalid ${name} marker`);
57
+ return value;
58
+ } finally {
59
+ await file.close();
60
+ }
61
+ }
62
+ export { isUpdateHelperReadyMarker, publishExclusiveUpdateMarker, publishExclusiveUpdateMarkerSync, readUpdateMarker };
@@ -0,0 +1,7 @@
1
+ /** A known, user-actionable reason the update pre-download check cannot proceed. */
2
+ export type UpdatePreflightReason = 'previous-update-in-progress' | 'previous-update-staged' | 'recovery-required';
3
+ /** Closed error codes let the manager report safe guidance without leaking callback details. */
4
+ export declare class UpdatePreflightError extends Error {
5
+ readonly reason: UpdatePreflightReason;
6
+ constructor(reason: UpdatePreflightReason);
7
+ }
@@ -0,0 +1,11 @@
1
+ // src/updates/update-preflight-error.ts
2
+ /** Closed error codes let the manager report safe guidance without leaking callback details. */
3
+ var UpdatePreflightError = class extends Error {
4
+ reason;
5
+ constructor(reason) {
6
+ super("Update preflight cannot proceed");
7
+ this.reason = reason;
8
+ this.name = "UpdatePreflightError";
9
+ }
10
+ };
11
+ export { UpdatePreflightError };
@@ -1,3 +1,6 @@
1
+ export declare class UpdateProcessFenceCancelledError extends Error {
2
+ constructor();
3
+ }
1
4
  /** Wait without signalling only processes whose executables were verified. This is not complete app-process discovery. */
2
5
  export declare function waitForUpdateProcesses(options: {
3
6
  processes: readonly {
@@ -7,4 +10,5 @@ export declare function waitForUpdateProcesses(options: {
7
10
  timeoutMs: number;
8
11
  env?: Record<string, string | undefined>;
9
12
  onVerified?: () => void;
13
+ cancellationRequested?: () => Promise<boolean>;
10
14
  }): Promise<void>;
@@ -2,10 +2,13 @@ import { linuxProcessIsExited } from "./linux-process-state.js";
2
2
  import { readFile, realpath } from "node:fs/promises";
3
3
  import { isAbsolute } from "node:path";
4
4
  import { FFIType, dlopen, ptr } from "bun:ffi";
5
- import { execFile } from "node:child_process";
6
- import { promisify } from "node:util";
7
5
  // src/updates/update-process-fence.ts
8
- var execute = promisify(execFile);
6
+ var UpdateProcessFenceCancelledError = class extends Error {
7
+ constructor() {
8
+ super("Update helper cancellation was requested");
9
+ this.name = "UpdateProcessFenceCancelledError";
10
+ }
11
+ };
9
12
  function isProcessRunning(pid) {
10
13
  try {
11
14
  process.kill(pid, 0);
@@ -29,80 +32,87 @@ async function hasVerifiedProcessExited(pid) {
29
32
  }
30
33
  return linuxProcessIsExited(stat, pid);
31
34
  }
32
- /** Wait without signalling only processes whose executables were verified. This is not complete app-process discovery. */
33
- async function waitForUpdateProcesses(options) {
34
- if (!Array.isArray(options.processes) || options.processes.length < 1 || options.processes.length > 16 || !Number.isSafeInteger(options.timeoutMs) || options.timeoutMs < 1 || options.timeoutMs > 12e4) throw new Error("Invalid update process fence");
35
- const seen = /* @__PURE__ */ new Set(), env = {};
36
- const deadline = Date.now() + options.timeoutMs;
37
- for (const key of [
38
- "PATH",
39
- "SystemRoot",
40
- "WINDIR",
41
- "TMP",
42
- "TEMP",
43
- "TMPDIR",
44
- "LANG",
45
- "LC_ALL"
46
- ]) if ((options.env ?? process.env)[key]) env[key] = (options.env ?? process.env)[key];
47
- async function executable(pid) {
48
- if (process.platform === "linux") return realpath(`/proc/${pid}/exe`);
49
- if (process.platform === "darwin") return realpath((await execute("/bin/ps", [
50
- "-p",
51
- String(pid),
52
- "-o",
53
- "comm="
54
- ], {
55
- env,
56
- timeout: Math.max(1, Math.min(5e3, deadline - Date.now())),
57
- maxBuffer: 16384
58
- })).stdout.trim());
59
- if (process.platform === "win32") {
60
- const library = dlopen("kernel32.dll", {
61
- OpenProcess: {
62
- args: [
63
- FFIType.u32,
64
- FFIType.i32,
65
- FFIType.u32
66
- ],
67
- returns: FFIType.ptr
68
- },
69
- QueryFullProcessImageNameW: {
70
- args: [
71
- FFIType.ptr,
72
- FFIType.u32,
73
- FFIType.ptr,
74
- FFIType.ptr
75
- ],
76
- returns: FFIType.i32
77
- },
78
- CloseHandle: {
79
- args: [FFIType.ptr],
80
- returns: FFIType.i32
81
- }
82
- });
35
+ async function executable(pid) {
36
+ if (process.platform === "linux") return realpath(`/proc/${pid}/exe`);
37
+ if (process.platform === "darwin") {
38
+ const library = dlopen("/usr/lib/libproc.dylib", { proc_pidpath: {
39
+ args: [
40
+ FFIType.i32,
41
+ FFIType.ptr,
42
+ FFIType.u32
43
+ ],
44
+ returns: FFIType.i32
45
+ } });
46
+ try {
47
+ const buffer = Buffer.alloc(4096);
48
+ const count = library.symbols.proc_pidpath(pid, ptr(buffer), buffer.length);
49
+ if (count <= 0 || count >= buffer.length) throw new Error("Cannot inspect update process");
50
+ const end = buffer.indexOf(0);
51
+ if (end <= 0 || end > count) throw new Error("Invalid update process path");
52
+ const path = buffer.subarray(0, end).toString("utf8");
53
+ if (!isAbsolute(path)) throw new Error("Invalid update process path");
54
+ return await realpath(path);
55
+ } finally {
56
+ library.close();
57
+ }
58
+ }
59
+ if (process.platform === "win32") {
60
+ const library = dlopen("kernel32.dll", {
61
+ OpenProcess: {
62
+ args: [
63
+ FFIType.u32,
64
+ FFIType.i32,
65
+ FFIType.u32
66
+ ],
67
+ returns: FFIType.ptr
68
+ },
69
+ QueryFullProcessImageNameW: {
70
+ args: [
71
+ FFIType.ptr,
72
+ FFIType.u32,
73
+ FFIType.ptr,
74
+ FFIType.ptr
75
+ ],
76
+ returns: FFIType.i32
77
+ },
78
+ CloseHandle: {
79
+ args: [FFIType.ptr],
80
+ returns: FFIType.i32
81
+ }
82
+ });
83
+ try {
84
+ const handle = library.symbols.OpenProcess(4096, 0, pid);
85
+ if (!handle) throw new Error("Cannot open update process");
83
86
  try {
84
- const handle = library.symbols.OpenProcess(4096, 0, pid);
85
- if (!handle) throw new Error("Cannot open update process");
86
- try {
87
- const buffer = Buffer.alloc(65536), length = Buffer.alloc(4);
88
- length.writeUInt32LE(32768);
89
- if (!library.symbols.QueryFullProcessImageNameW(handle, 0, ptr(buffer), ptr(length))) throw new Error("Cannot inspect update process");
90
- const count = length.readUInt32LE();
91
- if (!count || count >= 32768) throw new Error("Invalid update process path");
92
- return await realpath(buffer.subarray(0, count * 2).toString("utf16le"));
93
- } finally {
94
- library.symbols.CloseHandle(handle);
95
- }
87
+ const buffer = Buffer.alloc(65536), length = Buffer.alloc(4);
88
+ length.writeUInt32LE(32768);
89
+ if (!library.symbols.QueryFullProcessImageNameW(handle, 0, ptr(buffer), ptr(length))) throw new Error("Cannot inspect update process");
90
+ const count = length.readUInt32LE();
91
+ if (!count || count >= 32768) throw new Error("Invalid update process path");
92
+ return await realpath(buffer.subarray(0, count * 2).toString("utf16le"));
96
93
  } finally {
97
- library.close();
94
+ library.symbols.CloseHandle(handle);
98
95
  }
96
+ } finally {
97
+ library.close();
99
98
  }
100
- throw new Error("Unsupported update process platform");
101
99
  }
100
+ throw new Error("Unsupported update process platform");
101
+ }
102
+ /** Wait without signalling only processes whose executables were verified. This is not complete app-process discovery. */
103
+ async function waitForUpdateProcesses(options) {
104
+ if (!Array.isArray(options.processes) || options.processes.length < 1 || options.processes.length > 16 || !Number.isSafeInteger(options.timeoutMs) || options.timeoutMs < 1 || options.timeoutMs > 12e4) throw new Error("Invalid update process fence");
105
+ const seen = /* @__PURE__ */ new Set();
106
+ const deadline = performance.now() + options.timeoutMs;
102
107
  const waiting = /* @__PURE__ */ new Set();
108
+ const throwIfCancelled = async () => {
109
+ if (await options.cancellationRequested?.()) throw new UpdateProcessFenceCancelledError();
110
+ };
111
+ await throwIfCancelled();
103
112
  for (const processInfo of options.processes) {
104
113
  if (!processInfo || !Number.isSafeInteger(processInfo.pid) || processInfo.pid < 2 || processInfo.pid > 4294967295 || processInfo.pid === process.pid || seen.has(processInfo.pid) || typeof processInfo.executable !== "string" || !isAbsolute(processInfo.executable)) throw new Error("Invalid update process identity");
105
- if (Date.now() >= deadline) throw new Error("Update process fence timed out");
114
+ if (performance.now() >= deadline) throw new Error("Update process fence timed out");
115
+ await throwIfCancelled();
106
116
  seen.add(processInfo.pid);
107
117
  if (!isProcessRunning(processInfo.pid)) throw new Error("Update process exited before verification");
108
118
  let actual;
@@ -115,15 +125,17 @@ async function waitForUpdateProcesses(options) {
115
125
  if (process.platform === "win32" ? actual.toLowerCase() !== expected.toLowerCase() : actual !== expected) throw new Error("Update process executable mismatch");
116
126
  waiting.add(processInfo.pid);
117
127
  }
118
- if (Date.now() >= deadline) throw new Error("Update process fence timed out");
128
+ if (performance.now() >= deadline) throw new Error("Update process fence timed out");
119
129
  for (const pid of waiting) if (!isProcessRunning(pid)) throw new Error("Update process exited before verification");
130
+ await throwIfCancelled();
120
131
  const notified = options.onVerified?.();
121
132
  if (typeof notified === "object" && notified !== null && "then" in notified) throw new Error("Update process acknowledgement must be synchronous");
122
133
  while (waiting.size) {
134
+ await throwIfCancelled();
123
135
  for (const pid of waiting) if (await hasVerifiedProcessExited(pid)) waiting.delete(pid);
124
136
  if (!waiting.size) return;
125
- if (Date.now() >= deadline) throw new Error("Update processes did not exit");
126
- await Bun.sleep(Math.min(100, Math.max(1, deadline - Date.now())));
137
+ if (performance.now() >= deadline) throw new Error("Update processes did not exit");
138
+ await Bun.sleep(Math.min(100, Math.max(1, deadline - performance.now())));
127
139
  }
128
140
  }
129
- export { waitForUpdateProcesses };
141
+ export { UpdateProcessFenceCancelledError, waitForUpdateProcesses };
@@ -0,0 +1,2 @@
1
+ /** Only ESRCH proves a recorded process is absent; inspection errors fail closed. */
2
+ export declare function updateProcessMayBeAlive(pid: number): boolean;
@@ -0,0 +1,11 @@
1
+ // src/updates/update-process-liveness.ts
2
+ /** Only ESRCH proves a recorded process is absent; inspection errors fail closed. */
3
+ function updateProcessMayBeAlive(pid) {
4
+ try {
5
+ process.kill(pid, 0);
6
+ return true;
7
+ } catch (error) {
8
+ return error.code !== "ESRCH";
9
+ }
10
+ }
11
+ export { updateProcessMayBeAlive };
@@ -1,13 +1,47 @@
1
+ export { acquireRetainedUpdateTrees, type RetainedUpdateTree, type RetainedUpdateTrees, } from './update-retirement';
2
+ import { type ReleaseTrust } from './signed-release';
3
+ import { type RetainedUpdateTrees } from './update-retirement';
4
+ import { type UpdateLaunchGateRecoveryResult } from './update-launch-gate';
1
5
  export type UpdateResumeResult = Readonly<{
2
- status: 'none' | 'in-progress' | 'not-applied';
6
+ status: 'none' | 'in-progress' | 'not-applied' | 'recovery-required';
7
+ } | {
8
+ status: 'staged';
9
+ version: string;
10
+ channel: ReleaseTrust['channel'];
3
11
  } | {
4
12
  status: 'updated';
5
13
  version: string;
6
14
  }>;
15
+ export type UpdateResumeWithRetainedTreesResult = Readonly<{
16
+ status: 'ready';
17
+ resume: UpdateResumeResult;
18
+ retained: RetainedUpdateTrees;
19
+ } | {
20
+ status: 'busy' | 'in-progress' | 'recovery-required';
21
+ }>;
7
22
  /**
8
- * Call on app start. Reports whether an earlier helper installed an update and
9
- * removes the staging directory, unless a helper is still running from it.
23
+ * Reconcile only the schema-3 journal bound to the exact persisted gate. The
24
+ * caller deliberately opts into this operation; generated unmanaged startup
25
+ * reaches it through `recoverPackagedUpdateLaunchGate` before launch admission.
26
+ */
27
+ export declare function recoverUpdateLaunchGate(target: string, trust: ReleaseTrust): Promise<UpdateLaunchGateRecoveryResult>;
28
+ /**
29
+ * Call on app start. Reconcile only while holding the same per-install lock
30
+ * used by stage, helper handoff, and the swap. A valid staged candidate is
31
+ * retained until a helper completes or an explicit caller handles it.
10
32
  */
11
33
  export declare function resumeUpdate(options: {
12
34
  target: string;
35
+ trust: ReleaseTrust;
36
+ currentVersion: string;
13
37
  }): Promise<UpdateResumeResult>;
38
+ /**
39
+ * Resume and acquire retained-generation leases under one install lock. This
40
+ * lets callers with explicit release trust serve old lazy assets alongside a
41
+ * validated pending staged candidate without opening a swap race.
42
+ */
43
+ export declare function resumeUpdateWithRetainedTrees(options: {
44
+ target: string;
45
+ trust: ReleaseTrust;
46
+ currentVersion: string;
47
+ }): Promise<UpdateResumeWithRetainedTreesResult>;