opencode-usage-insights 0.3.1 → 0.4.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.
Files changed (57) hide show
  1. package/README.md +66 -542
  2. package/dist/core.d.ts +15 -1
  3. package/dist/gui-experimental.cjs +3 -3
  4. package/dist/index.d.ts +0 -47
  5. package/dist/index.js +1715 -1195
  6. package/dist/index.js.map +23 -16
  7. package/dist/line.d.ts +1 -0
  8. package/dist/panel-data.d.ts +8 -1
  9. package/dist/recorder.d.ts +1 -0
  10. package/dist/rpc.d.ts +4 -4
  11. package/dist/rpc.js +5 -5
  12. package/dist/rpc.js.map +3 -3
  13. package/dist/settings-client.d.ts +29 -0
  14. package/dist/settings-rpc.d.ts +746 -0
  15. package/dist/settings.d.ts +114 -0
  16. package/dist/sidebar.d.ts +3 -3
  17. package/dist/stats/aggregates.d.ts +15 -3
  18. package/dist/stats/constants.d.ts +7 -0
  19. package/dist/stats/db.d.ts +8 -128
  20. package/dist/stats/legacy.d.ts +25 -0
  21. package/dist/stats/maintenance.d.ts +1 -1
  22. package/dist/stats/migrate.d.ts +7 -0
  23. package/dist/stats/ndjson.d.ts +16 -0
  24. package/dist/stats/open.d.ts +15 -0
  25. package/dist/stats/paths.d.ts +5 -4
  26. package/dist/stats/queries.d.ts +25 -31
  27. package/dist/stats/records.d.ts +94 -0
  28. package/dist/stats/schema.d.ts +26 -0
  29. package/dist/stats-client.d.ts +9 -0
  30. package/dist/stats-worker.js +577 -352
  31. package/dist/stats-worker.js.map +17 -12
  32. package/dist/text.d.ts +2 -0
  33. package/dist/tui-settings.d.ts +18 -0
  34. package/dist/tui.d.ts +1 -57
  35. package/dist/tui.js +954 -144
  36. package/dist/tui.js.map +17 -13
  37. package/docs/cli.md +24 -0
  38. package/docs/configuration.md +108 -0
  39. package/docs/costs.md +44 -0
  40. package/docs/demo.md +94 -68
  41. package/docs/desktop.md +91 -0
  42. package/docs/images/desktop-overview-annotated.png +0 -0
  43. package/docs/images/desktop-overview.png +0 -0
  44. package/docs/images/desktop-settings.png +0 -0
  45. package/docs/images/desktop-turns-go-annotated.png +0 -0
  46. package/docs/images/desktop-turns.png +0 -0
  47. package/docs/images/line.png +0 -0
  48. package/docs/images/panel-cache.png +0 -0
  49. package/docs/images/panel-help.png +0 -0
  50. package/docs/images/panel-latency.png +0 -0
  51. package/docs/images/panel-overview.png +0 -0
  52. package/docs/images/panel-providers.png +0 -0
  53. package/docs/images/sidebar.png +0 -0
  54. package/docs/internals.md +87 -36
  55. package/docs/privacy.md +60 -0
  56. package/docs/tui.md +175 -0
  57. package/package.json +2 -1
