Skip to content
Open
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
3 changes: 2 additions & 1 deletion apps/desktop/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ Gateway and runs Agents. The daemon exits with the app.
[Packaging Details](../../docs/desktop-release.md#packaging-details) for
where the minimum comes from.
Quick Install installs the `recommendation` of the localmodels setup
report (`installer.js --inspect`, run once as the setup window opens):
report (`installer.js --inspect`, run for the selected install location
as the setup window opens and again when that location changes):
`local-models` is the planned model served by Pi, shown with the model,
GPU, memory and download (the card's memory is the whole stack's, so
"with its services"); otherwise the named runtime, with why there is no
Expand Down
63 changes: 63 additions & 0 deletions apps/desktop/src/main/local-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,69 @@ describe("LocalServerModule", () => {
});

describe("LocalServerModule install location", () => {
it("checks the folder selected before the first model check", async () => {
const f = fixture({ checkout: "/src" });
const picked = path.join(f.root, "models");
await f.host.start();
try {
await f.module.chooseLocation(picked);
f.module.inspect();
await vi.waitFor(() =>
expect(f.module.status().localModels.state).toBe("checked"),
);
expect(installerArgs(picked)).toEqual(["--home", picked, "--inspect"]);
expect(existsSync(path.join(f.home, "installer", "args.json"))).toBe(
false,
);
} finally {
await f.host.stop("quit");
}
});

it.each([false, true])(
"rechecks the selected folder when an earlier check finishes (failed: %s)",
async (failed) => {
const f = fixture({ checkout: "/src" });
const picked = path.join(f.root, "models");
writeFileSync(path.join(f.home, "tool-download"), "");
if (failed) writeFileSync(path.join(f.home, "check-fails"), "");
await f.host.start();
try {
f.module.inspect();
await vi.waitFor(() =>
expect(installerArgs(f.home)).toContain("--inspect"),
);
await f.module.chooseLocation(picked);
writeFileSync(path.join(f.home, "tool-ready"), "");
await vi.waitFor(() =>
expect(installerArgs(picked)).toEqual([
"--home",
picked,
"--inspect",
]),
);
await vi.waitFor(() =>
expect(f.module.status().localModels).toMatchObject({
state: "checked",
eligible: true,
}),
);
rmSync(path.join(f.home, "check-fails"), { force: true });
writeFileSync(path.join(f.home, "small-computer"), "");
await f.module.chooseLocation(null);
await vi.waitFor(() =>
expect(f.module.status().localModels).toMatchObject({
state: "checked",
eligible: false,
}),
);
} finally {
writeFileSync(path.join(f.home, "tool-ready"), "");
await f.host.stop("quit");
}
},
);

it("installs into the folder picked on the setup page", async () => {
const archive = sourceArchive(tempDirectory());
const file = path.join(tempDirectory(), "linger.tar.gz");
Expand Down
27 changes: 19 additions & 8 deletions apps/desktop/src/main/local-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ export class LocalServerModule implements Module {
// goes back to the default.
async chooseLocation(picked: string | null): Promise<void> {
if (this.#running) return;
const previous = this.#location;
if (picked === null) {
this.#location = undefined;
this.#locationError = undefined;
Expand All @@ -639,6 +640,8 @@ export class LocalServerModule implements Module {
if (!this.#locationError)
this.#location = home === this.#home ? undefined : home;
}
if (previous !== this.#location && this.#check.state !== "unchecked")
this.recheck();
this.#ctx?.bus.emit("local-server.changed");
}

Expand All @@ -657,7 +660,8 @@ 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, (download) => {
const home = this.#location ?? this.#home;
void this.#inspect(home, signal, (download) => {
if (this.#check.state !== "checking") return;
this.#check = { state: "checking", download };
this.#ctx?.bus.emit("local-server.changed");
Expand All @@ -675,20 +679,26 @@ export class LocalServerModule implements Module {
: {}),
...(reasonLog.length ? { reasons: reasonLog } : {}),
});
this.#check = check;
return check;
},
(error: unknown) => {
this.#ctx?.log.warn("local_server.inspect_failed", {
ms: Date.now() - started,
error: error instanceof Error ? error.message : String(error),
});
this.#check = { state: "unavailable" };
return { state: "unavailable" } as const;
},
)
.then(() => {
.then((check) => {
if (signal.aborted) return;
if (home !== (this.#location ?? this.#home)) {
this.#check = { state: "unchecked" };
this.inspect();
return;
}
this.#check = check;
this.#ctx?.bus.emit("local-server.changed");
if (!signal.aborted)
void this.#ensureNode(signal).catch(() => undefined);
void this.#ensureNode(signal).catch(() => undefined);
});
}

Expand Down Expand Up @@ -773,6 +783,7 @@ export class LocalServerModule implements Module {
}

async #inspect(
home: string,
signal: AbortSignal,
onDownload: (download: Transfer) => void,
): Promise<{
Expand All @@ -785,14 +796,14 @@ export class LocalServerModule implements Module {
const output = await new Promise<string>((resolve, reject) => {
const child = spawn(
process.execPath,
[this.#installerScript(), "--home", this.#home, "--inspect"],
[this.#installerScript(), "--home", home, "--inspect"],
{
stdio: ["ignore", "pipe", "pipe"],
windowsHide: true,
env: {
...process.env,
ELECTRON_RUN_AS_NODE: "1",
LINGER_HOME: this.#home,
LINGER_HOME: home,
},
signal,
},
Expand Down