trissue 0.0.0-stage → 0.2.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,2474 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/tui/run.tsx
4
+ import { spawnSync } from "node:child_process";
5
+ import { render } from "ink";
6
+ import { useEffect as useEffect4, useState as useState6 } from "react";
7
+
8
+ // src/tui/app.tsx
9
+ import { Box as Box8, Text as Text7 } from "ink";
10
+ import stringWidth4 from "string-width";
11
+
12
+ // src/tui/theme.ts
13
+ function parseHex(hex) {
14
+ let value = hex.replace("#", "");
15
+ if (value.length === 3)
16
+ value = [...value].map((char) => char + char).join("");
17
+ const number = Number.parseInt(value.slice(0, 6), 16);
18
+ return [number >> 16 & 255, number >> 8 & 255, number & 255];
19
+ }
20
+ function toHex([r, g, b]) {
21
+ return `#${[r, g, b].map((channel) => Math.round(channel).toString(16).padStart(2, "0")).join("")}`;
22
+ }
23
+ function mix(from, to, amount) {
24
+ const a = parseHex(from);
25
+ const b = parseHex(to);
26
+ return toHex([0, 1, 2].map((index) => a[index] + (b[index] - a[index]) * amount));
27
+ }
28
+ function gradientAt(stops, position) {
29
+ if (stops.length === 1)
30
+ return stops[0];
31
+ const scaled = Math.min(Math.max(position, 0), 1) * (stops.length - 1);
32
+ const index = Math.min(Math.floor(scaled), stops.length - 2);
33
+ return mix(stops[index], stops[index + 1], scaled - index);
34
+ }
35
+ var BASE_THEME = {
36
+ background: "#000000",
37
+ text: "#FFFFFF",
38
+ muted: "#9A9A9A",
39
+ faint: "#5C5C5C",
40
+ border: "#FFFFFF",
41
+ danger: "#FF4545",
42
+ success: "#3DDC84",
43
+ check: "#3DDC84",
44
+ product: "#FFFFFF",
45
+ scrim: "#000000B3",
46
+ focus: "#FFFFFF"
47
+ };
48
+ function themeFor(config, overrides = {}) {
49
+ const background = overrides.background ?? config?.background ?? BASE_THEME.background;
50
+ const light = luminance(background) > 0.5;
51
+ const text = light ? "#000000" : "#FFFFFF";
52
+ return {
53
+ ...BASE_THEME,
54
+ background,
55
+ text,
56
+ border: text,
57
+ focus: text,
58
+ muted: mix(text, background, 0.4),
59
+ faint: mix(text, background, 0.65),
60
+ scrim: `${light ? "#FFFFFF" : "#000000"}B3`,
61
+ check: config?.checkmark === "monochrome" ? text : BASE_THEME.check,
62
+ product: config?.product?.color ?? text
63
+ };
64
+ }
65
+ function luminance(hex) {
66
+ const [r, g, b] = parseHex(hex).map((channel) => channel / 255);
67
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
68
+ }
69
+ function veiled(theme) {
70
+ const out = { ...theme, veil: theme.scrim };
71
+ for (const key of Object.keys(theme)) {
72
+ if (key !== "scrim" && key !== "veil")
73
+ out[key] = paint(out, theme[key]);
74
+ }
75
+ return out;
76
+ }
77
+ function paint(theme, color) {
78
+ if (!theme.veil)
79
+ return color;
80
+ const opacity = Number.parseInt(theme.veil.slice(7, 9) || "FF", 16) / 255;
81
+ return mix(color, theme.veil.slice(0, 7), opacity);
82
+ }
83
+
84
+ // src/tui/components.tsx
85
+ import { Box, measureElement, Text } from "ink";
86
+ import { createContext, Fragment, useContext, useEffect, useRef, useState } from "react";
87
+ import { jsx, jsxs, Fragment as Fragment2 } from "react/jsx-runtime";
88
+ var ScreenSize = createContext({ columns: 80, rows: 24 });
89
+ var useScreenSize = () => useContext(ScreenSize);
90
+ var FrameSize = createContext({ width: 72, height: 18 });
91
+ var useFrameSize = () => useContext(FrameSize);
92
+ function useMeasure() {
93
+ const ref = useRef(null);
94
+ const [size, setSize] = useState({ width: 0, height: 0 });
95
+ useEffect(() => {
96
+ if (!ref.current)
97
+ return;
98
+ const next = measureElement(ref.current);
99
+ if (next.width !== size.width || next.height !== size.height)
100
+ setSize(next);
101
+ });
102
+ return [ref, size];
103
+ }
104
+ function SegmentText({ segment }) {
105
+ return /* @__PURE__ */ jsx(Text, {
106
+ color: segment.color,
107
+ backgroundColor: segment.background,
108
+ bold: segment.bold,
109
+ italic: segment.italic,
110
+ underline: segment.underline,
111
+ children: segment.text
112
+ });
113
+ }
114
+ function Lines({ lines }) {
115
+ return /* @__PURE__ */ jsx(Fragment2, {
116
+ children: lines.map((line, index) => /* @__PURE__ */ jsx(Text, {
117
+ wrap: "truncate-end",
118
+ children: line.length === 0 ? " " : line.map((segment, part) => /* @__PURE__ */ jsx(SegmentText, {
119
+ segment
120
+ }, part))
121
+ }, index))
122
+ });
123
+ }
124
+ function Panel({ borderColor, backgroundColor, children, paddingX = 0, paddingY = 0, flexDirection, gap, alignItems, justifyContent, ...box }) {
125
+ const [ref, size] = useMeasure();
126
+ const inner = Math.max(size.width - 2, 0);
127
+ const sides = Math.max(size.height - 2, 0);
128
+ return /* @__PURE__ */ jsxs(Box, {
129
+ ref,
130
+ ...box,
131
+ backgroundColor,
132
+ children: [
133
+ /* @__PURE__ */ jsx(Box, {
134
+ flexGrow: 1,
135
+ flexDirection,
136
+ gap,
137
+ alignItems,
138
+ justifyContent,
139
+ paddingX: paddingX + 1,
140
+ paddingY: paddingY + 1,
141
+ children
142
+ }),
143
+ size.width >= 2 && size.height >= 2 && /* @__PURE__ */ jsxs(Fragment2, {
144
+ children: [
145
+ /* @__PURE__ */ jsxs(Box, {
146
+ position: "absolute",
147
+ width: size.width,
148
+ height: size.height,
149
+ flexDirection: "column",
150
+ justifyContent: "space-between",
151
+ children: [
152
+ /* @__PURE__ */ jsx(Text, {
153
+ color: borderColor,
154
+ backgroundColor,
155
+ children: `┌${"─".repeat(inner)}┐`
156
+ }),
157
+ /* @__PURE__ */ jsx(Text, {
158
+ color: borderColor,
159
+ backgroundColor,
160
+ children: `└${"─".repeat(inner)}┘`
161
+ })
162
+ ]
163
+ }),
164
+ sides > 0 && /* @__PURE__ */ jsxs(Box, {
165
+ position: "absolute",
166
+ width: size.width,
167
+ height: size.height,
168
+ paddingY: 1,
169
+ flexDirection: "row",
170
+ justifyContent: "space-between",
171
+ children: [
172
+ /* @__PURE__ */ jsx(Text, {
173
+ color: borderColor,
174
+ backgroundColor,
175
+ children: Array(sides).fill("│").join(`
176
+ `)
177
+ }),
178
+ /* @__PURE__ */ jsx(Text, {
179
+ color: borderColor,
180
+ backgroundColor,
181
+ children: Array(sides).fill("│").join(`
182
+ `)
183
+ })
184
+ ]
185
+ })
186
+ ]
187
+ })
188
+ ]
189
+ });
190
+ }
191
+ function Header({ theme, product, detail }) {
192
+ return /* @__PURE__ */ jsxs(Box, {
193
+ flexDirection: "row",
194
+ justifyContent: "space-between",
195
+ height: 1,
196
+ flexShrink: 0,
197
+ gap: 2,
198
+ children: [
199
+ /* @__PURE__ */ jsxs(Text, {
200
+ wrap: "truncate-end",
201
+ children: [
202
+ /* @__PURE__ */ jsx(Text, {
203
+ color: theme.product,
204
+ bold: true,
205
+ children: product
206
+ }),
207
+ /* @__PURE__ */ jsx(Text, {
208
+ color: theme.text,
209
+ children: " Triage"
210
+ })
211
+ ]
212
+ }),
213
+ /* @__PURE__ */ jsx(Text, {
214
+ color: theme.muted,
215
+ wrap: "truncate-start",
216
+ children: detail
217
+ })
218
+ ]
219
+ });
220
+ }
221
+ function Hints({ theme, hints }) {
222
+ return /* @__PURE__ */ jsx(Box, {
223
+ flexShrink: 0,
224
+ children: /* @__PURE__ */ jsx(Text, {
225
+ children: hints.map(([key, label], index) => /* @__PURE__ */ jsxs(Fragment, {
226
+ children: [
227
+ index > 0 && /* @__PURE__ */ jsx(Text, {
228
+ color: theme.faint,
229
+ children: " · "
230
+ }),
231
+ /* @__PURE__ */ jsx(Text, {
232
+ color: theme.text,
233
+ children: key
234
+ }),
235
+ /* @__PURE__ */ jsxs(Text, {
236
+ color: theme.muted,
237
+ children: [
238
+ " ",
239
+ label
240
+ ]
241
+ })
242
+ ]
243
+ }, key + label))
244
+ })
245
+ });
246
+ }
247
+ function BrandLabel({ name, brand, selected, theme }) {
248
+ const label = ` ${name} `;
249
+ const chars = [...label];
250
+ const colors = brand?.color ?? [theme.text];
251
+ const selectedText = paint(theme, brand?.selectedText ?? theme.background);
252
+ return /* @__PURE__ */ jsx(Text, {
253
+ children: chars.map((char, index) => {
254
+ const color = paint(theme, gradientAt(colors, chars.length > 1 ? index / (chars.length - 1) : 0));
255
+ return selected ? /* @__PURE__ */ jsx(Text, {
256
+ color: selectedText,
257
+ backgroundColor: color,
258
+ bold: true,
259
+ children: char
260
+ }, index) : /* @__PURE__ */ jsx(Text, {
261
+ color,
262
+ children: char
263
+ }, index);
264
+ })
265
+ });
266
+ }
267
+ function ButtonRow({
268
+ theme,
269
+ items,
270
+ index,
271
+ focused
272
+ }) {
273
+ return /* @__PURE__ */ jsx(Box, {
274
+ flexDirection: "row",
275
+ flexWrap: "wrap",
276
+ columnGap: 2,
277
+ flexShrink: 0,
278
+ children: items.map((item, position) => {
279
+ const active = focused && position === index;
280
+ const inverted = { color: theme.background, backgroundColor: theme.focus };
281
+ return /* @__PURE__ */ jsxs(Text, {
282
+ children: [
283
+ /* @__PURE__ */ jsx(Text, {
284
+ ...active ? inverted : {},
285
+ children: " "
286
+ }),
287
+ item.prefix && /* @__PURE__ */ jsxs(Text, {
288
+ ...active ? inverted : { color: item.prefix.color },
289
+ bold: true,
290
+ children: [
291
+ item.prefix.text,
292
+ " "
293
+ ]
294
+ }),
295
+ /* @__PURE__ */ jsxs(Text, {
296
+ ...active ? inverted : { color: theme.text },
297
+ bold: active,
298
+ children: [
299
+ item.label,
300
+ " "
301
+ ]
302
+ })
303
+ ]
304
+ }, item.label);
305
+ })
306
+ });
307
+ }
308
+ function Modal({ theme, title, width = 64, children }) {
309
+ const screen = useScreenSize();
310
+ return /* @__PURE__ */ jsx(Box, {
311
+ position: "absolute",
312
+ width: screen.columns,
313
+ height: screen.rows,
314
+ alignItems: "center",
315
+ justifyContent: "center",
316
+ children: /* @__PURE__ */ jsxs(Panel, {
317
+ width: Math.min(width, Math.floor(screen.columns * 0.9)),
318
+ borderColor: theme.border,
319
+ backgroundColor: theme.background,
320
+ paddingX: 2,
321
+ paddingY: 1,
322
+ flexDirection: "column",
323
+ gap: 1,
324
+ children: [
325
+ /* @__PURE__ */ jsx(Text, {
326
+ color: theme.text,
327
+ bold: true,
328
+ children: title
329
+ }),
330
+ children
331
+ ]
332
+ })
333
+ });
334
+ }
335
+ var SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
336
+ function Spinner({ theme, frame, label }) {
337
+ return /* @__PURE__ */ jsxs(Text, {
338
+ wrap: "truncate-end",
339
+ children: [
340
+ /* @__PURE__ */ jsxs(Text, {
341
+ color: theme.text,
342
+ children: [
343
+ SPINNER[frame % SPINNER.length],
344
+ " "
345
+ ]
346
+ }),
347
+ /* @__PURE__ */ jsx(Text, {
348
+ color: theme.muted,
349
+ children: label
350
+ })
351
+ ]
352
+ });
353
+ }
354
+
355
+ // src/tui/keys.ts
356
+ import { useStdin } from "ink";
357
+ import { useEffect as useEffect2, useRef as useRef2 } from "react";
358
+ var CSI_NAMES = {
359
+ A: "up",
360
+ B: "down",
361
+ C: "right",
362
+ D: "left",
363
+ H: "home",
364
+ F: "end",
365
+ Z: "tab",
366
+ P: "f1",
367
+ Q: "f2",
368
+ R: "f3",
369
+ S: "f4"
370
+ };
371
+ var TILDE_NAMES = {
372
+ "1": "home",
373
+ "2": "insert",
374
+ "3": "delete",
375
+ "4": "end",
376
+ "5": "pageup",
377
+ "6": "pagedown",
378
+ "7": "home",
379
+ "8": "end"
380
+ };
381
+ function key(name, extra = {}) {
382
+ return { name, ctrl: false, shift: false, meta: false, text: "", ...extra };
383
+ }
384
+ function modifiers(value) {
385
+ const bits = Math.max(Number(value ?? 1) - 1, 0);
386
+ return { shift: Boolean(bits & 1), meta: Boolean(bits & 2), ctrl: Boolean(bits & 4) };
387
+ }
388
+ function decodeKey(sequence) {
389
+ if (sequence === "\r" || sequence === `
390
+ `)
391
+ return key("return");
392
+ if (sequence === "\x1B\r")
393
+ return key("return", { meta: true });
394
+ if (sequence === "\t")
395
+ return key("tab");
396
+ if (sequence === "" || sequence === "\b")
397
+ return key("backspace");
398
+ if (sequence === "\x1B" || sequence === "\x1B\b")
399
+ return key("backspace", { meta: true });
400
+ if (sequence === "\x1B" || sequence === "\x1B\x1B")
401
+ return key("escape");
402
+ if (sequence === " ")
403
+ return key("space", { text: " " });
404
+ const csi = /^\x1b(?:\[|O)(?:(\d+)(?:;(\d+))?)?([A-Za-z~])$/.exec(sequence);
405
+ if (csi) {
406
+ const [, number, modifier, final] = csi;
407
+ if (final === "~")
408
+ return key(TILDE_NAMES[number ?? ""] ?? "unknown", modifiers(modifier));
409
+ if (final === "Z")
410
+ return key("tab", { shift: true });
411
+ const name = CSI_NAMES[final];
412
+ if (name)
413
+ return key(name, modifiers(modifier));
414
+ return key("unknown");
415
+ }
416
+ if (sequence.length === 2 && sequence[0] === "\x1B") {
417
+ const char = sequence[1];
418
+ return key(char.toLowerCase(), { meta: true, shift: char !== char.toLowerCase() });
419
+ }
420
+ if (sequence.startsWith("\x1B"))
421
+ return key("unknown");
422
+ if (sequence.length === 1) {
423
+ const code = sequence.charCodeAt(0);
424
+ if (code >= 1 && code <= 26)
425
+ return key(String.fromCharCode(code + 96), { ctrl: true });
426
+ if (code < 32)
427
+ return key("unknown");
428
+ }
429
+ const text = sequence.replace(/\r\n?/g, `
430
+ `);
431
+ if ([...text].length > 1)
432
+ return key("paste", { text });
433
+ return key(text.toLowerCase(), { text, shift: text !== text.toLowerCase() });
434
+ }
435
+ function useKeys(handler, active = true) {
436
+ const { internal_eventEmitter: events, setRawMode } = useStdin();
437
+ const latest = useRef2(handler);
438
+ latest.current = handler;
439
+ useEffect2(() => {
440
+ if (!active)
441
+ return;
442
+ setRawMode(true);
443
+ const listener = (sequence) => latest.current(decodeKey(sequence));
444
+ events.on("input", listener);
445
+ return () => {
446
+ events.off("input", listener);
447
+ setRawMode(false);
448
+ };
449
+ }, [active, events, setRawMode]);
450
+ }
451
+
452
+ // src/tui/modals.tsx
453
+ import { Box as Box3, Text as Text3 } from "ink";
454
+ import { useState as useState2 } from "react";
455
+ import { linkIncludesIssue } from "trissue-embedded";
456
+
457
+ // src/tui/textarea.tsx
458
+ import { Box as Box2, Text as Text2 } from "ink";
459
+ import { useReducer, useRef as useRef3 } from "react";
460
+ import stringWidth from "string-width";
461
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
462
+ var segmenter = new Intl.Segmenter;
463
+ function boundaries(text) {
464
+ const out = [...segmenter.segment(text)].map((part) => part.index);
465
+ out.push(text.length);
466
+ return out;
467
+ }
468
+ function previousBoundary(text, offset) {
469
+ const all = boundaries(text);
470
+ for (let index = all.length - 1;index >= 0; index--)
471
+ if (all[index] < offset)
472
+ return all[index];
473
+ return 0;
474
+ }
475
+ function nextBoundary(text, offset) {
476
+ for (const boundary of boundaries(text))
477
+ if (boundary > offset)
478
+ return boundary;
479
+ return text.length;
480
+ }
481
+ function previousWord(text, offset) {
482
+ let index = offset;
483
+ while (index > 0 && /\s/.test(text[index - 1]))
484
+ index--;
485
+ while (index > 0 && !/\s/.test(text[index - 1]))
486
+ index--;
487
+ return index;
488
+ }
489
+ function nextWord(text, offset) {
490
+ let index = offset;
491
+ while (index < text.length && /\s/.test(text[index]))
492
+ index++;
493
+ while (index < text.length && !/\s/.test(text[index]))
494
+ index++;
495
+ return index;
496
+ }
497
+ function layoutRows(text, width) {
498
+ const limit = Math.max(width, 1);
499
+ const rows = [];
500
+ let paragraphStart = 0;
501
+ for (const paragraph of text.split(`
502
+ `)) {
503
+ let rowStart = paragraphStart;
504
+ let used = 0;
505
+ let lastBreak = -1;
506
+ for (const { segment, index } of segmenter.segment(paragraph)) {
507
+ const offset = paragraphStart + index;
508
+ const cells = stringWidth(segment);
509
+ const space = /^\s+$/.test(segment);
510
+ if (!space && used + cells > limit && offset > rowStart) {
511
+ const breakAt = lastBreak > rowStart ? lastBreak : offset;
512
+ rows.push({ start: rowStart, end: breakAt });
513
+ used = stringWidth(text.slice(breakAt, offset));
514
+ rowStart = breakAt;
515
+ lastBreak = -1;
516
+ }
517
+ used += cells;
518
+ if (space)
519
+ lastBreak = offset + segment.length;
520
+ }
521
+ const paragraphEnd = paragraphStart + paragraph.length;
522
+ rows.push({ start: rowStart, end: paragraphEnd });
523
+ paragraphStart = paragraphEnd + 1;
524
+ }
525
+ return rows;
526
+ }
527
+ function rowOf(rows, offset) {
528
+ let found = 0;
529
+ rows.forEach((row, index) => {
530
+ if (row.start <= offset)
531
+ found = index;
532
+ });
533
+ return found;
534
+ }
535
+ function offsetAtColumn(text, row, column) {
536
+ let offset = row.start;
537
+ let used = 0;
538
+ for (const { segment, index } of segmenter.segment(text.slice(row.start, row.end))) {
539
+ const cells = stringWidth(segment);
540
+ if (used + cells > column)
541
+ break;
542
+ used += cells;
543
+ offset = row.start + index + segment.length;
544
+ }
545
+ return offset;
546
+ }
547
+ function TextArea(props) {
548
+ const { value, theme, focused, height } = props;
549
+ const [ref, size] = useMeasure();
550
+ const [, redraw] = useReducer((count) => count + 1, 0);
551
+ const state = useRef3({ cursor: value.length, top: 0, goalColumn: null, known: value });
552
+ const history = useRef3({ undo: [], redo: [], lastKind: "", lastAt: 0 });
553
+ if (value !== state.current.known) {
554
+ state.current.cursor = value.length;
555
+ state.current.known = value;
556
+ }
557
+ state.current.cursor = Math.min(state.current.cursor, value.length);
558
+ const width = Math.max(size.width - 1, 1);
559
+ const rows = layoutRows(value, width);
560
+ const cursorRow = rowOf(rows, state.current.cursor);
561
+ function commit(text, cursor, kind) {
562
+ const log = history.current;
563
+ const now = Date.now();
564
+ if (kind !== log.lastKind || now - log.lastAt > 1000 || kind !== "type") {
565
+ log.undo.push({ text: value, cursor: state.current.cursor });
566
+ if (log.undo.length > 200)
567
+ log.undo.shift();
568
+ }
569
+ log.redo = [];
570
+ log.lastKind = kind;
571
+ log.lastAt = now;
572
+ move(cursor);
573
+ state.current.known = text;
574
+ props.onChange(text);
575
+ }
576
+ function restore(from, to) {
577
+ const snapshot = from.pop();
578
+ if (!snapshot)
579
+ return;
580
+ to.push({ text: value, cursor: state.current.cursor });
581
+ history.current.lastKind = "";
582
+ state.current.known = snapshot.text;
583
+ move(snapshot.cursor);
584
+ props.onChange(snapshot.text);
585
+ }
586
+ function move(cursor, keepGoal = false) {
587
+ state.current.cursor = cursor;
588
+ if (!keepGoal)
589
+ state.current.goalColumn = null;
590
+ }
591
+ function moveRow(step) {
592
+ const target = rows[cursorRow + step];
593
+ if (!target) {
594
+ move(step < 0 ? 0 : value.length);
595
+ return;
596
+ }
597
+ const current = rows[cursorRow];
598
+ const goal = state.current.goalColumn ?? stringWidth(value.slice(current.start, state.current.cursor));
599
+ move(offsetAtColumn(value, target, goal), true);
600
+ state.current.goalColumn = goal;
601
+ }
602
+ function insert(text) {
603
+ const clean = props.singleLine ? text.replace(/\n/g, " ") : text;
604
+ const cursor = state.current.cursor;
605
+ commit(value.slice(0, cursor) + clean + value.slice(cursor), cursor + clean.length, clean.length === 1 && !/\s/.test(clean) ? "type" : "insert");
606
+ }
607
+ function remove(from, to) {
608
+ if (from === to)
609
+ return;
610
+ commit(value.slice(0, from) + value.slice(to), from, "delete");
611
+ }
612
+ useKeys((key) => {
613
+ const cursor = state.current.cursor;
614
+ const row = rows[cursorRow];
615
+ if (key.ctrl && key.name === "z")
616
+ restore(key.shift ? history.current.redo : history.current.undo, key.shift ? history.current.undo : history.current.redo);
617
+ else if (key.ctrl && key.name === "y")
618
+ restore(history.current.redo, history.current.undo);
619
+ else if (key.name === "return") {
620
+ if (props.onSubmit)
621
+ props.onSubmit();
622
+ else if (!props.singleLine)
623
+ insert(`
624
+ `);
625
+ } else if (key.name === "backspace")
626
+ remove(key.meta || key.ctrl ? previousWord(value, cursor) : previousBoundary(value, cursor), cursor);
627
+ else if (key.ctrl && key.name === "w")
628
+ remove(previousWord(value, cursor), cursor);
629
+ else if (key.name === "delete" || key.ctrl && key.name === "d")
630
+ remove(cursor, key.meta || key.ctrl ? nextWord(value, cursor) : nextBoundary(value, cursor));
631
+ else if (key.meta && key.name === "d")
632
+ remove(cursor, nextWord(value, cursor));
633
+ else if (key.ctrl && key.name === "u")
634
+ remove(value.lastIndexOf(`
635
+ `, cursor - 1) + 1, cursor);
636
+ else if (key.ctrl && key.name === "k") {
637
+ const end = value.indexOf(`
638
+ `, cursor);
639
+ remove(cursor, end === -1 ? value.length : end);
640
+ } else if (key.name === "left")
641
+ move(key.ctrl || key.meta ? previousWord(value, cursor) : previousBoundary(value, cursor));
642
+ else if (key.name === "right")
643
+ move(key.ctrl || key.meta ? nextWord(value, cursor) : nextBoundary(value, cursor));
644
+ else if (key.meta && key.name === "b")
645
+ move(previousWord(value, cursor));
646
+ else if (key.meta && key.name === "f")
647
+ move(nextWord(value, cursor));
648
+ else if (key.name === "home" || key.ctrl && key.name === "a")
649
+ move(row.start);
650
+ else if (key.name === "end" || key.ctrl && key.name === "e")
651
+ move(row.end);
652
+ else if (key.name === "up" && !props.singleLine)
653
+ moveRow(-1);
654
+ else if (key.name === "down" && !props.singleLine)
655
+ moveRow(1);
656
+ else if (key.text && !key.ctrl && !key.meta)
657
+ insert(key.text);
658
+ else
659
+ return;
660
+ redraw();
661
+ }, focused);
662
+ const visibleRows = Math.max(height ?? size.height, 1);
663
+ const lastTop = Math.max(rows.length - visibleRows, 0);
664
+ const top = Math.min(Math.max(state.current.top, cursorRow - visibleRows + 1), cursorRow, lastTop);
665
+ state.current.top = Math.max(top, 0);
666
+ const cursorStyle = { color: theme.background, backgroundColor: theme.text };
667
+ const lines = [];
668
+ if (size.width === 0) {} else if (!value) {
669
+ lines.push(/* @__PURE__ */ jsxs2(Text2, {
670
+ wrap: "truncate-end",
671
+ children: [
672
+ focused && /* @__PURE__ */ jsx2(Text2, {
673
+ ...cursorStyle,
674
+ children: " "
675
+ }),
676
+ /* @__PURE__ */ jsx2(Text2, {
677
+ color: theme.faint,
678
+ children: props.placeholder ?? ""
679
+ })
680
+ ]
681
+ }, 0));
682
+ } else {
683
+ for (let index = state.current.top;index < Math.min(state.current.top + visibleRows, rows.length); index++) {
684
+ const row = rows[index];
685
+ const text = value.slice(row.start, row.end);
686
+ if (!focused || index !== cursorRow) {
687
+ lines.push(/* @__PURE__ */ jsx2(Text2, {
688
+ color: theme.text,
689
+ wrap: "truncate-end",
690
+ children: text || " "
691
+ }, index));
692
+ continue;
693
+ }
694
+ const at = state.current.cursor;
695
+ const after = at < row.end ? nextBoundary(value, at) : at;
696
+ lines.push(/* @__PURE__ */ jsxs2(Text2, {
697
+ color: theme.text,
698
+ wrap: "truncate-end",
699
+ children: [
700
+ value.slice(row.start, at),
701
+ /* @__PURE__ */ jsx2(Text2, {
702
+ ...cursorStyle,
703
+ children: at < row.end ? value.slice(at, after) : " "
704
+ }),
705
+ value.slice(after, row.end)
706
+ ]
707
+ }, index));
708
+ }
709
+ }
710
+ return /* @__PURE__ */ jsx2(Box2, {
711
+ ref,
712
+ flexDirection: "column",
713
+ flexGrow: 1,
714
+ height,
715
+ overflow: "hidden",
716
+ children: lines
717
+ });
718
+ }
719
+
720
+ // src/tui/modals.tsx
721
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
722
+ var LIST_ROWS = 8;
723
+ function ModelPicker({ controller: c, theme }) {
724
+ const [query, setQuery] = useState2("");
725
+ const [index, setIndex] = useState2(0);
726
+ const state = c.sessionState();
727
+ const session = state.status === "ready" ? state.session : null;
728
+ const allowed = session ? c.allowedModels(session) : [];
729
+ const words = query.toLowerCase().split(/\s+/).filter(Boolean);
730
+ const matches = allowed.filter((model) => words.every((word) => `${model.name} ${model.id}`.toLowerCase().includes(word)));
731
+ const windowStart = Math.min(Math.max(index - LIST_ROWS + 1, 0), Math.max(matches.length - LIST_ROWS, 0));
732
+ useKeys((key) => {
733
+ if (key.name === "escape")
734
+ c.setModal(null);
735
+ else if (key.name === "up")
736
+ setIndex((value) => Math.max(value - 1, 0));
737
+ else if (key.name === "down")
738
+ setIndex((value) => Math.min(value + 1, Math.max(matches.length - 1, 0)));
739
+ else if (key.name === "return") {
740
+ const model = matches[index];
741
+ if (model)
742
+ c.start(model.id);
743
+ }
744
+ });
745
+ const harnessName = c.harness()?.name ?? "The agent";
746
+ const filter = c.config()?.models;
747
+ let body;
748
+ if (state.status === "starting")
749
+ body = /* @__PURE__ */ jsxs3(Text3, {
750
+ color: theme.muted,
751
+ children: [
752
+ "Starting ",
753
+ harnessName,
754
+ "…"
755
+ ]
756
+ });
757
+ else if (state.status === "failed")
758
+ body = /* @__PURE__ */ jsx3(Text3, {
759
+ color: theme.danger,
760
+ children: state.error
761
+ });
762
+ else if (session && session.models.length === 0)
763
+ body = /* @__PURE__ */ jsxs3(Text3, {
764
+ color: theme.text,
765
+ children: [
766
+ harnessName,
767
+ " doesn't list its models. Use its default model instead."
768
+ ]
769
+ });
770
+ else if (session && allowed.length === 0)
771
+ body = /* @__PURE__ */ jsxs3(Box3, {
772
+ flexDirection: "column",
773
+ gap: 1,
774
+ children: [
775
+ /* @__PURE__ */ jsx3(Text3, {
776
+ color: theme.danger,
777
+ bold: true,
778
+ children: "No models are available"
779
+ }),
780
+ /* @__PURE__ */ jsxs3(Text3, {
781
+ color: theme.text,
782
+ children: [
783
+ "This repo doesn't allow any of ",
784
+ harnessName,
785
+ "'s models. Choose another agent."
786
+ ]
787
+ }),
788
+ filter?.allow?.length ? /* @__PURE__ */ jsxs3(Text3, {
789
+ color: theme.muted,
790
+ children: [
791
+ "Allowed: ",
792
+ filter.allow.join(", ")
793
+ ]
794
+ }) : null,
795
+ filter?.block?.length ? /* @__PURE__ */ jsxs3(Text3, {
796
+ color: theme.muted,
797
+ children: [
798
+ "Blocked: ",
799
+ filter.block.join(", ")
800
+ ]
801
+ }) : null
802
+ ]
803
+ });
804
+ else if (session)
805
+ body = /* @__PURE__ */ jsxs3(Box3, {
806
+ flexDirection: "column",
807
+ gap: 1,
808
+ children: [
809
+ /* @__PURE__ */ jsx3(Panel, {
810
+ borderColor: theme.border,
811
+ backgroundColor: theme.background,
812
+ paddingX: 1,
813
+ height: 3,
814
+ children: /* @__PURE__ */ jsx3(TextArea, {
815
+ value: query,
816
+ onChange: (value) => {
817
+ setQuery(value);
818
+ setIndex(0);
819
+ },
820
+ theme,
821
+ focused: true,
822
+ height: 1,
823
+ singleLine: true,
824
+ placeholder: "Search"
825
+ })
826
+ }),
827
+ /* @__PURE__ */ jsx3(Box3, {
828
+ flexDirection: "column",
829
+ height: LIST_ROWS,
830
+ children: matches.length === 0 ? /* @__PURE__ */ jsxs3(Text3, {
831
+ color: theme.muted,
832
+ children: [
833
+ 'No models match "',
834
+ query,
835
+ '".'
836
+ ]
837
+ }) : matches.slice(windowStart, windowStart + LIST_ROWS).map((model, offset) => {
838
+ const active = windowStart + offset === index;
839
+ const isDefault = model.id === session.currentModel?.id;
840
+ return /* @__PURE__ */ jsxs3(Box3, {
841
+ flexDirection: "row",
842
+ justifyContent: "space-between",
843
+ backgroundColor: active ? theme.focus : theme.background,
844
+ paddingX: 1,
845
+ gap: 2,
846
+ children: [
847
+ /* @__PURE__ */ jsx3(Text3, {
848
+ color: active ? theme.background : theme.text,
849
+ bold: active,
850
+ wrap: "truncate-end",
851
+ children: model.name
852
+ }),
853
+ /* @__PURE__ */ jsx3(Text3, {
854
+ color: active ? theme.background : theme.faint,
855
+ wrap: "truncate-start",
856
+ children: isDefault ? "default" : model.id
857
+ })
858
+ ]
859
+ }, model.id);
860
+ })
861
+ })
862
+ ]
863
+ });
864
+ return /* @__PURE__ */ jsxs3(Modal, {
865
+ theme,
866
+ title: "Select model",
867
+ width: 60,
868
+ children: [
869
+ body,
870
+ /* @__PURE__ */ jsx3(Hints, {
871
+ theme,
872
+ hints: session && allowed.length ? [["↑↓", "choose"], ["enter", "start"], ["esc", "close"]] : [["esc", "close"]]
873
+ })
874
+ ]
875
+ });
876
+ }
877
+ function Confirm({ theme, title, children, buttons, onClose }) {
878
+ const [index, setIndex] = useState2(0);
879
+ useKeys((key) => {
880
+ if (key.name === "escape")
881
+ onClose();
882
+ else if (key.name === "left")
883
+ setIndex((value) => Math.max(value - 1, 0));
884
+ else if (key.name === "right" || key.name === "tab")
885
+ setIndex((value) => Math.min(value + 1, buttons.length - 1));
886
+ else if (key.name === "return")
887
+ buttons[index]?.run();
888
+ });
889
+ return /* @__PURE__ */ jsxs3(Modal, {
890
+ theme,
891
+ title,
892
+ children: [
893
+ /* @__PURE__ */ jsx3(Box3, {
894
+ flexDirection: "column",
895
+ gap: 1,
896
+ children
897
+ }),
898
+ /* @__PURE__ */ jsx3(ButtonRow, {
899
+ theme,
900
+ focused: true,
901
+ index,
902
+ items: buttons.map((button) => ({ label: button.label }))
903
+ })
904
+ ]
905
+ });
906
+ }
907
+ function shorten(url, max = 120) {
908
+ return url.length > max ? `${url.slice(0, max - 1)}…` : url;
909
+ }
910
+ function Modals({ controller: c, theme }) {
911
+ const close = () => c.setModal(null);
912
+ const modal = c.modal();
913
+ if (!modal)
914
+ return null;
915
+ switch (modal.name) {
916
+ case "models":
917
+ return /* @__PURE__ */ jsx3(ModelPicker, {
918
+ controller: c,
919
+ theme
920
+ });
921
+ case "github-confirm":
922
+ return /* @__PURE__ */ jsxs3(Confirm, {
923
+ theme,
924
+ title: "File an issue on GitHub?",
925
+ onClose: close,
926
+ buttons: [
927
+ { label: "File issue", run: () => void c.fileOnGitHub(modal.repo) },
928
+ { label: "Cancel", run: close }
929
+ ],
930
+ children: [
931
+ /* @__PURE__ */ jsxs3(Text3, {
932
+ color: theme.text,
933
+ children: [
934
+ "This runs ",
935
+ /* @__PURE__ */ jsx3(Text3, {
936
+ bold: true,
937
+ children: "gh issue create"
938
+ }),
939
+ " and posts the issue to ",
940
+ /* @__PURE__ */ jsx3(Text3, {
941
+ bold: true,
942
+ children: modal.repo
943
+ }),
944
+ " as ",
945
+ /* @__PURE__ */ jsxs3(Text3, {
946
+ bold: true,
947
+ children: [
948
+ "@",
949
+ modal.login
950
+ ]
951
+ }),
952
+ "."
953
+ ]
954
+ }),
955
+ /* @__PURE__ */ jsx3(Text3, {
956
+ color: theme.muted,
957
+ children: "Issues on public repos can be read by anyone."
958
+ })
959
+ ]
960
+ }, modal.name);
961
+ case "github-signin":
962
+ return /* @__PURE__ */ jsxs3(Confirm, {
963
+ theme,
964
+ title: "Sign in to GitHub",
965
+ onClose: close,
966
+ buttons: [
967
+ { label: "Sign in", run: () => void c.signInToGitHub() },
968
+ { label: "Cancel", run: close }
969
+ ],
970
+ children: [
971
+ /* @__PURE__ */ jsx3(Text3, {
972
+ color: theme.text,
973
+ children: "Filing an issue needs the GitHub CLI signed in."
974
+ }),
975
+ /* @__PURE__ */ jsxs3(Text3, {
976
+ color: theme.muted,
977
+ children: [
978
+ "Sign in hands this terminal to ",
979
+ /* @__PURE__ */ jsx3(Text3, {
980
+ color: theme.text,
981
+ children: "gh auth login"
982
+ }),
983
+ ", which opens GitHub in your browser. You come back here when it's done."
984
+ ]
985
+ })
986
+ ]
987
+ }, modal.name);
988
+ case "github-missing":
989
+ return /* @__PURE__ */ jsx3(Confirm, {
990
+ theme,
991
+ title: "The GitHub CLI isn't installed",
992
+ onClose: close,
993
+ buttons: [
994
+ { label: "Open cli.github.com", run: () => void c.open("https://cli.github.com") },
995
+ { label: "Close", run: close }
996
+ ],
997
+ children: /* @__PURE__ */ jsx3(Text3, {
998
+ color: theme.text,
999
+ children: "Filing an issue uses the GitHub CLI (gh). Install it, then choose File an issue on GitHub again."
1000
+ })
1001
+ }, modal.name);
1002
+ case "filed":
1003
+ return /* @__PURE__ */ jsx3(Confirm, {
1004
+ theme,
1005
+ title: "Issue filed",
1006
+ onClose: close,
1007
+ buttons: [
1008
+ { label: "Open issue", run: () => void c.open(modal.url) },
1009
+ { label: "Done", run: close }
1010
+ ],
1011
+ children: /* @__PURE__ */ jsx3(Text3, {
1012
+ color: theme.text,
1013
+ children: modal.url
1014
+ })
1015
+ }, modal.name);
1016
+ case "link":
1017
+ return /* @__PURE__ */ jsxs3(Confirm, {
1018
+ theme,
1019
+ title: `Open ${modal.link.label}?`,
1020
+ onClose: close,
1021
+ buttons: [
1022
+ { label: "Open link", run: () => void c.open(modal.url) },
1023
+ { label: "Cancel", run: close }
1024
+ ],
1025
+ children: [
1026
+ modal.link.description && /* @__PURE__ */ jsx3(Text3, {
1027
+ color: theme.text,
1028
+ children: modal.link.description
1029
+ }),
1030
+ /* @__PURE__ */ jsx3(Text3, {
1031
+ color: theme.text,
1032
+ children: linkIncludesIssue(modal.link) ? "The link includes the issue's title and text." : "The link doesn't include the issue. Copy it first if you want to paste it there."
1033
+ }),
1034
+ /* @__PURE__ */ jsx3(Text3, {
1035
+ color: theme.muted,
1036
+ children: shorten(modal.url)
1037
+ })
1038
+ ]
1039
+ }, modal.name);
1040
+ }
1041
+ }
1042
+
1043
+ // src/tui/screens/compose.tsx
1044
+ import { Box as Box4, Text as Text4 } from "ink";
1045
+ import { useState as useState3 } from "react";
1046
+
1047
+ // src/tui/wrap.ts
1048
+ import stringWidth2 from "string-width";
1049
+ function wrap(text, width) {
1050
+ const out = [];
1051
+ const limit = Math.max(width, 1);
1052
+ for (const paragraph of text.split(`
1053
+ `)) {
1054
+ if (paragraph === "") {
1055
+ out.push("");
1056
+ continue;
1057
+ }
1058
+ let line = "";
1059
+ let lineWidth = 0;
1060
+ for (const word of paragraph.split(/(\s+)/)) {
1061
+ if (word === "")
1062
+ continue;
1063
+ const wordWidth = stringWidth2(word);
1064
+ if (lineWidth + wordWidth <= limit) {
1065
+ line += word;
1066
+ lineWidth += wordWidth;
1067
+ continue;
1068
+ }
1069
+ if (/^\s+$/.test(word)) {
1070
+ out.push(line);
1071
+ line = "";
1072
+ lineWidth = 0;
1073
+ continue;
1074
+ }
1075
+ if (line.trim())
1076
+ out.push(line.trimEnd());
1077
+ line = "";
1078
+ lineWidth = 0;
1079
+ let rest = word;
1080
+ while (stringWidth2(rest) > limit) {
1081
+ let cut = "";
1082
+ for (const char of rest) {
1083
+ if (stringWidth2(cut + char) > limit)
1084
+ break;
1085
+ cut += char;
1086
+ }
1087
+ out.push(cut);
1088
+ rest = rest.slice(cut.length);
1089
+ }
1090
+ line = rest;
1091
+ lineWidth = stringWidth2(rest);
1092
+ }
1093
+ out.push(line.trimEnd());
1094
+ }
1095
+ return out;
1096
+ }
1097
+
1098
+ // src/tui/screens/compose.tsx
1099
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
1100
+ var ZONES = ["input", "agents", "model"];
1101
+ var MAX_ROWS = 3;
1102
+ var CHIP_GAP = 1;
1103
+ var INPUT_ROWS = { min: 3, max: 12 };
1104
+ function chipRows(names, width) {
1105
+ const out = [];
1106
+ let row = [];
1107
+ let used = 0;
1108
+ names.forEach((name, index) => {
1109
+ const chip = name.length + 2;
1110
+ if (row.length && used + CHIP_GAP + chip > width) {
1111
+ out.push(row);
1112
+ row = [];
1113
+ used = 0;
1114
+ }
1115
+ used += (row.length ? CHIP_GAP : 0) + chip;
1116
+ row.push(index);
1117
+ });
1118
+ if (row.length)
1119
+ out.push(row);
1120
+ return out;
1121
+ }
1122
+ function ComposeScreen({ controller: c, theme, product, detail }) {
1123
+ const frame = useFrameSize();
1124
+ const [zone, setZone] = useState3("input");
1125
+ const [modelIndex, setModelIndex] = useState3(0);
1126
+ const hasAgents = c.harnesses.length > 0;
1127
+ const rows = chipRows(c.harnesses.map((harness) => harness.name), frame.width);
1128
+ const rowOf = (index) => rows.findIndex((row) => row.includes(index));
1129
+ const current = Math.max(rowOf(c.harnessIndex()), 0);
1130
+ const first = Math.min(Math.max(current - MAX_ROWS + 1, 0), Math.max(rows.length - MAX_ROWS, 0));
1131
+ const visible = rows.slice(first, first + MAX_ROWS);
1132
+ const hidden = rows.length - visible.length;
1133
+ function moveZone(step) {
1134
+ const available = hasAgents ? ZONES : ["input"];
1135
+ const next = available[(available.indexOf(zone) + step + available.length) % available.length];
1136
+ setZone(next);
1137
+ if (next === "model")
1138
+ c.prepareSession();
1139
+ }
1140
+ function moveHarness(dx, dy) {
1141
+ const index = c.harnessIndex();
1142
+ if (dx) {
1143
+ c.selectHarness(Math.min(Math.max(index + dx, 0), c.harnesses.length - 1));
1144
+ return;
1145
+ }
1146
+ const rowIndex = rowOf(index);
1147
+ const target = rows[rowIndex + dy];
1148
+ if (!target)
1149
+ return;
1150
+ const column = rows[rowIndex].indexOf(index);
1151
+ c.selectHarness(target[Math.min(column, target.length - 1)]);
1152
+ }
1153
+ async function chooseModelOption() {
1154
+ if (modelIndex === 0) {
1155
+ await c.start(null);
1156
+ return;
1157
+ }
1158
+ c.setModal({ name: "models" });
1159
+ c.prepareSession();
1160
+ }
1161
+ useKeys((key) => {
1162
+ if (c.modal() || c.screen() !== "compose")
1163
+ return;
1164
+ if (key.name === "tab") {
1165
+ moveZone(key.shift ? -1 : 1);
1166
+ return;
1167
+ }
1168
+ if (zone === "agents") {
1169
+ if (key.name === "left")
1170
+ moveHarness(-1, 0);
1171
+ else if (key.name === "right")
1172
+ moveHarness(1, 0);
1173
+ else if (key.name === "up")
1174
+ moveHarness(0, -1);
1175
+ else if (key.name === "down")
1176
+ moveHarness(0, 1);
1177
+ else if (key.name === "return")
1178
+ moveZone(1);
1179
+ } else if (zone === "model") {
1180
+ if (key.name === "left" || key.name === "right")
1181
+ setModelIndex(key.name === "left" ? 0 : 1);
1182
+ else if (key.name === "return")
1183
+ chooseModelOption();
1184
+ }
1185
+ });
1186
+ const sessionLine = (() => {
1187
+ const state = c.sessionState();
1188
+ const harness = c.harness();
1189
+ if (!harness || state.status === "idle")
1190
+ return null;
1191
+ if (state.status === "starting")
1192
+ return { text: `Starting ${harness.name}…`, color: theme.muted };
1193
+ if (state.status === "failed")
1194
+ return { text: state.error, color: theme.danger };
1195
+ const model = state.session.currentModel;
1196
+ return { text: model ? `${harness.name} is ready. Its default model is ${model.name}.` : `${harness.name} is ready.`, color: theme.muted };
1197
+ })();
1198
+ const hints = zone === "input" ? [["tab", "next"], ["enter", "new line"], ["ctrl+c", "quit"]] : zone === "agents" ? [["←→↑↓", "choose agent"], ["tab", "next"], ["shift+tab", "back"], ["ctrl+c", "quit"]] : [["←→", "choose"], ["enter", modelIndex === 0 ? "start" : "select model"], ["shift+tab", "back"], ["ctrl+c", "quit"]];
1199
+ const noAgents = "No coding agents are installed. Install Claude Code, Codex, Cursor, Grok, OpenCode, or another ACP agent, then run this again.";
1200
+ const prompt = c.config()?.prompt ?? "Explain the issue you're experiencing";
1201
+ const promptRows = wrap(prompt, frame.width).length;
1202
+ const agentRows = 2 + (hasAgents ? visible.length + (hidden > 0 ? 1 : 0) : wrap(noAgents, frame.width).length);
1203
+ const modelRows = hasAgents ? 3 + 2 : 0;
1204
+ const gaps = hasAgents ? 4 : 3;
1205
+ const free = frame.height - 1 - gaps - promptRows - 1 - agentRows - modelRows - 1;
1206
+ const inputRows = Math.min(Math.max(free, INPUT_ROWS.min), INPUT_ROWS.max);
1207
+ return /* @__PURE__ */ jsxs4(Box4, {
1208
+ flexDirection: "column",
1209
+ flexGrow: 1,
1210
+ gap: 1,
1211
+ children: [
1212
+ /* @__PURE__ */ jsx4(Header, {
1213
+ theme,
1214
+ product,
1215
+ detail
1216
+ }),
1217
+ /* @__PURE__ */ jsxs4(Box4, {
1218
+ flexDirection: "column",
1219
+ flexShrink: 0,
1220
+ children: [
1221
+ /* @__PURE__ */ jsx4(Text4, {
1222
+ color: theme.text,
1223
+ bold: true,
1224
+ children: prompt
1225
+ }),
1226
+ /* @__PURE__ */ jsx4(Panel, {
1227
+ borderColor: zone === "input" ? theme.border : theme.faint,
1228
+ backgroundColor: theme.background,
1229
+ height: inputRows,
1230
+ marginTop: 1,
1231
+ paddingX: 1,
1232
+ children: /* @__PURE__ */ jsx4(TextArea, {
1233
+ value: c.issueText(),
1234
+ onChange: c.setIssueText,
1235
+ theme,
1236
+ focused: zone === "input" && !c.modal(),
1237
+ height: Math.max(inputRows - 2, 1),
1238
+ placeholder: "What went wrong, and what did you expect to happen?"
1239
+ })
1240
+ })
1241
+ ]
1242
+ }),
1243
+ /* @__PURE__ */ jsxs4(Box4, {
1244
+ flexDirection: "column",
1245
+ flexShrink: 0,
1246
+ children: [
1247
+ /* @__PURE__ */ jsx4(Text4, {
1248
+ color: zone === "agents" ? theme.text : theme.muted,
1249
+ bold: true,
1250
+ children: "Agent"
1251
+ }),
1252
+ hasAgents ? /* @__PURE__ */ jsxs4(Box4, {
1253
+ flexDirection: "column",
1254
+ marginTop: 1,
1255
+ children: [
1256
+ visible.map((row) => /* @__PURE__ */ jsx4(Box4, {
1257
+ flexDirection: "row",
1258
+ columnGap: CHIP_GAP,
1259
+ children: row.map((index) => /* @__PURE__ */ jsx4(BrandLabel, {
1260
+ name: c.harnesses[index].name,
1261
+ brand: c.harnesses[index].brand,
1262
+ selected: index === c.harnessIndex(),
1263
+ theme
1264
+ }, index))
1265
+ }, row[0])),
1266
+ hidden > 0 && /* @__PURE__ */ jsxs4(Text4, {
1267
+ color: theme.faint,
1268
+ children: [
1269
+ first > 0 ? "↑ " : "",
1270
+ first + MAX_ROWS < rows.length ? "↓ " : "",
1271
+ "more agents"
1272
+ ]
1273
+ })
1274
+ ]
1275
+ }) : /* @__PURE__ */ jsx4(Box4, {
1276
+ marginTop: 1,
1277
+ children: /* @__PURE__ */ jsx4(Text4, {
1278
+ color: theme.danger,
1279
+ children: noAgents
1280
+ })
1281
+ })
1282
+ ]
1283
+ }),
1284
+ hasAgents && /* @__PURE__ */ jsxs4(Box4, {
1285
+ flexDirection: "column",
1286
+ flexShrink: 0,
1287
+ children: [
1288
+ /* @__PURE__ */ jsx4(Text4, {
1289
+ color: zone === "model" ? theme.text : theme.muted,
1290
+ bold: true,
1291
+ children: "Model"
1292
+ }),
1293
+ /* @__PURE__ */ jsx4(Box4, {
1294
+ marginTop: 1,
1295
+ children: /* @__PURE__ */ jsx4(ButtonRow, {
1296
+ theme,
1297
+ focused: zone === "model" && !c.modal(),
1298
+ index: modelIndex,
1299
+ items: [{ label: "Use default model", prefix: { text: "✓", color: theme.check } }, { label: "Select model" }]
1300
+ })
1301
+ }),
1302
+ /* @__PURE__ */ jsx4(Box4, {
1303
+ marginTop: 1,
1304
+ children: /* @__PURE__ */ jsx4(Text4, {
1305
+ color: sessionLine?.color ?? theme.muted,
1306
+ wrap: "truncate-end",
1307
+ children: sessionLine?.text ?? " "
1308
+ })
1309
+ })
1310
+ ]
1311
+ }),
1312
+ /* @__PURE__ */ jsx4(Box4, {
1313
+ flexGrow: 1,
1314
+ flexDirection: "column",
1315
+ justifyContent: "flex-end",
1316
+ children: /* @__PURE__ */ jsx4(Hints, {
1317
+ theme,
1318
+ hints
1319
+ })
1320
+ })
1321
+ ]
1322
+ });
1323
+ }
1324
+
1325
+ // src/tui/screens/result.tsx
1326
+ import { Box as Box5, Text as Text5 } from "ink";
1327
+ import { useState as useState4 } from "react";
1328
+
1329
+ // src/tui/markdown.ts
1330
+ import { Lexer } from "marked";
1331
+ import stringWidth3 from "string-width";
1332
+ function wrapSegments(segments, width, indent = [], first = indent) {
1333
+ const lines = [];
1334
+ const cellsOf = (line) => line.reduce((sum, segment) => sum + stringWidth3(segment.text), 0);
1335
+ let line = first.map((segment) => ({ ...segment }));
1336
+ let used = cellsOf(line);
1337
+ let hasText = false;
1338
+ const limit = (prefix) => Math.max(width, prefix + 1);
1339
+ const push = (text, style) => {
1340
+ const last = line[line.length - 1];
1341
+ if (last && last.color === style.color && last.bold === style.bold && last.italic === style.italic && last.underline === style.underline && last.background === style.background)
1342
+ last.text += text;
1343
+ else
1344
+ line.push({ ...style, text });
1345
+ used += stringWidth3(text);
1346
+ hasText = true;
1347
+ };
1348
+ const breakLine = () => {
1349
+ const end = line[line.length - 1];
1350
+ if (end)
1351
+ end.text = end.text.trimEnd();
1352
+ lines.push(line.filter((segment) => segment.text));
1353
+ line = indent.map((segment) => ({ ...segment }));
1354
+ used = cellsOf(line);
1355
+ hasText = false;
1356
+ };
1357
+ for (const segment of segments) {
1358
+ const style = { ...segment };
1359
+ delete style.text;
1360
+ for (const piece of segment.text.split(/(\n|\s+)/)) {
1361
+ if (!piece)
1362
+ continue;
1363
+ if (piece === `
1364
+ `) {
1365
+ breakLine();
1366
+ continue;
1367
+ }
1368
+ const cells = stringWidth3(piece);
1369
+ if (/^\s+$/.test(piece)) {
1370
+ if (hasText && used + cells <= limit(cellsOf(indent)))
1371
+ push(piece, style);
1372
+ continue;
1373
+ }
1374
+ if (used + cells > limit(cellsOf(indent)) && hasText)
1375
+ breakLine();
1376
+ let rest = piece;
1377
+ while (used + stringWidth3(rest) > limit(cellsOf(indent))) {
1378
+ let cut = "";
1379
+ for (const char of rest) {
1380
+ if (used + stringWidth3(cut + char) > limit(cellsOf(indent)))
1381
+ break;
1382
+ cut += char;
1383
+ }
1384
+ if (!cut)
1385
+ break;
1386
+ push(cut, style);
1387
+ rest = rest.slice(cut.length);
1388
+ breakLine();
1389
+ }
1390
+ if (rest)
1391
+ push(rest, style);
1392
+ }
1393
+ }
1394
+ if (hasText || lines.length === 0)
1395
+ breakLine();
1396
+ return lines;
1397
+ }
1398
+ function inline(tokens, style, theme) {
1399
+ const out = [];
1400
+ const code = theme.product === theme.text ? theme.muted : theme.product;
1401
+ for (const token of tokens ?? []) {
1402
+ switch (token.type) {
1403
+ case "strong":
1404
+ out.push(...inline(token.tokens, { ...style, bold: true }, theme));
1405
+ break;
1406
+ case "em":
1407
+ out.push(...inline(token.tokens, { ...style, italic: true }, theme));
1408
+ break;
1409
+ case "del":
1410
+ out.push(...inline(token.tokens, { ...style, color: theme.muted }, theme));
1411
+ break;
1412
+ case "codespan":
1413
+ out.push({ ...style, color: code, text: decode(token.text) });
1414
+ break;
1415
+ case "br":
1416
+ out.push({ ...style, text: `
1417
+ ` });
1418
+ break;
1419
+ case "link": {
1420
+ const link = token;
1421
+ const label = inline(link.tokens, { ...style, underline: true }, theme);
1422
+ const labelText = label.map((segment) => segment.text).join("");
1423
+ if (labelText === link.href || `mailto:${labelText}` === link.href)
1424
+ out.push({ ...style, color: theme.muted, underline: true, text: labelText });
1425
+ else
1426
+ out.push(...label, { ...style, color: theme.muted, text: ` (${link.href})` });
1427
+ break;
1428
+ }
1429
+ case "image":
1430
+ out.push({ ...style, color: theme.muted, text: `[${token.text || "image"}] (${token.href})` });
1431
+ break;
1432
+ case "text":
1433
+ if ("tokens" in token && token.tokens?.length)
1434
+ out.push(...inline(token.tokens, style, theme));
1435
+ else
1436
+ out.push({ ...style, text: decode(token.text) });
1437
+ break;
1438
+ case "escape":
1439
+ out.push({ ...style, text: token.text });
1440
+ break;
1441
+ default:
1442
+ out.push({ ...style, text: "raw" in token ? decode(String(token.raw)) : "" });
1443
+ }
1444
+ }
1445
+ return out;
1446
+ }
1447
+ var ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', "#39": "'", nbsp: " " };
1448
+ function decode(text) {
1449
+ return text.replace(/&(amp|lt|gt|quot|#39|nbsp);/g, (_, name) => ENTITIES[name]);
1450
+ }
1451
+ function dropCells(line, cells) {
1452
+ let left = cells;
1453
+ const out = [];
1454
+ for (const segment of line) {
1455
+ if (left <= 0) {
1456
+ out.push(segment);
1457
+ continue;
1458
+ }
1459
+ const chars = [...segment.text];
1460
+ let cut = 0;
1461
+ while (cut < chars.length && left > 0)
1462
+ left -= stringWidth3(chars[cut++]);
1463
+ const rest = chars.slice(cut).join("");
1464
+ if (rest)
1465
+ out.push({ ...segment, text: rest });
1466
+ }
1467
+ return out;
1468
+ }
1469
+ function blocks(tokens, width, theme, indent) {
1470
+ const out = [];
1471
+ const text = { color: theme.text };
1472
+ const gap = () => {
1473
+ if (out.length && out[out.length - 1].some((segment) => segment.text.trim()))
1474
+ out.push([...indent]);
1475
+ };
1476
+ for (const token of tokens) {
1477
+ switch (token.type) {
1478
+ case "space":
1479
+ break;
1480
+ case "heading":
1481
+ gap();
1482
+ out.push(...wrapSegments(inline(token.tokens, { ...text, bold: true }, theme), width, indent));
1483
+ break;
1484
+ case "paragraph":
1485
+ gap();
1486
+ out.push(...wrapSegments(inline(token.tokens, text, theme), width, indent));
1487
+ break;
1488
+ case "text":
1489
+ out.push(...wrapSegments(inline(token.tokens ?? [{ type: "text", raw: token.text, text: token.text }], text, theme), width, indent));
1490
+ break;
1491
+ case "code":
1492
+ gap();
1493
+ for (const row of token.text.split(`
1494
+ `))
1495
+ out.push([...indent, { color: theme.muted, text: ` ${row}` }]);
1496
+ break;
1497
+ case "blockquote": {
1498
+ gap();
1499
+ const bar = [...indent, { color: theme.faint, text: "│ " }];
1500
+ const quoted = blocks(token.tokens, width, { ...theme, text: theme.muted }, bar);
1501
+ out.push(...quoted.map((line) => line.map((segment) => segment.text === "│ " ? segment : { ...segment, italic: true })));
1502
+ break;
1503
+ }
1504
+ case "list": {
1505
+ gap();
1506
+ const list = token;
1507
+ const start = typeof list.start === "number" ? list.start : 1;
1508
+ list.items.forEach((item, index) => {
1509
+ const bullet = list.ordered ? `${start + index}. ` : item.task ? item.checked ? "[x] " : "[ ] " : "- ";
1510
+ const hang = [...indent, { color: theme.text, text: " ".repeat(stringWidth3(bullet)) }];
1511
+ const lines = blocks(item.tokens.filter((child) => child.type !== "checkbox"), width, theme, hang);
1512
+ if (lines[0])
1513
+ lines[0] = [...indent, { color: theme.muted, text: bullet }, ...dropCells(lines[0], stringWidth3(hang.map((segment) => segment.text).join("")))];
1514
+ out.push(...list.loose ? lines : lines.filter((line) => line.some((segment) => segment.text.trim())));
1515
+ });
1516
+ break;
1517
+ }
1518
+ case "hr":
1519
+ gap();
1520
+ out.push([...indent, { color: theme.faint, text: "─".repeat(Math.max(width - stringWidth3(indent.map((segment) => segment.text).join("")), 1)) }]);
1521
+ break;
1522
+ case "table": {
1523
+ gap();
1524
+ for (const row of token.raw.trimEnd().split(`
1525
+ `))
1526
+ out.push([...indent, { color: theme.muted, text: row }]);
1527
+ break;
1528
+ }
1529
+ default:
1530
+ if (token.raw.trim()) {
1531
+ gap();
1532
+ out.push(...wrapSegments([{ ...text, text: decode(token.raw.trim()) }], width, indent));
1533
+ }
1534
+ }
1535
+ }
1536
+ return out;
1537
+ }
1538
+ function renderMarkdown(markdown, width, theme) {
1539
+ return blocks(new Lexer({ gfm: true }).lex(markdown), width, theme, []);
1540
+ }
1541
+
1542
+ // src/tui/screens/result.tsx
1543
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
1544
+ function ResultScreen({ controller: c, theme, product, detail, onQuit }) {
1545
+ const [index, setIndex] = useState4(0);
1546
+ const [scroll, setScroll] = useState4(0);
1547
+ const [ref, size] = useMeasure();
1548
+ const actions = [];
1549
+ if (c.githubRepo())
1550
+ actions.push({ label: "File an issue on GitHub", run: () => void c.beginGitHub() });
1551
+ actions.push({ label: "Copy issue", run: () => void c.copy() });
1552
+ for (const link of c.config()?.links ?? [])
1553
+ actions.push({ label: link.label, run: () => c.chooseLink(link) });
1554
+ actions.push({ label: "Quit", run: onQuit });
1555
+ const issue = c.issue();
1556
+ const width = Math.max(size.width, 1);
1557
+ const lines = issue ? [...wrapSegments([{ text: issue.title, color: theme.text, bold: true }], width), [], ...renderMarkdown(issue.body, width, theme)] : [];
1558
+ const page = Math.max(size.height, 1);
1559
+ const maxScroll = Math.max(lines.length - page, 0);
1560
+ const top = Math.min(scroll, maxScroll);
1561
+ useKeys((key) => {
1562
+ if (c.modal() || c.screen() !== "result" || c.busy())
1563
+ return;
1564
+ const scrollBy = (rows) => setScroll(Math.min(Math.max(top + rows, 0), maxScroll));
1565
+ if (key.name === "left")
1566
+ setIndex((value) => Math.max(value - 1, 0));
1567
+ else if (key.name === "right" || key.name === "tab")
1568
+ setIndex((value) => Math.min(value + 1, actions.length - 1));
1569
+ else if (key.name === "up")
1570
+ scrollBy(-1);
1571
+ else if (key.name === "down")
1572
+ scrollBy(1);
1573
+ else if (key.name === "pageup")
1574
+ scrollBy(-(page - 2));
1575
+ else if (key.name === "pagedown" || key.name === "space")
1576
+ scrollBy(page - 2);
1577
+ else if (key.name === "home")
1578
+ scrollBy(-lines.length);
1579
+ else if (key.name === "end")
1580
+ scrollBy(lines.length);
1581
+ else if (key.name === "return")
1582
+ actions[index]?.run();
1583
+ });
1584
+ const busy = c.busy();
1585
+ return /* @__PURE__ */ jsxs5(Box5, {
1586
+ flexDirection: "column",
1587
+ flexGrow: 1,
1588
+ gap: 1,
1589
+ children: [
1590
+ /* @__PURE__ */ jsx5(Header, {
1591
+ theme,
1592
+ product,
1593
+ detail
1594
+ }),
1595
+ /* @__PURE__ */ jsx5(Text5, {
1596
+ color: theme.success,
1597
+ bold: true,
1598
+ children: "✓ Issue ready"
1599
+ }),
1600
+ /* @__PURE__ */ jsx5(Panel, {
1601
+ borderColor: theme.faint,
1602
+ backgroundColor: theme.background,
1603
+ flexGrow: 1,
1604
+ paddingX: 2,
1605
+ paddingY: 1,
1606
+ children: /* @__PURE__ */ jsx5(Box5, {
1607
+ ref,
1608
+ flexGrow: 1,
1609
+ flexDirection: "column",
1610
+ overflow: "hidden",
1611
+ children: size.height > 0 && /* @__PURE__ */ jsx5(Lines, {
1612
+ lines: lines.slice(top, top + page)
1613
+ })
1614
+ })
1615
+ }),
1616
+ /* @__PURE__ */ jsx5(ButtonRow, {
1617
+ theme,
1618
+ focused: !c.modal(),
1619
+ index,
1620
+ items: actions.map((action) => ({ label: action.label }))
1621
+ }),
1622
+ busy ? /* @__PURE__ */ jsx5(Text5, {
1623
+ color: theme.muted,
1624
+ children: busy
1625
+ }) : /* @__PURE__ */ jsx5(Hints, {
1626
+ theme,
1627
+ hints: maxScroll > 0 ? [["←→", "choose"], ["enter", "select"], ["↑↓", "scroll"], ["ctrl+c", "quit"]] : [["←→", "choose"], ["enter", "select"], ["ctrl+c", "quit"]]
1628
+ })
1629
+ ]
1630
+ });
1631
+ }
1632
+ function ErrorScreen({ controller: c, theme, product, detail, onQuit }) {
1633
+ const [index, setIndex] = useState4(0);
1634
+ const actions = [
1635
+ { label: "Try again", run: () => c.tryAgain() },
1636
+ { label: "Quit", run: onQuit }
1637
+ ];
1638
+ useKeys((key) => {
1639
+ if (c.modal() || c.screen() !== "error")
1640
+ return;
1641
+ if (key.name === "left")
1642
+ setIndex(0);
1643
+ else if (key.name === "right" || key.name === "tab")
1644
+ setIndex(1);
1645
+ else if (key.name === "return")
1646
+ actions[index].run();
1647
+ });
1648
+ return /* @__PURE__ */ jsxs5(Box5, {
1649
+ flexDirection: "column",
1650
+ flexGrow: 1,
1651
+ gap: 1,
1652
+ children: [
1653
+ /* @__PURE__ */ jsx5(Header, {
1654
+ theme,
1655
+ product,
1656
+ detail
1657
+ }),
1658
+ /* @__PURE__ */ jsxs5(Box5, {
1659
+ flexDirection: "column",
1660
+ flexGrow: 1,
1661
+ gap: 1,
1662
+ children: [
1663
+ /* @__PURE__ */ jsxs5(Text5, {
1664
+ color: theme.danger,
1665
+ bold: true,
1666
+ children: [
1667
+ "⚠ ",
1668
+ c.error()?.title ?? "Error"
1669
+ ]
1670
+ }),
1671
+ /* @__PURE__ */ jsx5(Text5, {
1672
+ color: theme.text,
1673
+ children: c.error()?.message
1674
+ })
1675
+ ]
1676
+ }),
1677
+ /* @__PURE__ */ jsx5(ButtonRow, {
1678
+ theme,
1679
+ focused: true,
1680
+ index,
1681
+ items: actions.map((action) => ({ label: action.label }))
1682
+ }),
1683
+ /* @__PURE__ */ jsx5(Hints, {
1684
+ theme,
1685
+ hints: [["←→", "choose"], ["enter", "select"], ["ctrl+c", "quit"]]
1686
+ })
1687
+ ]
1688
+ });
1689
+ }
1690
+
1691
+ // src/tui/screens/running.tsx
1692
+ import { Box as Box6 } from "ink";
1693
+ import { useEffect as useEffect3, useState as useState5 } from "react";
1694
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
1695
+ var ISSUE_MARKER = /<trissue-(issue|rejected)>[\s\S]*$/;
1696
+ var BRIGHT_SHARE = 0.35;
1697
+ var TOP_BRIGHTNESS = 0.18;
1698
+ function entryLines(entry, width, theme) {
1699
+ switch (entry.kind) {
1700
+ case "thought":
1701
+ return wrap(entry.text.trim(), width - 2).map((line) => [{ text: ` ${line}`, color: theme.muted, italic: true }]);
1702
+ case "message": {
1703
+ const visible = entry.text.replace(ISSUE_MARKER, "").trim();
1704
+ const lines = visible ? wrap(visible, width).map((line) => [{ text: line, color: theme.text }]) : [];
1705
+ if (ISSUE_MARKER.test(entry.text))
1706
+ lines.push([{ text: "Writing the issue…", color: theme.text, bold: true }]);
1707
+ return lines;
1708
+ }
1709
+ case "tool": {
1710
+ const glyph = entry.status === "completed" ? "✓" : entry.status === "failed" ? "✗" : "›";
1711
+ const glyphColor = entry.status === "completed" ? theme.success : entry.status === "failed" ? theme.danger : theme.muted;
1712
+ return wrap(entry.text, width - 2).map((line, index) => [
1713
+ { text: index === 0 ? `${glyph} ` : " ", color: glyphColor },
1714
+ { text: line, color: theme.muted }
1715
+ ]);
1716
+ }
1717
+ case "blocked":
1718
+ return wrap(entry.text, width - 10).map((line, index) => [
1719
+ { text: index === 0 ? "⊘ Blocked " : " ", color: theme.danger, bold: true },
1720
+ { text: line, color: theme.muted }
1721
+ ]);
1722
+ case "steer":
1723
+ return wrap(entry.text, width - 6).map((line, index) => [
1724
+ { text: index === 0 ? "You › " : " ", color: theme.product, bold: true },
1725
+ { text: line, color: theme.text }
1726
+ ]);
1727
+ case "notice":
1728
+ return wrap(entry.text, width).map((line) => [{ text: line, color: theme.muted }]);
1729
+ }
1730
+ }
1731
+ function transcriptLines(entries, width, theme) {
1732
+ const lines = [];
1733
+ let previous;
1734
+ for (const entry of entries) {
1735
+ const next = entryLines(entry, width, theme);
1736
+ if (!next.length)
1737
+ continue;
1738
+ const together = previous && (previous.kind === "tool" || previous.kind === "blocked") && (entry.kind === "tool" || entry.kind === "blocked");
1739
+ if (previous && !together)
1740
+ lines.push([]);
1741
+ lines.push(...next);
1742
+ previous = entry;
1743
+ }
1744
+ return lines;
1745
+ }
1746
+ function formatElapsed(ms) {
1747
+ const seconds = Math.floor(ms / 1000);
1748
+ return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
1749
+ }
1750
+ function RunningScreen({ controller: c, theme, product, detail }) {
1751
+ const [ref, size] = useMeasure();
1752
+ const [frame, setFrame] = useState5(0);
1753
+ const [steerText, setSteerText] = useState5("");
1754
+ useEffect3(() => {
1755
+ const timer = setInterval(() => setFrame((value) => value + 1), 80);
1756
+ return () => clearInterval(timer);
1757
+ }, []);
1758
+ useKeys((key) => {
1759
+ if (c.screen() === "running" && !c.modal() && key.name === "escape")
1760
+ c.stop();
1761
+ });
1762
+ const width = Math.max(size.width, 10);
1763
+ const height = Math.max(size.height, 1);
1764
+ const lines = transcriptLines(c.entries(), width, theme).slice(-height);
1765
+ const bright = Math.ceil(height * BRIGHT_SHARE);
1766
+ const faded = lines.map((line, index) => {
1767
+ const fromBottom = lines.length - 1 - index;
1768
+ const fade = fromBottom < bright ? 1 : Math.max(TOP_BRIGHTNESS, 1 - (fromBottom - bright) / Math.max(height - bright, 1) * (1 - TOP_BRIGHTNESS));
1769
+ return line.map((segment) => ({ ...segment, color: mix(theme.background, segment.color, fade) }));
1770
+ });
1771
+ const state = c.sessionState();
1772
+ const name = state.status === "ready" ? state.session.harness.name : c.harness()?.name ?? "The agent";
1773
+ const model = state.status === "ready" ? state.session.currentModel?.name : undefined;
1774
+ const status = `${name}${model ? ` · ${model}` : ""} is investigating · ${formatElapsed(Date.now() - c.startedAt())}`;
1775
+ return /* @__PURE__ */ jsxs6(Box6, {
1776
+ flexDirection: "column",
1777
+ flexGrow: 1,
1778
+ gap: 1,
1779
+ children: [
1780
+ /* @__PURE__ */ jsx6(Header, {
1781
+ theme,
1782
+ product,
1783
+ detail
1784
+ }),
1785
+ /* @__PURE__ */ jsx6(Box6, {
1786
+ ref,
1787
+ flexGrow: 1,
1788
+ flexDirection: "column",
1789
+ justifyContent: "flex-end",
1790
+ overflow: "hidden",
1791
+ children: size.height > 0 && /* @__PURE__ */ jsx6(Lines, {
1792
+ lines: faded
1793
+ })
1794
+ }),
1795
+ /* @__PURE__ */ jsxs6(Box6, {
1796
+ flexDirection: "column",
1797
+ flexShrink: 0,
1798
+ children: [
1799
+ /* @__PURE__ */ jsx6(Spinner, {
1800
+ theme,
1801
+ frame,
1802
+ label: status
1803
+ }),
1804
+ /* @__PURE__ */ jsx6(Panel, {
1805
+ borderColor: theme.border,
1806
+ backgroundColor: theme.background,
1807
+ paddingX: 1,
1808
+ marginTop: 1,
1809
+ height: 3,
1810
+ children: /* @__PURE__ */ jsx6(TextArea, {
1811
+ value: steerText,
1812
+ onChange: setSteerText,
1813
+ theme,
1814
+ focused: !c.modal(),
1815
+ height: 1,
1816
+ singleLine: true,
1817
+ placeholder: "Steer the model or press esc to stop...",
1818
+ onSubmit: () => {
1819
+ if (!steerText.trim())
1820
+ return;
1821
+ c.steer(steerText);
1822
+ setSteerText("");
1823
+ }
1824
+ })
1825
+ })
1826
+ ]
1827
+ }),
1828
+ /* @__PURE__ */ jsx6(Hints, {
1829
+ theme,
1830
+ hints: [["enter", "steer"], ["esc", "stop"]]
1831
+ })
1832
+ ]
1833
+ });
1834
+ }
1835
+
1836
+ // src/tui/screens/trust.tsx
1837
+ import { Box as Box7, Text as Text6 } from "ink";
1838
+ import { CONFIG_FILE } from "trissue-embedded";
1839
+ import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
1840
+ function TrustScreen({ controller: c, onQuit }) {
1841
+ const theme = BASE_THEME;
1842
+ const source = c.options.source;
1843
+ const ready = c.fetched() !== null;
1844
+ const error = c.fetchError();
1845
+ useKeys((key) => {
1846
+ if (key.name === "escape" || key.name === "q")
1847
+ onQuit();
1848
+ else if (key.name === "return" && ready)
1849
+ c.setScreen("compose");
1850
+ });
1851
+ const row = (label, value) => /* @__PURE__ */ jsxs7(Text6, {
1852
+ children: [
1853
+ /* @__PURE__ */ jsxs7(Text6, {
1854
+ color: theme.text,
1855
+ bold: true,
1856
+ children: [
1857
+ label,
1858
+ ":",
1859
+ " "
1860
+ ]
1861
+ }),
1862
+ /* @__PURE__ */ jsx7(Text6, {
1863
+ color: theme.text,
1864
+ children: value
1865
+ })
1866
+ ]
1867
+ });
1868
+ let status;
1869
+ if (error)
1870
+ status = [error, theme.danger];
1871
+ else if (!ready)
1872
+ status = ["Downloading the repo…", theme.muted];
1873
+ else if (c.config())
1874
+ status = [`This repo has a ${CONFIG_FILE}. Its instructions go to the agent, which checks them for anything malicious before following them.`, theme.muted];
1875
+ else
1876
+ status = ["This repo has no trissue configuration, so the defaults are used. Only continue if you trust it.", theme.muted];
1877
+ return /* @__PURE__ */ jsxs7(Box7, {
1878
+ flexDirection: "column",
1879
+ flexGrow: 1,
1880
+ justifyContent: "space-between",
1881
+ children: [
1882
+ /* @__PURE__ */ jsxs7(Box7, {
1883
+ flexDirection: "column",
1884
+ gap: 1,
1885
+ children: [
1886
+ /* @__PURE__ */ jsx7(Text6, {
1887
+ color: theme.danger,
1888
+ bold: true,
1889
+ children: "This command can prompt an AI agent on your computer. Be sure you trust this repo before running this command."
1890
+ }),
1891
+ /* @__PURE__ */ jsxs7(Box7, {
1892
+ flexDirection: "column",
1893
+ children: [
1894
+ row("Repo Organization", source.org || "None"),
1895
+ row("Repo Name", source.name),
1896
+ row(source.kind === "local" ? "Opened From" : "Downloaded From", source.kind === "local" ? `${source.origin} (${source.url})` : source.origin)
1897
+ ]
1898
+ }),
1899
+ /* @__PURE__ */ jsx7(Text6, {
1900
+ color: status[1],
1901
+ children: status[0]
1902
+ })
1903
+ ]
1904
+ }),
1905
+ /* @__PURE__ */ jsx7(Hints, {
1906
+ theme,
1907
+ hints: ready ? [["enter", "continue"], ["esc", "quit"]] : [["esc", "quit"]]
1908
+ })
1909
+ ]
1910
+ });
1911
+ }
1912
+
1913
+ // src/tui/store.ts
1914
+ import { useSyncExternalStore } from "react";
1915
+
1916
+ class Store {
1917
+ #listeners = new Set;
1918
+ #version = 0;
1919
+ #queued = false;
1920
+ value(initial, options = {}) {
1921
+ let current = initial;
1922
+ const get = () => current;
1923
+ const set = (next) => {
1924
+ const value = typeof next === "function" ? next(current) : next;
1925
+ if (options.equals !== false && Object.is(value, current))
1926
+ return;
1927
+ current = value;
1928
+ this.#changed();
1929
+ };
1930
+ return [get, set];
1931
+ }
1932
+ subscribe = (listener) => {
1933
+ this.#listeners.add(listener);
1934
+ return () => void this.#listeners.delete(listener);
1935
+ };
1936
+ version = () => this.#version;
1937
+ #changed() {
1938
+ this.#version++;
1939
+ if (this.#queued)
1940
+ return;
1941
+ this.#queued = true;
1942
+ queueMicrotask(() => {
1943
+ this.#queued = false;
1944
+ for (const listener of this.#listeners)
1945
+ listener();
1946
+ });
1947
+ }
1948
+ }
1949
+ function useStore(store) {
1950
+ return useSyncExternalStore(store.subscribe, store.version);
1951
+ }
1952
+
1953
+ // src/tui/app.tsx
1954
+ import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
1955
+ var MAX_FRAME = { width: 110, height: 36 };
1956
+ var FRAME_INSET = { x: 2 + 4, y: 2 + 2 };
1957
+ function App({ controller: c, onQuit }) {
1958
+ useStore(c.store);
1959
+ const screen = useScreenSize();
1960
+ const trusted = c.screen() !== "trust";
1961
+ const theme = trusted ? themeFor(c.config(), { background: c.options.background }) : BASE_THEME;
1962
+ const behind = c.modal() ? veiled(theme) : theme;
1963
+ const product = c.config()?.product?.name ?? c.options.source.name;
1964
+ const source = c.options.source;
1965
+ const detail = source.org ? `${source.org}/${source.name}` : source.name;
1966
+ const frame = { width: Math.min(screen.columns, MAX_FRAME.width), height: Math.min(screen.rows, MAX_FRAME.height) };
1967
+ const inner = { width: Math.max(frame.width - FRAME_INSET.x, 1), height: Math.max(frame.height - FRAME_INSET.y, 1) };
1968
+ const toast = c.toast();
1969
+ useKeys((key) => {
1970
+ if (key.ctrl && key.name === "c")
1971
+ onQuit();
1972
+ });
1973
+ const screens = {
1974
+ trust: () => /* @__PURE__ */ jsx8(TrustScreen, {
1975
+ controller: c,
1976
+ onQuit
1977
+ }),
1978
+ compose: () => /* @__PURE__ */ jsx8(ComposeScreen, {
1979
+ controller: c,
1980
+ theme: behind,
1981
+ product,
1982
+ detail
1983
+ }),
1984
+ running: () => /* @__PURE__ */ jsx8(RunningScreen, {
1985
+ controller: c,
1986
+ theme: behind,
1987
+ product,
1988
+ detail
1989
+ }),
1990
+ result: () => /* @__PURE__ */ jsx8(ResultScreen, {
1991
+ controller: c,
1992
+ theme: behind,
1993
+ product,
1994
+ detail,
1995
+ onQuit
1996
+ }),
1997
+ error: () => /* @__PURE__ */ jsx8(ErrorScreen, {
1998
+ controller: c,
1999
+ theme: behind,
2000
+ product,
2001
+ detail,
2002
+ onQuit
2003
+ })
2004
+ };
2005
+ return /* @__PURE__ */ jsx8(FrameSize.Provider, {
2006
+ value: inner,
2007
+ children: /* @__PURE__ */ jsxs8(Box8, {
2008
+ width: screen.columns,
2009
+ height: screen.rows,
2010
+ backgroundColor: behind.background,
2011
+ alignItems: "center",
2012
+ justifyContent: "center",
2013
+ children: [
2014
+ /* @__PURE__ */ jsx8(Panel, {
2015
+ width: frame.width,
2016
+ height: frame.height,
2017
+ borderColor: behind.border,
2018
+ backgroundColor: behind.background,
2019
+ paddingX: 2,
2020
+ paddingY: 1,
2021
+ flexDirection: "column",
2022
+ children: screens[c.screen()]()
2023
+ }),
2024
+ toast && /* @__PURE__ */ jsx8(Box8, {
2025
+ position: "absolute",
2026
+ width: frame.width,
2027
+ height: frame.height,
2028
+ flexDirection: "column",
2029
+ justifyContent: "flex-end",
2030
+ alignItems: "flex-end",
2031
+ paddingRight: 3,
2032
+ children: /* @__PURE__ */ jsx8(Box8, {
2033
+ backgroundColor: toast.tone === "danger" ? theme.danger : theme.success,
2034
+ paddingX: 1,
2035
+ width: Math.min(stringWidth4(toast.text) + 4, Math.floor(frame.width * 0.7)),
2036
+ children: /* @__PURE__ */ jsx8(Text7, {
2037
+ color: theme.background,
2038
+ bold: true,
2039
+ children: `${toast.tone === "danger" ? "⚠" : "✓"} ${toast.text}`
2040
+ })
2041
+ })
2042
+ }),
2043
+ c.modal() && /* @__PURE__ */ jsx8(Modals, {
2044
+ controller: c,
2045
+ theme
2046
+ })
2047
+ ]
2048
+ })
2049
+ });
2050
+ }
2051
+
2052
+ // src/tui/controller.ts
2053
+ import {
2054
+ startAgent,
2055
+ GITHUB_LOGIN_ARGS,
2056
+ RejectedError,
2057
+ StoppedError,
2058
+ Transcript,
2059
+ buildLink,
2060
+ buildPrompt,
2061
+ copyIssue,
2062
+ fetchSource,
2063
+ fileGitHubIssue,
2064
+ filterModels,
2065
+ formatIssue,
2066
+ gitHubStatus,
2067
+ hasModelFilter,
2068
+ isModelAllowed,
2069
+ loadConfig,
2070
+ openUrl,
2071
+ parseIssue
2072
+ } from "trissue-embedded";
2073
+ function createController(options) {
2074
+ const store = new Store;
2075
+ const [screen, setScreen] = store.value("trust");
2076
+ const [modal, setModal] = store.value(null);
2077
+ const [toast, setToastSignal] = store.value(null);
2078
+ const [fetched, setFetched] = store.value(options.fetched ?? null);
2079
+ const [fetchError, setFetchError] = store.value(null);
2080
+ const [config, setConfig] = store.value(options.config ?? null);
2081
+ const [issueText, setIssueText] = store.value("");
2082
+ const [harnessIndex, setHarnessIndex] = store.value(0);
2083
+ const [modelId, setModelId] = store.value(null);
2084
+ const [sessionState, setSessionState] = store.value({ status: "idle" });
2085
+ const [entries, setEntries] = store.value([], { equals: false });
2086
+ const [startedAt, setStartedAt] = store.value(0);
2087
+ const [issue, setIssue] = store.value(null);
2088
+ const [error, setError] = store.value(null);
2089
+ const [busy, setBusy] = store.value(null);
2090
+ let toastTimer;
2091
+ function showToast(text, tone = "success") {
2092
+ clearTimeout(toastTimer);
2093
+ setToastSignal({ text, tone });
2094
+ toastTimer = setTimeout(() => setToastSignal(null), 3500);
2095
+ }
2096
+ if (!options.fetched) {
2097
+ (async () => {
2098
+ try {
2099
+ const source = await fetchSource(options.source);
2100
+ const loaded = await loadConfig(source.dir).catch(async (error) => {
2101
+ await source.dispose();
2102
+ throw error;
2103
+ });
2104
+ setFetched(source);
2105
+ setConfig(loaded);
2106
+ } catch (error) {
2107
+ setFetchError(error.message);
2108
+ }
2109
+ })();
2110
+ }
2111
+ const harness = () => options.harnesses[harnessIndex()];
2112
+ let sessionToken = 0;
2113
+ function closeSession() {
2114
+ sessionToken++;
2115
+ const state = sessionState();
2116
+ if (state.status === "ready")
2117
+ state.session.close();
2118
+ setSessionState({ status: "idle" });
2119
+ }
2120
+ function selectHarness(index) {
2121
+ if (index === harnessIndex())
2122
+ return;
2123
+ closeSession();
2124
+ setHarnessIndex(index);
2125
+ setModelId(null);
2126
+ }
2127
+ async function prepareSession() {
2128
+ const chosen = harness();
2129
+ const source = fetched();
2130
+ if (!chosen || !source)
2131
+ return null;
2132
+ const state = sessionState();
2133
+ if (state.status === "ready" && state.harnessId === chosen.id)
2134
+ return state.session;
2135
+ if (state.status === "starting" && state.harnessId === chosen.id)
2136
+ return waitForSession(chosen.id);
2137
+ const token = ++sessionToken;
2138
+ setSessionState({ status: "starting", harnessId: chosen.id });
2139
+ try {
2140
+ const session = await startAgent({ harness: chosen, cwd: source.dir, onEvent: onAgentEvent });
2141
+ if (token !== sessionToken) {
2142
+ session.close();
2143
+ return null;
2144
+ }
2145
+ setSessionState({ status: "ready", harnessId: chosen.id, session });
2146
+ return session;
2147
+ } catch (error) {
2148
+ if (token === sessionToken)
2149
+ setSessionState({ status: "failed", harnessId: chosen.id, error: error.message });
2150
+ return null;
2151
+ }
2152
+ }
2153
+ function waitForSession(harnessId) {
2154
+ return new Promise((resolve) => {
2155
+ const check = () => {
2156
+ const state = sessionState();
2157
+ if (state.status === "ready" && state.harnessId === harnessId)
2158
+ resolve(state.session);
2159
+ else if (state.status !== "starting" || state.harnessId !== harnessId)
2160
+ resolve(null);
2161
+ else
2162
+ setTimeout(check, 50);
2163
+ };
2164
+ check();
2165
+ });
2166
+ }
2167
+ let transcript = new Transcript;
2168
+ let flushQueued = false;
2169
+ function onAgentEvent(event) {
2170
+ if (screen() !== "running")
2171
+ return;
2172
+ transcript.apply(event);
2173
+ if (flushQueued)
2174
+ return;
2175
+ flushQueued = true;
2176
+ setTimeout(() => {
2177
+ flushQueued = false;
2178
+ setEntries(transcript.entries);
2179
+ }, 33);
2180
+ }
2181
+ function allowedModels(session) {
2182
+ return filterModels(config()?.models, session.harness.id, session.models);
2183
+ }
2184
+ function modelProblem(session, id) {
2185
+ const filter = config()?.models;
2186
+ if (id)
2187
+ return isModelAllowed(filter, session.harness.id, id) ? null : `This repo doesn't allow ${id}.`;
2188
+ if (!hasModelFilter(filter))
2189
+ return null;
2190
+ const current = session.currentModel;
2191
+ if (!current)
2192
+ return `This repo only allows some models, and ${session.harness.name} doesn't say which model it uses by default.`;
2193
+ return isModelAllowed(filter, session.harness.id, current.id) ? null : `This repo doesn't allow ${current.name}, ${session.harness.name}'s default. Pick another model.`;
2194
+ }
2195
+ async function start(id) {
2196
+ if (!issueText().trim()) {
2197
+ showToast("Explain the issue first.", "danger");
2198
+ return false;
2199
+ }
2200
+ const session = await prepareSession();
2201
+ if (!session) {
2202
+ const state = sessionState();
2203
+ if (state.status === "failed")
2204
+ showToast(state.error, "danger");
2205
+ return false;
2206
+ }
2207
+ const problem = modelProblem(session, id);
2208
+ if (problem) {
2209
+ showToast(problem, "danger");
2210
+ setModal({ name: "models" });
2211
+ return false;
2212
+ }
2213
+ try {
2214
+ if (id)
2215
+ await session.setModel(id);
2216
+ } catch (error) {
2217
+ showToast(error.message, "danger");
2218
+ return false;
2219
+ }
2220
+ const source = fetched();
2221
+ const chosen = id ?? session.currentModel?.id ?? null;
2222
+ transcript = new Transcript;
2223
+ setModelId(chosen);
2224
+ setModal(null);
2225
+ setEntries([]);
2226
+ setStartedAt(Date.now());
2227
+ setScreen("running");
2228
+ const modelName = session.models.find((model) => model.id === chosen)?.name ?? chosen ?? undefined;
2229
+ try {
2230
+ const text = await session.run(buildPrompt({ issue: issueText(), source, instructions: config()?.instructions, harnessName: session.harness.name, modelName }));
2231
+ const parsed = parseIssue(text);
2232
+ setIssue(parsed);
2233
+ setScreen("result");
2234
+ } catch (error) {
2235
+ const title = error instanceof StoppedError ? "Stopped" : error instanceof RejectedError ? "The agent rejected this task" : "Error";
2236
+ setError({ title, message: error.message });
2237
+ setScreen("error");
2238
+ } finally {
2239
+ closeSession();
2240
+ }
2241
+ return true;
2242
+ }
2243
+ function steer(text) {
2244
+ const state = sessionState();
2245
+ if (state.status === "ready")
2246
+ state.session.steer(text);
2247
+ }
2248
+ function stop() {
2249
+ const state = sessionState();
2250
+ if (state.status === "ready")
2251
+ state.session.stop();
2252
+ }
2253
+ function tryAgain() {
2254
+ setError(null);
2255
+ setIssue(null);
2256
+ setScreen("compose");
2257
+ }
2258
+ const githubRepo = () => {
2259
+ const configured = config()?.github;
2260
+ if (configured === false)
2261
+ return null;
2262
+ return configured ?? fetched()?.github ?? null;
2263
+ };
2264
+ async function beginGitHub() {
2265
+ const repo = githubRepo();
2266
+ if (!repo)
2267
+ return;
2268
+ setBusy("Checking GitHub sign-in…");
2269
+ try {
2270
+ const status = await gitHubStatus();
2271
+ if (status.state === "missing")
2272
+ setModal({ name: "github-missing" });
2273
+ else if (status.state === "signed-out")
2274
+ setModal({ name: "github-signin", repo });
2275
+ else
2276
+ setModal({ name: "github-confirm", repo, login: status.login });
2277
+ } catch (error) {
2278
+ showToast(`Couldn't check GitHub sign-in: ${error.message}`, "danger");
2279
+ } finally {
2280
+ setBusy(null);
2281
+ }
2282
+ }
2283
+ async function signInToGitHub() {
2284
+ setModal(null);
2285
+ if (!options.runInTerminal) {
2286
+ showToast("Sign in with `gh auth login`, then try again.", "danger");
2287
+ return;
2288
+ }
2289
+ const code = await options.runInTerminal("gh", GITHUB_LOGIN_ARGS);
2290
+ if (code !== 0) {
2291
+ showToast("GitHub sign-in didn't finish.", "danger");
2292
+ return;
2293
+ }
2294
+ await beginGitHub();
2295
+ }
2296
+ async function fileOnGitHub(repo) {
2297
+ const current = issue();
2298
+ if (!current)
2299
+ return;
2300
+ setModal(null);
2301
+ setBusy("Filing the issue…");
2302
+ try {
2303
+ const url = await fileGitHubIssue(repo, current, config()?.labels ?? []);
2304
+ setModal({ name: "filed", url });
2305
+ } catch (error) {
2306
+ showToast(`Couldn't file the issue: ${error.message}`, "danger");
2307
+ } finally {
2308
+ setBusy(null);
2309
+ }
2310
+ }
2311
+ async function copy() {
2312
+ const current = issue();
2313
+ if (!current)
2314
+ return;
2315
+ try {
2316
+ await copyIssue(current);
2317
+ showToast("Copied the issue.");
2318
+ } catch (error) {
2319
+ if (options.copyFallback?.(formatIssue(current)))
2320
+ showToast("Copied the issue through your terminal.");
2321
+ else
2322
+ showToast(error.message, "danger");
2323
+ }
2324
+ }
2325
+ function chooseLink(link) {
2326
+ const current = issue();
2327
+ if (!current)
2328
+ return;
2329
+ setModal({ name: "link", link, url: buildLink(link, current) });
2330
+ }
2331
+ async function open(url) {
2332
+ try {
2333
+ await openUrl(url);
2334
+ setModal(null);
2335
+ } catch (error) {
2336
+ showToast(error.message, "danger");
2337
+ }
2338
+ }
2339
+ function dispose() {
2340
+ closeSession();
2341
+ clearTimeout(toastTimer);
2342
+ return fetched()?.dispose();
2343
+ }
2344
+ return {
2345
+ store,
2346
+ options,
2347
+ screen,
2348
+ setScreen,
2349
+ modal,
2350
+ setModal,
2351
+ toast,
2352
+ showToast,
2353
+ fetched,
2354
+ fetchError,
2355
+ config,
2356
+ issueText,
2357
+ setIssueText,
2358
+ harnesses: options.harnesses,
2359
+ harness,
2360
+ harnessIndex,
2361
+ selectHarness,
2362
+ modelId,
2363
+ sessionState,
2364
+ prepareSession,
2365
+ allowedModels,
2366
+ entries,
2367
+ startedAt,
2368
+ issue,
2369
+ error,
2370
+ busy,
2371
+ start,
2372
+ steer,
2373
+ stop,
2374
+ tryAgain,
2375
+ githubRepo,
2376
+ beginGitHub,
2377
+ signInToGitHub,
2378
+ fileOnGitHub,
2379
+ copy,
2380
+ chooseLink,
2381
+ open,
2382
+ dispose,
2383
+ debug: { setEntries, setIssue, setError, setStartedAt, setSessionState, setModelId }
2384
+ };
2385
+ }
2386
+
2387
+ // src/tui/run.tsx
2388
+ import { jsx as jsx9 } from "react/jsx-runtime";
2389
+ var ENTER_ALT_SCREEN = "\x1B[?1049h\x1B[2J\x1B[H";
2390
+ var LEAVE_ALT_SCREEN = "\x1B[?1049l";
2391
+ var SHOW_CURSOR = "\x1B[?25h";
2392
+ function terminalSize() {
2393
+ return { columns: Math.max(process.stdout.columns || 80, 20), rows: Math.max((process.stdout.rows || 24) - 1, 8) };
2394
+ }
2395
+ function Root({ children }) {
2396
+ const [size, setSize] = useState6(terminalSize);
2397
+ useEffect4(() => {
2398
+ const onResize = () => setSize(terminalSize());
2399
+ process.stdout.on("resize", onResize);
2400
+ return () => void process.stdout.off("resize", onResize);
2401
+ }, []);
2402
+ return /* @__PURE__ */ jsx9(ScreenSize.Provider, {
2403
+ value: size,
2404
+ children
2405
+ });
2406
+ }
2407
+ function copyThroughTerminal(text) {
2408
+ if (!process.stdout.isTTY)
2409
+ return false;
2410
+ process.stdout.write(`\x1B]52;c;${Buffer.from(text).toString("base64")}\x07`);
2411
+ return true;
2412
+ }
2413
+ async function runInterface(options) {
2414
+ let instance = null;
2415
+ let onScreen = false;
2416
+ const enter = () => {
2417
+ process.stdout.write(ENTER_ALT_SCREEN);
2418
+ onScreen = true;
2419
+ };
2420
+ const leave = () => {
2421
+ if (!onScreen)
2422
+ return;
2423
+ onScreen = false;
2424
+ process.stdout.write(LEAVE_ALT_SCREEN + SHOW_CURSOR);
2425
+ };
2426
+ process.once("exit", leave);
2427
+ const controller = createController({
2428
+ ...options,
2429
+ runInTerminal: async (command, args) => {
2430
+ await new Promise((resolve) => setImmediate(resolve));
2431
+ unmount();
2432
+ leave();
2433
+ try {
2434
+ return spawnSync(command, args, { stdio: "inherit" }).status ?? 1;
2435
+ } finally {
2436
+ mount();
2437
+ }
2438
+ },
2439
+ copyFallback: copyThroughTerminal
2440
+ });
2441
+ let quitting = false;
2442
+ const quit = async () => {
2443
+ if (quitting)
2444
+ return;
2445
+ quitting = true;
2446
+ try {
2447
+ await controller.dispose();
2448
+ } finally {
2449
+ unmount();
2450
+ leave();
2451
+ process.exit(0);
2452
+ }
2453
+ };
2454
+ for (const signal of ["SIGTERM", "SIGHUP"])
2455
+ process.on(signal, () => void quit());
2456
+ function mount() {
2457
+ enter();
2458
+ instance = render(/* @__PURE__ */ jsx9(Root, {
2459
+ children: /* @__PURE__ */ jsx9(App, {
2460
+ controller,
2461
+ onQuit: () => void quit()
2462
+ })
2463
+ }), { exitOnCtrlC: false, patchConsole: true, maxFps: 30 });
2464
+ }
2465
+ function unmount() {
2466
+ instance?.clear();
2467
+ instance?.unmount();
2468
+ instance = null;
2469
+ }
2470
+ mount();
2471
+ }
2472
+ export {
2473
+ runInterface
2474
+ };