package/docs/cli.md ADDED
@@ -0,0 +1,24 @@
1
+ # CLI report
2
+
3
+ From a checkout, the database can be read without opening the TUI:
4
+
5
+ ```sh
6
+ bun run report # overview over all time
7
+ bun run report models 7d # one view, one range
8
+ bun run report all # every view
9
+ bun run report providers --model deepseek-v4.1-flash
10
+ bun run report periods --granularity month
11
+ bun run report models --provider opencode-go
12
+ bun run report --no-estimates # charged money only
13
+ bun run report --json # raw rows and every analysis
14
+ bun run report --ndjson > backup.jsonl # export the whole database
15
+ bun run report --import backup.jsonl # merge an export (idempotent)
16
+ bun run report --help
17
+ ```
18
+
19
+ The views come from the same `buildPanel` the TUI and the Desktop render, so the
20
+ terminal and the panels never drift apart. Run this on the server that owns the
21
+ database; it is the local CLI counterpart to the RPC. `--width`,
22
+ `--granularity`, `--model`, `--provider`, `--sort` and `--asc` mirror what the
23
+ panel's controls do. The NDJSON export contains the whole database and `--import`
24
+ merges it back on another machine.
@@ -0,0 +1,108 @@
1
+ # Settings and installation
2
+
3
+ ## Install
4
+
5
+ ```sh
6
+ opencode plugin add opencode-usage-insights
7
+ ```
8
+
9
+ The package entry is a string and loads every part: the server recorder and RPC,
10
+ the TUI contributions and the Desktop GUI. Manual configuration:
11
+
12
+ ```jsonc
13
+ // ~/.config/opencode/opencode.jsonc
14
+ {
15
+ "$schema": "https://opencode.ai/config.json",
16
+ "plugins": ["opencode-usage-insights"]
17
+ }
18
+ ```
19
+
20
+ The plugin's settings live on the server and are edited in the app; `options` in
21
+ `opencode.json(c)` are no longer read. If an older entry used the object form,
22
+ replace it with the package string.
23
+
24
+ Desktop reads only `opencode.json(c)`. If the plugin is in
25
+ `~/.config/opencode/cli.json`, move that entry to `opencode.json(c)` and remove
26
+ it from `cli.json`; keeping both loads the TUI part twice.
27
+
28
+ To register a local checkout, point at the package root, not `src/`. Build once
29
+ before loading it, and rebuild after source changes:
30
+
31
+ ```sh
32
+ cd /home/you/code/projects/opencode-usage-insights
33
+ bun install
34
+ bun run build
35
+ ```
36
+
37
+ ```jsonc
38
+ // ~/.config/opencode/opencode.jsonc
39
+ { "plugins": [{ "package": "/home/you/code/projects/opencode-usage-insights" }] }
40
+ ```
41
+
42
+ For GUI development, keep `bun run dev:gui` running; each rebuild reloads the
43
+ Desktop bundle in every window. After changing server or TUI source, restart the
44
+ background service with `opencode service restart`. The host's `/usage` command
45
+ stays the place for Console budget details; the plugin command is
46
+ `/usage-insights`.
47
+
48
+ Restart OpenCode and send a prompt to verify: the line appears above the
49
+ composer, the Desktop badge appears in the session header, and `/usage-insights`
50
+ (alias `/insights`) opens the panel.
51
+
52
+ ## Settings
53
+
54
+ Settings live in the plugin's server KV and are shared by every TUI and Desktop
55
+ window connected to that server. A save in one updates the others live. They are
56
+ per server: a client connected to another server reads that server's value.
57
+
58
+ - **Desktop:** Settings → Usage insights.
59
+ - **TUI:** command palette → **Usage insights settings**, or
60
+ `/insights-settings` (`/usage-insights-settings` also works).
61
+ - **Reset to defaults:** both editors can restore the table below.
62
+
63
+ | Setting | Default | Meaning |
64
+ | --- | --- | --- |
65
+ | `pricing` | `true` | Price steps the host reports as free, and show the `≈` estimates. Off hides them everywhere and disables the historical backfill without deleting data. |
66
+ | `turnTotals` | `"latest"` | `latest` shows the prompt size the turn ended with; `sum` adds every step of the turn. |
67
+ | `fields` | all on except `reasoning` | Which segments the telemetry line shows. |
68
+ | `labels` | the built-in English labels | Text shown for each line segment. An empty label hides it. |
69
+ | `panel` | `true` | Show the `/usage-insights` statistics panel and its commands. |
70
+ | `sidebar` | `true` | TUI only: show the session summary and per-prompt history in the sidebar. The Desktop history is the Turns insights tab. |
71
+ | `sidebarTurns` | `8` | How many turns the TUI sidebar and the Desktop Turns insights tab show (`1`–`50`; values outside are clamped). |
72
+ | `quota` | `true` | Read the host's OpenCode Go meters and show the `go` view, sidebar block and forecast. Off makes no usage-limits request. |
73
+ | `quotaName` | empty | Full subscription label. Empty uses the provider display name, then `OpenCode Go`. |
74
+
75
+ Panel view, range, sort, bucket and filter state stay local to each client: they
76
+ are view state, not configuration, so two windows on different sessions do not
77
+ move each other's panel.
78
+
79
+ ### Line fields and labels
80
+
81
+ The line is edited field by field in the settings UI. **Fields:** `clock`,
82
+ `delta`, `model`, `variant`, `turn`, `session`, `reasoning`, `cost`,
83
+ `cacheExpiry`. **Labels:** `delta`, `turn`, `session`, `step`, `steps`, `input`,
84
+ `cached`, `output`, `reasoning`, `cost`, `estimate`, `cacheExpired`,
85
+ `providerChanged`, `modelChanged`. An empty label hides that segment; the turn
86
+ segment is empty by default, and `delta` defaults to `Δ`.
87
+
88
+ ## Server policy
89
+
90
+ Three things are not editable over the RPC. They are read from the environment
91
+ when the server part starts:
92
+
93
+ | Variable | Default | Meaning |
94
+ | --- | --- | --- |
95
+ | `OPENCODE_USAGE_INSIGHTS_DB` | per-OS state path | SQLite path override, resolved by the server. |
96
+ | `OPENCODE_USAGE_INSIGHTS_MAINTENANCE` | `true` | `0`/`false` disables `prune`, `wipe`, `vacuum` and `backfill`. |
97
+ | `OPENCODE_USAGE_INSIGHTS_EXPOSE_PATHS` | `false` | `1`/`true` returns the absolute database path in the `db` view. |
98
+
99
+ The settings editors show the active policy read-only. Set maintenance off on a
100
+ server reachable from other machines unless you need the destructive buttons
101
+ there. Changing a policy needs a server restart; shared settings do not.
102
+
103
+ ## Upgrading from options
104
+
105
+ There is no automatic migration. Keep the package entry as a string and re-enter
106
+ any customization in Settings → Usage insights or `/insights-settings`. A stale
107
+ options object logs a warning on the server. Removing the package entry is the
108
+ way to disable the plugin; the old `enabled` option is gone.
package/docs/costs.md ADDED
@@ -0,0 +1,44 @@
1
+ # Costs and estimates
2
+
3
+ **Charged money is never recalculated.** `steps.cost` is what the host reports.
4
+ When it is `0` or missing and the model has a price in the host's model list, the
5
+ plugin stores a list-price estimate in `steps.list_cost` (USD per 1M tokens).
6
+ `≈` marks an estimate, never a charge.
7
+
8
+ | Surface | Price source |
9
+ | --- | --- |
10
+ | Server recorder and backfill | `ctx.model.list()` |
11
+ | Live line (TUI/Desktop) | `data.location.model.list(location)` |
12
+ | Panel, sidebar, NDJSON, CLI | stored `steps.list_cost` |
13
+ | `sess` segment | `SUM(list_cost)` over the RPC |
14
+
15
+ The host resolves provider config/overrides. The plugin does not read
16
+ `~/.cache/opencode/models.json`, does not use `opencode models` for prices, and
17
+ makes no network call. `list_cost` is `NULL` for charged or unknown, `0` for a
18
+ known free model, and positive for an estimate. An unknown or inapplicable price
19
+ means no estimate; an all-zero price means free. The formula, context tiers and
20
+ worked example are in
21
+ [internals.md](internals.md#list-price-estimates).
22
+
23
+ | Situation | Line | Panel |
24
+ | --- | --- | --- |
25
+ | Charged | `cost $0.12` | `$0.12` |
26
+ | Covered (host `0`, price known) | `cost ≈ $3.40` | `≈$3.40` |
27
+ | Mixed | `cost $0.12 + ≈ $3.40` | `$0.12 + ≈ $3.40`; table `≈$3.52` |
28
+ | Compaction/title | in the host `sess` total | overview `other`; session/period cost |
29
+ | Known free / price unknown | cost omitted | `$0` |
30
+
31
+ The host also reports compaction and title usage with no assistant step. It is
32
+ stored in `usage`, keyed by the host event ID, and included in the overview,
33
+ periods and sessions totals; it is not attributed to a model because the host
34
+ record carries none. See [internals.md](internals.md#non-step-usage).
35
+
36
+ The live line's turn estimate uses the client's current model list; the `sess`
37
+ segment and historical views use the stored estimate, which freezes the price at
38
+ recording time. If the plugin started mid-session, the estimate covers only the
39
+ recorded steps; the charged total still follows the host.
40
+
41
+ Turning **List-price estimates** off in Settings hides estimates and disables the
42
+ backfill without deleting data. The `db` view counts `$0` steps without an
43
+ estimate and can backfill them at today's list price (`e` in the TUI, **Backfill**
44
+ in the Desktop panel).
package/docs/demo.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # Demo output
2
2
 
3
3
  Generated with `bun run demo 100` against a seeded throwaway database (times
4
- render in the local timezone). `bun run docs:images` captures the screenshots
5
- from the same database, through the same components the TUI renders.
4
+ render in the local timezone). `bun run docs:images` captures the TUI
5
+ screenshots from the same database, through the same components the TUI
6
+ renders. The annotated captures are produced by `bun run docs:annotate` (needs
7
+ Pillow). The sidebar and Turns captures use a demo OpenCode Go subscription so
8
+ the forecast and renewal are visible. The Desktop images use the same demo
9
+ dataset; see [desktop.md](desktop.md).
6
10
 
