diff --git a/src/claude-usage.ts b/src/claude-usage.ts index 0c5def7..617f772 100644 --- a/src/claude-usage.ts +++ b/src/claude-usage.ts @@ -58,13 +58,17 @@ function loadUsageDiskCache(): void { if (fs.existsSync(USAGE_CACHE_FILE)) { usageDiskCache = JSON.parse(fs.readFileSync(USAGE_CACHE_FILE, 'utf-8')); } - } catch { /* start fresh */ } + } catch { + /* start fresh */ + } } function saveUsageDiskCache(): void { try { fs.writeFileSync(USAGE_CACHE_FILE, JSON.stringify(usageDiskCache)); - } catch { /* best effort */ } + } catch { + /* best effort */ + } } function cacheKey(token: string): string { @@ -104,7 +108,9 @@ async function fetchUsageForToken( return null; } if (res.status === 429) { - logger.warn('Claude usage API: rate limited (429), returning cached data'); + logger.warn( + 'Claude usage API: rate limited (429), returning cached data', + ); return usageDiskCache[cacheKey(token)]?.usage ?? null; } if (!res.ok) { diff --git a/src/provider-fallback.ts b/src/provider-fallback.ts index 5140bdb..20343b7 100644 --- a/src/provider-fallback.ts +++ b/src/provider-fallback.ts @@ -48,15 +48,13 @@ interface FallbackConfig { // ── State ──────────────────────────────────────────────────────── let cooldown: CooldownState | null = null; -let lastUsageAvailabilityCheck: - | { - checkedAt: number; - result: 'available' | 'exhausted' | 'unknown'; - } - | null = null; -let usageAvailabilityCheckPromise: - | Promise<'available' | 'exhausted' | 'unknown'> - | null = null; +let lastUsageAvailabilityCheck: { + checkedAt: number; + result: 'available' | 'exhausted' | 'unknown'; +} | null = null; +let usageAvailabilityCheckPromise: Promise< + 'available' | 'exhausted' | 'unknown' +> | null = null; const USAGE_RECOVERY_RECHECK_MS = 30_000; @@ -213,7 +211,10 @@ export async function getActiveProvider(): Promise { } if (usageAvailability === 'exhausted') { // Current token exhausted — try rotating to another token (ignore cooldowns) - if (getTokenCount() > 1 && rotateToken(undefined, { ignoreRateLimits: true })) { + if ( + getTokenCount() > 1 && + rotateToken(undefined, { ignoreRateLimits: true }) + ) { logger.info( 'Claude current token exhausted, rotated to next token — retrying', ); diff --git a/src/task-scheduler.test.ts b/src/task-scheduler.test.ts index 6bf9a37..40f79cb 100644 --- a/src/task-scheduler.test.ts +++ b/src/task-scheduler.test.ts @@ -307,14 +307,14 @@ Check the run. phase: 'intermediate', result: "You're out of extra usage · resets 4am (Asia/Seoul)", }); - await onOutput?.({ - status: 'success', - result: "You're out of extra usage · resets 4am (Asia/Seoul)", - }); - return { - status: 'success', - result: null, - }; + await onOutput?.({ + status: 'success', + result: "You're out of extra usage · resets 4am (Asia/Seoul)", + }); + return { + status: 'success', + result: null, + }; }, ) .mockImplementationOnce( @@ -324,14 +324,14 @@ Check the run. _onProcess: unknown, onOutput?: (output: Record) => Promise, ) => { - await onOutput?.({ - status: 'success', - result: 'rotated scheduled task response', - }); - return { - status: 'success', - result: null, - }; + await onOutput?.({ + status: 'success', + result: 'rotated scheduled task response', + }); + return { + status: 'success', + result: null, + }; }, ); diff --git a/src/token-rotation.ts b/src/token-rotation.ts index 62e3473..664ceb8 100644 --- a/src/token-rotation.ts +++ b/src/token-rotation.ts @@ -156,11 +156,7 @@ export function rotateToken( for (let i = 1; i < tokens.length; i++) { const idx = (currentIndex + i) % tokens.length; const state = tokens[idx]; - if ( - ignoreRL || - !state.rateLimitedUntil || - state.rateLimitedUntil <= now - ) { + if (ignoreRL || !state.rateLimitedUntil || state.rateLimitedUntil <= now) { state.rateLimitedUntil = null; currentIndex = idx; logger.info(