Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions apps/desktop/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,14 @@ Gateway and runs Agents. The daemon exits with the app.
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,
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 runtime
it is greyed (`aria-disabled`, still focusable), does not toggle, and says
"Local models are only available with the Pi runtime."; choosing another
Expand All @@ -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 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
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 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
Expand Down
19 changes: 11 additions & 8 deletions apps/desktop/src/main/local-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,19 @@ 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 = {
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.stdout.write(JSON.stringify({ hardware, localModels: { ...local, reasons, estimate }, recommendation }) + "\n");
process.exit(0);
}
if (args.includes("--resume")) {
Expand Down Expand Up @@ -1612,14 +1615,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({
Expand Down Expand Up @@ -1651,7 +1653,8 @@ describe("LocalServerModule", () => {
reasons: [
{
code: "free-memory-required",
message: "Close other programs before installing.",
freeBytes: 2899102924,
requiredBytes: 13689304433,
},
],
recommendation: "codex",
Expand Down
61 changes: 36 additions & 25 deletions apps/desktop/src/main/local-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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`.
Expand Down Expand Up @@ -123,19 +127,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.
Expand Down Expand Up @@ -600,7 +599,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,
Expand All @@ -610,13 +609,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;
},
Expand Down Expand Up @@ -718,7 +711,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) => {
Expand Down Expand Up @@ -776,7 +773,6 @@ export class LocalServerModule implements Module {
state?: unknown;
memory?: Record<string, unknown>;
reasons?: unknown;
reasonMessages?: unknown;
estimate?: {
model?: unknown;
downloadBytes?: unknown;
Expand Down Expand Up @@ -825,12 +821,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.
Expand All @@ -840,7 +850,7 @@ export class LocalServerModule implements Module {
(pick !== "local-models" || eligible)
? (pick as SetupChoice)
: undefined;
return {
const check: LocalModelsCheck = {
state: "checked",
eligible,
memoryBytes: hardware.totalMemoryBytes,
Expand All @@ -864,6 +874,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.
Expand Down
22 changes: 16 additions & 6 deletions apps/desktop/src/shared/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
Loading
Loading