GeezerVison is showing github.com — feat(codex): add account picker visibility setting · lidge-jun/opencodex@a44af1f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/codex/account-namespaces.ts +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -147,3 +147,14 @@ export function codexAccountNamespaceEntries( | 147 | 147 | return Object.entries(config.codexAccountNamespaces ?? {}) | 148 | 148 | .map(([namespace, accountId]) => [namespace, normalizeCodexAccountNamespaceTarget(accountId)]); | 149 | 149 | } | | 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 | +} |
Collapse file Copy file name to clipboardExpand all lines: src/config.ts +38-1Lines changed: 38 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1024,6 +1024,9 @@ const configSchema = z.object({ | 1024 | 1024 | codexShimAutoRestore: z.boolean().optional(), | 1025 | 1025 | pausedCodexAccountIds: z.array(z.string().regex(/^[a-zA-Z0-9._-]{1,64}$/)).optional(), | 1026 | 1026 | codexAccountNamespaces: codexAccountNamespacesSchema.optional(), | | 1027 | + // A malformed hand edit must degrade to false without discarding providers, accounts, | | 1028 | + // or the exact selector map. Live writes remain strict. | | 1029 | + codexAccountPickerEnabled: z.boolean().optional().catch(false), | 1027 | 1030 | // Model ids excluded from the Grok Build managed block (dashboard switches). | 1028 | 1031 | grokExcludedModels: z.array(z.string()).optional(), | 1029 | 1032 | // Invalid values degrade to undefined ("auto") instead of failing the whole | @@ -1650,6 +1653,18 @@ function malformedNativeSubagentFieldWarning(field: NativeSubagentPersistedField | 1650 | 1653 | return `${field} ignored: expected ${expected}`; | 1651 | 1654 | } | 1652 | 1655 |
| | 1656 | +function malformedCodexAccountPickerWarning(rawParsed: unknown): string | null { | | 1657 | + const raw = rawConfigRecord(rawParsed); | | 1658 | + if (!raw || !Object.hasOwn(raw, "codexAccountPickerEnabled")) return null; | | 1659 | + if (typeof raw.codexAccountPickerEnabled === "boolean") return null; | | 1660 | + return "codexAccountPickerEnabled ignored: expected a boolean"; | | 1661 | +} | | 1662 | + | | 1663 | +function warnDegradedCodexAccountPicker(rawParsed: unknown): void { | | 1664 | + const warning = malformedCodexAccountPickerWarning(rawParsed); | | 1665 | + if (warning) console.warn(`⚠️ config.json ${warning}. Other settings were preserved.`); | | 1666 | +} | | 1667 | + | 1653 | 1668 | function nativeSubagentSyncDisabledReason(config: OcxConfig, rawParsed?: unknown): string | null { | 1654 | 1669 | if (config.syncCodexSubagentDefaults !== true) return null; | 1655 | 1670 | const malformed = malformedNativeSubagentFields(rawParsed); | @@ -1700,6 +1715,7 @@ export function loadConfig(): OcxConfig { | 1700 | 1715 | warnDegradedApiKeys(parsed, config); | 1701 | 1716 | warnDegradedClaudeSubagentEffort(parsed); | 1702 | 1717 | warnDegradedNativeSubagentConfig(parsed, config); | | 1718 | + warnDegradedCodexAccountPicker(parsed); | 1703 | 1719 | return normalizeClaudeSubagentEffort(normalizeNativeSubagentSync(config, parsed), parsed); | 1704 | 1720 | } | 1705 | 1721 | // Schema validation failed — merge defaults into the raw object instead of | @@ -1719,6 +1735,7 @@ export function loadConfig(): OcxConfig { | 1719 | 1735 | warnDegradedApiKeys(parsed, config); | 1720 | 1736 | warnDegradedClaudeSubagentEffort(parsed); | 1721 | 1737 | warnDegradedNativeSubagentConfig(parsed, config); | | 1738 | + warnDegradedCodexAccountPicker(parsed); | 1722 | 1739 | return normalizeClaudeSubagentEffort(normalizeNativeSubagentSync(config, parsed), parsed); | 1723 | 1740 | } | 1724 | 1741 | // Merge couldn't fix it — truly broken config | @@ -1767,6 +1784,8 @@ function validFileConfigDiagnostics(config: OcxConfig, rawParsed: unknown): Conf | 1767 | 1784 | warnings.push(`claudeCode.subagentEffort ignored: expected one of ${CLAUDE_SUBAGENT_EFFORTS.join(", ")}`); | 1768 | 1785 | } | 1769 | 1786 | warnings.push(...malformedNativeSubagentFields(rawParsed).map(malformedNativeSubagentFieldWarning)); | | 1787 | + const pickerWarning = malformedCodexAccountPickerWarning(rawParsed); | | 1788 | + if (pickerWarning) warnings.push(pickerWarning); | 1770 | 1789 | if (syncDisabledReason) { | 1771 | 1790 | warnings.push(`syncCodexSubagentDefaults ignored: ${syncDisabledReason}`); | 1772 | 1791 | } | @@ -1844,12 +1863,30 @@ function googleAntigravityStaticCatalogVersionError(value: unknown): string | nu | 1844 | 1863 | return "schema_invalid: googleAntigravityStaticCatalogVersion: must be 1 or omitted"; | 1845 | 1864 | } | 1846 | 1865 |
| | 1866 | +function codexAccountPickerEnabledError(value: unknown): string | null { | | 1867 | + const raw = rawConfigRecord(value); | | 1868 | + if (!raw) return null; | | 1869 | + const descriptor = Object.getOwnPropertyDescriptor(raw, "codexAccountPickerEnabled"); | | 1870 | + if (!descriptor) { | | 1871 | + return "codexAccountPickerEnabled" in raw | | 1872 | + ? "schema_invalid: codexAccountPickerEnabled: must be an own boolean data property or omitted" | | 1873 | + : null; | | 1874 | + } | | 1875 | + if (!("value" in descriptor)) { | | 1876 | + return "schema_invalid: codexAccountPickerEnabled: must be an own boolean data property or omitted"; | | 1877 | + } | | 1878 | + const enabled = descriptor.value; | | 1879 | + if (enabled === undefined || typeof enabled === "boolean") return null; | | 1880 | + return "schema_invalid: codexAccountPickerEnabled: must be a boolean or omitted"; | | 1881 | +} | | 1882 | + | 1847 | 1883 | /** Validate an in-memory config candidate without touching disk. Used by headless CLI import/set. */ | 1848 | 1884 | export function validateConfigCandidate(value: unknown): { ok: true; config: OcxConfig } | { ok: false; error: string } { | 1849 | 1885 | const boundaryError = blankHostnameError(value) | 1850 | 1886 | ?? claudeSubagentEffortError(value) | 1851 | 1887 | ?? appOwnedMemoryBudgetError(value) | 1852 | | - ?? googleAntigravityStaticCatalogVersionError(value); | | 1888 | + ?? googleAntigravityStaticCatalogVersionError(value) | | 1889 | + ?? codexAccountPickerEnabledError(value); | 1853 | 1890 | if (boundaryError) return { ok: false, error: boundaryError }; | 1854 | 1891 | const result = configSchema.safeParse(value); | 1855 | 1892 | if (result.success) return { ok: true, config: normalizeApiKeyIds(result.data as OcxConfig) }; | |
Collapse file Copy file name to clipboardExpand all lines: src/types.ts +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -768,6 +768,11 @@ export interface OcxConfig { | 768 | 768 | * are intentionally separate from these selectors. | 769 | 769 | */ | 770 | 770 | codexAccountNamespaces?: Record<string, string>; | | 771 | + /** | | 772 | + * Picker visibility override for account-qualified native models. When omitted, a non-empty | | 773 | + * selector map remains visible for compatibility with hand-written configurations. | | 774 | + */ | | 775 | + codexAccountPickerEnabled?: boolean; | 771 | 776 | /** Active pool account id for next session. undefined = main (passthrough as-is). */ | 772 | 777 | activeCodexAccountId?: string; | 773 | 778 | /** Auto-switch threshold (0-100). Default 80. 0 = disabled. */ | |
Collapse file Copy file name to clipboardExpand all lines: tests/codex-account-namespaces.test.ts +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,7 @@ import { | 12 | 12 | } from "../src/codex/account-namespace-match"; | 13 | 13 | import { | 14 | 14 | appendDefaultCodexAccountNamespace, | | 15 | + codexAccountPickerEnabled, | 15 | 16 | codexAccountNamespaceEntries, | 16 | 17 | defaultCodexAccountNamespaces, | 17 | 18 | isMainCodexAccountTarget, | @@ -306,6 +307,29 @@ describe("Codex account namespace foundations", () => { | 306 | 307 | })).toEqual({ "main-2": "@main", p454545: "main" }); | 307 | 308 | }); | 308 | 309 |
| | 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 | + | 309 | 333 | test("matches route and account namespaces exactly but provider namespaces case-insensitively", () => { | 310 | 334 | const inherited = Object.create({ inherited: "account-id" }) as Record<string, string>; | 311 | 335 | inherited.side = "side-account-id"; | |
Collapse file Copy file name to clipboardExpand all lines: tests/config.test.ts +89-1Lines changed: 89 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1477,7 +1477,7 @@ describe("opencodex config defaults", () => { | 1477 | 1477 | expect(isValidProviderName("constructor")).toBe(false); | 1478 | 1478 | }); | 1479 | 1479 |
| 1480 | | - test("persists an explicit Codex account selector map without enabling it by default", () => { | | 1480 | + test("persists an explicit Codex account selector map without adding one to defaults", () => { | 1481 | 1481 | const selectors = { | 1482 | 1482 | desktop: "@main", | 1483 | 1483 | work: "work-account", | @@ -1492,6 +1492,94 @@ describe("opencodex config defaults", () => { | 1492 | 1492 | expect(Object.hasOwn(getDefaultConfig(), "codexAccountNamespaces")).toBe(false); | 1493 | 1493 | }); | 1494 | 1494 |
| | 1495 | + test("persists the optional picker override without adding it to defaults", () => { | | 1496 | + for (const enabled of [true, false]) { | | 1497 | + writeAccountNamespaceConfig({ desktop: "@main" }, { codexAccountPickerEnabled: enabled }); | | 1498 | + | | 1499 | + const diagnostics = readConfigDiagnostics(); | | 1500 | + expect(diagnostics.error).toBeNull(); | | 1501 | + expect(diagnostics.config.codexAccountPickerEnabled).toBe(enabled); | | 1502 | + } | | 1503 | + | | 1504 | + expect(Object.hasOwn(getDefaultConfig(), "codexAccountPickerEnabled")).toBe(false); | | 1505 | + }); | | 1506 | + | | 1507 | + test("malformed persisted picker visibility fails closed without discarding accounts or providers", () => { | | 1508 | + writeAccountNamespaceConfig({ desktop: "@main", side: "stored-account" }, { | | 1509 | + codexAccountPickerEnabled: "yes", | | 1510 | + codexAccounts: [ | | 1511 | + | | 1512 | + | | 1513 | + ], | | 1514 | + }); | | 1515 | + | | 1516 | + const diagnostics = readConfigDiagnostics(); | | 1517 | + expect(diagnostics).toMatchObject({ | | 1518 | + source: "file", | | 1519 | + error: null, | | 1520 | + config: { | | 1521 | + defaultProvider: "openai", | | 1522 | + providers: { openai: { baseUrl: "https://chatgpt.com/backend-api/codex" } }, | | 1523 | + codexAccounts: [ | | 1524 | + | | 1525 | + | | 1526 | + ], | | 1527 | + codexAccountNamespaces: { desktop: "@main", side: "stored-account" }, | | 1528 | + codexAccountPickerEnabled: false, | | 1529 | + }, | | 1530 | + }); | | 1531 | + expect(diagnostics.warnings).toContain( | | 1532 | + "codexAccountPickerEnabled ignored: expected a boolean", | | 1533 | + ); | | 1534 | + expect(backupNames()).toEqual([]); | | 1535 | + | | 1536 | + const warnSpy = spyOn(console, "warn").mockImplementation(() => {}); | | 1537 | + try { | | 1538 | + expect(loadConfig()).toMatchObject({ | | 1539 | + codexAccountPickerEnabled: false, | | 1540 | + codexAccountNamespaces: { desktop: "@main", side: "stored-account" }, | | 1541 | + providers: { openai: { baseUrl: "https://chatgpt.com/backend-api/codex" } }, | | 1542 | + }); | | 1543 | + expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("codexAccountPickerEnabled ignored")); | | 1544 | + } finally { | | 1545 | + warnSpy.mockRestore(); | | 1546 | + } | | 1547 | + | | 1548 | + for (const invalid of [null, "false", 1]) { | | 1549 | + expect(validateConfigCandidate({ | | 1550 | + ...getDefaultConfig(), | | 1551 | + codexAccountPickerEnabled: invalid, | | 1552 | + })).toMatchObject({ | | 1553 | + ok: false, | | 1554 | + error: expect.stringContaining("codexAccountPickerEnabled"), | | 1555 | + }); | | 1556 | + } | | 1557 | + | | 1558 | + const inherited = Object.assign( | | 1559 | + Object.create({ codexAccountPickerEnabled: true }) as Record<string, unknown>, | | 1560 | + getDefaultConfig(), | | 1561 | + ); | | 1562 | + expect(validateConfigCandidate(inherited)).toMatchObject({ | | 1563 | + ok: false, | | 1564 | + error: expect.stringContaining("own boolean data property"), | | 1565 | + }); | | 1566 | + | | 1567 | + let getterCalls = 0; | | 1568 | + const accessor = { ...getDefaultConfig() } as Record<string, unknown>; | | 1569 | + Object.defineProperty(accessor, "codexAccountPickerEnabled", { | | 1570 | + enumerable: true, | | 1571 | + get() { | | 1572 | + getterCalls += 1; | | 1573 | + return true; | | 1574 | + }, | | 1575 | + }); | | 1576 | + expect(validateConfigCandidate(accessor)).toMatchObject({ | | 1577 | + ok: false, | | 1578 | + error: expect.stringContaining("own boolean data property"), | | 1579 | + }); | | 1580 | + expect(getterCalls).toBe(0); | | 1581 | + }); | | 1582 | + | 1495 | 1583 | test("validates Claude Desktop profiles and Codex account selectors independently", () => { | 1496 | 1584 | const desktopProfile = { | 1497 | 1585 | version: 1, | |
Collapse file Copy file name to clipboardExpand all lines: tests/router.test.ts +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -130,6 +130,16 @@ describe("routeModel registry effort defaults", () => { | 130 | 130 | }); | 131 | 131 | expect(() => routeModel(config, "side/claude-opus-4-6")) | 132 | 132 | .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 | + }); | 133 | 143 | }); | 134 | 144 |
| 135 | 145 | test("requires an enabled canonical OpenAI forward provider before exact credential injection", () => { | |
|