diff --git a/packages/commandcode/index.mjs b/packages/commandcode/index.mjs index 23280b6..ef0b2f5 100644 --- a/packages/commandcode/index.mjs +++ b/packages/commandcode/index.mjs @@ -513,7 +513,10 @@ function limits(c) { // allowanceOf makes a credits reply into the plan's windows: the 5-hour // and weekly limits, and the dollars as one more, used of the CLI's pool // (the plan's month of credits, or what is left of it if more, and the -// bought and free ones) as its /usage bar is. A reply with neither windows +// bought and free ones) as its /usage bar is. The dollars, the plan's +// whole allowance, go second, after the 5-hour window: magpie's account +// line and menu bar show an account's first two windows, and with them +// last the Credits bar was never there (01huadalang on Discord). A reply with neither windows // nor a plan tells a balance: a key's money, not an allowance. The month's // credits come back at until, the end of the plan's period // (billing/subscriptions' currentPeriodEnd), when it is known @@ -535,7 +538,7 @@ function allowanceOf(c, until) { } if (known && planMonthly > 0) { const pool = Math.max(planMonthly, monthly) + left - monthly - out.windows.push({ name: "Credits", used: Math.min(100, (100 * (pool - left)) / pool), display: money(pool - left) + " / " + money(pool), ...(until ? { resetsAt: until } : {}) }) + out.windows.splice(1, 0, { name: "Credits", used: Math.min(100, (100 * (pool - left)) / pool), display: money(pool - left) + " / " + money(pool), ...(until ? { resetsAt: until } : {}) }) } else if (known && !out.windows.length) out.balance = money(left) return out } diff --git a/packages/commandcode/package.json b/packages/commandcode/package.json index b03b3c9..2b89445 100644 --- a/packages/commandcode/package.json +++ b/packages/commandcode/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-commandcode-auth", - "version": "0.1.16", + "version": "0.1.17", "description": "Command Code plans (Pro, GOAT, Max, Ultra, Go, Teams) in OpenCode and magpie", "type": "module", "main": "./index.mjs", diff --git a/packages/commandcode/usage.test.mjs b/packages/commandcode/usage.test.mjs index 7c85aeb..a039c75 100644 --- a/packages/commandcode/usage.test.mjs +++ b/packages/commandcode/usage.test.mjs @@ -25,7 +25,7 @@ async function run(a, replies) { return { u: await hooks.auth.usage(async () => a), seen } } -test("a Max account: its 5 hours, its week and its credits, and its period", async () => { +test("a Max account: its 5 hours, its credits second, where magpie shows two windows, its week, and its period", async () => { const reset = Date.now() + 3600_000 const week = Date.now() + 72 * 3600_000 const { u, seen } = await run(api, { @@ -42,8 +42,8 @@ test("a Max account: its 5 hours, its week and its credits, and its period", asy renew: "off", windows: [ { name: "5 hours", used: 25, span: 18000, resetsAt: new Date(reset).toISOString() }, - { name: "Weekly", used: 10, span: 604800, resetsAt: new Date(week).toISOString() }, { name: "Credits", used: 30.9375, display: "$49.50 / $160.00", resetsAt: "2026-10-28T00:00:00.000Z" }, + { name: "Weekly", used: 10, span: 604800, resetsAt: new Date(week).toISOString() }, ], }) expect(seen.every((x) => x.auth === "Bearer own-key")).toBe(true)