diff --git a/lib/codex-manager.ts b/lib/codex-manager.ts index b1c32ea7..4c207ab8 100644 --- a/lib/codex-manager.ts +++ b/lib/codex-manager.ts @@ -45,6 +45,7 @@ import { } from "./codex-manager/commands/doctor.js"; import { type FixCliOptions, + type FixCommandDeps, runFixCommand, } from "./codex-manager/commands/fix.js"; import { runForecastCommand } from "./codex-manager/commands/forecast.js"; @@ -2667,41 +2668,6 @@ function upsertRecoveredFlaggedAccount( }; } -async function runFix(args: string[]): Promise { - return runFixCommand(args, { - setStoragePath, - loadAccounts, - parseFixArgs, - printFixUsage, - loadQuotaCache, - saveQuotaCache, - cloneQuotaCacheData, - buildQuotaEmailFallbackState, - updateQuotaCacheForAccount, - pruneUnsafeQuotaEmailCacheEntry, - resolveActiveIndex, - hasUsableAccessToken, - fetchCodexQuotaSnapshot, - formatCompactQuotaSnapshot, - normalizeFailureDetail, - hasLikelyInvalidRefreshToken, - queuedRefresh, - sanitizeEmail, - extractAccountEmail, - extractAccountId, - applyTokenAccountIdentity, - isHardRefreshFailure, - evaluateForecastAccounts, - recommendForecastAccount, - saveAccounts, - formatAccountLabel, - stylePromptText, - formatResultSummary, - styleAccountDetailText, - defaultDisplay: DEFAULT_DASHBOARD_DISPLAY_SETTINGS, - }); -} - interface DoctorFixAction { key: string; message: string; @@ -2834,37 +2800,43 @@ function applyDoctorFixes(storage: AccountStorageV3): { return { changed, actions }; } -async function runDoctor(args: string[]): Promise { - return runDoctorCommand(args, { +async function clearAccountsAndReset(): Promise { + await clearAccounts(); +} + +function buildFixCommandDeps(): FixCommandDeps { + return { setStoragePath, - getStoragePath, - getCodexCliAuthPath, - getCodexCliConfigPath, - loadCodexCliState, - parseDoctorArgs, - printDoctorUsage, loadAccounts, - applyDoctorFixes, - saveAccounts, + parseFixArgs, + printFixUsage, + loadQuotaCache, + saveQuotaCache, + cloneQuotaCacheData, + buildQuotaEmailFallbackState, + updateQuotaCacheForAccount, + pruneUnsafeQuotaEmailCacheEntry, resolveActiveIndex, - evaluateForecastAccounts, - recommendForecastAccount, + hasUsableAccessToken, + fetchCodexQuotaSnapshot, + formatCompactQuotaSnapshot, + normalizeFailureDetail, + hasLikelyInvalidRefreshToken, + queuedRefresh, sanitizeEmail, extractAccountEmail, extractAccountId, - hasPlaceholderEmail, - hasLikelyInvalidRefreshToken, - getDoctorRefreshTokenKey, - hasUsableAccessToken, - queuedRefresh, - normalizeFailureDetail, applyTokenAccountIdentity, - setCodexCliActiveSelection, - }); -} - -async function clearAccountsAndReset(): Promise { - await clearAccounts(); + isHardRefreshFailure, + evaluateForecastAccounts, + recommendForecastAccount, + saveAccounts, + formatAccountLabel, + stylePromptText, + formatResultSummary, + styleAccountDetailText, + defaultDisplay: DEFAULT_DASHBOARD_DISPLAY_SETTINGS, + }; } async function handleManageAction( @@ -3051,7 +3023,7 @@ async function runAuthLogin(args: string[]): Promise { "Auto-Fix", "Checking and fixing common issues", async () => { - await runFix(["--live"]); + await runFixCommand(["--live"], buildFixCommandDeps()); }, displaySettings, ); @@ -3597,10 +3569,35 @@ export async function runCodexMultiAuthCli(rawArgs: string[]): Promise { }); } if (command === "fix") { - return runFix(rest); + return runFixCommand(rest, buildFixCommandDeps()); } if (command === "doctor") { - return runDoctor(rest); + return runDoctorCommand(rest, { + setStoragePath, + getStoragePath, + getCodexCliAuthPath, + getCodexCliConfigPath, + loadCodexCliState, + parseDoctorArgs, + printDoctorUsage, + loadAccounts, + applyDoctorFixes, + saveAccounts, + resolveActiveIndex, + evaluateForecastAccounts, + recommendForecastAccount, + sanitizeEmail, + extractAccountEmail, + extractAccountId, + hasPlaceholderEmail, + hasLikelyInvalidRefreshToken, + getDoctorRefreshTokenKey, + hasUsableAccessToken, + queuedRefresh, + normalizeFailureDetail, + applyTokenAccountIdentity, + setCodexCliActiveSelection, + }); } console.error(`Unknown command: ${command}`);