opencode-usage-insights 0.1.1 → 0.1.3
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 +204 -67
- package/dist/core.d.ts +19 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +558 -154
- package/dist/index.js.map +9 -8
- package/dist/line.d.ts +15 -5
- package/dist/panel-build.d.ts +2 -0
- package/dist/panel-data.d.ts +15 -6
- package/dist/panel.d.ts +8 -0
- package/dist/pricing.d.ts +72 -0
- package/dist/recorder.d.ts +10 -0
- package/dist/stats/aggregates.d.ts +14 -3
- package/dist/stats/db.d.ts +34 -3
- package/dist/stats/maintenance.d.ts +19 -0
- package/dist/stats/queries.d.ts +50 -5
- package/dist/tui.d.ts +7 -1
- package/dist/tui.js +924 -278
- package/dist/tui.js.map +15 -14
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -5,37 +5,42 @@
|
|
|
5
5
|
[](https://github.com/hugobatista/opencode-usage-insights/actions/workflows/lint.yml)
|
|
6
6
|
[](https://www.npmjs.com/package/opencode-usage-insights)
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
**See what each turn costs.** OpenCode reports the cost of each request, but the
|
|
9
|
+
TUI no longer shows it. This plugin puts cost back in view: a telemetry line
|
|
10
|
+
after every turn, the session's running spend in the sidebar, and an interactive
|
|
11
|
+
`/usage` panel with charged cost, list-price estimates, tokens, prompt-cache
|
|
12
|
+
reuse and latency.
|
|
12
13
|
|
|
13
14
|

|
|
14
15
|
|
|
15
|
-
Everything stays local:
|
|
16
|
-
|
|
16
|
+
Everything stays local: no prompts or responses are stored, and nothing leaves
|
|
17
|
+
the machine.
|
|
17
18
|
|
|
18
19
|
## What it does
|
|
19
20
|
|
|
20
|
-
- **The line** (`session.composer.top`):
|
|
21
|
-
prompt
|
|
22
|
-
|
|
23
|
-
It belongs to finished work, so it stays hidden while a
|
|
21
|
+
- **The line** (`session.composer.top`): what the turn cost, the tokens and
|
|
22
|
+
prompt cache behind it, when it ended, the gap since the previous prompt, the
|
|
23
|
+
model and configured provider, and warnings when the prompt cache or the
|
|
24
|
+
provider changed. It belongs to finished work, so it stays hidden while a
|
|
25
|
+
turn is running.
|
|
24
26
|
- **The `/usage` panel**: nine keyboard-driven views — `overview`, `models`,
|
|
25
27
|
`providers`, `cache`, `periods`, `latency`, `sessions`, `turns`,
|
|
26
28
|
`db` — over five ranges (`session`, `today`, `7d`, `30d`, `all`), with
|
|
27
29
|
drill-downs, sorting, filters and state remembered between openings.
|
|
28
30
|
`/usage models 7d`, `/usage providers 30d`, `/usage turns 7d`.
|
|
29
|
-
- **The session sidebar**: the session's
|
|
30
|
-
same buckets as the line. Three lines per turn — when and through which
|
|
31
|
+
- **The session sidebar**: the session's running spend and its last turns, in
|
|
32
|
+
the same buckets as the line. Three lines per turn — when and through which
|
|
31
33
|
provider, the prompt volumes, then `hit · tok/s · cost` — plus the model at
|
|
32
34
|
both ends of the block and on any turn that changed it, so the history reads
|
|
33
35
|
whether it is the whole session or a window of a long one:
|
|
34
36
|
`16:54 opencode-go` / `deepseek-v4.1-flash max` /
|
|
35
37
|
`in 1.7k (427.3k) · out 1.06k` / `hit 99.7% · 1.2k/s · $0.0006`.
|
|
36
|
-
- **The record** (server
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
- **The record** (server part): every assistant step with tokens, charged cost,
|
|
39
|
+
the list-price estimate when the host reported `$0`, timings, finish reason,
|
|
40
|
+
the configured provider and model it ran through, and its session and parent
|
|
41
|
+
ids; prompts, session lifecycle and compaction events too; and the host's
|
|
42
|
+
`session.usage.recorded` for compactions and title generations, which have no
|
|
43
|
+
assistant step of their own.
|
|
39
44
|
- **Portable data** (from a checkout): `bun run report --ndjson` exports the
|
|
40
45
|
whole database, and `--import` merges it back on another machine.
|
|
41
46
|
- **Observational by design**: the plugin never rewrites prompts, requests or
|
|
@@ -55,17 +60,18 @@ written by the server-side recorder and read by the TUI.
|
|
|
55
60
|
|
|
56
61
|
## Install
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
> **Not on the npm registry yet.** Until the first release is published,
|
|
60
|
-
> `opencode plugin add` and the package-name form below cannot resolve it — use
|
|
61
|
-
> the local checkout, the last form of this section.
|
|
63
|
+
The plugin is published on npm as `opencode-usage-insights`.
|
|
62
64
|
|
|
63
65
|
```sh
|
|
64
66
|
opencode plugin add opencode-usage-insights
|
|
65
67
|
```
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
This adds one entry to the global `opencode.json(c)`. That entry loads both
|
|
70
|
+
parts: the server recorder and the TUI contributions. A TUI-only package goes in
|
|
71
|
+
`~/.config/opencode/cli.json`; this plugin has both parts, so `opencode.json(c)`
|
|
72
|
+
is enough.
|
|
73
|
+
|
|
74
|
+
If you prefer to edit the configuration yourself:
|
|
69
75
|
|
|
70
76
|
```jsonc
|
|
71
77
|
// ~/.config/opencode/opencode.jsonc
|
|
@@ -75,20 +81,12 @@ Or add the package to `~/.config/opencode/opencode.jsonc` (server entry) and
|
|
|
75
81
|
}
|
|
76
82
|
```
|
|
77
83
|
|
|
78
|
-
```jsonc
|
|
79
|
-
// ~/.config/opencode/cli.json
|
|
80
|
-
{
|
|
81
|
-
"$schema": "https://opencode.ai/v2/cli.json",
|
|
82
|
-
"plugins": ["opencode-usage-insights"]
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
84
|
To pass [options](#configuration), use the object form:
|
|
87
85
|
|
|
88
86
|
```jsonc
|
|
89
87
|
{
|
|
90
88
|
"plugins": [
|
|
91
|
-
{ "package": "opencode-usage-insights", "options": { "sidebarTurns":
|
|
89
|
+
{ "package": "opencode-usage-insights", "options": { "sidebarTurns": 8 } }
|
|
92
90
|
]
|
|
93
91
|
}
|
|
94
92
|
```
|
|
@@ -102,11 +100,6 @@ and the TUI contributions (`src/tui.tsx`) from source:
|
|
|
102
100
|
{ "plugins": [{ "package": "/home/you/code/projects/opencode-usage-insights/src" }] }
|
|
103
101
|
```
|
|
104
102
|
|
|
105
|
-
```jsonc
|
|
106
|
-
// ~/.config/opencode/cli.json
|
|
107
|
-
{ "plugins": [{ "package": "/home/you/code/projects/opencode-usage-insights/src" }] }
|
|
108
|
-
```
|
|
109
|
-
|
|
110
103
|
Configuration changes reload on their own; after changing the plugin's source,
|
|
111
104
|
restart the background service with `opencode service restart`.
|
|
112
105
|
|
|
@@ -123,20 +116,157 @@ turn finishes, and `/usage` (alias `/insights`) opens the panel.
|
|
|
123
116
|
| --- | --- |
|
|
124
117
|
| `14:32:07` | When the response ended (`completed`, else `streamed`, else `created`). |
|
|
125
118
|
| `Δ 3m12s` | Time since the previous prompt of the same session. |
|
|
126
|
-
| `opencode-go/deepseek-v4.1-flash max` | The identity of the turn: the provider the model ran through
|
|
119
|
+
| `opencode-go/deepseek-v4.1-flash max` | The identity of the turn: the configured provider the model ran through and the model (the variant as a trailing word; `fields.model`/`fields.variant` hide either). Yellow with `changed` when the provider differs from the previous prompt, `model changed` when only the model does. |
|
|
127
120
|
| `in 85.4k (1.62M), cached 1.53M, out 3.7k, cost $0.21` | `in` is the uncached part of the prompt (fresh input + cache writes), the parenthesised value the whole prompt — shown only when the two differ — `cached` its cached part, `out` everything generated (visible output + reasoning), and `cost` what the turn was billed. With several steps the segment reads `3 steps · …` and reports the step the turn ended with (`latest`) for the tokens, while the cost is always the turn's own — every step is paid for; `turnTotals: "sum"` adds every step's tokens instead. |
|
|
128
121
|
| `cost $0.21` | Money, not tokens: a turn sums every step's cost whatever the token view shows. A cost of zero is left out, so a free model reads as free. `fields.cost: false` hides it. |
|
|
129
|
-
| `
|
|
122
|
+
| `cost ≈ $0.21` | A **list-price estimate**, not money charged. When the host reports `cost: 0` for a paid model (OpenCode 2.2.0+ with an OpenCode Go subscription), the plugin prices the step from the host's model list. A turn mixing covered and paid steps keeps both parts visible: `cost $0.12 + ≈ $3.40`. `pricing: "off"` hides estimates everywhere; `fields.cost: false` hides both. |
|
|
123
|
+
| `sess in 2.1M (14.5M), cached 12.4M, out 88k, cost $1.90` | The session totals: tokens and charged money come from the host (including its compaction and title generations), and the list estimate comes from the steps the plugin recorded. A Go session reads `cost ≈ $3.40`; a session mixing charged and covered steps keeps both parts, `cost $0.12 + ≈ $3.40`. |
|
|
130
124
|
| `⚠ cache expired (−11.7k)` | Yellow. The prompt cache read fell by that many tokens against a comparable previous step; `×N` when several steps in the turn lost cache. |
|
|
131
125
|
|
|
132
126
|
The turn segment carries no label by default — the numbers are the turn's, and
|
|
133
127
|
`sess` marks the session's; `labels.turn` (e.g. `"turn"`) brings a prefix back.
|
|
134
128
|
|
|
129
|
+
`≈` is an estimate at the host's list price, never a charge. It appears when
|
|
130
|
+
OpenCode reports a step at `$0` — subscription-covered Go requests, or a provider
|
|
131
|
+
that stopped reporting a cost — and the host's model list still has a price. A
|
|
132
|
+
genuinely free model has no price and therefore no estimate; it is recorded as
|
|
133
|
+
known free rather than as an unknown price. The estimate is stored per step, so
|
|
134
|
+
the line's `sess` segment, the panel, the sidebar, the NDJSON export and the CLI
|
|
135
|
+
report all show the same number. The `db` view lists how many `$0` steps still
|
|
136
|
+
lack one; `e` backfills them using today's model list.
|
|
137
|
+
|
|
135
138
|
A turn is every consecutive assistant step after a prompt. Compaction, shell,
|
|
136
139
|
`idle` and info messages do not split a turn; `user`, `synthetic` and `system`
|
|
137
140
|
messages do. From a checkout, `bun run demo` prints one example per case,
|
|
138
141
|
including the streaming one and both turn-total views.
|
|
139
142
|
|
|
143
|
+
## How costs are calculated
|
|
144
|
+
|
|
145
|
+
**Charged money is never recalculated by the plugin.** `steps.cost` is what the
|
|
146
|
+
host reports for the step (possibly `0` for an OpenCode Go subscription). When
|
|
147
|
+
that number is `0` or missing and the model has a price in the host's model
|
|
148
|
+
list, the plugin computes a **list-price estimate** and stores it in
|
|
149
|
+
`steps.list_cost`. Prices are USD per 1,000,000 tokens.
|
|
150
|
+
|
|
151
|
+
The price source is the model list exposed by the OpenCode process that is
|
|
152
|
+
currently serving the session, already resolved by the host (provider config,
|
|
153
|
+
overrides, Zen/Go pricing):
|
|
154
|
+
|
|
155
|
+
| Surface | Where the price comes from |
|
|
156
|
+
| --- | --- |
|
|
157
|
+
| Server recorder | `ctx.model.list()` → `ModelInfo.cost` |
|
|
158
|
+
| Live turn / backfill | `ctx.data.location.model.list(ctx.location)` → `ModelInfo.cost` |
|
|
159
|
+
| Panel, sidebar, NDJSON, CLI report | stored `steps.list_cost` |
|
|
160
|
+
| `sess` segment | `SUM(list_cost)` from the plugin database |
|
|
161
|
+
|
|
162
|
+
The plugin does **not** read `~/.cache/opencode/models.json`, does **not** use
|
|
163
|
+
`opencode models` for prices (it lists model IDs only), and makes no network
|
|
164
|
+
call of its own. Each `ModelInfo` carries the prices as
|
|
165
|
+
`cost: Array<{ input, output, cache: { read, write }, tier? }>` in USD per
|
|
166
|
+
1,000,000 tokens.
|
|
167
|
+
|
|
168
|
+
The estimate uses the host's own fallback formula:
|
|
169
|
+
|
|
170
|
+
```text
|
|
171
|
+
input fresh (uncached) prompt tokens
|
|
172
|
+
cache.read prompt tokens read from the provider cache
|
|
173
|
+
cache.write prompt tokens written to the provider cache
|
|
174
|
+
output visible output tokens
|
|
175
|
+
reasoning reasoning tokens
|
|
176
|
+
|
|
177
|
+
prompt = input + cache.read + cache.write
|
|
178
|
+
cost = (input * inputPrice
|
|
179
|
+
+ (output + reasoning) * outputPrice
|
|
180
|
+
+ cache.read * cacheReadPrice
|
|
181
|
+
+ cache.write * cacheWritePrice) / 1_000_000
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Reasoning is billed at the output price. For models with context tiers, the
|
|
185
|
+
tier applies only when the whole prompt is **strictly greater** than the tier
|
|
186
|
+
size; at exactly the threshold the untiered price applies. An unknown model or
|
|
187
|
+
no applicable price means no estimate; an all-zero price means the model is
|
|
188
|
+
known to be free.
|
|
189
|
+
|
|
190
|
+
The buckets behind the line are the same ones the estimate uses, but folded for
|
|
191
|
+
display:
|
|
192
|
+
|
|
193
|
+
```text
|
|
194
|
+
in = input + cache.write (the uncached part of the prompt)
|
|
195
|
+
cached = cache.read
|
|
196
|
+
out = output + reasoning
|
|
197
|
+
prompt = in + cached
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
`list_cost` has three meanings: `NULL` means the step was charged or its price
|
|
201
|
+
is unknown; `0` means the model is known to be free; a positive value is the
|
|
202
|
+
estimate. That is why a free model reads as `$0`, while an older model the
|
|
203
|
+
host's model list no longer contains stays without a price.
|
|
204
|
+
|
|
205
|
+
A worked example, using the prices of `opencode-go/deepseek-v4.1-flash`
|
|
206
|
+
(`input 0.15`, `output 0.6`, `cache.read 0.003`):
|
|
207
|
+
|
|
208
|
+
```text
|
|
209
|
+
2,591 × 0.15 + (564 + 3,239) × 0.6 + 514,944 × 0.003
|
|
210
|
+
= 4,215.282 per 1,000,000 tokens
|
|
211
|
+
= $0.004215282
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Compactions and titles
|
|
215
|
+
|
|
216
|
+
The host also reports usage with no assistant step behind it:
|
|
217
|
+
`session.usage.recorded` with `source: "compaction"` or `source: "title"`. It is
|
|
218
|
+
part of the session's own `cost`, and the plugin stores it in the `usage` table,
|
|
219
|
+
keyed by the host event ID so a replay never counts twice.
|
|
220
|
+
|
|
221
|
+
Its cost is added to the **overview**, **periods** and **sessions** totals — the
|
|
222
|
+
same money the host already includes in the session. The `models`, `providers`
|
|
223
|
+
and `turns` rows stay step-based: the host's non-step usage record carries no
|
|
224
|
+
model, so attributing the money to one would invent an identity. The overview
|
|
225
|
+
shows the part as an `other` row, and a session row names it under its title.
|
|
226
|
+
|
|
227
|
+
This is host money, not a list-price estimate, so `pricing: "off"` does not hide
|
|
228
|
+
it. A database written by an older plugin is healed at open: the stored
|
|
229
|
+
compaction events already carry `cost` and `tokens`, and a migration recovers
|
|
230
|
+
them. Title usage recorded before the upgrade was never stored anywhere and
|
|
231
|
+
stays missing; the line's `sess` segment (which reads the host's own session
|
|
232
|
+
total) keeps covering the whole session meanwhile.
|
|
233
|
+
|
|
234
|
+
What each surface shows:
|
|
235
|
+
|
|
236
|
+
| Situation | Line | Panel |
|
|
237
|
+
| --- | --- | --- |
|
|
238
|
+
| Charged | `cost $0.12` | `$0.12` |
|
|
239
|
+
| Subscription-covered (host `0`, host model price known) | `cost ≈ $3.40` | `≈$3.40` |
|
|
240
|
+
| Mixed (some charged, some covered) | `cost $0.12 + ≈ $3.40` | overview `$0.12 + ≈ $3.40`; table cell `≈$3.52` (charged + estimate) |
|
|
241
|
+
| Compaction/title (host `session.usage.recorded`) | included in the host's `sess` total | overview `other $0.0042`; session and period cost include it |
|
|
242
|
+
| Known free model | cost omitted | `$0` |
|
|
243
|
+
| Price unknown | cost omitted | `$0` |
|
|
244
|
+
|
|
245
|
+
The **turn** estimate on the live line uses the model list the TUI currently
|
|
246
|
+
has. The **`sess`** segment uses the estimate recorded per step and summed for
|
|
247
|
+
the session, as do the panel, the sidebar, the NDJSON export and the CLI report.
|
|
248
|
+
If a price changes after a step is recorded, the live turn can therefore differ
|
|
249
|
+
from the stored history; `list_cost` freezes the price from the recording time.
|
|
250
|
+
The server loads its model list in the background, refreshes it on
|
|
251
|
+
`model.updated` and keeps the previous table if a refresh fails; the TUI
|
|
252
|
+
invalidates its table on the same event and refreshes it on a coarse TTL.
|
|
253
|
+
|
|
254
|
+
For a session, the charged total is the host's (including its compaction and
|
|
255
|
+
title generations); the estimate is `SUM(list_cost)` over the steps the plugin
|
|
256
|
+
recorded. The overview, periods and session rows additionally add the host's
|
|
257
|
+
non-step usage cost; the line's `sess` segment already has it in the host's
|
|
258
|
+
total, so it is not added twice. If the plugin started recording in the middle
|
|
259
|
+
of a session, the estimate covers only the recorded steps; the charged total
|
|
260
|
+
still follows the host. When the database is unavailable, the line falls back to
|
|
261
|
+
the host's charged total with no estimate.
|
|
262
|
+
|
|
263
|
+
The `db` view counts the `$0` steps that have no known price yet. `e` retries
|
|
264
|
+
them with today's host model list: free models become `0`, models still in that
|
|
265
|
+
list get an estimate, and models the list no longer contains stay unknown. Steps
|
|
266
|
+
without a provider/model or without tokens have nothing to price and are not
|
|
267
|
+
counted. `pricing: "off"` stops new estimates, hides stored ones everywhere and
|
|
268
|
+
disables the backfill, without deleting the data.
|
|
269
|
+
|
|
140
270
|
## The panel
|
|
141
271
|
|
|
142
272
|
`/usage [view] [range]` opens the panel (`/usage` alone opens the last view, or
|
|
@@ -169,6 +299,7 @@ a help overlay that repeats the keys and defines every number.
|
|
|
169
299
|
| `m` `p` | Filter by model or by **provider** (a picker of the values actually observed). |
|
|
170
300
|
| `x` | Clear the filters. |
|
|
171
301
|
| `r` | Re-read the database. |
|
|
302
|
+
| `e` | `db`: backfill list-price estimates for the `$0` steps that have none (asks first; uses today's model list). |
|
|
172
303
|
| `v` | `db`: compact the file, giving the space of deleted rows back. |
|
|
173
304
|
| `?` | Help overlay. |
|
|
174
305
|
| `f` / `escape` | Full screen / close. |
|
|
@@ -180,31 +311,32 @@ durable storage, so the panel reopens where it was left.
|
|
|
180
311
|
|
|
181
312
|
| View | Answers |
|
|
182
313
|
| --- | --- |
|
|
183
|
-
| `overview` | Steps, sessions, prompts, `in`/`cached`/`write`/`out`, `hit`, cost, an activity sparkline, a `this session` block and a **data coverage** block (how many models and providers were observed, and how many steps lack a model or a completion — a zero elsewhere is only trustworthy when this is complete). |
|
|
184
|
-
| `models` | Every model with its cache (`hit` and the per-step `hit p50`), tokens, cost, the **providers it ran through** and how often it switched model or provider — with the cache a provider switch cost. `enter` opens the per-provider detail. |
|
|
185
|
-
| `providers` | **
|
|
314
|
+
| `overview` | Steps, sessions, prompts, `in`/`cached`/`write`/`out`, `hit`, cost (with an `other` row naming the compaction/title part), an activity sparkline, a `this session` block and a **data coverage** block (how many models and providers were observed, and how many steps lack a model or a completion — a zero elsewhere is only trustworthy when this is complete). |
|
|
315
|
+
| `models` | Every model with its cache (`hit` and the per-step `hit p50`), tokens, cost, the **providers it ran through** and how often it switched model or provider — with the cache a provider switch cost. Cost is assistant steps only; `enter` opens the per-provider detail. |
|
|
316
|
+
| `providers` | **Which configured provider ran each model**: one row per provider, with the models it served, steps, share, prompt, cached, `hit`, p50 throughput, wall time and cost. Cost is assistant steps only. `enter` lists every model it served. Steps recorded without a provider (a model that was never observed) are dimmed and cannot be drilled into. |
|
|
186
317
|
| `cache` | Reuse by model, losses grouped by reason (`expired`, `compaction`, `unknown`), **cache survival against idle time**, reuse kept per provider, the observed TTL bounds (`hits up to` / `drops from`) and the most recent losses. |
|
|
187
|
-
| `periods` | Day, week or month totals — steps, sessions, `in`, `cached`, `write`, `hit`, `out`, cost — with a sparkline per metric and a totals row. `enter` lists the providers of a period. |
|
|
318
|
+
| `periods` | Day, week or month totals — steps, sessions, `in`, `cached`, `write`, `hit`, `out`, cost (including compaction/title usage) — with a sparkline per metric and a totals row. `enter` lists the providers of a period. |
|
|
188
319
|
| `latency` | Wall time, streaming window and throughput as p50/p90/p99 overall and per model (per provider when a model is filtered). `n < 5` is dimmed. |
|
|
189
|
-
| `sessions` | Each session with steps, prompts, tokens, `hit`, cost, its directory and how many models it used; subagent sessions are indented under their parent and rolled up. |
|
|
190
|
-
| `turns` | The per-prompt history: one line per finished turn, rendered exactly like the live line. `a` widens it to every session, titled. |
|
|
191
|
-
| `db` | Where the file lives, what it holds and how much of it is old. The retention table lists, per preset (`30`/`90`/`365` days), how many steps a prune would remove and the cutoff date it prunes from — pick one with `↑`/`↓` and `enter` prunes it (a confirmation first); `v` gives the space back. |
|
|
320
|
+
| `sessions` | Each session with steps, prompts, tokens, `hit`, cost (including compaction/title usage, named on the detail line), its directory and how many models it used; subagent sessions are indented under their parent and rolled up. |
|
|
321
|
+
| `turns` | The per-prompt history: one line per finished turn, rendered exactly like the live line. Cost is assistant steps only. `a` widens it to every session, titled. |
|
|
322
|
+
| `db` | Where the file lives, what it holds and how much of it is old. The retention table lists, per preset (`30`/`90`/`365` days), how many steps a prune would remove and the cutoff date it prunes from — pick one with `↑`/`↓` and `enter` prunes it (a confirmation first), removing the steps' compaction/title usage with them; `v` gives the space back. It also counts the `$0` steps with no list estimate; `e` backfills them at today's list price. |
|
|
192
323
|
|
|
193
324
|
The panel sums the stored per-step buckets over the selected range, so a number
|
|
194
325
|
read in one place means the same in the other: `prompt` is everything the
|
|
195
326
|
provider saw (`cached + fresh + writes`), `in` the uncached part, `hit` is
|
|
196
327
|
`cached / prompt`, and `out` everything generated (visible output + reasoning).
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
328
|
+
A `cost` cell marked `≈` includes list-price estimates for steps the host
|
|
329
|
+
reported as `$0`; the overview and the sidebar keep a mixed total in two parts
|
|
330
|
+
(`$0.12 + ≈ $3.40`) so charged money is never mistaken for the estimate.
|
|
331
|
+
|
|
332
|
+
The identity of a step is the **configured provider** the model ran through —
|
|
333
|
+
`opencode`, `opencode-go`, `deepseek`, whatever the provider is called in the
|
|
334
|
+
OpenCode configuration — and the model itself. That is what every view groups
|
|
335
|
+
by. A gateway may route a request to another operator, but that upstream is not
|
|
336
|
+
observable, so it is not guessed. The same model through `deepseek` and through
|
|
337
|
+
`opencode-go` is two rows, two caches and two latency profiles, and a switch
|
|
338
|
+
between them forfeits the cache the previous one held (the switch counts and the
|
|
339
|
+
cache losses in the `models` view count exactly that).
|
|
208
340
|
|
|
209
341
|
`tps`/`wall`/`stream` are produced tokens per streaming second / request to
|
|
210
342
|
completed step / request to the last chunk. The sidebar's rate (per turn, and
|
|
@@ -219,15 +351,16 @@ panel's `?` overlay defines every number in place.
|
|
|
219
351
|
|
|
220
352
|
## Configuration
|
|
221
353
|
|
|
222
|
-
Options apply to both
|
|
354
|
+
Options apply to both parts (each side reads the ones it needs):
|
|
223
355
|
|
|
224
356
|
| Option | Default | Meaning |
|
|
225
357
|
| --- | --- | --- |
|
|
226
358
|
| `enabled` | `true` | `false` disables that side completely — no line, no panel, no recording. |
|
|
227
|
-
| `db` | per-OS state path | SQLite path override. Must match between the server and TUI
|
|
359
|
+
| `db` | per-OS state path | SQLite path override. Must match between the server and TUI parts. |
|
|
228
360
|
| `turnTotals` | `"latest"` | How the turn segment counts prompt usage: `latest` shows the prompt size the turn ended with; `sum` adds every step of the turn. |
|
|
361
|
+
| `pricing` | `"auto"` | `"off"` disables list-price estimates everywhere: no new `list_cost` records, no `≈` on the line, in the panel or in the sidebar, and no historical backfill. Charged money is unaffected. |
|
|
229
362
|
| `sidebar` | `true` | Show the session summary and the per-prompt history — cache hit and cost per turn — in the session sidebar (the slot is invisible while the sidebar is hidden). |
|
|
230
|
-
| `sidebarTurns` | `
|
|
363
|
+
| `sidebarTurns` | `8` | How many turns the sidebar history shows. The host sidebar scrolls; raise it for a longer history. |
|
|
231
364
|
| `panel` | `true` | Show the `/usage` statistics panel and its command. `false` keeps the line and the sidebar. |
|
|
232
365
|
| `fields` | see below | Toggle line segments. |
|
|
233
366
|
| `labels` | see below | Override line labels (the plugin is English-only by default). |
|
|
@@ -239,7 +372,7 @@ Options apply to both entries (each side reads the ones it needs):
|
|
|
239
372
|
"options": {
|
|
240
373
|
"fields": { "clock": true, "delta": true, "model": true, "variant": true, "turn": true, "session": true, "reasoning": false, "cost": true, "cacheExpiry": true },
|
|
241
374
|
"turnTotals": "latest",
|
|
242
|
-
"labels": { "delta": "Δ", "turn": "", "session": "sess", "step": "step", "steps": "steps", "input": "in", "cached": "cached", "output": "out", "reasoning": "reason", "cost": "cost", "cacheExpired": "cache expired", "providerChanged": "changed", "modelChanged": "model changed" }
|
|
375
|
+
"labels": { "delta": "Δ", "turn": "", "session": "sess", "step": "step", "steps": "steps", "input": "in", "cached": "cached", "output": "out", "reasoning": "reason", "cost": "cost", "estimate": "≈", "cacheExpired": "cache expired", "providerChanged": "changed", "modelChanged": "model changed" }
|
|
243
376
|
}
|
|
244
377
|
}
|
|
245
378
|
```
|
|
@@ -259,13 +392,16 @@ The recorder writes to the per-user state directory:
|
|
|
259
392
|
|
|
260
393
|
`OPENCODE_USAGE_INSIGHTS_DB=/path/to/usage.db` overrides the path, and the `db`
|
|
261
394
|
option overrides both. The file is private to the user: its directory is created
|
|
262
|
-
`0700` and the file `0600` (POSIX), re-applied on every open. The TUI
|
|
263
|
-
through a read-only connection, so
|
|
264
|
-
recorder's lock.
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
395
|
+
`0700` and the file `0600` (POSIX), re-applied on every open. The TUI's views
|
|
396
|
+
read through a read-only connection, so they never write, migrate or take the
|
|
397
|
+
recorder's lock; prune, backfill and compact use a separate short-lived writer.
|
|
398
|
+
The server part applies schema migrations on open; after an upgrade, start it
|
|
399
|
+
once before opening the panel if the file predates the new schema.
|
|
400
|
+
|
|
401
|
+
Per step the database holds tokens, charged cost, the list-price estimate when
|
|
402
|
+
the host reported `$0`, timings, finish reason, the configured provider and the
|
|
403
|
+
model it ran through, and the session title and working directory. **Prompts and
|
|
404
|
+
responses are not stored**, and nothing leaves the machine. The schema, the
|
|
269
405
|
indexes, the identity rules and the security notes live in
|
|
270
406
|
[docs/internals.md](docs/internals.md).
|
|
271
407
|
|
|
@@ -280,6 +416,7 @@ bun run report all # every view
|
|
|
280
416
|
bun run report providers --model deepseek-v4.1-flash
|
|
281
417
|
bun run report periods --granularity month
|
|
282
418
|
bun run report models --provider opencode-go
|
|
419
|
+
bun run report --no-estimates # charged money only, like pricing: "off"
|
|
283
420
|
bun run report --json # raw rows and every analysis, for scripting
|
|
284
421
|
bun run report --ndjson > backup.jsonl # export the whole database
|
|
285
422
|
bun run report --import backup.jsonl # merge an export (idempotent)
|
|
@@ -310,7 +447,7 @@ bun run docs:images # re-render docs/images/*.png (needs ImageMagick)
|
|
|
310
447
|
- `src/recorder.ts` — the event-stream state machine that fills the database.
|
|
311
448
|
- `src/panel-build.ts`, `src/panel.tsx`, `src/sidebar.tsx` — panel assembly, the
|
|
312
449
|
panel component, and the sidebar contribution.
|
|
313
|
-
- `src/index.ts`, `src/tui.tsx` — the server and TUI
|
|
450
|
+
- `src/index.ts`, `src/tui.tsx` — the server and TUI parts.
|
|
314
451
|
- `scripts/` — the demo, report, bench, platform-check and documentation-image
|
|
315
452
|
CLIs, plus the two-entry `Bun.build`.
|
|
316
453
|
|
package/dist/core.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export type AssistantMessage = {
|
|
|
30
30
|
} | undefined;
|
|
31
31
|
} | undefined;
|
|
32
32
|
cost?: number | undefined;
|
|
33
|
+
/** List-price estimate for a step the host reported as costing nothing. */
|
|
34
|
+
listCost?: number | undefined;
|
|
33
35
|
finish?: string | null | undefined;
|
|
34
36
|
rawFinish?: string | null | undefined;
|
|
35
37
|
};
|
|
@@ -55,6 +57,8 @@ export type Totals = {
|
|
|
55
57
|
reasoning: number;
|
|
56
58
|
cacheWrite: number;
|
|
57
59
|
cost: number;
|
|
60
|
+
/** Sum of list-price estimates for steps the host reported as $0. */
|
|
61
|
+
listCost: number;
|
|
58
62
|
steps: number;
|
|
59
63
|
};
|
|
60
64
|
export type CacheDrop = {
|
|
@@ -201,6 +205,8 @@ export type LineLabels = {
|
|
|
201
205
|
output: string;
|
|
202
206
|
reasoning: string;
|
|
203
207
|
cost: string;
|
|
208
|
+
/** Prefix for a list-price estimate, e.g. `cost ≈ $0.03`. */
|
|
209
|
+
estimate: string;
|
|
204
210
|
cacheExpired: string;
|
|
205
211
|
providerChanged: string;
|
|
206
212
|
modelChanged: string;
|
|
@@ -229,6 +235,17 @@ export declare function formatClock(ms: number): string;
|
|
|
229
235
|
export declare function formatDuration(ms: number): string;
|
|
230
236
|
export declare function formatTokens(value: number): string;
|
|
231
237
|
export declare function formatCost(value: number): string;
|
|
238
|
+
/**
|
|
239
|
+
* Charged and estimated money as one string. A mixed total keeps both parts
|
|
240
|
+
* visible so list price is never mistaken for money that was charged:
|
|
241
|
+
* `$0.12 + ≈ $3.40`. Returns undefined when there is no money to show.
|
|
242
|
+
*/
|
|
243
|
+
export declare function formatMoney(charged: number, estimated: number, marker?: string): string | undefined;
|
|
244
|
+
/**
|
|
245
|
+
* The list-equivalent total for a compact table cell: charged money plus the
|
|
246
|
+
* estimates, marked with `≈` when any part is estimated.
|
|
247
|
+
*/
|
|
248
|
+
export declare function formatSpend(charged: number, estimated: number, marker?: string): string;
|
|
232
249
|
/**
|
|
233
250
|
* The buckets the line displays, derived from a totals group. `input` is the
|
|
234
251
|
* *uncached* part of the prompt (fresh input plus cache writes, i.e. what the
|
|
@@ -251,9 +268,11 @@ export declare function formatLineSegments(stats: TurnStats, options?: {
|
|
|
251
268
|
labels?: Partial<LineLabels>;
|
|
252
269
|
fields?: Partial<LineFields>;
|
|
253
270
|
turnTotals?: TurnTotalsView;
|
|
271
|
+
estimates?: boolean;
|
|
254
272
|
}): LineSegment[];
|
|
255
273
|
export declare function formatLine(stats: TurnStats, options?: {
|
|
256
274
|
labels?: Partial<LineLabels>;
|
|
257
275
|
fields?: Partial<LineFields>;
|
|
258
276
|
turnTotals?: TurnTotalsView;
|
|
277
|
+
estimates?: boolean;
|
|
259
278
|
}): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,11 @@ export type Options = {
|
|
|
15
15
|
enabled?: boolean | undefined;
|
|
16
16
|
/** SQLite database path override (defaults to the per-OS state directory). */
|
|
17
17
|
db?: string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* List-price estimates for steps the host reports as costing nothing.
|
|
20
|
+
* `off` records charged money only; the TUI hides any stored estimates.
|
|
21
|
+
*/
|
|
22
|
+
pricing?: "auto" | "off" | undefined;
|
|
18
23
|
};
|
|
19
24
|
declare const _default: Plugin.Plugin;
|
|
20
25
|
export default _default;
|