commandcode 0.1.17: the Credits window comes second, so magpie's account line and menu bar show the plan's dollars (01huadalang on Discord)

01huadalang: "command 的订阅插件没有显示总额度剩余的条子". A Pro, GOAT,
Max or Ultra account reports 5 hours, Weekly and then Credits. magpie's
Providers account line (quotaLine) and the menu bar (trayusage) show an
account's first two windows only, so the Credits bar, the plan's whole
allowance, was never drawn there; it sat in the tooltip. allowanceOf now
puts Credits right after the first window: 5 hours, Credits, Weekly. The
5-hour window stays first, so the Usage card's spark and pace line are
unchanged; Weekly moves to the account line's tooltip. Accounts with one
limit window (Weekly, Credits) or none (Go: Credits alone) are as before.

Not this change: #303 (amount/limit on the Credits window) is held, as
reviewed on it: on every released magpie a window with a limit is
printed as "17.89 / 70" with no "$" in both modes, until magpie formats
a unit "usd" window as money (#301 step 1, not landed).

Run (HOME a temp dir without "magpie" in its path; no-magpie.test.mjs
greps every request for the word and finds the HOME in the Go body
otherwise):
- packages/commandcode bun test: 65 pass, 0 fail.
- bun run check: exit 0, every package.
- Old code: usage.test.mjs's "a Max account: its 5 hours, its credits
  second ..." fails on origin/main's index.mjs (12 pass, 1 fail: Weekly
  where Credits is expected).
- Real account: the owner's GOAT key through hooks.auth.usage now gives
  [5 hours 0.93%, Credits $0.63 / $70.00, Weekly 1.20%] (before: 5 hours,
  Weekly, Credits).
Not tried: a Go, Pro, Max or Ultra account (none here).
This commit is contained in:
yetone
2026-10-25 18:56:03 +08:00
parent 564719b9d9
commit 8531ccc532
3 changed files with 8 additions and 5 deletions
+5 -2
View File
@@ -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
}
+1 -1
View File
@@ -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",
+2 -2
View File
@@ -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)