@1930dev/opencode-usage 0.1.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 (4) hide show
  1. package/README.md +144 -0
  2. package/dist/cli.js +922 -0
  3. package/dist/tui.js +833 -0
  4. package/package.json +58 -0
package/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # opencode-usage
2
+
3
+ Usage tracking, cost estimation, and model ranking CLI for [opencode](https://opencode.ai).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g @1930dev/opencode-usage # the opencode-usage CLI
9
+ ```
10
+
11
+ Requires [Bun](https://bun.sh): the CLI reads opencode's SQLite through `bun:sqlite`.
12
+
13
+ ## Usage
14
+
15
+ ```bash
16
+ # Local usage from opencode's SQLite (all providers, all projects)
17
+ opencode-usage usage # last 7 days, grouped by provider
18
+ opencode-usage usage --today # today only
19
+ opencode-usage usage --since 30d # last 30 days
20
+ opencode-usage usage --by model # group by model instead of provider
21
+ opencode-usage usage --by project # group by project directory
22
+ opencode-usage usage --by agent # group by agent (build/plan/etc)
23
+ opencode-usage usage --pct # add % BUDGET column (requires --by provider)
24
+ # --by provider lists every connected provider, including those idle in the window
25
+ opencode-usage usage --json # machine-readable output
26
+
27
+ # Connected providers + live quota
28
+ opencode-usage providers
29
+ opencode-usage providers --no-net # cached only
30
+
31
+ # Model ranking by intelligence per blended dollar
32
+ opencode-usage top
33
+ opencode-usage top --limit 10 --json
34
+ ```
35
+
36
+ ## Plugin for opencode
37
+
38
+ The package also ships a `/usage` slash command for the opencode TUI. It shows the
39
+ same table as the CLI, with the % budget column drawn as a progress bar.
40
+
41
+ ```bash
42
+ opencode plugin @1930dev/opencode-usage
43
+ ```
44
+
45
+ That installs the package and writes it into `~/.config/opencode/tui.json`. To do it
46
+ by hand:
47
+
48
+ ```json
49
+ {
50
+ "$schema": "https://opencode.ai/tui.json",
51
+ "plugin": ["@1930dev/opencode-usage"]
52
+ }
53
+ ```
54
+
55
+ TUI plugins go in `tui.json`, not in `opencode.json` and not in
56
+ `~/.config/opencode/plugins/`. Both of those are loaded as *server* plugins, and
57
+ opencode rejects a TUI-only module there with
58
+ `must default export an object with server()`.
59
+
60
+ To run it from a clone instead, build first and point `tui.json` at the bundle:
61
+
62
+ ```bash
63
+ bun install && bun run build
64
+ ```
65
+
66
+ ```json
67
+ { "plugin": ["/absolute/path/to/opencode-usage/dist/tui.js"] }
68
+ ```
69
+
70
+ Restart opencode after a rebuild: the bundle is read once at start.
71
+
72
+ ## % BUDGET (`--pct`)
73
+
74
+ Normalized percentage of budget consumed per provider, from these sources (in priority):
75
+
76
+ 1. **Live quota** — provider-reported usage:
77
+ - `opencode-go` (Zen): rolling 5h / weekly / monthly % (binding window)
78
+ - `github-copilot`: premium requests entitlement (7000/mo)
79
+ - `openrouter`: credits used / total credits
80
+ - `zai`: coding plan quota
81
+
82
+ 2. **Documented limits** — monthly equivalent of daily limits:
83
+ - `groq`: 200k tokens/day → 6M/month
84
+ - `google`: 1500 requests/day → 45k/month
85
+ - `digitalocean`: 5M tokens/day → 150M/month
86
+ - `cerebras`: 1M tokens/day → 30M/month
87
+ - `google` (Gemini free): 1500 requests/day → 45k/month
88
+ - `groq`: 200k tokens/day → 6M/month
89
+ - `cerebras`: 1M tokens/day → 30M/month
90
+
91
+ 3. **budgets.json** — your monthly USD per provider:
92
+ ```json
93
+ {
94
+ "digitalocean": 5,
95
+ "nvidia": 1
96
+ }
97
+ ```
98
+ Place at `~/.config/opencode-usage/budgets.json`.
99
+
100
+ Providers without any source show `—`.
101
+
102
+ ## Ranking (`top`)
103
+
104
+ Models ranked by intelligence index per blended dollar:
105
+ ```
106
+ MODEL NAME IQ CODING $/M IQ/$
107
+ glm-5.3-flash GLM 5.3-Flash 58 72 $0.11 534.9
108
+ ...
109
+ ```
110
+
111
+ Data from [Artificial Analysis](https://artificialanalysis.ai) (Intelligence Index v4.1) + [models.dev](https://models.dev) pricing.
112
+
113
+ ## Requirements
114
+
115
+ - [Bun](https://bun.sh) ≥ 1.0
116
+ - [opencode](https://opencode.ai) with existing sessions (reads `~/.local/share/opencode/opencode.db`)
117
+ - For live quota: credentials already configured in opencode (`~/.local/share/opencode/auth.json`)
118
+
119
+ ## Configuration
120
+
121
+ - `OPENCODE_DB_PATH` — override opencode database path
122
+ - `OPENCODE_AUTH_PATH` — override auth.json path
123
+ - `OPENCODE_IMP_CACHE` — cache directory (default `~/.cache/opencode-usage`)
124
+ - `OPENCODE_IMP_BUDGETS` — budgets.json path
125
+ - `AA_API_KEY` — Artificial Analysis API key, used by `top`. Without it, ranking is skipped
126
+ - `INFISICAL_PROJECT_ID` — optional: read `AA_API_KEY` from Infisical through the
127
+ `infisical-secret` wrapper instead of from the environment
128
+
129
+ ## Development
130
+
131
+ ```bash
132
+ bun install # install workspace deps
133
+ bun test # run tests
134
+ bunx tsc --noEmit # typecheck
135
+ ```
136
+
137
+ The workspace is a Bun monorepo with three packages:
138
+ - `@opencode-usage/core` — shared data layer (SQLite, quotas, matching)
139
+ - `@opencode-usage/cli` — the `opencode-usage` CLI
140
+ - `@opencode-usage/plugin` — TUI plugin for opencode itself
141
+
142
+ ## License
143
+
144
+ MIT