@restranger/repi-ui 0.0.0-stage → 0.0.1-3546f1c.dirty

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/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./src/index.js";
2
+ export { default } from "./src/index.js";
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
- "name": "@restranger/repi-ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@restranger/repi-ui",
3
+ "version": "0.0.1-3546f1c.dirty",
4
+ "description": "Declarative ViewNode renderer and UI service for Pi extensions",
5
+ "type": "module",
6
+ "main": "./index.ts",
7
+ "types": "./index.ts",
8
+ "exports": {
9
+ ".": "./index.ts"
10
+ },
11
+ "files": ["index.ts", "src", "README.md", "!src/**/__tests__"],
12
+ "keywords": ["pi-package", "pi-coding-agent", "ui", "tui", "view"],
13
+ "author": "ReStranger <restranger@disroot.org>",
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/ReStranger/repi-mono.git",
18
+ "directory": "packages/ui"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/ReStranger/repi-mono/issues"
22
+ },
23
+ "homepage": "https://github.com/ReStranger/repi-mono#readme",
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "pi": {
28
+ "extensions": ["./index.ts"]
29
+ },
30
+ "dependencies": {
31
+ "@restranger/repi-lib": "0.0.1-3546f1c.dirty"
32
+ },
33
+ "peerDependencies": {
34
+ "@earendil-works/pi-coding-agent": ">=0.79.0"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "@earendil-works/pi-coding-agent": {
38
+ "optional": true
39
+ }
40
+ }
41
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./native-menu.js";
2
+ export * from "./overlay.js";
3
+ export * from "./plugin.js";
4
+ export * from "./render-to-text.js";
5
+ export * from "./view.js";
6
+ export { default } from "./plugin.js";
@@ -0,0 +1,308 @@
1
+ import { displayWidth, fitWidth, sanitize, truncate, wrapDisplay } from "@restranger/repi-lib";
2
+ import { ListOverlay, mouseWheelDirection } from "./overlay.js";
3
+
4
+ /**
5
+ * Shared rendering primitives for Pi-native inline menus.
6
+ *
7
+ * `/fallback`, `/advisor` and any future settings menu look like the host's own pickers
8
+ * (`/models`, `/scoped-models`, `ctx.ui.select`): a content-sized frame drawn with `─` rules, an
9
+ * `accent`+`bold` title, `dim` metadata, a `→ ` cursor and a `dim key + muted description` hint
10
+ * line. There are no box corners and no second pane. Extracting the layout here keeps the menus
11
+ * from drifting apart the way the earlier overlay copies did.
12
+ */
13
+
14
+ export const MENU_LIST_GAP = 2;
15
+ export const MENU_MIN_VISIBLE = 3;
16
+ export const MENU_MAX_VISIBLE = 10;
17
+ export const MENU_MAX_CHAIN_LINES = 3;
18
+ const MIN_DESCRIPTION_WIDTH = 8;
19
+
20
+ export function clamp(value: number, min: number, max: number): number {
21
+ return Math.max(min, Math.min(value, max));
22
+ }
23
+
24
+ /**
25
+ * Subsequence match, the way Pi's `fuzzyFilter` treats a picker query: every query character must
26
+ * appear in order, consecutive runs score higher.
27
+ */
28
+ export function fuzzyScore(text: string, query: string): number | undefined {
29
+ if (query.length === 0) {
30
+ return 0;
31
+ }
32
+ const haystack = text.toLowerCase();
33
+ let index = 0;
34
+ let score = 0;
35
+ let streak = 0;
36
+ for (const char of query.toLowerCase()) {
37
+ const found = haystack.indexOf(char, index);
38
+ if (found === -1) {
39
+ return undefined;
40
+ }
41
+ streak = found === index ? streak + 1 : 0;
42
+ score += 1 + streak;
43
+ index = found + 1;
44
+ }
45
+ return score;
46
+ }
47
+
48
+ /** A printable character belongs in the search field, not in the list navigation. */
49
+ export function isPrintable(data: string): boolean {
50
+ return data.length === 1 && data >= " " && data !== "\x7f";
51
+ }
52
+
53
+ /** Widest label plus a gap, clamped so a long agent or model name cannot eat the description. */
54
+ export function primaryColumnWidth(labels: readonly string[], max = 34): number {
55
+ const widest = labels.reduce((width, label) => Math.max(width, displayWidth(label) + MENU_LIST_GAP), 0);
56
+ return clamp(widest, Math.min(16, max), max);
57
+ }
58
+
59
+ /** Options accepted by `NativeMenuView.row`. */
60
+ export interface MenuRowOptions {
61
+ readonly selected: boolean;
62
+ readonly cursor: string;
63
+ /** Reserve the `✓ ` column; rows without a checked state keep the column empty. */
64
+ readonly marker: boolean;
65
+ readonly checked: boolean;
66
+ readonly label: string;
67
+ readonly description?: string;
68
+ readonly descriptionColor?: string;
69
+ readonly unavailable?: boolean;
70
+ /** Dim suffix such as a chain rank; its width is reserved before the description. */
71
+ readonly trailing?: string;
72
+ readonly primary: number;
73
+ }
74
+
75
+ /**
76
+ * Base class for host-native inline menus. Subclasses own their data, modes and key handling; the
77
+ * frame, hint packing and list-row layout live here so every menu measures text identically.
78
+ */
79
+ export abstract class NativeMenuView extends ListOverlay {
80
+ /** 6 rows for title, subtitle, chain and rules; subclasses add their own content. */
81
+ protected static readonly MIN_WIDTH = 36;
82
+
83
+ /** Rows the last render could show, used by PageUp/PageDown. */
84
+ protected visibleRows = MENU_MIN_VISIBLE;
85
+
86
+ // --- frame ---------------------------------------------------------------------------------
87
+
88
+ /** Same content-sized rule the host draws around its own pickers. */
89
+ protected rule(width: number): string {
90
+ return this.border("─".repeat(Math.max(1, width)));
91
+ }
92
+
93
+ protected pad(text: string, width: number, indent = 1): string {
94
+ return truncate(`${" ".repeat(indent)}${text}`, width);
95
+ }
96
+
97
+ protected scrollInfo(position: number, total: number, width: number): string {
98
+ return this.pad(this.paint("dim", ` (${position}/${total})`), width, 0);
99
+ }
100
+
101
+ // --- hints ---------------------------------------------------------------------------------
102
+
103
+ protected hint(keys: string, description: string): string {
104
+ return `${this.paint("dim", keys)}${this.paint("muted", ` ${description}`)}`;
105
+ }
106
+
107
+ /**
108
+ * `keyLabel`, but formatted the way Pi's own `keyDisplayText` does it: `ctrl+s` → `Ctrl+S`,
109
+ * `alt+up` → `Alt+↑`, `escape` → `Esc`. Bare single-letter bindings keep their case (`p`).
110
+ */
111
+ protected hintLabel(key: string, fallback: string): string {
112
+ return this.keyLabel(key, fallback)
113
+ .split("/")
114
+ .map((part) => this.formatKey(part))
115
+ .join("/");
116
+ }
117
+
118
+ protected formatKey(part: string): string {
119
+ return part
120
+ .split("+")
121
+ .map((segment, index) => {
122
+ const lower = segment.toLowerCase();
123
+ if (lower === "ctrl") return "Ctrl";
124
+ if (lower === "alt") return "Alt";
125
+ if (lower === "shift") return "Shift";
126
+ if (lower === "super") return "Super";
127
+ if (lower === "up") return "↑";
128
+ if (lower === "down") return "↓";
129
+ if (lower === "left") return "←";
130
+ if (lower === "right") return "→";
131
+ if (lower === "escape" || lower === "esc") return "Esc";
132
+ if (lower === "enter" || lower === "return") return "Enter";
133
+ if (lower === "tab") return "Tab";
134
+ if (lower === "space") return "Space";
135
+ if (lower === "backspace") return "Backspace";
136
+ if (lower === "delete") return "Delete";
137
+ if (lower === "pageup") return "PageUp";
138
+ if (lower === "pagedown") return "PageDown";
139
+ if (lower === "home") return "Home";
140
+ if (lower === "end") return "End";
141
+ // A key after a modifier is capitalised (`Ctrl+S`); a bare single letter stays lowercase (`p`).
142
+ if (segment.length === 1) {
143
+ return index > 0 ? segment.toUpperCase() : segment;
144
+ }
145
+ return `${segment.charAt(0).toUpperCase()}${segment.slice(1)}`;
146
+ })
147
+ .join("+");
148
+ }
149
+
150
+ /** `↑↓` when the up/down bindings are the bare arrows, `p/n` when they are remapped. */
151
+ protected navLabel(): string {
152
+ return this.pairLabel("tui.select.up", "tui.select.down", "↑", "↓");
153
+ }
154
+
155
+ protected reorderLabel(): string {
156
+ return this.pairLabel("app.models.reorderUp", "app.models.reorderDown", "Alt+↑", "Alt+↓");
157
+ }
158
+
159
+ protected pairLabel(upKey: string, downKey: string, upFallback: string, downFallback: string): string {
160
+ const up = this.hintLabel(upKey, upFallback);
161
+ const down = this.hintLabel(downKey, downFallback);
162
+ if (up.endsWith("↑") && down.endsWith("↓")) {
163
+ const upPrefix = up.slice(0, -1);
164
+ const downPrefix = down.slice(0, -1);
165
+ if (upPrefix === downPrefix) {
166
+ return `${upPrefix}↑↓`;
167
+ }
168
+ }
169
+ return `${up}/${down}`;
170
+ }
171
+
172
+ /** Pack the key hints into as many lines as the width needs, so nothing important is clipped. */
173
+ protected packHints(hints: readonly string[], width: number): string[] {
174
+ const joined = hints.join(" ");
175
+ if (displayWidth(` ${joined}`) <= width) {
176
+ return [truncate(` ${joined}`, width)];
177
+ }
178
+
179
+ // Two balanced lines read better than one full line and one orphan. Prefer the split that
180
+ // minimises the difference between the halves, as long as both halves fit.
181
+ let best = 0;
182
+ let bestDiff = Number.POSITIVE_INFINITY;
183
+ for (let index = 1; index < hints.length; index++) {
184
+ const left = displayWidth(` ${hints.slice(0, index).join(" ")}`);
185
+ const right = displayWidth(` ${hints.slice(index).join(" ")}`);
186
+ if (left > width || right > width) {
187
+ continue;
188
+ }
189
+ const diff = Math.abs(left - right);
190
+ if (diff < bestDiff) {
191
+ bestDiff = diff;
192
+ best = index;
193
+ }
194
+ }
195
+ if (best > 0) {
196
+ return [
197
+ truncate(` ${hints.slice(0, best).join(" ")}`, width),
198
+ truncate(` ${hints.slice(best).join(" ")}`, width),
199
+ ];
200
+ }
201
+
202
+ const lines: string[] = [];
203
+ let current = "";
204
+ for (const hint of hints) {
205
+ const next = current ? `${current} ${hint}` : hint;
206
+ if (current && displayWidth(` ${next}`) > width) {
207
+ lines.push(truncate(` ${current}`, width));
208
+ current = hint;
209
+ } else {
210
+ current = next;
211
+ }
212
+ }
213
+ if (current) {
214
+ lines.push(truncate(` ${current}`, width));
215
+ }
216
+ return lines;
217
+ }
218
+
219
+ // --- rows ----------------------------------------------------------------------------------
220
+
221
+ protected row(width: number, opts: MenuRowOptions): string {
222
+ const marker = opts.marker ? "✓ " : "";
223
+ const trailing = opts.trailing ?? "";
224
+ const prefixWidth = displayWidth(opts.cursor) + displayWidth(marker);
225
+ const trailingWidth = displayWidth(trailing);
226
+ const labelWidth = Math.max(1, Math.min(opts.primary, width - prefixWidth - MIN_DESCRIPTION_WIDTH - trailingWidth));
227
+ const padded = fitWidth(sanitize(opts.label), labelWidth);
228
+ const descriptionWidth = Math.max(0, width - prefixWidth - labelWidth - trailingWidth);
229
+ const description = opts.description ? truncate(sanitize(opts.description), descriptionWidth) : "";
230
+
231
+ const cursor = opts.selected ? this.paint("accent", opts.cursor) : " ".repeat(displayWidth(opts.cursor));
232
+ const check = opts.checked ? this.paint("accent", marker) : " ".repeat(displayWidth(marker));
233
+ const label = opts.selected ? this.paint("accent", padded) : opts.unavailable ? this.paint("dim", padded) : padded;
234
+ const desc = description ? this.paint(opts.descriptionColor ?? "muted", description) : "";
235
+ const tail = trailing ? this.paint("dim", trailing) : "";
236
+ return `${cursor}${check}${label}${desc}${tail}`.trimEnd();
237
+ }
238
+
239
+ /** Selected model's fallback chain, wrapped like `/models` wraps the selected model's name. */
240
+ protected chainLines(
241
+ label: string,
242
+ models: readonly string[],
243
+ width: number,
244
+ maxLines = MENU_MAX_CHAIN_LINES,
245
+ ): string[] {
246
+ const painted = this.paint("muted", label);
247
+ const indent = 1 + displayWidth(painted) + MENU_LIST_GAP;
248
+ if (models.length === 0) {
249
+ return [this.pad(`${painted}${" ".repeat(MENU_LIST_GAP)}${this.paint("dim", "none")}`, width)];
250
+ }
251
+ const body = models.map((model, index) => `${index + 1}. ${sanitize(model)}`).join(" · ");
252
+ const wrapped = wrapDisplay(body, Math.max(10, width - indent));
253
+ const lines: string[] = [];
254
+ for (let index = 0; index < Math.min(wrapped.length, maxLines); index++) {
255
+ const prefix = index === 0 ? `${" ".repeat(1)}${painted}${" ".repeat(MENU_LIST_GAP)}` : " ".repeat(indent);
256
+ lines.push(truncate(`${prefix}${wrapped[index] ?? ""}`, width));
257
+ }
258
+ if (wrapped.length > maxLines) {
259
+ lines.push(truncate(`${" ".repeat(indent)}${this.paint("dim", "…")}`, width));
260
+ }
261
+ return lines;
262
+ }
263
+
264
+ // --- windowing -----------------------------------------------------------------------------
265
+
266
+ protected windowStart(selected: number, count: number, maxVisible: number): number {
267
+ return Math.max(0, Math.min(selected - Math.floor(maxVisible / 2), count - maxVisible));
268
+ }
269
+
270
+ /** Rows available for the list after `frameRows`; also remembered for PageUp/PageDown. */
271
+ protected maxVisibleRows(frameRows: number): number {
272
+ this.visibleRows = Math.max(MENU_MIN_VISIBLE, Math.min(MENU_MAX_VISIBLE, this.rowsBudget() - frameRows));
273
+ return this.visibleRows;
274
+ }
275
+
276
+ protected pageStep(): number {
277
+ return Math.max(1, this.visibleRows);
278
+ }
279
+
280
+ /** Wheel event or the host's scroll keybinding, in either direction. */
281
+ protected isUp(data: string): boolean {
282
+ return (
283
+ mouseWheelDirection(data) === -1 ||
284
+ this.matches(data, "tui.select.up") ||
285
+ data === "\x1b[A" ||
286
+ data === "\x1bOA" ||
287
+ data === "k"
288
+ );
289
+ }
290
+
291
+ protected isDown(data: string): boolean {
292
+ return (
293
+ mouseWheelDirection(data) === 1 ||
294
+ this.matches(data, "tui.select.down") ||
295
+ data === "\x1b[B" ||
296
+ data === "\x1bOB" ||
297
+ data === "j"
298
+ );
299
+ }
300
+
301
+ protected isArrowUp(data: string): boolean {
302
+ return data === "\x1b[A" || data === "\x1bOA";
303
+ }
304
+
305
+ protected isArrowDown(data: string): boolean {
306
+ return data === "\x1b[B" || data === "\x1bOB";
307
+ }
308
+ }
package/src/overlay.ts ADDED
@@ -0,0 +1,256 @@
1
+ import type { PiUiCustomComponent, PiUiCustomKeybindings, PiUiCustomTheme, PiUiCustomTui } from "@restranger/repi-lib";
2
+
3
+ /**
4
+ * Shared scaffolding for full-screen list overlays.
5
+ *
6
+ * `@restranger/repi-subagents` and `@restranger/repi-model-fallback` each shipped their own copy of the same fifteen
7
+ * methods: attach/refresh/dispose, selection clamping, detail scrolling, terminal row budgeting,
8
+ * safe `theme.fg`, safe keybinding lookup and the close handshake. The copies drifted (one handled
9
+ * `getKeys` failures, the other did not), so this is the single implementation.
10
+ *
11
+ * Subclasses own their data, rendering and key handling; everything about *host interaction* lives
12
+ * here.
13
+ */
14
+ export interface ListOverlayOptions {
15
+ /** Rows the host granted; defaults to the attached terminal, then to 32. */
16
+ readonly maxRows?: number;
17
+ }
18
+
19
+ /** Frame rows reserved for header/separator/footer lines. */
20
+ export const OVERLAY_FRAME_CHROME_ROWS = 6;
21
+
22
+ export abstract class ListOverlay implements PiUiCustomComponent {
23
+ protected tui?: PiUiCustomTui;
24
+ protected theme?: PiUiCustomTheme;
25
+ protected keybindings?: PiUiCustomKeybindings;
26
+ private done?: (value: undefined) => void;
27
+
28
+ protected selected = 0;
29
+ protected detailScroll = 0;
30
+ /** Last scroll ceiling seen by `render`, so `scrollDetail` can clamp without rendering first. */
31
+ protected maxDetailScroll = 0;
32
+
33
+ protected constructor(protected readonly overlayOptions: ListOverlayOptions = {}) {}
34
+
35
+ abstract render(width: number): string[];
36
+ abstract handleInput(data: string): void;
37
+
38
+ /** Number of selectable rows; `0` makes every move a no-op. */
39
+ protected abstract itemCount(): number;
40
+
41
+ /** Hook for subclasses that reset their own state when selection changes. */
42
+ protected onSelectionChanged(): void {}
43
+
44
+ /** Hook for subclasses that must run cleanup after the overlay closes. */
45
+ protected onClose(): void {}
46
+
47
+ attach(
48
+ tui: PiUiCustomTui,
49
+ theme: PiUiCustomTheme,
50
+ keybindings: PiUiCustomKeybindings,
51
+ done: (value: undefined) => void,
52
+ ): void {
53
+ this.tui = tui;
54
+ this.theme = theme;
55
+ this.keybindings = keybindings;
56
+ this.done = done;
57
+ }
58
+
59
+ /** Called by the plugin whenever underlying state changes. */
60
+ refresh(): void {
61
+ this.clampSelection();
62
+ this.tui?.requestRender();
63
+ }
64
+
65
+ dispose(): void {
66
+ this.close();
67
+ this.tui = undefined;
68
+ this.theme = undefined;
69
+ this.keybindings = undefined;
70
+ }
71
+
72
+ invalidate(): void {
73
+ this.clampSelection();
74
+ }
75
+
76
+ protected move(delta: number): void {
77
+ const length = this.itemCount();
78
+ if (length === 0) {
79
+ return;
80
+ }
81
+ this.select(this.selected + delta);
82
+ }
83
+
84
+ protected select(index: number): void {
85
+ const length = this.itemCount();
86
+ if (length === 0) {
87
+ return;
88
+ }
89
+ this.selected = Math.max(0, Math.min(index, length - 1));
90
+ this.detailScroll = 0;
91
+ this.onSelectionChanged();
92
+ this.tui?.requestRender();
93
+ }
94
+
95
+ protected clampSelection(): void {
96
+ this.selected = Math.max(0, Math.min(this.selected, Math.max(0, this.itemCount() - 1)));
97
+ }
98
+
99
+ protected scrollDetail(delta: number): void {
100
+ this.detailScroll = Math.max(0, Math.min(this.detailScroll + delta, this.maxDetailScroll));
101
+ this.tui?.requestRender();
102
+ }
103
+
104
+ protected rowsBudget(): number {
105
+ return Math.max(1, Math.floor(this.overlayOptions.maxRows ?? this.tui?.terminal?.rows ?? 32));
106
+ }
107
+
108
+ /**
109
+ * Body rows after the frame chrome. `bodyHeight + OVERLAY_FRAME_CHROME_ROWS` must stay inside
110
+ * the budget, or the host clips the footer away on a short terminal.
111
+ */
112
+ protected bodyHeightFor(rows: number): number {
113
+ return Math.max(1, Math.floor(rows * 0.85) - OVERLAY_FRAME_CHROME_ROWS);
114
+ }
115
+
116
+ protected bodyRows(): number {
117
+ return this.bodyHeightFor(this.rowsBudget());
118
+ }
119
+
120
+ /** Window over `body` honouring the current detail scroll position. */
121
+ protected windowBody(body: readonly string[], height: number): string[] {
122
+ if (height <= 0) {
123
+ return [];
124
+ }
125
+ const maxScroll = Math.max(0, body.length - height);
126
+ this.maxDetailScroll = maxScroll;
127
+ const start = Math.max(0, Math.min(this.detailScroll, maxScroll));
128
+ return body.slice(start, start + height);
129
+ }
130
+
131
+ protected close(): void {
132
+ const done = this.done;
133
+ this.done = undefined;
134
+ done?.(undefined);
135
+ this.onClose();
136
+ }
137
+
138
+ protected matches(data: string, key: string): boolean {
139
+ try {
140
+ return this.keybindings?.matches(data, key) ?? false;
141
+ } catch {
142
+ return false;
143
+ }
144
+ }
145
+
146
+ /** Human label for an action, falling back to the conventional key. */
147
+ protected keyLabel(key: string, fallback: string): string {
148
+ try {
149
+ const keys = this.keybindings?.getKeys?.(key);
150
+ if (!keys || keys.length === 0) {
151
+ return fallback;
152
+ }
153
+ return keys
154
+ .map((binding) => (binding === "up" ? "↑" : binding === "down" ? "↓" : binding === "escape" ? "Esc" : binding))
155
+ .join("/");
156
+ } catch {
157
+ return fallback;
158
+ }
159
+ }
160
+
161
+ /** `theme.fg` for a token that may be missing from a host theme; never throws. */
162
+ protected paint(color: string, text: string): string {
163
+ try {
164
+ return this.theme?.fg(color, text) ?? text;
165
+ } catch {
166
+ return text;
167
+ }
168
+ }
169
+
170
+ protected border(text: string): string {
171
+ return this.paint("border", text);
172
+ }
173
+ }
174
+
175
+ function parseSgrCode(data: string): number | undefined {
176
+ if (!data.startsWith("\x1b[<")) return undefined;
177
+ const semicolon = data.indexOf(";", 3);
178
+ if (semicolon === -1) return undefined;
179
+ const code = Number.parseInt(data.slice(3, semicolon), 10);
180
+ return Number.isNaN(code) ? undefined : code;
181
+ }
182
+
183
+ export interface MouseWheelEvent {
184
+ readonly direction: -1 | 1;
185
+ readonly x?: number;
186
+ readonly y?: number;
187
+ }
188
+
189
+ /**
190
+ * Decode an SGR or X10 mouse wheel event into direction and coordinates.
191
+ */
192
+ export function parseMouseWheel(data: string): MouseWheelEvent | undefined {
193
+ if (data.startsWith("\x1b[<")) {
194
+ const endChar = data[data.length - 1];
195
+ if (endChar !== "M" && endChar !== "m") return undefined;
196
+ const parts = data.slice(3, -1).split(";");
197
+ if (parts.length >= 3) {
198
+ const button = Number.parseInt(parts[0], 10);
199
+ const x = Number.parseInt(parts[1], 10);
200
+ const y = Number.parseInt(parts[2], 10);
201
+ if (!Number.isNaN(button) && (button & 64) !== 0) {
202
+ const direction: -1 | 1 = (button & 1) === 0 ? -1 : 1;
203
+ return {
204
+ direction,
205
+ x: Number.isNaN(x) ? undefined : x,
206
+ y: Number.isNaN(y) ? undefined : y,
207
+ };
208
+ }
209
+ }
210
+ return undefined;
211
+ }
212
+ if (data.startsWith("\x1b[M") && data.length >= 6) {
213
+ const button = data.charCodeAt(3) - 32;
214
+ const x = data.charCodeAt(4) - 32;
215
+ const y = data.charCodeAt(5) - 32;
216
+ if ((button & 64) !== 0) {
217
+ const direction: -1 | 1 = (button & 1) === 0 ? -1 : 1;
218
+ return {
219
+ direction,
220
+ x: x >= 1 ? x : undefined,
221
+ y: y >= 1 ? y : undefined,
222
+ };
223
+ }
224
+ }
225
+ const dir = mouseWheelDirection(data);
226
+ if (dir !== undefined) {
227
+ return { direction: dir };
228
+ }
229
+ return undefined;
230
+ }
231
+
232
+ /**
233
+ * Decode an SGR mouse scroll event into a direction.
234
+ *
235
+ * Terminals report the wheel as button 64 (up) / 65 (down) in three encodings; getting one wrong
236
+ * means scrolling silently does nothing, which is why this lives next to the overlay instead of in
237
+ * each component.
238
+ */
239
+ export function mouseWheelDirection(data: string): -1 | 1 | undefined {
240
+ if (data.startsWith("\x1b[<64;")) return -1;
241
+ if (data.startsWith("\x1b[<65;")) return 1;
242
+ const code = parseSgrCode(data);
243
+ if (code !== undefined) {
244
+ if ((code & 64) !== 0) {
245
+ return (code & 1) === 0 ? -1 : 1;
246
+ }
247
+ return undefined;
248
+ }
249
+ if (data.startsWith("\x1b[M") && data.length >= 4) {
250
+ const encoded = data.charCodeAt(3) - 32;
251
+ if ((encoded & 64) !== 0) {
252
+ return (encoded & 1) === 0 ? -1 : 1;
253
+ }
254
+ }
255
+ return undefined;
256
+ }
package/src/plugin.ts ADDED
@@ -0,0 +1,125 @@
1
+ import {
2
+ type Disposable,
3
+ type PiContext,
4
+ type PiExtensionAPI,
5
+ UI_CONTRACT_ID,
6
+ type UiService,
7
+ announceReady,
8
+ getSessionId,
9
+ publishService,
10
+ } from "@restranger/repi-lib";
11
+
12
+ export interface UiPluginOptions {
13
+ /** Session used when the host does not pass one in the event context. */
14
+ defaultSessionId?: string;
15
+ }
16
+
17
+ export interface UiRuntime {
18
+ attach(pi: PiExtensionAPI): void;
19
+ dispose(): void;
20
+ }
21
+
22
+ function serviceFromContext(ctx: PiContext): UiService {
23
+ return {
24
+ select: (title, options, opts) => ctx.ui.select(title, options, opts),
25
+ confirm: (title, message, opts) => ctx.ui.confirm(title, message, opts),
26
+ input: (title, placeholder, opts) => ctx.ui.input(title, placeholder, opts),
27
+ notify: (message, type) => ctx.ui.notify(message, type),
28
+ setStatus: (key, text) => ctx.ui.setStatus?.(key, text),
29
+ };
30
+ }
31
+
32
+ /**
33
+ * Publishes the host's dialog/notification surface as `re:ui@1`.
34
+ *
35
+ * This plugin has no dependency on permissions or modes. A consumer that wants a dialog resolves
36
+ * the service; a consumer that does not care simply never asks.
37
+ */
38
+ export function createUiRuntime(opts: UiPluginOptions = {}): UiRuntime {
39
+ const defaultSessionId = opts.defaultSessionId ?? "default";
40
+ const sessions = new Map<string, Disposable>();
41
+ let attached = false;
42
+ let disposed = false;
43
+
44
+ const publish = (pi: PiExtensionAPI, ctx: PiContext): void => {
45
+ const sessionId = getSessionId(ctx, defaultSessionId);
46
+ sessions.get(sessionId)?.dispose();
47
+ const registration = publishService({
48
+ contract: UI_CONTRACT_ID,
49
+ sessionId,
50
+ owner: "repi:ui",
51
+ impl: serviceFromContext(ctx),
52
+ });
53
+ sessions.set(sessionId, registration);
54
+ announceReady(pi.events, {
55
+ contract: UI_CONTRACT_ID,
56
+ version: 1,
57
+ sessionId,
58
+ owner: "repi:ui",
59
+ capabilities: ["select", "confirm", "input", "notify", "status"],
60
+ });
61
+ };
62
+
63
+ const attach = (pi: PiExtensionAPI): void => {
64
+ if (disposed) {
65
+ throw new Error("UI runtime is disposed and cannot be attached.");
66
+ }
67
+ if (attached) {
68
+ throw new Error("UI runtime is already attached to a Pi extension API.");
69
+ }
70
+ attached = true;
71
+
72
+ pi.on("session_start", (_event, ctx) => {
73
+ if (!disposed) {
74
+ publish(pi, ctx);
75
+ }
76
+ });
77
+ pi.on("before_agent_start", (_event, ctx) => {
78
+ if (disposed) {
79
+ return undefined;
80
+ }
81
+ if (!sessions.has(getSessionId(ctx, defaultSessionId))) {
82
+ publish(pi, ctx);
83
+ } else {
84
+ const sessionId = getSessionId(ctx, defaultSessionId);
85
+ announceReady(pi.events, {
86
+ contract: UI_CONTRACT_ID,
87
+ version: 1,
88
+ sessionId,
89
+ owner: "repi:ui",
90
+ capabilities: ["select", "confirm", "input", "notify", "status"],
91
+ });
92
+ }
93
+ return undefined;
94
+ });
95
+ pi.on("session_shutdown", (_event, ctx) => {
96
+ const sessionId = getSessionId(ctx, defaultSessionId);
97
+ sessions.get(sessionId)?.dispose();
98
+ sessions.delete(sessionId);
99
+ });
100
+ };
101
+
102
+ const dispose = (): void => {
103
+ if (disposed) {
104
+ return;
105
+ }
106
+ disposed = true;
107
+ for (const registration of sessions.values()) {
108
+ registration.dispose();
109
+ }
110
+ sessions.clear();
111
+ };
112
+
113
+ return { attach, dispose };
114
+ }
115
+
116
+ /** Return a Pi extension factory; useful for tests and for composition in a custom host. */
117
+ export function createUiPlugin(opts: UiPluginOptions = {}): (pi: unknown) => void {
118
+ const runtime = createUiRuntime(opts);
119
+ return (pi) => runtime.attach(pi as PiExtensionAPI);
120
+ }
121
+
122
+ /** Default Pi entry point (`pi.extensions`). Accepts the host API structurally. */
123
+ export default function uiExtension(pi: unknown): void {
124
+ createUiPlugin()(pi);
125
+ }
@@ -0,0 +1,364 @@
1
+ import { displayWidth, fitWidth, truncate, wrapDisplay } from "@restranger/repi-lib";
2
+ import type { BorderStyle, BoxSide, ListItem, ViewNode } from "./view.js";
3
+
4
+ export interface RenderToTextOptions {
5
+ /** Total width budget for the whole tree (`notes/02` §3). Defaults to 80 (or 120 for tui-120). */
6
+ width?: number;
7
+ /** Hard node budget so one plugin cannot lock the renderer (`notes/02` §2 rule 7). */
8
+ maxNodes?: number;
9
+ /** Hard output budget in UTF-8 bytes. Defaults to 64 KiB. */
10
+ maxBytes?: number;
11
+ /** Maximum nesting depth. Defaults to 50. */
12
+ maxDepth?: number;
13
+ /** Surface hint for rendering (`notes/02` §3, §7). */
14
+ surface?: "tui-80" | "tui-120" | "web" | "headless";
15
+ }
16
+
17
+ const DEFAULT_WIDTH = 80;
18
+ const DEFAULT_MAX_NODES = 5000;
19
+ const DEFAULT_MAX_BYTES = 64 * 1024;
20
+ const DEFAULT_MAX_DEPTH = 50;
21
+
22
+ type Node = Exclude<ViewNode, { t: "col" } | { t: "row" }>;
23
+
24
+ interface RenderState {
25
+ width: number;
26
+ readonly maxNodes: number;
27
+ readonly maxBytes: number;
28
+ readonly maxDepth: number;
29
+ nodes: number;
30
+ }
31
+
32
+ /** Cuts to `width` display columns, appending an ellipsis when something was removed. */
33
+ export const truncateText = truncate;
34
+
35
+ /** Word wrap that respects the display width, keeping existing newlines. */
36
+ export const wrapText = wrapDisplay;
37
+
38
+ function formatBadgeText(text: string): string {
39
+ if (text.startsWith("[") && text.endsWith("]")) {
40
+ return text;
41
+ }
42
+ return `[${text}]`;
43
+ }
44
+
45
+ function resolveListBadge(item: ListItem): string {
46
+ if (item.badge) {
47
+ return item.badge;
48
+ }
49
+ if (item.done === true) {
50
+ return "✓";
51
+ }
52
+ if (item.done === false) {
53
+ return "○";
54
+ }
55
+ if (item.status === "done" || item.status === "completed") {
56
+ return "✓";
57
+ }
58
+ if (item.status === "in_progress" || item.status === "active" || item.status === "running") {
59
+ return "●";
60
+ }
61
+ if (item.status === "pending" || item.status === "todo") {
62
+ return "○";
63
+ }
64
+ return "●";
65
+ }
66
+
67
+ interface FrameChars {
68
+ readonly tl: string;
69
+ readonly tr: string;
70
+ readonly bl: string;
71
+ readonly br: string;
72
+ readonly h: string;
73
+ readonly v: string;
74
+ }
75
+
76
+ const FRAMES: Record<Exclude<BorderStyle, "none">, FrameChars> = {
77
+ default: { tl: "╭", tr: "╮", bl: "╰", br: "╯", h: "─", v: "│" },
78
+ rounded: { tl: "╭", tr: "╮", bl: "╰", br: "╯", h: "─", v: "│" },
79
+ sharp: { tl: "┌", tr: "┐", bl: "└", br: "┘", h: "─", v: "│" },
80
+ double: { tl: "╔", tr: "╗", bl: "╚", br: "╝", h: "═", v: "║" },
81
+ minimal: { tl: "", tr: "", bl: "", br: "", h: "─", v: "" },
82
+ };
83
+
84
+ function padTo(text: string, width: number): string {
85
+ return fitWidth(text, width);
86
+ }
87
+
88
+ function frameBox(
89
+ innerLines: string[],
90
+ title: string | undefined,
91
+ style: BorderStyle,
92
+ sides: readonly BoxSide[] | undefined,
93
+ totalWidth: number,
94
+ ): string[] {
95
+ if (style === "none") {
96
+ return innerLines.map((line) => truncate(line, totalWidth));
97
+ }
98
+
99
+ const chars = FRAMES[style] ?? FRAMES.default;
100
+ const showLeft = sides === undefined || sides.includes("left");
101
+ const showRight = sides === undefined || sides.includes("right");
102
+ const showTop = sides === undefined || sides.includes("top");
103
+ const showBottom = sides === undefined || sides.includes("bottom");
104
+
105
+ const leftCap = showLeft ? chars.v : "";
106
+ const rightCap = showRight ? chars.v : "";
107
+ // Width available between the vertical borders.
108
+ const innerWidth = Math.max(1, totalWidth - displayWidth(leftCap) - displayWidth(rightCap));
109
+ // Body lines are `│ <content> │`, the left border costs two extra columns of padding.
110
+ const contentWidth = Math.max(1, innerWidth - (showLeft ? 2 : 0));
111
+ const rendered = innerLines.flatMap((line) => wrapDisplay(line, contentWidth));
112
+
113
+ const lines: string[] = [];
114
+
115
+ if (showTop) {
116
+ const titleText = title ? ` ${title} ` : "";
117
+ const trimmedTitle = truncate(titleText, innerWidth);
118
+ const fill = Math.max(0, innerWidth - displayWidth(trimmedTitle));
119
+ const topLeft = showLeft ? chars.tl : "";
120
+ const topRight = showRight ? chars.tr : "";
121
+ lines.push(`${topLeft}${trimmedTitle}${chars.h.repeat(fill)}${topRight}`);
122
+ } else if (title) {
123
+ lines.push(truncate(` ${title}`, totalWidth));
124
+ }
125
+
126
+ for (const line of rendered) {
127
+ const body = showLeft ? ` ${padTo(line, contentWidth)} ` : padTo(line, contentWidth);
128
+ lines.push(`${leftCap}${body}${rightCap}`);
129
+ }
130
+
131
+ if (showBottom) {
132
+ const bottomLeft = showLeft ? chars.bl : "";
133
+ const bottomRight = showRight ? chars.br : "";
134
+ lines.push(`${bottomLeft}${chars.h.repeat(innerWidth)}${bottomRight}`);
135
+ }
136
+
137
+ return lines;
138
+ }
139
+
140
+ function renderKnownNode(node: Node, state: RenderState, depth: number): string[] {
141
+ switch (node.t) {
142
+ case "text": {
143
+ const wrap = node.wrap ?? true;
144
+ return wrap ? wrapText(node.text, state.width) : [truncateText(node.text, state.width)];
145
+ }
146
+
147
+ case "markdown": {
148
+ // The plain-text surface keeps markdown readable as-is (`notes/02` §1: T1 fallback first).
149
+ return wrapText(node.md, state.width);
150
+ }
151
+
152
+ case "badge":
153
+ return [truncateText(formatBadgeText(node.text), state.width)];
154
+
155
+ case "button":
156
+ return [truncateText(`[ ${node.label} ]`, state.width)];
157
+
158
+ case "progress": {
159
+ const max = node.max ?? 100;
160
+ const value = Math.max(0, Math.min(node.value, max));
161
+ const label = node.label ? ` ${node.label}` : "";
162
+ return [truncateText(`[${value}/${max}]${label}`, state.width)];
163
+ }
164
+
165
+ case "spinner":
166
+ return [truncateText(`… ${node.label ?? ""}`.trim(), state.width)];
167
+
168
+ case "kv":
169
+ return node.items.map(([key, value]) => truncateText(`${key}: ${value}`, state.width));
170
+
171
+ case "list":
172
+ return node.items.map((item, index) => {
173
+ let prefix: string;
174
+ if (node.ordered) {
175
+ prefix = `${index + 1}.`;
176
+ } else if (node.checkbox) {
177
+ prefix = item.done ? "[x]" : "[ ]";
178
+ } else {
179
+ prefix = resolveListBadge(item);
180
+ }
181
+ return truncateText(`${prefix} ${item.text}`, state.width);
182
+ });
183
+
184
+ case "table": {
185
+ if (node.fallback) {
186
+ return node.fallback.flatMap((child) => renderNode(child, state, depth + 1));
187
+ }
188
+ const columns = Math.max(node.head.length, ...node.rows.map((row) => row.length), 1);
189
+ const widths: number[] = [];
190
+ for (let index = 0; index < columns; index++) {
191
+ widths.push(
192
+ Math.max(displayWidth(node.head[index] ?? ""), ...node.rows.map((row) => displayWidth(row[index] ?? "")), 1),
193
+ );
194
+ }
195
+ const total = widths.reduce((sum, width) => sum + width + 2, 0);
196
+ const scale = total > state.width ? state.width / total : 1;
197
+ const line = (cells: readonly string[]) =>
198
+ cells
199
+ .map((cell, index) => padTo(cell, Math.max(1, Math.floor((widths[index] ?? 1) * scale))))
200
+ .join(" ")
201
+ .trimEnd();
202
+ return [
203
+ line(node.head),
204
+ line(widths.map((width) => "─".repeat(Math.max(1, Math.floor(width * scale))))),
205
+ ...node.rows.map(line),
206
+ ].map((row) => truncateText(row, state.width));
207
+ }
208
+
209
+ case "diff": {
210
+ if (node.fallback) {
211
+ return node.fallback.flatMap((child) => renderNode(child, state, depth + 1));
212
+ }
213
+ return node.patch.split("\n").map((line) => truncateText(line, state.width));
214
+ }
215
+
216
+ case "box": {
217
+ const children = node.children.flatMap((child) => renderNode(child, state, depth + 1));
218
+ const variant = node.variant ?? "callout";
219
+
220
+ if (variant === "callout") {
221
+ const bar = node.border === "sharp" ? "│" : "┃";
222
+ const lines: string[] = [];
223
+ if (node.title) {
224
+ lines.push(`${bar} ${truncateText(`[${node.title}]`, state.width - 2)}`);
225
+ }
226
+ for (const line of children) {
227
+ lines.push(`${bar} ${truncateText(line, state.width - 2)}`);
228
+ }
229
+ return lines;
230
+ }
231
+
232
+ if (variant === "minimal") {
233
+ const body = children.map((line) => truncateText(line, state.width - 2));
234
+ return node.title ? [`${node.title}`, ...body] : body;
235
+ }
236
+
237
+ return frameBox(children, node.title, node.border ?? "default", node.sides, state.width);
238
+ }
239
+ }
240
+ }
241
+
242
+ function renderNode(node: ViewNode, state: RenderState, depth = 0): string[] {
243
+ state.nodes += 1;
244
+ if (state.nodes > state.maxNodes) {
245
+ throw new Error(`ViewNode tree exceeds the node budget (${state.maxNodes}); refusing to render.`);
246
+ }
247
+ if (depth > state.maxDepth) {
248
+ throw new Error(`ViewNode tree exceeds the depth budget (${state.maxDepth}); refusing to render.`);
249
+ }
250
+
251
+ if (node.t === "col") {
252
+ const gap = Math.max(0, node.gap ?? 0);
253
+ const lines: string[] = [];
254
+ node.children.forEach((child, index) => {
255
+ if (index > 0) {
256
+ for (let i = 0; i < gap; i++) {
257
+ lines.push("");
258
+ }
259
+ }
260
+ lines.push(...renderNode(child, state, depth + 1));
261
+ });
262
+ return lines;
263
+ }
264
+
265
+ if (node.t === "row") {
266
+ if (node.children.length === 0) {
267
+ return [];
268
+ }
269
+ const gap = Math.max(0, node.gap ?? 1);
270
+ const columnWidth = Math.max(
271
+ 1,
272
+ Math.floor((state.width - gap * (node.children.length - 1)) / node.children.length),
273
+ );
274
+ const originalWidth = state.width;
275
+ state.width = columnWidth;
276
+ const children = node.children.map((child) => renderNode(child, state, depth + 1));
277
+ state.width = originalWidth;
278
+
279
+ const height = Math.max(0, ...children.map((lines) => lines.length));
280
+ const widths = children.map((lines) => Math.min(columnWidth, Math.max(0, ...lines.map(displayWidth))));
281
+ const lines: string[] = [];
282
+ for (let index = 0; index < height; index++) {
283
+ const cells = children.map((childLines, childIndex) => padTo(childLines[index] ?? "", widths[childIndex] ?? 0));
284
+ lines.push(truncateText(cells.join(" ".repeat(gap)).trimEnd(), state.width));
285
+ }
286
+ return lines;
287
+ }
288
+
289
+ return renderKnownNode(node, state, depth);
290
+ }
291
+
292
+ export function renderNodeToLines(
293
+ node: ViewNode | ViewNode[] | string | number | boolean | null | undefined,
294
+ opts?: RenderToTextOptions,
295
+ ): string[] {
296
+ if (node === null || node === undefined) {
297
+ return [];
298
+ }
299
+
300
+ const defaultWidth = opts?.surface === "tui-120" ? 120 : DEFAULT_WIDTH;
301
+ const state: RenderState = {
302
+ width: Math.max(10, opts?.width ?? defaultWidth),
303
+ maxNodes: opts?.maxNodes ?? DEFAULT_MAX_NODES,
304
+ maxBytes: opts?.maxBytes ?? DEFAULT_MAX_BYTES,
305
+ maxDepth: opts?.maxDepth ?? DEFAULT_MAX_DEPTH,
306
+ nodes: 0,
307
+ };
308
+
309
+ const render = (value: unknown): string[] => {
310
+ if (value === null || value === undefined) {
311
+ return [];
312
+ }
313
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
314
+ return String(value)
315
+ .split("\n")
316
+ .flatMap((line) => wrapText(line, state.width));
317
+ }
318
+ if (Array.isArray(value)) {
319
+ return value.flatMap((child) => render(child));
320
+ }
321
+ // SAFETY: the union is exhaustive; anything else is a plugin bug and is surfaced, not dropped.
322
+ const asNode = value as ViewNode;
323
+ const known = [
324
+ "col",
325
+ "row",
326
+ "box",
327
+ "text",
328
+ "markdown",
329
+ "badge",
330
+ "kv",
331
+ "list",
332
+ "table",
333
+ "diff",
334
+ "progress",
335
+ "spinner",
336
+ "button",
337
+ ];
338
+ if (typeof asNode.t !== "string" || !known.includes(asNode.t)) {
339
+ return [`[unsupported view node: ${String((asNode as { t?: unknown }).t)}]`];
340
+ }
341
+ return renderNode(asNode, state);
342
+ };
343
+
344
+ const lines = render(node);
345
+ const bytes = Buffer.byteLength(lines.join("\n"), "utf8");
346
+ if (bytes > state.maxBytes) {
347
+ throw new Error(`ViewNode output exceeds the byte budget (${state.maxBytes} bytes); refusing to render.`);
348
+ }
349
+ return lines;
350
+ }
351
+
352
+ export function renderToText(
353
+ node: ViewNode | ViewNode[] | string | number | boolean | null | undefined,
354
+ opts?: RenderToTextOptions,
355
+ ): string {
356
+ return renderNodeToLines(node, opts).join("\n");
357
+ }
358
+
359
+ export function renderToJson(
360
+ tree: ViewNode | readonly ViewNode[],
361
+ _opts?: { surface?: "tui-80" | "tui-120" | "web" | "headless" },
362
+ ): string {
363
+ return JSON.stringify(tree, null, 2);
364
+ }
package/src/view.ts ADDED
@@ -0,0 +1,143 @@
1
+ import type { Tone } from "@restranger/repi-lib";
2
+ export type { Tone };
3
+
4
+ export type BorderStyle = "default" | "rounded" | "sharp" | "double" | "minimal" | "none";
5
+
6
+ export type BoxVariant = "card" | "callout" | "minimal";
7
+
8
+ export type BoxSide = "left" | "right" | "top" | "bottom";
9
+
10
+ export interface ActionRef {
11
+ id: string;
12
+ payload?: Record<string, unknown>;
13
+ }
14
+
15
+ export interface ListItem {
16
+ id: string;
17
+ text: string;
18
+ tone?: Tone;
19
+ badge?: string;
20
+ done?: boolean;
21
+ status?: string;
22
+ }
23
+
24
+ export type SlotId = "statusline" | "aboveEditor" | "belowEditor" | "header" | "footer" | "overlay";
25
+
26
+ export interface ColNode {
27
+ t: "col";
28
+ id?: string;
29
+ gap?: number;
30
+ children: ViewNode[];
31
+ }
32
+
33
+ export interface RowNode {
34
+ t: "row";
35
+ id?: string;
36
+ gap?: number;
37
+ children: ViewNode[];
38
+ }
39
+
40
+ export interface BoxNode {
41
+ t: "box";
42
+ id?: string;
43
+ title?: string;
44
+ tone?: Tone;
45
+ border?: BorderStyle;
46
+ variant?: BoxVariant;
47
+ sides?: BoxSide[];
48
+ children: ViewNode[];
49
+ }
50
+
51
+ export interface TextNode {
52
+ t: "text";
53
+ id?: string;
54
+ text: string;
55
+ tone?: Tone;
56
+ bold?: boolean;
57
+ wrap?: boolean;
58
+ }
59
+
60
+ export interface MarkdownNode {
61
+ t: "markdown";
62
+ id?: string;
63
+ md: string;
64
+ }
65
+
66
+ export interface BadgeNode {
67
+ t: "badge";
68
+ id?: string;
69
+ text: string;
70
+ tone?: Tone;
71
+ }
72
+
73
+ export interface KeyValueNode {
74
+ t: "kv";
75
+ id?: string;
76
+ items: Array<[string, string]>;
77
+ }
78
+
79
+ export interface ListNode {
80
+ t: "list";
81
+ id?: string;
82
+ items: ListItem[];
83
+ ordered?: boolean;
84
+ checkbox?: boolean;
85
+ onSelect?: ActionRef;
86
+ }
87
+
88
+ export interface TableNode {
89
+ t: "table";
90
+ id?: string;
91
+ head: string[];
92
+ rows: string[][];
93
+ fallback?: ViewNode[];
94
+ }
95
+
96
+ export interface DiffNode {
97
+ t: "diff";
98
+ id?: string;
99
+ patch: string;
100
+ fallback?: ViewNode[];
101
+ }
102
+
103
+ export interface ProgressNode {
104
+ t: "progress";
105
+ id?: string;
106
+ value: number;
107
+ max?: number;
108
+ label?: string;
109
+ }
110
+
111
+ export interface SpinnerNode {
112
+ t: "spinner";
113
+ id?: string;
114
+ label?: string;
115
+ }
116
+
117
+ export interface ButtonNode {
118
+ t: "button";
119
+ id?: string;
120
+ label: string;
121
+ action: ActionRef;
122
+ tone?: Tone;
123
+ }
124
+
125
+ export type ViewNode =
126
+ | ColNode
127
+ | RowNode
128
+ | BoxNode
129
+ | TextNode
130
+ | MarkdownNode
131
+ | BadgeNode
132
+ | KeyValueNode
133
+ | ListNode
134
+ | TableNode
135
+ | DiffNode
136
+ | ProgressNode
137
+ | SpinnerNode
138
+ | ButtonNode;
139
+
140
+ export interface ViewOptions {
141
+ /** Higher priority wins in composition order (`notes/01` §3.9). Defaults to 0. */
142
+ priority?: number;
143
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.