opencode-peak-badge 0.5.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/dist/rpc.d.ts ADDED
@@ -0,0 +1,298 @@
1
+ /**
2
+ * The shared settings RPC. `get` returns the defaults when nothing is stored;
3
+ * `set` replaces the full object; `reset` removes the stored value. `updated`
4
+ * reaches every open TUI and desktop window so both badges follow the change.
5
+ */
6
+ export declare const PeakBadgeSettingsRpc: {
7
+ readonly id: "peak-badge.settings";
8
+ readonly methods: {
9
+ readonly get: {
10
+ readonly input: {
11
+ readonly type: "object";
12
+ readonly additionalProperties: false;
13
+ };
14
+ readonly output: {
15
+ readonly type: "object";
16
+ readonly properties: {
17
+ readonly settings: {
18
+ readonly type: "object";
19
+ readonly properties: {
20
+ readonly models: {
21
+ readonly type: "array";
22
+ readonly items: {
23
+ readonly type: "string";
24
+ };
25
+ };
26
+ readonly windows: {
27
+ readonly type: "array";
28
+ readonly items: {
29
+ readonly type: "array";
30
+ readonly items: {
31
+ readonly type: "string";
32
+ };
33
+ readonly minItems: 2;
34
+ readonly maxItems: 2;
35
+ };
36
+ };
37
+ readonly weekdaysOnly: {
38
+ readonly type: "boolean";
39
+ };
40
+ readonly pollSeconds: {
41
+ readonly type: "string";
42
+ };
43
+ readonly labelPeak: {
44
+ readonly type: "string";
45
+ };
46
+ readonly labelOffPeak: {
47
+ readonly type: "string";
48
+ };
49
+ readonly subagents: {
50
+ readonly type: "boolean";
51
+ };
52
+ readonly alwaysShow: {
53
+ readonly type: "boolean";
54
+ };
55
+ readonly debug: {
56
+ readonly type: "boolean";
57
+ };
58
+ readonly fakeTime: {
59
+ readonly type: "string";
60
+ };
61
+ };
62
+ readonly additionalProperties: false;
63
+ };
64
+ };
65
+ readonly required: readonly ["settings"];
66
+ readonly additionalProperties: false;
67
+ };
68
+ };
69
+ readonly set: {
70
+ readonly input: {
71
+ readonly type: "object";
72
+ readonly properties: {
73
+ readonly settings: {
74
+ readonly type: "object";
75
+ readonly properties: {
76
+ readonly models: {
77
+ readonly type: "array";
78
+ readonly items: {
79
+ readonly type: "string";
80
+ };
81
+ };
82
+ readonly windows: {
83
+ readonly type: "array";
84
+ readonly items: {
85
+ readonly type: "array";
86
+ readonly items: {
87
+ readonly type: "string";
88
+ };
89
+ readonly minItems: 2;
90
+ readonly maxItems: 2;
91
+ };
92
+ };
93
+ readonly weekdaysOnly: {
94
+ readonly type: "boolean";
95
+ };
96
+ readonly pollSeconds: {
97
+ readonly type: "string";
98
+ };
99
+ readonly labelPeak: {
100
+ readonly type: "string";
101
+ };
102
+ readonly labelOffPeak: {
103
+ readonly type: "string";
104
+ };
105
+ readonly subagents: {
106
+ readonly type: "boolean";
107
+ };
108
+ readonly alwaysShow: {
109
+ readonly type: "boolean";
110
+ };
111
+ readonly debug: {
112
+ readonly type: "boolean";
113
+ };
114
+ readonly fakeTime: {
115
+ readonly type: "string";
116
+ };
117
+ };
118
+ readonly additionalProperties: false;
119
+ };
120
+ };
121
+ readonly required: readonly ["settings"];
122
+ readonly additionalProperties: false;
123
+ };
124
+ readonly output: {
125
+ readonly type: "object";
126
+ readonly properties: {
127
+ readonly settings: {
128
+ readonly type: "object";
129
+ readonly properties: {
130
+ readonly models: {
131
+ readonly type: "array";
132
+ readonly items: {
133
+ readonly type: "string";
134
+ };
135
+ };
136
+ readonly windows: {
137
+ readonly type: "array";
138
+ readonly items: {
139
+ readonly type: "array";
140
+ readonly items: {
141
+ readonly type: "string";
142
+ };
143
+ readonly minItems: 2;
144
+ readonly maxItems: 2;
145
+ };
146
+ };
147
+ readonly weekdaysOnly: {
148
+ readonly type: "boolean";
149
+ };
150
+ readonly pollSeconds: {
151
+ readonly type: "string";
152
+ };
153
+ readonly labelPeak: {
154
+ readonly type: "string";
155
+ };
156
+ readonly labelOffPeak: {
157
+ readonly type: "string";
158
+ };
159
+ readonly subagents: {
160
+ readonly type: "boolean";
161
+ };
162
+ readonly alwaysShow: {
163
+ readonly type: "boolean";
164
+ };
165
+ readonly debug: {
166
+ readonly type: "boolean";
167
+ };
168
+ readonly fakeTime: {
169
+ readonly type: "string";
170
+ };
171
+ };
172
+ readonly additionalProperties: false;
173
+ };
174
+ };
175
+ readonly required: readonly ["settings"];
176
+ readonly additionalProperties: false;
177
+ };
178
+ };
179
+ readonly reset: {
180
+ readonly input: {
181
+ readonly type: "object";
182
+ readonly additionalProperties: false;
183
+ };
184
+ readonly output: {
185
+ readonly type: "object";
186
+ readonly properties: {
187
+ readonly settings: {
188
+ readonly type: "object";
189
+ readonly properties: {
190
+ readonly models: {
191
+ readonly type: "array";
192
+ readonly items: {
193
+ readonly type: "string";
194
+ };
195
+ };
196
+ readonly windows: {
197
+ readonly type: "array";
198
+ readonly items: {
199
+ readonly type: "array";
200
+ readonly items: {
201
+ readonly type: "string";
202
+ };
203
+ readonly minItems: 2;
204
+ readonly maxItems: 2;
205
+ };
206
+ };
207
+ readonly weekdaysOnly: {
208
+ readonly type: "boolean";
209
+ };
210
+ readonly pollSeconds: {
211
+ readonly type: "string";
212
+ };
213
+ readonly labelPeak: {
214
+ readonly type: "string";
215
+ };
216
+ readonly labelOffPeak: {
217
+ readonly type: "string";
218
+ };
219
+ readonly subagents: {
220
+ readonly type: "boolean";
221
+ };
222
+ readonly alwaysShow: {
223
+ readonly type: "boolean";
224
+ };
225
+ readonly debug: {
226
+ readonly type: "boolean";
227
+ };
228
+ readonly fakeTime: {
229
+ readonly type: "string";
230
+ };
231
+ };
232
+ readonly additionalProperties: false;
233
+ };
234
+ };
235
+ readonly required: readonly ["settings"];
236
+ readonly additionalProperties: false;
237
+ };
238
+ };
239
+ };
240
+ readonly events: {
241
+ readonly updated: {
242
+ readonly schema: {
243
+ readonly type: "object";
244
+ readonly properties: {
245
+ readonly settings: {
246
+ readonly type: "object";
247
+ readonly properties: {
248
+ readonly models: {
249
+ readonly type: "array";
250
+ readonly items: {
251
+ readonly type: "string";
252
+ };
253
+ };
254
+ readonly windows: {
255
+ readonly type: "array";
256
+ readonly items: {
257
+ readonly type: "array";
258
+ readonly items: {
259
+ readonly type: "string";
260
+ };
261
+ readonly minItems: 2;
262
+ readonly maxItems: 2;
263
+ };
264
+ };
265
+ readonly weekdaysOnly: {
266
+ readonly type: "boolean";
267
+ };
268
+ readonly pollSeconds: {
269
+ readonly type: "string";
270
+ };
271
+ readonly labelPeak: {
272
+ readonly type: "string";
273
+ };
274
+ readonly labelOffPeak: {
275
+ readonly type: "string";
276
+ };
277
+ readonly subagents: {
278
+ readonly type: "boolean";
279
+ };
280
+ readonly alwaysShow: {
281
+ readonly type: "boolean";
282
+ };
283
+ readonly debug: {
284
+ readonly type: "boolean";
285
+ };
286
+ readonly fakeTime: {
287
+ readonly type: "string";
288
+ };
289
+ };
290
+ readonly additionalProperties: false;
291
+ };
292
+ };
293
+ readonly required: readonly ["settings"];
294
+ readonly additionalProperties: false;
295
+ };
296
+ };
297
+ };
298
+ };
package/dist/server.js CHANGED
@@ -1,11 +1,152 @@
1
1
  // src/server.ts
