opencode-peak-badge 0.4.0 → 0.6.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 CHANGED
@@ -5,57 +5,30 @@
5
5
  [![Test](https://img.shields.io/github/actions/workflow/status/hugobatista/opencode-peak-badge/test.yml?label=Test)](https://go.hugobatista.com/gh/opencode-peak-badge/actions/workflows/test.yml)
6
6
  [![npm](https://img.shields.io/npm/v/opencode-peak-badge.svg)](https://www.npmjs.com/package/opencode-peak-badge)
7
7
 
8
- OpenCode TUI plugin. Shows a `[PEAK]` / `[OFF-PEAK]` badge in the footer status
9
- line, so you always know whether the active model is billed at peak rates. When
10
- a subagent session is running, its model is tracked too: peak wins across the
11
- main model and all running subagents. Updates live — no restart needed when a
12
- session crosses a peak window boundary.
13
-
14
- ![Demo](docs/demo-peak.png)
15
-
16
- > **Using OpenCode V1 (CLI v1)?** OpenCode V2 changed the plugin API, so this
17
- > plugin was rewritten. `0.3.0` is the last release compatible with V1. Since
18
- > `0.4.0` the npm `latest` tag points at the V2 build, so **pin the version**:
19
- > use `opencode-peak-badge@opencode-v1` (or `@0.3.0`). See
20
- > [OpenCode V1 (legacy)](#opencode-v1-legacy).
21
-
22
- ## What it does
23
-
24
- - Renders a badge in the footer status line via `prompt.footer.status` (session)
25
- and `home.footer.status` (home) whenever a model with configured peak hours is
26
- active — or always, with `alwaysShow: true`.
27
- - `[PEAK]` renders in the theme's warning color. `[OFF-PEAK]` renders in the
28
- muted color. The badge shows in **both** states for tracked models.
29
- - Recomputes every `pollSeconds` (default 10) and reacts live to
30
- `session.model.selected`, `session.agent.selected`, `session.status` and
31
- `model.updated` through the TUI's cached session data — no restart when a
32
- session crosses a peak boundary.
33
- - Tracks all descendant subagent sessions through `data.session.family()`. While
34
- a subagent session is `running`, its model is checked against the peak
35
- windows. Peak wins: if any running subagent is in peak hours, the badge shows
36
- `[PEAK]`. Disable with `subagents: false`.
37
- - Resolves the active model from the session's committed model
38
- (`data.session.get(id)?.model` plus `session.created` /
39
- `session.model.selected` events) and, while the picker selection has not been
40
- committed yet, from the TUI's last picked model in
41
- `<XDG_STATE_HOME>/opencode/model.json`. The home screen uses the picked model
42
- too, falling back to `client.model.default()` when there is no pick.
43
- - Follows model changes live: picking a model updates the badge immediately
44
- (both on the home screen and inside a running session), and a committed
45
- session model always wins over a stale pick.
46
- - Shows nothing for models without configured peak hours, unless
47
- `alwaysShow: true` forces the badge for the main model from the top-level
48
- `windows` / `weekdaysOnly`.
49
- - Provider-agnostic: track any model that has peak pricing by adding a rule
50
- under `models`. Built-in defaults cover DeepSeek models, which is where peak
51
- hours are known today.
8
+ `[PEAK]` / `[OFF-PEAK]` badge for OpenCode TUI and OpenCode Desktop. It follows
9
+ the active model's configured peak-hour rules; running subagents are included and
10
+ peak wins. Settings are stored by the plugin's server and shared by both
11
+ surfaces; changes apply live.
12
+
13
+ ![TUI with the peak badge](docs/demo-peak.png)
14
+
15
+ ## Features
16
+
17
+ - TUI: footer badge for the session (`prompt.footer.status`) and Home
18
+ (`home.footer.status`), plus a `/peak-badge` settings editor.
19
+ - Desktop: header chip for the session (`session.header`), status strip on Home
20
+ (`window.bottom`) and a **Settings → Peak Badge** page.
21
+ - Shared settings: the TUI and Desktop read and write the same server-stored
22
+ object; an edit in either client updates the other.
23
+ - Provider-agnostic; built-in rules cover DeepSeek models.
24
+ - Tracks running subagent sessions; if any is peak, the parent shows `[PEAK]`.
25
+ - Configurable models, UTC windows, labels, polling and fallback (`alwaysShow`).
52
26
 
53
27
  ## Requirements
54
28
 
55
- - **OpenCode V2.** The V2 release changed the plugin API; V1 plugin
56
- implementations do not run in V2. If you are on the V1 CLI, use `0.3.0` — see
57
- [OpenCode V1 (legacy)](#opencode-v1-legacy).
58
- - [Bun](https://bun.sh) to install dependencies (dev only).
29
+ - **OpenCode 2.4.2 or newer.** The TUI and Desktop use the V2 plugin API; the
30
+ desktop GUI requires 2.4.2+ and targets 2.4.2. The GUI plugin API is experimental.
31
+ - **Bun** for development.
59
32
 
60
33
  ## Install
61
34
 
@@ -63,337 +36,207 @@ session crosses a peak window boundary.
63
36
  opencode plugin add opencode-peak-badge
64
37
  ```
65
38
 
66
- Or add the package to `opencode.jsonc` (project or
67
- `~/.config/opencode/opencode.jsonc`):
68
-
69
- ```jsonc
70
- {
71
- "$schema": "https://opencode.ai/config.json",
72
- "plugins": ["opencode-peak-badge"]
73
- }
74
- ```
39
+ This writes the package to the global `opencode.json(c)`, which both the TUI and
40
+ Desktop read.
75
41
 
76
- To pass [options](#configuration), use the object form:
42
+ Manual alternative:
77
43
 
78
44
  ```jsonc
79
45
  {
80
46
  "$schema": "https://opencode.ai/config.json",
81
- "plugins": [
82
- { "package": "opencode-peak-badge", "options": { "pollSeconds": 30 } }
83
- ]
84
- }
85
- ```
86
-
87
- CLI-only installs can use `~/.config/opencode/cli.json` instead:
88
-
89
- ```jsonc
90
- {
91
47
  "plugins": ["opencode-peak-badge"]
92
48
  }
93
49
  ```
94
50
 
95
- Restart OpenCode if a watched config file changed. Published package plugins load
96
- at startup.
97
-
98
- Verify. Start a session with a tracked model (for example
99
- `opencode-go/deepseek-v4-flash`) and confirm the badge appears in the footer
100
- status line. To force a known state, see [Evaluation](#evaluation).
51
+ Settings are edited in the app, not in `opencode.json(c)`. Keep the package entry
52
+ as a string; the object form with `options` is no longer read (see
53
+ [Breaking change](#breaking-change-in-060)).
54
+
55
+ Keep the package in `opencode.json(c)`, not only in `cli.json`: the TUI loads its
56
+ part from the connected server, and the shared settings need the plugin's server
57
+ part. `cli.json` is only for TUI-only plugins.
58
+
59
+ OpenCode reloads plugins when config changes; `/reload` forces a full reload. A
60
+ package update may need a client restart (Desktop loads the GUI bundle from the
61
+ installed package).
62
+
63
+ Verify with a tracked model (for example `opencode-go/deepseek-v4-flash`): the TUI
64
+ footer badge, or the Desktop header chip. To force a state, see
65
+ [Evaluation](#evaluation).
66
+
67
+ ### Desktop surfaces
68
+
69
+ - **Session:** `session.header` chip next to the context indicator. The active
70
+ timeline uses `composer.model()`; a cached hidden timeline uses the committed
71
+ model. Compact headers show the icon only, with the full label as tooltip. The
72
+ exact order relative to native header actions is host-controlled; `order` only
73
+ sorts plugin contributions.
74
+ - **Home / draft:** `window.bottom` strip shown while no session is routed. It
75
+ uses `client.model.default()`; it may lag behind the Home picker until a session
76
+ starts.
77
+ - The peak state is orange on both surfaces. The shade follows the active
78
+ light/dark theme so the label keeps AA contrast on the default surfaces.
79
+ - The parent session chip aggregates running subagents. A subagent's own header
80
+ follows that subagent's model.
81
+ - **Settings → Peak Badge** edits the shared settings.
82
+ - Settings → Extensions → Plugins can disable the GUI.
83
+
84
+ ![Desktop session with the peak badge](docs/demo-desktop-session.png)
101
85
 
102
86
  ### OpenCode V1 (legacy)
103
87
 
104
- `0.3.0` is the last release compatible with the OpenCode V1 CLI. It uses the old
105
- `@opencode-ai/plugin/tui` API and the `tui.json` config. Pin the version
106
- explicitly:
88
+ `0.3.0` is the last V1-compatible release; npm `latest` is V2. Pin it:
107
89
 
108
90
  ```sh
109
91
  opencode plugin opencode-peak-badge@opencode-v1 --global
110
- # or, exact pin (guaranteed):
111
- opencode plugin opencode-peak-badge@0.3.0 --global
112
92
  ```
113
93
 
114
- Or, CLI-version-proof, in `~/.config/opencode/tui.json`:
94
+ Or in `~/.config/opencode/tui.json`:
115
95
 
116
96
  ```jsonc
117
- {
118
- "$schema": "https://opencode.ai/tui.json",
119
- "plugin": ["opencode-peak-badge@opencode-v1"]
120
- }
97
+ { "plugin": ["opencode-peak-badge@opencode-v1"] }
121
98
  ```
122
99
 
123
- Do **not** use `opencode-peak-badge` without a version on V1: from `0.4.0` the
124
- `latest` tag points at the V2 build. The `opencode-v1` dist-tag always resolves
125
- to `0.3.0`.
126
-
127
- ### Install from source (local dev)
128
-
129
- 1. Clone the repository and install dependencies:
100
+ ## Settings
130
101
 
131
- ```sh
132
- git clone https://go.hugobatista.com/gh/opencode-peak-badge.git ~/code/projects/opencode-peak-badge
133
- cd ~/code/projects/opencode-peak-badge
134
- bun install
135
- ```
102
+ Settings live on the server in the plugin's storage (KV) and are shared by every
103
+ TUI and Desktop window connected to that server. Changes apply live: a save in
104
+ the Desktop updates the TUI badge, and a save in the TUI updates the Desktop.
136
105
 
137
- 2. Register the plugin in your `opencode.jsonc` with an absolute path to
138
- `src/index.tsx`:
106
+ - **Desktop:** Settings → Peak Badge.
107
+ - **TUI:** command palette → **Peak Badge settings**, or `/peak-badge`
108
+ (`/peakbadge` also works).
139
109
 
140
- ```jsonc
141
- {
142
- "$schema": "https://opencode.ai/config.json",
143
- "plugins": [
144
- "/home/your-user/code/projects/opencode-peak-badge/src/index.tsx"
145
- ]
146
- }
147
- ```
110
+ The TUI has no plugin settings page in its native Settings screen; the command
111
+ opens the host's select/prompt/confirm dialogs. Both editors change the same
112
+ object.
148
113
 
149
- The defaults below apply when no options are given. To override, use the
150
- object form (see [Configuration](#configuration)).
151
-
152
- 3. Restart OpenCode.
153
-
154
- ## Configuration
155
-
156
- Add options with the object form:
157
-
158
- ```jsonc
159
- {
160
- "$schema": "https://opencode.ai/config.json",
161
- "plugins": [
162
- {
163
- "package": "opencode-peak-badge",
164
- "options": {
165
- "models": [
166
- "re:^opencode-go/deepseek",
167
- "re:^opencode/deepseek",
168
- "re:^deepseek/deepseek"
169
- ],
170
- "windows": [["01:00", "04:00"], ["06:00", "10:00"]],
171
- "weekdaysOnly": true,
172
- "pollSeconds": 10,
173
- "subagents": true,
174
- "alwaysShow": false,
175
- "labelPeak": "[PEAK]",
176
- "labelOffPeak": "[OFF-PEAK]",
177
- "debug": false
178
- }
179
- }
180
- ]
181
- }
182
- ```
114
+ ![Desktop Settings → Peak Badge page](docs/demo-desktop-settings.png)
183
115
 
184
- ### Options
116
+ ### Defaults
185
117
 
186
- | Option | Default | Description |
118
+ | Setting | Default | Description |
187
119
  |---|---|---|
188
- | `models` | built-in patterns for any DeepSeek model (OpenCode Go, OpenCode Zen, DeepSeek direct) | Models with peak hours. Override to track any `provider/model`. Each entry is a `"provider/model"` exact string, a `"re:<pattern>"` regex string, or an object with per-model `windows`/`weekdaysOnly` overrides. Matching is against the full `provider/model` key (case-insensitive). Exact `id` entries win over regex patterns; otherwise the first matching entry in list order wins. |
189
- | `windows` | `[["01:00","04:00"],["06:00","10:00"]]` | Peak windows in UTC. Each is `["HH:MM","HH:MM"]`, half-open `[start, end)`. A window whose end is ≤ its start wraps past midnight. |
190
- | `weekdaysOnly` | `true` | When true, weekends are always off-peak. |
191
- | `pollSeconds` | `10` | How often the badge recomputes (minimum 1). The badge also reacts live to session and model events. |
192
- | `subagents` | `true` | Track subagent sessions while they are running. Peak wins over the main model's state. |
193
- | `alwaysShow` | `false` | When true, always show a badge for the main model, using the top-level `windows`/`weekdaysOnly` when no model rule matches. |
194
- | `labelPeak` | `"[PEAK]"` | Text shown during peak hours. |
195
- | `labelOffPeak` | `"[OFF-PEAK]"` | Text shown during off-peak hours. |
196
- | `debug` | `false` | When true, append the detected `provider/model` key to the badge. |
197
-
198
- `models` entries are additive to the defaults? No. Supplying `models`
199
- **replaces** the default list. Provide the full list you want tracked.
200
-
201
- ### Subagents
202
-
203
- When an OpenCode task spawns a subagent session, that child session carries a
204
- `parentID` pointing at the session that spawned it. The plugin reads the
205
- descendant tree from `data.session.family(sessionID)` and, for each descendant
206
- that is `running`, checks the child's model against the peak windows:
207
-
208
- - If any running subagent has a matching rule and is in peak hours, the badge
209
- shows `[PEAK]`, whatever the main model says (`peak` wins).
210
- - Otherwise the badge follows the main model's state.
211
- - Idle or deleted subagent sessions are ignored.
212
- - Subagent sessions whose model has no configured peak hours add nothing.
213
- - The badge reacts live to `session.status` changes when a subagent goes running
214
- or idle; no need to wait for the next poll tick.
215
-
216
- `alwaysShow` only affects the main model; a subagent never renders a badge from
217
- the fallback windows. Set `subagents: false` to ignore subagents entirely.
218
-
219
- ### Model picker and the home screen
220
-
221
- OpenCode keeps the picker selection in TUI-local state and only commits it to
222
- the session server-side when you submit a prompt. To avoid a stale badge, the
223
- plugin also reads the TUI's `model.json` (at
224
- `$XDG_STATE_HOME/opencode/model.json`, by default
225
- `~/.local/state/opencode/model.json`), which the picker updates immediately.
226
- The badge therefore:
227
-
228
- - on the home screen (where `session.new` lands), shows the last picked model
229
- instead of the server's `model.default()`;
230
- - inside a running session, shows the newly picked model right away, then the
231
- committed session model once the prompt is submitted.
232
-
233
- Precedence: a committed session model (`session.created` /
234
- `session.model.selected`) wins over the `model.json` pick; a pick is applied
235
- only to the session currently on screen and is dropped when you switch
236
- sessions. If `model.json` is missing, the plugin falls back to
237
- `client.model.default()` as before.
238
-
239
- This is a bridge over an internal TUI file — OpenCode V2 does not expose the
240
- in-progress picker selection to plugins. If a future release publishes an event
241
- or API for it, this can be simplified.
242
-
243
- ### Agent switches (plan / build) with different models
244
-
245
- When agents in a session use different models, the badge follows the session's
246
- model from the TUI store, updated by `session.agent.selected` and
247
- `session.model.selected`. One limitation remains: the TUI Tab agent cycle may not
248
- publish an event or persist the chosen model until the next prompt, because the
249
- cycle and per-agent model pick are stored in the TUI's local state. Between
250
- pressing Tab and submitting the next prompt, the badge keeps the last known
251
- session model. On prompt submission OpenCode publishes the selected
252
- agent/model, and the badge updates in the same tick.
253
-
254
- If you need an immediate update, pick the model explicitly from the model list.
255
-
256
- This behavior should be re-verified on your OpenCode V2 build; if the agent
257
- cycle starts emitting an event, the badge reacts automatically.
258
-
259
- ### alwaysShow
260
-
261
- By default the plugin shows nothing for models without a matching rule. Set
262
- `alwaysShow: true` to always render a badge in the footer: unmatched main models
263
- use the top-level `windows` / `weekdaysOnly` (defaults or your overrides).
264
- Combined with `subagents`, a running subagent in peak hours still wins over an
265
- off-peak main model.
266
-
267
- ## Background: peak pricing is property of channel + model
268
-
269
- Peak hours are a property of the **channel + model pair**, not of the model
270
- alone. The plugin is provider-agnostic: it renders a badge whenever the active
271
- `provider/model` key matches a configured rule, and prices are billable at peak
272
- in the channels you configure. Add any model you care about — the plugin does
273
- not know or care which provider it belongs to.
274
-
275
- The built-in defaults target DeepSeek models, because that is where peak
276
- pricing is known today. Current facts (per OpenCode docs):
277
-
278
- - **OpenCode Go** — DeepSeek V4 Pro, V4 Flash and V4 Flash Vision Exp: peak =
279
- Mon–Fri 01:00–04:00 and 06:00–10:00 UTC; everything else, including weekends,
280
- is off-peak (2× price in peak). No other Go model has peak hours. The same
281
- windows apply to newer ids such as `deepseek-v4.1-*`. OpenCode also exposes
282
- Flash as the alias `opencode-go/deepseek-flash`; the default patterns match
283
- every `opencode-go/deepseek*` id.
284
- - **OpenCode Zen** — bills the same DeepSeek models (`opencode/deepseek-*`) at
285
- DeepSeek's list price, so the same peak windows apply.
286
- - **DeepSeek direct API (BYOK)** — the same peak windows apply to
287
- `deepseek/deepseek-*`.
288
-
289
- In Lisbon time (WEST, UTC+1) the DeepSeek windows are 02:00–05:00 and
290
- 07:00–11:00; in winter (WET, UTC+0) the UTC windows apply as-is. The plugin
291
- computes in UTC, so DST is a non-issue.
292
-
293
- ### Exact matching
294
-
295
- Match one `provider/model` id exactly (case-insensitive). This is the simplest
296
- form and avoids regex entirely:
297
-
298
- ```jsonc
299
- {
300
- "models": [
301
- "opencode-go/deepseek-v4-flash",
302
- "opencode/deepseek-v4-pro"
303
- ]
304
- }
120
+ | `models` | DeepSeek patterns | Rules to track. One entry per row: exact `provider/model`, `re:<regex>`, or a JSON object. Replaces the defaults; an empty list tracks nothing. |
121
+ | `windows` | `[["01:00","04:00"],["06:00","10:00"]]` | Peak windows in UTC. Each is `["HH:MM","HH:MM"]`, half-open; end ≤ start wraps midnight. An empty list means no peak windows. |
122
+ | `weekdaysOnly` | `true` | Weekends are always off-peak. |
123
+ | `pollSeconds` | `10` | Recompute interval (minimum 1). Live events also trigger updates. |
124
+ | `labelPeak` | `"[PEAK]"` | Peak label. |
125
+ | `labelOffPeak` | `"[OFF-PEAK]"` | Off-peak label. |
126
+ | `subagents` | `true` | Include running subagent sessions; peak wins. |
127
+ | `alwaysShow` | `false` | Show the main model even without a matching rule, using the top-level windows. |
128
+ | `debug` | `false` | Append the detected `provider/model` to the badge. |
129
+ | `fakeTime` | unset | Fixed ISO timestamp for testing. Empty uses the real clock. |
130
+
131
+ **Reset to defaults** restores this table for both surfaces.
132
+
133
+ ### Model matching
134
+
135
+ - Exact `provider/model`, case-insensitive.
136
+ - `re:<pattern>` regex, case-insensitive.
137
+ - JSON object for per-model overrides: `{ "id": "provider/model", "windows": [...], "weekdaysOnly": false }`, or the same with `pattern` instead of `id`.
138
+ - Exact entries beat regex patterns; otherwise the first match wins. Invalid
139
+ patterns are ignored.
140
+ - JSON escapes backslashes: use `"re:^opencode-go/deepseek\\.v4"` inside the object
141
+ text. Plain regex rows do not need JSON escaping.
142
+
143
+ The shared models setting stores one raw line per entry. Both the Desktop and
144
+ TUI editors show and edit that list:
145
+
146
+ ```text
147
+ opencode-go/deepseek-v4-flash
148
+ re:^opencode/deepseek
149
+ {"pattern":"^my-provider/.*$","windows":[["09:00","17:00"]],"weekdaysOnly":false}
305
150
  ```
306
151
 
307
- Give a single model its own windows or weekday behavior with the object form:
152
+ ### Scope
153
+
154
+ - Settings are **per server**. A TUI connected to a different server sees that
155
+ server's settings.
156
+ - Removing the plugin leaves the stored settings in the server's KV; reset them
157
+ before uninstalling if you want a clean slate.
158
+ - If the server is unreachable, clients keep the last known settings (or the
159
+ defaults). The Desktop page shows a connection warning with a Retry action.
160
+
161
+ ### Breaking change in 0.6.0
162
+
163
+ Plugin `options` in `opencode.json(c)` are no longer read, and there is no
164
+ migration. Re-enter any customization in Settings → Peak Badge or `/peak-badge`.
165
+ The `fakeTime` option is replaced by the `fakeTime` setting; the
166
+ `OPENCODE_PEAK_HOURS_FAKE_TIME` environment variable remains a TUI-only test
167
+ override.
168
+
169
+ ## Behavior
170
+
171
+ - **TUI model source:** committed session model, plus the uncommitted picker
172
+ selection from `$XDG_STATE_HOME/opencode/model.json`. A committed model wins;
173
+ Home uses the pick, then `client.model.default()`.
174
+ - **Subagents:** running descendants from `data.session.family()`; peak wins.
175
+ Setting `subagents` to false ignores them; `alwaysShow` only affects the main
176
+ model.
177
+ - **Peak hours:** UTC defaults are Mon–Fri 01:00–04:00 and 06:00–10:00, weekends
178
+ off-peak. Defaults cover DeepSeek on OpenCode Go, OpenCode Zen and the DeepSeek
179
+ direct API; add rules for any other provider/model.
180
+ - **TUI agent cycle:** the Tab agent cycle may not update until the next prompt;
181
+ selecting a model explicitly updates immediately.
308
182
 
309
- ```jsonc
310
- {
311
- "models": [
312
- { "id": "opencode-go/deepseek-v4-flash", "windows": [["09:00", "17:00"]], "weekdaysOnly": false }
313
- ]
314
- }
315
- ```
316
-
317
- ### Regex matching
183
+ ## Evaluation
318
184
 
319
- Exact ids match one model. To track every current and future model id that
320
- fits a pattern, use the `re:` prefix on a string, or the `pattern` object form
321
- (which also allows per-model overrides):
185
+ Set **Fake time** in Settings → Peak Badge (Desktop) or `/peak-badge` (TUI):
322
186
 
323
- ```jsonc
324
- {
325
- "models": [
326
- "re:^opencode-go/deepseek",
327
- { "pattern": "^my-provider/.*$", "windows": [["09:00", "17:00"]] }
328
- ]
329
- }
187
+ ```text
188
+ 2026-09-07T08:30:00Z # peak
189
+ 2026-09-07T12:00:00Z # off-peak
330
190
  ```
331
191
 
332
- Matching rules:
192
+ Clear it to return to the real clock.
333
193
 
334
- - Patterns are compiled case-insensitively and tested against the full
335
- `provider/model` key.
336
- - An exact `id` entry always beats a regex pattern, regardless of list order.
337
- - Otherwise the first matching entry wins (list order).
338
- - An invalid or empty pattern is ignored.
339
-
340
- Escaping: `models` is JSON, so backslashes must be doubled. For example, to
341
- match a literal dot use `"re:^opencode-go/deepseek\\.v4"`. To avoid escaping,
342
- prefer plain `-` and `?` characters as in the defaults above.
343
-
344
- ## Evaluation
345
-
346
- Set the environment variable before launching OpenCode to force a specific
347
- instant. The variable is read on every tick, so changing it mid-session takes
348
- effect within `pollSeconds`:
194
+ For a one-off TUI launch, the environment variable still overrides the shared
195
+ `fakeTime` setting in the TUI:
349
196
 
350
197
  ```sh
351
- OPENCODE_PEAK_HOURS_FAKE_TIME=2026-09-07T08:30:00Z opencode # peak (Mon 08:30 UTC)
352
- OPENCODE_PEAK_HOURS_FAKE_TIME=2026-09-07T12:00:00Z opencode # off-peak (Mon 12:00 UTC)
198
+ OPENCODE_PEAK_HOURS_FAKE_TIME=2026-09-07T08:30:00Z opencode # peak
199
+ OPENCODE_PEAK_HOURS_FAKE_TIME=2026-09-07T12:00:00Z opencode # off-peak
353
200
  ```
354
201
 
355
- Unset the variable to use real time.
356
-
357
202
  ## Uninstall
358
203
 
359
204
  ```sh
360
205
  opencode plugin remove opencode-peak-badge
361
206
  ```
362
207
 
363
- Or remove the entry from `plugins` in your `opencode.jsonc` / `cli.json` and
364
- restart OpenCode.
208
+ Or remove the entry from `opencode.jsonc` / `cli.json`. Desktop only reads
209
+ `opencode.json(c)`. Server-stored settings remain in the plugin's KV; reset them
210
+ before removing the plugin if desired.
365
211
 
366
212
  ## Development
367
213
 
368
214
  ```sh
369
215
  bun install
370
- bun run typecheck # tsc --noEmit, strict
371
- bun test # unit (core logic) + functional (mocked TUI context)
372
- bun run build # dist/tui.js + dist/tui.d.ts (npm entrypoint)
373
- ```
374
-
375
- - `src/core.ts` — pure logic: window parsing, UTC peak check, per-model config
376
- resolution. No TUI imports. Fully unit-tested.
377
- - `src/index.tsx` — the TUI plugin (`id: "peak-badge"`), a
378
- `Plugin.define({ id, setup })` from `@opencode/plugin/tui`. The plugin loader
379
- reads the default export only; the `__test` named export is a test hook.
380
- - `scripts/build.ts` — bundles `src/index.tsx` to `dist/tui.js` with
381
- `@opencode/plugin`, `@opencode/theme`, `@opentui/*` and `solid-js` external.
382
- The npm `exports["./tui"]` entry points at `dist`, never at `src` (the Solid
383
- transform does not run inside `node_modules`).
384
-
385
- ## Pre-release checklist
386
-
387
- ```sh
388
- bun install
389
- bun run typecheck
390
- bun test
391
- bun run build
392
- npm pack --dry-run
216
+ bun run typecheck # TUI + GUI TypeScript configs
217
+ bun test # core, settings, server RPC and mocked TUI tests
218
+ bun run build # dist/tui.js, dist/server.js, dist/gui-experimental.cjs
393
219
  ```
394
220
 
395
- Inspect the pack list (`dist/`, `README.md`, `LICENSE` only). Scan for
396
- secrets before `npm publish`.
221
+ Local development: build, add the absolute repository directory to
222
+ `opencode.json(c)`, then reload. A local directory with `name` and `exports`
223
+ resolves `./tui`, `.` (server) and `./gui-experimental`; Desktop needs
224
+ `dist/gui-experimental.cjs`. A TUI-only local entry has no server part, so it
225
+ uses the defaults and the `/peak-badge` editor cannot persist changes.
226
+
227
+ - `src/core.ts` — pure rules, badge/subagent resolution and the fake-time clock.
228
+ - `src/settings.ts` — shared settings model, defaults, validation and normalization.
229
+ - `src/rpc.ts` — RPC contract between the server and both clients.
230
+ - `src/server.ts` — server part: stores settings and exposes `get`/`set`/`reset`.
231
+ - `src/index.tsx` — TUI part (`id: peak-badge`) and `/peak-badge` command.
232
+ - `src/tui-settings.ts` — TUI dialog editor.
233
+ - `src/gui.tsx` — Desktop part (`session.header` chip + `window.bottom` + settings page).
234
+ - `src/settings-page.tsx` — Desktop settings page.
235
+ - `scripts/build.ts` — TUI and server bundles; `vite.config.ts` — GUI CJS bundle.
236
+
237
+ Release check: `npm pack --dry-run`. The package must include `dist/tui.js`,
238
+ `dist/server.js` and `dist/gui-experimental.cjs`; scan for secrets before
239
+ publishing.
397
240
 
398
241
  ## License
399
242
 
package/dist/core.d.ts CHANGED
@@ -13,16 +13,10 @@ export type ModelEntryObject = {
13
13
  weekdaysOnly?: boolean;
14
14
  };
15
15
  export type ModelEntrySpec = string | ModelEntryObject;
16
- export type PeakHoursOptions = {
16
+ export type RuleOptions = {
17
17
  models?: ModelEntrySpec[];
18
18
  windows?: WindowSpec[];
19
19
  weekdaysOnly?: boolean;
20
- pollSeconds?: number;
21
- labelPeak?: string;
22
- labelOffPeak?: string;
23
- subagents?: boolean;
24
- alwaysShow?: boolean;
25
- debug?: boolean;
26
20
  };
27
21
  export type ResolvedModelRule = {
28
22
  id: string;
@@ -39,18 +33,41 @@ export type BadgeState = {
39
33
  label: string;
40
34
  peak: boolean;
41
35
  };
36
+ export type ModelRef = {
37
+ providerID: string;
38
+ id: string;
39
+ };
42
40
  export declare const DEFAULT_WINDOWS: WindowSpec[];
43
41
  export declare const DEFAULT_MODELS: ModelEntrySpec[];
42
+ export declare function currentNow(fakeTime?: string, realNow?: Date): Date;
44
43
  export declare function parseHHMM(value: string): number | undefined;
45
44
  export declare function parseWindow(spec: WindowSpec): MinuteWindow | undefined;
46
45
  export declare function parseWindows(specs: readonly WindowSpec[]): MinuteWindow[];
47
46
  export declare function inWindow(minutes: number, window: MinuteWindow): boolean;
48
47
  export declare function isPeakUtc(now: Date, windows: readonly MinuteWindow[], weekdaysOnly?: boolean): boolean;
49
48
  export declare function modelKey(providerID: string, modelID: string): string;
50
- export declare function resolveRules(options?: PeakHoursOptions): RuleSet;
49
+ export declare function resolveRules(options?: RuleOptions): RuleSet;
50
+ export declare function isValidModelEntry(entry: ModelEntrySpec): boolean;
51
51
  export declare function matchRule(rules: RuleSet, key: string): ResolvedModelRule | undefined;
52
52
  export declare function badgeFor(now: Date, rule: ResolvedModelRule | undefined, labels: {
53
53
  peak: string;
54
54
  offPeak: string;
55
55
  }): BadgeState | undefined;
56
56
  export declare function mergeBadges(states: Array<BadgeState | undefined>): BadgeState | undefined;
57
+ export declare function badgeForModels(input: {
58
+ now: Date;
59
+ rules: RuleSet;
60
+ labels: {
61
+ peak: string;
62
+ offPeak: string;
63
+ };
64
+ main: ModelRef | undefined;
65
+ subagents: readonly ModelRef[];
66
+ alwaysShow: boolean;
67
+ }): BadgeState | undefined;
68
+ export declare function runningSubagentRefs(input: {
69
+ sessionID: string;
70
+ family: (sessionID: string) => readonly string[];
71
+ status: (sessionID: string) => "idle" | "running";
72
+ model: (sessionID: string) => ModelRef | undefined;
73
+ }): ModelRef[];