feat(usage): add Pi-native provider quota inspection with /usage - #525
Merged
Conversation
Adds an orthogonal, lightweight /usage command to inspect live subscription quotas and rate limits across Cursor, Google Antigravity, and OpenAI Codex. Key highlights: - Pure read-only observability with 60s in-memory TTL caching; failed requests are never cached. - Wire-accurate parsing: Cursor sub/userId separation and auto/api pool distinction; Google Antigravity remainingFraction inversion and dual Gemini/3P pools; OpenAI Codex second-to-millisecond timestamp conversion, ChatGPT-Account-Id header injection, and Spark pool isolation. - Privacy-aware formatting with ANSI progress bars, relative countdowns, and optional --redact masking. - Includes 17 unit tests verifying wire headers, fallbacks, cache invalidation, and failure isolation.
…, and cache isolation Incorporates review feedback from docs/research/2026-09-09-openpi-usage-review.md: - Reuse Pi-native modelRegistry.getProviderAuth lifecycle and locking instead of direct auth.json reads - Parse both primary and secondary windows for OpenAI Codex additional rate limits - Key the in-memory cache by credential identity hash to prevent cross-account pollution - Invert remainingFraction properly and handle empty groups/remainingAmount for Google Antigravity - Route non-TUI output through ctx.ui.notify to preserve RPC channel contract - Sanitize error messages to eliminate potential credential leakage - Decouple status threshold calculation from display rounding - Document /usage in README.md quick-reference table
Aligns Antigravity quota request User-Agent with the provider's existing getAntigravityUserAgent helper, asserting the wire header in provider tests.
tt-a1i
approved these changes
Sep 9, 2026
tt-a1i
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed at exact head 2fb853e. Standards and Spec review found no P0/P1 blocker. The command is valuable, user-triggered, Pi-native, bounded, and does not add model-facing tools or context. Focused tests (30/30), repository checks, and hosted CI are green. Non-blocking follow-up: complete exhausted Codex reports currently carry a warning and therefore bypass the 60-second cache; completeness should eventually be represented separately from exhaustion/advisory state.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
用户在开始长任务前缺少直接查看订阅额度的入口,往往直到请求被拒绝才发现某个时间窗口已经耗尽。额度信息还必须属于当前登录身份,不能混用旧账号缓存、遗漏附加额度池,或将未知数据表达为没有限制。
Closes #524
Value
通过
/usage手动查看 Cursor、OpenAI Codex 和 Google Antigravity 的额度快照、剩余量、重置时间和采样年龄。失败按服务隔离,未知数据明确展示,账号标识可按需遮蔽。Approach
modelRegistry.getProviderAuth()解析当前身份并复用原生 OAuth 刷新;不读取 auth.json、不实现第二套刷新逻辑。Validation
node --test --experimental-strip-types tests/extensions/usage/*.test.ts:30 passed。覆盖身份切换、Pi 原生过期凭据刷新、窗口完整性、未知/绝对剩余量、协议头、超时回退、取消、脱敏及输出模式。bun run check:通过配置契约、discipline、Web 类型检查/构建、Biome 和 TypeScript。构建仍提示现有 bundle 大于 500 kB。bun run test有全套通过记录,也重复出现未改动的子代理生命周期测试 2 秒等待超时;最终默认并发一轮仍是该项失败。该文件单独复测 20/20 通过。没有修改该模块或放宽断言时限。node --test --test-concurrency=4 --experimental-strip-types tests/**/*.test.ts:同一完整 Node 测试集 1495 passed / 1 skipped / 0 failed。node node_modules/vitest/vitest.mjs run tests/**/*.spec.ts:130 passed / 9 files。较低并发结果不代表默认高并发命令稳定通过。--no-extensions -e ./extensions/usage/index.ts -e ./extensions/ai-providers/index.ts加载源码,关闭启动网络发现、模型工具和 Session 持久化。真实 RPC 查询三个服务分别返回 2/4/2 个额度项,均无错误或不完整警告;仅产生extension_ui_request和命令 response,没有模型回合,stderr 为空。1-15/21变为7-21/21,无宽度/渲染错误,进程正常退出。该 UI 验收在最终 User-Agent 修正前完成;修正后的三服务成功结果由 RPC 验收。Impact
/usage [-f|--refresh] [-r|--redact] [-j|--json];订阅额度快照与 Session token/cost 统计明确分开。JSON 是报告格式,不绕过宿主输出协议;Pi print 模式将扩展日志转到 stderr。