codex-multi-auth 2.1.13-beta.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +415 -415
  3. package/assets/codex-multi-auth-icon.svg +39 -39
  4. package/assets/readme-hero.svg +31 -31
  5. package/config/README.md +29 -29
  6. package/config/codex-legacy.json +571 -571
  7. package/config/codex-modern.json +258 -258
  8. package/config/minimal-codex.json +15 -15
  9. package/config/schema/config.schema.json +20 -20
  10. package/dist/lib/accounts.d.ts.map +1 -1
  11. package/dist/lib/accounts.js +30 -1
  12. package/dist/lib/accounts.js.map +1 -1
  13. package/dist/lib/auth/org-override.d.ts +19 -0
  14. package/dist/lib/auth/org-override.d.ts.map +1 -0
  15. package/dist/lib/auth/org-override.js +23 -0
  16. package/dist/lib/auth/org-override.js.map +1 -0
  17. package/dist/lib/circuit-breaker.d.ts +6 -0
  18. package/dist/lib/circuit-breaker.d.ts.map +1 -1
  19. package/dist/lib/circuit-breaker.js +8 -0
  20. package/dist/lib/circuit-breaker.js.map +1 -1
  21. package/dist/lib/codex-manager/account-manager-commands.d.ts +14 -0
  22. package/dist/lib/codex-manager/account-manager-commands.d.ts.map +1 -0
  23. package/dist/lib/codex-manager/account-manager-commands.js +43 -0
  24. package/dist/lib/codex-manager/account-manager-commands.js.map +1 -0
  25. package/dist/lib/codex-manager/commands/best.d.ts +1 -1
  26. package/dist/lib/codex-manager/commands/best.d.ts.map +1 -1
  27. package/dist/lib/codex-manager/commands/best.js +2 -1
  28. package/dist/lib/codex-manager/commands/best.js.map +1 -1
  29. package/dist/lib/codex-manager/commands/debug-bundle.d.ts +16 -0
  30. package/dist/lib/codex-manager/commands/debug-bundle.d.ts.map +1 -1
  31. package/dist/lib/codex-manager/commands/debug-bundle.js +80 -5
  32. package/dist/lib/codex-manager/commands/debug-bundle.js.map +1 -1
  33. package/dist/lib/codex-manager/commands/forecast.d.ts +1 -1
  34. package/dist/lib/codex-manager/commands/forecast.d.ts.map +1 -1
  35. package/dist/lib/codex-manager/commands/forecast.js +2 -1
  36. package/dist/lib/codex-manager/commands/forecast.js.map +1 -1
  37. package/dist/lib/codex-manager/commands/report.d.ts.map +1 -1
  38. package/dist/lib/codex-manager/commands/report.js +2 -2
  39. package/dist/lib/codex-manager/commands/report.js.map +1 -1
  40. package/dist/lib/codex-manager/commands/status.d.ts +2 -0
  41. package/dist/lib/codex-manager/commands/status.d.ts.map +1 -1
  42. package/dist/lib/codex-manager/commands/status.js +84 -25
  43. package/dist/lib/codex-manager/commands/status.js.map +1 -1
  44. package/dist/lib/codex-manager/commands/switch.d.ts.map +1 -1
  45. package/dist/lib/codex-manager/commands/switch.js +7 -0
  46. package/dist/lib/codex-manager/commands/switch.js.map +1 -1
  47. package/dist/lib/codex-manager/experimental-settings-prompt.d.ts.map +1 -1
  48. package/dist/lib/codex-manager/experimental-settings-prompt.js +13 -3
  49. package/dist/lib/codex-manager/experimental-settings-prompt.js.map +1 -1
  50. package/dist/lib/codex-manager/forecast-report-commands.d.ts.map +1 -1
  51. package/dist/lib/codex-manager/forecast-report-commands.js +3 -3
  52. package/dist/lib/codex-manager/forecast-report-commands.js.map +1 -1
  53. package/dist/lib/codex-manager/repair-commands.d.ts.map +1 -1
  54. package/dist/lib/codex-manager/repair-commands.js +11 -1
  55. package/dist/lib/codex-manager/repair-commands.js.map +1 -1
  56. package/dist/lib/codex-manager/settings-hub/experimental.d.ts.map +1 -1
  57. package/dist/lib/codex-manager/settings-hub/experimental.js +8 -0
  58. package/dist/lib/codex-manager/settings-hub/experimental.js.map +1 -1
  59. package/dist/lib/codex-manager.d.ts +3 -0
  60. package/dist/lib/codex-manager.d.ts.map +1 -1
  61. package/dist/lib/codex-manager.js +53 -65
  62. package/dist/lib/codex-manager.js.map +1 -1
  63. package/dist/lib/config.d.ts +26 -0
  64. package/dist/lib/config.d.ts.map +1 -1
  65. package/dist/lib/config.js +152 -5
  66. package/dist/lib/config.js.map +1 -1
  67. package/dist/lib/context-overflow.d.ts +7 -2
  68. package/dist/lib/context-overflow.d.ts.map +1 -1
  69. package/dist/lib/context-overflow.js +65 -47
  70. package/dist/lib/context-overflow.js.map +1 -1
  71. package/dist/lib/errors.d.ts +16 -0
  72. package/dist/lib/errors.d.ts.map +1 -1
  73. package/dist/lib/errors.js +23 -0
  74. package/dist/lib/errors.js.map +1 -1
  75. package/dist/lib/local-bridge.d.ts +8 -0
  76. package/dist/lib/local-bridge.d.ts.map +1 -1
  77. package/dist/lib/local-bridge.js +81 -7
  78. package/dist/lib/local-bridge.js.map +1 -1
  79. package/dist/lib/logger.d.ts +9 -1
  80. package/dist/lib/logger.d.ts.map +1 -1
  81. package/dist/lib/logger.js +104 -19
  82. package/dist/lib/logger.js.map +1 -1
  83. package/dist/lib/oauth-success.html +125 -125
  84. package/dist/lib/oc-chatgpt-orchestrator.d.ts +7 -1
  85. package/dist/lib/oc-chatgpt-orchestrator.d.ts.map +1 -1
  86. package/dist/lib/oc-chatgpt-orchestrator.js +68 -9
  87. package/dist/lib/oc-chatgpt-orchestrator.js.map +1 -1
  88. package/dist/lib/policy/runtime-policy.d.ts.map +1 -1
  89. package/dist/lib/policy/runtime-policy.js +15 -1
  90. package/dist/lib/policy/runtime-policy.js.map +1 -1
  91. package/dist/lib/prompts/codex-host-bridge.js +138 -138
  92. package/dist/lib/prompts/codex.d.ts.map +1 -1
  93. package/dist/lib/prompts/codex.js +203 -108
  94. package/dist/lib/prompts/codex.js.map +1 -1
  95. package/dist/lib/prompts/fetch-utils.d.ts +72 -0
  96. package/dist/lib/prompts/fetch-utils.d.ts.map +1 -0
  97. package/dist/lib/prompts/fetch-utils.js +165 -0
  98. package/dist/lib/prompts/fetch-utils.js.map +1 -0
  99. package/dist/lib/prompts/host-codex-prompt.d.ts.map +1 -1
  100. package/dist/lib/prompts/host-codex-prompt.js +24 -10
  101. package/dist/lib/prompts/host-codex-prompt.js.map +1 -1
  102. package/dist/lib/quota-cache.d.ts.map +1 -1
  103. package/dist/lib/quota-cache.js +10 -1
  104. package/dist/lib/quota-cache.js.map +1 -1
  105. package/dist/lib/quota-probe.d.ts +21 -0
  106. package/dist/lib/quota-probe.d.ts.map +1 -1
  107. package/dist/lib/quota-probe.js +39 -0
  108. package/dist/lib/quota-probe.js.map +1 -1
  109. package/dist/lib/quota-readiness.d.ts +3 -1
  110. package/dist/lib/quota-readiness.d.ts.map +1 -1
  111. package/dist/lib/quota-readiness.js +16 -3
  112. package/dist/lib/quota-readiness.js.map +1 -1
  113. package/dist/lib/recovery/storage.d.ts +7 -0
  114. package/dist/lib/recovery/storage.d.ts.map +1 -1
  115. package/dist/lib/recovery/storage.js +178 -10
  116. package/dist/lib/recovery/storage.js.map +1 -1
  117. package/dist/lib/refresh-lease.d.ts +1 -1
  118. package/dist/lib/refresh-lease.d.ts.map +1 -1
  119. package/dist/lib/refresh-lease.js +25 -3
  120. package/dist/lib/refresh-lease.js.map +1 -1
  121. package/dist/lib/refresh-queue.d.ts.map +1 -1
  122. package/dist/lib/refresh-queue.js +31 -17
  123. package/dist/lib/refresh-queue.js.map +1 -1
  124. package/dist/lib/request/fetch-helpers.d.ts +0 -5
  125. package/dist/lib/request/fetch-helpers.d.ts.map +1 -1
  126. package/dist/lib/request/fetch-helpers.js +36 -7
  127. package/dist/lib/request/fetch-helpers.js.map +1 -1
  128. package/dist/lib/rotation.d.ts +12 -0
  129. package/dist/lib/rotation.d.ts.map +1 -1
  130. package/dist/lib/rotation.js +36 -0
  131. package/dist/lib/rotation.js.map +1 -1
  132. package/dist/lib/runtime/account-check-types.d.ts +1 -0
  133. package/dist/lib/runtime/account-check-types.d.ts.map +1 -1
  134. package/dist/lib/runtime/account-check-types.js +1 -0
  135. package/dist/lib/runtime/account-check-types.js.map +1 -1
  136. package/dist/lib/runtime/account-check.d.ts.map +1 -1
  137. package/dist/lib/runtime/account-check.js +15 -4
  138. package/dist/lib/runtime/account-check.js.map +1 -1
  139. package/dist/lib/runtime/runtime-observability.d.ts.map +1 -1
  140. package/dist/lib/runtime/runtime-observability.js +24 -2
  141. package/dist/lib/runtime/runtime-observability.js.map +1 -1
  142. package/dist/lib/runtime-rotation-proxy.d.ts +3 -0
  143. package/dist/lib/runtime-rotation-proxy.d.ts.map +1 -1
  144. package/dist/lib/runtime-rotation-proxy.js +296 -21
  145. package/dist/lib/runtime-rotation-proxy.js.map +1 -1
  146. package/dist/lib/schemas.d.ts +2 -0
  147. package/dist/lib/schemas.d.ts.map +1 -1
  148. package/dist/lib/schemas.js +2 -0
  149. package/dist/lib/schemas.js.map +1 -1
  150. package/dist/lib/storage/account-clear.d.ts.map +1 -1
  151. package/dist/lib/storage/account-clear.js +4 -2
  152. package/dist/lib/storage/account-clear.js.map +1 -1
  153. package/dist/lib/storage/flagged-storage-io.d.ts.map +1 -1
  154. package/dist/lib/storage/flagged-storage-io.js +4 -1
  155. package/dist/lib/storage/flagged-storage-io.js.map +1 -1
  156. package/dist/lib/storage/import-export.d.ts.map +1 -1
  157. package/dist/lib/storage/import-export.js +29 -9
  158. package/dist/lib/storage/import-export.js.map +1 -1
  159. package/dist/lib/storage/paths.d.ts.map +1 -1
  160. package/dist/lib/storage/paths.js +93 -0
  161. package/dist/lib/storage/paths.js.map +1 -1
  162. package/dist/lib/storage/storage-parser.d.ts.map +1 -1
  163. package/dist/lib/storage/storage-parser.js +7 -1
  164. package/dist/lib/storage/storage-parser.js.map +1 -1
  165. package/dist/lib/storage.d.ts.map +1 -1
  166. package/dist/lib/storage.js +13 -9
  167. package/dist/lib/storage.js.map +1 -1
  168. package/dist/lib/table-formatter.d.ts.map +1 -1
  169. package/dist/lib/table-formatter.js +20 -2
  170. package/dist/lib/table-formatter.js.map +1 -1
  171. package/dist/lib/types.d.ts +7 -0
  172. package/dist/lib/types.d.ts.map +1 -1
  173. package/dist/lib/ui/auth-menu.d.ts.map +1 -1
  174. package/dist/lib/ui/auth-menu.js +8 -2
  175. package/dist/lib/ui/auth-menu.js.map +1 -1
  176. package/dist/lib/ui/display-width.d.ts +27 -0
  177. package/dist/lib/ui/display-width.d.ts.map +1 -0
  178. package/dist/lib/ui/display-width.js +194 -0
  179. package/dist/lib/ui/display-width.js.map +1 -0
  180. package/dist/lib/ui/select.d.ts +23 -0
  181. package/dist/lib/ui/select.d.ts.map +1 -1
  182. package/dist/lib/ui/select.js +64 -16
  183. package/dist/lib/ui/select.js.map +1 -1
  184. package/dist/lib/ui/theme.d.ts +13 -0
  185. package/dist/lib/ui/theme.d.ts.map +1 -1
  186. package/dist/lib/ui/theme.js +34 -1
  187. package/dist/lib/ui/theme.js.map +1 -1
  188. package/node_modules/@codex-ai/plugin/dist/index.d.ts +2 -2
  189. package/node_modules/@codex-ai/plugin/dist/index.js +2 -2
  190. package/node_modules/@codex-ai/plugin/dist/tool.d.ts +42 -42
  191. package/node_modules/@codex-ai/plugin/dist/tool.js +29 -29
  192. package/node_modules/@codex-ai/plugin/package.json +9 -9
  193. package/node_modules/@codex-ai/sdk/dist/index.d.ts +4 -0
  194. package/node_modules/@codex-ai/sdk/dist/index.js +2 -0
  195. package/node_modules/@codex-ai/sdk/package.json +8 -0
  196. package/package.json +196 -193
  197. package/scripts/codex-app-launcher.js +653 -653
  198. package/scripts/codex-app-router.js +322 -322
  199. package/scripts/codex-bin-resolver.js +254 -254
  200. package/scripts/codex-multi-auth.js +59 -59
  201. package/scripts/codex-routing.js +59 -56
  202. package/scripts/codex.js +4782 -4275
  203. package/scripts/install-codex-auth-utils.js +206 -206
  204. package/scripts/mcodex +117 -0
  205. package/scripts/postinstall.js +343 -343
  206. package/scripts/preuninstall.js +254 -254
  207. package/vendor/codex-ai-plugin/dist/index.d.ts +2 -2
  208. package/vendor/codex-ai-plugin/dist/index.js +2 -2
  209. package/vendor/codex-ai-plugin/dist/tool.d.ts +42 -42
  210. package/vendor/codex-ai-plugin/dist/tool.js +29 -29
  211. package/vendor/codex-ai-plugin/package.json +9 -9
  212. package/vendor/codex-ai-sdk/dist/index.d.ts +4 -4
  213. package/vendor/codex-ai-sdk/dist/index.js +2 -2
  214. package/vendor/codex-ai-sdk/package.json +8 -8