7
11
  ## The line
8
12
 
@@ -10,16 +14,31 @@ from the same database, through the same components the TUI renders.
10
14
 
11
15
  ## The sidebar
12
16
 
13
- ![The session sidebar: the session totals and its last turns](images/sidebar.png)
17
+ ![The session sidebar with the Go forecast and the latest turns](images/sidebar.png)
14
18
 
15
19
  ## The panel
16
20
 
17
21
  ![The /usage-insights overview view](images/panel-overview.png)
18
22
 
23
+ ![The /usage-insights latency view: wall, stream, TTFT, TPS and request TPS](images/panel-latency.png)
24
+
19
25
  ![The /usage-insights providers view](images/panel-providers.png)
20
26
 
21
27
  ![The /usage-insights cache view](images/panel-cache.png)
22
28
 
29
+ ![The help overlay, including the TPS, request TPS and TTFT definitions](images/panel-help.png)
30
+
31
+ ## Desktop
32
+
33
+ The Desktop images use the same demo dataset; the overview and the history are
34
+ annotated.
35
+
36
+ ![Annotated Usage insights in OpenCode Desktop](images/desktop-overview-annotated.png)
37
+
38
+ ![Annotated Turns insights in OpenCode Desktop](images/desktop-turns-go-annotated.png)
39
+
40
+ ![Settings · Usage insights in OpenCode Desktop](images/desktop-settings.png)
41
+
23
42
  ## Full output
