Skip to content

Commit fc75d7b

Browse files
committed
fix(codex): strip cli banner before output parsing
1 parent d8ebc40 commit fc75d7b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/agents/CodexAgent.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ export class CodexAgent extends BaseCliAgent {
106106
args,
107107
stdin: fullPrompt,
108108
outputFile,
109+
stdoutBannerPatterns: [
110+
// Codex CLI prints a startup banner like:
111+
// "OpenAI Codex v0.99.0-alpha.13 (research preview)"
112+
/^OpenAI Codex v[^\n]*$/gm,
113+
],
109114
cleanup: async () => {
110115
if (!this.opts.outputLastMessage) {
111116
await fs.rm(outputFile, { force: true }).catch(() => undefined);

tests/base-cli-agent-stdout-errors.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,19 @@ describe("BaseCliAgent banner handling (opt-in)", () => {
147147
expect(result.text).toBe("Here is the actual response from the model.");
148148
});
149149
});
150+
151+
describe("BaseCliAgent Codex banner stripping (opt-in)", () => {
152+
const codexBanner = /^OpenAI Codex v[^\n]*$/gm;
153+
154+
test("strips Codex startup banner and keeps JSON payload", async () => {
155+
const content = [
156+
"OpenAI Codex v0.99.0-alpha.13 (research preview)",
157+
'{"tickets":[{"id":"t1"}]}',
158+
].join("\n");
159+
const agent = new StdoutAgent(content, {
160+
stdoutBannerPatterns: [codexBanner],
161+
});
162+
const result = await agent.generate({ prompt: "test" });
163+
expect(result.text).toBe('{"tickets":[{"id":"t1"}]}');
164+
});
165+
});

0 commit comments

Comments
 (0)