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): unpack this app's source package again when its folder is damaged
Dongdong Chen33d4df4cfab5
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.mdindex 9927db68..2b133f8e 100644--- a/apps/desktop/AGENTS.md+++ b/apps/desktop/AGENTS.md@@ -174,8 +174,9 @@ Gateway and runs Agents. The daemon exits with the app.services on launch with `installer.js --resume`, which also restarts themwhen the instance's `user.env` changed. A source folder removed since, orone the installer no longer accepts as a Linger checkout (such as one the- earlier Simplex app unpacked), is unpacked again from the app's package- first and replaces the recorded one. The record also names the app+ earlier Simplex app unpacked, or this package's own folder with files+ missing since), is unpacked again from the app's package first and+ replaces the recorded one. The record also names the appversion that unpacked the source; when this app brings another sourcepackage (it was installed over an older one), that launch unpacks it andresumes on it, with the "Updating Linger" page instead of the olderdiff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.tsindex 362c8eb0..64059d1b 100644--- a/apps/desktop/src/main/local-server.test.ts+++ b/apps/desktop/src/main/local-server.test.ts@@ -2853,6 +2853,45 @@ describe("LocalServerModule after a restart", () => {await f.host.stop("quit");});+ it("unpacks the source package again when its folder is damaged", async () => {+ const root = tempDirectory();+ const archive = sourceArchive(root);+ const repo = (home: string) =>+ path.join(home, "desktop", "source", archive.sha256.slice(0, 16));+ const f = fixture(+ {+ sourceArchive: {+ url: "https://cdn.example/linger.tar.gz",+ sha256: archive.sha256,+ },+ fetch: (async () => new Response(archive.bytes)) as typeof fetch,+ },+ enrolled,+ (home) => {+ // This app's own folder: the marker is there, package.json is gone.+ mkdirSync(path.join(repo(home), "scripts"), { recursive: true });+ writeFileSync(path.join(repo(home), "scripts/source-native.mjs"), "");+ writeFileSync(+ path.join(home, "desktop", "local-server.json"),+ JSON.stringify({+ home,+ repo: repo(home),+ origin: "http://localhost:3000",+ version: APP_VERSION,+ }),+ );+ },+ );+ await f.host.start();+ await vi.waitFor(() => expect(f.module.status().phase).toBe("ready"));+ const args = installerArgs(f.home);+ expect(args[args.indexOf("--source-repo") + 1]).toBe(repo(f.home));+ expect(+ JSON.parse(readFileSync(path.join(repo(f.home), "package.json"), "utf8")),+ ).toEqual({ name: "linger" });+ await f.host.stop("quit");+ });+it("moves to the source package when the earlier Simplex app unpacked the one in use", async () => {const root = tempDirectory();const archive = sourceArchive(root);diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.tsindex b5d71e4e..c25f30e6 100644--- a/apps/desktop/src/main/local-server.ts+++ b/apps/desktop/src/main/local-server.ts@@ -1590,13 +1590,27 @@ export class LocalServerModule implements Module {archive.sha256.slice(0, 16),);if (await isFile(path.join(directory, SOURCE_MARKER))) {- await this.#timed("teamhub_binaries", () =>- this.#ensureTeamhubBinaries(directory, archive.sha256, signal),- );- await this.#timed("native_runtime", () =>- this.#ensureNativeRuntime(directory, archive.sha256, signal),- );- return directory;+ if (+ await validateSourceRepository(directory).then(+ () => true,+ () => false,+ )+ ) {+ await this.#timed("teamhub_binaries", () =>+ this.#ensureTeamhubBinaries(directory, archive.sha256, signal),+ );+ await this.#timed("native_runtime", () =>+ this.#ensureNativeRuntime(directory, archive.sha256, signal),+ );+ return directory;+ }+ // This package's own folder, damaged since it was unpacked (files+ // removed by hand or by a cleanup): the installer would refuse it, so+ // it is unpacked again in its place.+ this.#ctx?.log.warn("local_server.source_damaged", {+ source: path.basename(directory),+ });+ await removeRetrying(directory);}if ("file" in archive)await this.#extract(archive, directory, SOURCE_MARKER, signal);