Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Keep the person's ~/.codex/AGENTS.md out of Codex bot turns
Rino Cheng45afa65da763
diff --git a/server/drivers/codex-shared-home.test.ts b/server/drivers/codex-shared-home.test.tsindex 4ead31dc80..2a2eb4dd87 100644--- a/server/drivers/codex-shared-home.test.ts+++ b/server/drivers/codex-shared-home.test.ts@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";import { dirname, join } from "node:path";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";-import { keepChatsOutOfCodexHistory, linkSharedCodexHome } from "./codex-shared-home.ts";+import { inheritsUserCodexInstructions, keepChatsOutOfCodexHistory, linkSharedCodexHome } from "./codex-shared-home.ts";let root: string;let shared: string;@@ -61,6 +61,56 @@ describe("linkSharedCodexHome", () => {}});+ it("leaves the person's own AGENTS.md out of the plan's home, and keeps their sign-in, config and skills linked", () => {+ write(join(shared, "AGENTS.md"), "person's instructions");+ write(join(shared, "AGENTS.override.md"), "person's override");+ write(join(shared, "config.toml"));+ write(join(shared, "skills", "review", "SKILL.md"));+ write(join(shared, "auth.json"), "person's sign-in");++ expect(linkSharedCodexHome(shared, plan, "person", false)).toBe(true);++ for (const name of ["AGENTS.md", "AGENTS.override.md"]) expect(existsSync(join(plan, name)), name).toBe(false);+ for (const name of ["config.toml", "skills", "auth.json"]) expect(linksTo(join(plan, name), join(shared, name)), name).toBe(true);+ expect(readFileSync(join(shared, "AGENTS.md"), "utf8")).toBe("person's instructions");+ });++ it("links the person's AGENTS.md when asked to inherit their setup", () => {+ write(join(shared, "AGENTS.md"), "person's instructions");+ write(join(shared, "AGENTS.override.md"), "person's override");++ linkSharedCodexHome(shared, plan, "own", true);++ for (const name of ["AGENTS.md", "AGENTS.override.md"]) expect(linksTo(join(plan, name), join(shared, name)), name).toBe(true);+ });++ it("removes an AGENTS.md link from before, and leaves the person's file where it is", () => {+ write(join(shared, "AGENTS.md"), "person's instructions");+ write(join(shared, "config.toml"));+ mkdirSync(plan, { recursive: true });+ symlinkSync(join(shared, "AGENTS.md"), join(plan, "AGENTS.md"));++ linkSharedCodexHome(shared, plan, "own", false);++ expect(() => lstatSync(join(plan, "AGENTS.md"))).toThrow();+ expect(linksTo(join(plan, "config.toml"), join(shared, "config.toml"))).toBe(true);+ expect(readFileSync(join(shared, "AGENTS.md"), "utf8")).toBe("person's instructions");+ });++ it("follows OMB_CODEX_INHERIT_USER_CONFIG when no choice is passed", () => {+ write(join(shared, "AGENTS.md"), "person's instructions");+ expect(inheritsUserCodexInstructions({})).toBe(false);+ expect(inheritsUserCodexInstructions({ OMB_CODEX_INHERIT_USER_CONFIG: "1" })).toBe(true);++ linkSharedCodexHome(shared, plan);+ expect(existsSync(join(plan, "AGENTS.md"))).toBe(false);++ vi.stubEnv("OMB_CODEX_INHERIT_USER_CONFIG", "1");+ linkSharedCodexHome(shared, plan);+ expect(linksTo(join(plan, "AGENTS.md"), join(shared, "AGENTS.md"))).toBe(true);+ vi.unstubAllEnvs();+ });+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");@@ -210,6 +260,17 @@ describe("keepChatsOutOfCodexHistory", () => {expect(turnEnv({ CODEX_HOME: shared, CODEX_SQLITE_HOME: join(root, "elsewhere") }).CODEX_SQLITE_HOME).toBe(mausHome("codex"));});+ it("keeps the person's AGENTS.md out of MausBot's Codex home for a turn on their own login", () => {+ write(join(shared, "auth.json"), "person's sign-in");+ write(join(shared, "AGENTS.md"), "person's instructions");+ write(join(shared, "config.toml"));+ const env = turnEnv();+ expect(env.CODEX_HOME).toBe(mausHome("codex"));+ expect(existsSync(join(mausHome("codex"), "AGENTS.md"))).toBe(false);+ 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);+ });+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');diff --git a/server/drivers/codex-shared-home.ts b/server/drivers/codex-shared-home.tsindex 067517952e..2a1dbe2df5 100644--- a/server/drivers/codex-shared-home.ts+++ b/server/drivers/codex-shared-home.ts@@ -20,6 +20,8 @@ const CHATS = new Set(["sessions", "archived_sessions", "sqlite", "shell_snapsho"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$/;+/** The person's own instructions, which Codex adds to every turn (codex-cli 0.169.0; `project_doc_max_bytes` limits only project files). */+const USER_INSTRUCTIONS = new Set(["AGENTS.md", "AGENTS.override.md"]);/** Kept per home. */const LOCAL = new Set(["log", "memories", "tmp", ".DS_Store"]);/** Locks that guard shared state: a home's own copy gives way to the shared one once no lock in it is held. */@@ -76,14 +78,21 @@ function linkEntry(target: string, link: string, name: string): boolean {/** Whose login a MausBot home uses: its own (a ChatGPT plan's) or the person's, linked in. */export type CodexHomeLogin = "own" | "person";+/** Escape hatch: bot turns also load the person's own AGENTS.md, as Claude bots do with OMB_CLAUDE_INHERIT_USER_CONFIG. */+export function inheritsUserCodexInstructions(env: NodeJS.ProcessEnv = process.env): boolean {+ return env.OMB_CODEX_INHERIT_USER_CONFIG === "1";+}+/** 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 {+export function linkSharedCodexHome(sharedHome: string | null, mausHome: string, login: CodexHomeLogin = "own",+ inheritInstructions = inheritsUserCodexInstructions()): boolean {mkdirSync(mausHome, { recursive: true, mode: 0o700 });if (!isAbsolute(mausHome)) return false;const own = resolve(mausHome);- const apart = (name: string) => CHATS.has(name) || DATABASE.test(name) || (login === "own" && PRIVATE.has(name));+ const apart = (name: string) => CHATS.has(name) || DATABASE.test(name) || (login === "own" && PRIVATE.has(name))+ || (!inheritInstructions && USER_INSTRUCTIONS.has(name));// A link from before chats were kept apart goes, even when sharing fails below, so no new chat is written through it;// the person's own files behind it stay as they are.for (const name of readdirSync(own)) {