feat: Add process abort control and improve auth detection

This commit is contained in:
gsxdsm
2026-02-18 20:48:37 -08:00
parent 4ee160fae4
commit 15ca1eb6d3
24 changed files with 706 additions and 498 deletions

View File

@@ -59,6 +59,48 @@ export function getPaceStatusLabel(
return `${Math.abs(diff)}% ahead of pace`;
}
/**
* Calculate the expected pace percentage for a Codex rate limit window based on how far
* through the window we are. This is a generic version of getExpectedWeeklyPacePercentage
* that works with any window duration.
*
* Only returns a value for windows >= 1 day (1440 minutes) since pace tracking isn't
* meaningful for short windows.
*
* @param resetsAt - Unix timestamp in seconds for when the window resets
* @param windowDurationMins - Window duration in minutes
* @returns The expected usage percentage (0-100), or null if not applicable
*/
export function getExpectedCodexPacePercentage(
resetsAt: number | undefined | null,
windowDurationMins: number | undefined | null
): number | null {
// Only show pace for windows >= 1 day (1440 minutes)
if (!resetsAt || !windowDurationMins || windowDurationMins < 1440) return null;
try {
const resetDate = new Date(resetsAt * 1000);
if (isNaN(resetDate.getTime())) return null;
const now = new Date();
const windowMs = windowDurationMins * 60 * 1000;
// The window started windowDurationMins before the reset
const windowStartDate = new Date(resetDate.getTime() - windowMs);
// How far through the window are we?
const elapsed = now.getTime() - windowStartDate.getTime();
const fractionElapsed = elapsed / windowMs;
// Clamp to 0-1 range
const clamped = Math.max(0, Math.min(1, fractionElapsed));
return clamped * 100;
} catch {
return null;
}
}
/**
* Check if Claude usage is at its limit (any of: session >= 100%, weekly >= 100%, OR cost >= limit)
* Returns true if any limit is reached, meaning auto mode should pause feature pickup.