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): word localmodels setup reasons by code in the setup window
Dongdong Chen71b42436d4a1
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.mdindex 2b133f8e..0fb07a66 100644--- a/apps/desktop/AGENTS.md+++ b/apps/desktop/AGENTS.md@@ -138,8 +138,14 @@ Gateway and runs Agents. The daemon exits with the app.Quick Install installs the `recommendation` of the localmodels setupreport (`installer.js --inspect`, run once as the setup window opens):`local-models` is the planned model served by Pi, shown with the model,- GPU, memory and download, plus the tool's caveat when it has one;- otherwise the named runtime, with the tool's reason for no local 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+ local model. The page words each reason by its code and the counts it+ carries (`gpuIndex`, `freeBytes`, `requiredBytes`); the tool's message+ goes only to the main process log (`local_server.inspected`), never to+ the page. Under Customize the Local model card stays visible once the+ check ends: disabled, "Not available on this computer", with that reason.+ Off macOS the page names the system tray, not the menu bar.Under Customize the local model runs only behind Pi: with another runtimeit is greyed (`aria-disabled`, still focusable), does not toggle, and says"Local models are only available with the Pi runtime."; choosing another@@ -149,10 +155,11 @@ Gateway and runs Agents. The daemon exits with the app.memory it needs now; a tool before that field marks it by `basis:"capacity"` or reason `free-memory-required`, either one), the installwould plan again against the memory free then and stop, so the local model- shows on hold and is not offered. With the tool's `stack.memory` the page- says "quit other programs first; it needs X of memory, Y is free" (and the- graphics memory on a discrete GPU), adding the tool's words for any other- reason code; without it, the tool's reason. Quick Install installs the+ shows on hold and is not offered. `gpu-memory-required` names the GPU and+ its free against needed memory and says to close programs that use the+ GPU; `free-memory-required` gives the RAM counts (from the reason, or the+ tool's `stack.memory` when the reason has none). The page still words+ `gpu-ownership-unknown`, which localmodels 0.1.0.dev39 reports. Quick Install installs theruntime the installer recommends instead, and Check again(`local.recheck`) runs the check again. A tool before `stack.state` stillrecommends `local-models` there, so the installer's setup adapterdiff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.tsindex 64059d1b..3c525fad 100644--- a/apps/desktop/src/main/local-server.test.ts+++ b/apps/desktop/src/main/local-server.test.ts@@ -119,8 +119,11 @@ if (args.includes("--inspect")) {}process.stderr.write("Checked this computer in 1.5s.\n");const lowMemory = eligible && fs.existsSync(path.join(home, "low-memory"));- const reasons = eligible ? (lowMemory ? ["free-memory-required"] : []) : ["facts-unavailable"];- const reasonMessages = eligible ? (lowMemory ? ["Close other programs before installing."] : []) : ["nvidia-smi was not found"];+ const reasons = eligible+ ? lowMemory+ ? [{ code: "free-memory-required", message: "Close other programs before installing.", freeBytes: 2899102924, requiredBytes: 13689304433 }]+ : []+ : [{ code: "facts-unavailable", message: "nvidia-smi was not found" }];// With the plan priced on capacity, the installer recommends a runtime.const recommendation = eligible && !lowMemory ? "local-models" : "codex";const local = {@@ -128,7 +131,7 @@ if (args.includes("--inspect")) {state: lowMemory ? "blocked-now" : eligible ? "ready" : "unavailable",...(lowMemory ? { basis: "capacity", memory: { ramAvailableBytes: 2899102924, ramRequiredBytes: 13689304433 } } : {}),};- process.stdout.write(JSON.stringify({ hardware, localModels: { ...local, reasons, reasonMessages, estimate }, recommendation }) + "\n");+ process.stdout.write(JSON.stringify({ hardware, localModels: { ...local, reasons, estimate }, recommendation }) + "\n");process.exit(0);}if (args.includes("--resume")) {@@ -1621,14 +1624,13 @@ describe("LocalServerModule", () => {expect(f.module.status().localModels).toMatchObject({state: "checked",eligible: false,- reasons: [- { code: "facts-unavailable", message: "nvidia-smi was not found" },- ],+ reasons: [{ code: "facts-unavailable" }],recommendation: "codex",}),);expect(f.module.status().localModels).not.toHaveProperty("model");- // The log says why, as the localmodels tool did.+ // The page gets the code only; the tool's words go to the log.+ expect(JSON.stringify(f.module.status())).not.toContain("nvidia-smi");expect(info).toHaveBeenCalledWith("local_server.inspected",expect.objectContaining({@@ -1660,7 +1662,8 @@ describe("LocalServerModule", () => {reasons: [{code: "free-memory-required",- message: "Close other programs before installing.",+ freeBytes: 2899102924,+ requiredBytes: 13689304433,},],recommendation: "codex",diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.tsindex c25f30e6..da6cf2b3 100644--- a/apps/desktop/src/main/local-server.ts+++ b/apps/desktop/src/main/local-server.ts@@ -75,7 +75,11 @@ import {savedProviderKeys,type ProviderKeyChanges,} from "./provider-keys.js";-import type { SetupByokCheck, SetupByokConfig } from "../shared/setup.js";+import type {+ SetupByokCheck,+ SetupByokConfig,+ SetupReason,+} from "../shared/setup.js";// The pinned linger source this build installs, written by the release build:// downloaded from `url` (or a mirror of it), or bundled in the app at `file`.@@ -129,19 +133,14 @@ export type LocalModelsCheck =readonly gpu?: string;// Present when eligible or when it needs free memory.readonly model?: LocalModel;- // The localmodels tool's code and words for why not, or, when- // eligible, for what could still stop the install.+ // The localmodels tool's code for why not, or, when eligible, for+ // what could still stop the install, with the counts it carries.readonly reasons?: readonly SetupReason[];// The localmodels tool's pick for this computer, which Quick Install// installs; the page adds no rule of its own.readonly recommendation?: SetupChoice;};-export interface SetupReason {- readonly code: string;- readonly message?: string;-}-// A download under way: its bytes so far and in all, and the rate when the// source reports one. partial: the counts cover only the file downloading// now, so nothing says what remains.@@ -664,7 +663,7 @@ export class LocalServerModule implements Module {this.#ctx?.bus.emit("local-server.changed");}).then(- (check) => {+ ({ check, reasonLog }) => {this.#ctx?.log.info("local_server.inspected", {ms: Date.now() - started,eligible: check.state === "checked" && check.eligible,@@ -674,13 +673,7 @@ export class LocalServerModule implements Module {...(check.state === "checked" && check.recommendation? { recommendation: check.recommendation }: {}),- ...(check.state === "checked" && check.reasons- ? {- reasons: check.reasons.map(({ code, message }) =>- message ? `${code}: ${message}` : code,- ),- }- : {}),+ ...(reasonLog.length ? { reasons: reasonLog } : {}),});this.#check = check;},@@ -782,7 +775,11 @@ export class LocalServerModule implements Module {async #inspect(signal: AbortSignal,onDownload: (download: Transfer) => void,- ): Promise<LocalModelsCheck> {+ ): Promise<{+ check: LocalModelsCheck;+ // The tool's codes with its words, for the log only.+ reasonLog: string[];+ }> {// The app's own Node runs the check, so it needs no download of its own;// installing still uses the pinned Node runtime.const output = await new Promise<string>((resolve, reject) => {@@ -840,7 +837,6 @@ export class LocalServerModule implements Module {state?: unknown;memory?: Record<string, unknown>;reasons?: unknown;- reasonMessages?: unknown;estimate?: {model?: unknown;downloadBytes?: unknown;@@ -889,12 +885,26 @@ export class LocalServerModule implements Module {: {}),}: undefined;- const strings = (value: unknown) =>- Array.isArray(value) ? value.map(String) : [];- const messages = strings(report.localModels.reasonMessages);- const reasons = strings(report.localModels.reasons).map(- (code, index): SetupReason =>- messages[index] ? { code, message: messages[index] } : { code },+ const listed = Array.isArray(report.localModels.reasons)+ ? (report.localModels.reasons as Record<string, unknown>[]).filter(+ (reason) => typeof reason?.code === "string",+ )+ : [];+ // The page words each reason by its code and counts, never the tool's.+ const reasons = listed.map((reason): SetupReason => {+ const counted = (key: "gpuIndex" | "freeBytes" | "requiredBytes") =>+ bytes(reason[key]) !== null ? { [key]: reason[key] as number } : {};+ return {+ code: reason.code as string,+ ...counted("gpuIndex"),+ ...counted("freeBytes"),+ ...counted("requiredBytes"),+ };+ });+ const reasonLog = listed.map(({ code, message }) =>+ typeof message === "string" && message+ ? `${code}: ${message}`+ : `${code}`,);const pick = report.recommendation;// The local model is recommended only with a model the page can show.@@ -904,7 +914,7 @@ export class LocalServerModule implements Module {(pick !== "local-models" || eligible)? (pick as SetupChoice): undefined;- return {+ const check: LocalModelsCheck = {state: "checked",eligible,memoryBytes: hardware.totalMemoryBytes,@@ -928,6 +938,7 @@ export class LocalServerModule implements Module {...(reasons.length ? { reasons } : {}),...(recommendation ? { recommendation } : {}),};+ return { check, reasonLog };}// Logs how long one part of setup took, so a slow setup says which part.diff --git a/apps/desktop/src/shared/setup.ts b/apps/desktop/src/shared/setup.tsindex ef61ef8d..3ec2ccd4 100644--- a/apps/desktop/src/shared/setup.ts+++ b/apps/desktop/src/shared/setup.ts@@ -123,6 +123,18 @@ export interface SetupTransfer {readonly partial?: boolean;}+// The localmodels tool's reason code with the counts it carries. Its words+// stay in the main process log; the page has its own copy per code.+export interface SetupReason {+ readonly code: string;+ // On gpu-memory-required: the card other programs hold memory on.+ readonly gpuIndex?: number;+ // The memory free now and what the install needs free: that card's VRAM,+ // or RAM on free-memory-required.+ readonly freeBytes?: number;+ readonly requiredBytes?: number;+}+export type SetupLocalModelsCheck =| { readonly state: "unchecked" | "unavailable" }// While the check first downloads the localmodels tool: its bytes.@@ -147,12 +159,10 @@ export type SetupLocalModelsCheck =readonly diskBytes: number | null;readonly memoryBytes: number | null;};- // The localmodels tool's code and words for why not, or, when- // eligible, for what could still stop the install.- readonly reasons?: readonly {- readonly code: string;- readonly message?: string;- }[];+ // The localmodels tool's code for why not, or, when eligible, for+ // what could still stop the install, with the counts it carries. The+ // page words each code itself.+ readonly reasons?: readonly SetupReason[];// The localmodels tool's pick, which Quick Install installs:// "local-models" is the model above served by Pi.readonly recommendation?: SetupChoice;diff --git a/apps/desktop/src/shell/setup-page.test.ts b/apps/desktop/src/shell/setup-page.test.tsindex a837c6bc..fa4b1e35 100644--- a/apps/desktop/src/shell/setup-page.test.ts+++ b/apps/desktop/src/shell/setup-page.test.ts@@ -9,6 +9,7 @@ import type {SetupCommand,SetupLocalAccount,SetupLocalModelsCheck,+ SetupReason,SetupState,} from "../shared/setup.js";@@ -203,12 +204,13 @@ const small: SetupLocalModelsCheck = {eligible: false,memoryBytes: 8 * GB,diskFreeBytes: 100 * GB,- // A code the page never parses: it shows only the message.- reasons: [- { code: "upstream_policy", message: "No model fits this computer." },- ],+ reasons: [{ code: "plan-unavailable" }],recommendation: "codex",};+// The tool's own words, which the page must never show.+const TOOL_WORDS = "GPU service owners unknown; explicit sharing";+const reason = (fields: SetupReason): SetupReason =>+ ({ ...fields, message: TOOL_WORDS }) as SetupReason;// The model fits the hardware, but other programs hold its memory now.const held: SetupLocalModelsCheck = {state: "checked",@@ -222,13 +224,7 @@ const held: SetupLocalModelsCheck = {diskBytes: 8 * GB,memoryBytes: 12 * GB,},- reasons: [- {- code: "free-memory-required",- message:- "Other programs are using memory it needs (now 2.7 GB of RAM is available).",- },- ],+ reasons: [reason({ code: "free-memory-required" })],recommendation: "codex",};const welcome = (localModels: SetupLocalModelsCheck): SetupState => {@@ -263,7 +259,7 @@ describe("setup page Quick Install recommendation", () => {"Recommended for this computer: Codex",);expect($("plan-why").textContent).toBe(- "No local model: No model fits this computer.",+ "No local model fits this computer.",);expect($("local-row").hidden).toBe(true);$("local-install").click();@@ -278,7 +274,7 @@ describe("setup page Quick Install recommendation", () => {"Recommended for this computer: Codex",);expect($("plan-why").textContent).toBe(- "Local model on hold: Other programs are using memory it needs (now 2.7 GB of RAM is available). Quick Install sets up Codex now, or choose Check again once memory is free.",+ "Local model on hold. Other programs are using the memory it needs. Close other programs. Quick Install sets up Codex now, or choose Check again once memory is free.",);expect($("local-recheck").hidden).toBe(false);$("local-customize").click();@@ -313,25 +309,40 @@ describe("setup page Quick Install recommendation", () => {});it("says how much memory a held local model needs and how much is free", async () => {- const counted = (- code: string,- message: string,- vram = false,- ): SetupLocalModelsCheck => ({+ const withCounts = (reasons: SetupReason[]): SetupLocalModelsCheck => ({...held,freeMemory: {ramAvailableBytes: 2899102924,ramRequiredBytes: 13689304433,- ...(vram ? { vramFreeBytes: 3 * GB, vramRequiredBytes: 9 * GB } : {}),+ vramFreeBytes: 3 * GB,+ vramRequiredBytes: 9 * GB,},- reasons: [{ code, message }],+ reasons,});+ const customizeLocal = () => {+ $("local-customize").click();+ document+ .querySelector<HTMLButtonElement>(+ '[data-plan="source"] [data-value="local"]',+ )!+ .click();+ };+ // The GPU and the RAM each name what is free and what the install needs.await openPage(welcome(- counted(- "free-memory-required",- "Other programs are using memory it needs.",- ),+ withCounts([+ reason({+ code: "gpu-memory-required",+ gpuIndex: 1,+ freeBytes: 3 * GB,+ requiredBytes: 9 * GB,+ }),+ reason({+ code: "free-memory-required",+ freeBytes: 2899102924,+ requiredBytes: 13689304433,+ }),+ ]),),"welcome",);@@ -339,31 +350,95 @@ describe("setup page Quick Install recommendation", () => {"Recommended for this computer: Codex",);expect($("plan-why").textContent).toBe(- "Local model on hold: quit other programs first; it needs 12.7 GB of memory, 2.7 GB is free. Quick Install sets up Codex now, or choose Check again once memory is free.",+ "Local model on hold. Other programs are using GPU 1's memory (3.0 GB free, 9.0 GB needed). Close programs that use the GPU, such as games, video or other AI apps. Other programs are using the memory it needs (2.7 GB free, 12.7 GB needed). Close other programs. Quick Install sets up Codex now, or choose Check again once memory is free.",);expect($("local-recheck").hidden).toBe(false);+ customizeLocal();+ expect($("local-sub").textContent).toBe(+ "On hold: GPU 1 has 3.0 GB free, needs 9.0 GB",+ );+ expect(document.body.textContent).not.toContain(TOOL_WORDS);+ // A tool that counts only the plan's memory: the RAM counts from it.+ await openPage(+ welcome(withCounts([reason({ code: "free-memory-required" })])),+ "welcome",+ );+ expect($("plan-why").textContent).toBe(+ "Local model on hold. Other programs are using the memory it needs (2.7 GB free, 12.7 GB needed). Close other programs. Quick Install sets up Codex now, or choose Check again once memory is free.",+ );+ customizeLocal();+ expect($("local-sub").textContent).toBe(+ "On hold: 2.7 GB of memory free, needs 12.7 GB",+ );+ });++ it("words every localmodels reason by its code, never the tool's message", async () => {+ const cases: [SetupLocalModelsCheck, string][] = [+ [+ { ...held, reasons: [reason({ code: "gpu-sharing-required" })] },+ "Local model on hold. Other work is running on the GPU. Close it.",+ ],+ [+ { ...held, reasons: [reason({ code: "plan-unavailable" })] },+ "Local model on hold. Another app is holding the memory it needs, such as another AI app. Quit it.",+ ],+ [+ { ...small, reasons: [reason({ code: "gpu-ownership-unknown" })] },+ "Linger couldn't tell which programs are using the GPU, so it can't share it. Close programs that use the GPU.",+ ],+ [+ { ...small, reasons: [reason({ code: "facts-unavailable" })] },+ "Linger couldn't read this computer's memory, disk or GPU.",+ ],+ [+ { ...small, reasons: [reason({ code: "unsupported-platform" })] },+ "Local models don't run on this system.",+ ],+ [+ { ...small, reasons: [reason({ code: "a-new-code" })] },+ "This computer can't run a local model now.",+ ],+ ];+ for (const [check, words] of cases) {+ await openPage(welcome(check), "welcome");+ expect($("plan-why").textContent).toContain(words);+ expect(document.body.textContent).not.toContain(TOOL_WORDS);+ }+ });++ it("shows the Local model card disabled with the reason when none can run", async () => {+ await openPage(+ welcome({+ ...small,+ reasons: [reason({ code: "gpu-ownership-unknown" })],+ }),+ "welcome",+ );$("local-customize").click();document.querySelector<HTMLButtonElement>('[data-plan="source"] [data-value="local"]',)!.click();- expect($("local-sub").textContent).toBe(- "On hold: 12.7 GB memory needed, 2.7 GB free",+ expect($("local-row").hidden).toBe(false);+ expect($("local-model").hidden).toBe(false);+ expect(($("local-model") as HTMLButtonElement).disabled).toBe(true);+ expect($("local-model").getAttribute("aria-checked")).toBe("false");+ expect($("local-model-name").textContent).toBe(+ "Not available on this computer",);- // Another code names what holds the memory, so its words stay.- await openPage(- welcome(- counted(- "plan-unavailable",- "Another inference app holds this Mac's memory; quit it and check again.",- true,- ),- ),- "welcome",+ expect($("local-model-needs").textContent).toBe(+ "Linger couldn't tell which programs are using the GPU, so it can't share it. Close programs that use the GPU.",);- expect($("plan-why").textContent).toBe(- "Local model on hold: quit other programs first; it needs 12.7 GB of memory, 2.7 GB is free; graphics memory needs 9.0 GB, 3.0 GB is free. Another inference app holds this Mac's memory; quit it and check again. Quick Install sets up Codex now, or choose Check again once memory is free.",+ expect(($("local-install") as HTMLButtonElement).disabled).toBe(true);+ expect(document.body.textContent).not.toContain(TOOL_WORDS);+ });++ it("says the stack's memory covers the model and its services", async () => {+ await openPage(welcome(capable), "welcome");+ $("local-customize").click();+ expect($("local-model-needs").textContent).toBe(+ "6 GB download · 8 GB disk · 12 GB memory with its services",);});@@ -605,6 +680,24 @@ describe("setup page Quick Install recommendation", () => {});});+describe("setup page permissions", () => {+ it("names the menu bar on macOS and the system tray elsewhere", async () => {+ const permissions = () =>+ document.querySelector('[data-step="permissions"]')!.textContent!;+ for (const [platform, place] of [+ ["darwin", "menu bar"],+ ["win32", "system tray"],+ ["linux", "system tray"],+ ] as const) {+ await openPage({ ...welcome(capable), platform }, "welcome");+ const words = permissions().replace(/\s+/g, " ");+ expect(words).toContain(`Change these later from the ${place} or`);+ expect(words).toContain(`Start in the ${place} when you log in.`);+ if (platform !== "darwin") expect(words).not.toContain("menu bar");+ }+ });+});+describe("setup page download progress", () => {const installing = (transfer?: SetupState["localServer"]["transfer"]) => {const base = state("installing");diff --git a/apps/desktop/src/shell/setup.html b/apps/desktop/src/shell/setup.htmlindex dd13c3f1..109de925 100644--- a/apps/desktop/src/shell/setup.html+++ b/apps/desktop/src/shell/setup.html@@ -2057,7 +2057,8 @@<section data-step="permissions" aria-labelledby="permissions-title"><h1 id="permissions-title">A few permissions</h1><p class="lead compact">- Change these later from the menu bar or in your system settings.+ Change these later from the <span data-tray>menu bar</span> or in your+ system settings.</p><div class="rows"><div class="row">@@ -2162,7 +2163,10 @@></span><div class="text"><strong>Open at login</strong- ><span class="sub">Start in the menu bar when you log in.</span>+ ><span class="sub"+ >Start in the <span data-tray>menu bar</span> when you log+ in.</span+ ></div><buttonclass="switch"@@ -2567,6 +2571,96 @@requestAnimationFrame(placeKnobs);};+ // The page's own words for each localmodels reason code, with the+ // counts it carries; the tool's message is never shown. held: the+ // model fits the hardware, but other programs hold memory it needs now.+ const counts = (free, needed) =>+ free != null && needed != null+ ? " (" + size(free) + " free, " + size(needed) + " needed)"+ : "";+ const reasonText = (reason, held, freeMemory) => {+ switch (reason.code) {+ case "gpu-memory-required":+ return (+ "Other programs are using " ++ (reason.gpuIndex != null+ ? "GPU " + reason.gpuIndex + "'s"+ : "the GPU's") ++ " memory" ++ counts(reason.freeBytes, reason.requiredBytes) ++ ". Close programs that use the GPU, such as games, video or other AI apps."+ );+ case "free-memory-required":+ return (+ "Other programs are using the memory it needs" ++ (counts(reason.freeBytes, reason.requiredBytes) ||+ counts(+ freeMemory?.ramAvailableBytes,+ freeMemory?.ramRequiredBytes,+ )) ++ ". Close other programs."+ );+ case "gpu-sharing-required":+ return "Other work is running on the GPU. Close it.";+ // localmodels 0.1.0.dev39 reports it; later versions plan by the+ // GPU memory free instead.+ case "gpu-ownership-unknown":+ return "Linger couldn't tell which programs are using the GPU, so it can't share it. Close programs that use the GPU.";+ case "facts-unavailable":+ return "Linger couldn't read this computer's memory, disk or GPU.";+ case "unsupported-platform":+ return "Local models don't run on this system.";+ // Blocked now, it names another inference app holding a Mac's+ // memory.+ case "plan-unavailable":+ return held+ ? "Another app is holding the memory it needs, such as another AI app. Quit it."+ : "No local model fits this computer.";+ default:+ return held+ ? "Other programs are using the memory it needs. Close other programs."+ : "This computer can't run a local model now.";+ }+ };+ const reasonsText = (models, held) =>+ [+ ...new Set(+ (models.reasons?.length ? models.reasons : [{ code: "" }]).map(+ (reason) => reasonText(reason, held, models.freeMemory),+ ),+ ),+ ].join(" ");+ // The held card's short line: what is free against what is needed.+ const heldLine = (models) => {+ const gpu = models.reasons?.find(+ (reason) =>+ reason.code === "gpu-memory-required" &&+ reason.freeBytes != null &&+ reason.requiredBytes != null,+ );+ if (gpu)+ return (+ "On hold: " ++ (gpu.gpuIndex != null ? "GPU " + gpu.gpuIndex : "The GPU") ++ " has " ++ size(gpu.freeBytes) ++ " free, needs " ++ size(gpu.requiredBytes)+ );+ const ram = models.reasons?.find(+ (reason) =>+ reason.code === "free-memory-required" &&+ reason.freeBytes != null &&+ reason.requiredBytes != null,+ );+ const free = ram?.freeBytes ?? models.freeMemory?.ramAvailableBytes;+ const needed =+ ram?.requiredBytes ?? models.freeMemory?.ramRequiredBytes;+ return free != null && needed != null+ ? "On hold: " + size(free) + " of memory free, needs " + size(needed)+ : "On hold: close other programs, then Check again.";+ };+const renderLocal = (busy) => {const local = state.localServer;const recommended = defaults();@@ -2586,22 +2680,6 @@// needs now: shown, not offered, until a new check finds that memory.const held =models.state === "checked" && models.blockedNow && models.model;- // The tool's count of memory free now against what the plan needs.- const free = held && models.freeMemory;- const freeText =- free &&- "needs " +- size(free.ramRequiredBytes) +- " of memory, " +- size(free.ramAvailableBytes) +- " is free" +- (free.vramRequiredBytes != null- ? "; graphics memory needs " +- size(free.vramRequiredBytes) +- ", " +- size(free.vramFreeBytes) +- " is free"- : "");plan.localModel = plan.source === "local" && !!model;const custom = !isDefaultPlan(local);// Quick Install waits for the check, so it installs what it shows.@@ -2658,7 +2736,12 @@: following && known? "Recommended for this computer: " + named(plan): named(plan) || "Best AI runtime";- // Why, in the localmodels tool's facts and words.+ // Why: the localmodels tool's facts, and its reason codes in the+ // page's words.+ const unavailableText =+ models.state === "checked"+ ? reasonsText(models, false)+ : "Couldn't check this computer for a local model.";$("plan-why").textContent = fetching? transferParts(fetching).join(" · "): !following || checking@@ -2672,34 +2755,17 @@gigabytes(model.downloadBytes) + " download",].filter(Boolean)- .join(" · ") +- (models.reasons?.[0]?.message- ? ". " + models.reasons[0].message- : "")+ .join(" · "): held- ? "Local model on hold: " +- (free- ? "quit other programs first; it " +- freeText +- "." +- // Other codes name what to quit, such as another- // inference app; the counts alone do not.- (models.reasons?.[0]?.code !== "free-memory-required" &&- models.reasons?.[0]?.message- ? " " + models.reasons[0].message- : "")- : models.reasons?.[0]?.message ||- "other programs are using the memory it needs.") ++ ? "Local model on hold. " ++ reasonsText(models, true) +" Quick Install sets up " +named(plan) +" now, or choose Check again once memory is free."- : models.state === "checked" && !models.eligible- ? "No local model: " +- (models.reasons?.[0]?.message ||- "this computer can't run one.")- : models.state === "unavailable"- ? "Couldn't check this computer for a local model."- : "";+ : (models.state === "checked" && !models.eligible) ||+ models.state === "unavailable"+ ? unavailableText+ : "";$("plan-why").hidden =!local.available || customizing || !$("plan-why").textContent;$("plan-line").hidden = !local.available;@@ -2737,18 +2803,16 @@$("local-row").hidden = plan.source !== "local";$("subscription-row").hidden = plan.source !== "subscription";$("byok-row").hidden = plan.source !== "byok";- $("local-model").hidden = !shown;+ // Once checked, the card always shows: the model, or why there is+ // none, disabled.+ const settled =+ models.state === "checked" || models.state === "unavailable";+ $("local-model").hidden = !shown && !settled;$("local-recheck").hidden = !held || !local.available;$("local-recheck").disabled = busy;if (shown) {$("local-sub").textContent = held- ? free- ? "On hold: " +- size(free.ramRequiredBytes) +- " memory needed, " +- size(free.ramAvailableBytes) +- " free"- : "On hold: close other programs, then Check again."+ ? heldLine(models): [recommended.localModel? "Recommended for this computer · Runs on Pi via Bifrost"@@ -2762,18 +2826,24 @@shown.downloadBytes != null &&gigabytes(shown.downloadBytes) + " download",shown.diskBytes != null && gigabytes(shown.diskBytes) + " disk",+ // The whole stack's memory, so more than the model's own on+ // the Local models page.shown.memoryBytes != null &&- gigabytes(shown.memoryBytes) + " memory",+ gigabytes(shown.memoryBytes) + " memory with its services",].filter(Boolean).join(" · ");$("local-model").setAttribute("aria-checked", String(!!model));$("local-model").disabled = busy || !model;+ } else if (settled) {+ $("local-sub").textContent =+ "Runs your tasks on this computer via Pi";+ $("local-model-name").textContent = "Not available on this computer";+ $("local-model-needs").textContent = unavailableText;+ $("local-model").setAttribute("aria-checked", "false");+ $("local-model").disabled = true;} else {- $("local-sub").textContent = checking- ? "Checking this computer…"- : models.reasons?.[0]?.message ||- "No local model fits this computer.";+ $("local-sub").textContent = "Checking this computer…";}const subKnown =recommended.source === "subscription" &&@@ -2981,6 +3051,10 @@const render = () => {if (!state) return;document.body.dataset.platform = state.platform;+ // Where the tray icon lives on this platform.+ for (const el of document.querySelectorAll("[data-tray]"))+ el.textContent =+ state.platform === "darwin" ? "menu bar" : "system tray";const at = ORDER.indexOf(step);$("step-label").textContent =at >= 0 ? "Step " + (at + 1) + " of " + ORDER.length : "";diff --git a/apps/linger-installer/src/server/api.test.ts b/apps/linger-installer/src/server/api.test.tsindex 09daad58..92d6b060 100644--- a/apps/linger-installer/src/server/api.test.ts+++ b/apps/linger-installer/src/server/api.test.ts@@ -14,7 +14,7 @@ vi.mock("@linger/local-installation/setup-plan", () => ({choices: ["local-models", "codex", "claude", "pi"],localModels: {eligible: false,- reasons: ["upstream-unavailable"],+ reasons: [{ code: "upstream-unavailable", message: "" }],selectedGpuIndex: null,estimate: {model: "",diff --git a/apps/linger-installer/src/web/App.test.tsx b/apps/linger-installer/src/web/App.test.tsxindex f0179f78..ab607fc6 100644--- a/apps/linger-installer/src/web/App.test.tsx+++ b/apps/linger-installer/src/web/App.test.tsx@@ -71,7 +71,10 @@ beforeEach(() => {recommendation: "codex",localModels: {eligible: false,- reasons: ["linux_required", "ram_below_minimum"],+ reasons: [+ { code: "linux_required", message: "" },+ { code: "ram_below_minimum", message: "" },+ ],selectedGpuIndex: null,estimate: {model: "qwen3.8-27b",diff --git a/contracts/generated/typescript/src/generated/linger-installer/types.ts b/contracts/generated/typescript/src/generated/linger-installer/types.tsindex 8691a93a..ca6c9860 100644--- a/contracts/generated/typescript/src/generated/linger-installer/types.ts+++ b/contracts/generated/typescript/src/generated/linger-installer/types.ts@@ -671,9 +671,17 @@ export interface components {vramFreeBytes?: number;vramRequiredBytes?: number;};- reasons: string[];- /** @description Human-readable upstream explanations in the same order as reasons; model eligibility remains upstream-owned. */- reasonMessages?: string[];+ /** @description Upstream stack.reasons. Clients choose their copy by code and its counts; message is upstream diagnostic text for logs, never shown or matched on. */+ reasons: {+ code: string;+ message: string;+ /** @description On gpu-memory-required, the card other programs hold memory on. */+ gpuIndex?: number;+ /** @description On gpu-memory-required (that card's VRAM) and free-memory-required (RAM), the memory free now. */+ freeBytes?: number;+ /** @description The memory the install needs free, for the same resource as freeBytes. */+ requiredBytes?: number;+ }[];/*** @description Present when the upstream plan fits this computer's hardware only once other programs release the memory they hold now (reason free-memory-required); installing plans again against the memory free then.* @enum {string}diff --git a/contracts/openapi/linger-installer/openapi.yaml b/contracts/openapi/linger-installer/openapi.yamlindex f8bd9137..3da67e92 100644--- a/contracts/openapi/linger-installer/openapi.yaml+++ b/contracts/openapi/linger-installer/openapi.yaml@@ -1241,13 +1241,27 @@ components:type: numberreasons:type: array+ description: Upstream stack.reasons. Clients choose their copy by code and its counts; message is upstream diagnostic text for logs, never shown or matched on.items:- type: string- reasonMessages:- type: array- description: Human-readable upstream explanations in the same order as reasons; model eligibility remains upstream-owned.- items:- type: string+ type: object+ additionalProperties: false+ required:+ - code+ - message+ properties:+ code:+ type: string+ message:+ type: string+ gpuIndex:+ type: number+ description: On gpu-memory-required, the card other programs hold memory on.+ freeBytes:+ type: number+ description: On gpu-memory-required (that card's VRAM) and free-memory-required (RAM), the memory free now.+ requiredBytes:+ type: number+ description: The memory the install needs free, for the same resource as freeBytes.basis:type: stringenum:diff --git a/packages/local-installation/src/setup-plan.test.ts b/packages/local-installation/src/setup-plan.test.tsindex 0969b239..77ba816a 100644--- a/packages/local-installation/src/setup-plan.test.ts+++ b/packages/local-installation/src/setup-plan.test.ts@@ -1,5 +1,5 @@import { expect, it, vi } from "vitest";-import { inspectSetup, assertLocalModelsEligible } from "./setup-plan.js";+import { inspectSetup } from "./setup-plan.js";const upstream = (available = true) => ({schema: "localmodels.setup-report/v1",@@ -97,15 +97,11 @@ it("preserves upstream rejection and never substitutes downstream eligibility",const localmodels = runner(upstream(false));const report = await inspectSetup({ localmodels });expect(report.localModels.state).toBe("unavailable");- expect(report.localModels.reasons).toEqual(["upstream_policy"]);- expect(report.localModels.reasonMessages).toEqual([- "Upstream rejected this host",+ expect(report.localModels.reasons).toEqual([+ { code: "upstream_policy", message: "Upstream rejected this host" },]);expect(report.recommendation).toBe("pi");expect(report.localModels.estimate.downloadBytes).toBeNull();- await expect(assertLocalModelsEligible({ localmodels })).rejects.toThrow(- "upstream_policy: Upstream rejected this host",- );});it("recommends the next runtime while the local plan waits for free memory (tool without stack.state)", async () => {const freeMemory = (installed: boolean) => {@@ -136,14 +132,16 @@ it("recommends the next runtime while the local plan waits for free memory (tooleligible: false,state: "blocked-now",basis: "capacity",- reasons: ["free-memory-required"],+ reasons: [+ {+ code: "free-memory-required",+ message: "Close other programs before installing.",+ },+ ],estimate: { model: "upstream-model" },});expect(report.localModels).not.toHaveProperty("memory");expect(report.recommendation).toBe("pi");- await expect(- assertLocalModelsEligible({ localmodels: runner(freeMemory(true)) }),- ).rejects.toThrow("free-memory-required");const bare = await inspectSetup({ localmodels: runner(freeMemory(false)) });expect(bare.recommendation).toBe("codex");// The reason code alone holds the plan too.@@ -236,6 +234,54 @@ it("reads the tool's blocked-now state, memory and recommendation", async () =>hardwareCapable: false,});});+it("passes on the memory counts each reason carries", async () => {+ const value = upstream();+ const report = await inspectSetup({+ localmodels: runner({+ ...value,+ stack: {+ ...value.stack,+ available: false,+ state: "blocked-now",+ basis: "capacity",+ reasons: [+ {+ code: "gpu-memory-required",+ message: "Other programs are using GPU 1's memory.",+ gpuIndex: 1,+ freeBytes: 3,+ requiredBytes: 8,+ },+ {+ code: "free-memory-required",+ message: "Other programs are using memory they need.",+ freeBytes: 5,+ requiredBytes: 13,+ },+ // A count outside the contract is left out, not shown.+ { code: "free-memory-required", message: "", freeBytes: -1 },+ ],+ },+ recommendation: "codex",+ }),+ });+ expect(report.localModels.reasons).toEqual([+ {+ code: "gpu-memory-required",+ message: "Other programs are using GPU 1's memory.",+ gpuIndex: 1,+ freeBytes: 3,+ requiredBytes: 8,+ },+ {+ code: "free-memory-required",+ message: "Other programs are using memory they need.",+ freeBytes: 5,+ requiredBytes: 13,+ },+ { code: "free-memory-required", message: "" },+ ]);+});it("fails explicitly and redacts tool output when upstream is unavailable or malformed", async () => {for (const response of [{ code: 1, stdout: "private token", stderr: "secret" },diff --git a/packages/local-installation/src/setup-plan.ts b/packages/local-installation/src/setup-plan.tsindex 0849d576..2da3918b 100644--- a/packages/local-installation/src/setup-plan.ts+++ b/packages/local-installation/src/setup-plan.ts@@ -26,7 +26,20 @@ export function setupSelection(? { runtime: "pi", modelSource: "local" }: { runtime: choice, modelSource: "runtime" };}-export type SetupReason = string;+/**+ * One upstream stack reason. Clients pick their copy by `code` and its counts;+ * `message` is upstream diagnostic text for logs, never shown or matched on.+ */+export interface SetupReason {+ code: string;+ message: string;+ /** On gpu-memory-required: the card other programs hold memory on. */+ gpuIndex?: number;+ /** Memory free now: that card's VRAM, or RAM on free-memory-required. */+ freeBytes?: number;+ /** The memory the install needs free, for the same resource. */+ requiredBytes?: number;+}/** Whether local models can install now, as the localmodels tool says. */export type LocalModelsState = "ready" | "blocked-now" | "unavailable";/** Memory free now against what the plan needs, from the localmodels tool. */@@ -73,7 +86,6 @@ export interface SetupReport {/** Upstream `stack.memory`, when the tool reports it. */memory?: SetupMemory;reasons: SetupReason[];- reasonMessages?: string[];/*** "capacity": the plan fits this computer's hardware only once other* programs release memory (upstream basis "capacity" or reason@@ -122,7 +134,7 @@ interface UpstreamReport {hardwareCapable?: boolean | null;basis?: "capacity" | null;memory?: SetupMemory | null;- reasons: { code: string; message: string }[];+ reasons: SetupReason[];plan: {llm: { model: { id: string }; placement: { gpus: { index: number }[] } };budget: {@@ -239,9 +251,9 @@ export async function inspectSetup(: value.stack.available? "ready": "unavailable";+ const ok = (bytes: unknown): bytes is number =>+ typeof bytes === "number" && Number.isFinite(bytes) && bytes >= 0;const counts = (memory: SetupMemory) => {- const ok = (bytes: unknown) =>- typeof bytes === "number" && Number.isFinite(bytes) && bytes >= 0;if (!ok(memory.ramAvailableBytes) || !ok(memory.ramRequiredBytes))return undefined;return {@@ -293,8 +305,15 @@ export async function inspectSetup(? { hardwareCapable: value.stack.hardwareCapable }: {}),...(memory ? { memory } : {}),- reasons: value.stack.reasons.map((reason) => reason.code),- reasonMessages: value.stack.reasons.map((reason) => reason.message),+ reasons: value.stack.reasons.map(+ ({ code, message, gpuIndex, freeBytes, requiredBytes }) => ({+ code,+ message,+ ...(ok(gpuIndex) ? { gpuIndex } : {}),+ ...(ok(freeBytes) ? { freeBytes } : {}),+ ...(ok(requiredBytes) ? { requiredBytes } : {}),+ }),+ ),...(capacity ? { basis: "capacity" as const } : {}),selectedGpuIndex: plan?.llm.placement.gpus[0]?.index ?? null,estimate: {@@ -338,13 +357,3 @@ export async function inspectSetup();}}-export async function assertLocalModelsEligible(- options: SetupOptions = {},-): Promise<SetupReport> {- const report = await inspectSetup(options);- if (!report.localModels.eligible)- throw new Error(- `Local models are unavailable: ${report.localModels.reasons.map((code, index) => (report.localModels.reasonMessages?.[index] ? `${code}: ${report.localModels.reasonMessages[index]}` : code)).join(", ")}`,- );- return report;-}