Skip to content

Commit 868a9c4

Browse files
authored
fix(adapters): neutralize Codex CLI 0.145 identity wording (#638)
* fix(adapters): neutralize Codex CLI 0.145 identity wording Closes #622 * fix(adapters): consume full GPT-5.x.y identity versions
1 parent f492f7d commit 868a9c4

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/adapters/identity.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,19 @@
1414
* to be a specific first-party client.
1515
*/
1616

17-
/** The exact identity line Codex injects for every model. */
17+
/** Historical exact identity line Codex injected for every model. */
1818
export const CODEX_GPT5_IDENTITY_LINE = "You are Codex, a coding agent based on GPT-5.";
1919

20+
/** Codex CLI 0.145.0+ wording (#622) — still GPT-5 identity, slightly different phrasing. */
21+
export const CODEX_GPT5_IDENTITY_LINE_AGENT = "You are Codex, an agent based on GPT-5.";
22+
23+
/**
24+
* Known Codex GPT-5 identity sentences. Narrow: only "coding agent" / "an agent" + GPT-5(.x)?
25+
* Avoid a broad `You are Codex.*` rewrite that could touch unrelated content.
26+
*/
27+
const CODEX_GPT5_IDENTITY_RE =
28+
/You are Codex, (?:a coding agent|an agent) based on GPT-5(?:\.[0-9]+)*\./g;
29+
2030
/** Proxy-neutral replacement: no "opencodex proxy" mention, just the GPT-5/OpenAI disclaimer. */
2131
export const NEUTRAL_IDENTITY_LINE = "You are a coding agent. Do not claim to be GPT-5 or to be made by OpenAI.";
2232

@@ -27,7 +37,7 @@ export const NEUTRAL_IDENTITY_LINE = "You are a coding agent. Do not claim to be
2737
* the leak can't reappear in one adapter while being fixed in another.
2838
*/
2939
export function neutralizeIdentity(systemText: string): string {
30-
return systemText.replace(CODEX_GPT5_IDENTITY_LINE, NEUTRAL_IDENTITY_LINE);
40+
return systemText.replace(CODEX_GPT5_IDENTITY_RE, NEUTRAL_IDENTITY_LINE);
3141
}
3242

3343
/** The catalog (static, on-disk) replacement for `base_instructions`. Same neutral wording. */

tests/identity-neutralize.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
22
import { mkdtempSync, rmSync } from "node:fs";
33
import { tmpdir } from "node:os";
44
import { join } from "node:path";
5-
import { CODEX_GPT5_IDENTITY_LINE, NEUTRAL_IDENTITY_LINE, neutralizeIdentity } from "../src/adapters/identity";
5+
import {
6+
CODEX_GPT5_IDENTITY_LINE,
7+
CODEX_GPT5_IDENTITY_LINE_AGENT,
8+
NEUTRAL_IDENTITY_LINE,
9+
neutralizeIdentity,
10+
} from "../src/adapters/identity";
611
import { createGoogleAdapter } from "../src/adapters/google";
712
import { createKiroAdapter } from "../src/adapters/kiro";
813
import { createOpenAIChatAdapter } from "../src/adapters/openai-chat";
@@ -23,6 +28,12 @@ describe("identity neutralization — central helper", () => {
2328
expect(neutralizeIdentity(SYS)).toBe(NEUTRAL_IDENTITY_LINE);
2429
});
2530

31+
test("replaces the Codex CLI 0.145 'an agent' identity variant (#622)", () => {
32+
expect(neutralizeIdentity(CODEX_GPT5_IDENTITY_LINE_AGENT)).toBe(NEUTRAL_IDENTITY_LINE);
33+
expect(neutralizeIdentity("You are Codex, an agent based on GPT-5.4.")).toBe(NEUTRAL_IDENTITY_LINE);
34+
expect(neutralizeIdentity("You are Codex, an agent based on GPT-5.4.1.")).toBe(NEUTRAL_IDENTITY_LINE);
35+
});
36+
2637
test("never emits the opencodex proxy identity", () => {
2738
const out = neutralizeIdentity(`${SYS}\n\nmore context`);
2839
expect(out).not.toMatch(/opencodex proxy/i);
@@ -32,6 +43,9 @@ describe("identity neutralization — central helper", () => {
3243

3344
test("leaves text without the GPT-5 line unchanged", () => {
3445
expect(neutralizeIdentity("plain system text")).toBe("plain system text");
46+
expect(neutralizeIdentity("You are Codex, helpful for reviewing PRs.")).toBe(
47+
"You are Codex, helpful for reviewing PRs.",
48+
);
3549
});
3650

3751
test("neutral line still forbids GPT-5 / OpenAI self-reporting", () => {

0 commit comments

Comments
 (0)