@@ -3,6 +3,7 @@ import { createInterface } from "node:readline/promises";
3
3
  import { extractAccountEmail, extractAccountId, formatAccountLabel, formatWaitTime, getAccountIdCandidates, resolveRequestAccountId, sanitizeEmail, selectBestAccountCandidate, shouldUpdateAccountIdFromToken, } from "./accounts.js";
4
4
  import { createAuthorizationFlow, exchangeAuthorizationCode, parseAuthorizationInput, redactOAuthUrlForLog, REDIRECT_URI, } from "./auth/auth.js";
5
5
  import { runDeviceAuthFlow } from "./auth/device-auth.js";
6
+ import { resolveOrgOverride } from "./auth/org-override.js";
6
7
  import { copyTextToClipboard, isBrowserLaunchSuppressed, openBrowserUrl, } from "./auth/browser.js";
7
8
  import { startLocalOAuthServer } from "./auth/server.js";
8
9
  import { promptAddAnotherAccount, promptLoginMode, } from "./cli.js";
@@ -10,6 +11,7 @@ import { loadCodexCliState } from "./codex-cli/state.js";
10
11
  import { setCodexCliActiveSelection } from "./codex-cli/writer.js";
11
12
  import { runBestCommand, } from "./codex-manager/commands/best.js";
