codex-multi-auth 2.17.0 → 2.17.3
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/.codex-plugin/plugin.json +9 -9
- package/LICENSE +21 -21
- package/README.md +142 -484
- package/assets/codex-multi-auth-icon.svg +39 -39
- package/assets/readme-hero.svg +31 -31
- package/config/README.md +31 -31
- package/config/codex-legacy.json +1221 -1221
- package/config/codex-modern.json +423 -423
- package/config/minimal-codex.json +15 -15
- package/dist/index.d.ts +0 -1
- package/dist/lib/account-policy.d.ts +18 -2
- package/dist/lib/account-policy.js +97 -40
- package/dist/lib/accounts/rate-limits.d.ts +0 -1
- package/dist/lib/accounts.d.ts +1 -8
- package/dist/lib/accounts.d.ts.map +1 -1
- package/dist/lib/accounts.js +7 -19
- package/dist/lib/api-route-store.d.ts +0 -1
- package/dist/lib/audit.d.ts +0 -1
- package/dist/lib/audit.js +43 -12
- package/dist/lib/auth/account-access.d.ts +0 -1
- package/dist/lib/auth/account-access.js +5 -1
- package/dist/lib/auth/auth.d.ts +4 -3
- package/dist/lib/auth/auth.js +220 -28
- package/dist/lib/auth/browser.d.ts +0 -1
- package/dist/lib/auth/callback-guidance.d.ts +0 -1
- package/dist/lib/auth/device-auth.d.ts +0 -1
- package/dist/lib/auth/index.d.ts +0 -1
- package/dist/lib/auth/org-override.d.ts +0 -1
- package/dist/lib/auth/server.d.ts +1 -2
- package/dist/lib/auth/server.js +100 -53
- package/dist/lib/auth/token-utils.d.ts +0 -1
- package/dist/lib/auth-rate-limit.d.ts +0 -1
- package/dist/lib/budget-guard.d.ts +16 -2
- package/dist/lib/budget-guard.js +123 -43
- package/dist/lib/capability-policy.d.ts +0 -1
- package/dist/lib/circuit-breaker.d.ts +20 -1
- package/dist/lib/circuit-breaker.js +24 -5
- package/dist/lib/cli.d.ts +0 -1
- package/dist/lib/codex-cli/index.d.ts +0 -1
- package/dist/lib/codex-cli/observability.d.ts +0 -1
- package/dist/lib/codex-cli/state.d.ts +0 -1
- package/dist/lib/codex-cli/sync.d.ts +0 -1
- package/dist/lib/codex-cli/writer.d.ts +0 -1
- package/dist/lib/codex-manager/account-credentials.d.ts +0 -1
- package/dist/lib/codex-manager/account-manager-commands.d.ts +0 -1
- package/dist/lib/codex-manager/account-pool-write.d.ts +0 -1
- package/dist/lib/codex-manager/active-account-sync.d.ts +6 -0
- package/dist/lib/codex-manager/active-account-sync.js +336 -0
- package/dist/lib/codex-manager/api-login-menu.d.ts +0 -1
- package/dist/lib/codex-manager/backend-category-entry.d.ts +0 -1
- package/dist/lib/codex-manager/backend-category-helpers.d.ts +0 -1
- package/dist/lib/codex-manager/backend-category-prompt.d.ts +0 -1
- package/dist/lib/codex-manager/backend-settings-controller.d.ts +0 -1
- package/dist/lib/codex-manager/backend-settings-entry.d.ts +0 -1
- package/dist/lib/codex-manager/backend-settings-helpers.d.ts +0 -1
- package/dist/lib/codex-manager/backend-settings-prompt.d.ts +0 -1
- package/dist/lib/codex-manager/backend-settings-schema.d.ts +0 -1
- package/dist/lib/codex-manager/behavior-settings-panel.d.ts +0 -1
- package/dist/lib/codex-manager/commands/account.d.ts +8 -3
- package/dist/lib/codex-manager/commands/account.js +46 -34
- package/dist/lib/codex-manager/commands/best.d.ts +0 -1
- package/dist/lib/codex-manager/commands/bridge.d.ts +0 -1
- package/dist/lib/codex-manager/commands/budget.d.ts +8 -3
- package/dist/lib/codex-manager/commands/budget.js +6 -4
- package/dist/lib/codex-manager/commands/check.d.ts +0 -1
- package/dist/lib/codex-manager/commands/config-explain.d.ts +0 -1
- package/dist/lib/codex-manager/commands/debug-bundle.d.ts +0 -1
- package/dist/lib/codex-manager/commands/forecast.d.ts +1 -2
- package/dist/lib/codex-manager/commands/forecast.d.ts.map +1 -1
- package/dist/lib/codex-manager/commands/forecast.js +2 -2
- package/dist/lib/codex-manager/commands/history.d.ts +0 -1
- package/dist/lib/codex-manager/commands/init-config.d.ts +0 -1
- package/dist/lib/codex-manager/commands/integrations.d.ts +0 -1
- package/dist/lib/codex-manager/commands/limits.d.ts +0 -1
- package/dist/lib/codex-manager/commands/models.d.ts +0 -1
- package/dist/lib/codex-manager/commands/monitor.d.ts +0 -1
- package/dist/lib/codex-manager/commands/report.d.ts +0 -1
- package/dist/lib/codex-manager/commands/resets.d.ts +0 -1
- package/dist/lib/codex-manager/commands/resets.js +9 -1
- package/dist/lib/codex-manager/commands/rotation.d.ts +0 -1
- package/dist/lib/codex-manager/commands/status.d.ts +0 -1
- package/dist/lib/codex-manager/commands/switch.d.ts +0 -1
- package/dist/lib/codex-manager/commands/uninstall.d.ts +0 -1
- package/dist/lib/codex-manager/commands/unpin.d.ts +0 -1
- package/dist/lib/codex-manager/commands/usage.d.ts +0 -1
- package/dist/lib/codex-manager/commands/verify.d.ts +0 -1
- package/dist/lib/codex-manager/commands/why-selected.d.ts +0 -1
- package/dist/lib/codex-manager/commands/workspace.d.ts +0 -1
- package/dist/lib/codex-manager/dashboard-display-panel.d.ts +0 -1
- package/dist/lib/codex-manager/dashboard-formatters.d.ts +0 -1
- package/dist/lib/codex-manager/dashboard-settings-controller.d.ts +0 -1
- package/dist/lib/codex-manager/dashboard-settings-data.d.ts +0 -1
- package/dist/lib/codex-manager/dashboard-settings-entry.d.ts +0 -1
- package/dist/lib/codex-manager/experimental-settings-entry.d.ts +0 -1
- package/dist/lib/codex-manager/experimental-settings-prompt.d.ts +0 -1
- package/dist/lib/codex-manager/experimental-settings-schema.d.ts +0 -1
- package/dist/lib/codex-manager/experimental-sync-target-entry.d.ts +0 -1
- package/dist/lib/codex-manager/experimental-sync-target.d.ts +0 -1
- package/dist/lib/codex-manager/forecast-report-shared.d.ts +0 -1
- package/dist/lib/codex-manager/formatters/account-formatters.d.ts +0 -1
- package/dist/lib/codex-manager/formatters/index.d.ts +0 -1
- package/dist/lib/codex-manager/formatters/model-formatters.d.ts +0 -1
- package/dist/lib/codex-manager/formatters/quota-formatters.d.ts +0 -1
- package/dist/lib/codex-manager/formatters/text-style.d.ts +0 -1
- package/dist/lib/codex-manager/health-check.d.ts +0 -1
- package/dist/lib/codex-manager/health-check.js +1 -1
- package/dist/lib/codex-manager/help.d.ts +0 -1
- package/dist/lib/codex-manager/login-action-panel.d.ts +0 -1
- package/dist/lib/codex-manager/login-flow.d.ts +0 -1
- package/dist/lib/codex-manager/login-menu-actions.d.ts +0 -1
- package/dist/lib/codex-manager/login-menu-data.d.ts +0 -1
- package/dist/lib/codex-manager/login-menu-data.d.ts.map +1 -1
- package/dist/lib/codex-manager/login-menu-data.js +7 -3
- package/dist/lib/codex-manager/login-oauth.d.ts +0 -1
- package/dist/lib/codex-manager/login-workspace-choice.d.ts +0 -1
- package/dist/lib/codex-manager/manual-callback.d.ts +0 -1
- package/dist/lib/codex-manager/persist-selected-account.d.ts +0 -1
- package/dist/lib/codex-manager/quota-cache-helpers.d.ts +7 -2
- package/dist/lib/codex-manager/quota-cache-helpers.d.ts.map +1 -1
- package/dist/lib/codex-manager/quota-cache-helpers.js +34 -19
- package/dist/lib/codex-manager/rate-limit-markers.d.ts +0 -1
- package/dist/lib/codex-manager/repair-commands.d.ts +0 -1
- package/dist/lib/codex-manager/repair-commands.js +1 -1
- package/dist/lib/codex-manager/settings-hub/backend.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub/dashboard.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub/experimental.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub/index.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub/shared.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub-entry.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub-menu.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub-prompt.d.ts +0 -1
- package/dist/lib/codex-manager/settings-hub.d.ts +0 -1
- package/dist/lib/codex-manager/settings-panels.d.ts +0 -1
- package/dist/lib/codex-manager/settings-persist-utils.d.ts +0 -1
- package/dist/lib/codex-manager/settings-preview.d.ts +0 -1
- package/dist/lib/codex-manager/settings-write-queue.d.ts +0 -1
- package/dist/lib/codex-manager/statusline-settings-panel.d.ts +0 -1
- package/dist/lib/codex-manager/theme-settings-panel.d.ts +0 -1
- package/dist/lib/codex-manager/unified-settings-controller.d.ts +0 -1
- package/dist/lib/codex-manager/unified-settings-entry.d.ts +0 -1
- package/dist/lib/codex-manager.d.ts +1 -2
- package/dist/lib/codex-manager.js +5 -95
- package/dist/lib/concurrency.d.ts +0 -1
- package/dist/lib/config-schema.d.ts +0 -1
- package/dist/lib/config.d.ts +0 -1
- package/dist/lib/config.js +46 -241
- package/dist/lib/constants.d.ts +0 -1
- package/dist/lib/context-budget/model-context-windows.d.ts +0 -1
- package/dist/lib/context-budget-guard.d.ts +0 -1
- package/dist/lib/context-budget-response.d.ts +0 -1
- package/dist/lib/context-budget-response.js +8 -8
- package/dist/lib/context-overflow.d.ts +0 -1
- package/dist/lib/context-overflow.js +10 -10
- package/dist/lib/dashboard-settings.d.ts +0 -1
- package/dist/lib/entitlement-cache.d.ts +0 -1
- package/dist/lib/env-parsing.d.ts +13 -1
- package/dist/lib/env-parsing.js +21 -0
- package/dist/lib/errors.d.ts +0 -1
- package/dist/lib/forecast.d.ts +0 -1
- package/dist/lib/fs-retry.d.ts +0 -1
- package/dist/lib/health.d.ts +0 -1
- package/dist/lib/index.d.ts +0 -1
- package/dist/lib/integration-generators.d.ts +0 -1
- package/dist/lib/live-account-sync.d.ts +0 -1
- package/dist/lib/local-bridge.d.ts +0 -1
- package/dist/lib/local-bridge.js +4 -1
- package/dist/lib/local-client-tokens.d.ts +0 -1
- package/dist/lib/local-client-tokens.js +125 -30
- package/dist/lib/logger.d.ts +0 -1
- package/dist/lib/logger.js +11 -1
- package/dist/lib/model-capability-matrix.d.ts +0 -1
- package/dist/lib/model-route-policy.d.ts +1 -2
- package/dist/lib/named-backup-export.d.ts +0 -1
- package/dist/lib/oauth-success.html +125 -125
- package/dist/lib/oc-chatgpt-import-adapter.d.ts +0 -1
- package/dist/lib/oc-chatgpt-orchestrator.d.ts +0 -1
- package/dist/lib/oc-chatgpt-target-detection.d.ts +0 -1
- package/dist/lib/parallel-probe.d.ts +0 -1
- package/dist/lib/policy/runtime-policy-cache.d.ts +80 -0
- package/dist/lib/policy/runtime-policy-cache.js +310 -0
- package/dist/lib/policy/runtime-policy.d.ts +1 -2
- package/dist/lib/policy/runtime-policy.js +46 -19
- package/dist/lib/preemptive-quota-scheduler.d.ts +0 -1
- package/dist/lib/proactive-refresh.d.ts +0 -1
- package/dist/lib/prompts/codex-host-bridge.d.ts +0 -1
- package/dist/lib/prompts/codex-host-bridge.js +138 -138
- package/dist/lib/prompts/codex.d.ts +0 -1
- package/dist/lib/prompts/codex.js +79 -79
- package/dist/lib/prompts/fetch-utils.d.ts +0 -1
- package/dist/lib/prompts/host-codex-prompt.d.ts +0 -1
- package/dist/lib/quota-cache.d.ts +7 -4
- package/dist/lib/quota-cache.d.ts.map +1 -1
- package/dist/lib/quota-cache.js +117 -61
- package/dist/lib/quota-probe.d.ts +0 -1
- package/dist/lib/quota-probe.js +5 -2
- package/dist/lib/quota-readiness.d.ts +7 -3
- package/dist/lib/quota-readiness.d.ts.map +1 -1
- package/dist/lib/quota-readiness.js +25 -4
- package/dist/lib/recovery/constants.d.ts +0 -1
- package/dist/lib/recovery/storage.d.ts +0 -1
- package/dist/lib/recovery/types.d.ts +0 -1
- package/dist/lib/recovery.d.ts +0 -1
- package/dist/lib/redaction.d.ts +0 -1
- package/dist/lib/refresh-guardian.d.ts +0 -1
- package/dist/lib/refresh-lease.d.ts +0 -1
- package/dist/lib/refresh-queue.d.ts +0 -1
- package/dist/lib/request/client-cancellation.d.ts +0 -1
- package/dist/lib/request/error-classification.d.ts +0 -1
- package/dist/lib/request/failover-config.d.ts +0 -1
- package/dist/lib/request/failure-policy.d.ts +0 -1
- package/dist/lib/request/fetch-helpers.d.ts +0 -1
- package/dist/lib/request/headers.d.ts +0 -1
- package/dist/lib/request/helpers/input-utils.d.ts +0 -1
- package/dist/lib/request/helpers/input-utils.js +88 -34
- package/dist/lib/request/helpers/model-map.d.ts +0 -1
- package/dist/lib/request/helpers/tool-utils.d.ts +0 -1
- package/dist/lib/request/helpers/tool-utils.js +421 -4
- package/dist/lib/request/index.d.ts +0 -1
- package/dist/lib/request/rate-limit-backoff.d.ts +0 -1
- package/dist/lib/request/rate-limit-decision.d.ts +0 -1
- package/dist/lib/request/request-attempt-budget.d.ts +0 -1
- package/dist/lib/request/request-init.d.ts +0 -1
- package/dist/lib/request/request-resilience.d.ts +0 -1
- package/dist/lib/request/request-transformer.d.ts +0 -1
- package/dist/lib/request/request-transformer.js +50 -25
- package/dist/lib/request/response-compaction.d.ts +0 -1
- package/dist/lib/request/response-handler.d.ts +0 -1
- package/dist/lib/request/response-metadata.d.ts +0 -1
- package/dist/lib/request/response-outcome.d.ts +0 -1
- package/dist/lib/request/stream-failover-runtime.d.ts +0 -1
- package/dist/lib/request/stream-failover.d.ts +0 -1
- package/dist/lib/request/stream-failover.js +28 -4
- package/dist/lib/request/token-refresh.d.ts +0 -1
- package/dist/lib/request/url-rewriting.d.ts +0 -1
- package/dist/lib/request/wait-utils.d.ts +0 -1
- package/dist/lib/rotation.d.ts +0 -1
- package/dist/lib/routing-mutex.d.ts +0 -1
- package/dist/lib/routing-profiles.d.ts +16 -2
- package/dist/lib/routing-profiles.js +119 -44
- package/dist/lib/runtime/account-check-helpers.d.ts +0 -1
- package/dist/lib/runtime/account-check-types.d.ts +0 -1
- package/dist/lib/runtime/account-check.d.ts +0 -1
- package/dist/lib/runtime/account-manager-cache-entry.d.ts +0 -1
- package/dist/lib/runtime/account-manager-cache.d.ts +0 -1
- package/dist/lib/runtime/account-model-catalog.d.ts +1 -2
- package/dist/lib/runtime/account-pool.d.ts +0 -1
- package/dist/lib/runtime/account-reset-credits.d.ts +0 -1
- package/dist/lib/runtime/account-reset-credits.js +8 -2
- package/dist/lib/runtime/account-scope.d.ts +0 -1
- package/dist/lib/runtime/account-select-event.d.ts +0 -1
- package/dist/lib/runtime/account-selection.d.ts +0 -1
- package/dist/lib/runtime/account-state.d.ts +0 -1
- package/dist/lib/runtime/account-status.d.ts +0 -1
- package/dist/lib/runtime/account-storage-scope-entry.d.ts +0 -1
- package/dist/lib/runtime/api-model-capabilities.d.ts +0 -1
- package/dist/lib/runtime/api-model-runtime.d.ts +0 -1
- package/dist/lib/runtime/app-bind.d.ts +0 -1
- package/dist/lib/runtime/app-bind.d.ts.map +1 -1
- package/dist/lib/runtime/app-bind.js +10 -2
- package/dist/lib/runtime/app-helper-selection.d.ts +0 -1
- package/dist/lib/runtime/auth-facade.d.ts +0 -1
- package/dist/lib/runtime/automatic-account-checks.d.ts +5 -2
- package/dist/lib/runtime/automatic-account-checks.d.ts.map +1 -1
- package/dist/lib/runtime/automatic-account-checks.js +29 -2
- package/dist/lib/runtime/automatic-subscription-checks.d.ts +1 -2
- package/dist/lib/runtime/automatic-subscription-checks.d.ts.map +1 -1
- package/dist/lib/runtime/automatic-subscription-checks.js +13 -16
- package/dist/lib/runtime/browser-oauth-flow.d.ts +0 -1
- package/dist/lib/runtime/capability-boost.d.ts +0 -1
- package/dist/lib/runtime/catalog-capabilities.d.ts +0 -1
- package/dist/lib/runtime/config-toml.d.ts +0 -1
- package/dist/lib/runtime/context-budget-settings.d.ts +0 -1
- package/dist/lib/runtime/event-handler.d.ts +0 -1
- package/dist/lib/runtime/first-run.d.ts +0 -1
- package/dist/lib/runtime/flagged-verify-types.d.ts +0 -1
- package/dist/lib/runtime/hydrate-emails.d.ts +0 -1
- package/dist/lib/runtime/inference-activity.d.ts +0 -1
- package/dist/lib/runtime/live-sync-entry.d.ts +0 -1
- package/dist/lib/runtime/live-sync.d.ts +0 -1
- package/dist/lib/runtime/loader-setup.d.ts +0 -1
- package/dist/lib/runtime/login-menu-accounts.d.ts +0 -1
- package/dist/lib/runtime/manual-oauth-flow.d.ts +0 -1
- package/dist/lib/runtime/model-discovery-status.d.ts +2 -3
- package/dist/lib/runtime/native-account-storage.d.ts +0 -1
- package/dist/lib/runtime/native-account-sync.d.ts +0 -1
- package/dist/lib/runtime/native-binding-lock.d.ts +0 -1
- package/dist/lib/runtime/native-client-auth.d.ts +0 -1
- package/dist/lib/runtime/native-provider-config.d.ts +0 -1
- package/dist/lib/runtime/native-rate-limits.d.ts +2 -1
- package/dist/lib/runtime/native-rate-limits.js +23 -6
- package/dist/lib/runtime/preemptive-quota.d.ts +0 -1
- package/dist/lib/runtime/quota-headers.d.ts +0 -1
- package/dist/lib/runtime/quota-probe.d.ts +0 -1
- package/dist/lib/runtime/quota-settings.d.ts +0 -1
- package/dist/lib/runtime/refresh-guardian-entry.d.ts +0 -1
- package/dist/lib/runtime/refresh-guardian.d.ts +0 -1
- package/dist/lib/runtime/request-init.d.ts +0 -1
- package/dist/lib/runtime/reset-credit-routing.d.ts +0 -1
- package/dist/lib/runtime/reset-credits.d.ts +0 -1
- package/dist/lib/runtime/response-output-history.d.ts +0 -1
- package/dist/lib/runtime/responses-websocket.d.ts +0 -1
- package/dist/lib/runtime/resume-picker.d.ts +0 -1
- package/dist/lib/runtime/rotation-account-selection.d.ts +0 -1
- package/dist/lib/runtime/rotation-proxy-state.d.ts +0 -1
- package/dist/lib/runtime/rotation-server-types.d.ts +0 -1
- package/dist/lib/runtime/rotation-storage-meta.d.ts +0 -1
- package/dist/lib/runtime/rotation-token-refresh.d.ts +0 -1
- package/dist/lib/runtime/runtime-capability-failures.d.ts +0 -1
- package/dist/lib/runtime/runtime-current-account.d.ts +0 -1
- package/dist/lib/runtime/runtime-observability.d.ts +0 -1
- package/dist/lib/runtime/runtime-services.d.ts +0 -1
- package/dist/lib/runtime/session-affinity-entry.d.ts +0 -1
- package/dist/lib/runtime/session-recovery.d.ts +0 -1
- package/dist/lib/runtime/status-marker.d.ts +0 -1
- package/dist/lib/runtime/storage-scope.d.ts +0 -1
- package/dist/lib/runtime/subscription-first-use.d.ts +0 -1
- package/dist/lib/runtime/subscription-quota-event.d.ts +0 -1
- package/dist/lib/runtime/subscription-quota-order.d.ts +0 -1
- package/dist/lib/runtime/toast.d.ts +0 -1
- package/dist/lib/runtime/ui-runtime-entry.d.ts +0 -1
- package/dist/lib/runtime/ui-runtime.d.ts +0 -1
- package/dist/lib/runtime/verify-flagged.d.ts +0 -1
- package/dist/lib/runtime/workspace-model-scopes.d.ts +0 -1
- package/dist/lib/runtime-constants.d.ts +0 -1
- package/dist/lib/runtime-paths.d.ts +0 -1
- package/dist/lib/runtime-rotation-proxy.d.ts +1 -1
- package/dist/lib/runtime-rotation-proxy.js +136 -3
- package/dist/lib/schemas.d.ts +35 -13
- package/dist/lib/schemas.js +19 -2
- package/dist/lib/session-affinity.d.ts +0 -1
- package/dist/lib/shutdown.d.ts +0 -1
- package/dist/lib/storage/account-clear-entry.d.ts +0 -1
- package/dist/lib/storage/account-clear.d.ts +0 -1
- package/dist/lib/storage/account-match-utils.d.ts +0 -1
- package/dist/lib/storage/account-persistence.d.ts +0 -1
- package/dist/lib/storage/account-port.d.ts +0 -1
- package/dist/lib/storage/account-save-entry.d.ts +0 -1
- package/dist/lib/storage/account-save.d.ts +9 -2
- package/dist/lib/storage/account-save.js +4 -1
- package/dist/lib/storage/account-snapshot.d.ts +0 -1
- package/dist/lib/storage/backup-metadata-builder.d.ts +0 -1
- package/dist/lib/storage/backup-metadata.d.ts +0 -1
- package/dist/lib/storage/backup-paths.d.ts +0 -1
- package/dist/lib/storage/backup-restore.d.ts +0 -1
- package/dist/lib/storage/cache-artifacts.d.ts +0 -1
- package/dist/lib/storage/credential-sidecars.d.ts +0 -1
- package/dist/lib/storage/error-hints.d.ts +0 -1
- package/dist/lib/storage/file-lock.d.ts +0 -1
- package/dist/lib/storage/file-lock.js +33 -1
- package/dist/lib/storage/file-paths.d.ts +0 -1
- package/dist/lib/storage/fixture-guards.d.ts +0 -1
- package/dist/lib/storage/flagged-entry.d.ts +0 -1
- package/dist/lib/storage/flagged-load-entry.d.ts +0 -1
- package/dist/lib/storage/flagged-save-entry.d.ts +0 -1
- package/dist/lib/storage/flagged-storage-file.d.ts +0 -1
- package/dist/lib/storage/flagged-storage-io.d.ts +0 -1
- package/dist/lib/storage/flagged-storage.d.ts +0 -1
- package/dist/lib/storage/gitignore.d.ts +0 -1
- package/dist/lib/storage/hash.d.ts +0 -1
- package/dist/lib/storage/health.d.ts +0 -1
- package/dist/lib/storage/identity.d.ts +0 -1
- package/dist/lib/storage/import-export.d.ts +0 -1
- package/dist/lib/storage/json-store-lock.d.ts +105 -0
- package/dist/lib/storage/json-store-lock.js +259 -0
- package/dist/lib/storage/metadata-section.d.ts +0 -1
- package/dist/lib/storage/migrations.d.ts +0 -1
- package/dist/lib/storage/migrations.js +31 -18
- package/dist/lib/storage/named-backup-entry.d.ts +0 -1
- package/dist/lib/storage/named-backups-entry.d.ts +0 -1
- package/dist/lib/storage/named-backups.d.ts +0 -1
- package/dist/lib/storage/path-state.d.ts +0 -1
- package/dist/lib/storage/paths.d.ts +0 -1
- package/dist/lib/storage/pending-auth.d.ts +10 -3
- package/dist/lib/storage/pending-auth.d.ts.map +1 -1
- package/dist/lib/storage/pending-auth.js +33 -9
- package/dist/lib/storage/project-migration.d.ts +0 -1
- package/dist/lib/storage/public-types.d.ts +0 -1
- package/dist/lib/storage/record-identity.d.ts +15 -0
- package/dist/lib/storage/record-identity.d.ts.map +1 -0
- package/dist/lib/storage/record-identity.js +16 -0
- package/dist/lib/storage/record-utils.d.ts +0 -1
- package/dist/lib/storage/restore-assessment.d.ts +0 -1
- package/dist/lib/storage/restore-backup-entry.d.ts +0 -1
- package/dist/lib/storage/restore-metadata.d.ts +0 -1
- package/dist/lib/storage/save-retry.d.ts +0 -1
- package/dist/lib/storage/snapshot-inspectors.d.ts +0 -1
- package/dist/lib/storage/snapshot-merge.d.ts +0 -1
- package/dist/lib/storage/storage-parser.d.ts +2 -1
- package/dist/lib/storage/storage-parser.js +10 -2
- package/dist/lib/storage/transactions.d.ts +0 -1
- package/dist/lib/storage.d.ts +15 -2
- package/dist/lib/storage.js +612 -25
- package/dist/lib/synthetic-response.d.ts +0 -1
- package/dist/lib/table-formatter.d.ts +0 -1
- package/dist/lib/temp-path.d.ts +0 -1
- package/dist/lib/tools/hashline-tools.d.ts +0 -1
- package/dist/lib/types.d.ts +0 -1
- package/dist/lib/ui/ansi.d.ts +0 -1
- package/dist/lib/ui/auth-menu-builder.d.ts +0 -1
- package/dist/lib/ui/auth-menu.d.ts +0 -1
- package/dist/lib/ui/check-progress.d.ts +0 -1
- package/dist/lib/ui/confirm.d.ts +0 -1
- package/dist/lib/ui/display-width.d.ts +0 -1
- package/dist/lib/ui/format.d.ts +0 -1
- package/dist/lib/ui/index.d.ts +0 -1
- package/dist/lib/ui/runtime.d.ts +0 -1
- package/dist/lib/ui/select.d.ts +0 -1
- package/dist/lib/ui/theme.d.ts +0 -1
- package/dist/lib/ui/ui-copy.d.ts +0 -1
- package/dist/lib/unified-settings.d.ts +13 -11
- package/dist/lib/unified-settings.js +22 -14
- package/dist/lib/update-notice.d.ts +0 -1
- package/dist/lib/usage/index.d.ts +0 -1
- package/dist/lib/usage/ledger.d.ts +0 -1
- package/dist/lib/usage/pricing.d.ts +0 -1
- package/dist/lib/usage/redaction.d.ts +0 -1
- package/dist/lib/usage/stream-usage-deferral.d.ts +0 -1
- package/dist/lib/usage/types.d.ts +0 -1
- package/dist/lib/usage/usage-extraction.d.ts +0 -1
- package/dist/lib/utils.d.ts +21 -1
- package/dist/lib/utils.js +31 -0
- package/dist/lib/wsl.d.ts +0 -1
- package/node_modules/@codex-ai/plugin/dist/index.d.ts +2 -2
- package/node_modules/@codex-ai/plugin/dist/index.js +2 -2
- package/node_modules/@codex-ai/plugin/dist/tool.d.ts +42 -42
- package/node_modules/@codex-ai/plugin/dist/tool.js +29 -29
- package/node_modules/@codex-ai/plugin/package.json +9 -9
- package/node_modules/@codex-ai/sdk/dist/index.d.ts +4 -4
- package/node_modules/@codex-ai/sdk/dist/index.js +2 -2
- package/node_modules/@codex-ai/sdk/package.json +8 -8
- package/package.json +206 -200
- package/scripts/codex-app-launcher.js +653 -653
- package/scripts/codex-app-router.js +373 -373
- package/scripts/codex-bin-resolver.js +332 -313
- package/scripts/codex-multi-auth.js +65 -59
- package/scripts/codex-routing.js +62 -62
- package/scripts/codex.js +6923 -6642
- package/scripts/install-codex-auth-utils.js +213 -213
- package/scripts/mcodex.js +367 -367
- package/scripts/postinstall.js +114 -114
- package/scripts/preuninstall.js +265 -265
- package/skills/codex-auth-setup/SKILL.md +73 -0
- package/vendor/codex-ai-plugin/dist/index.d.ts +2 -2
- package/vendor/codex-ai-plugin/dist/index.js +2 -2
- package/vendor/codex-ai-plugin/dist/tool.d.ts +42 -42
- package/vendor/codex-ai-plugin/dist/tool.js +29 -29
- package/vendor/codex-ai-plugin/package.json +9 -9
- package/vendor/codex-ai-sdk/dist/index.d.ts +4 -4
- package/vendor/codex-ai-sdk/dist/index.js +2 -2
- package/vendor/codex-ai-sdk/package.json +8 -8
|
@@ -1,213 +1,213 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
import { rename as fsRename } from "node:fs/promises";
|
|
4
|
-
import { homedir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import process from "node:process";
|
|
7
|
-
|
|
8
|
-
const PLUGIN_NAME = "codex-multi-auth";
|
|
9
|
-
const LEGACY_PLUGIN_NAME = "@ndycode/codex-multi-auth";
|
|
10
|
-
const PLUGIN_NAMES = [PLUGIN_NAME, LEGACY_PLUGIN_NAME];
|
|
11
|
-
|
|
12
|
-
const TRUE_VALUES = new Set(["1", "true", "yes"]);
|
|
13
|
-
const FALSE_VALUES = new Set(["0", "false", "no"]);
|
|
14
|
-
const CI_ENV_KEYS = [
|
|
15
|
-
"CI",
|
|
16
|
-
"GITHUB_ACTIONS",
|
|
17
|
-
"GITLAB_CI",
|
|
18
|
-
"CIRCLECI",
|
|
19
|
-
"BUILDKITE",
|
|
20
|
-
"TF_BUILD",
|
|
21
|
-
"TEAMCITY_VERSION",
|
|
22
|
-
"JENKINS_URL",
|
|
23
|
-
"TRAVIS",
|
|
24
|
-
"APPVEYOR",
|
|
25
|
-
"BITBUCKET_BUILD_NUMBER",
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
/** @param {string | undefined} value */
|
|
29
|
-
function readOptionalBooleanValue(value) {
|
|
30
|
-
if (value === undefined || value.trim().length === 0) return null;
|
|
31
|
-
const normalized = value.trim().toLowerCase();
|
|
32
|
-
if (TRUE_VALUES.has(normalized)) return true;
|
|
33
|
-
if (FALSE_VALUES.has(normalized)) return false;
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** @param {NodeJS.ProcessEnv} env @param {string} key */
|
|
38
|
-
function isEnabledEnvFlag(env, key) {
|
|
39
|
-
const value = env[key];
|
|
40
|
-
if (value === undefined || value.trim().length === 0) return false;
|
|
41
|
-
return readOptionalBooleanValue(value) !== false;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** @param {NodeJS.ProcessEnv} [env] */
|
|
45
|
-
export function isCiEnvironment(env = process.env) {
|
|
46
|
-
if (readOptionalBooleanValue(env.npm_config_ignore_scripts) === true) return true;
|
|
47
|
-
return CI_ENV_KEYS.some((key) => isEnabledEnvFlag(env, key));
|
|
48
|
-
}
|
|
49
|
-
export const FILE_RETRY_CODES = new Set([
|
|
50
|
-
"EBUSY",
|
|
51
|
-
"EPERM",
|
|
52
|
-
"EAGAIN",
|
|
53
|
-
"ENOTEMPTY",
|
|
54
|
-
"EACCES",
|
|
55
|
-
]);
|
|
56
|
-
export const FILE_RETRY_MAX_ATTEMPTS = 6;
|
|
57
|
-
export const FILE_RETRY_BASE_DELAY_MS = 25;
|
|
58
|
-
export const FILE_RETRY_JITTER_MS = 20;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @param {NodeJS.Platform} [platform]
|
|
62
|
-
* @param {NodeJS.ProcessEnv} [env]
|
|
63
|
-
* @param {string} [home]
|
|
64
|
-
*/
|
|
65
|
-
export function resolveInstallPaths(
|
|
66
|
-
platform = process.platform,
|
|
67
|
-
env = process.env,
|
|
68
|
-
home = homedir(),
|
|
69
|
-
) {
|
|
70
|
-
const isWindows = platform === "win32";
|
|
71
|
-
const appData = (env.APPDATA ?? "").trim();
|
|
72
|
-
const localAppData = (env.LOCALAPPDATA ?? appData).trim();
|
|
73
|
-
const configBase = isWindows
|
|
74
|
-
? appData || join(home, "AppData", "Roaming")
|
|
75
|
-
: join(home, ".config");
|
|
76
|
-
const cacheBase = isWindows
|
|
77
|
-
? localAppData || join(home, "AppData", "Local")
|
|
78
|
-
: join(home, ".cache");
|
|
79
|
-
const configDir = join(configBase, "Codex");
|
|
80
|
-
const configPath = join(configDir, "Codex.json");
|
|
81
|
-
const cacheDir = join(cacheBase, "Codex");
|
|
82
|
-
return {
|
|
83
|
-
configDir,
|
|
84
|
-
configPath,
|
|
85
|
-
cacheDir,
|
|
86
|
-
cacheNodeModules: join(cacheDir, "node_modules", PLUGIN_NAME),
|
|
87
|
-
cacheLegacyNodeModules: join(cacheDir, "node_modules", "@ndycode", "codex-multi-auth"),
|
|
88
|
-
cacheBunLock: join(cacheDir, "bun.lock"),
|
|
89
|
-
cachePackageJson: join(cacheDir, "package.json"),
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** @param {unknown} list */
|
|
94
|
-
export function removePluginFromList(list) {
|
|
95
|
-
const entries = Array.isArray(list) ? list.filter(Boolean) : [];
|
|
96
|
-
return entries.filter((entry) => {
|
|
97
|
-
if (typeof entry !== "string") return true;
|
|
98
|
-
return !PLUGIN_NAMES.some(
|
|
99
|
-
(pluginName) => entry === pluginName || entry.startsWith(`${pluginName}@`),
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** @param {unknown} list */
|
|
105
|
-
export function normalizePluginList(list) {
|
|
106
|
-
const entries = Array.isArray(list) ? list.filter(Boolean) : [];
|
|
107
|
-
const filtered = entries.filter((entry) => {
|
|
108
|
-
if (typeof entry !== "string") return true;
|
|
109
|
-
return !PLUGIN_NAMES.some(
|
|
110
|
-
(pluginName) => entry === pluginName || entry.startsWith(`${pluginName}@`),
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
const deduped = [];
|
|
114
|
-
const seen = new Set();
|
|
115
|
-
for (const entry of filtered) {
|
|
116
|
-
const key =
|
|
117
|
-
typeof entry === "string" ? `s:${entry}` : `j:${JSON.stringify(entry)}`;
|
|
118
|
-
if (seen.has(key)) continue;
|
|
119
|
-
seen.add(key);
|
|
120
|
-
deduped.push(entry);
|
|
121
|
-
}
|
|
122
|
-
return [...deduped, PLUGIN_NAME];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** @param {number} ms */
|
|
126
|
-
function sleep(ms) {
|
|
127
|
-
// Keep this helper local so installer scripts remain standalone and do not depend on lib/.
|
|
128
|
-
return new Promise((resolve) => {
|
|
129
|
-
setTimeout(resolve, ms);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** @param {unknown} error */
|
|
134
|
-
function shouldRetryFileOperation(error) {
|
|
135
|
-
const fileError = /** @type {NodeJS.ErrnoException | undefined} */ (error);
|
|
136
|
-
return (
|
|
137
|
-
fileError instanceof Error &&
|
|
138
|
-
typeof fileError.code === "string" &&
|
|
139
|
-
FILE_RETRY_CODES.has(fileError.code)
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/** @template T @param {() => Promise<T>} operation */
|
|
144
|
-
export async function withFileOperationRetry(operation) {
|
|
145
|
-
for (let attempt = 1; ; attempt += 1) {
|
|
146
|
-
try {
|
|
147
|
-
return await operation();
|
|
148
|
-
} catch (error) {
|
|
149
|
-
if (
|
|
150
|
-
!shouldRetryFileOperation(error) ||
|
|
151
|
-
attempt >= FILE_RETRY_MAX_ATTEMPTS
|
|
152
|
-
) {
|
|
153
|
-
throw error;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const jitter = Math.floor(Math.random() * FILE_RETRY_JITTER_MS);
|
|
157
|
-
const delayMs = FILE_RETRY_BASE_DELAY_MS * 2 ** (attempt - 1) + jitter;
|
|
158
|
-
await sleep(delayMs);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* @param {string} sourcePath
|
|
165
|
-
* @param {string} targetPath
|
|
166
|
-
* @param {{
|
|
167
|
-
* rename?: (sourcePath: string, targetPath: string) => Promise<void>,
|
|
168
|
-
* log?: (message: string) => void,
|
|
169
|
-
* maxRetries?: number,
|
|
170
|
-
* baseDelayMs?: number,
|
|
171
|
-
* jitterMs?: number,
|
|
172
|
-
* random?: () => number,
|
|
173
|
-
* sleep?: (ms: number) => Promise<void>,
|
|
174
|
-
* }} [options]
|
|
175
|
-
*/
|
|
176
|
-
export async function renameWithRetry(sourcePath, targetPath, options = {}) {
|
|
177
|
-
const {
|
|
178
|
-
rename = fsRename,
|
|
179
|
-
log = () => {},
|
|
180
|
-
maxRetries = FILE_RETRY_MAX_ATTEMPTS,
|
|
181
|
-
baseDelayMs = FILE_RETRY_BASE_DELAY_MS,
|
|
182
|
-
jitterMs = FILE_RETRY_JITTER_MS,
|
|
183
|
-
random = Math.random,
|
|
184
|
-
sleep: sleepImpl = sleep,
|
|
185
|
-
} = options;
|
|
186
|
-
|
|
187
|
-
if (!Number.isInteger(maxRetries) || maxRetries < 1) {
|
|
188
|
-
throw new RangeError("maxRetries must be an integer >= 1");
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
for (let attempt = 0; attempt < maxRetries; attempt += 1) {
|
|
192
|
-
try {
|
|
193
|
-
await rename(sourcePath, targetPath);
|
|
194
|
-
return;
|
|
195
|
-
} catch (error) {
|
|
196
|
-
const code =
|
|
197
|
-
error && typeof error === "object" && "code" in error
|
|
198
|
-
? error.code
|
|
199
|
-
: undefined;
|
|
200
|
-
const isRetryable =
|
|
201
|
-
typeof code === "string" && FILE_RETRY_CODES.has(code);
|
|
202
|
-
if (!isRetryable || attempt === maxRetries - 1) {
|
|
203
|
-
throw error;
|
|
204
|
-
}
|
|
205
|
-
const delayMs =
|
|
206
|
-
baseDelayMs * 2 ** attempt + Math.floor(random() * jitterMs);
|
|
207
|
-
log(
|
|
208
|
-
`Retrying atomic rename (${attempt + 1}/${maxRetries}) code=${code ?? "unknown"} source=${sourcePath} target=${targetPath} delayMs=${delayMs}`,
|
|
209
|
-
);
|
|
210
|
-
await sleepImpl(delayMs);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { rename as fsRename } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
|
|
8
|
+
const PLUGIN_NAME = "codex-multi-auth";
|
|
9
|
+
const LEGACY_PLUGIN_NAME = "@ndycode/codex-multi-auth";
|
|
10
|
+
const PLUGIN_NAMES = [PLUGIN_NAME, LEGACY_PLUGIN_NAME];
|
|
11
|
+
|
|
12
|
+
const TRUE_VALUES = new Set(["1", "true", "yes"]);
|
|
13
|
+
const FALSE_VALUES = new Set(["0", "false", "no"]);
|
|
14
|
+
const CI_ENV_KEYS = [
|
|
15
|
+
"CI",
|
|
16
|
+
"GITHUB_ACTIONS",
|
|
17
|
+
"GITLAB_CI",
|
|
18
|
+
"CIRCLECI",
|
|
19
|
+
"BUILDKITE",
|
|
20
|
+
"TF_BUILD",
|
|
21
|
+
"TEAMCITY_VERSION",
|
|
22
|
+
"JENKINS_URL",
|
|
23
|
+
"TRAVIS",
|
|
24
|
+
"APPVEYOR",
|
|
25
|
+
"BITBUCKET_BUILD_NUMBER",
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/** @param {string | undefined} value */
|
|
29
|
+
function readOptionalBooleanValue(value) {
|
|
30
|
+
if (value === undefined || value.trim().length === 0) return null;
|
|
31
|
+
const normalized = value.trim().toLowerCase();
|
|
32
|
+
if (TRUE_VALUES.has(normalized)) return true;
|
|
33
|
+
if (FALSE_VALUES.has(normalized)) return false;
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @param {NodeJS.ProcessEnv} env @param {string} key */
|
|
38
|
+
function isEnabledEnvFlag(env, key) {
|
|
39
|
+
const value = env[key];
|
|
40
|
+
if (value === undefined || value.trim().length === 0) return false;
|
|
41
|
+
return readOptionalBooleanValue(value) !== false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @param {NodeJS.ProcessEnv} [env] */
|
|
45
|
+
export function isCiEnvironment(env = process.env) {
|
|
46
|
+
if (readOptionalBooleanValue(env.npm_config_ignore_scripts) === true) return true;
|
|
47
|
+
return CI_ENV_KEYS.some((key) => isEnabledEnvFlag(env, key));
|
|
48
|
+
}
|
|
49
|
+
export const FILE_RETRY_CODES = new Set([
|
|
50
|
+
"EBUSY",
|
|
51
|
+
"EPERM",
|
|
52
|
+
"EAGAIN",
|
|
53
|
+
"ENOTEMPTY",
|
|
54
|
+
"EACCES",
|
|
55
|
+
]);
|
|
56
|
+
export const FILE_RETRY_MAX_ATTEMPTS = 6;
|
|
57
|
+
export const FILE_RETRY_BASE_DELAY_MS = 25;
|
|
58
|
+
export const FILE_RETRY_JITTER_MS = 20;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {NodeJS.Platform} [platform]
|
|
62
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
63
|
+
* @param {string} [home]
|
|
64
|
+
*/
|
|
65
|
+
export function resolveInstallPaths(
|
|
66
|
+
platform = process.platform,
|
|
67
|
+
env = process.env,
|
|
68
|
+
home = homedir(),
|
|
69
|
+
) {
|
|
70
|
+
const isWindows = platform === "win32";
|
|
71
|
+
const appData = (env.APPDATA ?? "").trim();
|
|
72
|
+
const localAppData = (env.LOCALAPPDATA ?? appData).trim();
|
|
73
|
+
const configBase = isWindows
|
|
74
|
+
? appData || join(home, "AppData", "Roaming")
|
|
75
|
+
: join(home, ".config");
|
|
76
|
+
const cacheBase = isWindows
|
|
77
|
+
? localAppData || join(home, "AppData", "Local")
|
|
78
|
+
: join(home, ".cache");
|
|
79
|
+
const configDir = join(configBase, "Codex");
|
|
80
|
+
const configPath = join(configDir, "Codex.json");
|
|
81
|
+
const cacheDir = join(cacheBase, "Codex");
|
|
82
|
+
return {
|
|
83
|
+
configDir,
|
|
84
|
+
configPath,
|
|
85
|
+
cacheDir,
|
|
86
|
+
cacheNodeModules: join(cacheDir, "node_modules", PLUGIN_NAME),
|
|
87
|
+
cacheLegacyNodeModules: join(cacheDir, "node_modules", "@ndycode", "codex-multi-auth"),
|
|
88
|
+
cacheBunLock: join(cacheDir, "bun.lock"),
|
|
89
|
+
cachePackageJson: join(cacheDir, "package.json"),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** @param {unknown} list */
|
|
94
|
+
export function removePluginFromList(list) {
|
|
95
|
+
const entries = Array.isArray(list) ? list.filter(Boolean) : [];
|
|
96
|
+
return entries.filter((entry) => {
|
|
97
|
+
if (typeof entry !== "string") return true;
|
|
98
|
+
return !PLUGIN_NAMES.some(
|
|
99
|
+
(pluginName) => entry === pluginName || entry.startsWith(`${pluginName}@`),
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** @param {unknown} list */
|
|
105
|
+
export function normalizePluginList(list) {
|
|
106
|
+
const entries = Array.isArray(list) ? list.filter(Boolean) : [];
|
|
107
|
+
const filtered = entries.filter((entry) => {
|
|
108
|
+
if (typeof entry !== "string") return true;
|
|
109
|
+
return !PLUGIN_NAMES.some(
|
|
110
|
+
(pluginName) => entry === pluginName || entry.startsWith(`${pluginName}@`),
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
const deduped = [];
|
|
114
|
+
const seen = new Set();
|
|
115
|
+
for (const entry of filtered) {
|
|
116
|
+
const key =
|
|
117
|
+
typeof entry === "string" ? `s:${entry}` : `j:${JSON.stringify(entry)}`;
|
|
118
|
+
if (seen.has(key)) continue;
|
|
119
|
+
seen.add(key);
|
|
120
|
+
deduped.push(entry);
|
|
121
|
+
}
|
|
122
|
+
return [...deduped, PLUGIN_NAME];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** @param {number} ms */
|
|
126
|
+
function sleep(ms) {
|
|
127
|
+
// Keep this helper local so installer scripts remain standalone and do not depend on lib/.
|
|
128
|
+
return new Promise((resolve) => {
|
|
129
|
+
setTimeout(resolve, ms);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** @param {unknown} error */
|
|
134
|
+
function shouldRetryFileOperation(error) {
|
|
135
|
+
const fileError = /** @type {NodeJS.ErrnoException | undefined} */ (error);
|
|
136
|
+
return (
|
|
137
|
+
fileError instanceof Error &&
|
|
138
|
+
typeof fileError.code === "string" &&
|
|
139
|
+
FILE_RETRY_CODES.has(fileError.code)
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** @template T @param {() => Promise<T>} operation */
|
|
144
|
+
export async function withFileOperationRetry(operation) {
|
|
145
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
146
|
+
try {
|
|
147
|
+
return await operation();
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (
|
|
150
|
+
!shouldRetryFileOperation(error) ||
|
|
151
|
+
attempt >= FILE_RETRY_MAX_ATTEMPTS
|
|
152
|
+
) {
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const jitter = Math.floor(Math.random() * FILE_RETRY_JITTER_MS);
|
|
157
|
+
const delayMs = FILE_RETRY_BASE_DELAY_MS * 2 ** (attempt - 1) + jitter;
|
|
158
|
+
await sleep(delayMs);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @param {string} sourcePath
|
|
165
|
+
* @param {string} targetPath
|
|
166
|
+
* @param {{
|
|
167
|
+
* rename?: (sourcePath: string, targetPath: string) => Promise<void>,
|
|
168
|
+
* log?: (message: string) => void,
|
|
169
|
+
* maxRetries?: number,
|
|
170
|
+
* baseDelayMs?: number,
|
|
171
|
+
* jitterMs?: number,
|
|
172
|
+
* random?: () => number,
|
|
173
|
+
* sleep?: (ms: number) => Promise<void>,
|
|
174
|
+
* }} [options]
|
|
175
|
+
*/
|
|
176
|
+
export async function renameWithRetry(sourcePath, targetPath, options = {}) {
|
|
177
|
+
const {
|
|
178
|
+
rename = fsRename,
|
|
179
|
+
log = () => {},
|
|
180
|
+
maxRetries = FILE_RETRY_MAX_ATTEMPTS,
|
|
181
|
+
baseDelayMs = FILE_RETRY_BASE_DELAY_MS,
|
|
182
|
+
jitterMs = FILE_RETRY_JITTER_MS,
|
|
183
|
+
random = Math.random,
|
|
184
|
+
sleep: sleepImpl = sleep,
|
|
185
|
+
} = options;
|
|
186
|
+
|
|
187
|
+
if (!Number.isInteger(maxRetries) || maxRetries < 1) {
|
|
188
|
+
throw new RangeError("maxRetries must be an integer >= 1");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
for (let attempt = 0; attempt < maxRetries; attempt += 1) {
|
|
192
|
+
try {
|
|
193
|
+
await rename(sourcePath, targetPath);
|
|
194
|
+
return;
|
|
195
|
+
} catch (error) {
|
|
196
|
+
const code =
|
|
197
|
+
error && typeof error === "object" && "code" in error
|
|
198
|
+
? error.code
|
|
199
|
+
: undefined;
|
|
200
|
+
const isRetryable =
|
|
201
|
+
typeof code === "string" && FILE_RETRY_CODES.has(code);
|
|
202
|
+
if (!isRetryable || attempt === maxRetries - 1) {
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
const delayMs =
|
|
206
|
+
baseDelayMs * 2 ** attempt + Math.floor(random() * jitterMs);
|
|
207
|
+
log(
|
|
208
|
+
`Retrying atomic rename (${attempt + 1}/${maxRetries}) code=${code ?? "unknown"} source=${sourcePath} target=${targetPath} delayMs=${delayMs}`,
|
|
209
|
+
);
|
|
210
|
+
await sleepImpl(delayMs);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|