codex-multi-auth 2.3.0-beta.1 → 2.3.0-beta.2

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 (460) hide show
  1. package/README.md +4 -4
  2. package/config/schema/config.schema.json +268 -21
  3. package/dist/index.js +0 -1
  4. package/dist/lib/account-policy.js +0 -1
  5. package/dist/lib/accounts/rate-limits.js +0 -1
  6. package/dist/lib/accounts.d.ts +3 -8
  7. package/dist/lib/accounts.d.ts.map +1 -1
  8. package/dist/lib/accounts.js +2 -3
  9. package/dist/lib/audit.js +0 -1
  10. package/dist/lib/auth/auth.js +0 -1
  11. package/dist/lib/auth/browser.js +0 -1
  12. package/dist/lib/auth/device-auth.js +0 -1
  13. package/dist/lib/auth/index.js +0 -1
  14. package/dist/lib/auth/org-override.js +0 -1
  15. package/dist/lib/auth/server.js +0 -1
  16. package/dist/lib/auth/token-utils.js +0 -1
  17. package/dist/lib/auth-rate-limit.js +0 -1
  18. package/dist/lib/budget-guard.js +0 -1
  19. package/dist/lib/capability-policy.js +0 -1
  20. package/dist/lib/circuit-breaker.js +0 -1
  21. package/dist/lib/cli.js +1 -2
  22. package/dist/lib/codex-cli/index.js +0 -1
  23. package/dist/lib/codex-cli/observability.js +0 -1
  24. package/dist/lib/codex-cli/state.js +0 -1
  25. package/dist/lib/codex-cli/sync.d.ts +2 -2
  26. package/dist/lib/codex-cli/sync.d.ts.map +1 -1
  27. package/dist/lib/codex-cli/sync.js +1 -2
  28. package/dist/lib/codex-cli/writer.js +0 -1
  29. package/dist/lib/codex-manager/account-credentials.d.ts +13 -0
  30. package/dist/lib/codex-manager/account-credentials.d.ts.map +1 -0
  31. package/dist/lib/codex-manager/account-credentials.js +55 -0
  32. package/dist/lib/codex-manager/account-manager-commands.js +0 -1
  33. package/dist/lib/codex-manager/account-pool-write.d.ts +1 -1
  34. package/dist/lib/codex-manager/account-pool-write.d.ts.map +1 -1
  35. package/dist/lib/codex-manager/account-pool-write.js +0 -1
  36. package/dist/lib/codex-manager/backend-category-entry.js +0 -1
  37. package/dist/lib/codex-manager/backend-category-helpers.js +0 -1
  38. package/dist/lib/codex-manager/backend-category-prompt.js +0 -1
  39. package/dist/lib/codex-manager/backend-settings-controller.js +0 -1
  40. package/dist/lib/codex-manager/backend-settings-entry.js +0 -1
  41. package/dist/lib/codex-manager/backend-settings-helpers.js +0 -1
  42. package/dist/lib/codex-manager/backend-settings-prompt.js +0 -1
  43. package/dist/lib/codex-manager/backend-settings-schema.js +0 -1
  44. package/dist/lib/codex-manager/behavior-settings-panel.d.ts +1 -1
  45. package/dist/lib/codex-manager/behavior-settings-panel.d.ts.map +1 -1
  46. package/dist/lib/codex-manager/behavior-settings-panel.js +0 -1
  47. package/dist/lib/codex-manager/commands/account.js +0 -1
  48. package/dist/lib/codex-manager/commands/best.d.ts +8 -0
  49. package/dist/lib/codex-manager/commands/best.d.ts.map +1 -1
  50. package/dist/lib/codex-manager/commands/best.js +64 -1
  51. package/dist/lib/codex-manager/commands/bridge.js +0 -1
  52. package/dist/lib/codex-manager/commands/budget.js +0 -1
  53. package/dist/lib/codex-manager/commands/check.js +0 -1
  54. package/dist/lib/codex-manager/commands/config-explain.js +0 -1
  55. package/dist/lib/codex-manager/commands/debug-bundle.js +0 -1
  56. package/dist/lib/codex-manager/commands/forecast.js +0 -1
  57. package/dist/lib/codex-manager/commands/init-config.js +0 -1
  58. package/dist/lib/codex-manager/commands/integrations.js +0 -1
  59. package/dist/lib/codex-manager/commands/models.js +0 -1
  60. package/dist/lib/codex-manager/commands/monitor.js +0 -1
  61. package/dist/lib/codex-manager/commands/report.js +0 -1
  62. package/dist/lib/codex-manager/commands/rotation.d.ts.map +1 -1
  63. package/dist/lib/codex-manager/commands/rotation.js +1 -4
  64. package/dist/lib/codex-manager/commands/status.js +0 -1
  65. package/dist/lib/codex-manager/commands/switch.js +0 -1
  66. package/dist/lib/codex-manager/commands/uninstall.d.ts.map +1 -1
  67. package/dist/lib/codex-manager/commands/uninstall.js +2 -33
  68. package/dist/lib/codex-manager/commands/unpin.js +0 -1
  69. package/dist/lib/codex-manager/commands/usage.js +0 -1
  70. package/dist/lib/codex-manager/commands/verify.js +0 -1
  71. package/dist/lib/codex-manager/commands/why-selected.js +0 -1
  72. package/dist/lib/codex-manager/commands/workspace.js +0 -1
  73. package/dist/lib/codex-manager/dashboard-display-panel.d.ts +1 -1
  74. package/dist/lib/codex-manager/dashboard-display-panel.d.ts.map +1 -1
  75. package/dist/lib/codex-manager/dashboard-display-panel.js +0 -1
  76. package/dist/lib/codex-manager/dashboard-formatters.js +0 -1
  77. package/dist/lib/codex-manager/dashboard-settings-controller.js +0 -1
  78. package/dist/lib/codex-manager/dashboard-settings-data.js +0 -1
  79. package/dist/lib/codex-manager/dashboard-settings-entry.js +0 -1
  80. package/dist/lib/codex-manager/experimental-settings-entry.js +0 -1
  81. package/dist/lib/codex-manager/experimental-settings-prompt.js +0 -1
  82. package/dist/lib/codex-manager/experimental-settings-schema.js +1 -2
  83. package/dist/lib/codex-manager/experimental-sync-target-entry.js +0 -1
  84. package/dist/lib/codex-manager/experimental-sync-target.js +0 -1
  85. package/dist/lib/codex-manager/forecast-report-commands.js +0 -1
  86. package/dist/lib/codex-manager/forecast-report-shared.d.ts +2 -2
  87. package/dist/lib/codex-manager/forecast-report-shared.d.ts.map +1 -1
  88. package/dist/lib/codex-manager/forecast-report-shared.js +5 -21
  89. package/dist/lib/codex-manager/formatters/account-formatters.d.ts +11 -0
  90. package/dist/lib/codex-manager/formatters/account-formatters.d.ts.map +1 -0
  91. package/dist/lib/codex-manager/formatters/account-formatters.js +79 -0
  92. package/dist/lib/codex-manager/formatters/index.d.ts +5 -0
  93. package/dist/lib/codex-manager/formatters/index.d.ts.map +1 -0
  94. package/dist/lib/codex-manager/formatters/index.js +4 -0
  95. package/dist/lib/codex-manager/formatters/model-formatters.d.ts +12 -0
  96. package/dist/lib/codex-manager/formatters/model-formatters.d.ts.map +1 -0
  97. package/dist/lib/codex-manager/formatters/model-formatters.js +23 -0
  98. package/dist/lib/codex-manager/formatters/quota-formatters.d.ts +11 -0
  99. package/dist/lib/codex-manager/formatters/quota-formatters.d.ts.map +1 -0
  100. package/dist/lib/codex-manager/formatters/quota-formatters.js +104 -0
  101. package/dist/lib/codex-manager/formatters/text-style.d.ts +14 -0
  102. package/dist/lib/codex-manager/formatters/text-style.d.ts.map +1 -0
  103. package/dist/lib/codex-manager/formatters/text-style.js +111 -0
  104. package/dist/lib/codex-manager/health-check.d.ts +14 -0
  105. package/dist/lib/codex-manager/health-check.d.ts.map +1 -0
  106. package/dist/lib/codex-manager/health-check.js +278 -0
  107. package/dist/lib/codex-manager/help.js +0 -1
  108. package/dist/lib/codex-manager/login-action-panel.d.ts +4 -0
  109. package/dist/lib/codex-manager/login-action-panel.d.ts.map +1 -0
  110. package/dist/lib/codex-manager/login-action-panel.js +238 -0
  111. package/dist/lib/codex-manager/login-flow.d.ts +17 -0
  112. package/dist/lib/codex-manager/login-flow.d.ts.map +1 -0
  113. package/dist/lib/codex-manager/login-flow.js +387 -0
  114. package/dist/lib/codex-manager/login-menu-actions.d.ts +20 -0
  115. package/dist/lib/codex-manager/login-menu-actions.d.ts.map +1 -0
  116. package/dist/lib/codex-manager/login-menu-actions.js +303 -0
  117. package/dist/lib/codex-manager/login-menu-data.d.ts +19 -0
  118. package/dist/lib/codex-manager/login-menu-data.d.ts.map +1 -0
  119. package/dist/lib/codex-manager/login-menu-data.js +378 -0
  120. package/dist/lib/codex-manager/login-oauth.d.ts +55 -0
  121. package/dist/lib/codex-manager/login-oauth.d.ts.map +1 -0
  122. package/dist/lib/codex-manager/login-oauth.js +345 -0
  123. package/dist/lib/codex-manager/manual-callback.js +0 -1
  124. package/dist/lib/codex-manager/persist-selected-account.d.ts +24 -0
  125. package/dist/lib/codex-manager/persist-selected-account.d.ts.map +1 -0
  126. package/dist/lib/codex-manager/persist-selected-account.js +107 -0
  127. package/dist/lib/codex-manager/quota-cache-helpers.d.ts +18 -0
  128. package/dist/lib/codex-manager/quota-cache-helpers.d.ts.map +1 -0
  129. package/dist/lib/codex-manager/quota-cache-helpers.js +112 -0
  130. package/dist/lib/codex-manager/rate-limit-markers.js +0 -1
  131. package/dist/lib/codex-manager/repair-commands.js +0 -1
  132. package/dist/lib/codex-manager/settings-hub/backend.js +1 -2
  133. package/dist/lib/codex-manager/settings-hub/dashboard.js +1 -2
  134. package/dist/lib/codex-manager/settings-hub/experimental.js +1 -2
  135. package/dist/lib/codex-manager/settings-hub/index.js +1 -2
  136. package/dist/lib/codex-manager/settings-hub/shared.js +0 -1
  137. package/dist/lib/codex-manager/settings-hub-entry.js +0 -1
  138. package/dist/lib/codex-manager/settings-hub-menu.js +0 -1
  139. package/dist/lib/codex-manager/settings-hub-prompt.js +0 -1
  140. package/dist/lib/codex-manager/settings-hub.js +0 -1
  141. package/dist/lib/codex-manager/settings-panels.js +0 -1
  142. package/dist/lib/codex-manager/settings-persist-utils.js +0 -1
  143. package/dist/lib/codex-manager/settings-preview.js +0 -1
  144. package/dist/lib/codex-manager/settings-write-queue.js +0 -1
  145. package/dist/lib/codex-manager/statusline-order.js +0 -1
  146. package/dist/lib/codex-manager/statusline-settings-panel.d.ts +1 -1
  147. package/dist/lib/codex-manager/statusline-settings-panel.d.ts.map +1 -1
  148. package/dist/lib/codex-manager/statusline-settings-panel.js +0 -1
  149. package/dist/lib/codex-manager/theme-settings-panel.d.ts +1 -1
  150. package/dist/lib/codex-manager/theme-settings-panel.d.ts.map +1 -1
  151. package/dist/lib/codex-manager/theme-settings-panel.js +0 -1
  152. package/dist/lib/codex-manager/unified-settings-controller.js +0 -1
  153. package/dist/lib/codex-manager/unified-settings-entry.js +0 -1
  154. package/dist/lib/codex-manager.d.ts +2 -4
  155. package/dist/lib/codex-manager.d.ts.map +1 -1
  156. package/dist/lib/codex-manager.js +219 -2570
  157. package/dist/lib/config-schema.d.ts +32 -0
  158. package/dist/lib/config-schema.d.ts.map +1 -0
  159. package/dist/lib/config-schema.js +96 -0
  160. package/dist/lib/config.d.ts.map +1 -1
  161. package/dist/lib/config.js +60 -104
  162. package/dist/lib/constants.js +0 -1
  163. package/dist/lib/context-overflow.js +0 -1
  164. package/dist/lib/dashboard-settings.js +0 -1
  165. package/dist/lib/entitlement-cache.js +0 -1
  166. package/dist/lib/env-parsing.js +0 -1
  167. package/dist/lib/errors.js +0 -1
  168. package/dist/lib/forecast.js +0 -1
  169. package/dist/lib/fs-retry.d.ts +46 -0
  170. package/dist/lib/fs-retry.d.ts.map +1 -1
  171. package/dist/lib/fs-retry.js +74 -6
  172. package/dist/lib/health.js +0 -1
  173. package/dist/lib/index.js +0 -1
  174. package/dist/lib/integration-generators.js +0 -1
  175. package/dist/lib/live-account-sync.js +0 -1
  176. package/dist/lib/local-bridge.js +0 -1
  177. package/dist/lib/local-client-tokens.js +0 -1
  178. package/dist/lib/logger.js +0 -1
  179. package/dist/lib/model-capability-matrix.js +0 -1
  180. package/dist/lib/named-backup-export.js +0 -1
  181. package/dist/lib/oc-chatgpt-import-adapter.js +0 -1
  182. package/dist/lib/oc-chatgpt-orchestrator.js +0 -1
  183. package/dist/lib/oc-chatgpt-target-detection.js +0 -1
  184. package/dist/lib/parallel-probe.js +0 -1
  185. package/dist/lib/policy/runtime-policy.js +0 -1
  186. package/dist/lib/preemptive-quota-scheduler.js +0 -1
  187. package/dist/lib/proactive-refresh.js +0 -1
  188. package/dist/lib/prompts/codex-host-bridge.js +0 -1
  189. package/dist/lib/prompts/codex.d.ts +3 -11
  190. package/dist/lib/prompts/codex.d.ts.map +1 -1
  191. package/dist/lib/prompts/codex.js +4 -12
  192. package/dist/lib/prompts/fetch-utils.js +0 -1
  193. package/dist/lib/prompts/host-codex-prompt.js +0 -1
  194. package/dist/lib/quota-cache.d.ts.map +1 -1
  195. package/dist/lib/quota-cache.js +15 -43
  196. package/dist/lib/quota-probe.js +0 -1
  197. package/dist/lib/quota-readiness.js +0 -1
  198. package/dist/lib/recovery/constants.js +0 -1
  199. package/dist/lib/recovery/index.js +0 -1
  200. package/dist/lib/recovery/storage.d.ts.map +1 -1
  201. package/dist/lib/recovery/storage.js +30 -51
  202. package/dist/lib/recovery/storage.js.map +1 -1
  203. package/dist/lib/recovery/types.js +0 -1
  204. package/dist/lib/recovery.js +0 -1
  205. package/dist/lib/refresh-guardian.js +0 -1
  206. package/dist/lib/refresh-lease.d.ts.map +1 -1
  207. package/dist/lib/refresh-lease.js +1 -4
  208. package/dist/lib/refresh-queue.js +0 -1
  209. package/dist/lib/request/error-classification.d.ts +75 -0
  210. package/dist/lib/request/error-classification.d.ts.map +1 -0
  211. package/dist/lib/request/error-classification.js +295 -0
  212. package/dist/lib/request/failover-config.js +0 -1
  213. package/dist/lib/request/failure-policy.js +0 -1
  214. package/dist/lib/request/fetch-helpers.d.ts +10 -114
  215. package/dist/lib/request/fetch-helpers.d.ts.map +1 -1
  216. package/dist/lib/request/fetch-helpers.js +7 -589
  217. package/dist/lib/request/headers.d.ts +33 -0
  218. package/dist/lib/request/headers.d.ts.map +1 -0
  219. package/dist/lib/request/headers.js +64 -0
  220. package/dist/lib/request/helpers/input-utils.js +0 -1
  221. package/dist/lib/request/helpers/model-map.d.ts +10 -0
  222. package/dist/lib/request/helpers/model-map.d.ts.map +1 -1
  223. package/dist/lib/request/helpers/model-map.js +11 -1
  224. package/dist/lib/request/helpers/tool-utils.js +0 -1
  225. package/dist/lib/request/index.js +0 -1
  226. package/dist/lib/request/rate-limit-backoff.js +0 -1
  227. package/dist/lib/request/rate-limit-decision.d.ts +28 -0
  228. package/dist/lib/request/rate-limit-decision.d.ts.map +1 -0
  229. package/dist/lib/request/rate-limit-decision.js +191 -0
  230. package/dist/lib/request/request-attempt-budget.js +0 -1
  231. package/dist/lib/request/request-init.js +0 -1
  232. package/dist/lib/request/request-resilience.js +0 -1
  233. package/dist/lib/request/request-transformer.js +0 -1
  234. package/dist/lib/request/response-compaction.js +0 -1
  235. package/dist/lib/request/response-handler.js +0 -1
  236. package/dist/lib/request/response-metadata.js +0 -1
  237. package/dist/lib/request/stream-failover-runtime.d.ts +8 -0
  238. package/dist/lib/request/stream-failover-runtime.d.ts.map +1 -0
  239. package/dist/lib/request/stream-failover-runtime.js +149 -0
  240. package/dist/lib/request/stream-failover.js +0 -1
  241. package/dist/lib/request/token-refresh.d.ts +30 -0
  242. package/dist/lib/request/token-refresh.d.ts.map +1 -0
  243. package/dist/lib/request/token-refresh.js +116 -0
  244. package/dist/lib/request/url-rewriting.d.ts +24 -0
  245. package/dist/lib/request/url-rewriting.d.ts.map +1 -0
  246. package/dist/lib/request/url-rewriting.js +153 -0
  247. package/dist/lib/request/wait-utils.js +0 -1
  248. package/dist/lib/rotation.d.ts +1 -1
  249. package/dist/lib/rotation.d.ts.map +1 -1
  250. package/dist/lib/rotation.js +0 -1
  251. package/dist/lib/routing-mutex.js +0 -1
  252. package/dist/lib/routing-profiles.js +0 -1
  253. package/dist/lib/runtime/account-check-helpers.js +0 -1
  254. package/dist/lib/runtime/account-check-types.js +0 -1
  255. package/dist/lib/runtime/account-check.js +0 -1
  256. package/dist/lib/runtime/account-health-check.js +0 -1
  257. package/dist/lib/runtime/account-manager-cache-entry.js +0 -1
  258. package/dist/lib/runtime/account-manager-cache.js +0 -1
  259. package/dist/lib/runtime/account-pool.js +0 -1
  260. package/dist/lib/runtime/account-scope.js +0 -1
  261. package/dist/lib/runtime/account-select-event.js +0 -1
  262. package/dist/lib/runtime/account-selection.js +0 -1
  263. package/dist/lib/runtime/account-state.js +0 -1
  264. package/dist/lib/runtime/account-status.js +0 -1
  265. package/dist/lib/runtime/account-storage-scope-entry.js +0 -1
  266. package/dist/lib/runtime/app-bind.js +0 -1
  267. package/dist/lib/runtime/auth-facade.js +0 -1
  268. package/dist/lib/runtime/browser-oauth-flow.js +0 -1
  269. package/dist/lib/runtime/capability-boost.js +0 -1
  270. package/dist/lib/runtime/config-toml.js +0 -1
  271. package/dist/lib/runtime/event-handler.js +0 -1
  272. package/dist/lib/runtime/first-run.d.ts +80 -0
  273. package/dist/lib/runtime/first-run.d.ts.map +1 -0
  274. package/dist/lib/runtime/first-run.js +327 -0
  275. package/dist/lib/runtime/flagged-verify-types.js +0 -1
  276. package/dist/lib/runtime/hydrate-emails.js +0 -1
  277. package/dist/lib/runtime/live-sync-entry.js +0 -1
  278. package/dist/lib/runtime/live-sync.js +0 -1
  279. package/dist/lib/runtime/loader-setup.js +0 -1
  280. package/dist/lib/runtime/login-menu-accounts.js +0 -1
  281. package/dist/lib/runtime/manual-oauth-flow.js +0 -1
  282. package/dist/lib/runtime/oauth-browser-flow.js +0 -1
  283. package/dist/lib/runtime/preemptive-quota.js +0 -1
  284. package/dist/lib/runtime/quota-headers.js +0 -1
  285. package/dist/lib/runtime/quota-probe.js +0 -1
  286. package/dist/lib/runtime/quota-settings.js +0 -1
  287. package/dist/lib/runtime/refresh-guardian-entry.js +0 -1
  288. package/dist/lib/runtime/refresh-guardian.js +0 -1
  289. package/dist/lib/runtime/request-init.js +0 -1
  290. package/dist/lib/runtime/rotation-account-selection.d.ts +38 -0
  291. package/dist/lib/runtime/rotation-account-selection.d.ts.map +1 -0
  292. package/dist/lib/runtime/rotation-account-selection.js +172 -0
  293. package/dist/lib/runtime/rotation-proxy-state.d.ts +54 -0
  294. package/dist/lib/runtime/rotation-proxy-state.d.ts.map +1 -0
  295. package/dist/lib/runtime/rotation-proxy-state.js +56 -0
  296. package/dist/lib/runtime/rotation-server-types.d.ts +57 -0
  297. package/dist/lib/runtime/rotation-server-types.d.ts.map +1 -0
  298. package/dist/lib/runtime/rotation-server-types.js +1 -0
  299. package/dist/lib/runtime/rotation-storage-meta.d.ts +40 -0
  300. package/dist/lib/runtime/rotation-storage-meta.d.ts.map +1 -0
  301. package/dist/lib/runtime/rotation-storage-meta.js +143 -0
  302. package/dist/lib/runtime/rotation-token-refresh.d.ts +25 -0
  303. package/dist/lib/runtime/rotation-token-refresh.d.ts.map +1 -0
  304. package/dist/lib/runtime/rotation-token-refresh.js +99 -0
  305. package/dist/lib/runtime/runtime-current-account.d.ts.map +1 -1
  306. package/dist/lib/runtime/runtime-current-account.js +1 -4
  307. package/dist/lib/runtime/runtime-observability.js +0 -1
  308. package/dist/lib/runtime/runtime-services.js +0 -1
  309. package/dist/lib/runtime/session-affinity-entry.js +0 -1
  310. package/dist/lib/runtime/session-affinity.js +0 -1
  311. package/dist/lib/runtime/session-recovery.js +0 -1
  312. package/dist/lib/runtime/status-marker.js +0 -1
  313. package/dist/lib/runtime/storage-scope.js +0 -1
  314. package/dist/lib/runtime/toast.js +0 -1
  315. package/dist/lib/runtime/ui-runtime-entry.js +0 -1
  316. package/dist/lib/runtime/ui-runtime.js +0 -1
  317. package/dist/lib/runtime/verify-flagged.js +0 -1
  318. package/dist/lib/runtime-constants.js +0 -1
  319. package/dist/lib/runtime-paths.js +0 -1
  320. package/dist/lib/runtime-rotation-proxy.d.ts +7 -124
  321. package/dist/lib/runtime-rotation-proxy.d.ts.map +1 -1
  322. package/dist/lib/runtime-rotation-proxy.js +614 -1353
  323. package/dist/lib/schemas.d.ts +3 -3
  324. package/dist/lib/schemas.js +1 -2
  325. package/dist/lib/session-affinity.js +0 -1
  326. package/dist/lib/shutdown.js +0 -1
  327. package/dist/lib/storage/account-clear-entry.js +0 -1
  328. package/dist/lib/storage/account-clear.js +0 -1
  329. package/dist/lib/storage/account-match-utils.js +0 -1
  330. package/dist/lib/storage/account-persistence.d.ts +1 -1
  331. package/dist/lib/storage/account-persistence.d.ts.map +1 -1
  332. package/dist/lib/storage/account-persistence.js +0 -1
  333. package/dist/lib/storage/account-port.d.ts +1 -1
  334. package/dist/lib/storage/account-port.d.ts.map +1 -1
  335. package/dist/lib/storage/account-port.js +0 -1
  336. package/dist/lib/storage/account-save-entry.d.ts +1 -1
  337. package/dist/lib/storage/account-save-entry.d.ts.map +1 -1
  338. package/dist/lib/storage/account-save-entry.js +0 -1
  339. package/dist/lib/storage/account-save.d.ts +1 -1
  340. package/dist/lib/storage/account-save.d.ts.map +1 -1
  341. package/dist/lib/storage/account-save.js +0 -1
  342. package/dist/lib/storage/account-snapshot.js +0 -1
  343. package/dist/lib/storage/backup-metadata-builder.d.ts +1 -1
  344. package/dist/lib/storage/backup-metadata-builder.d.ts.map +1 -1
  345. package/dist/lib/storage/backup-metadata-builder.js +0 -1
  346. package/dist/lib/storage/backup-metadata.d.ts +13 -0
  347. package/dist/lib/storage/backup-metadata.d.ts.map +1 -1
  348. package/dist/lib/storage/backup-metadata.js +0 -1
  349. package/dist/lib/storage/backup-paths.js +0 -1
  350. package/dist/lib/storage/backup-restore.d.ts +1 -1
  351. package/dist/lib/storage/backup-restore.d.ts.map +1 -1
  352. package/dist/lib/storage/backup-restore.js +0 -1
  353. package/dist/lib/storage/cache-artifacts.js +0 -1
  354. package/dist/lib/storage/error-hints.js +0 -1
  355. package/dist/lib/storage/file-paths.js +0 -1
  356. package/dist/lib/storage/fixture-guards.d.ts +1 -1
  357. package/dist/lib/storage/fixture-guards.d.ts.map +1 -1
  358. package/dist/lib/storage/fixture-guards.js +0 -1
  359. package/dist/lib/storage/flagged-entry.js +0 -1
  360. package/dist/lib/storage/flagged-load-entry.d.ts +1 -1
  361. package/dist/lib/storage/flagged-load-entry.d.ts.map +1 -1
  362. package/dist/lib/storage/flagged-load-entry.js +0 -1
  363. package/dist/lib/storage/flagged-save-entry.d.ts +1 -1
  364. package/dist/lib/storage/flagged-save-entry.d.ts.map +1 -1
  365. package/dist/lib/storage/flagged-save-entry.js +0 -1
  366. package/dist/lib/storage/flagged-storage-file.d.ts +1 -1
  367. package/dist/lib/storage/flagged-storage-file.d.ts.map +1 -1
  368. package/dist/lib/storage/flagged-storage-file.js +0 -1
  369. package/dist/lib/storage/flagged-storage-io.d.ts +1 -1
  370. package/dist/lib/storage/flagged-storage-io.d.ts.map +1 -1
  371. package/dist/lib/storage/flagged-storage-io.js +0 -1
  372. package/dist/lib/storage/flagged-storage.d.ts +1 -1
  373. package/dist/lib/storage/flagged-storage.d.ts.map +1 -1
  374. package/dist/lib/storage/flagged-storage.js +15 -2
  375. package/dist/lib/storage/flagged-storage.js.map +1 -1
  376. package/dist/lib/storage/gitignore.js +0 -1
  377. package/dist/lib/storage/hash.js +0 -1
  378. package/dist/lib/storage/health.js +0 -1
  379. package/dist/lib/storage/identity.js +0 -1
  380. package/dist/lib/storage/import-export.d.ts +1 -1
  381. package/dist/lib/storage/import-export.d.ts.map +1 -1
  382. package/dist/lib/storage/import-export.js +0 -1
  383. package/dist/lib/storage/metadata-section.js +0 -1
  384. package/dist/lib/storage/migrations.d.ts +5 -48
  385. package/dist/lib/storage/migrations.d.ts.map +1 -1
  386. package/dist/lib/storage/migrations.js +5 -2
  387. package/dist/lib/storage/named-backup-entry.js +0 -1
  388. package/dist/lib/storage/named-backups-entry.d.ts +1 -1
  389. package/dist/lib/storage/named-backups-entry.d.ts.map +1 -1
  390. package/dist/lib/storage/named-backups-entry.js +0 -1
  391. package/dist/lib/storage/named-backups.js +0 -1
  392. package/dist/lib/storage/path-state.js +0 -1
  393. package/dist/lib/storage/paths.js +0 -1
  394. package/dist/lib/storage/project-migration.d.ts +1 -1
  395. package/dist/lib/storage/project-migration.d.ts.map +1 -1
  396. package/dist/lib/storage/project-migration.js +0 -1
  397. package/dist/lib/storage/public-types.d.ts +70 -0
  398. package/dist/lib/storage/public-types.d.ts.map +1 -0
  399. package/dist/lib/storage/public-types.js +6 -0
  400. package/dist/lib/storage/record-utils.js +0 -1
  401. package/dist/lib/storage/restore-assessment.d.ts +1 -1
  402. package/dist/lib/storage/restore-assessment.d.ts.map +1 -1
  403. package/dist/lib/storage/restore-assessment.js +0 -1
  404. package/dist/lib/storage/restore-backup-entry.d.ts +1 -1
  405. package/dist/lib/storage/restore-backup-entry.d.ts.map +1 -1
  406. package/dist/lib/storage/restore-backup-entry.js +0 -1
  407. package/dist/lib/storage/restore-metadata.d.ts +1 -1
  408. package/dist/lib/storage/restore-metadata.d.ts.map +1 -1
  409. package/dist/lib/storage/restore-metadata.js +0 -1
  410. package/dist/lib/storage/restore.d.ts +1 -1
  411. package/dist/lib/storage/restore.d.ts.map +1 -1
  412. package/dist/lib/storage/restore.js +0 -1
  413. package/dist/lib/storage/save-retry.d.ts +10 -0
  414. package/dist/lib/storage/save-retry.d.ts.map +1 -0
  415. package/dist/lib/storage/save-retry.js +26 -0
  416. package/dist/lib/storage/snapshot-inspectors.d.ts +1 -1
  417. package/dist/lib/storage/snapshot-inspectors.d.ts.map +1 -1
  418. package/dist/lib/storage/snapshot-inspectors.js +0 -1
  419. package/dist/lib/storage/storage-parser.d.ts +1 -1
  420. package/dist/lib/storage/storage-parser.d.ts.map +1 -1
  421. package/dist/lib/storage/storage-parser.js +0 -1
  422. package/dist/lib/storage/transactions.d.ts +1 -1
  423. package/dist/lib/storage/transactions.d.ts.map +1 -1
  424. package/dist/lib/storage/transactions.js +0 -1
  425. package/dist/lib/storage.d.ts +3 -24
  426. package/dist/lib/storage.d.ts.map +1 -1
  427. package/dist/lib/storage.js +17 -32
  428. package/dist/lib/table-formatter.js +0 -1
  429. package/dist/lib/tools/hashline-tools.js +0 -1
  430. package/dist/lib/types.js +0 -1
  431. package/dist/lib/ui/ansi.js +0 -1
  432. package/dist/lib/ui/auth-menu-builder.d.ts +89 -0
  433. package/dist/lib/ui/auth-menu-builder.d.ts.map +1 -0
  434. package/dist/lib/ui/auth-menu-builder.js +350 -0
  435. package/dist/lib/ui/auth-menu.d.ts +2 -76
  436. package/dist/lib/ui/auth-menu.d.ts.map +1 -1
  437. package/dist/lib/ui/auth-menu.js +3 -349
  438. package/dist/lib/ui/confirm.js +0 -1
  439. package/dist/lib/ui/display-width.js +0 -1
  440. package/dist/lib/ui/format.js +0 -1
  441. package/dist/lib/ui/index.d.ts +10 -0
  442. package/dist/lib/ui/index.d.ts.map +1 -0
  443. package/dist/lib/ui/index.js +9 -0
  444. package/dist/lib/ui/runtime.js +0 -1
  445. package/dist/lib/ui/select.js +0 -1
  446. package/dist/lib/ui/theme.js +0 -1
  447. package/dist/lib/ui/ui-copy.d.ts +159 -0
  448. package/dist/lib/ui/ui-copy.d.ts.map +1 -0
  449. package/dist/lib/ui/ui-copy.js +163 -0
  450. package/dist/lib/unified-settings.js +0 -1
  451. package/dist/lib/update-notice.js +0 -1
  452. package/dist/lib/usage/index.js +0 -1
  453. package/dist/lib/usage/ledger.js +0 -1
  454. package/dist/lib/usage/pricing.js +0 -1
  455. package/dist/lib/usage/redaction.js +0 -1
  456. package/dist/lib/usage/types.js +0 -1
  457. package/dist/lib/utils.js +0 -1
  458. package/package.json +8 -8
  459. package/scripts/postinstall.js +34 -265
  460. package/scripts/preuninstall.js +2 -2
