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): say where to install when a data-drive folder is refused
Kilyn9ed0f7548eb3
diff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.tsindex 75f64332..2a4fce87 100644--- a/apps/desktop/src/main/local-server.test.ts+++ b/apps/desktop/src/main/local-server.test.ts@@ -83,6 +83,11 @@ const home = args[args.indexOf("--home") + 1];if (args.includes("--user-keys")) {const changes = JSON.parse(fs.readFileSync(0, "utf8"));fs.writeFileSync(path.join(home, "keys-args.json"), JSON.stringify(args));+ // As the installer reports a folder the ACL program refused.+ if (Object.values(changes).includes("refused")) {+ process.stdout.write(JSON.stringify({ error: "Windows private path validation failed", refusal: { code: "WINDOWS_PRIVATE_PATH_UNSAFE", reason: "UNSAFE_PARENT_ACCESS" } }) + "\n");+ process.exit(1);+ }if (Object.values(changes).includes("bad")) {process.stdout.write(JSON.stringify({ error: "COMPOSIO_API_KEY is not a valid key" }) + "\n");process.exit(1);@@ -175,6 +180,12 @@ if (args.includes("--resume")) {process.stdout.write("noise\n" + JSON.stringify({ code, ...outcome, ...(runtime ? { runtime } : {}) }) + "\n");process.exit(code);}+if (fs.existsSync(path.join(home, "start-refused"))) {+ // As the installer stops when the ACL program refuses its home.+ process.stdout.write(JSON.stringify({ startFailure: { code: "WINDOWS_PRIVATE_PATH_UNSAFE", reason: "UNSAFE_OWNER" } }) + "\n");+ process.stderr.write("Installer could not start (WINDOWS_PRIVATE_PATH_UNSAFE): Windows private path validation failed\n");+ process.exit(1);+}const origin = "http://127.0.0.1:4321";fs.writeFileSync(path.join(home, "installer", "launch.html"),@@ -2292,6 +2303,40 @@ describe("LocalServerModule", () => {expect(f.signIn).not.toHaveBeenCalled();await f.host.stop("quit");});++ it("keeps the installer's refusal of a folder with the failure it caused", async () => {+ const f = fixture(withCheckout, {}, checkout);+ await f.host.start();+ try {+ writeFileSync(path.join(f.home, "start-refused"), "");+ await expect(f.module.begin()).rejects.toThrow(+ "The installer stopped while starting. Installer could not start (WINDOWS_PRIVATE_PATH_UNSAFE): Windows private path validation failed",+ );+ expect(f.module.status()).toMatchObject({+ phase: "failed",+ refusal: {+ code: "WINDOWS_PRIVATE_PATH_UNSAFE",+ reason: "UNSAFE_OWNER",+ },+ });+ rmSync(path.join(f.home, "start-refused"));+ await expect(+ f.module.begin({ runtime: "claude", keys: { composio: "refused" } }),+ ).rejects.toThrow("Keys could not be saved");+ expect(f.module.status().refusal).toEqual({+ code: "WINDOWS_PRIVATE_PATH_UNSAFE",+ reason: "UNSAFE_PARENT_ACCESS",+ });+ // Another failure does not carry it on.+ await expect(+ f.module.begin({ runtime: "claude", keys: { composio: "bad" } }),+ ).rejects.toThrow("COMPOSIO_API_KEY is not a valid key");+ expect(f.module.status().phase).toBe("failed");+ expect(f.module.status().refusal).toBeUndefined();+ } finally {+ await f.host.stop("quit");+ }+ });});describe("LocalServerModule install location", () => {diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.tsindex ff55bd37..d2472b8d 100644--- a/apps/desktop/src/main/local-server.ts+++ b/apps/desktop/src/main/local-server.ts@@ -58,6 +58,10 @@ import {TEAMHUB_BINARY_DIRECTORY,} from "@linger/local-installation/teamhub-binaries";import { redact } from "@linger/local-installation/redaction";+import {+ windowsPrivateRefusal,+ type WindowsPrivateRefusal,+} from "@linger/local-installation/windows-private";import { adoptUserEnvironment } from "@linger/local-installation/user-environment";import {@@ -295,6 +299,9 @@ export interface LocalServerStatus {// Where this installation moved the data of the earlier Simplex app,// which it could not upgrade.readonly legacyBackup?: string;+ // While failed because the installer refused a folder as not private+ // (Windows): its code and reason.+ readonly refusal?: WindowsPrivateRefusal;}export interface LocalServerOptions {@@ -439,6 +446,7 @@ export class LocalServerModule implements Module {#home: string;#location: string | undefined;#locationError: string | undefined;+ #refusal: WindowsPrivateRefusal | undefined;#node: Promise<string> | undefined;#abort = new AbortController();#offRetry: (() => void) | undefined;@@ -635,6 +643,7 @@ export class LocalServerModule implements Module {...(this.#byokCheck ? { byokCheck: this.#byokCheck } : {}),...(this.#byokModels ? { byokModels: this.#byokModels } : {}),...(this.#legacyBackup ? { legacyBackup: this.#legacyBackup } : {}),+ ...(this.#refusal ? { refusal: this.#refusal } : {}),};}@@ -1228,7 +1237,11 @@ export class LocalServerModule implements Module {step: this.#step,error: message,});- this.#set("failed", message);+ this.#set(+ "failed",+ message,+ windowsPrivateRefusal((error as { refusal?: unknown } | null)?.refusal),+ );throw error;}}@@ -1534,7 +1547,12 @@ export class LocalServerModule implements Module {);}- #set(phase: LocalServerPhase, message: string): void {+ // A refusal stays only with the failure it caused.+ #set(+ phase: LocalServerPhase,+ message: string,+ refusal?: WindowsPrivateRefusal,+ ): void {// A failure stays on the step it happened in.if (phase !== "installing" && phase !== "ready" && phase !== "failed") {this.#progress = 0;@@ -1544,6 +1562,7 @@ export class LocalServerModule implements Module {if (phase !== "installing") this.#transfer = undefined;this.#phase = phase;this.#message = message;+ this.#refusal = phase === "failed" ? refusal : undefined;this.#ctx?.bus.emit("local-server.changed");}@@ -2194,17 +2213,20 @@ export class LocalServerModule implements Module {child.once("close", () => resolve(text));child.stdin.end(JSON.stringify(installerKeyChanges(changes)));});- let outcome: { saved?: unknown; error?: unknown } = {};+ let outcome: { saved?: unknown; error?: unknown; refusal?: unknown } = {};try {outcome = JSON.parse(output.trim().split("\n").at(-1) ?? "") as never;} catch {// Reported below.}if (!Array.isArray(outcome.saved))- throw new Error(- typeof outcome.error === "string"- ? `Keys could not be saved: ${outcome.error}`- : "Keys could not be saved",+ throw Object.assign(+ new Error(+ typeof outcome.error === "string"+ ? `Keys could not be saved: ${outcome.error}`+ : "Keys could not be saved",+ ),+ { refusal: windowsPrivateRefusal(outcome.refusal) },);this.#ctx?.log.info("local_server.keys_saved", { saved: outcome.saved });this.#ctx?.bus.emit("local-server.changed");@@ -2252,7 +2274,11 @@ export class LocalServerModule implements Module {let output = "";const fail = (message: string) => {child.stdout.removeAllListeners("data");- reject(new Error(message));+ reject(+ Object.assign(new Error(message), {+ refusal: startRefusal(output),+ }),+ );};child.stdout.on("data", (chunk: Buffer) => {output += chunk.toString("utf8");@@ -3398,6 +3424,20 @@ const isByokProtocol = (value: unknown): value is SetupByokProtocol =>value === "openai-responses" ||value === "anthropic";+// The refusal the installer names in its startFailure line on stdout when+// it could not start (startFailureLine in apps/linger-installer).+const startRefusal = (output: string): WindowsPrivateRefusal | undefined => {+ for (const line of output.split("\n")) {+ if (!line.startsWith('{"startFailure"')) continue;+ try {+ const parsed = JSON.parse(line) as { startFailure?: unknown };+ return windowsPrivateRefusal(parsed.startFailure);+ } catch {+ return undefined;+ }+ }+ return undefined;+};// The installer's own words when it failed with { ok: false, message }:// localmodels names the address and HTTP status there.const byokFailure = (out: Record<string, unknown>, fallback: string): string =>diff --git a/apps/desktop/src/main/setup-window.ts b/apps/desktop/src/main/setup-window.tsindex d60b640a..32858d2b 100644--- a/apps/desktop/src/main/setup-window.ts+++ b/apps/desktop/src/main/setup-window.ts@@ -464,6 +464,7 @@ const localServerState = (byokCheck,byokModels,legacyBackup,+ refusal,} = local.status();const home = os.homedir();const shown = (folder: string) =>@@ -489,6 +490,7 @@ const localServerState = (...(byokCheck ? { byokCheck } : {}),...(byokModels ? { byokModels } : {}),...(legacyBackup ? { legacyBackup: shown(legacyBackup) } : {}),+ ...(refusal ? { refusal } : {}),...(account ? { account } : {}),};};diff --git a/apps/desktop/src/shared/setup.ts b/apps/desktop/src/shared/setup.tsindex c569b81c..b0cfd6d3 100644--- a/apps/desktop/src/shared/setup.ts+++ b/apps/desktop/src/shared/setup.ts@@ -6,6 +6,7 @@ import type {SetupChoice,SetupMemory,} from "@linger/local-installation/setup-plan";+import type { WindowsPrivateRefusal } from "@linger/local-installation/windows-private";export interface SetupFolder {readonly grantId: string;@@ -58,6 +59,9 @@ export interface SetupLocalServer {// Where the installation moved the earlier Simplex app's data it could// not upgrade (~ for the home folder).readonly legacyBackup?: string;+ // While failed because the installer refused a folder as not private+ // (Windows): its code and reason, for the page to say what to do.+ readonly refusal?: WindowsPrivateRefusal;}export type SetupByokProtocol =diff --git a/apps/desktop/src/shell/setup-page.test.ts b/apps/desktop/src/shell/setup-page.test.tsindex fc52f257..82f6c179 100644--- a/apps/desktop/src/shell/setup-page.test.ts+++ b/apps/desktop/src/shell/setup-page.test.ts@@ -977,3 +977,60 @@ describe("setup page Send Diagnostics", () => {expect($("send-close").textContent).toBe("Close");});});++describe("setup page refused install location", () => {+ beforeEach(() => {+ Element.prototype.scrollIntoView = () => {};+ });++ const message = (folder: string) =>+ `Windows private path validation failed: ${folder} is inside a folder other accounts on this computer can rename or replace. Use a current-user owned local directory without links or shared access.`;+ const failed = (+ location: string,+ reason?: NonNullable<SetupState["localServer"]["refusal"]>["reason"],+ ): SetupState => {+ const base = state("failed");+ return {+ ...base,+ platform: "win32",+ localServer: {+ ...base.localServer,+ message: message(location),+ location: { path: location, custom: true },+ ...(reason+ ? { refusal: { code: "WINDOWS_PRIVATE_PATH_UNSAFE", reason } }+ : {}),+ },+ };+ };++ const usual = "Your data is kept. Fix the problem and try again.";++ it("says where to install when a nested folder on a drive is refused", async () => {+ const folder = "D:\\Software\\Linger";+ const { push } = await openPage(failed(folder, "UNSAFE_PARENT_ACCESS"));+ expect($("installing-error").textContent).toBe(message(folder));+ expect($("installing-plan").textContent).toBe(+ "Go back and set the install location to the drive itself (Linger installs into D:\\Linger) or an empty folder directly on the drive.",+ );+ // The hint leaves with the failure.+ push(state("installing"));+ expect($("installing-plan").textContent).toBe(+ "This takes a few minutes. You can keep working.",+ );+ });++ it("gives no hint the person has already followed", async () => {+ // Directly on the drive, the drive's own permissions are what refuse it.+ await openPage(failed("E:\\Linger", "UNSAFE_PARENT_ACCESS"));+ expect($("installing-plan").textContent).toBe(usual);+ });++ it("keeps the hint to this refusal, known by its code", async () => {+ await openPage(failed("D:\\Software\\Linger", "UNSAFE_OWNER"));+ expect($("installing-plan").textContent).toBe(usual);+ // The words alone do not bring the hint.+ await openPage(failed("D:\\Software\\Linger"));+ expect($("installing-plan").textContent).toBe(usual);+ });+});diff --git a/apps/desktop/src/shell/setup.html b/apps/desktop/src/shell/setup.htmlindex cffc0645..ff71e8e5 100644--- a/apps/desktop/src/shell/setup.html+++ b/apps/desktop/src/shell/setup.html@@ -2503,6 +2503,22 @@value.length <= 46? value: value.slice(0, 18) + "…" + value.slice(-27);+ // Where to install instead, when the installer refused the location+ // because another account could rename a folder on the way to it; the+ // message, shown below, says why. A folder directly on the drive is+ // refused for the drive's own permissions, which choosing the drive+ // again would not change, so that case gets no hint.+ const locationHint = (local) => {+ const [, drive] =+ /^([A-Za-z]:\\)[^\\]+\\[^\\]/.exec(local.location.path) ?? [];+ return drive &&+ local.refusal?.code === "WINDOWS_PRIVATE_PATH_UNSAFE" &&+ local.refusal.reason === "UNSAFE_PARENT_ACCESS"+ ? "Go back and set the install location to the drive itself (Linger installs into " ++ drive ++ "Linger) or an empty folder directly on the drive."+ : "";+ };// Quick Install installs what the localmodels tool recommends for this// computer once it has checked; until then (or when it cannot check)// the installer picks. The tool's local-models pick runs through Pi,@@ -3707,7 +3723,8 @@? "Starting Linger": "Installing Linger";$("installing-plan").textContent = failed- ? "Your data is kept. Fix the problem and try again."+ ? locationHint(local) ||+ "Your data is kept. Fix the problem and try again.": "This takes a few minutes. You can keep working.";const section = document.querySelector('[data-step="installing"]');const steps = ALL_STEPS.filter(([id]) => local.steps.includes(id));diff --git a/apps/linger-installer/src/main.test.ts b/apps/linger-installer/src/main.test.tsindex b1fe3a21..0a970f68 100644--- a/apps/linger-installer/src/main.test.ts+++ b/apps/linger-installer/src/main.test.ts@@ -93,6 +93,31 @@ it("reports the real start failure and points at permissions only for access err);});+// A folder the ACL program refused, as windowsPrivatePath throws it.+const refused = () =>+ Object.assign(+ new Error(+ "Windows private path validation failed: D:\\Apps\\Linger is inside a folder.",+ ),+ {+ code: "WINDOWS_PRIVATE_PATH_UNSAFE",+ reason: "UNSAFE_PARENT_ACCESS",+ path: "D:\\Apps\\Linger",+ },+ );++it("tells the desktop client by code why a refused folder stopped the start", async () => {+ const { startFailureLine } = await import("./main.js");+ expect(startFailureLine(refused())).toBe(+ '{"startFailure":{"code":"WINDOWS_PRIVATE_PATH_UNSAFE","reason":"UNSAFE_PARENT_ACCESS"}}\n',+ );+ expect(+ startFailureLine(+ Object.assign(new Error("busy"), { code: "INSTALLER_BUSY" }),+ ),+ ).toBeUndefined();+});+it("keeps every line of a start failure", async () => {const { startFailure } = await import("./main.js");expect(@@ -232,3 +257,28 @@ it("does not migrate legacy installations during inspection", async () => {vi.resetModules();}});++it("tells the desktop client by code why a refused folder kept the keys unsaved", async () => {+ vi.resetModules();+ vi.doMock("@linger/local-installation/user-environment", () => ({+ updateUserKeys: () => Promise.reject(refused()),+ }));+ try {+ const { saveUserKeys } = await import("./main.js");+ expect(+ await saveUserKeys(+ { home: path.join(os.tmpdir(), "linger-refused"), instanceName: "d" },+ JSON.stringify({ XAI_API_KEY: "xai-1" }),+ ),+ ).toEqual({+ error: refused().message,+ refusal: {+ code: "WINDOWS_PRIVATE_PATH_UNSAFE",+ reason: "UNSAFE_PARENT_ACCESS",+ },+ });+ } finally {+ vi.doUnmock("@linger/local-installation/user-environment");+ vi.resetModules();+ }+});diff --git a/apps/linger-installer/src/main.ts b/apps/linger-installer/src/main.tsindex c749bd17..1921b109 100644--- a/apps/linger-installer/src/main.ts+++ b/apps/linger-installer/src/main.ts@@ -1,5 +1,9 @@import path from "node:path";import { lingerHome } from "@linger/local-installation/home";+import {+ windowsPrivateRefusal,+ type WindowsPrivateRefusal,+} from "@linger/local-installation/windows-private";import type { LegacyInstanceSkipped } from "@linger/local-installation/legacy-migration";import type { RuntimeDescriptor } from "@linger/local-installation/managed-runtimes";import { fileURLToPath } from "node:url";@@ -131,6 +135,17 @@ const failedToStart = (error: unknown) => {process.stderr.write(`${startFailure(error)}\n`);process.exitCode = 1;};+// The line the desktop client reads on stdout when the installer manager+// could not start, so it acts on the cause by code, not by the words above.+export function startFailureLine(error: unknown): string | undefined {+ const refusal = windowsPrivateRefusal(error);+ return refusal ? `${JSON.stringify({ startFailure: refusal })}\n` : undefined;+}+const serveFailed = (error: unknown) => {+ const line = startFailureLine(error);+ if (line) process.stdout.write(line);+ failedToStart(error);+};async function resume(options: ReturnType<typeof parseInstallerArguments>) {// Headless restart for the desktop client: progress on stderr, the outcome// as one JSON line on stdout.@@ -222,7 +237,9 @@ async function inspect(options: ReturnType<typeof parseInstallerArguments>) {export async function saveUserKeys(options: { home: string; instanceName?: string },input: string,-): Promise<{ saved: string[] } | { error: string }> {+): Promise<+ { saved: string[] } | { error: string; refusal?: WindowsPrivateRefusal }+> {const [{ instanceRoot }, { updateUserKeys }] = await Promise.all([import("@linger/local-installation/instance"),import("@linger/local-installation/user-environment"),@@ -240,8 +257,11 @@ export async function saveUserKeys();return { saved };} catch (error) {+ // The desktop client acts on a refused folder by its code and reason.+ const refusal = windowsPrivateRefusal(error);return {error: error instanceof Error ? error.message : "Cannot save keys",+ ...(refusal ? { refusal } : {}),};}}@@ -446,5 +466,5 @@ if (await byokEndpointCommand(options, options.byokCommand);else if (options?.inspect) await inspect(options);else if (options?.resume) await resume(options);- else if (options) await serve(options).catch(failedToStart);+ else if (options) await serve(options).catch(serveFailed);}diff --git a/packages/local-installation/AGENTS.md b/packages/local-installation/AGENTS.mdindex 63df2675..b769c378 100644--- a/packages/local-installation/AGENTS.md+++ b/packages/local-installation/AGENTS.md@@ -19,7 +19,11 @@ ancestor counts as well, because its holder can rename that folder, except ona volume root, which can be neither renamed nor removed. A folder directly ona data drive with the stock root ACL therefore passes, and a folder nested inone that inherits Modify for Authenticated Users does not. The Daemon's-`privatefs` treats the volume root the same way.+`privatefs` treats the volume root the same way. A refusal leaves the+installer as its code and reason (`windowsPrivateRefusal`), never as its+words: in the `startFailure` line on stdout when the installer manager cannot+start, and in the `--user-keys` outcome. The Desktop setup page branches on+`UNSAFE_PARENT_ACCESS` to say where to install instead.`atomicPrivate` closes and removes its temporary file on failed writes orsyncs as well as failed publication. A failed replacement keeps the previousdiff --git a/packages/local-installation/src/windows-private.test.ts b/packages/local-installation/src/windows-private.test.tsindex b7b3f9fe..395ea30d 100644--- a/packages/local-installation/src/windows-private.test.ts+++ b/packages/local-installation/src/windows-private.test.ts@@ -2,6 +2,8 @@ import path from "node:path";import { expect, it, vi } from "vitest";import {windowsPrivatePath,+ windowsPrivateRefusal,+ WINDOWS_PRIVATE_PATH_UNSAFE,WINDOWS_PRIVATE_SCRIPT,} from "./windows-private.js";it("sends paths through stdin and runs a fixed encoded ACL program", async () => {@@ -80,3 +82,34 @@ it("ignores inherit-only ACEs only for effective ancestor permissions", () => {expect(target).not.toContain("PropagationFlags");expect(target).toContain("SHARED_ACCESS");});+it("hands on the code and reason of a refusal, and nothing else", async () => {+ const run = vi.fn().mockResolvedValue({+ code: 1,+ stdout: "UNSAFE_PARENT_ACCESS",+ stderr: "",+ });+ const error: unknown = await windowsPrivatePath(+ "D:\\Apps\\Linger",+ "directory",+ true,+ run,+ ).catch((error: unknown) => error);+ const refusal = {+ code: WINDOWS_PRIVATE_PATH_UNSAFE,+ reason: "UNSAFE_PARENT_ACCESS",+ };+ expect(windowsPrivateRefusal(error)).toEqual(refusal);+ // The copy another process receives as JSON reads the same.+ expect(windowsPrivateRefusal(JSON.parse(JSON.stringify(refusal)))).toEqual(+ refusal,+ );+ for (const other of [+ undefined,+ "UNSAFE_PARENT_ACCESS",+ new Error("is inside a folder"),+ { code: "EACCES", reason: "UNSAFE_PARENT_ACCESS" },+ { code: WINDOWS_PRIVATE_PATH_UNSAFE, reason: "SOMETHING_ELSE" },+ { code: WINDOWS_PRIVATE_PATH_UNSAFE, reason: "toString" },+ ])+ expect(windowsPrivateRefusal(other)).toBeUndefined();+});diff --git a/packages/local-installation/src/windows-private.ts b/packages/local-installation/src/windows-private.tsindex 61805c00..e8634280 100644--- a/packages/local-installation/src/windows-private.ts+++ b/packages/local-installation/src/windows-private.ts@@ -168,3 +168,26 @@ const WINDOWS_PRIVATE_REASONS = {UNCHECKED: "could not be checked",} as const;export type WindowsPrivateReason = keyof typeof WINDOWS_PRIVATE_REASONS;+/** The code and reason of a windowsPrivatePath refusal. */+export interface WindowsPrivateRefusal {+ readonly code: typeof WINDOWS_PRIVATE_PATH_UNSAFE;+ readonly reason: WindowsPrivateReason;+}+/**+ * The code and reason of a refusal from windowsPrivatePath, from the error+ * itself or from a copy of the two passed between processes; undefined for+ * anything else.+ */+export function windowsPrivateRefusal(+ value: unknown,+): WindowsPrivateRefusal | undefined {+ const { code, reason } = (value ?? {}) as {+ code?: unknown;+ reason?: unknown;+ };+ return code === WINDOWS_PRIVATE_PATH_UNSAFE &&+ typeof reason === "string" &&+ Object.hasOwn(WINDOWS_PRIVATE_REASONS, reason)+ ? { code, reason: reason as WindowsPrivateReason }+ : undefined;+}