@hk_net/pi-usage-bars 0.3.0 → 0.4.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## [0.4.1] - 2026-07-31
6
+
7
+ ### Fixed
8
+
9
+ - Classify Codex quota windows by `limit_window_seconds` instead of assuming `primary_window` is always the session limit. Codex accounts that expose only a seven-day primary window now show it as Weekly and no longer display a fabricated `Session 0%` lane.
10
+
11
+ ### Changed
12
+
13
+ - Updated the development and test baseline to Pi SDK 0.83.0 while retaining runtime compatibility with Pi 0.81.1 and newer.
14
+
15
+ ## [0.4.0] - 2026-07-22
16
+
17
+ ### Added
18
+
19
+ - Added Kimi For Coding quota support through Pi's `kimi-coding` credential and the first-party five-hour/weekly usage endpoint.
20
+ - Added separate MiniMax Global and China Coding/Token Plan support, including the current token-plan endpoint and legacy coding-plan fallback.
21
+ - Added provider-specific quota labels and support for MiniMax responses that expose an interval quota without a weekly quota.
22
+ - Added neutral MiniMax purchased-Credits balance rendering when a key-authenticated first-party response exposes a balance.
23
+ - Added OpenRouter account balance and daily/weekly/monthly key spend using the first-party Credits and Key APIs.
24
+ - Added OpenRouter per-key limit bars only when the key has a real configured credit limit.
25
+ - Added DeepSeek total, topped-up, and granted balance support through the official key-authenticated balance API.
26
+ - Added separate Moonshot/Kimi API Global and China available, cash, and voucher balance support.
27
+ - Added a typed financial-metrics roadmap for further balance/spend providers.
28
+ - Added provider parsing, regional routing, endpoint fallback, financial rendering, authentication lifecycle, and smoke tests.
29
+ - Added CI, reproducible installs, production auditing, and a maintainer release guide.
30
+
31
+ ### Changed
32
+
33
+ - Treat MiniMax status `2062` as a neutral “No active Token Plan” account state rather than an API error; the cookie-only console balance endpoint remains out of scope.
34
+ - Expanded endpoint configuration documentation for Kimi, MiniMax, OpenRouter, DeepSeek, and Moonshot.
35
+ - Changed npm publishing to an explicit manual workflow so source tags cannot accidentally republish an already released version.
36
+ - Bumped the package version to 0.4.0.
37
+
3
38
  ## [0.3.0] - 2026-07-22
4
39
 
5
40
  ### Breaking changes
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # pi-usage-bars
2
2
 
