From a885a161900b525dea0f543f5a5773feb682bb59 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 13 Oct 2026 06:00:37 +0800 Subject: [PATCH] cursor 0.2.10: a Team member with no limit of their own spends the team's on-demand pool, which is shown and counted as the limit, not as unlimited (yetone/magpie#1868) PaSSw0rds' Team account has on-demand turned on for the whole organization: spendLimitUsage has no individualLimit, pooledLimit "45120000" and pooledRemaining "38785730" are int64 strings, pooledUsed 6334270 a number, and GetHardLimit answers {"hardLimit": 451200} with or without a team id. onDemandOf read that as "unlimited", as cursor-agent's own usage view does, so the On-demand row showed only the member's own $198.55 at 0%, and a spent team pool never counted the account used up. Now a team member with no individualLimit and a pooledLimit > 0 gets a fixed On-demand window on the pool: used = pooledUsed / pooledLimit, display "$63,342.70 / $451,200.00 (you: $198.55)", not aside, so magpie stops routing to it when the pool is spent. A hard limit that forbids on-demand still reads as disabled; a team with no pool and a hard limit still reads as unlimited. Dollar figures group thousands. Run: bun test in packages/cursor (86 pass), bun scripts/check.mjs (exit 0). The new test, built from the payloads quoted in yetone/magpie#1476, fails on the old index.mjs (On-demand "$198.55", used 0, aside) and on a fix that shows the member's spend against the pool instead of the pool's own. Not tried against a real Team account. --- packages/cursor/README.md | 5 ++++- packages/cursor/index.mjs | 20 +++++++++++------ packages/cursor/package.json | 2 +- packages/cursor/usage.test.mjs | 39 ++++++++++++++++++++++++---------- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/packages/cursor/README.md b/packages/cursor/README.md index 487dbc1..129a32d 100644 --- a/packages/cursor/README.md +++ b/packages/cursor/README.md @@ -140,7 +140,10 @@ team or personal spend limit, as `cursor-agent`'s usage view shows it) also shows On-demand: its spend, and its limit when it has one. Cursor keeps serving such an account past the included usage, so magpie doesn't count it used up when Cursor Models or Other Models reach 100%; it does when the -on-demand spend reaches its limit. +on-demand spend reaches its limit. A team member with no limit of their +own spends the team's pool: On-demand shows the pool's spend and limit, +with the member's own spend beside it, and the account is used up when +the pool is. Sign in to the Cursor account linked in Grok Bot. A linked SuperGrok subscription grants Bot access without a paid Cursor plan; see diff --git a/packages/cursor/index.mjs b/packages/cursor/index.mjs index 85917cf..64c8bd7 100644 --- a/packages/cursor/index.mjs +++ b/packages/cursor/index.mjs @@ -385,7 +385,10 @@ function firstParty(model) { // period's spendLimitUsage (cents) and, where that sets no limit of the // user's, GetHardLimit's reply (dollars; undefined when it couldn't be // read). kind is "fixed" (up to limitDollars), "unlimited", "disabled" or -// "unavailable" (not known). +// "unavailable" (not known). A team member with no limit of their own +// spends the team's pool, which cursor-agent's view calls unlimited but +// which runs out at pooledLimit for the whole team (magpie #1868): that is +// a fixed limit on the pool's spend, with the member's own in mineDollars. function onDemandOf(data, hard) { const s = data?.spendLimitUsage const usedDollars = Number(s?.individualUsed ?? 0) / 100 @@ -397,8 +400,11 @@ function onDemandOf(data, hard) { : { kind: "disabled", usedDollars } if (s?.limitType === "team") { if (own) return own - if (hard) return hard.noUsageBasedAllowed || !(Number(hard.hardLimit) > 0) ? { kind: "disabled", usedDollars } : { kind: "unlimited", usedDollars } - return Number(s.pooledLimit ?? 0) > 0 ? { kind: "unlimited", usedDollars } : { kind: "unavailable", usedDollars } + if (hard && (hard.noUsageBasedAllowed || !(Number(hard.hardLimit) > 0))) return { kind: "disabled", usedDollars } + // pooledLimit and pooledRemaining come as int64 strings, pooledUsed as a number + const pool = Number(s.pooledLimit ?? 0) + if (pool > 0) return { kind: "fixed", usedDollars: Number(s.pooledUsed ?? 0) / 100, limitDollars: pool / 100, mineDollars: usedDollars } + return hard ? { kind: "unlimited", usedDollars } : { kind: "unavailable", usedDollars } } if (!hard) return own ?? { kind: "unavailable", usedDollars } if (hard.noUsageBasedAllowed) return { kind: "disabled", usedDollars } @@ -422,7 +428,8 @@ async function hardLimit(tok) { } } -const dollars = (n) => "$" + n.toFixed(2) +// dollars, thousands grouped: a team's pool runs to six figures ($451,200.00) +const dollars = (n) => "$" + n.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 }) // usage is the account's windows this billing period; an enterprise plan // reports spend instead, and gets none. ids are the models it can be @@ -430,7 +437,8 @@ const dollars = (n) => "$" + n.toFixed(2) // may spend on-demand once its included usage is gone (fottencity on // Discord: a team that pays for more) is still served when the pools are // spent, so they are shown aside, and its On-demand spend is what can run -// out: at its limit, or never when it has none. +// out: at its limit (a team member with none of their own: the team's +// pool), or never when it has none. async function usage(tok, ids) { const [res, hard] = await Promise.all([ fetch(API + "/aiserver.v1.DashboardService/GetCurrentPeriodUsage", { @@ -467,7 +475,7 @@ async function usage(tok, ids) { const pooled = od.kind === "fixed" || od.kind === "unlimited" ? { aside: true } : {} const onDemand = od.kind === "fixed" - ? [{ name: "On-demand", used: Math.max(0, Math.min(100, (100 * od.usedDollars) / od.limitDollars)), display: `${dollars(od.usedDollars)} / ${dollars(od.limitDollars)}`, ...resets }] + ? [{ name: "On-demand", used: Math.max(0, Math.min(100, (100 * od.usedDollars) / od.limitDollars)), display: `${dollars(od.usedDollars)} / ${dollars(od.limitDollars)}` + (od.mineDollars === undefined ? "" : ` (you: ${dollars(od.mineDollars)})`), ...resets }] : od.kind === "unlimited" ? [{ name: "On-demand", used: 0, display: dollars(od.usedDollars), ...resets, aside: true }] : [] diff --git a/packages/cursor/package.json b/packages/cursor/package.json index d8b35b0..2928d9e 100644 --- a/packages/cursor/package.json +++ b/packages/cursor/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-cursor-auth", - "version": "0.2.9", + "version": "0.2.10", "description": "Cursor subscriptions (Pro, Pro+, Ultra, Teams) in OpenCode and magpie, through the API cursor-agent talks to", "type": "module", "main": "./index.mjs", diff --git a/packages/cursor/usage.test.mjs b/packages/cursor/usage.test.mjs index 4d73b7c..78f0cda 100644 --- a/packages/cursor/usage.test.mjs +++ b/packages/cursor/usage.test.mjs @@ -246,18 +246,35 @@ test("a team member's own on-demand limit: the spent pools are aside, the on-dem expect(seen.find((r) => r.url === HARD)).toEqual({ ...period, url: HARD }) }) -test("a team with no limit of the member's but a team hard limit: on-demand without end, every window aside", async () => { - for (const period of [ - { ...spent, spendLimitUsage: { individualUsed: 900, limitType: "team" } }, - { ...spent, spendLimitUsage: { individualUsed: 900, limitType: "team", pooledLimit: "100000" } }, - ]) { - const { u } = await onDemand(period, { hardLimit: 2000, perUserMonthlyLimitDollars: 0 }) - expect(u.windows.every((w) => w.aside)).toBe(true) - expect(shape(u)[2]).toEqual({ name: "On-demand", used: 0, display: "$9.00", resetsAt: at, aside: true }) - } - // GetHardLimit unread: the team's pooled limit says it is allowed - const { u } = await onDemand({ ...spent, spendLimitUsage: { individualUsed: 900, limitType: "team", pooledLimit: "100000" } }, new Response("no", { status: 500 })) +test("a team with no limit of the member's, a team hard limit and no pool: on-demand without end, every window aside", async () => { + const { u } = await onDemand({ ...spent, spendLimitUsage: { individualUsed: 900, limitType: "team" } }, { hardLimit: 2000, perUserMonthlyLimitDollars: 0 }) expect(u.windows.every((w) => w.aside)).toBe(true) + expect(shape(u)[2]).toEqual({ name: "On-demand", used: 0, display: "$9.00", resetsAt: at, aside: true }) +}) + +// magpie #1868 (PaSSw0rds, a real Team account whose on-demand is turned on +// for the whole organization): spendLimitUsage has no individualLimit at +// all, the pool's limit and remainder are int64 strings and its spend a +// number, and GetHardLimit answers the pool's limit in dollars with or +// without a team id. The pool is what runs out, for the whole team. +const teamPool = { totalSpend: 6334270, pooledLimit: "45120000", pooledUsed: 6334270, pooledRemaining: "38785730", individualUsed: 19855, limitType: "team" } +test("a team's org-wide on-demand pool is the allowance: its spend is shown, and the account is used up when it is", async () => { + const period = { ...spent, planUsage: { totalSpend: 16151, includedSpend: 2000, bonusSpend: 14151, limit: 2000, autoPercentUsed: 57.81428571428572, apiPercentUsed: 100, totalPercentUsed: 64.604 }, spendLimitUsage: teamPool } + for (const hard of [{ hardLimit: 451200 }, { hardLimit: 451200, isDynamicTeamLimit: true }, new Response("no", { status: 500 })]) { + const { u } = await onDemand(period, hard) + expect(shape(u)).toEqual([ + { name: "Cursor Models", used: 57.81428571428572, resetsAt: at, aside: true }, + { name: "Other Models", used: 100, resetsAt: at, aside: true }, + { name: "On-demand", used: (100 * 6334270) / 45120000, display: "$63,342.70 / $451,200.00 (you: $198.55)", resetsAt: at }, + { name: "Total", used: 64.604, resetsAt: at, aside: true }, + ]) + } + // the pool spent: the account is used up, though the member spent little of it + const out = (await onDemand({ ...spent, spendLimitUsage: { ...teamPool, pooledUsed: 45120000, pooledRemaining: "0" } }, { hardLimit: 451200 })).u + expect(shape(out)[2]).toEqual({ name: "On-demand", used: 100, display: "$451,200.00 / $451,200.00 (you: $198.55)", resetsAt: at }) + // nothing spent from the pool yet: Connect JSON leaves pooledUsed out + const none = (await onDemand({ ...spent, spendLimitUsage: { individualUsed: 900, limitType: "team", pooledLimit: "100000" } }, new Response("no", { status: 500 }))).u + expect(shape(none)[2]).toEqual({ name: "On-demand", used: 0, display: "$0.00 / $1,000.00 (you: $9.00)", resetsAt: at }) }) test("a personal plan's hard limit is its on-demand limit; the top int32 is none", async () => {