@@ -0,0 +1,345 @@
1
+ import { stdin as input, stdout as output } from "node:process";
2
+ import { createInterface } from "node:readline/promises";
3
+ import { extractAccountEmail, extractAccountId, getAccountIdCandidates, resolveRequestAccountId, sanitizeEmail, selectBestAccountCandidate, } from "../accounts.js";
4
+ import { createAuthorizationFlow, exchangeAuthorizationCode, redactOAuthUrlForLog, REDIRECT_URI, } from "../auth/auth.js";
5
+ import { copyTextToClipboard, openBrowserUrl, } from "../auth/browser.js";
6
+ import { runDeviceAuthFlow } from "../auth/device-auth.js";
7
+ import { resolveOrgOverride } from "../auth/org-override.js";
8
+ import { startLocalOAuthServer } from "../auth/server.js";
9
+ import { setCodexCliActiveSelection } from "../codex-cli/writer.js";
10
+ import { createLogger } from "../logger.js";
11
+ import { MODEL_FAMILIES } from "../prompts/codex.js";
12
+ import { findMatchingAccountIndex, withAccountStorageTransaction, } from "../storage.js";
13
+ import { UI_COPY } from "../ui/ui-copy.js";
14
+ import { applyAccountPoolResults, } from "./account-pool-write.js";
15
+ import { stylePromptText } from "./formatters/index.js";
16
+ import { classifyManualCallbackInput, } from "./manual-callback.js";
17
+ const log = createLogger("codex-manager");
18
+ /** @internal */
19
+ export function isOAuthCancellation(result) {
20
+ const message = (result.message ?? result.reason ?? "").trim().toLowerCase();
21
+ return message.includes("cancelled") || message.includes("canceled");
22
+ }
23
+ /** @internal */
24
+ export function isAbortError(error) {
25
+ if (!(error instanceof Error))
26
+ return false;
27
+ const maybe = error;
28
+ return maybe.name === "AbortError" || maybe.code === "ABORT_ERR";
29
+ }
30
+ /**
31
+ * Resolve the account-id selection for freshly-minted tokens.
32
+ *
33
+ * The org-override precedence (explicit `login --org` wins over the ambient
34
+ * CODEX_AUTH_ACCOUNT_ID env, for this call only) lives in the internal
35
+ * lib/auth/org-override.ts module so it can be unit-tested without exporting this
36
+ * CLI-internal function. Threading the org as a parameter avoids mutating
37
+ * process.env for the duration of a login, which raced on concurrent re-entry.
38
+ *
39
+ * @internal
40
+ */
41
+ export function resolveAccountSelection(tokens, orgOverride) {
42
+ const candidates = getAccountIdCandidates(tokens.access, tokens.idToken);
43
+ // Surface every workspace/organization exposed by the token so the saved
44
+ // account can track them (issue #491/#512). Without this, same-email
45
+ // multi-workspace logins persisted rows with `workspaces: null` and
46
+ // `workspace <account>` was unusable. Built before the `--org` override
47
+ // branch so the explicit-binding flow persists workspaces too (#512).
48
+ const workspaces = candidates.length > 0
49
+ ? candidates.map((candidate) => ({
50
+ id: candidate.accountId,
51
+ name: candidate.label,
52
+ enabled: true,
53
+ isDefault: candidate.isDefault,
54
+ }))
55
+ : undefined;
56
+ const override = resolveOrgOverride(orgOverride);
57
+ if (override) {
58
+ // Prefer the token candidate's human label for the chosen org so the
59
+ // saved row is identifiable, falling back to a bare manual binding.
60
+ const matched = candidates.find((candidate) => candidate.accountId === override);
61
+ return {
62
+ ...tokens,
63
+ accountIdOverride: override,
64
+ accountIdSource: "manual",
65
+ accountLabel: matched?.label,
66
+ workspaces,
67
+ };
68
+ }
69
+ if (candidates.length === 0) {
70
+ return tokens;
71
+ }
72
+ if (candidates.length === 1) {
73
+ const [candidate] = candidates;
74
+ if (candidate) {
75
+ return {
76
+ ...tokens,
77
+ accountIdOverride: candidate.accountId,
78
+ accountIdSource: candidate.source,
79
+ accountLabel: candidate.label,
80
+ workspaces,
81
+ };
82
+ }
83
+ }
84
+ const best = selectBestAccountCandidate(candidates);
85
+ if (!best) {
86
+ return tokens;
87
+ }
88
+ return {
89
+ ...tokens,
90
+ accountIdOverride: best.accountId,
91
+ accountIdSource: best.source ?? "token",
92
+ accountLabel: best.label,
93
+ workspaces,
94
+ };
95
+ }
96
+ async function promptManualCallback(state, options = {}) {
97
+ const useInteractivePrompt = input.isTTY && output.isTTY;
98
+ if (!useInteractivePrompt && !options.allowNonTty) {
99
+ return { type: "cancelled" };
100
+ }
101
+ const rl = createInterface({ input, output });
102
+ try {
103
+ if (useInteractivePrompt) {
104
+ console.log("");
105
+ console.log(stylePromptText(UI_COPY.oauth.pastePrompt, "accent"));
106
+ }
107
+ const answer = useInteractivePrompt
108
+ ? await rl.question("◆ ")
109
+ : await new Promise((resolve, reject) => {
110
+ if (input.readableEnded || input.destroyed) {
111
+ resolve(null);
112
+ return;
113
+ }
114
+ let settled = false;
115
+ const handleInputClosed = () => {
116
+ if (settled)
117
+ return;
118
+ settled = true;
119
+ input.off("end", handleInputClosed);
120
+ input.off("close", handleInputClosed);
121
+ resolve(null);
122
+ };
123
+ const finish = (value) => {
124
+ if (settled)
125
+ return;
126
+ settled = true;
127
+ input.off("end", handleInputClosed);
128
+ input.off("close", handleInputClosed);
129
+ resolve(value);
130
+ };
131
+ const fail = (error) => {
132
+ if (settled)
133
+ return;
134
+ settled = true;
135
+ input.off("end", handleInputClosed);
136
+ input.off("close", handleInputClosed);
137
+ reject(error);
138
+ };
139
+ rl.question("")
140
+ .then((value) => finish(value))
141
+ .catch((error) => {
142
+ if (isAbortError(error) || isReadlineClosedError(error)) {
143
+ handleInputClosed();
144
+ return;
145
+ }
146
+ fail(error);
147
+ });
148
+ input.once("end", handleInputClosed);
149
+ input.once("close", handleInputClosed);
150
+ });
151
+ return classifyManualCallbackInput(answer, state);
152
+ }
153
+ catch (error) {
154
+ if (isAbortError(error) || isReadlineClosedError(error)) {
155
+ return { type: "cancelled" };
156
+ }
157
+ throw error;
158
+ }
159
+ finally {
160
+ rl.close();
161
+ }
162
+ }
163
+ function isReadlineClosedError(error) {
164
+ if (!(error instanceof Error)) {
165
+ return false;
166
+ }
167
+ const errorCode = typeof error === "object" && error !== null && "code" in error
168
+ ? String(error.code)
169
+ : "";
170
+ return (errorCode === "ERR_USE_AFTER_CLOSE" ||
171
+ /readline was closed/i.test(error.message));
172
+ }
173
+ /** @internal */
174
+ export async function runOAuthFlow(forceNewLogin, signInMode) {
175
+ const { pkce, state, url } = await createAuthorizationFlow({ forceNewLogin });
176
+ let code = null;
177
+ let oauthServer = null;
178
+ try {
179
+ if (signInMode === "browser") {
180
+ try {
181
+ oauthServer = await startLocalOAuthServer({ state });
182
+ }
183
+ catch (serverError) {
184
+ log.warn("Local OAuth callback server unavailable; falling back to manual callback entry.", serverError instanceof Error
185
+ ? {
186
+ message: serverError.message,
187
+ stack: serverError.stack,
188
+ code: typeof serverError === "object" &&
189
+ serverError !== null &&
190
+ "code" in serverError
191
+ ? String(serverError.code)
192
+ : undefined,
193
+ }
194
+ : { error: String(serverError) });
195
+ oauthServer = null;
196
+ }
197
+ }
198
+ // Display the OAuth URL with sensitive query parameters (state,
199
+ // code, code_challenge, code_verifier) redacted so they do not leak
200
+ // into shell history, screen captures, CI transcripts, or clipboard
201
+ // managers. The full URL is still handed to the browser opener and
202
+ // the clipboard so sign-in continues to work end-to-end.
203
+ const displayUrl = redactOAuthUrlForLog(url);
204
+ if (signInMode === "browser") {
205
+ const opened = openBrowserUrl(url);
206
+ if (opened) {
207
+ console.log(stylePromptText(UI_COPY.oauth.browserOpened, "success"));
208
+ }
209
+ else {
210
+ console.log(stylePromptText(UI_COPY.oauth.browserOpenFail, "warning"));
211
+ console.log(`${stylePromptText(UI_COPY.oauth.goTo, "accent")} ${displayUrl}`);
212
+ const copied = copyTextToClipboard(url);
213
+ console.log(stylePromptText(copied ? UI_COPY.oauth.copyOk : UI_COPY.oauth.copyFail, copied ? "success" : "warning"));
214
+ }
215
+ }
216
+ else {
217
+ console.log(`${stylePromptText(UI_COPY.oauth.goTo, "accent")} ${displayUrl}`);
218
+ const copied = copyTextToClipboard(url);
219
+ console.log(stylePromptText(copied ? UI_COPY.oauth.copyOk : UI_COPY.oauth.copyFail, copied ? "success" : "warning"));
220
+ }
221
+ const waitingForCallback = signInMode === "browser" && oauthServer?.ready === true;
222
+ if (waitingForCallback && oauthServer) {
223
+ console.log(stylePromptText(UI_COPY.oauth.waitingCallback, "muted"));
224
+ const callbackResult = await oauthServer.waitForCode(state);
225
+ code = callbackResult?.code ?? null;
226
+ }
227
+ if (!code) {
228
+ console.log(stylePromptText(waitingForCallback
229
+ ? UI_COPY.oauth.callbackMissed
230
+ : signInMode === "manual"
231
+ ? UI_COPY.oauth.callbackBypassed
232
+ : UI_COPY.oauth.callbackUnavailable, "warning"));
233
+ const manualResult = await promptManualCallback(state, {
234
+ allowNonTty: signInMode === "manual",
235
+ });
236
+ // A parse/state failure must surface its own validation error instead
237
+ // of being reported as `Cancelled.` like a genuine user abort
238
+ // (issue #512 follow-up). Only an actual cancellation falls through to
239
+ // the cancelled path below.
240
+ if (manualResult.type === "invalid") {
241
+ return {
242
+ type: "failed",
243
+ reason: "invalid_response",
244
+ message: UI_COPY.oauth.callbackInvalid,
245
+ };
246
+ }
247
+ if (manualResult.type === "state-mismatch") {
248
+ return {
249
+ type: "failed",
250
+ reason: "invalid_response",
251
+ message: UI_COPY.oauth.callbackStateMismatch,
252
+ };
253
+ }
254
+ code = manualResult.type === "code" ? manualResult.code : null;
255
+ }
256
+ }
257
+ finally {
258
+ oauthServer?.close();
259
+ }
260
+ if (!code) {
261
+ return {
262
+ type: "failed",
263
+ reason: "unknown",
264
+ message: UI_COPY.oauth.cancelled,
265
+ };
266
+ }
267
+ return exchangeAuthorizationCode(code, pkce.verifier, REDIRECT_URI);
268
+ }
269
+ /** @internal */
270
+ export async function runSignInFlow(forceNewLogin, signInMode, options = {}) {
271
+ if (signInMode === "device") {
272
+ // OpenAI owns the device-code account picker; there is no force-new-login
273
+ // equivalent to pass through for this mode.
274
+ // TODO: Thread a manager-level AbortSignal when login cancellation exists.
275
+ return runDeviceAuthFlow({
276
+ log: console.log,
277
+ timeoutMs: options.timeoutMs,
278
+ // CLI invocations rely on top-level await in scripts/codex-multi-auth.js;
279
+ // without keepAlive the polling timers unref and Node exits before the
280
+ // user can complete the browser step (issue #477).
281
+ keepAlive: true,
282
+ });
283
+ }
284
+ return runOAuthFlow(forceNewLogin, signInMode);
285
+ }
286
+ /** @internal */
287
+ export async function persistAccountPool(results, replaceAll) {
288
+ if (results.length === 0)
289
+ return null;
290
+ return await withAccountStorageTransaction(async (loadedStorage, persist) => {
291
+ const stored = replaceAll ? null : loadedStorage;
292
+ const now = Date.now();
293
+ const existing = stored?.accounts ? [...stored.accounts] : [];
294
+ const writes = results.map((result) => {
295
+ const tokenAccountId = extractAccountId(result.access);
296
+ const accountId = resolveRequestAccountId(result.accountIdOverride, result.accountIdSource, tokenAccountId);
297
+ const accountIdSource = accountId
298
+ ? (result.accountIdSource ??
299
+ (result.accountIdOverride ? "manual" : "token"))
300
+ : undefined;
301
+ return {
302
+ accountId,
303
+ accountIdSource,
304
+ accountLabel: result.accountLabel,
305
+ email: sanitizeEmail(extractAccountEmail(result.access, result.idToken)),
306
+ refreshToken: result.refresh,
307
+ accessToken: result.access,
308
+ expiresAt: result.expires,
309
+ workspaces: result.workspaces,
310
+ now,
311
+ };
312
+ });
313
+ const { accounts, activeIndex, outcome } = applyAccountPoolResults({
314
+ existing,
315
+ writes,
316
+ priorActiveIndex: stored?.activeIndex,
317
+ findMatchingAccountIndex,
318
+ });
319
+ const activeIndexByFamily = {};
320
+ for (const family of MODEL_FAMILIES) {
321
+ activeIndexByFamily[family] = activeIndex;
322
+ }
323
+ await persist({
324
+ version: 3,
325
+ accounts,
326
+ activeIndex,
327
+ activeIndexByFamily,
328
+ });
329
+ return outcome;
330
+ });
331
+ }
332
+ /** @internal */
333
+ export async function syncSelectionToCodex(tokens) {
334
+ const tokenAccountId = extractAccountId(tokens.access);
335
+ const accountId = resolveRequestAccountId(tokens.accountIdOverride, tokens.accountIdSource, tokenAccountId);
336
+ const email = sanitizeEmail(extractAccountEmail(tokens.access, tokens.idToken));
337
+ await setCodexCliActiveSelection({
338
+ accountId,
339
+ email,
340
+ accessToken: tokens.access,
341
+ refreshToken: tokens.refresh,
342
+ expiresAt: tokens.expires,
343
+ idToken: tokens.idToken,
344
+ });
345
+ }
@@ -28,4 +28,3 @@ export function classifyManualCallbackInput(answer, expectedState) {
28
28
  }
