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(local-installation): validate complete native environment round trips
Afloatdf64c74b1167
diff --git a/packages/local-installation/AGENTS.md b/packages/local-installation/AGENTS.mdindex 05d60656..8f13d40c 100644--- a/packages/local-installation/AGENTS.md+++ b/packages/local-installation/AGENTS.md@@ -36,7 +36,7 @@ voice key; without them, or when they fail to prepare, TeamHub getssetting tracks only the tools, so a key change never restarts them throughit. A native process restarts when its generated environment changes.Generated native values preserve quoted paths and literal backslashes by-checking their dotenv representation with the launcher's parser. Multiline,+checking their complete dotenv file with the launcher's parser. Multiline,NUL-containing or otherwise unrepresentable values fail before publishingthe environment file.Every port the installer chooses (`ports.ts`) must be free on bothdiff --git a/packages/local-installation/src/native-source.test.ts b/packages/local-installation/src/native-source.test.tsindex 317ed7a8..fdadb9f2 100644--- a/packages/local-installation/src/native-source.test.ts+++ b/packages/local-installation/src/native-source.test.ts@@ -129,6 +129,46 @@ test("native environment quoting preserves literal Windows backslashes", async (expect(persisted.FIXTURE_PATH).toBe(value);});+test("native environments reject a value that would consume the next key", async () => {+ const f = await fixture();+ const options = { home: f.home, name: "cross-entry-value" };+ const native = await prepareNativeConfiguration(f.repo, options);+ const envFile = path.join(native.instance.root, "native.env");+ const before = await readFile(envFile, "utf8");+ const value = "'`=a\\n#\\";+ // As the last entry this is readable, but writing another quoted entry+ // after it can close its leading quote and absorb the following key.+ const supplied = `CONTROL=kept\nFIXTURE_VALUE=${value}\n`;+ expect(parseEnv(supplied)).toEqual({ CONTROL: "kept", FIXTURE_VALUE: value });+ await writeFile(path.join(f.repo, ".env"), supplied);++ await expect(prepareNativeConfiguration(f.repo, options)).rejects.toThrow(+ "Source environment contains unsupported characters.",+ );+ expect(await readFile(envFile, "utf8")).toBe(before);+});++test.each(["'quoted", '"quoted', "`quoted"])(+ "native environments preserve a representable leading quote in %s",+ async (value) => {+ const f = await fixture();+ const delimiter = value.startsWith("'") ? '"' : "'";+ await writeFile(+ path.join(f.repo, ".env"),+ `FIXTURE_VALUE=${delimiter}${value}${delimiter}\nFOLLOWING=kept\n`,+ );+ const native = await prepareNativeConfiguration(f.repo, {+ home: f.home,+ name: "leading-quote",+ });+ const persisted = parseEnv(+ await readFile(path.join(native.instance.root, "native.env"), "utf8"),+ );+ expect(persisted.FIXTURE_VALUE).toBe(value);+ expect(persisted.FOLLOWING).toBe("kept");+ },+);+test("native environments still reject multiline values without publishing them", async () => {const f = await fixture();await writeFile(path.join(f.repo, ".env"), "FIXTURE_VALUE='line\nbreak'\n");diff --git a/packages/local-installation/src/source-checkout.ts b/packages/local-installation/src/source-checkout.tsindex f24e688e..2681e84a 100644--- a/packages/local-installation/src/source-checkout.ts+++ b/packages/local-installation/src/source-checkout.ts@@ -354,13 +354,17 @@ export async function prepareSourceConfiguration("HOST","LOCAL_ENV_FILE",]);- await atomicPrivate(- envFile,- Object.entries(generated)- .filter(([key]) => !nativeFileOmissions.has(key))- .map(([key, value]) => `${key}=${quote(value)}`)- .join("\n") + "\n",+ const entries = Object.entries(generated).filter(+ ([key]) => !nativeFileOmissions.has(key),);+ const text =+ entries.map(([key, value]) => `${key}=${quote(value)}`).join("\n") + "\n";+ // An unmatched leading quote can consume a later entry, even if the+ // isolated value round-trips. Validate exactly what the launcher reads.+ const parsed = parseEnv(text);+ if (entries.some(([key, value]) => parsed[key] !== value))+ throw new Error("Source environment contains unsupported characters.");+ await atomicPrivate(envFile, text);return { instance, env: generated, warnings };});}