2
2
  import { Plugin } from "@opencode/plugin";
3
+
4
+ // src/rpc.ts
5
+ import { Rpc } from "@opencode/plugin/rpc";
6
+ var Settings = {
7
+ type: "object",
8
+ properties: {
9
+ models: { type: "array", items: { type: "string" } },
10
+ windows: {
11
+ type: "array",
12
+ items: {
13
+ type: "array",
14
+ items: { type: "string" },
15
+ minItems: 2,
16
+ maxItems: 2
17
+ }
18
+ },
19
+ weekdaysOnly: { type: "boolean" },
20
+ pollSeconds: { type: "string" },
21
+ labelPeak: { type: "string" },
22
+ labelOffPeak: { type: "string" },
23
+ subagents: { type: "boolean" },
24
+ alwaysShow: { type: "boolean" },
25
+ debug: { type: "boolean" },
26
+ fakeTime: { type: "string" }
27
+ },
28
+ additionalProperties: false
29
+ };
30
+ var Envelope = {
31
+ type: "object",
32
+ properties: { settings: Settings },
33
+ required: ["settings"],
34
+ additionalProperties: false
35
+ };
36
+ var Empty = { type: "object", additionalProperties: false };
37
+ var PeakBadgeSettingsRpc = Rpc.define({
38
+ id: "peak-badge.settings",
39
+ methods: {
40
+ get: { input: Empty, output: Envelope },
41
+ set: { input: Envelope, output: Envelope },
42
+ reset: { input: Empty, output: Envelope }
43
+ },
44
+ events: {
45
+ updated: { schema: Envelope }
46
+ }
47
+ });
48
+
49
+ // src/core.ts
50
+ var DEFAULT_WINDOWS = [
51
+ ["01:00", "04:00"],
52
+ ["06:00", "10:00"]
53
+ ];
54
+ var DEFAULT_MODELS = [
55
+ "re:^opencode-go/deepseek",
56
+ "re:^opencode/deepseek",
57
+ "re:^deepseek/deepseek"
58
+ ];
59
+
60
+ // src/settings.ts
61
+ var DEFAULT_POLL_SECONDS = 10;
62
+ var DEFAULT_SETTINGS = {
63
+ models: modelLines(DEFAULT_MODELS),
64
+ windows: DEFAULT_WINDOWS.map(([start, end]) => [start, end]),
65
+ weekdaysOnly: true,
66
+ pollSeconds: String(DEFAULT_POLL_SECONDS),
67
+ labelPeak: "[PEAK]",
68
+ labelOffPeak: "[OFF-PEAK]",
69
+ subagents: true,
70
+ alwaysShow: false,
71
+ debug: false,
72
+ fakeTime: ""
73
+ };
74
+ function defaultSettings() {
75
+ return {
76
+ ...DEFAULT_SETTINGS,
77
+ models: [...DEFAULT_SETTINGS.models],
78
+ windows: DEFAULT_SETTINGS.windows.map(([start, end]) => [start, end])
79
+ };
80
+ }
81
+ function isRecord(value) {
82
+ return typeof value === "object" && value !== null && !Array.isArray(value);
83
+ }
84
+ function isWindowSpec(value) {
85
+ return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "string";
86
+ }
87
+ function isWindowList(value) {
88
+ return Array.isArray(value) && value.every(isWindowSpec);
89
+ }
90
+ function sanitizeSettings(value) {
91
+ const next = defaultSettings();
92
+ if (!isRecord(value))
93
+ return next;
94
+ if (Array.isArray(value.models) && value.models.every((entry) => typeof entry === "string")) {
95
+ next.models = [...value.models];
96
+ }
97
+ if (isWindowList(value.windows)) {
98
+ next.windows = value.windows.map(([start, end]) => [start, end]);
99
+ }
100
+ if (typeof value.weekdaysOnly === "boolean")
101
+ next.weekdaysOnly = value.weekdaysOnly;
102
+ if (typeof value.pollSeconds === "string")
103
+ next.pollSeconds = value.pollSeconds;
104
+ if (typeof value.labelPeak === "string")
105
+ next.labelPeak = value.labelPeak;
106
+ if (typeof value.labelOffPeak === "string")
107
+ next.labelOffPeak = value.labelOffPeak;
108
+ if (typeof value.subagents === "boolean")
109
+ next.subagents = value.subagents;
110
+ if (typeof value.alwaysShow === "boolean")
111
+ next.alwaysShow = value.alwaysShow;
112
+ if (typeof value.debug === "boolean")
113
+ next.debug = value.debug;
114
+ if (typeof value.fakeTime === "string")
115
+ next.fakeTime = value.fakeTime;
116
+ return next;
117
+ }
118
+ function settingsFromEnvelope(value) {
119
+ return sanitizeSettings(isRecord(value) ? value.settings : undefined);
120
+ }
121
+ function modelLines(entries) {
122
+ return entries.map((entry) => typeof entry === "string" ? entry : JSON.stringify(entry));
123
+ }
124
+
125
+ // src/server.ts
3
126
  var server_default = Plugin.define({
4
127
  id: "peak-badge",
5
- setup() {}
128
+ async setup(ctx) {
129
+ let notify;
130
+ const registration = await ctx.rpc.register(PeakBadgeSettingsRpc, {
131
+ get: async () => ({ settings: sanitizeSettings(await ctx.storage.get("settings")) }),
132
+ set: async (input) => {
133
+ const settings = sanitizeSettings(settingsFromEnvelope(input));
134
+ await ctx.storage.set("settings", settings);
135
+ await notify?.(settings);
136
+ return { settings };
137
+ },
138
+ reset: async () => {
139
+ await ctx.storage.remove("settings");
140
+ const settings = sanitizeSettings(undefined);
141
+ await notify?.(settings);
142
+ return { settings };
143
+ }
144
+ });
145
+ notify = (settings) => registration.events.emit("updated", { settings });
146
+ }
6
147
  });