29
29
  return { type: "code", code: parsed.code };
30
30
  }
31
- //# sourceMappingURL=manual-callback.js.map
@@ -0,0 +1,24 @@
1
+ import type { PersistedSwitchReason } from "../schemas.js";
2
+ import { type AccountStorageV3 } from "../storage.js";
3
+ /**
4
+ * Persist an explicit account selection and sync it to the Codex CLI state.
5
+ *
6
+ * Shared by the `switch` and `best` commands (injected via their deps objects)
7
+ * and by the login dashboard's backup-restore flow. Moved verbatim out of
8
+ * lib/codex-manager.ts (audit roadmap §4.1.1 phase 3).
9
+ */
10
+ export declare function persistAndSyncSelectedAccount({ storage, targetIndex, parsed, switchReason, initialSyncIdToken, preserveActiveIndexByFamily, setPin, clearPin, bumpAffinityGeneration, }: {
11
+ storage: AccountStorageV3;
12
+ targetIndex: number;
13
+ parsed: number;
14
+ switchReason: PersistedSwitchReason;
15
+ initialSyncIdToken?: string;
16
+ preserveActiveIndexByFamily?: boolean;
17
+ setPin?: boolean;
18
+ clearPin?: boolean;
19
+ bumpAffinityGeneration?: boolean;
20
+ }): Promise<{
21
+ synced: boolean;
22
+ wasDisabled: boolean;
23
+ }>;
24
+ //# sourceMappingURL=persist-selected-account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persist-selected-account.d.ts","sourceRoot":"","sources":["../../../lib/codex-manager/persist-selected-account.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EACN,KAAK,gBAAgB,EAIrB,MAAM,eAAe,CAAC;AAQvB;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CAAC,EACnD,OAAO,EACP,WAAW,EACX,MAAM,EACN,YAAY,EACZ,kBAAkB,EAClB,2BAAmC,EACnC,MAAc,EACd,QAAgB,EAChB,sBAA8B,GAC9B,EAAE;IACF,OAAO,EAAE,gBAAgB,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,qBAAqB,CAAC;IACpC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sBAAsB,CAAC,EAAE,OAAO,CAAC;CACjC,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,CAAC,CAqGrD"}
@@ -0,0 +1,107 @@
1
+ import { extractAccountEmail, extractAccountId, sanitizeEmail, } from "../accounts.js";
2
+ import { setCodexCliActiveSelection } from "../codex-cli/writer.js";
3
+ import { MODEL_FAMILIES } from "../prompts/codex.js";
4
+ import { queuedRefresh } from "../refresh-queue.js";
5
+ import { getStoragePath, readAffinityGenerationFromDisk, saveAccounts, } from "../storage.js";
6
+ import { applyTokenAccountIdentity, hasUsableAccessToken, } from "./account-credentials.js";
7
+ import { normalizeFailureDetail } from "./formatters/index.js";
8
+ import { saveAccountsWithRetry } from "./forecast-report-shared.js";
9
+ /**
10
+ * Persist an explicit account selection and sync it to the Codex CLI state.
11
+ *
12
+ * Shared by the `switch` and `best` commands (injected via their deps objects)
13
+ * and by the login dashboard's backup-restore flow. Moved verbatim out of
14
+ * lib/codex-manager.ts (audit roadmap §4.1.1 phase 3).
15
+ */
16
+ export async function persistAndSyncSelectedAccount({ storage, targetIndex, parsed, switchReason, initialSyncIdToken, preserveActiveIndexByFamily = false, setPin = false, clearPin = false, bumpAffinityGeneration = false, }) {
17
+ const account = storage.accounts[targetIndex];
18
+ if (!account) {
19
+ throw new Error(`Account ${parsed} not found.`);
20
+ }
21
+ const shouldPreserveActiveIndexByFamily = preserveActiveIndexByFamily &&
22
+ !!storage.activeIndexByFamily &&
23
+ targetIndex === storage.activeIndex;
24
+ storage.activeIndex = targetIndex;
25
+ storage.activeIndexByFamily = storage.activeIndexByFamily ?? {};
26
+ if (shouldPreserveActiveIndexByFamily) {
27
+ const maxIndex = Math.max(0, storage.accounts.length - 1);
28
+ for (const family of MODEL_FAMILIES) {
29
+ const raw = storage.activeIndexByFamily[family];
30
+ const candidate = typeof raw === "number" && Number.isFinite(raw) ? raw : targetIndex;
31
+ storage.activeIndexByFamily[family] = Math.max(0, Math.min(candidate, maxIndex));
32
+ }
33
+ }
34
+ else {
35
+ storage.activeIndexByFamily = storage.activeIndexByFamily ?? {};
36
+ for (const family of MODEL_FAMILIES) {
37
+ storage.activeIndexByFamily[family] = targetIndex;
38
+ }
39
+ }
40
+ const wasDisabled = account.enabled === false;
41
+ if (wasDisabled) {
42
+ account.enabled = true;
43
+ }
44
+ const switchNow = Date.now();
45
+ let syncAccessToken = account.accessToken;
46
+ let syncRefreshToken = account.refreshToken;
47
+ let syncExpiresAt = account.expiresAt;
48
+ let syncIdToken = initialSyncIdToken;
49
+ if (!hasUsableAccessToken(account, switchNow)) {
50
+ const refreshResult = await queuedRefresh(account.refreshToken);
51
+ if (refreshResult.type === "success") {
52
+ const tokenAccountId = extractAccountId(refreshResult.access);
53
+ const nextEmail = sanitizeEmail(extractAccountEmail(refreshResult.access, refreshResult.idToken));
54
+ if (account.refreshToken !== refreshResult.refresh) {
55
+ account.refreshToken = refreshResult.refresh;
56
+ }
57
+ if (account.accessToken !== refreshResult.access) {
58
+ account.accessToken = refreshResult.access;
59
+ }
60
+ if (account.expiresAt !== refreshResult.expires) {
61
+ account.expiresAt = refreshResult.expires;
62
+ }
63
+ if (nextEmail && nextEmail !== account.email) {
64
+ account.email = nextEmail;
65
+ }
66
+ applyTokenAccountIdentity(account, tokenAccountId);
67
+ syncAccessToken = refreshResult.access;
68
+ syncRefreshToken = refreshResult.refresh;
69
+ syncExpiresAt = refreshResult.expires;
70
+ syncIdToken = refreshResult.idToken;
71
+ }
72
+ else {
73
+ console.warn(`Switch validation refresh failed for account ${parsed}: ${normalizeFailureDetail(refreshResult.message, refreshResult.reason)}.`);
74
+ }
75
+ }
76
+ account.lastUsed = switchNow;
77
+ account.lastSwitchReason = switchReason;
78
+ if (setPin) {
79
+ storage.pinnedAccountIndex = targetIndex;
80
+ }
81
+ else if (clearPin) {
82
+ delete storage.pinnedAccountIndex;
83
+ }
84
+ if (bumpAffinityGeneration) {
85
+ // Re-read the on-disk generation right before saving so concurrent CLI
86
+ // processes don't lose increments via lost-update on the load+mutate
87
+ // pair. Math.max keeps the counter monotonically increasing — extra
88
+ // bumps are harmless (just an additional affinity invalidation), but a
89
+ // missed bump can let the proxy cling to the wrong account. The save
90
+ // itself is serialized by withStorageLock; this only narrows the
91
+ // lost-update window. See issue #474.
92
+ const diskGeneration = readAffinityGenerationFromDisk(getStoragePath());
93
+ const inMemoryGeneration = storage.affinityGeneration ?? 0;
94
+ storage.affinityGeneration =
95
+ Math.max(inMemoryGeneration, diskGeneration) + 1;
96
+ }
97
+ await saveAccountsWithRetry(storage, saveAccounts);
98
+ const synced = await setCodexCliActiveSelection({
99
+ accountId: account.accountId,
100
+ email: account.email,
101
+ accessToken: syncAccessToken,
102
+ refreshToken: syncRefreshToken,
103
+ expiresAt: syncExpiresAt,
104
+ ...(syncIdToken ? { idToken: syncIdToken } : {}),
105
+ });
106
+ return { synced, wasDisabled };
107
+ }
@@ -0,0 +1,18 @@
1
+ import { type QuotaCacheData, type QuotaCacheEntry } from "../quota-cache.js";
2
+ import type { CodexQuotaSnapshot } from "../quota-probe.js";
3
+ import type { AccountMetadataV3 } from "../storage.js";
4
+ /**
5
+ * Quota-cache lookup/update helpers shared by the manager CLI commands (audit
6
+ * roadmap §4.1.1 phase 3). These previously lived as module-private helpers in
7
+ * lib/codex-manager.ts and were closure-captured by the health check, the
8
+ * forecast/repair dependency factories, and the login dashboard menu. Moved
9
+ * verbatim so every consumer injects or imports the same single
10
+ * implementation.
11
+ */
12
+ /** Default model used for live quota probes across manager commands. */
13
+ export declare const DEFAULT_LIVE_PROBE_MODEL = "gpt-5.5";
14
+ export declare function getPersistedQuotaViewForAccount(cache: QuotaCacheData | null, account: Pick<AccountMetadataV3, "accountId" | "email" | "rateLimitResetTimes">, accounts: readonly Pick<AccountMetadataV3, "accountId" | "email">[], now: number, emailFallbackState?: ReadonlyMap<string, import("../quota-readiness.js").QuotaEmailFallbackState>): QuotaCacheEntry | null;
15
+ export declare function updateQuotaCacheForAccount(cache: QuotaCacheData, account: Pick<AccountMetadataV3, "accountId" | "email">, snapshot: CodexQuotaSnapshot, accounts: readonly Pick<AccountMetadataV3, "accountId" | "email">[], emailFallbackState?: ReadonlyMap<string, import("../quota-readiness.js").QuotaEmailFallbackState>): boolean;
16
+ export declare function cloneQuotaCacheData(cache: QuotaCacheData): QuotaCacheData;
17
+ export declare function pruneUnsafeQuotaEmailCacheEntry(cache: QuotaCacheData, email: string | undefined, accounts: readonly Pick<AccountMetadataV3, "accountId" | "email">[], emailFallbackState?: ReadonlyMap<string, import("../quota-readiness.js").QuotaEmailFallbackState>): boolean;
18
+ //# sourceMappingURL=quota-cache-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quota-cache-helpers.d.ts","sourceRoot":"","sources":["../../../lib/codex-manager/quota-cache-helpers.ts"],"names":[],"mappings":"AAOA,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;;;GAOG;AAEH,wEAAwE;AACxE,eAAO,MAAM,wBAAwB,YAAgB,CAAC;AA2BtD,wBAAgB,+BAA+B,CAC9C,KAAK,EAAE,cAAc,GAAG,IAAI,EAC5B,OAAO,EAAE,IAAI,CACZ,iBAAiB,EACjB,WAAW,GAAG,OAAO,GAAG,qBAAqB,CAC7C,EACD,QAAQ,EAAE,SAAS,IAAI,CAAC,iBAAiB,EAAE,WAAW,GAAG,OAAO,CAAC,EAAE,EACnE,GAAG,EAAE,MAAM,EACX,kBAAkB,+EAAyC,GACzD,eAAe,GAAG,IAAI,CA+BxB;AAED,wBAAgB,0BAA0B,CACzC,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,WAAW,GAAG,OAAO,CAAC,EACvD,QAAQ,EAAE,kBAAkB,EAC5B,QAAQ,EAAE,SAAS,IAAI,CAAC,iBAAiB,EAAE,WAAW,GAAG,OAAO,CAAC,EAAE,EACnE,kBAAkB,+EAAyC,GACzD,OAAO,CAuCT;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,cAAc,GAAG,cAAc,CAOzE;AAED,wBAAgB,+BAA+B,CAC9C,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,QAAQ,EAAE,SAAS,IAAI,CAAC,iBAAiB,EAAE,WAAW,GAAG,OAAO,CAAC,EAAE,EACnE,kBAAkB,+EAAyC,GACzD,OAAO,CAeT"}
@@ -0,0 +1,112 @@
1
+ import { buildQuotaEmailFallbackState, hasSafeQuotaEmailFallback, hasUniqueQuotaAccountId, normalizeQuotaAccountId, normalizeQuotaEmail, } from "../quota-readiness.js";
2
+ import { DEFAULT_MODEL } from "../request/helpers/model-map.js";
3
+ import { getRateLimitResetTimeForFamily } from "../runtime/account-status.js";
4
+ /**
5
+ * Quota-cache lookup/update helpers shared by the manager CLI commands (audit
6
+ * roadmap §4.1.1 phase 3). These previously lived as module-private helpers in
7
+ * lib/codex-manager.ts and were closure-captured by the health check, the
8
+ * forecast/repair dependency factories, and the login dashboard menu. Moved
9
+ * verbatim so every consumer injects or imports the same single
10
+ * implementation.
11
+ */
12
+ /** Default model used for live quota probes across manager commands. */
13
+ export const DEFAULT_LIVE_PROBE_MODEL = DEFAULT_MODEL;
14
+ function getQuotaCacheEntryForAccount(cache, account, accounts, emailFallbackState = buildQuotaEmailFallbackState(accounts)) {
15
+ const accountId = normalizeQuotaAccountId(account.accountId);
16
+ if (accountId &&
17
+ hasUniqueQuotaAccountId(accounts, account) &&
18
+ cache.byAccountId[accountId]) {
19
+ return cache.byAccountId[accountId] ?? null;
20
+ }
21
+ const email = normalizeQuotaEmail(account.email);
22
+ if (email &&
23
+ hasSafeQuotaEmailFallback(emailFallbackState, account) &&
24
+ cache.byEmail[email]) {
25
+ return cache.byEmail[email] ?? null;
26
+ }
27
+ return null;
28
+ }
29
+ export function getPersistedQuotaViewForAccount(cache, account, accounts, now, emailFallbackState = buildQuotaEmailFallbackState(accounts)) {
30
+ const cachedEntry = cache
31
+ ? getQuotaCacheEntryForAccount(cache, account, accounts, emailFallbackState)
32
+ : null;
33
+ const persistedResetAt = getRateLimitResetTimeForFamily(account, now, "codex");
34
+ if (typeof persistedResetAt !== "number") {
35
+ return cachedEntry;
36
+ }
37
+ const cachedPrimaryResetAt = cachedEntry?.primary.resetAtMs ?? 0;
38
+ const cachedSecondaryResetAt = cachedEntry?.secondary.resetAtMs ?? 0;
39
+ if (cachedEntry?.status === 429 &&
40
+ Math.max(cachedPrimaryResetAt, cachedSecondaryResetAt) >= persistedResetAt) {
41
+ return cachedEntry;
42
+ }
43
+ return {
44
+ updatedAt: cachedEntry?.updatedAt ?? now,
45
+ status: 429,
46
+ model: cachedEntry?.model ?? DEFAULT_MODEL,
47
+ planType: cachedEntry?.planType,
48
+ primary: {
49
+ ...cachedEntry?.primary,
50
+ resetAtMs: Math.max(cachedPrimaryResetAt, persistedResetAt),
51
+ },
52
+ secondary: cachedEntry?.secondary ?? {},
53
+ };
54
+ }
55
+ export function updateQuotaCacheForAccount(cache, account, snapshot, accounts, emailFallbackState = buildQuotaEmailFallbackState(accounts)) {
56
+ const nextEntry = {
57
+ updatedAt: Date.now(),
58
+ status: snapshot.status,
59
+ model: snapshot.model,
60
+ planType: snapshot.planType,
61
+ primary: {
62
+ usedPercent: snapshot.primary.usedPercent,
63
+ windowMinutes: snapshot.primary.windowMinutes,
64
+ resetAtMs: snapshot.primary.resetAtMs,
65
+ },
66
+ secondary: {
67
+ usedPercent: snapshot.secondary.usedPercent,
68
+ windowMinutes: snapshot.secondary.windowMinutes,
69
+ resetAtMs: snapshot.secondary.resetAtMs,
70
+ },
71
+ };
72
+ let changed = false;
73
+ const accountId = normalizeQuotaAccountId(account.accountId);
74
+ const hasUniqueAccountId = accountId !== null && hasUniqueQuotaAccountId(accounts, account);
75
+ if (hasUniqueAccountId) {
76
+ cache.byAccountId[accountId] = nextEntry;
77
+ changed = true;
78
+ }
79
+ const email = normalizeQuotaEmail(account.email);
80
+ if (email &&
81
+ hasSafeQuotaEmailFallback(emailFallbackState, account) &&
82
+ !hasUniqueAccountId) {
83
+ cache.byEmail[email] = nextEntry;
84
+ changed = true;
85
+ }
86
+ else if (email && cache.byEmail[email]) {
87
+ delete cache.byEmail[email];
88
+ changed = true;
89
+ }
90
+ return changed;
91
+ }
92
+ export function cloneQuotaCacheData(cache) {
93
+ // Shallow spreading is safe because quota cache entries are always replaced,
94
+ // never mutated in-place.
95
+ return {
96
+ byAccountId: { ...cache.byAccountId },
97
+ byEmail: { ...cache.byEmail },
98
+ };
99
+ }
100
+ export function pruneUnsafeQuotaEmailCacheEntry(cache, email, accounts, emailFallbackState = buildQuotaEmailFallbackState(accounts)) {
101
+ const normalizedEmail = normalizeQuotaEmail(email);
102
+ if (!normalizedEmail || !cache.byEmail[normalizedEmail]) {
103
+ return false;
104
+ }
105
+ const hasSafeFallbackAccount = accounts.some((account) => normalizeQuotaEmail(account.email) === normalizedEmail &&
106
+ hasSafeQuotaEmailFallback(emailFallbackState, account));
107
+ if (hasSafeFallbackAccount) {
108
+ return false;
109
+ }
110
+ delete cache.byEmail[normalizedEmail];
111
+ return true;
112
+ }
@@ -1,4 +1,3 @@
1
1
  export function isRateLimitedMarker(marker) {
2
2
  return marker === "rate-limited" || marker.startsWith("rate-limited:");
3
3
  }
