@bitkyc08/opencodex 2.100.2 → 2.100.4
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/AGENTS_INSTALL.md +23 -1
- package/README.md +1 -1
- package/bin/ocx.mjs +40 -19
- package/gui/dist/assets/{App-COo8Yopd.css → App-BGP8I0V4.css} +1 -1
- package/gui/dist/assets/App-DcpyI78f.js +60 -0
- package/gui/dist/assets/{Tray-BcaI-VCr.js → Tray-CzjPJprT.js} +1 -1
- package/gui/dist/assets/brand-mark-BTIi7e69.js +1 -0
- package/gui/dist/assets/index-DJxM-imn.css +2 -0
- package/gui/dist/assets/index-DVgU6S3y.js +138 -0
- package/gui/dist/assets/{segment-thumb-features-e9A_FogJ.js → segment-thumb-features-Bn6Y-g3R.js} +1 -1
- package/gui/dist/classic/assets/App-eYJAyNHM.js +59 -0
- package/gui/dist/classic/assets/{Tray-DT146AhS.js → Tray-xHMYxLkV.js} +1 -1
- package/gui/dist/classic/assets/index-DSaVRW4F.js +138 -0
- package/gui/dist/classic/assets/quota-summary-DyzHlkFl.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/native/ocx-child/Cargo.toml +9 -0
- package/native/ocx-child/src/cli.rs +404 -20
- package/native/ocx-child/src/codex_home.rs +99 -14
- package/native/ocx-child/src/daemon.rs +2 -1
- package/native/ocx-child/src/lib.rs +3 -0
- package/native/ocx-child/src/link_ws.rs +2598 -0
- package/native/ocx-child/src/link_ws_advert.rs +346 -0
- package/native/ocx-child/src/link_ws_frame.rs +749 -0
- package/native/ocx-child/src/parity.rs +5 -1
- package/native/ocx-child/src/platform.rs +152 -6
- package/native/ocx-child/src/relay.rs +150 -19
- package/package.json +3 -3
- package/src/adapters/anthropic/advisor-tool.ts +176 -0
- package/src/adapters/anthropic/beta-body-pairs.ts +6 -0
- package/src/adapters/anthropic/client-identity.ts +3 -1
- package/src/adapters/anthropic/passthrough.ts +9 -3
- package/src/adapters/anthropic/per-message-effort.ts +296 -0
- package/src/adapters/anthropic.ts +34 -14
- package/src/adapters/claude-cli/adapter.ts +1 -0
- package/src/adapters/client-fingerprint.ts +3 -3
- package/src/adapters/cursor/discovery.ts +17 -0
- package/src/adapters/cursor/native-exec-desktop.ts +2 -1
- package/src/adapters/cursor/native-exec-shell.ts +2 -1
- package/src/adapters/cursor/protobuf-request.ts +8 -8
- package/src/adapters/cursor.ts +7 -6
- package/src/adapters/devin/cloud-direct/chat.ts +71 -14
- package/src/adapters/google-antigravity-wire.ts +7 -5
- package/src/adapters/google-errors.ts +14 -2
- package/src/adapters/google-wire-compiler.ts +2 -2
- package/src/adapters/google.ts +9 -2
- package/src/adapters/kiro/payload.ts +7 -4
- package/src/adapters/kiro/reasoning.ts +44 -1
- package/src/adapters/kiro/structured-output.ts +10 -8
- package/src/adapters/kiro-tools.ts +61 -15
- package/src/adapters/openai-chat/destination-policy.ts +16 -0
- package/src/adapters/openai-chat/reasoning-replay.ts +4 -1
- package/src/adapters/qoder/adapter.ts +9 -1
- package/src/adapters/zed.ts +7 -2
- package/src/advisor/consult.ts +15 -4
- package/src/advisor/context.ts +12 -3
- package/src/advisor/runtime.ts +35 -5
- package/src/advisor/settings.ts +8 -0
- package/src/advisor/synthetic-tool.ts +21 -8
- package/src/bridge/response-json.ts +11 -2
- package/src/bridge/sse.ts +43 -8
- package/src/claude/auth-detect.ts +21 -33
- package/src/claude/desktop-3p.ts +11 -5
- package/src/claude/desktop-gateway-state.ts +2 -0
- package/src/claude/desktop-remote-store-artifact.ts +14 -3
- package/src/claude/desktop-remote-store.ts +82 -12
- package/src/claude/inbound-content-options.ts +31 -16
- package/src/claude/outbound.ts +13 -3
- package/src/cli/account-api.ts +21 -1
- package/src/cli/account-auth.ts +83 -22
- package/src/cli/account-extended.ts +33 -2
- package/src/cli/account-key-quota.ts +34 -5
- package/src/cli/account.ts +4 -2
- package/src/cli/advisor.ts +7 -4
- package/src/cli/alias.ts +38 -1
- package/src/cli/capabilities-access-remote.ts +128 -3
- package/src/cli/capabilities-accounts.ts +6 -6
- package/src/cli/capabilities-agents-routing.ts +17 -10
- package/src/cli/capabilities-base.ts +49 -19
- package/src/cli/capabilities-integrations.ts +2 -2
- package/src/cli/capabilities-observe-system.ts +2 -2
- package/src/cli/capabilities-provider-models.ts +18 -2
- package/src/cli/capabilities-route-to.ts +43 -0
- package/src/cli/capabilities.ts +2 -0
- package/src/cli/capability-contracts.ts +1 -1
- package/src/cli/claude-desktop.ts +30 -11
- package/src/cli/claude.ts +17 -3
- package/src/cli/codex-launcher.ts +3 -1
- package/src/cli/codex-shim-autorestore.ts +5 -42
- package/src/cli/config-command.ts +14 -1
- package/src/cli/config-root-startup.ts +34 -0
- package/src/cli/connect.ts +88 -16
- package/src/cli/desktop-runtime-guidance.ts +1 -1
- package/src/cli/disconnect-runtime.ts +178 -0
- package/src/cli/dispatch.ts +61 -13
- package/src/cli/export-command.ts +1 -1
- package/src/cli/gui-pair-client.ts +6 -3
- package/src/cli/gui.ts +10 -5
- package/src/cli/help-catalog.ts +11 -0
- package/src/cli/help.ts +4 -3
- package/src/cli/index.ts +85 -94
- package/src/cli/inspect.ts +11 -2
- package/src/cli/integrations.ts +26 -1
- package/src/cli/link-apply-restart.ts +4 -2
- package/src/cli/link-capture.ts +64 -0
- package/src/cli/link-child-ops.ts +218 -40
- package/src/cli/link-cleanup.ts +8 -5
- package/src/cli/link-diagnostics.ts +67 -0
- package/src/cli/link-enrollment.ts +158 -12
- package/src/cli/link-operations.ts +52 -0
- package/src/cli/link-recover.ts +152 -0
- package/src/cli/link-routes.ts +90 -0
- package/src/cli/link-status-child.ts +44 -1
- package/src/cli/link-status-traffic.ts +34 -0
- package/src/cli/link.ts +315 -37
- package/src/cli/message-command.ts +1 -1
- package/src/cli/message-mcp-command.ts +23 -10
- package/src/cli/models-runtime.ts +3 -3
- package/src/cli/opencode.ts +3 -1
- package/src/cli/pi-sync.ts +35 -0
- package/src/cli/preflight-exemptions.ts +49 -0
- package/src/cli/registry.ts +33 -14
- package/src/cli/resolve.ts +23 -8
- package/src/cli/restart-failure.ts +15 -2
- package/src/cli/root.ts +5 -1
- package/src/cli/route-to.ts +172 -0
- package/src/cli/runtime-api.ts +9 -8
- package/src/cli/status.ts +7 -2
- package/src/cli/stop-approval.ts +66 -19
- package/src/cli/stop-report.ts +23 -0
- package/src/cli/stop-windows-checked.ts +304 -0
- package/src/cli/sync-command.ts +70 -15
- package/src/cli/sync-fanout.ts +74 -19
- package/src/cli/sync-flags.ts +40 -3
- package/src/cli/sync-link-status.ts +18 -2
- package/src/cli/sync-update-guard.ts +7 -2
- package/src/cli/system-command.ts +1 -1
- package/src/cli/system-restart-client.ts +10 -3
- package/src/cli/system-settings-parity.ts +2 -1
- package/src/cli/uninstall-plan.ts +77 -5
- package/src/cli/uninstall-stop.ts +152 -0
- package/src/cli/v2-input.ts +10 -6
- package/src/cli/v2-local-output.ts +3 -2
- package/src/cli/v2-runtime.ts +10 -3
- package/src/cli/v2.ts +22 -7
- package/src/client/connect.ts +376 -35
- package/src/client/desktop-refusal.ts +38 -0
- package/src/client/lifecycle-lock.ts +29 -4
- package/src/client/link-home-features.ts +27 -0
- package/src/client/link-home.ts +92 -4
- package/src/client/link-ingress.ts +21 -3
- package/src/client/link-join.ts +12 -2
- package/src/client/link-parity-reporter.ts +60 -6
- package/src/client/link-relay-transport.ts +161 -36
- package/src/client/link-relay.ts +150 -6
- package/src/client/link-request-compression.ts +84 -0
- package/src/client/link-state.ts +11 -5
- package/src/client/link-status.ts +39 -1
- package/src/client/link-teardown.ts +1 -0
- package/src/client/link-tunnel.ts +56 -5
- package/src/client/link-websocket-limits.ts +89 -0
- package/src/client/link-websocket.ts +586 -0
- package/src/client/link-ws-advertisement.ts +100 -0
- package/src/client/link-ws-framer.ts +241 -0
- package/src/client/link-ws-transport.ts +177 -0
- package/src/client/machine-api.ts +13 -2
- package/src/client/machine-listener.ts +48 -7
- package/src/client/route-intent-apply.ts +293 -0
- package/src/client/route-intent-file-originals.ts +97 -0
- package/src/client/route-intent-native-originals.ts +201 -0
- package/src/client/route-intent-watch.ts +141 -0
- package/src/client/runtime-restart.ts +141 -7
- package/src/client/runtime.ts +63 -15
- package/src/client/state.ts +44 -0
- package/src/client/sync-expectation.ts +36 -2
- package/src/client/sync-runtime.ts +7 -0
- package/src/clients/config-export/alias-selectors.ts +63 -40
- package/src/clients/config-export/contracts.ts +2 -0
- package/src/clients/config-export/nested-selectors.ts +42 -0
- package/src/clients/config-export.ts +22 -3
- package/src/codex/account-pause.ts +4 -0
- package/src/codex/account-runtime-state.ts +4 -0
- package/src/codex/account-store.ts +12 -3
- package/src/codex/account-usability.ts +13 -0
- package/src/codex/auth-api/account-list.ts +29 -3
- package/src/codex/auth-api/main-account-probe.ts +3 -1
- package/src/codex/auth-api/main-hard-lock-refusal-read.ts +172 -0
- package/src/codex/auth-collision.ts +23 -22
- package/src/codex/auth-context.ts +61 -8
- package/src/codex/catalog/build-entries.ts +10 -0
- package/src/codex/catalog/derive-entry.ts +7 -0
- package/src/codex/catalog/gather-capture.ts +8 -2
- package/src/codex/catalog/parsing.ts +7 -3
- package/src/codex/catalog/provider-models.ts +54 -15
- package/src/codex/catalog/reserve-warn.ts +7 -5
- package/src/codex/catalog/reserve.ts +4 -3
- package/src/codex/catalog/retained-sync.ts +4 -1
- package/src/codex/catalog/routed-defaults.ts +35 -0
- package/src/codex/catalog/routed-gather.ts +1 -1
- package/src/codex/catalog-auto-refresh.ts +11 -0
- package/src/codex/cli-update-job.ts +35 -13
- package/src/codex/convergence.ts +4 -2
- package/src/codex/desktop-compatibility/native-identity.ts +4 -8
- package/src/codex/features.ts +2 -2
- package/src/codex/history-provider.ts +31 -0
- package/src/codex/inject/multi-agent-v2.ts +9 -3
- package/src/codex/inject/paginated-openai-compat.ts +54 -1
- package/src/codex/inject/plan.ts +20 -2
- package/src/codex/inject.ts +2 -0
- package/src/codex/journal-config-restore.ts +217 -0
- package/src/codex/journal.ts +75 -6
- package/src/codex/loopback-target.ts +22 -8
- package/src/codex/main-account.ts +109 -57
- package/src/codex/native-main-auth-file.ts +118 -0
- package/src/codex/native-main-credentials.ts +270 -0
- package/src/codex/native-main-owner.ts +3 -0
- package/src/codex/native-main-refresh-mode.ts +14 -1
- package/src/codex/native-profile-manager.ts +4 -3
- package/src/codex/native-profile-store.ts +3 -61
- package/src/codex/orca-import.ts +10 -1
- package/src/codex/quota-history.ts +13 -0
- package/src/codex/quota-window-conflict.ts +103 -0
- package/src/codex/quota.ts +86 -15
- package/src/codex/subagent-model-fallback.ts +3 -1
- package/src/codex/websocket-activity.ts +171 -16
- package/src/codex/websocket-registry.ts +11 -4
- package/src/combos/cooldown-store.ts +25 -5
- package/src/combos/failover.ts +342 -3
- package/src/combos/index.ts +5 -0
- package/src/combos/resolve.ts +115 -19
- package/src/config/dashboard-trusted-proxy.ts +83 -0
- package/src/config/diagnostics.ts +31 -0
- package/src/config/feature-flags.ts +9 -0
- package/src/config/live-reconcile.ts +16 -4
- package/src/config/load-degrade.ts +14 -1
- package/src/config/multi-agent-surface.ts +28 -5
- package/src/config/pending-teardown.ts +60 -3
- package/src/config/persisted-mutation.ts +2 -2
- package/src/config/persisted-projections.ts +18 -0
- package/src/config/process-state.ts +176 -4
- package/src/config/provider-validation.ts +4 -4
- package/src/config/reserve-capability.ts +96 -0
- package/src/config/schema/config-schema.ts +12 -0
- package/src/config/schema/leaf-validators.ts +11 -2
- package/src/config/schema/routed-catalog-defaults.ts +49 -0
- package/src/config/windows-process-command-line.ts +107 -0
- package/src/config.ts +7 -7
- package/src/desktop-update/acquire.ts +202 -0
- package/src/desktop-update/cli.ts +168 -0
- package/src/desktop-update/drain.ts +40 -0
- package/src/desktop-update/headless.ts +285 -0
- package/src/desktop-update/image.ts +85 -0
- package/src/desktop-update/install.ts +53 -0
- package/src/desktop-update/msi.ts +72 -0
- package/src/desktop-update/release.ts +128 -0
- package/src/desktop-update/runtime.ts +155 -0
- package/src/desktop-update/staging.ts +118 -0
- package/src/desktop-update/trust.ts +45 -0
- package/src/generated/compatibility-version.json +1114 -442
- package/src/generated/model-metadata.ts +1 -1
- package/src/images/fulfill-video.ts +3 -3
- package/src/images/loop.ts +9 -2
- package/src/images/plan.ts +147 -11
- package/src/images/types.ts +13 -4
- package/src/images/xai-video-client.ts +72 -10
- package/src/integrations/model-name-guard.ts +25 -0
- package/src/integrations/route-intent-catalog.ts +26 -0
- package/src/integrations/route-intent-connected.ts +262 -0
- package/src/integrations/route-intent-contract.ts +55 -0
- package/src/integrations/route-intent-disconnect.ts +109 -0
- package/src/integrations/route-intent-initial.ts +64 -0
- package/src/integrations/route-intent-state.ts +117 -0
- package/src/integrations/route-intent-tick.ts +65 -0
- package/src/integrations/route-intent.ts +212 -0
- package/src/integrations/writer.ts +44 -11
- package/src/lib/client-retry-after.ts +29 -0
- package/src/lib/config-ownership.ts +13 -0
- package/src/lib/desktop-gui-origin.ts +28 -0
- package/src/lib/errors.ts +1 -1
- package/src/lib/gcp-adc.ts +48 -4
- package/src/lib/gui-pair-capability.ts +2 -1
- package/src/lib/messages-error-body.ts +4 -1
- package/src/lib/offline-resend.ts +150 -0
- package/src/lib/outbound-credential-registry.ts +362 -4
- package/src/lib/paced-stream.ts +34 -0
- package/src/lib/passive-key-fetch-proof.ts +30 -0
- package/src/lib/passive-read.ts +5 -0
- package/src/lib/process-control.ts +76 -12
- package/src/lib/provider-outbound.ts +17 -6
- package/src/lib/redact.ts +84 -8
- package/src/lib/request-failure-model.ts +2 -0
- package/src/lib/response-body-inactivity.ts +23 -1
- package/src/lib/state-store-registrations.ts +11 -0
- package/src/lib/state-store-sweeper.ts +4 -0
- package/src/lib/supervisor-markers.ts +18 -0
- package/src/lib/terminal-safe-text.ts +58 -0
- package/src/lib/translator-budget.ts +3 -2
- package/src/lib/upstream-retry.ts +52 -9
- package/src/link/alias-lock.ts +119 -0
- package/src/link/child-activity.ts +28 -2
- package/src/link/child-binary-cache-fill.d.mts +50 -0
- package/src/link/child-binary-cache-fill.mjs +494 -0
- package/src/link/child-binary-cache-start.ts +73 -0
- package/src/link/child-binary-source.ts +12 -5
- package/src/link/child-gated-ocx.ts +29 -11
- package/src/link/child-observations.ts +2 -1
- package/src/link/child-observe.ts +2 -2
- package/src/link/child-ops-engine.ts +159 -91
- package/src/link/child-ops-host.ts +138 -0
- package/src/link/child-ops-runners.ts +319 -0
- package/src/link/child-ops-scheduler.ts +207 -0
- package/src/link/child-ops-types.ts +89 -0
- package/src/link/child-parity.ts +23 -4
- package/src/link/child-policy.ts +93 -0
- package/src/link/child-update-contract.ts +12 -3
- package/src/link/codex-settings.ts +1 -1
- package/src/link/compatibility.ts +18 -1
- package/src/link/diagnostics-read.ts +163 -0
- package/src/link/diagnostics.ts +20 -7
- package/src/link/explicit-route.ts +209 -0
- package/src/link/link-recover.ts +113 -0
- package/src/link/management-routes.ts +3 -1
- package/src/link/operation-recovery-slot.ts +44 -0
- package/src/link/operations-journal.ts +408 -0
- package/src/link/peer-report.ts +1 -1
- package/src/link/relay-auth.ts +14 -0
- package/src/link/remote-plant.ts +152 -14
- package/src/link/remote-platform.ts +21 -10
- package/src/link/remote-probe.ts +11 -3
- package/src/link/remote-windows.ts +124 -36
- package/src/link/request-compression.ts +30 -0
- package/src/link/residual-recovery.ts +66 -0
- package/src/link/retirement.ts +128 -0
- package/src/link/route-intent-watch.ts +41 -0
- package/src/link/route-intent.ts +209 -0
- package/src/link/route-proof.ts +82 -0
- package/src/link/route-rounds.ts +579 -0
- package/src/link/route-select.ts +95 -0
- package/src/link/route-trust.ts +96 -0
- package/src/link/ssh-argv.ts +172 -24
- package/src/link/ssh-capture-redact.ts +253 -0
- package/src/link/ssh-capture.ts +497 -0
- package/src/link/ssh-runner.ts +141 -14
- package/src/link/status-projection.ts +87 -0
- package/src/link/store.ts +54 -1
- package/src/link/supervisor.ts +543 -55
- package/src/link/sync-fanout-classify.ts +16 -0
- package/src/link/sync-then-restart.ts +65 -0
- package/src/link/tombstones.ts +209 -0
- package/src/link/traffic.ts +178 -0
- package/src/link/ws-activity-holds.ts +474 -0
- package/src/local-credentials/publication-fence.ts +20 -1
- package/src/messaging/budget.ts +23 -5
- package/src/messaging/mcp-queue-rpc.ts +1 -1
- package/src/messaging/mcp-queue-server.ts +16 -1
- package/src/messaging/mcp-resume-tools.ts +25 -0
- package/src/messaging/remote-enrollment.ts +3 -3
- package/src/messaging/remote-tunnels.ts +2 -2
- package/src/messaging/resume-permissions.ts +27 -0
- package/src/messaging/rpc.ts +50 -6
- package/src/oauth/anthropic-continuity.ts +23 -7
- package/src/oauth/anthropic-routing.ts +5 -2
- package/src/oauth/anthropic.ts +22 -2
- package/src/oauth/antigravity-risk.ts +126 -0
- package/src/oauth/claude-keychain-read.ts +78 -68
- package/src/oauth/generic-account-failover.ts +89 -18
- package/src/oauth/generic-session-affinity.ts +10 -3
- package/src/oauth/index.ts +24 -6
- package/src/oauth/local-token-detect.ts +8 -29
- package/src/oauth/login-cli-errors.ts +5 -1
- package/src/oauth/login-cli.ts +68 -19
- package/src/oauth/login-flow-state.ts +26 -3
- package/src/oauth/meta-muse.ts +1 -1
- package/src/oauth/pool-kernel.ts +3 -3
- package/src/oauth/store.ts +7 -0
- package/src/oauth/xai.ts +248 -14
- package/src/protocols/contract.ts +4 -0
- package/src/protocols/encoders/messages.ts +1 -0
- package/src/providers/alias-template.ts +48 -0
- package/src/providers/anthropic-billing-ownership.ts +2 -0
- package/src/providers/anthropic-billing-refusal.ts +27 -3
- package/src/providers/anthropic-output-caps.ts +46 -0
- package/src/providers/anthropic-reset-grant-ledger.ts +9 -3
- package/src/providers/antigravity-effort-families.ts +11 -3
- package/src/providers/antigravity-models.ts +32 -9
- package/src/providers/antigravity-wire-snapshot.ts +3 -2
- package/src/providers/api-key-pause.ts +3 -0
- package/src/providers/api-key-resolve.ts +49 -7
- package/src/providers/api-key-response-ownership.ts +2 -0
- package/src/providers/api-key-selection.ts +51 -9
- package/src/providers/api-keys.ts +6 -2
- package/src/providers/cache-affinity-identity.ts +73 -0
- package/src/providers/cache-affinity.ts +256 -0
- package/src/providers/default-aliases.ts +98 -20
- package/src/providers/google-vertex-model-discovery.ts +515 -0
- package/src/providers/key-failover.ts +123 -8
- package/src/providers/key-store.ts +3 -3
- package/src/providers/kiro-models.ts +3 -5
- package/src/providers/label.ts +31 -5
- package/src/providers/mistral-transport.ts +17 -4
- package/src/providers/model-rename-fields.ts +5 -0
- package/src/providers/muse-key-quota.ts +14 -6
- package/src/providers/new-model-policy-runtime.ts +17 -4
- package/src/providers/new-model-policy.ts +30 -4
- package/src/providers/passive-key-observation.ts +252 -0
- package/src/providers/quota/account-cache.ts +2 -1
- package/src/providers/quota/anthropic-cooldown-recovery-worker.ts +121 -0
- package/src/providers/quota/passive-key-limits.ts +272 -0
- package/src/providers/quota/passive-wire-model.ts +126 -0
- package/src/providers/quota/report-cache.ts +61 -2
- package/src/providers/quota/workbuddy.ts +6 -2
- package/src/providers/quota-key-accounts.ts +11 -6
- package/src/providers/quota-types.ts +18 -0
- package/src/providers/quota.ts +11 -12
- package/src/providers/registry/entries-core.ts +34 -16
- package/src/providers/registry/entries-extended.ts +32 -0
- package/src/providers/registry/model-seeds.ts +35 -0
- package/src/providers/resolved-model-policy.ts +7 -0
- package/src/providers/routed-config.ts +8 -3
- package/src/providers/workbuddy-credit-balance.ts +125 -16
- package/src/providers/xai-transport.ts +3 -0
- package/src/remote/features.ts +17 -0
- package/src/responses/anthropic-progress.ts +10 -4
- package/src/responses/citation-markers.ts +231 -0
- package/src/responses/effort-history.ts +732 -0
- package/src/responses/spill-store.ts +5 -1
- package/src/responses/state/replay-input.ts +50 -0
- package/src/responses/state/replay-owner.ts +24 -0
- package/src/responses/state/snapshot-codec.ts +9 -0
- package/src/responses/state/spill-queue.ts +1 -0
- package/src/responses/state.ts +42 -60
- package/src/router.ts +2 -2
- package/src/routing/history/integrity.ts +41 -4
- package/src/routing/home-route-capture.ts +123 -0
- package/src/routing/home-route-intent.ts +200 -0
- package/src/routing/route-intent-state.ts +178 -0
- package/src/routing/route-to-live-settings.ts +35 -0
- package/src/routing/route-to-local.ts +145 -0
- package/src/routing/route-to-status.ts +94 -0
- package/src/routing/route-to-sync-child.ts +32 -0
- package/src/server/adapter-resolve.ts +21 -1
- package/src/server/admitted-http-turn.ts +3 -0
- package/src/server/auth-cors.ts +111 -3
- package/src/server/bare-upstream-error.ts +220 -0
- package/src/server/chat-native.ts +14 -5
- package/src/server/claude-messages.ts +6 -4
- package/src/server/codex-model-list.ts +4 -2
- package/src/server/configured-credentials.ts +37 -5
- package/src/server/direct-local-http.ts +26 -3
- package/src/server/gui-desktop-authorization.ts +36 -0
- package/src/server/gui-pair-delivery.ts +6 -3
- package/src/server/gui-session.ts +10 -1
- package/src/server/inbound-body-admission.ts +17 -4
- package/src/server/index/link-listener.ts +196 -12
- package/src/server/index/link-management.ts +15 -1
- package/src/server/index/link-relay-sessions.ts +87 -8
- package/src/server/index/link-websocket-limits.ts +136 -0
- package/src/server/index/link-websocket.ts +692 -0
- package/src/server/index/optional-listeners.ts +97 -7
- package/src/server/index/route-intent-watch.ts +47 -0
- package/src/server/index/serve-contract.ts +86 -0
- package/src/server/index/serve-options.ts +36 -86
- package/src/server/index/startup-warnings.ts +8 -2
- package/src/server/index/websocket-handler.ts +26 -4
- package/src/server/index.ts +15 -4
- package/src/server/inference/client-encoder-delivery.ts +2 -0
- package/src/server/inspection-tee.ts +39 -2
- package/src/server/lifecycle.ts +2 -0
- package/src/server/link-turn.ts +149 -0
- package/src/server/management/advisor-routes.ts +10 -2
- package/src/server/management/agent-settings-routes.ts +50 -16
- package/src/server/management/anthropic-reset-grant-routes.ts +1 -1
- package/src/server/management/config-routes.ts +39 -3
- package/src/server/management/context.ts +9 -2
- package/src/server/management/desktop-authorization.ts +41 -0
- package/src/server/management/desktop-compatibility-routes.ts +9 -8
- package/src/server/management/desktop-compatibility-runtime-routes.ts +3 -2
- package/src/server/management/desktop-compatibility-settings-routes.ts +5 -3
- package/src/server/management/home-integration-decision.ts +89 -0
- package/src/server/management/integration-routes.ts +208 -81
- package/src/server/management/link-child-ops-routes.ts +145 -43
- package/src/server/management/link-child-preflight.ts +31 -0
- package/src/server/management/link-diagnostics-route.ts +29 -0
- package/src/server/management/link-enrollment.ts +199 -47
- package/src/server/management/link-operation.ts +609 -0
- package/src/server/management/link-recover-route.ts +103 -0
- package/src/server/management/link-route-edit.ts +192 -0
- package/src/server/management/link-route-request.ts +62 -0
- package/src/server/management/link-route-state.ts +83 -7
- package/src/server/management/link-routes.ts +553 -51
- package/src/server/management/link-traffic-status.ts +13 -0
- package/src/server/management/model-routes.ts +122 -36
- package/src/server/management/model-rows.ts +2 -1
- package/src/server/management/native-integration-routes.ts +176 -70
- package/src/server/management/oauth-account-routes.ts +58 -18
- package/src/server/management/protocol-routes.ts +7 -0
- package/src/server/management/provider-completion-test.ts +4 -4
- package/src/server/management/provider-overwrite-carry.ts +14 -0
- package/src/server/management/provider-routes.ts +68 -65
- package/src/server/management/provider-routing-quota.ts +45 -0
- package/src/server/management/route-registry.ts +22 -3
- package/src/server/management/route-to-routes.ts +257 -0
- package/src/server/management/static-catalog-probe.ts +33 -0
- package/src/server/management/system-restart.ts +4 -2
- package/src/server/management/usage-aggregate-cache.ts +101 -66
- package/src/server/management-api.ts +17 -3
- package/src/server/management-auth.ts +13 -1
- package/src/server/messages-native-preflight.ts +27 -4
- package/src/server/messages-native.ts +17 -5
- package/src/server/persistent-gui-session.ts +6 -3
- package/src/server/proxy-liveness.ts +87 -15
- package/src/server/relay-eager.ts +36 -12
- package/src/server/relay.ts +189 -117
- package/src/server/request-body-facts.ts +48 -0
- package/src/server/request-decompress.ts +65 -2
- package/src/server/request-log-account-rotation.ts +6 -0
- package/src/server/request-log-attempt-usage.ts +69 -0
- package/src/server/request-log-cache-affinity.ts +60 -0
- package/src/server/request-log-conversation.ts +45 -2
- package/src/server/request-log-terminal-status.ts +210 -24
- package/src/server/request-log.ts +76 -80
- package/src/server/reserve-capability-startup.ts +32 -0
- package/src/server/responses/adapter-continuation.ts +2 -1
- package/src/server/responses/adapter-delivery.ts +4 -0
- package/src/server/responses/adapter-dispatch.ts +36 -17
- package/src/server/responses/advisor-plan-slot.ts +33 -1
- package/src/server/responses/advisor-question.ts +21 -0
- package/src/server/responses/advisor-slot.ts +10 -3
- package/src/server/responses/antigravity-fault-rotation.ts +24 -0
- package/src/server/responses/antigravity-validation-refusal.ts +43 -6
- package/src/server/responses/bare-namespace-aliases.ts +18 -0
- package/src/server/responses/buffered-sse-json.ts +9 -3
- package/src/server/responses/code-mode-collab-surface.ts +11 -0
- package/src/server/responses/codex-tool-catalog.ts +156 -0
- package/src/server/responses/combo-required-tool-fulfillments.ts +4 -2
- package/src/server/responses/combo-selection-keepalive.ts +254 -0
- package/src/server/responses/combo-stream-preflight.ts +557 -54
- package/src/server/responses/compact.ts +32 -8
- package/src/server/responses/core-codex-account.ts +17 -3
- package/src/server/responses/core-combo-failure.ts +8 -0
- package/src/server/responses/core-combo.ts +55 -12
- package/src/server/responses/core-errors.ts +13 -7
- package/src/server/responses/core-lifetime.ts +3 -2
- package/src/server/responses/core-normalize.ts +3 -1
- package/src/server/responses/core-options.ts +14 -0
- package/src/server/responses/core.ts +23 -0
- package/src/server/responses/estimated-usage.ts +115 -0
- package/src/server/responses/fetch-helpers.ts +15 -10
- package/src/server/responses/jev-model-invoke.ts +7 -2
- package/src/server/responses/native-replay-guard.ts +57 -0
- package/src/server/responses/opengateway-completion-guard.ts +10 -4
- package/src/server/responses/outbound-request-body.ts +29 -0
- package/src/server/responses/passthrough-completion.ts +109 -9
- package/src/server/responses/passthrough-delivery.ts +77 -18
- package/src/server/responses/passthrough-dispatch.ts +77 -73
- package/src/server/responses/policy-fallback.ts +13 -1
- package/src/server/responses/request-prepare.ts +59 -11
- package/src/server/responses/request-transport.ts +10 -3
- package/src/server/responses/reset-replay.ts +46 -2
- package/src/server/responses/run-turn-execution.ts +2 -0
- package/src/server/responses/sidecar-execution.ts +19 -0
- package/src/server/responses/terminal-error-redaction.ts +222 -25
- package/src/server/responses/ws-upstream.ts +2 -2
- package/src/server/sse-payload-rewrite.ts +3 -2
- package/src/server/stop-service-route.ts +85 -0
- package/src/server/system-env-shell.ts +12 -1
- package/src/server/system-env.ts +5 -3
- package/src/server/windows-tcp-drop.ts +21 -4
- package/src/server/workflow-refusal.ts +8 -0
- package/src/server/ws-bridge.ts +191 -12
- package/src/service/cli-windows-stop.ts +189 -0
- package/src/service/cli.ts +41 -12
- package/src/service/desktop-supervision.d.mts +2 -0
- package/src/service/desktop-supervision.mjs +5 -0
- package/src/service/disconnected-client-restart.ts +60 -0
- package/src/service/guarded-manager-target.ts +18 -1
- package/src/service/health.ts +99 -6
- package/src/service/launchd.ts +84 -31
- package/src/service/orchestration.ts +418 -91
- package/src/service/repair.ts +223 -6
- package/src/service/restart-proxy-stop.ts +79 -0
- package/src/service/service-child-ownership.ts +6 -2
- package/src/service/windows-checked-stop-live.ts +467 -0
- package/src/service/windows-checked-stop.ts +435 -0
- package/src/service/windows-command-line-token.ts +23 -0
- package/src/service/windows-guarded-manager.ts +77 -34
- package/src/service/windows-ops.ts +38 -56
- package/src/service/windows-process-evidence.ts +292 -0
- package/src/service/windows-process-native.ts +262 -0
- package/src/service/windows-service-stop.ts +321 -0
- package/src/service/windows-stop-binding.ts +187 -0
- package/src/service/windows-stop-budget.ts +123 -0
- package/src/service/windows-stop-confirm.ts +158 -0
- package/src/service/windows-stop-deadline.ts +56 -0
- package/src/service.ts +2 -2
- package/src/stall-timeout.ts +11 -0
- package/src/types/config.ts +57 -110
- package/src/types/link.ts +20 -0
- package/src/types/multi-agent.ts +13 -0
- package/src/types/provider.ts +60 -2
- package/src/types/request.ts +23 -0
- package/src/types/routed-catalog-defaults.ts +17 -0
- package/src/types/routing-profile.ts +90 -0
- package/src/types.ts +4 -0
- package/src/update/guarded-runtime-ops.ts +5 -7
- package/src/update/index.ts +26 -11
- package/src/update/install-detection.mjs +3 -1
- package/src/update/job-pinned-start.ts +2 -0
- package/src/update/job-windows-restart.ts +19 -32
- package/src/update/job.ts +12 -5
- package/src/update/npm-install.d.mts +11 -0
- package/src/update/npm-install.mjs +44 -7
- package/src/update/orchestrated-entry.ts +1 -1
- package/src/update/orchestrated-node-driver.mjs +3 -2
- package/src/update/orchestrated-pnpm.d.mts +4 -0
- package/src/update/orchestrated-pnpm.mjs +50 -6
- package/src/update/orchestrated-session.d.mts +3 -1
- package/src/update/orchestrated-session.mjs +21 -6
- package/src/update/pnpm-global-install.d.mts +21 -3
- package/src/update/pnpm-global-install.mjs +322 -19
- package/src/update/pnpm-store-layout.mjs +46 -0
- package/src/update/sync-update-mutex.d.mts +3 -2
- package/src/update/sync-update-mutex.mjs +57 -8
- package/src/update/transactional-install.d.mts +3 -1
- package/src/update/transactional-install.mjs +545 -12
- package/src/update/windows-installer-marker.d.mts +1 -0
- package/src/update/windows-installer-marker.mjs +44 -0
- package/src/usage/expected-prices.ts +8 -0
- package/src/usage/filter-index.ts +326 -77
- package/src/usage/ledger-scanner.ts +15 -0
- package/src/usage/link-log-fields.ts +48 -0
- package/src/usage/log.ts +57 -6
- package/src/usage/request-body.ts +37 -0
- package/src/usage/telemetry-contract.ts +1 -0
- package/src/web-search/loop.ts +3 -0
- package/src/web-search/passthrough-bridge.ts +7 -0
- package/gui/dist/assets/App-BpJOzw4F.js +0 -59
- package/gui/dist/assets/brand-mark-DU-0Vdkr.js +0 -1
- package/gui/dist/assets/index-Bbor_y80.js +0 -94
- package/gui/dist/assets/index-DJEkIDAi.css +0 -2
- package/gui/dist/classic/assets/App-BrIlUiLc.js +0 -58
- package/gui/dist/classic/assets/index-DyJHagvT.js +0 -94
- package/gui/dist/classic/assets/quota-summary-CakPe9Ni.js +0 -1
- package/src/server/management/desktop-compatibility-authorization.ts +0 -12
|
@@ -274,8 +274,9 @@ export function preferKiroModelSupport(
|
|
|
274
274
|
if (!model) return ids;
|
|
275
275
|
if (providerName === "google-antigravity") {
|
|
276
276
|
const positive = ids.filter(id => accountListsModel(providerName, id, model) === true);
|
|
277
|
-
|
|
278
|
-
|
|
277
|
+
const modelMatched = positive.length ? positive : ids.filter(id => accountListsModel(providerName, id, model) !== false);
|
|
278
|
+
const nonExhausted = modelMatched.filter(id => !isAccountQuotaExhausted(providerName, id, model));
|
|
279
|
+
return nonExhausted.length ? nonExhausted : modelMatched;
|
|
279
280
|
}
|
|
280
281
|
if (providerName !== "kiro") return ids;
|
|
281
282
|
const cap = config?.providers?.kiro?.oauthAccountFailover?.maxConcurrentPerAccount;
|
|
@@ -341,7 +342,10 @@ export function routeAntigravityModel(
|
|
|
341
342
|
const ready = new Set(eligibleFailoverAccounts(providerName, now, classifyModelFamilyForQuota(providerName, model)));
|
|
342
343
|
const rank = (id: string) => (ready.has(id) ? 0 : 2) + (accountListsModel(providerName, id, model) === true ? 0 : 1);
|
|
343
344
|
const tier = Math.min(...serving.map(rank));
|
|
344
|
-
|
|
345
|
+
// Same exhaustion preference as the initial pick: a listing account whose quota family is
|
|
346
|
+
// spent loses to one with headroom, unless every candidate in the tier is spent.
|
|
347
|
+
const candidates = preferKiroModelSupport(providerName, serving.filter(id => rank(id) === tier), model, config);
|
|
348
|
+
const best = rankAntigravityModelAccounts(config, candidates, model, now)[0]!;
|
|
345
349
|
return { kind: "reroute", accountId: best };
|
|
346
350
|
}
|
|
347
351
|
|
|
@@ -351,7 +355,8 @@ function rankAntigravityModelAccounts(config: OcxConfig, ids: string[], model: s
|
|
|
351
355
|
const rows = new Map((getAccountSet(provider)?.accounts ?? []).map(row => [row.id, row]));
|
|
352
356
|
const strategy = activeGenericStrategy(config, provider);
|
|
353
357
|
if (strategy === "round-robin") {
|
|
354
|
-
const
|
|
358
|
+
const poolKey = genericPoolKey(provider, classifyModelFamilyForQuota(provider, model));
|
|
359
|
+
const best = peekRoundRobinAccount(poolKey, ids, genericStickyLimit(config, provider));
|
|
355
360
|
return best ? [best, ...ids.filter(id => id !== best)] : ids;
|
|
356
361
|
}
|
|
357
362
|
if (strategy === "fill-first") return stableGenericRoster(provider).filter(id => ids.includes(id));
|
|
@@ -446,16 +451,44 @@ export function rotateAntigravityAccountOnAuthRefusal(
|
|
|
446
451
|
const set = getAccountSet("google-antigravity");
|
|
447
452
|
if (!set || set.accounts.length < 2) return null;
|
|
448
453
|
const family = classifyModelFamilyForQuota("google-antigravity", requestedModelId);
|
|
454
|
+
coolAntigravityAccount(set, failedAccountId, sentGeneration, family, now, {
|
|
455
|
+
cooldownUntil: now + DEFAULT_COOLDOWN_MS, cooldownSource: "auth", identity: sentGeneration,
|
|
456
|
+
});
|
|
457
|
+
return nextAntigravitySibling(set, failedAccountId, requestedModelId, family, now);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* The one cooldown write both Antigravity sibling rotations (403 refusal, 5xx fault) share. It is
|
|
462
|
+
* fenced on the sent credential generation, so a re-login that landed mid-request is never cooled,
|
|
463
|
+
* and it never shortens a cooldown already running for the same account and family: a 15-second
|
|
464
|
+
* fault window must not cut short a 60-second refusal or a quota cooldown.
|
|
465
|
+
*/
|
|
466
|
+
function coolAntigravityAccount(
|
|
467
|
+
set: NonNullable<ReturnType<typeof getAccountSet>>,
|
|
468
|
+
failedAccountId: string,
|
|
469
|
+
sentGeneration: string,
|
|
470
|
+
family: QuotaModelFamily | undefined,
|
|
471
|
+
now: number,
|
|
472
|
+
entry: AccountHealth,
|
|
473
|
+
): void {
|
|
449
474
|
const failed = set.accounts.find(row => row.id === failedAccountId);
|
|
450
|
-
if (failed
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
475
|
+
if (!failed || credentialGeneration(failed.credential) !== sentGeneration) return;
|
|
476
|
+
const key = healthKey("google-antigravity", failedAccountId, family);
|
|
477
|
+
if (isCooled("google-antigravity", failedAccountId, now, family)
|
|
478
|
+
&& (health.get(key)?.cooldownUntil ?? 0) >= entry.cooldownUntil) return;
|
|
479
|
+
health.set(key, entry);
|
|
480
|
+
presence.delete("google-antigravity");
|
|
481
|
+
sweepExpiredOnWrite(now);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** Next live sibling after the failed account, in roster order, honouring cooldowns and model support. */
|
|
485
|
+
function nextAntigravitySibling(
|
|
486
|
+
set: NonNullable<ReturnType<typeof getAccountSet>>,
|
|
487
|
+
failedAccountId: string,
|
|
488
|
+
requestedModelId: string | null | undefined,
|
|
489
|
+
family: QuotaModelFamily | undefined,
|
|
490
|
+
now: number,
|
|
491
|
+
): string | null {
|
|
459
492
|
const eligible = new Set(preferKiroModelSupport("google-antigravity",
|
|
460
493
|
eligibleIdsIn(set, "google-antigravity", now, family).filter(id => id !== failedAccountId), requestedModelId));
|
|
461
494
|
const order = set.accounts.map(row => row.id);
|
|
@@ -464,6 +497,31 @@ export function rotateAntigravityAccountOnAuthRefusal(
|
|
|
464
497
|
return ring.find(id => id !== failedAccountId && eligible.has(id)) ?? null;
|
|
465
498
|
}
|
|
466
499
|
|
|
500
|
+
/**
|
|
501
|
+
* A 502/503/504 that survived the same-account retry ladder says this account's route to Google is
|
|
502
|
+
* failing right now, not that the credential is bad. Cool it for a short, fixed window (pool-wide
|
|
503
|
+
* capacity trouble then clears on its own within seconds) and name a live sibling to replay on.
|
|
504
|
+
* No stored verdict: nothing here outlives the process or the window.
|
|
505
|
+
*/
|
|
506
|
+
const ANTIGRAVITY_FAULT_COOLDOWN_MS = 15_000;
|
|
507
|
+
|
|
508
|
+
export function rotateAntigravityAccountOnUpstreamFault(
|
|
509
|
+
poolActivated: boolean,
|
|
510
|
+
failedAccountId: string,
|
|
511
|
+
sentGeneration: string,
|
|
512
|
+
requestedModelId: string | null | undefined,
|
|
513
|
+
now = Date.now(),
|
|
514
|
+
): string | null {
|
|
515
|
+
if (!poolActivated) return null;
|
|
516
|
+
const set = getAccountSet("google-antigravity");
|
|
517
|
+
if (!set || set.accounts.length < 2) return null;
|
|
518
|
+
const family = classifyModelFamilyForQuota("google-antigravity", requestedModelId);
|
|
519
|
+
coolAntigravityAccount(set, failedAccountId, sentGeneration, family, now, {
|
|
520
|
+
cooldownUntil: now + ANTIGRAVITY_FAULT_COOLDOWN_MS, cooldownSource: "default",
|
|
521
|
+
});
|
|
522
|
+
return nextAntigravitySibling(set, failedAccountId, requestedModelId, family, now);
|
|
523
|
+
}
|
|
524
|
+
|
|
467
525
|
/** Generic pool strategies the kernel can actually run. `quota` IS the pre-kernel path. */
|
|
468
526
|
type ActiveGenericStrategy = "round-robin" | "fill-first" | "reset-first" | "least-loaded";
|
|
469
527
|
|
|
@@ -580,10 +638,16 @@ export function noteGenericPoolSelection(
|
|
|
580
638
|
requestedModelId?: string | null,
|
|
581
639
|
): void {
|
|
582
640
|
if (activeGenericStrategy(config, providerName) !== "round-robin") return;
|
|
583
|
-
const poolKey = genericPoolKey(providerName);
|
|
584
|
-
const limit = genericStickyLimit(config, providerName);
|
|
585
641
|
const family = classifyModelFamilyForQuota(providerName, requestedModelId);
|
|
586
|
-
const
|
|
642
|
+
const poolKey = genericPoolKey(providerName, family);
|
|
643
|
+
const limit = genericStickyLimit(config, providerName);
|
|
644
|
+
const eligible = preferKiroModelSupport(
|
|
645
|
+
providerName,
|
|
646
|
+
eligibleFailoverAccounts(providerName, Date.now(), family),
|
|
647
|
+
requestedModelId,
|
|
648
|
+
config,
|
|
649
|
+
);
|
|
650
|
+
const picked = pickRoundRobinAccount(poolKey, eligible, limit);
|
|
587
651
|
// The resolver may have admitted a different account than the ring proposed: a removal, a
|
|
588
652
|
// reauth verdict or a manual selection can land during credential resolution. Realign the
|
|
589
653
|
// cursor onto what actually served rather than leaving it on a road not taken.
|
|
@@ -684,7 +748,7 @@ export function rotateGenericOAuthAccountOnRefusal(
|
|
|
684
748
|
// PICK here, not peek: the failure already happened and this answer is the one being used,
|
|
685
749
|
// so the ring genuinely advances. A caller that only asks whether a sibling exists peeks.
|
|
686
750
|
return (commit ? pickRoundRobinAccount : peekRoundRobinAccount)(
|
|
687
|
-
genericPoolKey(providerName),
|
|
751
|
+
genericPoolKey(providerName, family),
|
|
688
752
|
candidates,
|
|
689
753
|
genericStickyLimit(config, providerName),
|
|
690
754
|
);
|
|
@@ -822,7 +886,7 @@ export function preferredInitialAccount(
|
|
|
822
886
|
// PEEK, not pick: this proposal is discardable, and advancing the ring for an account the
|
|
823
887
|
// resolver then rejects would skip a turn for nothing. noteGenericPoolSelection commits.
|
|
824
888
|
const picked = peekRoundRobinAccount(
|
|
825
|
-
genericPoolKey(providerName),
|
|
889
|
+
genericPoolKey(providerName, family),
|
|
826
890
|
eligibleNow,
|
|
827
891
|
genericStickyLimit(config, providerName),
|
|
828
892
|
);
|
|
@@ -889,6 +953,13 @@ export function genericFailoverRetryAfterSeconds(providerName: string, now = Dat
|
|
|
889
953
|
return earliest === null ? null : Math.max(1, Math.ceil((earliest - now) / 1000));
|
|
890
954
|
}
|
|
891
955
|
|
|
956
|
+
/** A manual selection must win in every ring a request can read, including the per-family ones. */
|
|
957
|
+
export function seedGenericPoolSelection(providerName: string, accountId: string): void {
|
|
958
|
+
seedPoolRotationAccount(genericPoolKey(providerName), accountId);
|
|
959
|
+
if (providerName !== "google-antigravity") return;
|
|
960
|
+
for (const family of ["gem", "cla"] satisfies QuotaModelFamily[]) seedPoolRotationAccount(genericPoolKey(providerName, family), accountId);
|
|
961
|
+
}
|
|
962
|
+
|
|
892
963
|
/** Test seam and manual-recovery hook. */
|
|
893
964
|
export function forgetGenericFailoverRoster(providerName: string): void {
|
|
894
965
|
presence.delete(providerName);
|
|
@@ -13,7 +13,8 @@ const IDLE_TTL_MS = 24 * 60 * 60_000;
|
|
|
13
13
|
const MAX_ENTRIES = 2_000;
|
|
14
14
|
const bindings = new Map<string, { accountId: string; lastUsedAt: number; selection: OAuthAccountSelection }>();
|
|
15
15
|
const prefix = (provider: string) => `${JSON.stringify([getConfigDir(), provider])}\u0000`;
|
|
16
|
-
const key = (provider: string, session: string
|
|
16
|
+
const key = (provider: string, session: string, family?: string) =>
|
|
17
|
+
prefix(provider) + (family ? `session:${family}:` : "session:") + createHash("sha256").update(session).digest("hex");
|
|
17
18
|
const cursorKey = (provider: string) => prefix(provider) + "fill-first";
|
|
18
19
|
|
|
19
20
|
/** A persisted operator/roster/policy change revokes old session choices before its writer returns. */
|
|
@@ -59,7 +60,9 @@ export function genericSessionAccount(
|
|
|
59
60
|
config: OcxConfig, provider: string, session: string | null, model?: string | null, now = Date.now(),
|
|
60
61
|
): string | null {
|
|
61
62
|
if (!genericSessionAffinityEnabled(config, provider) || !session) return null;
|
|
62
|
-
|
|
63
|
+
const family = classifyModelFamilyForQuota(provider, model);
|
|
64
|
+
return readBinding(config, provider, key(provider, session, family), model, now)
|
|
65
|
+
?? (family ? readBinding(config, provider, key(provider, session), model, now) : null);
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
function readBinding(config: OcxConfig, provider: string, id: string, model: string | null | undefined, now: number): string | null {
|
|
@@ -127,6 +130,10 @@ export function bindGenericSessionAccount(
|
|
|
127
130
|
const hit = session && genericSessionAccount(config, provider, session, model, now) === accountId;
|
|
128
131
|
if (!hit && config.pool?.kernel === true && config.providers[provider]?.oauthAccountFailover?.strategy === "fill-first")
|
|
129
132
|
keep(cursorKey(provider));
|
|
130
|
-
|
|
133
|
+
const family = classifyModelFamilyForQuota(provider, model);
|
|
134
|
+
if (session) {
|
|
135
|
+
keep(key(provider, session, family));
|
|
136
|
+
if (family) keep(key(provider, session));
|
|
137
|
+
}
|
|
131
138
|
while (bindings.size > MAX_ENTRIES) bindings.delete(bindings.keys().next().value!);
|
|
132
139
|
}
|
package/src/oauth/index.ts
CHANGED
|
@@ -96,7 +96,7 @@ export { OAUTH_REFRESH_LOCK_WAIT_MS, peekAuthStore, peekOAuthRefreshIntent } fro
|
|
|
96
96
|
import { codexAccountNamespaceProviderCollisionError } from "../codex/account-namespace-match";
|
|
97
97
|
|
|
98
98
|
import { REFRESH_SKEW_MS } from "./refresh-policy";
|
|
99
|
-
import { newerClaudeCredentialForInstance, captureAnthropicCredentialOwnerForInstance } from "./anthropic-continuity";
|
|
99
|
+
import { newerClaudeCredentialForInstance, captureAnthropicCredentialOwnerForInstance, claudeCredentialGenerationCurrent } from "./anthropic-continuity";
|
|
100
100
|
import { anthropicSubscriptionLabel } from "../providers/anthropic-subscription";
|
|
101
101
|
import { normalizeOAuthPlan, mergeOAuthPlan } from "./plan";
|
|
102
102
|
import { mergeAnthropicIdentity, type AnthropicIdentityResolver } from "./anthropic-identity";
|
|
@@ -201,8 +201,8 @@ export interface LoginOpts {
|
|
|
201
201
|
/** When set, persist into this account slot and require matching identity. */
|
|
202
202
|
reauthAccountId?: string;
|
|
203
203
|
/**
|
|
204
|
-
* ChatGPT
|
|
205
|
-
* localhost
|
|
204
|
+
* ChatGPT and xAI: `device` selects the device grant instead of the
|
|
205
|
+
* localhost callback flow, for hosts with no browser or no loopback
|
|
206
206
|
* listener (#3366). Ignored by every other provider.
|
|
207
207
|
*/
|
|
208
208
|
flow?: ChatGPTLoginFlow;
|
|
@@ -238,6 +238,8 @@ export interface OAuthProviderDef {
|
|
|
238
238
|
defaultRefreshPolicy?: RefreshPolicy;
|
|
239
239
|
/** Provider-hosted page that DISPLAYS the code; its presence enables `codeMode`. */
|
|
240
240
|
codeRedirectUri?: string;
|
|
241
|
+
/** Has an RFC 8628 device grant besides its browser login; `flow: "device"` selects it. */
|
|
242
|
+
deviceLogin?: true;
|
|
241
243
|
}
|
|
242
244
|
|
|
243
245
|
function oauthConfig(id: string): OcxProviderConfig {
|
|
@@ -294,7 +296,8 @@ export const OAUTH_PROVIDERS: Record<string, OAuthProviderDef> = {
|
|
|
294
296
|
},
|
|
295
297
|
xai: {
|
|
296
298
|
// forceLogin skips the local grok-cli import so a SECOND account can be chosen in the browser.
|
|
297
|
-
login: (ctrl, opts) => loginXai(ctrl, { importLocal: opts?.forceLogin ? "off" : "fallback" }),
|
|
299
|
+
login: (ctrl, opts) => loginXai(ctrl, { importLocal: opts?.forceLogin ? "off" : "fallback", device: opts?.flow === "device" }),
|
|
300
|
+
deviceLogin: true,
|
|
298
301
|
refresh: refreshXaiToken,
|
|
299
302
|
providerConfig: oauthConfig("xai"),
|
|
300
303
|
defaultModel: oauthDefaultModel("xai"),
|
|
@@ -416,6 +419,11 @@ export function supportsCodeLoginMode(name: string): boolean {
|
|
|
416
419
|
return OAUTH_PROVIDERS[name]?.codeRedirectUri !== undefined;
|
|
417
420
|
}
|
|
418
421
|
|
|
422
|
+
/** Providers that can log in with a device grant: a URL and a short code, approved in any browser. */
|
|
423
|
+
export function supportsDeviceLoginMode(name: string): boolean {
|
|
424
|
+
return OAUTH_PROVIDERS[name]?.deviceLogin === true;
|
|
425
|
+
}
|
|
426
|
+
|
|
419
427
|
function isRefreshPolicy(value: unknown): value is RefreshPolicy {
|
|
420
428
|
return value === "proactive" || value === "lazy-only" || value === "disabled";
|
|
421
429
|
}
|
|
@@ -865,18 +873,28 @@ export async function refreshAnthropicAccountWithLock(
|
|
|
865
873
|
const generation = credentialGeneration(stored);
|
|
866
874
|
let pendingIntent = readOAuthRefreshIntent(provider, accountId);
|
|
867
875
|
const observed = await newerClaudeCredentialForInstance(provider, stored, now(), deps.signal, deps.resolveIdentity);
|
|
876
|
+
// A write that depends on the CLI credential re-reads it: the non-adopting checks below run
|
|
877
|
+
// now, and adoption re-reads again inside the serialized writer (afterPrePersistRead), so a CLI
|
|
878
|
+
// rotation while the writer was queued is still caught. The read is async and never kills the
|
|
879
|
+
// Keychain child (#8161); the writer's predicate only consumes its result.
|
|
880
|
+
let diskVerified = observed.kind === "absent" || observed.kind === "adopt"
|
|
881
|
+
? undefined : await claudeCredentialGenerationCurrent(observed.diskGeneration, now);
|
|
868
882
|
const assertOwner = (store: AuthStore, checkDisk = true) => {
|
|
869
883
|
if (observed.kind !== "absent" && deps.signal?.aborted) throw new OAuthTokenRefreshStaleError();
|
|
870
|
-
if (!owns(store, checkDisk
|
|
884
|
+
if (!owns(store, checkDisk ? diskVerified : undefined)) {
|
|
871
885
|
if (store[provider]?.accounts.find(a => a.id === accountId)?.paused) throw new OAuthAccountPausedError();
|
|
872
886
|
throw new OAuthTokenRefreshStaleError();
|
|
873
887
|
}
|
|
874
888
|
};
|
|
875
889
|
assertOwner({ [provider]: getAccountSet(provider)! }, observed.kind !== "adopt");
|
|
876
890
|
if (observed.kind === "adopt") {
|
|
891
|
+
const diskGeneration = observed.diskGeneration;
|
|
877
892
|
const outcome = await mergeAccountCredential(provider, accountId, observed.credential, {
|
|
878
893
|
expectedGeneration: generation,
|
|
879
|
-
afterPrePersistRead:
|
|
894
|
+
afterPrePersistRead: async () => {
|
|
895
|
+
await deps.afterPrePersistRead?.();
|
|
896
|
+
diskVerified = await claudeCredentialGenerationCurrent(diskGeneration, now);
|
|
897
|
+
},
|
|
880
898
|
assertOwnership: assertOwner,
|
|
881
899
|
});
|
|
882
900
|
// A superseding write did not adopt our candidate. Its pending intent remains owned by it.
|
|
@@ -72,16 +72,6 @@ function claudeConfigDir(): string {
|
|
|
72
72
|
return explicit ? explicit : join(homedir(), ".claude");
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/**
|
|
76
|
-
* Read the Claude Code OAuth credential from the macOS Keychain (darwin only). A synchronous
|
|
77
|
-
* read cannot time out without killing `security`, which can crash `securityd` while an unlock
|
|
78
|
-
* prompt is pending (#8161), so it does not spawn while a read is still running or backing off,
|
|
79
|
-
* and its own timeout starts that backoff (`claude-keychain-read.ts`).
|
|
80
|
-
*/
|
|
81
|
-
function readClaudeKeychain(): string | null {
|
|
82
|
-
return claudeKeychainReader.readSync();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
75
|
/**
|
|
86
76
|
* Read the Claude Code credential file (`<config-dir>/.credentials.json`).
|
|
87
77
|
* Claude Code writes this on Linux/Windows (and on macOS when the Keychain is
|
|
@@ -98,26 +88,21 @@ export function readClaudeCredentialsFile(): string | null {
|
|
|
98
88
|
}
|
|
99
89
|
}
|
|
100
90
|
|
|
101
|
-
/** Keychain first on macOS, then the cross-platform credentials file. */
|
|
102
|
-
function readClaudeSecureStorage(): string | null {
|
|
103
|
-
// An explicit config-dir override identifies a separate Claude installation/profile.
|
|
104
|
-
// Do not let the default macOS Keychain entry shadow that requested credential file.
|
|
105
|
-
if (process.env.CLAUDE_CONFIG_DIR?.trim()) return readClaudeCredentialsFile() ?? readClaudeKeychain();
|
|
106
|
-
return readClaudeKeychain() ?? readClaudeCredentialsFile();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
91
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
92
|
+
* The Claude Code OAuth credential from the macOS Keychain (darwin only). There is no synchronous
|
|
93
|
+
* variant: a synchronous read cannot time out without killing `security`, which can crash
|
|
94
|
+
* `securityd` while an unlock prompt is pending (#8161). A timed-out child is left to exit on its
|
|
95
|
+
* own, concurrent reads share one child, and a timeout backs off before the next spawn
|
|
96
|
+
* (`claude-keychain-read.ts`).
|
|
113
97
|
*/
|
|
114
98
|
function readClaudeKeychainAsync(): Promise<string | null> {
|
|
115
99
|
return claudeKeychainReader.readAsync();
|
|
116
100
|
}
|
|
117
101
|
|
|
118
102
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
103
|
+
* The Claude Code sign-in: Keychain first on macOS, then the cross-platform credentials file. An
|
|
104
|
+
* explicit `CLAUDE_CONFIG_DIR` names a separate Claude profile, so its credentials file wins and
|
|
105
|
+
* the default Keychain entry cannot shadow it.
|
|
121
106
|
*/
|
|
122
107
|
export async function detectClaudeCodeTokenAsync(): Promise<OAuthCredentials | null> {
|
|
123
108
|
const raw = process.env.CLAUDE_CONFIG_DIR?.trim()
|
|
@@ -140,12 +125,6 @@ export function parseClaudeOauthPayload(raw: string): OAuthCredentials | null {
|
|
|
140
125
|
}
|
|
141
126
|
}
|
|
142
127
|
|
|
143
|
-
export function detectClaudeCodeToken(): OAuthCredentials | null {
|
|
144
|
-
const raw = readClaudeSecureStorage();
|
|
145
|
-
if (!raw) return null;
|
|
146
|
-
return parseClaudeOauthPayload(raw);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
128
|
/** Shared-token continuity for opaque Claude tokens; fully rotated pairs need authenticated account proof. */
|
|
150
129
|
export function hasClaudeCredentialContinuity(stored: OAuthCredentials, disk: OAuthCredentials): boolean {
|
|
151
130
|
const sameToken = (left: string, right: string): boolean =>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnthropicTokenError } from "./anthropic";
|
|
2
2
|
import { OAuthProviderNamespaceCollisionError, OAuthProviderPublicationError, publicOAuthAuthenticationErrorMessage } from "./index";
|
|
3
|
-
import { XaiTokenRequestError } from "./xai";
|
|
3
|
+
import { XaiRedirectRefusedError, XaiTokenRequestError } from "./xai";
|
|
4
4
|
import { AnthropicInstanceCollisionError, AnthropicInstanceConfigReadError } from "./store-anthropic-instance";
|
|
5
5
|
|
|
6
6
|
// Standard RFC 6749 / RFC 6750 / RFC 8628 error codes. A provider's `error` field is printed only
|
|
@@ -18,6 +18,10 @@ export function oauthLoginFailureDiagnostic(error: unknown): string {
|
|
|
18
18
|
|| error instanceof AnthropicInstanceCollisionError || error instanceof AnthropicInstanceConfigReadError) {
|
|
19
19
|
return "configuration_error";
|
|
20
20
|
}
|
|
21
|
+
// A refused redirect is a definitive server answer, not a transport fault: the request was
|
|
22
|
+
// not delivered anywhere it was allowed to go. Reporting it as `network_error` would invite a
|
|
23
|
+
// retry that can only be refused again.
|
|
24
|
+
if (error instanceof XaiRedirectRefusedError) return "oauth_authentication_failed";
|
|
21
25
|
const status = error instanceof AnthropicTokenError ? error.httpStatus
|
|
22
26
|
: error instanceof XaiTokenRequestError ? error.status : undefined;
|
|
23
27
|
const oauthError = error instanceof AnthropicTokenError || error instanceof XaiTokenRequestError
|
package/src/oauth/login-cli.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
requestBoundLocalProviderReload,
|
|
10
10
|
type LocalProviderReloadResult,
|
|
11
11
|
} from "../server/local-provider-reload-client";
|
|
12
|
-
import { DEPRECATED_OAUTH_PROVIDER_ALIASES, isPublicOAuthProvider, listOAuthProviders, publicOAuthAuthenticationErrorMessage, runLogin, supportsCodeLoginMode } from "./index";
|
|
12
|
+
import { DEPRECATED_OAUTH_PROVIDER_ALIASES, isPublicOAuthProvider, listOAuthProviders, publicOAuthAuthenticationErrorMessage, runLogin, supportsCodeLoginMode, supportsDeviceLoginMode } from "./index";
|
|
13
13
|
import { classifyLoginCodeError } from "./login-flow-state";
|
|
14
14
|
import { KEY_LOGIN_PROVIDERS, isKeyLoginProvider, validateApiKey, type KeyLoginProvider } from "./key-providers";
|
|
15
15
|
import type { OcxConfig, OcxProviderConfig } from "../types";
|
|
@@ -17,6 +17,14 @@ import { configuredAdminToken } from "../lib/admin-secrets";
|
|
|
17
17
|
import { codexAccountNamespaceProviderCollisionError } from "../codex/account-namespace-match";
|
|
18
18
|
import { assertAnthropicInstanceLoginConfig } from "./store-anthropic-instance";
|
|
19
19
|
import { reportOAuthLoginError } from "./login-cli-errors";
|
|
20
|
+
import { terminalSafeText } from "../lib/terminal-safe-text";
|
|
21
|
+
import {
|
|
22
|
+
ANTIGRAVITY_RISK_CLI_FLAG,
|
|
23
|
+
antigravityRiskDecisionMessage,
|
|
24
|
+
requiresAntigravityRiskAcknowledgement,
|
|
25
|
+
resolveAntigravityRiskAcknowledgement,
|
|
26
|
+
} from "./antigravity-risk";
|
|
27
|
+
import { isAgentDriven } from "../cli/agent-driven";
|
|
20
28
|
|
|
21
29
|
/**
|
|
22
30
|
* Seams a test drives in place of a browser, a terminal and a real provider. Production passes
|
|
@@ -33,6 +41,10 @@ export interface LoginCliDeps {
|
|
|
33
41
|
warn?: (message: string) => void;
|
|
34
42
|
/** Ask one question, read one line. Defaults to a readline prompt that owns its own lifetime. */
|
|
35
43
|
ask?: (question: string) => Promise<string>;
|
|
44
|
+
/** Whether a person can answer a prompt. Defaults to stdin and stdout both being terminals. */
|
|
45
|
+
isInteractive?: () => boolean;
|
|
46
|
+
/** Whether a coding agent or CI runner drives this process. Defaults to isAgentDriven(). */
|
|
47
|
+
agentDriven?: () => boolean;
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
/**
|
|
@@ -115,9 +127,12 @@ export function warnIfLiveReloadSkipped(result: LocalProviderReloadResult | null
|
|
|
115
127
|
* that used to be their only pointer to it.
|
|
116
128
|
*/
|
|
117
129
|
export function loginUsageMessage(): string {
|
|
118
|
-
return `Usage: ocx login <provider> [--headless]\n`
|
|
119
|
-
+ ` --headless: no browser and no local port — approve in any browser, paste the code\n`
|
|
130
|
+
return `Usage: ocx login <provider> [--headless] [${ANTIGRAVITY_RISK_CLI_FLAG}]\n`
|
|
131
|
+
+ ` --headless: no browser and no local port — approve in any browser, then paste the code\n`
|
|
132
|
+
+ ` it shows or confirm the device code printed here\n`
|
|
120
133
|
+ ` (${listCodeLoginProviders().join(", ")})\n`
|
|
134
|
+
+ ` ${ANTIGRAVITY_RISK_CLI_FLAG}: google-antigravity only; accept the account-ban risk without\n`
|
|
135
|
+
+ ` the interactive prompt (the warning is still printed)\n`
|
|
121
136
|
+ ` Codex / ChatGPT: ocx login codex (account pool, needs a running proxy; 'chatgpt' and\n`
|
|
122
137
|
+ ` 'openai' are the same route. An OpenAI platform key is 'openai-apikey'.)\n`
|
|
123
138
|
+ ` OAuth login: ${listOAuthProviders().join(", ")}\n`
|
|
@@ -127,10 +142,16 @@ export function loginUsageMessage(): string {
|
|
|
127
142
|
export interface LoginCliOptions {
|
|
128
143
|
/** `--headless`: no callback server, no browser launch — print the URL and read back the code. */
|
|
129
144
|
codeMode?: boolean;
|
|
145
|
+
/** `--accept-antigravity-risk`: accept the Antigravity warning without a prompt. */
|
|
146
|
+
acceptAntigravityRisk?: boolean;
|
|
130
147
|
}
|
|
131
148
|
|
|
132
149
|
export async function handleLogin(provider?: string, deps: LoginCliDeps = {}, opts: LoginCliOptions = {}): Promise<void> {
|
|
133
150
|
const name = (provider ?? "").trim().toLowerCase();
|
|
151
|
+
if (opts.acceptAntigravityRisk && !requiresAntigravityRiskAcknowledgement(DEPRECATED_OAUTH_PROVIDER_ALIASES[name] ?? name)) {
|
|
152
|
+
console.error(`${ANTIGRAVITY_RISK_CLI_FLAG} only applies to google-antigravity`);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
134
155
|
try {
|
|
135
156
|
// Check raw ownership before tolerant loading can print diagnostics or fall back to defaults.
|
|
136
157
|
if (name === "anthropic2") assertAnthropicInstanceLoginConfig({ providers: {} }, name);
|
|
@@ -147,7 +168,7 @@ export async function handleLogin(provider?: string, deps: LoginCliDeps = {}, op
|
|
|
147
168
|
}
|
|
148
169
|
if (isPublicOAuthProvider(name)) return handleOAuthLogin(name, deps, opts);
|
|
149
170
|
if (opts.codeMode) {
|
|
150
|
-
console.error(`--headless needs a provider with a code-display login: ${listCodeLoginProviders().join(", ")}`);
|
|
171
|
+
console.error(`--headless needs a provider with a code-display or device login: ${listCodeLoginProviders().join(", ")}`);
|
|
151
172
|
process.exit(1);
|
|
152
173
|
}
|
|
153
174
|
if (isKeyLoginProvider(name)) return handleKeyLogin(name, deps);
|
|
@@ -155,36 +176,49 @@ export async function handleLogin(provider?: string, deps: LoginCliDeps = {}, op
|
|
|
155
176
|
process.exit(1);
|
|
156
177
|
}
|
|
157
178
|
|
|
158
|
-
/** OAuth providers that accept `ocx login <provider> --headless
|
|
179
|
+
/** OAuth providers that accept `ocx login <provider> --headless`: a code-display or a device login. */
|
|
159
180
|
export function listCodeLoginProviders(): string[] {
|
|
160
|
-
return listOAuthProviders().filter(supportsCodeLoginMode);
|
|
181
|
+
return listOAuthProviders().filter(name => supportsCodeLoginMode(name) || supportsDeviceLoginMode(name));
|
|
161
182
|
}
|
|
162
183
|
|
|
163
184
|
/**
|
|
164
|
-
* `--headless`:
|
|
165
|
-
*
|
|
185
|
+
* `--headless`: nothing is launched and nothing listens, because the browser is on another machine.
|
|
186
|
+
* A code-display provider shows the authorization code to paste back here; a provider with only a
|
|
187
|
+
* device grant (xAI) shows a short code to confirm in that browser and settles on its own, so the
|
|
188
|
+
* same branch serves both and only the paste step differs (see `device` below).
|
|
166
189
|
*/
|
|
167
190
|
async function handleCodeLogin(name: string, deps: LoginCliDeps): Promise<void> {
|
|
168
191
|
const login = deps.runLogin ?? runLogin;
|
|
169
|
-
|
|
170
|
-
|
|
192
|
+
// A provider without a code-display page but with a device grant (xAI) is headless the same
|
|
193
|
+
// way: the browser is elsewhere and nothing listens here. It shows a code instead of asking for one.
|
|
194
|
+
const device = !supportsCodeLoginMode(name) && supportsDeviceLoginMode(name);
|
|
195
|
+
if (!device && !supportsCodeLoginMode(name)) {
|
|
196
|
+
console.error(`${name} has no headless login (code-display or device). Providers that have one: ${listCodeLoginProviders().join(", ")}`);
|
|
171
197
|
process.exit(1);
|
|
172
198
|
}
|
|
173
199
|
try {
|
|
174
200
|
await withPrompt(deps.ask, async (ask) => {
|
|
175
201
|
await login(name, {
|
|
176
202
|
onAuth: ({ url, instructions }) => {
|
|
177
|
-
|
|
178
|
-
|
|
203
|
+
// Both are provider-supplied. `--headless` for xAI is the device grant, whose instructions
|
|
204
|
+
// quote the provider's user code; a control sequence there would drive this tty.
|
|
205
|
+
console.log(`\n🔐 Open this URL in any browser to approve ${name}:\n${terminalSafeText(url)}\n`);
|
|
206
|
+
if (instructions) console.log(terminalSafeText(instructions));
|
|
179
207
|
},
|
|
180
|
-
|
|
208
|
+
// The Meta Muse device flow's last line quotes an action URL from the provider payload, so
|
|
209
|
+
// this is not a fixed sentence: it is provider-derived text on its way to a tty.
|
|
210
|
+
onProgress: (m) => console.log(` ${terminalSafeText(m)}`),
|
|
181
211
|
onManualCodeInput: async () => await ask("Paste the code shown after approval: "),
|
|
182
|
-
}, { codeMode: true });
|
|
212
|
+
}, device ? { flow: "device" } : { codeMode: true });
|
|
183
213
|
});
|
|
184
214
|
} catch (error) {
|
|
185
215
|
// Never let the raw error reach stderr: a token endpoint's error body can quote the pasted
|
|
186
216
|
// code back. Only fixed, allowlisted text and the machine-readable reason are printed.
|
|
187
|
-
|
|
217
|
+
// The reason comes from the same classifier the management API reports, so a definitive
|
|
218
|
+
// refusal (a redirect the client will not follow) reads as `oauth_authentication_failed`
|
|
219
|
+
// here and in `GET /api/oauth/status` rather than as a bad code or a network fault.
|
|
220
|
+
const reason = classifyLoginCodeError(error);
|
|
221
|
+
console.error(`\n❌ ${name} login failed (${reason}): ${publicOAuthAuthenticationErrorMessage(error)}`);
|
|
188
222
|
process.exit(1);
|
|
189
223
|
}
|
|
190
224
|
const reload = await notifyRunningProxyAfterOAuthLogin(name);
|
|
@@ -195,6 +229,21 @@ async function handleCodeLogin(name: string, deps: LoginCliDeps): Promise<void>
|
|
|
195
229
|
|
|
196
230
|
export async function handleOAuthLogin(name: string, deps: LoginCliDeps = {}, opts: LoginCliOptions = {}): Promise<void> {
|
|
197
231
|
if (name === "anthropic2") assertAnthropicInstanceLoginConfig(loadConfig(), name);
|
|
232
|
+
// Runs in-process, so there is no management API check behind it: this prompt is the gate.
|
|
233
|
+
if (requiresAntigravityRiskAcknowledgement(name)) {
|
|
234
|
+
const decision = await resolveAntigravityRiskAcknowledgement({
|
|
235
|
+
flag: opts.acceptAntigravityRisk === true,
|
|
236
|
+
// readline writes the question to stdout, so both ends must be a terminal.
|
|
237
|
+
interactive: (deps.isInteractive ?? (() => process.stdin.isTTY === true && process.stdout.isTTY === true))(),
|
|
238
|
+
agentDriven: (deps.agentDriven ?? isAgentDriven)(),
|
|
239
|
+
warn: text => console.error(text),
|
|
240
|
+
ask: question => withPrompt(deps.ask, ask => ask(question)),
|
|
241
|
+
});
|
|
242
|
+
if (decision !== "accepted") {
|
|
243
|
+
console.error(antigravityRiskDecisionMessage(decision));
|
|
244
|
+
process.exit(1);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
198
247
|
if (opts.codeMode) return handleCodeLogin(name, deps);
|
|
199
248
|
const login = deps.runLogin ?? runLogin;
|
|
200
249
|
const launch = deps.openUrl ?? openUrl;
|
|
@@ -203,17 +252,17 @@ export async function handleOAuthLogin(name: string, deps: LoginCliDeps = {}, op
|
|
|
203
252
|
await login(name, {
|
|
204
253
|
onAuth: ({ url, instructions }) => {
|
|
205
254
|
if (!url) {
|
|
206
|
-
if (instructions) console.log(instructions);
|
|
255
|
+
if (instructions) console.log(terminalSafeText(instructions));
|
|
207
256
|
return;
|
|
208
257
|
}
|
|
209
|
-
console.log(`\n🔐 Opening browser for ${name} login...\n${url}\n`);
|
|
210
|
-
if (instructions) console.log(instructions);
|
|
258
|
+
console.log(`\n🔐 Opening browser for ${name} login...\n${terminalSafeText(url)}\n`);
|
|
259
|
+
if (instructions) console.log(terminalSafeText(instructions));
|
|
211
260
|
// The controller does not await onAuth, so the launcher's answer cannot be reported from
|
|
212
261
|
// here — this returns long before it arrives. It reports itself instead, and the one
|
|
213
262
|
// thing that could collide with it waits below (#5261).
|
|
214
263
|
browser.track(launch(url));
|
|
215
264
|
},
|
|
216
|
-
onProgress: (m) => console.log(` ${m}`),
|
|
265
|
+
onProgress: (m) => console.log(` ${terminalSafeText(m)}`),
|
|
217
266
|
onManualCodeInput: async () => {
|
|
218
267
|
// "or wait for browser" is a lie if nothing opened, and a warning printed after readline
|
|
219
268
|
// has drawn the prompt lands on the line the user is typing on.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AnthropicTokenError } from "./anthropic";
|
|
2
2
|
import { parseCallbackInput } from "./callback-server";
|
|
3
|
+
import { XaiRedirectRefusedError, XaiTokenRequestError } from "./xai";
|
|
3
4
|
import { retainedUtf8Bytes } from "../lib/admission";
|
|
4
5
|
import type { GenerationContext } from "../lib/state-store-sweeper";
|
|
5
6
|
|
|
@@ -35,7 +36,14 @@ export type LoginCodeError =
|
|
|
35
36
|
| "no_pending_login"
|
|
36
37
|
| "provider_unreachable"
|
|
37
38
|
| "malformed_input"
|
|
38
|
-
| "code_mode_unsupported"
|
|
39
|
+
| "code_mode_unsupported"
|
|
40
|
+
/**
|
|
41
|
+
* The provider answered definitively and the client will not retry: today, a redirect the
|
|
42
|
+
* device poll refused to follow. Distinct from `invalid_or_expired_code` (the input was
|
|
43
|
+
* wrong) and `provider_unreachable` (the request never got an answer), because both of those
|
|
44
|
+
* invite a retry that can only fail the same way. Same spelling as the CLI's terminal reason.
|
|
45
|
+
*/
|
|
46
|
+
| "oauth_authentication_failed";
|
|
39
47
|
|
|
40
48
|
export interface LoginFlowState {
|
|
41
49
|
error?: string;
|
|
@@ -176,12 +184,27 @@ export class CodeLoginUnsupportedError extends Error {
|
|
|
176
184
|
* forwarded: a provider body can quote the submitted code back, and this response is the one
|
|
177
185
|
* surface a hosted caller renders to a user.
|
|
178
186
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
187
|
+
* Anthropic code exchanges and xAI device grants carry typed provider failures; other
|
|
188
|
+
* providers retain the generic branches.
|
|
189
|
+
*
|
|
190
|
+
* This is the single source of truth for the machine-readable reason: the code-mode paste
|
|
191
|
+
* response, `GET /api/oauth/status` and the headless CLI all read it, so a new terminal cause is
|
|
192
|
+
* added here once rather than special-cased at each surface.
|
|
181
193
|
*/
|
|
182
194
|
export function classifyLoginCodeError(error: unknown): LoginCodeError {
|
|
183
195
|
const message = error instanceof Error ? error.message : "";
|
|
184
196
|
if (message.startsWith("OAuth callback cancelled")) return "no_pending_login";
|
|
197
|
+
// A refused redirect is a definitive server answer, not a transport fault and not a bad code:
|
|
198
|
+
// the request was never delivered anywhere it was allowed to go, and replaying it would be
|
|
199
|
+
// refused identically. Checked before the status-less branches, which would otherwise read it
|
|
200
|
+
// as a retriable network failure or as an invalid code.
|
|
201
|
+
if (error instanceof XaiRedirectRefusedError) return "oauth_authentication_failed";
|
|
202
|
+
if (error instanceof XaiTokenRequestError) {
|
|
203
|
+
if (error.status === 429 || (error.status !== undefined && error.status >= 500)) return "provider_unreachable";
|
|
204
|
+
if (error.oauthError === "expired_token" || error.oauthError === "invalid_grant") return "invalid_or_expired_code";
|
|
205
|
+
if (error.status === undefined) return "provider_unreachable";
|
|
206
|
+
return "oauth_authentication_failed";
|
|
207
|
+
}
|
|
185
208
|
if (error instanceof AnthropicTokenError) {
|
|
186
209
|
return error.httpStatus !== undefined && error.httpStatus >= 500
|
|
187
210
|
? "provider_unreachable"
|
package/src/oauth/meta-muse.ts
CHANGED
|
@@ -37,7 +37,7 @@ const VALIDATE_TIMEOUT_MS = 10_000;
|
|
|
37
37
|
/**
|
|
38
38
|
* Shown BEFORE any credential is read.
|
|
39
39
|
*
|
|
40
|
-
* `login-cli.ts`
|
|
40
|
+
* `login-cli.ts` turns `onProgress` into a prefixed `console.log` line and never reads the
|
|
41
41
|
* registry note, so this is the CLI's only warning surface. The GUI ignores it because
|
|
42
42
|
* `OAuthTosWarningModal` has already been acknowledged by then.
|
|
43
43
|
*/
|
package/src/oauth/pool-kernel.ts
CHANGED
|
@@ -10,8 +10,8 @@ export const POOL_KEY_ANTHROPIC = "anthropic";
|
|
|
10
10
|
* with the two dedicated kinds, and so `reconcilePoolRotationState` can recognise
|
|
11
11
|
* the entry as sweepable rather than skipping it as unknown.
|
|
12
12
|
*/
|
|
13
|
-
export function genericPoolKey(providerName: string): string {
|
|
14
|
-
return `generic:${providerName}`;
|
|
13
|
+
export function genericPoolKey(providerName: string, family?: string): string {
|
|
14
|
+
return family ? `generic:${providerName}:${family}` : `generic:${providerName}`;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
interface SelectionState {
|
|
@@ -309,7 +309,7 @@ export function reconcilePoolRotationState(context: GenerationContext): number {
|
|
|
309
309
|
: poolKey === POOL_KEY_CODEX || poolKey.startsWith(`${POOL_KEY_CODEX}:`)
|
|
310
310
|
? context.codexAccountIds
|
|
311
311
|
: poolKey.startsWith("generic:")
|
|
312
|
-
? genericIds.get(poolKey.slice("generic:".length)) ?? new Set<string>()
|
|
312
|
+
? genericIds.get(poolKey.slice("generic:".length).split(":")[0]!) ?? new Set<string>()
|
|
313
313
|
: null;
|
|
314
314
|
if (!valid) continue;
|
|
315
315
|
if (valid.size === 0) {
|