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.
@@ -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
@@ -6,7 +6,8 @@ export default _default;
6
6
  export declare const __test: {
7
7
  badge: ((sessionID?: string) => BadgeState | undefined) | undefined;
8
8
  badgeText: ((sessionID?: string) => string) | undefined;
9
- refresh: (() => void) | undefined;
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
  };