12
13
  import { runAccountCommand } from "./codex-manager/commands/account.js";
14
+ import { ACCOUNT_MANAGER_COMMANDS } from "./codex-manager/account-manager-commands.js";
13
15
  import { runBudgetCommand } from "./codex-manager/commands/budget.js";
14
16
  import { runBridgeCommand } from "./codex-manager/commands/bridge.js";
15
17
  import { runCheckCommand } from "./codex-manager/commands/check.js";
@@ -49,7 +51,8 @@ import { formatRateLimitEntry as formatAccountRateLimitEntry, getRateLimitResetT
49
51
  import { buildQuotaEmailFallbackState, hasSafeQuotaEmailFallback, hasUniqueQuotaAccountId, isQuotaCacheEntryExhausted, normalizeQuotaAccountId, normalizeQuotaEmail, quotaLeftPercentFromUsed, } from "./quota-readiness.js";
50
52
  import { loadQuotaCache, saveQuotaCache, } from "./quota-cache.js";
51
53
  import { isDisplayCurrentAccount, readAppRuntimeHelperAccountSignal, resolveAccountCurrentMarkers, resolveRuntimeCurrentAccount, } from "./runtime/runtime-current-account.js";
52
- import { fetchCodexQuotaSnapshot, formatQuotaSnapshotLine, } from "./quota-probe.js";
54
+ import { fetchCodexQuotaSnapshot, formatQuotaSnapshotLine, CODEX_UNAVAILABLE_PROBE_NOTE, } from "./quota-probe.js";
55
+ import { isCodexUnavailableError } from "./errors.js";
53
56
  import { queuedRefresh } from "./refresh-queue.js";
54
57
  import { clearAccounts, findMatchingAccountIndex, formatStorageErrorHint, inspectStorageHealth, getLastAccountsSaveTimestamp, getNamedBackups, getStoragePath, loadAccounts, loadFlaggedAccounts, readAffinityGenerationFromDisk, restoreAccountsFromBackup, StorageError, saveAccounts, setStoragePath, withAccountStorageTransaction, } from "./storage.js";
55
58
  import { ANSI } from "./ui/ansi.js";
@@ -59,36 +62,6 @@ import { paintUiText, quotaToneFromLeftPercent } from "./ui/format.js";
59
62
  import { getUiRuntimeOptions } from "./ui/runtime.js";
60
63
  import { select } from "./ui/select.js";
61
64
  const log = createLogger("codex-manager");
62
- const ACCOUNT_MANAGER_COMMANDS = new Set([
63
- "login",
64
- "list",
65
- "status",
66
- "switch",
67
- "unpin",
68
- "workspace",
69
- "best",
70
- "check",
71
- "features",
72
- "usage",
73
- "verify-flagged",
74
- "verify",
75
- "forecast",
76
- "report",
77
- "fix",
78
- "doctor",
79
- "uninstall",
80
- "account",
81
- "budget",
82
- "bridge",
83
- "integrations",
84
- "models",
85
- "monitor",
86
- "rotation",
87
- "why-selected",
88
- "config",
89
- "init-config",
90
- "debug",
91
- ]);
92
65
  function stylePromptText(text, tone) {
93
66
  if (!output.isTTY)
94
67
  return text;
@@ -254,7 +227,10 @@ function styleQuotaSummary(summary) {
254
227
  });
255
228
  return joinStyledSegments(rendered);
256
229
  }
