@narumitw/pi-usage 0.52.0 β†’ 0.52.2

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,28 +1,26 @@
1
- # πŸ“Š pi-usage β€” Provider Usage for Pi
1
+ # πŸ“Š pi-usage β€” Check Provider Usage and Codex Fast Mode
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@narumitw/pi-usage)](https://www.npmjs.com/package/@narumitw/pi-usage) [![Pi extension](https://img.shields.io/badge/Pi-extension-blue)](https://pi.dev) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)
4
4
 
5
- `@narumitw/pi-usage` is a native [Pi coding agent](https://pi.dev) extension that adds an interactive `/usage` command for reading usage from the account Pi is actually using and a `/fast` shortcut for supported OpenAI Codex models. It supports Codex ChatGPT subscription windows, GitHub Copilot allowances, and OpenRouter API-key spend limits without pretending those limits have the same semantics.
5
+ Check the limits and usage for the provider account Pi is actually using, and toggle Fast mode for supported OpenAI Codex models.
6
+
7
+ The extension reports each provider's native semantics instead of presenting unlike quotas as equivalent.
6
8
 
7
9
  ## ✨ Features
8
10
 
9
- - Opens one interactive `/usage` menu with current state and next actions.
10
- - Automatically queries the selected model provider and active runtime account.
11
- - Supports OpenAI Codex subscription windows, resets, credits, and model-specific buckets.
12
- - Toggles persistent Codex Fast routing through `/fast` or the contextual `/usage` action.
13
- - Redeems earned Codex usage-limit resets for the active, matching Pi OAuth account with fresh availability, explicit confirmation, and idempotent retry.
14
- - Supports GitHub Copilot AI Credits, legacy premium requests, Free chat quota, additional usage, percentage, and reset time.
15
- - Supports OpenRouter per-key credit limits plus daily, weekly, monthly, and all-time spend.
16
- - Provides explicit refresh, another-provider, and all-configured-provider actions.
17
- - Runs manually requested all-provider queries with concurrency limited to two and preserves partial results.
18
- - Labels only the selected model provider as `Current`; other results are `Configured`.
19
- - Keeps the compact statusline scoped to the current provider and runtime account.
20
- - Isolates its five-minute in-memory cache by provider and a process-salted credential fingerprint.
21
- - Resolves runtime credentials through Pi; for Copilot only, reads Pi's stored OAuth credential through Pi's public credential API and verifies that it matches the active runtime account.
11
+ - Shows current-account usage and next actions through `/usage`.
12
+ - Supports OpenAI Codex subscription windows, credits, resets, and model-specific buckets.
13
+ - Supports GitHub Copilot allowances and OpenRouter per-key limits and spend windows.
14
+ - Toggles persistent Codex Fast routing through `/fast` or the contextual usage menu.
15
+ - Redeems eligible Codex resets only after fresh account matching and explicit confirmation.
16
+ - Refreshes one or all configured providers with bounded concurrency and partial-result preservation.
17
+ - Keeps statusline and cache data scoped to the current provider and runtime account.
18
+ - Resolves credentials through Pi or the process-local OAuth credential-source protocol and validates the effective provider endpoint before sending them.
22
19
 
23
20
  ## πŸ“¦ Install
24
21
 
25
22
  Requires Pi 0.81.0 or newer so the extension can validate the effective base URL attached to resolved provider auth before sending credentials to an official usage endpoint.
23
+ The v1 credential-source interoperability path is characterized against Pi 0.84.3; other runtimes retain standalone fallback but do not receive the protocol timing guarantee.
26
24
 
27
25
  ```bash
28
26
  pi install npm:@narumitw/pi-usage
@@ -34,13 +32,21 @@ Try without installing permanently:
34
32
  pi -e npm:@narumitw/pi-usage
35
33
  ```
36
34
 
37
- Try this package locally from the repository root:
35
+ Build and try this package locally from the repository root:
38
36
 
39
37
  ```bash
38
+ npm --workspace @narumitw/pi-usage run build
40
39
  pi -e ./packages/pi-usage
41
40
  ```
42
41
 
43
- ## πŸš€ Usage
42
+ The package declares `dist/index.ts`, so an unbuilt local checkout must run the build before Pi loads the package directory.
43
+
44
+ ## πŸš€ Quick start
45
+
46
+ Run `/usage` in TUI or RPC mode to inspect the current provider, refresh usage, or choose another configured provider.
47
+ Use `/fast` separately to toggle Fast mode for a supported current Codex model.
48
+
49
+ ## πŸ’¬ Commands
44
50
 
45
51
  Run:
46
52
 
@@ -48,8 +54,7 @@ Run:
48
54
  /usage
49
55
  ```
50
56
 
51
- In TUI or RPC mode, the standard menu first queries the current model provider and presents its state
52
- with these actions:
57
+ In TUI or RPC mode, the standard menu first queries the current model provider and presents its state with these actions:
53
58
 
54
59
  ```text
55
60
  Refresh current usage
@@ -61,19 +66,18 @@ Close
61
66
  ```
62
67
 
63
68
  There are intentionally no `/usage --refresh`, `/usage <provider>`, or `/usage --all` argument paths.
64
- Cross-provider traffic requires an explicit interactive choice. Escape returns from provider selection
65
- and closes the root menu. Print and JSON modes reject `/usage` observably because they cannot host the
66
- interactive flow. The cancellable live-query progress view remains extension-owned because it streams
67
- provider work and supports in-flight abort rather than presenting a standard menu screen.
68
-
69
- For the current OpenAI Codex provider, **Redeem usage limit reset…** checks fresh earned-reset
70
- details, lets you select a reset when details are available, and shows the exact reset before asking
71
- for confirmation. **No, go back** is the safe default and cancellation before confirmation sends no
72
- mutation. After confirmation, the reset operation cannot be cancelled from its progress view; session
73
- replacement or shutdown still aborts owned work. A transport failure offers **Try again** with the
74
- same redemption request ID so the backend can treat an uncertain retry idempotently. Successful,
75
- already-completed, not-needed, and no-credit outcomes are reported separately, then usage and the
76
- statusline are refreshed for the still-current account.
69
+ Cross-provider traffic requires an explicit interactive choice.
70
+ Escape returns from provider selection and closes the root menu.
71
+ Print and JSON modes reject `/usage` observably because they cannot host the interactive flow.
72
+ The cancellable live-query progress view remains extension-owned because it streams provider work and supports in-flight abort rather than presenting a standard menu screen.
73
+
74
+ For the current OpenAI Codex provider, **Redeem usage limit reset…** checks fresh earned-reset details, lets you select a reset when details are available, and shows the exact reset before asking for confirmation.
75
+ **No, go back** is the safe default and cancellation before confirmation sends no mutation.
76
+ After confirmation, the reset operation cannot be cancelled from its progress view; session replacement or shutdown still aborts owned work.
77
+ A transport failure offers **Try again** with the same redemption request ID so the backend can treat an uncertain retry idempotently.
78
+ Successful, already-completed, not-needed, and no-credit outcomes are reported separately, then usage and the statusline are refreshed for the still-current account.
79
+
80
+ ## βš™οΈ Settings
77
81
 
78
82
  ### Codex Fast mode
79
83
 
@@ -105,14 +109,14 @@ Repair or remove an invalid file, then run `/reload` before trying the toggle ag
105
109
  - Reset mutation: `POST /wham/rate-limit-reset-credits/consume` with a unique redemption request ID and, when available, the selected opaque credit ID
106
110
  - Statusline examples: `codex 59% 5h 61% wk`, `codex fast 59% 5h`, or `codex spark 100% 5h`
107
111
 
108
- The statusline selects a returned bucket that matches the current Codex model when one is available. Unlike `pi-codex-usage`, this successor intentionally has no Codex CLI fallback because the CLI may be logged into a different account than Pi's active runtime account.
112
+ The statusline selects a returned bucket that matches the current Codex model when one is available.
113
+ Unlike `pi-codex-usage`, this successor intentionally has no Codex CLI fallback because the CLI may be logged into a different account than Pi's active runtime account.
109
114
 
110
- Reset redemption is available only when Codex is the current provider and Pi's freshly resolved access
111
- token exactly matches its stored OpenAI Codex OAuth credential. `pi-usage` forwards only the bearer
112
- authorization and matching `chatgpt-account-id` to the official ChatGPT origin. API-key credentials,
113
- configured-but-not-current Codex accounts, account changes during the flow, and custom/proxy origins
114
- fail before mutation. Backend-provided titles and descriptions are sanitized for terminal display;
115
- opaque credit and account IDs are never shown or persisted by the extension.
115
+ Reset redemption is available only when Codex is the current provider and Pi's freshly resolved access token exactly matches an OAuth credential from Pi's stored login or a compatible credential source.
116
+ `pi-usage` forwards only the bearer authorization and matching `chatgpt-account-id` to the official ChatGPT origin.
117
+ API-key credentials, configured-but-not-current Codex accounts, account changes during the flow, and custom/proxy origins fail before mutation.
118
+ Backend-provided titles and descriptions are sanitized for terminal display.
119
+ Opaque credit and account IDs are never shown or persisted by the extension.
116
120
 
117
121
  ### GitHub Copilot
118
122
 
@@ -122,7 +126,12 @@ opaque credit and account IDs are never shown or persisted by the extension.
122
126
  - Displayed data: entitlement, remaining allowance, percentage, reset time, plan, and any additional usage beyond the included allowance
123
127
  - Statusline examples: `copilot credits 1200/1500 80%`, `copilot 245/300 82%`, or `copilot chat 40/50 80%`
124
128
 
125
- GitHub's quota endpoint requires the original GitHub OAuth token rather than the short-lived Copilot inference token exposed by runtime auth. `pi-usage` therefore supports Copilot accounts created through Pi's `/login` flow, reads that stored credential through Pi's public API, and uses it only when its short-lived access token matches the active runtime credential. API-key credentials, account mismatches, GitHub Enterprise accounts, and proxy/custom provider origins fail closed. The detailed report follows the endpoint's `token_based_billing` marker so AI credits are not mislabeled as legacy premium requests, and it reports overage without treating a negative included balance as a malformed response.
129
+ GitHub's quota endpoint requires the original GitHub OAuth token rather than the short-lived Copilot inference token exposed by runtime auth.
130
+ `pi-usage` supports Copilot accounts created through Pi's `/login` flow and named accounts offered by a compatible `oauth:credential-source:v1` owner.
131
+ It uses a candidate only when its short-lived access token exactly matches the freshly resolved active runtime credential.
132
+ Duplicate equivalent candidates are harmless, while conflicting matches fail closed without choosing by extension load order.
133
+ API-key credentials, account mismatches, GitHub Enterprise accounts, and proxy/custom provider origins fail closed.
134
+ The detailed report follows the endpoint's `token_based_billing` marker so AI credits are not mislabeled as legacy premium requests, and it reports overage without treating a negative included balance as a malformed response.
126
135
 
127
136
  ### OpenRouter
128
137
 
@@ -132,7 +141,8 @@ GitHub's quota endpoint requires the original GitHub OAuth token rather than the
132
141
  - Displayed data: key label when safely returned, optional per-key limit and remaining amount, reset period, and daily/weekly/monthly/all-time spend
133
142
  - Statusline examples: `openrouter $74.50 left` or `openrouter $25.50 used`
134
143
 
135
- The extension does not call OpenRouter's account-level `/credits` endpoint because that operation requires a separate management key. OpenRouter documents the distinction between credit and rate limits in its [API limits guide](https://openrouter.ai/docs/api_reference/limits).
144
+ The extension does not call OpenRouter's account-level `/credits` endpoint because that operation requires a separate management key.
145
+ OpenRouter documents the distinction between credit and rate limits in its [API limits guide](https://openrouter.ai/docs/api_reference/limits).
136
146
 
137
147
  ### OpenCode Go (Zen)
138
148
 
@@ -146,19 +156,28 @@ The usage endpoint is derived from the model's base URL (`…/zen/go/v1/usage`)
146
156
 
147
157
  ## 🧭 Current and configured accounts
148
158
 
149
- `Current` means the provider and credential used by Pi's selected model. `Configured` means Pi reports runtime auth for another supported provider; it does not mean that provider is active.
159
+ `Current` means the provider and credential used by Pi's selected model.
160
+ `Configured` means Pi reports runtime auth for another supported provider; it does not mean that provider is active.
150
161
 
151
- The extension does not enumerate multiple accounts inside one provider and does not switch accounts. Account selection remains owned by Pi or an account-management extension. After the active runtime credential changes, the next command, turn, or scheduled refresh resolves auth again and cannot reuse another account's cached report.
162
+ The extension does not enumerate multiple accounts inside one provider and does not switch accounts.
163
+ Account selection remains owned by Pi or an account-management extension.
164
+ A compatible credential owner may offer the verified active named account through the versioned process-local protocol without exposing its account label or storage.
165
+ Without such an owner, `pi-usage` retains its standalone Pi `auth.json` behavior.
166
+ An older or incompatible owner degrades to the existing authentication-unavailable result when the stored login does not match runtime auth.
167
+ After the active runtime credential changes, the next command, turn, or scheduled refresh resolves auth again and cannot reuse another account's cached report.
152
168
 
153
169
  ## πŸ“Š Statusline behavior
154
170
 
155
- The `usage` status item is active only for the selected model provider. It refreshes every five minutes while the session remains on a supported provider and is cleared when the model changes to an unsupported provider.
171
+ The `usage` status item is active only for the selected model provider.
172
+ It refreshes every five minutes while the session remains on a supported provider and is cleared when the model changes to an unsupported provider.
156
173
 
157
- Manual another-provider and all-provider queries never publish to the statusline. `@narumitw/pi-statusline` supplies the default `πŸ“Š` icon; `pi-usage` publishes text-only values.
174
+ Manual another-provider and all-provider queries never publish to the statusline.
175
+ `@narumitw/pi-statusline` supplies the default `πŸ“Š` icon; `pi-usage` publishes text-only values.
158
176
 
159
177
  ## πŸ”„ Migrating from pi-codex-usage
160
178
 
161
- `pi-codex-usage` is deprecated and its source is archived under `deprecated/`. To migrate one installation:
179
+ `pi-codex-usage` is deprecated and its source is archived under `deprecated/`.
180
+ To migrate one installation:
162
181
 
163
182
  ```bash
164
183
  pi remove npm:@narumitw/pi-codex-usage
@@ -174,15 +193,25 @@ Behavior changes:
174
193
  - Codex CLI fallback is removed to preserve active-runtime-account correctness.
175
194
  - The status key changes from `codex-usage` to `usage`.
176
195
 
196
+ ## πŸ”’ Security and privacy
197
+
198
+ Credential candidates are collected synchronously in memory and are not cached, persisted, logged, formatted, or appended to the Pi session.
199
+ The protocol carries no account name or extension identity.
200
+ Only the selected provider's exact runtime match is used, and secrets are sent only to the validated official provider origin.
201
+ Pi extensions run with the user's process privileges, so the shared event bus is not a security boundary between installed extensions.
202
+ Install only trusted extensions because any installed extension may already read user files and process memory.
203
+ Protocol v1 interoperability is characterized for the repository's supported Pi runtime; an absent or incompatible peer preserves standalone fallback and fail-closed mismatch behavior.
204
+
177
205
  ## 🚧 Limitations
178
206
 
179
207
  - Only providers with a meaningful usage source and verifiable Pi runtime auth are supported.
180
208
  - GitHub Copilot quota and OpenAI Codex reset redemption use undocumented provider endpoints that may change without notice.
181
- - Codex reset redemption requires a current ChatGPT OAuth login created through Pi; Codex API keys cannot redeem earned subscription resets.
209
+ - Codex reset redemption requires a current ChatGPT OAuth credential from Pi's login or a compatible credential source; Codex API keys cannot redeem earned subscription resets.
182
210
  - Credentials resolved for custom provider base URLs are never forwarded to the providers' official usage endpoints; effective auth origin validation requires Pi 0.81.0 or newer.
183
211
  - Provider reports are snapshots and may themselves be delayed by the provider.
184
212
  - OpenRouter successful inference responses do not expose proactive request-rate counters; `/usage` reports the documented per-key credit/spend fields instead.
185
- - A provider may not return a safe human-readable account identity. In that case the provider and runtime credential state remain visible without exposing secrets.
213
+ - A provider may not return a safe human-readable account identity.
214
+ In that case the provider and runtime credential state remain visible without exposing secrets.
186
215
  - Immediate account-change events are not available from Pi; auth is re-resolved before commands, turns, and scheduled refreshes.
187
216
  - Fast model support is intentionally conservative and may require an extension update when Codex adds or removes service tiers.
188
217
  - Another later-loaded extension can replace the final provider payload, so arbitrary third-party payload-rewrite conflicts cannot be prevented.
@@ -191,6 +220,9 @@ Behavior changes:
191
220
 
192
221
  ```txt
193
222
  packages/pi-usage/
223
+ β”œβ”€β”€ dist/ # Generated TypeScript runtime loaded by Jiti
224
+ β”œβ”€β”€ scripts/
225
+ β”‚ └── build-runtime.mjs # Deterministic runtime builder and boundary validator
194
226
  β”œβ”€β”€ src/
195
227
  β”‚ β”œβ”€β”€ index.ts # Pi package entrypoint and helper export barrel
196
228
  β”‚ β”œβ”€β”€ usage.ts # Menu, cache, and usage lifecycle orchestration
@@ -199,6 +231,7 @@ packages/pi-usage/
199
231
  β”‚ β”œβ”€β”€ settings.ts # Validated user settings and atomic persistence
200
232
  β”‚ β”œβ”€β”€ usage-helpers.ts # Small orchestration helpers
201
233
  β”‚ β”œβ”€β”€ query.ts # Runtime auth resolution and bounded provider queries
234
+ β”‚ β”œβ”€β”€ oauth-credential-source.ts # Ephemeral OAuth candidate collection
202
235
  β”‚ β”œβ”€β”€ codex-resets.ts # Codex reset auth, API contracts, and normalization
203
236
  β”‚ β”œβ”€β”€ format.ts # Provider-aware notifications and statusline text
204
237
  β”‚ β”œβ”€β”€ core.ts # Cache, concurrency, fingerprint, and redaction helpers
@@ -213,10 +246,13 @@ packages/pi-usage/
213
246
 
214
247
  `index.ts` is the Pi entrypoint and forwards the default factory from `usage.ts` while retaining the package's named helper exports; other source modules are internal.
215
248
 
249
+ The generated runtime is built from the authoritative `src/index.ts` graph and does not import back into `src`.
250
+
216
251
  ## πŸ”Ž Keywords
217
252
 
218
253
  Pi extension, Pi coding agent, usage, quota, OpenAI Codex usage, ChatGPT subscription limits, GitHub Copilot AI credits, GitHub Copilot premium requests, OpenRouter credits, API-key spend limits, TypeScript Pi package, npm Pi extension.
219
254
 
220
255
  ## πŸ“„ License
221
256
 
222
- MIT. See [`LICENSE`](./LICENSE).
257
+ MIT.
258
+ See [`LICENSE`](./LICENSE).