@adea-ai/app-framework 0.39.1 → 0.39.3
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/ci/desktop-release-feed.sh +8 -0
- package/ci/desktop-release.sh +2 -0
- package/dist/cli/release-finalize-cli.d.ts +1 -0
- package/dist/cli/release-finalize-cli.js +17 -13
- package/dist/desktop/client-assets.js +52 -7
- package/dist/developer-app/developer-app.js +30 -12
- package/dist/framework-source.json +1 -1
- package/dist/native/sidecar.d.ts +0 -19
- package/dist/native/sidecar.js +35 -9
- package/dist/native/window-bootstrap.js +3 -1
- package/dist/shell/app-shell.js +49 -60
- package/dist/shell/app-utilities.js +17 -10
- package/dist/shell/media-query.d.ts +2 -1
- package/dist/shell/media-query.js +4 -3
- package/dist/update-helper.bundle.js +4 -4
- package/dist/updates/desktop-updater.js +2 -2
- package/dist/updates/helper/resume-staging.d.ts +4 -1
- package/dist/updates/helper/resume-staging.js +7 -9
- package/dist/updates/helper/update-resume.js +4 -3
- package/dist/updates/install/update-download.d.ts +1 -0
- package/dist/updates/install/update-download.js +10 -2
- package/dist/updates/install/update-swap.d.ts +2 -0
- package/dist/updates/install/update-swap.js +6 -2
- package/dist/updates/launch/update-launch-gate.d.ts +3 -2
- package/dist/updates/launch/update-launch-gate.js +3 -2
- package/dist/updates/locks/update-download-lock.js +2 -2
- package/dist/updates/retention/retirement-inventory.d.ts +4 -0
- package/dist/updates/retention/retirement-inventory.js +6 -4
- package/dist/updates/update-state-store.js +3 -3
- package/package.json +1 -1
- package/src/desktop/client-assets.ts +73 -13
- package/src/shell/app-shell.tsx +38 -47
- package/src/shell/app-utilities.tsx +22 -17
- package/src/shell/media-query.ts +4 -3
- package/src/views/appearance-surface.tsx +3 -3
|
@@ -388,7 +388,7 @@ async function createDesktopUpdater(options) {
|
|
|
388
388
|
options.log(`update channel read failed during health recovery: ${String(error)}`);
|
|
389
389
|
}
|
|
390
390
|
if (channel) {
|
|
391
|
-
const deadline =
|
|
391
|
+
const deadline = performance.now() + HEALTH_ACK_HELPER_WAIT_MS;
|
|
392
392
|
for (;;) {
|
|
393
393
|
if ((await resumeUpdate({
|
|
394
394
|
target,
|
|
@@ -401,7 +401,7 @@ async function createDesktopUpdater(options) {
|
|
|
401
401
|
options.log(`update resume failed during health recovery: ${String(error)}`);
|
|
402
402
|
return null;
|
|
403
403
|
}))?.status !== "in-progress") break;
|
|
404
|
-
const remaining = deadline -
|
|
404
|
+
const remaining = deadline - performance.now();
|
|
405
405
|
if (remaining <= 0) {
|
|
406
406
|
options.log("update helper remains active; health acknowledgement is deferred");
|
|
407
407
|
break;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { type ReleaseTrust } from '../feed/signed-release';
|
|
2
2
|
import { type UpdateStageState } from '../update-state-store';
|
|
3
|
+
import { exists } from '../install/update-swap';
|
|
3
4
|
import type { UpdateResumeResult } from './update-resume';
|
|
4
|
-
export
|
|
5
|
+
export { exists };
|
|
6
|
+
/** Candidate digests proved by a staged resume result, keyed by that result object. */
|
|
7
|
+
export declare const provenCandidateTreeDigests: WeakMap<object, string>;
|
|
5
8
|
export declare function readTreeDigestForProof(path: string): Promise<string | undefined>;
|
|
6
9
|
/** Prove an installed tree, which may gain hard links after the exchange. */
|
|
7
10
|
export declare function readInstalledTreeDigestForProof(path: string): Promise<string | undefined>;
|
|
@@ -4,17 +4,11 @@ import { renameExclusive } from "../../native/native-rename.js";
|
|
|
4
4
|
import { parseUpdateHelperRequest } from "./update-helper.js";
|
|
5
5
|
import { updateProcessMayBeAlive } from "../locks/update-process-liveness.js";
|
|
6
6
|
import { readUpdateHelperRequestFile, writeUpdateStageState } from "../update-state-store.js";
|
|
7
|
-
import { readInstalledUpdateTreeDigest, readUpdateTreeDigest, readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity } from "../install/update-swap.js";
|
|
7
|
+
import { exists, readInstalledUpdateTreeDigest, readUpdateTreeDigest, readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity } from "../install/update-swap.js";
|
|
8
8
|
import { lstat, readdir, rm } from "node:fs/promises";
|
|
9
9
|
import { join } from "node:path";
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
11
|
// src/updates/helper/resume-staging.ts
|
|
12
|
-
async function exists(path) {
|
|
13
|
-
return lstat(path).then(() => true, (error) => {
|
|
14
|
-
if (errorCode(error) === "ENOENT") return false;
|
|
15
|
-
throw error;
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
12
|
/** Validate the empty extraction remainder left by the legacy stage publisher. */
|
|
19
13
|
async function isLegacyExtractionRemainder(path) {
|
|
20
14
|
const info = await lstat(path);
|
|
@@ -25,6 +19,8 @@ async function isLegacyExtractionRemainder(path) {
|
|
|
25
19
|
const payloadInfo = await lstat(payload);
|
|
26
20
|
return payloadInfo.isDirectory() && !payloadInfo.isSymbolicLink() && (await readdir(payload)).length === 0;
|
|
27
21
|
}
|
|
22
|
+
/** Candidate digests proved by a staged resume result, keyed by that result object. */
|
|
23
|
+
var provenCandidateTreeDigests = /* @__PURE__ */ new WeakMap();
|
|
28
24
|
async function readTreeDigestForProof(path) {
|
|
29
25
|
try {
|
|
30
26
|
return await readUpdateTreeDigest(path);
|
|
@@ -179,10 +175,12 @@ async function recoverStagedCandidate(options) {
|
|
|
179
175
|
}
|
|
180
176
|
if (!info.isDirectory() || info.isSymbolicLink()) return { status: "recovery-required" };
|
|
181
177
|
if (await exists(join(staging, "old")) || await readUpdateTreeVersion(candidate) !== state.version || !sameUpdateTreeIdentity(await readUpdateTreeIdentity(candidate), state.candidateTreeIdentity) || state.candidateTreeDigest !== void 0 && !sameUpdateTreeDigest(await readTreeDigestForProof(candidate), state.candidateTreeDigest)) return { status: "recovery-required" };
|
|
182
|
-
|
|
178
|
+
const result = {
|
|
183
179
|
status: "staged",
|
|
184
180
|
version: state.version,
|
|
185
181
|
channel: verified.descriptor.channel
|
|
186
182
|
};
|
|
183
|
+
if (state.candidateTreeDigest !== void 0) provenCandidateTreeDigests.set(result, state.candidateTreeDigest);
|
|
184
|
+
return result;
|
|
187
185
|
}
|
|
188
|
-
export { exists, hasUnknownStagingEntries, readInstalledTreeDigestForProof, readTreeDigestForProof, reconcileSwap, recoverLegacyHandoff, recoverStagedCandidate, resetToStaged };
|
|
186
|
+
export { exists, hasUnknownStagingEntries, provenCandidateTreeDigests, readInstalledTreeDigestForProof, readTreeDigestForProof, reconcileSwap, recoverLegacyHandoff, recoverStagedCandidate, resetToStaged };
|
|
@@ -2,12 +2,12 @@ import { renameExclusive } from "../../native/native-rename.js";
|
|
|
2
2
|
import { hasUpdateHelperArtifacts } from "./update-helper.js";
|
|
3
3
|
import { updateProcessMayBeAlive } from "../locks/update-process-liveness.js";
|
|
4
4
|
import { UpdateLockBusyError, acquireUpdateLock, readUpdateStageState } from "../update-state-store.js";
|
|
5
|
-
import { readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity, updateStagingFor } from "../install/update-swap.js";
|
|
5
|
+
import { exists, readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity, updateStagingFor } from "../install/update-swap.js";
|
|
6
6
|
import { acquireRetainedUpdateTrees, acquireRetainedUpdateTreesWhileLocked } from "../retention/retirement-inventory.js";
|
|
7
7
|
import { reconcileRetirementCleanupMarkerWhileLocked, retireCompletedUpdateWhileLocked } from "../retention/update-retirement.js";
|
|
8
8
|
import { matchesOldTree, updateRetirementPaths } from "../retention/retirement-records.js";
|
|
9
9
|
import { readUpdateLaunchGate } from "../launch/update-launch-gate.js";
|
|
10
|
-
import {
|
|
10
|
+
import { hasUnknownStagingEntries, provenCandidateTreeDigests, readInstalledTreeDigestForProof, reconcileSwap, recoverLegacyHandoff, recoverStagedCandidate, resetToStaged } from "./resume-staging.js";
|
|
11
11
|
import { recoverUpdateLaunchGate } from "./launch-gate-recovery.js";
|
|
12
12
|
import { lstat, readFile, readdir, rmdir, unlink } from "node:fs/promises";
|
|
13
13
|
import { join } from "node:path";
|
|
@@ -246,7 +246,8 @@ async function resumeUpdateWithRetainedTrees(options) {
|
|
|
246
246
|
currentVersion: resumed.status === "updated" ? resumed.version : options.currentVersion,
|
|
247
247
|
...resumed.status === "staged" ? {
|
|
248
248
|
validatedStagedVersion: resumed.version,
|
|
249
|
-
stagedTrust: options.trust
|
|
249
|
+
stagedTrust: options.trust,
|
|
250
|
+
provenCandidateTreeDigest: provenCandidateTreeDigests.get(resumed)
|
|
250
251
|
} : {}
|
|
251
252
|
});
|
|
252
253
|
if (retained.status === "busy") return { status: "busy" };
|
|
@@ -5,6 +5,7 @@ export declare function downloadVerifiedRelease(options: {
|
|
|
5
5
|
descriptor: VerifiedRelease;
|
|
6
6
|
directory: string;
|
|
7
7
|
maxBytes: number;
|
|
8
|
+
/** How long the transfer may make no progress (connect, headers, or between chunks). */
|
|
8
9
|
timeoutMs?: number;
|
|
9
10
|
signal?: AbortSignal;
|
|
10
11
|
fetch?: FetchFunction;
|
|
@@ -8,8 +8,14 @@ async function downloadVerifiedRelease(options) {
|
|
|
8
8
|
const { descriptor, maxBytes } = options;
|
|
9
9
|
const timeout = options.timeoutMs ?? 12e4;
|
|
10
10
|
if (!isVerifiedRelease(descriptor) || !Number.isSafeInteger(maxBytes) || maxBytes < 1 || descriptor.asset.size > maxBytes || !Number.isSafeInteger(timeout) || timeout < 1 || timeout > 6e5) throw new Error("Invalid verified download request");
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const stall = new AbortController();
|
|
12
|
+
let stallTimer;
|
|
13
|
+
const progressed = () => {
|
|
14
|
+
if (stallTimer !== void 0) clearTimeout(stallTimer);
|
|
15
|
+
stallTimer = setTimeout(() => stall.abort(new DOMException("The release download stalled", "TimeoutError")), timeout);
|
|
16
|
+
};
|
|
17
|
+
progressed();
|
|
18
|
+
const signal = options.signal ? AbortSignal.any([stall.signal, options.signal]) : stall.signal;
|
|
13
19
|
const fetcher = options.fetch ?? globalThis.fetch;
|
|
14
20
|
let temporary;
|
|
15
21
|
let response;
|
|
@@ -48,6 +54,7 @@ async function downloadVerifiedRelease(options) {
|
|
|
48
54
|
break;
|
|
49
55
|
}
|
|
50
56
|
if (!(chunk instanceof Uint8Array) || signal.aborted) throw new Error("Invalid download chunk");
|
|
57
|
+
progressed();
|
|
51
58
|
size += chunk.length;
|
|
52
59
|
if (!Number.isSafeInteger(size) || size > descriptor.asset.size) throw new Error("Release download exceeds signed size");
|
|
53
60
|
let offset = 0;
|
|
@@ -82,6 +89,7 @@ async function downloadVerifiedRelease(options) {
|
|
|
82
89
|
});
|
|
83
90
|
throw error;
|
|
84
91
|
} finally {
|
|
92
|
+
clearTimeout(stallTimer);
|
|
85
93
|
if (response?.body && !response.bodyUsed && !response.body.locked) try {
|
|
86
94
|
response.body.cancel().catch(() => {});
|
|
87
95
|
} catch {}
|
|
@@ -47,6 +47,8 @@ export declare function sameUpdateTreeDigest(left: UpdateTreeDigest | undefined,
|
|
|
47
47
|
export declare function syncUpdateTree(tree: string): Promise<void>;
|
|
48
48
|
/** Sync parent directory entries after the atomic exchange has completed. */
|
|
49
49
|
export declare function syncUpdateTreeParent(target: string): Promise<void>;
|
|
50
|
+
/** Whether a path exists, without following a final symbolic link. */
|
|
51
|
+
export declare function exists(path: string): Promise<boolean>;
|
|
50
52
|
/**
|
|
51
53
|
* Exchange the staged `candidate` and the install location atomically. The
|
|
52
54
|
* previous install remains at `staging/candidate` for journaled cleanup.
|
|
@@ -96,7 +96,10 @@ async function readUpdateTreeDigest(tree, options = {}) {
|
|
|
96
96
|
}
|
|
97
97
|
if (before.isDirectory()) {
|
|
98
98
|
writeRecord("directory", relative, before.mode, 0n);
|
|
99
|
-
const names = (await readdir(path)).
|
|
99
|
+
const names = (await readdir(path)).map((name) => ({
|
|
100
|
+
name,
|
|
101
|
+
bytes: Buffer.from(name, "utf8")
|
|
102
|
+
})).toSorted((left, right) => Buffer.compare(left.bytes, right.bytes)).map(({ name }) => name);
|
|
100
103
|
for (const name of names) {
|
|
101
104
|
const child = relative ? `${relative}/${name}` : name;
|
|
102
105
|
await visit(join(path, name), child);
|
|
@@ -185,6 +188,7 @@ async function syncUpdateTreeParent(target) {
|
|
|
185
188
|
await directory.close();
|
|
186
189
|
}
|
|
187
190
|
}
|
|
191
|
+
/** Whether a path exists, without following a final symbolic link. */
|
|
188
192
|
async function exists(path) {
|
|
189
193
|
return lstat(path).then(() => true, (error) => {
|
|
190
194
|
if (errorCode(error) === "ENOENT") return false;
|
|
@@ -230,4 +234,4 @@ async function swapUpdateTreeWhileLocked(options, exchangeOperation = exchangeDi
|
|
|
230
234
|
]);
|
|
231
235
|
if (nextTargetVersion !== candidateVersion || nextCandidateVersion !== previousVersion || !sameUpdateTreeIdentity(nextTargetId, candidateIdentity) || !sameUpdateTreeIdentity(nextCandidateId, previousIdentity)) throw new Error("Atomic update exchange did not preserve both app trees");
|
|
232
236
|
}
|
|
233
|
-
export { readInstalledUpdateTreeDigest, readUpdateTreeDigest, readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity, swapUpdateTree, swapUpdateTreeWhileLocked, syncUpdateTree, syncUpdateTreeParent, updateStagingFor, updateTreeIdentityFromStat };
|
|
237
|
+
export { exists, readInstalledUpdateTreeDigest, readUpdateTreeDigest, readUpdateTreeIdentity, readUpdateTreeVersion, sameUpdateTreeDigest, sameUpdateTreeIdentity, swapUpdateTree, swapUpdateTreeWhileLocked, syncUpdateTree, syncUpdateTreeParent, updateStagingFor, updateTreeIdentityFromStat };
|
|
@@ -89,8 +89,9 @@ export declare function publishUpdateLaunchGate(target: string, helperLiveness:
|
|
|
89
89
|
* The callback must verify journal generation/version and a recovery-safe phase,
|
|
90
90
|
* reconcile the actual tree for that exact gate, and return true only after the
|
|
91
91
|
* reconciliation is durable. False or a thrown error leaves the gate in place.
|
|
92
|
-
*
|
|
93
|
-
* substitutes unless they
|
|
92
|
+
* `recoverPackagedUpdateLaunchGate` (helper/launch-gate-recovery) is its caller;
|
|
93
|
+
* other resume paths are not safe substitutes unless they enforce these
|
|
94
|
+
* ownership and validation steps too.
|
|
94
95
|
*/
|
|
95
96
|
export declare function tryRecoverUpdateLaunchGate(target: string, reconcileJournalAndTree: (gate: UpdateLaunchGate) => Promise<boolean>): Promise<UpdateLaunchGateRecoveryResult>;
|
|
96
97
|
/**
|
|
@@ -279,8 +279,9 @@ async function publishUpdateLaunchGate(target, helperLiveness, input, persistOwn
|
|
|
279
279
|
* The callback must verify journal generation/version and a recovery-safe phase,
|
|
280
280
|
* reconcile the actual tree for that exact gate, and return true only after the
|
|
281
281
|
* reconciliation is durable. False or a thrown error leaves the gate in place.
|
|
282
|
-
*
|
|
283
|
-
* substitutes unless they
|
|
282
|
+
* `recoverPackagedUpdateLaunchGate` (helper/launch-gate-recovery) is its caller;
|
|
283
|
+
* other resume paths are not safe substitutes unless they enforce these
|
|
284
|
+
* ownership and validation steps too.
|
|
284
285
|
*/
|
|
285
286
|
async function tryRecoverUpdateLaunchGate(target, reconcileJournalAndTree) {
|
|
286
287
|
validateTarget(target);
|
|
@@ -45,11 +45,11 @@ async function acquireUpdateDownloadLease(directory, tryOnly = false) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
async function acquireWithin(path, timeoutMs) {
|
|
48
|
-
const deadline =
|
|
48
|
+
const deadline = performance.now() + timeoutMs;
|
|
49
49
|
while (true) {
|
|
50
50
|
const lock = await tryAcquireNativeFileLock(path, "exclusive");
|
|
51
51
|
if (lock) return lock;
|
|
52
|
-
if (
|
|
52
|
+
if (performance.now() >= deadline) throw new Error("Update download lock timed out");
|
|
53
53
|
await Bun.sleep(25);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -59,6 +59,8 @@ export declare function planRetentionWhileLocked(target: string, currentVersion:
|
|
|
59
59
|
allowUnhealthyReads?: boolean;
|
|
60
60
|
validatedStagedVersion?: string;
|
|
61
61
|
stagedTrust?: ReleaseTrust;
|
|
62
|
+
/** A candidate digest the caller proved in this same lock hold. */
|
|
63
|
+
provenCandidateTreeDigest?: string;
|
|
62
64
|
}>): Promise<{
|
|
63
65
|
inventory: Readonly<{
|
|
64
66
|
actualVersion: string;
|
|
@@ -89,5 +91,7 @@ export declare function acquireRetainedUpdateTreesWhileLocked(options: {
|
|
|
89
91
|
currentVersion: string;
|
|
90
92
|
validatedStagedVersion?: string;
|
|
91
93
|
stagedTrust?: ReleaseTrust;
|
|
94
|
+
/** A candidate digest the caller proved in this same lock hold; skips a second full hash. */
|
|
95
|
+
provenCandidateTreeDigest?: string;
|
|
92
96
|
}): Promise<RetainedUpdateTrees>;
|
|
93
97
|
export {};
|
|
@@ -204,10 +204,11 @@ async function planValidatedUpdateRetention(options) {
|
|
|
204
204
|
}
|
|
205
205
|
async function planRetentionWhileLocked(target, currentVersion, options = {}) {
|
|
206
206
|
const staging = updateStagingFor(target);
|
|
207
|
-
|
|
207
|
+
const stagedInfo = await pathInfo(staging);
|
|
208
|
+
if (stagedInfo) {
|
|
208
209
|
if (!options.validatedStagedVersion || !options.stagedTrust) throw new Error("An update staging directory requires recovery");
|
|
209
210
|
const stagedTrust = options.stagedTrust;
|
|
210
|
-
const info =
|
|
211
|
+
const info = stagedInfo;
|
|
211
212
|
const state = await readUpdateStageState(staging);
|
|
212
213
|
const descriptor = state?.signedRelease ? verifyReleaseDescriptor(state.signedRelease, stagedTrust) : { ok: false };
|
|
213
214
|
const candidate = join(staging, "candidate");
|
|
@@ -217,7 +218,7 @@ async function planRetentionWhileLocked(target, currentVersion, options = {}) {
|
|
|
217
218
|
readUpdateTreeIdentity(target),
|
|
218
219
|
readUpdateTreeIdentity(candidate)
|
|
219
220
|
]);
|
|
220
|
-
if (!info?.isDirectory() || info.isSymbolicLink() || !state || state.phase !== "staged" || state.version !== options.validatedStagedVersion || state.previousVersion !== currentVersion || state.helperPid !== void 0 || state.helperOwner !== void 0 || state.launchGateOwner !== void 0 || !state.candidateTreeDigest || !descriptor.ok || descriptor.descriptor.version !== state.version || descriptor.descriptor.channel !== stagedTrust.channel || await readUpdateLaunchGate(target) || await hasUpdateHelperArtifacts(staging) || await pathInfo(join(staging, "old")) || targetVersion !== currentVersion || candidateVersion !== state.version || state.previousTreeIdentity !== void 0 && !sameUpdateTreeIdentity(targetIdentity, state.previousTreeIdentity) || !sameUpdateTreeIdentity(candidateIdentity, state.candidateTreeIdentity) || !sameUpdateTreeDigest(await readUpdateTreeDigest(candidate), state.candidateTreeDigest)) throw new Error("A staged update changed before retained tree acquisition");
|
|
221
|
+
if (!info?.isDirectory() || info.isSymbolicLink() || !state || state.phase !== "staged" || state.version !== options.validatedStagedVersion || state.previousVersion !== currentVersion || state.helperPid !== void 0 || state.helperOwner !== void 0 || state.launchGateOwner !== void 0 || !state.candidateTreeDigest || !descriptor.ok || descriptor.descriptor.version !== state.version || descriptor.descriptor.channel !== stagedTrust.channel || await readUpdateLaunchGate(target) || await hasUpdateHelperArtifacts(staging) || await pathInfo(join(staging, "old")) || targetVersion !== currentVersion || candidateVersion !== state.version || state.previousTreeIdentity !== void 0 && !sameUpdateTreeIdentity(targetIdentity, state.previousTreeIdentity) || !sameUpdateTreeIdentity(candidateIdentity, state.candidateTreeIdentity) || !(sameUpdateTreeDigest(options.provenCandidateTreeDigest, state.candidateTreeDigest) || sameUpdateTreeDigest(await readUpdateTreeDigest(candidate), state.candidateTreeDigest))) throw new Error("A staged update changed before retained tree acquisition");
|
|
221
222
|
}
|
|
222
223
|
const inventory = await readValidatedRetirementInventoryWhileLocked(target, currentVersion, {
|
|
223
224
|
strictRetentionState: true,
|
|
@@ -308,7 +309,8 @@ async function acquireRetainedUpdateTreesWhileLocked(options) {
|
|
|
308
309
|
allowUnhealthyReads: true,
|
|
309
310
|
...options.validatedStagedVersion === void 0 ? {} : {
|
|
310
311
|
validatedStagedVersion: options.validatedStagedVersion,
|
|
311
|
-
stagedTrust: options.stagedTrust
|
|
312
|
+
stagedTrust: options.stagedTrust,
|
|
313
|
+
provenCandidateTreeDigest: options.provenCandidateTreeDigest
|
|
312
314
|
}
|
|
313
315
|
});
|
|
314
316
|
if (lineage.status !== "ready") throw new Error("Update retention lineage requires recovery");
|
|
@@ -18,12 +18,12 @@ function readUpdateHelperRequestFile(staging) {
|
|
|
18
18
|
}
|
|
19
19
|
/** Acquire the stable per-install lock, waiting briefly for short transitions. */
|
|
20
20
|
async function acquireUpdateLock(target, timeoutMs = 5e3) {
|
|
21
|
-
const deadline =
|
|
21
|
+
const deadline = performance.now() + timeoutMs;
|
|
22
22
|
while (true) {
|
|
23
23
|
const lock = await tryAcquireUpdateLock(target);
|
|
24
24
|
if (lock) return lock;
|
|
25
|
-
if (
|
|
26
|
-
await Bun.sleep(Math.min(25, Math.max(1, deadline -
|
|
25
|
+
if (performance.now() >= deadline) throw new UpdateLockBusyError();
|
|
26
|
+
await Bun.sleep(Math.min(25, Math.max(1, deadline - performance.now())));
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
function newUpdateStageState(input) {
|
package/package.json
CHANGED
|
@@ -65,6 +65,51 @@ const unavailable = (status = 404) =>
|
|
|
65
65
|
new Response(null, { status, headers: { 'cache-control': 'no-store' } })
|
|
66
66
|
|
|
67
67
|
const IMMUTABLE_CACHE_CONTROL = 'public, max-age=31536000, immutable'
|
|
68
|
+
const REVALIDATE_CACHE_CONTROL = 'no-cache'
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
* A validator for a file the manifest does not vouch for. It names the file's identity, so
|
|
72
|
+
* any rewrite, replacement or swapped root yields a new tag. With `no-cache` the webview keeps
|
|
73
|
+
* the bytes (and the compiled code it derives from them) and asks before each use; an
|
|
74
|
+
* unchanged file costs a 304 and no read.
|
|
75
|
+
*/
|
|
76
|
+
function fileEntityTag(metadata: Stats): string {
|
|
77
|
+
return `W/"${[metadata.dev, metadata.ino, metadata.size, metadata.mtimeMs, metadata.ctimeMs]
|
|
78
|
+
.map((value) => Math.trunc(value * 1000).toString(36))
|
|
79
|
+
.join('-')}"`
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function matchesEntityTag(request: Request, tag: string): boolean {
|
|
83
|
+
const header = request.headers.get('if-none-match')
|
|
84
|
+
if (!header) return false
|
|
85
|
+
if (header.trim() === '*') return true
|
|
86
|
+
return header.split(',').some((candidate) => {
|
|
87
|
+
const value = candidate.trim()
|
|
88
|
+
return value === tag || `W/${value}` === tag
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const deniedPrefixCache = new Map<string, readonly string[]>()
|
|
93
|
+
|
|
94
|
+
/** Normalized, case-folded denied prefixes, computed once per distinct list. */
|
|
95
|
+
function deniedPrefixes(paths: readonly string[] | undefined): readonly string[] {
|
|
96
|
+
if (!paths?.length) return []
|
|
97
|
+
const key = paths.join('\0')
|
|
98
|
+
let prefixes = deniedPrefixCache.get(key)
|
|
99
|
+
if (!prefixes) {
|
|
100
|
+
prefixes = paths.map(
|
|
101
|
+
(item) =>
|
|
102
|
+
posix
|
|
103
|
+
.normalize('/' + item.replaceAll('\\', '/'))
|
|
104
|
+
.toLowerCase()
|
|
105
|
+
.replace(/\/$/, '') || '/'
|
|
106
|
+
)
|
|
107
|
+
// Lists are few and fixed per host; the bound only guards a caller that builds them per request.
|
|
108
|
+
if (deniedPrefixCache.size >= 32) deniedPrefixCache.clear()
|
|
109
|
+
deniedPrefixCache.set(key, prefixes)
|
|
110
|
+
}
|
|
111
|
+
return prefixes
|
|
112
|
+
}
|
|
68
113
|
|
|
69
114
|
/** A caller-owned, immutable client root kept available for the resolver's lifetime. */
|
|
70
115
|
export type RetainedClientAssetRoot = Readonly<{
|
|
@@ -210,16 +255,14 @@ async function serveClientInternal(
|
|
|
210
255
|
|
|
211
256
|
const logical = clientPath(request)
|
|
212
257
|
if (logical === undefined) return unavailable()
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return prefix === '/' || folded === prefix || folded.startsWith(prefix + '/')
|
|
222
|
-
})
|
|
258
|
+
const prefixes = deniedPrefixes(options.deniedPaths)
|
|
259
|
+
const denied = (path: string) => {
|
|
260
|
+
if (!prefixes.length) return false
|
|
261
|
+
const folded = path.toLowerCase()
|
|
262
|
+
return prefixes.some(
|
|
263
|
+
(prefix) => prefix === '/' || folded === prefix || folded.startsWith(prefix + '/')
|
|
264
|
+
)
|
|
265
|
+
}
|
|
223
266
|
if (denied(logical)) return unavailable()
|
|
224
267
|
let root: string
|
|
225
268
|
try {
|
|
@@ -257,6 +300,23 @@ async function serveClientInternal(
|
|
|
257
300
|
/^[a-f0-9]{64}$/.test(configuredSha256)
|
|
258
301
|
? configuredSha256
|
|
259
302
|
: undefined
|
|
303
|
+
// A file the manifest does not name revalidates instead of being refetched, so the webview
|
|
304
|
+
// keeps its bytes and compiled code across reloads and launches. HTML stays uncached because
|
|
305
|
+
// the host may inject per-launch values into it, and so does a file the manifest names whose
|
|
306
|
+
// bytes disagree with it.
|
|
307
|
+
const entityTag =
|
|
308
|
+
extension !== '.html' && extension !== '.map' && configuredSha256 === undefined
|
|
309
|
+
? fileEntityTag(metadata)
|
|
310
|
+
: undefined
|
|
311
|
+
if (entityTag !== undefined && matchesEntityTag(request, entityTag))
|
|
312
|
+
return new Response(null, {
|
|
313
|
+
status: 304,
|
|
314
|
+
headers: { etag: entityTag, 'cache-control': REVALIDATE_CACHE_CONTROL },
|
|
315
|
+
})
|
|
316
|
+
const uncachedHeaders: Record<string, string> =
|
|
317
|
+
entityTag === undefined
|
|
318
|
+
? { 'cache-control': 'no-store' }
|
|
319
|
+
: { 'cache-control': REVALIDATE_CACHE_CONTROL, etag: entityTag }
|
|
260
320
|
if (request.method === 'HEAD' && !(extension === '.html' && options.transformHtml)) {
|
|
261
321
|
// Open the file to check readability and derive the representation length.
|
|
262
322
|
const file = await open(physical, 'r')
|
|
@@ -279,7 +339,7 @@ async function serveClientInternal(
|
|
|
279
339
|
headers: {
|
|
280
340
|
'content-type': contentType,
|
|
281
341
|
'content-length': String(fileMetadata.size),
|
|
282
|
-
'cache-control':
|
|
342
|
+
...(cacheVerified ? { 'cache-control': IMMUTABLE_CACHE_CONTROL } : uncachedHeaders),
|
|
283
343
|
},
|
|
284
344
|
})
|
|
285
345
|
}
|
|
@@ -297,7 +357,7 @@ async function serveClientInternal(
|
|
|
297
357
|
{
|
|
298
358
|
headers: {
|
|
299
359
|
'content-type': contentType,
|
|
300
|
-
'cache-control':
|
|
360
|
+
...(cacheVerified ? { 'cache-control': IMMUTABLE_CACHE_CONTROL } : uncachedHeaders),
|
|
301
361
|
'content-length': String(metadata.size),
|
|
302
362
|
},
|
|
303
363
|
}
|
|
@@ -314,7 +374,7 @@ async function serveClientInternal(
|
|
|
314
374
|
return new Response(request.method === 'HEAD' ? null : body, {
|
|
315
375
|
headers: {
|
|
316
376
|
'content-type': contentType,
|
|
317
|
-
'cache-control':
|
|
377
|
+
...(cacheVerified ? { 'cache-control': IMMUTABLE_CACHE_CONTROL } : uncachedHeaders),
|
|
318
378
|
...(cacheVerified && request.method === 'GET'
|
|
319
379
|
? { 'content-length': String(body.byteLength) }
|
|
320
380
|
: {}),
|
package/src/shell/app-shell.tsx
CHANGED
|
@@ -17,10 +17,12 @@ import { ActionButton } from '@adea-ai/ui/components/composites/action-button'
|
|
|
17
17
|
import { TooltipProvider } from '@adea-ai/ui/components/ui/tooltip'
|
|
18
18
|
import { PanelLeftClose, PanelLeftIcon, PanelLeftOpen } from 'lucide-solid'
|
|
19
19
|
import { hasEditableKeyboardTarget } from './keyboard-target'
|
|
20
|
+
import { createMediaQuery, DEFAULT_NARROW_QUERY } from './media-query'
|
|
20
21
|
import {
|
|
21
22
|
For,
|
|
22
23
|
Show,
|
|
23
24
|
Suspense,
|
|
25
|
+
children,
|
|
24
26
|
createComputed,
|
|
25
27
|
createEffect,
|
|
26
28
|
createSignal,
|
|
@@ -89,36 +91,17 @@ export type ApplicationShellProps = {
|
|
|
89
91
|
class?: string
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
function createNarrow(query: () => string | undefined) {
|
|
93
|
-
const [narrow, setNarrow] = createSignal(false)
|
|
94
|
-
createEffect(() => {
|
|
95
|
-
const value = query()
|
|
96
|
-
if (!value || typeof window === 'undefined' || !window.matchMedia) return setNarrow(false)
|
|
97
|
-
const media = window.matchMedia(value)
|
|
98
|
-
const update = () => setNarrow(media.matches)
|
|
99
|
-
update()
|
|
100
|
-
media.addEventListener('change', update)
|
|
101
|
-
onCleanup(() => media.removeEventListener('change', update))
|
|
102
|
-
})
|
|
103
|
-
return narrow
|
|
104
|
-
}
|
|
105
|
-
|
|
106
94
|
function getSidebarResponsiveMode(sidebar: ContextualSidebarProps | undefined) {
|
|
107
|
-
|
|
108
|
-
if (sidebar && 'responsiveMode' in sidebar) {
|
|
109
|
-
const mode = sidebar.responsiveMode
|
|
110
|
-
if (mode === 'auto' || mode === 'desktop' || mode === 'mobile') return mode
|
|
111
|
-
}
|
|
112
|
-
return undefined
|
|
95
|
+
return sidebar?.responsiveMode
|
|
113
96
|
}
|
|
114
97
|
|
|
115
98
|
/** Shared chrome and navigation composition; applications own routes and services. */
|
|
116
99
|
export function ApplicationShell(props: ApplicationShellProps) {
|
|
117
100
|
let sidebarToggle: HTMLButtonElement | undefined
|
|
118
|
-
const narrow =
|
|
119
|
-
props.drawer ? (props.narrowQuery ??
|
|
101
|
+
const narrow = createMediaQuery(() =>
|
|
102
|
+
props.drawer ? (props.narrowQuery ?? DEFAULT_NARROW_QUERY) : undefined
|
|
120
103
|
)
|
|
121
|
-
const sidebarMobile =
|
|
104
|
+
const sidebarMobile = createMediaQuery(() =>
|
|
122
105
|
!props.drawer && props.sidebar ? '(max-width: 48rem)' : undefined
|
|
123
106
|
)
|
|
124
107
|
const [sidebarElementMobile, setSidebarElementMobile] = createSignal<boolean>()
|
|
@@ -248,6 +231,37 @@ export function ApplicationShell(props: ApplicationShellProps) {
|
|
|
248
231
|
window.removeEventListener('keydown', handleToggle)
|
|
249
232
|
})
|
|
250
233
|
})
|
|
234
|
+
// The rail slot resolves once, and only while the rail shows: reading a JSX prop in both a
|
|
235
|
+
// `when` and the body would build the app's rail twice.
|
|
236
|
+
const RailContent = () => {
|
|
237
|
+
const rail = children(() => props.rail)
|
|
238
|
+
return (
|
|
239
|
+
<Show
|
|
240
|
+
when={rail()}
|
|
241
|
+
fallback={
|
|
242
|
+
<SideRailSection label="Views">
|
|
243
|
+
<For each={props.destinations}>
|
|
244
|
+
{(item) => (
|
|
245
|
+
<SideRailItem
|
|
246
|
+
as="button"
|
|
247
|
+
type="button"
|
|
248
|
+
label={item.label}
|
|
249
|
+
aria-label={item.label}
|
|
250
|
+
active={props.activeDestination === item.id}
|
|
251
|
+
aria-pressed={props.activeDestination === item.id}
|
|
252
|
+
onClick={() => props.onNavigate(item.id)}
|
|
253
|
+
>
|
|
254
|
+
{item.icon}
|
|
255
|
+
</SideRailItem>
|
|
256
|
+
)}
|
|
257
|
+
</For>
|
|
258
|
+
</SideRailSection>
|
|
259
|
+
}
|
|
260
|
+
>
|
|
261
|
+
{rail()}
|
|
262
|
+
</Show>
|
|
263
|
+
)
|
|
264
|
+
}
|
|
251
265
|
return (
|
|
252
266
|
<TooltipProvider openDelay={150}>
|
|
253
267
|
<div class={`flex h-screen w-screen flex-col overflow-hidden ${props.class ?? ''}`}>
|
|
@@ -302,30 +316,7 @@ export function ApplicationShell(props: ApplicationShellProps) {
|
|
|
302
316
|
searchKeys={props.searchKeys}
|
|
303
317
|
footer={props.footer}
|
|
304
318
|
>
|
|
305
|
-
<
|
|
306
|
-
when={props.rail}
|
|
307
|
-
fallback={
|
|
308
|
-
<SideRailSection label="Views">
|
|
309
|
-
<For each={props.destinations}>
|
|
310
|
-
{(item) => (
|
|
311
|
-
<SideRailItem
|
|
312
|
-
as="button"
|
|
313
|
-
type="button"
|
|
314
|
-
label={item.label}
|
|
315
|
-
aria-label={item.label}
|
|
316
|
-
active={props.activeDestination === item.id}
|
|
317
|
-
aria-pressed={props.activeDestination === item.id}
|
|
318
|
-
onClick={() => props.onNavigate(item.id)}
|
|
319
|
-
>
|
|
320
|
-
{item.icon}
|
|
321
|
-
</SideRailItem>
|
|
322
|
-
)}
|
|
323
|
-
</For>
|
|
324
|
-
</SideRailSection>
|
|
325
|
-
}
|
|
326
|
-
>
|
|
327
|
-
{props.rail}
|
|
328
|
-
</Show>
|
|
319
|
+
<RailContent />
|
|
329
320
|
</ShellRail>
|
|
330
321
|
</Show>
|
|
331
322
|
<AppShellBody>
|
|
@@ -234,7 +234,7 @@ export function ApplicationUtilities(props: ApplicationUtilitiesProps) {
|
|
|
234
234
|
}
|
|
235
235
|
const settingsOpen = () =>
|
|
236
236
|
props.settings?.open !== undefined ? props.settings.open : dialog() === 'settings'
|
|
237
|
-
const updatesAlways = () => props.accountMenu?.updates === 'always'
|
|
237
|
+
const updatesAlways = createMemo(() => props.accountMenu?.updates === 'always')
|
|
238
238
|
const updateAdapter = createMemo(
|
|
239
239
|
() => props.updater ?? browserUpdateAdapter(props.identity.version)
|
|
240
240
|
)
|
|
@@ -327,31 +327,36 @@ export function ApplicationUtilities(props: ApplicationUtilitiesProps) {
|
|
|
327
327
|
})
|
|
328
328
|
})
|
|
329
329
|
const close = () => show(undefined)
|
|
330
|
-
|
|
331
|
-
|
|
330
|
+
// Menu inputs as separate memos: an app that passes `accountMenu` as an inline object (say,
|
|
331
|
+
// with a reactive `busy`) rebuilds that object on every change, and the items must not be
|
|
332
|
+
// rebuilt, nor the open menu re-rendered, for a field they never read.
|
|
333
|
+
const menuSettingsShortcut = createMemo(() => props.accountMenu?.settingsShortcut)
|
|
334
|
+
const menuSettingsKeyshortcuts = createMemo(
|
|
335
|
+
() => props.accountMenu?.settingsKeyshortcuts ?? DEFAULT_SETTINGS_KEYSHORTCUTS
|
|
336
|
+
)
|
|
337
|
+
const menuAppearance = createMemo(() => props.accountMenu?.appearance !== false)
|
|
338
|
+
const hasSettings = createMemo(() => Boolean(props.settings))
|
|
339
|
+
const hasHelp = createMemo(() => Boolean(props.help))
|
|
340
|
+
const hasUpdates = createMemo(() => Boolean(props.updater || props.onUpdates || updatesAlways()))
|
|
341
|
+
const items = createMemo((): AccountMenuItem[] => {
|
|
342
|
+
const onSettings = props.onSettings
|
|
343
|
+
const onHelp = props.onHelp
|
|
332
344
|
const shared = createAppMenuItems({
|
|
333
345
|
primaryItem: props.primaryItem,
|
|
334
|
-
settingsShortcut:
|
|
346
|
+
settingsShortcut: menuSettingsShortcut(),
|
|
335
347
|
onAbout: (target) => open('about', target),
|
|
336
|
-
onUpdates:
|
|
337
|
-
props.updater || props.onUpdates || updatesAlways()
|
|
338
|
-
? (target) => openUpdates(target)
|
|
339
|
-
: undefined,
|
|
348
|
+
onUpdates: hasUpdates() ? (target) => openUpdates(target) : undefined,
|
|
340
349
|
onSettings:
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
onHelp: props.onHelp ?? (props.help ? (target) => open('help', target) : undefined),
|
|
350
|
+
onSettings ?? (hasSettings() ? (target) => openSettings(undefined, target) : undefined),
|
|
351
|
+
onHelp: onHelp ?? (hasHelp() ? (target) => open('help', target) : undefined),
|
|
344
352
|
onFeedback: props.onFeedback,
|
|
345
353
|
}).map((item) => {
|
|
346
354
|
if (item.id === 'settings' && item.shortcut)
|
|
347
|
-
return {
|
|
348
|
-
...item,
|
|
349
|
-
keyshortcuts: menu?.settingsKeyshortcuts ?? DEFAULT_SETTINGS_KEYSHORTCUTS,
|
|
350
|
-
}
|
|
355
|
+
return { ...item, keyshortcuts: menuSettingsKeyshortcuts() }
|
|
351
356
|
if (item.id === 'updates' && updatesAlways()) return { ...item, platform: undefined }
|
|
352
357
|
return item
|
|
353
358
|
})
|
|
354
|
-
if (
|
|
359
|
+
if (!menuAppearance()) return shared
|
|
355
360
|
return [
|
|
356
361
|
{
|
|
357
362
|
id: 'appearance',
|
|
@@ -361,7 +366,7 @@ export function ApplicationUtilities(props: ApplicationUtilitiesProps) {
|
|
|
361
366
|
},
|
|
362
367
|
...shared,
|
|
363
368
|
]
|
|
364
|
-
}
|
|
369
|
+
})
|
|
365
370
|
return (
|
|
366
371
|
<>
|
|
367
372
|
<AccountMenu
|
package/src/shell/media-query.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createComputed, createSignal, onCleanup } from 'solid-js'
|
|
2
2
|
|
|
3
3
|
/** When the application shell counts a window as narrow. */
|
|
4
4
|
export const DEFAULT_NARROW_QUERY = '(max-width: 799px)'
|
|
@@ -42,12 +42,13 @@ function subscribe(query: string, subscriber: (matches: boolean) => void): () =>
|
|
|
42
42
|
/**
|
|
43
43
|
* Reactive `matchMedia`. Components watching the same query share one listener. The query
|
|
44
44
|
* may be reactive and the subscription follows it; an empty or absent query, or a runtime
|
|
45
|
-
* without `matchMedia`, reads as not matching.
|
|
45
|
+
* without `matchMedia`, reads as not matching. The first read already reflects the window, so
|
|
46
|
+
* a narrow window never renders its wide layout for a frame and then swaps it out.
|
|
46
47
|
*/
|
|
47
48
|
export function createMediaQuery(query: string | (() => string | undefined)): () => boolean {
|
|
48
49
|
const text = typeof query === 'function' ? query : () => query
|
|
49
50
|
const [matches, setMatches] = createSignal(false)
|
|
50
|
-
|
|
51
|
+
createComputed(() => {
|
|
51
52
|
const value = text()
|
|
52
53
|
if (!value || !supported()) {
|
|
53
54
|
setMatches(false)
|