@@ -12,9 +12,8 @@ import type { UsageSnapshot, UsageWindow } from "../types";
1212 * Schema (per codexbar) of GET /api/usage-summary → individualUsage.plan:
1313 * { used (cents), limit (cents), breakdown { included, bonus, total },
1414 * totalPercentUsed, autoPercentUsed, apiPercentUsed } + billingCycleEnd +
15- * membershipType. Surfaced as Auto and API breakdown windows. The dollar
16- * allowance belongs to API usage; see `apiDollars` for how the clamped
17- * dollar fields are reconciled with the authoritative percents.
15+ * membershipType. Surfaced as Auto and API windows. API dollars use real
16+ * spend over the vendor plan limit; the bar uses apiPercentUsed separately.
1817 */
1918
2019export const CURSOR_USAGE_ENDPOINT = "https://cursor.com/api/usage-summary" ;
@@ -63,21 +62,22 @@ function clampPercent(value: number | undefined): number | undefined {
6362}
6463
6564/**
66- * Cursor's plan dollar fields need reconciliation (verified against the live
67- * payload and CodexBar's Cursor probe, which scrapes the same endpoint):
65+ * Cursor plan dollars vs API percent are different meters:
6866 *
69- * - `used`/`limit`/`remaining` clamp at the nominal plan price (e.g. $20/$20
70- * while the percent says 55%), so they understate real spend.
71- * - `breakdown.total` is the total credits *consumed* (included + bonus spend),
72- * not the allowance — treating it as the limit was CodexBar regression #240.
73- * Prefer it as the real spend when it exceeds the clamped `used`.
74- * - `apiPercentUsed` is the authoritative consumed fraction (it's what
75- * Cursor's own dashboard messages report). When the dollar pair disagrees
76- * with it, keep the spend and derive the allowance as `spend / percent` so
77- * the dollar text always matches the bar (e.g. $28.75 / $52.21 at 55%,
78- * instead of a clamped, full-looking $20 / $20).
67+ * - `used`/`limit` clamp at the nominal plan price (e.g. $20/$20) and can
68+ * understate real spend once bonus credit is consumed.
69+ * - `breakdown.total` is credits *consumed* (included + bonus spend), not the
70+ * allowance — treating it as the limit was CodexBar regression #240.
71+ * - `apiPercentUsed` drives the bar / "% by reset" pace; it is not a fraction
72+ * of the plan dollar cap. Deriving `limit = spend / apiPercent` invents a
73+ * nonsense ceiling (e.g. $35.61 / $775 at 4.5%) that is neither spend nor
74+ * the Pro included allowance.
75+ *
76+ * Surface honest money: real spend over the vendor plan limit. The bar may
77+ * then disagree with the dollar ratio — that is correct; they measure different
78+ * things.
7979 */
80- function apiDollars ( plan : CursorPlanUsage , percent : number ) : { used ?: number ; limit ?: number } {
80+ function apiDollars ( plan : CursorPlanUsage ) : { used ?: number ; limit ?: number } {
8181 const reportedUsed = centsToUsd ( plan . used ) ;
8282 const reportedLimit = centsToUsd ( plan . limit ) ;
8383 const breakdownTotal = centsToUsd ( plan . breakdown ?. total ) ;
@@ -89,15 +89,6 @@ function apiDollars(plan: CursorPlanUsage, percent: number): { used?: number; li
8989 if ( spend === undefined ) {
9090 return reportedLimit !== undefined && reportedLimit > 0 ? { limit : reportedLimit } : { } ;
9191 }
92- if ( spend > 0 && percent > 0 ) {
93- const impliedPercent =
94- reportedLimit !== undefined && reportedLimit > 0 ? ( spend / reportedLimit ) * 100 : undefined ;
95- // 1-point tolerance so ordinary rounding drift in the reported percent
96- // doesn't override a limit the spend already agrees with.
97- if ( impliedPercent === undefined || Math . abs ( impliedPercent - percent ) > 1 ) {
98- return { used : spend , limit : spend / ( percent / 100 ) } ;
99- }
100- }
10192 return {
10293 used : spend ,
10394 ...( reportedLimit !== undefined && reportedLimit > 0 ? { limit : reportedLimit } : { } ) ,
@@ -146,7 +137,7 @@ export function parseCursorUsage(
146137 usedPercent : apiPercent ,
147138 unit : "percent" ,
148139 currency : "USD" ,
149- ...apiDollars ( plan , apiPercent ) ,
140+ ...apiDollars ( plan ) ,
150141 ...withReset ,
151142 } ) ;
152143 }
0 commit comments