@slkiser/opencode-quota 2.3.0 → 2.4.1

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 CHANGED
@@ -12,7 +12,7 @@ Track OpenCode quota & tokens via Toasts/Commands with zero context window pollu
12
12
 
13
13
  ![Image of quota toasts](https://github.com/slkiser/opencode-quota/blob/main/toast.png)
14
14
 
15
- **Token Report Commands** - Track token usage and estimated costs across sessions using only local OpenCode SQLite history plus the bundled models.dev snapshot (no network calls).
15
+ **Token Report Commands** - Track token usage and estimated costs across sessions using local OpenCode SQLite history plus a local models.dev pricing snapshot. The plugin can refresh that local snapshot at runtime when stale.
16
16
 
17
17
  ![Image of /quota and /tokens_daily outputs](https://github.com/slkiser/opencode-quota/blob/main/quota.png)
18
18
 
@@ -77,7 +77,39 @@ Token reporting commands are the `/tokens_*` family (there is no `/token` comman
77
77
  | Google Antigravity | `google-antigravity` | Multi-account via `opencode-antigravity-auth` |
78
78
  | Z.ai | `zai` | OpenCode auth (automatic) |
79
79
 
80
- Token pricing coverage is broader than quota provider support: `/tokens_*` maps usage against all provider/model entries present in the bundled models.dev data snapshot.
80
+ Token pricing coverage is broader than quota provider support: `/tokens_*` maps usage against provider/model entries in the active local models.dev pricing snapshot.
81
+
82
+ Pricing refresh ownership is now runtime-based:
83
+
84
+ - A bundled snapshot (`src/data/modelsdev-pricing.min.json`) is always shipped as bootstrap/offline fallback.
85
+ - At plugin runtime, when `experimental.quotaToast.enabled` is `true`, pricing refresh runs as a bounded best-effort check (once per process window, plus persisted attempt tracking) during init and before `/tokens_*` / `/quota_status` report paths.
86
+ - If the active snapshot is older than 3 days, the plugin attempts to fetch `https://models.dev/api.json`, keeps only `input`, `output`, `cache_read`, `cache_write`, and writes a refreshed local runtime snapshot.
87
+ - If fetch fails, reports continue using the last local snapshot (no hard failure).
88
+
89
+ Runtime snapshot files are stored under the OpenCode cache directory:
90
+
91
+ - `.../opencode/opencode-quota/modelsdev-pricing.runtime.min.json`
92
+ - `.../opencode/opencode-quota/modelsdev-pricing.refresh-state.json`
93
+
94
+ Runtime refresh toggles:
95
+
96
+ ```sh
97
+ # Disable runtime pricing refresh
98
+ OPENCODE_QUOTA_PRICING_AUTO_REFRESH=0
99
+
100
+ # Change stale threshold (default: 3 days)
101
+ OPENCODE_QUOTA_PRICING_MAX_AGE_DAYS=5
102
+ ```
103
+
104
+ Maintainer-only bundled snapshot refresh (manual):
105
+
106
+ ```sh
107
+ npm run pricing:refresh
108
+ npm run pricing:refresh:if-stale
109
+ npm run build
110
+ ```
111
+
112
+ `pricing:refresh:if-stale` uses the same env knobs as runtime refresh (`OPENCODE_QUOTA_PRICING_AUTO_REFRESH`, `OPENCODE_QUOTA_PRICING_MAX_AGE_DAYS`).
81
113
 
82
114
  ### Provider-Specific Setup
83
115
 
@@ -104,6 +136,17 @@ Both fine-grained PATs (`github_pat_...`) and classic PATs (`ghp_...`) should wo
104
136
 
105
137
  Tier options: `free`, `pro`, `pro+`, `business`, `enterprise`
106
138
 
139
+ PAT scope guidance (read-only first):
140
+
141
+ - Personal/user-billed Copilot usage: fine-grained PAT with **Account permissions > Plan > Read**.
142
+ - Organization-managed Copilot usage metrics: classic token with **`read:org`** (or fine-grained org permission **Organization Copilot metrics: read** when using org metrics endpoints).
143
+ - Enterprise-managed Copilot usage metrics: classic token with **`read:enterprise`**.
144
+
145
+ GitHub notes that user-level billing endpoints may not include usage for org/enterprise-managed seats; use org/enterprise metrics endpoints in that case.
146
+
147
+ When both Copilot OAuth auth and `copilot-quota-token.json` are present, the plugin prefers the PAT billing path for quota metrics.
148
+ Run `/quota_status` and check `copilot_quota_auth` to confirm `pat_state`, candidate paths checked, and `effective_source`/`override`.
149
+
107
150
  </details>
108
151
 
109
152
  <details>
@@ -215,7 +258,7 @@ All options go under `experimental.quotaToast` in `opencode.json` or `opencode.j
215
258
 
216
259
  | Option | Default | Description |
217
260
  | ------------------- | ------------ | ---------------------------------------------------------------------------------------------------- |
218
- | `enabled` | `true` | Enable/disable plugin |
261
+ | `enabled` | `true` | Enable/disable plugin. When `false`, `/quota`, `/quota_status`, and `/tokens_*` are strict no-ops. |
219
262
  | `enableToast` | `true` | Show popup toasts |
220
263
  | `toastStyle` | `classic` | Toast layout style: `classic` or `grouped` |
221
264
  | `enabledProviders` | `"auto"` | Provider IDs to query, or `"auto"` to detect |