Skip to content

Commit b98a5c6

Browse files
wookiistclaude
andcommitted
fix(provider-cursor): report the billing-cycle length for usage windows
The Cursor usage response carries billingCycleStart, but the adapter only read billingCycleEnd, so the monthly windows had no windowDurationMins. Without it the Usage page cannot show the pace badge or the even-spend marker. Derive the length from end - start, as the Grok adapter does, and omit it when the start is missing or invalid. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent a1982c9 commit b98a5c6

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎packages/provider-cursor/src/server/usageLimits.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,41 @@ describe("Cursor usage limits", () => {
4242
);
4343
});
4444

45+
it("reports the billing-cycle length so pace can be computed", () => {
46+
const planUsage = { totalPercentUsed: 40, autoPercentUsed: 30, apiPercentUsed: 20 };
47+
const durations = (billingCycleStart: string | number | undefined, billingCycleEnd: string) =>
48+
cursorUsageResponseToLimits(
49+
{ billingCycleStart, billingCycleEnd, planUsage },
50+
checkedAt,
51+
).windows.map((window) => window.windowDurationMins);
52+
// A 30-day cycle and a 31-day cycle, from real start and end timestamps.
53+
expect(durations("1794045847072", "1796637847072")).toEqual([43_200, 43_200, 43_200]);
54+
expect(durations(1_796_637_847_072, "1799316247072")).toEqual([44_640, 44_640, 44_640]);
55+
});
56+
57+
it("omits the cycle length when the start is missing or invalid", () => {
58+
for (const billingCycleStart of [undefined, "", "0", "not-a-number", "1796637847072"]) {
59+
expect(
60+
cursorUsageResponseToLimits(
61+
{
62+
billingCycleStart,
63+
billingCycleEnd: "1796637847072",
64+
planUsage: { totalPercentUsed: 40 },
65+
},
66+
checkedAt,
67+
).windows,
68+
).toEqual([
69+
{
70+
id: "totalPercentUsed",
71+
kind: "monthly",
72+
label: "Overall",
73+
usedPercent: 40,
74+
resetsAt: "2026-12-07T10:04:07.072Z",
75+
},
76+
]);
77+
}
78+
});
79+
4580
it("does not invent unused allowance for absent buckets", () => {
4681
expect(cursorUsageResponseToLimits({ planUsage: {} }, checkedAt).unavailable?.reason).toBe(
4782
"unsupported",

‎packages/provider-cursor/src/server/usageLimits.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { DEFAULT_CURSOR_API_ENDPOINT, exchangeCursorApiKey } from "./apiKey.ts";
1717

1818
const CursorUsageResponse = Schema.Struct({
19+
billingCycleStart: Schema.optional(Schema.Union([Schema.String, Schema.Number])),
1920
billingCycleEnd: Schema.optional(Schema.Union([Schema.String, Schema.Number])),
2021
planUsage: Schema.optional(
2122
Schema.Struct({
@@ -36,6 +37,12 @@ export function cursorUsageResponseToLimits(
3637
Number(response.billingCycleEnd) > 0 && Option.isSome(reset)
3738
? DateTime.formatIso(reset.value)
3839
: undefined;
40+
// The pace badge and even-spend marker need the cycle length, which is end - start.
41+
const cycleStart = Number(response.billingCycleStart);
42+
const windowDurationMins =
43+
resetsAt && cycleStart > 0
44+
? Math.round((Number(response.billingCycleEnd) - cycleStart) / 60_000)
45+
: 0;
3946
const windows: ServerProviderUsageWindow[] = [];
4047
if (response.planUsage) {
4148
for (const { id, label } of CURSOR_USAGE_WINDOWS) {
@@ -47,6 +54,7 @@ export function cursorUsageResponseToLimits(
4754
label,
4855
usedPercent: clampPercent(usedPercent),
4956
...(resetsAt ? { resetsAt } : {}),
57+
...(windowDurationMins > 0 ? { windowDurationMins } : {}),
5058
});
5159
}
5260
}

0 commit comments

Comments
 (0)