7
148
  export {
8
149
  server_default as default
9
150
  };
10
151
 
11
- //# debugId=7462091FD6D1ECD864756E2164756E21
152
+ //# debugId=42D98E84CA3C7A8164756E2164756E21
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/server.ts"],
3
+ "sources": ["../src/server.ts", "../src/rpc.ts", "../src/core.ts", "../src/settings.ts"],
4
4
  "sourcesContent": [
5
- "import { Plugin } from \"@opencode/plugin\"\n\n// Identity-only server part. It gives the package (and therefore its GUI part)\n// the id `peak-badge`, matching the TUI part. The badge itself is computed in\n// each client; nothing runs here.\nexport default Plugin.define({\n id: \"peak-badge\",\n setup() {},\n})\n"
5
+ "import { Plugin } from \"@opencode/plugin\"\nimport { PeakBadgeSettingsRpc } from \"./rpc\"\nimport { sanitizeSettings, settingsFromEnvelope, type PeakBadgeSettings } from \"./settings\"\n\n// The server stores the single shared settings object and exposes it over RPC.\n// Keeping it here, in the server's plugin storage, lets the TUI and every\n// desktop window read and write the same value and receive live updates.\nexport default Plugin.define({\n id: \"peak-badge\",\n async setup(ctx) {\n // The registration is needed to emit, but the handlers are built before it\n // exists. Calls cannot arrive until register resolves, so a late binding is\n // safe and avoids returning the settings without notifying other clients.\n let notify: ((settings: PeakBadgeSettings) => Promise<void>) | undefined\n\n const registration = await ctx.rpc.register(PeakBadgeSettingsRpc, {\n get: async () => ({ settings: sanitizeSettings(await ctx.storage.get(\"settings\")) }),\n set: async (input) => {\n const settings = sanitizeSettings(settingsFromEnvelope(input))\n await ctx.storage.set(\"settings\", settings)\n await notify?.(settings)\n return { settings }\n },\n reset: async () => {\n await ctx.storage.remove(\"settings\")\n const settings = sanitizeSettings(undefined)\n await notify?.(settings)\n return { settings }\n },\n })\n\n notify = (settings) => registration.events.emit(\"updated\", { settings })\n },\n})\n",
6
+ "import { Rpc } from \"@opencode/plugin/rpc\"\n\n// JSON Schema keeps the RPC definition dependency-free and portable: both the\n// server and the clients use the same object, and the host validates every\n// call and event. Unknown fields are rejected so a typo cannot silently store\n// a setting the plugin does not understand.\nconst Settings = {\n type: \"object\",\n properties: {\n models: { type: \"array\", items: { type: \"string\" } },\n windows: {\n type: \"array\",\n items: {\n type: \"array\",\n items: { type: \"string\" },\n minItems: 2,\n maxItems: 2,\n },\n },\n weekdaysOnly: { type: \"boolean\" },\n pollSeconds: { type: \"string\" },\n labelPeak: { type: \"string\" },\n labelOffPeak: { type: \"string\" },\n subagents: { type: \"boolean\" },\n alwaysShow: { type: \"boolean\" },\n debug: { type: \"boolean\" },\n fakeTime: { type: \"string\" },\n },\n additionalProperties: false,\n} as const\n\nconst Envelope = {\n type: \"object\",\n properties: { settings: Settings },\n required: [\"settings\"],\n additionalProperties: false,\n} as const\n\nconst Empty = { type: \"object\", additionalProperties: false } as const\n\n/**\n * The shared settings RPC. `get` returns the defaults when nothing is stored;\n * `set` replaces the full object; `reset` removes the stored value. `updated`\n * reaches every open TUI and desktop window so both badges follow the change.\n */\nexport const PeakBadgeSettingsRpc = Rpc.define({\n id: \"peak-badge.settings\",\n methods: {\n get: { input: Empty, output: Envelope },\n set: { input: Envelope, output: Envelope },\n reset: { input: Empty, output: Envelope },\n },\n events: {\n updated: { schema: Envelope },\n },\n})\n",
7
+ "export type WindowSpec = readonly [start: string, end: string]\n\nexport type MinuteWindow = { start: number; end: number }\n\nexport type ModelEntryObject =\n | { id: string; windows?: WindowSpec[]; weekdaysOnly?: boolean }\n | { pattern: string; windows?: WindowSpec[]; weekdaysOnly?: boolean }\n\nexport type ModelEntrySpec = string | ModelEntryObject\n\nexport type RuleOptions = {\n models?: ModelEntrySpec[]\n windows?: WindowSpec[]\n weekdaysOnly?: boolean\n}\n\nexport type ResolvedModelRule = {\n id: string\n windows: MinuteWindow[]\n weekdaysOnly: boolean\n regex?: RegExp\n}\n\nexport type RuleSet = {\n exact: Map<string, ResolvedModelRule>\n patterns: ResolvedModelRule[]\n fallback: ResolvedModelRule\n}\n\nexport type BadgeState = { label: string; peak: boolean }\n\nexport type ModelRef = { providerID: string; id: string }\n\nexport const DEFAULT_WINDOWS: WindowSpec[] = [\n [\"01:00\", \"04:00\"],\n [\"06:00\", \"10:00\"],\n]\n\nexport const DEFAULT_MODELS: ModelEntrySpec[] = [\n \"re:^opencode-go/deepseek\",\n \"re:^opencode/deepseek\",\n \"re:^deepseek/deepseek\",\n]\n\n// Resolves the clock used by the badge. `fakeTime` comes from the shared\n// settings; the TUI also passes its test-only environment variable.\nexport function currentNow(fakeTime?: string, realNow: Date = new Date()): Date {\n if (fakeTime) {\n const parsed = new Date(fakeTime)\n if (!Number.isNaN(parsed.getTime())) return parsed\n }\n return realNow\n}\n\nexport function parseHHMM(value: string): number | undefined {\n const match = /^(\\d{1,2}):(\\d{2})$/.exec(value.trim())\n if (!match) return undefined\n const hours = Number(match[1])\n const minutes = Number(match[2])\n if (hours > 23 || minutes > 59) return undefined\n return hours * 60 + minutes\n}\n\nexport function parseWindow(spec: WindowSpec): MinuteWindow | undefined {\n const start = parseHHMM(spec[0])\n const end = parseHHMM(spec[1])\n if (start === undefined || end === undefined) return undefined\n return { start, end }\n}\n\nexport function parseWindows(specs: readonly WindowSpec[]): MinuteWindow[] {\n const windows: MinuteWindow[] = []\n for (const spec of specs) {\n const window = parseWindow(spec)\n if (window) windows.push(window)\n }\n return windows\n}\n\nexport function inWindow(minutes: number, window: MinuteWindow): boolean {\n if (window.end <= window.start) return minutes >= window.start || minutes < window.end\n return minutes >= window.start && minutes < window.end\n}\n\nexport function isPeakUtc(now: Date, windows: readonly MinuteWindow[], weekdaysOnly = true): boolean {\n if (weekdaysOnly) {\n const day = now.getUTCDay()\n if (day === 0 || day === 6) return false\n }\n const minutes = now.getUTCHours() * 60 + now.getUTCMinutes()\n return windows.some((window) => inWindow(minutes, window))\n}\n\nexport function modelKey(providerID: string, modelID: string): string {\n return `${providerID}/${modelID}`.trim().toLowerCase()\n}\n\nfunction buildRule(\n id: string,\n spec: { windows?: WindowSpec[]; weekdaysOnly?: boolean },\n defaultWindows: MinuteWindow[],\n defaultWeekdays: boolean,\n): ResolvedModelRule {\n return {\n id,\n windows: spec.windows?.length ? parseWindows(spec.windows) : defaultWindows,\n weekdaysOnly: spec.weekdaysOnly ?? defaultWeekdays,\n }\n}\n\nexport function resolveRules(options: RuleOptions = {}): RuleSet {\n const defaultWindows = parseWindows(options.windows ?? DEFAULT_WINDOWS)\n const defaultWeekdays = options.weekdaysOnly ?? true\n const entries = options.models ?? DEFAULT_MODELS\n const exact = new Map<string, ResolvedModelRule>()\n const patterns: ResolvedModelRule[] = []\n for (const entry of entries) {\n if (typeof entry === \"string\") {\n const trimmed = entry.trim()\n if (!trimmed) continue\n if (trimmed.toLowerCase().startsWith(\"re:\")) {\n const source = trimmed.slice(3)\n if (!source.trim()) continue\n const regex = compileRegex(source)\n if (!regex) continue\n patterns.push({ id: source, regex, windows: defaultWindows, weekdaysOnly: defaultWeekdays })\n } else {\n const id = trimmed.toLowerCase()\n exact.set(id, buildRule(id, {}, defaultWindows, defaultWeekdays))\n }\n } else if (\"pattern\" in entry) {\n const source = entry.pattern\n if (!source.trim()) continue\n const regex = compileRegex(source)\n if (!regex) continue\n patterns.push({\n id: source,\n regex,\n windows: entry.windows?.length ? parseWindows(entry.windows) : defaultWindows,\n weekdaysOnly: entry.weekdaysOnly ?? defaultWeekdays,\n })\n } else {\n const id = entry.id.trim().toLowerCase()\n if (!id) continue\n exact.set(id, buildRule(id, entry, defaultWindows, defaultWeekdays))\n }\n }\n return {\n exact,\n patterns,\n fallback: { id: \"\", windows: defaultWindows, weekdaysOnly: defaultWeekdays },\n }\n}\n\n// Whether one configured model entry is usable. Shared by the settings editors\n// so a typo in an exact id or an unsafe regex is reported instead of silently\n// matching nothing.\nexport function isValidModelEntry(entry: ModelEntrySpec): boolean {\n const rules = resolveRules({ models: [entry] })\n return rules.exact.size > 0 || rules.patterns.length > 0\n}\n\nfunction isSafeRegex(source: string): boolean {\n let depth = 0\n let inClass = false\n for (let i = 0; i < source.length; i++) {\n const ch = source[i]!\n if (ch === \"\\\\\") {\n i++\n continue\n }\n if (ch === \"[\") {\n inClass = true\n continue\n }\n if (ch === \"]\") {\n inClass = false\n continue\n }\n if (inClass) continue\n if (ch === \"(\") depth++\n else if (ch === \")\") depth = Math.max(0, depth - 1)\n else if (depth > 0 && \"+*}\".includes(ch)) return false\n }\n return true\n}\n\nfunction compileRegex(source: string): RegExp | undefined {\n try {\n if (!isSafeRegex(source)) return undefined\n return new RegExp(source, \"i\")\n } catch {\n // An invalid regex is ignored; resolveRules skips this entry.\n return undefined\n }\n}\n\nexport function matchRule(rules: RuleSet, key: string): ResolvedModelRule | undefined {\n const exact = rules.exact.get(key)\n if (exact) return exact\n for (const rule of rules.patterns) {\n if (rule.regex!.test(key)) return rule\n }\n return undefined\n}\n\nexport function badgeFor(\n now: Date,\n rule: ResolvedModelRule | undefined,\n labels: { peak: string; offPeak: string },\n): BadgeState | undefined {\n if (!rule) return undefined\n const peak = isPeakUtc(now, rule.windows, rule.weekdaysOnly)\n return { label: peak ? labels.peak : labels.offPeak, peak }\n}\n\nexport function mergeBadges(states: Array<BadgeState | undefined>): BadgeState | undefined {\n let result: BadgeState | undefined\n for (const state of states) {\n if (!state) continue\n if (!result) {\n result = state\n continue\n }\n if (state.peak && !result.peak) result = state\n }\n return result\n}\n\n// Shared by the TUI and desktop adapters: the main model follows `alwaysShow`;\n// a running subagent only contributes when it matches a configured rule.\nexport function badgeForModels(input: {\n now: Date\n rules: RuleSet\n labels: { peak: string; offPeak: string }\n main: ModelRef | undefined\n subagents: readonly ModelRef[]\n alwaysShow: boolean\n}): BadgeState | undefined {\n const states: BadgeState[] = []\n if (input.main) {\n const rule =\n matchRule(input.rules, modelKey(input.main.providerID, input.main.id)) ??\n (input.alwaysShow ? input.rules.fallback : undefined)\n const state = badgeFor(input.now, rule, input.labels)\n if (state) states.push(state)\n }\n for (const child of input.subagents) {\n const state = badgeFor(input.now, matchRule(input.rules, modelKey(child.providerID, child.id)), input.labels)\n if (state) states.push(state)\n }\n return mergeBadges(states)\n}\n\n// Walks the descendant tree of a session and returns the models of the\n// running subagents. The model callback lets each adapter decide how to read\n// (and cache) a child's model.\nexport function runningSubagentRefs(input: {\n sessionID: string\n family: (sessionID: string) => readonly string[]\n status: (sessionID: string) => \"idle\" | \"running\"\n model: (sessionID: string) => ModelRef | undefined\n}): ModelRef[] {\n const refs: ModelRef[] = []\n const seen = new Set<string>()\n const stack: string[] = [...input.family(input.sessionID)]\n while (stack.length > 0) {\n const id = stack.pop()\n if (!id || seen.has(id)) continue\n seen.add(id)\n if (input.status(id) === \"running\") {\n const model = input.model(id)\n if (model) refs.push(model)\n }\n // `family` may return every descendant already; recursing keeps nested\n // subagents covered if it only returns direct children. `seen` caps it.\n for (const nested of input.family(id)) {\n if (!seen.has(nested)) stack.push(nested)\n }\n }\n return refs\n}\n",
8
+ "import {\n DEFAULT_MODELS,\n DEFAULT_WINDOWS,\n isValidModelEntry,\n parseHHMM,\n resolveRules,\n type ModelEntryObject,\n type ModelEntrySpec,\n type RuleSet,\n type WindowSpec,\n} from \"./core\"\n\n/**\n * The settings shared by the TUI and the desktop app. `models` keeps one raw\n * line per entry so the editors can round-trip exact ids, regexes and JSON\n * objects without a second shape. `pollSeconds` and `fakeTime` stay raw for the\n * same reason; resolveSettings normalizes them for the badge.\n */\nexport type PeakBadgeSettings = {\n models: string[]\n windows: WindowSpec[]\n weekdaysOnly: boolean\n pollSeconds: string\n labelPeak: string\n labelOffPeak: string\n subagents: boolean\n alwaysShow: boolean\n debug: boolean\n fakeTime: string\n}\n\n/** The normalized values a badge needs, derived from PeakBadgeSettings. */\nexport type ResolvedSettings = {\n rules: RuleSet\n labels: { peak: string; offPeak: string }\n pollSeconds: number\n subagents: boolean\n alwaysShow: boolean\n debug: boolean\n fakeTime: string | undefined\n}\n\nexport const DEFAULT_POLL_SECONDS = 10\n\nexport const DEFAULT_SETTINGS: PeakBadgeSettings = {\n models: modelLines(DEFAULT_MODELS),\n windows: DEFAULT_WINDOWS.map(([start, end]): WindowSpec => [start, end]),\n weekdaysOnly: true,\n pollSeconds: String(DEFAULT_POLL_SECONDS),\n labelPeak: \"[PEAK]\",\n labelOffPeak: \"[OFF-PEAK]\",\n subagents: true,\n alwaysShow: false,\n debug: false,\n fakeTime: \"\",\n}\n\n/** A fresh copy of the built-in settings, safe for an editor to mutate. */\nexport function defaultSettings(): PeakBadgeSettings {\n return {\n ...DEFAULT_SETTINGS,\n models: [...DEFAULT_SETTINGS.models],\n windows: DEFAULT_SETTINGS.windows.map(([start, end]): WindowSpec => [start, end]),\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value)\n}\n\nfunction isWindowSpec(value: unknown): value is WindowSpec {\n return (\n Array.isArray(value) &&\n value.length === 2 &&\n typeof value[0] === \"string\" &&\n typeof value[1] === \"string\"\n )\n}\n\nfunction isWindowList(value: unknown): value is WindowSpec[] {\n return Array.isArray(value) && value.every(isWindowSpec)\n}/**\n * Fills missing or invalid fields with defaults. Used by the server when it\n * reads storage and by both clients when they receive an RPC payload, so a\n * partial or older value can never break a badge.\n */\nexport function sanitizeSettings(value: unknown): PeakBadgeSettings {\n const next = defaultSettings()\n if (!isRecord(value)) return next\n\n if (Array.isArray(value.models) && value.models.every((entry) => typeof entry === \"string\")) {\n next.models = [...value.models]\n }\n if (isWindowList(value.windows)) {\n next.windows = value.windows.map(([start, end]): WindowSpec => [start, end])\n }\n if (typeof value.weekdaysOnly === \"boolean\") next.weekdaysOnly = value.weekdaysOnly\n if (typeof value.pollSeconds === \"string\") next.pollSeconds = value.pollSeconds\n if (typeof value.labelPeak === \"string\") next.labelPeak = value.labelPeak\n if (typeof value.labelOffPeak === \"string\") next.labelOffPeak = value.labelOffPeak\n if (typeof value.subagents === \"boolean\") next.subagents = value.subagents\n if (typeof value.alwaysShow === \"boolean\") next.alwaysShow = value.alwaysShow\n if (typeof value.debug === \"boolean\") next.debug = value.debug\n if (typeof value.fakeTime === \"string\") next.fakeTime = value.fakeTime\n\n return next\n}\n\n/** Reads the `{ settings }` envelope used by the RPC methods and event. */\nexport function settingsFromEnvelope(value: unknown): PeakBadgeSettings {\n return sanitizeSettings(isRecord(value) ? value.settings : undefined)\n}\n\n/** Normalizes stored settings for both badge adapters. */\nexport function resolveSettings(settings: PeakBadgeSettings): ResolvedSettings {\n const poll = Number(settings.pollSeconds)\n return {\n rules: resolveRules({\n models: parseModelLines(settings.models),\n windows: settings.windows,\n weekdaysOnly: settings.weekdaysOnly,\n }),\n labels: { peak: settings.labelPeak, offPeak: settings.labelOffPeak },\n pollSeconds: Number.isFinite(poll) && poll >= 1 ? poll : DEFAULT_POLL_SECONDS,\n subagents: settings.subagents,\n alwaysShow: settings.alwaysShow,\n debug: settings.debug,\n fakeTime: settings.fakeTime.trim() || undefined,\n }\n}\n\n/** Serializes model entries into one editable line each. */\nexport function modelLines(entries: readonly ModelEntrySpec[]): string[] {\n return entries.map((entry) => (typeof entry === \"string\" ? entry : JSON.stringify(entry)))\n}\n\n/**\n * Parses one editable model line. Strings are exact ids or `re:` patterns;\n * lines starting with `{` are JSON objects with `id` or `pattern`, plus\n * optional `windows` and `weekdaysOnly`. Invalid JSON, a JSON array, or an\n * object without a usable id/pattern yields undefined.\n */\nexport function parseModelLine(line: string): ModelEntrySpec | undefined {\n const text = line.trim()\n if (!text) return undefined\n if (!text.startsWith(\"{\") && !text.startsWith(\"[\")) return text\n\n let value: unknown\n try {\n value = JSON.parse(text)\n } catch {\n // A line that starts like JSON but does not parse is an invalid entry.\n return undefined\n }\n if (!isRecord(value)) return undefined\n\n const pattern = typeof value.pattern === \"string\" && value.pattern.trim() ? value.pattern.trim() : undefined\n const id = typeof value.id === \"string\" && value.id.trim() ? value.id.trim() : undefined\n if (!pattern && !id) return undefined\n\n let windows: WindowSpec[] | undefined\n if (value.windows !== undefined) {\n if (!isWindowList(value.windows)) return undefined\n windows = value.windows.map(([start, end]): WindowSpec => [start, end])\n }\n if (value.weekdaysOnly !== undefined && typeof value.weekdaysOnly !== \"boolean\") return undefined\n const weekdaysOnly = typeof value.weekdaysOnly === \"boolean\" ? value.weekdaysOnly : undefined\n\n const entry: ModelEntryObject = pattern\n ? {\n pattern,\n ...(windows !== undefined ? { windows } : {}),\n ...(weekdaysOnly !== undefined ? { weekdaysOnly } : {}),\n }\n : {\n id: id!,\n ...(windows !== undefined ? { windows } : {}),\n ...(weekdaysOnly !== undefined ? { weekdaysOnly } : {}),\n }\n return entry\n}\n\n/** Parses the editable lines, dropping entries that are not valid shapes. */\nexport function parseModelLines(lines: readonly string[]): ModelEntrySpec[] {\n const entries: ModelEntrySpec[] = []\n for (const line of lines) {\n const entry = parseModelLine(line)\n if (entry !== undefined) entries.push(entry)\n }\n return entries\n}\n\nexport function isHHMM(value: string): boolean {\n return parseHHMM(value) !== undefined\n}\n\nexport function isWindowValid(window: WindowSpec): boolean {\n return isHHMM(window[0]) && isHHMM(window[1])\n}\n\n/**\n * A model line is valid when its shape parses, its regex/id is usable, and any\n * per-entry windows use HH:MM. Exact ids are accepted as-is; a regex with a\n * typo is reported so the badge does not silently stop matching.\n */\nexport function isValidModelLine(line: string): boolean {\n const entry = parseModelLine(line)\n if (entry === undefined || !isValidModelEntry(entry)) return false\n if (typeof entry === \"object\" && entry.windows && !entry.windows.every(isWindowValid)) return false\n return true\n}\n\nexport function isValidPollSeconds(raw: string): boolean {\n const value = Number(raw)\n return raw.trim() !== \"\" && Number.isFinite(value) && value >= 1\n}\n\nexport function isValidFakeTime(raw: string): boolean {\n if (!raw.trim()) return true\n return !Number.isNaN(new Date(raw).getTime())\n}\n\nexport function formatWindows(windows: readonly WindowSpec[]): string {\n if (windows.length === 0) return \"none\"\n return windows.map(([start, end]) => `${start} - ${end}`).join(\", \")\n}\n\nexport function formatModels(models: readonly string[]): string {\n if (models.length === 0) return \"none\"\n const shown = models.slice(0, 2).join(\", \")\n return models.length > 2 ? `${shown}, ...` : shown\n}\n\nexport function onOff(value: boolean): string {\n return value ? \"on\" : \"off\"\n}\n"
6
9
  ],
