diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.md index c3378c6b..97f1e9eb 100644 --- a/apps/desktop/AGENTS.md +++ b/apps/desktop/AGENTS.md @@ -137,7 +137,8 @@ Gateway and runs Agents. The daemon exits with the app. [Packaging Details](../../docs/desktop-release.md#packaging-details) for where the minimum comes from. Quick Install installs the `recommendation` of the localmodels setup - report (`installer.js --inspect`, run once as the setup window opens): + report (`installer.js --inspect`, run for the selected install location + as the setup window opens and again when that location changes): `local-models` is the planned model served by Pi, shown with the model, GPU, memory and download (the card's memory is the whole stack's, so "with its services"); otherwise the named runtime, with why there is no diff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.ts index c2a6ecb8..04eeb285 100644 --- a/apps/desktop/src/main/local-server.test.ts +++ b/apps/desktop/src/main/local-server.test.ts @@ -2209,6 +2209,69 @@ describe("LocalServerModule", () => { }); describe("LocalServerModule install location", () => { + it("checks the folder selected before the first model check", async () => { + const f = fixture({ checkout: "/src" }); + const picked = path.join(f.root, "models"); + await f.host.start(); + try { + await f.module.chooseLocation(picked); + f.module.inspect(); + await vi.waitFor(() => + expect(f.module.status().localModels.state).toBe("checked"), + ); + expect(installerArgs(picked)).toEqual(["--home", picked, "--inspect"]); + expect(existsSync(path.join(f.home, "installer", "args.json"))).toBe( + false, + ); + } finally { + await f.host.stop("quit"); + } + }); + + it.each([false, true])( + "rechecks the selected folder when an earlier check finishes (failed: %s)", + async (failed) => { + const f = fixture({ checkout: "/src" }); + const picked = path.join(f.root, "models"); + writeFileSync(path.join(f.home, "tool-download"), ""); + if (failed) writeFileSync(path.join(f.home, "check-fails"), ""); + await f.host.start(); + try { + f.module.inspect(); + await vi.waitFor(() => + expect(installerArgs(f.home)).toContain("--inspect"), + ); + await f.module.chooseLocation(picked); + writeFileSync(path.join(f.home, "tool-ready"), ""); + await vi.waitFor(() => + expect(installerArgs(picked)).toEqual([ + "--home", + picked, + "--inspect", + ]), + ); + await vi.waitFor(() => + expect(f.module.status().localModels).toMatchObject({ + state: "checked", + eligible: true, + }), + ); + rmSync(path.join(f.home, "check-fails"), { force: true }); + writeFileSync(path.join(f.home, "small-computer"), ""); + await f.module.chooseLocation(null); + await vi.waitFor(() => + expect(f.module.status().localModels).toMatchObject({ + state: "checked", + eligible: false, + }), + ); + } finally { + writeFileSync(path.join(f.home, "tool-ready"), ""); + await f.host.stop("quit"); + } + }, + ); + it("installs into the folder picked on the setup page", async () => { const archive = sourceArchive(tempDirectory()); const file = path.join(tempDirectory(), "linger.tar.gz"); diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.ts index 72188a19..4befe81f 100644 --- a/apps/desktop/src/main/local-server.ts +++ b/apps/desktop/src/main/local-server.ts @@ -630,6 +630,7 @@ export class LocalServerModule implements Module { // goes back to the default. async chooseLocation(picked: string | null): Promise { if (this.#running) return; + const previous = this.#location; if (picked === null) { this.#location = undefined; this.#locationError = undefined; @@ -639,6 +640,8 @@ export class LocalServerModule implements Module { if (!this.#locationError) this.#location = home === this.#home ? undefined : home; } + if (previous !== this.#location && this.#check.state !== "unchecked") + this.recheck(); this.#ctx?.bus.emit("local-server.changed"); } @@ -657,7 +660,8 @@ export class LocalServerModule implements Module { this.#ctx?.bus.emit("local-server.changed"); const started = Date.now(); const signal = this.#abort.signal; - void this.#inspect(signal, (download) => { + const home = this.#location ?? this.#home; + void this.#inspect(home, signal, (download) => { if (this.#check.state !== "checking") return; this.#check = { state: "checking", download }; this.#ctx?.bus.emit("local-server.changed"); @@ -675,20 +679,26 @@ export class LocalServerModule implements Module { : {}), ...(reasonLog.length ? { reasons: reasonLog } : {}), }); - this.#check = check; + return check; }, (error: unknown) => { this.#ctx?.log.warn("local_server.inspect_failed", { ms: Date.now() - started, error: error instanceof Error ? error.message : String(error), }); - this.#check = { state: "unavailable" }; + return { state: "unavailable" } as const; }, ) - .then(() => { + .then((check) => { + if (signal.aborted) return; + if (home !== (this.#location ?? this.#home)) { + this.#check = { state: "unchecked" }; + this.inspect(); + return; + } + this.#check = check; this.#ctx?.bus.emit("local-server.changed"); - if (!signal.aborted) - void this.#ensureNode(signal).catch(() => undefined); + void this.#ensureNode(signal).catch(() => undefined); }); } @@ -773,6 +783,7 @@ export class LocalServerModule implements Module { } async #inspect( + home: string, signal: AbortSignal, onDownload: (download: Transfer) => void, ): Promise<{ @@ -785,14 +796,14 @@ export class LocalServerModule implements Module { const output = await new Promise((resolve, reject) => { const child = spawn( process.execPath, - [this.#installerScript(), "--home", this.#home, "--inspect"], + [this.#installerScript(), "--home", home, "--inspect"], { stdio: ["ignore", "pipe", "pipe"], windowsHide: true, env: { ...process.env, ELECTRON_RUN_AS_NODE: "1", - LINGER_HOME: this.#home, + LINGER_HOME: home, }, signal, },