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 Unicode paths in Windows PostgreSQL
juemimgcd72b4ed2961fb
diff --git a/packages/local-installation/AGENTS.md b/packages/local-installation/AGENTS.mdindex a147bc3e..94ac2867 100644--- a/packages/local-installation/AGENTS.md+++ b/packages/local-installation/AGENTS.md@@ -97,6 +97,15 @@ never leaves a directory that later attempts treat as initialized. A `postgres-d`PG_VERSION` but no `postmaster.opts` (which only a started server writes)never served a connection, holds no data, and is initialized again.+On Windows the installer stages UTF-8 application manifests beside the bundled+PostgreSQL tools before recording their file hashes. This lets `initdb`+relaunch itself and start `postgres` when the profile path contains characters+outside the system code page. This copy uses the `<archive digest>-utf8`+component directory so older installers can still verify their own cache.+Both copies use the same instance data directory and the same executable path+in the supervisor's configuration hash. A matching live server keeps its+connections during the upgrade. Its next start uses the UTF-8 copy.+The desktop's bundled TeamHub binaries (`teamhub-binaries.ts`) count as currentonly when their files still match the manifest's sizes and hashes. A missingor damaged installed file is copied again from the bundle, so Native can usediff --git a/packages/local-installation/src/native-database.ts b/packages/local-installation/src/native-database.tsindex cfe65708..b106742d 100644--- a/packages/local-installation/src/native-database.ts+++ b/packages/local-installation/src/native-database.ts@@ -51,6 +51,7 @@ export async function windowsElevated(export async function prepareNativeDatabase(options: {instance: Instance;postgresBin: string;+ postgresConfigurationExecutable?: string;env: NodeJS.ProcessEnv;signal: AbortSignal;onOutput: (chunk: string) => void;@@ -149,6 +150,7 @@ export async function prepareNativeDatabase(options: {root: instance.root,name: "postgres",executable: postgresProgram(postgresBin, "postgres"),+ configurationExecutable: options.postgresConfigurationExecutable,args: ["-D",data,diff --git a/packages/local-installation/src/native-dependencies.test.ts b/packages/local-installation/src/native-dependencies.test.tsindex 8a9aabab..cac1f0b4 100644--- a/packages/local-installation/src/native-dependencies.test.ts+++ b/packages/local-installation/src/native-dependencies.test.ts@@ -206,6 +206,46 @@ describe("verified extraction", () => {),).rejects.toThrow(/cache/);});+ it("publishes verified Windows PostgreSQL manifests separately from the original cache", async () => {+ const { home, artifact, fetcher } = await fixture();+ const signal = new AbortController().signal;+ const load = (windowsPostgres: boolean) =>+ acquireNativeArtifact(+ home,+ { ...artifact, windowsPostgres },+ signal,+ undefined,+ fetcher,+ );+ const original = await load(false);+ const prepared = await load(true);+ expect(original).toBe(path.join(home, artifact.digest));+ expect(prepared).toBe(original + "-utf8");++ const tree = JSON.parse(+ await readFile(path.join(prepared, ".simplex-files.json"), "utf8"),+ );+ for (const program of [+ "postgres",+ "initdb",+ "pg_ctl",+ "pg_isready",+ "psql",+ "createdb",+ ]) {+ const name = `bin/${program}.exe.manifest`;+ const manifest = await readFile(path.join(prepared, name), "utf8");+ expect(manifest).toContain(+ '<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>',+ );+ expect(tree[name]).toBe(+ createHash("sha256").update(manifest).digest("hex"),+ );+ }+ expect(await load(true)).toBe(prepared);+ expect(await readdir(path.join(original, "bin"))).toEqual(["tool"]);+ expect(await load(false)).toBe(original);+ });it("checksum failure leaves no promoted component and permits clean retry", async () => {const f = await fixture();await expect(@@ -509,10 +549,12 @@ it("prepares real executable launchers and reuses verified warm dependencies entawait archive("postgres",Object.fromEntries(- ["postgres", "initdb", "pg_ctl", "psql", "createdb"].map((name) => [- `bin/${name}`,- "#!/bin/sh\nprintf 'postgres (PostgreSQL) 17.10\\n'\n",- ]),+ ["postgres", "initdb", "pg_ctl", "pg_isready", "psql", "createdb"].map(+ (name) => [+ `bin/${name}`,+ "#!/bin/sh\nprintf 'postgres (PostgreSQL) 17.10\\n'\n",+ ],+ ),),);const fetcher = vidiff --git a/packages/local-installation/src/native-dependencies.ts b/packages/local-installation/src/native-dependencies.tsindex c4bb51a6..0d469cb6 100644--- a/packages/local-installation/src/native-dependencies.ts+++ b/packages/local-installation/src/native-dependencies.ts@@ -34,6 +34,15 @@ import { validatePublishedServiceSource } from "./published-source.js";import type { InstallerEvent } from "./events.js";import { renameRetrying } from "./fs-retry.js";+const postgresPrograms = [+ "postgres",+ "initdb",+ "pg_ctl",+ "pg_isready",+ "psql",+ "createdb",+] as const;+export const nativeTargets = ["darwin-arm64","linux-x64",@@ -262,6 +271,8 @@ type Artifact = (maxBytes: number;/** Release archives are gzip tarballs unless they say otherwise. */format?: "zip";+ /** Install UTF-8 process manifests beside the Windows PostgreSQL tools. */+ windowsPostgres?: boolean;/** What a bundled archive holds, for its errors. */label?: string;};@@ -364,7 +375,11 @@ export async function acquireNativeArtifact(signal.throwIfAborted();await privateDirectory(base);return withInstanceLock({ root: base } as Instance, async () => {- const directory = path.join(base, artifact.digest);+ // Older installers verify the unmodified archive under its bare digest.+ const directory = path.join(+ base,+ artifact.windowsPostgres ? `${artifact.digest}-utf8` : artifact.digest,+ );const exists = await lstat(directory).catch((error) => {if (error.code === "ENOENT") return;throw error;@@ -453,6 +468,24 @@ export async function acquireNativeArtifact(},});if (archiveError) throw archiveError;+ if (artifact.windowsPostgres) {+ // initdb relaunches itself and starts postgres through narrow Win32 APIs.+ for (const program of postgresPrograms)+ await writeFile(+ path.join(stage, "bin", `${program}.exe.manifest`),+ `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">+ <assemblyIdentity name="Linger.PostgreSQL.${program}" version="1.0.0.0" type="win32"/>+ <application xmlns="urn:schemas-microsoft-com:asm.v3">+ <windowsSettings>+ <activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>+ </windowsSettings>+ </application>+</assembly>+`,+ { flag: "wx" },+ );+ }await writeFile(path.join(stage, ".simplex-files.json"),JSON.stringify(await tree(stage)),@@ -525,6 +558,7 @@ export async function prepareNativeDependencies(options: {}): Promise<{env: NodeJS.ProcessEnv;postgresBin: string;+ postgresConfigurationExecutable?: string;toolchainRoot: string;/** Package registries to install from, in order of preference. */registries: string[];@@ -656,6 +690,7 @@ export async function prepareNativeDependencies(options: {: { url: postgres.url!, mirrors: postgres.mirrors }),algorithm: "sha256",digest: postgres.sha256,+ windowsPostgres: windows,maxBytes: postgres.bytes,},);@@ -695,13 +730,7 @@ export async function prepareNativeDependencies(options: {await rename(temporary, file);await chmod(file, 0o700);}- for (const executable of [- "postgres",- "initdb",- "pg_ctl",- "psql",- "createdb",- ]) {+ for (const executable of postgresPrograms) {const info = await lstat(path.join(pg, "bin", `${executable}${exe}`));if (!info.isFile() ||@@ -795,7 +824,22 @@ export async function prepareNativeDependencies(options: {"A verified private native tool could not execute the required version on this host.",);}- return { env, postgresBin: path.join(pg, "bin"), toolchainRoot, registries };+ return {+ env,+ postgresBin: path.join(pg, "bin"),+ // Keep the service identity of a running server from this exact archive.+ ...(windows && {+ postgresConfigurationExecutable: path.join(+ nativeRoot,+ "components",+ postgres.sha256,+ "bin",+ "postgres.exe",+ ),+ }),+ toolchainRoot,+ registries,+ };}/*** The verified LiveKit server and ffmpeg for this computer, fromdiff --git a/packages/local-installation/src/native-process.test.ts b/packages/local-installation/src/native-process.test.tsindex be406aa7..aa38cfc1 100644--- a/packages/local-installation/src/native-process.test.ts+++ b/packages/local-installation/src/native-process.test.ts@@ -524,6 +524,32 @@ posix.for([false, true])(}},);+test("adopts a running service across executable cache layouts for the same archive", async (context) => {+ const { expect } = context;+ const root = await fixture(context);+ const original = {+ root,+ name: "teamhub" as const,+ executable: process.execPath,+ args: ["-e", "setInterval(()=>{},1000)"],+ cwd: root,+ env: process.env,+ };+ const running = await startNativeProcess(original);+ const upgraded = {+ ...original,+ executable: path.join(root, "new-cache", path.basename(process.execPath)),+ configurationExecutable: original.executable,+ };+ expect(await nativeConfigurationChanged(upgraded)).toBe(false);+ expect((await startNativeProcess(upgraded)).pid).toBe(running.pid);+ expect(+ await nativeConfigurationChanged({+ ...upgraded,+ configurationExecutable: "another-archive",+ }),+ ).toBe(true);+});test("reports a configuration change only for a running recorded process", async (context) => {const { expect } = context;const root = await fixture(context);diff --git a/packages/local-installation/src/native-process.ts b/packages/local-installation/src/native-process.tsindex 98511f93..8e63a850 100644--- a/packages/local-installation/src/native-process.ts+++ b/packages/local-installation/src/native-process.ts@@ -219,13 +219,16 @@ interface NativeConfiguration {executable: string;args: string[];cwd: string;+ /** Stable executable path when two cache layouts run the same binary. */+ configurationExecutable?: string;+ /** Generated configuration the process reads; a change counts as a new configuration. */settings?: string;}function configurationHash(options: NativeConfiguration): string {return createHash("sha256").update(JSON.stringify({- executable: options.executable,+ executable: options.configurationExecutable ?? options.executable,args: options.args,cwd: options.cwd,settings: options.settings,@@ -241,19 +244,16 @@ export async function nativeConfigurationChanged(if (!existing || !(await serving(existing))) return false;return configurationHash(options) !== existing.configuration;}-export async function startNativeProcess(options: {- root: string;- name: NativeService;- executable: string;- args: string[];- cwd: string;- env: NodeJS.ProcessEnv;- signal?: AbortSignal;- redactions?: string[];- /** Generated configuration the process reads; a change counts as a new configuration. */- settings?: string;- restartOnConfigurationChange?: boolean;-}): Promise<NativeProcessState> {+export async function startNativeProcess(+ options: NativeConfiguration & {+ root: string;+ name: NativeService;+ env: NodeJS.ProcessEnv;+ signal?: AbortSignal;+ redactions?: string[];+ restartOnConfigurationChange?: boolean;+ },+): Promise<NativeProcessState> {options.signal?.throwIfAborted();const location = paths(options.root, options.name);const configuration = configurationHash(options);diff --git a/packages/local-installation/src/native-source.ts b/packages/local-installation/src/native-source.tsindex 43f602b1..4b9fc929 100644--- a/packages/local-installation/src/native-source.ts+++ b/packages/local-installation/src/native-source.ts@@ -943,6 +943,8 @@ async function runNativeSource(prepareNativeDatabase({instance: current,postgresBin: tools.postgresBin,+ postgresConfigurationExecutable:+ tools.postgresConfigurationExecutable,env,signal,onOutput: (chunk) => output.write(chunk),