@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.
- package/README.md +183 -17
- package/dist/app/create-application.d.ts +2 -0
- package/dist/app/create-application.js +6 -0
- package/dist/app/service-registry.js +4 -0
- package/dist/appearance/custom-theme-import.js +43 -7
- package/dist/appearance/custom-theme-library.d.ts +2 -0
- package/dist/appearance/custom-theme-library.js +5 -1
- package/dist/appearance/theme-record-adapter.js +4 -2
- package/dist/appearance/theme-registry.js +7 -1
- package/dist/cli/cef-helper-cli.js +0 -0
- package/dist/cli/create-application-cli.js +4 -2
- package/dist/cli/electrobun-shortcut-patch-cli.js +0 -0
- package/dist/cli/framework-update-cli.js +0 -0
- package/dist/cli/macos-signing-cli.js +0 -0
- package/dist/cli/release-assets-plan-cli.js +0 -0
- package/dist/cli/release-cut-cli.js +0 -0
- package/dist/cli/release-descriptor-staging-cli.js +0 -0
- package/dist/cli/release-finalize-cli.js +0 -0
- package/dist/cli/release-promote-cli.js +0 -0
- package/dist/cli/release-publish-cli.js +0 -0
- package/dist/cli/release-sign-cli.js +0 -0
- package/dist/cli/release-step-cli.js +6 -1
- package/dist/cli/toolchain-identity-cli.js +0 -0
- package/dist/cli/update-helper-cli.js +28 -6
- package/dist/cli/windows-runtime-patch-cli.js +0 -0
- package/dist/desktop/client-asset-manifest.d.ts +47 -0
- package/dist/desktop/client-asset-manifest.js +114 -0
- package/dist/desktop/client-asset-stream.d.ts +10 -0
- package/dist/desktop/client-asset-stream.js +138 -33
- package/dist/desktop/client-assets.d.ts +20 -0
- package/dist/desktop/client-assets.js +132 -22
- package/dist/desktop/client-response-lifecycle.d.ts +22 -0
- package/dist/desktop/client-response-lifecycle.js +233 -0
- package/dist/desktop/desktop-host.d.ts +40 -2
- package/dist/desktop/desktop-host.js +159 -9
- package/dist/framework-source.json +1 -1
- package/dist/installer/command-artifact.d.ts +4 -2
- package/dist/installer/command-artifact.js +119 -19
- package/dist/installer/installer-identity.d.ts +4 -1
- package/dist/installer/installer-identity.js +6 -3
- package/dist/installer/installer-layout.d.ts +2 -0
- package/dist/installer/installer-layout.js +5 -1
- package/dist/installer/linux-process-group.d.ts +13 -0
- package/dist/installer/linux-process-group.js +58 -0
- package/dist/native/darwin-sync.d.ts +7 -0
- package/dist/native/darwin-sync.js +43 -0
- package/dist/native/desktop-build-hook.js +7 -0
- package/dist/native/directory-exchange.d.ts +10 -0
- package/dist/native/directory-exchange.js +90 -0
- package/dist/native/electrobun-source-patch.d.ts +5 -0
- package/dist/native/electrobun-source-patch.js +19 -1
- package/dist/native/posix-launcher-build.d.ts +24 -0
- package/dist/native/posix-launcher-build.js +232 -0
- package/dist/native/posix-tree-removal.d.ts +36 -0
- package/dist/native/posix-tree-removal.js +425 -0
- package/dist/release/release-steps.d.ts +5 -0
- package/dist/release/release-steps.js +2 -1
- package/dist/update-helper.bundle.js +1483 -105
- package/dist/updates/channel-update-manager.d.ts +5 -0
- package/dist/updates/channel-update-manager.js +13 -1
- package/dist/updates/desktop-updater.d.ts +78 -2
- package/dist/updates/desktop-updater.js +320 -37
- package/dist/updates/launch-environment.d.ts +2 -0
- package/dist/updates/launch-environment.js +4 -0
- package/dist/updates/native-file-lock.d.ts +15 -0
- package/dist/updates/native-file-lock.js +189 -0
- package/dist/updates/packaged-launch-admission.d.ts +13 -0
- package/dist/updates/packaged-launch-admission.js +45 -0
- package/dist/updates/packaged-release-config.d.ts +18 -0
- package/dist/updates/packaged-release-config.js +60 -0
- package/dist/updates/packaged-update-startup.d.ts +44 -0
- package/dist/updates/packaged-update-startup.js +81 -0
- package/dist/updates/update-arm.d.ts +9 -8
- package/dist/updates/update-arm.js +227 -62
- package/dist/updates/update-cleanup-error.d.ts +23 -0
- package/dist/updates/update-cleanup-error.js +65 -0
- package/dist/updates/update-download-cleanup.d.ts +11 -0
- package/dist/updates/update-download-cleanup.js +112 -2
- package/dist/updates/update-download-lock.d.ts +20 -0
- package/dist/updates/update-download-lock.js +73 -0
- package/dist/updates/update-download.d.ts +2 -0
- package/dist/updates/update-download.js +7 -3
- package/dist/updates/update-generation-lease.d.ts +6 -0
- package/dist/updates/update-generation-lease.js +14 -0
- package/dist/updates/update-helper.d.ts +11 -2
- package/dist/updates/update-helper.js +322 -13
- package/dist/updates/update-inherited-launch-lease.d.ts +22 -0
- package/dist/updates/update-inherited-launch-lease.js +58 -0
- package/dist/updates/update-instance-lease.d.ts +15 -0
- package/dist/updates/update-instance-lease.js +25 -0
- package/dist/updates/update-launch-gate.d.ts +137 -0
- package/dist/updates/update-launch-gate.js +617 -0
- package/dist/updates/update-launch.js +3 -1
- package/dist/updates/update-lock.d.ts +12 -0
- package/dist/updates/update-lock.js +18 -0
- package/dist/updates/update-manager.d.ts +2 -0
- package/dist/updates/update-manager.js +9 -2
- package/dist/updates/update-marker.d.ts +7 -0
- package/dist/updates/update-marker.js +62 -0
- package/dist/updates/update-preflight-error.d.ts +7 -0
- package/dist/updates/update-preflight-error.js +11 -0
- package/dist/updates/update-process-fence.d.ts +4 -0
- package/dist/updates/update-process-fence.js +85 -73
- package/dist/updates/update-process-liveness.d.ts +2 -0
- package/dist/updates/update-process-liveness.js +11 -0
- package/dist/updates/update-resume.d.ts +37 -3
- package/dist/updates/update-resume.js +839 -23
- package/dist/updates/update-retention-marker.d.ts +67 -0
- package/dist/updates/update-retention-marker.js +165 -0
- package/dist/updates/update-retention-plan.d.ts +25 -0
- package/dist/updates/update-retention-plan.js +54 -0
- package/dist/updates/update-retention-sync.d.ts +34 -0
- package/dist/updates/update-retention-sync.js +83 -0
- package/dist/updates/update-retirement.d.ts +205 -0
- package/dist/updates/update-retirement.js +1485 -0
- package/dist/updates/update-shutdown.d.ts +16 -4
- package/dist/updates/update-shutdown.js +133 -8
- package/dist/updates/update-state-store.d.ts +58 -0
- package/dist/updates/update-state-store.js +139 -0
- package/dist/updates/update-swap-stage.d.ts +1 -1
- package/dist/updates/update-swap-stage.js +85 -14
- package/dist/updates/update-swap.d.ts +45 -2
- package/dist/updates/update-swap.js +207 -17
- package/package.json +31 -1
- package/src/appearance/custom-theme-import.ts +96 -14
- package/src/appearance/custom-theme-library.ts +5 -0
- package/src/appearance/theme-record-adapter.ts +15 -6
- package/src/appearance/theme-registry.ts +8 -1
- package/src/desktop/client-asset-manifest.ts +207 -0
- package/src/desktop/client-asset-stream.ts +193 -32
- package/src/desktop/client-assets.ts +210 -19
- package/src/desktop/client-response-lifecycle.ts +305 -0
- package/src/native/electrobun-posix-launch-lease.patch +398 -0
- package/templates/application/README.md +50 -0
- package/templates/application/electrobun.config.ts +5 -1
- package/templates/application/scripts/build-desktop.ts +4 -0
- package/templates/application/src/bun/index.ts +173 -16
- 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
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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.
|
|
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 (
|
|
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 (
|
|
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 (
|
|
126
|
-
await Bun.sleep(Math.min(100, Math.max(1, deadline -
|
|
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,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
|
-
*
|
|
9
|
-
*
|
|
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>;
|