agy-cli 0.1.92: usage shows each group as a pool and lists its models again

tongzhenbao on X: since moving to agy-cli, the usage card shows only three
rings ("Gemini …", "Gemini …", "Claude …"), and they want each model's
usage as before.

Before: the retired antigravity plugin sent one window per model
(fetchAvailableModels' quotaInfo, with family and pool) and the pools
from retrieveUserQuotaSummary, so magpie's card showed the pools
("Gemini 5h", "Gemini 7d", two lines a ring) and "Every model (n)"
listed the models. agy-cli sent only "Gemini · 7 days"-named windows with
no pool and no model, so magpie drew plain rings with the name cut short
and had no models to list.

Google's per-model figure is the pool's: the owner's last antigravity
read (quotas.json, 2026-11-11) gave every Gemini model 1.58104% with the
Gemini pool's 7 days, and every Claude/GPT model 6.7575% with Claude &
GPT's, to the digit. So nothing new is asked of Google; from agy's own
/usage:

- each bucket goes as its pool's window: { pool: "Gemini", name: "7 days" }
  (magpie's LineName is still "Gemini · 7 days", so quota history and a
  cap the user set keep their names);
- each model family a group names (familiesInGroup, from the catalog agy
  models listed) gets an aside window in that pool: its display name
  without the effort word, model = the family id, models = every id of
  it, family Gemini/Claude/GPT-OSS, reading the group's most used
  measured bucket with that bucket's span and reset. A model two groups
  name reads the one that stops it first. A group with no measured bucket
  gives its models no window; no catalog yet gives no model windows.

Every window stays aside, so routing is as before (magpie's allowanceOf
skips aside windows, and a pool's window holds only members that aren't).

Run (mica, mote over 18 load): HOME=$(mktemp -d) bun test in
packages/agy-cli: 41 pass, 0 fail.
Broken by hand: a model reading its group's first bucket instead of the
most used one; "each model family a group names has its own window in
the pool, at the pool's most used bucket" went red (1 fail), green again
restored.
Not tried: a real agy /usage read (the parse is the captured live report
of 11-15 and its agy models rows); magpie's rendering is checked in
magpie's GUI tests with this shape.
This commit is contained in:
yetone
2026-11-18 08:22:40 +08:00
parent 677329db24
commit 207880e1d8
7 changed files with 137 additions and 34 deletions
+48 -5
View File
@@ -3,7 +3,7 @@ import fs from "node:fs/promises"
import os from "node:os"
import path from "node:path"
import { agySpawnSpec, childEnv as agyChildEnv } from "./platform.mjs"
import { modelsInGroup } from "./model-ids.mjs"
import { familiesInGroup } from "./model-ids.mjs"
import { cannotSignIn, isDead, noteDead, storedSignIn, storedToken } from "./signin.mjs"
const DEFAULT_TIMEOUT_MS = 15_000
@@ -161,8 +161,28 @@ function cadence(bucket, id, name) {
return { name: name || id }
}
// vendorOf is a model's family as magpie's cards group them (Gemini,
// Claude, GPT-OSS), as the retired antigravity plugin named them.
function vendorOf(id, name) {
const l = id.toLowerCase()
if (l.startsWith("gemini")) return "Gemini"
if (l.startsWith("claude")) return "Claude"
if (l.startsWith("gpt-oss")) return "GPT-OSS"
return String(name ?? "").trim().split(" ")[0] || id.split("-")[0]
}
// agy's command report is not its token-usage object or a model-availability list.
// Unknown quota is not evidence of exhaustion or a full allowance.
//
// Each group is a pool its models share: its windows go as the pool's
// ({ pool: "Gemini", name: "5 hours" }), and each model family the group
// names gets a window of its own in that pool, reading the pool's most
// used bucket, the one that stops it. That is what Google's own per-model
// reading said: the retired antigravity plugin's fetchAvailableModels
// read of 2026-11-11 gave every model of a pool the pool's figure, to the
// digit (each Gemini model 1.58104% with Gemini's 7 days). So magpie's
// card shows the pools, and "Every model" lists the models, as it did for
// the antigravity plugin.
export function parseUsageReport(value) {
let report
try { report = typeof value === "string" ? JSON.parse(value) : value } catch {
@@ -173,9 +193,13 @@ export function parseUsageReport(value) {
}
const groups = report.command.data?.groups
const windows = []
const models = new Map() // family id -> its window
for (const group of Array.isArray(groups) ? groups : []) {
const pool = (text(field(group, "displayName", "display_name")) || text(group?.name) || "Quota")
.replace(/\s+models$/i, "").replace(/\s+and\s+/gi, " & ")
const families = familiesInGroup(group)
const ids = [...new Set(families.flatMap(f => f.ids))].sort()
let tightest
for (const bucket of Array.isArray(group?.buckets) ? group.buckets : []) {
const id = text(field(bucket, "bucketId", "bucket_id")) || text(bucket?.id)
if (!id || bucket?.disabled === true) continue
@@ -187,15 +211,34 @@ export function parseUsageReport(value) {
?? (remaining?.case === "remainingFraction" ? remaining.value : undefined)
const known = typeof fraction === "number" && Number.isFinite(fraction) && fraction >= 0 && fraction <= 1
const resetsAt = resetTime(field(bucket, "resetTime", "reset_time"))
const ids = modelsInGroup(group)
windows.push({
name: `${pool} · ${period.name}`,
const w = {
name: period.name,
pool,
// This feature displays quota only; it must not change model routing.
aside: true,
...(ids.length ? { models: ids } : {}),
...(known ? { used: Math.round((1 - fraction) * 1e8) / 1e6 } : { display: "Limits not available" }),
...(period.span ? { span: period.span } : {}),
...(resetsAt ? { resetsAt } : {}),
}
windows.push(w)
if (known && (!tightest || w.used > tightest.used)) tightest = w
}
if (!tightest) continue
for (const f of families) {
const had = models.get(f.id)
// a model two groups name reads the one that stops it first
if (had && had.used >= tightest.used) continue
models.set(f.id, {
name: f.name,
model: f.id,
family: vendorOf(f.id, f.name),
pool,
aside: true,
models: f.ids,
used: tightest.used,
...(tightest.span ? { span: tightest.span } : {}),
...(tightest.resetsAt ? { resetsAt: tightest.resetsAt } : {}),
})
}
}
@@ -203,7 +246,7 @@ export function parseUsageReport(value) {
throw new UsageError("Limits not available: agy returned no enabled, measured quota buckets.")
}
// /usage has no verified account or plan identity. Do not borrow one elsewhere.
return { windows }
return { windows: [...[...models.values()].sort((a, b) => a.name.localeCompare(b.name)), ...windows] }
}
function timeout(value) {