From 73f5dcc756df942fd92050bde1d7ecbbf1a19b1b Mon Sep 17 00:00:00 2001 From: catwithtudou <949812478@qq.com> Date: Sun, 7 Jun 2026 14:48:41 +0800 Subject: [PATCH] fix: preserve existing AGENTS.md during Codex sync --- src/community/openai/codex-agent-runner.ts | 6 +++++- .../openai/codex-agent-runner.test.ts | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/community/openai/codex-agent-runner.ts b/src/community/openai/codex-agent-runner.ts index 7cfb9fd..e1b4208 100644 --- a/src/community/openai/codex-agent-runner.ts +++ b/src/community/openai/codex-agent-runner.ts @@ -510,12 +510,16 @@ export class CodexAgentRunner implements AgentRunner { const agentsMdPath = join(cwd, "AGENTS.md"); - // Skip write when contents are identical to avoid file-watcher churn. if (existsSync(agentsMdPath)) { const existing = readFileSync(agentsMdPath, "utf-8"); + // Skip write when contents are identical to avoid file-watcher churn. if (existing === normalized) { return; } + logger.warn( + "AGENTS.md already exists; skipping CLAUDE.md sync to avoid overwriting project instructions", + ); + return; } writeFileSync(agentsMdPath, normalized, "utf-8"); diff --git a/tests/community/openai/codex-agent-runner.test.ts b/tests/community/openai/codex-agent-runner.test.ts index bfa2f4f..6b5eadd 100644 --- a/tests/community/openai/codex-agent-runner.test.ts +++ b/tests/community/openai/codex-agent-runner.test.ts @@ -415,6 +415,27 @@ describe("CodexAgentRunner._parseStreamLine", () => { expect(agents).not.toContain("Claude Code"); }); + test("syncing AGENTS.md preserves existing project instructions", () => { + const cwd = mkdtempSync(join(tmpdir(), "agentara-codex-runner-")); + tempDirs.push(cwd); + const existingAgents = "# Project Instructions\n\nKeep this project's AGENTS.md.\n"; + writeFileSync( + join(cwd, "CLAUDE.md"), + "# Title\n\nAs Claude Code, use the shared instructions.\n", + "utf-8", + ); + writeFileSync(join(cwd, "AGENTS.md"), existingAgents, "utf-8"); + + const runner = new CodexAgentRunner() as unknown as Record< + string, + CallableFunction + >; + runner["_syncAgentsMd"]!(cwd); + + const agents = readFileSync(join(cwd, "AGENTS.md"), "utf-8"); + expect(agents).toBe(existingAgents); + }); + test("builds resume args with runnerSessionId when available", () => { const runner = new CodexAgentRunner() as unknown as Record< string,