codex-multi-auth 1.2.0 → 1.2.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.
- package/README.md +49 -32
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +929 -1712
- package/dist/index.js.map +1 -1
- package/dist/lib/accounts.d.ts +10 -0
- package/dist/lib/accounts.d.ts.map +1 -1
- package/dist/lib/accounts.js +312 -69
- package/dist/lib/accounts.js.map +1 -1
- package/dist/lib/auth/index.d.ts +2 -0
- package/dist/lib/auth/index.d.ts.map +1 -0
- package/dist/lib/auth/index.js +2 -0
- package/dist/lib/auth/index.js.map +1 -0
- package/dist/lib/circuit-breaker.d.ts +4 -0
- package/dist/lib/circuit-breaker.d.ts.map +1 -1
- package/dist/lib/circuit-breaker.js +33 -1
- package/dist/lib/circuit-breaker.js.map +1 -1
- package/dist/lib/codex-cli/index.d.ts +5 -0
- package/dist/lib/codex-cli/index.d.ts.map +1 -0
- package/dist/lib/codex-cli/index.js +5 -0
- package/dist/lib/codex-cli/index.js.map +1 -0
- package/dist/lib/codex-manager/auth-commands.d.ts +72 -0
- package/dist/lib/codex-manager/auth-commands.d.ts.map +1 -0
- package/dist/lib/codex-manager/auth-commands.js +643 -0
- package/dist/lib/codex-manager/auth-commands.js.map +1 -0
- package/dist/lib/codex-manager/backend-category-entry.d.ts +103 -0
- package/dist/lib/codex-manager/backend-category-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-category-entry.js +23 -0
- package/dist/lib/codex-manager/backend-category-entry.js.map +1 -0
- package/dist/lib/codex-manager/backend-category-helpers.d.ts +10 -0
- package/dist/lib/codex-manager/backend-category-helpers.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-category-helpers.js +29 -0
- package/dist/lib/codex-manager/backend-category-helpers.js.map +1 -0
- package/dist/lib/codex-manager/backend-category-prompt.d.ts +55 -0
- package/dist/lib/codex-manager/backend-category-prompt.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-category-prompt.js +178 -0
- package/dist/lib/codex-manager/backend-category-prompt.js.map +1 -0
- package/dist/lib/codex-manager/backend-settings-controller.d.ts +11 -0
- package/dist/lib/codex-manager/backend-settings-controller.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-settings-controller.js +14 -0
- package/dist/lib/codex-manager/backend-settings-controller.js.map +1 -0
- package/dist/lib/codex-manager/backend-settings-entry.d.ts +20 -0
- package/dist/lib/codex-manager/backend-settings-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-settings-entry.js +12 -0
- package/dist/lib/codex-manager/backend-settings-entry.js.map +1 -0
- package/dist/lib/codex-manager/backend-settings-helpers.d.ts +16 -0
- package/dist/lib/codex-manager/backend-settings-helpers.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-settings-helpers.js +102 -0
- package/dist/lib/codex-manager/backend-settings-helpers.js.map +1 -0
- package/dist/lib/codex-manager/backend-settings-prompt.d.ts +49 -0
- package/dist/lib/codex-manager/backend-settings-prompt.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-settings-prompt.js +121 -0
- package/dist/lib/codex-manager/backend-settings-prompt.js.map +1 -0
- package/dist/lib/codex-manager/backend-settings-schema.d.ts +55 -0
- package/dist/lib/codex-manager/backend-settings-schema.d.ts.map +1 -0
- package/dist/lib/codex-manager/backend-settings-schema.js +264 -0
- package/dist/lib/codex-manager/backend-settings-schema.js.map +1 -0
- package/dist/lib/codex-manager/behavior-settings-panel.d.ts +33 -0
- package/dist/lib/codex-manager/behavior-settings-panel.d.ts.map +1 -0
- package/dist/lib/codex-manager/behavior-settings-panel.js +180 -0
- package/dist/lib/codex-manager/behavior-settings-panel.js.map +1 -0
- package/dist/lib/codex-manager/commands/best.d.ts +81 -0
- package/dist/lib/codex-manager/commands/best.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/best.js +223 -0
- package/dist/lib/codex-manager/commands/best.js.map +1 -0
- package/dist/lib/codex-manager/commands/check.d.ts +7 -0
- package/dist/lib/codex-manager/commands/check.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/check.js +5 -0
- package/dist/lib/codex-manager/commands/check.js.map +1 -0
- package/dist/lib/codex-manager/commands/config-explain.d.ts +7 -0
- package/dist/lib/codex-manager/commands/config-explain.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/config-explain.js +31 -0
- package/dist/lib/codex-manager/commands/config-explain.js.map +1 -0
- package/dist/lib/codex-manager/commands/debug-bundle.d.ts +28 -0
- package/dist/lib/codex-manager/commands/debug-bundle.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/debug-bundle.js +62 -0
- package/dist/lib/codex-manager/commands/debug-bundle.js.map +1 -0
- package/dist/lib/codex-manager/commands/doctor.d.ts +85 -0
- package/dist/lib/codex-manager/commands/doctor.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/doctor.js +424 -0
- package/dist/lib/codex-manager/commands/doctor.js.map +1 -0
- package/dist/lib/codex-manager/commands/fix.d.ts +92 -0
- package/dist/lib/codex-manager/commands/fix.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/fix.js +347 -0
- package/dist/lib/codex-manager/commands/fix.js.map +1 -0
- package/dist/lib/codex-manager/commands/forecast.d.ts +71 -0
- package/dist/lib/codex-manager/commands/forecast.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/forecast.js +371 -0
- package/dist/lib/codex-manager/commands/forecast.js.map +1 -0
- package/dist/lib/codex-manager/commands/init-config.d.ts +15 -0
- package/dist/lib/codex-manager/commands/init-config.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/init-config.js +95 -0
- package/dist/lib/codex-manager/commands/init-config.js.map +1 -0
- package/dist/lib/codex-manager/commands/report.d.ts +25 -0
- package/dist/lib/codex-manager/commands/report.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/report.js +399 -0
- package/dist/lib/codex-manager/commands/report.js.map +1 -0
- package/dist/lib/codex-manager/commands/status.d.ts +23 -0
- package/dist/lib/codex-manager/commands/status.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/status.js +50 -0
- package/dist/lib/codex-manager/commands/status.js.map +1 -0
- package/dist/lib/codex-manager/commands/switch.d.ts +22 -0
- package/dist/lib/codex-manager/commands/switch.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/switch.js +41 -0
- package/dist/lib/codex-manager/commands/switch.js.map +1 -0
- package/dist/lib/codex-manager/commands/verify-flagged.d.ts +69 -0
- package/dist/lib/codex-manager/commands/verify-flagged.d.ts.map +1 -0
- package/dist/lib/codex-manager/commands/verify-flagged.js +251 -0
- package/dist/lib/codex-manager/commands/verify-flagged.js.map +1 -0
- package/dist/lib/codex-manager/dashboard-display-panel.d.ts +40 -0
- package/dist/lib/codex-manager/dashboard-display-panel.d.ts.map +1 -0
- package/dist/lib/codex-manager/dashboard-display-panel.js +187 -0
- package/dist/lib/codex-manager/dashboard-display-panel.js.map +1 -0
- package/dist/lib/codex-manager/dashboard-formatters.d.ts +6 -0
- package/dist/lib/codex-manager/dashboard-formatters.d.ts.map +1 -0
- package/dist/lib/codex-manager/dashboard-formatters.js +19 -0
- package/dist/lib/codex-manager/dashboard-formatters.js.map +1 -0
- package/dist/lib/codex-manager/dashboard-settings-controller.d.ts +12 -0
- package/dist/lib/codex-manager/dashboard-settings-controller.d.ts.map +1 -0
- package/dist/lib/codex-manager/dashboard-settings-controller.js +17 -0
- package/dist/lib/codex-manager/dashboard-settings-controller.js.map +1 -0
- package/dist/lib/codex-manager/dashboard-settings-data.d.ts +10 -0
- package/dist/lib/codex-manager/dashboard-settings-data.d.ts.map +1 -0
- package/dist/lib/codex-manager/dashboard-settings-data.js +95 -0
- package/dist/lib/codex-manager/dashboard-settings-data.js.map +1 -0
- package/dist/lib/codex-manager/dashboard-settings-entry.d.ts +22 -0
- package/dist/lib/codex-manager/dashboard-settings-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/dashboard-settings-entry.js +13 -0
- package/dist/lib/codex-manager/dashboard-settings-entry.js.map +1 -0
- package/dist/lib/codex-manager/experimental-settings-entry.d.ts +7 -0
- package/dist/lib/codex-manager/experimental-settings-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/experimental-settings-entry.js +30 -0
- package/dist/lib/codex-manager/experimental-settings-entry.js.map +1 -0
- package/dist/lib/codex-manager/experimental-settings-prompt.d.ts +66 -0
- package/dist/lib/codex-manager/experimental-settings-prompt.d.ts.map +1 -0
- package/dist/lib/codex-manager/experimental-settings-prompt.js +221 -0
- package/dist/lib/codex-manager/experimental-settings-prompt.js.map +1 -0
- package/dist/lib/codex-manager/experimental-settings-schema.d.ts +23 -0
- package/dist/lib/codex-manager/experimental-settings-schema.d.ts.map +1 -0
- package/dist/lib/codex-manager/experimental-settings-schema.js +34 -0
- package/dist/lib/codex-manager/experimental-settings-schema.js.map +1 -0
- package/dist/lib/codex-manager/experimental-sync-target-entry.d.ts +30 -0
- package/dist/lib/codex-manager/experimental-sync-target-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/experimental-sync-target-entry.js +16 -0
- package/dist/lib/codex-manager/experimental-sync-target-entry.js.map +1 -0
- package/dist/lib/codex-manager/experimental-sync-target.d.ts +23 -0
- package/dist/lib/codex-manager/experimental-sync-target.d.ts.map +1 -0
- package/dist/lib/codex-manager/experimental-sync-target.js +39 -0
- package/dist/lib/codex-manager/experimental-sync-target.js.map +1 -0
- package/dist/lib/codex-manager/forecast-report-commands.d.ts +54 -0
- package/dist/lib/codex-manager/forecast-report-commands.d.ts.map +1 -0
- package/dist/lib/codex-manager/forecast-report-commands.js +443 -0
- package/dist/lib/codex-manager/forecast-report-commands.js.map +1 -0
- package/dist/lib/codex-manager/help.d.ts +36 -0
- package/dist/lib/codex-manager/help.d.ts.map +1 -0
- package/dist/lib/codex-manager/help.js +125 -0
- package/dist/lib/codex-manager/help.js.map +1 -0
- package/dist/lib/codex-manager/repair-commands.d.ts +70 -0
- package/dist/lib/codex-manager/repair-commands.d.ts.map +1 -0
- package/dist/lib/codex-manager/repair-commands.js +1671 -0
- package/dist/lib/codex-manager/repair-commands.js.map +1 -0
- package/dist/lib/codex-manager/settings-hub-entry.d.ts +30 -0
- package/dist/lib/codex-manager/settings-hub-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-hub-entry.js +11 -0
- package/dist/lib/codex-manager/settings-hub-entry.js.map +1 -0
- package/dist/lib/codex-manager/settings-hub-menu.d.ts +30 -0
- package/dist/lib/codex-manager/settings-hub-menu.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-hub-menu.js +37 -0
- package/dist/lib/codex-manager/settings-hub-menu.js.map +1 -0
- package/dist/lib/codex-manager/settings-hub-prompt.d.ts +25 -0
- package/dist/lib/codex-manager/settings-hub-prompt.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-hub-prompt.js +23 -0
- package/dist/lib/codex-manager/settings-hub-prompt.js.map +1 -0
- package/dist/lib/codex-manager/settings-hub.d.ts +10 -29
- package/dist/lib/codex-manager/settings-hub.d.ts.map +1 -1
- package/dist/lib/codex-manager/settings-hub.js +260 -2168
- package/dist/lib/codex-manager/settings-hub.js.map +1 -1
- package/dist/lib/codex-manager/settings-panels.d.ts +56 -0
- package/dist/lib/codex-manager/settings-panels.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-panels.js +73 -0
- package/dist/lib/codex-manager/settings-panels.js.map +1 -0
- package/dist/lib/codex-manager/settings-persist-utils.d.ts +9 -0
- package/dist/lib/codex-manager/settings-persist-utils.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-persist-utils.js +33 -0
- package/dist/lib/codex-manager/settings-persist-utils.js.map +1 -0
- package/dist/lib/codex-manager/settings-preview.d.ts +12 -0
- package/dist/lib/codex-manager/settings-preview.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-preview.js +118 -0
- package/dist/lib/codex-manager/settings-preview.js.map +1 -0
- package/dist/lib/codex-manager/settings-write-queue.d.ts +14 -0
- package/dist/lib/codex-manager/settings-write-queue.d.ts.map +1 -0
- package/dist/lib/codex-manager/settings-write-queue.js +88 -0
- package/dist/lib/codex-manager/settings-write-queue.js.map +1 -0
- package/dist/lib/codex-manager/statusline-order.d.ts +3 -0
- package/dist/lib/codex-manager/statusline-order.d.ts.map +1 -0
- package/dist/lib/codex-manager/statusline-order.js +17 -0
- package/dist/lib/codex-manager/statusline-order.js.map +1 -0
- package/dist/lib/codex-manager/statusline-settings-panel.d.ts +40 -0
- package/dist/lib/codex-manager/statusline-settings-panel.d.ts.map +1 -0
- package/dist/lib/codex-manager/statusline-settings-panel.js +167 -0
- package/dist/lib/codex-manager/statusline-settings-panel.js.map +1 -0
- package/dist/lib/codex-manager/theme-settings-panel.d.ts +26 -0
- package/dist/lib/codex-manager/theme-settings-panel.d.ts.map +1 -0
- package/dist/lib/codex-manager/theme-settings-panel.js +131 -0
- package/dist/lib/codex-manager/theme-settings-panel.js.map +1 -0
- package/dist/lib/codex-manager/unified-settings-controller.d.ts +27 -0
- package/dist/lib/codex-manager/unified-settings-controller.d.ts.map +1 -0
- package/dist/lib/codex-manager/unified-settings-controller.js +50 -0
- package/dist/lib/codex-manager/unified-settings-controller.js.map +1 -0
- package/dist/lib/codex-manager/unified-settings-entry.d.ts +6 -0
- package/dist/lib/codex-manager/unified-settings-entry.d.ts.map +1 -0
- package/dist/lib/codex-manager/unified-settings-entry.js +23 -0
- package/dist/lib/codex-manager/unified-settings-entry.js.map +1 -0
- package/dist/lib/codex-manager.d.ts.map +1 -1
- package/dist/lib/codex-manager.js +441 -2199
- package/dist/lib/codex-manager.js.map +1 -1
- package/dist/lib/config.d.ts +38 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +371 -9
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/errors.d.ts +9 -0
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +13 -0
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/forecast.d.ts +17 -0
- package/dist/lib/forecast.d.ts.map +1 -1
- package/dist/lib/forecast.js +33 -6
- package/dist/lib/forecast.js.map +1 -1
- package/dist/lib/health.d.ts +1 -0
- package/dist/lib/health.d.ts.map +1 -1
- package/dist/lib/health.js +6 -2
- package/dist/lib/health.js.map +1 -1
- package/dist/lib/named-backup-export.js +2 -2
- package/dist/lib/named-backup-export.js.map +1 -1
- package/dist/lib/parallel-probe.d.ts +1 -1
- package/dist/lib/parallel-probe.d.ts.map +1 -1
- package/dist/lib/parallel-probe.js +5 -2
- package/dist/lib/parallel-probe.js.map +1 -1
- package/dist/lib/proactive-refresh.d.ts +1 -1
- package/dist/lib/proactive-refresh.d.ts.map +1 -1
- package/dist/lib/proactive-refresh.js +14 -5
- package/dist/lib/proactive-refresh.js.map +1 -1
- package/dist/lib/prompts/codex.d.ts +8 -3
- package/dist/lib/prompts/codex.d.ts.map +1 -1
- package/dist/lib/prompts/codex.js +16 -26
- package/dist/lib/prompts/codex.js.map +1 -1
- package/dist/lib/refresh-guardian.d.ts +3 -0
- package/dist/lib/refresh-guardian.d.ts.map +1 -1
- package/dist/lib/refresh-guardian.js +142 -52
- package/dist/lib/refresh-guardian.js.map +1 -1
- package/dist/lib/request/failover-config.d.ts +4 -0
- package/dist/lib/request/failover-config.d.ts.map +1 -0
- package/dist/lib/request/failover-config.js +15 -0
- package/dist/lib/request/failover-config.js.map +1 -0
- package/dist/lib/request/fetch-helpers.d.ts +10 -4
- package/dist/lib/request/fetch-helpers.d.ts.map +1 -1
- package/dist/lib/request/fetch-helpers.js +77 -21
- package/dist/lib/request/fetch-helpers.js.map +1 -1
- package/dist/lib/request/helpers/model-map.d.ts +49 -12
- package/dist/lib/request/helpers/model-map.d.ts.map +1 -1
- package/dist/lib/request/helpers/model-map.js +303 -108
- package/dist/lib/request/helpers/model-map.js.map +1 -1
- package/dist/lib/request/helpers/tool-utils.d.ts +2 -15
- package/dist/lib/request/helpers/tool-utils.d.ts.map +1 -1
- package/dist/lib/request/helpers/tool-utils.js +40 -27
- package/dist/lib/request/helpers/tool-utils.js.map +1 -1
- package/dist/lib/request/index.d.ts +5 -0
- package/dist/lib/request/index.d.ts.map +1 -0
- package/dist/lib/request/index.js +5 -0
- package/dist/lib/request/index.js.map +1 -0
- package/dist/lib/request/request-init.d.ts +3 -0
- package/dist/lib/request/request-init.d.ts.map +1 -0
- package/dist/lib/request/request-init.js +50 -0
- package/dist/lib/request/request-init.js.map +1 -0
- package/dist/lib/request/request-transformer.d.ts +19 -6
- package/dist/lib/request/request-transformer.d.ts.map +1 -1
- package/dist/lib/request/request-transformer.js +210 -193
- package/dist/lib/request/request-transformer.js.map +1 -1
- package/dist/lib/request/response-compaction.d.ts +20 -0
- package/dist/lib/request/response-compaction.d.ts.map +1 -0
- package/dist/lib/request/response-compaction.js +124 -0
- package/dist/lib/request/response-compaction.js.map +1 -0
- package/dist/lib/request/response-handler.d.ts +2 -0
- package/dist/lib/request/response-handler.d.ts.map +1 -1
- package/dist/lib/request/response-handler.js +567 -11
- package/dist/lib/request/response-handler.js.map +1 -1
- package/dist/lib/request/response-metadata.d.ts +3 -0
- package/dist/lib/request/response-metadata.d.ts.map +1 -0
- package/dist/lib/request/response-metadata.js +61 -0
- package/dist/lib/request/response-metadata.js.map +1 -0
- package/dist/lib/request/wait-utils.d.ts +14 -0
- package/dist/lib/request/wait-utils.d.ts.map +1 -0
- package/dist/lib/request/wait-utils.js +44 -0
- package/dist/lib/request/wait-utils.js.map +1 -0
- package/dist/lib/rotation.d.ts +14 -11
- package/dist/lib/rotation.d.ts.map +1 -1
- package/dist/lib/rotation.js +36 -30
- package/dist/lib/rotation.js.map +1 -1
- package/dist/lib/runtime/account-check-helpers.d.ts +8 -0
- package/dist/lib/runtime/account-check-helpers.d.ts.map +1 -0
- package/dist/lib/runtime/account-check-helpers.js +30 -0
- package/dist/lib/runtime/account-check-helpers.js.map +1 -0
- package/dist/lib/runtime/account-check-types.d.ts +18 -0
- package/dist/lib/runtime/account-check-types.d.ts.map +1 -0
- package/dist/lib/runtime/account-check-types.js +12 -0
- package/dist/lib/runtime/account-check-types.js.map +1 -0
- package/dist/lib/runtime/account-check.d.ts +48 -0
- package/dist/lib/runtime/account-check.d.ts.map +1 -0
- package/dist/lib/runtime/account-check.js +202 -0
- package/dist/lib/runtime/account-check.js.map +1 -0
- package/dist/lib/runtime/account-health-check.d.ts +8 -0
- package/dist/lib/runtime/account-health-check.d.ts.map +1 -0
- package/dist/lib/runtime/account-health-check.js +30 -0
- package/dist/lib/runtime/account-health-check.js.map +1 -0
- package/dist/lib/runtime/account-manager-cache-entry.d.ts +25 -0
- package/dist/lib/runtime/account-manager-cache-entry.d.ts.map +1 -0
- package/dist/lib/runtime/account-manager-cache-entry.js +17 -0
- package/dist/lib/runtime/account-manager-cache-entry.js.map +1 -0
- package/dist/lib/runtime/account-manager-cache.d.ts +25 -0
- package/dist/lib/runtime/account-manager-cache.d.ts.map +1 -0
- package/dist/lib/runtime/account-manager-cache.js +44 -0
- package/dist/lib/runtime/account-manager-cache.js.map +1 -0
- package/dist/lib/runtime/account-pool.d.ts +23 -0
- package/dist/lib/runtime/account-pool.d.ts.map +1 -0
- package/dist/lib/runtime/account-pool.js +138 -0
- package/dist/lib/runtime/account-pool.js.map +1 -0
- package/dist/lib/runtime/account-scope.d.ts +10 -0
- package/dist/lib/runtime/account-scope.d.ts.map +1 -0
- package/dist/lib/runtime/account-scope.js +13 -0
- package/dist/lib/runtime/account-scope.js.map +1 -0
- package/dist/lib/runtime/account-select-event.d.ts +19 -0
- package/dist/lib/runtime/account-select-event.d.ts.map +1 -0
- package/dist/lib/runtime/account-select-event.js +53 -0
- package/dist/lib/runtime/account-select-event.js.map +1 -0
- package/dist/lib/runtime/account-selection.d.ts +28 -0
- package/dist/lib/runtime/account-selection.d.ts.map +1 -0
- package/dist/lib/runtime/account-selection.js +46 -0
- package/dist/lib/runtime/account-selection.js.map +1 -0
- package/dist/lib/runtime/account-state.d.ts +13 -0
- package/dist/lib/runtime/account-state.d.ts.map +1 -0
- package/dist/lib/runtime/account-state.js +38 -0
- package/dist/lib/runtime/account-state.js.map +1 -0
- package/dist/lib/runtime/account-status.d.ts +13 -0
- package/dist/lib/runtime/account-status.d.ts.map +1 -0
- package/dist/lib/runtime/account-status.js +37 -0
- package/dist/lib/runtime/account-status.js.map +1 -0
- package/dist/lib/runtime/account-storage-scope-entry.d.ts +26 -0
- package/dist/lib/runtime/account-storage-scope-entry.d.ts.map +1 -0
- package/dist/lib/runtime/account-storage-scope-entry.js +15 -0
- package/dist/lib/runtime/account-storage-scope-entry.js.map +1 -0
- package/dist/lib/runtime/auth-facade.d.ts +51 -0
- package/dist/lib/runtime/auth-facade.d.ts.map +1 -0
- package/dist/lib/runtime/auth-facade.js +48 -0
- package/dist/lib/runtime/auth-facade.js.map +1 -0
- package/dist/lib/runtime/browser-oauth-flow.d.ts +32 -0
- package/dist/lib/runtime/browser-oauth-flow.d.ts.map +1 -0
- package/dist/lib/runtime/browser-oauth-flow.js +31 -0
- package/dist/lib/runtime/browser-oauth-flow.js.map +1 -0
- package/dist/lib/runtime/capability-boost.d.ts +25 -0
- package/dist/lib/runtime/capability-boost.d.ts.map +1 -0
- package/dist/lib/runtime/capability-boost.js +26 -0
- package/dist/lib/runtime/capability-boost.js.map +1 -0
- package/dist/lib/runtime/event-handler.d.ts +53 -0
- package/dist/lib/runtime/event-handler.d.ts.map +1 -0
- package/dist/lib/runtime/event-handler.js +46 -0
- package/dist/lib/runtime/event-handler.js.map +1 -0
- package/dist/lib/runtime/flagged-verify-types.d.ts +9 -0
- package/dist/lib/runtime/flagged-verify-types.d.ts.map +1 -0
- package/dist/lib/runtime/flagged-verify-types.js +7 -0
- package/dist/lib/runtime/flagged-verify-types.js.map +1 -0
- package/dist/lib/runtime/hydrate-emails.d.ts +13 -0
- package/dist/lib/runtime/hydrate-emails.d.ts.map +1 -0
- package/dist/lib/runtime/hydrate-emails.js +56 -0
- package/dist/lib/runtime/hydrate-emails.js.map +1 -0
- package/dist/lib/runtime/live-sync-entry.d.ts +36 -0
- package/dist/lib/runtime/live-sync-entry.d.ts.map +1 -0
- package/dist/lib/runtime/live-sync-entry.js +14 -0
- package/dist/lib/runtime/live-sync-entry.js.map +1 -0
- package/dist/lib/runtime/live-sync.d.ts +35 -0
- package/dist/lib/runtime/live-sync.d.ts.map +1 -0
- package/dist/lib/runtime/live-sync.js +65 -0
- package/dist/lib/runtime/live-sync.js.map +1 -0
- package/dist/lib/runtime/loader-setup.d.ts +9 -0
- package/dist/lib/runtime/loader-setup.d.ts.map +1 -0
- package/dist/lib/runtime/loader-setup.js +8 -0
- package/dist/lib/runtime/loader-setup.js.map +1 -0
- package/dist/lib/runtime/login-menu-accounts.d.ts +29 -0
- package/dist/lib/runtime/login-menu-accounts.d.ts.map +1 -0
- package/dist/lib/runtime/login-menu-accounts.js +33 -0
- package/dist/lib/runtime/login-menu-accounts.js.map +1 -0
- package/dist/lib/runtime/manual-oauth-flow.d.ts +40 -0
- package/dist/lib/runtime/manual-oauth-flow.d.ts.map +1 -0
- package/dist/lib/runtime/manual-oauth-flow.js +71 -0
- package/dist/lib/runtime/manual-oauth-flow.js.map +1 -0
- package/dist/lib/runtime/metrics.d.ts +29 -0
- package/dist/lib/runtime/metrics.d.ts.map +1 -0
- package/dist/lib/runtime/metrics.js +97 -0
- package/dist/lib/runtime/metrics.js.map +1 -0
- package/dist/lib/runtime/oauth-browser-flow.d.ts +9 -0
- package/dist/lib/runtime/oauth-browser-flow.d.ts.map +1 -0
- package/dist/lib/runtime/oauth-browser-flow.js +34 -0
- package/dist/lib/runtime/oauth-browser-flow.js.map +1 -0
- package/dist/lib/runtime/preemptive-quota.d.ts +13 -0
- package/dist/lib/runtime/preemptive-quota.d.ts.map +1 -0
- package/dist/lib/runtime/preemptive-quota.js +9 -0
- package/dist/lib/runtime/preemptive-quota.js.map +1 -0
- package/dist/lib/runtime/quota-headers.d.ts +12 -0
- package/dist/lib/runtime/quota-headers.d.ts.map +1 -0
- package/dist/lib/runtime/quota-headers.js +131 -0
- package/dist/lib/runtime/quota-headers.js.map +1 -0
- package/dist/lib/runtime/quota-probe.d.ts +18 -0
- package/dist/lib/runtime/quota-probe.d.ts.map +1 -0
- package/dist/lib/runtime/quota-probe.js +82 -0
- package/dist/lib/runtime/quota-probe.js.map +1 -0
- package/dist/lib/runtime/quota-settings.d.ts +14 -0
- package/dist/lib/runtime/quota-settings.d.ts.map +1 -0
- package/dist/lib/runtime/quota-settings.js +12 -0
- package/dist/lib/runtime/quota-settings.js.map +1 -0
- package/dist/lib/runtime/refresh-guardian-entry.d.ts +32 -0
- package/dist/lib/runtime/refresh-guardian-entry.d.ts.map +1 -0
- package/dist/lib/runtime/refresh-guardian-entry.js +12 -0
- package/dist/lib/runtime/refresh-guardian-entry.js.map +1 -0
- package/dist/lib/runtime/refresh-guardian.d.ts +24 -0
- package/dist/lib/runtime/refresh-guardian.d.ts.map +1 -0
- package/dist/lib/runtime/refresh-guardian.js +32 -0
- package/dist/lib/runtime/refresh-guardian.js.map +1 -0
- package/dist/lib/runtime/request-init.d.ts +5 -0
- package/dist/lib/runtime/request-init.d.ts.map +1 -0
- package/dist/lib/runtime/request-init.js +50 -0
- package/dist/lib/runtime/request-init.js.map +1 -0
- package/dist/lib/runtime/runtime-services.d.ts +58 -0
- package/dist/lib/runtime/runtime-services.d.ts.map +1 -0
- package/dist/lib/runtime/runtime-services.js +87 -0
- package/dist/lib/runtime/runtime-services.js.map +1 -0
- package/dist/lib/runtime/session-affinity-entry.d.ts +30 -0
- package/dist/lib/runtime/session-affinity-entry.d.ts.map +1 -0
- package/dist/lib/runtime/session-affinity-entry.js +11 -0
- package/dist/lib/runtime/session-affinity-entry.js.map +1 -0
- package/dist/lib/runtime/session-affinity.d.ts +13 -0
- package/dist/lib/runtime/session-affinity.d.ts.map +1 -0
- package/dist/lib/runtime/session-affinity.js +17 -0
- package/dist/lib/runtime/session-affinity.js.map +1 -0
- package/dist/lib/runtime/session-recovery.d.ts +8 -0
- package/dist/lib/runtime/session-recovery.d.ts.map +1 -0
- package/dist/lib/runtime/session-recovery.js +7 -0
- package/dist/lib/runtime/session-recovery.js.map +1 -0
- package/dist/lib/runtime/status-marker.d.ts +3 -0
- package/dist/lib/runtime/status-marker.d.ts.map +1 -0
- package/dist/lib/runtime/status-marker.js +15 -0
- package/dist/lib/runtime/status-marker.js.map +1 -0
- package/dist/lib/runtime/storage-scope.d.ts +13 -0
- package/dist/lib/runtime/storage-scope.d.ts.map +1 -0
- package/dist/lib/runtime/storage-scope.js +14 -0
- package/dist/lib/runtime/storage-scope.js.map +1 -0
- package/dist/lib/runtime/toast.d.ts +16 -0
- package/dist/lib/runtime/toast.d.ts.map +1 -0
- package/dist/lib/runtime/toast.js +16 -0
- package/dist/lib/runtime/toast.js.map +1 -0
- package/dist/lib/runtime/ui-runtime-entry.d.ts +7 -0
- package/dist/lib/runtime/ui-runtime-entry.d.ts.map +1 -0
- package/dist/lib/runtime/ui-runtime-entry.js +4 -0
- package/dist/lib/runtime/ui-runtime-entry.js.map +1 -0
- package/dist/lib/runtime/ui-runtime.d.ts +9 -0
- package/dist/lib/runtime/ui-runtime.d.ts.map +1 -0
- package/dist/lib/runtime/ui-runtime.js +23 -0
- package/dist/lib/runtime/ui-runtime.js.map +1 -0
- package/dist/lib/runtime/verify-flagged.d.ts +44 -0
- package/dist/lib/runtime/verify-flagged.d.ts.map +1 -0
- package/dist/lib/runtime/verify-flagged.js +84 -0
- package/dist/lib/runtime/verify-flagged.js.map +1 -0
- package/dist/lib/schemas.d.ts +2 -0
- package/dist/lib/schemas.d.ts.map +1 -1
- package/dist/lib/schemas.js +2 -0
- package/dist/lib/schemas.js.map +1 -1
- package/dist/lib/session-affinity.d.ts +10 -0
- package/dist/lib/session-affinity.d.ts.map +1 -1
- package/dist/lib/session-affinity.js +53 -6
- package/dist/lib/session-affinity.js.map +1 -1
- package/dist/lib/storage/account-clear-entry.d.ts +16 -0
- package/dist/lib/storage/account-clear-entry.d.ts.map +1 -0
- package/dist/lib/storage/account-clear-entry.js +12 -0
- package/dist/lib/storage/account-clear-entry.js.map +1 -0
- package/dist/lib/storage/account-clear.d.ts +8 -0
- package/dist/lib/storage/account-clear.d.ts.map +1 -0
- package/dist/lib/storage/account-clear.js +29 -0
- package/dist/lib/storage/account-clear.js.map +1 -0
- package/dist/lib/storage/account-match-utils.d.ts +9 -0
- package/dist/lib/storage/account-match-utils.d.ts.map +1 -0
- package/dist/lib/storage/account-match-utils.js +45 -0
- package/dist/lib/storage/account-match-utils.js.map +1 -0
- package/dist/lib/storage/account-persistence.d.ts +3 -0
- package/dist/lib/storage/account-persistence.d.ts.map +1 -0
- package/dist/lib/storage/account-persistence.js +12 -0
- package/dist/lib/storage/account-persistence.js.map +1 -0
- package/dist/lib/storage/account-port.d.ts +50 -0
- package/dist/lib/storage/account-port.d.ts.map +1 -0
- package/dist/lib/storage/account-port.js +43 -0
- package/dist/lib/storage/account-port.js.map +1 -0
- package/dist/lib/storage/account-save-entry.d.ts +7 -0
- package/dist/lib/storage/account-save-entry.d.ts.map +1 -0
- package/dist/lib/storage/account-save-entry.js +6 -0
- package/dist/lib/storage/account-save-entry.js.map +1 -0
- package/dist/lib/storage/account-save.d.ts +30 -0
- package/dist/lib/storage/account-save.d.ts.map +1 -0
- package/dist/lib/storage/account-save.js +49 -0
- package/dist/lib/storage/account-save.js.map +1 -0
- package/dist/lib/storage/account-snapshot.d.ts +25 -0
- package/dist/lib/storage/account-snapshot.d.ts.map +1 -0
- package/dist/lib/storage/account-snapshot.js +78 -0
- package/dist/lib/storage/account-snapshot.js.map +1 -0
- package/dist/lib/storage/backup-metadata-builder.d.ts +32 -0
- package/dist/lib/storage/backup-metadata-builder.d.ts.map +1 -0
- package/dist/lib/storage/backup-metadata-builder.js +77 -0
- package/dist/lib/storage/backup-metadata-builder.js.map +1 -0
- package/dist/lib/storage/backup-metadata.d.ts +29 -0
- package/dist/lib/storage/backup-metadata.d.ts.map +1 -0
- package/dist/lib/storage/backup-metadata.js +16 -0
- package/dist/lib/storage/backup-metadata.js.map +1 -0
- package/dist/lib/storage/backup-paths.d.ts +10 -0
- package/dist/lib/storage/backup-paths.d.ts.map +1 -0
- package/dist/lib/storage/backup-paths.js +27 -0
- package/dist/lib/storage/backup-paths.js.map +1 -0
- package/dist/lib/storage/backup-restore.d.ts +11 -0
- package/dist/lib/storage/backup-restore.d.ts.map +1 -0
- package/dist/lib/storage/backup-restore.js +52 -0
- package/dist/lib/storage/backup-restore.js.map +1 -0
- package/dist/lib/storage/cache-artifacts.d.ts +2 -0
- package/dist/lib/storage/cache-artifacts.d.ts.map +1 -0
- package/dist/lib/storage/cache-artifacts.js +4 -0
- package/dist/lib/storage/cache-artifacts.js.map +1 -0
- package/dist/lib/storage/error-hints.d.ts +10 -0
- package/dist/lib/storage/error-hints.d.ts.map +1 -0
- package/dist/lib/storage/error-hints.js +36 -0
- package/dist/lib/storage/error-hints.js.map +1 -0
- package/dist/lib/storage/file-paths.d.ts +6 -0
- package/dist/lib/storage/file-paths.d.ts.map +1 -0
- package/dist/lib/storage/file-paths.js +17 -0
- package/dist/lib/storage/file-paths.js.map +1 -0
- package/dist/lib/storage/fixture-guards.d.ts +4 -0
- package/dist/lib/storage/fixture-guards.d.ts.map +1 -0
- package/dist/lib/storage/fixture-guards.js +27 -0
- package/dist/lib/storage/fixture-guards.js.map +1 -0
- package/dist/lib/storage/flagged-entry.d.ts +15 -0
- package/dist/lib/storage/flagged-entry.d.ts.map +1 -0
- package/dist/lib/storage/flagged-entry.js +12 -0
- package/dist/lib/storage/flagged-entry.js.map +1 -0
- package/dist/lib/storage/flagged-load-entry.d.ts +20 -0
- package/dist/lib/storage/flagged-load-entry.d.ts.map +1 -0
- package/dist/lib/storage/flagged-load-entry.js +13 -0
- package/dist/lib/storage/flagged-load-entry.js.map +1 -0
- package/dist/lib/storage/flagged-save-entry.d.ts +7 -0
- package/dist/lib/storage/flagged-save-entry.d.ts.map +1 -0
- package/dist/lib/storage/flagged-save-entry.js +6 -0
- package/dist/lib/storage/flagged-save-entry.js.map +1 -0
- package/dist/lib/storage/flagged-storage-file.d.ts +7 -0
- package/dist/lib/storage/flagged-storage-file.d.ts.map +1 -0
- package/dist/lib/storage/flagged-storage-file.js +25 -0
- package/dist/lib/storage/flagged-storage-file.js.map +1 -0
- package/dist/lib/storage/flagged-storage-io.d.ts +28 -0
- package/dist/lib/storage/flagged-storage-io.d.ts.map +1 -0
- package/dist/lib/storage/flagged-storage-io.js +135 -0
- package/dist/lib/storage/flagged-storage-io.js.map +1 -0
- package/dist/lib/storage/flagged-storage.d.ts +6 -0
- package/dist/lib/storage/flagged-storage.d.ts.map +1 -0
- package/dist/lib/storage/flagged-storage.js +90 -0
- package/dist/lib/storage/flagged-storage.js.map +1 -0
- package/dist/lib/storage/gitignore.d.ts +7 -0
- package/dist/lib/storage/gitignore.d.ts.map +1 -0
- package/dist/lib/storage/gitignore.js +34 -0
- package/dist/lib/storage/gitignore.js.map +1 -0
- package/dist/lib/storage/hash.d.ts +2 -0
- package/dist/lib/storage/hash.d.ts.map +1 -0
- package/dist/lib/storage/hash.js +5 -0
- package/dist/lib/storage/hash.js.map +1 -0
- package/dist/lib/storage/identity.d.ts +21 -0
- package/dist/lib/storage/identity.d.ts.map +1 -0
- package/dist/lib/storage/identity.js +59 -0
- package/dist/lib/storage/identity.js.map +1 -0
- package/dist/lib/storage/import-export.d.ts +24 -0
- package/dist/lib/storage/import-export.d.ts.map +1 -0
- package/dist/lib/storage/import-export.js +108 -0
- package/dist/lib/storage/import-export.js.map +1 -0
- package/dist/lib/storage/metadata-section.d.ts +16 -0
- package/dist/lib/storage/metadata-section.d.ts.map +1 -0
- package/dist/lib/storage/metadata-section.js +16 -0
- package/dist/lib/storage/metadata-section.js.map +1 -0
- package/dist/lib/storage/named-backup-entry.d.ts +15 -0
- package/dist/lib/storage/named-backup-entry.d.ts.map +1 -0
- package/dist/lib/storage/named-backup-entry.js +7 -0
- package/dist/lib/storage/named-backup-entry.js.map +1 -0
- package/dist/lib/storage/named-backups-entry.d.ts +19 -0
- package/dist/lib/storage/named-backups-entry.d.ts.map +1 -0
- package/dist/lib/storage/named-backups-entry.js +7 -0
- package/dist/lib/storage/named-backups-entry.js.map +1 -0
- package/dist/lib/storage/named-backups.d.ts +15 -0
- package/dist/lib/storage/named-backups.d.ts.map +1 -0
- package/dist/lib/storage/named-backups.js +68 -0
- package/dist/lib/storage/named-backups.js.map +1 -0
- package/dist/lib/storage/path-state.d.ts +9 -0
- package/dist/lib/storage/path-state.d.ts.map +1 -0
- package/dist/lib/storage/path-state.js +20 -0
- package/dist/lib/storage/path-state.js.map +1 -0
- package/dist/lib/storage/project-migration.d.ts +10 -0
- package/dist/lib/storage/project-migration.d.ts.map +1 -0
- package/dist/lib/storage/project-migration.js +38 -0
- package/dist/lib/storage/project-migration.js.map +1 -0
- package/dist/lib/storage/record-utils.d.ts +3 -0
- package/dist/lib/storage/record-utils.d.ts.map +1 -0
- package/dist/lib/storage/record-utils.js +9 -0
- package/dist/lib/storage/record-utils.js.map +1 -0
- package/dist/lib/storage/restore-assessment.d.ts +7 -0
- package/dist/lib/storage/restore-assessment.d.ts.map +1 -0
- package/dist/lib/storage/restore-assessment.js +42 -0
- package/dist/lib/storage/restore-assessment.js.map +1 -0
- package/dist/lib/storage/restore-backup-entry.d.ts +24 -0
- package/dist/lib/storage/restore-backup-entry.d.ts.map +1 -0
- package/dist/lib/storage/restore-backup-entry.js +10 -0
- package/dist/lib/storage/restore-backup-entry.js.map +1 -0
- package/dist/lib/storage/restore-metadata.d.ts +10 -0
- package/dist/lib/storage/restore-metadata.d.ts.map +1 -0
- package/dist/lib/storage/restore-metadata.js +18 -0
- package/dist/lib/storage/restore-metadata.js.map +1 -0
- package/dist/lib/storage/restore.d.ts +14 -0
- package/dist/lib/storage/restore.d.ts.map +1 -0
- package/dist/lib/storage/restore.js +53 -0
- package/dist/lib/storage/restore.js.map +1 -0
- package/dist/lib/storage/snapshot-inspectors.d.ts +22 -0
- package/dist/lib/storage/snapshot-inspectors.d.ts.map +1 -0
- package/dist/lib/storage/snapshot-inspectors.js +95 -0
- package/dist/lib/storage/snapshot-inspectors.js.map +1 -0
- package/dist/lib/storage/storage-parser.d.ts +15 -0
- package/dist/lib/storage/storage-parser.d.ts.map +1 -0
- package/dist/lib/storage/storage-parser.js +16 -0
- package/dist/lib/storage/storage-parser.js.map +1 -0
- package/dist/lib/storage/transactions.d.ts +23 -0
- package/dist/lib/storage/transactions.d.ts.map +1 -0
- package/dist/lib/storage/transactions.js +64 -0
- package/dist/lib/storage/transactions.js.map +1 -0
- package/dist/lib/storage.d.ts +8 -47
- package/dist/lib/storage.d.ts.map +1 -1
- package/dist/lib/storage.js +482 -1044
- package/dist/lib/storage.js.map +1 -1
- package/dist/lib/types.d.ts +80 -1
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +41 -4
- package/scripts/check-pack-budget-lib.js +114 -0
- package/scripts/check-pack-budget.mjs +10 -0
- package/scripts/codex-multi-auth.js +34 -10
- package/scripts/install-codex-auth-utils.js +54 -14
- package/scripts/install-codex-auth.js +62 -33
- package/scripts/update-vendor-provenance.mjs +96 -0
- package/scripts/verify-vendor-provenance.mjs +53 -0
|
@@ -0,0 +1,1671 @@
|
|
|
1
|
+
import { existsSync, promises as fs } from "node:fs";
|
|
2
|
+
import { ACCOUNT_LIMITS } from "../constants.js";
|
|
3
|
+
import { DEFAULT_DASHBOARD_DISPLAY_SETTINGS } from "../dashboard-settings.js";
|
|
4
|
+
import { evaluateForecastAccounts, isHardRefreshFailure, recommendForecastAccount, } from "../forecast.js";
|
|
5
|
+
import { extractAccountEmail, extractAccountId, formatAccountLabel, sanitizeEmail, } from "../accounts.js";
|
|
6
|
+
import { loadQuotaCache, saveQuotaCache } from "../quota-cache.js";
|
|
7
|
+
import { fetchCodexQuotaSnapshot } from "../quota-probe.js";
|
|
8
|
+
import { queuedRefresh } from "../refresh-queue.js";
|
|
9
|
+
import { findMatchingAccountIndex, getStoragePath, loadAccounts, loadFlaggedAccounts, setStoragePath, withAccountStorageTransaction, withAccountAndFlaggedStorageTransaction, withFlaggedStorageTransaction, } from "../storage.js";
|
|
10
|
+
import { getCodexCliAuthPath, getCodexCliConfigPath, loadCodexCliState, } from "../codex-cli/state.js";
|
|
11
|
+
import { setCodexCliActiveSelection } from "../codex-cli/writer.js";
|
|
12
|
+
import { MODEL_FAMILIES } from "../prompts/codex.js";
|
|
13
|
+
import { resolveNormalizedModel } from "../request/helpers/model-map.js";
|
|
14
|
+
export function printFixUsage() {
|
|
15
|
+
console.log([
|
|
16
|
+
"Usage:",
|
|
17
|
+
" codex auth fix [--dry-run] [--json] [--live] [--model <model>]",
|
|
18
|
+
"",
|
|
19
|
+
"Options:",
|
|
20
|
+
" --dry-run, -n Preview changes without writing storage",
|
|
21
|
+
" --json, -j Print machine-readable JSON output",
|
|
22
|
+
" --live, -l Run live session probe before deciding health",
|
|
23
|
+
" --model, -m Probe model for live mode (default: gpt-5-codex)",
|
|
24
|
+
"",
|
|
25
|
+
"Behavior:",
|
|
26
|
+
" - Refreshes tokens for enabled accounts",
|
|
27
|
+
" - Disables hard-failed accounts (never deletes)",
|
|
28
|
+
" - Recommends a better current account when needed",
|
|
29
|
+
].join("\n"));
|
|
30
|
+
}
|
|
31
|
+
export function printVerifyFlaggedUsage() {
|
|
32
|
+
console.log([
|
|
33
|
+
"Usage:",
|
|
34
|
+
" codex auth verify-flagged [--dry-run] [--json] [--no-restore]",
|
|
35
|
+
"",
|
|
36
|
+
"Options:",
|
|
37
|
+
" --dry-run, -n Preview changes without writing storage",
|
|
38
|
+
" --json, -j Print machine-readable JSON output",
|
|
39
|
+
" --no-restore Check flagged accounts without restoring healthy ones",
|
|
40
|
+
"",
|
|
41
|
+
"Behavior:",
|
|
42
|
+
" - Refresh-checks accounts from flagged storage",
|
|
43
|
+
" - Restores healthy accounts back to active storage by default",
|
|
44
|
+
].join("\n"));
|
|
45
|
+
}
|
|
46
|
+
export function printDoctorUsage() {
|
|
47
|
+
console.log([
|
|
48
|
+
"Usage:",
|
|
49
|
+
" codex auth doctor [--json] [--fix] [--dry-run]",
|
|
50
|
+
"",
|
|
51
|
+
"Options:",
|
|
52
|
+
" --json, -j Print machine-readable JSON diagnostics",
|
|
53
|
+
" --fix Apply safe auto-fixes to storage",
|
|
54
|
+
" --dry-run, -n Preview --fix changes without writing storage",
|
|
55
|
+
"",
|
|
56
|
+
"Behavior:",
|
|
57
|
+
" - Validates account storage readability",
|
|
58
|
+
" - Checks active index consistency and account duplication",
|
|
59
|
+
" - Flags placeholder/demo accounts and disabled-all scenarios",
|
|
60
|
+
].join("\n"));
|
|
61
|
+
}
|
|
62
|
+
export function parseFixArgs(args) {
|
|
63
|
+
const options = {
|
|
64
|
+
dryRun: false,
|
|
65
|
+
json: false,
|
|
66
|
+
live: false,
|
|
67
|
+
model: "gpt-5-codex",
|
|
68
|
+
};
|
|
69
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
70
|
+
const argValue = args[i];
|
|
71
|
+
if (typeof argValue !== "string")
|
|
72
|
+
continue;
|
|
73
|
+
if (argValue === "--dry-run" || argValue === "-n") {
|
|
74
|
+
options.dryRun = true;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (argValue === "--json" || argValue === "-j") {
|
|
78
|
+
options.json = true;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (argValue === "--live" || argValue === "-l") {
|
|
82
|
+
options.live = true;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (argValue === "--model" || argValue === "-m") {
|
|
86
|
+
const value = args[i + 1];
|
|
87
|
+
if (!value) {
|
|
88
|
+
return { ok: false, message: "Missing value for --model" };
|
|
89
|
+
}
|
|
90
|
+
options.model = value;
|
|
91
|
+
i += 1;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (argValue.startsWith("--model=")) {
|
|
95
|
+
const value = argValue.slice("--model=".length).trim();
|
|
96
|
+
if (!value) {
|
|
97
|
+
return { ok: false, message: "Missing value for --model" };
|
|
98
|
+
}
|
|
99
|
+
options.model = value;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
return { ok: false, message: `Unknown option: ${argValue}` };
|
|
103
|
+
}
|
|
104
|
+
return { ok: true, options };
|
|
105
|
+
}
|
|
106
|
+
export function parseVerifyFlaggedArgs(args) {
|
|
107
|
+
const options = {
|
|
108
|
+
dryRun: false,
|
|
109
|
+
json: false,
|
|
110
|
+
restore: true,
|
|
111
|
+
};
|
|
112
|
+
for (const arg of args) {
|
|
113
|
+
if (arg === "--dry-run" || arg === "-n") {
|
|
114
|
+
options.dryRun = true;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (arg === "--json" || arg === "-j") {
|
|
118
|
+
options.json = true;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (arg === "--no-restore") {
|
|
122
|
+
options.restore = false;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
return { ok: false, message: `Unknown option: ${arg}` };
|
|
126
|
+
}
|
|
127
|
+
return { ok: true, options };
|
|
128
|
+
}
|
|
129
|
+
export function parseDoctorArgs(args) {
|
|
130
|
+
const options = { json: false, fix: false, dryRun: false };
|
|
131
|
+
for (const arg of args) {
|
|
132
|
+
if (arg === "--json" || arg === "-j") {
|
|
133
|
+
options.json = true;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (arg === "--fix") {
|
|
137
|
+
options.fix = true;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (arg === "--dry-run" || arg === "-n") {
|
|
141
|
+
options.dryRun = true;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
return { ok: false, message: `Unknown option: ${arg}` };
|
|
145
|
+
}
|
|
146
|
+
if (options.dryRun && !options.fix) {
|
|
147
|
+
return { ok: false, message: "--dry-run requires --fix" };
|
|
148
|
+
}
|
|
149
|
+
return { ok: true, options };
|
|
150
|
+
}
|
|
151
|
+
function summarizeFixReports(reports) {
|
|
152
|
+
let healthy = 0;
|
|
153
|
+
let disabled = 0;
|
|
154
|
+
let warnings = 0;
|
|
155
|
+
let skipped = 0;
|
|
156
|
+
for (const report of reports) {
|
|
157
|
+
if (report.outcome === "healthy")
|
|
158
|
+
healthy += 1;
|
|
159
|
+
else if (report.outcome === "disabled-hard-failure")
|
|
160
|
+
disabled += 1;
|
|
161
|
+
else if (report.outcome === "warning-soft-failure")
|
|
162
|
+
warnings += 1;
|
|
163
|
+
else
|
|
164
|
+
skipped += 1;
|
|
165
|
+
}
|
|
166
|
+
return { healthy, disabled, warnings, skipped };
|
|
167
|
+
}
|
|
168
|
+
function createEmptyAccountStorage() {
|
|
169
|
+
const activeIndexByFamily = {};
|
|
170
|
+
for (const family of MODEL_FAMILIES) {
|
|
171
|
+
activeIndexByFamily[family] = 0;
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
version: 3,
|
|
175
|
+
accounts: [],
|
|
176
|
+
activeIndex: 0,
|
|
177
|
+
activeIndexByFamily,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function hasAccountStorageMutation(before, after) {
|
|
181
|
+
return (before.refreshToken !== after.refreshToken
|
|
182
|
+
|| before.accessToken !== after.accessToken
|
|
183
|
+
|| before.expiresAt !== after.expiresAt
|
|
184
|
+
|| before.email !== after.email
|
|
185
|
+
|| before.accountId !== after.accountId
|
|
186
|
+
|| before.accountIdSource !== after.accountIdSource
|
|
187
|
+
|| before.enabled !== after.enabled);
|
|
188
|
+
}
|
|
189
|
+
function collectAccountStorageMutations(beforeAccounts, afterAccounts) {
|
|
190
|
+
const mutations = [];
|
|
191
|
+
for (let i = 0; i < afterAccounts.length; i += 1) {
|
|
192
|
+
const before = beforeAccounts[i];
|
|
193
|
+
const after = afterAccounts[i];
|
|
194
|
+
if (!before || !after)
|
|
195
|
+
continue;
|
|
196
|
+
if (!hasAccountStorageMutation(before, after))
|
|
197
|
+
continue;
|
|
198
|
+
mutations.push({
|
|
199
|
+
before: structuredClone(before),
|
|
200
|
+
after: structuredClone(after),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return mutations;
|
|
204
|
+
}
|
|
205
|
+
function applyAccountStorageMutations(storage, mutations) {
|
|
206
|
+
for (const mutation of mutations) {
|
|
207
|
+
const targetIndex = findMatchingAccountIndex(storage.accounts, mutation.before, {
|
|
208
|
+
allowUniqueAccountIdFallbackWithoutEmail: true,
|
|
209
|
+
})
|
|
210
|
+
?? findMatchingAccountIndex(storage.accounts, mutation.after, {
|
|
211
|
+
allowUniqueAccountIdFallbackWithoutEmail: true,
|
|
212
|
+
});
|
|
213
|
+
if (targetIndex === undefined)
|
|
214
|
+
continue;
|
|
215
|
+
const target = storage.accounts[targetIndex];
|
|
216
|
+
if (!target)
|
|
217
|
+
continue;
|
|
218
|
+
target.refreshToken = mutation.after.refreshToken;
|
|
219
|
+
target.accessToken = mutation.after.accessToken;
|
|
220
|
+
target.expiresAt = mutation.after.expiresAt;
|
|
221
|
+
target.email = mutation.after.email;
|
|
222
|
+
target.accountId = mutation.after.accountId;
|
|
223
|
+
target.accountIdSource = mutation.after.accountIdSource;
|
|
224
|
+
target.enabled = mutation.after.enabled;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function findExistingAccountIndexForFlagged(storage, flagged, nextRefreshToken, nextAccountId, nextEmail) {
|
|
228
|
+
const flaggedEmail = sanitizeEmail(flagged.email);
|
|
229
|
+
const candidateAccountId = nextAccountId ?? flagged.accountId;
|
|
230
|
+
const candidateEmail = sanitizeEmail(nextEmail) ?? flaggedEmail;
|
|
231
|
+
const nextMatchIndex = findMatchingAccountIndex(storage.accounts, {
|
|
232
|
+
accountId: candidateAccountId,
|
|
233
|
+
email: candidateEmail,
|
|
234
|
+
refreshToken: nextRefreshToken,
|
|
235
|
+
}, {
|
|
236
|
+
allowUniqueAccountIdFallbackWithoutEmail: true,
|
|
237
|
+
});
|
|
238
|
+
if (nextMatchIndex !== undefined) {
|
|
239
|
+
return nextMatchIndex;
|
|
240
|
+
}
|
|
241
|
+
const flaggedMatchIndex = findMatchingAccountIndex(storage.accounts, {
|
|
242
|
+
accountId: candidateAccountId,
|
|
243
|
+
email: candidateEmail,
|
|
244
|
+
refreshToken: flagged.refreshToken,
|
|
245
|
+
}, {
|
|
246
|
+
allowUniqueAccountIdFallbackWithoutEmail: true,
|
|
247
|
+
});
|
|
248
|
+
return flaggedMatchIndex ?? -1;
|
|
249
|
+
}
|
|
250
|
+
function findMatchingFlaggedAccountIndex(accounts, target) {
|
|
251
|
+
const targetEmail = sanitizeEmail(target.email);
|
|
252
|
+
return accounts.findIndex((account) => {
|
|
253
|
+
if (account.refreshToken === target.refreshToken) {
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
if (target.accountId && account.accountId === target.accountId) {
|
|
257
|
+
if (!targetEmail) {
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
return sanitizeEmail(account.email) === targetEmail;
|
|
261
|
+
}
|
|
262
|
+
return Boolean(targetEmail) && sanitizeEmail(account.email) === targetEmail;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
function findFlaggedAccountIndexByStableIdentity(accounts, target) {
|
|
266
|
+
const targetEmail = sanitizeEmail(target.email);
|
|
267
|
+
return accounts.findIndex((account) => {
|
|
268
|
+
if (target.accountId && account.accountId === target.accountId) {
|
|
269
|
+
if (!targetEmail) {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
return sanitizeEmail(account.email) === targetEmail;
|
|
273
|
+
}
|
|
274
|
+
return Boolean(targetEmail) && sanitizeEmail(account.email) === targetEmail;
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
function hasFlaggedRefreshTokenDrift(accounts, target) {
|
|
278
|
+
const targetIndex = findFlaggedAccountIndexByStableIdentity(accounts, target);
|
|
279
|
+
if (targetIndex < 0) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
const current = accounts[targetIndex];
|
|
283
|
+
return current ? current.refreshToken !== target.refreshToken : false;
|
|
284
|
+
}
|
|
285
|
+
function applyFlaggedStorageMutations(flaggedStorage, mutations) {
|
|
286
|
+
for (const mutation of mutations) {
|
|
287
|
+
const targetIndex = findMatchingFlaggedAccountIndex(flaggedStorage.accounts, mutation.before);
|
|
288
|
+
if (targetIndex < 0) {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
if (mutation.after) {
|
|
292
|
+
flaggedStorage.accounts[targetIndex] = structuredClone(mutation.after);
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
flaggedStorage.accounts.splice(targetIndex, 1);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function upsertRecoveredFlaggedAccount(storage, flagged, refreshResult, now, deps) {
|
|
299
|
+
const nextEmail = sanitizeEmail(extractAccountEmail(refreshResult.access, refreshResult.idToken))
|
|
300
|
+
?? flagged.email;
|
|
301
|
+
const tokenAccountId = extractAccountId(refreshResult.access);
|
|
302
|
+
const { accountId: nextAccountId, accountIdSource: nextAccountIdSource } = deps.resolveStoredAccountIdentity(flagged.accountId, flagged.accountIdSource, tokenAccountId);
|
|
303
|
+
const existingIndex = findExistingAccountIndexForFlagged(storage, flagged, refreshResult.refresh, nextAccountId, nextEmail);
|
|
304
|
+
if (existingIndex >= 0) {
|
|
305
|
+
const existing = storage.accounts[existingIndex];
|
|
306
|
+
if (!existing) {
|
|
307
|
+
return { restored: false, changed: false, message: "existing account entry is missing" };
|
|
308
|
+
}
|
|
309
|
+
let changed = false;
|
|
310
|
+
if (existing.refreshToken !== refreshResult.refresh) {
|
|
311
|
+
existing.refreshToken = refreshResult.refresh;
|
|
312
|
+
changed = true;
|
|
313
|
+
}
|
|
314
|
+
if (existing.accessToken !== refreshResult.access) {
|
|
315
|
+
existing.accessToken = refreshResult.access;
|
|
316
|
+
changed = true;
|
|
317
|
+
}
|
|
318
|
+
if (existing.expiresAt !== refreshResult.expires) {
|
|
319
|
+
existing.expiresAt = refreshResult.expires;
|
|
320
|
+
changed = true;
|
|
321
|
+
}
|
|
322
|
+
if (nextEmail && nextEmail !== existing.email) {
|
|
323
|
+
existing.email = nextEmail;
|
|
324
|
+
changed = true;
|
|
325
|
+
}
|
|
326
|
+
if (nextAccountId !== undefined
|
|
327
|
+
&& (nextAccountId !== existing.accountId
|
|
328
|
+
|| nextAccountIdSource !== existing.accountIdSource)) {
|
|
329
|
+
existing.accountId = nextAccountId;
|
|
330
|
+
existing.accountIdSource = nextAccountIdSource;
|
|
331
|
+
changed = true;
|
|
332
|
+
}
|
|
333
|
+
if (existing.enabled === false) {
|
|
334
|
+
existing.enabled = true;
|
|
335
|
+
changed = true;
|
|
336
|
+
}
|
|
337
|
+
if (existing.accountLabel !== flagged.accountLabel && flagged.accountLabel) {
|
|
338
|
+
existing.accountLabel = flagged.accountLabel;
|
|
339
|
+
changed = true;
|
|
340
|
+
}
|
|
341
|
+
existing.lastUsed = now;
|
|
342
|
+
return {
|
|
343
|
+
restored: true,
|
|
344
|
+
changed,
|
|
345
|
+
message: `restored into existing account ${existingIndex + 1}`,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
if (storage.accounts.length >= ACCOUNT_LIMITS.MAX_ACCOUNTS) {
|
|
349
|
+
return {
|
|
350
|
+
restored: false,
|
|
351
|
+
changed: false,
|
|
352
|
+
message: `cannot restore (max ${ACCOUNT_LIMITS.MAX_ACCOUNTS} accounts reached)`,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
storage.accounts.push({
|
|
356
|
+
refreshToken: refreshResult.refresh,
|
|
357
|
+
accessToken: refreshResult.access,
|
|
358
|
+
expiresAt: refreshResult.expires,
|
|
359
|
+
accountId: nextAccountId,
|
|
360
|
+
accountIdSource: nextAccountIdSource,
|
|
361
|
+
accountLabel: flagged.accountLabel,
|
|
362
|
+
email: nextEmail,
|
|
363
|
+
addedAt: flagged.addedAt ?? now,
|
|
364
|
+
lastUsed: now,
|
|
365
|
+
enabled: true,
|
|
366
|
+
});
|
|
367
|
+
return {
|
|
368
|
+
restored: true,
|
|
369
|
+
changed: true,
|
|
370
|
+
message: `restored as account ${storage.accounts.length}`,
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
function maskDoctorEmail(value) {
|
|
374
|
+
if (!value)
|
|
375
|
+
return undefined;
|
|
376
|
+
const email = value.trim();
|
|
377
|
+
const atIndex = email.indexOf("@");
|
|
378
|
+
if (atIndex < 0)
|
|
379
|
+
return "***@***";
|
|
380
|
+
const local = email.slice(0, atIndex);
|
|
381
|
+
const domain = email.slice(atIndex + 1);
|
|
382
|
+
const parts = domain.split(".");
|
|
383
|
+
const tld = parts.pop() || "";
|
|
384
|
+
const prefix = local.slice(0, Math.min(2, local.length));
|
|
385
|
+
return `${prefix}***@***.${tld}`;
|
|
386
|
+
}
|
|
387
|
+
function redactDoctorIdentifier(value) {
|
|
388
|
+
if (!value)
|
|
389
|
+
return undefined;
|
|
390
|
+
const identifier = value.trim();
|
|
391
|
+
if (!identifier)
|
|
392
|
+
return undefined;
|
|
393
|
+
if (identifier.includes("@")) {
|
|
394
|
+
return maskDoctorEmail(identifier);
|
|
395
|
+
}
|
|
396
|
+
if (identifier.length <= 8) {
|
|
397
|
+
return "***";
|
|
398
|
+
}
|
|
399
|
+
return `${identifier.slice(0, 4)}***${identifier.slice(-3)}`;
|
|
400
|
+
}
|
|
401
|
+
function formatDoctorIdentitySummary(identity) {
|
|
402
|
+
const parts = [];
|
|
403
|
+
const maskedEmail = maskDoctorEmail(identity.email);
|
|
404
|
+
const maskedAccountId = redactDoctorIdentifier(identity.accountId);
|
|
405
|
+
if (maskedEmail) {
|
|
406
|
+
parts.push(`email=${maskedEmail}`);
|
|
407
|
+
}
|
|
408
|
+
if (maskedAccountId) {
|
|
409
|
+
parts.push(`accountId=${maskedAccountId}`);
|
|
410
|
+
}
|
|
411
|
+
return parts.join(", ") || "unknown";
|
|
412
|
+
}
|
|
413
|
+
function hasPlaceholderEmail(value) {
|
|
414
|
+
if (!value)
|
|
415
|
+
return false;
|
|
416
|
+
const email = value.trim().toLowerCase();
|
|
417
|
+
if (!email)
|
|
418
|
+
return false;
|
|
419
|
+
return email.endsWith("@example.com");
|
|
420
|
+
}
|
|
421
|
+
function normalizeDoctorIndexes(storage) {
|
|
422
|
+
const total = storage.accounts.length;
|
|
423
|
+
const nextActive = total === 0 ? 0 : Math.max(0, Math.min(storage.activeIndex, total - 1));
|
|
424
|
+
let changed = false;
|
|
425
|
+
if (storage.activeIndex !== nextActive) {
|
|
426
|
+
storage.activeIndex = nextActive;
|
|
427
|
+
changed = true;
|
|
428
|
+
}
|
|
429
|
+
storage.activeIndexByFamily = storage.activeIndexByFamily ?? {};
|
|
430
|
+
for (const family of MODEL_FAMILIES) {
|
|
431
|
+
const raw = storage.activeIndexByFamily[family];
|
|
432
|
+
const fallback = storage.activeIndex;
|
|
433
|
+
const candidate = typeof raw === "number" && Number.isFinite(raw) ? raw : fallback;
|
|
434
|
+
const clamped = total === 0 ? 0 : Math.max(0, Math.min(candidate, total - 1));
|
|
435
|
+
if (storage.activeIndexByFamily[family] !== clamped) {
|
|
436
|
+
storage.activeIndexByFamily[family] = clamped;
|
|
437
|
+
changed = true;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return changed;
|
|
441
|
+
}
|
|
442
|
+
function getDoctorRefreshTokenKey(refreshToken) {
|
|
443
|
+
if (typeof refreshToken !== "string")
|
|
444
|
+
return undefined;
|
|
445
|
+
const trimmed = refreshToken.trim();
|
|
446
|
+
return trimmed || undefined;
|
|
447
|
+
}
|
|
448
|
+
function applyDoctorFixes(storage, deps) {
|
|
449
|
+
let changed = false;
|
|
450
|
+
const actions = [];
|
|
451
|
+
const recordActiveIndexAction = () => {
|
|
452
|
+
if (actions.some((action) => action.key === "active-index"))
|
|
453
|
+
return;
|
|
454
|
+
actions.push({
|
|
455
|
+
key: "active-index",
|
|
456
|
+
message: "Normalized active account indexes",
|
|
457
|
+
});
|
|
458
|
+
};
|
|
459
|
+
if (normalizeDoctorIndexes(storage)) {
|
|
460
|
+
changed = true;
|
|
461
|
+
recordActiveIndexAction();
|
|
462
|
+
}
|
|
463
|
+
const seenRefreshTokens = new Map();
|
|
464
|
+
for (let i = 0; i < storage.accounts.length; i += 1) {
|
|
465
|
+
const account = storage.accounts[i];
|
|
466
|
+
if (!account)
|
|
467
|
+
continue;
|
|
468
|
+
const refreshToken = getDoctorRefreshTokenKey(account.refreshToken);
|
|
469
|
+
if (!refreshToken)
|
|
470
|
+
continue;
|
|
471
|
+
const existingTokenIndex = seenRefreshTokens.get(refreshToken);
|
|
472
|
+
if (typeof existingTokenIndex === "number") {
|
|
473
|
+
if (account.enabled !== false) {
|
|
474
|
+
account.enabled = false;
|
|
475
|
+
changed = true;
|
|
476
|
+
actions.push({
|
|
477
|
+
key: "duplicate-refresh-token",
|
|
478
|
+
message: `Disabled duplicate token entry on account ${i + 1} (kept account ${existingTokenIndex + 1})`,
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
seenRefreshTokens.set(refreshToken, i);
|
|
484
|
+
}
|
|
485
|
+
const tokenEmail = sanitizeEmail(extractAccountEmail(account.accessToken));
|
|
486
|
+
if (tokenEmail && (!sanitizeEmail(account.email) || hasPlaceholderEmail(account.email))) {
|
|
487
|
+
account.email = tokenEmail;
|
|
488
|
+
changed = true;
|
|
489
|
+
actions.push({
|
|
490
|
+
key: "email-from-token",
|
|
491
|
+
message: `Updated account ${i + 1} email from token claims`,
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
const tokenAccountId = extractAccountId(account.accessToken);
|
|
495
|
+
if (!account.accountId && tokenAccountId) {
|
|
496
|
+
account.accountId = tokenAccountId;
|
|
497
|
+
account.accountIdSource = "token";
|
|
498
|
+
changed = true;
|
|
499
|
+
actions.push({
|
|
500
|
+
key: "account-id-from-token",
|
|
501
|
+
message: `Filled missing accountId for account ${i + 1}`,
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
const enabledCount = storage.accounts.filter((account) => account.enabled !== false).length;
|
|
506
|
+
if (storage.accounts.length > 0 && enabledCount === 0) {
|
|
507
|
+
const index = deps.resolveActiveIndex(storage, "codex");
|
|
508
|
+
const candidate = storage.accounts[index] ?? storage.accounts[0];
|
|
509
|
+
if (candidate) {
|
|
510
|
+
candidate.enabled = true;
|
|
511
|
+
changed = true;
|
|
512
|
+
actions.push({
|
|
513
|
+
key: "enabled-accounts",
|
|
514
|
+
message: `Re-enabled account ${index + 1} to avoid an all-disabled pool`,
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
if (normalizeDoctorIndexes(storage)) {
|
|
519
|
+
changed = true;
|
|
520
|
+
recordActiveIndexAction();
|
|
521
|
+
}
|
|
522
|
+
return { changed, actions };
|
|
523
|
+
}
|
|
524
|
+
export async function runVerifyFlagged(args, deps) {
|
|
525
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
526
|
+
printVerifyFlaggedUsage();
|
|
527
|
+
return 0;
|
|
528
|
+
}
|
|
529
|
+
const parsedArgs = parseVerifyFlaggedArgs(args);
|
|
530
|
+
if (!parsedArgs.ok) {
|
|
531
|
+
console.error(parsedArgs.message);
|
|
532
|
+
printVerifyFlaggedUsage();
|
|
533
|
+
return 1;
|
|
534
|
+
}
|
|
535
|
+
const options = parsedArgs.options;
|
|
536
|
+
setStoragePath(null);
|
|
537
|
+
const flaggedStorage = await loadFlaggedAccounts();
|
|
538
|
+
if (flaggedStorage.accounts.length === 0) {
|
|
539
|
+
if (options.json) {
|
|
540
|
+
console.log(JSON.stringify({
|
|
541
|
+
command: "verify-flagged",
|
|
542
|
+
total: 0,
|
|
543
|
+
restored: 0,
|
|
544
|
+
healthyFlagged: 0,
|
|
545
|
+
stillFlagged: 0,
|
|
546
|
+
remainingFlagged: 0,
|
|
547
|
+
changed: false,
|
|
548
|
+
dryRun: options.dryRun,
|
|
549
|
+
restore: options.restore,
|
|
550
|
+
reports: [],
|
|
551
|
+
}, null, 2));
|
|
552
|
+
return 0;
|
|
553
|
+
}
|
|
554
|
+
console.log("No flagged accounts to check.");
|
|
555
|
+
return 0;
|
|
556
|
+
}
|
|
557
|
+
let storageChanged = false;
|
|
558
|
+
let flaggedChanged = false;
|
|
559
|
+
const reports = [];
|
|
560
|
+
const nextFlaggedAccounts = [];
|
|
561
|
+
const flaggedMutations = [];
|
|
562
|
+
const now = Date.now();
|
|
563
|
+
const collectRefreshChecks = async (accounts) => {
|
|
564
|
+
const refreshChecks = [];
|
|
565
|
+
for (let i = 0; i < accounts.length; i += 1) {
|
|
566
|
+
const flagged = accounts[i];
|
|
567
|
+
if (!flagged)
|
|
568
|
+
continue;
|
|
569
|
+
refreshChecks.push({
|
|
570
|
+
index: i,
|
|
571
|
+
flagged,
|
|
572
|
+
label: formatAccountLabel(flagged, i),
|
|
573
|
+
result: await queuedRefresh(flagged.refreshToken),
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
return refreshChecks;
|
|
577
|
+
};
|
|
578
|
+
const applyRefreshChecks = (storage, refreshChecks) => {
|
|
579
|
+
for (const check of refreshChecks) {
|
|
580
|
+
const { index: i, flagged, label, result } = check;
|
|
581
|
+
if (result.type === "success") {
|
|
582
|
+
if (!options.restore) {
|
|
583
|
+
const tokenAccountId = extractAccountId(result.access);
|
|
584
|
+
const nextIdentity = deps.resolveStoredAccountIdentity(flagged.accountId, flagged.accountIdSource, tokenAccountId);
|
|
585
|
+
const nextFlagged = {
|
|
586
|
+
...flagged,
|
|
587
|
+
refreshToken: result.refresh,
|
|
588
|
+
accessToken: result.access,
|
|
589
|
+
expiresAt: result.expires,
|
|
590
|
+
accountId: nextIdentity.accountId,
|
|
591
|
+
accountIdSource: nextIdentity.accountIdSource,
|
|
592
|
+
email: sanitizeEmail(extractAccountEmail(result.access, result.idToken))
|
|
593
|
+
?? flagged.email,
|
|
594
|
+
lastUsed: now,
|
|
595
|
+
lastError: undefined,
|
|
596
|
+
};
|
|
597
|
+
nextFlaggedAccounts.push(nextFlagged);
|
|
598
|
+
if (JSON.stringify(nextFlagged) !== JSON.stringify(flagged)) {
|
|
599
|
+
flaggedChanged = true;
|
|
600
|
+
}
|
|
601
|
+
flaggedMutations.push({
|
|
602
|
+
index: i,
|
|
603
|
+
label,
|
|
604
|
+
before: flagged,
|
|
605
|
+
after: nextFlagged,
|
|
606
|
+
});
|
|
607
|
+
reports.push({
|
|
608
|
+
index: i,
|
|
609
|
+
label,
|
|
610
|
+
outcome: "healthy-flagged",
|
|
611
|
+
message: "session is healthy (left in flagged list due to --no-restore)",
|
|
612
|
+
});
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
const upsertResult = upsertRecoveredFlaggedAccount(storage, flagged, result, now, deps);
|
|
616
|
+
if (upsertResult.restored) {
|
|
617
|
+
storageChanged = storageChanged || upsertResult.changed;
|
|
618
|
+
flaggedChanged = true;
|
|
619
|
+
flaggedMutations.push({
|
|
620
|
+
index: i,
|
|
621
|
+
label,
|
|
622
|
+
before: flagged,
|
|
623
|
+
});
|
|
624
|
+
reports.push({
|
|
625
|
+
index: i,
|
|
626
|
+
label,
|
|
627
|
+
outcome: "restored",
|
|
628
|
+
message: upsertResult.message,
|
|
629
|
+
});
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
const tokenAccountId = extractAccountId(result.access);
|
|
633
|
+
const nextIdentity = deps.resolveStoredAccountIdentity(flagged.accountId, flagged.accountIdSource, tokenAccountId);
|
|
634
|
+
const updatedFlagged = {
|
|
635
|
+
...flagged,
|
|
636
|
+
refreshToken: result.refresh,
|
|
637
|
+
accessToken: result.access,
|
|
638
|
+
expiresAt: result.expires,
|
|
639
|
+
accountId: nextIdentity.accountId,
|
|
640
|
+
accountIdSource: nextIdentity.accountIdSource,
|
|
641
|
+
email: sanitizeEmail(extractAccountEmail(result.access, result.idToken))
|
|
642
|
+
?? flagged.email,
|
|
643
|
+
lastUsed: now,
|
|
644
|
+
lastError: upsertResult.message,
|
|
645
|
+
};
|
|
646
|
+
nextFlaggedAccounts.push(updatedFlagged);
|
|
647
|
+
if (JSON.stringify(updatedFlagged) !== JSON.stringify(flagged)) {
|
|
648
|
+
flaggedChanged = true;
|
|
649
|
+
}
|
|
650
|
+
flaggedMutations.push({
|
|
651
|
+
index: i,
|
|
652
|
+
label,
|
|
653
|
+
before: flagged,
|
|
654
|
+
after: updatedFlagged,
|
|
655
|
+
});
|
|
656
|
+
reports.push({
|
|
657
|
+
index: i,
|
|
658
|
+
label,
|
|
659
|
+
outcome: "restore-skipped",
|
|
660
|
+
message: upsertResult.message,
|
|
661
|
+
});
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
const detail = deps.normalizeFailureDetail(result.message, result.reason);
|
|
665
|
+
const failedFlagged = {
|
|
666
|
+
...flagged,
|
|
667
|
+
lastError: detail,
|
|
668
|
+
};
|
|
669
|
+
nextFlaggedAccounts.push(failedFlagged);
|
|
670
|
+
if ((flagged.lastError ?? "") !== detail) {
|
|
671
|
+
flaggedChanged = true;
|
|
672
|
+
}
|
|
673
|
+
flaggedMutations.push({
|
|
674
|
+
index: i,
|
|
675
|
+
label,
|
|
676
|
+
before: flagged,
|
|
677
|
+
after: failedFlagged,
|
|
678
|
+
});
|
|
679
|
+
reports.push({
|
|
680
|
+
index: i,
|
|
681
|
+
label,
|
|
682
|
+
outcome: "still-flagged",
|
|
683
|
+
message: detail,
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
let remainingFlagged = 0;
|
|
688
|
+
const refreshChecks = await collectRefreshChecks(flaggedStorage.accounts);
|
|
689
|
+
if (options.restore) {
|
|
690
|
+
if (options.dryRun) {
|
|
691
|
+
applyRefreshChecks((await loadAccounts()) ?? createEmptyAccountStorage(), refreshChecks);
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
await withAccountAndFlaggedStorageTransaction(async (loadedStorage, persist, loadedFlaggedStorage) => {
|
|
695
|
+
const nextStorage = loadedStorage
|
|
696
|
+
? structuredClone(loadedStorage)
|
|
697
|
+
: createEmptyAccountStorage();
|
|
698
|
+
const nextFlaggedStorage = structuredClone(loadedFlaggedStorage);
|
|
699
|
+
const staleRefreshChecks = refreshChecks.filter((check) => hasFlaggedRefreshTokenDrift(nextFlaggedStorage.accounts, check.flagged));
|
|
700
|
+
const safeRefreshChecks = refreshChecks.filter((check) => !hasFlaggedRefreshTokenDrift(nextFlaggedStorage.accounts, check.flagged));
|
|
701
|
+
applyRefreshChecks(nextStorage, safeRefreshChecks);
|
|
702
|
+
for (const check of staleRefreshChecks) {
|
|
703
|
+
reports.push({
|
|
704
|
+
index: check.index,
|
|
705
|
+
label: check.label,
|
|
706
|
+
outcome: "restore-skipped",
|
|
707
|
+
message: "Skipped restore because flagged refresh token changed before persistence",
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
applyFlaggedStorageMutations(nextFlaggedStorage, flaggedMutations);
|
|
711
|
+
remainingFlagged = nextFlaggedStorage.accounts.length;
|
|
712
|
+
if (!storageChanged && !flaggedChanged) {
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
if (storageChanged) {
|
|
716
|
+
normalizeDoctorIndexes(nextStorage);
|
|
717
|
+
}
|
|
718
|
+
await persist(nextStorage, nextFlaggedStorage);
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
applyRefreshChecks(createEmptyAccountStorage(), refreshChecks);
|
|
724
|
+
remainingFlagged = nextFlaggedAccounts.length;
|
|
725
|
+
}
|
|
726
|
+
if (options.dryRun) {
|
|
727
|
+
remainingFlagged = nextFlaggedAccounts.length;
|
|
728
|
+
}
|
|
729
|
+
if (!options.dryRun && !options.restore && flaggedChanged) {
|
|
730
|
+
await withFlaggedStorageTransaction(async (loadedFlaggedStorage, persist) => {
|
|
731
|
+
const nextFlaggedStorage = structuredClone(loadedFlaggedStorage);
|
|
732
|
+
const staleFlaggedMutations = flaggedMutations.filter((mutation) => hasFlaggedRefreshTokenDrift(nextFlaggedStorage.accounts, mutation.before));
|
|
733
|
+
const safeFlaggedMutations = flaggedMutations.filter((mutation) => !hasFlaggedRefreshTokenDrift(nextFlaggedStorage.accounts, mutation.before));
|
|
734
|
+
for (const mutation of staleFlaggedMutations) {
|
|
735
|
+
const staleReport = reports.find((report) => report.index === mutation.index && report.label === mutation.label);
|
|
736
|
+
if (staleReport) {
|
|
737
|
+
staleReport.outcome = "restore-skipped";
|
|
738
|
+
staleReport.message =
|
|
739
|
+
"Skipped flagged update because refresh token changed before persistence";
|
|
740
|
+
continue;
|
|
741
|
+
}
|
|
742
|
+
reports.push({
|
|
743
|
+
index: mutation.index,
|
|
744
|
+
label: mutation.label,
|
|
745
|
+
outcome: "restore-skipped",
|
|
746
|
+
message: "Skipped flagged update because refresh token changed before persistence",
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
applyFlaggedStorageMutations(nextFlaggedStorage, safeFlaggedMutations);
|
|
750
|
+
remainingFlagged = nextFlaggedStorage.accounts.length;
|
|
751
|
+
if (safeFlaggedMutations.length === 0) {
|
|
752
|
+
flaggedChanged = false;
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
await persist(nextFlaggedStorage);
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
const restored = reports.filter((report) => report.outcome === "restored").length;
|
|
759
|
+
const healthyFlagged = reports.filter((report) => report.outcome === "healthy-flagged").length;
|
|
760
|
+
const stillFlagged = reports.filter((report) => report.outcome === "still-flagged").length;
|
|
761
|
+
const changed = storageChanged || flaggedChanged;
|
|
762
|
+
if (options.json) {
|
|
763
|
+
console.log(JSON.stringify({
|
|
764
|
+
command: "verify-flagged",
|
|
765
|
+
total: flaggedStorage.accounts.length,
|
|
766
|
+
restored,
|
|
767
|
+
healthyFlagged,
|
|
768
|
+
stillFlagged,
|
|
769
|
+
remainingFlagged,
|
|
770
|
+
changed,
|
|
771
|
+
dryRun: options.dryRun,
|
|
772
|
+
restore: options.restore,
|
|
773
|
+
reports,
|
|
774
|
+
}, null, 2));
|
|
775
|
+
return 0;
|
|
776
|
+
}
|
|
777
|
+
console.log(deps.stylePromptText(`Checking ${flaggedStorage.accounts.length} flagged account(s)...`, "accent"));
|
|
778
|
+
for (const report of reports) {
|
|
779
|
+
const tone = report.outcome === "restored"
|
|
780
|
+
? "success"
|
|
781
|
+
: report.outcome === "healthy-flagged" || report.outcome === "restore-skipped"
|
|
782
|
+
? "warning"
|
|
783
|
+
: "danger";
|
|
784
|
+
const marker = report.outcome === "restored"
|
|
785
|
+
? "✓"
|
|
786
|
+
: report.outcome === "healthy-flagged" || report.outcome === "restore-skipped"
|
|
787
|
+
? "!"
|
|
788
|
+
: "✗";
|
|
789
|
+
console.log(`${deps.stylePromptText(marker, tone)} ${deps.stylePromptText(`${report.index + 1}. ${report.label}`, "accent")} ${deps.stylePromptText("|", "muted")} ${deps.styleAccountDetailText(report.message, tone)}`);
|
|
790
|
+
}
|
|
791
|
+
console.log("");
|
|
792
|
+
console.log(deps.formatResultSummary([
|
|
793
|
+
{ text: `${restored} restored`, tone: restored > 0 ? "success" : "muted" },
|
|
794
|
+
{
|
|
795
|
+
text: `${healthyFlagged} healthy (kept flagged)`,
|
|
796
|
+
tone: healthyFlagged > 0 ? "warning" : "muted",
|
|
797
|
+
},
|
|
798
|
+
{
|
|
799
|
+
text: `${stillFlagged} still flagged`,
|
|
800
|
+
tone: stillFlagged > 0 ? "danger" : "muted",
|
|
801
|
+
},
|
|
802
|
+
]));
|
|
803
|
+
if (options.dryRun) {
|
|
804
|
+
console.log(deps.stylePromptText("Preview only: no changes were saved.", "warning"));
|
|
805
|
+
}
|
|
806
|
+
else if (!changed) {
|
|
807
|
+
console.log(deps.stylePromptText("No storage changes were needed.", "muted"));
|
|
808
|
+
}
|
|
809
|
+
return 0;
|
|
810
|
+
}
|
|
811
|
+
export async function runFix(args, deps) {
|
|
812
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
813
|
+
printFixUsage();
|
|
814
|
+
return 0;
|
|
815
|
+
}
|
|
816
|
+
const parsedArgs = parseFixArgs(args);
|
|
817
|
+
if (!parsedArgs.ok) {
|
|
818
|
+
console.error(parsedArgs.message);
|
|
819
|
+
printFixUsage();
|
|
820
|
+
return 1;
|
|
821
|
+
}
|
|
822
|
+
const options = parsedArgs.options;
|
|
823
|
+
const probeModel = resolveNormalizedModel(options.model.trim() || "gpt-5-codex");
|
|
824
|
+
const display = DEFAULT_DASHBOARD_DISPLAY_SETTINGS;
|
|
825
|
+
const quotaCache = options.live ? await loadQuotaCache() : null;
|
|
826
|
+
const workingQuotaCache = quotaCache ? deps.cloneQuotaCacheData(quotaCache) : null;
|
|
827
|
+
let quotaCacheChanged = false;
|
|
828
|
+
setStoragePath(null);
|
|
829
|
+
const storage = await loadAccounts();
|
|
830
|
+
if (!storage || storage.accounts.length === 0) {
|
|
831
|
+
if (options.json) {
|
|
832
|
+
console.log(JSON.stringify({
|
|
833
|
+
command: "fix",
|
|
834
|
+
dryRun: options.dryRun,
|
|
835
|
+
liveProbe: options.live,
|
|
836
|
+
model: options.model,
|
|
837
|
+
changed: false,
|
|
838
|
+
summary: {
|
|
839
|
+
healthy: 0,
|
|
840
|
+
disabled: 0,
|
|
841
|
+
warnings: 0,
|
|
842
|
+
skipped: 0,
|
|
843
|
+
},
|
|
844
|
+
recommendation: {
|
|
845
|
+
recommendedIndex: null,
|
|
846
|
+
reason: "No accounts configured.",
|
|
847
|
+
},
|
|
848
|
+
recommendedSwitchCommand: null,
|
|
849
|
+
reports: [],
|
|
850
|
+
}, null, 2));
|
|
851
|
+
}
|
|
852
|
+
else {
|
|
853
|
+
console.log("No accounts configured.");
|
|
854
|
+
}
|
|
855
|
+
return 0;
|
|
856
|
+
}
|
|
857
|
+
const originalAccounts = storage.accounts.map((account) => structuredClone(account));
|
|
858
|
+
let quotaEmailFallbackState = options.live && quotaCache
|
|
859
|
+
? deps.buildQuotaEmailFallbackState(storage.accounts)
|
|
860
|
+
: null;
|
|
861
|
+
const now = Date.now();
|
|
862
|
+
const activeIndex = deps.resolveActiveIndex(storage, "codex");
|
|
863
|
+
let accountStorageChanged = false;
|
|
864
|
+
const reports = [];
|
|
865
|
+
const refreshFailures = new Map();
|
|
866
|
+
const hardDisabledIndexes = [];
|
|
867
|
+
for (let i = 0; i < storage.accounts.length; i += 1) {
|
|
868
|
+
const account = storage.accounts[i];
|
|
869
|
+
if (!account)
|
|
870
|
+
continue;
|
|
871
|
+
const label = formatAccountLabel(account, i);
|
|
872
|
+
if (account.enabled === false) {
|
|
873
|
+
reports.push({
|
|
874
|
+
index: i,
|
|
875
|
+
label,
|
|
876
|
+
outcome: "already-disabled",
|
|
877
|
+
message: "already disabled",
|
|
878
|
+
});
|
|
879
|
+
continue;
|
|
880
|
+
}
|
|
881
|
+
if (deps.hasUsableAccessToken(account, now)) {
|
|
882
|
+
let refreshAfterLiveProbeFailure = false;
|
|
883
|
+
if (options.live) {
|
|
884
|
+
const currentAccessToken = account.accessToken;
|
|
885
|
+
const probeAccountId = currentAccessToken
|
|
886
|
+
? account.accountId ?? extractAccountId(currentAccessToken)
|
|
887
|
+
: undefined;
|
|
888
|
+
if (probeAccountId && currentAccessToken) {
|
|
889
|
+
try {
|
|
890
|
+
const snapshot = await fetchCodexQuotaSnapshot({
|
|
891
|
+
accountId: probeAccountId,
|
|
892
|
+
accessToken: currentAccessToken,
|
|
893
|
+
model: probeModel,
|
|
894
|
+
});
|
|
895
|
+
if (workingQuotaCache) {
|
|
896
|
+
quotaCacheChanged =
|
|
897
|
+
deps.updateQuotaCacheForAccount(workingQuotaCache, account, snapshot, storage.accounts, quotaEmailFallbackState ?? undefined) || quotaCacheChanged;
|
|
898
|
+
}
|
|
899
|
+
reports.push({
|
|
900
|
+
index: i,
|
|
901
|
+
label,
|
|
902
|
+
outcome: "healthy",
|
|
903
|
+
message: display.showQuotaDetails
|
|
904
|
+
? `live session OK (${deps.formatCompactQuotaSnapshot(snapshot)})`
|
|
905
|
+
: "live session OK",
|
|
906
|
+
});
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
catch {
|
|
910
|
+
refreshAfterLiveProbeFailure = true;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
if (!refreshAfterLiveProbeFailure) {
|
|
915
|
+
const refreshWarning = deps.hasLikelyInvalidRefreshToken(account.refreshToken)
|
|
916
|
+
? " (refresh token looks stale; re-login recommended)"
|
|
917
|
+
: "";
|
|
918
|
+
reports.push({
|
|
919
|
+
index: i,
|
|
920
|
+
label,
|
|
921
|
+
outcome: "healthy",
|
|
922
|
+
message: `access token still valid${refreshWarning}`,
|
|
923
|
+
});
|
|
924
|
+
continue;
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
const refreshResult = await queuedRefresh(account.refreshToken);
|
|
928
|
+
if (refreshResult.type === "success") {
|
|
929
|
+
const nextEmail = sanitizeEmail(extractAccountEmail(refreshResult.access, refreshResult.idToken));
|
|
930
|
+
const nextAccountId = extractAccountId(refreshResult.access);
|
|
931
|
+
const previousEmail = account.email;
|
|
932
|
+
let accountChanged = false;
|
|
933
|
+
let accountIdentityChanged = false;
|
|
934
|
+
if (account.refreshToken !== refreshResult.refresh) {
|
|
935
|
+
account.refreshToken = refreshResult.refresh;
|
|
936
|
+
accountChanged = true;
|
|
937
|
+
}
|
|
938
|
+
if (account.accessToken !== refreshResult.access) {
|
|
939
|
+
account.accessToken = refreshResult.access;
|
|
940
|
+
accountChanged = true;
|
|
941
|
+
}
|
|
942
|
+
if (account.expiresAt !== refreshResult.expires) {
|
|
943
|
+
account.expiresAt = refreshResult.expires;
|
|
944
|
+
accountChanged = true;
|
|
945
|
+
}
|
|
946
|
+
if (nextEmail && nextEmail !== account.email) {
|
|
947
|
+
account.email = nextEmail;
|
|
948
|
+
accountChanged = true;
|
|
949
|
+
accountIdentityChanged = true;
|
|
950
|
+
}
|
|
951
|
+
if (deps.applyTokenAccountIdentity(account, nextAccountId)) {
|
|
952
|
+
accountChanged = true;
|
|
953
|
+
accountIdentityChanged = true;
|
|
954
|
+
}
|
|
955
|
+
if (accountChanged)
|
|
956
|
+
accountStorageChanged = true;
|
|
957
|
+
if (accountIdentityChanged && options.live && workingQuotaCache) {
|
|
958
|
+
quotaEmailFallbackState = deps.buildQuotaEmailFallbackState(storage.accounts);
|
|
959
|
+
quotaCacheChanged =
|
|
960
|
+
deps.pruneUnsafeQuotaEmailCacheEntry(workingQuotaCache, previousEmail, storage.accounts, quotaEmailFallbackState) || quotaCacheChanged;
|
|
961
|
+
}
|
|
962
|
+
if (options.live) {
|
|
963
|
+
const probeAccountId = account.accountId ?? nextAccountId;
|
|
964
|
+
if (probeAccountId) {
|
|
965
|
+
try {
|
|
966
|
+
const snapshot = await fetchCodexQuotaSnapshot({
|
|
967
|
+
accountId: probeAccountId,
|
|
968
|
+
accessToken: refreshResult.access,
|
|
969
|
+
model: probeModel,
|
|
970
|
+
});
|
|
971
|
+
if (workingQuotaCache) {
|
|
972
|
+
quotaCacheChanged =
|
|
973
|
+
deps.updateQuotaCacheForAccount(workingQuotaCache, account, snapshot, storage.accounts, quotaEmailFallbackState ?? undefined) || quotaCacheChanged;
|
|
974
|
+
}
|
|
975
|
+
reports.push({
|
|
976
|
+
index: i,
|
|
977
|
+
label,
|
|
978
|
+
outcome: "healthy",
|
|
979
|
+
message: display.showQuotaDetails
|
|
980
|
+
? `refresh + live probe succeeded (${deps.formatCompactQuotaSnapshot(snapshot)})`
|
|
981
|
+
: "refresh + live probe succeeded",
|
|
982
|
+
});
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
catch (error) {
|
|
986
|
+
const message = deps.normalizeFailureDetail(error instanceof Error ? error.message : String(error), undefined);
|
|
987
|
+
reports.push({
|
|
988
|
+
index: i,
|
|
989
|
+
label,
|
|
990
|
+
outcome: "warning-soft-failure",
|
|
991
|
+
message: `refresh succeeded but live probe failed: ${message}`,
|
|
992
|
+
});
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
reports.push({
|
|
998
|
+
index: i,
|
|
999
|
+
label,
|
|
1000
|
+
outcome: "healthy",
|
|
1001
|
+
message: "refresh succeeded",
|
|
1002
|
+
});
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
1005
|
+
const detail = deps.normalizeFailureDetail(refreshResult.message, refreshResult.reason);
|
|
1006
|
+
refreshFailures.set(i, {
|
|
1007
|
+
...refreshResult,
|
|
1008
|
+
message: detail,
|
|
1009
|
+
});
|
|
1010
|
+
if (isHardRefreshFailure(refreshResult)) {
|
|
1011
|
+
account.enabled = false;
|
|
1012
|
+
accountStorageChanged = true;
|
|
1013
|
+
hardDisabledIndexes.push(i);
|
|
1014
|
+
reports.push({
|
|
1015
|
+
index: i,
|
|
1016
|
+
label,
|
|
1017
|
+
outcome: "disabled-hard-failure",
|
|
1018
|
+
message: detail,
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
else {
|
|
1022
|
+
reports.push({
|
|
1023
|
+
index: i,
|
|
1024
|
+
label,
|
|
1025
|
+
outcome: "warning-soft-failure",
|
|
1026
|
+
message: detail,
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
if (hardDisabledIndexes.length > 0) {
|
|
1031
|
+
const enabledCount = storage.accounts.filter((account) => account.enabled !== false).length;
|
|
1032
|
+
if (enabledCount === 0) {
|
|
1033
|
+
const fallbackIndex = hardDisabledIndexes.includes(activeIndex)
|
|
1034
|
+
? activeIndex
|
|
1035
|
+
: hardDisabledIndexes[0];
|
|
1036
|
+
const fallback = typeof fallbackIndex === "number"
|
|
1037
|
+
? storage.accounts[fallbackIndex]
|
|
1038
|
+
: undefined;
|
|
1039
|
+
if (fallback && fallback.enabled === false) {
|
|
1040
|
+
fallback.enabled = true;
|
|
1041
|
+
accountStorageChanged = true;
|
|
1042
|
+
const existingReport = reports.find((report) => report.index === fallbackIndex
|
|
1043
|
+
&& report.outcome === "disabled-hard-failure");
|
|
1044
|
+
if (existingReport) {
|
|
1045
|
+
existingReport.outcome = "warning-soft-failure";
|
|
1046
|
+
existingReport.message =
|
|
1047
|
+
`${existingReport.message} (kept enabled to avoid lockout; re-login required)`;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
const forecastResults = evaluateForecastAccounts(storage.accounts.map((account, index) => ({
|
|
1053
|
+
index,
|
|
1054
|
+
account,
|
|
1055
|
+
isCurrent: index === activeIndex,
|
|
1056
|
+
now,
|
|
1057
|
+
refreshFailure: refreshFailures.get(index),
|
|
1058
|
+
})));
|
|
1059
|
+
const recommendation = recommendForecastAccount(forecastResults);
|
|
1060
|
+
const reportSummary = summarizeFixReports(reports);
|
|
1061
|
+
const accountMutations = collectAccountStorageMutations(originalAccounts, storage.accounts);
|
|
1062
|
+
if (accountStorageChanged && !options.dryRun) {
|
|
1063
|
+
await withAccountStorageTransaction(async (loadedStorage, persist) => {
|
|
1064
|
+
const nextStorage = loadedStorage
|
|
1065
|
+
? structuredClone(loadedStorage)
|
|
1066
|
+
: createEmptyAccountStorage();
|
|
1067
|
+
applyAccountStorageMutations(nextStorage, accountMutations);
|
|
1068
|
+
await persist(nextStorage);
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
const changed = accountStorageChanged;
|
|
1072
|
+
if (options.json) {
|
|
1073
|
+
if (!options.dryRun && workingQuotaCache && quotaCacheChanged) {
|
|
1074
|
+
await saveQuotaCache(workingQuotaCache);
|
|
1075
|
+
}
|
|
1076
|
+
console.log(JSON.stringify({
|
|
1077
|
+
command: "fix",
|
|
1078
|
+
dryRun: options.dryRun,
|
|
1079
|
+
liveProbe: options.live,
|
|
1080
|
+
model: options.model,
|
|
1081
|
+
changed,
|
|
1082
|
+
quotaCacheChanged,
|
|
1083
|
+
summary: reportSummary,
|
|
1084
|
+
recommendation,
|
|
1085
|
+
recommendedSwitchCommand: recommendation.recommendedIndex !== null
|
|
1086
|
+
&& recommendation.recommendedIndex !== activeIndex
|
|
1087
|
+
? `codex auth switch ${recommendation.recommendedIndex + 1}`
|
|
1088
|
+
: null,
|
|
1089
|
+
reports,
|
|
1090
|
+
}, null, 2));
|
|
1091
|
+
return 0;
|
|
1092
|
+
}
|
|
1093
|
+
console.log(deps.stylePromptText(`Auto-fix scan (${options.dryRun ? "preview" : "apply"})`, "accent"));
|
|
1094
|
+
console.log(deps.formatResultSummary([
|
|
1095
|
+
{ text: `${reportSummary.healthy} working`, tone: "success" },
|
|
1096
|
+
{
|
|
1097
|
+
text: `${reportSummary.disabled} disabled`,
|
|
1098
|
+
tone: reportSummary.disabled > 0 ? "danger" : "muted",
|
|
1099
|
+
},
|
|
1100
|
+
{
|
|
1101
|
+
text: `${reportSummary.warnings} warning${reportSummary.warnings === 1 ? "" : "s"}`,
|
|
1102
|
+
tone: reportSummary.warnings > 0 ? "warning" : "muted",
|
|
1103
|
+
},
|
|
1104
|
+
{ text: `${reportSummary.skipped} already disabled`, tone: "muted" },
|
|
1105
|
+
]));
|
|
1106
|
+
if (display.showPerAccountRows) {
|
|
1107
|
+
console.log("");
|
|
1108
|
+
for (const report of reports) {
|
|
1109
|
+
const prefix = report.outcome === "healthy"
|
|
1110
|
+
? "✓"
|
|
1111
|
+
: report.outcome === "disabled-hard-failure"
|
|
1112
|
+
? "✗"
|
|
1113
|
+
: report.outcome === "warning-soft-failure"
|
|
1114
|
+
? "!"
|
|
1115
|
+
: "-";
|
|
1116
|
+
const tone = report.outcome === "healthy"
|
|
1117
|
+
? "success"
|
|
1118
|
+
: report.outcome === "disabled-hard-failure"
|
|
1119
|
+
? "danger"
|
|
1120
|
+
: report.outcome === "warning-soft-failure"
|
|
1121
|
+
? "warning"
|
|
1122
|
+
: "muted";
|
|
1123
|
+
console.log(`${deps.stylePromptText(prefix, tone)} ${deps.stylePromptText(`${report.index + 1}. ${report.label}`, "accent")} ${deps.stylePromptText("|", "muted")} ${deps.styleAccountDetailText(report.message, tone === "success" ? "muted" : tone)}`);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
else {
|
|
1127
|
+
console.log("");
|
|
1128
|
+
console.log(deps.stylePromptText("Per-account lines are hidden in dashboard settings.", "muted"));
|
|
1129
|
+
}
|
|
1130
|
+
if (display.showRecommendations) {
|
|
1131
|
+
console.log("");
|
|
1132
|
+
if (recommendation.recommendedIndex !== null) {
|
|
1133
|
+
const target = recommendation.recommendedIndex + 1;
|
|
1134
|
+
console.log(`${deps.stylePromptText("Best next account:", "accent")} ${deps.stylePromptText(String(target), "success")}`);
|
|
1135
|
+
console.log(`${deps.stylePromptText("Why:", "accent")} ${deps.stylePromptText(recommendation.reason, "muted")}`);
|
|
1136
|
+
if (recommendation.recommendedIndex !== activeIndex) {
|
|
1137
|
+
console.log(`${deps.stylePromptText("Switch now with:", "accent")} codex auth switch ${target}`);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
else {
|
|
1141
|
+
console.log(`${deps.stylePromptText("Note:", "accent")} ${deps.stylePromptText(recommendation.reason, "muted")}`);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
if (!options.dryRun && workingQuotaCache && quotaCacheChanged) {
|
|
1145
|
+
await saveQuotaCache(workingQuotaCache);
|
|
1146
|
+
}
|
|
1147
|
+
if (accountStorageChanged && options.dryRun) {
|
|
1148
|
+
console.log(`\n${deps.stylePromptText("Preview only: no changes were saved.", "warning")}`);
|
|
1149
|
+
}
|
|
1150
|
+
else if (accountStorageChanged) {
|
|
1151
|
+
console.log(`\n${deps.stylePromptText("Saved updates.", "success")}`);
|
|
1152
|
+
}
|
|
1153
|
+
else if (quotaCacheChanged) {
|
|
1154
|
+
console.log(`\n${deps.stylePromptText("Quota cache refreshed (no account storage changes).", "muted")}`);
|
|
1155
|
+
}
|
|
1156
|
+
else {
|
|
1157
|
+
console.log(`\n${deps.stylePromptText("No changes were needed.", "muted")}`);
|
|
1158
|
+
}
|
|
1159
|
+
return 0;
|
|
1160
|
+
}
|
|
1161
|
+
export async function runDoctor(args, deps) {
|
|
1162
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1163
|
+
printDoctorUsage();
|
|
1164
|
+
return 0;
|
|
1165
|
+
}
|
|
1166
|
+
const parsedArgs = parseDoctorArgs(args);
|
|
1167
|
+
if (!parsedArgs.ok) {
|
|
1168
|
+
console.error(parsedArgs.message);
|
|
1169
|
+
printDoctorUsage();
|
|
1170
|
+
return 1;
|
|
1171
|
+
}
|
|
1172
|
+
const options = parsedArgs.options;
|
|
1173
|
+
setStoragePath(null);
|
|
1174
|
+
const storagePath = getStoragePath();
|
|
1175
|
+
const storageFileExists = existsSync(storagePath);
|
|
1176
|
+
const checks = [];
|
|
1177
|
+
const addCheck = (check) => {
|
|
1178
|
+
checks.push(check);
|
|
1179
|
+
};
|
|
1180
|
+
addCheck({
|
|
1181
|
+
key: "storage-file",
|
|
1182
|
+
severity: storageFileExists ? "ok" : "warn",
|
|
1183
|
+
message: storageFileExists
|
|
1184
|
+
? "Account storage file found"
|
|
1185
|
+
: "Account storage file does not exist yet (first login pending)",
|
|
1186
|
+
details: storagePath,
|
|
1187
|
+
});
|
|
1188
|
+
if (storageFileExists) {
|
|
1189
|
+
try {
|
|
1190
|
+
const stat = await fs.stat(storagePath);
|
|
1191
|
+
addCheck({
|
|
1192
|
+
key: "storage-readable",
|
|
1193
|
+
severity: stat.size > 0 ? "ok" : "warn",
|
|
1194
|
+
message: stat.size > 0 ? "Storage file is readable" : "Storage file is empty",
|
|
1195
|
+
details: `${stat.size} bytes`,
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
catch (error) {
|
|
1199
|
+
addCheck({
|
|
1200
|
+
key: "storage-readable",
|
|
1201
|
+
severity: "error",
|
|
1202
|
+
message: "Unable to read storage file metadata",
|
|
1203
|
+
details: error instanceof Error ? error.message : String(error),
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
const codexAuthPath = getCodexCliAuthPath();
|
|
1208
|
+
const codexConfigPath = getCodexCliConfigPath();
|
|
1209
|
+
const codexAuthFileExists = existsSync(codexAuthPath);
|
|
1210
|
+
const codexConfigFileExists = existsSync(codexConfigPath);
|
|
1211
|
+
let codexAuthEmail;
|
|
1212
|
+
let codexAuthAccountId;
|
|
1213
|
+
addCheck({
|
|
1214
|
+
key: "codex-auth-file",
|
|
1215
|
+
severity: codexAuthFileExists ? "ok" : "warn",
|
|
1216
|
+
message: codexAuthFileExists
|
|
1217
|
+
? "Codex auth file found"
|
|
1218
|
+
: "Codex auth file does not exist",
|
|
1219
|
+
details: codexAuthPath,
|
|
1220
|
+
});
|
|
1221
|
+
if (codexAuthFileExists) {
|
|
1222
|
+
try {
|
|
1223
|
+
const raw = await fs.readFile(codexAuthPath, "utf-8");
|
|
1224
|
+
const parsed = JSON.parse(raw);
|
|
1225
|
+
if (parsed && typeof parsed === "object") {
|
|
1226
|
+
const payload = parsed;
|
|
1227
|
+
const tokens = payload.tokens && typeof payload.tokens === "object"
|
|
1228
|
+
? payload.tokens
|
|
1229
|
+
: null;
|
|
1230
|
+
const accessToken = tokens && typeof tokens.access_token === "string"
|
|
1231
|
+
? tokens.access_token
|
|
1232
|
+
: undefined;
|
|
1233
|
+
const idToken = tokens && typeof tokens.id_token === "string"
|
|
1234
|
+
? tokens.id_token
|
|
1235
|
+
: undefined;
|
|
1236
|
+
const accountIdFromFile = tokens && typeof tokens.account_id === "string"
|
|
1237
|
+
? tokens.account_id
|
|
1238
|
+
: undefined;
|
|
1239
|
+
const emailFromFile = typeof payload.email === "string" ? payload.email : undefined;
|
|
1240
|
+
codexAuthEmail = sanitizeEmail(emailFromFile ?? extractAccountEmail(accessToken, idToken));
|
|
1241
|
+
codexAuthAccountId = accountIdFromFile ?? extractAccountId(accessToken);
|
|
1242
|
+
}
|
|
1243
|
+
addCheck({
|
|
1244
|
+
key: "codex-auth-readable",
|
|
1245
|
+
severity: "ok",
|
|
1246
|
+
message: "Codex auth file is readable",
|
|
1247
|
+
details: codexAuthEmail || codexAuthAccountId
|
|
1248
|
+
? formatDoctorIdentitySummary({
|
|
1249
|
+
email: codexAuthEmail,
|
|
1250
|
+
accountId: codexAuthAccountId,
|
|
1251
|
+
})
|
|
1252
|
+
: undefined,
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
catch (error) {
|
|
1256
|
+
addCheck({
|
|
1257
|
+
key: "codex-auth-readable",
|
|
1258
|
+
severity: "error",
|
|
1259
|
+
message: "Unable to read Codex auth file",
|
|
1260
|
+
details: error instanceof Error ? error.message : String(error),
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
addCheck({
|
|
1265
|
+
key: "codex-config-file",
|
|
1266
|
+
severity: codexConfigFileExists ? "ok" : "warn",
|
|
1267
|
+
message: codexConfigFileExists
|
|
1268
|
+
? "Codex config file found"
|
|
1269
|
+
: "Codex config file does not exist",
|
|
1270
|
+
details: codexConfigPath,
|
|
1271
|
+
});
|
|
1272
|
+
let codexAuthStoreMode;
|
|
1273
|
+
if (codexConfigFileExists) {
|
|
1274
|
+
try {
|
|
1275
|
+
const configRaw = await fs.readFile(codexConfigPath, "utf-8");
|
|
1276
|
+
const match = configRaw.match(/^\s*cli_auth_credentials_store\s*=\s*"([^"]+)"\s*$/m);
|
|
1277
|
+
if (match?.[1]) {
|
|
1278
|
+
codexAuthStoreMode = match[1].trim();
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
catch (error) {
|
|
1282
|
+
addCheck({
|
|
1283
|
+
key: "codex-auth-store",
|
|
1284
|
+
severity: "warn",
|
|
1285
|
+
message: "Unable to read Codex auth-store config",
|
|
1286
|
+
details: error instanceof Error ? error.message : String(error),
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
if (!checks.some((check) => check.key === "codex-auth-store")) {
|
|
1291
|
+
addCheck({
|
|
1292
|
+
key: "codex-auth-store",
|
|
1293
|
+
severity: codexAuthStoreMode === "file" ? "ok" : "warn",
|
|
1294
|
+
message: codexAuthStoreMode === "file"
|
|
1295
|
+
? "Codex auth storage is set to file"
|
|
1296
|
+
: "Codex auth storage is not explicitly set to file",
|
|
1297
|
+
details: codexAuthStoreMode ? `mode=${codexAuthStoreMode}` : "mode=unset",
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
const codexCliState = await loadCodexCliState({ forceRefresh: true });
|
|
1301
|
+
addCheck({
|
|
1302
|
+
key: "codex-cli-state",
|
|
1303
|
+
severity: codexCliState ? "ok" : "warn",
|
|
1304
|
+
message: codexCliState
|
|
1305
|
+
? "Codex CLI state loaded"
|
|
1306
|
+
: "Codex CLI state unavailable",
|
|
1307
|
+
details: codexCliState?.path,
|
|
1308
|
+
});
|
|
1309
|
+
const loadedStorage = await loadAccounts();
|
|
1310
|
+
const storage = loadedStorage ? structuredClone(loadedStorage) : loadedStorage;
|
|
1311
|
+
const storageForChecks = options.fix && storage ? structuredClone(storage) : storage;
|
|
1312
|
+
let fixChanged = false;
|
|
1313
|
+
let storageFixChanged = false;
|
|
1314
|
+
let structuralFixActions = [];
|
|
1315
|
+
const supplementalFixActions = [];
|
|
1316
|
+
let doctorRefreshMutation = null;
|
|
1317
|
+
let pendingCodexActiveSync = null;
|
|
1318
|
+
if (options.fix && storageForChecks && storageForChecks.accounts.length > 0) {
|
|
1319
|
+
const fixed = applyDoctorFixes(storageForChecks, deps);
|
|
1320
|
+
storageFixChanged = fixed.changed;
|
|
1321
|
+
structuralFixActions = fixed.actions;
|
|
1322
|
+
}
|
|
1323
|
+
if (!storageForChecks || storageForChecks.accounts.length === 0) {
|
|
1324
|
+
addCheck({
|
|
1325
|
+
key: "accounts",
|
|
1326
|
+
severity: "warn",
|
|
1327
|
+
message: "No accounts configured",
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
else {
|
|
1331
|
+
addCheck({
|
|
1332
|
+
key: "accounts",
|
|
1333
|
+
severity: "ok",
|
|
1334
|
+
message: `Loaded ${storageForChecks.accounts.length} account(s)`,
|
|
1335
|
+
});
|
|
1336
|
+
const activeIndex = deps.resolveActiveIndex(storageForChecks, "codex");
|
|
1337
|
+
const activeExists = activeIndex >= 0 && activeIndex < storageForChecks.accounts.length;
|
|
1338
|
+
addCheck({
|
|
1339
|
+
key: "active-index",
|
|
1340
|
+
severity: activeExists ? "ok" : "error",
|
|
1341
|
+
message: activeExists
|
|
1342
|
+
? `Active index is valid (${activeIndex + 1})`
|
|
1343
|
+
: "Active index is out of range",
|
|
1344
|
+
});
|
|
1345
|
+
const disabledCount = storageForChecks.accounts.filter((a) => a.enabled === false).length;
|
|
1346
|
+
addCheck({
|
|
1347
|
+
key: "enabled-accounts",
|
|
1348
|
+
severity: disabledCount >= storageForChecks.accounts.length ? "error" : "ok",
|
|
1349
|
+
message: disabledCount >= storageForChecks.accounts.length
|
|
1350
|
+
? "All accounts are disabled"
|
|
1351
|
+
: `${storageForChecks.accounts.length - disabledCount} enabled / ${disabledCount} disabled`,
|
|
1352
|
+
});
|
|
1353
|
+
const seenRefreshTokens = new Set();
|
|
1354
|
+
let duplicateTokenCount = 0;
|
|
1355
|
+
for (const account of storageForChecks.accounts) {
|
|
1356
|
+
const token = getDoctorRefreshTokenKey(account.refreshToken);
|
|
1357
|
+
if (!token)
|
|
1358
|
+
continue;
|
|
1359
|
+
if (seenRefreshTokens.has(token)) {
|
|
1360
|
+
duplicateTokenCount += 1;
|
|
1361
|
+
}
|
|
1362
|
+
else {
|
|
1363
|
+
seenRefreshTokens.add(token);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
addCheck({
|
|
1367
|
+
key: "duplicate-refresh-token",
|
|
1368
|
+
severity: duplicateTokenCount > 0 ? "warn" : "ok",
|
|
1369
|
+
message: duplicateTokenCount > 0
|
|
1370
|
+
? `Detected ${duplicateTokenCount} duplicate refresh token entr${duplicateTokenCount === 1 ? "y" : "ies"}`
|
|
1371
|
+
: "No duplicate refresh tokens detected",
|
|
1372
|
+
});
|
|
1373
|
+
const seenEmails = new Set();
|
|
1374
|
+
let duplicateEmailCount = 0;
|
|
1375
|
+
let placeholderEmailCount = 0;
|
|
1376
|
+
let likelyInvalidRefreshTokenCount = 0;
|
|
1377
|
+
for (const account of storageForChecks.accounts) {
|
|
1378
|
+
if (deps.hasLikelyInvalidRefreshToken(account.refreshToken)) {
|
|
1379
|
+
likelyInvalidRefreshTokenCount += 1;
|
|
1380
|
+
}
|
|
1381
|
+
const email = sanitizeEmail(account.email);
|
|
1382
|
+
if (!email)
|
|
1383
|
+
continue;
|
|
1384
|
+
if (seenEmails.has(email))
|
|
1385
|
+
duplicateEmailCount += 1;
|
|
1386
|
+
seenEmails.add(email);
|
|
1387
|
+
if (hasPlaceholderEmail(email))
|
|
1388
|
+
placeholderEmailCount += 1;
|
|
1389
|
+
}
|
|
1390
|
+
addCheck({
|
|
1391
|
+
key: "duplicate-email",
|
|
1392
|
+
severity: duplicateEmailCount > 0 ? "warn" : "ok",
|
|
1393
|
+
message: duplicateEmailCount > 0
|
|
1394
|
+
? `Detected ${duplicateEmailCount} duplicate email entr${duplicateEmailCount === 1 ? "y" : "ies"}`
|
|
1395
|
+
: "No duplicate emails detected",
|
|
1396
|
+
});
|
|
1397
|
+
addCheck({
|
|
1398
|
+
key: "placeholder-email",
|
|
1399
|
+
severity: placeholderEmailCount > 0 ? "warn" : "ok",
|
|
1400
|
+
message: placeholderEmailCount > 0
|
|
1401
|
+
? `${placeholderEmailCount} account(s) appear to be placeholder/demo entries`
|
|
1402
|
+
: "No placeholder emails detected",
|
|
1403
|
+
});
|
|
1404
|
+
addCheck({
|
|
1405
|
+
key: "refresh-token-shape",
|
|
1406
|
+
severity: likelyInvalidRefreshTokenCount > 0 ? "warn" : "ok",
|
|
1407
|
+
message: likelyInvalidRefreshTokenCount > 0
|
|
1408
|
+
? `${likelyInvalidRefreshTokenCount} account(s) have likely invalid refresh token format`
|
|
1409
|
+
: "Refresh token format looks normal",
|
|
1410
|
+
});
|
|
1411
|
+
const now = Date.now();
|
|
1412
|
+
const forecastResults = evaluateForecastAccounts(storageForChecks.accounts.map((account, index) => ({
|
|
1413
|
+
index,
|
|
1414
|
+
account,
|
|
1415
|
+
isCurrent: index === activeIndex,
|
|
1416
|
+
now,
|
|
1417
|
+
})));
|
|
1418
|
+
const recommendation = recommendForecastAccount(forecastResults);
|
|
1419
|
+
if (recommendation.recommendedIndex !== null
|
|
1420
|
+
&& recommendation.recommendedIndex !== activeIndex) {
|
|
1421
|
+
addCheck({
|
|
1422
|
+
key: "recommended-switch",
|
|
1423
|
+
severity: "warn",
|
|
1424
|
+
message: `A healthier account is available: switch to ${recommendation.recommendedIndex + 1}`,
|
|
1425
|
+
details: recommendation.reason,
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
else {
|
|
1429
|
+
addCheck({
|
|
1430
|
+
key: "recommended-switch",
|
|
1431
|
+
severity: "ok",
|
|
1432
|
+
message: "Current account aligns with forecast recommendation",
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
if (activeExists) {
|
|
1436
|
+
const activeAccount = storageForChecks.accounts[activeIndex];
|
|
1437
|
+
const managerActiveEmail = sanitizeEmail(activeAccount?.email);
|
|
1438
|
+
const managerActiveAccountId = activeAccount?.accountId;
|
|
1439
|
+
const codexActiveEmail = sanitizeEmail(codexCliState?.activeEmail) ?? codexAuthEmail;
|
|
1440
|
+
const codexActiveAccountId = codexCliState?.activeAccountId ?? codexAuthAccountId;
|
|
1441
|
+
const isEmailMismatch = !!managerActiveEmail
|
|
1442
|
+
&& !!codexActiveEmail
|
|
1443
|
+
&& managerActiveEmail !== codexActiveEmail;
|
|
1444
|
+
const isAccountIdMismatch = !!managerActiveAccountId
|
|
1445
|
+
&& !!codexActiveAccountId
|
|
1446
|
+
&& managerActiveAccountId !== codexActiveAccountId;
|
|
1447
|
+
addCheck({
|
|
1448
|
+
key: "active-selection-sync",
|
|
1449
|
+
severity: isEmailMismatch || isAccountIdMismatch ? "warn" : "ok",
|
|
1450
|
+
message: isEmailMismatch || isAccountIdMismatch
|
|
1451
|
+
? "Manager active account and Codex active account are not aligned"
|
|
1452
|
+
: "Manager active account and Codex active account are aligned",
|
|
1453
|
+
details: `manager=${formatDoctorIdentitySummary({
|
|
1454
|
+
email: managerActiveEmail,
|
|
1455
|
+
accountId: managerActiveAccountId,
|
|
1456
|
+
})} | codex=${formatDoctorIdentitySummary({
|
|
1457
|
+
email: codexActiveEmail,
|
|
1458
|
+
accountId: codexActiveAccountId,
|
|
1459
|
+
})}`,
|
|
1460
|
+
});
|
|
1461
|
+
if (options.fix && activeAccount) {
|
|
1462
|
+
const activeAccountMatch = structuredClone(activeAccount);
|
|
1463
|
+
let syncAccessToken = activeAccount.accessToken;
|
|
1464
|
+
let syncRefreshToken = activeAccount.refreshToken;
|
|
1465
|
+
let syncExpiresAt = activeAccount.expiresAt;
|
|
1466
|
+
let syncIdToken;
|
|
1467
|
+
let canSyncActiveAccount = deps.hasUsableAccessToken(activeAccount, now);
|
|
1468
|
+
if (!canSyncActiveAccount) {
|
|
1469
|
+
if (options.dryRun) {
|
|
1470
|
+
supplementalFixActions.push({
|
|
1471
|
+
key: "doctor-refresh",
|
|
1472
|
+
message: `Prepared active-account token refresh for account ${activeIndex + 1} (dry-run)`,
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
else {
|
|
1476
|
+
const refreshResult = await queuedRefresh(activeAccount.refreshToken);
|
|
1477
|
+
if (refreshResult.type === "success") {
|
|
1478
|
+
const refreshedEmail = sanitizeEmail(extractAccountEmail(refreshResult.access, refreshResult.idToken));
|
|
1479
|
+
const refreshedAccountId = extractAccountId(refreshResult.access);
|
|
1480
|
+
activeAccount.accessToken = refreshResult.access;
|
|
1481
|
+
activeAccount.refreshToken = refreshResult.refresh;
|
|
1482
|
+
activeAccount.expiresAt = refreshResult.expires;
|
|
1483
|
+
if (refreshedEmail)
|
|
1484
|
+
activeAccount.email = refreshedEmail;
|
|
1485
|
+
deps.applyTokenAccountIdentity(activeAccount, refreshedAccountId);
|
|
1486
|
+
doctorRefreshMutation = {
|
|
1487
|
+
match: activeAccountMatch,
|
|
1488
|
+
accessToken: refreshResult.access,
|
|
1489
|
+
refreshToken: refreshResult.refresh,
|
|
1490
|
+
expiresAt: refreshResult.expires,
|
|
1491
|
+
...(refreshedEmail ? { email: refreshedEmail } : {}),
|
|
1492
|
+
...(refreshedAccountId ? { accountId: refreshedAccountId } : {}),
|
|
1493
|
+
};
|
|
1494
|
+
syncAccessToken = refreshResult.access;
|
|
1495
|
+
syncRefreshToken = refreshResult.refresh;
|
|
1496
|
+
syncExpiresAt = refreshResult.expires;
|
|
1497
|
+
syncIdToken = refreshResult.idToken;
|
|
1498
|
+
canSyncActiveAccount = true;
|
|
1499
|
+
storageFixChanged = true;
|
|
1500
|
+
fixChanged = true;
|
|
1501
|
+
supplementalFixActions.push({
|
|
1502
|
+
key: "doctor-refresh",
|
|
1503
|
+
message: `Refreshed active account tokens for account ${activeIndex + 1}`,
|
|
1504
|
+
});
|
|
1505
|
+
}
|
|
1506
|
+
else {
|
|
1507
|
+
addCheck({
|
|
1508
|
+
key: "doctor-refresh",
|
|
1509
|
+
severity: "warn",
|
|
1510
|
+
message: "Unable to refresh active account before Codex sync",
|
|
1511
|
+
details: deps.normalizeFailureDetail(refreshResult.message, refreshResult.reason),
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
if (!options.dryRun && canSyncActiveAccount) {
|
|
1517
|
+
pendingCodexActiveSync = {
|
|
1518
|
+
accountId: activeAccount.accountId,
|
|
1519
|
+
email: activeAccount.email,
|
|
1520
|
+
accessToken: syncAccessToken,
|
|
1521
|
+
refreshToken: syncRefreshToken,
|
|
1522
|
+
expiresAt: syncExpiresAt,
|
|
1523
|
+
...(syncIdToken ? { idToken: syncIdToken } : {}),
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
else if (options.dryRun && canSyncActiveAccount) {
|
|
1527
|
+
supplementalFixActions.push({
|
|
1528
|
+
key: "codex-active-sync",
|
|
1529
|
+
message: "Prepared Codex active-account sync (dry-run)",
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
if (options.fix
|
|
1536
|
+
&& storageForChecks
|
|
1537
|
+
&& storageForChecks.accounts.length > 0
|
|
1538
|
+
&& storageFixChanged
|
|
1539
|
+
&& !options.dryRun) {
|
|
1540
|
+
await withAccountStorageTransaction(async (loadedStorage, persist) => {
|
|
1541
|
+
const nextStorage = loadedStorage
|
|
1542
|
+
? structuredClone(loadedStorage)
|
|
1543
|
+
: createEmptyAccountStorage();
|
|
1544
|
+
const transactionFixed = applyDoctorFixes(nextStorage, deps);
|
|
1545
|
+
structuralFixActions = transactionFixed.actions;
|
|
1546
|
+
let transactionChanged = transactionFixed.changed;
|
|
1547
|
+
if (doctorRefreshMutation) {
|
|
1548
|
+
const fallbackActiveIndex = deps.resolveActiveIndex(nextStorage, "codex");
|
|
1549
|
+
const fallbackTargetIndex = fallbackActiveIndex >= 0 && fallbackActiveIndex < nextStorage.accounts.length
|
|
1550
|
+
? fallbackActiveIndex
|
|
1551
|
+
: undefined;
|
|
1552
|
+
const targetIndex = findMatchingAccountIndex(nextStorage.accounts, doctorRefreshMutation.match, {
|
|
1553
|
+
allowUniqueAccountIdFallbackWithoutEmail: true,
|
|
1554
|
+
})
|
|
1555
|
+
?? findMatchingAccountIndex(nextStorage.accounts, {
|
|
1556
|
+
accountId: doctorRefreshMutation.accountId,
|
|
1557
|
+
email: doctorRefreshMutation.email,
|
|
1558
|
+
refreshToken: doctorRefreshMutation.refreshToken,
|
|
1559
|
+
}, {
|
|
1560
|
+
allowUniqueAccountIdFallbackWithoutEmail: true,
|
|
1561
|
+
})
|
|
1562
|
+
?? fallbackTargetIndex;
|
|
1563
|
+
const target = targetIndex === undefined ? undefined : nextStorage.accounts[targetIndex];
|
|
1564
|
+
if (target) {
|
|
1565
|
+
if (target.accessToken !== doctorRefreshMutation.accessToken) {
|
|
1566
|
+
target.accessToken = doctorRefreshMutation.accessToken;
|
|
1567
|
+
transactionChanged = true;
|
|
1568
|
+
}
|
|
1569
|
+
if (target.refreshToken !== doctorRefreshMutation.refreshToken) {
|
|
1570
|
+
target.refreshToken = doctorRefreshMutation.refreshToken;
|
|
1571
|
+
transactionChanged = true;
|
|
1572
|
+
}
|
|
1573
|
+
if (target.expiresAt !== doctorRefreshMutation.expiresAt) {
|
|
1574
|
+
target.expiresAt = doctorRefreshMutation.expiresAt;
|
|
1575
|
+
transactionChanged = true;
|
|
1576
|
+
}
|
|
1577
|
+
if (doctorRefreshMutation.email && target.email !== doctorRefreshMutation.email) {
|
|
1578
|
+
target.email = doctorRefreshMutation.email;
|
|
1579
|
+
transactionChanged = true;
|
|
1580
|
+
}
|
|
1581
|
+
if (deps.applyTokenAccountIdentity(target, doctorRefreshMutation.accountId)) {
|
|
1582
|
+
transactionChanged = true;
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
if (normalizeDoctorIndexes(nextStorage)) {
|
|
1587
|
+
transactionChanged = true;
|
|
1588
|
+
}
|
|
1589
|
+
if (!transactionChanged) {
|
|
1590
|
+
structuralFixActions = [];
|
|
1591
|
+
storageFixChanged = false;
|
|
1592
|
+
return;
|
|
1593
|
+
}
|
|
1594
|
+
storageFixChanged = true;
|
|
1595
|
+
await persist(nextStorage);
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
if (pendingCodexActiveSync && (!doctorRefreshMutation || storageFixChanged)) {
|
|
1599
|
+
const synced = await setCodexCliActiveSelection(pendingCodexActiveSync);
|
|
1600
|
+
if (synced) {
|
|
1601
|
+
supplementalFixActions.push({
|
|
1602
|
+
key: "codex-active-sync",
|
|
1603
|
+
message: "Synced manager active account into Codex auth state",
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1606
|
+
else {
|
|
1607
|
+
addCheck({
|
|
1608
|
+
key: "codex-active-sync",
|
|
1609
|
+
severity: "warn",
|
|
1610
|
+
message: "Failed to sync manager active account into Codex auth state",
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
const fixActions = [...structuralFixActions, ...supplementalFixActions];
|
|
1615
|
+
if (options.fix && storageForChecks && storageForChecks.accounts.length > 0) {
|
|
1616
|
+
fixChanged = storageFixChanged || fixActions.length > 0;
|
|
1617
|
+
addCheck({
|
|
1618
|
+
key: "auto-fix",
|
|
1619
|
+
severity: fixChanged ? "warn" : "ok",
|
|
1620
|
+
message: fixChanged
|
|
1621
|
+
? options.dryRun
|
|
1622
|
+
? `Prepared ${fixActions.length} fix(es) (dry-run)`
|
|
1623
|
+
: `Applied ${fixActions.length} fix(es)`
|
|
1624
|
+
: "No safe auto-fixes needed",
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
const summary = checks.reduce((acc, check) => {
|
|
1628
|
+
acc[check.severity] += 1;
|
|
1629
|
+
return acc;
|
|
1630
|
+
}, { ok: 0, warn: 0, error: 0 });
|
|
1631
|
+
if (options.json) {
|
|
1632
|
+
console.log(JSON.stringify({
|
|
1633
|
+
command: "doctor",
|
|
1634
|
+
storagePath,
|
|
1635
|
+
summary,
|
|
1636
|
+
checks,
|
|
1637
|
+
fix: {
|
|
1638
|
+
enabled: options.fix,
|
|
1639
|
+
dryRun: options.dryRun,
|
|
1640
|
+
changed: fixChanged,
|
|
1641
|
+
actions: fixActions,
|
|
1642
|
+
},
|
|
1643
|
+
}, null, 2));
|
|
1644
|
+
return summary.error > 0 ? 1 : 0;
|
|
1645
|
+
}
|
|
1646
|
+
console.log("Doctor diagnostics");
|
|
1647
|
+
console.log(`Storage: ${storagePath}`);
|
|
1648
|
+
console.log(`Summary: ${summary.ok} ok, ${summary.warn} warnings, ${summary.error} errors`);
|
|
1649
|
+
console.log("");
|
|
1650
|
+
for (const check of checks) {
|
|
1651
|
+
const marker = check.severity === "ok" ? "✓" : check.severity === "warn" ? "!" : "✗";
|
|
1652
|
+
console.log(`${marker} ${check.key}: ${check.message}`);
|
|
1653
|
+
if (check.details) {
|
|
1654
|
+
console.log(` ${check.details}`);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
if (options.fix) {
|
|
1658
|
+
console.log("");
|
|
1659
|
+
if (fixActions.length > 0) {
|
|
1660
|
+
console.log(`Auto-fix actions (${options.dryRun ? "dry-run" : "applied"}):`);
|
|
1661
|
+
for (const action of fixActions) {
|
|
1662
|
+
console.log(` - ${action.message}`);
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
else {
|
|
1666
|
+
console.log("Auto-fix actions: none");
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
return summary.error > 0 ? 1 : 0;
|
|
1670
|
+
}
|
|
1671
|
+
//# sourceMappingURL=repair-commands.js.map
|