@humain/humain-code 0.8.2 → 0.8.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/CHANGELOG.md +11 -0
- package/dist/bundle/chunks/{chunk-EFY2QPVP.js → chunk-2XD7TLKB.js} +4 -4
- package/dist/bundle/chunks/{chunk-U4EAJPMO.js → chunk-4GB7A76U.js} +39 -35
- package/dist/bundle/chunks/{chunk-PJXBU6CR.js → chunk-7LSTTCSC.js} +111 -89
- package/dist/bundle/chunks/{chunk-H2B3WLIM.js → chunk-AW24RHGJ.js} +1 -1
- package/dist/bundle/chunks/{chunk-3PJ7NPWN.js → chunk-B3ZLWVDA.js} +1 -1
- package/dist/bundle/chunks/{chunk-H7UPU2SH.js → chunk-MUN4ZZZP.js} +706 -703
- package/dist/bundle/chunks/chunk-S2US54IU.js +37 -0
- package/dist/bundle/chunks/{chunk-G2QMON4O.js → chunk-VSXVZVBE.js} +3 -3
- package/dist/bundle/chunks/{chunk-JQBZUFH7.js → chunk-ZAHVC5V2.js} +175 -164
- package/dist/bundle/chunks/{compat-ELBUCH6U.js → compat-4ILE5BEC.js} +1 -1
- package/dist/bundle/chunks/{dist-QSYDYE3Y.js → dist-I6CI3CG5.js} +6 -6
- package/dist/bundle/chunks/{dist-NERIS6SW.js → dist-NXHRL2KY.js} +1 -1
- package/dist/bundle/chunks/{entry-SRYLSS5P.js → entry-6XDR2IDE.js} +1 -1
- package/dist/bundle/chunks/{flow-implementer-3P3BHQ7E.js → flow-implementer-XOP4MG5X.js} +3 -3
- package/dist/bundle/chunks/{inprocess-3PDJKE5F.js → inprocess-MBKFGDM2.js} +4 -4
- package/dist/bundle/chunks/{interactive-mode-SDUO5OLD.js → interactive-mode-3322RQEH.js} +2 -2
- package/dist/bundle/chunks/{virtual-modules-IU5KWB2C.js → virtual-modules-47MGUPYN.js} +3 -3
- package/dist/bundle/cli-runtime.js +3 -3
- package/dist/bundle/index.js +6 -6
- package/dist/bundle/rpc-entry.js +3 -3
- package/dist/coordination/adapter/delivery.d.ts +27 -0
- package/dist/coordination/adapter/delivery.d.ts.map +1 -1
- package/dist/coordination/adapter/delivery.js +164 -4
- package/dist/coordination/adapter/delivery.js.map +1 -1
- package/dist/coordination/adapter/index.d.ts.map +1 -1
- package/dist/coordination/adapter/index.js +31 -5
- package/dist/coordination/adapter/index.js.map +1 -1
- package/dist/coordination/adapter/presence.d.ts +5 -0
- package/dist/coordination/adapter/presence.d.ts.map +1 -1
- package/dist/coordination/adapter/presence.js +25 -3
- package/dist/coordination/adapter/presence.js.map +1 -1
- package/dist/coordination/adapter/question-routing.d.ts +7 -0
- package/dist/coordination/adapter/question-routing.d.ts.map +1 -0
- package/dist/coordination/adapter/question-routing.js +40 -0
- package/dist/coordination/adapter/question-routing.js.map +1 -0
- package/dist/coordination/adapter/receipts.d.ts +7 -0
- package/dist/coordination/adapter/receipts.d.ts.map +1 -1
- package/dist/coordination/adapter/receipts.js +25 -2
- package/dist/coordination/adapter/receipts.js.map +1 -1
- package/dist/coordination/adapter/tool.d.ts +19 -3
- package/dist/coordination/adapter/tool.d.ts.map +1 -1
- package/dist/coordination/adapter/tool.js +93 -19
- package/dist/coordination/adapter/tool.js.map +1 -1
- package/dist/coordination/client/client.d.ts +2 -2
- package/dist/coordination/client/client.d.ts.map +1 -1
- package/dist/coordination/client/client.js +4 -0
- package/dist/coordination/client/client.js.map +1 -1
- package/dist/coordination/transport/protocol.d.ts.map +1 -1
- package/dist/coordination/transport/protocol.js +23 -0
- package/dist/coordination/transport/protocol.js.map +1 -1
- package/dist/coordination/transport/types.d.ts +11 -1
- package/dist/coordination/transport/types.d.ts.map +1 -1
- package/dist/coordination/transport/types.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +14 -8
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/oauth-account-pool.d.ts +14 -0
- package/dist/core/oauth-account-pool.d.ts.map +1 -1
- package/dist/core/oauth-account-pool.js +166 -14
- package/dist/core/oauth-account-pool.js.map +1 -1
- package/dist/core/run-outcome.d.ts +1 -1
- package/dist/core/run-outcome.d.ts.map +1 -1
- package/dist/core/run-outcome.js +2 -2
- package/dist/core/run-outcome.js.map +1 -1
- package/dist/core/run-preflight.d.ts.map +1 -1
- package/dist/core/run-preflight.js +15 -8
- package/dist/core/run-preflight.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +2 -0
- package/dist/main.js.map +1 -1
- package/docs/cli.md +6 -0
- package/docs/coordination.md +16 -4
- package/docs/environment-variables.md +2 -1
- package/docs/providers.md +5 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/bundle/chunks/chunk-UEW6TUSP.js +0 -36
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-account-pool.js","sourceRoot":"","sources":["../../src/core/oauth-account-pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAWH,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACzG,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAEN,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,GAC1B,MAAM,mBAAmB,CAAC;AAgJ3B,kFAAkF;AAClF,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC;AACjD,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,GAAG,MA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,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;gBAChE,CAAC,EAAE,OAAO,CAAC,CAAC;gBACZ,6EAA6E;gBAC7E,IAAI,SAAS,CAAC,IAAI;oBAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;gBAC/D,OAAO,OAAO,CAAC;YAChB,CAAC;oBAAS,CAAC;gBACV,SAAS,CAAC,MAAM,EAAE,CAAC;gBACnB,QAAQ,CAAC,MAAM,EAAE,CAAC;YACnB,CAAC;QACF,CAAC,CAAC,EAAE,CAAC;QACL,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YACtB,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CACpC,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CACf,CAAC;YACF,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAChC,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,gBAAgB,CAAC;IACzB,CAAC;CACD","sourcesContent":["/**\n * Multi-account credential pool with OAuth-only runtime APIs.\n *\n * auth.json keeps holding exactly one credential per provider (the ACTIVE account) so pi-ai reads\n * and refreshes it unchanged. This module stores OAuth and literal API-key entries in the versioned\n * `oauth-accounts.json` next to auth.json. Generalized additions use random local keys; existing\n * OAuth runtime APIs and migrated keys remain usable until runtime/UI integration.\n *\n * Reads (`list`, `getActive`, `getCachedAccounts`) never write: they merge the credential currently\n * stored in auth.json into the returned view in memory only. Mutations (`add`, `setActive`,\n * `remove`, `failover`, `adoptCurrent`) first sync the auth.json credential back into the pool\n * (pi-ai may have refreshed it), then write the pool file and, when the active account changed,\n * the new active credential into auth.json. All of this happens under one pool-file lock.\n * `clearExhaustion` only clears matching stored quota markers, rechecking auth and merging its changes only in cache.\n */\n\nimport type {\n\tApiKeyCredential,\n\tAssistantMessage,\n\tAuthOperationOptions,\n\tCredential,\n\tCredentialDeleteOptions,\n\tCredentialStore,\n\tOAuthCredential,\n} from \"@earendil-works/pi-ai\";\nimport { getOpenAICodexTokenIdentity } from \"@earendil-works/pi-ai\";\nimport { randomUUID } from \"crypto\";\nimport { closeSync, existsSync, fchmodSync, fsyncSync, openSync, readFileSync, writeFileSync } from \"fs\";\nimport { join } from \"path\";\nimport { getAgentDir } from \"../config.ts\";\nimport { normalizePath } from \"../utils/paths.ts\";\nimport { stripBom } from \"../utils/text.ts\";\nimport {\n\ttype AuthStorageBackend,\n\tFileAuthStorageBackend,\n\tgetAccountCredentialStore,\n\tInMemoryAuthStorageBackend,\n} from \"./auth-storage.ts\";\n\ntype UsageRefreshResult = OAuthAccount | \"refresh_failed\" | \"refresh_rejected\";\ntype UsageCredentialRefresh = (\n\tcredential: OAuthCredential,\n) => Promise<OAuthCredential | \"refresh_failed\" | \"refresh_rejected\">;\n\nexport interface OAuthAccountIdentity {\n\t/** Stable per-provider account key (for example the ChatGPT account id). */\n\tkey: string;\n\t/** Human-readable default label (email when available). */\n\tlabel: string;\n}\n\n/** Derives provider-specific identity before the generic credential fields are considered. */\nexport type OAuthAccountIdentityResolver = (credential: OAuthCredential) => OAuthAccountIdentity | undefined;\n\nexport interface PoolAccount<T extends Credential = Credential> {\n\tkey: string;\n\tlabel: string;\n\tcredential: T;\n\t/** Epoch ms until which the account is treated as out of quota. */\n\texhaustedUntil?: number;\n\t/** Observed failure count, used for bounded cooldown backoff. */\n\tquotaFailures?: number;\n\t/** Monotonic cooldown observation revision; absent legacy values mean zero. */\n\tcooldownRevision?: number;\n\tactive: boolean;\n}\n\nexport type OAuthAccount = PoolAccount<OAuthCredential>;\n\nexport type AccountRemoveResult<T extends Credential = Credential> =\n\t| { status: \"removed\"; removed: PoolAccount<T>; active: PoolAccount<T> | undefined }\n\t| { status: \"unmatched\" }\n\t| { status: \"changed\" };\n\nexport type OAuthAccountRemoveResult =\n\t| {\n\t\t\tstatus: \"removed\";\n\t\t\tremoved: OAuthAccount;\n\t\t\t/** Account promoted to active, or undefined when the pool is now empty. */\n\t\t\tactive: OAuthAccount | undefined;\n\t }\n\t/** No account has the key, or (without a key) auth.json holds no credential of an account. Nothing changed. */\n\t| { status: \"unmatched\" }\n\t/** auth.json changed under the auth.json lock; nothing removed, but the latest credential is synced into the pool. */\n\t| { status: \"changed\" };\n\nexport interface OAuthAccountFailoverOptions extends AuthOperationOptions {\n\t/**\n\t * Account key the caller observed as active. Checked under the pool lock against the OAuth credential stored\n\t * in auth.json, and again at the auth.json write; the failover is skipped (`active_changed`) when auth.json\n\t * holds no OAuth credential, an unidentifiable one, or another account's.\n\t * Aborting `signal` before the auth.json write throws and changes nothing; after it, the operation completes.\n\t */\n\texpectedActiveKey: string;\n\t/** Epoch ms until which the expected account is treated as out of quota. Omit to leave its marker unchanged. */\n\texhaustedUntil?: number;\n\t/** Reference time for exhaustion checks. Defaults to `Date.now()`. */\n\tnow?: number;\n\t/** Account keys that must not be selected as the failover target (for example accounts already tried). */\n\tskipKeys?: ReadonlySet<string>;\n\t/** Runtime quota rotation records a preferred account and applies the bounded cooldown when reset is unknown. */\n\ttrackPreferred?: boolean;\n\t/** Synchronous live policy check under the auth lock, before any activation checkpoint or credential commit. */\n\tcanActivate?: (from: PoolAccount, to: PoolAccount) => boolean;\n}\n\nexport interface AccountFailoverOptions extends OAuthAccountFailoverOptions {\n\t/** Caller has resolved explicit user consent; target must still exist as a same-provider stored API key. */\n\tapiKeyFallback?: string;\n\t/** Only subscription-marked API-key providers may rotate among keys automatically. */\n\tallowApiKeyRotation?: boolean;\n\t/** An OAuth rotation already recorded this failure before considering the consent target. */\n\tmarkExhausted?: boolean;\n\t/** Ordered same-type targets, replacing the round-robin order. Keys not in the pool are ignored. */\n\tcandidateKeys?: readonly string[];\n\t/** Live eligibility of a same-type target, evaluated under the pool lock. */\n\tcandidateFilter?: (from: PoolAccount, to: PoolAccount) => boolean;\n}\n\nexport type AccountFailoverResult =\n\t| { switched: true; from: PoolAccount; to: PoolAccount; total: number }\n\t| {\n\t\t\tswitched: false;\n\t\t\treason: \"active_changed\" | \"exhausted\";\n\t\t\tactive: PoolAccount | undefined;\n\t\t\ttotal: number;\n\t\t\tearliestResetAt: number | undefined;\n\t };\n\nexport type OAuthAccountFailoverResult =\n\t| { switched: true; from: OAuthAccount; to: OAuthAccount; total: number }\n\t| {\n\t\t\tswitched: false;\n\t\t\t/**\n\t\t\t * `active_changed`: auth.json no longer holds the expected account (another process switched\n\t\t\t * accounts, or the credential is not a resolvable OAuth one); nothing was marked.\n\t\t\t * `exhausted`: no other account is usable (the expected account is marked only when requested).\n\t\t\t */\n\t\t\treason: \"active_changed\" | \"exhausted\";\n\t\t\t/** Currently active account (after sync), if auth.json holds a resolvable OAuth credential. */\n\t\t\tactive: OAuthAccount | undefined;\n\t\t\ttotal: number;\n\t\t\t/** Earliest `exhaustedUntil` still in the future among pooled accounts. */\n\t\t\tearliestResetAt: number | undefined;\n\t };\n\nexport interface OAuthAccountCreditFallbackOptions extends AuthOperationOptions {\n\t/**\n\t * Account key the caller observed as active. Checked under the pool lock against the OAuth credential stored\n\t * in auth.json, and again at the auth.json write; nothing changes (`active_changed`) when it no longer matches.\n\t * Aborting `signal` before the auth.json write throws and changes nothing; after it, the operation completes.\n\t */\n\texpectedActiveKey: string;\n\t/** Account that reported exhausted plan quota with credits available; selected for possible credit use. */\n\ttargetKey: string;\n\t/** Account keys that are not untried (for example accounts already tried this run). */\n\tskipKeys?: ReadonlySet<string>;\n\t/** Reference time for exhaustion checks. Defaults to `Date.now()`. */\n\tnow?: number;\n\t/** Reauthorize even when credit recovery would keep the current credential. */\n\tcanActivate?: (from: PoolAccount, to: PoolAccount) => boolean;\n}\n\nexport type OAuthAccountCreditFallbackResult =\n\t/** auth.json no longer holds the expected account; nothing changed. `active` is the current resolvable active account. */\n\t| { outcome: \"active_changed\"; active: OAuthAccount | undefined }\n\t/** An untried usable account exists now and was activated. */\n\t| { outcome: \"untried\"; account: OAuthAccount }\n\t/** The credit-capable target was activated. */\n\t| { outcome: \"credit\"; account: OAuthAccount }\n\t/** The credit-capable target no longer exists; nothing changed. */\n\t| { outcome: \"missing\" };\n\ninterface StoredAccount {\n\tcredential: Credential;\n\tlabel: string;\n\texhaustedUntil?: number;\n\tquotaFailures?: number;\n\tcooldownRevision?: number;\n}\n\n/** Tunable fallback cooldown bounds; never probe a provider in the background. */\nexport const ACCOUNT_RETURN_COOLDOWN_MS = 60_000;\nexport const ACCOUNT_RETURN_MAX_COOLDOWN_MS = 30 * 60_000;\n\ninterface StoredProviderPool {\n\tactive: string;\n\taccounts: Record<string, StoredAccount>;\n\t/** Next local key suffix. Retained even when every account has been removed. */\n\tnextLocalAccountId?: number;\n\t/** Persisted across sessions/Flow. A manual activation cancels this pending return. */\n\treturnTo?: { preferredKey: string; fromKey: string };\n}\n\ntype PoolData = Record<string, StoredProviderPool>;\n\nexport function resolveOpenAICodexAccountIdentity(credential: OAuthCredential): OAuthAccountIdentity | undefined {\n\tconst identity = getOpenAICodexTokenIdentity(credential.access);\n\tif (!identity) return undefined;\n\treturn { key: identity.accountId, label: identity.email ?? identity.accountId.slice(0, 8) };\n}\n\nexport const OAUTH_ACCOUNT_IDENTITY_FIELDS = [\"accountKey\", \"accountId\", \"organizationId\", \"accountLabel\"] as const;\n\n/** Identity values are persisted and displayed: bounded, printable, and free of the credential's tokens. */\nfunction isSafeIdentityValue(value: unknown, credential: Credential): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.trim().length > 0 &&\n\t\tvalue.length <= 320 &&\n\t\t!/[\\p{Cc}\\p{Cf}]/u.test(value) &&\n\t\t!(\n\t\t\tcredential.type === \"oauth\"\n\t\t\t\t? [credential.access, credential.refresh]\n\t\t\t\t: [credential.key ?? \"\", ...Object.values(credential.env ?? {})]\n\t\t).some((token) => token.length > 0 && value.includes(token))\n\t);\n}\n\n/** Account keys are also object keys: never a name `Object.prototype` defines (`__proto__`, `constructor`, ...). */\nfunction isSafeAccountKey(key: unknown, credential: Credential): key is string {\n\treturn isSafeIdentityValue(key, credential) && !(key in Object.prototype);\n}\n\n/** Resolve non-secret identity metadata, preferring the stamped pool key. */\nexport function resolveGenericAccountIdentity(credential: OAuthCredential): OAuthAccountIdentity | undefined {\n\tconst organization = isSafeIdentityValue(credential.organizationId, credential)\n\t\t? `-org-${credential.organizationId}`\n\t\t: \"\";\n\tconst accountId = isSafeIdentityValue(credential.accountId, credential)\n\t\t? `acct-${credential.accountId}${organization}`\n\t\t: undefined;\n\tconst key = [credential.accountKey, accountId].find((value): value is string => isSafeAccountKey(value, credential));\n\tif (!key) return undefined;\n\tconst label = isSafeIdentityValue(credential.accountLabel, credential) ? credential.accountLabel : key;\n\treturn { key, label };\n}\n\nfunction reserveLocalAccountKeys(pool: StoredProviderPool): void {\n\t// Older version-1 pools have no counter; also reserve keys restored from auth.json after a failed pool write.\n\tfor (const key of Object.keys(pool.accounts)) {\n\t\tif (!/^local-\\d+$/.test(key)) continue;\n\t\tconst index = Number(key.slice(6));\n\t\tif (!Number.isSafeInteger(index) || index >= Number.MAX_SAFE_INTEGER) {\n\t\t\tthrow new Error(\"Local OAuth account key range exhausted\");\n\t\t}\n\t\tpool.nextLocalAccountId = Math.max(pool.nextLocalAccountId ?? 1, index + 1);\n\t}\n}\n\nfunction nextLocalAccountIdentity(pool: StoredProviderPool): OAuthAccountIdentity {\n\treserveLocalAccountKeys(pool);\n\tconst index = pool.nextLocalAccountId ?? 1;\n\tif (index >= Number.MAX_SAFE_INTEGER) throw new Error(\"Local OAuth account key range exhausted\");\n\tpool.nextLocalAccountId = index + 1;\n\treturn { key: `local-${index}`, label: `Account ${index}` };\n}\n\nexport const DEFAULT_OAUTH_ACCOUNT_IDENTITY_RESOLVERS: ReadonlyMap<string, OAuthAccountIdentityResolver> = new Map([\n\t[\"openai-codex\", resolveOpenAICodexAccountIdentity],\n]);\n\nconst USAGE_LIMIT_ERROR_CODE_PATTERN = /usage_limit_reached|usage_not_included|rate_limit_exceeded|insufficient_quota/i;\n\nconst MS_PER_MINUTE = 60_000;\n/** 366 days plus one day of margin: the furthest a reported reset time may lie in the future. */\nconst MAX_RESET_HORIZON_MS = (527040 + 1440) * MS_PER_MINUTE;\n\n/** A reset time is plausible only when it lies in the future and within the longest rate-limit window. */\nfunction isPlausibleResetAt(value: number, nowMs: number): boolean {\n\treturn value > nowMs && value <= nowMs + MAX_RESET_HORIZON_MS;\n}\n\nexport interface UsageLimitSignal {\n\t/** Epoch ms when the provider expects the limit to reset, when reported. */\n\tresetsAt: number | undefined;\n}\n\n/**\n * Inspect the latest `provider_http_error` diagnostic of a failed assistant message and report\n * whether it is a terminal usage-limit failure that warrants switching OAuth accounts.\n * Authentication failures (401/403) are never usage limits, whatever code or reset time they carry.\n */\nexport function getUsageLimitSignal(message: AssistantMessage): UsageLimitSignal | undefined {\n\tif (message.stopReason !== \"error\") return undefined;\n\tconst nowMs = Date.now();\n\tconst details = message.diagnostics?.findLast((entry) => entry.type === \"provider_http_error\")?.details;\n\tif (details?.retryable !== false) return undefined;\n\tif (details.status === 401 || details.status === 403) return undefined;\n\tconst resetsAt =\n\t\ttypeof details.resetsAt === \"number\" &&\n\t\tNumber.isFinite(details.resetsAt) &&\n\t\tisPlausibleResetAt(details.resetsAt, nowMs)\n\t\t\t? details.resetsAt\n\t\t\t: undefined;\n\tconst isUsageLimit =\n\t\tdetails.status === 429 ||\n\t\t(typeof details.code === \"string\" && USAGE_LIMIT_ERROR_CODE_PATTERN.test(details.code)) ||\n\t\tresetsAt !== undefined;\n\treturn isUsageLimit ? { resetsAt } : undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nexport interface CodexRateLimitWindow {\n\tusedPercent: number;\n\twindowMinutes?: number;\n\t/** Epoch ms. */\n\tresetsAt?: number;\n}\n\nexport interface CodexRateLimitSnapshot {\n\tprimary?: CodexRateLimitWindow;\n\tsecondary?: CodexRateLimitWindow;\n\tcredits?: { hasCredits: boolean; unlimited: boolean; balance?: string };\n\trateLimitReachedType?: string;\n}\n\nconst BALANCE_PATTERN = /^-?\\d{1,15}(\\.\\d{1,8})?$/;\nconst REACHED_TYPE_PATTERN = /^[a-z0-9_]{1,64}$/;\n/** 366 days: the longest rate-limit window the provider could plausibly report. */\nconst MAX_WINDOW_MINUTES = 527040;\n\nfunction finiteNumber(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\nfunction parseRateLimitWindow(value: unknown, nowMs: number): CodexRateLimitWindow | undefined {\n\tif (!isRecord(value)) return undefined;\n\tconst usedPercent = finiteNumber(value.usedPercent);\n\tif (usedPercent === undefined || usedPercent < 0 || usedPercent > 1000) return undefined;\n\tconst window: CodexRateLimitWindow = { usedPercent };\n\tconst windowMinutes = finiteNumber(value.windowMinutes);\n\tif (windowMinutes !== undefined && windowMinutes > 0 && windowMinutes <= MAX_WINDOW_MINUTES) {\n\t\twindow.windowMinutes = windowMinutes;\n\t}\n\tconst resetsAt = finiteNumber(value.resetsAt);\n\tif (resetsAt !== undefined && isPlausibleResetAt(resetsAt, nowMs)) window.resetsAt = resetsAt;\n\treturn window;\n}\n\n/** Read the latest `provider_rate_limit` diagnostic of an assistant message, ignoring malformed fields. */\nexport function getRateLimitSnapshot(message: AssistantMessage): CodexRateLimitSnapshot | undefined {\n\tconst details = message.diagnostics?.findLast((entry) => entry.type === \"provider_rate_limit\")?.details;\n\tif (!isRecord(details)) return undefined;\n\tconst nowMs = Date.now();\n\tconst snapshot: CodexRateLimitSnapshot = {};\n\tconst primary = parseRateLimitWindow(details.primary, nowMs);\n\tif (primary) snapshot.primary = primary;\n\tconst secondary = parseRateLimitWindow(details.secondary, nowMs);\n\tif (secondary) snapshot.secondary = secondary;\n\tconst credits = details.credits;\n\tif (isRecord(credits) && typeof credits.hasCredits === \"boolean\" && typeof credits.unlimited === \"boolean\") {\n\t\tsnapshot.credits = { hasCredits: credits.hasCredits, unlimited: credits.unlimited };\n\t\tconst balance = typeof credits.balance === \"string\" ? credits.balance.trim() : \"\";\n\t\tif (BALANCE_PATTERN.test(balance)) snapshot.credits.balance = balance;\n\t}\n\tif (typeof details.rateLimitReachedType === \"string\" && REACHED_TYPE_PATTERN.test(details.rateLimitReachedType))\n\t\tsnapshot.rateLimitReachedType = details.rateLimitReachedType;\n\treturn snapshot;\n}\n\nexport interface QuotaExhaustionSignal {\n\t/**\n\t * usage_limit: request failed because plan quota is exhausted.\n\t * credits: a completed response was served while a plan window was reported at 100% or more and credits were\n\t * available, so the response may be billed to credits. The provider does not confirm billing.\n\t */\n\tkind: \"usage_limit\" | \"credits\";\n\tresetsAt: number | undefined;\n\t/** true/false when the provider reported credit state; undefined when unknown. */\n\tcreditsAvailable: boolean | undefined;\n\t/**\n\t * \"possible\" when credits may be used or billed (the credits kind, or a usage limit with credits available).\n\t * There is no confirmed-billing signal: the provider never reports that a response was billed to credits.\n\t */\n\tcreditUse?: \"possible\";\n}\n\nfunction latestExhaustedResetAt(snapshot: CodexRateLimitSnapshot | undefined): number | undefined {\n\tconst resets = [snapshot?.primary, snapshot?.secondary]\n\t\t.filter((window) => window !== undefined && window.usedPercent >= 100)\n\t\t.map((window) => window?.resetsAt)\n\t\t.filter((value): value is number => value !== undefined);\n\treturn resets.length > 0 ? Math.max(...resets) : undefined;\n}\n\n/**\n * Classify an assistant message as a quota exhaustion: either a terminal usage-limit failure, or a\n * completed response reporting exhausted plan quota with credits available and possible credit use.\n */\nexport function getQuotaExhaustionSignal(message: AssistantMessage): QuotaExhaustionSignal | undefined {\n\tconst httpDetails = message.diagnostics?.findLast((entry) => entry.type === \"provider_http_error\")?.details;\n\tconst snapshot = getRateLimitSnapshot(message);\n\n\tconst usageLimit = getUsageLimitSignal(message);\n\tif (usageLimit) {\n\t\tconst reachedType =\n\t\t\ttypeof httpDetails?.rateLimitReachedType === \"string\"\n\t\t\t\t? httpDetails.rateLimitReachedType\n\t\t\t\t: snapshot?.rateLimitReachedType;\n\t\tlet creditsAvailable: boolean | undefined;\n\t\tif (reachedType?.endsWith(\"_credits_depleted\")) creditsAvailable = false;\n\t\telse if (snapshot?.credits) creditsAvailable = snapshot.credits.unlimited || snapshot.credits.hasCredits;\n\t\treturn {\n\t\t\tkind: \"usage_limit\",\n\t\t\tresetsAt: usageLimit.resetsAt ?? latestExhaustedResetAt(snapshot),\n\t\t\tcreditsAvailable,\n\t\t\t...(creditsAvailable === true ? { creditUse: \"possible\" as const } : {}),\n\t\t};\n\t}\n\n\tif (message.stopReason !== \"stop\" && message.stopReason !== \"length\" && message.stopReason !== \"toolUse\") {\n\t\treturn undefined;\n\t}\n\tconst credits = snapshot?.credits;\n\tif (!snapshot || !credits?.hasCredits || credits.unlimited) return undefined;\n\tconst exhausted = [snapshot.primary, snapshot.secondary].some((window) => window && window.usedPercent >= 100);\n\tif (!exhausted) return undefined;\n\treturn {\n\t\tkind: \"credits\",\n\t\tresetsAt: latestExhaustedResetAt(snapshot),\n\t\tcreditsAvailable: true,\n\t\tcreditUse: \"possible\",\n\t};\n}\n\nfunction isOAuthCredential(value: unknown): value is OAuthCredential {\n\treturn (\n\t\tisRecord(value) &&\n\t\tvalue.type === \"oauth\" &&\n\t\ttypeof value.access === \"string\" &&\n\t\ttypeof value.refresh === \"string\" &&\n\t\ttypeof value.expires === \"number\" &&\n\t\tNumber.isFinite(value.expires)\n\t);\n}\n\nfunction isApiKeyCredential(value: unknown): value is ApiKeyCredential {\n\treturn (\n\t\tisRecord(value) &&\n\t\tvalue.type === \"api_key\" &&\n\t\ttypeof value.key === \"string\" &&\n\t\tvalue.key.trim().length > 0 &&\n\t\t(value.env === undefined ||\n\t\t\t(isRecord(value.env) && Object.values(value.env).every((entry) => typeof entry === \"string\")))\n\t);\n}\n\nfunction parsePoolData(content: string | undefined): PoolData {\n\tif (!content || content.trim() === \"\") return {};\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(stripBom(content));\n\t} catch {\n\t\t// V8 quotes a snippet of the source in SyntaxError messages; never surface token material.\n\t\tthrow new Error(\"not valid JSON\");\n\t}\n\tif (!isRecord(parsed)) throw new Error(\"expected an object\");\n\tif (Object.hasOwn(parsed, \"version\")) {\n\t\tif (parsed.version !== 2 || !isRecord(parsed.providers)) throw new Error(\"unsupported account document\");\n\t\tparsed = parsed.providers;\n\t}\n\tif (!isRecord(parsed)) throw new Error(\"expected provider pools\");\n\t// Errors never quote provider ids or account keys from the file: they are unvalidated and may hold token material.\n\tfor (const pool of Object.values(parsed)) {\n\t\tif (\n\t\t\t!isRecord(pool) ||\n\t\t\ttypeof pool.active !== \"string\" ||\n\t\t\t!isRecord(pool.accounts) ||\n\t\t\t(pool.nextLocalAccountId !== undefined &&\n\t\t\t\t(typeof pool.nextLocalAccountId !== \"number\" ||\n\t\t\t\t\t!Number.isSafeInteger(pool.nextLocalAccountId) ||\n\t\t\t\t\tpool.nextLocalAccountId < 1))\n\t\t) {\n\t\t\tthrow new Error(\"invalid provider pool\");\n\t\t}\n\t\tif (\n\t\t\tpool.returnTo !== undefined &&\n\t\t\t(!isRecord(pool.returnTo) ||\n\t\t\t\ttypeof pool.returnTo.preferredKey !== \"string\" ||\n\t\t\t\ttypeof pool.returnTo.fromKey !== \"string\" ||\n\t\t\t\t!Object.hasOwn(pool.accounts, pool.returnTo.preferredKey) ||\n\t\t\t\t!Object.hasOwn(pool.accounts, pool.returnTo.fromKey))\n\t\t)\n\t\t\tthrow new Error(\"invalid preferred account state\");\n\t\tfor (const [key, account] of Object.entries(pool.accounts)) {\n\t\t\tif (\n\t\t\t\t!isRecord(account) ||\n\t\t\t\t(!isOAuthCredential(account.credential) && !isApiKeyCredential(account.credential)) ||\n\t\t\t\t(account.quotaFailures !== undefined &&\n\t\t\t\t\t(typeof account.quotaFailures !== \"number\" ||\n\t\t\t\t\t\t!Number.isSafeInteger(account.quotaFailures) ||\n\t\t\t\t\t\taccount.quotaFailures < 0 ||\n\t\t\t\t\t\taccount.quotaFailures > 31)) ||\n\t\t\t\t(account.cooldownRevision !== undefined &&\n\t\t\t\t\t(typeof account.cooldownRevision !== \"number\" ||\n\t\t\t\t\t\t!Number.isSafeInteger(account.cooldownRevision) ||\n\t\t\t\t\t\taccount.cooldownRevision < 0)) ||\n\t\t\t\t(account.exhaustedUntil !== undefined &&\n\t\t\t\t\t(typeof account.exhaustedUntil !== \"number\" || !Number.isFinite(account.exhaustedUntil)))\n\t\t\t) {\n\t\t\t\tthrow new Error(\"invalid account entry\");\n\t\t\t}\n\t\t\tif (!isSafeAccountKey(key, account.credential)) throw new Error(\"invalid account key\");\n\t\t\t// Labels are displayed: an unsafe one falls back to the validated key instead of rejecting the pool.\n\t\t\tif (!isSafeIdentityValue(account.label, account.credential)) account.label = key;\n\t\t}\n\t}\n\treturn parsed as PoolData;\n}\n\nfunction toPoolAccount(pool: StoredProviderPool, key: string): PoolAccount {\n\tconst stored = pool.accounts[key];\n\treturn {\n\t\tkey,\n\t\tlabel: stored.label,\n\t\tcredential: structuredClone(stored.credential),\n\t\texhaustedUntil: stored.exhaustedUntil,\n\t\t...(stored.quotaFailures !== undefined ? { quotaFailures: stored.quotaFailures } : {}),\n\t\t...(stored.cooldownRevision !== undefined ? { cooldownRevision: stored.cooldownRevision } : {}),\n\t\tactive: pool.active === key,\n\t};\n}\n\nfunction toAccount(pool: StoredProviderPool, key: string): OAuthAccount {\n\tconst account = toPoolAccount(pool, key);\n\tif (account.credential.type !== \"oauth\") throw new Error(\"Expected OAuth account\");\n\treturn account as OAuthAccount;\n}\n\nfunction toPoolAccounts(pool: StoredProviderPool): PoolAccount[] {\n\treturn Object.keys(pool.accounts).map((key) => toPoolAccount(pool, key));\n}\n\nfunction toAccounts(pool: StoredProviderPool | undefined): OAuthAccount[] {\n\treturn pool\n\t\t? Object.keys(pool.accounts)\n\t\t\t\t.filter((key) => pool.accounts[key].credential.type === \"oauth\")\n\t\t\t\t.map((key) => toAccount(pool, key))\n\t\t: [];\n}\n\n/** Whether the account is currently usable (never exhausted, or its exhaustion window has passed). */\nexport function isOAuthAccountUsable(account: { exhaustedUntil?: number }, nowMs: number): boolean {\n\treturn account.exhaustedUntil === undefined || account.exhaustedUntil <= nowMs;\n}\n\n/** Exact removal fallback: next usable account round-robin, then first remaining in insertion order. */\nexport function getOAuthAccountRemovalSuccessor<T extends Credential>(\n\taccounts: readonly PoolAccount<T>[],\n\taccountKey: string,\n\tnowMs: number = Date.now(),\n): PoolAccount<T> | undefined {\n\tconst index = accounts.findIndex((account) => account.key === accountKey);\n\tconst ordered = [...accounts.slice(index + 1), ...accounts.slice(0, index)];\n\treturn (\n\t\tordered.find((account) => isOAuthAccountUsable(account, nowMs)) ??\n\t\taccounts.find((account) => account.key !== accountKey)\n\t);\n}\n\nfunction earliestResetAt(pool: StoredProviderPool, nowMs: number, includeApiKeys = false): number | undefined {\n\tconst resetTimes = Object.values(pool.accounts)\n\t\t.filter((account) => includeApiKeys || account.credential.type === \"oauth\")\n\t\t.map((account) => account.exhaustedUntil)\n\t\t.filter((value): value is number => value !== undefined && value > nowMs);\n\treturn resetTimes.length > 0 ? Math.min(...resetTimes) : undefined;\n}\n\n/** Keys ordered round-robin starting after the active account. */\nfunction keysAfterActive(pool: StoredProviderPool): string[] {\n\tconst keys = Object.keys(pool.accounts);\n\tconst index = keys.indexOf(pool.active);\n\treturn index === -1 ? keys : [...keys.slice(index + 1), ...keys.slice(0, index)];\n}\n\n/** Forwards the caller's abort to a local controller until `detach()` (the commit point). */\nfunction linkAbortSignal(options: AuthOperationOptions | undefined): {\n\toptions: AuthOperationOptions | undefined;\n\tdetach: () => void;\n} {\n\tconst source = options?.signal;\n\tif (!source) return { options, detach: () => {} };\n\tconst controller = new AbortController();\n\tconst forward = () => controller.abort(source.reason);\n\tif (source.aborted) forward();\n\telse source.addEventListener(\"abort\", forward, { once: true });\n\treturn {\n\t\toptions: { ...options, signal: controller.signal },\n\t\tdetach: () => source.removeEventListener(\"abort\", forward),\n\t};\n}\n\ninterface RunContext {\n\t/** Identity key of the OAuth credential read from auth.json under the lock, if resolvable. */\n\tcurrentKey: string | undefined;\n\t/** Current auth credential normalized to the pool's identity metadata, without persisting it. */\n\tcurrentCredential?: Credential;\n\t/** Explicit login or selection may replace a non-OAuth credential. Adoption/removal must not. */\n\tactivate?: boolean;\n}\n\nexport function sameCredential(a: Credential | undefined, b: Credential | undefined): boolean {\n\treturn JSON.stringify(a) === JSON.stringify(b);\n}\n\nexport class OAuthAccountPool {\n\tprivate readonly credentials: CredentialStore;\n\tprivate readonly pendingWrites = new Set<Promise<void>>();\n\tprivate readonly storage: AuthStorageBackend;\n\tprivate readonly location: string;\n\tprivate readonly resolvers: Map<string, OAuthAccountIdentityResolver>;\n\tprivate readonly cache = new Map<string, PoolAccount[]>();\n\tprivate readonly backupPath: string | undefined;\n\tprivate error: string | undefined;\n\n\tconstructor(\n\t\tcredentials: CredentialStore,\n\t\tstorage: AuthStorageBackend,\n\t\tlocation: string,\n\t\tresolvers: ReadonlyMap<string, OAuthAccountIdentityResolver> = DEFAULT_OAUTH_ACCOUNT_IDENTITY_RESOLVERS,\n\t\tbackupPath?: string,\n\t) {\n\t\tthis.credentials = getAccountCredentialStore(credentials);\n\t\tthis.storage = storage;\n\t\tthis.location = location;\n\t\tthis.resolvers = new Map(resolvers);\n\t\tthis.backupPath = backupPath;\n\t}\n\n\tstatic create(\n\t\tcredentials: CredentialStore,\n\t\tpoolPath: string = join(getAgentDir(), \"oauth-accounts.json\"),\n\t): OAuthAccountPool {\n\t\tconst normalized = normalizePath(poolPath);\n\t\treturn new OAuthAccountPool(\n\t\t\tcredentials,\n\t\t\tnew FileAuthStorageBackend(normalized),\n\t\t\tnormalized,\n\t\t\tDEFAULT_OAUTH_ACCOUNT_IDENTITY_RESOLVERS,\n\t\t\t`${normalized}.v1.bak`,\n\t\t);\n\t}\n\n\tstatic inMemory(credentials: CredentialStore): OAuthAccountPool {\n\t\treturn new OAuthAccountPool(credentials, new InMemoryAuthStorageBackend(), \"oauth-accounts (in-memory)\");\n\t}\n\n\t/** Wait for started pool writes, including auth.json and pool-file persistence. */\n\tasync settled(): Promise<void> {\n\t\twhile (this.pendingWrites.size > 0) await Promise.all(this.pendingWrites);\n\t}\n\n\t/** Register a provider-specific identity hook, taking precedence over generic identity. */\n\tregisterIdentityResolver(providerId: string, resolver: OAuthAccountIdentityResolver): void {\n\t\tthis.resolvers.set(providerId, resolver);\n\t}\n\n\t/** Every provider can pool stored OAuth credentials; API-key credentials are ignored. */\n\tisPooled(_providerId: string): boolean {\n\t\treturn true;\n\t}\n\n\t/**\n\t * Exact account key of an access token, resolved from the token itself via the provider's registered resolver.\n\t * Resolvers must derive identity from `access` only (the refresh token and expiry passed here are placeholders).\n\t * Undefined when no provider resolver can identify the token; opaque tokens need credential metadata.\n\t */\n\tgetAccountKeyForAccessToken(providerId: string, accessToken: string): string | undefined {\n\t\tconst credential: OAuthCredential = { type: \"oauth\", access: accessToken, refresh: \"\", expires: 0 };\n\t\tconst cached = this.cache\n\t\t\t.get(providerId)\n\t\t\t?.find((account) => account.credential.type === \"oauth\" && account.credential.access === accessToken);\n\t\tif (cached) return cached.key;\n\t\tconst key = this.resolvers.get(providerId)?.(credential)?.key;\n\t\treturn isSafeAccountKey(key, credential) ? key : undefined;\n\t}\n\n\t/**\n\t * Identity of the credential actually used for authentication, independent of the active pool view: the registered\n\t * resolver's, else the generic one. An unsafe key from either source counts as no identity; an unsafe label falls\n\t * back to the key.\n\t */\n\tgetAccountIdentity(providerId: string, credential: OAuthCredential): OAuthAccountIdentity | undefined {\n\t\tif (\n\t\t\ttypeof credential.accountKey === \"string\" &&\n\t\t\t/^account-[0-9a-f-]{36}$/.test(credential.accountKey) &&\n\t\t\tisSafeAccountKey(credential.accountKey, credential)\n\t\t)\n\t\t\treturn resolveGenericAccountIdentity(credential);\n\t\tconst resolved = this.resolvers.get(providerId)?.(credential);\n\t\tif (!resolved || !isSafeAccountKey(resolved.key, credential)) return resolveGenericAccountIdentity(credential);\n\t\treturn {\n\t\t\tkey: resolved.key,\n\t\t\tlabel: isSafeIdentityValue(resolved.label, credential) ? resolved.label : resolved.key,\n\t\t};\n\t}\n\n\t/** Last parse error of the pool file, if the file is corrupt. */\n\tgetError(): string | undefined {\n\t\treturn this.error;\n\t}\n\n\t/**\n\t * Synchronous view of the accounts as of the last read or mutation in this process.\n\t * Undefined until the pool has been read once. May be stale across processes.\n\t */\n\tgetCachedAccounts(providerId: string): readonly OAuthAccount[] | undefined {\n\t\tconst cached = this.cache.get(providerId);\n\t\treturn cached\n\t\t\t? cached\n\t\t\t\t\t.filter((account): account is OAuthAccount => account.credential.type === \"oauth\")\n\t\t\t\t\t.map((account) => ({ ...account, credential: structuredClone(account.credential) }))\n\t\t\t: undefined;\n\t}\n\n\t/** Last-known generalized view for recovery prediction; never use it to choose request credentials. */\n\tgetCachedPoolAccounts(providerId: string): readonly PoolAccount[] | undefined {\n\t\treturn this.cache\n\t\t\t.get(providerId)\n\t\t\t?.map((account) => ({ ...account, credential: structuredClone(account.credential) }));\n\t}\n\n\tgetAccountKeyForApiKey(providerId: string, apiKey: string): string | undefined {\n\t\treturn this.cache\n\t\t\t.get(providerId)\n\t\t\t?.find((account) => account.credential.type === \"api_key\" && account.credential.key === apiKey)?.key;\n\t}\n\n\tasync list(providerId: string, options?: AuthOperationOptions): Promise<OAuthAccount[]> {\n\t\treturn (await this.run(providerId, \"read\", options, (pool) => toAccounts(pool))) ?? [];\n\t}\n\n\t/** Collapse confirmed identity aliases for display only; every stored slot remains addressable by key. */\n\tdisplayAccounts<T extends Credential>(providerId: string, accounts: readonly PoolAccount<T>[]): PoolAccount<T>[] {\n\t\tconst winners = new Map<string, PoolAccount<T>>();\n\t\tconst identities = accounts.map((account) => {\n\t\t\tif (account.credential.type !== \"oauth\") return undefined;\n\t\t\tconst identity = this.loginIdentity(providerId, account.credential)?.key;\n\t\t\tif (identity === undefined) return undefined;\n\t\t\tconst incumbent = winners.get(identity);\n\t\t\tif (\n\t\t\t\t!incumbent ||\n\t\t\t\t(!incumbent.active &&\n\t\t\t\t\t(account.active ||\n\t\t\t\t\t\t(incumbent.credential.type === \"oauth\" && account.credential.expires > incumbent.credential.expires)))\n\t\t\t) {\n\t\t\t\twinners.set(identity, account);\n\t\t\t}\n\t\t\treturn identity;\n\t\t});\n\t\tconst visible = accounts.filter(\n\t\t\t(account, index) => identities[index] === undefined || winners.get(identities[index]!) === account,\n\t\t);\n\t\tif (providerId !== \"anthropic\") return visible;\n\t\tconst orgLabels = new Set(\n\t\t\tvisible.flatMap(({ label, credential }) =>\n\t\t\t\tcredential.type === \"oauth\" && credential.organizationId !== undefined && label.includes(\" · \")\n\t\t\t\t\t? [label.split(\" · \")[0]]\n\t\t\t\t\t: [],\n\t\t\t),\n\t\t);\n\t\treturn visible.map((account) =>\n\t\t\taccount.credential.type === \"oauth\" &&\n\t\t\taccount.credential.organizationId === undefined &&\n\t\t\torgLabels.has(account.label)\n\t\t\t\t? { ...account, label: `${account.label} · Anthropic` }\n\t\t\t\t: account,\n\t\t);\n\t}\n\n\tprivate loginIdentity(providerId: string, credential: OAuthCredential): OAuthAccountIdentity | undefined {\n\t\tif (credential.organizationId !== undefined && !isSafeIdentityValue(credential.organizationId, credential))\n\t\t\treturn undefined;\n\t\tconst identity = this.getAccountIdentity(providerId, { ...credential, accountKey: undefined });\n\t\tif (providerId !== \"openai-codex\" || !identity || !isSafeAccountKey(credential.accountId, credential))\n\t\t\treturn identity;\n\t\treturn resolveOpenAICodexAccountIdentity(credential) ? identity : { ...identity, key: credential.accountId };\n\t}\n\n\tprivate removeExpiredAliases(providerId: string, pool: StoredProviderPool, key: string): void {\n\t\tconst survivor = pool.accounts[key]?.credential;\n\t\tconst now = Date.now();\n\t\tif (survivor?.type !== \"oauth\" || survivor.expires <= now || !survivor.refresh) return;\n\t\tconst identity = this.loginIdentity(providerId, survivor)?.key;\n\t\tif (identity === undefined) return;\n\t\tfor (const [alias, { credential }] of Object.entries(pool.accounts)) {\n\t\t\t// Expired access alone is not proof of a dead login: a different refresh grant can still be valid.\n\t\t\tif (\n\t\t\t\talias === key ||\n\t\t\t\talias === pool.active ||\n\t\t\t\tcredential.type !== \"oauth\" ||\n\t\t\t\tcredential.expires > now ||\n\t\t\t\tcredential.refresh !== survivor.refresh ||\n\t\t\t\tthis.loginIdentity(providerId, credential)?.key !== identity\n\t\t\t)\n\t\t\t\tcontinue;\n\t\t\tdelete pool.accounts[alias];\n\t\t\tif (pool.returnTo?.preferredKey === alias || pool.returnTo?.fromKey === alias) delete pool.returnTo;\n\t\t}\n\t}\n\n\tasync getActive(providerId: string, options?: AuthOperationOptions): Promise<OAuthAccount | undefined> {\n\t\treturn this.run(providerId, \"read\", options, (pool) =>\n\t\t\tObject.hasOwn(pool.accounts, pool.active) && pool.accounts[pool.active].credential.type === \"oauth\"\n\t\t\t\t? toAccount(pool, pool.active)\n\t\t\t\t: undefined,\n\t\t);\n\t}\n\n\t/**\n\t * The account whose credential auth.json holds; undefined when auth.json holds no credential, a non-OAuth one, or\n\t * one that matches no account (unlike `getActive`, which then still reports the pool's last active account).\n\t */\n\tasync getCurrent(providerId: string, options?: AuthOperationOptions): Promise<OAuthAccount | undefined> {\n\t\treturn this.run(providerId, \"read\", options, (pool, context) =>\n\t\t\tcontext.currentKey !== undefined ? toAccount(pool, context.currentKey) : undefined,\n\t\t);\n\t}\n\n\t/**\n\t * Pool the credential currently stored in auth.json (if any) as the active account, stamping\n\t * its key for non-Codex providers. Call before an operation that replaces the auth.json credential.\n\t */\n\tasync adoptCurrent(providerId: string, options?: AuthOperationOptions): Promise<OAuthAccount | undefined> {\n\t\treturn this.run(providerId, \"write\", options, (pool, context) =>\n\t\t\tcontext.currentKey !== undefined ? toAccount(pool, context.currentKey) : undefined,\n\t\t);\n\t}\n\n\t/** Reconcile auth.json and refresh one exact OAuth account without activating it. */\n\tasync prepareUsageAccount(\n\t\tproviderId: string,\n\t\tkey: string | undefined,\n\t\trefresh: UsageCredentialRefresh,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<UsageRefreshResult | undefined> {\n\t\treturn this.run<UsageRefreshResult | undefined>(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t() => undefined,\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t\tfalse,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t\t{ key, refresh, result: (value) => value },\n\t\t);\n\t}\n\n\t/** Clear only a still-current cooldown observation; never select credentials or persist auth.json changes. */\n\tasync clearExhaustion(providerId: string, expected: OAuthAccount, options?: AuthOperationOptions): Promise<boolean> {\n\t\treturn (\n\t\t\t(await this.run(\n\t\t\t\tproviderId,\n\t\t\t\t\"write\",\n\t\t\t\toptions,\n\t\t\t\t(pool, context) => {\n\t\t\t\t\tif (!Object.hasOwn(pool.accounts, expected.key)) return undefined;\n\t\t\t\t\tconst account = pool.accounts[expected.key];\n\t\t\t\t\tif (\n\t\t\t\t\t\texpected.exhaustedUntil === undefined ||\n\t\t\t\t\t\t!Number.isFinite(expected.exhaustedUntil) ||\n\t\t\t\t\t\texpected.exhaustedUntil <= Date.now() ||\n\t\t\t\t\t\taccount.exhaustedUntil !== expected.exhaustedUntil ||\n\t\t\t\t\t\taccount.quotaFailures !== expected.quotaFailures ||\n\t\t\t\t\t\t(account.cooldownRevision ?? 0) !== (expected.cooldownRevision ?? 0) ||\n\t\t\t\t\t\t// A saturated revision cannot distinguish another failure with the same reset time.\n\t\t\t\t\t\taccount.cooldownRevision === Number.MAX_SAFE_INTEGER ||\n\t\t\t\t\t\t!sameCredential(account.credential, expected.credential) ||\n\t\t\t\t\t\t(context.currentKey === expected.key &&\n\t\t\t\t\t\t\t!sameCredential(context.currentCredential, expected.credential))\n\t\t\t\t\t)\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\tdelete account.exhaustedUntil;\n\t\t\t\t\tdelete account.quotaFailures;\n\t\t\t\t\treturn true;\n\t\t\t\t},\n\t\t\t\tundefined,\n\t\t\t\ttrue,\n\t\t\t\tfalse,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\ttrue,\n\t\t\t)) ?? false\n\t\t);\n\t}\n\n\t/** Generalized storage view. Credentials are sensitive; UI must display only keys, labels and markers. */\n\tasync listAccounts(providerId: string, options?: AuthOperationOptions): Promise<PoolAccount[]> {\n\t\treturn (\n\t\t\t(await this.run(providerId, \"read\", options, (pool) => toPoolAccounts(pool), undefined, false, true)) ?? []\n\t\t);\n\t}\n\n\tasync getCurrentAccount(providerId: string, options?: AuthOperationOptions): Promise<PoolAccount | undefined> {\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"read\",\n\t\t\toptions,\n\t\t\t(pool, context) => (context.currentKey ? toPoolAccount(pool, context.currentKey) : undefined),\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\tasync adoptCurrentAccount(providerId: string, options?: AuthOperationOptions): Promise<PoolAccount | undefined> {\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t(pool, context) => {\n\t\t\t\tif (!context.currentKey) return undefined;\n\t\t\t\tthis.removeExpiredAliases(providerId, pool, context.currentKey);\n\t\t\t\treturn toPoolAccount(pool, context.currentKey);\n\t\t\t},\n\t\t\tundefined,\n\t\t\ttrue,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\t/** New entries have random token-free keys; exact API-key equality deduplicates without a stored fingerprint. */\n\tasync addAccount(\n\t\tproviderId: string,\n\t\tcredential: Credential,\n\t\toptions?: AuthOperationOptions & { key?: string; label?: string },\n\t): Promise<PoolAccount | undefined> {\n\t\tif (!isOAuthCredential(credential) && !isApiKeyCredential(credential))\n\t\t\tthrow new Error(\"Invalid account credential\");\n\t\tif (options?.key !== undefined && !isSafeAccountKey(options.key, credential))\n\t\t\tthrow new Error(\"Invalid account key\");\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t(pool, context) => {\n\t\t\t\tif (\n\t\t\t\t\toptions?.label !== undefined &&\n\t\t\t\t\t![credential, ...Object.values(pool.accounts).map((account) => account.credential)].every((entry) =>\n\t\t\t\t\t\tisSafeIdentityValue(options.label, entry),\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(\"Invalid account label\");\n\t\t\t\tconst identity = credential.type === \"oauth\" ? this.loginIdentity(providerId, credential) : undefined;\n\t\t\t\tconst matches = Object.keys(pool.accounts).filter((key) => {\n\t\t\t\t\tconst stored = pool.accounts[key].credential;\n\t\t\t\t\tif (credential.type === \"api_key\") return stored.type === \"api_key\" && stored.key === credential.key;\n\t\t\t\t\treturn (\n\t\t\t\t\t\tstored.type === \"oauth\" &&\n\t\t\t\t\t\t(sameCredential(stored, credential) ||\n\t\t\t\t\t\t\t(identity !== undefined && this.loginIdentity(providerId, stored)?.key === identity.key))\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\tconst matching = matches.includes(pool.active)\n\t\t\t\t\t? pool.active\n\t\t\t\t\t: matches.reduce<string | undefined>((best, candidate) => {\n\t\t\t\t\t\t\tconst previous = best === undefined ? undefined : pool.accounts[best].credential;\n\t\t\t\t\t\t\tconst next = pool.accounts[candidate].credential;\n\t\t\t\t\t\t\treturn !previous ||\n\t\t\t\t\t\t\t\t(next.type === \"oauth\" && previous.type === \"oauth\" && next.expires > previous.expires)\n\t\t\t\t\t\t\t\t? candidate\n\t\t\t\t\t\t\t\t: best;\n\t\t\t\t\t\t}, undefined);\n\t\t\t\tif (\n\t\t\t\t\tcredential.type === \"api_key\" &&\n\t\t\t\t\toptions?.key !== undefined &&\n\t\t\t\t\tmatching !== undefined &&\n\t\t\t\t\tmatching !== options.key\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(\"API key already belongs to another account\");\n\t\t\t\t// Claude organizations are distinct quota owners, even for the same user.\n\t\t\t\tconst organizationKey =\n\t\t\t\t\tproviderId === \"anthropic\" && credential.type === \"oauth\" && credential.organizationId !== undefined\n\t\t\t\t\t\t? identity?.key\n\t\t\t\t\t\t: undefined;\n\t\t\t\tconst key = options?.key ?? matching ?? organizationKey ?? `account-${randomUUID()}`;\n\t\t\t\tif (\n\t\t\t\t\t![credential, ...Object.values(pool.accounts).map((account) => account.credential)].every((entry) =>\n\t\t\t\t\t\tisSafeAccountKey(key, entry),\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(\"Invalid account key\");\n\t\t\t\tconst existing = Object.hasOwn(pool.accounts, key) ? pool.accounts[key] : undefined;\n\t\t\t\tif (existing && existing.credential.type !== credential.type)\n\t\t\t\t\tthrow new Error(\"Account credential type cannot change\");\n\t\t\t\tif (existing?.credential.type === \"oauth\" && identity !== undefined) {\n\t\t\t\t\tconst existingIdentity = this.loginIdentity(providerId, existing.credential);\n\t\t\t\t\tif (existingIdentity !== undefined && existingIdentity.key !== identity.key)\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\"Sign-in returned a different account or workspace. Sign in to the selected account or use Add another account.\",\n\t\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst label =\n\t\t\t\t\toptions?.label ??\n\t\t\t\t\texisting?.label ??\n\t\t\t\t\tidentity?.label ??\n\t\t\t\t\t`Account ${pool.nextLocalAccountId ?? Object.keys(pool.accounts).length + 1}`;\n\t\t\t\tif (\n\t\t\t\t\t![credential, ...Object.values(pool.accounts).map((account) => account.credential)].every((entry) =>\n\t\t\t\t\t\tisSafeIdentityValue(label, entry),\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(\"Invalid account label\");\n\t\t\t\tpool.nextLocalAccountId =\n\t\t\t\t\t(pool.nextLocalAccountId ?? Object.keys(pool.accounts).length + 1) + (existing ? 0 : 1);\n\t\t\t\tif (credential.type === \"oauth\") this.removeExpiredAliases(providerId, pool, key);\n\t\t\t\tpool.accounts[key] = {\n\t\t\t\t\tcredential:\n\t\t\t\t\t\tcredential.type === \"oauth\"\n\t\t\t\t\t\t\t? { ...structuredClone(credential), accountKey: key }\n\t\t\t\t\t\t\t: structuredClone(credential),\n\t\t\t\t\tlabel,\n\t\t\t\t\texhaustedUntil: existing?.exhaustedUntil,\n\t\t\t\t\tquotaFailures: existing?.quotaFailures,\n\t\t\t\t\tcooldownRevision: existing?.cooldownRevision,\n\t\t\t\t};\n\t\t\t\tdelete pool.returnTo;\n\t\t\t\tpool.active = key;\n\t\t\t\tif (credential.type === \"oauth\") this.removeExpiredAliases(providerId, pool, key);\n\t\t\t\tcontext.activate = true;\n\t\t\t\treturn toPoolAccount(pool, key);\n\t\t\t},\n\t\t\tundefined,\n\t\t\ttrue,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\tasync setActiveAccount(\n\t\tproviderId: string,\n\t\taccountKey: string,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<PoolAccount | undefined> {\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t(pool, context) => {\n\t\t\t\tif (!Object.hasOwn(pool.accounts, accountKey)) return undefined;\n\t\t\t\tcontext.activate = true;\n\t\t\t\tdelete pool.returnTo;\n\t\t\t\tpool.active = accountKey;\n\t\t\t\treturn toPoolAccount(pool, accountKey);\n\t\t\t},\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\tasync renameAccount(\n\t\tproviderId: string,\n\t\taccountKey: string,\n\t\tlabel: string,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<PoolAccount | undefined> {\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t(pool) => {\n\t\t\t\tif (!Object.hasOwn(pool.accounts, accountKey)) return undefined;\n\t\t\t\tif (!Object.values(pool.accounts).every((account) => isSafeIdentityValue(label, account.credential)))\n\t\t\t\t\tthrow new Error(\"Invalid account label\");\n\t\t\t\tpool.accounts[accountKey].label = label;\n\t\t\t\treturn toPoolAccount(pool, accountKey);\n\t\t\t},\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\t/** `ifCurrent` binds removal to a raw stored observation, checked before planning and under the auth lock. */\n\tasync removeAccount(\n\t\tproviderId: string,\n\t\taccountKey: string | undefined,\n\t\toptions?: CredentialDeleteOptions,\n\t): Promise<AccountRemoveResult> {\n\t\treturn this.removeStored(providerId, accountKey, options, true);\n\t}\n\n\t/**\n\t * Add or update an account (same key updates the stored credential) and make it active. An explicit `key` must be a\n\t * safe account key (bounded, printable, token-free, not an `Object.prototype` name).\n\t */\n\tasync add(\n\t\tproviderId: string,\n\t\tcredential: OAuthCredential,\n\t\toptions?: AuthOperationOptions & { key?: string },\n\t): Promise<OAuthAccount | undefined> {\n\t\tif (options?.key !== undefined && !isSafeAccountKey(options.key, credential)) {\n\t\t\tthrow new Error(\"Invalid OAuth account key\");\n\t\t}\n\t\tconst identity = this.getAccountIdentity(providerId, credential);\n\t\tif (providerId === \"openai-codex\" && !identity && options?.key === undefined) return undefined;\n\t\treturn this.run(providerId, \"write\", options, (pool, context) => {\n\t\t\tcontext.activate = true;\n\t\t\tconst local = options?.key === undefined && !identity ? nextLocalAccountIdentity(pool) : undefined;\n\t\t\tconst key = options?.key ?? identity?.key ?? local!.key;\n\t\t\tconst existing = pool.accounts[key];\n\t\t\tpool.accounts[key] = {\n\t\t\t\tcredential:\n\t\t\t\t\tproviderId === \"openai-codex\"\n\t\t\t\t\t\t? structuredClone(credential)\n\t\t\t\t\t\t: { ...structuredClone(credential), accountKey: key },\n\t\t\t\tlabel: existing?.label ?? identity?.label ?? local?.label ?? key,\n\t\t\t\texhaustedUntil: existing?.exhaustedUntil,\n\t\t\t\tquotaFailures: existing?.quotaFailures,\n\t\t\t\tcooldownRevision: existing?.cooldownRevision,\n\t\t\t};\n\t\t\tdelete pool.returnTo;\n\t\t\tpool.active = key;\n\t\t\treturn toAccount(pool, key);\n\t\t});\n\t}\n\n\tasync setActive(\n\t\tproviderId: string,\n\t\taccountKey: string,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<OAuthAccount | undefined> {\n\t\treturn this.run(providerId, \"write\", options, (pool, context) => {\n\t\t\tif (!Object.hasOwn(pool.accounts, accountKey) || pool.accounts[accountKey].credential.type !== \"oauth\")\n\t\t\t\treturn undefined;\n\t\t\tcontext.activate = true;\n\t\t\tdelete pool.returnTo;\n\t\t\tpool.active = accountKey;\n\t\t\treturn toAccount(pool, accountKey);\n\t\t});\n\t}\n\n\t/**\n\t * Remove an account, or with `accountKey` undefined the account whose credential auth.json holds (`unmatched` when\n\t * that credential is missing, not OAuth, or cannot be matched to an account). Removing the active account promotes\n\t * the next usable one; when the pool becomes empty the auth.json credential is deleted if it still belongs to a\n\t * removed account. `changed` when auth.json changed before its lock so that the removal no longer applied; without\n\t * `accountKey` this includes auth.json no longer holding the account found first, which is never retargeted.\n\t */\n\tasync remove(\n\t\tproviderId: string,\n\t\taccountKey: string | undefined,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<OAuthAccountRemoveResult> {\n\t\tconst result = await this.removeStored(providerId, accountKey, options, false);\n\t\treturn result as OAuthAccountRemoveResult;\n\t}\n\n\tprivate async removeStored(\n\t\tproviderId: string,\n\t\taccountKey: string | undefined,\n\t\toptions: CredentialDeleteOptions | undefined,\n\t\tincludeApiKeys: boolean,\n\t): Promise<AccountRemoveResult> {\n\t\tlet matched = false;\n\t\tlet target = accountKey;\n\t\tconst result = await this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t(pool, context): AccountRemoveResult | undefined => {\n\t\t\t\tconst key = target ?? context.currentKey;\n\t\t\t\tif (\n\t\t\t\t\tkey === undefined ||\n\t\t\t\t\t!Object.hasOwn(pool.accounts, key) ||\n\t\t\t\t\t(!includeApiKeys && pool.accounts[key].credential.type !== \"oauth\")\n\t\t\t\t)\n\t\t\t\t\treturn undefined;\n\t\t\t\t// A keyless re-plan removes only the account auth.json held at the first plan.\n\t\t\t\tif (accountKey === undefined && context.currentKey !== key) return undefined;\n\t\t\t\tmatched = true;\n\t\t\t\ttarget = key;\n\t\t\t\tconst removed = toPoolAccount(pool, key);\n\t\t\t\tconst wasActive = pool.active === key;\n\t\t\t\tconst successor = wasActive\n\t\t\t\t\t? getOAuthAccountRemovalSuccessor(\n\t\t\t\t\t\t\ttoPoolAccounts(pool).filter((account) => account.credential.type === removed.credential.type),\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t)?.key\n\t\t\t\t\t: undefined;\n\t\t\t\tif (wasActive || pool.returnTo?.preferredKey === key || pool.returnTo?.fromKey === key)\n\t\t\t\t\tdelete pool.returnTo;\n\t\t\t\tdelete pool.accounts[key];\n\t\t\t\tif (wasActive) pool.active = successor ?? \"\";\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"removed\",\n\t\t\t\t\tremoved,\n\t\t\t\t\tactive:\n\t\t\t\t\t\tpool.active && (includeApiKeys || pool.accounts[pool.active].credential.type === \"oauth\")\n\t\t\t\t\t\t\t? toPoolAccount(pool, pool.active)\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t};\n\t\t\t},\n\t\t\tundefined,\n\t\t\ttrue,\n\t\t\tincludeApiKeys,\n\t\t\toptions?.ifCurrent ? { ifCurrent: options.ifCurrent, changed: { status: \"changed\" } } : undefined,\n\t\t);\n\t\t// `run` stops when the first plan declines; a decline after a match came from a re-plan under the auth.json lock.\n\t\treturn result ?? { status: matched ? \"changed\" : \"unmatched\" };\n\t}\n\n\t/**\n\t * Atomic usage-limit failover: under one pool lock, verify auth.json holds an OAuth credential of the expected\n\t * account, optionally mark it exhausted, activate the next usable account, and write it to auth.json. The check is\n\t * repeated at the auth.json write; a different account there (other process) is never overwritten.\n\t * Returns `active_changed` (nothing marked, auth.json untouched) when auth.json does not hold the expected\n\t * account. Abort before the auth.json write throws with nothing changed.\n\t */\n\tasync failover(\n\t\tproviderId: string,\n\t\toptions: OAuthAccountFailoverOptions,\n\t): Promise<OAuthAccountFailoverResult | undefined> {\n\t\treturn this.failoverStored(providerId, options, false) as Promise<OAuthAccountFailoverResult | undefined>;\n\t}\n\n\t/** Same-type rotation first, then only the explicitly named OAuth-to-API-key target. */\n\tasync failoverAccounts(\n\t\tproviderId: string,\n\t\toptions: AccountFailoverOptions,\n\t): Promise<AccountFailoverResult | undefined> {\n\t\t// Callers may pass `trackPreferred: false` to skip the persisted return-to-preferred state and doubling cooldown.\n\t\treturn this.failoverStored(providerId, { ...options, trackPreferred: options.trackPreferred ?? true }, true);\n\t}\n\n\tprivate async failoverStored(\n\t\tproviderId: string,\n\t\toptions: AccountFailoverOptions,\n\t\tincludeApiKeys: boolean,\n\t): Promise<AccountFailoverResult | undefined> {\n\t\tconst {\n\t\t\texpectedActiveKey,\n\t\t\texhaustedUntil,\n\t\t\tnow = Date.now(),\n\t\t\tskipKeys,\n\t\t\ttrackPreferred,\n\t\t\tapiKeyFallback,\n\t\t\tallowApiKeyRotation,\n\t\t\tmarkExhausted = true,\n\t\t\tcandidateKeys,\n\t\t\tcandidateFilter,\n\t\t\tcanActivate,\n\t\t\t...operationOptions\n\t\t} = options;\n\t\tconst accounts = (pool: StoredProviderPool) => (includeApiKeys ? toPoolAccounts(pool) : toAccounts(pool));\n\t\tconst activeChanged = (pool: StoredProviderPool, activeKey: string | undefined): AccountFailoverResult => ({\n\t\t\tswitched: false,\n\t\t\treason: \"active_changed\",\n\t\t\tactive:\n\t\t\t\tactiveKey !== undefined && Object.hasOwn(pool.accounts, activeKey)\n\t\t\t\t\t? toPoolAccount(pool, activeKey)\n\t\t\t\t\t: undefined,\n\t\t\ttotal: accounts(pool).length,\n\t\t\tearliestResetAt: earliestResetAt(pool, now, includeApiKeys),\n\t\t});\n\t\tconst operation = (pool: StoredProviderPool, context: RunContext): AccountFailoverResult => {\n\t\t\tconst total = accounts(pool).length;\n\t\t\tif (context.currentKey !== expectedActiveKey || pool.active !== expectedActiveKey) {\n\t\t\t\treturn activeChanged(pool, context.currentKey);\n\t\t\t}\n\t\t\tconst source = pool.accounts[expectedActiveKey];\n\t\t\tif (trackPreferred && markExhausted) source.quotaFailures = Math.min(31, (source.quotaFailures ?? 0) + 1);\n\t\t\tconst reset =\n\t\t\t\texhaustedUntil ??\n\t\t\t\t(trackPreferred\n\t\t\t\t\t? now +\n\t\t\t\t\t\tMath.min(\n\t\t\t\t\t\t\tACCOUNT_RETURN_MAX_COOLDOWN_MS,\n\t\t\t\t\t\t\tACCOUNT_RETURN_COOLDOWN_MS * 2 ** ((source.quotaFailures ?? 1) - 1),\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined);\n\t\t\tif (reset !== undefined && markExhausted) {\n\t\t\t\tsource.exhaustedUntil = reset;\n\t\t\t\tsource.cooldownRevision = Math.min(Number.MAX_SAFE_INTEGER, (source.cooldownRevision ?? 0) + 1);\n\t\t\t}\n\t\t\tconst usable = (key: string) =>\n\t\t\t\tkey !== expectedActiveKey && !skipKeys?.has(key) && isOAuthAccountUsable(pool.accounts[key], now);\n\t\t\tconst sameType = source.credential.type === \"oauth\" || allowApiKeyRotation === true;\n\t\t\tconst ordered = candidateKeys\n\t\t\t\t? candidateKeys.filter((key) => Object.hasOwn(pool.accounts, key))\n\t\t\t\t: keysAfterActive(pool);\n\t\t\tconst candidate =\n\t\t\t\t(sameType\n\t\t\t\t\t? ordered.find(\n\t\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t\t\tpool.accounts[key].credential.type === source.credential.type &&\n\t\t\t\t\t\t\t\tusable(key) &&\n\t\t\t\t\t\t\t\t(candidateFilter === undefined ||\n\t\t\t\t\t\t\t\t\tcandidateFilter(toPoolAccount(pool, expectedActiveKey), toPoolAccount(pool, key))),\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined) ??\n\t\t\t\t(source.credential.type === \"oauth\" &&\n\t\t\t\tapiKeyFallback !== undefined &&\n\t\t\t\tObject.hasOwn(pool.accounts, apiKeyFallback) &&\n\t\t\t\tpool.accounts[apiKeyFallback].credential.type === \"api_key\" &&\n\t\t\t\tusable(apiKeyFallback)\n\t\t\t\t\t? apiKeyFallback\n\t\t\t\t\t: undefined);\n\t\t\tif (candidate === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tswitched: false,\n\t\t\t\t\treason: \"exhausted\",\n\t\t\t\t\tactive: toPoolAccount(pool, expectedActiveKey),\n\t\t\t\t\ttotal,\n\t\t\t\t\tearliestResetAt: earliestResetAt(pool, now, includeApiKeys),\n\t\t\t\t};\n\t\t\t}\n\t\t\tpool.accounts[candidate].exhaustedUntil = undefined;\n\t\t\tif (trackPreferred)\n\t\t\t\tpool.returnTo = { preferredKey: pool.returnTo?.preferredKey ?? expectedActiveKey, fromKey: candidate };\n\t\t\tpool.active = candidate;\n\t\t\treturn {\n\t\t\t\tswitched: true,\n\t\t\t\tfrom: toPoolAccount(pool, expectedActiveKey),\n\t\t\t\tto: toPoolAccount(pool, candidate),\n\t\t\t\ttotal,\n\t\t\t};\n\t\t};\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toperationOptions,\n\t\t\toperation,\n\t\t\texpectedActiveKey,\n\t\t\tfalse,\n\t\t\tincludeApiKeys,\n\t\t\tundefined,\n\t\t\tcanActivate,\n\t\t);\n\t}\n\n\t/** Request-boundary only. Rechecks the active credential under the auth lock; no network calls. */\n\tasync returnToPreferred(\n\t\tproviderId: string,\n\t\toptions?: AuthOperationOptions & {\n\t\t\tskipKeys?: ReadonlySet<string>;\n\t\t\tcanActivate?: (from: PoolAccount, to: PoolAccount) => boolean;\n\t\t},\n\t): Promise<PoolAccount | undefined> {\n\t\tconst result = await this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t(pool, context) => {\n\t\t\t\tconst pending = pool.returnTo;\n\t\t\t\tif (!pending) return undefined;\n\t\t\t\tif (context.currentKey !== pending.fromKey) {\n\t\t\t\t\tdelete pool.returnTo;\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tconst preferred = pool.accounts[pending.preferredKey];\n\t\t\t\tif (\n\t\t\t\t\t!preferred ||\n\t\t\t\t\toptions?.skipKeys?.has(pending.preferredKey) ||\n\t\t\t\t\t!isOAuthAccountUsable(preferred, Date.now())\n\t\t\t\t)\n\t\t\t\t\treturn false;\n\t\t\t\tpool.active = pending.preferredKey;\n\t\t\t\tdelete pool.returnTo;\n\t\t\t\treturn toPoolAccount(pool, pool.active);\n\t\t\t},\n\t\t\tundefined,\n\t\t\ttrue,\n\t\t\ttrue,\n\t\t\tundefined,\n\t\t\toptions?.canActivate,\n\t\t);\n\t\treturn result || undefined;\n\t}\n\n\t/**\n\t * Atomic credit fallback once every pooled account was tried: under one pool lock, verify auth.json holds an\n\t * OAuth credential of the expected account (rechecked at the auth.json write), then activate an untried usable account if one exists now\n\t * (`untried`), else the credit-capable target (`credit`). Nothing changes for `active_changed`\n\t * or `missing`. Abort before the auth.json write throws with nothing changed.\n\t */\n\tasync activateCreditFallback(\n\t\tproviderId: string,\n\t\toptions: OAuthAccountCreditFallbackOptions,\n\t): Promise<OAuthAccountCreditFallbackResult | undefined> {\n\t\tconst { expectedActiveKey, targetKey, skipKeys, now = Date.now(), canActivate, ...operationOptions } = options;\n\t\tconst activeChanged = (\n\t\t\tpool: StoredProviderPool,\n\t\t\tactiveKey: string | undefined,\n\t\t): OAuthAccountCreditFallbackResult => ({\n\t\t\toutcome: \"active_changed\",\n\t\t\tactive:\n\t\t\t\tactiveKey !== undefined && Object.hasOwn(pool.accounts, activeKey) ? toAccount(pool, activeKey) : undefined,\n\t\t});\n\t\tconst operation = (pool: StoredProviderPool, context: RunContext): OAuthAccountCreditFallbackResult => {\n\t\t\tif (context.currentKey !== expectedActiveKey || pool.active !== expectedActiveKey) {\n\t\t\t\treturn activeChanged(pool, context.currentKey);\n\t\t\t}\n\t\t\tconst untried = keysAfterActive(pool).find(\n\t\t\t\t(key) =>\n\t\t\t\t\tpool.accounts[key].credential.type === \"oauth\" &&\n\t\t\t\t\t!skipKeys?.has(key) &&\n\t\t\t\t\tisOAuthAccountUsable(pool.accounts[key], now),\n\t\t\t);\n\t\t\tif (untried !== undefined) {\n\t\t\t\tpool.accounts[untried].exhaustedUntil = undefined;\n\t\t\t\tpool.active = untried;\n\t\t\t\tif (pool.returnTo) pool.returnTo.fromKey = untried;\n\t\t\t\treturn { outcome: \"untried\", account: toAccount(pool, untried) };\n\t\t\t}\n\t\t\tif (!Object.hasOwn(pool.accounts, targetKey) || pool.accounts[targetKey].credential.type !== \"oauth\")\n\t\t\t\treturn { outcome: \"missing\" };\n\t\t\tpool.active = targetKey;\n\t\t\tif (pool.returnTo) pool.returnTo.fromKey = targetKey;\n\t\t\treturn { outcome: \"credit\", account: toAccount(pool, targetKey) };\n\t\t};\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toperationOptions,\n\t\t\toperation,\n\t\t\texpectedActiveKey,\n\t\t\tfalse,\n\t\t\tfalse,\n\t\t\tundefined,\n\t\t\tcanActivate,\n\t\t);\n\t}\n\n\t/** Store `credential` under its account key (keeping label/exhaustion); returns the key. */\n\tprivate upsertCredential(\n\t\tpool: StoredProviderPool,\n\t\tcredential: Credential | undefined,\n\t\tproviderId: string,\n\t\tactiveKey: string = pool.active,\n\t\tincludeApiKeys = false,\n\t): string | undefined {\n\t\tif (credential?.type === \"api_key\") {\n\t\t\tif (!includeApiKeys || !isApiKeyCredential(credential)) return undefined;\n\t\t\tconst existingKey = Object.keys(pool.accounts).find(\n\t\t\t\t(key) =>\n\t\t\t\t\tpool.accounts[key].credential.type === \"api_key\" &&\n\t\t\t\t\t(pool.accounts[key].credential as ApiKeyCredential).key === credential.key,\n\t\t\t);\n\t\t\tconst cachedKey = this.cache\n\t\t\t\t.get(providerId)\n\t\t\t\t?.find(\n\t\t\t\t\t(account) => account.credential.type === \"api_key\" && account.credential.key === credential.key,\n\t\t\t\t)?.key;\n\t\t\tconst key = existingKey ?? cachedKey ?? `account-${randomUUID()}`;\n\t\t\tconst existing = pool.accounts[key];\n\t\t\tpool.accounts[key] = {\n\t\t\t\tcredential: structuredClone(credential),\n\t\t\t\tlabel: existing?.label ?? `Account ${Object.keys(pool.accounts).length + 1}`,\n\t\t\t\texhaustedUntil: existing?.exhaustedUntil,\n\t\t\t\tquotaFailures: existing?.quotaFailures,\n\t\t\t\tcooldownRevision: existing?.cooldownRevision,\n\t\t\t};\n\t\t\treturn key;\n\t\t}\n\t\tif (credential?.type !== \"oauth\") return undefined;\n\t\tlet identity = this.getAccountIdentity(providerId, credential);\n\t\tconst loginId = this.loginIdentity(providerId, credential)?.key;\n\t\tconst stampedKey = credential.accountKey;\n\t\tconst matchesLogin = (stored: Credential) =>\n\t\t\tstored.type === \"oauth\" && loginId !== undefined && this.loginIdentity(providerId, stored)?.key === loginId;\n\t\tif (\n\t\t\tidentity &&\n\t\t\tisSafeAccountKey(stampedKey, credential) &&\n\t\t\tObject.hasOwn(pool.accounts, stampedKey) &&\n\t\t\tmatchesLogin(pool.accounts[stampedKey].credential)\n\t\t) {\n\t\t\t// Legacy local keys are not always account-UUIDs; trust the stamp only with a matching provider identity.\n\t\t\tidentity = { ...identity, key: stampedKey };\n\t\t}\n\t\tif (identity && !Object.hasOwn(pool.accounts, identity.key) && stampedKey === undefined) {\n\t\t\tconst matching =\n\t\t\t\tObject.hasOwn(pool.accounts, activeKey) && matchesLogin(pool.accounts[activeKey].credential)\n\t\t\t\t\t? activeKey\n\t\t\t\t\t: Object.keys(pool.accounts).find((key) => matchesLogin(pool.accounts[key].credential));\n\t\t\tidentity = {\n\t\t\t\tkey:\n\t\t\t\t\tmatching ??\n\t\t\t\t\tthis.cache.get(providerId)?.find((account) => matchesLogin(account.credential))?.key ??\n\t\t\t\t\t(includeApiKeys ? `account-${randomUUID()}` : identity.key),\n\t\t\t\tlabel: identity.label,\n\t\t\t};\n\t\t}\n\t\tif (!identity) {\n\t\t\t// Unidentified legacy Codex credentials stay unmatched; explicit addAccount stamps even opaque logins.\n\t\t\tif (providerId === \"openai-codex\") return undefined;\n\t\t\tconst cached = this.cache\n\t\t\t\t.get(providerId)\n\t\t\t\t?.find(\n\t\t\t\t\t(account) =>\n\t\t\t\t\t\taccount.credential.type === \"oauth\" &&\n\t\t\t\t\t\tsameCredential({ ...account.credential, accountKey: undefined }, credential),\n\t\t\t\t);\n\t\t\t// ponytail: unstamped credential assumed to be the active account's refresh; an older HUMAIN Code version logging in a different account overwrites the active entry\n\t\t\tidentity =\n\t\t\t\tactiveKey && Object.hasOwn(pool.accounts, activeKey) && pool.accounts[activeKey].credential.type === \"oauth\"\n\t\t\t\t\t? { key: activeKey, label: pool.accounts[activeKey].label }\n\t\t\t\t\t: cached\n\t\t\t\t\t\t? { key: cached.key, label: cached.label }\n\t\t\t\t\t\t: includeApiKeys\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tkey: `account-${randomUUID()}`,\n\t\t\t\t\t\t\t\t\tlabel: `Account ${pool.nextLocalAccountId ?? Object.keys(pool.accounts).length + 1}`,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: nextLocalAccountIdentity(pool);\n\t\t}\n\t\tconst existing = pool.accounts[identity.key];\n\t\tpool.accounts[identity.key] = {\n\t\t\tcredential:\n\t\t\t\tproviderId === \"openai-codex\" && !identity.key.startsWith(\"account-\")\n\t\t\t\t\t? structuredClone(credential)\n\t\t\t\t\t: { ...structuredClone(credential), accountKey: identity.key },\n\t\t\tlabel: existing?.label ?? identity.label,\n\t\t\texhaustedUntil: existing?.exhaustedUntil,\n\t\t\tquotaFailures: existing?.quotaFailures,\n\t\t\tcooldownRevision: existing?.cooldownRevision,\n\t\t};\n\t\treturn identity.key;\n\t}\n\n\t/**\n\t * Runs `operation` under the pool lock on the stored pool, with the credential auth.json holds synced in as the\n\t * active account. When auth.json changes between that read and the auth.json lock (a token refresh, another\n\t * process), the operation is re-applied to the latest credential under the auth.json lock, so a refresh can neither\n\t * resurrect a removed account nor be rolled back. Removals recheck even when the first plan needs no auth.json\n\t * change. An observation guard checks raw credentials before planning and under the auth.json lock; a mismatch\n\t * returns its `changed` result without pool writes or cache publication. With `expectedKey`, the\n\t * operation only applies while auth.json holds an OAuth credential of `expectedKey`, both when read and again under\n\t * the auth.json lock (even when auth.json needs no change); otherwise auth.json is not overwritten. The caller's\n\t * abort signal is honoured, including while waiting for the auth.json lock, until the commit point (just before\n\t * auth.json is changed) and ignored afterwards so the pool file write is never skipped once auth.json changed. The\n\t * cache is published only after the operation succeeded. `poolOnly` rechecks auth and merges it only into cache;\n\t * it never persists auth changes, activates credentials, or normalizes stored account metadata.\n\t */\n\tprivate async run<T>(\n\t\tproviderId: string,\n\t\tmode: \"read\" | \"write\",\n\t\tcallerOptions: AuthOperationOptions | undefined,\n\t\toperation: (pool: StoredProviderPool, context: RunContext) => T,\n\t\texpectedKey?: string,\n\t\trecheckAuth = false,\n\t\tincludeApiKeys = false,\n\t\tobservation?: { ifCurrent: NonNullable<CredentialDeleteOptions[\"ifCurrent\"]>; changed: T },\n\t\tcanActivate?: (from: PoolAccount, to: PoolAccount) => boolean,\n\t\tpoolOnly = false,\n\t\tusageRefresh?: {\n\t\t\tkey: string | undefined;\n\t\t\trefresh: UsageCredentialRefresh;\n\t\t\tresult: (value: UsageRefreshResult) => T;\n\t\t},\n\t): Promise<T | undefined> {\n\t\tconst operationPromise = (async () => {\n\t\t\tlet observationChanged = false;\n\t\t\tconst credentials = observation\n\t\t\t\t? getAccountCredentialStore(this.credentials, (current) => {\n\t\t\t\t\t\tconst matches = observation.ifCurrent(current);\n\t\t\t\t\t\tif (!matches) observationChanged = true;\n\t\t\t\t\t\treturn matches;\n\t\t\t\t\t})\n\t\t\t\t: this.credentials;\n\t\t\t// `outerLink` governs the pool lock and the pool-file write; `authLink` governs the auth.json lock wait.\n\t\t\t// Both forward the caller's abort until the commit point; `authLink` outlives it until auth.json settles.\n\t\t\tconst passthrough = { options: callerOptions, detach: () => {} };\n\t\t\tconst outerLink = mode === \"write\" ? linkAbortSignal(callerOptions) : passthrough;\n\t\t\tconst authLink = mode === \"write\" ? linkAbortSignal(callerOptions) : passthrough;\n\t\t\tconst options = outerLink.options;\n\t\t\t/** Last abort check before auth.json changes; afterwards the pool-file write must not be skipped. */\n\t\t\tconst commitAuthChange = () => {\n\t\t\t\tcallerOptions?.signal?.throwIfAborted();\n\t\t\t\touterLink.detach();\n\t\t\t};\n\t\t\tconst published: { view?: PoolAccount[] } = {};\n\t\t\ttry {\n\t\t\t\tconst outcome = await this.storage.withLockAsync(async (content, save) => {\n\t\t\t\t\tlet data: PoolData;\n\t\t\t\t\tlet corrupt = false;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tdata = parsePoolData(content);\n\t\t\t\t\t\tthis.error = undefined;\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthis.error = `Invalid ${this.location}: ${error instanceof Error ? error.message : String(error)}`;\n\t\t\t\t\t\tif (mode === \"write\")\n\t\t\t\t\t\t\tthrow new Error(`Refusing to modify corrupt ${this.location}. Fix or delete it first.`);\n\t\t\t\t\t\tcorrupt = true;\n\t\t\t\t\t\tdata = {};\n\t\t\t\t\t}\n\t\t\t\t\tconst legacy =\n\t\t\t\t\t\t!corrupt &&\n\t\t\t\t\t\tcontent !== undefined &&\n\t\t\t\t\t\t!Object.hasOwn(JSON.parse(stripBom(content).trim() || \"{}\"), \"version\");\n\t\t\t\t\t// Snapshot before planning mutates data: a newly created empty file has no legacy accounts to back up.\n\t\t\t\t\tconst hasLegacyAccounts = legacy && Object.keys(data).length > 0;\n\t\t\t\t\tlet backedUp = false;\n\t\t\t\t\tconst serialize = (providers: PoolData): string => {\n\t\t\t\t\t\tif (hasLegacyAccounts && this.storage instanceof FileAuthStorageBackend && !this.backupPath)\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\"File-backed account migration requires OAuthAccountPool.create() or a backup path\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\tif (hasLegacyAccounts && !backedUp && this.backupPath) {\n\t\t\t\t\t\t\tif (existsSync(this.backupPath)) {\n\t\t\t\t\t\t\t\tif (readFileSync(this.backupPath, \"utf8\") !== content)\n\t\t\t\t\t\t\t\t\tthrow new Error(\"Account migration backup already exists; refusing to overwrite it\");\n\t\t\t\t\t\t\t\tconst fd = openSync(this.backupPath, \"r\");\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tfchmodSync(fd, 0o600);\n\t\t\t\t\t\t\t\t\tfsyncSync(fd);\n\t\t\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\t\t\tcloseSync(fd);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tconst fd = openSync(this.backupPath, \"wx\", 0o600);\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\twriteFileSync(fd, content!, \"utf8\");\n\t\t\t\t\t\t\t\t\tfsyncSync(fd);\n\t\t\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\t\t\tcloseSync(fd);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbackedUp = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Use the backend's actual path, not its display location or optional migration backup path.\n\t\t\t\t\t\tif (this.storage instanceof FileAuthStorageBackend) this.storage.makePrivate();\n\t\t\t\t\t\treturn JSON.stringify({ version: 2, providers }, null, 2);\n\t\t\t\t\t};\n\t\t\t\t\tconst stored = Object.hasOwn(data, providerId) ? data[providerId] : undefined;\n\t\t\t\t\tconst before = JSON.stringify(stored);\n\t\t\t\t\t/** Applies `operation` to a copy of the stored pool as if auth.json held `credential`. */\n\t\t\t\t\tconst plan = (credential: Credential | undefined) => {\n\t\t\t\t\t\tlet pool: StoredProviderPool = stored ? structuredClone(stored) : { active: \"\", accounts: {} };\n\t\t\t\t\t\tconst currentKey = this.upsertCredential(pool, credential, providerId, pool.active, includeApiKeys);\n\t\t\t\t\t\tif (providerId !== \"openai-codex\") reserveLocalAccountKeys(pool);\n\t\t\t\t\t\tif (currentKey !== undefined) pool.active = currentKey;\n\t\t\t\t\t\t/** The pool before the operation, holding the source tokens auth.json may stop holding. */\n\t\t\t\t\t\tconst source = structuredClone(pool);\n\t\t\t\t\t\tconst context: RunContext = {\n\t\t\t\t\t\t\tcurrentKey,\n\t\t\t\t\t\t\tcurrentCredential: currentKey === undefined ? undefined : pool.accounts[currentKey].credential,\n\t\t\t\t\t\t};\n\t\t\t\t\t\t// Marker-only mutations validate against auth.json but must not persist its unrelated changes.\n\t\t\t\t\t\tif (poolOnly) pool = stored ? structuredClone(stored) : { active: \"\", accounts: {} };\n\t\t\t\t\t\tconst result = operation(pool, context);\n\t\t\t\t\t\tconst keys = Object.keys(pool.accounts);\n\t\t\t\t\t\tif (!poolOnly && !Object.hasOwn(pool.accounts, pool.active)) pool.active = \"\";\n\t\t\t\t\t\tconst active = pool.accounts[pool.active];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!poolOnly &&\n\t\t\t\t\t\t\tactive?.credential.type === \"api_key\" &&\n\t\t\t\t\t\t\t(active.credential.key?.includes(\"$\") || active.credential.key?.startsWith(\"!\"))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tconst stamped = { ...active.credential, accountKey: pool.active };\n\t\t\t\t\t\t\tactive.credential = stamped;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn { pool, source, context, result, empty: keys.length === 0 || pool.active === \"\" };\n\t\t\t\t\t};\n\n\t\t\t\t\t// auth.json always holds the active account (pi-ai may have refreshed it): sync it into the view.\n\t\t\t\t\tconst current = await credentials.read(providerId, options);\n\t\t\t\t\tif (observationChanged) return { result: observation!.changed };\n\t\t\t\t\tlet next = plan(current);\n\t\t\t\t\toptions?.signal?.throwIfAborted();\n\t\t\t\t\tif (mode === \"read\") {\n\t\t\t\t\t\t// OAuth-only eligibility must not erase a generalized transient identity. Keep cache reconciliation\n\t\t\t\t\t\t// separate from the operation's view, so legacy mutations never adopt API keys implicitly.\n\t\t\t\t\t\tconst view = structuredClone(next.pool);\n\t\t\t\t\t\tif (!includeApiKeys) this.upsertCredential(view, current, providerId, view.active, true);\n\t\t\t\t\t\tthis.cache.set(providerId, toPoolAccounts(view));\n\t\t\t\t\t\treturn { result: next.result };\n\t\t\t\t\t}\n\t\t\t\t\tif (next.result === undefined && !usageRefresh) return { result: undefined };\n\t\t\t\t\t// Prepare backup and private permissions before changing auth.json, even without a checkpoint.\n\t\t\t\t\t// Observation guards defer setup until their auth-lock comparison succeeds.\n\t\t\t\t\tif (!observation && JSON.stringify(next.pool) !== before) serialize(data);\n\t\t\t\t\t/** Re-applies the operation when auth.json no longer holds the credential `next` was planned for. */\n\t\t\t\t\tlet planned = current;\n\t\t\t\t\tconst replan = (latest: Credential | undefined) => {\n\t\t\t\t\t\tif (poolOnly || !sameCredential(latest, planned)) {\n\t\t\t\t\t\t\tnext = plan(latest);\n\t\t\t\t\t\t\tplanned = latest;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn next;\n\t\t\t\t\t};\n\t\t\t\t\t/** This provider's pool as last written to the pool file, including a checkpoint. */\n\t\t\t\t\tlet persisted = before;\n\n\t\t\t\t\tconst { currentKey } = next.context;\n\t\t\t\t\tif (usageRefresh) {\n\t\t\t\t\t\t// Same lock order as switching. Inference also takes the auth lock before refreshing;\n\t\t\t\t\t\t// re-read under both locks before consuming a possibly single-use refresh token.\n\t\t\t\t\t\tawait credentials.modify(\n\t\t\t\t\t\t\tproviderId,\n\t\t\t\t\t\t\tasync (latest) => {\n\t\t\t\t\t\t\t\tconst { pool, context } = replan(latest);\n\t\t\t\t\t\t\t\tconst key = usageRefresh.key ?? pool.active;\n\t\t\t\t\t\t\t\tconst account = Object.hasOwn(pool.accounts, key) ? pool.accounts[key] : undefined;\n\t\t\t\t\t\t\t\tif (account?.credential.type !== \"oauth\") return undefined;\n\t\t\t\t\t\t\t\tif (account.credential.expires > Date.now()) {\n\t\t\t\t\t\t\t\t\tnext.result = usageRefresh.result(toAccount(pool, key));\n\t\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tserialize(data);\n\t\t\t\t\t\t\t\t// Once the grant starts, closing a popup must not discard a rotated token.\n\t\t\t\t\t\t\t\tcommitAuthChange();\n\t\t\t\t\t\t\t\tauthLink.detach();\n\t\t\t\t\t\t\t\tconst refreshed = await usageRefresh.refresh(account.credential);\n\t\t\t\t\t\t\t\tif (typeof refreshed === \"string\") {\n\t\t\t\t\t\t\t\t\tnext.result = usageRefresh.result(refreshed);\n\t\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\taccount.credential = { ...refreshed, accountKey: key };\n\t\t\t\t\t\t\t\tnext.result = usageRefresh.result(toAccount(pool, key));\n\t\t\t\t\t\t\t\treturn context.currentKey === key ? structuredClone(account.credential) : undefined;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthLink.options,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if (expectedKey !== undefined && currentKey !== expectedKey) {\n\t\t\t\t\t\t// The operation declined to act (active_changed): no auth.json write; only the sync is persisted.\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tpoolOnly ||\n\t\t\t\t\t\t(!next.empty && (currentKey !== undefined || next.context.activate)) ||\n\t\t\t\t\t\t(recheckAuth && currentKey === undefined)\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst authChange =\n\t\t\t\t\t\t\t!next.empty && !sameCredential(next.pool.accounts[next.pool.active].credential, current);\n\t\t\t\t\t\tif (authChange || expectedKey !== undefined || recheckAuth) {\n\t\t\t\t\t\t\t// Guarded operations and removals recheck under the auth.json lock, even without an initial auth change.\n\t\t\t\t\t\t\tawait credentials.modify(\n\t\t\t\t\t\t\t\tproviderId,\n\t\t\t\t\t\t\t\tasync (latest) => {\n\t\t\t\t\t\t\t\t\tauthLink.options?.signal?.throwIfAborted();\n\t\t\t\t\t\t\t\t\tconst { pool, source, context, result, empty } = replan(latest);\n\t\t\t\t\t\t\t\t\t// Declined, or adoption/removal facing a credential it must not replace (non-OAuth or unmatched).\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tpoolOnly ||\n\t\t\t\t\t\t\t\t\t\tresult === undefined ||\n\t\t\t\t\t\t\t\t\t\t(expectedKey !== undefined && context.currentKey !== expectedKey) ||\n\t\t\t\t\t\t\t\t\t\t(context.currentKey === undefined && !context.activate)\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// A re-plan that emptied the pool cannot delete inside modify: the guarded delete below does.\n\t\t\t\t\t\t\t\t\tif (empty) return undefined;\n\t\t\t\t\t\t\t\t\tconst target = pool.accounts[pool.active].credential;\n\t\t\t\t\t\t\t\t\t// Policy can change while either lock is awaited, even without a credential change.\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tcanActivate &&\n\t\t\t\t\t\t\t\t\t\t(context.currentKey === undefined ||\n\t\t\t\t\t\t\t\t\t\t\t!canActivate(\n\t\t\t\t\t\t\t\t\t\t\t\ttoPoolAccount(source, context.currentKey),\n\t\t\t\t\t\t\t\t\t\t\t\ttoPoolAccount(pool, pool.active),\n\t\t\t\t\t\t\t\t\t\t\t))\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\tthrow new Error(\"Account activation is no longer authorized\");\n\t\t\t\t\t\t\t\t\tif (sameCredential(target, latest)) return undefined;\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tlatest !== undefined &&\n\t\t\t\t\t\t\t\t\t\tpool.active !== context.currentKey &&\n\t\t\t\t\t\t\t\t\t\tJSON.stringify(source) !== persisted\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t// Keep the latest source tokens durable before auth.json stops holding them.\n\t\t\t\t\t\t\t\t\t\tsave(serialize({ ...data, [providerId]: source }));\n\t\t\t\t\t\t\t\t\t\tpersisted = JSON.stringify(source);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// A concurrent refresh can turn an initially unchanged plan into an auth write.\n\t\t\t\t\t\t\t\t\tserialize(data);\n\t\t\t\t\t\t\t\t\tcommitAuthChange();\n\t\t\t\t\t\t\t\t\treturn structuredClone(target);\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tauthLink.options,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (observationChanged) return { result: observation!.changed };\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (!poolOnly && next.result !== undefined && next.empty && next.context.currentKey !== undefined) {\n\t\t\t\t\t\t// The last account was removed (by the first plan or a re-plan above): delete the auth.json credential\n\t\t\t\t\t\t// only while, under the auth.json lock, it still belongs to a removed account. An API key, another\n\t\t\t\t\t\t// account (adopted by the re-plan), or an unmatched credential stays.\n\t\t\t\t\t\tconst deleteOptions: CredentialDeleteOptions = {\n\t\t\t\t\t\t\t...authLink.options,\n\t\t\t\t\t\t\tifCurrent: (latest) => {\n\t\t\t\t\t\t\t\tconst { result, empty, context } = replan(latest);\n\t\t\t\t\t\t\t\tif (result === undefined || !empty || context.currentKey === undefined) return false;\n\t\t\t\t\t\t\t\tserialize(data);\n\t\t\t\t\t\t\t\tcommitAuthChange();\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t\tawait credentials.delete(providerId, deleteOptions);\n\t\t\t\t\t\tif (observationChanged) return { result: observation!.changed };\n\t\t\t\t\t}\n\t\t\t\t\tconst { pool, result } = next;\n\t\t\t\t\t// A declined re-plan still adopts the latest credential without removing any account.\n\t\t\t\t\tif (Object.keys(pool.accounts).length === 0 && pool.nextLocalAccountId === undefined)\n\t\t\t\t\t\tdelete data[providerId];\n\t\t\t\t\telse\n\t\t\t\t\t\tObject.defineProperty(data, providerId, {\n\t\t\t\t\t\t\tvalue: pool,\n\t\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\t\tconfigurable: true,\n\t\t\t\t\t\t\twritable: true,\n\t\t\t\t\t\t});\n\t\t\t\t\tconst view = structuredClone(pool);\n\t\t\t\t\tif (poolOnly) {\n\t\t\t\t\t\tconst currentKey = this.upsertCredential(\n\t\t\t\t\t\t\tview,\n\t\t\t\t\t\t\tnext.context.currentCredential ?? planned,\n\t\t\t\t\t\t\tproviderId,\n\t\t\t\t\t\t\tview.active,\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (currentKey !== undefined) view.active = currentKey;\n\t\t\t\t\t}\n\t\t\t\t\tif (!poolOnly && !includeApiKeys && planned?.type === \"api_key\" && !next.context.activate)\n\t\t\t\t\t\tthis.upsertCredential(view, planned, providerId, view.active, true);\n\t\t\t\t\tpublished.view = toPoolAccounts(view);\n\t\t\t\t\tconst changed = !corrupt && JSON.stringify(data[providerId]) !== persisted;\n\t\t\t\t\treturn { result, next: changed ? serialize(data) : undefined };\n\t\t\t\t}, options);\n\t\t\t\t// Publish only once the whole operation (auth.json and pool file) succeeded.\n\t\t\t\tif (published.view) this.cache.set(providerId, published.view);\n\t\t\t\treturn outcome;\n\t\t\t} finally {\n\t\t\t\touterLink.detach();\n\t\t\t\tauthLink.detach();\n\t\t\t}\n\t\t})();\n\t\tif (mode === \"write\") {\n\t\t\tconst pending = operationPromise.then(\n\t\t\t\t() => undefined,\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\tthis.pendingWrites.add(pending);\n\t\t\tvoid pending.finally(() => this.pendingWrites.delete(pending));\n\t\t}\n\t\treturn operationPromise;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"oauth-account-pool.js","sourceRoot":"","sources":["../../src/core/oauth-account-pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GA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AE,IAAI,CAAC,CAAC;oBACrE,SAAS,CAAC,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;oBACtC,MAAM,OAAO,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,KAAK,SAAS,CAAC;oBAC3E,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;gBAChE,CAAC,EAAE,OAAO,CAAC,CAAC;gBACZ,6EAA6E;gBAC7E,IAAI,SAAS,CAAC,IAAI;oBAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;gBAC/D,OAAO,OAAO,CAAC;YAChB,CAAC;oBAAS,CAAC;gBACV,SAAS,CAAC,MAAM,EAAE,CAAC;gBACnB,QAAQ,CAAC,MAAM,EAAE,CAAC;YACnB,CAAC;QACF,CAAC,CAAC,EAAE,CAAC;QACL,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YACtB,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CACpC,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CACf,CAAC;YACF,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAChC,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,gBAAgB,CAAC;IACzB,CAAC;CACD","sourcesContent":["/**\n * Multi-account credential pool with OAuth-only runtime APIs.\n *\n * auth.json keeps holding exactly one credential per provider (the ACTIVE account) so pi-ai reads\n * and refreshes it unchanged. This module stores OAuth and literal API-key entries in the versioned\n * `oauth-accounts.json` next to auth.json. Generalized additions use random local keys; existing\n * OAuth runtime APIs and migrated keys remain usable until runtime/UI integration.\n *\n * Reads (`list`, `getActive`, `getCachedAccounts`) never write: they merge the credential currently\n * stored in auth.json into the returned view in memory only. Mutations (`add`, `setActive`,\n * `remove`, `failover`, `adoptCurrent`) first sync the auth.json credential back into the pool\n * (pi-ai may have refreshed it), then write the pool file and, when the active account changed,\n * the new active credential into auth.json. All of this happens under one pool-file lock.\n * `clearExhaustion` only clears matching stored quota markers, rechecking auth and merging its changes only in cache.\n */\n\nimport type {\n\tApiKeyCredential,\n\tAssistantMessage,\n\tAuthOperationOptions,\n\tCredential,\n\tCredentialDeleteOptions,\n\tCredentialStore,\n\tOAuthCredential,\n} from \"@earendil-works/pi-ai\";\nimport { getOpenAICodexTokenIdentity } from \"@earendil-works/pi-ai\";\nimport { randomUUID } from \"crypto\";\nimport { closeSync, existsSync, fchmodSync, fsyncSync, openSync, readFileSync, writeFileSync } from \"fs\";\nimport { join } from \"path\";\nimport { getAgentDir } from \"../config.ts\";\nimport { normalizePath } from \"../utils/paths.ts\";\nimport { stripBom } from \"../utils/text.ts\";\nimport {\n\ttype AuthStorageBackend,\n\tFileAuthStorageBackend,\n\tgetAccountCredentialStore,\n\tInMemoryAuthStorageBackend,\n} from \"./auth-storage.ts\";\n\ntype UsageRefreshResult = OAuthAccount | \"refresh_failed\" | \"refresh_rejected\";\ntype UsageCredentialRefresh = (\n\tcredential: OAuthCredential,\n) => Promise<OAuthCredential | \"refresh_failed\" | \"refresh_rejected\">;\n\nexport interface OAuthAccountIdentity {\n\t/** Stable per-provider account key (for example the ChatGPT account id). */\n\tkey: string;\n\t/** Human-readable default label (email when available). */\n\tlabel: string;\n}\n\n/** Derives provider-specific identity before the generic credential fields are considered. */\nexport type OAuthAccountIdentityResolver = (credential: OAuthCredential) => OAuthAccountIdentity | undefined;\n\nexport interface PoolAccount<T extends Credential = Credential> {\n\t/** Unsafe stored ownership; excluded from activation and refresh until matching sign-in. */\n\tquarantine?: { identity?: string };\n\tkey: string;\n\tlabel: string;\n\tcredential: T;\n\t/** Epoch ms until which the account is treated as out of quota. */\n\texhaustedUntil?: number;\n\t/** Observed failure count, used for bounded cooldown backoff. */\n\tquotaFailures?: number;\n\t/** Monotonic cooldown observation revision; absent legacy values mean zero. */\n\tcooldownRevision?: number;\n\tactive: boolean;\n}\n\nexport type OAuthAccount = PoolAccount<OAuthCredential>;\n\nexport type AccountRemoveResult<T extends Credential = Credential> =\n\t| { status: \"removed\"; removed: PoolAccount<T>; active: PoolAccount<T> | undefined }\n\t| { status: \"unmatched\" }\n\t| { status: \"changed\" };\n\nexport type OAuthAccountRemoveResult =\n\t| {\n\t\t\tstatus: \"removed\";\n\t\t\tremoved: OAuthAccount;\n\t\t\t/** Account promoted to active, or undefined when the pool is now empty. */\n\t\t\tactive: OAuthAccount | undefined;\n\t }\n\t/** No account has the key, or (without a key) auth.json holds no credential of an account. Nothing changed. */\n\t| { status: \"unmatched\" }\n\t/** auth.json changed under the auth.json lock; nothing removed, but the latest credential is synced into the pool. */\n\t| { status: \"changed\" };\n\nexport interface OAuthAccountFailoverOptions extends AuthOperationOptions {\n\t/**\n\t * Account key the caller observed as active. Checked under the pool lock against the OAuth credential stored\n\t * in auth.json, and again at the auth.json write; the failover is skipped (`active_changed`) when auth.json\n\t * holds no OAuth credential, an unidentifiable one, or another account's.\n\t * Aborting `signal` before the auth.json write throws and changes nothing; after it, the operation completes.\n\t */\n\texpectedActiveKey: string;\n\t/** Epoch ms until which the expected account is treated as out of quota. Omit to leave its marker unchanged. */\n\texhaustedUntil?: number;\n\t/** Reference time for exhaustion checks. Defaults to `Date.now()`. */\n\tnow?: number;\n\t/** Account keys that must not be selected as the failover target (for example accounts already tried). */\n\tskipKeys?: ReadonlySet<string>;\n\t/** Runtime quota rotation records a preferred account and applies the bounded cooldown when reset is unknown. */\n\ttrackPreferred?: boolean;\n\t/** Synchronous live policy check under the auth lock, before any activation checkpoint or credential commit. */\n\tcanActivate?: (from: PoolAccount, to: PoolAccount) => boolean;\n}\n\nexport interface AccountFailoverOptions extends OAuthAccountFailoverOptions {\n\t/** Caller has resolved explicit user consent; target must still exist as a same-provider stored API key. */\n\tapiKeyFallback?: string;\n\t/** Only subscription-marked API-key providers may rotate among keys automatically. */\n\tallowApiKeyRotation?: boolean;\n\t/** An OAuth rotation already recorded this failure before considering the consent target. */\n\tmarkExhausted?: boolean;\n\t/** Ordered same-type targets, replacing the round-robin order. Keys not in the pool are ignored. */\n\tcandidateKeys?: readonly string[];\n\t/** Live eligibility of a same-type target, evaluated under the pool lock. */\n\tcandidateFilter?: (from: PoolAccount, to: PoolAccount) => boolean;\n}\n\nexport type AccountFailoverResult =\n\t| { switched: true; from: PoolAccount; to: PoolAccount; total: number }\n\t| {\n\t\t\tswitched: false;\n\t\t\treason: \"active_changed\" | \"exhausted\";\n\t\t\tactive: PoolAccount | undefined;\n\t\t\ttotal: number;\n\t\t\tearliestResetAt: number | undefined;\n\t };\n\nexport type OAuthAccountFailoverResult =\n\t| { switched: true; from: OAuthAccount; to: OAuthAccount; total: number }\n\t| {\n\t\t\tswitched: false;\n\t\t\t/**\n\t\t\t * `active_changed`: auth.json no longer holds the expected account (another process switched\n\t\t\t * accounts, or the credential is not a resolvable OAuth one); nothing was marked.\n\t\t\t * `exhausted`: no other account is usable (the expected account is marked only when requested).\n\t\t\t */\n\t\t\treason: \"active_changed\" | \"exhausted\";\n\t\t\t/** Currently active account (after sync), if auth.json holds a resolvable OAuth credential. */\n\t\t\tactive: OAuthAccount | undefined;\n\t\t\ttotal: number;\n\t\t\t/** Earliest `exhaustedUntil` still in the future among pooled accounts. */\n\t\t\tearliestResetAt: number | undefined;\n\t };\n\nexport interface OAuthAccountCreditFallbackOptions extends AuthOperationOptions {\n\t/**\n\t * Account key the caller observed as active. Checked under the pool lock against the OAuth credential stored\n\t * in auth.json, and again at the auth.json write; nothing changes (`active_changed`) when it no longer matches.\n\t * Aborting `signal` before the auth.json write throws and changes nothing; after it, the operation completes.\n\t */\n\texpectedActiveKey: string;\n\t/** Account that reported exhausted plan quota with credits available; selected for possible credit use. */\n\ttargetKey: string;\n\t/** Account keys that are not untried (for example accounts already tried this run). */\n\tskipKeys?: ReadonlySet<string>;\n\t/** Reference time for exhaustion checks. Defaults to `Date.now()`. */\n\tnow?: number;\n\t/** Reauthorize even when credit recovery would keep the current credential. */\n\tcanActivate?: (from: PoolAccount, to: PoolAccount) => boolean;\n}\n\nexport type OAuthAccountCreditFallbackResult =\n\t/** auth.json no longer holds the expected account; nothing changed. `active` is the current resolvable active account. */\n\t| { outcome: \"active_changed\"; active: OAuthAccount | undefined }\n\t/** An untried usable account exists now and was activated. */\n\t| { outcome: \"untried\"; account: OAuthAccount }\n\t/** The credit-capable target was activated. */\n\t| { outcome: \"credit\"; account: OAuthAccount }\n\t/** The credit-capable target no longer exists; nothing changed. */\n\t| { outcome: \"missing\" };\n\ninterface StoredAccount {\n\t/** Retain uncertain grants in place until an explicit matching sign-in replaces them. */\n\tquarantine?: { identity?: string };\n\tcredential: Credential;\n\tlabel: string;\n\texhaustedUntil?: number;\n\tquotaFailures?: number;\n\tcooldownRevision?: number;\n}\n\n/** Tunable fallback cooldown bounds; never probe a provider in the background. */\nexport const ACCOUNT_RETURN_COOLDOWN_MS = 60_000;\nexport const ACCOUNT_RETURN_MAX_COOLDOWN_MS = 30 * 60_000;\n\ninterface StoredProviderPool {\n\tactive: string;\n\taccounts: Record<string, StoredAccount>;\n\t/** Next local key suffix. Retained even when every account has been removed. */\n\tnextLocalAccountId?: number;\n\t/** Persisted across sessions/Flow. A manual activation cancels this pending return. */\n\treturnTo?: { preferredKey: string; fromKey: string };\n}\n\ntype PoolData = Record<string, StoredProviderPool>;\n\nexport function resolveOpenAICodexAccountIdentity(credential: OAuthCredential): OAuthAccountIdentity | undefined {\n\tconst identity = getOpenAICodexTokenIdentity(credential.access);\n\tif (!identity) return undefined;\n\treturn { key: identity.accountId, label: identity.email ?? identity.accountId.slice(0, 8) };\n}\n\nexport const OAUTH_ACCOUNT_IDENTITY_FIELDS = [\"accountKey\", \"accountId\", \"organizationId\", \"accountLabel\"] as const;\n\n/** Identity values are persisted and displayed: bounded, printable, and free of the credential's tokens. */\nfunction isSafeIdentityValue(value: unknown, credential: Credential): value is string {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\tvalue.trim().length > 0 &&\n\t\tvalue.length <= 320 &&\n\t\t!/[\\p{Cc}\\p{Cf}]/u.test(value) &&\n\t\t!(\n\t\t\tcredential.type === \"oauth\"\n\t\t\t\t? [credential.access, credential.refresh]\n\t\t\t\t: [credential.key ?? \"\", ...Object.values(credential.env ?? {})]\n\t\t).some((token) => token.length > 0 && value.includes(token))\n\t);\n}\n\n/** Account keys are also object keys: never a name `Object.prototype` defines (`__proto__`, `constructor`, ...). */\nfunction isSafeAccountKey(key: unknown, credential: Credential): key is string {\n\treturn isSafeIdentityValue(key, credential) && !(key in Object.prototype);\n}\n\n/** Resolve non-secret identity metadata, preferring the stamped pool key. */\nexport function resolveGenericAccountIdentity(credential: OAuthCredential): OAuthAccountIdentity | undefined {\n\tconst organization = isSafeIdentityValue(credential.organizationId, credential)\n\t\t? `-org-${credential.organizationId}`\n\t\t: \"\";\n\tconst accountId = isSafeIdentityValue(credential.accountId, credential)\n\t\t? `acct-${credential.accountId}${organization}`\n\t\t: undefined;\n\tconst key = [credential.accountKey, accountId].find((value): value is string => isSafeAccountKey(value, credential));\n\tif (!key) return undefined;\n\tconst label = isSafeIdentityValue(credential.accountLabel, credential) ? credential.accountLabel : key;\n\treturn { key, label };\n}\n\nfunction reserveLocalAccountKeys(pool: StoredProviderPool): void {\n\t// Older version-1 pools have no counter; also reserve keys restored from auth.json after a failed pool write.\n\tfor (const key of Object.keys(pool.accounts)) {\n\t\tif (!/^local-\\d+$/.test(key)) continue;\n\t\tconst index = Number(key.slice(6));\n\t\tif (!Number.isSafeInteger(index) || index >= Number.MAX_SAFE_INTEGER) {\n\t\t\tthrow new Error(\"Local OAuth account key range exhausted\");\n\t\t}\n\t\tpool.nextLocalAccountId = Math.max(pool.nextLocalAccountId ?? 1, index + 1);\n\t}\n}\n\nfunction nextLocalAccountIdentity(pool: StoredProviderPool): OAuthAccountIdentity {\n\treserveLocalAccountKeys(pool);\n\tconst index = pool.nextLocalAccountId ?? 1;\n\tif (index >= Number.MAX_SAFE_INTEGER) throw new Error(\"Local OAuth account key range exhausted\");\n\tpool.nextLocalAccountId = index + 1;\n\treturn { key: `local-${index}`, label: `Account ${index}` };\n}\n\nexport const DEFAULT_OAUTH_ACCOUNT_IDENTITY_RESOLVERS: ReadonlyMap<string, OAuthAccountIdentityResolver> = new Map([\n\t[\"openai-codex\", resolveOpenAICodexAccountIdentity],\n]);\n\nconst USAGE_LIMIT_ERROR_CODE_PATTERN = /usage_limit_reached|usage_not_included|rate_limit_exceeded|insufficient_quota/i;\n\nconst MS_PER_MINUTE = 60_000;\n/** 366 days plus one day of margin: the furthest a reported reset time may lie in the future. */\nconst MAX_RESET_HORIZON_MS = (527040 + 1440) * MS_PER_MINUTE;\n\n/** A reset time is plausible only when it lies in the future and within the longest rate-limit window. */\nfunction isPlausibleResetAt(value: number, nowMs: number): boolean {\n\treturn value > nowMs && value <= nowMs + MAX_RESET_HORIZON_MS;\n}\n\nexport interface UsageLimitSignal {\n\t/** Epoch ms when the provider expects the limit to reset, when reported. */\n\tresetsAt: number | undefined;\n}\n\n/**\n * Inspect the latest `provider_http_error` diagnostic of a failed assistant message and report\n * whether it is a terminal usage-limit failure that warrants switching OAuth accounts.\n * Authentication failures (401/403) are never usage limits, whatever code or reset time they carry.\n */\nexport function getUsageLimitSignal(message: AssistantMessage): UsageLimitSignal | undefined {\n\tif (message.stopReason !== \"error\") return undefined;\n\tconst nowMs = Date.now();\n\tconst details = message.diagnostics?.findLast((entry) => entry.type === \"provider_http_error\")?.details;\n\tif (details?.retryable !== false) return undefined;\n\tif (details.status === 401 || details.status === 403) return undefined;\n\tconst resetsAt =\n\t\ttypeof details.resetsAt === \"number\" &&\n\t\tNumber.isFinite(details.resetsAt) &&\n\t\tisPlausibleResetAt(details.resetsAt, nowMs)\n\t\t\t? details.resetsAt\n\t\t\t: undefined;\n\tconst isUsageLimit =\n\t\tdetails.status === 429 ||\n\t\t(typeof details.code === \"string\" && USAGE_LIMIT_ERROR_CODE_PATTERN.test(details.code)) ||\n\t\tresetsAt !== undefined;\n\treturn isUsageLimit ? { resetsAt } : undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nexport interface CodexRateLimitWindow {\n\tusedPercent: number;\n\twindowMinutes?: number;\n\t/** Epoch ms. */\n\tresetsAt?: number;\n}\n\nexport interface CodexRateLimitSnapshot {\n\tprimary?: CodexRateLimitWindow;\n\tsecondary?: CodexRateLimitWindow;\n\tcredits?: { hasCredits: boolean; unlimited: boolean; balance?: string };\n\trateLimitReachedType?: string;\n}\n\nconst BALANCE_PATTERN = /^-?\\d{1,15}(\\.\\d{1,8})?$/;\nconst REACHED_TYPE_PATTERN = /^[a-z0-9_]{1,64}$/;\n/** 366 days: the longest rate-limit window the provider could plausibly report. */\nconst MAX_WINDOW_MINUTES = 527040;\n\nfunction finiteNumber(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\nfunction parseRateLimitWindow(value: unknown, nowMs: number): CodexRateLimitWindow | undefined {\n\tif (!isRecord(value)) return undefined;\n\tconst usedPercent = finiteNumber(value.usedPercent);\n\tif (usedPercent === undefined || usedPercent < 0 || usedPercent > 1000) return undefined;\n\tconst window: CodexRateLimitWindow = { usedPercent };\n\tconst windowMinutes = finiteNumber(value.windowMinutes);\n\tif (windowMinutes !== undefined && windowMinutes > 0 && windowMinutes <= MAX_WINDOW_MINUTES) {\n\t\twindow.windowMinutes = windowMinutes;\n\t}\n\tconst resetsAt = finiteNumber(value.resetsAt);\n\tif (resetsAt !== undefined && isPlausibleResetAt(resetsAt, nowMs)) window.resetsAt = resetsAt;\n\treturn window;\n}\n\n/** Read the latest `provider_rate_limit` diagnostic of an assistant message, ignoring malformed fields. */\nexport function getRateLimitSnapshot(message: AssistantMessage): CodexRateLimitSnapshot | undefined {\n\tconst details = message.diagnostics?.findLast((entry) => entry.type === \"provider_rate_limit\")?.details;\n\tif (!isRecord(details)) return undefined;\n\tconst nowMs = Date.now();\n\tconst snapshot: CodexRateLimitSnapshot = {};\n\tconst primary = parseRateLimitWindow(details.primary, nowMs);\n\tif (primary) snapshot.primary = primary;\n\tconst secondary = parseRateLimitWindow(details.secondary, nowMs);\n\tif (secondary) snapshot.secondary = secondary;\n\tconst credits = details.credits;\n\tif (isRecord(credits) && typeof credits.hasCredits === \"boolean\" && typeof credits.unlimited === \"boolean\") {\n\t\tsnapshot.credits = { hasCredits: credits.hasCredits, unlimited: credits.unlimited };\n\t\tconst balance = typeof credits.balance === \"string\" ? credits.balance.trim() : \"\";\n\t\tif (BALANCE_PATTERN.test(balance)) snapshot.credits.balance = balance;\n\t}\n\tif (typeof details.rateLimitReachedType === \"string\" && REACHED_TYPE_PATTERN.test(details.rateLimitReachedType))\n\t\tsnapshot.rateLimitReachedType = details.rateLimitReachedType;\n\treturn snapshot;\n}\n\nexport interface QuotaExhaustionSignal {\n\t/**\n\t * usage_limit: request failed because plan quota is exhausted.\n\t * credits: a completed response was served while a plan window was reported at 100% or more and credits were\n\t * available, so the response may be billed to credits. The provider does not confirm billing.\n\t */\n\tkind: \"usage_limit\" | \"credits\";\n\tresetsAt: number | undefined;\n\t/** true/false when the provider reported credit state; undefined when unknown. */\n\tcreditsAvailable: boolean | undefined;\n\t/**\n\t * \"possible\" when credits may be used or billed (the credits kind, or a usage limit with credits available).\n\t * There is no confirmed-billing signal: the provider never reports that a response was billed to credits.\n\t */\n\tcreditUse?: \"possible\";\n}\n\nfunction latestExhaustedResetAt(snapshot: CodexRateLimitSnapshot | undefined): number | undefined {\n\tconst resets = [snapshot?.primary, snapshot?.secondary]\n\t\t.filter((window) => window !== undefined && window.usedPercent >= 100)\n\t\t.map((window) => window?.resetsAt)\n\t\t.filter((value): value is number => value !== undefined);\n\treturn resets.length > 0 ? Math.max(...resets) : undefined;\n}\n\n/**\n * Classify an assistant message as a quota exhaustion: either a terminal usage-limit failure, or a\n * completed response reporting exhausted plan quota with credits available and possible credit use.\n */\nexport function getQuotaExhaustionSignal(message: AssistantMessage): QuotaExhaustionSignal | undefined {\n\tconst httpDetails = message.diagnostics?.findLast((entry) => entry.type === \"provider_http_error\")?.details;\n\tconst snapshot = getRateLimitSnapshot(message);\n\n\tconst usageLimit = getUsageLimitSignal(message);\n\tif (usageLimit) {\n\t\tconst reachedType =\n\t\t\ttypeof httpDetails?.rateLimitReachedType === \"string\"\n\t\t\t\t? httpDetails.rateLimitReachedType\n\t\t\t\t: snapshot?.rateLimitReachedType;\n\t\tlet creditsAvailable: boolean | undefined;\n\t\tif (reachedType?.endsWith(\"_credits_depleted\")) creditsAvailable = false;\n\t\telse if (snapshot?.credits) creditsAvailable = snapshot.credits.unlimited || snapshot.credits.hasCredits;\n\t\treturn {\n\t\t\tkind: \"usage_limit\",\n\t\t\tresetsAt: usageLimit.resetsAt ?? latestExhaustedResetAt(snapshot),\n\t\t\tcreditsAvailable,\n\t\t\t...(creditsAvailable === true ? { creditUse: \"possible\" as const } : {}),\n\t\t};\n\t}\n\n\tif (message.stopReason !== \"stop\" && message.stopReason !== \"length\" && message.stopReason !== \"toolUse\") {\n\t\treturn undefined;\n\t}\n\tconst credits = snapshot?.credits;\n\tif (!snapshot || !credits?.hasCredits || credits.unlimited) return undefined;\n\tconst exhausted = [snapshot.primary, snapshot.secondary].some((window) => window && window.usedPercent >= 100);\n\tif (!exhausted) return undefined;\n\treturn {\n\t\tkind: \"credits\",\n\t\tresetsAt: latestExhaustedResetAt(snapshot),\n\t\tcreditsAvailable: true,\n\t\tcreditUse: \"possible\",\n\t};\n}\n\nfunction isOAuthCredential(value: unknown): value is OAuthCredential {\n\treturn (\n\t\tisRecord(value) &&\n\t\tvalue.type === \"oauth\" &&\n\t\ttypeof value.access === \"string\" &&\n\t\ttypeof value.refresh === \"string\" &&\n\t\ttypeof value.expires === \"number\" &&\n\t\tNumber.isFinite(value.expires)\n\t);\n}\n\nfunction isApiKeyCredential(value: unknown): value is ApiKeyCredential {\n\treturn (\n\t\tisRecord(value) &&\n\t\tvalue.type === \"api_key\" &&\n\t\ttypeof value.key === \"string\" &&\n\t\tvalue.key.trim().length > 0 &&\n\t\t(value.env === undefined ||\n\t\t\t(isRecord(value.env) && Object.values(value.env).every((entry) => typeof entry === \"string\")))\n\t);\n}\n\nfunction parsePoolData(content: string | undefined): PoolData {\n\tif (!content || content.trim() === \"\") return {};\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(stripBom(content));\n\t} catch {\n\t\t// V8 quotes a snippet of the source in SyntaxError messages; never surface token material.\n\t\tthrow new Error(\"not valid JSON\");\n\t}\n\tif (!isRecord(parsed)) throw new Error(\"expected an object\");\n\tif (Object.hasOwn(parsed, \"version\")) {\n\t\tif (parsed.version !== 2 || !isRecord(parsed.providers)) throw new Error(\"unsupported account document\");\n\t\tparsed = parsed.providers;\n\t}\n\tif (!isRecord(parsed)) throw new Error(\"expected provider pools\");\n\t// Errors never quote provider ids or account keys from the file: they are unvalidated and may hold token material.\n\tfor (const pool of Object.values(parsed)) {\n\t\tif (\n\t\t\t!isRecord(pool) ||\n\t\t\ttypeof pool.active !== \"string\" ||\n\t\t\t!isRecord(pool.accounts) ||\n\t\t\t(pool.nextLocalAccountId !== undefined &&\n\t\t\t\t(typeof pool.nextLocalAccountId !== \"number\" ||\n\t\t\t\t\t!Number.isSafeInteger(pool.nextLocalAccountId) ||\n\t\t\t\t\tpool.nextLocalAccountId < 1))\n\t\t) {\n\t\t\tthrow new Error(\"invalid provider pool\");\n\t\t}\n\t\tif (\n\t\t\tpool.returnTo !== undefined &&\n\t\t\t(!isRecord(pool.returnTo) ||\n\t\t\t\ttypeof pool.returnTo.preferredKey !== \"string\" ||\n\t\t\t\ttypeof pool.returnTo.fromKey !== \"string\" ||\n\t\t\t\t!Object.hasOwn(pool.accounts, pool.returnTo.preferredKey) ||\n\t\t\t\t!Object.hasOwn(pool.accounts, pool.returnTo.fromKey))\n\t\t)\n\t\t\tthrow new Error(\"invalid preferred account state\");\n\t\tfor (const [key, account] of Object.entries(pool.accounts)) {\n\t\t\tif (\n\t\t\t\t!isRecord(account) ||\n\t\t\t\t(!isOAuthCredential(account.credential) && !isApiKeyCredential(account.credential)) ||\n\t\t\t\t(account.quotaFailures !== undefined &&\n\t\t\t\t\t(typeof account.quotaFailures !== \"number\" ||\n\t\t\t\t\t\t!Number.isSafeInteger(account.quotaFailures) ||\n\t\t\t\t\t\taccount.quotaFailures < 0 ||\n\t\t\t\t\t\taccount.quotaFailures > 31)) ||\n\t\t\t\t(account.cooldownRevision !== undefined &&\n\t\t\t\t\t(typeof account.cooldownRevision !== \"number\" ||\n\t\t\t\t\t\t!Number.isSafeInteger(account.cooldownRevision) ||\n\t\t\t\t\t\taccount.cooldownRevision < 0)) ||\n\t\t\t\t(account.exhaustedUntil !== undefined &&\n\t\t\t\t\t(typeof account.exhaustedUntil !== \"number\" || !Number.isFinite(account.exhaustedUntil)))\n\t\t\t) {\n\t\t\t\tthrow new Error(\"invalid account entry\");\n\t\t\t}\n\t\t\tif (\n\t\t\t\taccount.quarantine !== undefined &&\n\t\t\t\t(!isRecord(account.quarantine) ||\n\t\t\t\t\t(account.quarantine.identity !== undefined &&\n\t\t\t\t\t\t!isSafeAccountKey(account.quarantine.identity, account.credential)))\n\t\t\t)\n\t\t\t\tthrow new Error(\"invalid account quarantine\");\n\t\t\tif (!isSafeAccountKey(key, account.credential)) throw new Error(\"invalid account key\");\n\t\t\t// Labels are displayed: an unsafe one falls back to the validated key instead of rejecting the pool.\n\t\t\tif (!isSafeIdentityValue(account.label, account.credential)) account.label = key;\n\t\t}\n\t}\n\treturn parsed as PoolData;\n}\n\nfunction toPoolAccount(pool: StoredProviderPool, key: string): PoolAccount {\n\tconst stored = pool.accounts[key];\n\treturn {\n\t\tkey,\n\t\tlabel: stored.label,\n\t\tcredential: structuredClone(stored.credential),\n\t\texhaustedUntil: stored.exhaustedUntil,\n\t\t...(stored.quotaFailures !== undefined ? { quotaFailures: stored.quotaFailures } : {}),\n\t\t...(stored.cooldownRevision !== undefined ? { cooldownRevision: stored.cooldownRevision } : {}),\n\t\t...(stored.quarantine ? { quarantine: structuredClone(stored.quarantine) } : {}),\n\t\tactive: pool.active === key && !stored.quarantine,\n\t};\n}\n\nfunction toAccount(pool: StoredProviderPool, key: string): OAuthAccount {\n\tconst account = toPoolAccount(pool, key);\n\tif (account.credential.type !== \"oauth\") throw new Error(\"Expected OAuth account\");\n\treturn account as OAuthAccount;\n}\n\nfunction toPoolAccounts(pool: StoredProviderPool): PoolAccount[] {\n\treturn Object.keys(pool.accounts).map((key) => toPoolAccount(pool, key));\n}\n\nfunction toAccounts(pool: StoredProviderPool | undefined): OAuthAccount[] {\n\treturn pool\n\t\t? Object.keys(pool.accounts)\n\t\t\t\t.filter((key) => pool.accounts[key].credential.type === \"oauth\")\n\t\t\t\t.map((key) => toAccount(pool, key))\n\t\t: [];\n}\n\n/** Whether the account is currently usable (never exhausted, or its exhaustion window has passed). */\nexport function isOAuthAccountUsable(\n\taccount: { exhaustedUntil?: number; quarantine?: unknown },\n\tnowMs: number,\n): boolean {\n\treturn !account.quarantine && (account.exhaustedUntil === undefined || account.exhaustedUntil <= nowMs);\n}\n\n/** Exact removal fallback: next usable account round-robin, then first remaining in insertion order. */\nexport function getOAuthAccountRemovalSuccessor<T extends Credential>(\n\taccounts: readonly PoolAccount<T>[],\n\taccountKey: string,\n\tnowMs: number = Date.now(),\n): PoolAccount<T> | undefined {\n\tconst index = accounts.findIndex((account) => account.key === accountKey);\n\tconst ordered = [...accounts.slice(index + 1), ...accounts.slice(0, index)];\n\treturn (\n\t\tordered.find((account) => isOAuthAccountUsable(account, nowMs)) ??\n\t\taccounts.find((account) => account.key !== accountKey && !account.quarantine)\n\t);\n}\n\nfunction earliestResetAt(pool: StoredProviderPool, nowMs: number, includeApiKeys = false): number | undefined {\n\tconst resetTimes = Object.values(pool.accounts)\n\t\t.filter((account) => includeApiKeys || account.credential.type === \"oauth\")\n\t\t.map((account) => account.exhaustedUntil)\n\t\t.filter((value): value is number => value !== undefined && value > nowMs);\n\treturn resetTimes.length > 0 ? Math.min(...resetTimes) : undefined;\n}\n\n/** Keys ordered round-robin starting after the active account. */\nfunction keysAfterActive(pool: StoredProviderPool): string[] {\n\tconst keys = Object.keys(pool.accounts);\n\tconst index = keys.indexOf(pool.active);\n\treturn index === -1 ? keys : [...keys.slice(index + 1), ...keys.slice(0, index)];\n}\n\n/** Forwards the caller's abort to a local controller until `detach()` (the commit point). */\nfunction linkAbortSignal(options: AuthOperationOptions | undefined): {\n\toptions: AuthOperationOptions | undefined;\n\tdetach: () => void;\n} {\n\tconst source = options?.signal;\n\tif (!source) return { options, detach: () => {} };\n\tconst controller = new AbortController();\n\tconst forward = () => controller.abort(source.reason);\n\tif (source.aborted) forward();\n\telse source.addEventListener(\"abort\", forward, { once: true });\n\treturn {\n\t\toptions: { ...options, signal: controller.signal },\n\t\tdetach: () => source.removeEventListener(\"abort\", forward),\n\t};\n}\n\ninterface RunContext {\n\t/** Identity key of the OAuth credential read from auth.json under the lock, if resolvable. */\n\tcurrentKey: string | undefined;\n\t/** Current auth credential normalized to the pool's identity metadata, without persisting it. */\n\tcurrentCredential?: Credential;\n\t/** Explicit login or selection may replace a non-OAuth credential. Adoption/removal must not. */\n\tactivate?: boolean;\n}\n\nexport function sameCredential(a: Credential | undefined, b: Credential | undefined): boolean {\n\treturn JSON.stringify(a) === JSON.stringify(b);\n}\n\nexport class OAuthAccountPool {\n\tprivate readonly credentials: CredentialStore;\n\tprivate readonly pendingWrites = new Set<Promise<void>>();\n\tprivate readonly storage: AuthStorageBackend;\n\tprivate readonly location: string;\n\tprivate readonly resolvers: Map<string, OAuthAccountIdentityResolver>;\n\tprivate readonly cache = new Map<string, PoolAccount[]>();\n\tprivate readonly backupPath: string | undefined;\n\tprivate error: string | undefined;\n\n\tconstructor(\n\t\tcredentials: CredentialStore,\n\t\tstorage: AuthStorageBackend,\n\t\tlocation: string,\n\t\tresolvers: ReadonlyMap<string, OAuthAccountIdentityResolver> = DEFAULT_OAUTH_ACCOUNT_IDENTITY_RESOLVERS,\n\t\tbackupPath?: string,\n\t) {\n\t\tthis.credentials = getAccountCredentialStore(credentials);\n\t\tthis.storage = storage;\n\t\tthis.location = location;\n\t\tthis.resolvers = new Map(resolvers);\n\t\tthis.backupPath = backupPath;\n\t}\n\n\tstatic create(\n\t\tcredentials: CredentialStore,\n\t\tpoolPath: string = join(getAgentDir(), \"oauth-accounts.json\"),\n\t): OAuthAccountPool {\n\t\tconst normalized = normalizePath(poolPath);\n\t\treturn new OAuthAccountPool(\n\t\t\tcredentials,\n\t\t\tnew FileAuthStorageBackend(normalized),\n\t\t\tnormalized,\n\t\t\tDEFAULT_OAUTH_ACCOUNT_IDENTITY_RESOLVERS,\n\t\t\t`${normalized}.v1.bak`,\n\t\t);\n\t}\n\n\tstatic inMemory(credentials: CredentialStore): OAuthAccountPool {\n\t\treturn new OAuthAccountPool(credentials, new InMemoryAuthStorageBackend(), \"oauth-accounts (in-memory)\");\n\t}\n\n\t/** Wait for started pool writes, including auth.json and pool-file persistence. */\n\tasync settled(): Promise<void> {\n\t\twhile (this.pendingWrites.size > 0) await Promise.all(this.pendingWrites);\n\t}\n\n\t/** Register a provider-specific identity hook, taking precedence over generic identity. */\n\tregisterIdentityResolver(providerId: string, resolver: OAuthAccountIdentityResolver): void {\n\t\tthis.resolvers.set(providerId, resolver);\n\t}\n\n\t/** Every provider can pool stored OAuth credentials; API-key credentials are ignored. */\n\tisPooled(_providerId: string): boolean {\n\t\treturn true;\n\t}\n\n\t/**\n\t * Exact account key of an access token, resolved from the token itself via the provider's registered resolver.\n\t * Resolvers must derive identity from `access` only (the refresh token and expiry passed here are placeholders).\n\t * Undefined when no provider resolver can identify the token; opaque tokens need credential metadata.\n\t */\n\tgetAccountKeyForAccessToken(providerId: string, accessToken: string): string | undefined {\n\t\tconst credential: OAuthCredential = { type: \"oauth\", access: accessToken, refresh: \"\", expires: 0 };\n\t\tconst cached = this.cache\n\t\t\t.get(providerId)\n\t\t\t?.find(\n\t\t\t\t(account) =>\n\t\t\t\t\t!account.quarantine && account.credential.type === \"oauth\" && account.credential.access === accessToken,\n\t\t\t);\n\t\tif (cached) return cached.key;\n\t\tconst key = this.resolvers.get(providerId)?.(credential)?.key;\n\t\treturn isSafeAccountKey(key, credential) ? key : undefined;\n\t}\n\n\t/**\n\t * Identity of the credential actually used for authentication, independent of the active pool view: the registered\n\t * resolver's, else the generic one. An unsafe key from either source counts as no identity; an unsafe label falls\n\t * back to the key.\n\t */\n\tgetAccountIdentity(providerId: string, credential: OAuthCredential): OAuthAccountIdentity | undefined {\n\t\tconst token = providerId === \"openai-codex\" ? resolveOpenAICodexAccountIdentity(credential) : undefined;\n\t\tconst owner = this.cache.get(providerId)?.find((account) => account.key === credential.accountKey);\n\t\tif (\n\t\t\ttoken &&\n\t\t\towner?.credential.type === \"oauth\" &&\n\t\t\tresolveOpenAICodexAccountIdentity(owner.credential)?.key !== token.key\n\t\t) {\n\t\t\tconst actual = this.cache\n\t\t\t\t.get(providerId)\n\t\t\t\t?.find(\n\t\t\t\t\t(account) =>\n\t\t\t\t\t\taccount.credential.type === \"oauth\" &&\n\t\t\t\t\t\tresolveOpenAICodexAccountIdentity(account.credential)?.key === token.key,\n\t\t\t\t);\n\t\t\treturn actual\n\t\t\t\t? { key: actual.key, label: actual.label }\n\t\t\t\t: this.getAccountIdentity(providerId, { ...credential, accountKey: undefined });\n\t\t}\n\t\tif (\n\t\t\ttypeof credential.accountKey === \"string\" &&\n\t\t\t/^account-[0-9a-f-]{36}$/.test(credential.accountKey) &&\n\t\t\tisSafeAccountKey(credential.accountKey, credential)\n\t\t)\n\t\t\treturn resolveGenericAccountIdentity(credential);\n\t\tconst resolved = this.resolvers.get(providerId)?.(credential);\n\t\tif (!resolved || !isSafeAccountKey(resolved.key, credential)) return resolveGenericAccountIdentity(credential);\n\t\treturn {\n\t\t\tkey: resolved.key,\n\t\t\tlabel: isSafeIdentityValue(resolved.label, credential) ? resolved.label : resolved.key,\n\t\t};\n\t}\n\n\t/** Describe a request's observed account without resolving auth or consulting the later active selection. */\n\tgetAccountDescription(providerId: string, key: string | undefined): string | undefined {\n\t\tconst account = this.cache.get(providerId)?.find((entry) => entry.key === key);\n\t\tif (!account) return undefined;\n\t\tconst saved = account.credential;\n\t\tconst upstream =\n\t\t\tsaved.type === \"oauth\"\n\t\t\t\t? ((providerId === \"openai-codex\" ? getOpenAICodexTokenIdentity(saved.access)?.accountId : undefined) ??\n\t\t\t\t\tsaved.accountId)\n\t\t\t\t: undefined;\n\t\treturn isSafeIdentityValue(upstream, saved) ? `${account.label} (${upstream})` : account.label;\n\t}\n\n\t/** Reject a quarantined grant using the pool view loaded before auth resolution; safe under the auth lock. */\n\tassertCredentialUsable(providerId: string, credential: OAuthCredential): void {\n\t\tconst accounts = this.cache.get(providerId);\n\t\tconst owner = accounts?.find((account) => account.key === credential.accountKey);\n\t\tif (\n\t\t\towner?.quarantine ||\n\t\t\t(!owner && accounts?.some((account) => account.quarantine && sameCredential(account.credential, credential)))\n\t\t)\n\t\t\tthrow new Error(\"Account is quarantined; sign in to the matching account again\");\n\t}\n\n\t/** Bind a refresh result to the credential that issued the grant, never provider-returned local metadata. */\n\tbindRefresh(providerId: string, issued: OAuthCredential, refreshed: OAuthCredential): OAuthCredential {\n\t\tconst before = this.loginIdentity(providerId, issued);\n\t\tconst after = this.loginIdentity(providerId, refreshed);\n\t\tif (before && after && before.key !== after.key)\n\t\t\tthrow new Error(\"OAuth refresh returned a different account or workspace\");\n\t\tconst bound: OAuthCredential = { ...refreshed, accountKey: issued.accountKey };\n\t\tfor (const field of OAUTH_ACCOUNT_IDENTITY_FIELDS) {\n\t\t\tif (issued[field] !== undefined && (field !== \"accountLabel\" || bound[field] === undefined))\n\t\t\t\tbound[field] = issued[field];\n\t\t}\n\t\treturn bound;\n\t}\n\n\t/** Load ownership evidence without reading auth.json or holding a pool lock across auth resolution. */\n\tasync loadIntegrity(providerId: string, options?: AuthOperationOptions): Promise<void> {\n\t\tawait this.storage.withLockAsync(async (content) => {\n\t\t\tconst data = parsePoolData(content);\n\t\t\tconst pool = Object.hasOwn(data, providerId) ? data[providerId] : { active: \"\", accounts: {} };\n\t\t\tthis.quarantineCrosslinks(providerId, pool);\n\t\t\tthis.cache.set(providerId, toPoolAccounts(pool));\n\t\t\treturn { result: undefined };\n\t\t}, options);\n\t}\n\n\tprivate quarantineCrosslinks(providerId: string, pool: StoredProviderPool): void {\n\t\tfor (const [key, account] of Object.entries(pool.accounts)) {\n\t\t\tconst saved = account.credential;\n\t\t\tif (saved.type !== \"oauth\" || account.quarantine) continue;\n\t\t\tconst token = providerId === \"openai-codex\" ? getOpenAICodexTokenIdentity(saved.access) : undefined;\n\t\t\tconst wrongStamp =\n\t\t\t\ttypeof saved.accountKey === \"string\" &&\n\t\t\t\tsaved.accountKey !== key &&\n\t\t\t\tObject.hasOwn(pool.accounts, saved.accountKey);\n\t\t\tconst wrongIdentity =\n\t\t\t\ttoken &&\n\t\t\t\tsaved.accountId !== undefined &&\n\t\t\t\tsaved.accountId !== token.accountId &&\n\t\t\t\t((typeof saved.accountId === \"string\" &&\n\t\t\t\t\tsaved.accountId !== key &&\n\t\t\t\t\tObject.hasOwn(pool.accounts, saved.accountId)) ||\n\t\t\t\t\t(token.accountId !== key && Object.hasOwn(pool.accounts, token.accountId)));\n\t\t\t// Loading cannot infer ownership from an alias or a lone credential's inconsistent metadata.\n\t\t\t// A self-stamped legacy slot needs a canonical neighbor as evidence of a foreign grant.\n\t\t\tconst legacyIdentity =\n\t\t\t\tproviderId === \"openai-codex\" && !/^account-[0-9a-f-]{36}$/.test(key) && !/^local-\\d+$/.test(key);\n\t\t\tconst canonical =\n\t\t\t\ttoken && Object.hasOwn(pool.accounts, token.accountId)\n\t\t\t\t\t? pool.accounts[token.accountId].credential\n\t\t\t\t\t: undefined;\n\t\t\tconst canonicalOwner =\n\t\t\t\tcanonical?.type === \"oauth\" &&\n\t\t\t\tgetOpenAICodexTokenIdentity(canonical.access)?.accountId === token?.accountId;\n\t\t\tconst wrongLegacyOwner =\n\t\t\t\tlegacyIdentity && token && key !== token.accountId && saved.accountKey === key && canonicalOwner;\n\t\t\tif (wrongStamp || wrongIdentity || wrongLegacyOwner) {\n\t\t\t\tconst identity = wrongLegacyOwner\n\t\t\t\t\t? key\n\t\t\t\t\t: wrongIdentity && isSafeAccountKey(saved.accountId, saved)\n\t\t\t\t\t\t? saved.accountId\n\t\t\t\t\t\t: this.loginIdentity(providerId, saved)?.key;\n\t\t\t\taccount.quarantine = identity ? { identity } : {};\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Last parse error of the pool file, if the file is corrupt. */\n\tgetError(): string | undefined {\n\t\treturn this.error;\n\t}\n\n\t/**\n\t * Synchronous view of the accounts as of the last read or mutation in this process.\n\t * Undefined until the pool has been read once. May be stale across processes.\n\t */\n\tgetCachedAccounts(providerId: string): readonly OAuthAccount[] | undefined {\n\t\tconst cached = this.cache.get(providerId);\n\t\treturn cached\n\t\t\t? cached\n\t\t\t\t\t.filter((account): account is OAuthAccount => account.credential.type === \"oauth\")\n\t\t\t\t\t.map((account) => ({ ...account, credential: structuredClone(account.credential) }))\n\t\t\t: undefined;\n\t}\n\n\t/** Last-known generalized view for recovery prediction; never use it to choose request credentials. */\n\tgetCachedPoolAccounts(providerId: string): readonly PoolAccount[] | undefined {\n\t\treturn this.cache\n\t\t\t.get(providerId)\n\t\t\t?.map((account) => ({ ...account, credential: structuredClone(account.credential) }));\n\t}\n\n\tgetAccountKeyForApiKey(providerId: string, apiKey: string): string | undefined {\n\t\treturn this.cache\n\t\t\t.get(providerId)\n\t\t\t?.find((account) => account.credential.type === \"api_key\" && account.credential.key === apiKey)?.key;\n\t}\n\n\tasync list(providerId: string, options?: AuthOperationOptions): Promise<OAuthAccount[]> {\n\t\treturn (await this.run(providerId, \"read\", options, (pool) => toAccounts(pool))) ?? [];\n\t}\n\n\t/** Collapse confirmed identity aliases for display only; every stored slot remains addressable by key. */\n\tdisplayAccounts<T extends Credential>(providerId: string, accounts: readonly PoolAccount<T>[]): PoolAccount<T>[] {\n\t\tconst winners = new Map<string, PoolAccount<T>>();\n\t\tconst identities = accounts.map((account) => {\n\t\t\tif (account.quarantine || account.credential.type !== \"oauth\") return undefined;\n\t\t\tconst identity = this.loginIdentity(providerId, account.credential)?.key;\n\t\t\tif (identity === undefined) return undefined;\n\t\t\tconst incumbent = winners.get(identity);\n\t\t\tif (\n\t\t\t\t!incumbent ||\n\t\t\t\t(!incumbent.active &&\n\t\t\t\t\t(account.active ||\n\t\t\t\t\t\t(incumbent.credential.type === \"oauth\" && account.credential.expires > incumbent.credential.expires)))\n\t\t\t) {\n\t\t\t\twinners.set(identity, account);\n\t\t\t}\n\t\t\treturn identity;\n\t\t});\n\t\tconst visible = accounts.filter(\n\t\t\t(account, index) => identities[index] === undefined || winners.get(identities[index]!) === account,\n\t\t);\n\t\tif (providerId !== \"anthropic\") return visible;\n\t\tconst orgLabels = new Set(\n\t\t\tvisible.flatMap(({ label, credential }) =>\n\t\t\t\tcredential.type === \"oauth\" && credential.organizationId !== undefined && label.includes(\" · \")\n\t\t\t\t\t? [label.split(\" · \")[0]]\n\t\t\t\t\t: [],\n\t\t\t),\n\t\t);\n\t\treturn visible.map((account) =>\n\t\t\taccount.credential.type === \"oauth\" &&\n\t\t\taccount.credential.organizationId === undefined &&\n\t\t\torgLabels.has(account.label)\n\t\t\t\t? { ...account, label: `${account.label} · Anthropic` }\n\t\t\t\t: account,\n\t\t);\n\t}\n\n\tprivate loginIdentity(providerId: string, credential: OAuthCredential): OAuthAccountIdentity | undefined {\n\t\tif (credential.organizationId !== undefined && !isSafeIdentityValue(credential.organizationId, credential))\n\t\t\treturn undefined;\n\t\tconst identity = this.getAccountIdentity(providerId, { ...credential, accountKey: undefined });\n\t\tif (providerId !== \"openai-codex\" || !identity || !isSafeAccountKey(credential.accountId, credential))\n\t\t\treturn identity;\n\t\treturn resolveOpenAICodexAccountIdentity(credential) ? identity : { ...identity, key: credential.accountId };\n\t}\n\n\tprivate removeExpiredAliases(providerId: string, pool: StoredProviderPool, key: string): void {\n\t\tconst survivor = pool.accounts[key]?.credential;\n\t\tconst now = Date.now();\n\t\tif (pool.accounts[key]?.quarantine || survivor?.type !== \"oauth\" || survivor.expires <= now || !survivor.refresh)\n\t\t\treturn;\n\t\tconst identity = this.loginIdentity(providerId, survivor)?.key;\n\t\tif (identity === undefined) return;\n\t\tfor (const [alias, { credential }] of Object.entries(pool.accounts)) {\n\t\t\t// Expired access alone is not proof of a dead login: a different refresh grant can still be valid.\n\t\t\tif (\n\t\t\t\talias === key ||\n\t\t\t\tpool.accounts[alias].quarantine ||\n\t\t\t\talias === pool.active ||\n\t\t\t\tcredential.type !== \"oauth\" ||\n\t\t\t\tcredential.expires > now ||\n\t\t\t\tcredential.refresh !== survivor.refresh ||\n\t\t\t\tthis.loginIdentity(providerId, credential)?.key !== identity\n\t\t\t)\n\t\t\t\tcontinue;\n\t\t\tdelete pool.accounts[alias];\n\t\t\tif (pool.returnTo?.preferredKey === alias || pool.returnTo?.fromKey === alias) delete pool.returnTo;\n\t\t}\n\t}\n\n\tasync getActive(providerId: string, options?: AuthOperationOptions): Promise<OAuthAccount | undefined> {\n\t\treturn this.run(providerId, \"read\", options, (pool) =>\n\t\t\tObject.hasOwn(pool.accounts, pool.active) &&\n\t\t\t!pool.accounts[pool.active].quarantine &&\n\t\t\tpool.accounts[pool.active].credential.type === \"oauth\"\n\t\t\t\t? toAccount(pool, pool.active)\n\t\t\t\t: undefined,\n\t\t);\n\t}\n\n\t/**\n\t * The account whose credential auth.json holds; undefined when auth.json holds no credential, a non-OAuth one, or\n\t * one that matches no account (unlike `getActive`, which then still reports the pool's last active account).\n\t */\n\tasync getCurrent(providerId: string, options?: AuthOperationOptions): Promise<OAuthAccount | undefined> {\n\t\treturn this.run(providerId, \"read\", options, (pool, context) =>\n\t\t\tcontext.currentKey !== undefined ? toAccount(pool, context.currentKey) : undefined,\n\t\t);\n\t}\n\n\t/**\n\t * Pool the credential currently stored in auth.json (if any) as the active account, stamping\n\t * its key for non-Codex providers. Call before an operation that replaces the auth.json credential.\n\t */\n\tasync adoptCurrent(providerId: string, options?: AuthOperationOptions): Promise<OAuthAccount | undefined> {\n\t\treturn this.run(providerId, \"write\", options, (pool, context) =>\n\t\t\tcontext.currentKey !== undefined ? toAccount(pool, context.currentKey) : undefined,\n\t\t);\n\t}\n\n\t/** Reconcile auth.json and refresh one exact OAuth account without activating it. */\n\tasync prepareUsageAccount(\n\t\tproviderId: string,\n\t\tkey: string | undefined,\n\t\trefresh: UsageCredentialRefresh,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<UsageRefreshResult | undefined> {\n\t\treturn this.run<UsageRefreshResult | undefined>(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t() => undefined,\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t\tfalse,\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t\t{ key, refresh, result: (value) => value },\n\t\t);\n\t}\n\n\t/** Clear only a still-current cooldown observation; never select credentials or persist auth.json changes. */\n\tasync clearExhaustion(providerId: string, expected: OAuthAccount, options?: AuthOperationOptions): Promise<boolean> {\n\t\treturn (\n\t\t\t(await this.run(\n\t\t\t\tproviderId,\n\t\t\t\t\"write\",\n\t\t\t\toptions,\n\t\t\t\t(pool, context) => {\n\t\t\t\t\tif (!Object.hasOwn(pool.accounts, expected.key)) return undefined;\n\t\t\t\t\tconst account = pool.accounts[expected.key];\n\t\t\t\t\tif (\n\t\t\t\t\t\texpected.exhaustedUntil === undefined ||\n\t\t\t\t\t\t!Number.isFinite(expected.exhaustedUntil) ||\n\t\t\t\t\t\texpected.exhaustedUntil <= Date.now() ||\n\t\t\t\t\t\taccount.exhaustedUntil !== expected.exhaustedUntil ||\n\t\t\t\t\t\taccount.quotaFailures !== expected.quotaFailures ||\n\t\t\t\t\t\t(account.cooldownRevision ?? 0) !== (expected.cooldownRevision ?? 0) ||\n\t\t\t\t\t\t// A saturated revision cannot distinguish another failure with the same reset time.\n\t\t\t\t\t\taccount.cooldownRevision === Number.MAX_SAFE_INTEGER ||\n\t\t\t\t\t\t!sameCredential(account.credential, expected.credential) ||\n\t\t\t\t\t\t(context.currentKey === expected.key &&\n\t\t\t\t\t\t\t!sameCredential(context.currentCredential, expected.credential))\n\t\t\t\t\t)\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\tdelete account.exhaustedUntil;\n\t\t\t\t\tdelete account.quotaFailures;\n\t\t\t\t\treturn true;\n\t\t\t\t},\n\t\t\t\tundefined,\n\t\t\t\ttrue,\n\t\t\t\tfalse,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\ttrue,\n\t\t\t)) ?? false\n\t\t);\n\t}\n\n\t/** Generalized storage view. Credentials are sensitive; UI must display only keys, labels and markers. */\n\tasync listAccounts(providerId: string, options?: AuthOperationOptions): Promise<PoolAccount[]> {\n\t\treturn (\n\t\t\t(await this.run(providerId, \"read\", options, (pool) => toPoolAccounts(pool), undefined, false, true)) ?? []\n\t\t);\n\t}\n\n\tasync getCurrentAccount(providerId: string, options?: AuthOperationOptions): Promise<PoolAccount | undefined> {\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"read\",\n\t\t\toptions,\n\t\t\t(pool, context) => (context.currentKey ? toPoolAccount(pool, context.currentKey) : undefined),\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\tasync adoptCurrentAccount(providerId: string, options?: AuthOperationOptions): Promise<PoolAccount | undefined> {\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t(pool, context) => {\n\t\t\t\tif (!context.currentKey) return undefined;\n\t\t\t\tthis.removeExpiredAliases(providerId, pool, context.currentKey);\n\t\t\t\treturn toPoolAccount(pool, context.currentKey);\n\t\t\t},\n\t\t\tundefined,\n\t\t\ttrue,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\t/** New entries have random token-free keys; exact API-key equality deduplicates without a stored fingerprint. */\n\tasync addAccount(\n\t\tproviderId: string,\n\t\tcredential: Credential,\n\t\toptions?: AuthOperationOptions & { key?: string; label?: string },\n\t): Promise<PoolAccount | undefined> {\n\t\tif (!isOAuthCredential(credential) && !isApiKeyCredential(credential))\n\t\t\tthrow new Error(\"Invalid account credential\");\n\t\tif (options?.key !== undefined && !isSafeAccountKey(options.key, credential))\n\t\t\tthrow new Error(\"Invalid account key\");\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t(pool, context) => {\n\t\t\t\tif (\n\t\t\t\t\toptions?.label !== undefined &&\n\t\t\t\t\t![credential, ...Object.values(pool.accounts).map((account) => account.credential)].every((entry) =>\n\t\t\t\t\t\tisSafeIdentityValue(options.label, entry),\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(\"Invalid account label\");\n\t\t\t\tconst identity = credential.type === \"oauth\" ? this.loginIdentity(providerId, credential) : undefined;\n\t\t\t\tconst matches = Object.keys(pool.accounts).filter((key) => {\n\t\t\t\t\tconst entry = pool.accounts[key];\n\t\t\t\t\tconst stored = entry.credential;\n\t\t\t\t\tif (entry.quarantine) return identity !== undefined && entry.quarantine.identity === identity.key;\n\t\t\t\t\tif (credential.type === \"api_key\") return stored.type === \"api_key\" && stored.key === credential.key;\n\t\t\t\t\treturn (\n\t\t\t\t\t\tstored.type === \"oauth\" &&\n\t\t\t\t\t\t(sameCredential(stored, credential) ||\n\t\t\t\t\t\t\t(identity !== undefined && this.loginIdentity(providerId, stored)?.key === identity.key))\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\tconst matching = matches.includes(pool.active)\n\t\t\t\t\t? pool.active\n\t\t\t\t\t: matches.reduce<string | undefined>((best, candidate) => {\n\t\t\t\t\t\t\tconst previous = best === undefined ? undefined : pool.accounts[best].credential;\n\t\t\t\t\t\t\tconst next = pool.accounts[candidate].credential;\n\t\t\t\t\t\t\treturn !previous ||\n\t\t\t\t\t\t\t\t(next.type === \"oauth\" && previous.type === \"oauth\" && next.expires > previous.expires)\n\t\t\t\t\t\t\t\t? candidate\n\t\t\t\t\t\t\t\t: best;\n\t\t\t\t\t\t}, undefined);\n\t\t\t\tif (\n\t\t\t\t\tcredential.type === \"api_key\" &&\n\t\t\t\t\toptions?.key !== undefined &&\n\t\t\t\t\tmatching !== undefined &&\n\t\t\t\t\tmatching !== options.key\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(\"API key already belongs to another account\");\n\t\t\t\t// Claude organizations are distinct quota owners, even for the same user.\n\t\t\t\tconst organizationKey =\n\t\t\t\t\tproviderId === \"anthropic\" && credential.type === \"oauth\" && credential.organizationId !== undefined\n\t\t\t\t\t\t? identity?.key\n\t\t\t\t\t\t: undefined;\n\t\t\t\tconst key = options?.key ?? matching ?? organizationKey ?? `account-${randomUUID()}`;\n\t\t\t\tif (\n\t\t\t\t\t![credential, ...Object.values(pool.accounts).map((account) => account.credential)].every((entry) =>\n\t\t\t\t\t\tisSafeAccountKey(key, entry),\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(\"Invalid account key\");\n\t\t\t\tconst existing = Object.hasOwn(pool.accounts, key) ? pool.accounts[key] : undefined;\n\t\t\t\tif (existing && existing.credential.type !== credential.type)\n\t\t\t\t\tthrow new Error(\"Account credential type cannot change\");\n\t\t\t\tif (existing?.quarantine && (!identity || !existing.quarantine.identity))\n\t\t\t\t\tthrow new Error(\"Quarantined account identity is unknown; use Add another account\");\n\t\t\t\tif (existing?.credential.type === \"oauth\" && identity !== undefined) {\n\t\t\t\t\tconst existingIdentity = existing.quarantine\n\t\t\t\t\t\t? existing.quarantine.identity\n\t\t\t\t\t\t\t? { key: existing.quarantine.identity }\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t: this.loginIdentity(providerId, existing.credential);\n\t\t\t\t\tif (existingIdentity !== undefined && existingIdentity.key !== identity.key)\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\"Sign-in returned a different account or workspace. Sign in to the selected account or use Add another account.\",\n\t\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst label =\n\t\t\t\t\toptions?.label ??\n\t\t\t\t\texisting?.label ??\n\t\t\t\t\tidentity?.label ??\n\t\t\t\t\t`Account ${pool.nextLocalAccountId ?? Object.keys(pool.accounts).length + 1}`;\n\t\t\t\tif (\n\t\t\t\t\t![credential, ...Object.values(pool.accounts).map((account) => account.credential)].every((entry) =>\n\t\t\t\t\t\tisSafeIdentityValue(label, entry),\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(\"Invalid account label\");\n\t\t\t\tpool.nextLocalAccountId =\n\t\t\t\t\t(pool.nextLocalAccountId ?? Object.keys(pool.accounts).length + 1) + (existing ? 0 : 1);\n\t\t\t\tif (credential.type === \"oauth\") this.removeExpiredAliases(providerId, pool, key);\n\t\t\t\tpool.accounts[key] = {\n\t\t\t\t\tcredential:\n\t\t\t\t\t\tcredential.type === \"oauth\"\n\t\t\t\t\t\t\t? { ...structuredClone(credential), accountKey: key }\n\t\t\t\t\t\t\t: structuredClone(credential),\n\t\t\t\t\tlabel,\n\t\t\t\t\texhaustedUntil: existing?.exhaustedUntil,\n\t\t\t\t\tquotaFailures: existing?.quotaFailures,\n\t\t\t\t\tcooldownRevision: existing?.cooldownRevision,\n\t\t\t\t};\n\t\t\t\tdelete pool.returnTo;\n\t\t\t\tpool.active = key;\n\t\t\t\tif (credential.type === \"oauth\") this.removeExpiredAliases(providerId, pool, key);\n\t\t\t\tcontext.activate = true;\n\t\t\t\treturn toPoolAccount(pool, key);\n\t\t\t},\n\t\t\tundefined,\n\t\t\ttrue,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\tasync setActiveAccount(\n\t\tproviderId: string,\n\t\taccountKey: string,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<PoolAccount | undefined> {\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t(pool, context) => {\n\t\t\t\tif (!Object.hasOwn(pool.accounts, accountKey)) return undefined;\n\t\t\t\tif (pool.accounts[accountKey].quarantine)\n\t\t\t\t\tthrow new Error(\"Account is quarantined; sign in to the matching account again\");\n\t\t\t\tcontext.activate = true;\n\t\t\t\tdelete pool.returnTo;\n\t\t\t\tpool.active = accountKey;\n\t\t\t\treturn toPoolAccount(pool, accountKey);\n\t\t\t},\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\tasync renameAccount(\n\t\tproviderId: string,\n\t\taccountKey: string,\n\t\tlabel: string,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<PoolAccount | undefined> {\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t(pool) => {\n\t\t\t\tif (!Object.hasOwn(pool.accounts, accountKey)) return undefined;\n\t\t\t\tif (!Object.values(pool.accounts).every((account) => isSafeIdentityValue(label, account.credential)))\n\t\t\t\t\tthrow new Error(\"Invalid account label\");\n\t\t\t\tpool.accounts[accountKey].label = label;\n\t\t\t\treturn toPoolAccount(pool, accountKey);\n\t\t\t},\n\t\t\tundefined,\n\t\t\tfalse,\n\t\t\ttrue,\n\t\t);\n\t}\n\n\t/** `ifCurrent` binds removal to a raw stored observation, checked before planning and under the auth lock. */\n\tasync removeAccount(\n\t\tproviderId: string,\n\t\taccountKey: string | undefined,\n\t\toptions?: CredentialDeleteOptions,\n\t): Promise<AccountRemoveResult> {\n\t\treturn this.removeStored(providerId, accountKey, options, true);\n\t}\n\n\t/**\n\t * Add or update an account (same key updates the stored credential) and make it active. An explicit `key` must be a\n\t * safe account key (bounded, printable, token-free, not an `Object.prototype` name).\n\t */\n\tasync add(\n\t\tproviderId: string,\n\t\tcredential: OAuthCredential,\n\t\toptions?: AuthOperationOptions & { key?: string },\n\t): Promise<OAuthAccount | undefined> {\n\t\tif (options?.key !== undefined && !isSafeAccountKey(options.key, credential)) {\n\t\t\tthrow new Error(\"Invalid OAuth account key\");\n\t\t}\n\t\tconst identity = this.getAccountIdentity(providerId, credential);\n\t\tif (providerId === \"openai-codex\" && !identity && options?.key === undefined) return undefined;\n\t\treturn this.run(providerId, \"write\", options, (pool, context) => {\n\t\t\tcontext.activate = true;\n\t\t\tconst local = options?.key === undefined && !identity ? nextLocalAccountIdentity(pool) : undefined;\n\t\t\tconst key = options?.key ?? identity?.key ?? local!.key;\n\t\t\tconst existing = pool.accounts[key];\n\t\t\tif (\n\t\t\t\texisting?.quarantine &&\n\t\t\t\t(!existing.quarantine.identity ||\n\t\t\t\t\tthis.loginIdentity(providerId, credential)?.key !== existing.quarantine.identity)\n\t\t\t)\n\t\t\t\tthrow new Error(\"Sign-in returned a different account or workspace\");\n\t\t\tpool.accounts[key] = {\n\t\t\t\tcredential:\n\t\t\t\t\tproviderId === \"openai-codex\"\n\t\t\t\t\t\t? structuredClone(credential)\n\t\t\t\t\t\t: { ...structuredClone(credential), accountKey: key },\n\t\t\t\tlabel: existing?.label ?? identity?.label ?? local?.label ?? key,\n\t\t\t\texhaustedUntil: existing?.exhaustedUntil,\n\t\t\t\tquotaFailures: existing?.quotaFailures,\n\t\t\t\tcooldownRevision: existing?.cooldownRevision,\n\t\t\t};\n\t\t\tdelete pool.returnTo;\n\t\t\tpool.active = key;\n\t\t\treturn toAccount(pool, key);\n\t\t});\n\t}\n\n\tasync setActive(\n\t\tproviderId: string,\n\t\taccountKey: string,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<OAuthAccount | undefined> {\n\t\treturn this.run(providerId, \"write\", options, (pool, context) => {\n\t\t\tif (!Object.hasOwn(pool.accounts, accountKey) || pool.accounts[accountKey].credential.type !== \"oauth\")\n\t\t\t\treturn undefined;\n\t\t\tif (pool.accounts[accountKey].quarantine)\n\t\t\t\tthrow new Error(\"Account is quarantined; sign in to the matching account again\");\n\t\t\tcontext.activate = true;\n\t\t\tdelete pool.returnTo;\n\t\t\tpool.active = accountKey;\n\t\t\treturn toAccount(pool, accountKey);\n\t\t});\n\t}\n\n\t/**\n\t * Remove an account, or with `accountKey` undefined the account whose credential auth.json holds (`unmatched` when\n\t * that credential is missing, not OAuth, or cannot be matched to an account). Removing the active account promotes\n\t * the next usable one; when the pool becomes empty the auth.json credential is deleted if it still belongs to a\n\t * removed account. `changed` when auth.json changed before its lock so that the removal no longer applied; without\n\t * `accountKey` this includes auth.json no longer holding the account found first, which is never retargeted.\n\t */\n\tasync remove(\n\t\tproviderId: string,\n\t\taccountKey: string | undefined,\n\t\toptions?: AuthOperationOptions,\n\t): Promise<OAuthAccountRemoveResult> {\n\t\tconst result = await this.removeStored(providerId, accountKey, options, false);\n\t\treturn result as OAuthAccountRemoveResult;\n\t}\n\n\tprivate async removeStored(\n\t\tproviderId: string,\n\t\taccountKey: string | undefined,\n\t\toptions: CredentialDeleteOptions | undefined,\n\t\tincludeApiKeys: boolean,\n\t): Promise<AccountRemoveResult> {\n\t\tlet matched = false;\n\t\tlet target = accountKey;\n\t\tconst result = await this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t(pool, context): AccountRemoveResult | undefined => {\n\t\t\t\tconst key = target ?? context.currentKey;\n\t\t\t\tif (\n\t\t\t\t\tkey === undefined ||\n\t\t\t\t\t!Object.hasOwn(pool.accounts, key) ||\n\t\t\t\t\t(!includeApiKeys && pool.accounts[key].credential.type !== \"oauth\")\n\t\t\t\t)\n\t\t\t\t\treturn undefined;\n\t\t\t\t// A keyless re-plan removes only the account auth.json held at the first plan.\n\t\t\t\tif (accountKey === undefined && context.currentKey !== key) return undefined;\n\t\t\t\tmatched = true;\n\t\t\t\ttarget = key;\n\t\t\t\tconst removed = toPoolAccount(pool, key);\n\t\t\t\tconst wasActive = pool.active === key;\n\t\t\t\tconst successor = wasActive\n\t\t\t\t\t? getOAuthAccountRemovalSuccessor(\n\t\t\t\t\t\t\ttoPoolAccounts(pool).filter((account) => account.credential.type === removed.credential.type),\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t)?.key\n\t\t\t\t\t: undefined;\n\t\t\t\tif (wasActive || pool.returnTo?.preferredKey === key || pool.returnTo?.fromKey === key)\n\t\t\t\t\tdelete pool.returnTo;\n\t\t\t\tdelete pool.accounts[key];\n\t\t\t\tif (wasActive) pool.active = successor ?? \"\";\n\t\t\t\treturn {\n\t\t\t\t\tstatus: \"removed\",\n\t\t\t\t\tremoved,\n\t\t\t\t\tactive:\n\t\t\t\t\t\tpool.active && (includeApiKeys || pool.accounts[pool.active].credential.type === \"oauth\")\n\t\t\t\t\t\t\t? toPoolAccount(pool, pool.active)\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t};\n\t\t\t},\n\t\t\tundefined,\n\t\t\ttrue,\n\t\t\tincludeApiKeys,\n\t\t\toptions?.ifCurrent ? { ifCurrent: options.ifCurrent, changed: { status: \"changed\" } } : undefined,\n\t\t);\n\t\t// `run` stops when the first plan declines; a decline after a match came from a re-plan under the auth.json lock.\n\t\treturn result ?? { status: matched ? \"changed\" : \"unmatched\" };\n\t}\n\n\t/**\n\t * Atomic usage-limit failover: under one pool lock, verify auth.json holds an OAuth credential of the expected\n\t * account, optionally mark it exhausted, activate the next usable account, and write it to auth.json. The check is\n\t * repeated at the auth.json write; a different account there (other process) is never overwritten.\n\t * Returns `active_changed` (nothing marked, auth.json untouched) when auth.json does not hold the expected\n\t * account. Abort before the auth.json write throws with nothing changed.\n\t */\n\tasync failover(\n\t\tproviderId: string,\n\t\toptions: OAuthAccountFailoverOptions,\n\t): Promise<OAuthAccountFailoverResult | undefined> {\n\t\treturn this.failoverStored(providerId, options, false) as Promise<OAuthAccountFailoverResult | undefined>;\n\t}\n\n\t/** Same-type rotation first, then only the explicitly named OAuth-to-API-key target. */\n\tasync failoverAccounts(\n\t\tproviderId: string,\n\t\toptions: AccountFailoverOptions,\n\t): Promise<AccountFailoverResult | undefined> {\n\t\t// Callers may pass `trackPreferred: false` to skip the persisted return-to-preferred state and doubling cooldown.\n\t\treturn this.failoverStored(providerId, { ...options, trackPreferred: options.trackPreferred ?? true }, true);\n\t}\n\n\tprivate async failoverStored(\n\t\tproviderId: string,\n\t\toptions: AccountFailoverOptions,\n\t\tincludeApiKeys: boolean,\n\t): Promise<AccountFailoverResult | undefined> {\n\t\tconst {\n\t\t\texpectedActiveKey,\n\t\t\texhaustedUntil,\n\t\t\tnow = Date.now(),\n\t\t\tskipKeys,\n\t\t\ttrackPreferred,\n\t\t\tapiKeyFallback,\n\t\t\tallowApiKeyRotation,\n\t\t\tmarkExhausted = true,\n\t\t\tcandidateKeys,\n\t\t\tcandidateFilter,\n\t\t\tcanActivate,\n\t\t\t...operationOptions\n\t\t} = options;\n\t\tconst accounts = (pool: StoredProviderPool) => (includeApiKeys ? toPoolAccounts(pool) : toAccounts(pool));\n\t\tconst activeChanged = (pool: StoredProviderPool, activeKey: string | undefined): AccountFailoverResult => ({\n\t\t\tswitched: false,\n\t\t\treason: \"active_changed\",\n\t\t\tactive:\n\t\t\t\tactiveKey !== undefined && Object.hasOwn(pool.accounts, activeKey)\n\t\t\t\t\t? toPoolAccount(pool, activeKey)\n\t\t\t\t\t: undefined,\n\t\t\ttotal: accounts(pool).length,\n\t\t\tearliestResetAt: earliestResetAt(pool, now, includeApiKeys),\n\t\t});\n\t\tconst operation = (pool: StoredProviderPool, context: RunContext): AccountFailoverResult => {\n\t\t\tconst total = accounts(pool).length;\n\t\t\tif (context.currentKey !== expectedActiveKey || pool.active !== expectedActiveKey) {\n\t\t\t\treturn activeChanged(pool, context.currentKey);\n\t\t\t}\n\t\t\tconst source = pool.accounts[expectedActiveKey];\n\t\t\tif (trackPreferred && markExhausted) source.quotaFailures = Math.min(31, (source.quotaFailures ?? 0) + 1);\n\t\t\tconst reset =\n\t\t\t\texhaustedUntil ??\n\t\t\t\t(trackPreferred\n\t\t\t\t\t? now +\n\t\t\t\t\t\tMath.min(\n\t\t\t\t\t\t\tACCOUNT_RETURN_MAX_COOLDOWN_MS,\n\t\t\t\t\t\t\tACCOUNT_RETURN_COOLDOWN_MS * 2 ** ((source.quotaFailures ?? 1) - 1),\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined);\n\t\t\tif (reset !== undefined && markExhausted) {\n\t\t\t\tsource.exhaustedUntil = reset;\n\t\t\t\tsource.cooldownRevision = Math.min(Number.MAX_SAFE_INTEGER, (source.cooldownRevision ?? 0) + 1);\n\t\t\t}\n\t\t\tconst usable = (key: string) =>\n\t\t\t\tkey !== expectedActiveKey && !skipKeys?.has(key) && isOAuthAccountUsable(pool.accounts[key], now);\n\t\t\tconst sameType = source.credential.type === \"oauth\" || allowApiKeyRotation === true;\n\t\t\tconst ordered = candidateKeys\n\t\t\t\t? candidateKeys.filter((key) => Object.hasOwn(pool.accounts, key))\n\t\t\t\t: keysAfterActive(pool);\n\t\t\tconst candidate =\n\t\t\t\t(sameType\n\t\t\t\t\t? ordered.find(\n\t\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t\t\tpool.accounts[key].credential.type === source.credential.type &&\n\t\t\t\t\t\t\t\tusable(key) &&\n\t\t\t\t\t\t\t\t(candidateFilter === undefined ||\n\t\t\t\t\t\t\t\t\tcandidateFilter(toPoolAccount(pool, expectedActiveKey), toPoolAccount(pool, key))),\n\t\t\t\t\t\t)\n\t\t\t\t\t: undefined) ??\n\t\t\t\t(source.credential.type === \"oauth\" &&\n\t\t\t\tapiKeyFallback !== undefined &&\n\t\t\t\tObject.hasOwn(pool.accounts, apiKeyFallback) &&\n\t\t\t\tpool.accounts[apiKeyFallback].credential.type === \"api_key\" &&\n\t\t\t\tusable(apiKeyFallback)\n\t\t\t\t\t? apiKeyFallback\n\t\t\t\t\t: undefined);\n\t\t\tif (candidate === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tswitched: false,\n\t\t\t\t\treason: \"exhausted\",\n\t\t\t\t\tactive: toPoolAccount(pool, expectedActiveKey),\n\t\t\t\t\ttotal,\n\t\t\t\t\tearliestResetAt: earliestResetAt(pool, now, includeApiKeys),\n\t\t\t\t};\n\t\t\t}\n\t\t\tpool.accounts[candidate].exhaustedUntil = undefined;\n\t\t\tif (trackPreferred)\n\t\t\t\tpool.returnTo = { preferredKey: pool.returnTo?.preferredKey ?? expectedActiveKey, fromKey: candidate };\n\t\t\tpool.active = candidate;\n\t\t\treturn {\n\t\t\t\tswitched: true,\n\t\t\t\tfrom: toPoolAccount(pool, expectedActiveKey),\n\t\t\t\tto: toPoolAccount(pool, candidate),\n\t\t\t\ttotal,\n\t\t\t};\n\t\t};\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toperationOptions,\n\t\t\toperation,\n\t\t\texpectedActiveKey,\n\t\t\tfalse,\n\t\t\tincludeApiKeys,\n\t\t\tundefined,\n\t\t\tcanActivate,\n\t\t);\n\t}\n\n\t/** Request-boundary only. Rechecks the active credential under the auth lock; no network calls. */\n\tasync returnToPreferred(\n\t\tproviderId: string,\n\t\toptions?: AuthOperationOptions & {\n\t\t\tskipKeys?: ReadonlySet<string>;\n\t\t\tcanActivate?: (from: PoolAccount, to: PoolAccount) => boolean;\n\t\t},\n\t): Promise<PoolAccount | undefined> {\n\t\tconst result = await this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toptions,\n\t\t\t(pool, context) => {\n\t\t\t\tconst pending = pool.returnTo;\n\t\t\t\tif (!pending) return undefined;\n\t\t\t\tif (context.currentKey !== pending.fromKey) {\n\t\t\t\t\tdelete pool.returnTo;\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tconst preferred = pool.accounts[pending.preferredKey];\n\t\t\t\tif (\n\t\t\t\t\t!preferred ||\n\t\t\t\t\toptions?.skipKeys?.has(pending.preferredKey) ||\n\t\t\t\t\t!isOAuthAccountUsable(preferred, Date.now())\n\t\t\t\t)\n\t\t\t\t\treturn false;\n\t\t\t\tpool.active = pending.preferredKey;\n\t\t\t\tdelete pool.returnTo;\n\t\t\t\treturn toPoolAccount(pool, pool.active);\n\t\t\t},\n\t\t\tundefined,\n\t\t\ttrue,\n\t\t\ttrue,\n\t\t\tundefined,\n\t\t\toptions?.canActivate,\n\t\t);\n\t\treturn result || undefined;\n\t}\n\n\t/**\n\t * Atomic credit fallback once every pooled account was tried: under one pool lock, verify auth.json holds an\n\t * OAuth credential of the expected account (rechecked at the auth.json write), then activate an untried usable account if one exists now\n\t * (`untried`), else the credit-capable target (`credit`). Nothing changes for `active_changed`\n\t * or `missing`. Abort before the auth.json write throws with nothing changed.\n\t */\n\tasync activateCreditFallback(\n\t\tproviderId: string,\n\t\toptions: OAuthAccountCreditFallbackOptions,\n\t): Promise<OAuthAccountCreditFallbackResult | undefined> {\n\t\tconst { expectedActiveKey, targetKey, skipKeys, now = Date.now(), canActivate, ...operationOptions } = options;\n\t\tconst activeChanged = (\n\t\t\tpool: StoredProviderPool,\n\t\t\tactiveKey: string | undefined,\n\t\t): OAuthAccountCreditFallbackResult => ({\n\t\t\toutcome: \"active_changed\",\n\t\t\tactive:\n\t\t\t\tactiveKey !== undefined && Object.hasOwn(pool.accounts, activeKey) ? toAccount(pool, activeKey) : undefined,\n\t\t});\n\t\tconst operation = (pool: StoredProviderPool, context: RunContext): OAuthAccountCreditFallbackResult => {\n\t\t\tif (context.currentKey !== expectedActiveKey || pool.active !== expectedActiveKey) {\n\t\t\t\treturn activeChanged(pool, context.currentKey);\n\t\t\t}\n\t\t\tconst untried = keysAfterActive(pool).find(\n\t\t\t\t(key) =>\n\t\t\t\t\tpool.accounts[key].credential.type === \"oauth\" &&\n\t\t\t\t\t!skipKeys?.has(key) &&\n\t\t\t\t\tisOAuthAccountUsable(pool.accounts[key], now),\n\t\t\t);\n\t\t\tif (untried !== undefined) {\n\t\t\t\tpool.accounts[untried].exhaustedUntil = undefined;\n\t\t\t\tpool.active = untried;\n\t\t\t\tif (pool.returnTo) pool.returnTo.fromKey = untried;\n\t\t\t\treturn { outcome: \"untried\", account: toAccount(pool, untried) };\n\t\t\t}\n\t\t\tif (\n\t\t\t\t!Object.hasOwn(pool.accounts, targetKey) ||\n\t\t\t\tpool.accounts[targetKey].quarantine ||\n\t\t\t\tpool.accounts[targetKey].credential.type !== \"oauth\"\n\t\t\t)\n\t\t\t\treturn { outcome: \"missing\" };\n\t\t\tpool.active = targetKey;\n\t\t\tif (pool.returnTo) pool.returnTo.fromKey = targetKey;\n\t\t\treturn { outcome: \"credit\", account: toAccount(pool, targetKey) };\n\t\t};\n\t\treturn this.run(\n\t\t\tproviderId,\n\t\t\t\"write\",\n\t\t\toperationOptions,\n\t\t\toperation,\n\t\t\texpectedActiveKey,\n\t\t\tfalse,\n\t\t\tfalse,\n\t\t\tundefined,\n\t\t\tcanActivate,\n\t\t);\n\t}\n\n\t/** Store `credential` under its account key (keeping label/exhaustion); returns the key. */\n\tprivate upsertCredential(\n\t\tpool: StoredProviderPool,\n\t\tcredential: Credential | undefined,\n\t\tproviderId: string,\n\t\tactiveKey: string = pool.active,\n\t\tincludeApiKeys = false,\n\t): string | undefined {\n\t\tif (credential?.type === \"api_key\") {\n\t\t\tif (!includeApiKeys || !isApiKeyCredential(credential)) return undefined;\n\t\t\tconst apiKey = credential.key;\n\t\t\tconst existingKey = Object.keys(pool.accounts).find(\n\t\t\t\t(key) =>\n\t\t\t\t\tpool.accounts[key].credential.type === \"api_key\" &&\n\t\t\t\t\t(pool.accounts[key].credential as ApiKeyCredential).key === apiKey,\n\t\t\t);\n\t\t\tconst cachedKey = this.cache\n\t\t\t\t.get(providerId)\n\t\t\t\t?.find((account) => account.credential.type === \"api_key\" && account.credential.key === apiKey)?.key;\n\t\t\tconst key = existingKey ?? cachedKey ?? `account-${randomUUID()}`;\n\t\t\tconst existing = pool.accounts[key];\n\t\t\tpool.accounts[key] = {\n\t\t\t\tcredential: structuredClone(credential),\n\t\t\t\tlabel: existing?.label ?? `Account ${Object.keys(pool.accounts).length + 1}`,\n\t\t\t\texhaustedUntil: existing?.exhaustedUntil,\n\t\t\t\tquotaFailures: existing?.quotaFailures,\n\t\t\t\tcooldownRevision: existing?.cooldownRevision,\n\t\t\t};\n\t\t\treturn key;\n\t\t}\n\t\tif (credential?.type !== \"oauth\") return undefined;\n\t\t// Reconciliation is not consent to recover an unsafe slot, even when auth still contains its grant.\n\t\tconst owner =\n\t\t\tisSafeAccountKey(credential.accountKey, credential) && Object.hasOwn(pool.accounts, credential.accountKey)\n\t\t\t\t? pool.accounts[credential.accountKey]\n\t\t\t\t: undefined;\n\t\tif (\n\t\t\towner?.quarantine ||\n\t\t\t(!owner &&\n\t\t\t\tObject.values(pool.accounts).some(\n\t\t\t\t\t(entry) => entry.quarantine && sameCredential(credential, entry.credential),\n\t\t\t\t))\n\t\t)\n\t\t\treturn undefined;\n\t\t// Repair auth's identity metadata when its stamp names another stored owner; otherwise retain\n\t\t// mismatched metadata so downstream identity validation can reject it rather than laundering it.\n\t\tconst tokenIdentity = providerId === \"openai-codex\" ? getOpenAICodexTokenIdentity(credential.access) : undefined;\n\t\tif (\n\t\t\ttokenIdentity &&\n\t\t\t(credential.accountId === undefined ||\n\t\t\t\t(owner?.credential.type === \"oauth\" &&\n\t\t\t\t\tthis.loginIdentity(providerId, owner.credential)?.key !== tokenIdentity.accountId))\n\t\t)\n\t\t\tcredential = { ...credential, accountId: tokenIdentity.accountId };\n\t\tconst stamped = credential.accountKey;\n\t\tif (isSafeAccountKey(stamped, credential) && Object.hasOwn(pool.accounts, stamped)) {\n\t\t\tconst owner = pool.accounts[stamped].credential;\n\t\t\tif (\n\t\t\t\towner.type !== \"oauth\" ||\n\t\t\t\tthis.loginIdentity(providerId, owner)?.key !== this.loginIdentity(providerId, credential)?.key\n\t\t\t)\n\t\t\t\tcredential = { ...credential, accountKey: undefined };\n\t\t}\n\t\tlet identity = this.getAccountIdentity(providerId, credential);\n\t\tconst loginId = this.loginIdentity(providerId, credential)?.key;\n\t\tconst stampedKey = credential.accountKey;\n\t\tconst matchesLogin = (stored: Credential) =>\n\t\t\tstored.type === \"oauth\" && loginId !== undefined && this.loginIdentity(providerId, stored)?.key === loginId;\n\t\tif (\n\t\t\tidentity &&\n\t\t\tisSafeAccountKey(stampedKey, credential) &&\n\t\t\tObject.hasOwn(pool.accounts, stampedKey) &&\n\t\t\tmatchesLogin(pool.accounts[stampedKey].credential)\n\t\t) {\n\t\t\t// Legacy local keys are not always account-UUIDs; trust the stamp only with a matching provider identity.\n\t\t\tidentity = { ...identity, key: stampedKey };\n\t\t}\n\t\tif (identity && !Object.hasOwn(pool.accounts, identity.key) && stampedKey === undefined) {\n\t\t\tconst matching =\n\t\t\t\tObject.hasOwn(pool.accounts, activeKey) && matchesLogin(pool.accounts[activeKey].credential)\n\t\t\t\t\t? activeKey\n\t\t\t\t\t: Object.keys(pool.accounts).find((key) => matchesLogin(pool.accounts[key].credential));\n\t\t\tidentity = {\n\t\t\t\tkey:\n\t\t\t\t\tmatching ??\n\t\t\t\t\tthis.cache.get(providerId)?.find((account) => matchesLogin(account.credential))?.key ??\n\t\t\t\t\t(includeApiKeys ? `account-${randomUUID()}` : identity.key),\n\t\t\t\tlabel: identity.label,\n\t\t\t};\n\t\t}\n\t\tif (!identity) {\n\t\t\t// Unidentified legacy Codex credentials stay unmatched; explicit addAccount stamps even opaque logins.\n\t\t\tif (providerId === \"openai-codex\") return undefined;\n\t\t\tconst cached = this.cache\n\t\t\t\t.get(providerId)\n\t\t\t\t?.find(\n\t\t\t\t\t(account) =>\n\t\t\t\t\t\taccount.credential.type === \"oauth\" &&\n\t\t\t\t\t\tsameCredential({ ...account.credential, accountKey: undefined }, credential),\n\t\t\t\t);\n\t\t\t// ponytail: unstamped credential assumed to be the active account's refresh; an older HUMAIN Code version logging in a different account overwrites the active entry\n\t\t\tidentity =\n\t\t\t\tactiveKey && Object.hasOwn(pool.accounts, activeKey) && pool.accounts[activeKey].credential.type === \"oauth\"\n\t\t\t\t\t? { key: activeKey, label: pool.accounts[activeKey].label }\n\t\t\t\t\t: cached\n\t\t\t\t\t\t? { key: cached.key, label: cached.label }\n\t\t\t\t\t\t: includeApiKeys\n\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\tkey: `account-${randomUUID()}`,\n\t\t\t\t\t\t\t\t\tlabel: `Account ${pool.nextLocalAccountId ?? Object.keys(pool.accounts).length + 1}`,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t: nextLocalAccountIdentity(pool);\n\t\t}\n\t\tconst existing = pool.accounts[identity.key];\n\t\tif (existing?.quarantine) return undefined;\n\t\tpool.accounts[identity.key] = {\n\t\t\tcredential:\n\t\t\t\tproviderId === \"openai-codex\" && !identity.key.startsWith(\"account-\")\n\t\t\t\t\t? structuredClone(credential)\n\t\t\t\t\t: { ...structuredClone(credential), accountKey: identity.key },\n\t\t\tlabel: existing?.label ?? identity.label,\n\t\t\texhaustedUntil: existing?.exhaustedUntil,\n\t\t\tquotaFailures: existing?.quotaFailures,\n\t\t\tcooldownRevision: existing?.cooldownRevision,\n\t\t};\n\t\treturn identity.key;\n\t}\n\n\t/**\n\t * Runs `operation` under the pool lock on the stored pool, with the credential auth.json holds synced in as the\n\t * active account. When auth.json changes between that read and the auth.json lock (a token refresh, another\n\t * process), the operation is re-applied to the latest credential under the auth.json lock, so a refresh can neither\n\t * resurrect a removed account nor be rolled back. Removals recheck even when the first plan needs no auth.json\n\t * change. An observation guard checks raw credentials before planning and under the auth.json lock; a mismatch\n\t * returns its `changed` result without pool writes or cache publication. With `expectedKey`, the\n\t * operation only applies while auth.json holds an OAuth credential of `expectedKey`, both when read and again under\n\t * the auth.json lock (even when auth.json needs no change); otherwise auth.json is not overwritten. The caller's\n\t * abort signal is honoured, including while waiting for the auth.json lock, until the commit point (just before\n\t * auth.json is changed) and ignored afterwards so the pool file write is never skipped once auth.json changed. The\n\t * cache is published only after the operation succeeded. `poolOnly` rechecks auth and merges it only into cache;\n\t * it never persists auth changes, activates credentials, or normalizes stored account metadata.\n\t */\n\tprivate async run<T>(\n\t\tproviderId: string,\n\t\tmode: \"read\" | \"write\",\n\t\tcallerOptions: AuthOperationOptions | undefined,\n\t\toperation: (pool: StoredProviderPool, context: RunContext) => T,\n\t\texpectedKey?: string,\n\t\trecheckAuth = false,\n\t\tincludeApiKeys = false,\n\t\tobservation?: { ifCurrent: NonNullable<CredentialDeleteOptions[\"ifCurrent\"]>; changed: T },\n\t\tcanActivate?: (from: PoolAccount, to: PoolAccount) => boolean,\n\t\tpoolOnly = false,\n\t\tusageRefresh?: {\n\t\t\tkey: string | undefined;\n\t\t\trefresh: UsageCredentialRefresh;\n\t\t\tresult: (value: UsageRefreshResult) => T;\n\t\t},\n\t): Promise<T | undefined> {\n\t\tconst operationPromise = (async () => {\n\t\t\tlet observationChanged = false;\n\t\t\tconst credentials = observation\n\t\t\t\t? getAccountCredentialStore(this.credentials, (current) => {\n\t\t\t\t\t\tconst matches = observation.ifCurrent(current);\n\t\t\t\t\t\tif (!matches) observationChanged = true;\n\t\t\t\t\t\treturn matches;\n\t\t\t\t\t})\n\t\t\t\t: this.credentials;\n\t\t\t// `outerLink` governs the pool lock and the pool-file write; `authLink` governs the auth.json lock wait.\n\t\t\t// Both forward the caller's abort until the commit point; `authLink` outlives it until auth.json settles.\n\t\t\tconst passthrough = { options: callerOptions, detach: () => {} };\n\t\t\tconst outerLink = mode === \"write\" ? linkAbortSignal(callerOptions) : passthrough;\n\t\t\tconst authLink = mode === \"write\" ? linkAbortSignal(callerOptions) : passthrough;\n\t\t\tconst options = outerLink.options;\n\t\t\t/** Last abort check before auth.json changes; afterwards the pool-file write must not be skipped. */\n\t\t\tconst commitAuthChange = () => {\n\t\t\t\tcallerOptions?.signal?.throwIfAborted();\n\t\t\t\touterLink.detach();\n\t\t\t};\n\t\t\tconst published: { view?: PoolAccount[] } = {};\n\t\t\ttry {\n\t\t\t\tconst outcome = await this.storage.withLockAsync(async (content, save) => {\n\t\t\t\t\tlet data: PoolData;\n\t\t\t\t\tlet corrupt = false;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tdata = parsePoolData(content);\n\t\t\t\t\t\tthis.error = undefined;\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthis.error = `Invalid ${this.location}: ${error instanceof Error ? error.message : String(error)}`;\n\t\t\t\t\t\tif (mode === \"write\")\n\t\t\t\t\t\t\tthrow new Error(`Refusing to modify corrupt ${this.location}. Fix or delete it first.`);\n\t\t\t\t\t\tcorrupt = true;\n\t\t\t\t\t\tdata = {};\n\t\t\t\t\t}\n\t\t\t\t\tconst legacy =\n\t\t\t\t\t\t!corrupt &&\n\t\t\t\t\t\tcontent !== undefined &&\n\t\t\t\t\t\t!Object.hasOwn(JSON.parse(stripBom(content).trim() || \"{}\"), \"version\");\n\t\t\t\t\t// Snapshot before planning mutates data: a newly created empty file has no legacy accounts to back up.\n\t\t\t\t\tconst hasLegacyAccounts = legacy && Object.keys(data).length > 0;\n\t\t\t\t\tlet backedUp = false;\n\t\t\t\t\tconst serialize = (providers: PoolData): string => {\n\t\t\t\t\t\tif (hasLegacyAccounts && this.storage instanceof FileAuthStorageBackend && !this.backupPath)\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\"File-backed account migration requires OAuthAccountPool.create() or a backup path\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\tif (hasLegacyAccounts && !backedUp && this.backupPath) {\n\t\t\t\t\t\t\tif (existsSync(this.backupPath)) {\n\t\t\t\t\t\t\t\tif (readFileSync(this.backupPath, \"utf8\") !== content)\n\t\t\t\t\t\t\t\t\tthrow new Error(\"Account migration backup already exists; refusing to overwrite it\");\n\t\t\t\t\t\t\t\tconst fd = openSync(this.backupPath, \"r\");\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tfchmodSync(fd, 0o600);\n\t\t\t\t\t\t\t\t\tfsyncSync(fd);\n\t\t\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\t\t\tcloseSync(fd);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tconst fd = openSync(this.backupPath, \"wx\", 0o600);\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\twriteFileSync(fd, content!, \"utf8\");\n\t\t\t\t\t\t\t\t\tfsyncSync(fd);\n\t\t\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\t\t\tcloseSync(fd);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbackedUp = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Use the backend's actual path, not its display location or optional migration backup path.\n\t\t\t\t\t\tif (this.storage instanceof FileAuthStorageBackend) this.storage.makePrivate();\n\t\t\t\t\t\treturn JSON.stringify({ version: 2, providers }, null, 2);\n\t\t\t\t\t};\n\t\t\t\t\tconst stored = Object.hasOwn(data, providerId) ? data[providerId] : undefined;\n\t\t\t\t\tconst before = JSON.stringify(stored);\n\t\t\t\t\t/** Applies `operation` to a copy of the stored pool as if auth.json held `credential`. */\n\t\t\t\t\tconst plan = (credential: Credential | undefined) => {\n\t\t\t\t\t\tlet pool: StoredProviderPool = stored ? structuredClone(stored) : { active: \"\", accounts: {} };\n\t\t\t\t\t\t// Persist evidence, not a restamp: ambiguous ownership never authorizes another slot's grant.\n\t\t\t\t\t\tthis.quarantineCrosslinks(providerId, pool);\n\t\t\t\t\t\tconst currentKey = this.upsertCredential(pool, credential, providerId, pool.active, includeApiKeys);\n\t\t\t\t\t\tif (providerId !== \"openai-codex\") reserveLocalAccountKeys(pool);\n\t\t\t\t\t\tif (currentKey !== undefined) pool.active = currentKey;\n\t\t\t\t\t\t/** The pool before the operation, holding the source tokens auth.json may stop holding. */\n\t\t\t\t\t\tconst source = structuredClone(pool);\n\t\t\t\t\t\tconst context: RunContext = {\n\t\t\t\t\t\t\tcurrentKey,\n\t\t\t\t\t\t\tcurrentCredential: currentKey === undefined ? undefined : pool.accounts[currentKey].credential,\n\t\t\t\t\t\t};\n\t\t\t\t\t\t// Marker-only mutations validate against auth.json but must not persist its unrelated changes.\n\t\t\t\t\t\tif (poolOnly) pool = stored ? structuredClone(stored) : { active: \"\", accounts: {} };\n\t\t\t\t\t\tconst result = operation(pool, context);\n\t\t\t\t\t\tconst keys = Object.keys(pool.accounts);\n\t\t\t\t\t\tif (!poolOnly && !Object.hasOwn(pool.accounts, pool.active)) pool.active = \"\";\n\t\t\t\t\t\tconst active = pool.accounts[pool.active];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!poolOnly &&\n\t\t\t\t\t\t\tactive?.credential.type === \"api_key\" &&\n\t\t\t\t\t\t\t(active.credential.key?.includes(\"$\") || active.credential.key?.startsWith(\"!\"))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tconst stamped = { ...active.credential, accountKey: pool.active };\n\t\t\t\t\t\t\tactive.credential = stamped;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn { pool, source, context, result, empty: keys.length === 0 || pool.active === \"\" };\n\t\t\t\t\t};\n\n\t\t\t\t\t// auth.json always holds the active account (pi-ai may have refreshed it): sync it into the view.\n\t\t\t\t\tconst current = await credentials.read(providerId, options);\n\t\t\t\t\tif (observationChanged) return { result: observation!.changed };\n\t\t\t\t\tlet next = plan(current);\n\t\t\t\t\toptions?.signal?.throwIfAborted();\n\t\t\t\t\tif (mode === \"read\") {\n\t\t\t\t\t\t// OAuth-only eligibility must not erase a generalized transient identity. Keep cache reconciliation\n\t\t\t\t\t\t// separate from the operation's view, so legacy mutations never adopt API keys implicitly.\n\t\t\t\t\t\tconst view = structuredClone(next.pool);\n\t\t\t\t\t\tif (!includeApiKeys) this.upsertCredential(view, current, providerId, view.active, true);\n\t\t\t\t\t\tthis.cache.set(providerId, toPoolAccounts(view));\n\t\t\t\t\t\treturn { result: next.result };\n\t\t\t\t\t}\n\t\t\t\t\tif (next.result === undefined && !usageRefresh) return { result: undefined };\n\t\t\t\t\t// Prepare backup and private permissions before changing auth.json, even without a checkpoint.\n\t\t\t\t\t// Observation guards defer setup until their auth-lock comparison succeeds.\n\t\t\t\t\tif (!observation && JSON.stringify(next.pool) !== before) serialize(data);\n\t\t\t\t\t/** Re-applies the operation when auth.json no longer holds the credential `next` was planned for. */\n\t\t\t\t\tlet planned = current;\n\t\t\t\t\tconst replan = (latest: Credential | undefined) => {\n\t\t\t\t\t\tif (poolOnly || !sameCredential(latest, planned)) {\n\t\t\t\t\t\t\tnext = plan(latest);\n\t\t\t\t\t\t\tplanned = latest;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn next;\n\t\t\t\t\t};\n\t\t\t\t\t/** This provider's pool as last written to the pool file, including a checkpoint. */\n\t\t\t\t\tlet persisted = before;\n\n\t\t\t\t\tconst { currentKey } = next.context;\n\t\t\t\t\tif (usageRefresh) {\n\t\t\t\t\t\t// Same lock order as switching. Inference also takes the auth lock before refreshing;\n\t\t\t\t\t\t// re-read under both locks before consuming a possibly single-use refresh token.\n\t\t\t\t\t\tawait credentials.modify(\n\t\t\t\t\t\t\tproviderId,\n\t\t\t\t\t\t\tasync (latest) => {\n\t\t\t\t\t\t\t\tconst { pool, context } = replan(latest);\n\t\t\t\t\t\t\t\tconst key = usageRefresh.key ?? pool.active;\n\t\t\t\t\t\t\t\tconst account = Object.hasOwn(pool.accounts, key) ? pool.accounts[key] : undefined;\n\t\t\t\t\t\t\t\tif (account?.quarantine || account?.credential.type !== \"oauth\") return undefined;\n\t\t\t\t\t\t\t\tif (account.credential.expires > Date.now()) {\n\t\t\t\t\t\t\t\t\tnext.result = usageRefresh.result(toAccount(pool, key));\n\t\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tserialize(data);\n\t\t\t\t\t\t\t\t// Once the grant starts, closing a popup must not discard a rotated token.\n\t\t\t\t\t\t\t\tcommitAuthChange();\n\t\t\t\t\t\t\t\tauthLink.detach();\n\t\t\t\t\t\t\t\tconst refreshed = await usageRefresh.refresh(account.credential);\n\t\t\t\t\t\t\t\tif (typeof refreshed === \"string\") {\n\t\t\t\t\t\t\t\t\tnext.result = usageRefresh.result(refreshed);\n\t\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\taccount.credential = {\n\t\t\t\t\t\t\t\t\t...this.bindRefresh(providerId, account.credential, refreshed),\n\t\t\t\t\t\t\t\t\taccountKey: key,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\tnext.result = usageRefresh.result(toAccount(pool, key));\n\t\t\t\t\t\t\t\treturn context.currentKey === key ? structuredClone(account.credential) : undefined;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tauthLink.options,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if (expectedKey !== undefined && currentKey !== expectedKey) {\n\t\t\t\t\t\t// The operation declined to act (active_changed): no auth.json write; only the sync is persisted.\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tpoolOnly ||\n\t\t\t\t\t\t(!next.empty && (currentKey !== undefined || next.context.activate)) ||\n\t\t\t\t\t\t(recheckAuth && currentKey === undefined)\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst authChange =\n\t\t\t\t\t\t\t!next.empty && !sameCredential(next.pool.accounts[next.pool.active].credential, current);\n\t\t\t\t\t\tif (authChange || expectedKey !== undefined || recheckAuth) {\n\t\t\t\t\t\t\t// Guarded operations and removals recheck under the auth.json lock, even without an initial auth change.\n\t\t\t\t\t\t\tawait credentials.modify(\n\t\t\t\t\t\t\t\tproviderId,\n\t\t\t\t\t\t\t\tasync (latest) => {\n\t\t\t\t\t\t\t\t\tauthLink.options?.signal?.throwIfAborted();\n\t\t\t\t\t\t\t\t\tconst { pool, source, context, result, empty } = replan(latest);\n\t\t\t\t\t\t\t\t\t// Declined, or adoption/removal facing a credential it must not replace (non-OAuth or unmatched).\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tpoolOnly ||\n\t\t\t\t\t\t\t\t\t\tresult === undefined ||\n\t\t\t\t\t\t\t\t\t\t(expectedKey !== undefined && context.currentKey !== expectedKey) ||\n\t\t\t\t\t\t\t\t\t\t(context.currentKey === undefined && !context.activate)\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// A re-plan that emptied the pool cannot delete inside modify: the guarded delete below does.\n\t\t\t\t\t\t\t\t\tif (empty) return undefined;\n\t\t\t\t\t\t\t\t\tconst target = pool.accounts[pool.active].credential;\n\t\t\t\t\t\t\t\t\t// Policy can change while either lock is awaited, even without a credential change.\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tcanActivate &&\n\t\t\t\t\t\t\t\t\t\t(context.currentKey === undefined ||\n\t\t\t\t\t\t\t\t\t\t\t!canActivate(\n\t\t\t\t\t\t\t\t\t\t\t\ttoPoolAccount(source, context.currentKey),\n\t\t\t\t\t\t\t\t\t\t\t\ttoPoolAccount(pool, pool.active),\n\t\t\t\t\t\t\t\t\t\t\t))\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\tthrow new Error(\"Account activation is no longer authorized\");\n\t\t\t\t\t\t\t\t\tif (pool.accounts[pool.active].quarantine) return undefined;\n\t\t\t\t\t\t\t\t\tif (sameCredential(target, latest)) return undefined;\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tlatest !== undefined &&\n\t\t\t\t\t\t\t\t\t\tpool.active !== context.currentKey &&\n\t\t\t\t\t\t\t\t\t\tJSON.stringify(source) !== persisted\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t// Keep the latest source tokens durable before auth.json stops holding them.\n\t\t\t\t\t\t\t\t\t\tsave(serialize({ ...data, [providerId]: source }));\n\t\t\t\t\t\t\t\t\t\tpersisted = JSON.stringify(source);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// A concurrent refresh can turn an initially unchanged plan into an auth write.\n\t\t\t\t\t\t\t\t\tserialize(data);\n\t\t\t\t\t\t\t\t\tcommitAuthChange();\n\t\t\t\t\t\t\t\t\treturn structuredClone(target);\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tauthLink.options,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (observationChanged) return { result: observation!.changed };\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (!poolOnly && next.result !== undefined && next.empty && next.context.currentKey !== undefined) {\n\t\t\t\t\t\t// The last account was removed (by the first plan or a re-plan above): delete the auth.json credential\n\t\t\t\t\t\t// only while, under the auth.json lock, it still belongs to a removed account. An API key, another\n\t\t\t\t\t\t// account (adopted by the re-plan), or an unmatched credential stays.\n\t\t\t\t\t\tconst deleteOptions: CredentialDeleteOptions = {\n\t\t\t\t\t\t\t...authLink.options,\n\t\t\t\t\t\t\tifCurrent: (latest) => {\n\t\t\t\t\t\t\t\tconst { result, empty, context } = replan(latest);\n\t\t\t\t\t\t\t\tif (result === undefined || !empty || context.currentKey === undefined) return false;\n\t\t\t\t\t\t\t\tserialize(data);\n\t\t\t\t\t\t\t\tcommitAuthChange();\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t\tawait credentials.delete(providerId, deleteOptions);\n\t\t\t\t\t\tif (observationChanged) return { result: observation!.changed };\n\t\t\t\t\t}\n\t\t\t\t\tconst { pool, result } = next;\n\t\t\t\t\t// A declined re-plan still adopts the latest credential without removing any account.\n\t\t\t\t\tif (Object.keys(pool.accounts).length === 0 && pool.nextLocalAccountId === undefined)\n\t\t\t\t\t\tdelete data[providerId];\n\t\t\t\t\telse\n\t\t\t\t\t\tObject.defineProperty(data, providerId, {\n\t\t\t\t\t\t\tvalue: pool,\n\t\t\t\t\t\t\tenumerable: true,\n\t\t\t\t\t\t\tconfigurable: true,\n\t\t\t\t\t\t\twritable: true,\n\t\t\t\t\t\t});\n\t\t\t\t\tconst view = structuredClone(pool);\n\t\t\t\t\tif (poolOnly) {\n\t\t\t\t\t\tconst currentKey = this.upsertCredential(\n\t\t\t\t\t\t\tview,\n\t\t\t\t\t\t\tnext.context.currentCredential ?? planned,\n\t\t\t\t\t\t\tproviderId,\n\t\t\t\t\t\t\tview.active,\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (currentKey !== undefined) view.active = currentKey;\n\t\t\t\t\t}\n\t\t\t\t\tif (!poolOnly && !includeApiKeys && planned?.type === \"api_key\" && !next.context.activate)\n\t\t\t\t\t\tthis.upsertCredential(view, planned, providerId, view.active, true);\n\t\t\t\t\tpublished.view = toPoolAccounts(view);\n\t\t\t\t\tconst changed = !corrupt && JSON.stringify(data[providerId]) !== persisted;\n\t\t\t\t\treturn { result, next: changed ? serialize(data) : undefined };\n\t\t\t\t}, options);\n\t\t\t\t// Publish only once the whole operation (auth.json and pool file) succeeded.\n\t\t\t\tif (published.view) this.cache.set(providerId, published.view);\n\t\t\t\treturn outcome;\n\t\t\t} finally {\n\t\t\t\touterLink.detach();\n\t\t\t\tauthLink.detach();\n\t\t\t}\n\t\t})();\n\t\tif (mode === \"write\") {\n\t\t\tconst pending = operationPromise.then(\n\t\t\t\t() => undefined,\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\tthis.pendingWrites.add(pending);\n\t\t\tvoid pending.finally(() => this.pendingWrites.delete(pending));\n\t\t}\n\t\treturn operationPromise;\n\t}\n}\n"]}
|