Skip to content

Commit b39eecf

Browse files
authored
Merge pull request #1096 from chrisae9/split/1019-01-picker-setting
feat(codex): add account picker visibility setting
2 parents e9d957b + 435ade0 commit b39eecf

6 files changed

Lines changed: 177 additions & 2 deletions

File tree

‎src/codex/account-namespaces.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,14 @@ export function codexAccountNamespaceEntries(
147147
return Object.entries(config.codexAccountNamespaces ?? {})
148148
.map(([namespace, accountId]) => [namespace, normalizeCodexAccountNamespaceTarget(accountId)]);
149149
}
150+
151+
/**
152+
* Whether generated account-qualified rows are enabled for catalog discovery.
153+
* A non-empty hand-written map predating the explicit override remains enabled.
154+
*/
155+
export function codexAccountPickerEnabled(
156+
config: Pick<OcxConfig, "codexAccountNamespaces" | "codexAccountPickerEnabled">,
157+
): boolean {
158+
return (config.codexAccountPickerEnabled === undefined || config.codexAccountPickerEnabled === true)
159+
&& Object.keys(config.codexAccountNamespaces ?? {}).length > 0;
160+
}

‎src/config.ts‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,9 @@ const configSchema = z.object({
10601060
// pool accounts. Warning emitted in loadConfig.
10611061
codexAccountPriorities: codexAccountPrioritiesSchema.optional().catch(undefined),
10621062
activeCodexAccountPinned: z.string().regex(CODEX_ACCOUNT_PIN_PATTERN).optional().catch(undefined),
1063+
// A malformed hand edit must degrade to false without discarding providers, accounts,
1064+
// or the exact selector map. Live writes remain strict.
1065+
codexAccountPickerEnabled: z.boolean().optional().catch(false),
10631066
// Model ids excluded from the Grok Build managed block (dashboard switches).
10641067
grokExcludedModels: z.array(z.string()).optional(),
10651068
// Invalid values degrade to undefined ("auto") instead of failing the whole
@@ -1712,6 +1715,18 @@ function malformedNativeSubagentFieldWarning(field: NativeSubagentPersistedField
17121715
return `${field} ignored: expected ${expected}`;
17131716
}
17141717

1718+
function malformedCodexAccountPickerWarning(rawParsed: unknown): string | null {
1719+
const raw = rawConfigRecord(rawParsed);
1720+
if (!raw || !Object.hasOwn(raw, "codexAccountPickerEnabled")) return null;
1721+
if (typeof raw.codexAccountPickerEnabled === "boolean") return null;
1722+
return "codexAccountPickerEnabled ignored: expected a boolean";
1723+
}
1724+
1725+
function warnDegradedCodexAccountPicker(rawParsed: unknown): void {
1726+
const warning = malformedCodexAccountPickerWarning(rawParsed);
1727+
if (warning) console.warn(`⚠️ config.json ${warning}. Other settings were preserved.`);
1728+
}
1729+
17151730
function nativeSubagentSyncDisabledReason(config: OcxConfig, rawParsed?: unknown): string | null {
17161731
if (config.syncCodexSubagentDefaults !== true) return null;
17171732
const malformed = malformedNativeSubagentFields(rawParsed);
@@ -1763,6 +1778,7 @@ export function loadConfig(): OcxConfig {
17631778
warnDegradedCodexAccountPriorities(parsed, config);
17641779
warnDegradedClaudeSubagentEffort(parsed);
17651780
warnDegradedNativeSubagentConfig(parsed, config);
1781+
warnDegradedCodexAccountPicker(parsed);
17661782
return normalizeClaudeSubagentEffort(normalizeNativeSubagentSync(config, parsed), parsed);
17671783
}
17681784
// Schema validation failed — merge defaults into the raw object instead of
@@ -1783,6 +1799,7 @@ export function loadConfig(): OcxConfig {
17831799
warnDegradedCodexAccountPriorities(parsed, config);
17841800
warnDegradedClaudeSubagentEffort(parsed);
17851801
warnDegradedNativeSubagentConfig(parsed, config);
1802+
warnDegradedCodexAccountPicker(parsed);
17861803
return normalizeClaudeSubagentEffort(normalizeNativeSubagentSync(config, parsed), parsed);
17871804
}
17881805
// Merge couldn't fix it — truly broken config
@@ -1832,6 +1849,8 @@ function validFileConfigDiagnostics(config: OcxConfig, rawParsed: unknown): Conf
18321849
warnings.push(`claudeCode.subagentEffort ignored: expected one of ${CLAUDE_SUBAGENT_EFFORTS.join(", ")}`);
18331850
}
18341851
warnings.push(...malformedNativeSubagentFields(rawParsed).map(malformedNativeSubagentFieldWarning));
1852+
const pickerWarning = malformedCodexAccountPickerWarning(rawParsed);
1853+
if (pickerWarning) warnings.push(pickerWarning);
18351854
if (syncDisabledReason) {
18361855
warnings.push(`syncCodexSubagentDefaults ignored: ${syncDisabledReason}`);
18371856
}
@@ -1935,13 +1954,31 @@ function googleAntigravityStaticCatalogVersionError(value: unknown): string | nu
19351954
return "schema_invalid: googleAntigravityStaticCatalogVersion: must be 1 or omitted";
19361955
}
19371956

1957+
function codexAccountPickerEnabledError(value: unknown): string | null {
1958+
const raw = rawConfigRecord(value);
1959+
if (!raw) return null;
1960+
const descriptor = Object.getOwnPropertyDescriptor(raw, "codexAccountPickerEnabled");
1961+
if (!descriptor) {
1962+
return "codexAccountPickerEnabled" in raw
1963+
? "schema_invalid: codexAccountPickerEnabled: must be an own boolean data property or omitted"
1964+
: null;
1965+
}
1966+
if (!("value" in descriptor)) {
1967+
return "schema_invalid: codexAccountPickerEnabled: must be an own boolean data property or omitted";
1968+
}
1969+
const enabled = descriptor.value;
1970+
if (enabled === undefined || typeof enabled === "boolean") return null;
1971+
return "schema_invalid: codexAccountPickerEnabled: must be a boolean or omitted";
1972+
}
1973+
19381974
/** Validate an in-memory config candidate without touching disk. Used by headless CLI import/set. */
19391975
export function validateConfigCandidate(value: unknown): { ok: true; config: OcxConfig } | { ok: false; error: string } {
19401976
const boundaryError = blankHostnameError(value)
19411977
?? claudeSubagentEffortError(value)
19421978
?? appOwnedMemoryBudgetError(value)
19431979
?? googleAntigravityStaticCatalogVersionError(value)
1944-
?? codexAccountPrioritiesError(value);
1980+
?? codexAccountPrioritiesError(value)
1981+
?? codexAccountPickerEnabledError(value);
19451982
if (boundaryError) return { ok: false, error: boundaryError };
19461983
const result = configSchema.safeParse(value);
19471984
if (result.success) return { ok: true, config: normalizeApiKeyIds(result.data as OcxConfig) };

‎src/types.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,11 @@ export interface OcxConfig {
782782
* are intentionally separate from these selectors.
783783
*/
784784
codexAccountNamespaces?: Record<string, string>;
785+
/**
786+
* Picker visibility override for account-qualified native models. When omitted, a non-empty
787+
* selector map remains visible for compatibility with hand-written configurations.
788+
*/
789+
codexAccountPickerEnabled?: boolean;
785790
/** Active pool account id for next session. undefined = main (passthrough as-is). */
786791
activeCodexAccountId?: string;
787792
/** Auto-switch threshold (0-100). Default 80. 0 = disabled. */

‎tests/codex-account-namespaces.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "../src/codex/account-namespace-match";
1313
import {
1414
appendDefaultCodexAccountNamespace,
15+
codexAccountPickerEnabled,
1516
codexAccountNamespaceEntries,
1617
defaultCodexAccountNamespaces,
1718
isMainCodexAccountTarget,
@@ -306,6 +307,29 @@ describe("Codex account namespace foundations", () => {
306307
})).toEqual({ "main-2": "@main", p454545: "main" });
307308
});
308309

310+
test("keeps existing selector maps enabled unless the visibility override is false", () => {
311+
expect(codexAccountPickerEnabled({ codexAccountNamespaces: { desktop: "@main" } })).toBe(true);
312+
expect(codexAccountPickerEnabled({
313+
codexAccountNamespaces: { desktop: "@main" },
314+
codexAccountPickerEnabled: true,
315+
})).toBe(true);
316+
expect(codexAccountPickerEnabled({
317+
codexAccountNamespaces: { desktop: "@main" },
318+
codexAccountPickerEnabled: false,
319+
})).toBe(false);
320+
expect(codexAccountPickerEnabled({
321+
codexAccountNamespaces: {},
322+
codexAccountPickerEnabled: true,
323+
})).toBe(false);
324+
expect(codexAccountPickerEnabled({})).toBe(false);
325+
for (const malformed of [null, "false", 0, {}, []]) {
326+
expect(codexAccountPickerEnabled({
327+
codexAccountNamespaces: { desktop: "@main" },
328+
codexAccountPickerEnabled: malformed as never,
329+
})).toBe(false);
330+
}
331+
});
332+
309333
test("matches route and account namespaces exactly but provider namespaces case-insensitively", () => {
310334
const inherited = Object.create({ inherited: "account-id" }) as Record<string, string>;
311335
inherited.side = "side-account-id";

‎tests/config.test.ts‎

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ describe("opencodex config defaults", () => {
15161516
expect(isValidProviderName("constructor")).toBe(false);
15171517
});
15181518

1519-
test("persists an explicit Codex account selector map without enabling it by default", () => {
1519+
test("persists an explicit Codex account selector map without adding one to defaults", () => {
15201520
const selectors = {
15211521
desktop: "@main",
15221522
work: "work-account",
@@ -1531,6 +1531,94 @@ describe("opencodex config defaults", () => {
15311531
expect(Object.hasOwn(getDefaultConfig(), "codexAccountNamespaces")).toBe(false);
15321532
});
15331533

1534+
test("persists the optional picker override without adding it to defaults", () => {
1535+
for (const enabled of [true, false]) {
1536+
writeAccountNamespaceConfig({ desktop: "@main" }, { codexAccountPickerEnabled: enabled });
1537+
1538+
const diagnostics = readConfigDiagnostics();
1539+
expect(diagnostics.error).toBeNull();
1540+
expect(diagnostics.config.codexAccountPickerEnabled).toBe(enabled);
1541+
}
1542+
1543+
expect(Object.hasOwn(getDefaultConfig(), "codexAccountPickerEnabled")).toBe(false);
1544+
});
1545+
1546+
test("malformed persisted picker visibility fails closed without discarding accounts or providers", () => {
1547+
writeAccountNamespaceConfig({ desktop: "@main", side: "stored-account" }, {
1548+
codexAccountPickerEnabled: "yes",
1549+
codexAccounts: [
1550+
{ id: "main", email: "[email protected]", isMain: true },
1551+
{ id: "stored-account", email: "[email protected]", isMain: false },
1552+
],
1553+
});
1554+
1555+
const diagnostics = readConfigDiagnostics();
1556+
expect(diagnostics).toMatchObject({
1557+
source: "file",
1558+
error: null,
1559+
config: {
1560+
defaultProvider: "openai",
1561+
providers: { openai: { baseUrl: "https://chatgpt.com/backend-api/codex" } },
1562+
codexAccounts: [
1563+
{ id: "main", email: "[email protected]", isMain: true },
1564+
{ id: "stored-account", email: "[email protected]", isMain: false },
1565+
],
1566+
codexAccountNamespaces: { desktop: "@main", side: "stored-account" },
1567+
codexAccountPickerEnabled: false,
1568+
},
1569+
});
1570+
expect(diagnostics.warnings).toContain(
1571+
"codexAccountPickerEnabled ignored: expected a boolean",
1572+
);
1573+
expect(backupNames()).toEqual([]);
1574+
1575+
const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
1576+
try {
1577+
expect(loadConfig()).toMatchObject({
1578+
codexAccountPickerEnabled: false,
1579+
codexAccountNamespaces: { desktop: "@main", side: "stored-account" },
1580+
providers: { openai: { baseUrl: "https://chatgpt.com/backend-api/codex" } },
1581+
});
1582+
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("codexAccountPickerEnabled ignored"));
1583+
} finally {
1584+
warnSpy.mockRestore();
1585+
}
1586+
1587+
for (const invalid of [null, "false", 1]) {
1588+
expect(validateConfigCandidate({
1589+
...getDefaultConfig(),
1590+
codexAccountPickerEnabled: invalid,
1591+
})).toMatchObject({
1592+
ok: false,
1593+
error: expect.stringContaining("codexAccountPickerEnabled"),
1594+
});
1595+
}
1596+
1597+
const inherited = Object.assign(
1598+
Object.create({ codexAccountPickerEnabled: true }) as Record<string, unknown>,
1599+
getDefaultConfig(),
1600+
);
1601+
expect(validateConfigCandidate(inherited)).toMatchObject({
1602+
ok: false,
1603+
error: expect.stringContaining("own boolean data property"),
1604+
});
1605+
1606+
let getterCalls = 0;
1607+
const accessor = { ...getDefaultConfig() } as Record<string, unknown>;
1608+
Object.defineProperty(accessor, "codexAccountPickerEnabled", {
1609+
enumerable: true,
1610+
get() {
1611+
getterCalls += 1;
1612+
return true;
1613+
},
1614+
});
1615+
expect(validateConfigCandidate(accessor)).toMatchObject({
1616+
ok: false,
1617+
error: expect.stringContaining("own boolean data property"),
1618+
});
1619+
expect(getterCalls).toBe(0);
1620+
});
1621+
15341622
test("validates Claude Desktop profiles and Codex account selectors independently", () => {
15351623
const desktopProfile = {
15361624
version: 1,

‎tests/router.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ describe("routeModel registry effort defaults", () => {
130130
});
131131
expect(() => routeModel(config, "side/claude-opus-4-6"))
132132
.toThrow("only supports native OpenAI model ids");
133+
134+
config.codexAccountPickerEnabled = false;
135+
expect(routeModel(config, "side/gpt-5.5")).toMatchObject({
136+
providerName: "openai",
137+
modelId: "gpt-5.5",
138+
codexAccountMode: "pool",
139+
codexAccountId: "side-account-id",
140+
codexAccountNamespace: "side",
141+
provider: { authMode: "forward" },
142+
});
133143
});
134144

135145
test("requires an enabled canonical OpenAI forward provider before exact credential injection", () => {

0 commit comments

Comments
 (0)