diff --git a/src/main/codex/codex-home-paths.test.ts b/src/main/codex/codex-home-paths.test.ts index 26053b8786c9..5b87165bafc2 100644 --- a/src/main/codex/codex-home-paths.test.ts +++ b/src/main/codex/codex-home-paths.test.ts @@ -268,6 +268,22 @@ describe('syncSystemCodexResourcesIntoManagedHome', () => { expectSymbolicLinkTargetIfLinked(runtimeHooksPath, systemHooksPath) }) + it('mirrors execpolicy rules into a per-account home so the user rules still apply', () => { + const systemRulesPath = join(getSystemCodexHomePath(), 'rules') + mkdirSync(systemRulesPath, { recursive: true }) + writeFileSync(join(systemRulesPath, 'default.rules'), 'prefix_rule(pattern=["git", "add"])\n') + const perAccountHome = join(userDataDir, 'codex-accounts', 'account-1', 'home') + mkdirSync(perAccountHome, { recursive: true }) + + syncSystemCodexResourcesIntoManagedHome(perAccountHome) + + const perAccountRulesPath = join(perAccountHome, 'rules') + expect(readFileSync(join(perAccountRulesPath, 'default.rules'), 'utf-8')).toBe( + 'prefix_rule(pattern=["git", "add"])\n' + ) + expectSymbolicLinkTargetIfLinked(perAccountRulesPath, systemRulesPath) + }) + it('mirrors the global AGENTS.md into the managed runtime home so user instructions survive', () => { const systemAgentsPath = join(getSystemCodexHomePath(), 'AGENTS.md') const runtimeAgentsPath = join(getRuntimeCodexHomePath(), 'AGENTS.md') diff --git a/src/main/codex/codex-home-paths.ts b/src/main/codex/codex-home-paths.ts index e838d11fe6b2..79d008993088 100644 --- a/src/main/codex/codex-home-paths.ts +++ b/src/main/codex/codex-home-paths.ts @@ -29,6 +29,8 @@ const CODEX_SYSTEM_RESOURCE_ENTRIES = [ 'profile-v2', 'themes', 'prompts', + // Why: Codex loads the user's execpolicy `.rules` from `$CODEX_HOME/rules`. + 'rules', CODEX_GLOBAL_INSTRUCTIONS_ENTRY ] as const