

























@@ -1,3 +1,7 @@
1+/**
2+ * Reads and refreshes credentials stored by external CLI runtimes such as
3+ * Claude Code, Codex, Gemini, and MiniMax.
4+ */
15import { execFileSync, execSync } from "node:child_process";
26import { createHash } from "node:crypto";
37import fs from "node:fs";
@@ -36,13 +40,15 @@ let codexCliCache: CachedValue<CodexCliCredential> | null = null;
3640let minimaxCliCache: CachedValue<MiniMaxCliCredential> | null = null;
3741let geminiCliCache: CachedValue<GeminiCliCredential> | null = null;
384243+/** Clears in-memory CLI credential caches for isolated tests. */
3944export function resetCliCredentialCachesForTest(): void {
4045claudeCliCache = null;
4146codexCliCache = null;
4247minimaxCliCache = null;
4348geminiCliCache = null;
4449}
455051+/** Credential shape parsed from Claude Code CLI storage. */
4652export type ClaudeCliCredential =
4753| {
4854type: "oauth";
@@ -58,6 +64,7 @@ export type ClaudeCliCredential =
5864expires: number;
5965};
606667+/** Credential shape parsed from Codex CLI storage. */
6168export type CodexCliCredential = {
6269type: "oauth";
6370provider: OAuthProvider;
@@ -68,6 +75,7 @@ export type CodexCliCredential = {
6875idToken?: string;
6976};
707778+/** Credential shape parsed from MiniMax portal CLI storage. */
7179export type MiniMaxCliCredential = {
7280type: "oauth";
7381provider: "minimax-portal";
@@ -76,6 +84,7 @@ export type MiniMaxCliCredential = {
7684expires: number;
7785};
788687+/** Credential shape parsed from Gemini CLI storage. */
7988export type GeminiCliCredential = {
8089type: "oauth";
8190provider: "google-gemini-cli";
@@ -437,6 +446,7 @@ function readClaudeCliKeychainCredentials(
437446}
438447}
439448449+/** Reads Claude CLI credentials from macOS Keychain or the CLI credential file. */
440450export function readClaudeCliCredentials(options?: {
441451allowKeychainPrompt?: boolean;
442452platform?: NodeJS.Platform;
@@ -494,6 +504,7 @@ export function readClaudeCliCredentialsCached(options?: {
494504});
495505}
496506507+/** Writes refreshed Claude OAuth tokens back to the Claude CLI macOS Keychain item. */
497508export function writeClaudeCliKeychainCredentials(
498509newCredentials: OAuthCredentials,
499510options?: { execFileSync?: ExecFileSyncFn },
@@ -550,6 +561,7 @@ export function writeClaudeCliKeychainCredentials(
550561}
551562}
552563564+/** Writes refreshed Claude OAuth tokens back to the Claude CLI credential file. */
553565export function writeClaudeCliFileCredentials(
554566newCredentials: OAuthCredentials,
555567options?: ClaudeCliFileOptions,
@@ -592,6 +604,7 @@ export function writeClaudeCliFileCredentials(
592604}
593605}
594606607+/** Writes refreshed Claude OAuth tokens to the preferred Claude CLI credential store. */
595608export function writeClaudeCliCredentials(
596609newCredentials: OAuthCredentials,
597610options?: ClaudeCliWriteOptions,
@@ -612,6 +625,7 @@ export function writeClaudeCliCredentials(
612625return writeFile(newCredentials, { homeDir: options?.homeDir });
613626}
614627628+/** Reads Codex CLI OAuth credentials from Keychain or CODEX_HOME auth.json. */
615629export function readCodexCliCredentials(options?: {
616630codexHome?: string;
617631allowKeychainPrompt?: boolean;
@@ -673,6 +687,7 @@ export function readCodexCliCredentials(options?: {
673687};
674688}
675689690+/** Reads Codex CLI credentials with optional short-lived cache and file fingerprinting. */
676691export function readCodexCliCredentialsCached(options?: {
677692codexHome?: string;
678693allowKeychainPrompt?: boolean;
@@ -703,6 +718,7 @@ export function readCodexCliCredentialsCached(options?: {
703718});
704719}
705720721+/** Reads MiniMax CLI credentials with optional short-lived cache. */
706722export function readMiniMaxCliCredentialsCached(options?: {
707723ttlMs?: number;
708724homeDir?: string;
@@ -720,6 +736,7 @@ export function readMiniMaxCliCredentialsCached(options?: {
720736});
721737}
722738739+/** Reads Gemini CLI credentials with optional short-lived cache. */
723740export function readGeminiCliCredentialsCached(options?: {
724741ttlMs?: number;
725742homeDir?: string;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。