opencode-usage-limits 0.3.0 → 0.3.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/CHANGELOG.en.md +40 -0
- package/CHANGELOG.md +35 -0
- package/README.en.md +42 -12
- package/README.md +37 -11
- package/dist/tui.js +822 -0
- package/package.json +24 -9
- package/core.ts +0 -380
- package/tui.ts +0 -3
- package/tui.tsx +0 -319
package/CHANGELOG.en.md
CHANGED
|
@@ -6,6 +6,46 @@ All notable changes to `usage-limits` are documented here. The format is based o
|
|
|
6
6
|
|
|
7
7
|
[简体中文](./CHANGELOG.md) · [English](./CHANGELOG.en.md)
|
|
8
8
|
|
|
9
|
+
## 0.3.2 - 2026-11-05
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- **The plugin failed to load entirely when installed from npm**
|
|
14
|
+
([#2](https://github.com/GamingNowEdward/opencode-usage-limits/issues/2)): 0.3.1 shipped raw `.tsx`
|
|
15
|
+
source, but OpenCode only runs its own Solid Babel transform on plugin files that live **outside**
|
|
16
|
+
`node_modules`. In an npm-installed plugin directory the source is transpiled by Bun alone, which
|
|
17
|
+
injects an `@opentui/solid/jsx-dev-runtime` import from the `@jsxImportSource` pragma. That injection
|
|
18
|
+
happens *after* the host rewrote the source imports, so it falls back to Bun's native resolution —
|
|
19
|
+
and `@opentui/solid` is an optional peer that npm never installs. The result was a `stage=load`
|
|
20
|
+
failure: no sidebar block and no entry in the plugin list. The package now ships **compiled output**:
|
|
21
|
+
`tui.tsx` is compiled with `babel-preset-solid { generate: "universal", moduleName: "@opentui/solid" }`
|
|
22
|
+
and bundled into `dist/tui.js`, which `exports["./tui"]` points at. The artifact only contains explicit
|
|
23
|
+
`@opentui/solid` / `solid-js` / `@opencode/plugin/tui` imports, which the host rewrites to its own runtime.
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- Added `scripts/build.mjs` (`npm run build`; `npm run dev` watches), run automatically before publishing
|
|
28
|
+
through `prepack`.
|
|
29
|
+
- The published package no longer contains `tui.tsx` / `tui.ts` / `core.ts`, only `dist/tui.js` and
|
|
30
|
+
`index.ts`. The `.tsx` source stays in the repository for local development.
|
|
31
|
+
|
|
32
|
+
### Thanks
|
|
33
|
+
|
|
34
|
+
- Thanks to [@third774](https://github.com/third774) for reporting the problem, pinpointing the injected
|
|
35
|
+
JSX runtime path, and verifying the compiled-output approach — 0.3.2 adopts that option.
|
|
36
|
+
|
|
37
|
+
## 0.3.1 - 2026-10-26
|
|
38
|
+
|
|
39
|
+
### Fixed
|
|
40
|
+
|
|
41
|
+
- **The panel broke once OpenCode v2.1 moved credentials**: v2 migrated login credentials from
|
|
42
|
+
`auth.json` to the `credential` table in `opencode.db`, but the plugin still read `auth.json`, so
|
|
43
|
+
selecting OpenCode Go always showed `API key not found`. Keys are now read through
|
|
44
|
+
`context.client.credential.list()`, with `auth.json` as a fallback only.
|
|
45
|
+
- **Prefer the host usage endpoint**: when the host exposes `GET /api/experimental/usage/limits`,
|
|
46
|
+
OpenCode Go uses that payload directly (no key at all); older releases fall back to the Zen endpoint.
|
|
47
|
+
- `preview.mjs` now reads credentials from `opencode.db` too, so the panel can be verified without the TUI.
|
|
48
|
+
|
|
9
49
|
## 0.3.0 - 2026-10-13
|
|
10
50
|
|
|
11
51
|
### Changed
|
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,41 @@
|
|
|
4
4
|
|
|
5
5
|
[简体中文](./CHANGELOG.md) · [English](./CHANGELOG.en.md)
|
|
6
6
|
|
|
7
|
+
## 0.3.2 - 2026-11-05
|
|
8
|
+
|
|
9
|
+
### 修复
|
|
10
|
+
|
|
11
|
+
- **npm 安装后插件完全无法加载**([#2](https://github.com/GamingNowEdward/opencode-usage-limits/issues/2)):
|
|
12
|
+
0.3.1 直接发布 `.tsx` 源码,而 OpenCode 只对 **node_modules 之外**的插件文件运行自带的 Solid
|
|
13
|
+
Babel 转换。npm 安装的插件目录里,源码由 Bun 自行转译,会按 `@jsxImportSource` 注入
|
|
14
|
+
`@opentui/solid/jsx-dev-runtime` 导入;该注入发生在宿主重写 import 之后,于是回到 Bun 原生解析,
|
|
15
|
+
而 `@opentui/solid` 是可选 peer、npm 不会安装,最终 `stage=load` 失败,侧边栏不出现、插件列表也没有条目。
|
|
16
|
+
现在改为**发布编译产物**:`tui.tsx` 经 `babel-preset-solid { generate: "universal",
|
|
17
|
+
moduleName: "@opentui/solid" }` 编译并打包为 `dist/tui.js`,`exports["./tui"]` 指向该文件。
|
|
18
|
+
产物中只有显式的 `@opentui/solid` / `solid-js` / `@opencode/plugin/tui` 导入,宿主可以正常重写到自己的运行时。
|
|
19
|
+
|
|
20
|
+
### 变更
|
|
21
|
+
|
|
22
|
+
- 新增构建脚本 `scripts/build.mjs`(`npm run build`;`npm run dev` 为监听模式),发布前由 `prepack` 自动执行。
|
|
23
|
+
- 发布包不再包含 `tui.tsx` / `tui.ts` / `core.ts`,仅包含 `dist/tui.js` 与 `index.ts`。
|
|
24
|
+
仓库内仍保留 `.tsx` 源码,供本地开发使用。
|
|
25
|
+
|
|
26
|
+
### 致谢
|
|
27
|
+
|
|
28
|
+
- 感谢 [@third774](https://github.com/third774) 报告该问题、定位到 JSX 运行时注入路径,并先行
|
|
29
|
+
验证了「发布编译产物」这一方案;0.3.2 采用的是该方案。
|
|
30
|
+
|
|
31
|
+
## 0.3.1 - 2026-10-26
|
|
32
|
+
|
|
33
|
+
### 修复
|
|
34
|
+
|
|
35
|
+
- **OpenCode v2.1+ 凭据迁移导致面板失效**:v2 把登录凭据从 `auth.json` 迁移到 `opencode.db`
|
|
36
|
+
的 `credential` 表,插件仍只读 `auth.json`,因此选中 OpenCode Go 时固定显示
|
|
37
|
+
`API key not found`。现在优先通过 `context.client.credential.list()` 读取,`auth.json` 仅作兜底。
|
|
38
|
+
- **优先使用宿主用量接口**:宿主提供 `GET /api/experimental/usage/limits` 时,OpenCode Go 直接使用
|
|
39
|
+
该接口(无需密钥);旧版本自动回退到 Zen 用量接口。
|
|
40
|
+
- `preview.mjs` 同步支持从 `opencode.db` 读取凭据,便于在不启动 TUI 的情况下验证。
|
|
41
|
+
|
|
7
42
|
## 0.3.0 - 2026-10-13
|
|
8
43
|
|
|
9
44
|
### 变更
|
package/README.en.md
CHANGED
|
@@ -17,15 +17,17 @@ the percentage, a progress bar and the reset countdown for three rolling windows
|
|
|
17
17
|
▾ USAGE · OpenCode Go
|
|
18
18
|
5 hours 0%
|
|
19
19
|
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
20
|
-
↻ 5h
|
|
20
|
+
↻ 5h
|
|
21
21
|
|
|
22
22
|
Weekly 1%
|
|
23
23
|
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
24
|
-
↻ 6d 4h
|
|
24
|
+
↻ 6d 4h
|
|
25
25
|
|
|
26
26
|
Monthly 60%
|
|
27
27
|
███████████████████░░░░░░░░░░░░░░░░░
|
|
28
|
-
↻ 7d 14h
|
|
28
|
+
↻ 7d 14h
|
|
29
|
+
|
|
30
|
+
deepseek-v4.1-flash $80/$160
|
|
29
31
|
```
|
|
30
32
|
|
|
31
33
|
## Features
|
|
@@ -41,7 +43,8 @@ Monthly 60%
|
|
|
41
43
|
- **Rate-limit backoff**: 429 / 5xx / network failures back off exponentially (capped at 5 minutes) and show `retry in Ns`.
|
|
42
44
|
- **Stale-data warning**: once a reading is older than ~75 seconds (2.5 polling intervals) the title row
|
|
43
45
|
shows its age in yellow; while the data is fresh nothing is shown, so there is no constant noise.
|
|
44
|
-
- **Key safety**: the API key is read live
|
|
46
|
+
- **Key safety**: the API key is read live through OpenCode's credential API (v2 keeps credentials in
|
|
47
|
+
its database), with `auth.json` as a fallback; the plugin stores nothing.
|
|
45
48
|
|
|
46
49
|
## Supported sources
|
|
47
50
|
|
|
@@ -86,8 +89,8 @@ opencode plugin add github:GamingNowEdward/opencode-usage-limits
|
|
|
86
89
|
}
|
|
87
90
|
```
|
|
88
91
|
|
|
89
|
-
CLI plugins run inside the local TUI process, so they can
|
|
90
|
-
directly, and they stay active even when the CLI is connected to a remote server. See the
|
|
92
|
+
CLI plugins run inside the local TUI process, so they can call OpenCode's credential API and reach
|
|
93
|
+
the network directly, and they stay active even when the CLI is connected to a remote server. See the
|
|
91
94
|
[CLI plugin documentation](https://opencode.ai/v2/docs/build/plugins/cli).
|
|
92
95
|
|
|
93
96
|
## Usage
|
|
@@ -111,23 +114,37 @@ In `setup()` the plugin does three things:
|
|
|
111
114
|
|
|
112
115
|
1. **Registers a sidebar slot**: `context.ui.slot({ prepend: "sidebar.content", ... })`.
|
|
113
116
|
2. **Reads the current model**: `context.ui.model.current()?.providerID` (reactive).
|
|
114
|
-
3. **Fetches usage per provider**: resolves the key
|
|
115
|
-
|
|
117
|
+
3. **Fetches usage per provider**: resolves the key through `context.client.credential.list()`
|
|
118
|
+
(OpenCode v2's authoritative store), calls the usage endpoint with `Authorization: Bearer`,
|
|
119
|
+
polls every 30 seconds and ticks the countdown every second.
|
|
120
|
+
|
|
121
|
+
Key resolution order: the `<PROVIDER>_API_KEY` environment variable →
|
|
122
|
+
`context.client.credential.list()` → `~/.local/share/opencode/auth.json`. OpenCode v2 keeps login
|
|
123
|
+
credentials in the `credential` table of `opencode.db`; `auth.json` is the legacy path only.
|
|
116
124
|
|
|
117
|
-
|
|
125
|
+
When the host exposes `GET /api/experimental/usage/limits`, OpenCode Go uses that payload directly
|
|
126
|
+
and needs no key at all.
|
|
118
127
|
|
|
119
128
|
## File layout
|
|
120
129
|
|
|
121
130
|
| File | Purpose |
|
|
122
131
|
| --- | --- |
|
|
123
|
-
| [`tui.tsx`](./tui.tsx) | The TUI plugin itself |
|
|
132
|
+
| [`tui.tsx`](./tui.tsx) | The TUI plugin itself (JSX source) |
|
|
124
133
|
| [`core.ts`](./core.ts) | Auth, API client, formatting, thresholds (pure logic, no JSX) |
|
|
125
134
|
| [`index.ts`](./index.ts) | Server entrypoint (no-op) |
|
|
126
|
-
| [`tui.ts`](./tui.ts) |
|
|
135
|
+
| [`tui.ts`](./tui.ts) | Local-development discovery entry, re-exports `tui.tsx` |
|
|
136
|
+
| [`dist/tui.js`](./dist/tui.js) | **Published artifact**: `tui.tsx` compiled and bundled (`exports["./tui"]` points here) |
|
|
137
|
+
| [`scripts/build.mjs`](./scripts/build.mjs) | Build script (babel-preset-solid + esbuild) |
|
|
127
138
|
| [`preview.mjs`](./preview.mjs) | Offline preview script |
|
|
128
139
|
| [`AGENTS.md`](./AGENTS.md) | Development conventions |
|
|
129
140
|
| [`CHANGELOG.md`](./CHANGELOG.md) | Changelog |
|
|
130
141
|
|
|
142
|
+
> Why the package ships compiled output: OpenCode only applies its Solid JSX transform to plugin files
|
|
143
|
+
> **outside** `node_modules`. Shipping raw `.tsx` meant Bun transpiled the plugin on the user's machine,
|
|
144
|
+
> injecting an unresolvable `@opentui/solid/jsx-dev-runtime` import, so the plugin failed at load time
|
|
145
|
+
> (see [#2](https://github.com/GamingNowEdward/opencode-usage-limits/issues/2)). After editing `tui.tsx`,
|
|
146
|
+
> run `npm run build` and commit `dist/tui.js`.
|
|
147
|
+
|
|
131
148
|
## Offline preview
|
|
132
149
|
|
|
133
150
|
Verify the API and layout without starting the TUI (it reads your real local key):
|
|
@@ -140,8 +157,21 @@ node preview.mjs cline-pass # a single source
|
|
|
140
157
|
## Troubleshooting
|
|
141
158
|
|
|
142
159
|
1. Make sure the current model belongs to `opencode-go` or `cline-pass`.
|
|
143
|
-
2.
|
|
160
|
+
2. When developing from a local directory, plugin files **hot reload on save**, but the bundle must be
|
|
161
|
+
rebuilt first: run `npm run dev` to watch the source and update `dist/tui.js`. The host loads that
|
|
162
|
+
artifact, not `tui.tsx`.
|
|
144
163
|
3. Check the log: `~/.local/share/opencode/log/opencode.log`, filter by `role=cli` and `plugin`.
|
|
164
|
+
A `stage=load` failure mentioning `Cannot find package '@opentui/solid'` means you are on 0.3.1 or
|
|
165
|
+
earlier; upgrading to 0.3.2+ fixes it (see the [CHANGELOG](./CHANGELOG.en.md)).
|
|
166
|
+
4. If the panel shows **API key not found**, check the login first:
|
|
167
|
+
|
|
168
|
+
```sh
|
|
169
|
+
opencode auth list
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
When it says `stored` but the panel still fails, the host release is too old to expose the
|
|
173
|
+
credential API. As a workaround, set the `<PROVIDER>_API_KEY` environment variable (for example
|
|
174
|
+
`OPENCODE_GO_API_KEY`) and restart the TUI.
|
|
145
175
|
|
|
146
176
|
## See also
|
|
147
177
|
|
package/README.md
CHANGED
|
@@ -17,15 +17,17 @@
|
|
|
17
17
|
▾ USAGE · OpenCode Go
|
|
18
18
|
5 hours 0%
|
|
19
19
|
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
20
|
-
↻ 5h
|
|
20
|
+
↻ 5h
|
|
21
21
|
|
|
22
22
|
Weekly 1%
|
|
23
23
|
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
24
|
-
↻ 6d 4h
|
|
24
|
+
↻ 6d 4h
|
|
25
25
|
|
|
26
26
|
Monthly 60%
|
|
27
27
|
███████████████████░░░░░░░░░░░░░░░░░
|
|
28
|
-
↻ 7d 14h
|
|
28
|
+
↻ 7d 14h
|
|
29
|
+
|
|
30
|
+
deepseek-v4.1-flash $80/$160
|
|
29
31
|
```
|
|
30
32
|
|
|
31
33
|
## 功能
|
|
@@ -38,7 +40,8 @@ Monthly 60%
|
|
|
38
40
|
- **不打扰**:选中其他 provider 时**完全不渲染**,不占空间。
|
|
39
41
|
- **限流退避**:遇 429 / 5xx / 网络失败自动指数退避(最长 5 分钟),并显示 `retry in Ns`。
|
|
40
42
|
- **数据过期提示**:数据变旧(超过约 75 秒,即 2.5 个轮询间隔)时,标题行才显示年龄并变黄;平时不显示,不产生噪音。
|
|
41
|
-
-
|
|
43
|
+
- **密钥安全**:通过 OpenCode 的凭据 API 实时读取(v2 把凭据存在自己的数据库中),
|
|
44
|
+
`auth.json` 仅作兜底;插件不存储任何凭据。
|
|
42
45
|
|
|
43
46
|
## 支持的数据源
|
|
44
47
|
|
|
@@ -82,7 +85,7 @@ opencode plugin add github:GamingNowEdward/opencode-usage-limits
|
|
|
82
85
|
}
|
|
83
86
|
```
|
|
84
87
|
|
|
85
|
-
CLI 插件在本地 TUI
|
|
88
|
+
CLI 插件在本地 TUI 进程内运行,因此可以调用 OpenCode 的凭据 API 与访问网络;它也会在连接
|
|
86
89
|
远程 server 时保持可用。详见 [CLI 插件文档](https://opencode.ai/v2/docs/build/plugins/cli)。
|
|
87
90
|
|
|
88
91
|
## 使用
|
|
@@ -106,23 +109,35 @@ CLI 插件在本地 TUI 进程内运行,因此可以直接读取 `auth.json`
|
|
|
106
109
|
|
|
107
110
|
1. **注册侧边栏 slot**:`context.ui.slot({ prepend: "sidebar.content", ... })`。
|
|
108
111
|
2. **读取当前模型**:`context.ui.model.current()?.providerID`(响应式)。
|
|
109
|
-
3. **按 provider
|
|
110
|
-
30 秒轮询一次,1 秒刷新倒计时。
|
|
112
|
+
3. **按 provider 拉取用量**:通过 `context.client.credential.list()` 取密钥(OpenCode v2 的
|
|
113
|
+
权威来源),带 `Authorization: Bearer` 请求用量接口,30 秒轮询一次,1 秒刷新倒计时。
|
|
114
|
+
|
|
115
|
+
密钥解析顺序:环境变量 `<PROVIDER>_API_KEY` → `context.client.credential.list()` →
|
|
116
|
+
`~/.local/share/opencode/auth.json`。OpenCode v2 把登录凭据存在 `opencode.db` 的 `credential`
|
|
117
|
+
表中,`auth.json` 只是旧版兼容路径。
|
|
111
118
|
|
|
112
|
-
|
|
119
|
+
若宿主版本提供 `GET /api/experimental/usage/limits`,OpenCode Go 会直接使用该接口返回的用量,
|
|
120
|
+
完全不需要密钥。
|
|
113
121
|
|
|
114
122
|
## 文件结构
|
|
115
123
|
|
|
116
124
|
| 文件 | 说明 |
|
|
117
125
|
| --- | --- |
|
|
118
|
-
| [`tui.tsx`](./tui.tsx) | TUI
|
|
126
|
+
| [`tui.tsx`](./tui.tsx) | TUI 插件主体(JSX 源码) |
|
|
119
127
|
| [`core.ts`](./core.ts) | 鉴权、API 客户端、格式化、阈值(纯逻辑,无 JSX) |
|
|
120
128
|
| [`index.ts`](./index.ts) | server 入口(no-op) |
|
|
121
|
-
| [`tui.ts`](./tui.ts) |
|
|
129
|
+
| [`tui.ts`](./tui.ts) | 本地开发用的发现入口,re-export `tui.tsx` |
|
|
130
|
+
| [`dist/tui.js`](./dist/tui.js) | **发布产物**:`tui.tsx` 编译打包后的入口(`exports["./tui"]` 指向它) |
|
|
131
|
+
| [`scripts/build.mjs`](./scripts/build.mjs) | 构建脚本(babel-preset-solid + esbuild) |
|
|
122
132
|
| [`preview.mjs`](./preview.mjs) | 离线预览脚本 |
|
|
123
133
|
| [`AGENTS.md`](./AGENTS.md) | 开发约定 |
|
|
124
134
|
| [`CHANGELOG.md`](./CHANGELOG.md) | 变更日志 |
|
|
125
135
|
|
|
136
|
+
> 为什么发布编译产物:OpenCode 只对 `node_modules` **之外**的插件文件应用自带的 Solid JSX 转换。
|
|
137
|
+
> 若直接发布 `.tsx`,npm 安装后由 Bun 自行转译,会注入无法解析的 `@opentui/solid/jsx-dev-runtime`
|
|
138
|
+
> 导入,插件在加载阶段即失败(见 [#2](https://github.com/GamingNowEdward/opencode-usage-limits/issues/2))。
|
|
139
|
+
> 修改 `tui.tsx` 后请运行 `npm run build` 并提交 `dist/tui.js`。
|
|
140
|
+
|
|
126
141
|
## 离线预览
|
|
127
142
|
|
|
128
143
|
无需启动 TUI 即可验证接口与排版(会读取你本机的真实密钥):
|
|
@@ -135,8 +150,19 @@ node preview.mjs cline-pass # 只预览一个
|
|
|
135
150
|
## 排障
|
|
136
151
|
|
|
137
152
|
1. 确认当前模型属于 `opencode-go` 或 `cline-pass`。
|
|
138
|
-
2.
|
|
153
|
+
2. 从本地目录开发时,插件文件**保存即热重载**,但需要先重建产物:`npm run dev` 监听源码并更新
|
|
154
|
+
`dist/tui.js`;宿主加载的是该产物,不是 `tui.tsx`。
|
|
139
155
|
3. 查看日志:`~/.local/share/opencode/log/opencode.log`,筛 `role=cli` 与 `plugin`。
|
|
156
|
+
若出现 `stage=load` 且报 `Cannot find package '@opentui/solid'`,说明装到了 0.3.1 或更早版本,
|
|
157
|
+
升级到 0.3.2+ 即可(详见 [CHANGELOG](./CHANGELOG.md))。
|
|
158
|
+
4. 面板显示 **API key not found** 时,先确认登录状态:
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
opencode auth list
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
若已显示 `stored` 但面板仍报错,说明宿主版本过旧,无法通过凭据 API 读取密钥;
|
|
165
|
+
可临时设置环境变量 `<PROVIDER>_API_KEY`(如 `OPENCODE_GO_API_KEY`)后重启 TUI。
|
|
140
166
|
|
|
141
167
|
## 相关
|
|
142
168
|
|