Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
fix(desktop): check local models on the selected install drive
shiroha777ef42c0df5229
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.mdindex 37da5403..c054af6d 100644--- a/apps/desktop/AGENTS.md+++ b/apps/desktop/AGENTS.md@@ -144,8 +144,11 @@ Gateway and runs Agents. The daemon exits with the app.[Packaging Details](../../docs/desktop-release.md#packaging-details) forwhere the minimum comes from.Quick Install installs the `recommendation` of the localmodels setup- report (`installer.js --inspect`, run once as the setup window opens):- `local-models` is the planned model served by Pi, shown with the model,+ report (`installer.js --inspect`, run for the selected install location+ as the setup window opens and again when that location changes, including+ after a failed install). Checks keep their tool cache in the default home,+ leave alternative locations untouched, and never migrate installations.+ In the report, `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 nolocal model. The page words each reason by its code and the counts itdiff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.tsindex 308d91b1..75f64332 100644--- a/apps/desktop/src/main/local-server.test.ts+++ b/apps/desktop/src/main/local-server.test.ts@@ -117,13 +117,14 @@ if (args.includes("--migrate")) {process.stdout.write(JSON.stringify({ skipped }) + "\n");process.exit(0);}-fs.mkdirSync(path.join(home, "installer"), { recursive: true });-fs.writeFileSync(path.join(home, "installer", "args.json"), JSON.stringify(args));if (args.includes("--inspect")) {+ const target = args.includes("--inspect-target") ? args[args.indexOf("--inspect-target") + 1] : home;+ fs.mkdirSync(path.join(home, "runtime", "localmodels", "state"), { recursive: true });+ fs.writeFileSync(path.join(home, "runtime", "inspect-args.json"), JSON.stringify(args));const hardware = { totalMemoryBytes: 64 * 1024 ** 3, diskFreeBytes: 200 * 1024 ** 3, gpus: [{ name: "RTX 4090" }] };- const eligible = !fs.existsSync(path.join(home, "small-computer"));+ const eligible = !fs.existsSync(path.join(target, "small-computer"));const estimate = eligible- ? { model: fs.existsSync(path.join(home, "unnamed-model")) ? "" : "qwen3-8b", downloadBytes: 6 * 1024 ** 3, diskBytes: 8 * 1024 ** 3, memoryBytes: 12 * 1024 ** 3 }+ ? { model: fs.existsSync(path.join(target, "unnamed-model")) ? "" : "qwen3-8b", downloadBytes: 6 * 1024 ** 3, diskBytes: 8 * 1024 ** 3, memoryBytes: 12 * 1024 ** 3 }: { model: "", downloadBytes: null, diskBytes: null, memoryBytes: null };if (fs.existsSync(path.join(home, "tool-download"))) {// The first check downloads the localmodels tool, counted before the report.@@ -131,14 +132,14 @@ if (args.includes("--inspect")) {while (!fs.existsSync(path.join(home, "tool-ready")))Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 20);}- if (fs.existsSync(path.join(home, "check-fails"))) {+ if (fs.existsSync(path.join(target, "check-fails"))) {// A failed check names its cause on stderr and prints null.process.stderr.write("The check failed: Unsupported or changed Codex provider configuration\n");process.stdout.write("null\n");process.exit(1);}process.stderr.write("Checked this computer in 1.5s.\n");- const lowMemory = eligible && fs.existsSync(path.join(home, "low-memory"));+ const lowMemory = eligible && fs.existsSync(path.join(target, "low-memory"));const reasons = eligible? lowMemory? [{ code: "free-memory-required", message: "Close other programs before installing.", freeBytes: 2899102924, requiredBytes: 13689304433 }]@@ -154,6 +155,8 @@ if (args.includes("--inspect")) {process.stdout.write(JSON.stringify({ hardware, localModels: { ...local, reasons, estimate }, recommendation }) + "\n");process.exit(0);}+fs.mkdirSync(path.join(home, "installer"), { recursive: true });+fs.writeFileSync(path.join(home, "installer", "args.json"), JSON.stringify(args));if (args.includes("--resume")) {const code = fs.existsSync(path.join(home, "resume-fails")) ? 1 : 0;const runtimeFile = path.join(home, "resume-runtime.json");@@ -501,6 +504,11 @@ const installerArgs = (home: string) =>readFileSync(path.join(home, "installer", "args.json"), "utf8"),) as string[];+const inspectArgs = (home: string) =>+ JSON.parse(+ readFileSync(path.join(home, "runtime", "inspect-args.json"), "utf8"),+ ) as string[];+// A developer's linger checkout (LINGER_CHECKOUT) in the home folder.const withCheckout = (home: string) => ({ checkout: path.join(home, "src") });const checkout = (home: string) => {@@ -1588,7 +1596,13 @@ describe("LocalServerModule", () => {recommendation: "local-models",}),);- expect(installerArgs(f.home)).toEqual(["--home", f.home, "--inspect"]);+ expect(inspectArgs(f.home)).toEqual([+ "--home",+ f.home,+ "--inspect",+ "--inspect-target",+ f.home,+ ]);// How long the check took, as the installer reported it.expect(info).toHaveBeenCalledWith("local_server.inspect_log", {line: "Checked this computer in 1.5s.",@@ -2281,6 +2295,158 @@ describe("LocalServerModule", () => {});describe("LocalServerModule install location", () => {+ it.each(["empty", "missing", "nonempty"])(+ "leaves the %s candidate untouched when selecting, resetting and selecting it again",+ async (kind) => {+ const f = fixture({ checkout: "/src" });+ const picked = path.join(f.root, "data");+ if (kind !== "missing") mkdirSync(picked);+ if (kind === "nonempty")+ writeFileSync(path.join(picked, "notes.txt"), "keep");+ const target = kind === "nonempty" ? path.join(picked, "Linger") : picked;+ await f.host.start();+ try {+ f.module.inspect();+ await vi.waitFor(() =>+ expect(f.module.status().localModels.state).toBe("checked"),+ );+ for (let attempt = 0; attempt < 2; attempt++) {+ await f.module.chooseLocation(picked);+ await vi.waitFor(() =>+ expect(f.module.status().localModels.state).toBe("checked"),+ );+ expect(f.module.status().location.path).toBe(target);+ expect(+ kind === "missing" ? existsSync(picked) : readdirSync(picked),+ ).toEqual(+ kind === "missing" ? false : kind === "empty" ? [] : ["notes.txt"],+ );+ if (kind === "nonempty") expect(existsSync(target)).toBe(false);+ await f.module.chooseLocation(null);+ await vi.waitFor(() =>+ expect(f.module.status().localModels.state).toBe("checked"),+ );+ }+ } finally {+ await f.host.stop("quit");+ }+ },+ );++ it("rechecks a new location and allows manual checks after installation fails", async () => {+ const f = fixture(+ withCheckout,+ {},+ checkout,+ installerApi([], { state: "failed", message: "Disk full" }),+ );+ const picked = path.join(f.root, "models");+ await f.host.start();+ try {+ f.module.inspect();+ await vi.waitFor(() =>+ expect(f.module.status().localModels).toMatchObject({+ state: "checked",+ eligible: true,+ }),+ );+ await expect(f.module.begin()).rejects.toThrow("Disk full");+ expect(f.module.status().phase).toBe("failed");+ mkdirSync(path.join(picked, "instances"), { recursive: true });+ writeFileSync(path.join(picked, "small-computer"), "");+ await f.module.chooseLocation(picked);+ await vi.waitFor(() =>+ expect(f.module.status().localModels).toMatchObject({+ state: "checked",+ eligible: false,+ }),+ );+ expect(inspectArgs(f.home)).toContain(picked);+ rmSync(path.join(picked, "small-computer"));+ f.module.recheck();+ await vi.waitFor(() =>+ expect(f.module.status().localModels).toMatchObject({+ state: "checked",+ eligible: true,+ }),+ );+ } finally {+ await f.host.stop("quit");+ }+ });++ 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(inspectArgs(f.home)).toEqual([+ "--home",+ f.home,+ "--inspect",+ "--inspect-target",+ picked,+ ]);+ expect(existsSync(picked)).toBe(false);+ 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(inspectArgs(f.home)).toContain("--inspect"),+ );+ await f.module.chooseLocation(picked);+ writeFileSync(path.join(f.home, "tool-ready"), "");+ await vi.waitFor(() =>+ expect(inspectArgs(f.home)).toEqual([+ "--home",+ f.home,+ "--inspect",+ "--inspect-target",+ picked,+ ]),+ );+ 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.tsindex f24b6986..5400d90d 100644--- a/apps/desktop/src/main/local-server.ts+++ b/apps/desktop/src/main/local-server.ts@@ -645,6 +645,7 @@ export class LocalServerModule implements Module {// goes back to the default.async chooseLocation(picked: string | null): Promise<void> {if (this.#running) return;+ const previous = this.#location;if (picked === null) {this.#location = undefined;this.#locationError = undefined;@@ -654,6 +655,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");}@@ -664,7 +667,8 @@ export class LocalServerModule implements Module {inspect(): void {if (this.#check.state !== "unchecked" ||- this.#phase !== "idle" ||+ this.#running ||+ (this.#phase !== "idle" && this.#phase !== "failed") ||!this.status().available)return;@@ -674,7 +678,8 @@ export class LocalServerModule implements Module {const started = Date.now();const signal = this.#abort.signal;if (!signal.aborted) void this.#ensureNode(signal).catch(() => undefined);- 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");@@ -692,19 +697,26 @@ export class LocalServerModule implements Module {: {}),...(reasonLog.length ? { reasons: reasonLog } : {}),});- this.#check = check;- this.#checkedAt = Date.now();+ 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" };- this.#checkedAt = undefined;+ 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.#checkedAt =+ check.state === "unavailable" ? undefined : Date.now();this.#ctx?.bus.emit("local-server.changed");});}@@ -712,7 +724,12 @@ export class LocalServerModule implements Module {// Checks again, for example after the person closed other programs to free// the memory the local model needs.recheck(): void {- if (this.#check.state === "checking" || this.#phase !== "idle") return;+ if (+ this.#check.state === "checking" ||+ this.#running ||+ (this.#phase !== "idle" && this.#phase !== "failed")+ )+ return;this.#check = { state: "unchecked" };this.inspect();}@@ -790,6 +807,7 @@ export class LocalServerModule implements Module {}async #inspect(+ targetHome: string,signal: AbortSignal,onDownload: (download: Transfer) => void,): Promise<{@@ -802,14 +820,21 @@ export class LocalServerModule implements Module {const output = await new Promise<string>((resolve, reject) => {const child = spawn(process.execPath,- [this.#installerScript(), "--home", this.#home, "--inspect"],+ [+ this.#installerScript(),+ "--home",+ this.#options.home,+ "--inspect",+ "--inspect-target",+ targetHome,+ ],{stdio: ["ignore", "pipe", "pipe"],windowsHide: true,env: {...process.env,ELECTRON_RUN_AS_NODE: "1",- LINGER_HOME: this.#home,+ LINGER_HOME: this.#options.home,},signal,},diff --git a/apps/linger-installer/AGENTS.md b/apps/linger-installer/AGENTS.mdindex b092ea92..5621c27a 100644--- a/apps/linger-installer/AGENTS.md+++ b/apps/linger-installer/AGENTS.md@@ -100,6 +100,10 @@ still be running. The full `--stop` command reports the same failure. Windowsuninstall aborts on that failure; replacement setup reports it and proceeds.A missing pinned kit has nothing to stop.+`--inspect` checks without migrating installations. Its optional+`--inspect-target` selects the home whose disk and runtimes are checked;+`--home` still owns the inspection tool cache and state.+Every other mode first converts an install from before the rename to Linger(`migrateLegacyInstallation`); `--migrate` does only that and exits, for thedesktop client. An instance it could not convert never stops thediff --git a/apps/linger-installer/src/main.test.ts b/apps/linger-installer/src/main.test.tsindex 16169360..b1fe3a21 100644--- a/apps/linger-installer/src/main.test.ts+++ b/apps/linger-installer/src/main.test.ts@@ -1,7 +1,8 @@import { mkdtempSync, writeFileSync } from "node:fs";import os from "node:os";import path from "node:path";-import { expect, it } from "vitest";+import { expect, it, vi } from "vitest";+import { fileURLToPath } from "node:url";import { loadPublishedSources } from "./main.js";const distribution = (value: object) => {@@ -158,3 +159,76 @@ it("migrates without a source checkout", async () => {migrate: true,});});++it("inspects a separate target without changing the tool home", async () => {+ const { parseInstallerArguments } = await import("./main.js");+ expect(+ parseInstallerArguments([+ "--home",+ "cache",+ "--inspect",+ "--inspect-target",+ "candidate",+ ]),+ ).toMatchObject({+ home: path.resolve("cache"),+ inspect: true,+ inspectTarget: path.resolve("candidate"),+ });+ expect(() =>+ parseInstallerArguments(["--inspect", "--inspect-target"]),+ ).toThrow("Installer option is missing a value.");+ expect(() =>+ parseInstallerArguments([+ "--source-repo",+ "checkout",+ "--inspect-target",+ "candidate",+ ]),+ ).toThrow("An inspection target requires --inspect.");+});++it("does not migrate legacy installations during inspection", async () => {+ const migrate = vi.fn().mockResolvedValue([]);+ const inspect = vi.fn().mockResolvedValue({ recommendation: "codex" });+ vi.doMock("@linger/local-installation/legacy-migration", () => ({+ migrateLegacyInstallation: migrate,+ }));+ vi.doMock("@linger/local-installation/setup-plan", () => ({+ inspectSetup: inspect,+ }));+ const argv = process.argv;+ const stdout = vi.spyOn(process.stdout, "write").mockReturnValue(true);+ const stderr = vi.spyOn(process.stderr, "write").mockReturnValue(true);+ try {+ process.argv = [+ process.execPath,+ fileURLToPath(new URL("./main.ts", import.meta.url)),+ "--home",+ "cache",+ "--inspect",+ "--inspect-target",+ "candidate",+ ];+ vi.resetModules();+ await import("./main.js");+ expect(migrate).not.toHaveBeenCalled();+ expect(inspect).toHaveBeenCalledWith(+ expect.objectContaining({+ home: path.resolve("cache"),+ targetHome: path.resolve("candidate"),+ }),+ );+ expect(stdout).toHaveBeenCalledWith(+ `${JSON.stringify({ recommendation: "codex" })}\n`,+ expect.any(Function),+ );+ } finally {+ process.argv = argv;+ stdout.mockRestore();+ stderr.mockRestore();+ vi.doUnmock("@linger/local-installation/legacy-migration");+ vi.doUnmock("@linger/local-installation/setup-plan");+ vi.resetModules();+ }+});diff --git a/apps/linger-installer/src/main.ts b/apps/linger-installer/src/main.tsindex 3648753b..4c2812be 100644--- a/apps/linger-installer/src/main.ts+++ b/apps/linger-installer/src/main.ts@@ -16,6 +16,7 @@ export function parseInstallerArguments(args: string[]) {noOpen?: boolean;resume?: boolean;inspect?: boolean;+ inspectTarget?: string;checkByok?: boolean;userKeys?: boolean;migrate?: boolean;@@ -63,13 +64,21 @@ export function parseInstallerArguments(args: string[]) {continue;}if (- !["--home", "--port", "--source-repo", "--instance"].includes(flag ?? "")+ ![+ "--home",+ "--port",+ "--source-repo",+ "--instance",+ "--inspect-target",+ ].includes(flag ?? ""))throw new Error("Invalid installer option.");const value = args[++i];if (!value || value.startsWith("--"))throw new Error("Installer option is missing a value.");if (flag === "--home") options.home = path.resolve(value);+ else if (flag === "--inspect-target")+ options.inspectTarget = path.resolve(value);else if (flag === "--source-repo") options.sourceRepo = path.resolve(value);else if (flag === "--instance") {if (!/^[a-z][a-z0-9-]{0,39}$/.test(value))@@ -92,6 +101,8 @@ export function parseInstallerArguments(args: string[]) {!options.stopLocalModels)throw new Error("The installer needs a source checkout (--source-repo).");+ if (options.inspectTarget && !options.inspect)+ throw new Error("An inspection target requires --inspect.");if (options.resume && !options.instanceName)throw new Error("Resume needs a source checkout and an instance.");if (options.userKeys && !options.instanceName)@@ -172,6 +183,7 @@ async function inspect(options: ReturnType<typeof parseInstallerArguments>) {// The desktop logs stderr, so a slow check says which part was slow.const report = await inspectSetup({home: options.home,+ targetHome: options.inspectTarget,signal: AbortSignal.timeout(10 * 60_000),onEvent: (event) => {if (event.kind === "log")@@ -385,13 +397,13 @@ if (}// Installs from before the rename move to the Linger home once, before// any mode opens it; --migrate does only that, for the desktop client.- // Stopping for an uninstall or a quit changes nothing.+ // Inspecting or stopping for an uninstall or a quit never migrates it.// Only --migrate reports the instances it skipped, as warnings and as one// JSON line on stdout: the desktop runs it first, and in the other modes a// warning on stderr would read as the reason a start failed. A skipped// instance is refused with its own error when a mode opens it.let skipped: LegacyInstanceSkipped[] = [];- if (options && !options.stop && !options.stopLocalModels)+ if (options && !options.inspect && !options.stop && !options.stopLocalModels)await import("@linger/local-installation/legacy-migration").then(async ({ migrateLegacyInstallation }) => {skipped = await migrateLegacyInstallation({ home: options!.home });diff --git a/packages/local-installation/AGENTS.md b/packages/local-installation/AGENTS.mdindex 4a8d7926..95bc683a 100644--- a/packages/local-installation/AGENTS.md+++ b/packages/local-installation/AGENTS.md@@ -76,9 +76,13 @@ Every update or recreate path stops node-services on its own, right beforeTeamHub restarts (natively: for a changed configuration) and while TeamHub isstill up, so its graceful shutdown requeues in-flight Agent Runs.+`inspectSetup` keeps tool downloads and state in `home`; `targetHome`, when+provided, selects the installation paths to inspect independently of that cache.+The home is `LINGER_HOME`, else `~/.simplexai` (`home.ts`). Installs frombefore the product was renamed Linger convert once in-`legacy-migration.ts`, which the installer runs before it opens the home and+`legacy-migration.ts`, which the installer runs before it opens the home (except+inspection and stop modes) andthe desktop runs through `installer.js --migrate`. Under each instance's lockit stops the instance's Computer and native services, renames `SIMPLEX_*`keys in the generated env files, and gives the instance itsdiff --git a/packages/local-installation/src/setup-plan.test.ts b/packages/local-installation/src/setup-plan.test.tsindex 54cd8443..2ad4fe7b 100644--- a/packages/local-installation/src/setup-plan.test.ts+++ b/packages/local-installation/src/setup-plan.test.ts@@ -352,3 +352,20 @@ it("inspects with GPU sharing unless sharing was explicitly declined", async ()await inspectSetup({ localmodels });expect(localmodels.mock.calls[2]?.[1]).toContain("--share-gpu");});++it("checks the installation target while keeping tool state in the existing home", async () => {+ const home = path.resolve("cached-home");+ const targetHome = path.resolve("candidate");+ const localmodels = runner();+ await inspectSetup({ home, targetHome, localmodels });+ expect(localmodels).toHaveBeenCalledWith(+ home,+ expect.arrayContaining([+ "--root",+ path.join(targetHome, "runtime", "harness"),+ "--model-base-dir",+ path.join(targetHome, "runtime", "localmodels", "models"),+ ]),+ expect.anything(),+ );+});diff --git a/packages/local-installation/src/setup-plan.ts b/packages/local-installation/src/setup-plan.tsindex 2da3918b..2cfe3678 100644--- a/packages/local-installation/src/setup-plan.ts+++ b/packages/local-installation/src/setup-plan.ts@@ -107,6 +107,7 @@ export interface SetupReport {export interface SetupOptions {shareGpu?: boolean;home?: string;+ targetHome?: string;userHome?: string;signal?: AbortSignal;localmodels?: typeof runLocalmodels;@@ -175,15 +176,16 @@ export async function inspectSetup(const home = path.resolve(options.home ?? path.join(options.userHome ?? homedir(), ".simplexai"),);+ const targetHome = path.resolve(options.targetHome ?? home);let failure: string | undefined;try {const args = ["setup","inspect","--root",- path.join(home, "runtime", "harness"),+ path.join(targetHome, "runtime", "harness"),"--model-base-dir",- path.join(home, "runtime", "localmodels", "models"),+ path.join(targetHome, "runtime", "localmodels", "models"),"--decision","none","--offline",