Skip to content

Commit a365898

Browse files
committed
feat(usage): show one weekly limit for a merged X subscription
GetPlanInfo.isMerged marks Cursor Models as the shared weekly window. Limits hides that window when Grok reports the same email. Token history stays split. A failed plan read keeps the monthly cards.
1 parent 3a8c250 commit a365898

5 files changed

Lines changed: 315 additions & 11 deletions

File tree

‎docs/user/usage.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ your Go API key as `OPENCODE_API_KEY` in the OpenCode instance's **Environment v
158158
refresh provider status. Cursor reports
159159
its monthly allowance, including separate Auto and API usage, for `CURSOR_AUTH_TOKEN` when it is set,
160160
otherwise for the account you signed in with in T3 or set as `CURSOR_API_KEY`.
161+
On a merged X Subscription, Cursor Models is that shared weekly limit. When Grok is signed in with
162+
the same email, Limits keeps the Grok card and hides Cursor Models. Other models stay on their own
163+
Cursor card. An unmerged Cursor plan still shows the monthly allowance.
161164
Sign-in and API keys report limits only with Cursor's default API endpoint. If you configure a custom
162165
Cursor endpoint, use an explicit `CURSOR_AUTH_TOKEN` for limits.
163166

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

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ describe("Cursor usage limits", () => {
136136
"https://api2.cursor.sh/aiserver.v1.DashboardService/GetCurrentPeriodUsage",
137137
"Bearer api-key-access-token",
138138
],
139+
[
140+
"https://api2.cursor.sh/aiserver.v1.DashboardService/GetPlanInfo",
141+
"Bearer api-key-access-token",
142+
],
139143
]);
140144
expect(limits.windows[0]?.usedPercent).toBe(37);
141145
}),
@@ -160,4 +164,114 @@ describe("Cursor usage limits", () => {
160164
}
161165
}),
162166
);
167+
168+
it("reports a merged plan as a weekly Cursor Models window and omits Overall", () => {
169+
const limits = cursorUsageResponseToLimits(
170+
{
171+
billingCycleEnd: "1789876386000",
172+
planUsage: { totalPercentUsed: 100, autoPercentUsed: 80, apiPercentUsed: 15 },
173+
},
174+
checkedAt,
175+
true,
176+
);
177+
expect(limits.windows).toEqual([
178+
{
179+
id: "autoPercentUsed",
180+
kind: "weekly",
181+
label: "Cursor Models",
182+
usedPercent: 80,
183+
resetsAt: "2026-09-20T03:53:06.000Z",
184+
},
185+
{
186+
id: "apiPercentUsed",
187+
kind: "monthly",
188+
label: "Other Models",
189+
usedPercent: 15,
190+
resetsAt: "2026-09-20T03:53:06.000Z",
191+
},
192+
]);
193+
expect(
194+
cursorUsageResponseToLimits(
195+
{ planUsage: { autoPercentUsed: 100, totalPercentUsed: 100 } },
196+
checkedAt,
197+
true,
198+
).windows,
199+
).toEqual([
200+
{ id: "autoPercentUsed", kind: "weekly", label: "Cursor Models", usedPercent: 100 },
201+
]);
202+
});
203+
204+
it.effect("keeps monthly cards when GetPlanInfo fails", () =>
205+
Effect.gen(function* () {
206+
const requests: string[] = [];
207+
const limits = yield* readCursorUsageLimits(
208+
{ apiEndpoint: "" },
209+
{ CURSOR_AUTH_TOKEN: "explicit-token" },
210+
).pipe(
211+
Effect.provideService(
212+
HttpClient.HttpClient,
213+
HttpClient.make((request) => {
214+
requests.push(request.url);
215+
return Effect.succeed(
216+
HttpClientResponse.fromWeb(
217+
request,
218+
request.url.endsWith("/GetPlanInfo")
219+
? new Response("no plan", { status: 500 })
220+
: Response.json({
221+
planUsage: { totalPercentUsed: 10, autoPercentUsed: 4, apiPercentUsed: 6 },
222+
}),
223+
),
224+
);
225+
}),
226+
),
227+
);
228+
expect(requests).toEqual([
229+
"https://api2.cursor.sh/aiserver.v1.DashboardService/GetCurrentPeriodUsage",
230+
"https://api2.cursor.sh/aiserver.v1.DashboardService/GetPlanInfo",
231+
]);
232+
expect(limits.windows).toEqual(
233+
expect.arrayContaining([
234+
expect.objectContaining({ id: "totalPercentUsed", kind: "monthly", usedPercent: 10 }),
235+
expect.objectContaining({ id: "autoPercentUsed", kind: "monthly", usedPercent: 4 }),
236+
expect.objectContaining({ id: "apiPercentUsed", kind: "monthly", usedPercent: 6 }),
237+
]),
238+
);
239+
expect(limits.windows).toHaveLength(3);
240+
}),
241+
);
242+
243+
it.effect("reads isMerged from GetPlanInfo", () =>
244+
Effect.gen(function* () {
245+
const limits = yield* readCursorUsageLimits(
246+
{ apiEndpoint: "" },
247+
{ CURSOR_AUTH_TOKEN: "explicit-token" },
248+
).pipe(
249+
Effect.provideService(
250+
HttpClient.HttpClient,
251+
HttpClient.make((request) =>
252+
Effect.succeed(
253+
HttpClientResponse.fromWeb(
254+
request,
255+
Response.json(
256+
request.url.endsWith("/GetPlanInfo")
257+
? { isMerged: true }
258+
: {
259+
planUsage: {
260+
totalPercentUsed: 100,
261+
autoPercentUsed: 80,
262+
apiPercentUsed: 15,
263+
},
264+
},
265+
),
266+
),
267+
),
268+
),
269+
),
270+
);
271+
expect(limits.windows.map((window) => [window.id, window.kind])).toEqual([
272+
["autoPercentUsed", "weekly"],
273+
["apiPercentUsed", "monthly"],
274+
]);
275+
}),
276+
);
163277
});

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

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,26 @@ const CursorUsageResponse = Schema.Struct({
2626
),
2727
});
2828

