@amd-gaia/agent-ui 0.26.0-rc.3 → 0.26.0-rc.32
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 +2 -2
- package/app.config.json +1 -1
- package/assets/tray-iconTemplate.png +0 -0
- package/assets/tray-iconTemplate@2x.png +0 -0
- package/dist/assets/AdvancedSettings-Cm4olLWs.js +1 -0
- package/dist/assets/AutomationsSettings-CWyhLjhu.js +1 -0
- package/dist/assets/ConnectorsPane-RL0Ch1Om.js +1 -0
- package/dist/assets/ConnectorsPane-w-HLcq3n.css +1 -0
- package/dist/assets/DocumentLibrary-BKZdx6rJ.css +1 -0
- package/dist/assets/DocumentLibrary-FUi9SAlf.js +5 -0
- package/dist/assets/FileBrowser-CrRQXiPo.css +1 -0
- package/dist/assets/FileBrowser-DoSLvA8S.js +4 -0
- package/dist/assets/MemoryDashboard-B4AO_CU8.css +1 -0
- package/dist/assets/MemoryDashboard-CwW36Iek.js +1 -0
- package/dist/assets/MessagingSettings-poGVVmpj.js +1 -0
- package/dist/assets/MobileAccessModal-CX4NZmr4.css +1 -0
- package/dist/assets/MobileAccessModal-DZkORMXO.js +2 -0
- package/dist/assets/ScheduleManager-ChQ-9lw8.js +1 -0
- package/dist/assets/ScheduleManager-DQBnf_IN.css +1 -0
- package/dist/assets/{browser-KnDALPx_.js → browser-DfYHeeW3.js} +1 -1
- package/dist/assets/index-B76Qbzm4.js +116 -0
- package/dist/assets/index-D6KUNvpp.css +1 -0
- package/dist/assets/useT-EkYpTPcQ.js +6 -0
- package/dist/assets/zap-0ZlZBaRk.js +1 -0
- package/dist/index.html +17 -4
- package/dist/sw.js +1 -1
- package/main-safety-net.cjs +30 -3
- package/main.cjs +74 -220
- package/package.json +3 -3
- package/preload.cjs +0 -30
- package/services/agent-process-manager.cjs +3 -411
- package/services/appimage-launcher.cjs +183 -0
- package/services/auto-updater.cjs +56 -3
- package/services/backend-installer.cjs +207 -497
- package/services/renderer-gone-dialog.cjs +57 -0
- package/services/tray-manager.cjs +7 -14
- package/services/window-reveal.cjs +42 -0
- package/assets/tray-icon-active.png +0 -0
- package/assets/tray-icon-active@2x.png +0 -0
- package/dist/assets/AdvancedSettings-CaObX4Wa.js +0 -1
- package/dist/assets/ConnectorsPane-D0I07qUd.js +0 -1
- package/dist/assets/ConnectorsPane-DU5VkSj1.css +0 -1
- package/dist/assets/DocumentLibrary-CM6o8j2T.css +0 -1
- package/dist/assets/DocumentLibrary-CijRJVE8.js +0 -4
- package/dist/assets/FileBrowser-BU-MxcRT.js +0 -4
- package/dist/assets/FileBrowser-Cna3BsT7.css +0 -1
- package/dist/assets/MemoryDashboard-BPAUphrI.js +0 -1
- package/dist/assets/MemoryDashboard-DwrWAXi6.css +0 -1
- package/dist/assets/MobileAccessModal-BSC78LTu.js +0 -2
- package/dist/assets/MobileAccessModal-BkVDm3YG.css +0 -1
- package/dist/assets/ScheduleManager-Bc1GA1nB.js +0 -1
- package/dist/assets/ScheduleManager-CjHJ4NbD.css +0 -1
- package/dist/assets/api-BemWvhdJ.js +0 -4
- package/dist/assets/index-BbM3URRX.js +0 -83
- package/dist/assets/index-LLooEbjq.css +0 -1
- package/dist/assets/useT-DRJDft_1.js +0 -3
- package/dist/assets/zap-DSyPz4mM.js +0 -1
- package/services/deep-link-queue.cjs +0 -77
- package/services/deep-link.cjs +0 -230
- package/services/system-metrics.cjs +0 -154
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* backend-installer.cjs — Shared GAIA Python backend bootstrap logic.
|
|
6
6
|
*
|
|
7
|
-
* Single source of truth for
|
|
8
|
-
*
|
|
7
|
+
* Single source of truth for the GAIA backend the app runs. A packaged app
|
|
8
|
+
* runs the frozen `gaia` it ships (<resources>/core) and installs nothing; run
|
|
9
|
+
* from source, it installs `~/.gaia/venv` with `amd-gaia[ui]==<pinned-version>`.
|
|
10
|
+
* Called from both:
|
|
9
11
|
*
|
|
10
12
|
* - `bin/gaia-ui.cjs` (the npm CLI entry point)
|
|
11
13
|
* - `main.cjs` (the Electron app, on first-run bootstrap)
|
|
@@ -17,7 +19,7 @@
|
|
|
17
19
|
* - installBackend(opts) → Promise<void>
|
|
18
20
|
* - ensureBackend(opts) → Promise<string> (returns gaia bin path)
|
|
19
21
|
* - isBackendCurrent() → boolean (nothing to install or refresh)
|
|
20
|
-
* - stopRunningDaemon(opts) → Promise<void> (before
|
|
22
|
+
* - stopRunningDaemon(opts) → Promise<void> (before its files are replaced)
|
|
21
23
|
* - getInstalledVersion(gaiaBin) → string | null
|
|
22
24
|
* - findGaiaBin() → string | null
|
|
23
25
|
* - getState() / setState() → state machine helpers
|
|
@@ -34,7 +36,6 @@
|
|
|
34
36
|
"use strict";
|
|
35
37
|
|
|
36
38
|
const { spawn, spawnSync, execFileSync } = require("child_process");
|
|
37
|
-
const crypto = require("crypto");
|
|
38
39
|
const fs = require("fs");
|
|
39
40
|
const path = require("path");
|
|
40
41
|
const os = require("os");
|
|
@@ -55,6 +56,16 @@ const GAIA_PYTHON_BIN = IS_WINDOWS
|
|
|
55
56
|
? path.join(GAIA_VENV, "Scripts", "python.exe")
|
|
56
57
|
: path.join(GAIA_VENV, "bin", "python");
|
|
57
58
|
|
|
59
|
+
// The frozen `gaia` a packaged app ships (installer/core/freeze.py). A packaged
|
|
60
|
+
// app runs only this one; the venv below is for running the app from source.
|
|
61
|
+
const BUNDLED_GAIA_BIN = process.resourcesPath
|
|
62
|
+
? path.join(process.resourcesPath, "core", IS_WINDOWS ? "gaia.exe" : "gaia")
|
|
63
|
+
: null;
|
|
64
|
+
// Not ~/.gaia/core: install.sh unpacks its own gaia there.
|
|
65
|
+
const APPIMAGE_CORE_ROOT = path.join(GAIA_HOME, "app-core");
|
|
66
|
+
// Written last, so a copy a quit cut short is redone.
|
|
67
|
+
const APPIMAGE_CORE_DONE = ".copied";
|
|
68
|
+
|
|
58
69
|
const STATE_FILE = path.join(GAIA_HOME, "electron-install-state.json");
|
|
59
70
|
const LOG_FILE = path.join(GAIA_HOME, "electron-install.log");
|
|
60
71
|
// hub/installer.py writes this once the flagship is installed; first-run setup installs it.
|
|
@@ -78,55 +89,6 @@ const NETWORK_CHECK_TIMEOUT_MS = 5000;
|
|
|
78
89
|
const INSTALL_MAX_ATTEMPTS = 3;
|
|
79
90
|
const INSTALL_RETRY_BACKOFF_MS = 3000;
|
|
80
91
|
|
|
81
|
-
// ── Bundled `uv` binary ──────────────────────────────────────────────────────
|
|
82
|
-
//
|
|
83
|
-
// Issue #782 / T3: the AppImage now ships a pinned `uv` under
|
|
84
|
-
// `extraResources` (see electron-builder.yml). At runtime we copy it into
|
|
85
|
-
// `~/.gaia/bin/uv` with atomic-rename + SHA256 verification. The previous
|
|
86
|
-
// `curl | sh` path is retained only as an unpackaged-dev fallback so
|
|
87
|
-
// contributors running from source keep working.
|
|
88
|
-
//
|
|
89
|
-
// When bumping uv, update:
|
|
90
|
-
// - .github/workflows/build-installers.yml (tarball .tar.gz SHA256 — archive)
|
|
91
|
-
// - BUNDLED_UV_SHA256 below (extracted binary SHA256, linux-x64/win-x64 only)
|
|
92
|
-
//
|
|
93
|
-
// IMPORTANT: per-platform verification strategy differs:
|
|
94
|
-
// - linux-x64 / win-x64: BUNDLED_UV_SHA256 pins the raw extracted-binary
|
|
95
|
-
// digest (no post-build modification) — deterministic across CI runs.
|
|
96
|
-
// - mac-arm64: NOT pinned here. electron-builder code-signs the bundled uv
|
|
97
|
-
// during packaging (ad-hoc `identity=-` when no Developer ID cert is
|
|
98
|
-
// configured, which is every CI build today), and ad-hoc codesign output
|
|
99
|
-
// depends on the codesign/Xcode toolchain baked into the GitHub-hosted
|
|
100
|
-
// `macos-latest` runner image — which floats and is NOT reproducible
|
|
101
|
-
// across CI runs (observed: macos-15-arm64 vs macos-26-arm64 images
|
|
102
|
-
// produced two different digests for byte-identical source). A fixed
|
|
103
|
-
// SHA256 pin is therefore not deterministic on macOS and would fail
|
|
104
|
-
// ~half of CI runs and brick first-launch on user machines whenever the
|
|
105
|
-
// runner image rolls. Instead, ensureUv() and the dmg-structural-smoke
|
|
106
|
-
// test both run `codesign --verify --strict` against the bundled binary
|
|
107
|
-
// — this validates the on-disk signature is intact/untampered without
|
|
108
|
-
// depending on the exact signing bytes, and still fails loud on
|
|
109
|
-
// corruption or an actually-invalid signature.
|
|
110
|
-
const BUNDLED_UV_VERSION = "0.5.14";
|
|
111
|
-
const BUNDLED_UV_SHA256 = {
|
|
112
|
-
"linux-x64": "0e05d828b5708e8a927724124db3746396afddad6273c47283d7c562dc795bd6",
|
|
113
|
-
// The Windows extracted uv.exe SHA is populated by CI during the
|
|
114
|
-
// build step. The placeholder MUST be replaced in CI before packaging
|
|
115
|
-
// so runtime verification remains strict.
|
|
116
|
-
"win-x64": "055d55eec85a91cfb5e9c8bc7f6463f9883866796c5bcb205fbcdfed9c088c88",
|
|
117
|
-
// mac-arm64: intentionally absent. See the comment block above — the
|
|
118
|
-
// post-codesign digest is not deterministic across CI runner images, so
|
|
119
|
-
// mac-arm64 is verified via codesignVerify() (identity/signature validity)
|
|
120
|
-
// instead of a fixed SHA256 pin. bundledUvPlatformKey() still returns
|
|
121
|
-
// "mac-arm64"; callers must not treat a missing entry here as "unpinned
|
|
122
|
-
// platform" for darwin — see ensureUv()/installBundledUv().
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const MANAGED_UV_DIR = path.join(GAIA_HOME, "bin");
|
|
126
|
-
const MANAGED_UV_BIN = IS_WINDOWS
|
|
127
|
-
? path.join(MANAGED_UV_DIR, "uv.exe")
|
|
128
|
-
: path.join(MANAGED_UV_DIR, "uv");
|
|
129
|
-
|
|
130
92
|
const STATES = Object.freeze({
|
|
131
93
|
IDLE: "idle",
|
|
132
94
|
INSTALLING: "installing",
|
|
@@ -457,10 +419,59 @@ function commandExists(cmd) {
|
|
|
457
419
|
return result.status === 0;
|
|
458
420
|
}
|
|
459
421
|
|
|
422
|
+
/** The `gaia` this packaged app ships, or null when it ships none. */
|
|
423
|
+
function shippedGaiaBin() {
|
|
424
|
+
return BUNDLED_GAIA_BIN && fs.existsSync(BUNDLED_GAIA_BIN) ? BUNDLED_GAIA_BIN : null;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** Where an AppImage keeps its copy of the shipped core for this version. */
|
|
428
|
+
function appImageCoreDir() {
|
|
429
|
+
return path.join(APPIMAGE_CORE_ROOT, toPep440(appVersion()));
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* The shipped `gaia` as the app runs it, or null until it can run. An
|
|
434
|
+
* AppImage's files vanish when the app quits, and the daemon outlives the app,
|
|
435
|
+
* so an AppImage runs a copy under ~/.gaia once ensureBundledCore has made it.
|
|
436
|
+
*/
|
|
437
|
+
function bundledGaiaBin() {
|
|
438
|
+
const shipped = shippedGaiaBin();
|
|
439
|
+
if (!shipped || !process.env.APPIMAGE) return shipped;
|
|
440
|
+
const dir = appImageCoreDir();
|
|
441
|
+
return fs.existsSync(path.join(dir, APPIMAGE_CORE_DONE)) ? path.join(dir, path.basename(shipped)) : null;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/** bundledGaiaBin, after copying an AppImage's core out of its mount. */
|
|
445
|
+
async function ensureBundledCore() {
|
|
446
|
+
const shipped = shippedGaiaBin();
|
|
447
|
+
if (!shipped || !process.env.APPIMAGE) return shipped;
|
|
448
|
+
const ready = bundledGaiaBin();
|
|
449
|
+
if (ready) return ready;
|
|
450
|
+
const dir = appImageCoreDir();
|
|
451
|
+
log(`Copying the backend out of the AppImage to ${dir}`);
|
|
452
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
453
|
+
await fs.promises.cp(path.dirname(shipped), dir, { recursive: true, verbatimSymlinks: true });
|
|
454
|
+
fs.writeFileSync(path.join(dir, APPIMAGE_CORE_DONE), appVersion());
|
|
455
|
+
const copy = bundledGaiaBin();
|
|
456
|
+
const older = listDir(APPIMAGE_CORE_ROOT).filter((name) => name !== path.basename(dir));
|
|
457
|
+
if (older.length) {
|
|
458
|
+
// A daemon from an older copy reads its files as it runs, so it stops first.
|
|
459
|
+
await stopRunningDaemon({ gaiaBin: copy });
|
|
460
|
+
for (const name of older) {
|
|
461
|
+
fs.rmSync(path.join(APPIMAGE_CORE_ROOT, name), { recursive: true, force: true });
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return copy;
|
|
465
|
+
}
|
|
466
|
+
|
|
460
467
|
/**
|
|
461
|
-
* Find the gaia binary
|
|
468
|
+
* Find the gaia binary. A packaged app runs only the one it ships; from
|
|
469
|
+
* source, the managed venv, else PATH.
|
|
462
470
|
*/
|
|
463
471
|
function findGaiaBin() {
|
|
472
|
+
if (shippedGaiaBin()) {
|
|
473
|
+
return bundledGaiaBin();
|
|
474
|
+
}
|
|
464
475
|
if (fs.existsSync(GAIA_BIN)) {
|
|
465
476
|
return GAIA_BIN;
|
|
466
477
|
}
|
|
@@ -633,9 +644,9 @@ function liveDaemonPid() {
|
|
|
633
644
|
* stop that fails with no daemon running (a broken venv, say) must not block
|
|
634
645
|
* the reinstall that repairs it.
|
|
635
646
|
*/
|
|
636
|
-
async function stopRunningDaemon({ timeoutMs = DAEMON_STOP_TIMEOUT_MS, signal } = {}) {
|
|
637
|
-
if (!fs.existsSync(
|
|
638
|
-
const result = await runCommand(
|
|
647
|
+
async function stopRunningDaemon({ gaiaBin = GAIA_BIN, timeoutMs = DAEMON_STOP_TIMEOUT_MS, signal } = {}) {
|
|
648
|
+
if (!fs.existsSync(gaiaBin) || (gaiaBin === GAIA_BIN && !fs.existsSync(GAIA_PYTHON_BIN))) return;
|
|
649
|
+
const result = await runCommand(gaiaBin, ["daemon", "stop"], {
|
|
639
650
|
stageLabel: "daemon",
|
|
640
651
|
timeoutMs,
|
|
641
652
|
signal,
|
|
@@ -666,7 +677,7 @@ async function stopRunningDaemon({ timeoutMs = DAEMON_STOP_TIMEOUT_MS, signal }
|
|
|
666
677
|
const why = result.timedOut
|
|
667
678
|
? `did not stop within ${Math.round(timeoutMs / 1000)} seconds`
|
|
668
679
|
: `could not be stopped (gaia daemon stop exit ${result.code})`;
|
|
669
|
-
log(`To stop it by hand: ${
|
|
680
|
+
log(`To stop it by hand: ${gaiaBin} daemon stop`);
|
|
670
681
|
throw new InstallError(
|
|
671
682
|
`GAIA's background service (the GAIA daemon, pid ${pid}) ${why}, so its files can't be updated.`,
|
|
672
683
|
{
|
|
@@ -1188,7 +1199,7 @@ async function runPreChecks(opts = {}) {
|
|
|
1188
1199
|
// ── uv install ───────────────────────────────────────────────────────────────
|
|
1189
1200
|
|
|
1190
1201
|
class InstallError extends Error {
|
|
1191
|
-
constructor(message, { stage, code, suggestion, reason, lockedFiles } = {}) {
|
|
1202
|
+
constructor(message, { stage, code, suggestion, reason, lockedFiles, keepState } = {}) {
|
|
1192
1203
|
super(message);
|
|
1193
1204
|
this.name = "InstallError";
|
|
1194
1205
|
this.stage = stage || null;
|
|
@@ -1197,6 +1208,8 @@ class InstallError extends Error {
|
|
|
1197
1208
|
this.reason = reason || null;
|
|
1198
1209
|
// The files another program held open, for main to find who holds them.
|
|
1199
1210
|
this.lockedFiles = lockedFiles || null;
|
|
1211
|
+
// Nothing was touched, so the recorded state still holds.
|
|
1212
|
+
this.keepState = Boolean(keepState);
|
|
1200
1213
|
}
|
|
1201
1214
|
}
|
|
1202
1215
|
|
|
@@ -1208,446 +1221,119 @@ class InstallCancelled extends Error {
|
|
|
1208
1221
|
}
|
|
1209
1222
|
}
|
|
1210
1223
|
|
|
1211
|
-
/**
|
|
1212
|
-
function
|
|
1213
|
-
|
|
1214
|
-
if (isTlsCertError(output)) return FAILURE_REASONS.TLS;
|
|
1215
|
-
if (isTransientNetworkError(output)) return FAILURE_REASONS.NETWORK;
|
|
1216
|
-
return null;
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
/**
|
|
1220
|
-
* Which `extraResources` subdirectory holds the bundled uv for this host.
|
|
1221
|
-
* Returns null for platforms we don't yet ship a binary for (falls through
|
|
1222
|
-
* to the dev fallback).
|
|
1223
|
-
*/
|
|
1224
|
-
function bundledUvPlatformKey() {
|
|
1225
|
-
if (process.platform === "linux" && process.arch === "x64") return "linux-x64";
|
|
1226
|
-
if (process.platform === "win32" && process.arch === "x64") return "win-x64";
|
|
1227
|
-
if (process.platform === "darwin" && process.arch === "arm64") return "mac-arm64";
|
|
1228
|
-
return null;
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
/**
|
|
1232
|
-
* Stream-SHA256 a file. Returns lowercase hex.
|
|
1233
|
-
*/
|
|
1234
|
-
function sha256File(filePath) {
|
|
1235
|
-
return new Promise((resolve, reject) => {
|
|
1236
|
-
const hash = crypto.createHash("sha256");
|
|
1237
|
-
const stream = fs.createReadStream(filePath);
|
|
1238
|
-
stream.on("error", reject);
|
|
1239
|
-
stream.on("data", (chunk) => hash.update(chunk));
|
|
1240
|
-
stream.on("end", () => resolve(hash.digest("hex")));
|
|
1241
|
-
});
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
/**
|
|
1245
|
-
* Verify a macOS binary's code signature is structurally intact via
|
|
1246
|
-
* `codesign --verify --strict`. Used in place of a fixed SHA256 pin for
|
|
1247
|
-
* mac-arm64 (see the BUNDLED_UV_SHA256 comment) — ad-hoc-signed binaries
|
|
1248
|
-
* (identity=-, which is every CI build today) pass this check, but a
|
|
1249
|
-
* corrupted, tampered, or actually-unsigned binary fails it. This does NOT
|
|
1250
|
-
* depend on the specific bytes any given codesign/Xcode toolchain produces,
|
|
1251
|
-
* so it is stable across GitHub-hosted runner image rollovers where a fixed
|
|
1252
|
-
* digest pin is not.
|
|
1253
|
-
*
|
|
1254
|
-
* @param {string} binPath
|
|
1255
|
-
* @returns {{ ok: boolean, output: string }}
|
|
1256
|
-
*/
|
|
1257
|
-
function codesignVerify(binPath) {
|
|
1258
|
-
const result = spawnSync("codesign", ["--verify", "--strict", binPath], {
|
|
1259
|
-
encoding: "utf8",
|
|
1260
|
-
});
|
|
1261
|
-
const output = `${result.stdout || ""}${result.stderr || ""}`.trim();
|
|
1262
|
-
return { ok: result.status === 0, output };
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
/**
|
|
1266
|
-
* Resolve the bundled uv binary path inside the Electron resources dir.
|
|
1267
|
-
* Returns null if this isn't an Electron-packaged runtime (no
|
|
1268
|
-
* `process.resourcesPath`) or if the host platform isn't bundled.
|
|
1269
|
-
*/
|
|
1270
|
-
function findBundledUvResource() {
|
|
1271
|
-
const key = bundledUvPlatformKey();
|
|
1272
|
-
if (!key) return null;
|
|
1273
|
-
const resourcesPath = process.resourcesPath;
|
|
1274
|
-
if (!resourcesPath) return null;
|
|
1275
|
-
const candidate = path.join(
|
|
1276
|
-
resourcesPath,
|
|
1277
|
-
"vendor",
|
|
1278
|
-
"uv",
|
|
1279
|
-
key,
|
|
1280
|
-
IS_WINDOWS ? "uv.exe" : "uv"
|
|
1281
|
-
);
|
|
1282
|
-
return fs.existsSync(candidate) ? candidate : null;
|
|
1224
|
+
/** ENOSPC on POSIX (os error 28) and ERROR_DISK_FULL on Windows (os error 112). */
|
|
1225
|
+
function isDiskFullError(output) {
|
|
1226
|
+
return /No space left on device|not enough space on the disk|os error (28|112)\b/i.test(output || "");
|
|
1283
1227
|
}
|
|
1284
1228
|
|
|
1285
1229
|
/**
|
|
1286
|
-
*
|
|
1287
|
-
*
|
|
1288
|
-
*
|
|
1289
|
-
* Verification strategy differs by platform (see the BUNDLED_UV_SHA256
|
|
1290
|
-
* comment): mac-arm64 uses `codesign --verify --strict` (darwin only —
|
|
1291
|
-
* post-codesign SHA256 is not deterministic across CI runner images);
|
|
1292
|
-
* linux-x64 / win-x64 use the SHA256 pin in BUNDLED_UV_SHA256, which IS
|
|
1293
|
-
* deterministic for those platforms (no post-build re-signing).
|
|
1294
|
-
*
|
|
1295
|
-
* Writes to `uv.tmp-<pid>-<rand>` with mode 0o700, verifies, `chmod +x`,
|
|
1296
|
-
* then `fs.rename()` (atomic on same filesystem).
|
|
1230
|
+
* The pre-check found too little space to install. `keep`: a working install
|
|
1231
|
+
* is in place and the refusal leaves it, and its recorded state, untouched.
|
|
1297
1232
|
*/
|
|
1298
|
-
|
|
1299
|
-
const
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
fs.mkdirSync(MANAGED_UV_DIR, { recursive: true });
|
|
1314
|
-
} catch (err) {
|
|
1315
|
-
throw new InstallError(
|
|
1316
|
-
`Could not create ${MANAGED_UV_DIR}: ${err.message}`,
|
|
1317
|
-
{ stage: STAGES.ENSURE_UV }
|
|
1318
|
-
);
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
const rand = crypto.randomBytes(6).toString("hex");
|
|
1322
|
-
const tmpPath = path.join(
|
|
1323
|
-
MANAGED_UV_DIR,
|
|
1324
|
-
`uv.tmp-${process.pid}-${rand}${IS_WINDOWS ? ".exe" : ""}`
|
|
1325
|
-
);
|
|
1326
|
-
|
|
1327
|
-
// Copy source → tmp with restrictive mode.
|
|
1328
|
-
await new Promise((resolve, reject) => {
|
|
1329
|
-
const rs = fs.createReadStream(sourcePath);
|
|
1330
|
-
const ws = fs.createWriteStream(tmpPath, { mode: 0o700 });
|
|
1331
|
-
rs.on("error", reject);
|
|
1332
|
-
ws.on("error", reject);
|
|
1333
|
-
ws.on("finish", resolve);
|
|
1334
|
-
rs.pipe(ws);
|
|
1335
|
-
});
|
|
1336
|
-
|
|
1337
|
-
if (isDarwin) {
|
|
1338
|
-
// chmod BEFORE codesign --verify: codesign needs the execute bit to
|
|
1339
|
-
// resolve the binary's designated requirement on some toolchains.
|
|
1340
|
-
try {
|
|
1341
|
-
fs.chmodSync(tmpPath, 0o700);
|
|
1342
|
-
} catch (err) {
|
|
1343
|
-
log(`Warning: chmod on tmp uv failed: ${err.message}`);
|
|
1344
|
-
}
|
|
1345
|
-
const { ok, output } = codesignVerify(tmpPath);
|
|
1346
|
-
if (!ok) {
|
|
1347
|
-
try { fs.unlinkSync(tmpPath); } catch { /* ignore */ }
|
|
1348
|
-
throw new InstallError(
|
|
1349
|
-
`Bundled uv failed code signature verification (codesign --verify --strict): ${output || "no output"}`,
|
|
1350
|
-
{
|
|
1351
|
-
stage: STAGES.ENSURE_UV,
|
|
1352
|
-
suggestion:
|
|
1353
|
-
"The AppImage/installer may be corrupt. Re-download from https://amd-gaia.ai and try again.",
|
|
1354
|
-
}
|
|
1355
|
-
);
|
|
1356
|
-
}
|
|
1357
|
-
log("Bundled uv passed codesign --verify --strict");
|
|
1358
|
-
} else {
|
|
1359
|
-
let actual;
|
|
1360
|
-
try {
|
|
1361
|
-
actual = await sha256File(tmpPath);
|
|
1362
|
-
} catch (err) {
|
|
1363
|
-
try { fs.unlinkSync(tmpPath); } catch { /* ignore */ }
|
|
1364
|
-
throw new InstallError(
|
|
1365
|
-
`Could not hash copied uv binary: ${err.message}`,
|
|
1366
|
-
{ stage: STAGES.ENSURE_UV }
|
|
1367
|
-
);
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
if (actual !== expected) {
|
|
1371
|
-
try { fs.unlinkSync(tmpPath); } catch { /* ignore */ }
|
|
1372
|
-
throw new InstallError(
|
|
1373
|
-
`Bundled uv SHA256 mismatch (expected ${expected}, got ${actual}).`,
|
|
1374
|
-
{
|
|
1375
|
-
stage: STAGES.ENSURE_UV,
|
|
1376
|
-
suggestion:
|
|
1377
|
-
"The AppImage/installer may be corrupt. Re-download from https://amd-gaia.ai and try again.",
|
|
1378
|
-
}
|
|
1379
|
-
);
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
try {
|
|
1383
|
-
if (!IS_WINDOWS) fs.chmodSync(tmpPath, 0o700);
|
|
1384
|
-
} catch (err) {
|
|
1385
|
-
log(`Warning: chmod on tmp uv failed: ${err.message}`);
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
|
-
try {
|
|
1390
|
-
// rename() is atomic on the same filesystem on POSIX; on Windows
|
|
1391
|
-
// it requires the target not to exist, so unlink first.
|
|
1392
|
-
if (IS_WINDOWS && fs.existsSync(MANAGED_UV_BIN)) {
|
|
1393
|
-
try { fs.unlinkSync(MANAGED_UV_BIN); } catch { /* ignore */ }
|
|
1233
|
+
function lowDiskError(disk, { keep, installedVersion }) {
|
|
1234
|
+
const mb = (bytes) => Math.round(bytes / (1024 * 1024));
|
|
1235
|
+
const requiredMb = mb(disk.requiredBytes);
|
|
1236
|
+
const freeMb = disk.freeBytes != null ? mb(disk.freeBytes) : null;
|
|
1237
|
+
const need = freeMb != null ? `${requiredMb - freeMb} MB more` : `${requiredMb} MB`;
|
|
1238
|
+
const kept = keep ? ` Your installed GAIA${installedVersion ? ` ${installedVersion}` : ""} was not changed.` : "";
|
|
1239
|
+
return new InstallError(
|
|
1240
|
+
`Not enough free disk space${keep ? " to update GAIA" : ""}. Required: ${requiredMb} MB${
|
|
1241
|
+
freeMb != null ? `, available: ${freeMb} MB` : ""
|
|
1242
|
+
}.${kept}`,
|
|
1243
|
+
{
|
|
1244
|
+
stage: STAGES.PRE_CHECKS,
|
|
1245
|
+
reason: FAILURE_REASONS.DISK,
|
|
1246
|
+
suggestion: `Free at least ${need} at ${path.dirname(GAIA_HOME)}, then try again.`,
|
|
1247
|
+
keepState: keep,
|
|
1394
1248
|
}
|
|
1395
|
-
|
|
1396
|
-
} catch (err) {
|
|
1397
|
-
try { fs.unlinkSync(tmpPath); } catch { /* ignore */ }
|
|
1398
|
-
throw new InstallError(
|
|
1399
|
-
`Could not install uv to ${MANAGED_UV_BIN}: ${err.message}`,
|
|
1400
|
-
{ stage: STAGES.ENSURE_UV }
|
|
1401
|
-
);
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
log(`Installed bundled uv v${BUNDLED_UV_VERSION} → ${MANAGED_UV_BIN}`);
|
|
1405
|
-
return MANAGED_UV_BIN;
|
|
1249
|
+
);
|
|
1406
1250
|
}
|
|
1407
1251
|
|
|
1408
|
-
/**
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
if (
|
|
1414
|
-
|
|
1415
|
-
!process.env.PATH.split(path.delimiter).includes(MANAGED_UV_DIR)
|
|
1416
|
-
) {
|
|
1417
|
-
process.env.PATH = `${MANAGED_UV_DIR}${path.delimiter}${process.env.PATH}`;
|
|
1418
|
-
log(`Prepended ${MANAGED_UV_DIR} to PATH for this process`);
|
|
1419
|
-
}
|
|
1252
|
+
/** Which FAILURE_REASONS a uv failure's output shows, or null. */
|
|
1253
|
+
function failureReason(output) {
|
|
1254
|
+
if (isDiskFullError(output)) return FAILURE_REASONS.DISK;
|
|
1255
|
+
if (isFileLockedError(output)) return FAILURE_REASONS.LOCKED;
|
|
1256
|
+
if (isTlsCertError(output)) return FAILURE_REASONS.TLS;
|
|
1257
|
+
if (isTransientNetworkError(output)) return FAILURE_REASONS.NETWORK;
|
|
1258
|
+
return null;
|
|
1420
1259
|
}
|
|
1421
1260
|
|
|
1422
1261
|
/**
|
|
1423
|
-
* Ensure `uv` is available.
|
|
1424
|
-
*
|
|
1425
|
-
*
|
|
1426
|
-
* 2. Bundled binary in process.resourcesPath/vendor/uv/<platform>/uv:
|
|
1427
|
-
* copy atomically to ~/.gaia/bin/uv with the same platform-appropriate
|
|
1428
|
-
* verification.
|
|
1429
|
-
* 3. DEV-ONLY fallback (app.isPackaged === false OR no resourcesPath):
|
|
1430
|
-
* the original `curl | sh` from astral.sh. Not a shipped-user path.
|
|
1431
|
-
* 4. System `uv` on PATH (last resort — unverified version).
|
|
1262
|
+
* Ensure `uv` is available. Only running the app from source gets here: a
|
|
1263
|
+
* packaged app ships its backend. Uses the uv on PATH, else installs it from
|
|
1264
|
+
* astral.sh.
|
|
1432
1265
|
*
|
|
1433
1266
|
* Throws InstallError on failure.
|
|
1434
1267
|
*/
|
|
1435
|
-
async function ensureUv({ onProgress,
|
|
1268
|
+
async function ensureUv({ onProgress, signal } = {}) {
|
|
1436
1269
|
const report = makeProgressReporter(onProgress);
|
|
1437
1270
|
report(STAGES.ENSURE_UV, 0, "Checking uv (Python package manager)");
|
|
1438
1271
|
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
// Fast path: warm install already on disk and still passes verification.
|
|
1444
|
-
if (isDarwin && fs.existsSync(MANAGED_UV_BIN)) {
|
|
1445
|
-
const { ok, output } = codesignVerify(MANAGED_UV_BIN);
|
|
1446
|
-
if (ok) {
|
|
1447
|
-
log(`Managed uv at ${MANAGED_UV_BIN} passed codesign --verify --strict — reusing`);
|
|
1448
|
-
addManagedBinToPath();
|
|
1449
|
-
report(STAGES.ENSURE_UV, 100, "uv ready (cached)");
|
|
1450
|
-
return;
|
|
1451
|
-
}
|
|
1452
|
-
log(`Managed uv failed codesign verification (${output || "no output"}) — replacing`);
|
|
1453
|
-
} else if (expectedSha && fs.existsSync(MANAGED_UV_BIN)) {
|
|
1454
|
-
try {
|
|
1455
|
-
const actual = await sha256File(MANAGED_UV_BIN);
|
|
1456
|
-
if (actual === expectedSha) {
|
|
1457
|
-
log(`Managed uv at ${MANAGED_UV_BIN} passed SHA256 check — reusing`);
|
|
1458
|
-
addManagedBinToPath();
|
|
1459
|
-
report(STAGES.ENSURE_UV, 100, "uv ready (cached)");
|
|
1460
|
-
return;
|
|
1461
|
-
}
|
|
1462
|
-
log(
|
|
1463
|
-
`Managed uv hash mismatch (expected ${expectedSha}, got ${actual}) — replacing`
|
|
1464
|
-
);
|
|
1465
|
-
} catch (err) {
|
|
1466
|
-
log(`Could not verify managed uv: ${err.message} — replacing`);
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
// Bundled path (the shipped-user path — AppImage, NSIS, DMG).
|
|
1471
|
-
const bundled = findBundledUvResource();
|
|
1472
|
-
if (bundled && platformKey) {
|
|
1473
|
-
report(STAGES.ENSURE_UV, 30, "Installing bundled uv");
|
|
1474
|
-
log(`Using bundled uv from ${bundled}`);
|
|
1475
|
-
|
|
1476
|
-
// Verify the source resource before copying — catches installer
|
|
1477
|
-
// corruption before we touch the user's home. mac-arm64 uses
|
|
1478
|
-
// codesign --verify --strict (see BUNDLED_UV_SHA256 comment for why a
|
|
1479
|
-
// fixed digest isn't viable there); other platforms use the SHA256 pin,
|
|
1480
|
-
// which CI must have populated — a missing/placeholder value is a
|
|
1481
|
-
// build-time error, rejected at runtime here.
|
|
1482
|
-
if (isDarwin) {
|
|
1483
|
-
const { ok, output } = codesignVerify(bundled);
|
|
1484
|
-
if (!ok) {
|
|
1485
|
-
throw new InstallError(
|
|
1486
|
-
`Bundled uv resource failed code signature verification (codesign --verify --strict): ${output || "no output"}`,
|
|
1487
|
-
{
|
|
1488
|
-
stage: STAGES.ENSURE_UV,
|
|
1489
|
-
suggestion:
|
|
1490
|
-
"The installer appears to be corrupt. Re-download GAIA from https://amd-gaia.ai and try again.",
|
|
1491
|
-
}
|
|
1492
|
-
);
|
|
1493
|
-
}
|
|
1494
|
-
} else {
|
|
1495
|
-
const srcHash = await sha256File(bundled);
|
|
1496
|
-
if (srcHash !== expectedSha) {
|
|
1497
|
-
throw new InstallError(
|
|
1498
|
-
`Bundled uv resource SHA256 mismatch (expected ${expectedSha}, got ${srcHash}).`,
|
|
1499
|
-
{
|
|
1500
|
-
stage: STAGES.ENSURE_UV,
|
|
1501
|
-
suggestion:
|
|
1502
|
-
"The installer appears to be corrupt. Re-download GAIA from https://amd-gaia.ai and try again.",
|
|
1503
|
-
}
|
|
1504
|
-
);
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
await installBundledUv(bundled, platformKey);
|
|
1508
|
-
addManagedBinToPath();
|
|
1509
|
-
report(STAGES.ENSURE_UV, 100, "uv installed (bundled)");
|
|
1272
|
+
if (commandExists("uv")) {
|
|
1273
|
+
log("uv already on PATH (dev) — using system install");
|
|
1274
|
+
report(STAGES.ENSURE_UV, 100, "uv is already installed (system)");
|
|
1510
1275
|
return;
|
|
1511
1276
|
}
|
|
1512
1277
|
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
],
|
|
1534
|
-
{ stageLabel: "uv-install-dev", signal }
|
|
1535
|
-
);
|
|
1536
|
-
} else {
|
|
1537
|
-
result = await runCommand(
|
|
1538
|
-
"bash",
|
|
1539
|
-
["-c", "curl -LsSf https://astral.sh/uv/install.sh | sh"],
|
|
1540
|
-
{ stageLabel: "uv-install-dev", signal }
|
|
1541
|
-
);
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
if (result.code !== 0) {
|
|
1545
|
-
throw new InstallError(
|
|
1546
|
-
`Could not install uv automatically (exit code ${result.code}).`,
|
|
1547
|
-
{
|
|
1548
|
-
stage: STAGES.ENSURE_UV,
|
|
1549
|
-
code: result.code,
|
|
1550
|
-
suggestion: IS_WINDOWS
|
|
1551
|
-
? 'Install uv manually: powershell -c "irm https://astral.sh/uv/install.ps1 | iex"'
|
|
1552
|
-
: "Install uv manually: curl -LsSf https://astral.sh/uv/install.sh | sh",
|
|
1553
|
-
}
|
|
1554
|
-
);
|
|
1555
|
-
}
|
|
1278
|
+
log("No uv on PATH — installing it from astral.sh");
|
|
1279
|
+
let result;
|
|
1280
|
+
if (IS_WINDOWS) {
|
|
1281
|
+
result = await runCommand(
|
|
1282
|
+
"powershell",
|
|
1283
|
+
[
|
|
1284
|
+
"-ExecutionPolicy",
|
|
1285
|
+
"Bypass",
|
|
1286
|
+
"-Command",
|
|
1287
|
+
"irm https://astral.sh/uv/install.ps1 | iex",
|
|
1288
|
+
],
|
|
1289
|
+
{ stageLabel: "uv-install", signal }
|
|
1290
|
+
);
|
|
1291
|
+
} else {
|
|
1292
|
+
result = await runCommand(
|
|
1293
|
+
"bash",
|
|
1294
|
+
["-c", "curl -LsSf https://astral.sh/uv/install.sh | sh"],
|
|
1295
|
+
{ stageLabel: "uv-install", signal }
|
|
1296
|
+
);
|
|
1297
|
+
}
|
|
1556
1298
|
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
}
|
|
1299
|
+
if (result.code !== 0) {
|
|
1300
|
+
throw new InstallError(
|
|
1301
|
+
`Could not install uv automatically (exit code ${result.code}).`,
|
|
1302
|
+
{
|
|
1303
|
+
stage: STAGES.ENSURE_UV,
|
|
1304
|
+
code: result.code,
|
|
1305
|
+
suggestion: IS_WINDOWS
|
|
1306
|
+
? 'Install uv manually: powershell -c "irm https://astral.sh/uv/install.ps1 | iex"'
|
|
1307
|
+
: "Install uv manually: curl -LsSf https://astral.sh/uv/install.sh | sh",
|
|
1567
1308
|
}
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
if (!commandExists("uv")) {
|
|
1571
|
-
throw new InstallError(
|
|
1572
|
-
"uv installed but not found on PATH. A shell restart may be required.",
|
|
1573
|
-
{
|
|
1574
|
-
stage: STAGES.ENSURE_UV,
|
|
1575
|
-
suggestion:
|
|
1576
|
-
"Restart your terminal or reboot, then re-launch GAIA. If the problem persists, install uv manually from https://astral.sh/uv",
|
|
1577
|
-
}
|
|
1578
|
-
);
|
|
1579
|
-
}
|
|
1580
|
-
|
|
1581
|
-
report(STAGES.ENSURE_UV, 100, "uv installed (dev fallback)");
|
|
1582
|
-
return;
|
|
1309
|
+
);
|
|
1583
1310
|
}
|
|
1584
1311
|
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
"powershell",
|
|
1595
|
-
[
|
|
1596
|
-
"-ExecutionPolicy",
|
|
1597
|
-
"Bypass",
|
|
1598
|
-
"-Command",
|
|
1599
|
-
"irm https://astral.sh/uv/install.ps1 | iex",
|
|
1600
|
-
],
|
|
1601
|
-
{ stageLabel: "uv-install-packaged-rescue", signal }
|
|
1602
|
-
);
|
|
1603
|
-
if (rescue.code === 0) {
|
|
1604
|
-
// Ensure common install locations are present on PATH for this
|
|
1605
|
-
// process in case the installer placed uv in a user-local bin.
|
|
1606
|
-
const candidates = [
|
|
1607
|
-
path.join(os.homedir(), ".local", "bin"),
|
|
1608
|
-
path.join(os.homedir(), ".cargo", "bin"),
|
|
1609
|
-
];
|
|
1610
|
-
for (const uvDir of candidates) {
|
|
1611
|
-
if (process.env.PATH && !process.env.PATH.includes(uvDir)) {
|
|
1612
|
-
process.env.PATH = `${uvDir}${path.delimiter}${process.env.PATH}`;
|
|
1613
|
-
log(`Added ${uvDir} to PATH for this process`);
|
|
1614
|
-
}
|
|
1615
|
-
}
|
|
1616
|
-
if (commandExists("uv")) {
|
|
1617
|
-
log("Packaged Windows: uv installed and found on PATH (rescue succeeded)");
|
|
1618
|
-
addManagedBinToPath();
|
|
1619
|
-
report(STAGES.ENSURE_UV, 100, "uv ready (system, unverified)");
|
|
1620
|
-
return;
|
|
1621
|
-
}
|
|
1622
|
-
log("Packaged Windows: uv installer ran but uv not found on PATH");
|
|
1623
|
-
} else {
|
|
1624
|
-
log(`Packaged Windows: automated uv installer exited ${rescue.code}`);
|
|
1312
|
+
if (!commandExists("uv")) {
|
|
1313
|
+
const candidates = [
|
|
1314
|
+
path.join(os.homedir(), ".local", "bin"),
|
|
1315
|
+
path.join(os.homedir(), ".cargo", "bin"),
|
|
1316
|
+
];
|
|
1317
|
+
for (const uvDir of candidates) {
|
|
1318
|
+
if (process.env.PATH && !process.env.PATH.includes(uvDir)) {
|
|
1319
|
+
process.env.PATH = `${uvDir}${path.delimiter}${process.env.PATH}`;
|
|
1320
|
+
log(`Added ${uvDir} to PATH for this process`);
|
|
1625
1321
|
}
|
|
1626
|
-
} catch (rescueErr) {
|
|
1627
|
-
if (rescueErr instanceof InstallCancelled) throw rescueErr;
|
|
1628
|
-
log(`Packaged Windows: rescue installer threw: ${rescueErr.message}`);
|
|
1629
1322
|
}
|
|
1630
1323
|
}
|
|
1631
1324
|
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1325
|
+
if (!commandExists("uv")) {
|
|
1326
|
+
throw new InstallError(
|
|
1327
|
+
"uv installed but not found on PATH. A shell restart may be required.",
|
|
1328
|
+
{
|
|
1329
|
+
stage: STAGES.ENSURE_UV,
|
|
1330
|
+
suggestion:
|
|
1331
|
+
"Restart your terminal or reboot, then re-launch GAIA. If the problem persists, install uv manually from https://astral.sh/uv",
|
|
1332
|
+
}
|
|
1638
1333
|
);
|
|
1639
|
-
report(STAGES.ENSURE_UV, 100, "uv ready (system, unverified)");
|
|
1640
|
-
return;
|
|
1641
1334
|
}
|
|
1642
1335
|
|
|
1643
|
-
|
|
1644
|
-
`GAIA could not find or install its Python helper (uv) required to provision the backend.`,
|
|
1645
|
-
{
|
|
1646
|
-
stage: STAGES.ENSURE_UV,
|
|
1647
|
-
suggestion:
|
|
1648
|
-
"GAIA attempted automatic recovery but could not install uv. Please either: (a) click 'Install uv' in the dialog to let GAIA try again, or (b) install uv from https://astral.sh/uv and re-launch GAIA.",
|
|
1649
|
-
}
|
|
1650
|
-
);
|
|
1336
|
+
report(STAGES.ENSURE_UV, 100, "uv installed");
|
|
1651
1337
|
}
|
|
1652
1338
|
|
|
1653
1339
|
// ── Backend install ──────────────────────────────────────────────────────────
|
|
@@ -2079,8 +1765,12 @@ function _prefetchMarker(pep440) {
|
|
|
2079
1765
|
return path.join(PREFETCH_DIR, `${pep440}.ready`);
|
|
2080
1766
|
}
|
|
2081
1767
|
|
|
2082
|
-
/**
|
|
1768
|
+
/**
|
|
1769
|
+
* True when `version`'s backend needs no download: an app that ships its
|
|
1770
|
+
* backend gets it with the update, otherwise a prefetch left it in uv's cache.
|
|
1771
|
+
*/
|
|
2083
1772
|
function isBackendPrefetched(version) {
|
|
1773
|
+
if (shippedGaiaBin()) return true;
|
|
2084
1774
|
return Boolean(version) && fs.existsSync(_prefetchMarker(toPep440(version)));
|
|
2085
1775
|
}
|
|
2086
1776
|
|
|
@@ -2091,6 +1781,10 @@ function isBackendPrefetched(version) {
|
|
|
2091
1781
|
* Throws with uv's own words when the download fails.
|
|
2092
1782
|
*/
|
|
2093
1783
|
async function prefetchBackend(appVersion, { isPackaged } = {}) {
|
|
1784
|
+
if (isPackaged) {
|
|
1785
|
+
log("This app ships its own backend, so the update carries it and there is nothing to prefetch");
|
|
1786
|
+
return;
|
|
1787
|
+
}
|
|
2094
1788
|
if (process.env.GAIA_LOCAL_WHEEL) {
|
|
2095
1789
|
log("GAIA_LOCAL_WHEEL is set: the next launch installs that wheel, so there is nothing to prefetch");
|
|
2096
1790
|
return;
|
|
@@ -2154,7 +1848,20 @@ function _lastLines({ stdout, stderr }) {
|
|
|
2154
1848
|
*/
|
|
2155
1849
|
function isBackendCurrent() {
|
|
2156
1850
|
// A local wheel is reinstalled on every launch, as ensureBackend says.
|
|
2157
|
-
if (process.env.GAIA_LOCAL_WHEEL) return false;
|
|
1851
|
+
if (process.env.GAIA_LOCAL_WHEEL && !shippedGaiaBin()) return false;
|
|
1852
|
+
if (shippedGaiaBin()) {
|
|
1853
|
+
// The core is always current; an app version is done once it refreshed the agent.
|
|
1854
|
+
if (!bundledGaiaBin()) return false;
|
|
1855
|
+
const prev = getState();
|
|
1856
|
+
if (!prev) {
|
|
1857
|
+
if (fs.existsSync(FLAGSHIP_SENTINEL)) return false;
|
|
1858
|
+
// Record this version now, or the agent first-run setup installs reads as an update next launch.
|
|
1859
|
+
const version = appVersion();
|
|
1860
|
+
setState(STATES.READY, { version, installedVersion: toPep440(version) });
|
|
1861
|
+
return true;
|
|
1862
|
+
}
|
|
1863
|
+
return prev.state === STATES.READY && toPep440(prev.version || "") === toPep440(appVersion());
|
|
1864
|
+
}
|
|
2158
1865
|
const bin = findGaiaBin();
|
|
2159
1866
|
if (!bin) return false;
|
|
2160
1867
|
const prev = getState();
|
|
@@ -2168,6 +1875,10 @@ function isBackendCurrent() {
|
|
|
2168
1875
|
* `gaia --version`, which starts Python and can take 20 s+ on a busy PC.
|
|
2169
1876
|
*/
|
|
2170
1877
|
function getInstalledVersion(gaiaBin) {
|
|
1878
|
+
// Built with the app, from the same commit.
|
|
1879
|
+
if (shippedGaiaBin() && gaiaBin === bundledGaiaBin()) {
|
|
1880
|
+
return toPep440(appVersion());
|
|
1881
|
+
}
|
|
2171
1882
|
if (gaiaBin === GAIA_BIN) {
|
|
2172
1883
|
// existsSync follows the venv's python symlink, so a removed base interpreter reads as missing.
|
|
2173
1884
|
if (!fs.existsSync(GAIA_PYTHON_BIN)) {
|
|
@@ -2243,6 +1954,19 @@ async function ensureBackend(opts = {}) {
|
|
|
2243
1954
|
openLog({ truncate: true });
|
|
2244
1955
|
|
|
2245
1956
|
try {
|
|
1957
|
+
const bundled = await ensureBundledCore();
|
|
1958
|
+
if (bundled) {
|
|
1959
|
+
log(`Using the GAIA backend this app ships: ${bundled}`);
|
|
1960
|
+
await refreshAgent(bundled, opts);
|
|
1961
|
+
return bundled;
|
|
1962
|
+
}
|
|
1963
|
+
if (opts.isPackaged) {
|
|
1964
|
+
throw new InstallError("This GAIA install is missing its backend.", {
|
|
1965
|
+
stage: STAGES.VERIFY,
|
|
1966
|
+
suggestion: `Reinstall GAIA from https://amd-gaia.ai/#install. Expected it at ${BUNDLED_GAIA_BIN}.`,
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
|
|
2246
1970
|
const preChecks = await runPreChecks({ onProgress: opts.onProgress });
|
|
2247
1971
|
|
|
2248
1972
|
// Handle a pre-existing partial install first (before disk/network fails
|
|
@@ -2265,31 +1989,6 @@ async function ensureBackend(opts = {}) {
|
|
|
2265
1989
|
}
|
|
2266
1990
|
}
|
|
2267
1991
|
|
|
2268
|
-
// Disk check failure: fatal, surface as InstallError.
|
|
2269
|
-
if (!preChecks.disk.ok) {
|
|
2270
|
-
const freeMb =
|
|
2271
|
-
preChecks.disk.freeBytes != null
|
|
2272
|
-
? Math.round(preChecks.disk.freeBytes / (1024 * 1024))
|
|
2273
|
-
: null;
|
|
2274
|
-
const requiredMb = Math.round(
|
|
2275
|
-
preChecks.disk.requiredBytes / (1024 * 1024)
|
|
2276
|
-
);
|
|
2277
|
-
const err = new InstallError(
|
|
2278
|
-
`Not enough free disk space. Required: ${requiredMb} MB${
|
|
2279
|
-
freeMb != null ? `, available: ${freeMb} MB` : ""
|
|
2280
|
-
}.`,
|
|
2281
|
-
{
|
|
2282
|
-
stage: STAGES.PRE_CHECKS,
|
|
2283
|
-
reason: FAILURE_REASONS.DISK,
|
|
2284
|
-
suggestion: `Free at least ${requiredMb} MB at ${path.dirname(
|
|
2285
|
-
GAIA_HOME
|
|
2286
|
-
)} and try again.`,
|
|
2287
|
-
}
|
|
2288
|
-
);
|
|
2289
|
-
setState(STATES.FAILED, { stage: STAGES.PRE_CHECKS, message: err.message });
|
|
2290
|
-
throw err;
|
|
2291
|
-
}
|
|
2292
|
-
|
|
2293
1992
|
// Network check is ADVISORY, never fatal. A failed HEAD probe is most often
|
|
2294
1993
|
// a corporate TLS-inspection proxy whose root CA isn't in Node's bundled
|
|
2295
1994
|
// trust store (#1572) — the machine is online and `uv`/`pip`, which honor
|
|
@@ -2325,8 +2024,9 @@ async function ensureBackend(opts = {}) {
|
|
|
2325
2024
|
prev.stage === LEGACY_SETUP_STAGE ||
|
|
2326
2025
|
prev.stage === STAGES.VERIFY ||
|
|
2327
2026
|
prev.stage === STAGES.AGENT_REFRESH;
|
|
2027
|
+
let installedVersion = null;
|
|
2328
2028
|
if (existingBin) {
|
|
2329
|
-
|
|
2029
|
+
installedVersion = getInstalledVersion(existingBin);
|
|
2330
2030
|
const versionMatches =
|
|
2331
2031
|
expectedVersion !== null && installedVersion === toPep440(expectedVersion);
|
|
2332
2032
|
if (versionMatches && packageFinished && prev && prev.stage === STAGES.AGENT_REFRESH) {
|
|
@@ -2352,6 +2052,12 @@ async function ensureBackend(opts = {}) {
|
|
|
2352
2052
|
log("GAIA backend not found — installing from scratch");
|
|
2353
2053
|
}
|
|
2354
2054
|
|
|
2055
|
+
// Checked only once there is something to install, so a full disk never stops a current install.
|
|
2056
|
+
if (!preChecks.disk.ok) {
|
|
2057
|
+
const keep = Boolean(existingBin) && packageFinished && prev?.state !== STATES.FAILED;
|
|
2058
|
+
throw lowDiskError(preChecks.disk, { keep, installedVersion });
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2355
2061
|
await installBackend(opts);
|
|
2356
2062
|
|
|
2357
2063
|
const verified = findGaiaBin();
|
|
@@ -2378,6 +2084,10 @@ async function ensureBackend(opts = {}) {
|
|
|
2378
2084
|
throw err;
|
|
2379
2085
|
}
|
|
2380
2086
|
if (err instanceof InstallError) {
|
|
2087
|
+
if (err.keepState) {
|
|
2088
|
+
log(`Install refused; the recorded state is unchanged: ${err.message}`);
|
|
2089
|
+
throw err;
|
|
2090
|
+
}
|
|
2381
2091
|
setState(STATES.FAILED, {
|
|
2382
2092
|
stage: err.stage || null,
|
|
2383
2093
|
message: err.message,
|