Skip to content

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.

feat(desktop): show the setup check and download progress

claude-opus-5-5-medium24abfcf717dd
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.md
index afe28af9..66279f19 100644
--- a/apps/desktop/AGENTS.md
+++ b/apps/desktop/AGENTS.md
@@ -118,8 +118,14 @@ Gateway and runs Agents. The daemon exits with the app.
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; otherwise the named runtime, with the tool's
- reason for no local model. The page adds no host rule of its own; it waits
- for the check, and Customize marks the recommended runtime and model. When
+ reason for no local model. The page adds no host rule of its own; while
+ the 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 the
+ recommended runtime and model. While installing, a step that downloads
+ shows its bytes, what remains and the rate from the installer's byte
+ counter (`localmodels.stack-progress/v1` for the local model and
+ engine); a counter of one file (`partial`) shows only that file. When
the check fails the installer picks, or Codex when it cannot inspect the
computer either. It records the install location, source, origin and engine in
`desktop/local-server.json` under the default home and, while the window
diff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.ts
index 84667267..dc429216 100644
--- a/apps/desktop/src/main/local-server.test.ts
+++ b/apps/desktop/src/main/local-server.test.ts
@@ -78,6 +78,12 @@ if (args.includes("--inspect")) {
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: "", 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.
+ process.stdout.write(JSON.stringify({ event: "download", completed: 5, total: 10 }) + "\n");
+ while (!fs.existsSync(path.join(home, "tool-ready")))
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 20);
+ }
process.stderr.write("Checked this computer in 1.5s.\n");
const reasons = eligible ? [] : ["facts-unavailable"];
const reasonMessages = eligible ? [] : ["nvidia-smi was not found"];
@@ -1270,6 +1276,28 @@ describe("LocalServerModule", () => {
info.mockRestore();
});
+ it("counts the localmodels tool download while checking", async () => {
+ const f = fixture({ checkout: "/src" }, {}, (home) => {
+ mkdirSync(home, { recursive: true });
+ writeFileSync(path.join(home, "tool-download"), "");
+ });
+ await f.host.start();
+ f.module.inspect();
+ await vi.waitFor(() =>
+ expect(f.module.status().localModels).toEqual({
+ state: "checking",
+ download: { completed: 5, total: 10 },
+ }),
+ );
+ writeFileSync(path.join(f.home, "tool-ready"), "");
+ await vi.waitFor(() =>
+ expect(f.module.status().localModels).toMatchObject({
+ state: "checked",
+ recommendation: "local-models",
+ }),
+ );
+ });
+
it("does not recommend a local model it cannot name", async () => {
const f = fixture({ checkout: "/src" }, {}, (home) => {
mkdirSync(home, { recursive: true });
@@ -1468,6 +1496,48 @@ describe("LocalServerModule", () => {
await f.host.stop("quit");
});
+ it("shows the local model download the installer counts", async () => {
+ const f = fixture(
+ withCheckout,
+ {},
+ checkout,
+ installerApi([], undefined, undefined, {
+ state: "running",
+ stage: "runtime",
+ message: "Downloading the local model…",
+ stages: [
+ {
+ id: "runtime",
+ state: "running",
+ progress: {
+ completed: 4,
+ total: 10,
+ unit: "bytes",
+ bytesPerSecond: 2,
+ partial: true,
+ },
+ },
+ ],
+ }),
+ );
+ await f.host.start();
+ const seen: unknown[] = [];
+ f.host.ctx.bus.on("local-server.changed", () =>
+ seen.push(f.module.status().transfer),
+ );
+ await f.module.begin();
+ expect(seen).toContainEqual({
+ label: "Downloading the local model…",
+ completed: 4,
+ total: 10,
+ bytesPerSecond: 2,
+ partial: true,
+ });
+ // Done, nothing downloads.
+ expect(f.module.status().transfer).toBeUndefined();
+ await f.host.stop("quit");
+ });
+
it("never steps back while the runtime prepares beside the checkout", async () => {
const f = fixture(
withCheckout,
diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.ts
index 9fb4266e..67153c18 100644
--- a/apps/desktop/src/main/local-server.ts
+++ b/apps/desktop/src/main/local-server.ts
@@ -95,7 +95,9 @@ export interface LocalModel {
// What the installer found on this computer, for the optional local model.
export type LocalModelsCheck =
- | { readonly state: "unchecked" | "checking" | "unavailable" }
+ | { readonly state: "unchecked" | "unavailable" }
+ // While the check first downloads the localmodels tool: its bytes.
+ | { readonly state: "checking"; readonly download?: Transfer }
| {
readonly state: "checked";
// Whether this computer can serve a local model at all.
@@ -114,6 +116,16 @@ export type LocalModelsCheck =
};
export type SetupRecommendation = "local-models" | "codex" | "claude" | "pi";
+
+// 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.
+export interface Transfer {
+ readonly completed: number;
+ readonly total?: number;
+ readonly bytesPerSecond?: number;
+ readonly partial?: boolean;
+}
const RECOMMENDATIONS: readonly string[] = [
"local-models",
"codex",
@@ -236,6 +248,8 @@ export interface LocalServerStatus {
readonly steps: readonly LocalServerStep[];
readonly step: LocalServerStep;
readonly progress: number;
+ // While the current step downloads: what and how far.
+ readonly transfer?: Transfer & { readonly label: string };
// Which installation this is; each Install or Try Again starts a new one.
readonly attempt: number;
readonly localModels: LocalModelsCheck;
@@ -328,6 +342,7 @@ export class LocalServerModule implements Module {
#message = "";
#step: LocalServerStep = "prepare";
#progress = 0;
+ #transfer: LocalServerStatus["transfer"];
// Counts installations started, so the setup page restarts its timers.
#attempt = 0;
#origin: string | undefined;
@@ -424,6 +439,7 @@ export class LocalServerModule implements Module {
steps: this.#steps(),
step: this.#step,
progress: this.#progress,
+ ...(this.#transfer ? { transfer: this.#transfer } : {}),
attempt: this.#attempt,
localModels: this.#check,
location: {
@@ -478,7 +494,11 @@ export class LocalServerModule implements Module {
this.#ctx?.bus.emit("local-server.changed");
const started = Date.now();
const signal = this.#abort.signal;
- void this.#inspect(signal)
+ void this.#inspect(signal, (download) => {
+ if (this.#check.state !== "checking") return;
+ this.#check = { state: "checking", download };
+ this.#ctx?.bus.emit("local-server.changed");
+ })
.then(
(check) => {
this.#ctx?.log.info("local_server.inspected", {
@@ -508,7 +528,10 @@ export class LocalServerModule implements Module {
});
}
- async #inspect(signal: AbortSignal): Promise<LocalModelsCheck> {
+ async #inspect(
+ signal: AbortSignal,
+ onDownload: (download: Transfer) => void,
+ ): Promise<LocalModelsCheck> {
// 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) => {
@@ -534,14 +557,31 @@ export class LocalServerModule implements Module {
line: line.slice(0, 300),
});
});
- let text = "";
- child.stdout.on("data", (chunk: Buffer) => {
- text += chunk.toString("utf8");
+ // The report is the last line; lines before it count the bytes of the
+ // localmodels tool while the check first downloads it.
+ let last = "";
+ createInterface({ input: child.stdout }).on("line", (line) => {
+ if (!line.trim()) return;
+ last = line;
+ let event: { event?: unknown; completed?: unknown; total?: unknown };
+ try {
+ event = JSON.parse(line);
+ } catch {
+ return;
+ }
+ const count = (value: unknown) =>
+ typeof value === "number" && Number.isFinite(value) && value >= 0
+ ? value
+ : undefined;
+ const completed = count(event?.completed);
+ const total = count(event?.total);
+ if (event?.event === "download" && completed !== undefined)
+ onDownload({ completed, ...(total ? { total } : {}) });
});
child.once("error", reject);
- child.once("close", () => resolve(text));
+ child.once("close", () => resolve(last));
});
- const report = JSON.parse(output.trim().split("\n").at(-1) ?? "") as {
+ const report = JSON.parse(output) as {
recommendation?: unknown;
localModels?: {
eligible?: unknown;
@@ -685,7 +725,8 @@ export class LocalServerModule implements Module {
installer.run(
next,
signal,
- (stage, share, text) => this.#advance(stage, share, text),
+ (stage, share, text, transfer) =>
+ this.#advance(stage, share, text, transfer),
fresh,
);
// Changed keys reach the services only when the installation runs
@@ -744,7 +785,12 @@ export class LocalServerModule implements Module {
}
}
- #advance(step: LocalServerStep, share: number, message: string): void {
+ #advance(
+ step: LocalServerStep,
+ share: number,
+ message: string,
+ transfer?: Transfer,
+ ): void {
const steps = this.#steps();
share = Math.min(1, Math.max(0, share));
// Without a download, its stages finish preparing instead.
@@ -759,6 +805,7 @@ export class LocalServerModule implements Module {
this.#progress,
(steps.indexOf(step) + share) / steps.length,
);
+ this.#transfer = transfer && { ...transfer, label: message };
this.#set("installing", message);
}
@@ -1038,6 +1085,7 @@ export class LocalServerModule implements Module {
this.#step = "prepare";
}
if (phase === "ready") this.#progress = 1;
+ if (phase !== "installing") this.#transfer = undefined;
this.#phase = phase;
this.#message = message;
this.#ctx?.bus.emit("local-server.changed");
@@ -1211,8 +1259,13 @@ export class LocalServerModule implements Module {
SOURCE_MARKER,
path.join(home, "desktop", "downloads"),
signal,
- (share) =>
- this.#advance("download", share * 0.05, "Downloading Linger…"),
+ (bytes) =>
+ this.#advance(
+ "download",
+ (bytes.completed / bytes.total) * 0.05,
+ "Downloading Linger…",
+ bytes,
+ ),
);
if (!(await isFile(path.join(directory, SOURCE_MARKER))))
throw new Error("The source package is not a Linger source tree");
@@ -1420,7 +1473,13 @@ export class LocalServerModule implements Module {
".",
path.join(path.dirname(path.dirname(repo)), "downloads"),
signal,
- (share) => this.#advance("download", 0.05 + share * 0.05, message),
+ (bytes) =>
+ this.#advance(
+ "download",
+ 0.05 + (bytes.completed / bytes.total) * 0.05,
+ message,
+ bytes,
+ ),
);
} catch (error) {
if (signal.aborted) throw error;
@@ -1480,7 +1539,7 @@ export class LocalServerModule implements Module {
marker: string,
downloads: string,
signal: AbortSignal,
- onShare?: (share: number) => void,
+ onBytes?: (bytes: { completed: number; total: number }) => void,
): Promise<void> {
await mkdir(downloads, { recursive: true, mode: 0o700 });
const file = path.join(
@@ -1501,7 +1560,7 @@ export class LocalServerModule implements Module {
// A retry continues a large download where it stopped.
resumable: true,
onProgress: (completed, total) =>
- total && onShare?.(completed / total),
+ total && onBytes?.({ completed, total }),
},
followHttps(this.#options.fetch ?? fetch),
);
@@ -2127,7 +2186,13 @@ interface Job {
readonly stages: readonly {
readonly id: string;
readonly state: string;
- readonly progress?: { readonly completed: number; readonly total?: number };
+ readonly progress?: {
+ readonly completed: number;
+ readonly total?: number;
+ readonly unit?: string;
+ readonly bytesPerSecond?: number;
+ readonly partial?: boolean;
+ };
}[];
}
@@ -2211,7 +2276,12 @@ export class InstallerApi {
async run(
plan: LocalServerPlan,
signal: AbortSignal,
- onStep: (step: LocalServerStep, share: number, message: string) => void,
+ onStep: (
+ step: LocalServerStep,
+ share: number,
+ message: string,
+ transfer?: Transfer,
+ ) => void,
fresh = false,
): Promise<{ readonly origin: string; readonly signInRequired: boolean }> {
const { items } = await this.#json<{ items: Job[] }>("/api/jobs");
@@ -2268,7 +2338,26 @@ export class InstallerApi {
: ready
? Number(ready[1]) / Math.max(1, Number(ready[2]))
: 0;
- onStep(at[0], at[1] + (at[2] - at[1]) * part, job.message ?? "");
+ // A byte counter on the running step is a download to show.
+ const bytes =
+ stage?.state === "running" &&
+ counter?.unit === "bytes" &&
+ counter.total
+ ? counter
+ : undefined;
+ onStep(
+ at[0],
+ at[1] + (at[2] - at[1]) * part,
+ job.message ?? "",
+ bytes && {
+ completed: bytes.completed,
+ total: bytes.total,
+ ...(bytes.bytesPerSecond !== undefined
+ ? { bytesPerSecond: bytes.bytesPerSecond }
+ : {}),
+ ...(bytes.partial ? { partial: true } : {}),
+ },
+ );
}
if (finished(job))
return { origin: job.origin!, signInRequired: signInRequired(job) };
diff --git a/apps/desktop/src/main/setup-window.ts b/apps/desktop/src/main/setup-window.ts
index 5382cc64..ac2a919e 100644
--- a/apps/desktop/src/main/setup-window.ts
+++ b/apps/desktop/src/main/setup-window.ts
@@ -405,6 +405,7 @@ const localServerState = (
steps,
step,
progress,
+ transfer,
attempt,
localModels,
location,
@@ -419,6 +420,7 @@ const localServerState = (
steps,
step,
progress,
+ ...(transfer ? { transfer } : {}),
attempt,
localModels,
location: {
diff --git a/apps/desktop/src/shared/setup.ts b/apps/desktop/src/shared/setup.ts
index 05a88aaf..41b86a43 100644
--- a/apps/desktop/src/shared/setup.ts
+++ b/apps/desktop/src/shared/setup.ts
@@ -22,6 +22,10 @@ export interface SetupLocalServer {
readonly steps: readonly SetupLocalStep[];
readonly step: SetupLocalStep;
readonly progress: number;
+ // While the current step downloads: what (label), the 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.
+ readonly transfer?: SetupTransfer & { readonly label: string };
// Which installation this is; timers and the bar start over with each.
readonly attempt: number;
// Whether this computer can serve a local model; checked as the setup
@@ -79,8 +83,17 @@ export interface SetupRuntimeSignIn {
readonly message?: string;
}
+export interface SetupTransfer {
+ readonly completed: number;
+ readonly total?: number;
+ readonly bytesPerSecond?: number;
+ readonly partial?: boolean;
+}
+
export type SetupLocalModelsCheck =
- | { readonly state: "unchecked" | "checking" | "unavailable" }
+ | { readonly state: "unchecked" | "unavailable" }
+ // While the check first downloads the localmodels tool: its bytes.
+ | { readonly state: "checking"; readonly download?: SetupTransfer }
| {
readonly state: "checked";
readonly eligible: boolean;
diff --git a/apps/desktop/src/shell/setup-page.test.ts b/apps/desktop/src/shell/setup-page.test.ts
index 2cf7db44..e6ac8415 100644
--- a/apps/desktop/src/shell/setup-page.test.ts
+++ b/apps/desktop/src/shell/setup-page.test.ts
@@ -241,12 +241,34 @@ describe("setup page Quick Install recommendation", () => {
);
});
- it("waits for the check before Quick Install", async () => {
+ it("says what Quick Install waits for until the check ends", async () => {
const { push } = await openPage(welcome({ state: "checking" }), "welcome");
- expect($("plan-summary").textContent).toBe("Checking this computer…");
- expect(($("local-install") as HTMLButtonElement).disabled).toBe(true);
+ const button = $("local-install") as HTMLButtonElement;
+ expect(button.disabled).toBe(true);
+ expect(button.getAttribute("aria-busy")).toBe("true");
+ expect($("local-install-label").textContent).toBe(
+ "Checking this computer…",
+ );
+ expect($("local-install-label").querySelector(".spinner")).not.toBeNull();
+ expect($("plan-summary").textContent).toBe(
+ "Finding the best setup for this computer",
+ );
+ // The first run downloads the localmodels tool before checking.
+ push(
+ welcome({
+ state: "checking",
+ download: { completed: 12 * 1024 ** 2, total: 69 * 1024 ** 2 },
+ }),
+ );
+ expect($("local-install-label").textContent).toBe(
+ "Downloading setup tools…",
+ );
+ expect($("plan-why").textContent).toBe("12 MB of 69 MB · 57 MB left");
+ expect($("plan-why").hidden).toBe(false);
push(welcome(capable));
- expect(($("local-install") as HTMLButtonElement).disabled).toBe(false);
+ expect(button.disabled).toBe(false);
+ expect(button.getAttribute("aria-busy")).toBe("false");
+ expect($("local-install-label").textContent).toBe("Quick Install");
expect($("plan-summary").textContent).toBe(
"Recommended for this computer: Local model + Pi",
);
@@ -284,3 +306,50 @@ describe("setup page Quick Install recommendation", () => {
);
});
});
+
+describe("setup page download progress", () => {
+ const installing = (transfer?: SetupState["localServer"]["transfer"]) => {
+ const base = state("installing");
+ return {
+ ...base,
+ localServer: { ...base.localServer, ...(transfer ? { transfer } : {}) },
+ };
+ };
+
+ it("shows how much of the local model is left, the rate and the time", async () => {
+ const { push } = await openPage(installing());
+ expect($("installing-transfer").hidden).toBe(true);
+ push(
+ installing({
+ label: "Downloading the local model…",
+ completed: 12 * GB,
+ total: 31 * GB,
+ bytesPerSecond: 50 * 1024 ** 2,
+ }),
+ );
+ expect($("installing-transfer").hidden).toBe(false);
+ expect($("installing-transfer-label").textContent).toBe(
+ "Downloading the local model…",
+ );
+ expect($("installing-transfer-bytes").textContent).toBe(
+ "12.0 GB of 31.0 GB · 19.0 GB left · 50 MB/s · about 6 min left",
+ );
+ push(installing());
+ expect($("installing-transfer").hidden).toBe(true);
+ });
+
+ it("says only the file's bytes when the tool counts one file", async () => {
+ await openPage(
+ installing({
+ label: "Downloading the local model…",
+ completed: 3 * GB,
+ total: 4 * GB,
+ bytesPerSecond: 50 * 1024 ** 2,
+ partial: true,
+ }),
+ );
+ expect($("installing-transfer-bytes").textContent).toBe(
+ "This file: 3.0 GB of 4.0 GB · 50 MB/s",
+ );
+ });
+});
diff --git a/apps/desktop/src/shell/setup.html b/apps/desktop/src/shell/setup.html
index e3c57335..7f52dbf2 100644
--- a/apps/desktop/src/shell/setup.html
+++ b/apps/desktop/src/shell/setup.html
@@ -574,6 +574,14 @@
.primary.large:hover:not(:disabled) svg {
transform: translateX(2px);
}
+ /* Checking this computer: the button waits with what it is doing. */
+ .primary.large[data-busy="true"] {
+ opacity: 0.8;
+ cursor: progress;
+ }
+ .primary.large[data-busy="true"] svg {
+ display: none;
+ }
/* What Quick Install does, and the way to change it. */
.plan-line {
display: flex;
@@ -590,6 +598,24 @@
color: var(--faint);
font-size: 11.5px;
line-height: 1.45;
+ font-variant-numeric: tabular-nums;
+ }
+ /* What downloads now, under the installing bar. */
+ .transfer {
+ display: grid;
+ gap: 2px;
+ margin: 10px 0 0;
+ color: var(--faint);
+ font-size: 11.5px;
+ line-height: 1.45;
+ font-variant-numeric: tabular-nums;
+ }
+ .transfer span span {
+ white-space: nowrap;
+ }
+ .transfer strong {
+ color: var(--ink);
+ font-weight: 500;
}
.plan-line .sep {
width: 3px;
@@ -1462,6 +1488,10 @@
><span class="pct" id="installing-count"></span>
</div>
<div class="track"><div class="fill" id="installing-fill"></div></div>
+ <p class="transfer" id="installing-transfer" hidden>
+ <strong id="installing-transfer-label"></strong
+ ><span id="installing-transfer-bytes"></span>
+ </p>
<ol class="checks" id="installing-checks"></ol>
</div>
<div
@@ -1857,6 +1887,40 @@
["agents", () => "Preparing your agents"],
];
const gigabytes = (bytes) => Math.round(bytes / 1024 ** 3) + " GB";
+ // Download sizes: MB below a gigabyte, one decimal GB above.
+ const size = (bytes) =>
+ bytes < 1024 ** 3
+ ? Math.max(0, Math.round(bytes / 1024 ** 2)) + " MB"
+ : (bytes / 1024 ** 3).toFixed(1) + " GB";
+ const duration = (seconds) => {
+ const minutes = Math.round(seconds / 60);
+ if (minutes < 1) return "less than a minute left";
+ if (minutes < 60) return "about " + minutes + " min left";
+ const hours = Math.floor(minutes / 60);
+ return (
+ "about " +
+ hours +
+ " h" +
+ (minutes % 60 ? " " + (minutes % 60) + " min" : "") +
+ " left"
+ );
+ };
+ // A download as the localmodels tool or the installer counts it: how
+ // much of how much, what remains, and the rate and time left when the
+ // source reports a rate. A count of one file of several says only
+ // that file's bytes, since nothing says what remains after it.
+ const transferParts = (transfer) => {
+ const { completed, total, bytesPerSecond: rate, partial } = transfer;
+ const left = total && !partial ? total - completed : undefined;
+ return [
+ (partial ? "This file: " : "") +
+ size(completed) +
+ (total ? " of " + size(total) : ""),
+ left !== undefined && size(left) + " left",
+ rate > 0 && size(rate) + "/s",
+ rate > 0 && left !== undefined && duration(left / rate),
+ ].filter(Boolean);
+ };
// Long folders keep their start and their end.
const shortPath = (value) =>
value.length <= 46
@@ -2145,14 +2209,25 @@
$("local-customize").textContent = customizing
? "Use the defaults"
: "Customize";
- $("local-install-label").textContent = custom
- ? "Install"
- : "Quick Install";
+ // Until the check ends the button says what it waits for: the first
+ // run downloads the localmodels tool, then the check runs. The label
+ // changes only when it differs, so the spinner keeps turning.
+ const fetching = checking ? models.download : undefined;
+ const label = checking
+ ? '<span class="spinner"></span>' +
+ (fetching ? "Downloading setup tools…" : "Checking this computer…")
+ : custom
+ ? "Install"
+ : "Quick Install";
+ if ($("local-install-label").innerHTML !== label)
+ $("local-install-label").innerHTML = label;
document.querySelector('[data-step="welcome"]').dataset.customizing =
String(customizing && local.available);
$("local-install").disabled ||= checking;
+ $("local-install").dataset.busy = String(checking);
+ $("local-install").setAttribute("aria-busy", String(checking));
$("plan-summary").textContent = checking
- ? "Checking this computer…"
+ ? "Finding the best setup for this computer"
: following && known
? "Recommended for this computer: " + named(plan)
: [
@@ -2162,8 +2237,9 @@
.filter(Boolean)
.join(" · ");
// Why, in the localmodels tool's facts and words.
- $("plan-why").textContent =
- !following || checking
+ $("plan-why").textContent = fetching
+ ? transferParts(fetching).join(" · ")
+ : !following || checking
? ""
: plan.localModel
? [
@@ -2287,6 +2363,21 @@
? local.message
: steps[at][1]() + "…";
$("installing-count").textContent = starting ? "" : percent + "%";
+ // A download under way: what it is and how far, in the counts the
+ // installer passes on from the localmodels tool.
+ const transfer = !failed && !starting ? local.transfer : undefined;
+ $("installing-transfer").hidden = !transfer;
+ $("installing-transfer-label").textContent = transfer
+ ? transfer.label
+ : "";
+ // Each part stays on one line, so a wrap falls between parts.
+ $("installing-transfer-bytes").replaceChildren(
+ ...(transfer ? transferParts(transfer) : []).flatMap((text, i) => {
+ const part = document.createElement("span");
+ part.textContent = text;
+ return i ? [" · ", part] : [part];
+ }),
+ );
$("installing-checks").hidden = starting;
const checks = $("installing-checks");
if (checks.children.length !== steps.length)
diff --git a/apps/linger-installer/src/main.ts b/apps/linger-installer/src/main.ts
index 59564731..db553351 100644
--- a/apps/linger-installer/src/main.ts
+++ b/apps/linger-installer/src/main.ts
@@ -117,11 +117,13 @@ async function resume(options: ReturnType<typeof parseInstallerArguments>) {
);
}
// Headless check of this computer for the desktop client: the setup report
-// as one JSON line on stdout.
+// as the last JSON line on stdout. Before it, {"event":"download"} lines
+// count the bytes while the check first downloads the localmodels tool.
async function inspect(options: ReturnType<typeof parseInstallerArguments>) {
const { inspectSetup } =
await import("@linger/local-installation/setup-plan");
const startedAt = Date.now();
+ let counted = 0;
// The desktop logs stderr, so a slow check says which part was slow.
const report = await inspectSetup({
home: options.home,
@@ -129,6 +131,19 @@ async function inspect(options: ReturnType<typeof parseInstallerArguments>) {
onEvent: (event) => {
if (event.kind === "log")
process.stderr.write(event.message.replace(/\n?$/, "\n"));
+ const progress = event.progress;
+ if (event.kind !== "stage" || progress?.unit !== "bytes") return;
+ // A download reports every chunk; a few lines a second are enough.
+ const done = progress.total === progress.completed;
+ if (!done && Date.now() - counted < 250) return;
+ counted = Date.now();
+ process.stdout.write(
+ `${JSON.stringify({
+ event: "download",
+ completed: progress.completed,
+ ...(progress.total ? { total: progress.total } : {}),
+ })}\n`,
+ );
},
}).catch(() => null);
process.stderr.write(
diff --git a/apps/linger-installer/src/server/jobs.test.ts b/apps/linger-installer/src/server/jobs.test.ts
index aa250864..cffb73e4 100644
--- a/apps/linger-installer/src/server/jobs.test.ts
+++ b/apps/linger-installer/src/server/jobs.test.ts
@@ -1,4 +1,4 @@
-import { expect, test, afterEach } from "vitest";
+import { expect, test, afterEach, vi } from "vitest";
import { mkdtemp, rm, readFile, stat } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
@@ -577,3 +577,33 @@ test("chunk progress replaces the previous update and keeps the log lines", asyn
await loaded.load();
expect(loaded.replay(job.id, 0)).toHaveLength(events.length);
});
+test("a step update without a counter clears the finished download's bytes", async () => {
+ let release!: () => void;
+ const held = new Promise<void>((resolve) => (release = resolve));
+ const { jobs } = await setup(async (_input, _signal, emit) => {
+ emit({
+ kind: "stage",
+ stage: "runtime",
+ state: "running",
+ message: "Downloading the local model…",
+ progress: { completed: 5, total: 10, unit: "bytes", bytesPerSecond: 2 },
+ });
+ emit({
+ kind: "stage",
+ stage: "runtime",
+ state: "running",
+ message: "Installing the selected Harness…",
+ });
+ await held;
+ return { code: 0, state: "ready", message: "Ready" };
+ });
+ const job = await jobs.start({ instance: "default" });
+ await vi.waitFor(() =>
+ expect(jobs.get(job.id)?.message).toBe("Installing the selected Harness…"),
+ );
+ expect(
+ jobs.get(job.id)?.stages.find((stage) => stage.id === "runtime")?.progress,
+ ).toBeUndefined();
+ release();
+ await jobs.wait(job.id);
+});
diff --git a/apps/linger-installer/src/server/jobs.ts b/apps/linger-installer/src/server/jobs.ts
index adcee093..f803bfc0 100644
--- a/apps/linger-installer/src/server/jobs.ts
+++ b/apps/linger-installer/src/server/jobs.ts
@@ -235,6 +235,9 @@ export class JobManager {
const stage = record.job.stages.find((item) => item.id === value.stage);
if (stage && value.progress)
stage.progress = structuredClone(value.progress);
+ // A step update without a counter ends the counted part, so a finished
+ // download's bytes do not stay on the step.
+ else if (stage && value.kind === "stage") delete stage.progress;
if (stage && value.kind === "stage") {
stage.state = (value.state ?? "running") as typeof stage.state;
stage.message = event.message;
diff --git a/contracts/generated/typescript/src/generated/linger-installer/types.ts b/contracts/generated/typescript/src/generated/linger-installer/types.ts
index 8e190a90..c9fa7fb6 100644
--- a/contracts/generated/typescript/src/generated/linger-installer/types.ts
+++ b/contracts/generated/typescript/src/generated/linger-installer/types.ts
@@ -514,6 +514,10 @@ export interface components {
completed: number;
total?: number;
unit: string;
+ /** @description The current download rate, when the source reports one. */
+ bytesPerSecond?: number;
+ /** @description The counter covers only the file downloading now, not the whole download, so it gives no remaining amount. */
+ partial?: boolean;
};
RuntimeLogin: {
/** @enum {string} */
diff --git a/contracts/openapi/linger-installer/openapi.yaml b/contracts/openapi/linger-installer/openapi.yaml
index b9313514..066cd4d2 100644
--- a/contracts/openapi/linger-installer/openapi.yaml
+++ b/contracts/openapi/linger-installer/openapi.yaml
@@ -880,6 +880,13 @@ components:
type: number
minimum: 0
unit: *a1
+ bytesPerSecond:
+ type: number
+ minimum: 0
+ description: The current download rate, when the source reports one.
+ partial:
+ type: boolean
+ description: The counter covers only the file downloading now, not the whole download, so it gives no remaining amount.
RuntimeLogin:
type: object
additionalProperties: false
diff --git a/packages/local-installation/src/events.ts b/packages/local-installation/src/events.ts
index 347bf7d0..df9ef30f 100644
--- a/packages/local-installation/src/events.ts
+++ b/packages/local-installation/src/events.ts
@@ -11,7 +11,15 @@ export interface InstallerEvent {
stage?: InstallStage;
state?: "running" | "succeeded" | "failed" | "skipped" | "waiting_user";
message: string;
- progress?: { completed: number; total?: number; unit: string };
+ progress?: {
+ completed: number;
+ total?: number;
+ unit: string;
+ // The current download rate, when the source reports one.
+ bytesPerSecond?: number;
+ // Counts only the file downloading now, not the whole download.
+ partial?: boolean;
+ };
}
export interface InstallObserver {
interactive?: boolean;
diff --git a/packages/local-installation/src/local-models.test.ts b/packages/local-installation/src/local-models.test.ts
index c8190571..a823819a 100644
--- a/packages/local-installation/src/local-models.test.ts
+++ b/packages/local-installation/src/local-models.test.ts
@@ -9,7 +9,11 @@ import {
import path from "node:path";
import os from "node:os";
import { afterEach, expect, test, vi } from "vitest";
-import { prepareLocalModels, localModelsEnvironment } from "./local-models.js";
+import {
+ prepareLocalModels,
+ localModelsEnvironment,
+ stackProgress,
+} from "./local-models.js";
import { runProcess } from "./process.js";
import { runLocalmodels } from "./localmodels-tool.js";
import type { Instance } from "./instance.js";
@@ -188,7 +192,7 @@ test("forwards actual split JSONL byte counters but never raw output", async ()
);
expect(f.options.onEvent.mock.calls.flat()).toContainEqual(
expect.objectContaining({
- progress: { completed: 4, total: 10, unit: "bytes" },
+ progress: { completed: 4, total: 10, unit: "bytes", partial: true },
}),
);
expect(JSON.stringify(f.options.onEvent.mock.calls)).not.toContain("hidden");
@@ -298,7 +302,7 @@ test("streams more than the process capture limit during an approved stack apply
).toBeUndefined();
expect(f.options.onEvent.mock.calls.flat()).toContainEqual(
expect.objectContaining({
- progress: { completed: 2, total: 2, unit: "bytes" },
+ progress: { completed: 2, total: 2, unit: "bytes", partial: true },
}),
);
expect(
@@ -608,3 +612,46 @@ test("a stale stored binding with missing approval inputs cannot authorize deplo
});
expect(f.call.mock.calls.some(([, args]) => args[0] === "stack")).toBe(false);
});
+
+test("names what downloads and keeps the tool's counters", () => {
+ const progress = {
+ event: "progress",
+ component: "llm",
+ step: "download",
+ phase: "download",
+ done: 4,
+ total: 10,
+ };
+ // Today's tool counts one file at a time.
+ expect(stackProgress({ ...progress, bytes_per_second: 3 })).toEqual({
+ kind: "stage",
+ stage: "runtime",
+ state: "running",
+ message: "Downloading the local model…",
+ progress: {
+ completed: 4,
+ total: 10,
+ unit: "bytes",
+ bytesPerSecond: 3,
+ partial: true,
+ },
+ });
+ // Whole-component counters, once the tool sends them, replace the file's.
+ expect(
+ stackProgress({ ...progress, component_done: 40, component_total: 100 })
+ ?.progress,
+ ).toEqual({ completed: 40, total: 100, unit: "bytes" });
+ expect(stackProgress({ ...progress, step: "engine" })?.message).toBe(
+ "Downloading the inference engine…",
+ );
+ expect(
+ stackProgress({ ...progress, component: "embedding", phase: "verify" })
+ ?.message,
+ ).toBe("Checking the embedding model…");
+ for (const other of [
+ { ...progress, phase: "loading", done: null, total: null },
+ { ...progress, done: 11 },
+ { ...progress, event: "log" },
+ ])
+ expect(stackProgress(other)).toBeUndefined();
+});
diff --git a/packages/local-installation/src/local-models.ts b/packages/local-installation/src/local-models.ts
index a2e2cdab..f0f3f3ad 100644
--- a/packages/local-installation/src/local-models.ts
+++ b/packages/local-installation/src/local-models.ts
@@ -49,6 +49,68 @@ interface Options {
interface Dependencies {
localmodels?: typeof runLocalmodels;
}
+// What each stack component downloads, as the setup page names it.
+const DOWNLOADS: Record<string, string> = {
+ llm: "the local model",
+ decision: "the decision model",
+ embedding: "the embedding model",
+ rerank: "the reranking model",
+ stt: "the speech recognition model",
+ tts: "the speech model",
+ search: "the search service",
+};
+// A localmodels.stack-progress/v1 event from `stack apply --jsonl`, as the
+// runtime stage's byte counter. The tool counts the file downloading now
+// (done/total); component_done/component_total, when it sends them, count
+// the whole component, so the page can show what remains.
+export function stackProgress(value: unknown): InstallerEvent | undefined {
+ const event = value as Record<string, unknown> | null;
+ const count = (key: string) => {
+ const n = event?.[key];
+ return typeof n === "number" && Number.isSafeInteger(n) && n >= 0
+ ? n
+ : undefined;
+ };
+ const done = count("done"),
+ total = count("total");
+ if (
+ event?.event !== "progress" ||
+ typeof event.component !== "string" ||
+ !/^[a-z][a-z0-9_-]{0,40}$/.test(event.component) ||
+ !(event.phase === "download" || event.phase === "verify") ||
+ done === undefined ||
+ total === undefined ||
+ done > total
+ )
+ return;
+ const wholeDone = count("component_done"),
+ wholeTotal = count("component_total");
+ const whole =
+ wholeDone !== undefined &&
+ wholeTotal !== undefined &&
+ wholeTotal > 0 &&
+ wholeDone <= wholeTotal;
+ const rate = count("bytes_per_second");
+ const what =
+ event.step === "engine"
+ ? "the inference engine"
+ : (DOWNLOADS[event.component] ?? "the local model files");
+ return {
+ kind: "stage",
+ stage: "runtime",
+ state: "running",
+ message: `${event.phase === "download" ? "Downloading" : "Checking"} ${what}…`,
+ progress: {
+ completed: whole ? wholeDone : done,
+ total: whole ? wholeTotal : total,
+ unit: "bytes",
+ ...(rate !== undefined && event.phase === "download"
+ ? { bytesPerSecond: rate }
+ : {}),
+ ...(whole ? {} : { partial: true }),
+ },
+ };
+}
function review(value: unknown): LocalModelsPlanSummary {
const v = value as LocalModelsPlanSummary & { schema?: string };
if (
@@ -227,33 +289,14 @@ export async function prepareLocalModels(
if (newline < 0) break;
const line = buffer.slice(0, newline);
buffer = buffer.slice(newline + 1);
- let event;
+ let event: unknown;
try {
event = JSON.parse(line);
} catch {
continue;
}
- if (
- event?.event === "progress" &&
- typeof event.component === "string" &&
- /^[a-z][a-z0-9_-]{0,40}$/.test(event.component) &&
- ["download", "verify"].includes(event.phase) &&
- Number.isSafeInteger(event.done) &&
- event.done >= 0 &&
- Number.isSafeInteger(event.total) &&
- event.total >= event.done
- )
- options.onEvent({
- kind: "stage",
- stage: "runtime",
- state: "running",
- message: `Local model ${event.component}: ${event.phase}`,
- progress: {
- completed: event.done,
- total: event.total,
- unit: "bytes",
- },
- });
+ const progress = stackProgress(event);
+ if (progress) options.onEvent(progress);
}
},
});