opencode-usage-limits 0.2.1 → 0.3.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/CHANGELOG.en.md CHANGED
@@ -6,6 +6,27 @@ 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.0 - 2026-10-13
10
+
11
+ ### Changed
12
+
13
+ - **OpenCode Go now shows percentages only.** The official allowances are **per model** ($15–$80, plus a
14
+ Go Plus tier), so the old flat `$12/$30/$60` no longer holds. Measurement also shows the percentage
15
+ cannot be turned into dollars: 84% monthly corresponded to $49.27 of actual 30-day spend, implying a
16
+ ~$59 allowance rather than $80. The `used / limit` row is therefore gone for Go.
17
+ - **New allowance reference line** at the bottom of the panel, showing the selected model and its
18
+ allowance (`deepseek-v4.1-flash $80/$160`) so you can tell how expensive the model is. The built-in
19
+ table covers the official **31 models**; unknown models show `—` and free models show `∞`. This line is
20
+ purely informational and takes no part in any calculation.
21
+ - The `limits` option is narrowed to a **ClinePass-only fallback** (used when the plan read fails);
22
+ OpenCode Go no longer accepts dollar budgets.
23
+ - **ClinePass is unchanged**: caps are still read live from `/users/me/plan` and `used / limit` stays accurate.
24
+
25
+ ### Fixed
26
+
27
+ - `formatUsd` threw `Cannot read properties of undefined` when a window had no limit; the amount text is
28
+ now computed safely instead of relying on a `<Show>` guard to prevent evaluation.
29
+
9
30
  ## 0.2.1 - 2026-10-06
10
31
 
11
32
  ### Docs
package/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@
4
4
 
5
5
  [简体中文](./CHANGELOG.md) · [English](./CHANGELOG.en.md)
6
6
 
7
+ ## 0.3.0 - 2026-10-13
8
+
9
+ ### 变更
10
+
11
+ - **OpenCode Go 改为只显示百分比**。官方额度已改成**按模型区分**($15–$80,另有 Go Plus 档),原有的统一 `$12/$30/$60` 不再成立。实测进一步表明百分比**不能**换算成美元:月度 84% 对应的 30 天实际花费为 $49.27,反推额度约 $59 而非 $80。因此移除了 Go 窗口的 `已用 / 限额` 行。
12
+ - **新增模型额度参考行**(放在面板底部):显示当前模型与其额度,如 `deepseek-v4.1-flash $80/$160`,用于判断该模型是贵还是便宜。内置官方 **31 个模型**的额度表;未收录的模型显示 `—`,免费模型显示 `∞`。该行**仅作参考,不参与任何计算**。
13
+ - `limits` 配置项收窄为 **ClinePass 专用回退**(套餐上限读取失败时使用);OpenCode Go 不再接受美元额度配置。
14
+ - **ClinePass 行为不变**:额度仍从 `/users/me/plan` 实时读取,`已用 / 限额` 保持准确。
15
+
16
+ ### 修复
17
+
18
+ - 额度缺失时 `formatUsd` 会抛 `Cannot read properties of undefined`;金额文本改为安全求值(不再依赖 `<Show>` 守卫拦住求值)。
19
+
7
20
  ## 0.2.1 - 2026-10-06
8
21
 
9
22
  ### 文档
package/README.en.md CHANGED
@@ -33,7 +33,9 @@ Monthly 60%
33
33
  - **Two usage sources**: OpenCode Go and ClinePass, switched automatically by the current model.
34
34
  - **Three windows**: rolling 5 hours / weekly / monthly, with percentage, bar and reset countdown.
35
35
  - **Green / yellow / red**: < 50% green, 50–79% yellow, ≥ 80% red (thresholds live in `core.ts`).
36
- - **Spend display**: OpenCode Go shows `used / limit` ($12 / $30 / $60); ClinePass reads its caps live from `/users/me/plan`.
36
+ - **Spend display**: ClinePass shows `used / limit` (caps read live from `/users/me/plan`, $10 / $25 / $50);
37
+ OpenCode Go shows percentages only, with the selected model's allowance (e.g. `$80/$160`) noted at the bottom
38
+ as a reference.
37
39
  - **Collapsible**: click the title row to collapse to a single line; the state is persisted.
38
40
  - **Unobtrusive**: nothing is rendered for any other provider, so it never takes up space.
39
41
  - **Rate-limit backoff**: 429 / 5xx / network failures back off exponentially (capped at 5 minutes) and show `retry in Ns`.
@@ -45,7 +47,7 @@ Monthly 60%
45
47
 
46
48
  | Provider ID | Name | Usage endpoint | Spend shown |
47
49
  | --- | --- | --- | --- |