4
- //# sourceMappingURL=rate-limit-markers.js.map
@@ -1733,4 +1733,3 @@ export async function runDoctor(args, deps) {
1733
1733
  }
1734
1734
  return summary.error > 0 ? 1 : 0;
1735
1735
  }
1736
- //# sourceMappingURL=repair-commands.js.map
@@ -1,5 +1,5 @@
1
1
  import { loadPluginConfig } from "../../config.js";
2
- import { UI_COPY } from "../../ui/copy.js";
2
+ import { UI_COPY } from "../../ui/ui-copy.js";
3
3
  import { getUiRuntimeOptions } from "../../ui/runtime.js";
4
4
  import { select } from "../../ui/select.js";
5
5
  import { promptBackendCategorySettingsEntry } from "../backend-category-entry.js";
@@ -76,4 +76,3 @@ export async function configureBackendSettings(currentConfig) {
76
76
  });
77
77
  }
78
78
  /* c8 ignore stop */
79
- //# sourceMappingURL=backend.js.map
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_DASHBOARD_DISPLAY_SETTINGS, getDashboardSettingsPath, loadDashboardDisplaySettings, } from "../../dashboard-settings.js";
2
- import { UI_COPY } from "../../ui/copy.js";
2
+ import { UI_COPY } from "../../ui/ui-copy.js";
3
3
  import { getUiRuntimeOptions, setUiRuntimeOptions } from "../../ui/runtime.js";
4
4
  import { promptBehaviorSettingsPanel } from "../behavior-settings-panel.js";
5
5
  import { promptDashboardDisplayPanel, } from "../dashboard-display-panel.js";
@@ -220,4 +220,3 @@ export async function promptThemeSettings(initial) {
220
220
  });
221
221
  }
222
222
  /* c8 ignore stop */
223
- //# sourceMappingURL=dashboard.js.map