29+
const CursorPlanInfoResponse = Schema.Struct({
30+
isMerged: Schema.optional(Schema.Boolean),
31+
});
32+
33+
function cursorDashboardPost(url: string, token: string) {
34+
return HttpClientRequest.post(url).pipe(
35+
HttpClientRequest.bearerToken(token),
36+
HttpClientRequest.setHeaders({
37+
"connect-protocol-version": "1",
38+
"x-cursor-client-type": "cli",
39+
}),
40+
HttpClientRequest.bodyJsonUnsafe({}),
41+
);
42+
}
43+
2944
/** Cursor's dashboard percentages include bonus usage; spend / limit does not. */
3045
export function cursorUsageResponseToLimits(
3146
response: typeof CursorUsageResponse.Type,
3247
checkedAt: string,
48+
isMerged = false,
3349
) {
3450
const reset = DateTime.make(Number(response.billingCycleEnd));
3551
const resetsAt =
@@ -39,11 +55,12 @@ export function cursorUsageResponseToLimits(
3955
const windows: ServerProviderUsageWindow[] = [];
4056
if (response.planUsage) {
4157
for (const { id, label } of CURSOR_USAGE_WINDOWS) {
58+
if (isMerged && id === "totalPercentUsed") continue;
4259
const usedPercent = response.planUsage[id];
4360
if (usedPercent === undefined || !Number.isFinite(usedPercent)) continue;
4461
windows.push({
4562
id,
46-
kind: "monthly",
63+
kind: isMerged && id === "autoPercentUsed" ? "weekly" : "monthly",
4764
label,
4865
usedPercent: clampPercent(usedPercent),
4966
...(resetsAt ? { resetsAt } : {}),
@@ -81,19 +98,24 @@ export const readCursorUsageLimits = Effect.fn("readCursorUsageLimits")(function
8198
if (!token) return makeUnavailableUsageLimits({ checkedAt, reason: "unsupported" });
8299
const client = yield* HttpClient.HttpClient;
83100
const response = yield* client.execute(
84-
HttpClientRequest.post(`${endpoint}/aiserver.v1.DashboardService/GetCurrentPeriodUsage`).pipe(
85-
HttpClientRequest.bearerToken(token),
86-
HttpClientRequest.setHeaders({
87-
"connect-protocol-version": "1",
88-
"x-cursor-client-type": "cli",
89-
}),
90-
HttpClientRequest.bodyJsonUnsafe({}),
91-
),
101+
cursorDashboardPost(`${endpoint}/aiserver.v1.DashboardService/GetCurrentPeriodUsage`, token),
92102
);
93103
const body = yield* HttpClientResponse.schemaBodyJson(CursorUsageResponse)(
94104
yield* HttpClientResponse.filterStatusOk(response),
95105
);
96-
return cursorUsageResponseToLimits(body, checkedAt);
106+
const isMerged = yield* Effect.gen(function* () {
107+
const plan = yield* client.execute(
108+
cursorDashboardPost(`${endpoint}/aiserver.v1.DashboardService/GetPlanInfo`, token),
109+
);
110+
const info = yield* HttpClientResponse.schemaBodyJson(CursorPlanInfoResponse)(
111+
yield* HttpClientResponse.filterStatusOk(plan),
112+
);
113+
return info.isMerged === true;
114+
}).pipe(
115+
Effect.timeout("3 seconds"),
116+
Effect.orElseSucceed(() => false),
117+
);
118+
return cursorUsageResponseToLimits(body, checkedAt, isMerged);
97119
}).pipe(
98120
Effect.timeout("10 seconds"),
99121
Effect.orElseSucceed(() =>

‎packages/shared/src/usageLimits.test.ts‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,3 +1556,129 @@ describe("ChatGPT sharing presentation", () => {
15561556
).toBe(false);
15571557
});
15581558
});
1559+
1560+
describe("merged X subscription limits", () => {
1561+
const checkedAt = "2026-09-03T11:00:00.000Z";
1562+
const card = (
1563+
driver: "cursor" | "grok",
1564+
email: string | undefined,
1565+
windows: LimitAccount["limits"]["windows"],
1566+
): LimitAccount => ({
1567+
key: `${driver}:${email ?? "none"}`,
1568+
driver: ProviderDriverKind.make(driver),
1569+
displayName: null,
1570+
email,
1571+
plan: undefined,
1572+
accentColor: undefined,
1573+
environments: [],
1574+
sourceLabel: null,
1575+
redeem: null,
1576+
limits: { checkedAt, windows },
1577+
});
1578+
const grokWeekly = (email: string, usedPercent: number) =>
1579+
card("grok", email, [
1580+
{
1581+
id: "subscription",
1582+
kind: "weekly",
1583+
label: "Weekly",
1584+
usedPercent,
1585+
resetsAt: "2026-09-08T00:00:00.000Z",
1586+
},
1587+
]);
1588+
const cursorMerged = (email: string, withOtherModels = true) =>
1589+
card(
1590+
"cursor",
1591+
email,
1592+
withOtherModels
1593+
? [
1594+
{ id: "autoPercentUsed", kind: "weekly", label: "Cursor Models", usedPercent: 90 },
1595+
{ id: "apiPercentUsed", kind: "monthly", label: "Other Models", usedPercent: 12 },
1596+
]
1597+
: [{ id: "autoPercentUsed", kind: "weekly", label: "Cursor Models", usedPercent: 90 }],
1598+
);
1599+
1600+
it("keeps one first-party card and Other Models for the same email", () => {
1601+
const accounts = [cursorMerged(" [email protected] "), grokWeekly("[email protected]", 40)];
1602+
const cursorWindows = accounts[0]?.limits.windows;
1603+
const snapshot = structuredClone(accounts);
1604+
const pools = collectLimitPools(accounts, now);
1605+
expect(accounts).toEqual(snapshot);
1606+
expect(accounts[0]?.limits.windows).toBe(cursorWindows);
1607+
const cursor = pools.find((pool) => pool.driver === "cursor");
1608+
const grok = pools.find((pool) => pool.driver === "grok");
1609+
expect(cursor?.windows.map((window) => [window.id, window.usedPercent])).toEqual([
1610+
["apiPercentUsed", 12],
1611+
]);
1612+
expect(
1613+
grok?.windows.map((window) => [window.id, window.usedPercent, window.remainingPercent]),
1614+
).toEqual([["subscription", 40, 60]]);
1615+
});
1616+
1617+
it("drops the Cursor section when the merged account has no other models", () => {
1618+
const pools = collectLimitPools(
1619+
[cursorMerged("[email protected]", false), grokWeekly("[email protected]", 40)],
1620+
now,
1621+
);
1622+
expect(pools.map((pool) => pool.driver)).toEqual(["grok"]);
1623+
});
1624+
1625+
it("keeps both first-party cards for different emails", () => {
1626+
const pools = collectLimitPools(
1627+
[cursorMerged("[email protected]"), grokWeekly("[email protected]", 40)],
1628+
now,
1629+
);
1630+
expect(
1631+
pools.find((pool) => pool.driver === "cursor")?.windows.map((window) => window.id),
1632+
).toEqual(["autoPercentUsed", "apiPercentUsed"]);
1633+
expect(pools.find((pool) => pool.driver === "grok")?.windows[0]?.usedPercent).toBe(40);
1634+
});
1635+
1636+
it("keeps a monthly Cursor card beside a weekly Grok card", () => {
1637+
const pools = collectLimitPools(
1638+
[
1639+
card("cursor", "[email protected]", [
1640+
{ id: "autoPercentUsed", kind: "monthly", label: "Cursor Models", usedPercent: 90 },
1641+
{ id: "apiPercentUsed", kind: "monthly", label: "Other Models", usedPercent: 12 },
1642+
]),
1643+
grokWeekly("[email protected]", 40),
1644+
],
1645+
now,
1646+
);
1647+
expect(
1648+
pools.find((pool) => pool.driver === "cursor")?.windows.map((window) => window.id),
1649+
).toEqual(["autoPercentUsed", "apiPercentUsed"]);
1650+
expect(pools.find((pool) => pool.driver === "grok")?.windows[0]?.id).toBe("subscription");
1651+
});
1652+
1653+
it("does not join a merged Cursor card with a monthly Grok period", () => {
1654+
const pools = collectLimitPools(
1655+
[
1656+
cursorMerged("[email protected]"),
1657+
card("grok", "[email protected]", [
1658+
{ id: "subscription", kind: "monthly", label: "Monthly", usedPercent: 40 },
1659+
]),
1660+
],
1661+
now,
1662+
);
1663+
expect(
1664+
pools.find((pool) => pool.driver === "cursor")?.windows.map((window) => window.id),
1665+
).toEqual(["autoPercentUsed", "apiPercentUsed"]);
1666+
expect(pools.find((pool) => pool.driver === "grok")?.windows[0]?.kind).toBe("monthly");
1667+
});
1668+
1669+
it("shows a merged Cursor plan on its own when Grok is signed out", () => {
1670+
const [pool] = collectLimitPools([cursorMerged("[email protected]")], now);
1671+
expect(pool?.driver).toBe("cursor");
1672+
expect(pool?.windows.map((window) => [window.id, window.kind])).toEqual([
1673+
["autoPercentUsed", "weekly"],
1674+
["apiPercentUsed", "monthly"],
1675+
]);
1676+
});
1677+
1678+
it("leaves a Grok-only weekly card unchanged", () => {
1679+
const [pool] = collectLimitPools([grokWeekly("[email protected]", 40)], now);
1680+
expect(pool?.windows.map((window) => [window.id, window.usedPercent])).toEqual([
1681+
["subscription", 40],
1682+
]);
1683+
});
1684+
});

‎packages/shared/src/usageLimits.ts‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,51 @@ const WINDOW_KIND_ORDER: Record<ServerProviderUsageWindow["kind"], number> = {
470470
other: 3,
471471
};
472472

473+
function weeklyGrokEmail(account: LimitAccount): string | null {
474+
if (account.driver !== "grok") return null;
475+
const email = account.email?.trim().toLowerCase();
476+
if (!email) return null;
477+
return account.limits.windows.some(
478+
(window) => window.id === "subscription" && window.kind === "weekly",
479+
)
480+
? email
481+
: null;
482+
}
483+
484+
function dropCursorAutoCoveredByGrok(accounts: readonly LimitAccount[]): readonly LimitAccount[] {
485+
const grokEmails = new Set<string>();
486+
for (const account of accounts) {
487+
const email = weeklyGrokEmail(account);
488+
if (email) grokEmails.add(email);
489+
}
490+
if (grokEmails.size === 0) return accounts;
491+
const visible: LimitAccount[] = [];
492+
for (const account of accounts) {
493+
const email = account.email?.trim().toLowerCase();
494+
if (account.driver !== "cursor" || !email || !grokEmails.has(email)) {
495+
visible.push(account);
496+
continue;
497+
}
498+
const windows = account.limits.windows.filter(
499+
(window) => window.id !== "autoPercentUsed" || window.kind !== "weekly",
500+
);
501+
if (windows.length === account.limits.windows.length) {
502+
visible.push(account);
503+
continue;
504+
}
505+
if (windows.length === 0) continue;
506+
visible.push({ ...account, limits: { ...account.limits, windows } });
507+
}
508+
return visible;
509+
}
510+
473511
export function collectLimitPools(
474512
accounts: readonly LimitAccount[],
475513
now: number,
476514
): readonly LimitPool[] {
515+
const visibleAccounts = dropCursorAutoCoveredByGrok(accounts);
477516
const byDriver = new Map<ServerProvider["driver"], LimitAccount[]>();
478-
for (const account of accounts) {
517+
for (const account of visibleAccounts) {
479518
const list = byDriver.get(account.driver);
480519
if (list) list.push(account);
481520
else byDriver.set(account.driver, [account]);

0 commit comments

Comments
 (0)