24
43
 
25
44
  ```text
@@ -52,17 +71,18 @@ sidebar (the session's totals, then the turns — three lines each, plus the mod
52
71
  session
53
72
  3 steps · in 130.3k
54
73
  cached 3.24M · out 8.25k
55
- hit 96.1% · 1618/s · $1.69
74
+ hit 96.1% · 2171 tps · 1618 rtps
75
+ ttft p50 400ms · $1.69
56
76
 
57
77
  turns
58
- 09:42 anthropic
78
+ 09:42 anthropic · 1m14s
59
79
  claude-opus-4.6
60
- in 23.8k (119.8k) · out 3.3k
61
- hit 80.1% · 1179/s · $1.42
62
- 09:24 opencode
80
+ in 23.8k · out 3.3k · hit 80.1%
81
+ 1500 tps · 600ms ttft · $1.42
82
+ 09:24 opencode · 23m20s
63
83
  deepseek-v4.1-flash-free
64
- in 10.3k (1.62M) · out 1.25k
65
- hit 99.4% · 2152/s · $0.2700
84
+ in 10.3k · out 1.25k · hit 99.4%
85
+ 3094 tps · 400ms ttft · $0.2700
66
86
 
67
87
  /usage-insights overview
68
88
  ────────────────────────────────────────────────────────────────────────────────────────────────────
@@ -71,7 +91,8 @@ steps 7 in 287.1k
71
91
  prompt 4.87M cached 4.58M
72
92
  hit 94.1% out 26.6k
73
93
  write 45.6k reasoning 900
74
- cost $2.70 tps 2709.2/s
94
+ tps 3792.9/s rtps 2709.2/s
95
+ ttft p50 400ms cost $2.70
75
96
  first 12/10/2026, 09:01:00 last 15/10/2026, 07:20:31
76
97
 
77
98
  activity █▁▁▁▁▁▁▁▁▁▃▁▁▁▁▁▁▁▃▁▁▁▁▁▆ 25 buckets
@@ -81,31 +102,32 @@ steps 3 in 130.3k
81
102
  prompt 3.37M cached 3.24M
82
103
  hit 96.1% out 8.25k
83
104
  write 23.9k reasoning 900
84
- cost $1.69 tps 1617.6/s
105
+ tps 2171.1/s rtps 1617.6/s
106
+ ttft p50 400ms cost $1.69
85
107
 
86
108
  data coverage
87
109
  models 4 · unknown 0.0% providers 3
88
- unsettled 0 · no tps 0.0%
110
+ unsettled 0 · no tps 0.0% no ttft 0.0%
89
111
  window 12/10/2026, 09:01:00 → 15/10/2026, 07:20:00
90
112
 
91
113
  /usage-insights models
92
114
  ────────────────────────────────────────────────────────────────────────────────────────────────────
93
- model steps prompt cached hit out cost providers
94
- deepseek-v4.1-flash 1 410.6k 402k 97.9% 2.1k $0.0700 opencode-go
95
- p50 hit 97.9% · 1 switch (1 provider)
96
- claude-opus-4.6 1 119.8k 96k 80.1% 3.3k $1.42 anthropic
97
- p50 hit 80.1% · 1 switch (1 provider)
98
- glm-5.3-flash 2 754.1k 632.4k 83.9% 9.9k $0.7600 opencode
99
- p50 hit 14.6%
100
- deepseek-v4.1-flash-free 3 3.59M 3.45M 96.3% 11.3k $0.4500 opencode
101
- p50 hit 94.1%
115
+ model steps prompt cached hit out cost
116
+ deepseek-v4.1-flash-free 3 3.59M 3.45M 96.3% 11.3k $0.4500
117
+ p50 hit 94.1%
118
+ glm-5.3-flash 2 754.1k 632.4k 83.9% 9.9k $0.7600
119
+ p50 hit 14.6%
120
+ deepseek-v4.1-flash 1 410.6k 402k 97.9% 2.1k $0.0700
121
+ p50 hit 97.9% · 1 switch (1 provider)
122
+ claude-opus-4.6 1 119.8k 96k 80.1% 3.3k $1.42
123
+ p50 hit 80.1% · 1 switch (1 provider)
102
124
 
103
125
  /usage-insights providers
104
126
  ────────────────────────────────────────────────────────────────────────────────────────────────────
105
- provider models steps share prompt cached hit tps p50 wall
106
- anthropic 1 1 14% 119.8k 96k 80.1% 1178.6/s 1m14s
107
- opencode-go 1 1 14% 410.6k 402k 97.9% 2625.0/s 31.0s
108
- opencode 2 5 71% 4.34M 4.09M 94.1% 3000.0/s 58.0s
127
+ provider models steps share prompt cached hit tps p50 ttft p50 wall cost
128
+ opencode 2 5 71% 4.34M 4.09M 94.1% 4363.6/s 400ms 58.0s $1.21
129
+ anthropic 1 1 14% 119.8k 96k 80.1% 1500.0/s 600ms 1m14s $1.42
130
+ opencode-go 1 1 14% 410.6k 402k 97.9% 3818.2/s 250ms 31.0s $0.0700
109
131
 
110
132
  /usage-insights cache
111
133
  ────────────────────────────────────────────────────────────────────────────────────────────────────
@@ -113,24 +135,25 @@ reuse losses 1 event · 607.6k tokens
113
135
  expired 1 · 607.6k
114
136
 
115
137
  reuse by model
116
- model steps prompt cached write hit hit p50
117
- deepseek-v4.1-flash-free 3 3.59M 3.45M 16.9k 96.3% 94.1%
118
- glm-5.3-flash 2 754.1k 632.4k 17k 83.9% 14.6%
119
- deepseek-v4.1-flash 1 410.6k 402k 700 97.9% 97.9%
120
- claude-opus-4.6 1 119.8k 96k 11k 80.1% 80.1%
138
+ model steps prompt cached write hit hit p50
139
+ deepseek-v4.1-flash-free 3 3.59M 3.45M 16.9k 96.3% 94.1%
140
+ glm-5.3-flash 2 754.1k 632.4k 17k 83.9% 14.6%
141
+ deepseek-v4.1-flash 1 410.6k 402k 700 97.9% 97.9%
142
+ claude-opus-4.6 1 119.8k 96k 11k 80.1% 80.1%
121
143
 
122
144
  cache survival against idle time
123
- gap pairs kept drops lost
124
- 20–30m 1 100% 0 0
125
- >6h 1 0% 1 607.6k
145
+ gap pairs kept drops lost
146
+ 20–30m 1 100% 0 0
147
+ >6h 1 0% 1 607.6k
126
148
 
127
149
  observed cache TTL bounds
128
- model hits up to drops from samples
129
- opencode/deepseek-v4.1-flash-free 22m – 1
130
- opencode/glm-5.3-flash – 23.9h 1
150
+ model hits up to drops from samples
151
+ opencode/deepseek-v4.1-flash-free 22m – 1
152
+ opencode/glm-5.3-flash – 23.9h 1
131
153
 
132
154
  recent losses
133
- 15:00:00 opencode/glm-5.3-flash −607.6k 23.9h idle · expired
155
+ when provider/model tokens idle
156
+ 15:00:00 opencode/glm-5.3-flash −607.6k 23.9h idle · expired
134
157
 
135
158
  /usage-insights periods
136
159
  ────────────────────────────────────────────────────────────────────────────────────────────────────
@@ -138,59 +161,62 @@ per day · 4 periods · 7 steps · hit 94.1%
138
161
  steps █▃▃▆
139
162
  cached █▂▁▃
140
163
  cost █▂▃▂
141
- period steps sess prompt cached hit out cost
142
- 2026-10-15 2 1 747.1k 712k 95% 8.4k $0.2500
143
- 2026-10-14 1 1 85.1k 12.4k 15% 4.8k $0.4400
144
- 2026-10-13 1 1 669k 620k 93% 5.1k $0.3200
145
- 2026-10-12 3 1 3.37M 3.24M 96% 8.25k $1.69
164
+ period steps sess prompt cached hit out cost
165
+ 2026-10-15 2 1 747.1k 712k 95% 8.4k $0.2500
166
+ 2026-10-14 1 1 85.1k 12.4k 15% 4.8k $0.4400
167
+ 2026-10-13 1 1 669k 620k 93% 5.1k $0.3200
168
+ 2026-10-12 3 1 3.37M 3.24M 96% 8.25k $1.69
146
169
 
147
- total 7 4 4.87M 4.58M 94% 26.6k $2.70
170
+ total 7 3 4.87M 4.58M 94% 26.6k $2.70
148
171
 
149
172
  /usage-insights latency
150
173
  ────────────────────────────────────────────────────────────────────────────────────────────────────
151
174
  wall p50 58.0s p90 1m28s p99 1m28s n 7
152
175
  stream p50 1.2s p90 2.8s p99 2.8s
153
- throughput p50 2642.9/s p90 5250.0/s p99 5250.0/s
176
+ ttft p50 400ms p90 600ms p99 600ms
177
+ tps p50 3818.2/s p90 7875.0/s p99 7875.0/s
178
+ rtps p50 2642.9/s p90 5250.0/s p99 5250.0/s
154
179
 
155
- wall = request to completed · stream = request to last chunk · throughput = output+reasoning tokens…
180
+ wall = request to completed · stream = request to last chunk
181
+ ttft = request to first token · tps = first token to last chunk · rtps = request to last chunk
156
182
 
157
183
  by group
158
- group n wall p50 wall p90 stream tps p50 tps p90 cost
159
- claude-opus-4.6 1 1m14s 1m14s 2.8s 1178.6/s 1178.6/s $1.42
160
- deepseek-v4.1-f… 1 31.0s 31.0s 800ms 2625.0/s 2625.0/s $0.0700
161
- glm-5.3-flash 2 58.0s 1m01s 1.1s 3000.0/s 4636.4/s $0.7600
162
- deepseek-v4.1-f… 3 52.0s 1m28s 1.2s 2642.9/s 5250.0/s $0.4500
184
+ group n wall p50 wall p90 stream tps p50 tps p90 ttft p50 cost
185
+ deepseek-v4.1-flash-free 3 52.0s 1m28s 1.2s 3700.0/s 7875.0/s 400ms $0.4500
186
+ glm-5.3-flash 2 58.0s 1m01s 1.1s 4363.6/s 6800.0/s 350ms $0.7600
187
+ claude-opus-4.6 1 1m14s 1m14s 2.8s 1500.0/s 1500.0/s 600ms $1.42
188
+ deepseek-v4.1-flash 1 31.0s 31.0s 800ms 3818.2/s 3818.2/s 250ms $0.0700
163
189
  n < 5 is dimmed: too few samples to compare
164
190
 
165
191
  /usage-insights sessions
166
192
  ────────────────────────────────────────────────────────────────────────────────────────────────────
167
- title steps prompt cached hit out cost
168
- Refactor the recorder 3 3.37M 3.24M 96% 8.25k $1.69
193
+ title steps prompt cached hit out cost
194
+ Docs pass 2 747.1k 712k 95% 8.4k $0.2500
169
195
  /code/opencode-usage-insights · 2 models
170
- Fix the cache regression 2 754.1k 632.4k 84% 9.9k $0.7600
196
+ Fix the cache regression 2 754.1k 632.4k 84% 9.9k $0.7600
171
197
  /code/opencode-usage-insights
172
- Docs pass 2 747.1k 712k 95% 8.4k $0.2500
198
+ Refactor the recorder 3 3.37M 3.24M 96% 8.25k $1.69
173
199
  /code/opencode-usage-insights · 2 models
174
200
 
175
201
  /usage-insights turns
176
202
  ────────────────────────────────────────────────────────────────────────────────────────────────────
177
203
  6 turns · newest first
178
- Refactor the reco… 09:24:20 · opencode/deepseek-v4.1-flash-free · 2 steps · in 10.3k (1.62M), cach…
179
- Refactor the reco… 09:42:14 · Δ 40m00s · anthropic/claude-opus-4.6 · changed · in 23.8k (119.8k),…
180
- Fix the cache reg… 15:03:01 · opencode/glm-5.3-flash · in 49k (669k), cached 620k, out 5.1k, cost…
181
- Fix the cache reg… 15:00:58 · Δ 23h58m · opencode/glm-5.3-flash · in 72.7k (85.1k), cached 12.4k,…
182
- Docs pass 07:01:28 · opencode/deepseek-v4.1-flash-free · in 26.5k (336.5k), cached 310k, out 6.3k,…
183
- Docs pass 07:20:31 · Δ 20m00s · opencode-go/deepseek-v4.1-flash · changed · in 8.6k (410.6k), cach…
204
+ Docs pass 07:20:31 opencode-go/deepseek-v4.1-flash · in 8.6k (410.6k), cached 402k · cost $0.0700
205
+ Docs pass 07:01:28 opencode/deepseek-v4.1-flash-free · in 26.5k (336.5k) · cost $0.1800
206
+ Fix the cache reg… 15:00:58 opencode/glm-5.3-flash · in 72.7k (85.1k), cached 12.4k · cost $0.4400
207
+ Fix the cache reg… 15:03:01 opencode/glm-5.3-flash · in 49k (669k), cached 620k · cost $0.3200
208
+ Refactor the reco… 09:42:14 anthropic/claude-opus-4.6 · in 23.8k (119.8k), cached 96k · cost $1.42
209
+ Refactor the reco… 09:24:20 opencode/deepseek-v4.1-flash-free · in 10.3k (1.62M) · cost $0.2700
184
210
 
185
211
  /usage-insights db
186
212
  ────────────────────────────────────────────────────────────────────────────────────────────────────
187
- /tmp/usage-insights-demo-mFDbHx/usage.db
188
- 0.0 MB + 0.4 MB wal · schema v11
213
+ /tmp/usage-insights-demo-ccgvVs/usage.db
214
+ 0.0 MB + 0.5 MB wal · schema v14
189
215
 
190
216
  what it holds
191
217
  sessions 3 rows
192
218
  prompts 6 rows
193
- events 0 rows
219
+ compactions 0 rows
194
220
  steps 7 rows
195
221
  usage 0 rows
196
222
  window 12/10/2026 → 15/10/2026
@@ -198,10 +224,10 @@ what it holds
198
224
  clean up
199
225
  ↑↓ pick a retention · enter prunes from its cutoff · the wipe row deletes everything (asks first)…
200
226
  list estimates every $0 step has a price
201
- keep prunes older than
202
- 30 days 0 steps 16/09/2026
203
- 90 days 0 steps 18/07/2026
204
- 365 days 0 steps 16/10/2025
227
+ keep prunes older than
228
+ 30 days 0 steps 16/09/2026
229
+ 90 days 0 steps 18/07/2026
230
+ 365 days 0 steps 16/10/2025
205
231
 
206
232
  wipe everything · 7 steps · 3 sessions · cannot be undone
207
233
  ```