7
- "mappings": ";AAAA;AAKA,IAAe,wBAAO,OAAO;AAAA,EAC3B,IAAI;AAAA,EACJ,KAAK,GAAG;AACV,CAAC;",
8
- "debugId": "7462091FD6D1ECD864756E2164756E21",
10
+ "mappings": ";AAAA;;;AC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,QAAQ,IAAI,YAAY,QAAQ;AAAA,QAC1C,MAAM,SAAS,QAAQ;AAAA,QACvB,OAAO,EAAE,SAAS;AAAA;AAAA,MAEpB,OAAO,YAAY;AAAA,QACjB,MAAM,IAAI,QAAQ,OAAO,UAAU;AAAA,QACnC,MAAM,WAAW,iBAAiB,SAAS;AAAA,QAC3C,MAAM,SAAS,QAAQ;AAAA,QACvB,OAAO,EAAE,SAAS;AAAA;AAAA,IAEtB,CAAC;AAAA,IAED,SAAS,CAAC,aAAa,aAAa,OAAO,KAAK,WAAW,EAAE,SAAS,CAAC;AAAA;AAE3E,CAAC;",
11
+ "debugId": "42D98E84CA3C7A8164756E2164756E21",
9
12
  "names": []
10
13
  }
@@ -0,0 +1,29 @@
1
+ import type { OpenCodeClient } from "@opencode/client";
2
+ import { type PeakBadgeSettings } from "./settings";
3
+ /**
4
+ * The shared settings RPC plumbing both badge adapters need: connect to the
5
+ * event stream, refresh on demand, save a full object, and reset to defaults.
6
+ * The TUI and the desktop differ only in when they call these methods and how
7
+ * they surface errors.
8
+ */
9
+ export type SettingsSync = {
10
+ connect(): void;
11
+ refresh(force?: boolean): Promise<void>;
12
+ save(next: PeakBadgeSettings): Promise<void>;
13
+ reset(): Promise<void>;
14
+ stop(): void;
15
+ };
16
+ export type SettingsSyncOptions = {
17
+ /** Read the client where it is used: it changes after a server restart. */
18
+ readonly client: () => OpenCodeClient;
19
+ readonly set: (next: PeakBadgeSettings) => void;
20
+ /** Skip an incoming value while the caller has a local edit pending. */
21
+ readonly canApply?: (next: PeakBadgeSettings) => boolean;
22
+ /** Replace the default event acceptance check. Return false to ignore. */
23
+ readonly acceptEvent?: (next: PeakBadgeSettings) => boolean;
24
+ /** Load failures: fetch or event subscription. */
25
+ readonly onLoadError?: (message: string) => void;
26
+ /** Save and reset failures. */
27
+ readonly onSaveError?: (message: string) => void;
28
+ };
29
+ export declare function createSettingsSync(options: SettingsSyncOptions): SettingsSync;
@@ -0,0 +1,65 @@
1
+ import { type ModelEntrySpec, type RuleSet, type WindowSpec } from "./core";
2
+ /**
3
+ * The settings shared by the TUI and the desktop app. `models` keeps one raw
4
+ * line per entry so the editors can round-trip exact ids, regexes and JSON
5
+ * objects without a second shape. `pollSeconds` and `fakeTime` stay raw for the
6
+ * same reason; resolveSettings normalizes them for the badge.
7
+ */
8
+ export type PeakBadgeSettings = {
9
+ models: string[];
10
+ windows: WindowSpec[];
11
+ weekdaysOnly: boolean;
12
+ pollSeconds: string;
13
+ labelPeak: string;
14
+ labelOffPeak: string;
15
+ subagents: boolean;
16
+ alwaysShow: boolean;
17
+ debug: boolean;
18
+ fakeTime: string;
19
+ };
20
+ /** The normalized values a badge needs, derived from PeakBadgeSettings. */
21
+ export type ResolvedSettings = {
22
+ rules: RuleSet;
23
+ labels: {
24
+ peak: string;
25
+ offPeak: string;
26
+ };
27
+ pollSeconds: number;
28
+ subagents: boolean;
29
+ alwaysShow: boolean;
30
+ debug: boolean;
31
+ fakeTime: string | undefined;
32
+ };
33
+ export declare const DEFAULT_POLL_SECONDS = 10;
34
+ export declare const DEFAULT_SETTINGS: PeakBadgeSettings;
35
+ /** A fresh copy of the built-in settings, safe for an editor to mutate. */
36
+ export declare function defaultSettings(): PeakBadgeSettings;
37
+ export declare function sanitizeSettings(value: unknown): PeakBadgeSettings;
38
+ /** Reads the `{ settings }` envelope used by the RPC methods and event. */
39
+ export declare function settingsFromEnvelope(value: unknown): PeakBadgeSettings;
40
+ /** Normalizes stored settings for both badge adapters. */
41
+ export declare function resolveSettings(settings: PeakBadgeSettings): ResolvedSettings;
42
+ /** Serializes model entries into one editable line each. */
43
+ export declare function modelLines(entries: readonly ModelEntrySpec[]): string[];
44
+ /**
45
+ * Parses one editable model line. Strings are exact ids or `re:` patterns;
46
+ * lines starting with `{` are JSON objects with `id` or `pattern`, plus
47
+ * optional `windows` and `weekdaysOnly`. Invalid JSON, a JSON array, or an
48
+ * object without a usable id/pattern yields undefined.
49
+ */
50
+ export declare function parseModelLine(line: string): ModelEntrySpec | undefined;
51
+ /** Parses the editable lines, dropping entries that are not valid shapes. */
52
+ export declare function parseModelLines(lines: readonly string[]): ModelEntrySpec[];
53
+ export declare function isHHMM(value: string): boolean;
54
+ export declare function isWindowValid(window: WindowSpec): boolean;
55
+ /**
56
+ * A model line is valid when its shape parses, its regex/id is usable, and any
57
+ * per-entry windows use HH:MM. Exact ids are accepted as-is; a regex with a
58
+ * typo is reported so the badge does not silently stop matching.
59
+ */
60
+ export declare function isValidModelLine(line: string): boolean;
61
+ export declare function isValidPollSeconds(raw: string): boolean;
62
+ export declare function isValidFakeTime(raw: string): boolean;
63
+ export declare function formatWindows(windows: readonly WindowSpec[]): string;
64
+ export declare function formatModels(models: readonly string[]): string;
65
+ export declare function onOff(value: boolean): string;
@@ -0,0 +1,15 @@
1
+ import type { Context } from "@opencode/plugin/tui/context";
2
+ import { type PeakBadgeSettings } from "./settings";
3
+ /** The state the settings dialog reads and writes. */
4
+ export type SettingsDialogState = {
5
+ readonly settings: () => PeakBadgeSettings;
6
+ save(next: PeakBadgeSettings): Promise<void>;
7
+ reset(): Promise<void>;
8
+ };
9
+ /**
10
+ * The TUI's settings editor. The TUI SDK has no settings-page registry, so the
11
+ * editor is a command (`/peak-badge` or the command palette) that opens the
12
+ * host's native select/prompt/confirm dialogs. Every change is stored through
13
+ * the shared RPC, so the desktop page and the TUI badge follow it immediately.
14
+ */
15
+ export declare function openPeakBadgeSettings(ctx: Context, state: SettingsDialogState): Promise<void>;
package/dist/tui.d.ts CHANGED
@@ -9,4 +9,5 @@ export declare const __test: {
9
9
  refresh: ((date?: Date) => void) | undefined;
10
10
  applyRecentModel: (() => Promise<void>) | undefined;
11
11
  refreshHomeModel: (() => Promise<void>) | undefined;
12
+ refreshSettings: (() => Promise<void>) | undefined;
12
13
  };