A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.
TypeScript
fix(daemon): give the engine a private TMPDIR when none is set
Alan Buscagliaea8b37a6ce64
diff --git a/packages/daemon/src/isolation.ts b/packages/daemon/src/isolation.tsindex c3da26c..ee03267 100644--- a/packages/daemon/src/isolation.ts+++ b/packages/daemon/src/isolation.ts@@ -62,6 +62,10 @@ export function ensureMemoryProject(workspace: string): void {* engine's home, on port 7438 (`GENTLE_DOT_ENGRAM_PORT` overrides it).* Subagents are off (`GENTLE_PI_AGENTS=0`) until S25.*+ * Without a `TMPDIR` (the installed app's launch on Linux), the engine gets a+ * private one under its home: it caches compiled extensions in the temporary+ * folder, and a shared `/tmp` would let another local user plant that cache.+ ** An installed app (`GENTLE_DOT_RUNTIME`) also names the Engram binary* (`ENGRAM_BIN`, see `resolveEngramBin`), since its PATH has no user folders.*/@@ -78,6 +82,10 @@ export function isolatedAgentEnv(base: NodeJS.ProcessEnv, dataDir: string): NodeXDG_STATE_HOME: join(home, ".local", "state"),};for (const key of INHERITED_HOMES) delete env[key];+ if (!base.TMPDIR) {+ env.TMPDIR = join(home, ".cache", "tmp");+ ensurePrivateDir(env.TMPDIR);+ }const bin = bundledBinDir(base);if (bin) {const rest = (base.PATH ?? "").split(delimiter).filter((part) => part && part !== bin);diff --git a/packages/daemon/test/isolation.test.ts b/packages/daemon/test/isolation.test.tsindex 23ad12b..10b6547 100644--- a/packages/daemon/test/isolation.test.ts+++ b/packages/daemon/test/isolation.test.ts@@ -1,4 +1,12 @@-import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";+import {+ existsSync,+ mkdirSync,+ readdirSync,+ readFileSync,+ realpathSync,+ statSync,+ writeFileSync,+} from "node:fs";import { join } from "node:path";import { afterEach, describe, expect, it } from "vitest";import { type DotDaemon, startDaemon } from "../src/daemon.ts";@@ -86,6 +94,21 @@ describe("isolatedAgentEnv subagents", () => {});});+describe("isolatedAgentEnv temporary folder", () => {+ it("gives the engine a private TMPDIR when none is set, so its caches never land in a shared /tmp", () => {+ const dataDir = tempDir();+ const env = isolatedAgentEnv({ HOME: tempDir() }, dataDir);+ expect(env.TMPDIR).toBe(join(dataDir, "home", ".cache", "tmp"));+ expect(statSync(env.TMPDIR ?? "").mode & 0o777).toBe(0o700);+ });++ it("keeps the user's own TMPDIR", () => {+ expect(isolatedAgentEnv({ HOME: tempDir(), TMPDIR: "/var/tmp/me" }, tempDir()).TMPDIR).toBe(+ "/var/tmp/me",+ );+ });+});+describe("ensureMemoryProject", () => {it("names the workspace's memory project gentle-dot, replacing any other name", () => {const workspace = tempDir();