opencode-usage-limits 0.3.3 → 0.3.4
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 +145 -85
- package/CHANGELOG.zh-CN.md +139 -0
- package/README.md +100 -93
- package/README.zh-CN.md +173 -0
- package/dist/tui.js +5 -164
- package/package.json +3 -3
- package/CHANGELOG.en.md +0 -167
- package/README.en.md +0 -184
package/README.md
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
[](./LICENSE)
|
|
6
6
|
[](https://opencode.ai/v2/docs/)
|
|
7
7
|
|
|
8
|
-
>
|
|
8
|
+
> Show your subscription usage limits (5-hour / weekly / monthly) in the OpenCode sidebar.
|
|
9
9
|
|
|
10
|
-
[
|
|
10
|
+
[English](./README.md) · [简体中文](./README.zh-CN.md)
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
**OpenCode Go**
|
|
14
|
-
|
|
12
|
+
An [OpenCode](https://opencode.ai/v2/docs/) **V2 TUI plugin**. When the selected model belongs
|
|
13
|
+
to **OpenCode Go** or **ClinePass**, a usage block appears automatically in the sidebar, showing
|
|
14
|
+
the percentage, a progress bar and the reset countdown for three rolling windows.
|
|
15
15
|
|
|
16
16
|
```text
|
|
17
17
|
▾ USAGE · OpenCode Go
|
|
@@ -26,53 +26,55 @@ Weekly 1%
|
|
|
26
26
|
Monthly 60%
|
|
27
27
|
███████████████████░░░░░░░░░░░░░░░░░
|
|
28
28
|
↻ 7d 14h
|
|
29
|
-
|
|
30
|
-
deepseek-v4.1-flash $100/$200
|
|
31
29
|
```
|
|
32
30
|
|
|
33
|
-
##
|
|
34
|
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- **Two usage sources**: OpenCode Go and ClinePass, switched automatically by the current model.
|
|
34
|
+
- **Three windows**: rolling 5 hours / weekly / monthly, with percentage, bar and reset countdown.
|
|
35
|
+
- **Green / yellow / red**: < 50% green, 50–79% yellow, ≥ 80% red (thresholds live in `core.ts`).
|
|
36
|
+
- **Spend display**: ClinePass shows `used / limit` (caps read live from `/users/me/plan`, $10 / $25 / $50);
|
|
37
|
+
OpenCode Go shows **percentages only** — the official per-model allowances change too often to ship a
|
|
38
|
+
built-in table, so no dollar figures are shown for it.
|
|
39
|
+
- **Collapsible**: click the title row to collapse to a single line; the state is persisted.
|
|
40
|
+
- **Unobtrusive**: nothing is rendered for any other provider, so it never takes up space.
|
|
41
|
+
- **Rate-limit backoff**: 429 / 5xx / network failures back off exponentially (capped at 5 minutes) and show `retry in Ns`.
|
|
42
|
+
- **Stale-data warning**: once a reading is older than ~75 seconds (2.5 polling intervals) the title row
|
|
43
|
+
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 through OpenCode's credential API (v2 keeps credentials in
|
|
45
|
+
its database), with `auth.json` as a fallback; the plugin stores nothing.
|
|
46
|
+
|
|
47
|
+
## Supported sources
|
|
48
|
+
|
|
49
|
+
| Provider ID | Name | Usage endpoint | Spend shown |
|
|
49
50
|
| --- | --- | --- | --- |
|
|
50
|
-
| `opencode-go` | [OpenCode Go](https://opencode.ai/zh/go) | `GET https://opencode.ai/zen/go/v1/usage` |
|
|
51
|
-
| `cline-pass` | [ClinePass](https://docs.cline.bot/getting-started/clinepass) | `GET https://api.cline.bot/api/v1/users/me/plan/usage-limits` |
|
|
51
|
+
| `opencode-go` | [OpenCode Go](https://opencode.ai/zh/go) | `GET https://opencode.ai/zen/go/v1/usage` | No (percentages only) |
|
|
52
|
+
| `cline-pass` | [ClinePass](https://docs.cline.bot/getting-started/clinepass) | `GET https://api.cline.bot/api/v1/users/me/plan/usage-limits` | Yes (plan caps read live from `/users/me/plan`) |
|
|
52
53
|
|
|
53
|
-
> Cline
|
|
54
|
+
> Cline's public documentation is at [Cline API](https://docs.cline.bot/api/overview).
|
|
54
55
|
|
|
55
|
-
##
|
|
56
|
+
## Requirements
|
|
56
57
|
|
|
57
|
-
- [OpenCode](https://opencode.ai/v2/docs/) **v2.0.0
|
|
58
|
-
-
|
|
59
|
-
-
|
|
58
|
+
- [OpenCode](https://opencode.ai/v2/docs/) **v2.0.0 or newer**
|
|
59
|
+
- An **OpenCode Go** or **ClinePass** subscription connected via `/connect`
|
|
60
|
+
- Network access to the matching usage endpoint (see the table above)
|
|
60
61
|
|
|
61
|
-
##
|
|
62
|
+
## Install
|
|
62
63
|
|
|
63
|
-
|
|
64
|
+
**From npm (recommended)**:
|
|
64
65
|
|
|
65
66
|
```sh
|
|
66
67
|
opencode plugin add opencode-usage-limits
|
|
67
68
|
```
|
|
68
69
|
|
|
69
|
-
|
|
70
|
+
Restart the TUI afterwards. A Git specifier works too:
|
|
70
71
|
|
|
71
72
|
```sh
|
|
72
73
|
opencode plugin add github:GamingNowEdward/opencode-usage-limits
|
|
73
74
|
```
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
**From a local directory**: add the plugin directory to OpenCode's CLI config `cli.json`
|
|
77
|
+
(global path: `~/.config/opencode/cli.json`):
|
|
76
78
|
|
|
77
79
|
```jsonc
|
|
78
80
|
{
|
|
@@ -85,91 +87,96 @@ opencode plugin add github:GamingNowEdward/opencode-usage-limits
|
|
|
85
87
|
}
|
|
86
88
|
```
|
|
87
89
|
|
|
88
|
-
CLI
|
|
89
|
-
|
|
90
|
+
CLI plugins run inside the local TUI process, so they can call OpenCode's credential API and reach
|
|
91
|
+
the network directly, and they stay active even when the CLI is connected to a remote server. See the
|
|
92
|
+
[CLI plugin documentation](https://opencode.ai/v2/docs/build/plugins/cli).
|
|
90
93
|
|
|
91
|
-
##
|
|
94
|
+
## Usage
|
|
92
95
|
|
|
93
|
-
-
|
|
94
|
-
-
|
|
95
|
-
-
|
|
96
|
+
- Select any model from `opencode-go` or `cline-pass` and the matching block appears in the sidebar.
|
|
97
|
+
- **Click the title row** to collapse/expand, or search **Toggle usage panel** in the command palette.
|
|
98
|
+
- Switch to another provider and the block disappears.
|
|
96
99
|
|
|
97
|
-
##
|
|
100
|
+
## Options
|
|
98
101
|
|
|
99
|
-
|
|
|
102
|
+
| Option | Type | Default | Description |
|
|
100
103
|
| --- | --- | --- | --- |
|
|
101
|
-
| `refreshMs` | number | `30000` |
|
|
102
|
-
| `limits` | object | — |
|
|
104
|
+
| `refreshMs` | number | `30000` | Polling interval in milliseconds |
|
|
105
|
+
| `limits` | object | — | ClinePass fallback only, used when the plan read fails, e.g. `{ "cline-pass": { "hour5": 10, "weekly": 25, "monthly": 50 } }` |
|
|
103
106
|
|
|
104
|
-
|
|
107
|
+
Thresholds and colours live in the source: `WARN_AT` / `DANGER_AT` in `core.ts`, `readPalette` in `tui.tsx`.
|
|
105
108
|
|
|
106
|
-
##
|
|
109
|
+
## How it works
|
|
107
110
|
|
|
108
|
-
|
|
111
|
+
In `setup()` the plugin does three things:
|
|
109
112
|
|
|
110
|
-
1.
|
|
111
|
-
2.
|
|
112
|
-
3.
|
|
113
|
-
|
|
113
|
+
1. **Registers a sidebar slot**: `context.ui.slot({ prepend: "sidebar.content", ... })`.
|
|
114
|
+
2. **Reads the current model**: `context.ui.model.current()?.providerID` (reactive).
|
|
115
|
+
3. **Fetches usage per provider**: resolves the key through `context.client.credential.list()`
|
|
116
|
+
(OpenCode v2's authoritative store), calls the usage endpoint with `Authorization: Bearer`,
|
|
117
|
+
polls every 30 seconds and ticks the countdown every second.
|
|
114
118
|
|
|
115
|
-
|
|
116
|
-
`~/.local/share/opencode/auth.json
|
|
117
|
-
|
|
119
|
+
Key resolution order: the `<PROVIDER>_API_KEY` environment variable →
|
|
120
|
+
`context.client.credential.list()` → `~/.local/share/opencode/auth.json`. OpenCode v2 keeps login
|
|
121
|
+
credentials in the `credential` table of `opencode.db`; `auth.json` is the legacy path only.
|
|
118
122
|
|
|
119
|
-
|
|
120
|
-
|
|
123
|
+
When the host exposes `GET /api/experimental/usage/limits`, OpenCode Go uses that payload directly
|
|
124
|
+
and needs no key at all.
|
|
121
125
|
|
|
122
|
-
##
|
|
126
|
+
## File layout
|
|
123
127
|
|
|
124
|
-
|
|
|
128
|
+
| File | Purpose |
|
|
125
129
|
| --- | --- |
|
|
126
|
-
| [`tui.tsx`](./tui.tsx) | TUI
|
|
127
|
-
| [`core.ts`](./core.ts) |
|
|
128
|
-
| [`index.ts`](./index.ts) |
|
|
129
|
-
| [`tui.ts`](./tui.ts) |
|
|
130
|
-
| [`dist/tui.js`](./dist/tui.js) |
|
|
131
|
-
| [`scripts/build.mjs`](./scripts/build.mjs) |
|
|
132
|
-
| [`preview.mjs`](./preview.mjs) |
|
|
133
|
-
| [`AGENTS.md`](./AGENTS.md) |
|
|
134
|
-
| [`CHANGELOG.md`](./CHANGELOG.md) |
|
|
135
|
-
|
|
136
|
-
>
|
|
137
|
-
>
|
|
138
|
-
>
|
|
139
|
-
>
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
130
|
+
| [`tui.tsx`](./tui.tsx) | The TUI plugin itself (JSX source) |
|
|
131
|
+
| [`core.ts`](./core.ts) | Auth, API client, formatting, thresholds (pure logic, no JSX) |
|
|
132
|
+
| [`index.ts`](./index.ts) | Server entrypoint (no-op) |
|
|
133
|
+
| [`tui.ts`](./tui.ts) | Local-development discovery entry, re-exports `tui.tsx` |
|
|
134
|
+
| [`dist/tui.js`](./dist/tui.js) | **Published artifact**: `tui.tsx` compiled and bundled (`exports["./tui"]` points here) |
|
|
135
|
+
| [`scripts/build.mjs`](./scripts/build.mjs) | Build script (babel-preset-solid + esbuild) |
|
|
136
|
+
| [`preview.mjs`](./preview.mjs) | Offline preview script |
|
|
137
|
+
| [`AGENTS.md`](./AGENTS.md) | Development conventions |
|
|
138
|
+
| [`CHANGELOG.md`](./CHANGELOG.md) | Changelog |
|
|
139
|
+
|
|
140
|
+
> Why the package ships compiled output: OpenCode only applies its Solid JSX transform to plugin files
|
|
141
|
+
> **outside** `node_modules`. Shipping raw `.tsx` meant Bun transpiled the plugin on the user's machine,
|
|
142
|
+
> injecting an unresolvable `@opentui/solid/jsx-dev-runtime` import, so the plugin failed at load time
|
|
143
|
+
> (see [#2](https://github.com/GamingNowEdward/opencode-usage-limits/issues/2)). After editing `tui.tsx`,
|
|
144
|
+
> run `npm run build` and commit `dist/tui.js`.
|
|
145
|
+
|
|
146
|
+
## Offline preview
|
|
147
|
+
|
|
148
|
+
Verify the API and layout without starting the TUI (it reads your real local key):
|
|
144
149
|
|
|
145
150
|
```powershell
|
|
146
|
-
node preview.mjs #
|
|
147
|
-
node preview.mjs cline-pass #
|
|
151
|
+
node preview.mjs # both sources
|
|
152
|
+
node preview.mjs cline-pass # a single source
|
|
148
153
|
```
|
|
149
154
|
|
|
150
|
-
##
|
|
155
|
+
## Troubleshooting
|
|
151
156
|
|
|
152
|
-
1.
|
|
153
|
-
2.
|
|
154
|
-
`dist/tui.js
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
1. Make sure the current model belongs to `opencode-go` or `cline-pass`.
|
|
158
|
+
2. When developing from a local directory, plugin files **hot reload on save**, but the bundle must be
|
|
159
|
+
rebuilt first: run `npm run dev` to watch the source and update `dist/tui.js`. The host loads that
|
|
160
|
+
artifact, not `tui.tsx`.
|
|
161
|
+
3. Check the log: `~/.local/share/opencode/log/opencode.log`, filter by `role=cli` and `plugin`.
|
|
162
|
+
A `stage=load` failure mentioning `Cannot find package '@opentui/solid'` means you are on 0.3.1 or
|
|
163
|
+
earlier; upgrading to 0.3.2+ fixes it (see the [CHANGELOG](./CHANGELOG.md)).
|
|
164
|
+
4. If the panel shows **API key not found**, check the login first:
|
|
159
165
|
|
|
160
166
|
```sh
|
|
161
167
|
opencode auth list
|
|
162
168
|
```
|
|
163
169
|
|
|
164
|
-
|
|
165
|
-
|
|
170
|
+
When it says `stored` but the panel still fails, the host release is too old to expose the
|
|
171
|
+
credential API. As a workaround, set the `<PROVIDER>_API_KEY` environment variable (for example
|
|
172
|
+
`OPENCODE_GO_API_KEY`) and restart the TUI.
|
|
166
173
|
|
|
167
|
-
##
|
|
174
|
+
## See also
|
|
168
175
|
|
|
169
|
-
- [OpenCode V2
|
|
170
|
-
- [
|
|
171
|
-
-
|
|
176
|
+
- [OpenCode V2 documentation](https://opencode.ai/v2/docs/)
|
|
177
|
+
- [Building plugins](https://opencode.ai/v2/docs/build/plugins) · [CLI plugins](https://opencode.ai/v2/docs/build/plugins/cli)
|
|
178
|
+
- Similar community plugin: [leleor/opencode-usage-limits-sidebar](https://github.com/leleor/opencode-usage-limits-sidebar)
|
|
172
179
|
|
|
173
|
-
##
|
|
180
|
+
## License
|
|
174
181
|
|
|
175
182
|
[MIT](./LICENSE) © 2026 GamingNowEdward
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# usage-limits
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/opencode-usage-limits)
|
|
4
|
+
[](https://www.npmjs.com/package/opencode-usage-limits)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
[](https://opencode.ai/v2/docs/)
|
|
7
|
+
|
|
8
|
+
> 在 OpenCode 右侧侧边栏实时显示订阅方案的用量限额(5 小时 / 周 / 月)。
|
|
9
|
+
|
|
10
|
+
[English](./README.md) · [简体中文](./README.zh-CN.md)
|
|
11
|
+
|
|
12
|
+
一个 [OpenCode](https://opencode.ai/v2/docs/) **V2 TUI 插件**。当当前选中的模型属于
|
|
13
|
+
**OpenCode Go** 或 **ClinePass** 时,右侧侧边栏会自动出现用量区块,展示三个滚动窗口的
|
|
14
|
+
占用百分比、进度条与重置倒计时。
|
|
15
|
+
|
|
16
|
+
```text
|
|
17
|
+
▾ USAGE · OpenCode Go
|
|
18
|
+
5 hours 0%
|
|
19
|
+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
20
|
+
↻ 5h
|
|
21
|
+
|
|
22
|
+
Weekly 1%
|
|
23
|
+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
|
|
24
|
+
↻ 6d 4h
|
|
25
|
+
|
|
26
|
+
Monthly 60%
|
|
27
|
+
███████████████████░░░░░░░░░░░░░░░░░
|
|
28
|
+
↻ 7d 14h
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 功能
|
|
32
|
+
|
|
33
|
+
- **两个用量来源**:OpenCode Go、ClinePass,按当前模型自动切换。
|
|
34
|
+
- **三个窗口**:5 小时滚动 / 周 / 月,含百分比、进度条、重置倒计时。
|
|
35
|
+
- **绿黄红提醒**:< 50% 绿、50–79% 黄、≥ 80% 红(阈值见 `core.ts`)。
|
|
36
|
+
- **金额显示**:ClinePass 显示 `已用 / 限额`(限额从 `/users/me/plan` 实时读取,$10 / $25 / $50);OpenCode Go **只显示百分比**——官方每模型额度调整频繁,不再内置金额表。
|
|
37
|
+
- **整体折叠**:点标题行收起,只留一行;状态持久化,重启保持。
|
|
38
|
+
- **不打扰**:选中其他 provider 时**完全不渲染**,不占空间。
|
|
39
|
+
- **限流退避**:遇 429 / 5xx / 网络失败自动指数退避(最长 5 分钟),并显示 `retry in Ns`。
|
|
40
|
+
- **数据过期提示**:数据变旧(超过约 75 秒,即 2.5 个轮询间隔)时,标题行才显示年龄并变黄;平时不显示,不产生噪音。
|
|
41
|
+
- **密钥安全**:通过 OpenCode 的凭据 API 实时读取(v2 把凭据存在自己的数据库中),
|
|
42
|
+
`auth.json` 仅作兜底;插件不存储任何凭据。
|
|
43
|
+
|
|
44
|
+
## 支持的数据源
|
|
45
|
+
|
|
46
|
+
| Provider ID | 名称 | 用量接口 | 显示金额 |
|
|
47
|
+
| --- | --- | --- | --- |
|
|
48
|
+
| `opencode-go` | [OpenCode Go](https://opencode.ai/zh/go) | `GET https://opencode.ai/zen/go/v1/usage` | 否(仅百分比) |
|
|
49
|
+
| `cline-pass` | [ClinePass](https://docs.cline.bot/getting-started/clinepass) | `GET https://api.cline.bot/api/v1/users/me/plan/usage-limits` | 是(从 `/users/me/plan` 实时读取套餐上限) |
|
|
50
|
+
|
|
51
|
+
> Cline 的公开文档见 [Cline API](https://docs.cline.bot/api/overview)。
|
|
52
|
+
|
|
53
|
+
## 要求
|
|
54
|
+
|
|
55
|
+
- [OpenCode](https://opencode.ai/v2/docs/) **v2.0.0 或更高版本**
|
|
56
|
+
- 已通过 `/connect` 连接 **OpenCode Go** 或 **ClinePass** 订阅
|
|
57
|
+
- 能访问对应用量接口的网络环境(端点见上方数据源表)
|
|
58
|
+
|
|
59
|
+
## 安装
|
|
60
|
+
|
|
61
|
+
**从 npm 安装(推荐)**:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
opencode plugin add opencode-usage-limits
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
装完重启 TUI 即可。也可使用 Git 规格安装:
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
opencode plugin add github:GamingNowEdward/opencode-usage-limits
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**从本地目录安装**:把插件目录加入 OpenCode 的 CLI 配置 `cli.json`(全局位于 `~/.config/opencode/cli.json`):
|
|
74
|
+
|
|
75
|
+
```jsonc
|
|
76
|
+
{
|
|
77
|
+
"plugins": [
|
|
78
|
+
{
|
|
79
|
+
"package": "C:/path/to/opencode-usage-limits",
|
|
80
|
+
"options": { "refreshMs": 30000 }
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
CLI 插件在本地 TUI 进程内运行,因此可以调用 OpenCode 的凭据 API 与访问网络;它也会在连接
|
|
87
|
+
远程 server 时保持可用。详见 [CLI 插件文档](https://opencode.ai/v2/docs/build/plugins/cli)。
|
|
88
|
+
|
|
89
|
+
## 使用
|
|
90
|
+
|
|
91
|
+
- 选中 `opencode-go` 或 `cline-pass` 的任意模型,侧边栏即出现对应区块。
|
|
92
|
+
- **点击标题行**折叠 / 展开,或在命令面板搜索 **Toggle usage panel**。
|
|
93
|
+
- 切换到其他 provider 时区块自动消失。
|
|
94
|
+
|
|
95
|
+
## 配置项
|
|
96
|
+
|
|
97
|
+
| 选项 | 类型 | 默认 | 说明 |
|
|
98
|
+
| --- | --- | --- | --- |
|
|
99
|
+
| `refreshMs` | number | `30000` | 轮询间隔(毫秒) |
|
|
100
|
+
| `limits` | object | — | 仅作 ClinePass 的回退:套餐上限读取失败时使用,如 `{ "cline-pass": { "hour5": 10, "weekly": 25, "monthly": 50 } }` |
|
|
101
|
+
|
|
102
|
+
配色阈值写在源码中:`core.ts` 的 `WARN_AT` / `DANGER_AT`,`tui.tsx` 的 `readPalette`。
|
|
103
|
+
|
|
104
|
+
## 工作原理
|
|
105
|
+
|
|
106
|
+
插件在 `setup()` 中做三件事:
|
|
107
|
+
|
|
108
|
+
1. **注册侧边栏 slot**:`context.ui.slot({ prepend: "sidebar.content", ... })`。
|
|
109
|
+
2. **读取当前模型**:`context.ui.model.current()?.providerID`(响应式)。
|
|
110
|
+
3. **按 provider 拉取用量**:通过 `context.client.credential.list()` 取密钥(OpenCode v2 的
|
|
111
|
+
权威来源),带 `Authorization: Bearer` 请求用量接口,30 秒轮询一次,1 秒刷新倒计时。
|
|
112
|
+
|
|
113
|
+
密钥解析顺序:环境变量 `<PROVIDER>_API_KEY` → `context.client.credential.list()` →
|
|
114
|
+
`~/.local/share/opencode/auth.json`。OpenCode v2 把登录凭据存在 `opencode.db` 的 `credential`
|
|
115
|
+
表中,`auth.json` 只是旧版兼容路径。
|
|
116
|
+
|
|
117
|
+
若宿主版本提供 `GET /api/experimental/usage/limits`,OpenCode Go 会直接使用该接口返回的用量,
|
|
118
|
+
完全不需要密钥。
|
|
119
|
+
|
|
120
|
+
## 文件结构
|
|
121
|
+
|
|
122
|
+
| 文件 | 说明 |
|
|
123
|
+
| --- | --- |
|
|
124
|
+
| [`tui.tsx`](./tui.tsx) | TUI 插件主体(JSX 源码) |
|
|
125
|
+
| [`core.ts`](./core.ts) | 鉴权、API 客户端、格式化、阈值(纯逻辑,无 JSX) |
|
|
126
|
+
| [`index.ts`](./index.ts) | server 入口(no-op) |
|
|
127
|
+
| [`tui.ts`](./tui.ts) | 本地开发用的发现入口,re-export `tui.tsx` |
|
|
128
|
+
| [`dist/tui.js`](./dist/tui.js) | **发布产物**:`tui.tsx` 编译打包后的入口(`exports["./tui"]` 指向它) |
|
|
129
|
+
| [`scripts/build.mjs`](./scripts/build.mjs) | 构建脚本(babel-preset-solid + esbuild) |
|
|
130
|
+
| [`preview.mjs`](./preview.mjs) | 离线预览脚本 |
|
|
131
|
+
| [`AGENTS.md`](./AGENTS.md) | 开发约定 |
|
|
132
|
+
| [`CHANGELOG.zh-CN.md`](./CHANGELOG.zh-CN.md) | 变更日志 |
|
|
133
|
+
|
|
134
|
+
> 为什么发布编译产物:OpenCode 只对 `node_modules` **之外**的插件文件应用自带的 Solid JSX 转换。
|
|
135
|
+
> 若直接发布 `.tsx`,npm 安装后由 Bun 自行转译,会注入无法解析的 `@opentui/solid/jsx-dev-runtime`
|
|
136
|
+
> 导入,插件在加载阶段即失败(见 [#2](https://github.com/GamingNowEdward/opencode-usage-limits/issues/2))。
|
|
137
|
+
> 修改 `tui.tsx` 后请运行 `npm run build` 并提交 `dist/tui.js`。
|
|
138
|
+
|
|
139
|
+
## 离线预览
|
|
140
|
+
|
|
141
|
+
无需启动 TUI 即可验证接口与排版(会读取你本机的真实密钥):
|
|
142
|
+
|
|
143
|
+
```powershell
|
|
144
|
+
node preview.mjs # 两个来源
|
|
145
|
+
node preview.mjs cline-pass # 只预览一个
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## 排障
|
|
149
|
+
|
|
150
|
+
1. 确认当前模型属于 `opencode-go` 或 `cline-pass`。
|
|
151
|
+
2. 从本地目录开发时,插件文件**保存即热重载**,但需要先重建产物:`npm run dev` 监听源码并更新
|
|
152
|
+
`dist/tui.js`;宿主加载的是该产物,不是 `tui.tsx`。
|
|
153
|
+
3. 查看日志:`~/.local/share/opencode/log/opencode.log`,筛 `role=cli` 与 `plugin`。
|
|
154
|
+
若出现 `stage=load` 且报 `Cannot find package '@opentui/solid'`,说明装到了 0.3.1 或更早版本,
|
|
155
|
+
升级到 0.3.2+ 即可(详见 [CHANGELOG](./CHANGELOG.zh-CN.md))。
|
|
156
|
+
4. 面板显示 **API key not found** 时,先确认登录状态:
|
|
157
|
+
|
|
158
|
+
```sh
|
|
159
|
+
opencode auth list
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
若已显示 `stored` 但面板仍报错,说明宿主版本过旧,无法通过凭据 API 读取密钥;
|
|
163
|
+
可临时设置环境变量 `<PROVIDER>_API_KEY`(如 `OPENCODE_GO_API_KEY`)后重启 TUI。
|
|
164
|
+
|
|
165
|
+
## 相关
|
|
166
|
+
|
|
167
|
+
- [OpenCode V2 文档](https://opencode.ai/v2/docs/)
|
|
168
|
+
- [插件开发](https://opencode.ai/v2/docs/build/plugins) · [CLI 插件](https://opencode.ai/v2/docs/build/plugins/cli)
|
|
169
|
+
- 社区同类插件:[leleor/opencode-usage-limits-sidebar](https://github.com/leleor/opencode-usage-limits-sidebar)
|
|
170
|
+
|
|
171
|
+
## 许可
|
|
172
|
+
|
|
173
|
+
[MIT](./LICENSE) © 2026 GamingNowEdward
|
package/dist/tui.js
CHANGED
|
@@ -20,9 +20,8 @@ var PROVIDERS = {
|
|
|
20
20
|
title: "OpenCode Go",
|
|
21
21
|
baseUrl: "https://opencode.ai/zen/go/v1",
|
|
22
22
|
path: "/usage"
|
|
23
|
-
// No dollar budgets: the usage API only reports percentages,
|
|
24
|
-
//
|
|
25
|
-
// separately (see GO_MODEL_ALLOWANCE).
|
|
23
|
+
// No dollar budgets: the usage API only reports percentages, so the panel
|
|
24
|
+
// shows percentages, bars and reset countdowns for this provider.
|
|
26
25
|
},
|
|
27
26
|
"cline-pass": {
|
|
28
27
|
id: "cline-pass",
|
|
@@ -32,130 +31,6 @@ var PROVIDERS = {
|
|
|
32
31
|
planPath: "/users/me/plan"
|
|
33
32
|
}
|
|
34
33
|
};
|
|
35
|
-
var GO_MODEL_ALLOWANCE = {
|
|
36
|
-
"beam-free": "free",
|
|
37
|
-
"claude-haiku-5-5": {
|
|
38
|
-
go: 15,
|
|
39
|
-
plus: 60
|
|
40
|
-
},
|
|
41
|
-
"deepseek-v4-pro": {
|
|
42
|
-
go: 15,
|
|
43
|
-
plus: 60
|
|
44
|
-
},
|
|
45
|
-
"deepseek-v4.1-flash": {
|
|
46
|
-
go: 100,
|
|
47
|
-
plus: 200
|
|
48
|
-
},
|
|
49
|
-
"gemini-4-argon": {
|
|
50
|
-
go: 30,
|
|
51
|
-
plus: 120
|
|
52
|
-
},
|
|
53
|
-
"glm-5.2": {
|
|
54
|
-
go: 60,
|
|
55
|
-
plus: 180
|
|
56
|
-
},
|
|
57
|
-
"glm-5.3": {
|
|
58
|
-
go: 15,
|
|
59
|
-
plus: 120
|
|
60
|
-
},
|
|
61
|
-
"glm-5.3-flash": {
|
|
62
|
-
go: 60,
|
|
63
|
-
plus: 180
|
|
64
|
-
},
|
|
65
|
-
"gpt-5.6-luna": {
|
|
66
|
-
go: 15,
|
|
67
|
-
plus: 60
|
|
68
|
-
},
|
|
69
|
-
"gpt-6-luna": {
|
|
70
|
-
go: 15,
|
|
71
|
-
plus: 60
|
|
72
|
-
},
|
|
73
|
-
"grok-4.7": {
|
|
74
|
-
go: 15,
|
|
75
|
-
plus: 60
|
|
76
|
-
},
|
|
77
|
-
hy3: {
|
|
78
|
-
go: 60,
|
|
79
|
-
plus: 240
|
|
80
|
-
},
|
|
81
|
-
hy4: {
|
|
82
|
-
go: 60,
|
|
83
|
-
plus: 240
|
|
84
|
-
},
|
|
85
|
-
"hy4-preview": {
|
|
86
|
-
go: 30,
|
|
87
|
-
plus: 120
|
|
88
|
-
},
|
|
89
|
-
"iceman-contributor-free": "free",
|
|
90
|
-
"kimi-k2.7-code": {
|
|
91
|
-
go: 60,
|
|
92
|
-
plus: 180
|
|
93
|
-
},
|
|
94
|
-
"kimi-k3": {
|
|
95
|
-
go: 15,
|
|
96
|
-
plus: 60
|
|
97
|
-
},
|
|
98
|
-
"kimi-k3.1-pro": {
|
|
99
|
-
go: 15,
|
|
100
|
-
plus: 60
|
|
101
|
-
},
|
|
102
|
-
"longcat-2.0": {
|
|
103
|
-
go: 60,
|
|
104
|
-
plus: 240
|
|
105
|
-
},
|
|
106
|
-
"mimo-v2.5": {
|
|
107
|
-
go: 60,
|
|
108
|
-
plus: 120
|
|
109
|
-
},
|
|
110
|
-
"mimo-v2.5-pro": {
|
|
111
|
-
go: 15,
|
|
112
|
-
plus: 60
|
|
113
|
-
},
|
|
114
|
-
"mimo-v2.6-flash": {
|
|
115
|
-
go: 60,
|
|
116
|
-
plus: 120
|
|
117
|
-
},
|
|
118
|
-
"mimo-v2.6-pro": {
|
|
119
|
-
go: 15,
|
|
120
|
-
plus: 60
|
|
121
|
-
},
|
|
122
|
-
"minimax-m3": {
|
|
123
|
-
go: 60,
|
|
124
|
-
plus: 180
|
|
125
|
-
},
|
|
126
|
-
"minimax-m3.1-flash": {
|
|
127
|
-
go: 20,
|
|
128
|
-
plus: 80
|
|
129
|
-
},
|
|
130
|
-
"muse-spark-1.2-contributor": {
|
|
131
|
-
go: 60,
|
|
132
|
-
plus: 120
|
|
133
|
-
},
|
|
134
|
-
"muse-spark-1.3-contributor": {
|
|
135
|
-
go: 60,
|
|
136
|
-
plus: 120
|
|
137
|
-
},
|
|
138
|
-
"qwen3.7-plus": {
|
|
139
|
-
go: 60,
|
|
140
|
-
plus: 180
|
|
141
|
-
},
|
|
142
|
-
"qwen3.8-flash": {
|
|
143
|
-
go: 30,
|
|
144
|
-
plus: 90
|
|
145
|
-
},
|
|
146
|
-
"qwen3.8-max": {
|
|
147
|
-
go: 15,
|
|
148
|
-
plus: 60
|
|
149
|
-
},
|
|
150
|
-
"step-5-preview": {
|
|
151
|
-
go: 15,
|
|
152
|
-
plus: 60
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
function modelAllowance(modelID) {
|
|
156
|
-
if (!modelID) return void 0;
|
|
157
|
-
return GO_MODEL_ALLOWANCE[modelID];
|
|
158
|
-
}
|
|
159
34
|
var WINDOW_LABEL = {
|
|
160
35
|
hour5: "5 hours",
|
|
161
36
|
weekly: "Weekly",
|
|
@@ -538,18 +413,10 @@ function UsagePanel(props) {
|
|
|
538
413
|
const ctx = props.context;
|
|
539
414
|
const palette = createMemo(() => readPalette(ctx.theme));
|
|
540
415
|
const providerID = createMemo(() => ctx.ui.model.current()?.providerID);
|
|
541
|
-
const modelID = createMemo(() => ctx.ui.model.current()?.modelID);
|
|
542
416
|
const config = createMemo(() => {
|
|
543
417
|
const id = providerID();
|
|
544
418
|
return id ? resolveProvider(id, ctx.options) : void 0;
|
|
545
419
|
});
|
|
546
|
-
const allowanceText = createMemo(() => {
|
|
547
|
-
if (providerID() !== "opencode-go") return "";
|
|
548
|
-
const allowance = modelAllowance(modelID());
|
|
549
|
-
if (allowance === "free") return "\u221E";
|
|
550
|
-
if (!allowance) return "\u2014";
|
|
551
|
-
return `$${allowance.go}/$${allowance.plus}`;
|
|
552
|
-
});
|
|
553
420
|
const [windows, setWindows] = createSignal([]);
|
|
554
421
|
const [loading, setLoading] = createSignal(false);
|
|
555
422
|
const [error, setError] = createSignal("");
|
|
@@ -744,39 +611,13 @@ function UsagePanel(props) {
|
|
|
744
611
|
return now();
|
|
745
612
|
}
|
|
746
613
|
})
|
|
747
|
-
}), _$createComponent(Show, {
|
|
748
|
-
get when() {
|
|
749
|
-
return allowanceText() !== "";
|
|
750
|
-
},
|
|
751
|
-
get children() {
|
|
752
|
-
var _el$19 = _$createElement("box"), _el$20 = _$createElement("box"), _el$21 = _$createElement("text"), _el$22 = _$createElement("text");
|
|
753
|
-
_$insertNode(_el$19, _el$20);
|
|
754
|
-
_$insertNode(_el$19, _el$22);
|
|
755
|
-
_$setProp(_el$19, "flexDirection", "row");
|
|
756
|
-
_$setProp(_el$19, "width", "100%");
|
|
757
|
-
_$setProp(_el$19, "marginTop", 1);
|
|
758
|
-
_$insertNode(_el$20, _el$21);
|
|
759
|
-
_$setProp(_el$20, "flexGrow", 1);
|
|
760
|
-
_$insert(_el$21, () => modelID() ?? "");
|
|
761
|
-
_$insert(_el$22, allowanceText);
|
|
762
|
-
_$effect((_p$) => {
|
|
763
|
-
var _v$8 = palette().text, _v$9 = palette().text;
|
|
764
|
-
_v$8 !== _p$.e && (_p$.e = _$setProp(_el$21, "fg", _v$8, _p$.e));
|
|
765
|
-
_v$9 !== _p$.t && (_p$.t = _$setProp(_el$22, "fg", _v$9, _p$.t));
|
|
766
|
-
return _p$;
|
|
767
|
-
}, {
|
|
768
|
-
e: void 0,
|
|
769
|
-
t: void 0
|
|
770
|
-
});
|
|
771
|
-
return _el$19;
|
|
772
|
-
}
|
|
773
614
|
})];
|
|
774
615
|
}
|
|
775
616
|
}), null);
|
|
776
617
|
_$effect((_p$) => {
|
|
777
|
-
var _v$
|
|
778
|
-
_v$
|
|
779
|
-
_v$
|
|
618
|
+
var _v$8 = palette().text, _v$9 = isStale() && !loading() ? palette().warn : palette().muted;
|
|
619
|
+
_v$8 !== _p$.e && (_p$.e = _$setProp(_el$15, "fg", _v$8, _p$.e));
|
|
620
|
+
_v$9 !== _p$.t && (_p$.t = _$setProp(_el$16, "fg", _v$9, _p$.t));
|
|
780
621
|
return _p$;
|
|
781
622
|
}, {
|
|
782
623
|
e: void 0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-usage-limits",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Show OpenCode Go and ClinePass subscription usage (5-hour / weekly / monthly) in the OpenCode TUI sidebar.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"index.ts",
|
|
33
33
|
"dist/tui.js",
|
|
34
34
|
"README.md",
|
|
35
|
-
"README.
|
|
35
|
+
"README.zh-CN.md",
|
|
36
36
|
"CHANGELOG.md",
|
|
37
|
-
"CHANGELOG.
|
|
37
|
+
"CHANGELOG.zh-CN.md",
|
|
38
38
|
"LICENSE"
|
|
39
39
|
],
|
|
40
40
|
"scripts": {
|