48
- | `opencode-go` | [OpenCode Go](https://opencode.ai/docs/go) | `GET https://opencode.ai/zen/go/v1/usage` | Yes ($12 / $30 / $60) |
50
+ | `opencode-go` | [OpenCode Go](https://opencode.ai/zh/go) | `GET https://opencode.ai/zen/go/v1/usage` | No (percentages only; the model's allowance is noted at the bottom) |
49
51
  | `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`) |
50
52
 
51
53
  > Cline's public documentation is at [Cline API](https://docs.cline.bot/api/overview).
@@ -99,7 +101,7 @@ directly, and they stay active even when the CLI is connected to a remote server
99
101
  | Option | Type | Default | Description |
100
102
  | --- | --- | --- | --- |
101
103
  | `refreshMs` | number | `30000` | Polling interval in milliseconds |
102
- | `limits` | object | — | Overrides the built-in budgets, e.g. `{ "opencode-go": { "monthly": 100 } }` |
104
+ | `limits` | object | — | ClinePass fallback only, used when the plan read fails, e.g. `{ "cline-pass": { "hour5": 10, "weekly": 25, "monthly": 50 } }` |
103
105
 
104
106
  Thresholds and colours live in the source: `WARN_AT` / `DANGER_AT` in `core.ts`, `readPalette` in `tui.tsx`.
105
107
 
package/README.md CHANGED
@@ -33,7 +33,7 @@ Monthly 60%
33
33
  - **两个用量来源**:OpenCode Go、ClinePass,按当前模型自动切换。
34
34
  - **三个窗口**:5 小时滚动 / 周 / 月,含百分比、进度条、重置倒计时。
35
35
  - **绿黄红提醒**:< 50% 绿、50–79% 黄、≥ 80% 红(阈值见 `core.ts`)。
36
- - **金额显示**:OpenCode Go 显示 `已用 / 限额`($12 / $30 / $60);ClinePass 的限额从 `/users/me/plan` 实时读取。
36
+ - **金额显示**:ClinePass 显示 `已用 / 限额`(限额从 `/users/me/plan` 实时读取,$10 / $25 / $50);OpenCode Go 只显示百分比,并在**底部**标注当前模型的额度(如 `$80/$160`)供参考。
37
37
  - **整体折叠**:点标题行收起,只留一行;状态持久化,重启保持。
38
38
  - **不打扰**:选中其他 provider 时**完全不渲染**,不占空间。
39
39
  - **限流退避**:遇 429 / 5xx / 网络失败自动指数退避(最长 5 分钟),并显示 `retry in Ns`。
@@ -44,7 +44,7 @@ Monthly 60%
44
44
 
45
45
  | Provider ID | 名称 | 用量接口 | 显示金额 |
46
46
  | --- | --- | --- | --- |
47
- | `opencode-go` | [OpenCode Go](https://opencode.ai/docs/go) | `GET https://opencode.ai/zen/go/v1/usage` | 是($12 / $30 / $60) |
47
+ | `opencode-go` | [OpenCode Go](https://opencode.ai/zh/go) | `GET https://opencode.ai/zen/go/v1/usage` | 否(只显示百分比;底部标注当前模型额度) |
48
48
  | `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` 实时读取套餐上限) |
49
49
 
50
50
  > Cline 的公开文档见 [Cline API](https://docs.cline.bot/api/overview)。
@@ -96,7 +96,7 @@ CLI 插件在本地 TUI 进程内运行,因此可以直接读取 `auth.json`
96
96
  | 选项 | 类型 | 默认 | 说明 |
97
97
  | --- | --- | --- | --- |
98
98
  | `refreshMs` | number | `30000` | 轮询间隔(毫秒) |
99
- | `limits` | object | — | 覆盖内置额度,如 `{ "opencode-go": { "monthly": 100 } }` |
99
+ | `limits` | object | — | 仅作 ClinePass 的回退:套餐上限读取失败时使用,如 `{ "cline-pass": { "hour5": 10, "weekly": 25, "monthly": 50 } }` |
100
100
 
101
101
  配色阈值写在源码中:`core.ts` 的 `WARN_AT` / `DANGER_AT`,`tui.tsx` 的 `readPalette`。
102
102
 
package/core.ts CHANGED
@@ -36,7 +36,9 @@ export const PROVIDERS: Record<string, ProviderConfig> = {
36
36
  title: "OpenCode Go",
37
37
  baseUrl: "https://opencode.ai/zen/go/v1",
38
38
  path: "/usage",
39
- limits: { hour5: 12, weekly: 30, monthly: 60 },
39
+ // No dollar budgets: the usage API only reports percentages, and the
40
+ // per-model allowances on the pricing page are reference information shown
41
+ // separately (see GO_MODEL_ALLOWANCE).
40
42
  },
41
43
  "cline-pass": {
42
44
  id: "cline-pass",
@@ -47,6 +49,57 @@ export const PROVIDERS: Record<string, ProviderConfig> = {
47
49
  },
48
50
  }
49
51
 
52
+ export type PlanTier = "go" | "plus"
53
+
54
+ /**
55
+ * Monthly allowance per OpenCode Go model, by plan tier, taken from the
56
+ * official usage table at https://opencode.ai/zh/go.
57
+ *
58
+ * Reference only: it is displayed as "how expensive is this model", never used
59
+ * to derive spend. The usage API reports percentages and says nothing about
60
+ * which model an allowance belongs to, so converting a percentage into dollars
61
+ * would be guesswork.
62
+ */
63
+ export const GO_MODEL_ALLOWANCE: Record<string, Record<PlanTier, number> | "free"> = {
64
+ "kimi-k3": { go: 15, plus: 60 },
65
+ "qwen3.8-max": { go: 15, plus: 60 },
66
+ "grok-4.7": { go: 15, plus: 60 },
67
+ "grok-4.6": { go: 15, plus: 60 },
68
+ "glm-5.3": { go: 15, plus: 120 },
69
+ "glm-5.2": { go: 60, plus: 180 },
70
+ "deepseek-v4-pro": { go: 15, plus: 60 },
71
+ "kimi-k2.7-code": { go: 60, plus: 180 },
72
+ "hy4-preview": { go: 30, plus: 120 },
73
+ "gpt-5.6-luna": { go: 15, plus: 60 },
74
+ "space-bunny": { go: 30, plus: 120 },
75
+ "minimax-m3": { go: 60, plus: 180 },
76
+ "mimo-v2.6-pro": { go: 15, plus: 60 },
77
+ "mimo-v2.5-pro": { go: 15, plus: 60 },
78
+ "minimax-m2.7": { go: 60, plus: 240 },
79
+ "claude-haiku-5-5": { go: 15, plus: 60 },
80
+ "gpt-6-luna": { go: 15, plus: 60 },
81
+ "qwen3.7-plus": { go: 60, plus: 180 },
82
+ hy3: { go: 60, plus: 240 },
83
+ "qwen3.8-flash": { go: 30, plus: 90 },
84
+ "glm-5.3-flash": { go: 60, plus: 180 },
85
+ "deepseek-v4-flash-vision-exp": { go: 15, plus: 60 },
86
+ "longcat-2.0": { go: 60, plus: 240 },
87
+ "deepseek-v4-flash": { go: 30, plus: 120 },
88
+ "mimo-v2.6-flash": { go: 60, plus: 120 },
89
+ "mimo-v2.5": { go: 60, plus: 120 },
90
+ "deepseek-v4.1-flash": { go: 80, plus: 160 },
91
+ "muse-spark-1.3-contributor": { go: 60, plus: 120 },
92
+ "muse-spark-1.2-contributor": { go: 60, plus: 120 },
93
+ "longcat-2.5-preview-free": "free",
94
+ "step-5-preview-free": "free",
95
+ }
96
+
97
+ /** Allowance of an OpenCode Go model, or undefined when it is not in the table. */
98
+ export function modelAllowance(modelID: string | undefined): Record<PlanTier, number> | "free" | undefined {
99
+ if (!modelID) return undefined
100
+ return GO_MODEL_ALLOWANCE[modelID]
101
+ }
102
+
50
103
  const WINDOW_LABEL: Record<WindowKind, string> = {
51
104
  hour5: "5 hours",
52
105
  weekly: "Weekly",
@@ -223,8 +276,11 @@ export function isTransient(error: unknown): boolean {
223
276
 
224
277
  /**
225
278
  * Fetch the three usage windows for a provider.
226
- * OpenCode Go reports percentages and we map them onto its $12/$30/$60 budgets.
227
- * ClinePass reports percentages only, so no dollar amount is shown.
279
+ *
280
+ * OpenCode Go reports percentages only; the per-model dollar allowances on the
281
+ * pricing page are reference information and are never converted into "spend".
282
+ * ClinePass reports percentages plus a plan document whose caps ARE real
283
+ * dollars, so its windows carry a limit and the panel can show used / limit.
228
284
  */
229
285
  export async function fetchUsage(config: ProviderConfig, key: string, timeoutMs = 10000): Promise<UsageWindow[]> {
230
286
  const url = config.baseUrl.replace(/\/$/, "") + config.path
@@ -255,7 +311,7 @@ export async function fetchUsage(config: ProviderConfig, key: string, timeoutMs
255
311
  const src = sources[kind]
256
312
  if (!src) continue
257
313
  const status = typeof src.status === "string" ? src.status : undefined
258
- windows.push(buildWindow(kind, Number(src.percent) || 0, toMs(src.resetsAt), config.limits, status))
314
+ windows.push(buildWindow(kind, Number(src.percent) || 0, toMs(src.resetsAt), undefined, status))
259
315
  }
260
316
  if (windows.length === 0) throw new Error("usage API returned an unexpected shape")
261
317
  return windows
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-usage-limits",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
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",
package/tui.tsx CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  formatUsd,
10
10
  isTransient,
11
11
  isWindowLimited,
12
+ modelAllowance,
12
13
  resetText,
13
14
  resolveKey,
14
15
  resolveProvider,
@@ -72,12 +73,18 @@ function ProgressBar(props: { percent: number; color: any; track: any }) {
72
73
  function WindowRow(props: { window: UsageWindow; palette: Palette; now: number }) {
73
74
  const pct = () => clampPercent(props.window.percent)
74
75
  const color = () => severityColor(props.palette, props.window)
75
- const used = () => usedUsd(props.window)
76
- const hasAmount = () => used() != null && props.window.limit != null
77
76
  const limited = () => isWindowLimited(props.window)
78
77
  // Memoised so the ticking clock only writes to the DOM when the rendered text
79
78
  // actually changes (Solid memos compare with ===).
80
79
  const resetLabel = createMemo(() => `↻ ${resetText(props.window.resetsAt, props.now)}`)
80
+ // Only providers with a real dollar cap (ClinePass) have one; computing this
81
+ // here keeps the Show guard from being the only thing preventing a crash on
82
+ // an undefined amount.
83
+ const amountText = createMemo(() => {
84
+ const used = usedUsd(props.window)
85
+ if (used == null || props.window.limit == null) return ""
86
+ return `${formatUsd(used)} / ${formatUsd(props.window.limit)}`
87
+ })
81
88
 
82
89
  return (
83
90
  <box flexDirection="column" width="100%" marginTop={1}>
@@ -94,8 +101,8 @@ function WindowRow(props: { window: UsageWindow; palette: Palette; now: number }
94
101
  <box flexDirection="row" width="100%">
95
102
  <text fg={props.palette.muted}>{resetLabel()}</text>
96
103
  <box flexGrow={1} />
97
- <Show when={hasAmount()}>
98
- <text fg={props.palette.muted}>{`${formatUsd(used() as number)} / ${formatUsd(props.window.limit as number)}`}</text>
104
+ <Show when={amountText() !== ""}>
105
+ <text fg={props.palette.muted}>{amountText()}</text>
99
106
  </Show>
100
107
  </box>
101
108
  </box>
@@ -106,11 +113,22 @@ function UsagePanel(props: { context: any; panel: any; toggle: () => void }) {
106
113
  const ctx = props.context
107
114
  const palette = createMemo<Palette>(() => readPalette(ctx.theme))
108
115
  const providerID = createMemo<string | undefined>(() => ctx.ui.model.current()?.providerID)
116
+ const modelID = createMemo<string | undefined>(() => ctx.ui.model.current()?.modelID)
109
117
  const config = createMemo(() => {
110
118
  const id = providerID()
111
119
  return id ? resolveProvider(id, ctx.options) : undefined
112
120
  })
113
121
 
122
+ // How expensive the selected model is, shown as a reference line under the
123
+ // windows. Purely informational: the usage API reports percentages only.
124
+ const allowanceText = createMemo(() => {
125
+ if (providerID() !== "opencode-go") return ""
126
+ const allowance = modelAllowance(modelID())
127
+ if (allowance === "free") return "∞"
128
+ if (!allowance) return "—"
129
+ return `$${allowance.go}/$${allowance.plus}`
130
+ })
131
+
114
132
  const [windows, setWindows] = createSignal<UsageWindow[]>([])
115
133
  const [loading, setLoading] = createSignal(false)
116
134
  const [error, setError] = createSignal("")
@@ -257,6 +275,14 @@ function UsagePanel(props: { context: any; panel: any; toggle: () => void }) {
257
275
  <text fg={palette().warn}>{`partial data · ${windows().length}/${WINDOW_COUNT} windows`}</text>
258
276
  </Show>
259
277
  <Index each={windows()}>{(w) => <WindowRow window={w()} palette={palette()} now={now()} />}</Index>
278
+ <Show when={allowanceText() !== ""}>
279
+ <box flexDirection="row" width="100%" marginTop={1}>
280
+ <box flexGrow={1}>
281
+ <text fg={palette().text}>{modelID() ?? ""}</text>
282
+ </box>
283
+ <text fg={palette().text}>{allowanceText()}</text>
284
+ </box>
285
+ </Show>
260
286
  </Show>
261
287
  </box>
262
288
  )}