opencode-usage-insights 0.2.0 → 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/README.md +100 -36
- package/dist/core.d.ts +10 -0
- package/dist/gui-experimental.cjs +3 -3
- package/dist/index.d.ts +7 -0
- package/dist/index.js +249 -18
- package/dist/index.js.map +9 -8
- package/dist/panel-data.d.ts +27 -4
- package/dist/panel.d.ts +9 -2
- package/dist/quota-client.d.ts +13 -0
- package/dist/quota.d.ts +114 -0
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.js +2 -2
- package/dist/rpc.js.map +3 -3
- package/dist/sidebar.d.ts +5 -0
- package/dist/stats-worker.js +248 -17
- package/dist/stats-worker.js.map +7 -6
- package/dist/tui.d.ts +13 -4
- package/dist/tui.js +406 -36
- package/dist/tui.js.map +11 -9
- package/docs/demo.md +17 -12
- package/docs/internals.md +72 -4
- package/package.json +7 -3
package/docs/demo.md
CHANGED
|
@@ -14,11 +14,11 @@ from the same database, through the same components the TUI renders.
|
|
|
14
14
|
|
|
15
15
|
## The panel
|
|
16
16
|
|
|
17
|
-

|
|
17
|
+

|
|
18
18
|
|
|
19
|
-

|
|
19
|
+

|
|
20
20
|
|
|
21
|
-

|
|
21
|
+