3
- Subscription usage indicators for [Pi](https://github.com/earendil-works/pi).
3
+ Quota, balance, and spend indicators for [Pi](https://github.com/earendil-works/pi).
4
4
 
5
5
  ![Codex footer bar](https://raw.githubusercontent.com/hknet/pi-usage-bars/main/assets/codex.png)
6
6
 
7
7
  It adds:
8
8
 
9
- - a footer status bar for the active subscription provider
10
- - a `/usage` command showing every configured supported subscription
9
+ - a footer status bar for the active supported provider
10
+ - a `/usage` command showing configured quota, balance, and spend data
11
11
 
12
12
  ## Supported providers
13
13
 
@@ -17,6 +17,19 @@ It adds:
17
17
  | Anthropic Claude | `anthropic` | Claude Pro/Max OAuth |
18
18
  | ZAI Coding Plan (Global) | `zai` | ZAI API key |
19
19
  | ZAI Coding Plan (China) | `zai-coding-cn` | ZAI China API key |
20
+ | Kimi For Coding | `kimi-coding` | Kimi Coding Plan API key |
21
+ | MiniMax Coding Plan (Global) | `minimax` | MiniMax Global API key |
22
+ | MiniMax Coding Plan (China) | `minimax-cn` | MiniMax China API key |
23
+ | OpenRouter | `openrouter` | OpenRouter API key |
24
+ | DeepSeek | `deepseek` | DeepSeek API key |
25
+ | Moonshot/Kimi API (Global) | `moonshotai` | Moonshot Global API key |
26
+ | Moonshot/Kimi API (China) | `moonshotai-cn` | Moonshot China API key |
27
+
28
+ DeepSeek shows total, topped-up, and granted balances in the currency returned by the API. Moonshot shows available, cash, and voucher balances; this is separate from the Kimi For Coding subscription provider. Pi uses `MOONSHOT_API_KEY` for both Moonshot regions, so `/usage` automatically hides the expected authentication failure from the region where a shared environment key is not valid.
29
+
30
+ OpenRouter shows the account credit balance and current daily, weekly, and monthly key spend. If the API key has a configured credit limit, that limit is also rendered as a usage bar.
31
+
32
+ MiniMax Subscription Keys can represent an active Token Plan, purchased Credits, or both. The extension shows quota windows when present and a neutral credit-balance line if a first-party key-authenticated response exposes `points_balance`/`credits_balance`. MiniMax currently exposes Credits-only balances through a console endpoint requiring browser-cookie authentication, so a key-only Credits account is shown as “No active Token Plan” with a direction to check the console rather than a fabricated percentage. The extension does not import browser cookies.
20
33
 
21
34
  Google Gemini CLI and Google Antigravity are not supported because Pi removed those built-in providers in version 0.71.0.
22
35
 
@@ -43,11 +56,17 @@ pi install https://github.com/hknet/pi-usage-bars
43
56
 
44
57
  Restart Pi after installation, or use `/reload` when the package is already installed.
45
58
 
59
+ Update an existing npm installation with:
60
+
61
+ ```bash
62
+ pi update npm:@hk_net/pi-usage-bars
63
+ ```
64
+
46
65
  ## Use
47
66
 
48
67
  ### Footer usage bars
49
68
 
50
- When the active model belongs to a configured supported provider, the footer shows session and weekly usage with reset countdowns when available.
69
+ When the active model belongs to a configured supported provider, the footer shows its available quota windows with reset countdowns when provided by the service.
51
70
 
52
71
  ![Claude footer bar](https://raw.githubusercontent.com/hknet/pi-usage-bars/main/assets/claude.png)
53
72
 
@@ -61,17 +80,31 @@ Run `/usage` to open a searchable list of configured supported providers.
61
80
 
62
81
  ## Endpoint configuration
63
82
 
64
- The ZAI monitoring endpoints can be overridden:
83
+ First-party monitoring endpoints can be overridden:
65
84
 
66
85
  | Variable | Default |
67
86
  | --- | --- |
68
87
  | `PI_ZAI_USAGE_ENDPOINT` | `https://api.z.ai/api/monitor/usage/quota/limit` |
69
88
  | `PI_ZAI_CODING_CN_USAGE_ENDPOINT` | `https://open.bigmodel.cn/api/monitor/usage/quota/limit` |
89
+ | `PI_KIMI_USAGE_ENDPOINT` | `https://api.kimi.com/coding/v1/usages` |
90
+ | `PI_MINIMAX_USAGE_ENDPOINT` | `https://api.minimax.io/v1/token_plan/remains` |
91
+ | `PI_MINIMAX_LEGACY_USAGE_ENDPOINT` | `https://api.minimax.io/v1/api/openplatform/coding_plan/remains` |
92
+ | `PI_MINIMAX_CN_USAGE_ENDPOINT` | `https://api.minimaxi.com/v1/token_plan/remains` |
93
+ | `PI_MINIMAX_CN_LEGACY_USAGE_ENDPOINT` | `https://api.minimaxi.com/v1/api/openplatform/coding_plan/remains` |
94
+ | `PI_OPENROUTER_CREDITS_ENDPOINT` | `https://openrouter.ai/api/v1/credits` |
95
+ | `PI_OPENROUTER_KEY_ENDPOINT` | `https://openrouter.ai/api/v1/key` |
96
+ | `PI_DEEPSEEK_BALANCE_ENDPOINT` | `https://api.deepseek.com/user/balance` |
97
+ | `PI_MOONSHOT_BALANCE_ENDPOINT` | `https://api.moonshot.ai/v1/users/me/balance` |
98
+ | `PI_MOONSHOT_CN_BALANCE_ENDPOINT` | `https://api.moonshot.cn/v1/users/me/balance` |
70
99
 
71
100
  **Security:** the corresponding provider token is sent as a bearer token to the configured endpoint. Only override these variables with an endpoint you trust.
72
101
 
73
102
  The Codex and Claude usage endpoints are fixed to their first-party services. Claude responses are cached briefly in the system temporary directory to coordinate multiple Pi processes and reduce rate limiting. The cache contains usage values, not credentials.
74
103
 
104
+ ## Financial metrics roadmap
105
+
106
+ Quota percentages and monetary account data have different meaning and color semantics. OpenRouter, DeepSeek, Moonshot, and MiniMax financial data are rendered as neutral account values; percentages are used only when an actual limit exists. See [Financial metrics plan](docs/financial-metrics-plan.md) for the normalized model and future provider rollout.
107
+
75
108
  ## Development
76
109
 
77
110
  Install Node.js 22.19+ and Bun 1.3, then run:
@@ -83,9 +116,12 @@ npm run check
83
116
 
84
117
  `npm run check` performs a strict TypeScript check, runs the Bun test suite, and smoke-loads the extension with the pinned current Pi release.
85
118
 
119
+ Maintainers should follow the complete [release and npm publication guide](docs/releasing.md). npm publication is manual; pushing a Git tag does not publish automatically.
120
+
86
121
  ## Credits
87
122
 
88
123
  This extension is based on and inspired by:
89
124
 
90
125
  - [CodexBar](https://github.com/steipete/CodexBar)
91
126
  - [rho usage-bars](https://github.com/mikeyobrien/rho/tree/main/extensions/usage-bars)
127
+ - [ajarellanod/pi-usage-bars](https://github.com/ajarellanod/pi-usage-bars)
@@ -0,0 +1,75 @@
1
+ # Financial metrics plan
2
+
3
+ ## Goal
4
+
5
+ Add an optional account-value view without treating balances and spend as subscription quota. Quota usage increases toward exhaustion; a balance decreases toward exhaustion; spend may be meaningful only relative to a budget. Those metrics must retain distinct labels and color rules.
6
+
7
+ ## Normalized model
8
+
9
+ A future core revision should replace the two fixed quota fields with a list of typed metrics:
10
+
11
+ ```ts
12
+ type UsageMetric =
13
+ | {
14
+ kind: "quota";
15
+ id: string;
16
+ label: string;
17
+ usedPercent: number;
18
+ resetsAt?: string;
19
+ }
20
+ | {
21
+ kind: "money";
22
+ id: string;
23
+ label: string;
24
+ currency: string;
25
+ balance?: number;
26
+ spent?: number;
27
+ limit?: number;
28
+ period?: "day" | "week" | "month" | "lifetime";
29
+ resetsAt?: string;
30
+ };
31
+ ```
32
+
33
+ Provider fetchers should return normalized metrics. Rendering, not provider parsing, decides which metrics appear in the footer or `/usage` dialog.
34
+
35
+ ## View behavior
36
+
37
+ The initial OpenRouter implementation displays both balance and spend in `/usage`. The footer prefers the balance and current-month spend, while a configured per-key limit remains the primary bar. A later persistent view setting may provide:
38
+
39
+ - `auto`: prefer quota windows; otherwise show a financial summary.
40
+ - `balance`: show remaining prepaid/credit balance.
41
+ - `spent`: show spend and a percentage only when a real limit or budget exists.
42
+ - `off`: retain quota-only behavior.
43
+
44
+ No environment variable or config key is reserved for that future view selector yet.
45
+
46
+ Color semantics:
47
+
48
+ - quota `usedPercent`: high is bad;
49
+ - balance: low remaining balance is bad only when a known starting balance or warning threshold exists;
50
+ - spend/limit: high is bad;
51
+ - unconstrained spend and raw balance: neutral colors, never a manufactured percentage.
52
+
53
+ ## Provider rollout
54
+
55
+ 1. **OpenRouter — implemented in 0.4.0**
56
+ - `GET /api/v1/credits`: purchased credits, total usage, derived balance.
57
+ - `GET /api/v1/key`: configured key limit and daily/weekly/monthly spend where supplied.
58
+ - Uses only the API key resolved through Pi's provider registry.
59
+ 2. **Balance providers**
60
+ - DeepSeek and Moonshot/Kimi API prepaid balances are implemented in 0.4.0 using their official key-authenticated endpoints.
61
+ - Mistral balance or monthly-plan data when available through an API credential.
62
+ - MiniMax purchased Credits have a limited provider-specific implementation: when a first-party key-authenticated quota response includes `points_balance` or `credits_balance`, it is rendered neutrally. In current MiniMax deployments, the dedicated `/backend/account/token_plan_credit` endpoint requires browser-cookie authentication and does not accept the Subscription Key, so it remains out of scope. API status `2062` is rendered as a neutral “No active Token Plan” account state and never converted into a quota percentage.
63
+ 3. **Spend providers**
64
+ - OpenAI organization spend requires an Admin API key and therefore should appear only when Pi can resolve an appropriate credential.
65
+ - AWS Bedrock spend requires explicit Cost Explorer permissions and should remain a separate opt-in integration.
66
+
67
+ Browser cookies and direct reads of Pi's credential files remain out of scope.
68
+
69
+ ## Migration steps
70
+
71
+ 1. Introduce `UsageMetric` alongside the existing `session`/`weekly` compatibility fields.
72
+ 2. Convert quota fetchers and both renderers to metric lists.
73
+ 3. Add persistent view selection; neutral financial formatting is already covered by OpenRouter tests.
74
+ 4. Add further key-authenticated financial providers beyond OpenRouter, DeepSeek, and Moonshot.
75
+ 5. Remove compatibility fields only in a documented major release.
@@ -0,0 +1,84 @@
1
+ # Releasing
2
+
3
+ This repository uses semantic versions. The package version, changelog heading, Git tag, and npm version must agree.
4
+
5
+ Local publication uses npm browser authentication. The GitHub Actions publish workflow is manual-only; pushing a tag does not publish the package.
6
+
7
+ ## Prerequisites
8
+
9
+ - Write access to `hknet/pi-usage-bars`.
10
+ - Publish access to the npm scope `@hk_net`.
11
+ - Node.js 22.19 or newer.
12
+ - A clean, synchronized `main` branch.
13
+
14
+ Never place an npm token in the repository, command history, or endpoint configuration. Complete npm's browser or OTP authorization when prompted.
15
+
16
+ ## Recommended release script
17
+
18
+ From the repository root, provide the exact new semantic version:
19
+
20
+ ```bash
21
+ cd /path/to/pi-usage-bars
22
+ scripts/release.sh 0.4.1
23
+ ```
24
+
25
+ This **default command only prepares the release**. It deliberately stops before npm login or publication, so the pushed release commit can be reviewed first. The launcher first executes an immutable temporary copy of itself, so editing the script while a release is running cannot corrupt that run.
26
+
27
+ Preparation:
28
+
29
+ 1. verifies that `main` is clean and synchronized with `origin/main`;
30
+ 2. rejects an existing npm version or Git tag;
31
+ 3. updates `package.json` and `package-lock.json` without creating an early tag;
32
+ 4. promotes the `Unreleased` changelog entries into a dated release while preserving an empty `Unreleased` heading;
33
+ 5. installs dependencies with `npm ci --no-audit`, provisions a temporary pinned Bun binary, and runs typecheck, tests, detailed dependency audits, and package dry-run; and
34
+ 6. commits and pushes the release source.
35
+
36
+ After reviewing the prepared commit, stage it for browser approval:
37
+
38
+ ```bash
39
+ scripts/release.sh 0.4.1 stage
40
+ ```
41
+
42
+ `stage` submits the package to npm's staged-publishing queue. It **does not publish live**, does not open a browser, and does not tag Git. If npm authentication is needed, run `npm login --auth-type=web` manually first.
43
+
44
+ In [npmjs.com](https://www.npmjs.com), open **Staged Packages**, review the staged tarball, and click **Approve**. npm prompts for 2FA during approval. After npm shows the version as live, finalize the release:
45
+
46
+ ```bash
47
+ scripts/release.sh 0.4.1 finalize
48
+ ```
49
+
50
+ `finalize` refuses to run until the exact version is live in the npm registry. It then verifies registry metadata and creates/pushes the annotated Git tag. It never stages or publishes a package.
51
+
52
+ Use `--yes` only for attended preparation:
53
+
54
+ ```bash
55
+ scripts/release.sh 0.4.1 --yes # prepare only
56
+ ```
57
+
58
+ ## Recovery
59
+
60
+ Staging and finalization are safe to rerun: `stage` refuses if the exact version is already live, and `finalize` refuses until it is live. Never force-push a release tag.
61
+
62
+ The release script first prints a full dependency audit with package names, dependency paths, affected ranges, and available fixes. This is informational because it includes development-only dependencies. It then runs a blocking production-only audit, which rejects high or critical production findings.
63
+
64
+ Show script help with:
65
+
66
+ ```bash
67
+ scripts/release.sh --help
68
+ ```
69
+
70
+ ## Post-release verification
71
+
72
+ Confirm installation through Pi:
73
+
74
+ ```bash
75
+ pi install npm:@hk_net/pi-usage-bars
76
+ # If already installed from npm:
77
+ pi update npm:@hk_net/pi-usage-bars
78
+ ```
79
+
80
+ Restart Pi, or use `/reload`, then run `/usage`.
81
+
82
+ ## GitHub Actions alternative
83
+
84
+ The **Publish to npm (manual)** workflow is available as an alternative. It requires the `NPM_TOKEN` repository secret and publishes with npm provenance. Do not run it after publishing the same version locally.