Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 59 additions & 62 deletions lib/codex-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -2667,41 +2668,6 @@ function upsertRecoveredFlaggedAccount(
};
}

async function runFix(args: string[]): Promise<number> {
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;
Expand Down Expand Up @@ -2834,37 +2800,43 @@ function applyDoctorFixes(storage: AccountStorageV3): {
return { changed, actions };
}

async function runDoctor(args: string[]): Promise<number> {
return runDoctorCommand(args, {
async function clearAccountsAndReset(): Promise<void> {
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<void> {
await clearAccounts();
isHardRefreshFailure,
evaluateForecastAccounts,
recommendForecastAccount,
saveAccounts,
formatAccountLabel,
stylePromptText,
formatResultSummary,
styleAccountDetailText,
defaultDisplay: DEFAULT_DASHBOARD_DISPLAY_SETTINGS,
};
}

async function handleManageAction(
Expand Down Expand Up @@ -3051,7 +3023,7 @@ async function runAuthLogin(args: string[]): Promise<number> {
"Auto-Fix",
"Checking and fixing common issues",
async () => {
await runFix(["--live"]);
await runFixCommand(["--live"], buildFixCommandDeps());
},
displaySettings,
);
Expand Down Expand Up @@ -3597,10 +3569,35 @@ export async function runCodexMultiAuthCli(rawArgs: string[]): Promise<number> {
});
}
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}`);
Expand Down