From f4c2f2fb2bec6d4205c9d8ef56697ea40fe376bc Mon Sep 17 00:00:00 2001 From: Ruining Yang <111631455+ArmedHelicopter@users.noreply.github.com> Date: Sun, 15 Nov 2026 04:31:27 -0800 Subject: [PATCH] agy-cli 0.1.65: usage windows name the model ids they cover (#1180) A usage window from `agy usage` now carries the model ids it covers, taken from the catalog `agy models` listed: each display name in the group's "Models within this group:" line (or the group's own name) maps to the family id and every effort variant the catalog serves. With no catalog yet, or a name the catalog doesn't have, a window has no ids. The windows stay aside, so routing is unchanged; agy-cli 0.1.65. Run at 8acf7ffb5 on macOS (mote), CI-style with a temp HOME: bun test packages/agy-cli, 35 pass, 0 fail; bun scripts/check.mjs agy-cli passes. Not tried: a real agy account (the local one answers 403). Co-authored-by: Ruining Yang --- packages/agy-cli/index.mjs | 7 +++ packages/agy-cli/model-ids.mjs | 89 +++++++++++++++++++++++++++ packages/agy-cli/package.json | 3 +- packages/agy-cli/test/testkit.mjs | 3 + packages/agy-cli/test/usage.mjs | 99 ++++++++++++++++++++++++++++++- packages/agy-cli/usage.mjs | 3 + 6 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 packages/agy-cli/model-ids.mjs diff --git a/packages/agy-cli/index.mjs b/packages/agy-cli/index.mjs index 6250ff3..acca8fa 100644 --- a/packages/agy-cli/index.mjs +++ b/packages/agy-cli/index.mjs @@ -8,6 +8,7 @@ import os from "node:os" import path from "node:path" import { fileURLToPath } from "node:url" import { createUsageReader } from "./usage.mjs" +import { storeCatalogRows } from "./model-ids.mjs" import { backgroundBlocked, cannotSignIn, forgetStoredSignIn, storedEmail, storedSignInNow } from "./signin.mjs" import { sanitizePatternFields } from "./re2-pattern.mjs" import { startLogin } from "./login.mjs" @@ -620,6 +621,8 @@ function buildModelCatalog(list) { } function fallbackModelCatalog(agyPath = null) { + // The usage reader names ids on its windows from the catalog being served. + storeCatalogRows(FALLBACK_MODELS) return { agyPath, list: FALLBACK_MODELS, catalog: null, offeredKey: null, isFallback: true, fetchedAt: 0, lastAttemptAt: null } } @@ -692,6 +695,8 @@ function startingModelCatalog(agyPath) { acpOfferedModels = new Map(saved.offered.map(({ id, name }) => [id, name])) acpOfferedKey = [...acpOfferedModels.keys()].sort().join("\n") } + // The usage reader names ids on its windows from the catalog being served. + storeCatalogRows(saved.list) return { agyPath, list: saved.list, catalog: null, offeredKey: null, isFallback: false, fetchedAt: 0, lastAttemptAt: null } } @@ -707,6 +712,8 @@ function useAgyPath(agyPath) { function storeListedCatalog(agyPath, list, lastAttemptAt) { saveCatalog(agyPath, { list }) + // The usage reader names ids on its windows from the catalog being served. + storeCatalogRows(list) cachedModelCatalog = { agyPath, list, diff --git a/packages/agy-cli/model-ids.mjs b/packages/agy-cli/model-ids.mjs new file mode 100644 index 0000000..99a9d16 --- /dev/null +++ b/packages/agy-cli/model-ids.mjs @@ -0,0 +1,89 @@ +// The runtime catalog `agy models` listed, so usage windows can name the ids +// the provider serves (usage.mjs stays import-free of index.mjs). +// +// rows(): [{ id, name, effort? }] — the shape `agy models` parses into +// (parseAgyModels), the saved catalog, and FALLBACK_MODELS. +// +// nameIndex(): display name ("Claude Opus 5.5", case- and space-insensitive) +// → the family id ("claude-opus-5-5") and every effort variant id agy listed +// in it, plus the bare family id itself even when agy lists no variant of +// that name (the catalog serves it as its default). + +let rows = null +let index = new Map() + +export function storeCatalogRows(list) { + rows = Array.isArray(list) ? list.filter(model => model && typeof model.id === "string" && model.id) : null + index = null +} + +export function catalogRows() { + return rows ? [...rows] : null +} + +const normalizeName = (value) => String(value ?? "").trim().toLowerCase().replace(/\s+/g, " ").replace(/[.,;]$/, "") + +// `agy models` names its variants "Gemini 4 Hydrogen (High)" while usage +// groups say "Gemini 4 Hydrogen": match on the name without the effort +// suffix, too, so every variant of a family answers its display name. +const stripEffortSuffix = (name) => name.replace(/\s+\((?:high|medium|low|minimal|xhigh|max)\)$/i, "") + +// In "Models within this group: A, B and C", the separator before "and" can +// be a comma (as agy prints today) or nothing at all. +function listedNames(description) { + const listed = /Models within this group:\s*(.+)/i.exec(String(description ?? "")) + if (!listed) return null + return listed[1] + .split(/,|\s+and\s+/i) + .map(normalizeName) + .filter(Boolean) +} + +export function nameIndex() { + if (index) return index + index = new Map() + if (rows) { + const families = new Map() + const aliases = [] + for (const model of rows) { + const effort = /-(high|medium|low|minimal|xhigh|max)$/i.exec(model.id)?.[1]?.toLowerCase() || "" + const family = effort ? model.id.slice(0, -(effort.length + 1)) : model.id + if (!families.has(family)) families.set(family, new Set()) + families.get(family).add(model.id) + const name = normalizeName(model.name) + if (!name) continue + if (index.has(name) && index.get(name).family !== family) continue // one name, two families: no match + aliases.push([name, family], [stripEffortSuffix(name), family]) + } + for (const [family, ids] of families) { + // the bare id the catalog serves even when agy lists no variant of it + ids.add(family) + } + for (const [name, family] of aliases) { + if (index.has(name) && index.get(name).family !== family) continue + index.set(name, { family, ids: families.get(family) }) + } + } + return index +} + +// modelsInGroup answers the ids to put on a usage window. Group names are +// matched against the catalog's display names; a name that matches nothing +// is left out, as is a group whose description names no model and whose own +// name isn't a catalog name either. +export function modelsInGroup(group) { + const index = nameIndex() + if (!index.size) return [] + const ids = new Set() + const names = listedNames(group?.description) || [] + for (const name of names) { + const entry = index.get(name) + if (entry) for (const id of entry.ids) ids.add(id) + } + if (!ids.size) { + const own = normalizeName((group?.displayName || group?.display_name || group?.name || "").replace(/\s+models$/i, "")) + const entry = index.get(own) + if (entry) for (const id of entry.ids) ids.add(id) + } + return [...ids].sort() +} diff --git a/packages/agy-cli/package.json b/packages/agy-cli/package.json index 16fda56..07fd91b 100644 --- a/packages/agy-cli/package.json +++ b/packages/agy-cli/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-agy-cli-auth", - "version": "0.1.64", + "version": "0.1.65", "description": "Magpie/OpenCode model provider that connects your local agy CLI through the Agent Client Protocol (agy acp), so Antigravity subscription models run through the real CLI", "type": "module", "main": "./opencode.mjs", @@ -18,6 +18,7 @@ "step-usage.mjs", "tool-schema.mjs", "tool-budget.mjs", "usage.mjs", + "model-ids.mjs", "signin.mjs", "README.md", "README.en.md", diff --git a/packages/agy-cli/test/testkit.mjs b/packages/agy-cli/test/testkit.mjs index a264e04..1a6c098 100644 --- a/packages/agy-cli/test/testkit.mjs +++ b/packages/agy-cli/test/testkit.mjs @@ -30,6 +30,7 @@ export const REPO_DIR = path.dirname(path.dirname(fileURLToPath(import.meta.url) // AGY_BRIDGE_TEST_INDEX 只用于反向验证(让同一套用例跑修复前的旧副本,确认能抓到旧缺陷)。 export const INDEX_FILE = process.env.AGY_BRIDGE_TEST_INDEX || path.join(REPO_DIR, "index.mjs") export const USAGE_FILE = path.join(REPO_DIR, "usage.mjs") +export const MODEL_IDS_FILE = path.join(REPO_DIR, "model-ids.mjs") export const PLATFORM_FILE = path.join(REPO_DIR, "platform.mjs") export const ARRAY_ITEMS_FILE = path.join(REPO_DIR, "array-items.mjs") export const CLOAK_FILE = path.join(REPO_DIR, "cloak.mjs") @@ -535,6 +536,7 @@ export async function createBridgeKit(options = {}) { const cache = new Map([[RUNTIME_SPECIFIER, runtime]]) const indexUrl = pathToFileURL(path.join(REPO_DIR, "index.mjs")).href const usageUrl = pathToFileURL(USAGE_FILE).href + const modelIdsUrl = pathToFileURL(MODEL_IDS_FILE).href const platformUrl = pathToFileURL(PLATFORM_FILE).href const arrayItemsUrl = pathToFileURL(ARRAY_ITEMS_FILE).href const cloakUrl = pathToFileURL(CLOAK_FILE).href @@ -552,6 +554,7 @@ export async function createBridgeKit(options = {}) { if (cache.has(key)) return cache.get(key) let module if (key === "./usage.mjs") module = sourceModule(USAGE_FILE, "", usageUrl) + else if (key === "./model-ids.mjs") module = sourceModule(MODEL_IDS_FILE, "", modelIdsUrl) else if (key === "./platform.mjs") module = sourceModule(PLATFORM_FILE, "", platformUrl) else if (key === "./array-items.mjs") module = sourceModule(ARRAY_ITEMS_FILE, "", arrayItemsUrl) else if (key === "./cloak.mjs") module = sourceModule(CLOAK_FILE, "", cloakUrl) diff --git a/packages/agy-cli/test/usage.mjs b/packages/agy-cli/test/usage.mjs index c2697b6..a271c5a 100644 --- a/packages/agy-cli/test/usage.mjs +++ b/packages/agy-cli/test/usage.mjs @@ -7,10 +7,107 @@ import os from "node:os" import path from "node:path" import { test } from "node:test" import { createUsageReader, fetchUsage, parseUsageReport } from "../usage.mjs" +import { modelsInGroup, storeCatalogRows } from "../model-ids.mjs" import { forgetStoredSignIn } from "../signin.mjs" +// Live data captured from `agy -p /usage --output-format json` (agy 1.5.9, +// 2026-11-15), group descriptions pasted verbatim. +const LIVE_REPORT = { + status: "SUCCESS", + command: { + name: "usage", + data: { + description: "Within each group, models share a weekly limit and a 5-hour limit. Quota is consumed proportionally to the cost of the tokens. Thus, limits will last longer with shorter tasks or using more cost-effective models. The 5-hour limit smooths out aggregate demand to fairly distribute global capacity across all users, while your weekly limit is tied directly to your individual tier.", + groups: [ + { + name: "Gemini Models", + description: "Models within this group: Gemini 4 Hydrogen, Gemini 3.8 Flash", + buckets: [ + { id: "gemini-weekly", name: "Weekly Limit Remaining", window: "weekly", remaining_fraction: 1, reset_time: "2026-11-22T11:19:33Z" }, + { id: "gemini-5h", name: "Five Hour Limit Remaining", window: "5h", remaining_fraction: 1, reset_time: "2026-11-15T16:19:33Z" }, + ], + }, + { + name: "Claude and GPT models", + description: "Models within this group: Claude Opus 5.5, Claude Sonnet 5.5, GPT-OSS 120B", + buckets: [ + { id: "3p-weekly", name: "Weekly Limit Remaining", description: "You have used some of your weekly limit, it will fully refresh in 4 days, 21 hours.", window: "weekly", remaining_fraction: 0.3360503911972046, reset_time: "2026-11-20T09:01:10Z" }, + { id: "3p-5h", name: "Five Hour Limit Remaining", window: "5h", remaining_fraction: 1, reset_time: "2026-11-15T16:19:33Z" }, + ], + }, + { + name: "Gemini 4 Argon", + description: "For paid Pro plans, Argon quota is separate. Higher Argon quota (included as part of the larger Gemini quota bucket) is available on Ultra plans.", + buckets: [ + { id: "gemini-argon-wtu-weekly", name: "Gemini 4 Argon Weekly Limit", window: "weekly", remaining_fraction: 1, reset_time: "2026-11-22T11:19:33Z" }, + ], + }, + ], + }, + }, +} + +// The rows `agy models` listed for the same account, verbatim. +const LIVE_MODEL_ROWS = [ + { id: "gemini-4-argon-medium", name: "Gemini 4 Argon (Medium)", effort: "medium" }, + { id: "gemini-4-argon-high", name: "Gemini 4 Argon (High)", effort: "high" }, + { id: "gemini-4-argon-low", name: "Gemini 4 Argon (Low)", effort: "low" }, + { id: "gemini-4-hydrogen-high", name: "Gemini 4 Hydrogen (High)", effort: "high" }, + { id: "gemini-4-hydrogen-xhigh", name: "Gemini 4 Hydrogen (XHigh)", effort: "xhigh" }, + { id: "gemini-4-hydrogen-medium", name: "Gemini 4 Hydrogen (Medium)", effort: "medium" }, + { id: "gemini-4-hydrogen-low", name: "Gemini 4 Hydrogen (Low)", effort: "low" }, + { id: "gemini-pro-orchestrator-g1-pro", name: "Orchestrator (Argon)" }, + { id: "gemini-3.8-flash-high", name: "Gemini 3.8 Flash (High)", effort: "high" }, + { id: "gemini-3.8-flash-medium", name: "Gemini 3.8 Flash (Medium)", effort: "medium" }, + { id: "gemini-3.8-flash-low", name: "Gemini 3.8 Flash (Low)", effort: "low" }, + { id: "claude-opus-5-5-low", name: "Claude Opus 5.5 (Low)", effort: "low" }, + { id: "claude-opus-5-5-medium", name: "Claude Opus 5.5 (Medium)", effort: "medium" }, + { id: "claude-opus-5-5-high", name: "Claude Opus 5.5 (High)", effort: "high" }, + { id: "claude-sonnet-5-5-low", name: "Claude Sonnet 5.5 (Low)", effort: "low" }, + { id: "claude-sonnet-5-5-medium", name: "Claude Sonnet 5.5 (Medium)", effort: "medium" }, + { id: "claude-sonnet-5-5-high", name: "Claude Sonnet 5.5 (High)", effort: "high" }, + { id: "gpt-oss-120b-medium", name: "GPT-OSS 120B (Medium)", effort: "medium" }, +] + +test("a live report names on each window the ids the listed catalog serves", () => { + storeCatalogRows(LIVE_MODEL_ROWS) + const result = parseUsageReport(structuredClone(LIVE_REPORT)) + assert.deepEqual(result.windows.map(w => w.models), [ + ["gemini-3.8-flash", "gemini-3.8-flash-high", "gemini-3.8-flash-low", "gemini-3.8-flash-medium", "gemini-4-hydrogen", "gemini-4-hydrogen-high", "gemini-4-hydrogen-low", "gemini-4-hydrogen-medium", "gemini-4-hydrogen-xhigh"], + ["gemini-3.8-flash", "gemini-3.8-flash-high", "gemini-3.8-flash-low", "gemini-3.8-flash-medium", "gemini-4-hydrogen", "gemini-4-hydrogen-high", "gemini-4-hydrogen-low", "gemini-4-hydrogen-medium", "gemini-4-hydrogen-xhigh"], + ["claude-opus-5-5", "claude-opus-5-5-high", "claude-opus-5-5-low", "claude-opus-5-5-medium", "claude-sonnet-5-5", "claude-sonnet-5-5-high", "claude-sonnet-5-5-low", "claude-sonnet-5-5-medium", "gpt-oss-120b", "gpt-oss-120b-medium"], + ["claude-opus-5-5", "claude-opus-5-5-high", "claude-opus-5-5-low", "claude-opus-5-5-medium", "claude-sonnet-5-5", "claude-sonnet-5-5-high", "claude-sonnet-5-5-low", "claude-sonnet-5-5-medium", "gpt-oss-120b", "gpt-oss-120b-medium"], + // Argon's description names no model; its group name is a catalog name. + ["gemini-4-argon", "gemini-4-argon-high", "gemini-4-argon-low", "gemini-4-argon-medium"], + ]) + assert.deepEqual(result.windows.map(w => w.used), [0, 0, 66.394961, 0, 0]) + // agy names a family in the description even though it lists no bare id. + assert.ok(result.windows[2].models.includes("gpt-oss-120b")) + storeCatalogRows(null) +}) + +test("ids on windows follow the catalog, and names agy adds match nothing until it lists them", () => { + storeCatalogRows(LIVE_MODEL_ROWS) + // A renamed model: the description keeps the old name, the catalog the new. + assert.deepEqual(modelsInGroup({ description: "Models within this group: Claude Opus 5.5", name: "x" }), + ["claude-opus-5-5", "claude-opus-5-5-high", "claude-opus-5-5-low", "claude-opus-5-5-medium"]) + assert.deepEqual(modelsInGroup({ description: "Models within this group: Claude Opus 6", name: "x" }), []) + assert.deepEqual(modelsInGroup({ description: "Models within this group: Claude Opus 5.5 and Claude Opus 6", name: "x" }), + ["claude-opus-5-5", "claude-opus-5-5-high", "claude-opus-5-5-low", "claude-opus-5-5-medium"]) + // A group whose name matches no catalog name gets no ids, not guesses. + assert.deepEqual(modelsInGroup({ name: "Veo models" }), []) + // No catalog yet: no ids at all, windows stay account-level. + storeCatalogRows(null) + assert.deepEqual(modelsInGroup({ description: "Models within this group: Claude Opus 5.5" }), []) + // The separator list "A, B and C" also splits with no comma before "and". + storeCatalogRows([{ id: "m1", name: "Model One" }, { id: "m2", name: "Model Two" }]) + assert.deepEqual(modelsInGroup({ description: "Models within this group: Model One and Model Two" }), ["m1", "m2"]) + storeCatalogRows(null) +}) + const report = groups => ({ status: "SUCCESS", command: { name: "usage", data: { groups } } }) -const group = (buckets, name = "Gemini Models") => ({ name, buckets }) +const group = (buckets, name = "Gemini Models", description = "For paid Pro plans, Argon quota is separate.") => ({ name, description, buckets }) +const groupNoDesc = (buckets, name = "Gemini Models") => ({ name, buckets }) const bucket = (overrides = {}) => ({ id: "gemini-5h", name: "Five Hour Limit Remaining", window: "5h", remaining_fraction: 0.75, ...overrides }) test("maps all groups/cadences to display-only Magpie windows, without invented identity", () => { diff --git a/packages/agy-cli/usage.mjs b/packages/agy-cli/usage.mjs index 02efb61..41dbe48 100644 --- a/packages/agy-cli/usage.mjs +++ b/packages/agy-cli/usage.mjs @@ -3,6 +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 { cannotSignIn, isDead, noteDead, storedSignIn } from "./signin.mjs" const DEFAULT_TIMEOUT_MS = 15_000 @@ -90,10 +91,12 @@ 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}`, // 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 } : {}),