@specode/pi-subscription-usage 1.3.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,140 +1,170 @@
1
- # Pi Subscription Usage
1
+ # pi-subscription-usage
2
2
 
3
- [English](README.md) | [简体中文](README.zh-CN.md)
3
+ [English](./README.md) | [简体中文](./README.zh-CN.md)
4
4
 
5
- A Pi extension that shows the active account's subscription quota in one consistent view.
5
+ A [Pi](https://github.com/earendil-works/pi-mono) extension that shows your active provider's subscription quota in the footer status bar and a full breakdown via `/usage`.
6
6
 
7
- Supported providers:
7
+ Footer status bar:
8
8
 
9
- - **OpenAI (ChatGPT subscription)** — separate `Plan limits` and app-limit groups for Pi's `openai` OAuth login, rendered with the existing quota bars. The footer and status event use `Plan limits`, matching the ChatGPT usage page. Also requires `openai-codex` OAuth in Pi for the same ChatGPT account/workspace, because OpenAI rejects the Sign in with ChatGPT token on ChatGPT usage and reset endpoints; run `/login openai-codex` once and keep OpenAI as the active model (see [Stability](#stability)). The Codex backend credential reads `/wham/usage` for website plan windows (`rate_limit`) and credits, and `/wham/usage/chatpass/apps` for the exact active application registration. Plan and app windows have distinct percentages and reset times; neither substitutes for the other. `App Allowance` is the configured usage cap, not remaining quota. Both credentials participate in cache invalidation. No browser cookies are used. Available account reset tickets are shown as `Account Resets`; redemption uses the companion Codex account's reset endpoint with explicit confirmation, not an app-specific reset endpoint.
9
+ ```text
10
+ 5h 99% ↻2h13m · 1w 85% ↻3d4h
11
+ ```
10
12
 
11
- - **OpenAI Codex** — 5-hour and weekly quota, model-specific quota, and confirmed reset-credit redemption. `Resets Left` counts only redeemable tickets from the reset-credit list, not the usage summary.
12
- - **OpenCode Go** — 5-hour, weekly, and monthly windows.
13
- - **Grok** — weekly and/or monthly quota using only Pi's `xai` / `xai-auth` OAuth credentials, with account identity verification. A weekly `currentPeriod` with an omitted `creditUsagePercent` is treated as 0% used (proto3 omits zero after reset). Unified SuperGrok billing is still probed from the default monthly endpoint, but that probe is no longer required when the weekly window is already displayable. Windows use the same `5h / 1w / 1m` status format as other providers.
14
- - **Kimi Coding** — 5-hour and weekly windows, plus the membership plan reported by the usage API.
13
+ `/usage` output:
15
14
 
16
- The extension does not implement or modify Codex Fast mode and never rewrites model requests.
15
+ ```text
16
+ OpenAI Codex
17
+ Shared Across Models:
18
+ 5h Window ████████████ 99% left · resets 08/27 12:13
19
+ 1w Window ██████████░░ 85% left · resets 08/30 14:00
20
+
21
+ gpt-5.6-spark:
22
+ 5h Window █░░░░░░░░░░░ 10% left · resets 08/27 11:40
23
+
24
+ Account:
25
+ Email user@example.com
26
+ Plan Pro
27
+ Resets Left 2
28
+ Extra Credit none
29
+ ```
17
30
 
18
- ## Installation
31
+ ## Supported Providers
19
32
 
20
- Install directly from GitHub:
33
+ To sign in, run `/login`, pick `Sign in with an account` (Account below) or `Sign in with an API key` (API key below), then pick the name shown in the table.
21
34
 
22
- ```bash
23
- pi install git:github.com/specode/pi-subscription-usage
24
- ```
35
+ | Provider | `/login` option | Quota shown | Reset credits | Extra extension |
36
+ | --- | --- | --- | --- | --- |
37
+ | OpenAI (ChatGPT) | Account → `OpenAI`, and Account → `OpenAI Codex (legacy)` | ChatGPT plan limits, current app limits | Yes (`Account Resets`) | |
38
+ | OpenAI Codex | Account → `OpenAI Codex (legacy)` | `5h`, `1w`, model-specific windows, account email | Yes (`Resets Left`) | |
39
+ | OpenCode Go | API key → `OpenCode Go` | `5h`, `1w`, `1m` | — | |
40
+ | xAI Grok | Account → `xAI` | `1w` and/or `1m` | — | |
41
+ | Kimi Coding | Account → `Kimi For Coding` | `5h`, `1w`, membership level | — | |
42
+ | Antigravity | Account → `Antigravity` | Gemini (`5h`, `1w`), Claude and GPT (`5h`, `1w`), Gemini 4 Argon (`1w`), plan, email, project | — | [`pi-antigravity`](https://www.npmjs.com/package/pi-antigravity) |
43
+ | Claude (Claude Code) | None; signed in through Claude Code | `5h`, `1w` | — | [`pi-claude-bridge`](https://www.npmjs.com/package/pi-claude-bridge) 0.9.3 or later |
25
44
 
26
- After the npm package is published, it can also be installed with:
45
+ ### Provider Notes
27
46
 
28
- ```bash
29
- pi install npm:@specode/pi-subscription-usage
30
- ```
47
+ #### OpenAI (ChatGPT)
31
48
 
32
- For local development:
49
+ Sign in to both `OpenAI` and `OpenAI Codex (legacy)` with the same ChatGPT account and workspace, then keep chatting with an `OpenAI` model. OpenAI rejects the `OpenAI` sign-in on its usage endpoints, so the extension uses the `OpenAI Codex (legacy)` sign-in only to read usage. `/usage` lists website `Plan limits` separately from the current app's limits (`App Allowance` shows the configured cap share, not remaining quota), and the footer tracks `Plan limits`.
33
50
 
34
- ```bash
35
- pi install /absolute/path/to/pi-subscription-usage
36
- ```
51
+ #### xAI Grok
37
52
 
38
- Pi packages execute with your full system permissions. Review third-party package source before installing it.
53
+ Sign in with your SuperGrok account (Account → `xAI`). Signing in with an xAI API key does not show subscription quota. If you use the third-party `pi-xai-oauth` extension instead, its sign-in works too.
39
54
 
40
- ## Usage
55
+ #### Antigravity
41
56
 
42
- Run:
57
+ Requires [`pi-antigravity`](https://www.npmjs.com/package/pi-antigravity) by Rahul Arya ([GitHub](https://github.com/Rahularya01/pi-antigravity)). Install it with `pi install npm:pi-antigravity`; `Antigravity` then appears under `Sign in with an account` in `/login`. Quota is split into three separate shared pools: Gemini models (`5h` and `1w`), Claude and GPT models (`5h` and `1w`), and Gemini 4 Argon (`1w`). The footer shows the pool of the model you are using: Claude and GPT-OSS models show the Claude and GPT pool, Gemini 4 Argon shows the Argon pool, and other Gemini models show the Gemini pool. Quota data requires a paid Google AI subscription; free-tier accounts show `Unsupported` in `/usage` and display nothing in the footer instead of an error.
43
58
 
44
- ```text
45
- /usage
46
- ```
59
+ Tested with `pi-antigravity` 0.11.0. Every earlier version back to 0.1.0 registers the same provider id, Google endpoint, and credential format, so they are expected to work too.
47
60
 
48
- Each invocation bypasses the cache and queries the current provider again. Quota windows use a uniform display with `MM/DD HH:mm` reset times. When a provider reports account metrics, they appear in a separate `Account` section after the quota windows.
61
+ Several packages have similar names. The extension recognizes the `antigravity` provider id and reads quota from Google's Cloud Code API with the credential Pi resolves for it, so the package must register that id and serve models from Google's endpoint. Install only one package that registers `antigravity`. As of October 31, 2026:
49
62
 
50
- Codex results are grouped by quota domain in this order:
63
+ | Package | Result |
64
+ | --- | --- |
65
+ | `pi-antigravity` | Works |
66
+ | `@gwylook/pi-antigravity`, `@dereknex/pi-antigravity` (forks of `pi-antigravity`), `@heyhuynhgiabuu/pi-oauth-antigravity`, `@raquezha/antigravity`, `pi-provider-antigravity` | Same provider id, Google endpoint, and credential format; expected to work, untested |
67
+ | `@estebanforge/pi-antigravity-bridge`, `@thoth-agents/pi-antigravity-bridge` | Register `antigravity` but run models through a local Antigravity bridge (`agy-bridge://`): unsupported, so the footer stays empty and `/usage` explains why |
68
+ | `@cortexkit/pi-antigravity-auth` (`google`), `pi-antigravity-acp-provider` and `@dapidev/pi-antigravity-pure` (`antigravity-acp`), `@ackneal/pi-agy-bridge` (`agy`) | Register a different provider id; not supported |
51
69
 
52
- 1. `Shared Across Models`
53
- 2. Model-specific sections
54
- 3. `Account`
70
+ #### Claude (Claude Code)
55
71
 
56
- Windows from different domains are never interleaved. When available, the Codex `Account` section displays the email decoded locally from the active OAuth token. Run `/usage` again whenever you want to refresh; the command does not show refresh, provider-switching, or all-provider menus.
72
+ Requires [`pi-claude-bridge`](https://www.npmjs.com/package/pi-claude-bridge) by elidickinson ([GitHub](https://github.com/elidickinson/pi-claude-bridge)), version 0.9.3 or later. 0.9.3 is the first version that passes Claude Code's usage reports on to Pi. Install it with `pi install npm:pi-claude-bridge` and sign in to Claude Code itself; there is no Pi login. Usage covers models under the `claude-bridge` provider; Claude models served by Antigravity use the Antigravity pool above.
57
73
 
58
- The reset menu appears for OpenAI and Codex only when redeemable reset credits are verified. Grok's current API exposes quota windows and natural reset times, but no verified manual-reset endpoint or reset-credit count, so the extension never invents a reset action. Grok windows still render through the same `/usage` bars and status event as Codex, OpenCode Go, and Kimi.
74
+ The bridge has no usage endpoint to query: Claude Code attaches your plan usage to its responses, and the extension reads that report. So the footer stays empty in each new session until the first report arrives, `/usage` shows the last reported values with the time they were reported instead of fetching, and a window whose reset time has passed shows as unused until the next report. The extension never reads Claude Code's credentials.
59
75
 
60
- ## Configuration
76
+ Tested with `pi-claude-bridge` 0.9.3 and Claude Code 2.1.311, the version bundled with the bridge's Agent SDK. If you point the bridge at your own `claude` executable (`pathToClaudeCodeExecutable`), older Claude Code versions are untested.
61
77
 
62
- Create `~/.pi/agent/subscription-usage.json` for a global setting, or `.pi/subscription-usage.json` in a trusted project to override it:
78
+ Several packages have similar names. The extension recognizes the `claude-bridge` provider id, so the package must both register that id and pass usage reports on. As of October 31, 2026:
63
79
 
64
- ```json
65
- {
66
- "displayMode": "used"
67
- }
80
+ | Package | Result |
81
+ | --- | --- |
82
+ | `pi-claude-bridge` 0.9.3 or later | Works |
83
+ | `@viniciosrab/pi-claude-bridge` 0.9.4-fork.3 | Same usage code as 0.9.3; expected to work, untested |
84
+ | `pi-claude-bridge` before 0.9.3, `@fractaal/pi-claude-bridge`, `@yassimba/pi-claude-bridge`, `@agimon-ai/po-claude-bridge` | Register `claude-bridge` but never pass usage on: the footer stays empty and `/usage` keeps showing `Waiting` |
85
+ | `@vanillagreen/pi-claude-bridge`, `pi-claude-subscription`, `pi-claude-directsdk`, `@ramtinj95/pi-claude-delegation` | Register a different provider id; not supported |
86
+
87
+ The npm package `claude-bridge`, without the `pi-` prefix, is an unrelated proxy server for the Claude Code CLI; `pi install npm:claude-bridge` installs the wrong package. Run `pi list` to check which package you have.
88
+
89
+ ## Installation
90
+
91
+ From npm:
92
+
93
+ ```bash
94
+ pi install npm:@specode/pi-subscription-usage
68
95
  ```
69
96
 
70
- `displayMode` accepts:
97
+ From GitHub:
71
98
 
72
- - `"remaining"` — show quota remaining (default, preserving the existing behavior).
73
- - `"used"` — show quota consumed.
99
+ ```bash
100
+ pi install git:github.com/specode/pi-subscription-usage
101
+ ```
74
102
 
75
- The setting applies to the footer status, `/usage` quota bars, and the structured status event. Run `/reload` after editing the file.
103
+ From a local directory for development:
76
104
 
77
- ## OpenAI / Codex reset safety
105
+ ```bash
106
+ pi install /path/to/pi-subscription-usage
107
+ ```
78
108
 
79
- OpenAI and Codex modes both use the same `/wham/rate-limit-reset-credits` and `/consume` endpoints as the ChatGPT usage page, authenticated with the Codex account's backend credential and scoped to that token's own account (`chatgpt-account-id`) for both display and redemption. Both modes count and offer only explicit, available, plan-supported, unexpired `codex_rate_limits` tickets, and always redeem a specific ticket: neither a summary count nor a failed listing falls back to a server-chosen reset. In OpenAI mode, tickets reset server-defined account windows, **not necessarily the current app's window**; the confirmation states this scope. Reset availability failure does not hide quota; successful redemption invalidates both providers' usage caches.
109
+ ## Usage
80
110
 
81
- Before redeeming a reset credit, the extension:
111
+ Sign in through `/login` as described above, then select a model from that provider. From then on:
82
112
 
83
- 1. Verifies that the active OpenAI or Codex model and usage account have not changed.
84
- 2. Verifies that the runtime token exactly matches the OAuth account stored by Pi through `/login`. OpenAI mode checks both stored credentials and rechecks application matching before redemption.
85
- 3. Shows the reset that will be consumed and asks for explicit confirmation. `Cancel (Default)` is always the first option; only deliberately choosing the second option continues.
86
- 4. Uses a unique request ID and reuses it across retries.
113
+ - The footer status bar shows the active quota windows and refreshes after each turn and every 5 minutes (using a 5-minute cache).
114
+ - Running `/usage` always fetches fresh data for the active provider and shows progress bars, reset times (`MM/DD HH:mm`), and account details.
115
+ - Claude is the exception: its quota is never fetched, only read from Claude Code's responses (see [Claude (Claude Code)](#claude-claude-code)).
87
116
 
88
- ## Status integration
117
+ ### Reset Credits (OpenAI and Codex)
89
118
 
90
- The extension publishes two status layers:
119
+ When your OpenAI or Codex account has redeemable rate-limit reset tickets, `/usage` offers to use one:
91
120
 
92
- - A plain `setStatus` string without provider names or icons, such as `5h 99% ↻2h13m · 1w 85% ↻3d4h · 1m 60%`. `↻` marks the countdown to each window's reset, shown only when the provider reports a future reset time. The footer refreshes every 5 minutes and after each agent turn, so the countdown can lag by up to about 5 minutes.
93
- - Structured window data through the `subscription-usage/status/v1` event.
121
+ - `Cancel (Default)` is selected by default, and an explicit confirmation is required before a ticket is consumed.
122
+ - Before redeeming, the extension checks that the active model and account have not changed and that the runtime token matches Pi's stored OAuth login.
123
+ - In OpenAI mode, a ticket resets server-defined account windows rather than specifically clearing the current app's limits.
124
+ - Redeeming a reset ticket is the only write operation in this extension.
94
125
 
95
- Windows are always ordered as `5h / 1w / 1m / other`. Other extensions can consume the structured event to provide their own icons, colors, and layout without parsing display text. Ready events include `displayMode`; each window includes `displayPercent`, `remainingPercent`, and `usedPercent`. Consumers should render `displayPercent` while using the explicit remaining/used fields for semantic decisions such as colors or alerts. When the provider reports a future reset time, a window also carries `resetCountdown` (for example `2h13m`), computed at publish time with the same format and refresh cadence as the footer text; consumers can show it as-is instead of formatting `resetsAt` themselves.
126
+ ## Configuration
96
127
 
97
- ## Security boundaries
128
+ Percentages show remaining quota by default. To show used quota instead, create `~/.pi/agent/subscription-usage.json` (global) or `.pi/subscription-usage.json` (trusted project override):
98
129
 
99
- - Usage queries resolve credentials only through `ctx.modelRegistry.getProviderAuth()`.
100
- - Account reset additionally reads Pi's stored OAuth credentials through the public `readStoredCredential()` API, solely to verify that it exactly matches the active runtime account before redemption.
101
- - Grok never reads `~/.grok/auth.json` and never accepts an API key in place of subscription OAuth.
102
- - Credentials are never written to caches, sessions, the status line, or error messages. Cache keys contain only in-process HMAC fingerprints.
103
- - The Codex email is decoded locally for the `/usage` account panel and is not included in the footer or structured status event.
104
- - Credentials are sent only to the corresponding official domains. Custom proxies and custom base URLs are rejected.
105
- - Account reset redemption (OpenAI / Codex) is the only write operation. It is shown only when redeemable credits exist and always requires explicit confirmation.
130
+ ```json
131
+ {
132
+ "displayMode": "used"
133
+ }
134
+ ```
106
135
 
107
- ## Development
136
+ | Value | Description |
137
+ | --- | --- |
138
+ | `"remaining"` | Show remaining quota percentage (default) |
139
+ | `"used"` | Show used quota percentage |
108
140
 
109
- Requirements:
141
+ Run `/reload` after changing the config file. `displayMode` applies to the footer status bar, `/usage` progress bars, and status events.
110
142
 
111
- - A current Pi installation.
112
- - A Node.js version that can run TypeScript files directly for the test suite.
143
+ ## Privacy and Safety
113
144
 
114
- Run the tests:
145
+ - Credentials come only from Pi's own login (provider registry). The extension never reads browser cookies or other tools' credential files (for example, Grok never reads `~/.grok/auth.json`, and Claude usage comes from the bridge's responses, not Claude Code's keychain entry).
146
+ - Requests go only to each provider's official endpoints. Custom proxies and custom base URLs are refused.
147
+ - Tokens are never written to caches, session files, the status bar, or error messages.
148
+ - The extension does not modify model requests.
149
+ - Several provider usage endpoints are undocumented. If an endpoint changes, the extension shows an error rather than guessing.
150
+
151
+ ## Development
115
152
 
116
153
  ```bash
154
+ # Run tests (requires Node.js with native TypeScript support)
117
155
  npm test
118
- ```
119
156
 
120
- Inspect the npm package contents:
121
-
122
- ```bash
157
+ # Check package contents
123
158
  npm run pack:check
124
- ```
125
159
 
126
- Load the extension directly without installing it:
127
-
128
- ```bash
160
+ # Load the extension directly in Pi without installing
129
161
  pi --no-extensions --offline -e ./index.ts --list-models
130
162
  ```
131
163
 
132
- ## Stability
133
-
134
- OpenAI app usage also depends on an undocumented ChatGPT endpoint. OpenAI rejects Sign in with ChatGPT tokens on these ChatGPT usage and reset endpoints (HTTP 401), so the companion Codex login is required: run `/login openai-codex` once with the same account/workspace. It is used only to read usage; keep OpenAI as the active model. Without it, check usage at https://chatgpt.com/settings/usage. An account/workspace mismatch, missing registration, or missing windows produces an error rather than displaying another account's quota. `App Allowance` is the configured share the app may use, not its remaining percentage. `Source` identifies this as the matching app in Pi's Codex account; matching application IDs is not independent cryptographic verification of both token identities.
164
+ ### Status Events for Theme and Extension Authors
135
165
 
136
- Codex reset, Grok billing, and Kimi usage rely on undocumented provider APIs that may change. When an API fails, the extension reports the query error and does not fall back to uncontrolled credential or proxy paths.
166
+ The extension emits structured events on `subscription-usage/status/v1` so custom themes or status extensions can render quota data without parsing the footer string. Windows are ordered `5h` -> `1w` -> `1m` -> other. Ready payloads include `displayMode` and, for each window, `displayPercent`, `remainingPercent`, `usedPercent`, and `resetCountdown`.
137
167
 
138
168
  ## License
139
169
 
140
- [MIT](LICENSE). See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for adapted third-party sources and licenses.
170
+ [MIT](./LICENSE). See [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md) for adapted sources and licenses.
package/README.zh-CN.md CHANGED
@@ -1,140 +1,170 @@
1
- # Pi Subscription Usage
1
+ # pi-subscription-usage
2
2
 
3
- [English](README.md) | [简体中文](README.zh-CN.md)
3
+ [English](./README.md) | [简体中文](./README.zh-CN.md)
4
4
 
5
- 一个用统一格式展示当前 Pi 账户订阅额度的扩展。
5
+ 一个 [Pi](https://github.com/earendil-works/pi-mono) 扩展:在底部状态栏显示当前订阅还剩多少额度,输入 `/usage` 查看完整明细。
6
6
 
7
- 支持以下提供商:
7
+ 底部状态栏效果:
8
8
 
9
- - **OpenAI(ChatGPT 订阅)**:将套餐 `Plan limits` 与当前应用额度分组展示,沿用原有进度条。底部及状态事件默认展示 `Plan limits`,与 ChatGPT 用量页对齐。同时需要在 Pi 登录同一 ChatGPT 账户/工作区的 `openai-codex`,因为 OpenAI 会拒绝 Sign in with ChatGPT 令牌访问 ChatGPT 用量和重置接口;执行一次 `/login openai-codex` 即可,当前模型仍保持 OpenAI(见[稳定性](#稳定性))。插件用 Codex 后端凭据从 `/wham/usage` 的 `rate_limit` 读取网页套餐窗口及积分余额,并从 `/wham/usage/chatpass/apps` 精确匹配当前应用窗口。两组各自保留百分比与重置时间,不互相冒充。`App Allowance` 是配置的使用上限,不是剩余额度;任一凭据变化都会使缓存失效。不读取浏览器 Cookie。可用账户重置票据显示为 `Account Resets`;明确确认后,通过配套 Codex 账户的重置接口兑换,并非应用专属重置接口。
9
+ ```text
10
+ 5h 99% ↻2h13m · 1w 85% ↻3d4h
11
+ ```
10
12
 
11
- - **OpenAI Codex**:5 小时与每周额度、模型专属额度,以及需要确认的重置次数兑换。`Resets Left` 只统计重置票据列表中可兑换的票据,不采用用量接口的汇总数。
12
- - **OpenCode Go**:5 小时、每周和每月窗口。
13
- - **Grok**:每周和/或每月额度;只使用 Pi 的 `xai` / `xai-auth` OAuth 凭据,并先验证账户身份。若 weekly `currentPeriod` 存在但省略了 `creditUsagePercent`,按已用 0% 处理(proto3 在周期重置后会省略 0)。统一账单账户仍会探测默认月度接口,但 weekly 窗口已经可展示时,月度探测失败不再让整次查询失败。窗口与其他提供商一样使用 `5h / 1w / 1m` 状态格式。
14
- - **Kimi Coding**:5 小时和每周窗口,以及额度接口返回的会员套餐。
13
+ `/usage` 输出示例:
15
14
 
16
- 本扩展不实现或修改 Codex Fast 模式,也不会改写模型请求。
15
+ ```text
16
+ OpenAI Codex
17
+ Shared Across Models:
18
+ 5h Window ████████████ 99% left · resets 08/27 12:13
19
+ 1w Window ██████████░░ 85% left · resets 08/30 14:00
20
+
21
+ gpt-5.6-spark:
22
+ 5h Window █░░░░░░░░░░░ 10% left · resets 08/27 11:40
23
+
24
+ Account:
25
+ Email user@example.com
26
+ Plan Pro
27
+ Resets Left 2
28
+ Extra Credit none
29
+ ```
17
30
 
18
- ## 安装
31
+ ## 支持的提供商
19
32
 
20
- 直接从 GitHub 安装:
33
+ 登录方法:输入 `/login`,先选 `Sign in with an account`(下表记为 Account)或 `Sign in with an API key`(下表记为 API key),再在列表里选下表中的名称。Pi 界面只有英文,这里的选项名称都按界面原文写。
21
34
 
22
- ```bash
23
- pi install git:github.com/specode/pi-subscription-usage
24
- ```
35
+ | 提供商 | `/login` 中选择 | 显示内容 | 重置券 | 额外扩展 |
36
+ | --- | --- | --- | --- | --- |
37
+ | OpenAI (ChatGPT) | Account → `OpenAI`,以及 Account → `OpenAI Codex (legacy)` | ChatGPT 套餐限额、当前应用限额 | 支持(`Account Resets`) | |
38
+ | OpenAI Codex | Account → `OpenAI Codex (legacy)` | `5h`、`1w`、模型专属窗口、账号邮箱 | 支持(`Resets Left`) | |
39
+ | OpenCode Go | API key → `OpenCode Go` | `5h`、`1w`、`1m` | — | |
40
+ | xAI Grok | Account → `xAI` | `1w` 和/或 `1m` | — | |
41
+ | Kimi Coding | Account → `Kimi For Coding` | `5h`、`1w`、会员等级 | — | |
42
+ | Antigravity | Account → `Antigravity` | Gemini(`5h`、`1w`)、Claude 与 GPT(`5h`、`1w`)、Gemini 4 Argon(`1w`)、套餐、邮箱、项目 | — | [`pi-antigravity`](https://www.npmjs.com/package/pi-antigravity) |
43
+ | Claude (Claude Code) | 无需在 Pi 登录,使用 Claude Code 的登录 | `5h`、`1w` | — | [`pi-claude-bridge`](https://www.npmjs.com/package/pi-claude-bridge) 0.9.3 及以上 |
25
44
 
26
- npm 包发布后,也可以这样安装:
45
+ ### 提供商说明
27
46
 
28
- ```bash
29
- pi install npm:@specode/pi-subscription-usage
30
- ```
47
+ #### OpenAI (ChatGPT)
31
48
 
32
- 本地开发时可以安装本地目录:
49
+ 用同一个 ChatGPT 账号和工作区,分别登录 `OpenAI` 和 `OpenAI Codex (legacy)`,平时对话继续用 `OpenAI` 下的模型就行。OpenAI 的用量接口不认 `OpenAI` 这个登录,所以扩展只借 `OpenAI Codex (legacy)` 的登录来读额度。`/usage` 会将网页端的套餐总限额(`Plan limits`)与当前应用限额分开显示(`App Allowance` 表示该应用的配额上限比例,而非剩余额度),底部状态栏显示 `Plan limits`。
33
50
 
34
- ```bash
35
- pi install /absolute/path/to/pi-subscription-usage
36
- ```
51
+ #### xAI Grok
37
52
 
38
- Pi package 拥有当前用户的完整系统权限。安装第三方 package 前,请先审查其源码。
53
+ 用 SuperGrok 账号登录(Account → `xAI`)。用 xAI 的 API Key 登录看不到订阅额度。如果你装的是第三方扩展 `pi-xai-oauth`,用它登录也可以。
39
54
 
40
- ## 使用
55
+ #### Antigravity
41
56
 
42
- 运行:
57
+ 需要 Rahul Arya 发布的 [`pi-antigravity`](https://www.npmjs.com/package/pi-antigravity)([GitHub](https://github.com/Rahularya01/pi-antigravity))。用 `pi install npm:pi-antigravity` 安装,之后 `/login` 的 `Sign in with an account` 列表里才会出现 `Antigravity`。额度分为三个独立的共享池:Gemini 模型(`5h` 与 `1w`)、Claude 与 GPT 模型(`5h` 与 `1w`)、Gemini 4 Argon(`1w`)。底部状态栏显示当前所用模型对应的额度池:用 Claude 或 GPT-OSS 模型时显示 Claude 与 GPT 池,用 Gemini 4 Argon 时显示 Argon 池,其他 Gemini 模型显示 Gemini 池。额度数据只对 Google AI 付费订阅开放;免费账号在 `/usage` 里显示 `Unsupported`,底部状态栏不显示内容,不会报错。
43
58
 
44
- ```text
45
- /usage
46
- ```
59
+ 已用 `pi-antigravity` 0.11.0 测试。0.1.0 以来的各个版本注册的 provider id、Google 接口地址和凭据格式都相同,预计同样可用。
47
60
 
48
- 每次调用都会跳过缓存并重新查询当前提供商。所有额度窗口都使用统一格式,并以 `MM/DD HH:mm` 显示重置时间。提供商返回账户指标时,这些指标会统一显示在额度窗口之后的独立 `Account` 区域。
61
+ npm 上有好几个名字相近的包。扩展按 `antigravity` 这个 provider id 识别,并用 Pi 为它提供的凭据向 Google 的 Cloud Code 接口查询额度,所以所用的包既要注册这个 id,模型也要走 Google 的接口。注册 `antigravity` 的包只装一个。截至 2026 年 10 月 31 日:
49
62
 
50
- Codex 结果会按以下额度域分组:
63
+ | 包 | 结果 |
64
+ | --- | --- |
65
+ | `pi-antigravity` | 可用 |
66
+ | `@gwylook/pi-antigravity`、`@dereknex/pi-antigravity`(`pi-antigravity` 的 fork)、`@heyhuynhgiabuu/pi-oauth-antigravity`、`@raquezha/antigravity`、`pi-provider-antigravity` | provider id、Google 接口地址和凭据格式都相同,预计可用,未测试 |
67
+ | `@estebanforge/pi-antigravity-bridge`、`@thoth-agents/pi-antigravity-bridge` | 注册了 `antigravity`,但模型经由本地 Antigravity 桥(`agy-bridge://`)运行:不支持,底部状态栏为空,`/usage` 会说明原因 |
68
+ | `@cortexkit/pi-antigravity-auth`(`google`)、`pi-antigravity-acp-provider` 与 `@dapidev/pi-antigravity-pure`(`antigravity-acp`)、`@ackneal/pi-agy-bridge`(`agy`) | 注册的是别的 provider id,不支持 |
51
69
 
52
- 1. `Shared Across Models`
53
- 2. 各模型专属分组
54
- 3. `Account`
70
+ #### Claude (Claude Code)
55
71
 
56
- 不同额度域的窗口不会交错。存在邮箱字段时,Codex `Account` 区域会显示从当前 OAuth Token 本地解析出的邮箱。需要刷新时再次运行 `/usage` 即可;命令不会显示刷新、切换提供商或查询所有提供商的菜单。
72
+ 需要 elidickinson 发布的 [`pi-claude-bridge`](https://www.npmjs.com/package/pi-claude-bridge)([GitHub](https://github.com/elidickinson/pi-claude-bridge))0.9.3 及以上版本,0.9.3 是第一个把 Claude Code 的用量数据转交给 Pi 的版本。用 `pi install npm:pi-claude-bridge` 安装,并在 Claude Code 里登录,Pi 这边不用登录。这里指 `claude-bridge` 提供商下的模型;通过 Antigravity 使用的 Claude 模型按上文的 Antigravity 额度池显示。
57
73
 
58
- OpenAI 和 Codex 模式都仅在确认有可兑换重置次数时显示重置菜单。Grok 当前 API 只公开额度窗口和自然重置时间,没有经过验证的手动重置端点或重置次数,因此本扩展不会虚构重置操作。Grok 窗口仍通过与 Codex、OpenCode Go、Kimi 相同的 `/usage` 进度条和状态事件展示。
74
+ bridge 没有可查询的用量接口:Claude Code 会在回复中附带当前套餐用量,扩展读取的就是这份数据。因此每个新会话要等收到第一份用量数据,底部状态栏才有内容;`/usage` 不会重新查询,只显示最近一次收到的数值和对应时间;如果某个窗口的重置时间已过,在收到下一份数据之前按未使用显示。扩展不会读取 Claude Code 的凭据。
59
75
 
60
- ## 配置
76
+ 已用 `pi-claude-bridge` 0.9.3 和 Claude Code 2.1.311(bridge 所带 Agent SDK 内置的版本)测试。如果你让 bridge 改用自己安装的 `claude` 可执行文件(`pathToClaudeCodeExecutable`),较旧的 Claude Code 版本未经测试。
61
77
 
62
- 可创建 `~/.pi/agent/subscription-usage.json` 作为全局配置,或在受信任项目中创建 `.pi/subscription-usage.json` 覆盖全局配置:
78
+ npm 上有好几个名字相近的包。扩展按 `claude-bridge` 这个 provider id 识别,所以所用的包既要注册这个 id,也要转交用量数据。截至 2026 年 10 月 31 日:
63
79
 
64
- ```json
65
- {
66
- "displayMode": "used"
67
- }
80
+ | 包 | 结果 |
81
+ | --- | --- |
82
+ | `pi-claude-bridge` 0.9.3 及以上 | 可用 |
83
+ | `@viniciosrab/pi-claude-bridge` 0.9.4-fork.3 | 用量相关代码与 0.9.3 相同,预计可用,未测试 |
84
+ | `pi-claude-bridge` 0.9.3 以前的版本、`@fractaal/pi-claude-bridge`、`@yassimba/pi-claude-bridge`、`@agimon-ai/po-claude-bridge` | 注册了 `claude-bridge`,但不转交用量:底部状态栏一直为空,`/usage` 一直显示 `Waiting` |
85
+ | `@vanillagreen/pi-claude-bridge`、`pi-claude-subscription`、`pi-claude-directsdk`、`@ramtinj95/pi-claude-delegation` | 注册的是别的 provider id,不支持 |
86
+
87
+ 不带 `pi-` 前缀的 npm 包 `claude-bridge` 是一个与此无关的 Claude Code CLI 代理服务器,`pi install npm:claude-bridge` 会装错包。可以用 `pi list` 确认装的是哪个。
88
+
89
+ ## 安装
90
+
91
+ 从 npm 安装:
92
+
93
+ ```bash
94
+ pi install npm:@specode/pi-subscription-usage
68
95
  ```
69
96
 
70
- `displayMode` 支持:
97
+ 从 GitHub 安装:
71
98
 
72
- - `"remaining"`:显示剩余额度(默认值,保持当前行为)。
73
- - `"used"`:显示已使用额度。
99
+ ```bash
100
+ pi install git:github.com/specode/pi-subscription-usage
101
+ ```
74
102
 
75
- 该配置同时作用于底部状态、`/usage` 额度条和结构化状态事件。修改配置文件后运行 `/reload`。
103
+ 从本地目录安装(开发调试):
76
104
 
77
- ## OpenAI / Codex 重置安全措施
105
+ ```bash
106
+ pi install /path/to/pi-subscription-usage
107
+ ```
78
108
 
79
- OpenAI 与 Codex 模式都使用 ChatGPT 用量页相同的 `/wham/rate-limit-reset-credits` 和 `/consume` 接口,并以 Codex 账户的后端凭据认证;显示和兑换时都通过 `chatgpt-account-id` 限定为该令牌自身的账户。两种模式都只统计和提供明确存在、可用、套餐支持且未过期的 `codex_rate_limits` 票据,且始终指定具体票据兑换:仅有汇总次数或列表查询失败时,都不会退回由服务端选票的兑换。OpenAI 模式下,票据重置的是服务端定义的账户窗口,**不保证清空当前应用窗口**,确认框会说明这一范围。查询重置次数失败不会隐藏额度;兑换成功会使两种模式的额度缓存失效。
109
+ ## 使用说明
80
110
 
81
- 兑换重置次数前,本扩展会:
111
+ 按上面的方法登录,再选一个该提供商的模型,之后:
82
112
 
83
- 1. 确认当前 OpenAI 或 Codex 模型及展示额度对应的账户没有变化。
84
- 2. 确认运行时令牌与 Pi 通过 `/login` 保存的 OAuth 账户完全一致。OpenAI 模式会检查两套保存的凭据,并在兑换前重新核验应用匹配。
85
- 3. 显示即将消耗的重置次数并要求明确确认。`Cancel (Default)` 始终位于第一项;只有主动选择第二项才会继续。
86
- 4. 使用唯一请求 ID,并在重试时复用同一个 ID。
113
+ - 底部状态栏会自动显示当前额度窗口,在每轮对话结束后及每 5 分钟刷新一次(带 5 分钟缓存)。
114
+ - 执行 `/usage` 会跳过缓存直接拉取最新数据,显示进度条、重置时间(`MM/DD HH:mm`)及账号信息。
115
+ - Claude 例外:不会主动查询额度,只读取 Claude Code 回复中附带的数据(见 [Claude (Claude Code)](#claude-claude-code))。
87
116
 
88
- ## 状态集成
117
+ ### 使用重置券(OpenAI 与 Codex)
89
118
 
90
- 本扩展提供两层状态输出:
119
+ OpenAI 或 Codex 账号里有可用的限额重置券时,`/usage` 会提供使用入口:
91
120
 
92
- - 不含提供商名称或图标的普通 `setStatus` 文本,例如 `5h 99% ↻2h13m · 1w 85% ↻3d4h · 1m 60%`。`↻` 后是距离该窗口重置的倒计时,仅在提供商返回未来的重置时间时显示。底部状态每 5 分钟及每轮 agent 结束后刷新,因此倒计时最多可能滞后约 5 分钟。
93
- - 通过 `subscription-usage/status/v1` 事件发布的结构化窗口数据。
121
+ - 确认弹窗默认选中 `Cancel (Default)`,必须手动确认才会消耗重置券。
122
+ - 提交兑换前,扩展会检查当前模型和账号是否发生变动,并核对运行时令牌是否与 Pi 保存的 OAuth 登录信息一致。
123
+ - 在 OpenAI 模式下,重置券作用于服务端定义的账户级窗口,不一定单独清空当前应用的限额。
124
+ - 兑换重置券是本扩展唯一的写操作。
94
125
 
95
- 窗口始终按 `5h / 1w / 1m / other` 排序。其他扩展可以直接消费结构化事件,自定义图标、颜色和布局,而不必解析显示文本。就绪事件包含 `displayMode`,每个窗口包含 `displayPercent`、`remainingPercent` 和 `usedPercent`;消费者应展示 `displayPercent`,并在颜色或告警等语义判断中使用明确的剩余/已用字段。提供商返回未来的重置时间时,窗口还包含 `resetCountdown`(例如 `2h13m`),在发布事件时计算,格式和刷新频率与底部状态文本一致;消费者可直接展示,无需自行根据 `resetsAt` 格式化。
126
+ ## 配置
96
127
 
97
- ## 安全边界
128
+ 百分比默认显示剩余额度。如需改为显示已用额度,可在 `~/.pi/agent/subscription-usage.json`(全局)或 `.pi/subscription-usage.json`(受信任项目的局部覆盖)中配置:
98
129
 
99
- - 额度查询只通过 `ctx.modelRegistry.getProviderAuth()` 解析凭据。
100
- - 账户重置还会通过公开的 `readStoredCredential()` API 读取 Pi 保存的 OAuth 凭据,仅用于确认其与当前运行时账户完全一致。
101
- - Grok 不会读取 `~/.grok/auth.json`,也不会用 API Key 代替订阅 OAuth。
102
- - 凭据不会写入缓存、会话、状态栏或错误消息;缓存键只保存进程内 HMAC 指纹。
103
- - Codex 邮箱仅在本地解析后显示于 `/usage` 账户区域,不会进入底部状态或结构化状态事件。
104
- - 凭据只会发送到对应的官方域名;自定义代理和自定义基础 URL 会被拒绝。
105
- - 账户重置兑换(OpenAI / Codex)是唯一的写操作。只有存在可兑换次数时才会显示,并且始终要求明确确认。
130
+ ```json
131
+ {
132
+ "displayMode": "used"
133
+ }
134
+ ```
106
135
 
107
- ## 开发
136
+ | 配置值 | 说明 |
137
+ | --- | --- |
138
+ | `"remaining"` | 显示剩余额度百分比(默认) |
139
+ | `"used"` | 显示已用额度百分比 |
108
140
 
109
- 要求:
141
+ 修改配置文件后执行 `/reload` 生效。`displayMode` 同时作用于底部状态栏、`/usage` 进度条和状态事件。
110
142
 
111
- - 当前版本的 Pi。
112
- - 能够直接运行 TypeScript 文件的 Node.js 版本,用于执行测试。
143
+ ## 隐私与安全
113
144
 
114
- 运行测试:
145
+ - 仅从 Pi 自身的登录注册表读取凭据,不读取浏览器 Cookie 或其他工具的凭据文件(例如 Grok 不会读取 `~/.grok/auth.json`;Claude 用量来自 bridge 返回的数据,不读取 Claude Code 存在钥匙串里的凭据)。
146
+ - 仅向各提供商的官方接口发起请求,拒绝自定义代理和自定义 Base URL。
147
+ - 令牌不会写入缓存、会话文件、状态栏或报错信息。
148
+ - 不修改任何模型请求。
149
+ - 部分提供商的用量接口属于未公开接口;若接口变更,扩展会直接报错提示,不会猜测或伪造数据。
150
+
151
+ ## 本地开发
115
152
 
116
153
  ```bash
154
+ # 运行测试(需要原生支持 TypeScript 的 Node.js 版本)
117
155
  npm test
118
- ```
119
-
120
- 检查 npm 包内容:
121
156
 
122
- ```bash
157
+ # 检查打包文件列表
123
158
  npm run pack:check
124
- ```
125
-
126
- 不安装、直接加载扩展:
127
159
 
128
- ```bash
160
+ # 不安装直接加载扩展验证
129
161
  pi --no-extensions --offline -e ./index.ts --list-models
130
162
  ```
131
163
 
132
- ## 稳定性
133
-
134
- OpenAI 应用额度也依赖未公开的 ChatGPT 接口。OpenAI 会拒绝 Sign in with ChatGPT 令牌访问这些 ChatGPT 用量和重置接口(HTTP 401),因此必须配套 Codex 登录:用同一账户/工作区执行一次 `/login openai-codex`。它只用于读取用量,当前模型仍可保持 OpenAI。未登录时,可在 https://chatgpt.com/settings/usage 查看用量。账户/工作区不匹配、找不到应用注册或额度窗口时会报告错误,不展示其他账户的额度。`App Allowance` 表示允许应用使用的套餐份额,不是剩余额度百分比。`Source` 明确标注这是 Pi Codex 登录账户内匹配应用的数据;应用 ID 匹配不是对两套令牌身份的独立验签证明。
164
+ ### 主题与状态栏扩展接入
135
165
 
136
- Codex 重置、Grok 账单和 Kimi 额度依赖未公开的提供商 API,这些 API 可能发生变化。如果 API 调用失败,本扩展只会报告查询错误,不会退回到不受控制的凭据或代理路径。
166
+ 扩展会在 `subscription-usage/status/v1` 事件通道发布结构化状态事件,供自定义主题或状态栏扩展直接渲染额度数据,无需解析状态栏文本。窗口固定按 `5h` -> `1w` -> `1m` -> 其他顺序排列;就绪事件包含 `displayMode`,每个窗口提供 `displayPercent`、`remainingPercent`、`usedPercent` 和 `resetCountdown`。
137
167
 
138
168
  ## 许可证
139
169
 
140
- 采用 [MIT](LICENSE) 许可证。改编的第三方源码及其许可证见 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。
170
+ [MIT](./LICENSE)。改编的第三方源码及许可证信息见 [THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md)。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@specode/pi-subscription-usage",
3
- "version": "1.3.1",
4
- "description": "Show subscription quota for OpenAI, Codex, OpenCode Go, Grok, and Kimi, plus OpenAI and Codex account reset credits in Pi",
3
+ "version": "1.5.0",
4
+ "description": "Show subscription quota for OpenAI, Codex, OpenCode Go, Grok, Kimi, Antigravity, and Claude (via pi-claude-bridge), plus OpenAI and Codex account reset credits in Pi",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "Specode",
@@ -22,7 +22,9 @@
22
22
  "codex",
23
23
  "opencode",
24
24
  "grok",
25
- "kimi"
25
+ "kimi",
26
+ "antigravity",
27
+ "claude"
26
28
  ],
27
29
  "files": [
28
30
  "index.ts",
package/src/format.ts CHANGED
@@ -79,6 +79,7 @@ export function formatProviderState(
79
79
  let status = "Query Failed";
80
80
  if (state.status === "auth-unavailable") status = "Auth Unavailable";
81
81
  else if (state.status === "unsupported") status = "Unsupported";
82
+ else if (state.status === "pending") status = "Waiting";
82
83
  return `${state.providerName}\n ${status}: ${state.message}`;
83
84
  }
84
85