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): hold the local model while it is blocked now
claude-opus-5-5-medium2ddbd3d211d4
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.mdindex d1da90cc..b8928546 100644--- a/apps/desktop/AGENTS.md+++ b/apps/desktop/AGENTS.md@@ -123,9 +123,23 @@ 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 (low free- memory, which the install's own plan can still fail on); otherwise the- named runtime, with the tool's reason for no local model. The page adds no host rule of its own; while+ 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.+ When the tool reports local models blocked now (`stack.state:+"blocked-now"`: the model fits the hardware, but other programs hold the+ memory it needs now; a tool before that field marks it by `basis:+"capacity"` or reason `free-memory-required`, either one), the install+ would 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+ runtime the installer recommends instead, and Check again+ (`local.recheck`) runs the check again. A tool before `stack.state` still+ recommends `local-models` there, so the installer's setup adapter+ (`packages/local-installation/src/setup-plan.ts`) replaces that pick with+ an installed runtime (signed-in first), else Codex; that override and the+ fallbacks go once the pinned tool reports `state`. The page adds no host rule of its own; whilethe check runs the button waits with a spinner and says what it waits for(the first run downloads the localmodels tool, counted by `download`event lines before the report), and Customize marks thediff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.tsindex 14add591..f2bc6a04 100644--- a/apps/desktop/src/main/local-server.test.ts+++ b/apps/desktop/src/main/local-server.test.ts@@ -95,8 +95,14 @@ if (args.includes("--inspect")) {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 recommendation = eligible ? "local-models" : "codex";- process.stdout.write(JSON.stringify({ hardware, localModels: { eligible, reasons, reasonMessages, estimate }, recommendation }) + "\n");+ // With the plan priced on capacity, the installer recommends a runtime.+ const recommendation = eligible && !lowMemory ? "local-models" : "codex";+ const local = {+ eligible: eligible && !lowMemory,+ 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.exit(0);}if (args.includes("--resume")) {@@ -1388,7 +1394,8 @@ describe("LocalServerModule", () => {info.mockRestore();});- it("keeps the tool's free-memory warning for an eligible computer", async () => {+ it("holds a local model that needs free memory until a check finds it", async () => {+ const info = vi.spyOn(silentLog, "info");const f = fixture({ checkout: "/src" }, {}, (home) => {mkdirSync(home, { recursive: true });writeFileSync(path.join(home, "low-memory"), "");@@ -1398,16 +1405,40 @@ describe("LocalServerModule", () => {await vi.waitFor(() =>expect(f.module.status().localModels).toMatchObject({state: "checked",- eligible: true,+ eligible: false,+ blockedNow: true,+ freeMemory: {+ ramAvailableBytes: 2899102924,+ ramRequiredBytes: 13689304433,+ },+ model: { name: "qwen3-8b" },reasons: [{code: "free-memory-required",message: "Close other programs before installing.",},],+ recommendation: "codex",+ }),+ );+ expect(info).toHaveBeenCalledWith(+ "local_server.inspected",+ expect.objectContaining({ eligible: false, blocked_now: true }),+ );+ // The person closed other programs and checks again.+ rmSync(path.join(f.home, "low-memory"));+ f.module.recheck();+ expect(f.module.status().localModels).toEqual({ state: "checking" });+ await vi.waitFor(() =>+ expect(f.module.status().localModels).toMatchObject({+ state: "checked",+ eligible: true,recommendation: "local-models",}),);+ expect(f.module.status().localModels).not.toHaveProperty("blockedNow");+ expect(f.module.status().localModels).not.toHaveProperty("freeMemory");+ info.mockRestore();});it("approves the deployment of the chosen local model", async () => {diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.tsindex 67d3fd49..b893b58a 100644--- a/apps/desktop/src/main/local-server.ts+++ b/apps/desktop/src/main/local-server.ts@@ -36,6 +36,7 @@ import { legacyMigrationPending } from "@linger/local-installation/home";import type { LegacyInstanceSkipped } from "@linger/local-installation/legacy-migration";import {type SetupChoice,+ type SetupMemory,setupChoices,} from "@linger/local-installation/setup-plan";import {@@ -106,15 +107,23 @@ export type LocalModelsCheck =| { readonly state: "checking"; readonly download?: Transfer }| {readonly state: "checked";- // Whether this computer can serve a local model at all.+ // Whether this computer can serve a local model now.readonly eligible: boolean;+ // The model fits this computer's hardware, but other programs hold+ // memory it needs now: the tool's state "blocked-now". The install+ // would plan again against the memory free then, so it is not offered+ // until a new check finds that memory.+ readonly blockedNow?: true;+ // While blocked now: the memory free now and what the plan needs, as+ // the tool counts them (VRAM only for a discrete GPU).+ readonly freeMemory?: SetupMemory;readonly memoryBytes: number;readonly diskFreeBytes: number | null;readonly gpu?: string;- // Present only when eligible.+ // 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 (free memory).+ // eligible, for what could still stop the install.readonly reasons?: readonly SetupReason[];// The localmodels tool's pick for this computer, which Quick Install// installs; the page adds no rule of its own.@@ -543,9 +552,10 @@ export class LocalServerModule implements Module {this.#ctx?.bus.emit("local-server.changed");}- // Asks the installer, once per run, whether this computer can serve a- // local model; the setup window asks as it opens, before anything is- // installed. Then fetches the Node runtime an installation starts with.+ // Asks the installer whether this computer can serve a local model; the+ // setup window asks as it opens, before anything is installed, and again+ // through recheck(). Then fetches the Node runtime an installation starts+ // with.inspect(): void {if (this.#check.state !== "unchecked" ||@@ -567,6 +577,9 @@ export class LocalServerModule implements Module {this.#ctx?.log.info("local_server.inspected", {ms: Date.now() - started,eligible: check.state === "checked" && check.eligible,+ ...(check.state === "checked" && check.blockedNow+ ? { blocked_now: true, free_memory: check.freeMemory }+ : {}),...(check.state === "checked" && check.recommendation? { recommendation: check.recommendation }: {}),@@ -595,6 +608,14 @@ 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;+ this.#check = { state: "unchecked" };+ this.inspect();+ }+async #inspect(signal: AbortSignal,onDownload: (download: Transfer) => void,@@ -653,6 +674,8 @@ export class LocalServerModule implements Module {recommendation?: unknown;localModels?: {eligible?: unknown;+ state?: unknown;+ memory?: Record<string, unknown>;reasons?: unknown;reasonMessages?: unknown;estimate?: {@@ -682,8 +705,27 @@ export class LocalServerModule implements Module {typeof estimate?.model === "string" && estimate.model? estimate.model: undefined;- // Offered only with a model to show; the plan names it.- const eligible = report.localModels.eligible && !!name;+ // Offered only with a model to show; the plan names it. A plan blocked+ // now cannot install until other programs free memory.+ const blockedNow = !!name && report.localModels.state === "blocked-now";+ const eligible = report.localModels.eligible && !!name && !blockedNow;+ const memory = report.localModels.memory;+ const freeMemory: SetupMemory | undefined =+ blockedNow &&+ bytes(memory?.ramAvailableBytes) !== null &&+ bytes(memory?.ramRequiredBytes) !== null+ ? {+ ramAvailableBytes: memory!.ramAvailableBytes as number,+ ramRequiredBytes: memory!.ramRequiredBytes as number,+ ...(bytes(memory?.vramFreeBytes) !== null &&+ bytes(memory?.vramRequiredBytes) !== null+ ? {+ vramFreeBytes: memory!.vramFreeBytes as number,+ vramRequiredBytes: memory!.vramRequiredBytes as number,+ }+ : {}),+ }+ : undefined;const strings = (value: unknown) =>Array.isArray(value) ? value.map(String) : [];const messages = strings(report.localModels.reasonMessages);@@ -708,7 +750,9 @@ export class LocalServerModule implements Module {? hardware.diskFreeBytes: null,...(typeof gpu === "string" ? { gpu } : {}),- ...(eligible && name+ ...(blockedNow ? { blockedNow } : {}),+ ...(freeMemory ? { freeMemory } : {}),+ ...((eligible || blockedNow) && name? {model: {name,diff --git a/apps/desktop/src/main/setup-command.test.ts b/apps/desktop/src/main/setup-command.test.tsindex 1857d2a2..269e1e3c 100644--- a/apps/desktop/src/main/setup-command.test.ts+++ b/apps/desktop/src/main/setup-command.test.ts@@ -29,6 +29,9 @@ describe("parseSetupCommand", () => {expect(parseSetupCommand({ op: "local.location.reset" })).toEqual({op: "local.location.reset",});+ expect(parseSetupCommand({ op: "local.recheck" })).toEqual({+ op: "local.recheck",+ });expect(parseSetupCommand({ op: "local.signin.start" })).toEqual({op: "local.signin.start",});diff --git a/apps/desktop/src/main/setup-command.ts b/apps/desktop/src/main/setup-command.tsindex 2df7bb9f..c9b5760e 100644--- a/apps/desktop/src/main/setup-command.ts+++ b/apps/desktop/src/main/setup-command.ts@@ -27,6 +27,7 @@ const setupCommand = z.discriminatedUnion("op", [.optional(),}).strict(),+ z.object({ op: z.literal("local.recheck") }).strict(),z.object({ op: z.literal("local.location.pick") }).strict(),z.object({ op: z.literal("local.location.reset") }).strict(),zdiff --git a/apps/desktop/src/main/setup-window.ts b/apps/desktop/src/main/setup-window.tsindex b5d25a38..199c6092 100644--- a/apps/desktop/src/main/setup-window.ts+++ b/apps/desktop/src/main/setup-window.ts@@ -232,6 +232,9 @@ export class SetupWindowModule implements Module {void local.begin(plan).catch(() => undefined);return;}+ case "local.recheck":+ ctx.get<LocalServerModule>("LocalServer").recheck();+ return;case "local.location.pick": {const picked = await dialog.showOpenDialog(this.#window!, {title: "Choose Where to Install Linger",diff --git a/apps/desktop/src/shared/setup.ts b/apps/desktop/src/shared/setup.tsindex 668d2e12..4ff25ddb 100644--- a/apps/desktop/src/shared/setup.ts+++ b/apps/desktop/src/shared/setup.ts@@ -2,7 +2,10 @@// The setup window walks a new install through server, sign-in, connecting// this computer and the system permissions it needs.-import type { SetupChoice } from "@linger/local-installation/setup-plan";+import type {+ SetupChoice,+ SetupMemory,+} from "@linger/local-installation/setup-plan";export interface SetupFolder {readonly grantId: string;@@ -102,10 +105,17 @@ export type SetupLocalModelsCheck =| {readonly state: "checked";readonly eligible: boolean;+ // The model fits the hardware, but other programs hold the memory it+ // needs now (the tool's "blocked-now"); it is shown on hold until a+ // new check finds that memory.+ readonly blockedNow?: true;+ // While blocked now: memory free now and what the plan needs.+ readonly freeMemory?: SetupMemory;readonly memoryBytes: number;readonly diskFreeBytes: number | null;readonly gpu?: string;- // The inference model to deploy, with what it needs; when eligible.+ // The inference model to deploy, with what it needs; when eligible or+ // on hold for free memory.readonly model?: {readonly name: string;readonly downloadBytes: number | null;@@ -113,7 +123,7 @@ export type SetupLocalModelsCheck =readonly memoryBytes: number | null;};// The localmodels tool's code and words for why not, or, when- // eligible, for what could still stop the install (free memory).+ // eligible, for what could still stop the install.readonly reasons?: readonly {readonly code: string;readonly message?: string;@@ -164,6 +174,8 @@ export type SetupCommand =readonly runtime?: SetupLocalRuntime;readonly keys?: SetupProviderKeys;}+ // Checks this computer for a local model again.+ | { readonly op: "local.recheck" }// Picks the install folder with the system picker, or goes back to the// default.| { readonly op: "local.location.pick" }diff --git a/apps/desktop/src/shell/setup-page.test.ts b/apps/desktop/src/shell/setup-page.test.tsindex f52fa02b..92ddd109 100644--- a/apps/desktop/src/shell/setup-page.test.ts+++ b/apps/desktop/src/shell/setup-page.test.ts@@ -186,6 +186,28 @@ const small: SetupLocalModelsCheck = {],recommendation: "codex",};+// The model fits the hardware, but other programs hold its memory now.+const held: SetupLocalModelsCheck = {+ state: "checked",+ eligible: false,+ blockedNow: true,+ memoryBytes: 16 * GB,+ diskFreeBytes: 400 * GB,+ model: {+ name: "qwen3-8b",+ downloadBytes: 6 * GB,+ 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).",+ },+ ],+ recommendation: "codex",+};const welcome = (localModels: SetupLocalModelsCheck): SetupState => {const base = state("idle");return { ...base, localServer: { ...base.localServer, localModels } };@@ -227,6 +249,84 @@ describe("setup page Quick Install recommendation", () => {);});+ it("holds a local model that needs free memory and checks again on request", async () => {+ const { run } = await openPage(welcome(held), "welcome");+ expect($("plan-summary").textContent).toBe(+ "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.",+ );+ expect($("local-recheck").hidden).toBe(false);+ $("local-customize").click();+ expect($("local-row").hidden).toBe(false);+ expect($("local-model-name").textContent).toBe("qwen3-8b");+ expect($("local-sub").textContent).toBe(+ "On hold: close other programs, then Check again.",+ );+ expect(($("local-model") as HTMLButtonElement).disabled).toBe(true);+ expect($("local-model").getAttribute("aria-checked")).toBe("false");+ $("local-recheck").click();+ await vi.waitFor(() =>+ expect(run).toHaveBeenCalledWith({ op: "local.recheck" }),+ );+ $("local-customize").click();+ $("local-install").click();+ await vi.waitFor(() =>+ expect(installed(run)).toEqual([{ op: "local.start", runtime: "codex" }]),+ );+ });++ 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 => ({+ ...held,+ freeMemory: {+ ramAvailableBytes: 2899102924,+ ramRequiredBytes: 13689304433,+ ...(vram ? { vramFreeBytes: 3 * GB, vramRequiredBytes: 9 * GB } : {}),+ },+ reasons: [{ code, message }],+ });+ await openPage(+ welcome(+ counted(+ "free-memory-required",+ "Other programs are using memory it needs.",+ ),+ ),+ "welcome",+ );+ expect($("plan-summary").textContent).toBe(+ "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.",+ );+ expect($("local-recheck").hidden).toBe(false);+ $("local-customize").click();+ expect($("local-sub").textContent).toBe(+ "On hold: 12.7 GB memory needed, 2.7 GB free",+ );+ // 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($("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.",+ );+ });+it("lets the installer pick when this computer could not be checked", async () => {const { run } = await openPage(welcome({ state: "unavailable" }),diff --git a/apps/desktop/src/shell/setup.html b/apps/desktop/src/shell/setup.htmlindex 571a3506..f450c04d 100644--- a/apps/desktop/src/shell/setup.html+++ b/apps/desktop/src/shell/setup.html@@ -1475,6 +1475,9 @@</button></p><p class="plan-why" id="plan-why" hidden></p>+ <button class="link quiet" id="local-recheck" type="button" hidden>+ Check again+ </button></div><p class="error" id="local-error" role="alert"></p><p class="team" id="team">@@ -2209,6 +2212,26 @@const models = local.localModels;const model =models.state === "checked" && models.eligible && models.model;+ // The model fits the hardware, but other programs hold the memory it+ // 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"+ : "");if (!model) plan.localModel = false;const custom = !isDefaultPlan(local);// Quick Install waits for the check, so it installs what it shows.@@ -2275,13 +2298,30 @@(models.reasons?.[0]?.message? ". " + models.reasons[0].message: "")- : 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."- : "";+ : 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.") ++ " 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."+ : "";$("plan-why").hidden =!local.available || customizing || !$("plan-why").textContent;$("plan-line").hidden = !local.available;@@ -2307,24 +2347,35 @@remove.textContent = removing ? "Keep" : "Remove";}$("keys-note").textContent = "Applies when the installation runs.";- $("local-row").hidden = !model;- $("local-model").hidden = !model;- if (model) {- $("local-sub").textContent = [- recommended.localModel- ? "Recommended for this computer"- : "Runs your tasks on this computer",- models.gpu,- ]- .filter(Boolean)- .join(" · ");- $("local-model-name").textContent = model.name;+ const shown = model || held;+ $("local-row").hidden = !shown;+ $("local-model").hidden = !shown;+ $("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."+ : [+ recommended.localModel+ ? "Recommended for this computer"+ : "Runs your tasks on this computer",+ models.gpu,+ ]+ .filter(Boolean)+ .join(" · ");+ $("local-model-name").textContent = shown.name;$("local-model-needs").textContent = [- model.downloadBytes != null &&- gigabytes(model.downloadBytes) + " download",- model.diskBytes != null && gigabytes(model.diskBytes) + " disk",- model.memoryBytes != null &&- gigabytes(model.memoryBytes) + " memory",+ shown.downloadBytes != null &&+ gigabytes(shown.downloadBytes) + " download",+ shown.diskBytes != null && gigabytes(shown.diskBytes) + " disk",+ shown.memoryBytes != null &&+ gigabytes(shown.memoryBytes) + " memory",].filter(Boolean).join(" · ");@@ -2332,7 +2383,7 @@"aria-checked",String(plan.localModel),);- $("local-model").disabled = busy;+ $("local-model").disabled = busy || !model;}$("runtime-sub").textContent = known? "Recommended: " + RUNTIMES[recommended.runtime] + "."@@ -2709,6 +2760,9 @@$("location-change").addEventListener("click", () =>run({ op: "local.location.pick" }),);+ $("local-recheck").addEventListener("click", () =>+ run({ op: "local.recheck" }, "local-error"),+ );$("local-model").addEventListener("click", () => {picked = true;plan = plan.localModeldiff --git a/contracts/generated/typescript/src/generated/linger-installer/types.ts b/contracts/generated/typescript/src/generated/linger-installer/types.tsindex c9fa7fb6..fd720faa 100644--- a/contracts/generated/typescript/src/generated/linger-installer/types.ts+++ b/contracts/generated/typescript/src/generated/linger-installer/types.ts@@ -623,9 +623,28 @@ export interface components {choices: components["schemas"]["SetupChoice"][];localModels: {eligible: boolean;+ /**+ * @description Upstream stack.state. blocked-now means the hardware can run the plan, but installing now would stop until other programs free memory; a tool without stack.state reports that case as basis capacity or reason free-memory-required.+ * @enum {string}+ */+ state: "ready" | "blocked-now" | "unavailable";+ /** @description Upstream stack.hardwareCapable, separate from whether local models can install now; null when the tool cannot read the facts. */+ hardwareCapable?: boolean | null;+ /** @description Upstream stack.memory, present on a capacity basis; memory free now against what the plan needs. */+ memory?: {+ ramAvailableBytes: number;+ ramRequiredBytes: number;+ 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 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}+ */+ basis?: "capacity";selectedGpuIndex: number | null;estimate: {downloadBytes: number | null;diff --git a/contracts/openapi/linger-installer/openapi.yaml b/contracts/openapi/linger-installer/openapi.yamlindex 066cd4d2..9813fb2b 100644--- a/contracts/openapi/linger-installer/openapi.yaml+++ b/contracts/openapi/linger-installer/openapi.yaml@@ -1134,12 +1134,41 @@ components:additionalProperties: falserequired:- eligible+ - state- reasons- selectedGpuIndex- estimateproperties:eligible:type: boolean+ state:+ type: string+ enum:+ - ready+ - blocked-now+ - unavailable+ description: Upstream stack.state. blocked-now means the hardware can run the plan, but installing now would stop until other programs free memory; a tool without stack.state reports that case as basis capacity or reason free-memory-required.+ hardwareCapable:+ type:+ - boolean+ - "null"+ description: Upstream stack.hardwareCapable, separate from whether local models can install now; null when the tool cannot read the facts.+ memory:+ type: object+ additionalProperties: false+ description: Upstream stack.memory, present on a capacity basis; memory free now against what the plan needs.+ required:+ - ramAvailableBytes+ - ramRequiredBytes+ properties:+ ramAvailableBytes:+ type: number+ ramRequiredBytes:+ type: number+ vramFreeBytes:+ type: number+ vramRequiredBytes:+ type: numberreasons:type: arrayitems:@@ -1149,6 +1178,11 @@ components:description: Human-readable upstream explanations in the same order as reasons; model eligibility remains upstream-owned.items:type: string+ basis:+ type: string+ enum:+ - capacity+ 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.selectedGpuIndex:type:- numberdiff --git a/packages/local-installation/src/setup-plan.test.ts b/packages/local-installation/src/setup-plan.test.tsindex 047d6b1c..0969b239 100644--- a/packages/local-installation/src/setup-plan.test.ts+++ b/packages/local-installation/src/setup-plan.test.ts@@ -39,7 +39,7 @@ const upstream = (available = true) => ({},recommendation: available ? "local-models" : "pi",});-const runner = (value = upstream()) =>+const runner = (value: object = upstream()) =>vi.fn(async () => ({ code: 0, stdout: JSON.stringify(value), stderr: "" }));it("delegates all hardware policy, runtime detection, estimates and recommendation upstream", async () => {const localmodels = runner();@@ -70,6 +70,7 @@ it("delegates all hardware policy, runtime detection, estimates and recommendatiexpect(report.hardware.totalMemoryBytes).toBe(7);expect(report.localModels).toMatchObject({eligible: true,+ state: "ready",selectedGpuIndex: 4,estimate: {model: "upstream-model",@@ -95,6 +96,7 @@ it("delegates all hardware policy, runtime detection, estimates and recommendatiit("preserves upstream rejection and never substitutes downstream eligibility", async () => {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",@@ -105,6 +107,135 @@ it("preserves upstream rejection and never substitutes downstream eligibility","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) => {+ const value = upstream();+ return {+ ...value,+ stack: {+ ...value.stack,+ basis: "capacity",+ reasons: [+ {+ code: "free-memory-required",+ message: "Close other programs before installing.",+ },+ ],+ },+ harness: {+ ...value.harness,+ runtimes: value.harness.runtimes.map((row) => ({+ ...row,+ installed: installed && row.installed,+ })),+ },+ };+ };+ const report = await inspectSetup({ localmodels: runner(freeMemory(true)) });+ expect(report.localModels).toMatchObject({+ eligible: false,+ state: "blocked-now",+ basis: "capacity",+ reasons: ["free-memory-required"],+ 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.+ const { basis: _, ...stack } = freeMemory(true).stack;+ const coded = await inspectSetup({+ localmodels: runner({ ...freeMemory(true), stack }),+ });+ expect(coded.localModels).toMatchObject({+ state: "blocked-now",+ basis: "capacity",+ });+ expect(coded.recommendation).toBe("pi");+ const ready = await inspectSetup({ localmodels: runner() });+ expect(ready.localModels).not.toHaveProperty("basis");+});+it("reads the tool's blocked-now state, memory and recommendation", async () => {+ const value = upstream();+ const blocked = {+ ...value,+ stack: {+ ...value.stack,+ available: false,+ state: "blocked-now",+ hardwareCapable: true,+ basis: "capacity",+ reasons: [+ {+ code: "free-memory-required",+ message: "Close other programs before installing.",+ },+ ],+ memory: {+ ramAvailableBytes: 2899102924,+ ramRequiredBytes: 13689304433,+ vramFreeBytes: 3,+ vramRequiredBytes: 8,+ },+ },+ recommendation: "codex",+ };+ const report = await inspectSetup({ localmodels: runner(blocked) });+ expect(report.localModels).toMatchObject({+ eligible: false,+ state: "blocked-now",+ hardwareCapable: true,+ basis: "capacity",+ memory: {+ ramAvailableBytes: 2899102924,+ ramRequiredBytes: 13689304433,+ vramFreeBytes: 3,+ vramRequiredBytes: 8,+ },+ estimate: { model: "upstream-model" },+ });+ // The tool's non-local pick stands, even with Pi installed.+ expect(report.recommendation).toBe("codex");+ // The tool's state wins over the older marks; null fields stay out.+ const ready = await inspectSetup({+ localmodels: runner({+ ...value,+ stack: {+ ...value.stack,+ state: "ready",+ hardwareCapable: true,+ basis: null,+ memory: null,+ },+ }),+ });+ expect(ready.localModels).toMatchObject({+ eligible: true,+ state: "ready",+ hardwareCapable: true,+ });+ expect(ready.localModels).not.toHaveProperty("basis");+ expect(ready.localModels).not.toHaveProperty("memory");+ const small = await inspectSetup({+ localmodels: runner({+ ...upstream(false),+ stack: {+ ...upstream(false).stack,+ state: "unavailable",+ hardwareCapable: false,+ },+ }),+ });+ expect(small.localModels).toMatchObject({+ eligible: false,+ state: "unavailable",+ hardwareCapable: false,+ });+});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 ca1d30fc..c9aff3cf 100644--- a/packages/local-installation/src/setup-plan.ts+++ b/packages/local-installation/src/setup-plan.ts@@ -27,6 +27,15 @@ export function setupSelection(: { runtime: choice, modelSource: "runtime" };}export type SetupReason = string;+/** 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. */+export interface SetupMemory {+ ramAvailableBytes: number;+ ramRequiredBytes: number;+ vramFreeBytes?: number;+ vramRequiredBytes?: number;+}export interface SetupGpu {index: number;name: string;@@ -52,8 +61,26 @@ export interface SetupReport {choices: SetupChoice[];localModels: {eligible: boolean;+ /**+ * Upstream `stack.state`. "blocked-now": the hardware can run the plan,+ * but installing now would stop until other programs free memory (or quit+ * another inference app). A tool without the field reports the same case+ * with basis "capacity" or reason free-memory-required.+ */+ state: LocalModelsState;+ /** Upstream `stack.hardwareCapable`, when the tool reports it. */+ hardwareCapable?: boolean | null;+ /** 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+ * free-memory-required); the install plans again against the memory free+ * then.+ */+ basis?: "capacity";selectedGpuIndex: number | null;estimate: SetupEstimate & { model: string };};@@ -91,6 +118,10 @@ interface UpstreamReport {};stack: {available: boolean;+ state?: LocalModelsState;+ hardwareCapable?: boolean | null;+ basis?: "capacity" | null;+ memory?: SetupMemory | null;reasons: { code: string; message: string }[];plan: {llm: { model: { id: string }; placement: { gpus: { index: number }[] } };@@ -118,7 +149,13 @@ export const setupChoices: readonly SetupChoice[] = ["claude","pi",];-/** Presentation adapter only. Host probes, admission, recommendation and budgets belong upstream. */+/**+ * Presentation adapter only. Host probes, admission, recommendation and+ * budgets belong upstream, with one exception: when local models are blocked+ * now, a tool before setup-report `stack.state` still picks "local-models",+ * which its own install-time plan refuses; the adapter replaces that pick.+ * Remove the override and the fallbacks once the pinned tool reports `state`.+ */export async function inspectSetup(options: SetupOptions = {},): Promise<SetupReport> {@@ -184,6 +221,52 @@ export async function inspectSetup(budget?.assumption ??"Resource estimates are unavailable from localmodels.",});+ // Either structured mark means the plan needs memory other programs+ // hold now, which the install-time plan refuses.+ const capacity =+ value.stack.basis === "capacity" ||+ value.stack.reasons.some(+ (reason) => reason.code === "free-memory-required",+ );+ // The tool's own state when it reports one; an older tool marks the+ // blocked case only by the capacity basis or reason.+ const states: readonly string[] = ["ready", "blocked-now", "unavailable"];+ const state: LocalModelsState =+ value.stack.state && states.includes(value.stack.state)+ ? value.stack.state+ : capacity+ ? "blocked-now"+ : value.stack.available+ ? "ready"+ : "unavailable";+ 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 {+ ramAvailableBytes: memory.ramAvailableBytes,+ ramRequiredBytes: memory.ramRequiredBytes,+ ...(ok(memory.vramFreeBytes) && ok(memory.vramRequiredBytes)+ ? {+ vramFreeBytes: memory.vramFreeBytes,+ vramRequiredBytes: memory.vramRequiredBytes,+ }+ : {}),+ };+ };+ const memory = value.stack.memory ? counts(value.stack.memory) : undefined;+ const runtimes = value.harness.runtimes;+ const installed = runtimes.filter((row) => row.installed);+ // A tool before `stack.state` recommends local models whenever they fit+ // the hardware, even when they cannot be installed until memory is+ // freed. Then the adapter picks as upstream does for unavailable local+ // models: an installed (signed-in first) runtime, else Codex.+ const recommendation =+ state === "blocked-now" && value.recommendation === "local-models"+ ? ((installed.find((row) => row.authenticated) ?? installed[0])+ ?.runtime ?? "codex")+ : value.recommendation;return {hardware: {platform: value.facts.platform,@@ -203,9 +286,16 @@ export async function inspectSetup(},choices: [...setupChoices],localModels: {- eligible: value.stack.available,+ eligible: state === "ready" && value.stack.available,+ state,+ ...(typeof value.stack.hardwareCapable === "boolean" ||+ value.stack.hardwareCapable === null+ ? { hardwareCapable: value.stack.hardwareCapable }+ : {}),+ ...(memory ? { memory } : {}),reasons: value.stack.reasons.map((reason) => reason.code),reasonMessages: value.stack.reasons.map((reason) => reason.message),+ ...(capacity ? { basis: "capacity" as const } : {}),selectedGpuIndex: plan?.llm.placement.gpus[0]?.index ?? null,estimate: {...estimate(@@ -223,7 +313,7 @@ export async function inspectSetup(model: plan?.llm.model.id ?? "",},},- runtimes: value.harness.runtimes.map((row) => ({+ runtimes: runtimes.map((row) => ({choice: row.runtime,installed: row.installed,auth:@@ -234,7 +324,7 @@ export async function inspectSetup(: "unauthenticated",estimate: estimate(row.estimate),})),- recommendation: value.recommendation,+ recommendation,};} catch {options.signal?.throwIfAborted();