|
|
22
22
|
|
|
23
23
|
## Full output
|
|
24
24
|
|
|
@@ -64,7 +64,7 @@ turns
|
|
|
64
64
|
in 10.3k (1.62M) · out 1.25k
|
|
65
65
|
hit 99.4% · 2152/s · $0.2700
|
|
66
66
|
|
|
67
|
-
/usage overview
|
|
67
|
+
/usage-insights overview
|
|
68
68
|
────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
69
69
|
all time · 7 steps · 3 sessions · 6 prompts
|
|
70
70
|
steps 7 in 287.1k
|
|
@@ -88,7 +88,7 @@ models 4 · unknown 0.0% providers 3
|
|
|
88
88
|
unsettled 0 · no tps 0.0%
|
|
89
89
|
window 12/10/2026, 09:01:00 → 15/10/2026, 07:20:00
|
|
90
90
|
|
|
91
|
-
/usage models
|
|
91
|
+
/usage-insights models
|
|
92
92
|
────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
93
93
|
model steps prompt cached hit out cost providers
|
|
94
94
|
deepseek-v4.1-flash 1 410.6k 402k 97.9% 2.1k $0.0700 opencode-go
|
|
@@ -100,14 +100,14 @@ glm-5.3-flash 2 754.1k 632.4k 83.9% 9.9k $0.7600
|
|
|
100
100
|
deepseek-v4.1-flash-free 3 3.59M 3.45M 96.3% 11.3k $0.4500 opencode
|
|
101
101
|
p50 hit 94.1%
|
|
102
102
|
|
|
103
|
-
/usage providers
|
|
103
|
+
/usage-insights providers
|
|
104
104
|
────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
105
105
|
provider models steps share prompt cached hit tps p50 wall
|
|
106
106
|
anthropic 1 1 14% 119.8k 96k 80.1% 1178.6/s 1m14s
|
|
107
107
|
opencode-go 1 1 14% 410.6k 402k 97.9% 2625.0/s 31.0s
|
|
108
108
|
opencode 2 5 71% 4.34M 4.09M 94.1% 3000.0/s 58.0s
|
|
109
109
|
|
|
110
|
-
/usage cache
|
|
110
|
+
/usage-insights cache
|
|
111
111
|
────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
112
112
|
reuse losses 1 event · 607.6k tokens
|
|
113
113
|
expired 1 · 607.6k
|
|
@@ -132,7 +132,7 @@ opencode/glm-5.3-flash – 23.9h 1
|
|
|
132
132
|
recent losses
|
|
133
133
|
15:00:00 opencode/glm-5.3-flash −607.6k 23.9h idle · expired
|
|
134
134
|
|
|
135
|
-
/usage periods
|
|
135
|
+
/usage-insights periods
|
|
136
136
|
────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
137
137
|
per day · 4 periods · 7 steps · hit 94.1%
|
|
138
138
|
steps █▃▃▆
|
|
@@ -146,7 +146,7 @@ period steps sess prompt cached hit out cost
|
|
|
146
146
|
|
|
147
147
|
total 7 4 4.87M 4.58M 94% 26.6k $2.70
|
|
148
148
|
|
|
149
|
-
/usage latency
|
|
149
|
+
/usage-insights latency
|
|
150
150
|
────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
151
151
|
wall p50 58.0s p90 1m28s p99 1m28s n 7
|
|
152
152
|
stream p50 1.2s p90 2.8s p99 2.8s
|
|
@@ -162,7 +162,7 @@ glm-5.3-flash 2 58.0s 1m01s 1.1s 3000.0/s 4636.4/s $0.7600
|
|
|
162
162
|
deepseek-v4.1-f… 3 52.0s 1m28s 1.2s 2642.9/s 5250.0/s $0.4500
|
|
163
163
|
n < 5 is dimmed: too few samples to compare
|
|
164
164
|
|
|
165
|
-
/usage sessions
|
|
165
|
+
/usage-insights sessions
|
|
166
166
|
────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
167
167
|
title steps prompt cached hit out cost
|
|
168
168
|
Refactor the recorder 3 3.37M 3.24M 96% 8.25k $1.69
|
|
@@ -172,7 +172,7 @@ Fix the cache regression 2 754.1k 632.4k 84%
|
|
|
172
172
|
Docs pass 2 747.1k 712k 95% 8.4k $0.2500
|
|
173
173
|
/code/opencode-usage-insights · 2 models
|
|
174
174
|
|
|
175
|
-
/usage turns
|
|
175
|
+
/usage-insights turns
|
|
176
176
|
────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
177
177
|
6 turns · newest first
|
|
178
178
|
Refactor the reco… 09:24:20 · opencode/deepseek-v4.1-flash-free · 2 steps · in 10.3k (1.62M), cach…
|
|
@@ -182,7 +182,7 @@ Fix the cache reg… 15:00:58 · Δ 23h58m · opencode/glm-5.3-flash · in 72.7
|
|
|
182
182
|
Docs pass 07:01:28 · opencode/deepseek-v4.1-flash-free · in 26.5k (336.5k), cached 310k, out 6.3k,…
|
|
183
183
|
Docs pass 07:20:31 · Δ 20m00s · opencode-go/deepseek-v4.1-flash · changed · in 8.6k (410.6k), cach…
|
|
184
184
|
|
|
185
|
-
/usage db
|
|
185
|
+
/usage-insights db
|
|
186
186
|
────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
187
187
|
/tmp/usage-insights-demo-mFDbHx/usage.db
|
|
188
188
|
0.0 MB + 0.4 MB wal · schema v11
|
|
@@ -205,3 +205,8 @@ keep prunes older than
|
|
|
205
205
|
|
|
206
206
|
wipe everything · 7 steps · 3 sessions · cannot be undone
|
|
207
207
|
```
|
|
208
|
+
|
|
209
|
+
The `go` view is not part of this database demo: it is live OpenCode Go
|
|
210
|
+
allowance read by the TUI/Desktop client from the host, so it has no rows in
|
|
211
|
+
the demo database. Run `/usage-insights go` in the TUI or open the Desktop panel
|
|
212
|
+
to see it.
|
package/docs/internals.md
CHANGED
|
@@ -148,7 +148,9 @@ Each `ModelInfo` carries the prices in `cost: ModelCost[]`, with
|
|
|
148
148
|
|
|
149
149
|
The plugin deliberately does **not** read `~/.cache/opencode/models.json`, does
|
|
150
150
|
**not** use `opencode models` for prices (that command lists model IDs only),
|
|
151
|
-
and makes no network call of its own.
|
|
151
|
+
and makes no external network call of its own. The `go` view's local read of
|
|
152
|
+
the host's usage-limits endpoint is the only host API call; it never reaches the
|
|
153
|
+
Console.
|
|
152
154
|
|
|
153
155
|
The server loads the list without blocking the recorder, refreshes it on
|
|
154
156
|
`model.updated` and on a coarse TTL, and keeps the previous table when a refresh
|
|
@@ -257,11 +259,71 @@ deduplicates compaction rows an older recorder inserted on every delivery
|
|
|
257
259
|
before the index is created, so the event count and any cost read from the
|
|
258
260
|
table stay honest.
|
|
259
261
|
|
|
262
|
+
## OpenCode Go allowance
|
|
263
|
+
|
|
264
|
+
The `go` view is the one panel view that does not read SQLite. The host publishes
|
|
265
|
+
the Go allowance at `GET /api/experimental/usage/limits` and exposes the same
|
|
266
|
+
call to clients as `client.experimental.usage.limits()`. The plugin reads it
|
|
267
|
+
from the TUI and the Desktop; the server part's plugin context does not expose
|
|
268
|
+
that endpoint, so a server-rendered view would have no data. A caller that asks
|
|
269
|
+
the RPC for `go` gets an explanatory line instead of a table.
|
|
270
|
+
|
|
271
|
+
The payload has one meter per window:
|
|
272
|
+
|
|
273
|
+
```json
|
|
274
|
+
{
|
|
275
|
+
"go": {
|
|
276
|
+
"rolling": { "percent": 2, "limited": false, "resetsAt": 1796067785000 },
|
|
277
|
+
"weekly": { "percent": 9, "limited": false, "resetsAt": 1796601600000 },
|
|
278
|
+
"monthly": { "percent": 40, "limited": false, "resetsAt": 1797285964000 }
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
`percent` is a whole number, `limited` is Go refusing requests, and `resetsAt`
|
|
284
|
+
is the window's reset. The monthly reset is also the paid-period renewal; the UI
|
|
285
|
+
calls it `renews` and prints the exact local date and time. The payload carries
|
|
286
|
+
neither a cycle start nor a plan type: Go, Go Plus and Go Teams share the same
|
|
287
|
+
meters. The UI therefore shows `quotaName` when configured, else the host
|
|
288
|
+
provider name, else the full `OpenCode Go`; a Go Plus/Teams user can set
|
|
289
|
+
`quotaName` to their plan name. The compact blocks show that name before the
|
|
290
|
+
numbers.
|
|
291
|
+
|
|
292
|
+
The payload carries no cycle start, so the forecast infers it as one calendar
|
|
293
|
+
month before the reset:
|
|
294
|
+
|
|
295
|
+
```text
|
|
296
|
+
start = previousCycleStart(monthly.resetsAt)
|
|
297
|
+
elapsed = now - start
|
|
298
|
+
rate = percent / elapsedDays
|
|
299
|
+
projected = percent + rate * remainingDays
|
|
300
|
+
exhaustAt = now + (100 - percent) / rate
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
The projection is shown only after 30 minutes of the cycle, and only when the
|
|
304
|
+
percent is a useful signal; a fresh cycle reads `too early to project`. A
|
|
305
|
+
limited or 100% meter reads `monthly limit reached` instead of a projection.
|
|
306
|
+
There is deliberately no sample history: the host exposes one current value, so
|
|
307
|
+
a line chart would imply observations the plugin never took. The Desktop draws
|
|
308
|
+
current-versus-forecast bars from this single sample. If a real trend chart is
|
|
309
|
+
ever wanted, the clients must record quota samples first.
|
|
310
|
+
|
|
311
|
+
OpenCode 2.4 also has its own **Usage** dialog: Desktop's **View usage** lists
|
|
312
|
+
the Go meters and Console budgets; the TUI `/usage` lists Console budgets and
|
|
313
|
+
per-model remaining. The plugin does not duplicate the Console budget section;
|
|
314
|
+
it adds the forecast, the exact renewal, the TUI sidebar block, the Desktop
|
|
315
|
+
Turns block and the panel chart. The
|
|
316
|
+
plugin's command is `/usage-insights` (alias `/insights`) so the host keeps
|
|
317
|
+
`/usage`.
|
|
318
|
+
|
|
260
319
|
## Privacy and security
|
|
261
320
|
|
|
262
|
-
The plugin is local by construction: no network client, no
|
|
263
|
-
credentials, no telemetry. Everything it records stays in the
|
|
264
|
-
user's own state directory.
|
|
321
|
+
The plugin is local by construction: no external network client, no
|
|
322
|
+
subprocess, no credentials, no telemetry. Everything it records stays in the
|
|
323
|
+
SQLite file in the user's own state directory. The one extra call is local: the
|
|
324
|
+
`go` view asks the OpenCode server for the allowance the host already fetched
|
|
325
|
+
from the OpenCode Console. The plugin never sees the Console API key and never
|
|
326
|
+
contacts the Console itself; `quota: "off"` stops that read.
|
|
265
327
|
|
|
266
328
|
**What is stored.** Per step: timings, token counts, charged cost and the
|
|
267
329
|
list-price estimate when the host reported `$0`, the provider/model/variant it
|
|
@@ -278,6 +340,9 @@ arguments, no file contents, no environment variables.
|
|
|
278
340
|
- **Private files.** The database directory is created `0700` and the file
|
|
279
341
|
`0600` (POSIX), re-applied on every open; on Windows the file inherits the
|
|
280
342
|
user profile's ACL.
|
|
343
|
+
- **The Go allowance is read, not stored.** The `go` view keeps the meters and
|
|
344
|
+
the inferred forecast in memory only. No workspace id, usage URL or quota
|
|
345
|
+
sample is written to the database or sent over the plugin RPC.
|
|
281
346
|
- **A read-only reader.** The worker opens the database read-only, so panel and
|
|
282
347
|
history queries can never write, migrate or take the recorder's lock. Prune,
|
|
283
348
|
wipe and compact open a short-lived writer inside the worker with a 250 ms
|
|
@@ -319,6 +384,9 @@ TUI line and the Desktop header badge. The rules it keeps are:
|
|
|
319
384
|
request, and the worker runs the query off the server's event loop. The
|
|
320
385
|
panel's and the history's rows are shared; the file's own numbers (`dbInfo`)
|
|
321
386
|
are only asked for by the `db` view.
|
|
387
|
+
- **The Desktop badge reads the session mid-turn.** While a turn runs it reads
|
|
388
|
+
the host's session cost and tokens plus the cached list estimate, both O(1),
|
|
389
|
+
and never the transcript; only an idle badge walks the transcript tail.
|
|
322
390
|
- **The panel's cost is the range it shows.** A view folds the steps of its
|
|
323
391
|
range — in SQLite where the answer is a sum or a count, in JavaScript where it
|
|
324
392
|
is a percentile or a comparison between consecutive steps. That is why the
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-usage-insights",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "OpenCode V2 plugin that puts per-turn and per-session cost back in the TUI and OpenCode Desktop
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "OpenCode V2 plugin that puts per-turn and per-session cost back in the TUI and OpenCode Desktop — charged cost, list-price estimates, tokens, prompt-cache reuse, latency, local history and an OpenCode Go allowance forecast in a live line, sidebar, header badge and /usage-insights panel.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": {
|
|
@@ -37,7 +37,11 @@
|
|
|
37
37
|
"desktop",
|
|
38
38
|
"electron",
|
|
39
39
|
"gui",
|
|
40
|
-
"rpc"
|
|
40
|
+
"rpc",
|
|
41
|
+
"opencode-go",
|
|
42
|
+
"quota",
|
|
43
|
+
"allowance",
|
|
44
|
+
"forecast"
|
|
41
45
|
],
|
|
42
46
|
"engines": {
|
|
43
47
|
"opencode": ">=2.4.2"
|