|
1 | | -import { readMiniMaxCliCredentialsCached } from "../cli-credentials.js"; |
2 | | -import { EXTERNAL_CLI_SYNC_TTL_MS, MINIMAX_CLI_PROFILE_ID } from "./constants.js"; |
| 1 | +import { |
| 2 | + readCodexCliCredentialsCached, |
| 3 | + readMiniMaxCliCredentialsCached, |
| 4 | +} from "../cli-credentials.js"; |
| 5 | +import { |
| 6 | + EXTERNAL_CLI_SYNC_TTL_MS, |
| 7 | + MINIMAX_CLI_PROFILE_ID, |
| 8 | + OPENAI_CODEX_DEFAULT_PROFILE_ID, |
| 9 | +} from "./constants.js"; |
3 | 10 | import { log } from "./constants.js"; |
4 | 11 | import { |
5 | 12 | areOAuthCredentialsEquivalent, |
@@ -29,6 +36,12 @@ type ExternalCliSyncProvider = { |
29 | 36 | profileId: string; |
30 | 37 | provider: string; |
31 | 38 | readCredentials: () => OAuthCredential | null; |
| 39 | + // bootstrapOnly providers adopt the external CLI credential only to |
| 40 | + // seed an empty slot; once a local OAuth credential exists for the |
| 41 | + // profile, the local refresh token is treated as canonical and the |
| 42 | + // CLI state must not replace or shadow it. Codex requires this to |
| 43 | + // avoid clobbering a locally refreshed token with stale CLI state. |
| 44 | + bootstrapOnly?: boolean; |
32 | 45 | }; |
33 | 46 |
|
34 | 47 | function normalizeAuthIdentityToken(value: string | undefined): string | undefined { |
@@ -72,6 +85,12 @@ export function isSafeToUseExternalCliCredential( |
72 | 85 | } |
73 | 86 |
|
74 | 87 | const EXTERNAL_CLI_SYNC_PROVIDERS: ExternalCliSyncProvider[] = [ |
| 88 | + { |
| 89 | + profileId: OPENAI_CODEX_DEFAULT_PROFILE_ID, |
| 90 | + provider: "openai-codex", |
| 91 | + readCredentials: () => readCodexCliCredentialsCached({ ttlMs: EXTERNAL_CLI_SYNC_TTL_MS }), |
| 92 | + bootstrapOnly: true, |
| 93 | + }, |
75 | 94 | { |
76 | 95 | profileId: MINIMAX_CLI_PROFILE_ID, |
77 | 96 | provider: "minimax-portal", |
@@ -103,6 +122,13 @@ export function readExternalCliBootstrapCredential(params: { |
103 | 122 | if (!provider) { |
104 | 123 | return null; |
105 | 124 | } |
| 125 | + // bootstrapOnly providers must not replace an existing local credential |
| 126 | + // during runtime refresh. The oauth-manager only calls this hook when a |
| 127 | + // local credential is already present, so returning null here keeps the |
| 128 | + // locally stored refresh token canonical. |
| 129 | + if (provider.bootstrapOnly) { |
| 130 | + return null; |
| 131 | + } |
106 | 132 | return provider.readCredentials(); |
107 | 133 | } |
108 | 134 |
|
@@ -132,6 +158,13 @@ export function resolveExternalCliAuthProfiles( |
132 | 158 | }); |
133 | 159 | continue; |
134 | 160 | } |
| 161 | + if (providerConfig.bootstrapOnly && existingOAuth) { |
| 162 | + log.debug("kept local oauth over external cli bootstrap-only provider", { |
| 163 | + profileId: providerConfig.profileId, |
| 164 | + provider: providerConfig.provider, |
| 165 | + }); |
| 166 | + continue; |
| 167 | + } |
135 | 168 | if (existingOAuth && !isSafeToUseExternalCliCredential(existingOAuth, creds)) { |
136 | 169 | log.warn("refused external cli oauth bootstrap: identity mismatch", { |
137 | 170 | profileId: providerConfig.profileId, |
|
0 commit comments