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 +169 -326
- package/dist/core.d.ts +25 -8
- package/dist/gui-experimental.cjs +2 -0
- package/dist/rpc.d.ts +298 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +152 -0
- package/dist/server.js.map +13 -0
- package/dist/settings-client.d.ts +29 -0
- package/dist/settings.d.ts +65 -0
- package/dist/tui-settings.d.ts +15 -0
- package/dist/tui.d.ts +2 -1
- package/dist/tui.js +804 -68
- package/dist/tui.js.map +9 -5
- package/package.json +29 -18
package/README.md
CHANGED
|
@@ -5,57 +5,30 @@
|
|
|
5
5
|
[](https://go.hugobatista.com/gh/opencode-peak-badge/actions/workflows/test.yml)
|
|
6
6
|
[](https://www.npmjs.com/package/opencode-peak-badge)
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
|
|
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
|
+

|
|
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
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
`opencode
|
|
100
|
-
|
|
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
|
+

|
|
101
85
|
|
|
102
86
|
### OpenCode V1 (legacy)
|
|
103
87
|
|
|
104
|
-
`0.3.0` is the last
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
138
|
-
|
|
106
|
+
- **Desktop:** Settings → Peak Badge.
|
|
107
|
+
- **TUI:** command palette → **Peak Badge settings**, or `/peak-badge`
|
|
108
|
+
(`/peakbadge` also works).
|
|
139
109
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
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
|
+

|
|
183
115
|
|
|
184
|
-
###
|
|
116
|
+
### Defaults
|
|
185
117
|
|
|
186
|
-
|
|
|
118
|
+
| Setting | Default | Description |
|
|
187
119
|
|---|---|---|
|
|
188
|
-
| `models` |
|
|
189
|
-
| `windows` | `[["01:00","04:00"],["06:00","10:00"]]` | Peak windows in UTC. Each is `["HH:MM","HH:MM"]`, half-open
|
|
190
|
-
| `weekdaysOnly` | `true` |
|
|
191
|
-
| `pollSeconds` | `10` |
|
|
192
|
-
| `
|
|
193
|
-
| `
|
|
194
|
-
| `
|
|
195
|
-
| `
|
|
196
|
-
| `debug` | `false` |
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
**
|
|
200
|
-
|
|
201
|
-
###
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
`
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
```
|
|
324
|
-
|
|
325
|
-
|
|
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
|
-
|
|
192
|
+
Clear it to return to the real clock.
|
|
333
193
|
|
|
334
|
-
-
|
|
335
|
-
|
|
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
|
|
352
|
-
OPENCODE_PEAK_HOURS_FAKE_TIME=2026-09-07T12:00:00Z opencode # off-peak
|
|
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 `
|
|
364
|
-
|
|
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 #
|
|
371
|
-
bun test #
|
|
372
|
-
bun run build # dist/tui.js
|
|
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
|
-
|
|
396
|
-
|
|
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
|
|
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?:
|
|
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[];
|