kiro 0.1.17: credits tell their count, so magpie's "Left" shows what is left (#408)

Fidelxyz switched magpie's usage to "Left" and Kiro's credits still read
as used ("12.5 / 50"). magpie turns a window round only from its count
(amount, limit, unit; quotaCount in app.js): display alone is the
vendor's text, shown as it is. usageOf now gives each Credits and Free
trial window amount = currentUsageWithPrecision, limit =
usageLimitWithPrecision and unit "credits"; display is unchanged.

Run: HOME=$(mktemp -d) bun test in packages/kiro: 57 pass 0 fail. On the
old index.mjs the two usage tests fail (amount/limit/unit missing).
bun scripts/check.mjs: kiro ok.
Not tried: a real Kiro account (no vendor credentials used); the window
shape is the one workbuddy's Credits already shows "left" with.
This commit is contained in:
yetone
2026-10-26 15:50:26 +08:00
parent f32736f015
commit 634a865346
3 changed files with 14 additions and 6 deletions
+7 -3
View File
@@ -414,7 +414,10 @@ function goG(x) {
// usageOf is the allowance Get-Usage-Limits tells, as magpie's built-in
// said it: the account's email, the credits of each allowance, the month's and a free trial's
// while it runs.
// while it runs. Each window carries its count (amount, limit, unit), so
// magpie can say what is left of it when the user shows what is left
// (#408): display alone is the vendor's text, which magpie can't turn
// round.
function usageOf(l) {
const at = (secs) => (secs > 0 ? new Date(Math.trunc(secs) * 1000).toISOString() : undefined)
const count = (used, limit) => used.toFixed(2).replace(/0+$/, "").replace(/\.$/, "") + " / " + goG(limit)
@@ -424,13 +427,14 @@ function usageOf(l) {
const t = u?.freeTrialInfo
if (t && String(t.freeTrialStatus ?? "").toUpperCase() === "ACTIVE" && num(t.usageLimitWithPrecision) > 0) {
const used = num(t.currentUsageWithPrecision), limit = num(t.usageLimitWithPrecision)
windows.push({ name: "Free trial", used: (100 * used) / limit, resetsAt: at(num(t.freeTrialExpiry)), display: count(used, limit) })
windows.push({ name: "Free trial", used: (100 * used) / limit, resetsAt: at(num(t.freeTrialExpiry)), display: count(used, limit),
amount: used, limit, unit: "credits" })
}
const used = num(u?.currentUsageWithPrecision), limit = num(u?.usageLimitWithPrecision)
if (limit <= 0) continue
const reset = num(u?.nextDateReset) || num(l?.nextDateReset)
windows.push({ name: u?.displayNamePlural || u?.displayName || "Credits", used: (100 * used) / limit, resetsAt: at(reset),
display: count(used, limit), span: 30 * 24 * 3600 })
display: count(used, limit), amount: used, limit, unit: "credits", span: 30 * 24 * 3600 })
}
const email = l?.userInfo?.email
return { plan: planName(l?.subscriptionInfo?.subscriptionTitle), ...(typeof email === "string" && email ? { user: email } : {}), windows }
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-kiro-auth",
"version": "0.1.16",
"version": "0.1.17",
"description": "Kiro subscriptions (Free, Pro, Pro+, Power) in OpenCode and magpie",
"type": "module",
"main": "./index.mjs",
+6 -2
View File
@@ -45,8 +45,10 @@ test("a free account's credits and trial", async () => {
plan: "Kiro Free",
user: "me@example.com",
windows: [
{ name: "Free trial", used: 20, resetsAt: new Date(1791000000_000).toISOString(), display: "100 / 500" },
{ name: "Credits", used: 25, resetsAt: new Date(1790000000_000).toISOString(), display: "12.5 / 50", span: 30 * 24 * 3600 },
{ name: "Free trial", used: 20, resetsAt: new Date(1791000000_000).toISOString(), display: "100 / 500",
amount: 100, limit: 500, unit: "credits" },
{ name: "Credits", used: 25, resetsAt: new Date(1790000000_000).toISOString(), display: "12.5 / 50",
amount: 12.5, limit: 50, unit: "credits", span: 30 * 24 * 3600 },
],
signIn: "kept",
})
@@ -70,6 +72,8 @@ test("names, resets and counts as Go says them", () => {
["Credits", "150.1 / 100", new Date(1800000000_000).toISOString()],
])
expect(windows[1].used).toBeCloseTo(150.1) // the host clamps it to 100; Go's built-in didn't
// #408: the count goes along, so magpie's "left" shows 0 / 100, not the used text
expect(windows.map((w) => [w.amount, w.limit, w.unit])).toEqual([[1.005, 1000000, "credits"], [150.1, 100, "credits"]])
})
test("Kiro's refusal is the card's error", async () => {