Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Keep MausBot's Codex chats out of the person's Codex and ChatGPT history
Bugfixer 2c26ffe24224b
diff --git a/server/drivers/codex-shared-home.test.ts b/server/drivers/codex-shared-home.test.tsindex 4eb926242e..4cae57ee51 100644--- a/server/drivers/codex-shared-home.test.ts+++ b/server/drivers/codex-shared-home.test.ts@@ -1,9 +1,10 @@+import { createHash } from "node:crypto";import { existsSync, lstatSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, readlinkSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { dirname, join } from "node:path";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";-import { linkSharedCodexHome } from "./codex-shared-home.ts";+import { keepChatsOutOfCodexHistory, linkSharedCodexHome } from "./codex-shared-home.ts";let root: string;let shared: string;@@ -30,7 +31,7 @@ afterEach(() => {});describe("linkSharedCodexHome", () => {- it("links the person's Codex home into the plan's, but never its sign-in, local folders or SQLite journals", () => {+ it("links the person's Codex home into the plan's, but never its sign-in, chats, local folders or SQLite journals", () => {write(join(shared, "config.toml"), '[mcp_servers.notes]\ncommand = "notes"\n');write(join(shared, "skills", "review", "SKILL.md"));write(join(shared, "history.jsonl"));@@ -41,23 +42,65 @@ describe("linkSharedCodexHome", () => {write(join(shared, "auth.json"), "person's sign-in");write(join(shared, "auth.lock"));write(join(shared, "models_cache.json"));- for (const local of ["log", "memories", "tmp"]) mkdirSync(join(shared, local), { recursive: true });+ write(join(shared, "session_index.jsonl"));+ write(join(shared, "logs_2.sqlite"));+ for (const folder of ["log", "memories", "tmp", "sessions", "archived_sessions", "shell_snapshots", "thread-writer-locks"]) mkdirSync(join(shared, folder), { recursive: true });- linkSharedCodexHome(shared, plan);+ expect(linkSharedCodexHome(shared, plan)).toBe(true);- for (const name of ["config.toml", "skills", "history.jsonl", ".credentials.json", "state_5.sqlite", "sessions", "plugins", "thread-writer-locks"]) {+ for (const name of ["config.toml", "skills", ".credentials.json", "plugins", "mcp-oauth-locks"]) {expect(linksTo(join(plan, name), join(shared, name)), name).toBe(true);}- // The shared folders exist in the person's home from the first turn, so what the plan writes lands there.- expect(lstatSync(join(shared, "sessions")).isDirectory()).toBe(true);- write(join(plan, "sessions", "2026", "rollout.jsonl"));- expect(existsSync(join(shared, "sessions", "2026", "rollout.jsonl"))).toBe(true);expect(readFileSync(join(plan, "skills", "review", "SKILL.md"), "utf8")).toBe("x");- for (const name of ["auth.json", "auth.lock", "models_cache.json", "log", "memories", "tmp", "state_5.sqlite-wal", "state_5.sqlite-shm"]) {+ // Chats the plan starts stay in its own home, out of the person's Codex and ChatGPT apps.+ write(join(plan, "sessions", "2026", "rollout.jsonl"));+ expect(existsSync(join(shared, "sessions", "2026", "rollout.jsonl"))).toBe(false);+ for (const name of ["auth.json", "auth.lock", "models_cache.json", "log", "memories", "tmp", "state_5.sqlite-wal", "state_5.sqlite-shm", "history.jsonl",+ "session_index.jsonl", "state_5.sqlite", "logs_2.sqlite", "archived_sessions", "shell_snapshots", "thread-writer-locks"]) {expect(existsSync(join(plan, name)), name).toBe(false);}});+ it("removes links to the person's chats from before, and leaves the chats themselves where they are", () => {+ write(join(shared, "sessions", "2026", "rollout-person.jsonl"), "person's chat");+ write(join(shared, "history.jsonl"), "person's history");+ write(join(shared, "state_5.sqlite"), "person's chat list");+ write(join(shared, "config.toml"), "person's config");+ mkdirSync(plan, { recursive: true });+ for (const name of ["sessions", "history.jsonl", "state_5.sqlite", "config.toml"]) symlinkSync(join(shared, name), join(plan, name));+ symlinkSync(join(root, "gone", "archived_sessions"), join(plan, "archived_sessions"));++ linkSharedCodexHome(shared, plan);++ for (const name of ["sessions", "history.jsonl", "state_5.sqlite", "archived_sessions"]) expect(() => lstatSync(join(plan, name)), name).toThrow();+ expect(linksTo(join(plan, "config.toml"), join(shared, "config.toml"))).toBe(true);+ expect(readFileSync(join(shared, "sessions", "2026", "rollout-person.jsonl"), "utf8")).toBe("person's chat");+ expect(readFileSync(join(shared, "history.jsonl"), "utf8")).toBe("person's history");+ expect(readFileSync(join(shared, "state_5.sqlite"), "utf8")).toBe("person's chat list");+ });++ it("links the person's own login into a home that uses it, and says when it cannot", () => {+ write(join(shared, "auth.json"), "person's sign-in");+ write(join(shared, "models_cache.json"), "person's models");+ write(join(shared, "history.jsonl"));++ expect(linkSharedCodexHome(shared, plan, "person")).toBe(true);+ for (const name of ["auth.json", "models_cache.json"]) expect(linksTo(join(plan, name), join(shared, name)), name).toBe(true);+ expect(existsSync(join(plan, "history.jsonl"))).toBe(false);+ // A refreshed login written through the link is the person's own file.+ writeFileSync(join(plan, "auth.json"), "refreshed");+ expect(readFileSync(join(shared, "auth.json"), "utf8")).toBe("refreshed");++ const copied = join(root, "copied", "codex");+ write(join(copied, "auth.json"), "a login of its own");+ expect(linkSharedCodexHome(shared, copied, "person")).toBe(false);+ expect(readFileSync(join(copied, "auth.json"), "utf8")).toBe("a login of its own");++ const signedOut = join(root, "signed-out", ".codex");+ write(join(signedOut, "config.toml"));+ expect(linkSharedCodexHome(signedOut, join(root, "fresh", "codex"), "person")).toBe(true);+ });+it("keeps the plan's own sign-in real and removes a link that stands in its place", () => {write(join(shared, "auth.json"), "person's sign-in");write(join(shared, "models_cache.json"), "person's models");@@ -82,7 +125,9 @@ describe("linkSharedCodexHome", () => {write(join(plan, "skills", ".system", "openai-docs", "SKILL.md"));mkdirSync(join(plan, "plugins"), { recursive: true });write(join(plan, "thread-writer-locks", "thread-1.lock"));- write(join(plan, "mcp-oauth-locks", ".coordination.lock"));+ write(join(plan, "mcp-oauth-locks", "server.lock"));+ write(join(plan, "config.toml"), "plan config");+ write(join(shared, "config.toml"), "person config");linkSharedCodexHome(shared, plan);@@ -93,15 +138,17 @@ describe("linkSharedCodexHome", () => {// Codex's bundled .system skills and an empty folder are rebuilt; the person's skills take their place.expect(linksTo(join(plan, "skills"), join(shared, "skills"))).toBe(true);expect(linksTo(join(plan, "plugins"), join(shared, "plugins"))).toBe(true);+ expect(readFileSync(join(plan, "thread-writer-locks", "thread-1.lock"), "utf8")).toBe("x");+ expect(readFileSync(join(plan, "config.toml"), "utf8")).toBe("plan config");// A lock still in the plan's own folder may guard a live writer: shared on a later turn, once released.- expect(isLink(join(plan, "thread-writer-locks"))).toBe(false);- expect(linksTo(join(plan, "mcp-oauth-locks"), join(shared, "mcp-oauth-locks"))).toBe(true);+ expect(isLink(join(plan, "mcp-oauth-locks"))).toBe(false);expect(console.error).toHaveBeenCalledTimes(1);- expect(String(vi.mocked(console.error).mock.calls[0]?.[0])).toContain("sessions, thread-writer-locks, history.jsonl");+ expect(String(vi.mocked(console.error).mock.calls[0]?.[0])).toContain("keeps its own mcp-oauth-locks, config.toml from earlier turns");- rmSync(join(plan, "thread-writer-locks", "thread-1.lock"));+ rmSync(join(plan, "mcp-oauth-locks", "server.lock"));linkSharedCodexHome(shared, plan);- expect(linksTo(join(plan, "thread-writer-locks"), join(shared, "thread-writer-locks"))).toBe(true);+ expect(linksTo(join(plan, "mcp-oauth-locks"), join(shared, "mcp-oauth-locks"))).toBe(true);+ expect(isLink(join(plan, "thread-writer-locks"))).toBe(false);expect(console.error).toHaveBeenCalledTimes(1);});@@ -132,3 +179,42 @@ describe("linkSharedCodexHome", () => {expect(readdirSync(fresh)).toEqual([]);});});++describe("keepChatsOutOfCodexHistory", () => {+ const data = () => join(root, "data");+ const mausHome = (instanceId: string) => join(data(), "providers", "codex-own", createHash("sha256").update(instanceId).digest("hex"), "codex");+ const turnEnv = (extra: Record<string, string> = {}, teamCloud = false) => {+ const env: Record<string, string | undefined> = { HOME: join(root, "person"), ...extra };+ keepChatsOutOfCodexHistory(env, "codex", data(), teamCloud);+ return env;+ };++ it("runs a turn on the person's own login in MausBot's Codex home, with their login and setup linked in", () => {+ write(join(shared, "auth.json"), "person's sign-in");+ write(join(shared, "config.toml"), 'model = "gpt-5"\n');+ expect(turnEnv()).toMatchObject({ CODEX_HOME: mausHome("codex"), CODEX_SQLITE_HOME: mausHome("codex") });+ expect(linksTo(join(mausHome("codex"), "auth.json"), join(shared, "auth.json"))).toBe(true);+ expect(linksTo(join(mausHome("codex"), "config.toml"), join(shared, "config.toml"))).toBe(true);+ expect(turnEnv({ CODEX_HOME: shared, CODEX_SQLITE_HOME: join(root, "elsewhere") }).CODEX_SQLITE_HOME).toBe(mausHome("codex"));+ });++ it("keeps the person's home when the login may be in the keyring, cannot be linked, or the home is MausBot's already", () => {+ write(join(shared, "auth.json"), "person's sign-in");+ write(join(shared, "config.toml"), 'cli_auth_credentials_store = "keyring"\n');+ expect(turnEnv().CODEX_HOME).toBeUndefined();+ write(join(shared, "config.toml"), "cli_auth_credentials_store = 'auto'\n");+ expect(turnEnv().CODEX_HOME).toBeUndefined();+ // Only a top-level setting moves the login: one inside a table is about something else.+ write(join(shared, "config.toml"), '[profiles.work]\ncli_auth_credentials_store = "keyring"\n');+ expect(turnEnv().CODEX_HOME).toBe(mausHome("codex"));++ expect(turnEnv({}, true).CODEX_HOME).toBeUndefined();+ const engineHome = join(data(), "engine-homes", "team", ".codex");+ write(join(engineHome, "auth.json"));+ expect(turnEnv({ CODEX_HOME: engineHome }).CODEX_HOME).toBe(engineHome);++ rmSync(mausHome("codex"), { recursive: true });+ write(join(mausHome("codex"), "auth.json"), "a login of its own");+ expect(turnEnv().CODEX_HOME).toBeUndefined();+ });+});diff --git a/server/drivers/codex-shared-home.ts b/server/drivers/codex-shared-home.tsindex 2b7763d876..c8afa3f420 100644--- a/server/drivers/codex-shared-home.ts+++ b/server/drivers/codex-shared-home.ts@@ -1,19 +1,30 @@-// A ChatGPT-plan instance signs in on a Codex home of its own, so its login never mixes with the person's. Everything-// else the person set up for Codex (config.toml, skills, plugins, sessions, MCP sign-ins) is linked in from their own-// home, so a plan turn works like their own Codex. Company Codex homes never come here: they stay fully separate.-import { lstatSync, mkdirSync, readdirSync, realpathSync, rmSync, statSync, symlinkSync, unlinkSync } from "node:fs";+// MausBot's Codex turns run in Codex homes of its own. A ChatGPT-plan instance signs in there, so its login never mixes+// with the person's; a turn on the person's own Codex sign-in links their login in. Everything else the person set up for+// Codex (config.toml, skills, plugins, MCP sign-ins) is linked in from their own home, so a turn works like their own+// Codex, but MausBot's chats stay in its own home: the Codex and ChatGPT apps list every session in the person's home as+// their history. Company Codex homes never come here: they stay fully separate.+import { createHash } from "node:crypto";+import { lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, symlinkSync, unlinkSync } from "node:fs";import { isAbsolute, join, relative, resolve } from "node:path";-/** Made in the person's home first, so a plan shares them from its first turn. */-const SHARED_FOLDERS = ["sessions", "archived_sessions", "sqlite", "shell_snapshots", "worktrees", "skills", "plugins", "cache",- "logs", "mcp-oauth-locks", "thread-writer-locks"];-/** The plan's own sign-in and model list: always real files in its own home, never links. */+import { DATA_DIR } from "../config.ts";+import { engineHomes } from "../engine-homes/engine-homes.ts";+import { codexHome } from "./codex-identity.ts";++/** Made in the person's home first, so a turn shares them from its first run. */+const SHARED_FOLDERS = ["worktrees", "skills", "plugins", "cache", "logs", "mcp-oauth-locks"];+/** A plan's own sign-in and model list: always real files in its own home, never links. */const PRIVATE = new Set(["auth.json", "auth.lock", "models_cache.json"]);+/** Where Codex keeps its chats and the list the apps show (codex-cli 0.167.2): never linked, so each home has its own. */+const CHATS = new Set(["sessions", "archived_sessions", "sqlite", "shell_snapshots", "thread-writer-locks", "history.jsonl",+ "session_index.jsonl", "session_index.jsonl.lock", ".sqlite-maintenance.lock"]);+/** Codex's databases (state_5.sqlite holds the chat list) sit in the home unless config.toml moves them. */+const DATABASE = /\.sqlite$/;/** Kept per home. */const LOCAL = new Set(["log", "memories", "tmp", ".DS_Store"]);-/** Locks that guard shared state: a plan's own copy gives way to the shared one once no lock in it is held. */-const RUNTIME_LOCKS = new Set(["mcp-oauth-locks", "thread-writer-locks", ".sqlite-maintenance.lock"]);-/** What Codex writes into a folder by itself and rebuilds: a plan folder holding nothing else gives way to a link. */+/** Locks that guard shared state: a home's own copy gives way to the shared one once no lock in it is held. */+const RUNTIME_LOCKS = new Set(["mcp-oauth-locks"]);+/** What Codex writes into a folder by itself and rebuilds: a folder holding nothing else gives way to a link. */const REBUILT = new Set([".system", ".DS_Store"]);// SQLite opens a database through its link and keeps -wal and -shm beside the real file; a journal linked on its own// would pair one home's journal with the other home's database.@@ -31,7 +42,7 @@ function inside(parent: string, child: string): boolean {return path === "" || (!path.startsWith("..") && !isAbsolute(path));}-/** A real entry the plan made itself that holds nothing of its own, or only locks no one holds any more. */+/** A real entry the home made itself that holds nothing of its own, or only locks no one holds any more. */function givesWay(path: string, name: string): boolean {const stats = lstatSync(path);if (!stats.isDirectory()) return RUNTIME_LOCKS.has(name);@@ -40,7 +51,7 @@ function givesWay(path: string, name: string): boolean {return names.every(entry => REBUILT.has(entry));}-/** Links one entry; false when the plan keeps a real one of its own. */+/** Links one entry; false when the home keeps a real one of its own. */function linkEntry(target: string, link: string, name: string): boolean {let stats;try { stats = lstatSync(link); } catch { stats = null; }@@ -48,7 +59,7 @@ function linkEntry(target: string, link: string, name: string): boolean {try { if (realpathSync(link) === realpathSync(target)) return true; } catch {}unlinkSync(link);} else if (stats) {- // Earlier plan turns kept their own sessions and history here: never delete them, keep using them.+ // Earlier turns kept their own files here: never delete them, keep using them.if (!givesWay(link, name)) return false;rmSync(link, { recursive: true, force: true });}@@ -56,38 +67,76 @@ function linkEntry(target: string, link: string, name: string): boolean {try {symlinkSync(target, link, process.platform === "win32" ? (folder ? "junction" : "file") : undefined);} catch (error) {- // Another turn of the same plan linked it first.+ // Another turn of the same instance linked it first.if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;}return true;}-/** Makes the plan's Codex home and links the person's own Codex home into it. Linking never fails the turn: an entry- * that cannot be linked (a file link Windows refuses without Developer Mode) stays as the plan had it. */-export function linkSharedCodexHome(sharedHome: string | null, planHome: string): void {- mkdirSync(planHome, { recursive: true, mode: 0o700 });- if (!sharedHome || !isAbsolute(sharedHome) || !isAbsolute(planHome)) return;- const shared = resolve(sharedHome), own = resolve(planHome);- if (inside(shared, own) || inside(own, shared)) return;+/** Whose login a MausBot home uses: its own (a ChatGPT plan's) or the person's, linked in. */+export type CodexHomeLogin = "own" | "person";++/** Makes MausBot's Codex home and links the person's own Codex home into it. Linking never fails the turn: an entry+ * that cannot be linked (a file link Windows refuses without Developer Mode) stays as the home had it. True when the+ * home has the login it should: its own, or the person's (none when they have none). */+export function linkSharedCodexHome(sharedHome: string | null, mausHome: string, login: CodexHomeLogin = "own"): boolean {+ mkdirSync(mausHome, { recursive: true, mode: 0o700 });+ if (!sharedHome || !isAbsolute(sharedHome) || !isAbsolute(mausHome)) return false;+ const shared = resolve(sharedHome), own = resolve(mausHome);+ if (inside(shared, own) || inside(own, shared)) return false;let names: string[];try {for (const name of SHARED_FOLDERS) mkdirSync(join(shared, name), { recursive: true, mode: 0o700 });names = readdirSync(shared);} catch (error) {- return note(shared, `could not share your Codex home with the ChatGPT plan: ${(error as Error).message}`);+ note(shared, `could not share your Codex home with MausBot's: ${(error as Error).message}`);+ return false;}- for (const name of PRIVATE) {+ const apart = (name: string) => CHATS.has(name) || DATABASE.test(name) || (login === "own" && PRIVATE.has(name));+ // A link from before chats were kept apart goes; the person's own files behind it stay as they are.+ for (const name of readdirSync(own)) {const path = join(own, name);- try { if (lstatSync(path).isSymbolicLink()) unlinkSync(path); } catch {}+ if (apart(name)) try { if (lstatSync(path).isSymbolicLink()) unlinkSync(path); } catch {}}const kept: string[] = [];for (const name of new Set([...SHARED_FOLDERS, ...names])) {- if (PRIVATE.has(name) || LOCAL.has(name) || SQLITE_JOURNAL.test(name)) continue;+ if (apart(name) || LOCAL.has(name) || SQLITE_JOURNAL.test(name)) continue;try {if (!linkEntry(join(shared, name), join(own, name), name)) kept.push(name);} catch (error) {- note(join(own, name), `could not link ${JSON.stringify(name)} of your Codex home for the ChatGPT plan: ${(error as Error).message}`);+ note(join(own, name), `could not link ${JSON.stringify(name)} of your Codex home into MausBot's: ${(error as Error).message}`);}}- if (kept.length) note(own, `the ChatGPT plan's Codex home keeps its own ${kept.join(", ")} from earlier turns; the rest of your Codex home is shared`);+ if (kept.length) note(own, `MausBot's Codex home keeps its own ${kept.join(", ")} from earlier turns; the rest of your Codex home is shared`);+ return login === "own" || personLogin(shared, own);+}++/** The home reads the person's login file itself, or, like the person's home, has none. */+function personLogin(shared: string, own: string): boolean {+ const real = (home: string) => { try { return realpathSync(join(home, "auth.json")); } catch { return null; } };+ const person = real(shared);+ if (person) return real(own) === person;+ try { return lstatSync(join(own, "auth.json")).isSymbolicLink(); } catch { return true; }+}++/** `cli_auth_credentials_store = "keyring"` or `"auto"`: Codex may keep the login in the system keyring under a name made+ * from the home's path, which another home cannot reach, and a refresh there could leave the person's own copy stale. */+function keyringLogin(home: string): boolean {+ let text: string;+ try { text = readFileSync(join(home, "config.toml"), "utf8"); } catch { return false; }+ const topLevel = text.split(/^\s*\[/m)[0] ?? "";+ return /^\s*cli_auth_credentials_store\s*=\s*["'](?:keyring|auto)["']/m.test(topLevel);+}++/** A turn on the person's own Codex sign-in runs in MausBot's Codex home for this instance, so its chats stay out of their+ * Codex and ChatGPT apps. It keeps their home when that is MausBot's already (a Team Cloud's engine homes, anything in+ * the data folder), when their login may be in the keyring, or when their login cannot be linked. */+export function keepChatsOutOfCodexHistory(env: Record<string, string | undefined>, instanceId: string, dataDir = DATA_DIR, teamCloud = engineHomes.active()): void {+ const person = codexHome(env);+ if (!person || teamCloud || inside(resolve(dataDir), person) || keyringLogin(person)) return;+ const home = join(resolve(dataDir), "providers", "codex-own", createHash("sha256").update(instanceId).digest("hex"), "codex");+ if (!linkSharedCodexHome(person, home, "person")) return;+ env.CODEX_HOME = home;+ // Codex keeps its databases here too unless config.toml names another folder.+ env.CODEX_SQLITE_HOME = home;}diff --git a/server/drivers/codex.test.ts b/server/drivers/codex.test.tsindex f37d5230cf..23febc723f 100644--- a/server/drivers/codex.test.ts+++ b/server/drivers/codex.test.ts@@ -1235,7 +1235,12 @@ process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,result})+'\\n');});`)await instance.adapter.sendTurn({ threadId: "t-environment", text: "hi" });await recorder.until((event) => event.type === "turn.completed");- expect(JSON.parse(readFileSync(dump, "utf8")).env.CODEX_HOME).toBe(codexHome);+ // The turn runs in MausBot's own Codex home, with the instance's Codex home linked in but its chats kept apart.+ const { env } = JSON.parse(readFileSync(dump, "utf8"));+ expect(env.CODEX_HOME.startsWith(join(DATA_DIR, "providers", "codex-own") + sep)).toBe(true);+ expect(env.CODEX_SQLITE_HOME).toBe(env.CODEX_HOME);+ expect(realpathSync(join(env.CODEX_HOME, "skills"))).toBe(realpathSync(join(codexHome, "skills")));+ expect(existsSync(join(codexHome, "sessions"))).toBe(false);});it("mounts connected apps without placing credential values in argv", async () => {@@ -2259,10 +2264,15 @@ process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,result})+'\\n');});`)if (plan) {expect(seen.env.CODEX_HOME.startsWith(join(DATA_DIR, "providers", "chatgpt-plan") + sep)).toBe(true);expect(seen.env.CODEX_HOME).not.toBe(join(scratch, ".codex"));- // The plan signs in on its own home; the person's Codex skills, settings and sessions are linked in.+ // The plan signs in on its own home; the person's Codex skills and settings are linked in, never their chats.expect(realpathSync(join(seen.env.CODEX_HOME, "skills"))).toBe(realpathSync(join(scratch, ".codex", "skills")));expect(seen.argv.some((arg: string) => arg.startsWith("shell_environment_policy.exclude="))).toBe(false);- } else expect(seen.env.CODEX_HOME).toBe(join(scratch, ".codex"));+ } else if (Object.keys(opts).length) expect(seen.env.CODEX_HOME).toBe(join(scratch, ".codex"));+ else {+ // A turn on the person's own login keeps its chats in MausBot's own Codex home, with their login linked in.+ expect(seen.env.CODEX_HOME.startsWith(join(DATA_DIR, "providers", "codex-own") + sep)).toBe(true);+ expect(realpathSync(join(seen.env.CODEX_HOME, "skills"))).toBe(realpathSync(join(scratch, ".codex", "skills")));+ }const threadCalls = seen.calls.filter((call: { method: string }) => ["thread/start", "thread/resume"].includes(call.method));expect(threadCalls).toHaveLength(1);if (plan) expect(threadCalls[0].params.config["shell_environment_policy.exclude"]).toEqual(["OPENMAUSBOT_CHATGPT_TOKEN"]);diff --git a/server/drivers/codex.ts b/server/drivers/codex.tsindex e07da37d92..799de9f1c7 100644--- a/server/drivers/codex.ts+++ b/server/drivers/codex.ts@@ -54,7 +54,7 @@ import { volatileContextNote, withContextNote } from "./prompt-split.ts";import type { ApprovalMode } from "../../shared/approval-mode.ts";import { CodexDeviceAuthController } from "./codex-device-auth.ts"; import { messageItem } from "../harness/text-items.ts";import { codexAccountEmail, codexHome } from "./codex-identity.ts";-import { linkSharedCodexHome } from "./codex-shared-home.ts";+import { keepChatsOutOfCodexHistory, linkSharedCodexHome } from "./codex-shared-home.ts";import { containsControlCharacter, mcpAppApprovalForm, mcpAppApprovalText, mcpElicitationDeclined, plainRecord } from "./codex-app-approval.ts";import { archivedNativeCodexThread, CODEX_MISSING_CREDENTIALS, codexProviderMismatch, CODEX_SIGN_IN_EXPIRED, codexLimitFacts, codexNotSignedIn, CodexRpcError, codexSignInExpired, codexPlanModelRefused, codexSignInRefused, codexUserError, codexUserFailure, missingNativeCodexThread, type CodexRoute } from "./codex-errors.ts";import { codexLoginCheck, codexLoginStatus, storedCodexLogin } from "./codex-login.ts";@@ -544,7 +544,7 @@ export const CodexDriver: ProviderDriver<CodexConfig> = {};const launchAttempt = async (attempt: number): Promise<void> => {const env = childEnv();- const launchedLogin = chatgptTurn ? storedCodexLogin(env) : null;+ const launchedLogin = chatgptTurn ? storedCodexLogin(env) : null; if (ownLogin) keepChatsOutOfCodexHistory(env, instanceId);if (authBridge) Object.assign(env, authBridge.env); else if (planToken) env.OPENMAUSBOT_CHATGPT_TOKEN = planToken;const appServerArgs = ["app-server", ...(plan ? chatgptPlanCodexArgs(!!authBridge) : config.endpoint ? endpointCodexArgs(config.endpoint) : config.managed ? managedCodexArgs(config.managed) : codexSelectedProviderArgs(env, turn.model)), ...codexToolSurfaceArgs(),// Native shell snapshots can restore variables the shell policy removed.diff --git a/server/host/delete-leftovers.test.ts b/server/host/delete-leftovers.test.tsindex 182f132251..98f60fa8a2 100644--- a/server/host/delete-leftovers.test.ts+++ b/server/host/delete-leftovers.test.ts@@ -327,13 +327,14 @@ describe("the helpers", () => {it("finds each engine's folder from the environment its instance runs with", () => {const { dataDir, home } = fixture();- mkdirSync(join(dataDir, "providers", "chatgpt-plan", "abc", "codex"), { recursive: true });+ for (const kind of ["chatgpt-plan", "codex-own"]) mkdirSync(join(dataDir, "providers", kind, "abc", "codex"), { recursive: true });const work = instanceEnvironment({ HOME: home }, { config: { configDir: "~/.claude-work" } });const endpoint = instanceEnvironment({ HOME: home }, { environment: { CODEX_HOME: join(dataDir, "providers", "relay") } });expect(instanceEnvironment({ HOME: home }, { config: { configDir: "relative" } }).CLAUDE_CONFIG_DIR).toBeUndefined();expect(engineSessionFolders(dataDir, [{ HOME: home }, work, endpoint, {}])).toEqual({claude: [join(home, ".claude"), join(home, ".claude-work")],- codex: [join(home, ".codex"), join(dataDir, "providers", "relay"), join(dataDir, "providers", "chatgpt-plan", "abc", "codex")],+ codex: [join(home, ".codex"), join(dataDir, "providers", "relay"), join(dataDir, "providers", "chatgpt-plan", "abc", "codex"),+ join(dataDir, "providers", "codex-own", "abc", "codex")],pi: [join(home, ".pi", "agent")],});});diff --git a/server/host/delete-leftovers.ts b/server/host/delete-leftovers.tsindex 7c8b82ecce..6fd6064f32 100644--- a/server/host/delete-leftovers.ts+++ b/server/host/delete-leftovers.ts@@ -178,8 +178,11 @@ export function engineSessionFolders(dataDir: string, environments: Iterable<Recif (codexFolder) codex.add(codexFolder);if (home) pi.add(join(home, ".pi", "agent"));}- const plans = join(resolve(dataDir), "providers", "chatgpt-plan");- for (const plan of entries(plans)) codex.add(join(plans, plan, "codex"));+ // MausBot's own Codex homes (codex-shared-home.ts): a ChatGPT plan's, and those of turns on the person's own sign-in.+ for (const kind of ["chatgpt-plan", "codex-own"]) {+ const homes = join(resolve(dataDir), "providers", kind);+ for (const home of entries(homes)) codex.add(join(homes, home, "codex"));+ }return { claude: [...claude], codex: [...codex], pi: [...pi] };}