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): preserve split UTF-8 process output
Afloat481ca4c5c1ec
diff --git a/packages/local-installation/AGENTS.md b/packages/local-installation/AGENTS.mdindex 802af587..6fe5929d 100644--- a/packages/local-installation/AGENTS.md+++ b/packages/local-installation/AGENTS.md@@ -136,6 +136,9 @@ that check and the quit-time stop share one lock per home(`withLocalModelsLock`); the check waits up to 180 s for it, past the stop's150 s hard exit, then asks to try again.+`runProcess` decodes stdout and stderr as separate UTF-8 streams before+capture and output callbacks, preserving characters split across pipe reads.+Each native service runs under a detached supervisor(`native-process-worker.mjs`) whose record holds its PID, birth and anunguessable lease. POSIX finds the service's processes by process group anddiff --git a/packages/local-installation/src/process.test.ts b/packages/local-installation/src/process.test.tsindex 5fede375..3712c4d1 100644--- a/packages/local-installation/src/process.test.ts+++ b/packages/local-installation/src/process.test.ts@@ -1,4 +1,5 @@import { expect, it } from "vitest";+import { PassThrough } from "node:stream";import { runProcess } from "./process.js";it("executes argument arrays literally and preserves JSON output", async () => {const value = "$(touch /tmp/never-linger); a b";@@ -10,6 +11,42 @@ it("executes argument arrays literally and preserves JSON output", async () => {expect(JSON.parse(result.stdout)).toEqual([value]);expect(result.code).toBe(0);});+it.each(["stdout", "stderr"] as const)(+ "preserves a UTF-8 character split between %s chunks",+ async (stream) => {+ const input = new PassThrough();+ const output: string[] = [];+ let continued = false;+ const result = await runProcess(+ process.execPath,+ [+ "-e",+ `const stream = process[process.argv[1]];+const bytes = Buffer.from(JSON.stringify({path: 'file-\\u2603.txt'}));+const split = bytes.indexOf(0xe2) + 1;+process.stdin.once('data', () => stream.write(bytes.subarray(split)));+stream.write(bytes.subarray(0, split));`,+ stream,+ ],+ {+ inputStream: input,+ timeoutMs: 2_000,+ onOutput: (value) => {+ output.push(value);+ if (!continued) {+ continued = true;+ // The child sends the remaining bytes only after this chunk arrived.+ input.end("continue");+ }+ },+ },+ );+ expect(result.code).toBe(0);+ expect(JSON.parse(result[stream])).toEqual({ path: "file-\u2603.txt" });+ expect(output.join("")).toBe(result[stream]);+ expect(result[stream === "stdout" ? "stderr" : "stdout"]).toBe("");+ },+);it("reports nonzero exit without exposing argv in errors", async () => {expect((await runProcess(process.execPath, ["-e", "process.exit(7)"])).code,diff --git a/packages/local-installation/src/process.ts b/packages/local-installation/src/process.tsindex f14d3b1f..09901325 100644--- a/packages/local-installation/src/process.ts+++ b/packages/local-installation/src/process.ts@@ -118,8 +118,7 @@ export async function runProcess(options.timeoutMs,): undefined;- const output = (chunk: Buffer, stream: "stdout" | "stderr") => {- const value = chunk.toString();+ const output = (value: string, stream: "stdout" | "stderr") => {if (options.capture !== false &&stdout.length + stderr.length + value.length > 2_000_000@@ -133,8 +132,12 @@ export async function runProcess(}options.onOutput?.(value);};- child.stdout!.on("data", (chunk: Buffer) => output(chunk, "stdout"));- child.stderr!.on("data", (chunk: Buffer) => output(chunk, "stderr"));+ child+ .stdout!.setEncoding("utf8")+ .on("data", (value: string) => output(value, "stdout"));+ child+ .stderr!.setEncoding("utf8")+ .on("data", (value: string) => output(value, "stderr"));child.once("error", () => {failure = new Error("Command executable unavailable");});