257
- function styleAccountDetailText(detail, fallbackTone = "muted") {
230
+ // Exported for unit tests: tone precedence (danger before warning) is
231
+ // security/UX-relevant — a failure whose text contains "unavailable" must
232
+ // render red, not be downgraded to yellow. See test/codex-manager-detail-tone.test.ts.
233
+ export function styleAccountDetailText(detail, fallbackTone = "muted") {
258
234
  const compact = collapseWhitespace(detail);
259
235
  if (!compact)
260
236
  return stylePromptText("", fallbackTone);
@@ -268,10 +244,14 @@ function styleAccountDetailText(detail, fallbackTone = "muted") {
268
244
  : /ok|working|succeeded|valid/i.test(prefix)
269
245
  ? "success"
270
246
  : fallbackTone;
271
- const suffixTone = /re-login|stale|warning|retry|fallback/i.test(suffix)
272
- ? "warning"
273
- : /failed|error/i.test(suffix)
274
- ? "danger"
247
+ const suffixTone =
248
+ // danger wins first: a real failure whose text happens to contain
249
+ // "unavailable"/"not available" (e.g. a 5xx "service not available")
250
+ // must render red, not be downgraded to a yellow warning.
251
+ /failed|error/i.test(suffix)
252
+ ? "danger"
253
+ : /re-login|stale|warning|retry|fallback|unavailable|not available/i.test(suffix)
254
+ ? "warning"
275
255
  : "muted";
276
256
  const chunks = [];
277
257
  if (prefix)
@@ -283,10 +263,10 @@ function styleAccountDetailText(detail, fallbackTone = "muted") {
283
263
  }
284
264
  if (/rate-limited/i.test(compact))
285
265
  return stylePromptText(compact, "danger");
286
- if (/re-login|stale|warning|fallback/i.test(compact))
287
- return stylePromptText(compact, "warning");
288
266
  if (/failed|error/i.test(compact))
289
267
  return stylePromptText(compact, "danger");
268
+ if (/re-login|stale|warning|fallback|unavailable|not available/i.test(compact))
269
+ return stylePromptText(compact, "warning");
290
270
  if (/ok|working|succeeded|valid/i.test(compact))
291
271
  return stylePromptText(compact, "success");
292
272
  return stylePromptText(compact, fallbackTone);
@@ -860,8 +840,17 @@ async function syncCodexCliActiveSelectionIfDrifted(storage) {
860
840
  return false;
861
841
  }
862
842
  }
863
- function resolveAccountSelection(tokens) {
864
- const override = (process.env.CODEX_AUTH_ACCOUNT_ID ?? "").trim();
843
+ /**
844
+ * Resolve the account-id selection for freshly-minted tokens.
845
+ *
846
+ * The org-override precedence (explicit `login --org` wins over the ambient
847
+ * CODEX_AUTH_ACCOUNT_ID env, for this call only) lives in the internal
848
+ * lib/auth/org-override.ts module so it can be unit-tested without exporting this
849
+ * CLI-internal function. Threading the org as a parameter avoids mutating
850
+ * process.env for the duration of a login, which raced on concurrent re-entry.
851
+ */
852
+ function resolveAccountSelection(tokens, orgOverride) {
853
+ const override = resolveOrgOverride(orgOverride);
865
854
  if (override) {
866
855
  return {
867
856
  ...tokens,
@@ -1660,9 +1649,15 @@ async function runHealthCheck(options = {}) {
1660
1649
  healthDetail = formatQuotaSnapshotForDashboard(snapshot, display);
1661
1650
  }
1662
1651
  catch (error) {
1663
- const message = normalizeFailureDetail(error instanceof Error ? error.message : String(error), undefined);
1664
1652
  warnings += 1;
1665
- healthDetail = `signed in and working (live check failed: ${message})`;
1653
+ if (isCodexUnavailableError(error)) {
1654
+ healthDetail =
1655
+ `signed in and working (${CODEX_UNAVAILABLE_PROBE_NOTE})`;
1656
+ }
1657
+ else {
1658
+ const message = normalizeFailureDetail(error instanceof Error ? error.message : String(error), undefined);
1659
+ healthDetail = `signed in and working (live check failed: ${message})`;
1660
+ }
1666
1661
  }
1667
1662
  }
1668
1663
  }
@@ -1738,9 +1733,15 @@ async function runHealthCheck(options = {}) {
1738
1733
  healthyMessage = formatQuotaSnapshotForDashboard(snapshot, display);
1739
1734
  }
1740
1735
  catch (error) {
1741
- const message = normalizeFailureDetail(error instanceof Error ? error.message : String(error), undefined);
1742
1736
  warnings += 1;
1743
- healthyMessage = `working now (live check failed: ${message})`;
1737
+ if (isCodexUnavailableError(error)) {
1738
+ healthyMessage =
1739
+ `working now (${CODEX_UNAVAILABLE_PROBE_NOTE})`;
1740
+ }
1741
+ else {
1742
+ const message = normalizeFailureDetail(error instanceof Error ? error.message : String(error), undefined);
1743
+ healthyMessage = `working now (live check failed: ${message})`;
1744
+ }
1744
1745
  }
1745
1746
  }
1746
1747
  }
@@ -2074,27 +2075,13 @@ async function runAuthLogin(args) {
2074
2075
  const loginOptions = parsedArgs.options;
2075
2076
  // `--org <id>` binds this login to a specific workspace/org so the same
2076
2077
  // email's personal vs business/team workspace can be registered on demand
2077
- // (issue #491). It reuses the CODEX_AUTH_ACCOUNT_ID override that every login
2078
- // resolver already honors. Scope it to this invocation and restore the prior
2079
- // value in a finally so a later login in the same process (menu re-entry, a
2080
- // reused test worker) is never silently bound to a stale org.
2081
- if (!loginOptions.org) {
2082
- return runAuthLoginFlow(loginOptions);
2083
- }
2084
- const previousAccountIdOverride = process.env.CODEX_AUTH_ACCOUNT_ID;
2085
- process.env.CODEX_AUTH_ACCOUNT_ID = loginOptions.org;
2086
- console.log(`Binding this login to workspace org id: ${loginOptions.org}`);
2087
- try {
2088
- return await runAuthLoginFlow(loginOptions);
2089
- }
2090
- finally {
2091
- if (previousAccountIdOverride === undefined) {
2092
- delete process.env.CODEX_AUTH_ACCOUNT_ID;
2093
- }
2094
- else {
2095
- process.env.CODEX_AUTH_ACCOUNT_ID = previousAccountIdOverride;
2096
- }
2078
+ // (issue #491). The org is threaded explicitly into resolveAccountSelection
2079
+ // (no process.env mutation), so concurrent re-entry (menu re-entry, a reused
2080
+ // test worker) can never bind a login to a stale org via a shared global.
2081
+ if (loginOptions.org) {
2082
+ console.log(`Binding this login to workspace org id: ${loginOptions.org}`);
2097
2083
  }
2084
+ return runAuthLoginFlow(loginOptions);
2098
2085
  }
2099
2086
  async function runAuthLoginFlow(loginOptions) {
2100
2087
  setStoragePath(null);
@@ -2368,7 +2355,7 @@ async function runAuthLoginFlow(loginOptions) {
2368
2355
  console.error(`Login failed: ${tokenResult.message ?? tokenResult.reason ?? "unknown error"}`);
2369
2356
  return 1;
2370
2357
  }
2371
- const resolved = resolveAccountSelection(tokenResult);
2358
+ const resolved = resolveAccountSelection(tokenResult, loginOptions.org);
2372
2359
  await persistAccountPool([resolved], false);
2373
2360
  await syncSelectionToCodex(resolved);
2374
2361
  const latestStorage = await loadAccounts();
@@ -2688,6 +2675,7 @@ export async function runCodexMultiAuthCli(rawArgs) {
2688
2675
  .catch(() => null),
2689
2676
  loadAppHelperStatus: readAppRuntimeHelperAccountSignal,
2690
2677
  loadQuotaCache,
2678
+ json: rest.includes("--json") || rest.includes("-j"),
2691
2679
  });
2692
2680
  }
2693
2681
  if (command === "switch") {