GeezerVison is showing github.com — feat(codex): add account picker visibility setting · lidge-jun/opencodex@435ade0
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 |
|---|
@@ -1060,6 +1060,9 @@ const configSchema = z.object({ | 1060 | 1060 | // pool accounts. Warning emitted in loadConfig. | 1061 | 1061 | codexAccountPriorities: codexAccountPrioritiesSchema.optional().catch(undefined), | 1062 | 1062 | 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), | 1063 | 1066 | // Model ids excluded from the Grok Build managed block (dashboard switches). | 1064 | 1067 | grokExcludedModels: z.array(z.string()).optional(), | 1065 | 1068 | // Invalid values degrade to undefined ("auto") instead of failing the whole | @@ -1712,6 +1715,18 @@ function malformedNativeSubagentFieldWarning(field: NativeSubagentPersistedField | 1712 | 1715 | return `${field} ignored: expected ${expected}`; | 1713 | 1716 | } | 1714 | 1717 |
| | 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 | + | 1715 | 1730 | function nativeSubagentSyncDisabledReason(config: OcxConfig, rawParsed?: unknown): string | null { | 1716 | 1731 | if (config.syncCodexSubagentDefaults !== true) return null; | 1717 | 1732 | const malformed = malformedNativeSubagentFields(rawParsed); | @@ -1763,6 +1778,7 @@ export function loadConfig(): OcxConfig { | 1763 | 1778 | warnDegradedCodexAccountPriorities(parsed, config); | 1764 | 1779 | warnDegradedClaudeSubagentEffort(parsed); | 1765 | 1780 | warnDegradedNativeSubagentConfig(parsed, config); | | 1781 | + warnDegradedCodexAccountPicker(parsed); | 1766 | 1782 | return normalizeClaudeSubagentEffort(normalizeNativeSubagentSync(config, parsed), parsed); | 1767 | 1783 | } | 1768 | 1784 | // Schema validation failed — merge defaults into the raw object instead of | @@ -1783,6 +1799,7 @@ export function loadConfig(): OcxConfig { | 1783 | 1799 | warnDegradedCodexAccountPriorities(parsed, config); | 1784 | 1800 | warnDegradedClaudeSubagentEffort(parsed); | 1785 | 1801 | warnDegradedNativeSubagentConfig(parsed, config); | | 1802 | + warnDegradedCodexAccountPicker(parsed); | 1786 | 1803 | return normalizeClaudeSubagentEffort(normalizeNativeSubagentSync(config, parsed), parsed); | 1787 | 1804 | } | 1788 | 1805 | // Merge couldn't fix it — truly broken config | @@ -1832,6 +1849,8 @@ function validFileConfigDiagnostics(config: OcxConfig, rawParsed: unknown): Conf | 1832 | 1849 | warnings.push(`claudeCode.subagentEffort ignored: expected one of ${CLAUDE_SUBAGENT_EFFORTS.join(", ")}`); | 1833 | 1850 | } | 1834 | 1851 | warnings.push(...malformedNativeSubagentFields(rawParsed).map(malformedNativeSubagentFieldWarning)); | | 1852 | + const pickerWarning = malformedCodexAccountPickerWarning(rawParsed); | | 1853 | + if (pickerWarning) warnings.push(pickerWarning); | 1835 | 1854 | if (syncDisabledReason) { | 1836 | 1855 | warnings.push(`syncCodexSubagentDefaults ignored: ${syncDisabledReason}`); | 1837 | 1856 | } | @@ -1935,13 +1954,31 @@ function googleAntigravityStaticCatalogVersionError(value: unknown): string | nu | 1935 | 1954 | return "schema_invalid: googleAntigravityStaticCatalogVersion: must be 1 or omitted"; | 1936 | 1955 | } | 1937 | 1956 |
| | 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 | + | 1938 | 1974 | /** Validate an in-memory config candidate without touching disk. Used by headless CLI import/set. */ | 1939 | 1975 | export function validateConfigCandidate(value: unknown): { ok: true; config: OcxConfig } | { ok: false; error: string } { | 1940 | 1976 | const boundaryError = blankHostnameError(value) | 1941 | 1977 | ?? claudeSubagentEffortError(value) | 1942 | 1978 | ?? appOwnedMemoryBudgetError(value) | 1943 | 1979 | ?? googleAntigravityStaticCatalogVersionError(value) | 1944 | | - ?? codexAccountPrioritiesError(value); | | 1980 | + ?? codexAccountPrioritiesError(value) | | 1981 | + ?? codexAccountPickerEnabledError(value); | 1945 | 1982 | if (boundaryError) return { ok: false, error: boundaryError }; | 1946 | 1983 | const result = configSchema.safeParse(value); | 1947 | 1984 | 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 |
|---|
@@ -782,6 +782,11 @@ export interface OcxConfig { | 782 | 782 | * are intentionally separate from these selectors. | 783 | 783 | */ | 784 | 784 | 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; | 785 | 790 | /** Active pool account id for next session. undefined = main (passthrough as-is). */ | 786 | 791 | activeCodexAccountId?: string; | 787 | 792 | /** 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 |
|---|
@@ -1516,7 +1516,7 @@ describe("opencodex config defaults", () => { | 1516 | 1516 | expect(isValidProviderName("constructor")).toBe(false); | 1517 | 1517 | }); | 1518 | 1518 |
| 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", () => { | 1520 | 1520 | const selectors = { | 1521 | 1521 | desktop: "@main", | 1522 | 1522 | work: "work-account", | @@ -1531,6 +1531,94 @@ describe("opencodex config defaults", () => { | 1531 | 1531 | expect(Object.hasOwn(getDefaultConfig(), "codexAccountNamespaces")).toBe(false); | 1532 | 1532 | }); | 1533 | 1533 |
| | 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 | + | | 1551 | + | | 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 | + | | 1564 | + | | 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 | + | 1534 | 1622 | test("validates Claude Desktop profiles and Codex account selectors independently", () => { | 1535 | 1623 | const desktopProfile = { | 1536 | 1624 | 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", () => { | |
|