@@ -0,0 +1,91 @@
1
+ # OpenCode Desktop
2
+
3
+ The Desktop part is a spend badge in the session header and two side-region
4
+ panels. The window is Electron/Chromium: it has no Bun, no `bun:sqlite` and no
5
+ Node filesystem. The recorder, database and worker stay in the server, and the
6
+ window reads them over the same RPC the TUI uses. The images below use the demo
7
+ dataset; see [demo.md](demo.md) for the rest.
8
+
9
+ ![Annotated Usage insights in OpenCode Desktop](images/desktop-overview-annotated.png)
10
+
11
+ *1 turn or session spend · 2 Usage insights panel · 3 session totals · 4 data
12
+ coverage.*
13
+
14
+ ## The cost badge
15
+
16
+ Next to the peak/off-peak badge, the usage insights badge shows the finished
17
+ turn's spend (`$0.0210` or `≈$0.0210`). Hovering shows the full telemetry line.
18
+ While a turn runs the badge shows the session's accumulated spend instead
19
+ (`≈$1.90`) and returns to the turn's spend when it ends. Clicking it opens
20
+ **Turns insights**. The shared line settings apply to the line, the badge
21
+ tooltip and the panel; turning off the cost field hides the badge, and turning
22
+ off the session field keeps it hidden while a turn runs.
23
+
24
+ ## Usage insights and Turns insights
25
+
26
+ `/usage-insights` (alias `/insights`) opens **Usage insights** in the side
27
+ region. It has the same ten views, five ranges, drill-downs, sorting and filters
28
+ as the TUI, plus the database view's maintenance buttons. The view menu lists
29
+ **OpenCode Go** immediately after **Overview**.
30
+
31
+ **Turns insights** shows the current session's history. `/usage-insights turns`
32
+ opens the same history inside Usage insights, where the session/all-sessions
33
+ scope is available. Both panels link to each other: **Open turns insights** in
34
+ the Usage insights footer, **Open usage insights** in Turns insights.
35
+
36
+ | Where | What it shows |
37
+ | --- | --- |
38
+ | Session header badge | The turn spend and the full line on hover; click opens Turns insights. |
39
+ | Turns insights tab | The current session's complete history, with the same compact Go forecast block as the TUI sidebar. `/usage-insights turns` adds the session/all-sessions scope. |
40
+ | Side panel `+` menu | **Usage insights** and **Turns insights** launchers. |
41
+
42
+ The TUI's always-visible sidebar has no Desktop slot. Panel state is stored
43
+ separately from the TUI: opening the Desktop panel does not move the TUI panel,
44
+ and vice versa.
45
+
46
+ ![Annotated Turns insights in OpenCode Desktop](images/desktop-turns-go-annotated.png)
47
+
48
+ *1 the Go forecast · 2 the renewal date · 3 request TPS, TTFT and spend ·
49
+ 4 one line per turn.*
50
+
51
+ ## Settings
52
+
53
+ **Settings → Usage insights** edits the same shared settings as the TUI's
54
+ `/insights-settings` command: list-price estimates, turn totals, every line
55
+ field and label, the panels, the sidebar, the Go allowance and its label.
56
+ Changes apply live to every open TUI and Desktop window. The page also documents
57
+ the rate windows, the formulas and the fallback for old steps.
58
+
59
+ The server is the single source of truth. Settings are per server, so a TUI or
60
+ Desktop connected to another server reads and writes that server's value. The
61
+ database path and the two security switches are server policy, not app settings.
62
+ See [configuration.md](configuration.md#settings) for the full list.
63
+
64
+ ![The rates and formulas section of Settings · Usage insights](images/desktop-settings.png)
65
+
66
+ ## Server side
67
+
68
+ The server registers the usage RPC and the settings RPC, and starts a database
69
+ worker. The worker owns a read-only SQLite connection for the panel and the turn
70
+ history, and opens a short write connection for `prune`, `wipe`, `vacuum` and
71
+ `backfill`. Panel queries never block the agent's event loop, and the TUI does
72
+ not open SQLite either.
73
+
74
+ The worker starts lazily on the first usage request (the panel, the history or
75
+ the header badge estimate). If it cannot start, the server falls back to an
76
+ in-process service and logs it; the plugin still works, but the fallback shares
77
+ the server's event loop.
78
+
79
+ If the plugin was installed before it gained the GUI part, restart the
80
+ background service once (`opencode service restart`) and reopen the Desktop
81
+ window. The plugin inventory caches the package's parts.
82
+
83
+ ## Remote servers
84
+
85
+ The TUI and Desktop call the RPC on the server that owns the session. A TUI
86
+ connected to a remote server shows that server's usage; the Desktop panel and
87
+ the shared settings target the session's server. The plugin's server part must
88
+ be installed on that server. If it is not, the panel explains that usage data is
89
+ unavailable, and the settings editors fall back to defaults. Server policy and
90
+ the maintenance switch are in
91
+ [configuration.md](configuration.md#server-policy).
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file