Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/community/openai/codex-agent-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
21 changes: 21 additions & 0 deletions tests/community/openai/codex-agent-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down