@conveno/cli 0.2.0-rc.3 → 0.2.0-rc.4

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.
@@ -1,15 +1,16 @@
1
- import { Box, Text, render, useApp, useInput, useWindowSize } from "ink";
1
+ import { Box, Text, render, useApp, useInput, useStdin, useWindowSize } from "ink";
2
2
  import { n as connectOpts, t as adapterEnv } from "./ctx-CDLE-2f2.js";
3
- import { b as openInBrowser, g as PAIR_TIMEOUT_MS, h as unifiedDiff, l as StaleError, r as collectPlans, t as inspect, u as applyChanges, y as daemonProblem } from "./doctor-D1sP9gCl.js";
3
+ import { b as openInBrowser, g as PAIR_TIMEOUT_MS, h as unifiedDiff, l as StaleError, r as collectPlans, t as inspect, u as applyChanges, y as daemonProblem } from "./doctor-Bckon1ju.js";
4
4
  import { d as plainError, l as fail, m as tilde, o as cmd } from "./args-DEYV4Ran.js";
5
- import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
5
+ import { createContext, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState, useSyncExternalStore } from "react";
6
+ import { readFileSync, readdirSync, writeFileSync } from "node:fs";
7
+ import { Readable } from "node:stream";
8
+ import { At as readSettings, D as compatStatus, G as fetchAccountStatus, N as dataPaths, Nt as realSpawnDeps, Tt as readAccountTokens, Ut as spawnRecordPath, Wt as spawnSession, _n as PERMISSION_ANSWERS, gn as OWNER_SESSION_ID, in as writeSettings, jt as readSpawnRecord, l as SPAWN_TABLE } from "./dist-DUqXHTRg.js";
9
+ import { homedir } from "node:os";
6
10
  import { i as tokens, n as detectColorLevel, r as detectUnicode } from "./dist-BRjg9CLd.js";
7
11
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
- import { readdirSync, writeFileSync } from "node:fs";
9
- import { homedir } from "node:os";
10
12
  import { basename, join, resolve } from "node:path";
11
- import { At as readSettings, D as compatStatus, G as fetchAccountStatus, N as dataPaths, Nt as realSpawnDeps, Tt as readAccountTokens, Ut as spawnRecordPath, Wt as spawnSession, _n as PERMISSION_ANSWERS, gn as OWNER_SESSION_ID, in as writeSettings, jt as readSpawnRecord, l as SPAWN_TABLE } from "./dist-M9Gs7e_K.js";
12
- import { i as stopRequestPath, t as killProcessTree } from "./dist-BiAm0SS8.js";
13
+ import { i as stopRequestPath, t as killProcessTree } from "./dist-CuStS_nO.js";
13
14
  // \0rolldown/runtime.js
14
15
  var __defProp = Object.defineProperty;
15
16
  var __exportAll = (all, flags) => {
@@ -55,11 +56,421 @@ const SCREENS = [
55
56
  title: "Setup"
56
57
  }
57
58
  ];
59
+ // src/tui/mouse.ts
60
+ /**
61
+ * Mouse support for the app, with no React in it: an SGR mouse parser, a stream that sits between
62
+ * the real stdin and Ink and strips mouse reports out of the bytes, and a hub that hit-tests
63
+ * registered boxes. `ui.tsx` wraps the hub in hooks.
64
+ */
65
+ const ESC = "\x1B";
66
+ const PASTE_START = `${ESC}[200~`;
67
+ const PASTE_END = `${ESC}[201~`;
68
+ const SGR = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])/;
69
+ const SGR_PREFIX = /^\x1b(?:\[(?:<[0-9;]*)?)?$/;
70
+ /** Turn the numbers of an SGR report into an event. */
71
+ function sgrEvent(b, x, y, final) {
72
+ const wheel = (b & 64) !== 0;
73
+ const motion = (b & 32) !== 0;
74
+ const low = b & 3;
75
+ return {
76
+ kind: wheel ? "wheel" : motion ? "move" : final === "m" ? "release" : "press",
77
+ button: wheel ? "left" : low === 1 ? "middle" : low === 2 ? "right" : "left",
78
+ x: Math.max(0, x - 1),
79
+ y: Math.max(0, y - 1),
80
+ delta: wheel ? (b & 1) === 0 ? -1 : 1 : 0,
81
+ shift: (b & 4) !== 0,
82
+ alt: (b & 8) !== 0,
83
+ ctrl: (b & 16) !== 0
84
+ };
85
+ }
86
+ /**
87
+ * Takes the bytes the terminal sends and splits them into the text Ink should see and mouse
88
+ * events. A report cut by a chunk boundary is held until the rest arrives (`flush` gives it up
89
+ * when nothing follows). Bracketed paste passes through as it is, mouse-looking text included.
90
+ */
91
+ var MouseParser = class {
92
+ held = "";
93
+ inPaste = false;
94
+ push(chunk) {
95
+ const s = this.held + chunk;
96
+ this.held = "";
97
+ const events = [];
98
+ let text = "";
99
+ let i = 0;
100
+ while (i < s.length) {
101
+ if (this.inPaste) {
102
+ const end = s.indexOf(PASTE_END, i);
103
+ if (end >= 0) {
104
+ text += s.slice(i, end + PASTE_END.length);
105
+ i = end + PASTE_END.length;
106
+ this.inPaste = false;
107
+ continue;
108
+ }
109
+ let keep = 0;
110
+ for (let n = Math.min(PASTE_END.length - 1, s.length - i); n > 0; n--) if (PASTE_END.startsWith(s.slice(s.length - n))) {
111
+ keep = n;
112
+ break;
113
+ }
114
+ text += s.slice(i, s.length - keep);
115
+ this.held = s.slice(s.length - keep);
116
+ break;
117
+ }
118
+ const esc = s.indexOf(ESC, i);
119
+ if (esc < 0) {
120
+ text += s.slice(i);
121
+ break;
122
+ }
123
+ text += s.slice(i, esc);
124
+ const rest = s.slice(esc);
125
+ const m = SGR.exec(rest);
126
+ if (m) {
127
+ events.push(sgrEvent(Number(m[1]), Number(m[2]), Number(m[3]), m[4]));
128
+ i = esc + m[0].length;
129
+ continue;
130
+ }
131
+ if (rest.startsWith(PASTE_START)) {
132
+ text += PASTE_START;
133
+ this.inPaste = true;
134
+ i = esc + PASTE_START.length;
135
+ continue;
136
+ }
137
+ if (SGR_PREFIX.test(rest) || rest.length < PASTE_START.length && isPasteStartPrefix(rest)) {
138
+ this.held = rest;
139
+ break;
140
+ }
141
+ text += ESC;
142
+ i = esc + 1;
143
+ }
144
+ return {
145
+ text,
146
+ events
147
+ };
148
+ }
149
+ /** Whether bytes are being held back. */
150
+ get pending() {
151
+ return this.held !== "";
152
+ }
153
+ /** Give up what is held: it was not a mouse report after all. */
154
+ flush() {
155
+ const h = this.held;
156
+ this.held = "";
157
+ return h;
158
+ }
159
+ };
160
+ function isPasteStartPrefix(s) {
161
+ return PASTE_START.startsWith(s);
162
+ }
163
+ /** Position of a box on the screen, in cells. Zero size when it is not laid out or hidden. */
164
+ function boxRect(node) {
165
+ const own = node.yogaNode;
166
+ if (!own) return {
167
+ x: 0,
168
+ y: 0,
169
+ w: 0,
170
+ h: 0
171
+ };
172
+ let x = own.getComputedLeft();
173
+ let y = own.getComputedTop();
174
+ for (let p = node.parentNode; p; p = p.parentNode) if (p.yogaNode) {
175
+ x += p.yogaNode.getComputedLeft();
176
+ y += p.yogaNode.getComputedTop();
177
+ }
178
+ return {
179
+ x,
180
+ y,
181
+ w: own.getComputedWidth(),
182
+ h: own.getComputedHeight()
183
+ };
184
+ }
185
+ function depthOf(node) {
186
+ let d = 0;
187
+ for (let p = node.parentNode; p; p = p.parentNode) d++;
188
+ return d;
189
+ }
190
+ const ENABLE_SEQ = "\x1B[?1000h\x1B[?1006h";
191
+ const DISABLE_SEQ = "\x1B[?1006l\x1B[?1002l\x1B[?1000l";
192
+ /** Hit testing and dispatch. One per running app. */
193
+ var MouseHub = class {
194
+ targets = [];
195
+ listeners = /* @__PURE__ */ new Set();
196
+ fallbacks = /* @__PURE__ */ new Set();
197
+ last;
198
+ on;
199
+ reporter;
200
+ available;
201
+ forcedOff;
202
+ showHint;
203
+ inject;
204
+ persist;
205
+ markHint;
206
+ now;
207
+ constructor(opts = {}) {
208
+ this.available = opts.available ?? true;
209
+ this.forcedOff = opts.forcedOff ?? false;
210
+ this.on = this.available && !this.forcedOff && (opts.enabled ?? true);
211
+ this.showHint = (opts.showHint ?? false) && this.on;
212
+ this.inject = opts.inject ?? (() => void 0);
213
+ this.persist = opts.persist;
214
+ this.markHint = opts.markHintShown;
215
+ this.now = opts.now ?? Date.now;
216
+ }
217
+ get enabled() {
218
+ return this.on;
219
+ }
220
+ /** Switch the mouse on or off at once; with `persist` the choice is also kept. */
221
+ setEnabled(on, persist = false) {
222
+ if (persist) this.persist?.(on);
223
+ const next = on && this.available && !this.forcedOff;
224
+ if (next === this.on) return;
225
+ this.on = next;
226
+ this.last = void 0;
227
+ this.reporter?.(next);
228
+ for (const l of this.listeners) l();
229
+ }
230
+ /** Called by the stream that sends the enable and disable sequences. */
231
+ attachReporter(fn) {
232
+ this.reporter = fn;
233
+ }
234
+ subscribe = (l) => {
235
+ this.listeners.add(l);
236
+ return () => this.listeners.delete(l);
237
+ };
238
+ getEnabled = () => this.on;
239
+ hintShown() {
240
+ this.markHint?.();
241
+ }
242
+ /** Type keys into the app, as if pressed. */
243
+ press(keys) {
244
+ this.inject(keys);
245
+ }
246
+ register(t) {
247
+ this.targets.push(t);
248
+ return () => {
249
+ this.targets = this.targets.filter((x) => x !== t);
250
+ };
251
+ }
252
+ /** Called with a press that no box took. */
253
+ onUnhandled(fn) {
254
+ this.fallbacks.add(fn);
255
+ return () => this.fallbacks.delete(fn);
256
+ }
257
+ /** The innermost active target of a kind under a cell. */
258
+ hit(kind, x, y) {
259
+ let best;
260
+ for (const t of this.targets) {
261
+ if (t.kind !== kind || !t.active()) continue;
262
+ const el = t.el();
263
+ if (!el) continue;
264
+ const r = boxRect(el);
265
+ if (r.w <= 0 || r.h <= 0) continue;
266
+ if (x < r.x || x >= r.x + r.w || y < r.y || y >= r.y + r.h) continue;
267
+ const depth = depthOf(el);
268
+ if (!best || depth >= best.depth) best = {
269
+ t,
270
+ rx: x - r.x,
271
+ ry: y - r.y,
272
+ depth
273
+ };
274
+ }
275
+ return best;
276
+ }
277
+ /** Handle one mouse event from the terminal. */
278
+ dispatch(e) {
279
+ if (!this.on) return;
280
+ if (e.kind === "wheel") {
281
+ this.hit("wheel", e.x, e.y)?.t.wheel?.(e.delta);
282
+ return;
283
+ }
284
+ if (e.kind !== "press") return;
285
+ let double = false;
286
+ if (e.button === "left") {
287
+ const t = this.now();
288
+ double = this.last !== void 0 && this.last.x === e.x && this.last.y === e.y && t - this.last.t <= 400;
289
+ this.last = double ? void 0 : {
290
+ x: e.x,
291
+ y: e.y,
292
+ t
293
+ };
294
+ }
295
+ const h = this.hit("click", e.x, e.y);
296
+ if (h) {
297
+ h.t.click?.({
298
+ x: h.rx,
299
+ y: h.ry,
300
+ button: e.button,
301
+ double,
302
+ shift: e.shift
303
+ });
304
+ return;
305
+ }
306
+ for (const f of this.fallbacks) f(e);
307
+ }
308
+ };
309
+ const HOLD_MS = 15;
310
+ /** The stream Ink reads. Looks like the terminal's stdin, without the mouse reports. */
311
+ var FilteredStdin = class extends Readable {
312
+ real;
313
+ out;
314
+ hub;
315
+ isTTY = true;
316
+ isRaw = false;
317
+ parser = new MouseParser();
318
+ timer;
319
+ reporting = false;
320
+ raw = false;
321
+ shut = false;
322
+ onData = (chunk) => {
323
+ const { text, events } = this.parser.push(typeof chunk === "string" ? chunk : chunk.toString("utf8"));
324
+ for (const e of events) this.hub.dispatch(e);
325
+ if (text) this.push(text);
326
+ if (this.timer) clearTimeout(this.timer);
327
+ this.timer = void 0;
328
+ if (this.parser.pending) this.timer = setTimeout(() => {
329
+ this.timer = void 0;
330
+ const rest = this.parser.flush();
331
+ if (rest) this.push(rest);
332
+ }, HOLD_MS);
333
+ };
334
+ constructor(real, out, hub) {
335
+ super();
336
+ this.real = real;
337
+ this.out = out;
338
+ this.hub = hub;
339
+ real.setEncoding("utf8");
340
+ real.on("data", this.onData);
341
+ hub.attachReporter((on) => this.report(on));
342
+ }
343
+ _read() {}
344
+ setRawMode(on) {
345
+ this.real.setRawMode?.(on);
346
+ this.raw = on;
347
+ this.isRaw = on;
348
+ this.report(on && this.hub.enabled);
349
+ return this;
350
+ }
351
+ ref() {
352
+ this.real.ref?.();
353
+ return this;
354
+ }
355
+ unref() {
356
+ this.real.unref?.();
357
+ return this;
358
+ }
359
+ /** Put keys in front of Ink as if typed. */
360
+ inject(keys) {
361
+ this.push(keys);
362
+ }
363
+ report(on) {
364
+ const want = on && this.raw && !this.shut;
365
+ if (want === this.reporting) return;
366
+ this.reporting = want;
367
+ try {
368
+ this.out.write(want ? ENABLE_SEQ : DISABLE_SEQ);
369
+ } catch {}
370
+ }
371
+ /** Stop reading and make sure the terminal is out of mouse mode. */
372
+ close() {
373
+ if (this.shut) return;
374
+ this.shut = true;
375
+ if (this.timer) clearTimeout(this.timer);
376
+ this.real.removeListener("data", this.onData);
377
+ this.hub.attachReporter(void 0);
378
+ try {
379
+ this.real.pause();
380
+ } catch {}
381
+ this.out.write(DISABLE_SEQ);
382
+ this.reporting = false;
383
+ }
384
+ };
385
+ /**
386
+ * Put the mouse filter between the real stdin and Ink. Reporting is switched on when Ink turns raw
387
+ * mode on and off again on every way out: dispose, process exit (which also covers an uncaught
388
+ * error), SIGTERM and SIGHUP.
389
+ */
390
+ function createMouseInput(ctx, real = process.stdin, out = process.stdout) {
391
+ const usable = real.isTTY === true && out.isTTY === true && typeof real.setRawMode === "function";
392
+ const forcedOff = mouseForcedOff(ctx);
393
+ const hint = usable && getMouseSetting(ctx) && !hintWasShown(ctx);
394
+ let stream;
395
+ const hub = new MouseHub({
396
+ available: usable,
397
+ forcedOff,
398
+ enabled: getMouseSetting(ctx),
399
+ showHint: hint,
400
+ inject: (k) => stream?.inject(k),
401
+ persist: (on) => saveSetting(ctx, { appMouse: on }),
402
+ markHintShown: () => saveSetting(ctx, { appMouseHintShown: true })
403
+ });
404
+ if (!usable) return {
405
+ stdin: real,
406
+ hub,
407
+ dispose: () => void 0
408
+ };
409
+ stream = new FilteredStdin(real, out, hub);
410
+ const restore = () => {
411
+ try {
412
+ out.write(DISABLE_SEQ);
413
+ } catch {}
414
+ };
415
+ const onTerm = (sig) => {
416
+ restore();
417
+ process.removeListener("SIGTERM", onTerm);
418
+ process.removeListener("SIGHUP", onTerm);
419
+ process.kill(process.pid, sig);
420
+ };
421
+ process.on("exit", restore);
422
+ process.on("SIGTERM", onTerm);
423
+ process.on("SIGHUP", onTerm);
424
+ let done = false;
425
+ return {
426
+ stdin: stream,
427
+ hub,
428
+ dispose() {
429
+ if (done) return;
430
+ done = true;
431
+ stream?.close();
432
+ process.removeListener("exit", restore);
433
+ process.removeListener("SIGTERM", onTerm);
434
+ process.removeListener("SIGHUP", onTerm);
435
+ }
436
+ };
437
+ }
438
+ function settingsFile(ctx) {
439
+ return dataPaths(ctx.platform, ctx.dataDir).settings;
440
+ }
441
+ function readRaw(ctx) {
442
+ try {
443
+ const v = JSON.parse(readFileSync(settingsFile(ctx), "utf8"));
444
+ return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
445
+ } catch {
446
+ return {};
447
+ }
448
+ }
449
+ function saveSetting(ctx, patch) {
450
+ try {
451
+ writeSettings(settingsFile(ctx), patch);
452
+ } catch {}
453
+ }
454
+ function hintWasShown(ctx) {
455
+ return readRaw(ctx).appMouseHintShown === true;
456
+ }
457
+ /** `CONVENO_MOUSE=0` (or `off`, `false`) switches the mouse off whatever was saved. */
458
+ function mouseForcedOff(ctx) {
459
+ const v = ctx.env.CONVENO_MOUSE?.trim().toLowerCase();
460
+ return v === "0" || v === "off" || v === "false" || v === "no";
461
+ }
462
+ /** Whether the mouse should be on: on unless forced off or saved as off (`appMouse: false`). */
463
+ function getMouseSetting(ctx) {
464
+ if (mouseForcedOff(ctx)) return false;
465
+ return readRaw(ctx).appMouse !== false;
466
+ }
58
467
  // src/tui/ui.tsx
59
468
  /**
60
469
  * Small building blocks every screen shares. Colours come from the brand tokens; with NO_COLOR or
61
470
  * a terminal without colour every colour is undefined and state is carried by words.
62
471
  */
472
+ /** The selected-row highlight from the approved mockup. */
473
+ const SELECT_BG = "#1B2A40";
63
474
  const NAMES = [
64
475
  "ground",
65
476
  "surface",
@@ -84,7 +495,10 @@ function makeUiTheme(env = process.env, opts = {}) {
84
495
  const level = opts.colourLevel ?? detectColorLevel(ctx);
85
496
  const unicode = opts.unicode ?? detectUnicode(ctx);
86
497
  const c = {};
87
- if (level > 0) for (const n of NAMES) c[n] = tokens.color.dark[n];
498
+ if (level > 0) {
499
+ for (const n of NAMES) c[n] = tokens.color.dark[n];
500
+ c.select = SELECT_BG;
501
+ }
88
502
  return {
89
503
  c,
90
504
  ascii: !unicode,
@@ -114,6 +528,73 @@ const FALLBACK = {
114
528
  ascii: true,
115
529
  colour: false
116
530
  };
531
+ const MouseContext = createContext(void 0);
532
+ /** The shell provides the hub that turns terminal mouse reports into clicks and wheel turns. */
533
+ const MouseProvider = MouseContext.Provider;
534
+ const ScopeContext = createContext(true);
535
+ /** Everything below gets no mouse events while `active` is false (a screen under an overlay). */
536
+ function MouseScope({ active, children }) {
537
+ const outer = useContext(ScopeContext);
538
+ return /* @__PURE__ */ jsx(ScopeContext.Provider, {
539
+ value: outer && active,
540
+ children
541
+ });
542
+ }
543
+ function useTarget(kind, ref, fn, isActive) {
544
+ const hub = useContext(MouseContext);
545
+ const scope = useContext(ScopeContext);
546
+ const fnRef = useRef(fn);
547
+ fnRef.current = fn;
548
+ const activeRef = useRef(true);
549
+ activeRef.current = (isActive ?? true) && scope;
550
+ useEffect(() => {
551
+ if (!hub) return;
552
+ const call = (a) => fnRef.current(a);
553
+ return hub.register({
554
+ kind,
555
+ el: () => ref.current,
556
+ active: () => activeRef.current,
557
+ ...kind === "click" ? { click: call } : { wheel: call }
558
+ });
559
+ }, [
560
+ hub,
561
+ kind,
562
+ ref
563
+ ]);
564
+ }
565
+ /** Make a Box react to clicks. The handler gets the position inside the box. */
566
+ function useClick(ref, onClick, opts) {
567
+ useTarget("click", ref, onClick, opts?.isActive);
568
+ }
569
+ /** Make a Box a wheel target. `delta` is -1 (up) or +1 (down) per notch. */
570
+ function useWheel(ref, onWheel, opts) {
571
+ useTarget("wheel", ref, onWheel, opts?.isActive);
572
+ }
573
+ const NO_SUBSCRIBE = () => () => void 0;
574
+ /** Whether the mouse is on, to show hints like "click to open". */
575
+ function useMouseEnabled() {
576
+ const hub = useContext(MouseContext);
577
+ return useSyncExternalStore(hub?.subscribe ?? NO_SUBSCRIBE, hub?.getEnabled ?? (() => false));
578
+ }
579
+ /** For the Setup switch: the state, whether it can be on at all, and a setter that is kept. */
580
+ function useMouseControl() {
581
+ const hub = useContext(MouseContext);
582
+ return {
583
+ enabled: useMouseEnabled(),
584
+ available: hub?.available ?? false,
585
+ forcedOff: hub?.forcedOff ?? false,
586
+ set: (on) => hub?.setEnabled(on, true)
587
+ };
588
+ }
589
+ /** A ready-made clickable piece of text. */
590
+ function Clickable({ onClick, children, isActive }) {
591
+ const ref = useRef(null);
592
+ useClick(ref, onClick, isActive === void 0 ? void 0 : { isActive });
593
+ return /* @__PURE__ */ jsx(Box, {
594
+ ref,
595
+ children
596
+ });
597
+ }
117
598
  /** Cut a string to `width` columns, with an ellipsis. */
118
599
  function cut(text, width, ascii = false) {
119
600
  const dots = ascii ? "..." : "…";
@@ -123,11 +604,17 @@ function cut(text, width, ascii = false) {
123
604
  if (width <= dots.length) return dots.slice(0, width);
124
605
  return chars.slice(0, width - dots.length).join("") + dots;
125
606
  }
607
+ /** Swap the few Unicode glyphs the app uses for plain ones, when the terminal needs that. */
608
+ function plain(text, ascii) {
609
+ if (!ascii) return text;
610
+ return text.replace(/·/g, "-").replace(/⏎/g, "Enter").replace(/↑↓/g, "Up/Down").replace(/›/g, ">").replace(/…/g, "...");
611
+ }
126
612
  /** One line of text, cut with `…`. Never wraps. */
127
613
  function Ell({ width, color, bold, dim, children }) {
128
614
  const { ascii } = useTheme();
129
615
  const one = children.replace(/\s*\n\s*/g, " ");
130
616
  return /* @__PURE__ */ jsx(Text, {
617
+ wrap: "truncate",
131
618
  ...color ? { color } : {},
132
619
  ...bold ? { bold } : {},
133
620
  ...dim ? { dimColor: dim } : {},
@@ -147,23 +634,31 @@ const CHIPS = {
147
634
  function chipText(cli) {
148
635
  return CHIPS[cli] ?? cli.slice(0, 2).toLowerCase();
149
636
  }
150
- function Chip({ cli }) {
637
+ function Chip({ cli, dim }) {
151
638
  const { c } = useTheme();
639
+ const text = chipText(cli).padEnd(2).slice(0, 2);
640
+ if (!c.surface) return /* @__PURE__ */ jsx(Text, {
641
+ ...dim ? { dimColor: true } : {},
642
+ children: `[${text}]`
643
+ });
152
644
  return /* @__PURE__ */ jsx(Text, {
153
- ...c.quiet ? { color: c.quiet } : {},
154
- children: chipText(cli)
645
+ bold: true,
646
+ backgroundColor: c.surface,
647
+ ...c.entry ? { color: c.entry } : {},
648
+ ...dim ? { dimColor: true } : {},
649
+ children: ` ${text} `
155
650
  });
156
651
  }
157
652
  /** A small, dim, uppercase section label. */
158
653
  function Label({ children }) {
159
- const { c } = useTheme();
654
+ const { c, ascii } = useTheme();
160
655
  return /* @__PURE__ */ jsx(Text, {
161
656
  ...c.quiet ? { color: c.quiet } : { dimColor: true },
162
- children: children.toUpperCase()
657
+ children: plain(children.toUpperCase(), ascii)
163
658
  });
164
659
  }
165
660
  /** A bordered box. */
166
- function Card({ accent, width, children }) {
661
+ function Card({ accent, width, fill, children }) {
167
662
  const { c, ascii } = useTheme();
168
663
  const color = accent ?? c.rule;
169
664
  return /* @__PURE__ */ jsx(Box, {
@@ -171,6 +666,7 @@ function Card({ accent, width, children }) {
171
666
  borderStyle: ascii ? "classic" : "round",
172
667
  ...color ? { borderColor: color } : {},
173
668
  paddingX: 1,
669
+ ...fill && c.surface ? { backgroundColor: c.surface } : {},
174
670
  ...width !== void 0 ? { width } : {},
175
671
  children
176
672
  });
@@ -188,12 +684,161 @@ function relTime(iso, now = Date.now()) {
188
684
  const d = Math.floor(h / 24);
189
685
  return d === 1 ? "1 day ago" : `${d} days ago`;
190
686
  }
687
+ /** "now", "3m", "2h", "4d": always short enough for a narrow column. */
688
+ function relCompact(iso, now = Date.now()) {
689
+ const t = Date.parse(iso);
690
+ if (Number.isNaN(t)) return "";
691
+ const m = Math.floor(Math.max(0, now - t) / 6e4);
692
+ if (m < 1) return "now";
693
+ if (m < 60) return `${m}m`;
694
+ const h = Math.floor(m / 60);
695
+ if (h < 24) return `${h}h`;
696
+ return `${Math.floor(h / 24)}d`;
697
+ }
698
+ /**
699
+ * The home folder as `~`. Knows this machine's home and the usual homes of other machines:
700
+ * `/home/x`, `/Users/x`, and `C:\Users\x` or `C:/Users/x` in any case. Separators stay as given.
701
+ */
702
+ function homePath(path, home = homedir()) {
703
+ const h = home.replace(/[\\/]+$/, "");
704
+ if (h !== "" && path.length >= h.length) {
705
+ const head = path.slice(0, h.length);
706
+ const next = path[h.length];
707
+ if ((/^[A-Za-z]:/.test(h) ? head.toLowerCase() === h.toLowerCase() : head === h) && (next === void 0 || next === "/" || next === "\\")) return `~${path.slice(h.length)}`;
708
+ }
709
+ return path.replace(/^(?:\/home\/[^/]+|\/Users\/[^/]+|[A-Za-z]:[\\/]Users[\\/][^\\/]+)(?=[\\/]|$)/i, "~");
710
+ }
711
+ /**
712
+ * A folder for a column `width` wide: home as `~`, and when it is too long, cut from the left so
713
+ * the end stays: `…/NOV-2026/win-trouble`. Separators are kept as the path has them.
714
+ */
715
+ function shortPath$1(path, width, ascii = false, home) {
716
+ const dots = ascii ? "..." : "…";
717
+ const p = homePath(path, home);
718
+ if (width <= 0) return "";
719
+ if ([...p].length <= width) return p;
720
+ const sep = p.lastIndexOf("\\") > p.lastIndexOf("/") ? "\\" : "/";
721
+ const parts = p.split(/[\\/]+/).filter((x) => x !== "");
722
+ const kept = [];
723
+ let used = dots.length + 1;
724
+ for (let i = parts.length - 1; i >= 0; i--) {
725
+ const part = parts[i] ?? "";
726
+ const add = [...part].length + (kept.length > 0 ? 1 : 0);
727
+ if (used + add > width) break;
728
+ used += add;
729
+ kept.unshift(part);
730
+ }
731
+ if (kept.length > 0) return `${dots}${sep}${kept.join(sep)}`;
732
+ const last = [...parts[parts.length - 1] ?? p];
733
+ return dots + last.slice(Math.max(0, last.length - (width - dots.length))).join("");
734
+ }
735
+ /** A full-width bar on the surface colour. */
736
+ function Band({ width, children }) {
737
+ const { c } = useTheme();
738
+ return /* @__PURE__ */ jsx(Box, {
739
+ width,
740
+ height: 1,
741
+ flexShrink: 0,
742
+ paddingX: 1,
743
+ ...c.surface ? { backgroundColor: c.surface } : {},
744
+ children
745
+ });
746
+ }
747
+ /** A horizontal rule. */
748
+ function Rule({ width }) {
749
+ const { c, ascii } = useTheme();
750
+ return /* @__PURE__ */ jsx(Text, {
751
+ ...c.rule ? { color: c.rule } : { dimColor: true },
752
+ children: (ascii ? "-" : "─").repeat(Math.max(0, width))
753
+ });
754
+ }
755
+ /**
756
+ * The side panel: sunken colour, a vertical rule on its left. `width` includes the rule and one
757
+ * column of padding each side, so the text inside gets `width - 3`.
758
+ */
759
+ const paneInner = (width) => Math.max(4, width - 3);
760
+ function Pane({ width, height, children }) {
761
+ const { c, ascii } = useTheme();
762
+ return /* @__PURE__ */ jsx(Box, {
763
+ width,
764
+ flexShrink: 0,
765
+ flexDirection: "column",
766
+ overflow: "hidden",
767
+ borderStyle: ascii ? "classic" : "single",
768
+ borderTop: false,
769
+ borderRight: false,
770
+ borderBottom: false,
771
+ ...c.rule ? { borderColor: c.rule } : { borderDimColor: true },
772
+ ...c.sunken ? {
773
+ backgroundColor: c.sunken,
774
+ borderLeftBackgroundColor: c.sunken
775
+ } : {},
776
+ paddingX: 1,
777
+ ...height !== void 0 ? { height } : {},
778
+ children
779
+ });
780
+ }
781
+ /**
782
+ * Split a screen into main part and side panel. On very wide terminals the main part stops at
783
+ * `maxMain` and the panel sits right after it. Without a panel, main is capped alone.
784
+ */
785
+ function splitWidths(columns, panel, opts = {}) {
786
+ const maxMain = opts.maxMain ?? 130;
787
+ if (!panel) return {
788
+ mainW: Math.min(columns, maxMain),
789
+ panelW: 0
790
+ };
791
+ const panelW = opts.panelW ?? (columns >= 160 ? 40 : 36);
792
+ return {
793
+ mainW: Math.min(maxMain, Math.max(30, columns - panelW)),
794
+ panelW
795
+ };
796
+ }
797
+ /** One cell of a table row: `w` columns wide, the last `gap` of them empty. Never overflows. */
798
+ function Cell({ w, gap = 2, color, bold, dim, children }) {
799
+ return /* @__PURE__ */ jsx(Box, {
800
+ width: w,
801
+ flexShrink: 0,
802
+ children: /* @__PURE__ */ jsx(Ell, {
803
+ width: Math.max(0, w - gap),
804
+ color,
805
+ ...bold ? { bold } : {},
806
+ ...dim ? { dim } : {},
807
+ children
808
+ })
809
+ });
810
+ }
811
+ /** A table row. The selected one gets the highlight across the whole width. */
812
+ function Row({ width, selected, children }) {
813
+ const { c } = useTheme();
814
+ return /* @__PURE__ */ jsx(Box, {
815
+ width,
816
+ flexShrink: 0,
817
+ ...selected && c.select ? { backgroundColor: c.select } : {},
818
+ children
819
+ });
820
+ }
821
+ /** The header row of a table: small, dim capitals. */
822
+ function HeaderRow({ width, cols }) {
823
+ const { c } = useTheme();
824
+ return /* @__PURE__ */ jsx(Box, {
825
+ width,
826
+ flexShrink: 0,
827
+ children: cols.map((col) => /* @__PURE__ */ jsx(Cell, {
828
+ w: col.w,
829
+ ...col.gap !== void 0 ? { gap: col.gap } : {},
830
+ color: c.quiet,
831
+ dim: !c.quiet,
832
+ children: col.text.toUpperCase()
833
+ }, col.text || col.w))
834
+ });
835
+ }
191
836
  /** A list that keeps the selected row in view and says how many rows are hidden. */
192
- function ScrollList({ items, selected, height, renderItem, keyOf }) {
837
+ function ScrollList({ items, selected, height, renderItem, keyOf, onSelect, onActivate, isActive }) {
193
838
  const { c, ascii } = useTheme();
839
+ const box = useRef(null);
194
840
  const h = Math.max(1, height);
195
841
  const total = items.length;
196
- if (total === 0) return null;
197
842
  let slots = h;
198
843
  let start = 0;
199
844
  if (total > h) for (let pass = 0; pass < 3; pass++) {
@@ -203,11 +848,45 @@ function ScrollList({ items, selected, height, renderItem, keyOf }) {
203
848
  start = Math.max(0, Math.min(start, total - slots));
204
849
  }
205
850
  const end = Math.min(total, start + slots);
851
+ const view = useRef({
852
+ start,
853
+ end,
854
+ selected,
855
+ total
856
+ });
857
+ view.current = {
858
+ start,
859
+ end,
860
+ selected,
861
+ total
862
+ };
863
+ useClick(box, (e) => {
864
+ if (e.button !== "left") return;
865
+ const v = view.current;
866
+ const kids = box.current?.childNodes ?? [];
867
+ const first = v.start > 0 ? 1 : 0;
868
+ for (let i = v.start; i < v.end; i++) {
869
+ const kid = kids[first + i - v.start];
870
+ const y = kid && "yogaNode" in kid ? kid.yogaNode : void 0;
871
+ if (!y) continue;
872
+ const top = y.getComputedTop();
873
+ if (e.y < top || e.y >= top + y.getComputedHeight()) continue;
874
+ if (i !== v.selected) onSelect?.(i);
875
+ if (i === v.selected || e.double) onActivate?.(i);
876
+ return;
877
+ }
878
+ }, { isActive: (isActive ?? true) && (onSelect !== void 0 || onActivate !== void 0) });
879
+ useWheel(box, (d) => {
880
+ const v = view.current;
881
+ onSelect?.(Math.max(0, Math.min(v.total - 1, v.selected + d)));
882
+ }, { isActive: (isActive ?? true) && onSelect !== void 0 });
883
+ if (total === 0) return null;
206
884
  const above = start;
207
885
  const below = total - end;
208
886
  const dots = ascii ? "..." : "…";
209
887
  const quiet = c.quiet ? { color: c.quiet } : { dimColor: true };
210
888
  return /* @__PURE__ */ jsxs(Box, {
889
+ ref: box,
211
890
  flexDirection: "column",
212
891
  children: [
213
892
  above > 0 ? /* @__PURE__ */ jsx(Text, {
@@ -223,14 +902,94 @@ function ScrollList({ items, selected, height, renderItem, keyOf }) {
223
902
  });
224
903
  }
225
904
  /**
905
+ * Text that scrolls by line. Each entry of `lines` is exactly one row (cut or wrapped by the
906
+ * caller). The wheel scrolls it while the pointer is over it; PgUp/PgDn/Home/End scroll it while
907
+ * `isActive`. With `stickToBottom` it follows new lines while you are at the bottom and stays put
908
+ * once you scroll up. `onAtBottomChange` says when you are at the bottom or not, and `handleRef`
909
+ * lets the screen jump to the newest line ("↓ 3 new").
910
+ */
911
+ function ScrollView({ lines, height, stickToBottom = false, isActive = true, onAtBottomChange, onReachTop, handleRef, wheelStep = 3 }) {
912
+ const box = useRef(null);
913
+ const h = Math.max(1, height);
914
+ const max = Math.max(0, lines.length - h);
915
+ const [pos, setPos] = useState({
916
+ top: 0,
917
+ pinned: true
918
+ });
919
+ const top = stickToBottom && pos.pinned ? max : Math.min(pos.top, max);
920
+ const atBottom = top >= max;
921
+ const cur = useRef({
922
+ top,
923
+ max,
924
+ h
925
+ });
926
+ cur.current = {
927
+ top,
928
+ max,
929
+ h
930
+ };
931
+ const moveTo = (to) => {
932
+ const n = Math.max(0, Math.min(cur.current.max, to));
933
+ cur.current.top = n;
934
+ setPos({
935
+ top: n,
936
+ pinned: n >= cur.current.max
937
+ });
938
+ return n;
939
+ };
940
+ const reach = useRef(onReachTop);
941
+ reach.current = onReachTop;
942
+ const up = (to) => {
943
+ if (moveTo(to) === 0) reach.current?.();
944
+ };
945
+ const by = (d) => d < 0 ? up(cur.current.top + d) : void moveTo(cur.current.top + d);
946
+ useImperativeHandle(handleRef, () => ({
947
+ scrollToBottom: () => void moveTo(Number.POSITIVE_INFINITY),
948
+ scrollToTop: () => void moveTo(0),
949
+ scrollBy: (n) => {
950
+ const t = Math.max(0, cur.current.top + n);
951
+ cur.current.top = t;
952
+ setPos({
953
+ top: t,
954
+ pinned: false
955
+ });
956
+ }
957
+ }));
958
+ useWheel(box, (d) => by(d * wheelStep), { isActive });
959
+ useInput((_input, key) => {
960
+ if (key.pageUp) by(-Math.max(1, cur.current.h - 1));
961
+ else if (key.pageDown) by(Math.max(1, cur.current.h - 1));
962
+ else if (key.home) up(0);
963
+ else if (key.end) moveTo(Number.POSITIVE_INFINITY);
964
+ }, { isActive });
965
+ const told = useRef(void 0);
966
+ useEffect(() => {
967
+ if (told.current === atBottom) return;
968
+ told.current = atBottom;
969
+ onAtBottomChange?.(atBottom);
970
+ });
971
+ return /* @__PURE__ */ jsx(Box, {
972
+ ref: box,
973
+ flexDirection: "column",
974
+ height: h,
975
+ overflow: "hidden",
976
+ children: lines.slice(top, top + h).map((line, i) => /* @__PURE__ */ jsx(Box, {
977
+ flexShrink: 0,
978
+ children: typeof line === "string" ? /* @__PURE__ */ jsx(Text, { children: line }) : line
979
+ }, top + i))
980
+ });
981
+ }
982
+ /**
226
983
  * The shell provides this. A text box with unsent text tells it when Ctrl+C cleared that text,
227
984
  * so the shell shows a hint instead of quitting.
228
985
  */
229
986
  const DraftContext = createContext({ cleared: () => void 0 });
230
987
  const DraftProvider = DraftContext.Provider;
231
988
  /** A small input. Enter sends; Shift+Enter (or Ctrl+J) adds a line when `multiline`. */
232
- function TextBox({ value, onChange, onSubmit, placeholder, focus, multiline, onCancel }) {
989
+ function TextBox({ value, onChange, onSubmit, placeholder, focus, multiline, onCancel, onFocusRequest }) {
233
990
  const { c, ascii } = useTheme();
991
+ const area = useRef(null);
992
+ useClick(area, () => onFocusRequest?.(), { isActive: onFocusRequest !== void 0 });
234
993
  const [cursor, setCursor] = useState(value.length);
235
994
  const pos = Math.min(cursor, value.length);
236
995
  const draft = useContext(DraftContext);
@@ -279,24 +1038,28 @@ function TextBox({ value, onChange, onSubmit, placeholder, focus, multiline, onC
279
1038
  }
280
1039
  }, { isActive: focus });
281
1040
  const quiet = c.quiet ? { color: c.quiet } : { dimColor: true };
282
- if (value.length === 0) return /* @__PURE__ */ jsxs(Text, { children: [focus ? /* @__PURE__ */ jsx(Text, {
1041
+ const wrap = (node) => onFocusRequest ? /* @__PURE__ */ jsx(Box, {
1042
+ ref: area,
1043
+ children: node
1044
+ }) : node;
1045
+ if (value.length === 0) return wrap(/* @__PURE__ */ jsxs(Text, { children: [focus ? /* @__PURE__ */ jsx(Text, {
283
1046
  inverse: true,
284
1047
  children: " "
285
1048
  }) : null, /* @__PURE__ */ jsx(Text, {
286
1049
  ...quiet,
287
1050
  children: placeholder ?? ""
288
- })] });
1051
+ })] }));
289
1052
  const before = value.slice(0, pos);
290
1053
  const at = value[pos] ?? " ";
291
1054
  const after = value.slice(pos + 1);
292
- return /* @__PURE__ */ jsxs(Text, { children: [
1055
+ return wrap(/* @__PURE__ */ jsxs(Text, { children: [
293
1056
  before,
294
1057
  focus ? /* @__PURE__ */ jsx(Text, {
295
1058
  inverse: true,
296
1059
  children: at === "\n" ? " \n" : at
297
1060
  }) : at,
298
1061
  after
299
- ] });
1062
+ ] }));
300
1063
  }
301
1064
  // src/tui/palette.tsx
302
1065
  /** The command palette and the all-keys help, drawn over the screen body. */
@@ -329,7 +1092,7 @@ function filterCommands(cmds, query) {
329
1092
  })).filter((x) => x.s !== void 0).sort((a, b) => b.s - a.s || (a.c.rank ?? 50) - (b.c.rank ?? 50) || a.i - b.i).map((x) => x.c);
330
1093
  }
331
1094
  function Palette({ commands, width, height, onClose }) {
332
- const { c } = useTheme();
1095
+ const { c, ascii } = useTheme();
333
1096
  const [query, setQuery] = useState("");
334
1097
  const [sel, setSel] = useState(0);
335
1098
  const shown = useMemo(() => filterCommands(commands, query), [commands, query]);
@@ -339,65 +1102,89 @@ function Palette({ commands, width, height, onClose }) {
339
1102
  if (key.upArrow) setSel(Math.max(0, index - 1));
340
1103
  else if (key.downArrow) setSel(Math.min(shown.length - 1, index + 1));
341
1104
  });
342
- const run = () => {
343
- const cmd = shown[index];
1105
+ const runCmd = (cmd) => {
344
1106
  onClose();
345
1107
  if (cmd) Promise.resolve(cmd.run()).catch(() => void 0);
346
1108
  };
1109
+ const run = () => runCmd(shown[index]);
1110
+ const list = useRef(null);
1111
+ useWheel(list, (d) => setSel(Math.max(0, Math.min(shown.length - 1, index + d))));
347
1112
  const inner = Math.max(10, width - 4);
348
1113
  const start = Math.max(0, Math.min(index - rowsMax + 1, shown.length - rowsMax));
349
1114
  const view = shown.slice(start, start + rowsMax);
350
- return /* @__PURE__ */ jsxs(Card, {
351
- ...c.entry ? { accent: c.entry } : {},
352
- width,
353
- children: [
354
- /* @__PURE__ */ jsx(TextBox, {
355
- value: query,
356
- onChange: (v) => {
357
- setQuery(v);
358
- setSel(0);
359
- },
360
- onSubmit: run,
361
- onCancel: onClose,
362
- placeholder: "Type to find something to do",
363
- focus: true
364
- }),
365
- /* @__PURE__ */ jsx(Box, {
366
- flexDirection: "column",
367
- marginTop: 1,
368
- children: view.length === 0 ? /* @__PURE__ */ jsx(Text, {
369
- ...c.quiet ? { color: c.quiet } : { dimColor: true },
370
- children: "Nothing matches that."
371
- }) : view.map((cmd) => {
372
- const on = cmd === shown[index];
373
- return /* @__PURE__ */ jsxs(Box, { children: [
374
- /* @__PURE__ */ jsxs(Text, {
375
- ...on ? { inverse: true } : {},
376
- children: [on ? "› " : " ", /* @__PURE__ */ jsx(Ell, {
377
- width: Math.max(4, inner - 12),
378
- children: cmd.label
379
- })]
380
- }),
381
- /* @__PURE__ */ jsx(Box, { flexGrow: 1 }),
382
- /* @__PURE__ */ jsx(Text, {
383
- ...c.quiet ? { color: c.quiet } : { dimColor: true },
384
- children: cmd.key ?? ""
385
- })
386
- ] }, cmd.id);
387
- })
388
- }),
389
- /* @__PURE__ */ jsx(Box, {
390
- marginTop: 1,
391
- children: /* @__PURE__ */ jsx(Text, {
392
- ...c.quiet ? { color: c.quiet } : { dimColor: true },
393
- children: "↑↓ move · ⏎ run · Esc close"
1115
+ return /* @__PURE__ */ jsx(Clickable, {
1116
+ onClick: () => void 0,
1117
+ children: /* @__PURE__ */ jsxs(Card, {
1118
+ ...c.entry ? { accent: c.entry } : {},
1119
+ fill: true,
1120
+ width,
1121
+ children: [
1122
+ /* @__PURE__ */ jsx(TextBox, {
1123
+ value: query,
1124
+ onChange: (v) => {
1125
+ setQuery(v);
1126
+ setSel(0);
1127
+ },
1128
+ onSubmit: run,
1129
+ onCancel: onClose,
1130
+ placeholder: "Type to find something to do",
1131
+ focus: true
1132
+ }),
1133
+ /* @__PURE__ */ jsx(Box, {
1134
+ ref: list,
1135
+ flexDirection: "column",
1136
+ marginTop: 1,
1137
+ children: view.length === 0 ? /* @__PURE__ */ jsx(Text, {
1138
+ ...c.quiet ? { color: c.quiet } : { dimColor: true },
1139
+ children: "Nothing matches that."
1140
+ }) : view.map((cmd) => {
1141
+ const on = cmd === shown[index];
1142
+ return /* @__PURE__ */ jsxs(PaletteRow, {
1143
+ onPick: () => runCmd(cmd),
1144
+ children: [
1145
+ /* @__PURE__ */ jsxs(Text, {
1146
+ ...on ? c.select ? {
1147
+ backgroundColor: c.select,
1148
+ bold: true
1149
+ } : { inverse: true } : {},
1150
+ children: [on ? ascii ? "> " : "› " : " ", /* @__PURE__ */ jsx(Ell, {
1151
+ width: Math.max(4, inner - 12),
1152
+ children: cmd.label
1153
+ })]
1154
+ }),
1155
+ /* @__PURE__ */ jsx(Box, { flexGrow: 1 }),
1156
+ /* @__PURE__ */ jsx(Text, {
1157
+ ...c.quiet ? { color: c.quiet } : { dimColor: true },
1158
+ children: plain(cmd.key ?? "", ascii)
1159
+ })
1160
+ ]
1161
+ }, cmd.id);
1162
+ })
1163
+ }),
1164
+ /* @__PURE__ */ jsx(Box, {
1165
+ marginTop: 1,
1166
+ children: /* @__PURE__ */ jsx(Text, {
1167
+ ...c.quiet ? { color: c.quiet } : { dimColor: true },
1168
+ children: plain("↑↓ move · ⏎ run · Esc close", ascii)
1169
+ })
394
1170
  })
395
- })
396
- ]
1171
+ ]
1172
+ })
1173
+ });
1174
+ }
1175
+ /** One palette row: a click selects it and runs it. */
1176
+ function PaletteRow({ onPick, children }) {
1177
+ const ref = useRef(null);
1178
+ useClick(ref, (e) => {
1179
+ if (e.button === "left") onPick();
1180
+ });
1181
+ return /* @__PURE__ */ jsx(Box, {
1182
+ ref,
1183
+ children
397
1184
  });
398
1185
  }
399
1186
  function Help({ screenTitle, screenKeys, width, onClose }) {
400
- const { c } = useTheme();
1187
+ const { c, ascii } = useTheme();
401
1188
  useInput((input, key) => {
402
1189
  if (key.escape || input === "?" || input === "q" || key.return) onClose();
403
1190
  });
@@ -432,38 +1219,55 @@ function Help({ screenTitle, screenKeys, width, onClose }) {
432
1219
  children: /* @__PURE__ */ jsx(Text, {
433
1220
  bold: true,
434
1221
  ...c.ink ? { color: c.ink } : {},
435
- children: k.key
1222
+ children: plain(k.key, ascii)
436
1223
  })
437
1224
  }), /* @__PURE__ */ jsx(Ell, {
438
1225
  width: Math.max(8, width - 20),
439
- children: k.label
1226
+ children: plain(k.label, ascii)
440
1227
  })] }, `${k.key}-${k.label}`);
441
- return /* @__PURE__ */ jsxs(Card, {
442
- ...c.entry ? { accent: c.entry } : {},
443
- width,
444
- children: [
445
- /* @__PURE__ */ jsx(Label, { children: "Everywhere" }),
446
- global.map(row),
447
- /* @__PURE__ */ jsx(Box, {
448
- marginTop: 1,
449
- children: /* @__PURE__ */ jsx(Label, { children: screenTitle })
450
- }),
451
- screenKeys.length === 0 ? /* @__PURE__ */ jsx(Text, {
452
- ...c.quiet ? { color: c.quiet } : { dimColor: true },
453
- children: "No other keys here."
454
- }) : screenKeys.map(row),
455
- /* @__PURE__ */ jsx(Box, {
456
- marginTop: 1,
457
- children: /* @__PURE__ */ jsx(Text, {
1228
+ return /* @__PURE__ */ jsx(Clickable, {
1229
+ onClick: () => void 0,
1230
+ children: /* @__PURE__ */ jsxs(Card, {
1231
+ ...c.entry ? { accent: c.entry } : {},
1232
+ fill: true,
1233
+ width,
1234
+ children: [
1235
+ /* @__PURE__ */ jsx(Label, { children: "Everywhere" }),
1236
+ global.map(row),
1237
+ /* @__PURE__ */ jsx(Box, {
1238
+ marginTop: 1,
1239
+ children: /* @__PURE__ */ jsx(Label, { children: screenTitle })
1240
+ }),
1241
+ screenKeys.length === 0 ? /* @__PURE__ */ jsx(Text, {
458
1242
  ...c.quiet ? { color: c.quiet } : { dimColor: true },
459
- children: "Esc or ? to close"
1243
+ children: "No other keys here."
1244
+ }) : screenKeys.map(row),
1245
+ /* @__PURE__ */ jsx(Box, {
1246
+ marginTop: 1,
1247
+ children: /* @__PURE__ */ jsx(Text, {
1248
+ ...c.quiet ? { color: c.quiet } : { dimColor: true },
1249
+ children: "Esc or ? to close"
1250
+ })
460
1251
  })
461
- })
462
- ]
1252
+ ]
1253
+ })
463
1254
  });
464
1255
  }
465
1256
  // src/tui/screens/kit.tsx
466
1257
  /** Small helpers the New, Devices and Setup screens share. */
1258
+ /** A Box that takes left clicks and/or the wheel. Other props go to the Box. */
1259
+ function Hit({ onClick, onWheel, isActive = true, children, ...box }) {
1260
+ const ref = useRef(null);
1261
+ useClick(ref, (e) => {
1262
+ if (e.button === "left") onClick?.(e);
1263
+ }, { isActive: isActive && onClick !== void 0 });
1264
+ useWheel(ref, (d) => onWheel?.(d), { isActive: isActive && onWheel !== void 0 });
1265
+ return /* @__PURE__ */ jsx(Box, {
1266
+ ref,
1267
+ ...box,
1268
+ children
1269
+ });
1270
+ }
467
1271
  /** A counter that ticks every `ms` while `on`. Drives spinners and countdowns. */
468
1272
  function useTick(on, ms = 120) {
469
1273
  const [n, setN] = useState(0);
@@ -745,6 +1549,16 @@ function DevicesScreen(props) {
745
1549
  actions,
746
1550
  toast
747
1551
  ]);
1552
+ const removeSelected = () => {
1553
+ const d = machines[at];
1554
+ if (!d) return;
1555
+ if (d.self) return toast("That's this machine. Remove it from another machine.", "warn");
1556
+ setAsk({
1557
+ k: "revoke",
1558
+ device: d
1559
+ });
1560
+ };
1561
+ const closePair = () => setPhase({ k: "idle" });
748
1562
  useInput((input, key) => {
749
1563
  if (ask) {
750
1564
  if (input === "y") return void answer(true);
@@ -764,34 +1578,41 @@ function DevicesScreen(props) {
764
1578
  if (key.downArrow) return setSel(Math.min(machines.length - 1, at + 1));
765
1579
  if (input === "p") return void startPairing();
766
1580
  if (input === "u") return void actions.openAccountPage();
767
- if (input === "r") {
768
- const d = machines[at];
769
- if (!d) return;
770
- if (d.self) return toast("That's this machine. Remove it from another machine.", "warn");
771
- return setAsk({
772
- k: "revoke",
773
- device: d
774
- });
775
- }
1581
+ if (input === "r") return removeSelected();
776
1582
  if (input === "R") return setAsk({ k: "all" });
777
1583
  }, { isActive: active && !typing });
778
1584
  const wide = layout === "wide";
779
- const sideW = wide ? 48 : 0;
780
- const mainW = Math.max(30, columns - sideW - (wide ? 3 : 2));
1585
+ const split = splitWidths(columns, wide, {
1586
+ panelW: 50,
1587
+ maxMain: 100
1588
+ });
1589
+ const sideW = paneInner(split.panelW);
1590
+ const mainW = wide ? split.mainW - 2 : Math.min(columns, 100);
781
1591
  const quiet = c.quiet ? { color: c.quiet } : { dimColor: true };
782
1592
  const pairPanel = (width) => /* @__PURE__ */ jsxs(Box, {
783
1593
  flexDirection: "column",
784
1594
  width,
785
- children: [/* @__PURE__ */ jsx(Label, { children: "Add a machine" }), phase.k === "idle" ? /* @__PURE__ */ jsx(Text, {
786
- ...quiet,
787
- children: pitch || !state.relay ? "Sign in first (u)." : "Press p to link another machine."
1595
+ children: [/* @__PURE__ */ jsx(Label, { children: "Add a machine" }), phase.k === "idle" ? /* @__PURE__ */ jsx(Hit, {
1596
+ onClick: () => void (pitch || !state.relay ? actions.openAccountPage() : startPairing()),
1597
+ isActive: active,
1598
+ children: /* @__PURE__ */ jsx(Text, {
1599
+ ...quiet,
1600
+ children: pitch || !state.relay ? "Sign in first (u)." : "Press p to link another machine."
1601
+ })
788
1602
  }) : /* @__PURE__ */ jsxs(Fragment, { children: [
789
1603
  /* @__PURE__ */ jsx(Text, { children: "1. On the other machine, run" }),
790
1604
  /* @__PURE__ */ jsx(Text, {
791
1605
  bold: true,
792
1606
  children: " conveno devices join"
793
1607
  }),
794
- phase.k === "waiting" ? /* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Spinner, { tick }), ` Waiting for it${m.ellipsis} ${clock(phase.since + 3e5 - Date.now())}`] }) : null,
1608
+ phase.k === "waiting" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Spinner, { tick }), ` Waiting for it${m.ellipsis} ${clock(phase.since + 3e5 - Date.now())}`] }), /* @__PURE__ */ jsx(Hit, {
1609
+ onClick: () => void decline(),
1610
+ isActive: active,
1611
+ children: /* @__PURE__ */ jsx(Text, {
1612
+ ...quiet,
1613
+ children: "Esc stops"
1614
+ })
1615
+ })] }) : null,
795
1616
  phase.k === "confirm" ? /* @__PURE__ */ jsxs(Fragment, { children: [
796
1617
  /* @__PURE__ */ jsx(Text, { children: "2. This machine shows" }),
797
1618
  /* @__PURE__ */ jsx(Card, {
@@ -821,20 +1642,52 @@ function DevicesScreen(props) {
821
1642
  ...c.error ? { color: c.error } : {},
822
1643
  children: phase.error
823
1644
  }) : null,
824
- /* @__PURE__ */ jsx(Text, {
825
- ...quiet,
826
- children: `Wrong or different? Press Esc and nothing gets linked. ${clock(phase.expiresAt - Date.now())} left`
1645
+ /* @__PURE__ */ jsxs(Box, {
1646
+ flexWrap: "wrap",
1647
+ children: [
1648
+ /* @__PURE__ */ jsx(Text, {
1649
+ ...quiet,
1650
+ children: "Wrong or different? "
1651
+ }),
1652
+ /* @__PURE__ */ jsx(Hit, {
1653
+ onClick: () => void decline(),
1654
+ isActive: active,
1655
+ children: /* @__PURE__ */ jsx(Text, {
1656
+ ...quiet,
1657
+ children: "Press Esc"
1658
+ })
1659
+ }),
1660
+ /* @__PURE__ */ jsx(Text, {
1661
+ ...quiet,
1662
+ children: ` and nothing gets linked. ${clock(phase.expiresAt - Date.now())} left`
1663
+ })
1664
+ ]
827
1665
  })
828
1666
  ] }) : null,
829
- phase.k === "finishing" ? /* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Spinner, { tick }), ` Waiting for the other machine to confirm${m.ellipsis}`] }) : null,
830
- phase.k === "done" ? /* @__PURE__ */ jsx(Text, {
831
- ...c.ok ? { color: c.ok } : {},
832
- children: `${m.ok} Linked. Press ${m.enter}.`
1667
+ phase.k === "finishing" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Spinner, { tick }), ` Waiting for the other machine to confirm${m.ellipsis}`] }), /* @__PURE__ */ jsx(Hit, {
1668
+ onClick: () => void decline(),
1669
+ isActive: active,
1670
+ children: /* @__PURE__ */ jsx(Text, {
1671
+ ...quiet,
1672
+ children: "Esc stops"
1673
+ })
1674
+ })] }) : null,
1675
+ phase.k === "done" ? /* @__PURE__ */ jsx(Hit, {
1676
+ onClick: closePair,
1677
+ isActive: active,
1678
+ children: /* @__PURE__ */ jsx(Text, {
1679
+ ...c.ok ? { color: c.ok } : {},
1680
+ children: `${m.ok} Linked. Press ${m.enter}.`
1681
+ })
833
1682
  }) : null,
834
- phase.k === "failed" ? /* @__PURE__ */ jsx(Text, {
835
- ...c.error ? { color: c.error } : {},
836
- wrap: "wrap",
837
- children: `${m.error} ${phase.error} (${m.enter} to close)`
1683
+ phase.k === "failed" ? /* @__PURE__ */ jsx(Hit, {
1684
+ onClick: closePair,
1685
+ isActive: active,
1686
+ children: /* @__PURE__ */ jsx(Text, {
1687
+ ...c.error ? { color: c.error } : {},
1688
+ wrap: "wrap",
1689
+ children: `${m.error} ${phase.error} (${m.enter} to close)`
1690
+ })
838
1691
  }) : null
839
1692
  ] })]
840
1693
  });
@@ -848,14 +1701,18 @@ function DevicesScreen(props) {
848
1701
  children: [
849
1702
  /* @__PURE__ */ jsx(Label, { children: "Your machines" }),
850
1703
  /* @__PURE__ */ jsx(Text, { children: "Pro links your machines so sessions can talk across them." }),
851
- /* @__PURE__ */ jsxs(Text, { children: [
852
- "Press ",
853
- /* @__PURE__ */ jsx(Text, {
854
- bold: true,
855
- children: "u"
856
- }),
857
- " to sign in."
858
- ] }),
1704
+ /* @__PURE__ */ jsx(Hit, {
1705
+ onClick: () => void actions.openAccountPage(),
1706
+ isActive: active,
1707
+ children: /* @__PURE__ */ jsxs(Text, { children: [
1708
+ "Press ",
1709
+ /* @__PURE__ */ jsx(Text, {
1710
+ bold: true,
1711
+ children: "u"
1712
+ }),
1713
+ " to sign in."
1714
+ ] })
1715
+ }),
859
1716
  /* @__PURE__ */ jsx(Text, {
860
1717
  ...quiet,
861
1718
  children: "We only see machine names and message sizes. Never what's inside."
@@ -870,15 +1727,21 @@ function DevicesScreen(props) {
870
1727
  children: "This machine was removed from your account."
871
1728
  }), /* @__PURE__ */ jsx(Text, { children: "Run conveno devices reset here, then link it again." })]
872
1729
  });
873
- const nameW = Math.max(10, Math.min(24, mainW - 38));
1730
+ const longest = machines.reduce((n, d) => Math.max(n, [...d.self ? `${d.name} (this one)` : d.name].length), 0);
1731
+ const nameW = Math.max(12, Math.min(40, longest + 1));
1732
+ const sessionsW = Math.max(0, mainW - 2 - nameW - 2 - 9 - 2 - 20 - 2);
874
1733
  const showPair = pairing || phase.k === "done" || phase.k === "failed";
875
1734
  const table = /* @__PURE__ */ jsxs(Box, {
876
1735
  flexDirection: "column",
877
1736
  width: mainW,
878
1737
  children: [
879
- /* @__PURE__ */ jsx(Text, {
880
- ...quiet,
881
- children: accountLine(state.account)
1738
+ /* @__PURE__ */ jsx(Hit, {
1739
+ onClick: () => void actions.openAccountPage(),
1740
+ isActive: active,
1741
+ children: /* @__PURE__ */ jsx(Text, {
1742
+ ...quiet,
1743
+ children: accountLine(state.account)
1744
+ })
882
1745
  }),
883
1746
  state.relay && state.relay.state !== "connected" && state.relay.state !== "unpaired" ? /* @__PURE__ */ jsx(Text, {
884
1747
  ...quiet,
@@ -886,45 +1749,88 @@ function DevicesScreen(props) {
886
1749
  }) : null,
887
1750
  /* @__PURE__ */ jsx(Text, { children: " " }),
888
1751
  /* @__PURE__ */ jsx(Label, { children: `Your machines · ${machines.length}` }),
889
- machines.length === 0 ? /* @__PURE__ */ jsx(Text, {
890
- ...quiet,
891
- children: "Only this machine so far. Press p to add another."
892
- }) : /* @__PURE__ */ jsx(ScrollList, {
893
- items: machines,
894
- selected: at,
895
- height: Math.max(3, rows - 11),
896
- keyOf: (d) => d.deviceId,
897
- renderItem: (d, isSel) => /* @__PURE__ */ jsxs(Box, { children: [
898
- /* @__PURE__ */ jsx(Text, { children: isSel ? `${m.cursor} ` : " " }),
899
- /* @__PURE__ */ jsx(Box, {
900
- width: nameW,
901
- children: /* @__PURE__ */ jsx(Ell, {
902
- width: nameW,
903
- bold: isSel,
904
- children: d.self ? `${d.name} (this one)` : d.name
905
- })
906
- }),
907
- /* @__PURE__ */ jsx(Box, {
908
- width: 9,
909
- children: /* @__PURE__ */ jsx(Text, {
910
- ...d.online ? c.ok ? { color: c.ok } : {} : quiet,
911
- children: d.online ? "online" : "offline"
912
- })
913
- }),
914
- /* @__PURE__ */ jsx(Box, {
915
- width: 20,
916
- children: /* @__PURE__ */ jsx(Ell, {
917
- width: 20,
918
- dim: true,
919
- children: d.self ? "" : d.addedAt ? `added ${relTime(d.addedAt)}` : ""
1752
+ machines.length === 0 ? /* @__PURE__ */ jsx(Hit, {
1753
+ onClick: () => void startPairing(),
1754
+ isActive: active,
1755
+ children: /* @__PURE__ */ jsx(Text, {
1756
+ ...quiet,
1757
+ children: "Only this machine so far. Press p to add another."
1758
+ })
1759
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(HeaderRow, {
1760
+ width: mainW,
1761
+ cols: [
1762
+ {
1763
+ w: 2,
1764
+ text: "",
1765
+ gap: 0
1766
+ },
1767
+ {
1768
+ w: nameW + 2,
1769
+ text: "Machine"
1770
+ },
1771
+ {
1772
+ w: 11,
1773
+ text: "Status"
1774
+ },
1775
+ {
1776
+ w: 22,
1777
+ text: "Added"
1778
+ },
1779
+ {
1780
+ w: sessionsW,
1781
+ text: "Sessions",
1782
+ gap: 0
1783
+ }
1784
+ ]
1785
+ }), /* @__PURE__ */ jsx(Hit, {
1786
+ onWheel: (d) => setSel(Math.max(0, Math.min(machines.length - 1, at + (d < 0 ? -1 : 1)))),
1787
+ isActive: active,
1788
+ flexDirection: "column",
1789
+ children: /* @__PURE__ */ jsx(ScrollList, {
1790
+ items: machines,
1791
+ selected: at,
1792
+ height: Math.max(3, rows - 12),
1793
+ keyOf: (d) => d.deviceId,
1794
+ renderItem: (d, isSel, i) => /* @__PURE__ */ jsx(Hit, {
1795
+ onClick: () => setSel(i),
1796
+ isActive: active,
1797
+ children: /* @__PURE__ */ jsxs(Row, {
1798
+ width: mainW,
1799
+ selected: isSel,
1800
+ children: [
1801
+ /* @__PURE__ */ jsx(Cell, {
1802
+ w: 2,
1803
+ gap: 0,
1804
+ color: c.entry,
1805
+ children: isSel ? `${m.cursor} ` : " "
1806
+ }),
1807
+ /* @__PURE__ */ jsx(Cell, {
1808
+ w: nameW + 2,
1809
+ bold: isSel,
1810
+ children: d.self ? `${d.name} (this one)` : d.name
1811
+ }),
1812
+ /* @__PURE__ */ jsx(Cell, {
1813
+ w: 11,
1814
+ color: d.online ? c.ok : c.quiet,
1815
+ dim: !d.online,
1816
+ children: d.online ? "online" : "offline"
1817
+ }),
1818
+ /* @__PURE__ */ jsx(Cell, {
1819
+ w: 22,
1820
+ color: c.quiet,
1821
+ children: d.self ? "" : d.addedAt ? `added ${relTime(d.addedAt)}` : ""
1822
+ }),
1823
+ /* @__PURE__ */ jsx(Cell, {
1824
+ w: sessionsW,
1825
+ gap: 0,
1826
+ color: c.quiet,
1827
+ children: d.self ? "" : `${d.sessions} ${d.sessions === 1 ? "session" : "sessions"}`
1828
+ })
1829
+ ]
920
1830
  })
921
- }),
922
- /* @__PURE__ */ jsx(Text, {
923
- ...quiet,
924
- children: d.self ? "" : `${d.sessions} ${d.sessions === 1 ? "session" : "sessions"}`
925
1831
  })
926
- ] })
927
- }),
1832
+ })
1833
+ })] }),
928
1834
  state.devices?.conflict ? /* @__PURE__ */ jsx(Text, {
929
1835
  ...c.error ? { color: c.error } : {},
930
1836
  wrap: "wrap",
@@ -935,28 +1841,86 @@ function DevicesScreen(props) {
935
1841
  ...quiet,
936
1842
  children: "We only see machine names and message sizes. Never what's inside."
937
1843
  }),
938
- ask?.k === "revoke" ? /* @__PURE__ */ jsxs(Text, {
939
- wrap: "wrap",
940
- children: [/* @__PURE__ */ jsx(Text, {
941
- bold: true,
942
- children: `Remove ${ask.device.name}?`
943
- }), " It can't read or send messages for your sessions. y/n"]
944
- }) : ask?.k === "all" ? /* @__PURE__ */ jsxs(Text, {
945
- wrap: "wrap",
946
- children: [/* @__PURE__ */ jsx(Text, {
947
- bold: true,
948
- children: "Remove all machines?"
949
- }), " This opens your browser to sign in. Then run conveno devices reset here. y/n"]
950
- }) : /* @__PURE__ */ jsx(Text, {
951
- ...quiet,
952
- children: "Lost a machine? r removes it. R removes all of them (you sign in again first)."
1844
+ ask ? /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Box, {
1845
+ flexShrink: 1,
1846
+ children: /* @__PURE__ */ jsxs(Text, {
1847
+ wrap: "wrap",
1848
+ children: [/* @__PURE__ */ jsx(Text, {
1849
+ bold: true,
1850
+ children: ask.k === "revoke" ? `Remove ${ask.device.name}?` : "Remove all machines?"
1851
+ }), ask.k === "revoke" ? " It can't read or send messages for your sessions." : " This opens your browser to sign in. Then run conveno devices reset here."]
1852
+ })
1853
+ }), /* @__PURE__ */ jsxs(Box, {
1854
+ flexShrink: 0,
1855
+ children: [
1856
+ /* @__PURE__ */ jsx(Text, { children: " " }),
1857
+ /* @__PURE__ */ jsx(Hit, {
1858
+ onClick: () => void answer(true),
1859
+ isActive: active,
1860
+ children: /* @__PURE__ */ jsx(Text, { children: "y" })
1861
+ }),
1862
+ /* @__PURE__ */ jsx(Text, { children: "/" }),
1863
+ /* @__PURE__ */ jsx(Hit, {
1864
+ onClick: () => void answer(false),
1865
+ isActive: active,
1866
+ children: /* @__PURE__ */ jsx(Text, { children: "n" })
1867
+ })
1868
+ ]
1869
+ })] }) : /* @__PURE__ */ jsxs(Box, {
1870
+ flexWrap: "wrap",
1871
+ children: [
1872
+ /* @__PURE__ */ jsx(Hit, {
1873
+ onClick: () => void startPairing(),
1874
+ isActive: active,
1875
+ children: /* @__PURE__ */ jsx(Text, {
1876
+ ...quiet,
1877
+ children: "p adds a machine"
1878
+ })
1879
+ }),
1880
+ /* @__PURE__ */ jsx(Text, {
1881
+ ...quiet,
1882
+ children: ". Lost a machine? "
1883
+ }),
1884
+ /* @__PURE__ */ jsx(Hit, {
1885
+ onClick: removeSelected,
1886
+ isActive: active,
1887
+ children: /* @__PURE__ */ jsx(Text, {
1888
+ ...quiet,
1889
+ children: "r removes it"
1890
+ })
1891
+ }),
1892
+ /* @__PURE__ */ jsx(Text, {
1893
+ ...quiet,
1894
+ children: ". "
1895
+ }),
1896
+ /* @__PURE__ */ jsx(Hit, {
1897
+ onClick: () => setAsk({ k: "all" }),
1898
+ isActive: active,
1899
+ children: /* @__PURE__ */ jsx(Text, {
1900
+ ...quiet,
1901
+ children: "R removes all of them"
1902
+ })
1903
+ }),
1904
+ /* @__PURE__ */ jsx(Text, {
1905
+ ...quiet,
1906
+ children: " (you sign in again first)."
1907
+ })
1908
+ ]
953
1909
  })
954
1910
  ]
955
1911
  });
956
1912
  if (wide) return /* @__PURE__ */ jsxs(Box, {
957
1913
  flexDirection: "row",
958
- gap: 2,
959
- children: [table, pairPanel(sideW)]
1914
+ height: rows,
1915
+ children: [/* @__PURE__ */ jsx(Box, {
1916
+ width: split.mainW,
1917
+ flexShrink: 0,
1918
+ children: table
1919
+ }), /* @__PURE__ */ jsx(Pane, {
1920
+ width: split.panelW,
1921
+ height: rows,
1922
+ children: pairPanel(sideW)
1923
+ })]
960
1924
  });
961
1925
  return showPair ? pairPanel(Math.min(columns - 2, 70)) : table;
962
1926
  }
@@ -1210,12 +2174,31 @@ function NewScreen(props) {
1210
2174
  if (key.downArrow) return move(1);
1211
2175
  }, { isActive: active });
1212
2176
  const wide = layout === "wide";
1213
- const sideW = wide ? 46 : 0;
1214
- const mainW = Math.max(30, columns - sideW - (wide ? 3 : 2));
1215
- const label = (f, text) => /* @__PURE__ */ jsx(Text, {
1216
- ...field === f ? { bold: true } : {},
1217
- ...c.quiet && field !== f ? { color: c.quiet } : {},
1218
- children: `${field === f ? m.cursor : " "} ${text.toUpperCase()}`
2177
+ const split = splitWidths(columns, wide, {
2178
+ panelW: 46,
2179
+ maxMain: 100
2180
+ });
2181
+ const sideW = paneInner(split.panelW);
2182
+ const mainW = wide ? split.mainW - 2 : Math.min(columns, 100);
2183
+ const fieldW = Math.max(20, Math.min(72, mainW - 4));
2184
+ const focusField = (f) => {
2185
+ if (!busy) setField(f);
2186
+ };
2187
+ const field_ = (f, node) => /* @__PURE__ */ jsx(Hit, {
2188
+ onClick: () => focusField(f),
2189
+ marginLeft: 2,
2190
+ width: fieldW,
2191
+ paddingX: 1,
2192
+ ...c.surface ? { backgroundColor: c.surface } : {},
2193
+ children: node
2194
+ });
2195
+ const label = (f, text) => /* @__PURE__ */ jsx(Hit, {
2196
+ onClick: () => focusField(f),
2197
+ children: /* @__PURE__ */ jsx(Text, {
2198
+ ...field === f ? { bold: true } : {},
2199
+ ...c.quiet && field !== f ? { color: c.quiet } : {},
2200
+ children: `${field === f ? m.cursor : " "} ${text.toUpperCase()}`
2201
+ })
1219
2202
  });
1220
2203
  const steps = [
1221
2204
  ...mode === "acp" && cli && needsHelper(cli.cli) ? [{ text: `getting the ${cli.label} helper (first time only)` }] : [],
@@ -1232,10 +2215,11 @@ function NewScreen(props) {
1232
2215
  }) : [];
1233
2216
  return /* @__PURE__ */ jsxs(Box, {
1234
2217
  flexDirection: "row",
1235
- gap: 2,
2218
+ height: props.rows,
1236
2219
  children: [/* @__PURE__ */ jsx(Box, {
1237
2220
  flexDirection: "column",
1238
- width: mainW,
2221
+ width: wide ? split.mainW : mainW,
2222
+ flexShrink: 0,
1239
2223
  children: installed.length === 0 ? /* @__PURE__ */ jsx(Text, {
1240
2224
  dimColor: true,
1241
2225
  children: state.setup ? "No CLI found. Set one up on screen 5 first." : `Looking for your CLIs${m.ellipsis}`
@@ -1244,81 +2228,104 @@ function NewScreen(props) {
1244
2228
  /* @__PURE__ */ jsx(Box, {
1245
2229
  flexDirection: "column",
1246
2230
  marginLeft: 2,
1247
- children: installed.map((x, i) => /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Text, { children: `${i === cliIx ? m.radioOn : m.radioOff} ${x.label}` }), x.status === "not-set-up" || x.status === "needs-update" ? /* @__PURE__ */ jsx(Text, {
1248
- dimColor: true,
1249
- children: ` ${x.status === "not-set-up" ? "not set up yet" : "needs update"}`
1250
- }) : null] }, x.cli))
2231
+ children: installed.map((x, i) => /* @__PURE__ */ jsxs(Hit, {
2232
+ onClick: () => {
2233
+ if (busy) return;
2234
+ setCliIx(i);
2235
+ setField("cli");
2236
+ },
2237
+ children: [/* @__PURE__ */ jsx(Text, { children: `${i === cliIx ? m.radioOn : m.radioOff} ${x.label}` }), x.status === "not-set-up" || x.status === "needs-update" ? /* @__PURE__ */ jsx(Text, {
2238
+ dimColor: true,
2239
+ children: ` ${x.status === "not-set-up" ? "not set up yet" : "needs update"}`
2240
+ }) : null]
2241
+ }, x.cli))
1251
2242
  }),
1252
2243
  label("folder", "Folder"),
1253
- /* @__PURE__ */ jsx(Box, {
1254
- marginLeft: 2,
1255
- children: /* @__PURE__ */ jsx(TextBox, {
1256
- value: folder,
1257
- onChange: setFolder,
1258
- onSubmit: () => move(1),
1259
- focus: active && field === "folder",
1260
- placeholder: "~/code/my-project"
1261
- }, folderKey)
1262
- }),
2244
+ field_("folder", /* @__PURE__ */ jsx(TextBox, {
2245
+ value: folder,
2246
+ onChange: setFolder,
2247
+ onSubmit: () => move(1),
2248
+ focus: active && field === "folder",
2249
+ placeholder: "~/code/my-project"
2250
+ }, folderKey)),
1263
2251
  label("mode", "How it runs"),
1264
2252
  /* @__PURE__ */ jsx(Box, {
1265
2253
  flexDirection: "column",
1266
2254
  marginLeft: 2,
1267
- children: modes.map((x, i) => /* @__PURE__ */ jsxs(Text, {
1268
- wrap: "truncate-end",
1269
- children: [/* @__PURE__ */ jsx(Text, {
1270
- ...i === modeIx && field === "mode" ? { bold: true } : {},
1271
- children: `${i === modeIx ? m.radioOn : m.radioOff} ${x.title}`
1272
- }), /* @__PURE__ */ jsx(Text, {
1273
- dimColor: true,
1274
- children: ` ${x.hint}`
1275
- })]
2255
+ children: modes.map((x, i) => /* @__PURE__ */ jsx(Hit, {
2256
+ onClick: () => {
2257
+ if (busy) return;
2258
+ setModeIx(i);
2259
+ setField("mode");
2260
+ },
2261
+ children: /* @__PURE__ */ jsxs(Text, {
2262
+ wrap: "truncate-end",
2263
+ children: [/* @__PURE__ */ jsx(Text, {
2264
+ ...i === modeIx && field === "mode" ? { bold: true } : {},
2265
+ children: `${i === modeIx ? m.radioOn : m.radioOff} ${x.title}`
2266
+ }), /* @__PURE__ */ jsx(Text, {
2267
+ dimColor: true,
2268
+ children: ` ${x.hint}`
2269
+ })]
2270
+ })
1276
2271
  }, x.id))
1277
2272
  }),
1278
2273
  label("name", "Name"),
1279
- /* @__PURE__ */ jsx(Box, {
1280
- marginLeft: 2,
1281
- children: /* @__PURE__ */ jsx(TextBox, {
1282
- value: name,
1283
- onChange: setName,
1284
- onSubmit: () => move(1),
1285
- focus: active && field === "name",
1286
- placeholder: suggested
1287
- })
1288
- }),
2274
+ field_("name", /* @__PURE__ */ jsx(TextBox, {
2275
+ value: name,
2276
+ onChange: setName,
2277
+ onSubmit: () => move(1),
2278
+ focus: active && field === "name",
2279
+ placeholder: suggested
2280
+ })),
1289
2281
  label("task", "Task"),
1290
- /* @__PURE__ */ jsx(Box, {
1291
- marginLeft: 2,
1292
- children: /* @__PURE__ */ jsx(TextBox, {
1293
- value: task,
1294
- onChange: setTask,
1295
- onSubmit: () => void start(),
1296
- focus: active && field === "task",
1297
- multiline: true,
1298
- placeholder: mode === "headless" ? "What should it do?" : "What should it start on? (optional)"
1299
- })
1300
- }),
2282
+ field_("task", /* @__PURE__ */ jsx(TextBox, {
2283
+ value: task,
2284
+ onChange: setTask,
2285
+ onSubmit: () => void start(),
2286
+ focus: active && field === "task",
2287
+ multiline: true,
2288
+ placeholder: mode === "headless" ? "What should it do?" : "What should it start on? (optional)"
2289
+ })),
1301
2290
  label("auto", "Auto"),
1302
- /* @__PURE__ */ jsx(Box, {
2291
+ /* @__PURE__ */ jsx(Hit, {
1303
2292
  marginLeft: 2,
2293
+ onClick: () => {
2294
+ if (busy) return;
2295
+ setField("auto");
2296
+ setAuto(!auto);
2297
+ },
1304
2298
  children: /* @__PURE__ */ jsx(Text, { children: `${auto ? "[x]" : "[ ]"} reply on its own, without waiting for you` })
1305
2299
  }),
1306
2300
  /* @__PURE__ */ jsx(Text, { children: " " }),
1307
- busy ? /* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Spinner, { tick }), ` Starting ${finalName}${m.ellipsis}`] }) : /* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Text, {
1308
- bold: true,
1309
- children: `${m.enter} Start`
1310
- }), /* @__PURE__ */ jsx(Text, {
1311
- dimColor: true,
1312
- children: " Tab next Esc cancel"
1313
- })] }),
2301
+ busy ? /* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Spinner, { tick }), ` Starting ${finalName}${m.ellipsis}`] }) : /* @__PURE__ */ jsxs(Box, { children: [
2302
+ /* @__PURE__ */ jsx(Hit, {
2303
+ onClick: () => void start(),
2304
+ children: /* @__PURE__ */ jsx(Text, {
2305
+ bold: true,
2306
+ children: `${m.enter} Start`
2307
+ })
2308
+ }),
2309
+ /* @__PURE__ */ jsx(Text, {
2310
+ dimColor: true,
2311
+ children: " Tab next "
2312
+ }),
2313
+ /* @__PURE__ */ jsx(Hit, {
2314
+ onClick: () => go("sessions"),
2315
+ children: /* @__PURE__ */ jsx(Text, {
2316
+ dimColor: true,
2317
+ children: "Esc cancel"
2318
+ })
2319
+ })
2320
+ ] }),
1314
2321
  error ? /* @__PURE__ */ jsx(Text, {
1315
2322
  ...c.error ? { color: c.error } : {},
1316
2323
  children: `${m.error} ${error}`
1317
2324
  }) : null
1318
2325
  ] })
1319
- }), wide ? /* @__PURE__ */ jsxs(Box, {
1320
- flexDirection: "column",
1321
- width: sideW,
2326
+ }), wide ? /* @__PURE__ */ jsxs(Pane, {
2327
+ width: split.panelW,
2328
+ height: props.rows,
1322
2329
  children: [
1323
2330
  /* @__PURE__ */ jsx(Label, { children: "After you press ⏎" }),
1324
2331
  steps.map((s, i) => /* @__PURE__ */ jsxs(Box, { children: [
@@ -1348,14 +2355,6 @@ function NewScreen(props) {
1348
2355
  }
1349
2356
  // src/tui/screens/session-view.tsx
1350
2357
  /** One session, opened from the Sessions screen: Chat, Live view and Info. */
1351
- /** Home folder as `~`. Handles this machine's home and the usual homes of other machines. */
1352
- function tildePath(cwd) {
1353
- let p = cwd;
1354
- const home = homedir();
1355
- if (home && home !== "/" && (p === home || p.startsWith(`${home}/`))) p = `~${p.slice(home.length)}`;
1356
- else p = p.replace(/^(\/home\/[^/]+|\/Users\/[^/]+|[A-Za-z]:[\\/]Users[\\/][^\\/]+)(?=[\\/]|$)/, "~");
1357
- return p.replace(/\\/g, "/");
1358
- }
1359
2358
  /** `10:41` in local time. */
1360
2359
  function clockTime(iso) {
1361
2360
  const d = new Date(iso);
@@ -1435,7 +2434,7 @@ const TABS = [
1435
2434
  title: "Info"
1436
2435
  }
1437
2436
  ];
1438
- const PANEL_WIDTH$2 = 42;
2437
+ const PANEL_WIDTH = 44;
1439
2438
  function SessionView(props) {
1440
2439
  const { session, state, actions, layout, rows, columns, active, setTyping, toast, onClose } = props;
1441
2440
  const { c, ascii } = useTheme();
@@ -1484,10 +2483,12 @@ function SessionView(props) {
1484
2483
  const status = statusWord(session);
1485
2484
  const sep = ascii ? " - " : " › ";
1486
2485
  const right = `auto ${session.auto ? "on" : "off"} ${status.text}`;
1487
- const left = `Sessions${sep}${session.name} ${chipText(session.cli)} · ${tildePath(session.cwd)} · ${where} · started by ${starter}`;
1488
- const headWidth = Math.max(10, columns - right.length - 2);
1489
- const panelW = wide ? PANEL_WIDTH$2 : 0;
1490
- const mainW = wide ? columns - panelW - 2 : columns;
2486
+ const left = plain(`Sessions${sep}${session.name} ${chipText(session.cli)} · ${shortPath$1(session.cwd, 40, ascii)} · ${where} · started by ${starter}`, ascii);
2487
+ const split = splitWidths(columns, wide, { panelW: PANEL_WIDTH });
2488
+ const frameW = wide ? split.mainW + split.panelW : Math.min(columns, 130);
2489
+ const headWidth = Math.max(10, frameW - right.length - 2);
2490
+ const panelW = split.panelW;
2491
+ const mainW = wide ? split.mainW - 2 : Math.min(columns, 130);
1491
2492
  const boxLines = Math.max(1, Math.min(4, draft.split("\n").length));
1492
2493
  const chrome = 1 + (wide ? 0 : 1) + 1 + boxLines + (note ? 1 : 0);
1493
2494
  const chatH = Math.max(2, rows - chrome);
@@ -1499,12 +2500,12 @@ function SessionView(props) {
1499
2500
  session,
1500
2501
  messages: state.history[session.id] ?? [],
1501
2502
  width: mainW,
1502
- height: chatH
1503
- }),
1504
- /* @__PURE__ */ jsx(Text, {
1505
- ...quiet$2(c),
1506
- children: (ascii ? "-" : "─").repeat(mainW)
2503
+ height: chatH,
2504
+ active: active && tab === "chat",
2505
+ more: state.historyMore[session.id] === true,
2506
+ loadOlder: () => actions.loadOlder(session.id)
1507
2507
  }),
2508
+ /* @__PURE__ */ jsx(Rule, { width: mainW }),
1508
2509
  /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Text, {
1509
2510
  ...c.entry ? { color: c.entry } : {},
1510
2511
  children: ascii ? "> " : "› "
@@ -1515,6 +2516,7 @@ function SessionView(props) {
1515
2516
  onChange: setDraft,
1516
2517
  onSubmit: send,
1517
2518
  focus: active && tab === "chat" && boxFocus,
2519
+ onFocusRequest: () => setBoxFocus(true),
1518
2520
  multiline: true,
1519
2521
  placeholder: boxFocus ? `Message ${session.name}…` : `Press Enter to message ${session.name}`
1520
2522
  })
@@ -1531,7 +2533,7 @@ function SessionView(props) {
1531
2533
  flexDirection: "column",
1532
2534
  width: columns,
1533
2535
  children: [/* @__PURE__ */ jsxs(Box, {
1534
- width: columns,
2536
+ width: frameW,
1535
2537
  children: [
1536
2538
  /* @__PURE__ */ jsx(Box, {
1537
2539
  width: headWidth,
@@ -1547,34 +2549,41 @@ function SessionView(props) {
1547
2549
  children: right
1548
2550
  })
1549
2551
  ]
1550
- }), wide ? /* @__PURE__ */ jsxs(Box, { children: [chat, /* @__PURE__ */ jsxs(Box, {
1551
- flexDirection: "column",
2552
+ }), wide ? /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Box, {
2553
+ width: split.mainW,
2554
+ flexShrink: 0,
2555
+ children: chat
2556
+ }), /* @__PURE__ */ jsxs(Pane, {
1552
2557
  width: panelW,
1553
- marginLeft: 2,
2558
+ height: rows - 1,
1554
2559
  children: [/* @__PURE__ */ jsx(LiveView, {
1555
2560
  session,
1556
2561
  actions,
1557
2562
  active,
1558
- width: panelW,
2563
+ width: paneInner(panelW),
1559
2564
  height: Math.max(4, Math.floor(bodyH / 2))
1560
2565
  }), /* @__PURE__ */ jsx(Box, {
1561
2566
  marginTop: 1,
1562
2567
  flexDirection: "column",
1563
2568
  children: /* @__PURE__ */ jsx(InfoPanel, {
1564
2569
  session,
1565
- width: panelW
2570
+ width: paneInner(panelW)
1566
2571
  })
1567
2572
  })]
1568
2573
  })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1569
2574
  /* @__PURE__ */ jsxs(Box, {
1570
2575
  gap: 2,
1571
- children: [TABS.map((t) => /* @__PURE__ */ jsx(Text, {
1572
- ...t.id === tab ? {
1573
- bold: true,
1574
- underline: true,
1575
- ...c.ink ? { color: c.ink } : {}
1576
- } : quiet$2(c),
1577
- children: t.title
2576
+ children: [TABS.map((t) => /* @__PURE__ */ jsx(Hit, {
2577
+ onClick: () => setTab(t.id),
2578
+ isActive: active,
2579
+ children: /* @__PURE__ */ jsx(Text, {
2580
+ ...t.id === tab ? {
2581
+ bold: true,
2582
+ underline: true,
2583
+ ...c.ink ? { color: c.ink } : {}
2584
+ } : quiet$2(c),
2585
+ children: t.title
2586
+ })
1578
2587
  }, t.id)), /* @__PURE__ */ jsx(Text, {
1579
2588
  ...quiet$2(c),
1580
2589
  children: "Tab switches"
@@ -1598,7 +2607,7 @@ function SessionView(props) {
1598
2607
  /** The word for a session's state. State is always in the word, never in colour alone. */
1599
2608
  function statusWord(s) {
1600
2609
  if (s.status === "offline") {
1601
- const r = relTime(s.lastSeenAt);
2610
+ const r = relCompact(s.lastSeenAt);
1602
2611
  return {
1603
2612
  text: r === "" || r === "now" ? "offline" : `offline ${r}`,
1604
2613
  kind: "offline"
@@ -1626,15 +2635,27 @@ function statusColor(kind, c) {
1626
2635
  if (kind === "working") return c.info;
1627
2636
  return c.quiet;
1628
2637
  }
1629
- function ChatLines({ session, messages, width, height }) {
2638
+ function ChatLines({ session, messages, width, height, active, more, loadOlder }) {
1630
2639
  const { c, ascii } = useTheme();
1631
- const lines = useMemo(() => {
2640
+ const mouse = useMouseEnabled();
2641
+ const handle = useRef(null);
2642
+ const [atBottom, setAtBottom] = useState(true);
2643
+ const atBottomRef = useRef(true);
2644
+ atBottomRef.current = atBottom;
2645
+ const [seen, setSeen] = useState(void 0);
2646
+ const { lines, sorted } = useMemo(() => {
1632
2647
  const sorted = [...messages].sort((a, b) => a.createdAt.localeCompare(b.createdAt));
1633
2648
  let lastMine = -1;
1634
2649
  sorted.forEach((m, i) => {
1635
2650
  if (isFromOwner(m)) lastMine = i;
1636
2651
  });
1637
2652
  const out = [];
2653
+ if (more && sorted.length > 0) out.push({
2654
+ key: "more",
2655
+ text: "Scroll up for older messages",
2656
+ own: false,
2657
+ marker: true
2658
+ });
1638
2659
  sorted.forEach((m, i) => {
1639
2660
  const own = isFromOwner(m);
1640
2661
  const who = own ? "you" : m.fromName ?? session.name;
@@ -1658,14 +2679,51 @@ function ChatLines({ session, messages, width, height }) {
1658
2679
  tail: true
1659
2680
  });
1660
2681
  });
1661
- return out;
2682
+ return {
2683
+ lines: out,
2684
+ sorted
2685
+ };
1662
2686
  }, [
1663
2687
  messages,
2688
+ more,
1664
2689
  session.name,
1665
2690
  session.unreadCount,
1666
2691
  width,
1667
2692
  ascii
1668
2693
  ]);
2694
+ const newest = sorted[sorted.length - 1];
2695
+ useEffect(() => {
2696
+ if (atBottom) setSeen(newest?.id);
2697
+ }, [atBottom, newest?.id]);
2698
+ useEffect(() => {
2699
+ if (newest && isFromOwner(newest)) handle.current?.scrollToBottom();
2700
+ }, [newest?.id, newest]);
2701
+ const seenAt = seen === void 0 ? -1 : sorted.findIndex((m) => m.id === seen);
2702
+ const fresh = atBottom || seenAt < 0 ? 0 : sorted.slice(seenAt + 1).filter((m) => !isFromOwner(m)).length;
2703
+ const first = useRef(void 0);
2704
+ useEffect(() => {
2705
+ const real = lines.find((l) => !l.marker);
2706
+ const prev = first.current;
2707
+ if (!real) {
2708
+ first.current = void 0;
2709
+ return;
2710
+ }
2711
+ first.current = {
2712
+ key: real.key,
2713
+ at: lines.indexOf(real)
2714
+ };
2715
+ if (!prev || prev.key === real.key || atBottomRef.current) return;
2716
+ const was = lines.findIndex((l) => l.key === prev.key);
2717
+ if (was > prev.at) handle.current?.scrollBy(was - prev.at);
2718
+ }, [lines]);
2719
+ const loading = useRef(false);
2720
+ const reachTop = useCallback(() => {
2721
+ if (!more || loading.current) return;
2722
+ loading.current = true;
2723
+ loadOlder().catch(() => false).finally(() => {
2724
+ loading.current = false;
2725
+ });
2726
+ }, [more, loadOlder]);
1669
2727
  if (lines.length === 0) return /* @__PURE__ */ jsx(Box, {
1670
2728
  height,
1671
2729
  children: /* @__PURE__ */ jsx(Text, {
@@ -1673,17 +2731,37 @@ function ChatLines({ session, messages, width, height }) {
1673
2731
  children: "No messages yet. Type one below."
1674
2732
  })
1675
2733
  });
1676
- const shown = lines.slice(-height);
1677
- return /* @__PURE__ */ jsx(Box, {
2734
+ const room = fresh > 0 ? Math.max(1, height - 1) : height;
2735
+ const rows = lines.map((l) => /* @__PURE__ */ jsx(Ell, {
2736
+ width,
2737
+ color: l.own ? c.entry : l.head || l.tail || l.marker ? c.quiet : void 0,
2738
+ ...l.head || l.tail || l.marker ? { dim: !c.quiet } : {},
2739
+ children: l.text === "" ? " " : l.text
2740
+ }, l.key));
2741
+ const padded = [...Array.from({ length: Math.max(0, room - rows.length) }, (_, i) => /* @__PURE__ */ jsx(Text, { children: " " }, `pad${i}`)), ...rows];
2742
+ return /* @__PURE__ */ jsxs(Box, {
1678
2743
  flexDirection: "column",
1679
2744
  height,
1680
- justifyContent: "flex-end",
1681
- children: shown.map((l) => /* @__PURE__ */ jsx(Ell, {
1682
- width,
1683
- color: l.own ? c.entry : l.head || l.tail ? c.quiet : void 0,
1684
- ...l.head || l.tail ? { dim: !c.quiet } : {},
1685
- children: l.text === "" ? " " : l.text
1686
- }, l.key))
2745
+ children: [/* @__PURE__ */ jsx(ScrollView, {
2746
+ lines: padded,
2747
+ height: room,
2748
+ stickToBottom: true,
2749
+ isActive: active,
2750
+ onAtBottomChange: setAtBottom,
2751
+ handleRef: handle,
2752
+ onReachTop: reachTop
2753
+ }), fresh > 0 ? /* @__PURE__ */ jsxs(Hit, {
2754
+ onClick: () => handle.current?.scrollToBottom(),
2755
+ isActive: active,
2756
+ children: [/* @__PURE__ */ jsx(Text, {
2757
+ bold: true,
2758
+ ...c.stamp ? { color: c.stamp } : {},
2759
+ children: `${ascii ? "v" : "↓"} ${fresh} new`
2760
+ }), /* @__PURE__ */ jsx(Text, {
2761
+ ...quiet$2(c),
2762
+ children: mouse ? " click or End" : " End"
2763
+ })]
2764
+ }) : null]
1687
2765
  });
1688
2766
  }
1689
2767
  const PEEK_EVERY_MS = 3e3;
@@ -1764,7 +2842,7 @@ function LiveView({ session, actions, active, width, height }) {
1764
2842
  });
1765
2843
  }
1766
2844
  function InfoPanel({ session, width }) {
1767
- const { c } = useTheme();
2845
+ const { c, ascii } = useTheme();
1768
2846
  const row = (label, value) => /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Box, {
1769
2847
  width: 12,
1770
2848
  children: /* @__PURE__ */ jsx(Text, {
@@ -1778,7 +2856,7 @@ function InfoPanel({ session, width }) {
1778
2856
  const rowsOut = [row("Wakes up", wakesUp(session.deliveryTier)), row("Auto", session.auto ? "on" : "off")];
1779
2857
  if (session.autoPausedAt) rowsOut.push(row("Paused", "it hit its auto limit"));
1780
2858
  if (session.autoLimit) rowsOut.push(row("Auto limit", `${session.autoLimit} turns`));
1781
- rowsOut.push(row("Folder", tildePath(session.cwd)));
2859
+ rowsOut.push(row("Folder", shortPath$1(session.cwd, Math.max(4, width - 12), ascii)));
1782
2860
  rowsOut.push(row("Started", agoText(session.startedAt)));
1783
2861
  return /* @__PURE__ */ jsxs(Box, {
1784
2862
  flexDirection: "column",
@@ -1789,10 +2867,25 @@ function InfoPanel({ session, width }) {
1789
2867
  // src/tui/screens/sessions.tsx
1790
2868
  var sessions_exports = /* @__PURE__ */ __exportAll({
1791
2869
  default: () => Sessions,
1792
- groupSessions: () => groupSessions
2870
+ groupSessions: () => groupSessions,
2871
+ listColumns: () => listColumns
1793
2872
  });
1794
- const PANEL_WIDTH$1 = 34;
1795
- const STATUS_WIDTH = 11;
2873
+ const AUTO_WIDTH = 4;
2874
+ const GAP = 2;
2875
+ /** Column widths for the list. The name takes what it needs, the folder takes the rest. */
2876
+ function listColumns(width, longestName) {
2877
+ const fixed = 32;
2878
+ let name = Math.max(12, Math.min(32, longestName + 1));
2879
+ let folder = width - fixed - name;
2880
+ if (folder < 10) {
2881
+ name = Math.max(8, name - (10 - folder));
2882
+ folder = width - fixed - name;
2883
+ }
2884
+ return {
2885
+ name,
2886
+ folder: Math.max(0, folder)
2887
+ };
2888
+ }
1796
2889
  /** Letters that are keys on this screen. A word starting with one of them needs `f` first. */
1797
2890
  const BOUND = /* @__PURE__ */ new Set([
1798
2891
  "m",
@@ -1839,7 +2932,6 @@ function Sessions(props) {
1839
2932
  const { state, actions, layout, rows, columns, active, setKeys, setCommands, go, toast, setTyping, claimKeys } = props;
1840
2933
  const { c, ascii } = useTheme();
1841
2934
  const wide = layout === "wide";
1842
- const narrow = layout === "narrow";
1843
2935
  const [selectedId, setSelectedId] = useState(props.focus);
1844
2936
  const [filter, setFilter] = useState(void 0);
1845
2937
  const [confirm, setConfirm] = useState(void 0);
@@ -2045,18 +3137,27 @@ function Sessions(props) {
2045
3137
  children: "No sessions yet. Open Claude Code, Codex or another CLI you set up, or press n to start one."
2046
3138
  })
2047
3139
  });
2048
- const listW = wide ? columns - PANEL_WIDTH$1 - 2 : columns;
2049
- const listH = Math.max(2, rows - 2);
3140
+ const { mainW, panelW } = splitWidths(columns, wide);
3141
+ const listW = wide ? mainW - 2 : columns;
3142
+ const bodyH = Math.max(3, rows - 2);
3143
+ const listH = Math.max(2, bodyH - 1);
2050
3144
  const dot = ascii ? "*" : "◆";
2051
3145
  const mid = ascii ? "-" : "·";
2052
- const folderW = narrow ? 0 : listW >= 100 ? 24 : 18;
2053
- const autoW = narrow ? 0 : 5;
2054
- const fixed = 18 + (folderW ? folderW + 1 : 0) + autoW;
2055
- const nameW = Math.max(6, Math.min(28, listW - fixed));
3146
+ const { name: nameW, folder: folderW } = listColumns(listW, flat.reduce((n, s) => Math.max(n, [...s.name].length), 0));
3147
+ const clickRow = (s, isSel, double) => {
3148
+ setConfirm(void 0);
3149
+ if (isSel || double) {
3150
+ setSelectedId(s.id);
3151
+ setView({
3152
+ id: s.id,
3153
+ focusBox: false
3154
+ });
3155
+ } else setSelectedId(s.id);
3156
+ };
2056
3157
  const renderRow = (r, isSel) => {
2057
3158
  if (r.t === "head") return /* @__PURE__ */ jsxs(Box, {
2058
3159
  width: listW,
2059
- children: [/* @__PURE__ */ jsx(Label, { children: r.text }), r.synced ? /* @__PURE__ */ jsx(Text, {
3160
+ children: [/* @__PURE__ */ jsx(Label, { children: plain(r.text, ascii) }), r.synced ? /* @__PURE__ */ jsx(Text, {
2060
3161
  ...quiet$1(c),
2061
3162
  children: ` synced`
2062
3163
  }) : null]
@@ -2065,62 +3166,65 @@ function Sessions(props) {
2065
3166
  const st = statusWord(s);
2066
3167
  const off = st.kind === "offline";
2067
3168
  const tone = off ? c.quiet : void 0;
2068
- const sc = statusColor(st.kind, c);
2069
- return /* @__PURE__ */ jsxs(Box, {
2070
- width: listW,
2071
- children: [
2072
- /* @__PURE__ */ jsx(Text, {
2073
- ...c.entry ? { color: c.entry } : {},
2074
- children: isSel ? ascii ? "> " : "▸ " : " "
2075
- }),
2076
- /* @__PURE__ */ jsxs(Text, {
2077
- ...s.isOrchestrator && c.entry && !off ? { color: c.entry } : quiet$1(c),
2078
- children: [s.isOrchestrator ? dot : mid, " "]
2079
- }),
2080
- /* @__PURE__ */ jsx(Box, {
2081
- width: nameW,
2082
- children: /* @__PURE__ */ jsx(Ell, {
2083
- width: nameW,
3169
+ const sc = off ? c.quiet : statusColor(st.kind, c);
3170
+ const lead = s.isOrchestrator;
3171
+ return /* @__PURE__ */ jsx(Hit, {
3172
+ onClick: (e) => clickRow(s, isSel, e.double),
3173
+ isActive: active,
3174
+ children: /* @__PURE__ */ jsxs(Row, {
3175
+ width: listW,
3176
+ selected: isSel,
3177
+ children: [
3178
+ /* @__PURE__ */ jsx(Cell, {
3179
+ w: 2,
3180
+ gap: 0,
3181
+ color: c.entry,
3182
+ children: isSel ? ascii ? "> " : "▸ " : " "
3183
+ }),
3184
+ /* @__PURE__ */ jsx(Cell, {
3185
+ w: 2,
3186
+ gap: 0,
3187
+ color: lead && !off ? c.entry : c.quiet,
3188
+ dim: off,
3189
+ children: lead ? `${dot} ` : `${mid} `
3190
+ }),
3191
+ /* @__PURE__ */ jsx(Cell, {
3192
+ w: nameW + GAP,
2084
3193
  bold: isSel,
2085
3194
  color: tone,
3195
+ dim: off,
2086
3196
  children: s.name
2087
- })
2088
- }),
2089
- /* @__PURE__ */ jsx(Box, {
2090
- width: 3,
2091
- marginLeft: 0,
2092
- children: /* @__PURE__ */ jsxs(Text, {
2093
- ...off ? quiet$1(c) : {},
2094
- children: [" ", /* @__PURE__ */ jsx(Chip, { cli: s.cli })]
2095
- })
2096
- }),
2097
- folderW ? /* @__PURE__ */ jsx(Box, {
2098
- width: folderW + 1,
2099
- paddingLeft: 1,
2100
- children: /* @__PURE__ */ jsx(Ell, {
2101
- width: folderW,
3197
+ }),
3198
+ /* @__PURE__ */ jsx(Box, {
3199
+ width: 6,
3200
+ flexShrink: 0,
3201
+ children: /* @__PURE__ */ jsx(Chip, {
3202
+ cli: s.cli,
3203
+ dim: off
3204
+ })
3205
+ }),
3206
+ /* @__PURE__ */ jsx(Cell, {
3207
+ w: folderW + GAP,
2102
3208
  color: c.quiet,
2103
- children: tildePath(s.cwd)
2104
- })
2105
- }) : null,
2106
- /* @__PURE__ */ jsx(Box, {
2107
- width: STATUS_WIDTH,
2108
- children: /* @__PURE__ */ jsx(Ell, {
2109
- width: 10,
3209
+ dim: off,
3210
+ children: shortPath$1(s.cwd, folderW - GAP, ascii)
3211
+ }),
3212
+ /* @__PURE__ */ jsx(Cell, {
3213
+ w: 14,
2110
3214
  bold: st.kind === "new",
2111
3215
  color: sc,
3216
+ dim: off,
2112
3217
  children: st.text
2113
- })
2114
- }),
2115
- autoW ? /* @__PURE__ */ jsx(Box, {
2116
- width: autoW,
2117
- children: /* @__PURE__ */ jsx(Ell, {
2118
- width: autoW,
3218
+ }),
3219
+ /* @__PURE__ */ jsx(Cell, {
3220
+ w: AUTO_WIDTH,
3221
+ gap: 0,
2119
3222
  color: c.quiet,
3223
+ dim: off,
2120
3224
  children: off ? "" : s.auto ? "on" : "off"
2121
3225
  })
2122
- }) : null
2123
- ]
3226
+ ]
3227
+ })
2124
3228
  });
2125
3229
  };
2126
3230
  const list = flat.length === 0 ? /* @__PURE__ */ jsx(Text, {
@@ -2135,11 +3239,39 @@ function Sessions(props) {
2135
3239
  });
2136
3240
  const unreadTotal = state.sessions.reduce((n, s) => n + (s.unreadCount ?? 0), 0);
2137
3241
  let bottom;
2138
- if (confirm) bottom = /* @__PURE__ */ jsx(Text, {
2139
- bold: true,
2140
- ...c.stamp ? { color: c.stamp } : {},
2141
- children: `Stop ${confirm.name}? y/n`
2142
- });
3242
+ if (confirm) bottom = /* @__PURE__ */ jsxs(Box, { children: [
3243
+ /* @__PURE__ */ jsx(Text, {
3244
+ bold: true,
3245
+ ...c.stamp ? { color: c.stamp } : {},
3246
+ children: `Stop ${confirm.name}? `
3247
+ }),
3248
+ /* @__PURE__ */ jsx(Hit, {
3249
+ onClick: () => {
3250
+ stop(confirm);
3251
+ setConfirm(void 0);
3252
+ },
3253
+ isActive: active,
3254
+ children: /* @__PURE__ */ jsx(Text, {
3255
+ bold: true,
3256
+ ...c.stamp ? { color: c.stamp } : {},
3257
+ children: "y"
3258
+ })
3259
+ }),
3260
+ /* @__PURE__ */ jsx(Text, {
3261
+ bold: true,
3262
+ ...c.stamp ? { color: c.stamp } : {},
3263
+ children: "/"
3264
+ }),
3265
+ /* @__PURE__ */ jsx(Hit, {
3266
+ onClick: () => setConfirm(void 0),
3267
+ isActive: active,
3268
+ children: /* @__PURE__ */ jsx(Text, {
3269
+ bold: true,
3270
+ ...c.stamp ? { color: c.stamp } : {},
3271
+ children: "n"
3272
+ })
3273
+ })
3274
+ ] });
2143
3275
  else if (filtering) bottom = /* @__PURE__ */ jsxs(Text, { children: [
2144
3276
  /* @__PURE__ */ jsx(Text, {
2145
3277
  ...quiet$1(c),
@@ -2158,56 +3290,121 @@ function Sessions(props) {
2158
3290
  children: ` Esc clears ⏎ opens`
2159
3291
  })
2160
3292
  ] });
2161
- else bottom = /* @__PURE__ */ jsx(Ell, {
2162
- width: listW,
2163
- color: c.quiet,
2164
- children: `${dot} lead session working busy right now ${unreadTotal > 0 ? unreadTotal : "N"} new unread messages type to filter`
2165
- });
2166
- return /* @__PURE__ */ jsxs(Box, {
2167
- width: columns,
2168
- children: [/* @__PURE__ */ jsxs(Box, {
2169
- flexDirection: "column",
2170
- width: listW,
2171
- height: rows,
2172
- children: [/* @__PURE__ */ jsx(Box, {
2173
- flexDirection: "column",
2174
- height: rows - 1,
2175
- children: list
2176
- }), bottom]
2177
- }), wide ? /* @__PURE__ */ jsx(Box, {
2178
- width: PANEL_WIDTH$1,
2179
- marginLeft: 2,
2180
- flexDirection: "column",
2181
- children: selected ? /* @__PURE__ */ jsx(SidePanel$1, {
2182
- session: selected,
2183
- state,
2184
- width: PANEL_WIDTH$1
2185
- }) : null
2186
- }) : null]
3293
+ else {
3294
+ const n = unreadTotal > 0 ? `${unreadTotal} new` : "N new";
3295
+ const variants = [
3296
+ `${dot} lead session working = busy right now ${n} = unread messages type to filter`,
3297
+ `${dot} lead working = busy ${n} = unread type to filter`,
3298
+ `${dot} lead ${n} = unread type to filter`
3299
+ ];
3300
+ const legend = variants.find((v) => [...v].length <= columns) ?? variants[2] ?? "";
3301
+ const tail = "type to filter";
3302
+ const head = legend.endsWith(tail) ? legend.slice(0, -14) : legend;
3303
+ bottom = /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Ell, {
3304
+ width: Math.min([...head].length, Math.max(0, columns - 14)),
3305
+ color: c.quiet,
3306
+ children: head
3307
+ }), legend.endsWith(tail) ? /* @__PURE__ */ jsx(Hit, {
3308
+ onClick: () => setFilter((f) => f ?? ""),
3309
+ isActive: active,
3310
+ children: /* @__PURE__ */ jsx(Ell, {
3311
+ width: 14,
3312
+ color: c.quiet,
3313
+ children: tail
3314
+ })
3315
+ }) : null] });
3316
+ }
3317
+ return /* @__PURE__ */ jsxs(Box, {
3318
+ flexDirection: "column",
3319
+ width: columns,
3320
+ children: [
3321
+ /* @__PURE__ */ jsxs(Box, {
3322
+ height: bodyH,
3323
+ children: [/* @__PURE__ */ jsxs(Hit, {
3324
+ flexDirection: "column",
3325
+ width: wide ? mainW : columns,
3326
+ flexShrink: 0,
3327
+ onWheel: (d) => move(d < 0 ? -1 : 1),
3328
+ isActive: active,
3329
+ children: [/* @__PURE__ */ jsx(HeaderRow, {
3330
+ width: listW,
3331
+ cols: [
3332
+ {
3333
+ w: 4,
3334
+ text: "",
3335
+ gap: 0
3336
+ },
3337
+ {
3338
+ w: nameW + GAP,
3339
+ text: "Name"
3340
+ },
3341
+ {
3342
+ w: 6,
3343
+ text: "CLI"
3344
+ },
3345
+ {
3346
+ w: folderW + GAP,
3347
+ text: "Folder"
3348
+ },
3349
+ {
3350
+ w: 14,
3351
+ text: "Status"
3352
+ },
3353
+ {
3354
+ w: AUTO_WIDTH,
3355
+ text: "Auto",
3356
+ gap: 0
3357
+ }
3358
+ ]
3359
+ }), list]
3360
+ }), wide ? /* @__PURE__ */ jsx(Pane, {
3361
+ width: panelW,
3362
+ height: bodyH,
3363
+ children: selected ? /* @__PURE__ */ jsx(SidePanel$1, {
3364
+ session: selected,
3365
+ state,
3366
+ width: paneInner(panelW)
3367
+ }) : null
3368
+ }) : null]
3369
+ }),
3370
+ /* @__PURE__ */ jsx(Box, {
3371
+ marginLeft: -1,
3372
+ children: /* @__PURE__ */ jsx(Rule, { width: columns + 1 })
3373
+ }),
3374
+ /* @__PURE__ */ jsx(Box, {
3375
+ height: 1,
3376
+ children: bottom
3377
+ })
3378
+ ]
2187
3379
  });
2188
3380
  }
2189
3381
  function SidePanel$1({ session, state, width }) {
2190
3382
  const { c, ascii } = useTheme();
2191
3383
  const history = [...state.history[session.id] ?? []].sort((a, b) => a.createdAt.localeCompare(b.createdAt)).slice(-3);
2192
- const sub = `${session.isOrchestrator ? "lead" : "worker"} ${ascii ? "-" : "·"} ${tildePath(session.cwd)} ${ascii ? "-" : "·"} started ${agoText(session.startedAt)}`;
3384
+ const role = session.isOrchestrator ? "lead" : "worker";
3385
+ const sep = ascii ? "-" : "·";
3386
+ const started = `started ${agoText(session.startedAt)}`;
3387
+ const whole = `${role} ${sep} ${shortPath$1(session.cwd, 200, ascii)} ${sep} ${started}`;
3388
+ const sub = [...whole].length <= width ? [whole] : [`${role} ${sep} ${started}`, shortPath$1(session.cwd, width, ascii)];
3389
+ const status = session.statusText ?? "No update yet.";
2193
3390
  return /* @__PURE__ */ jsxs(Box, {
2194
3391
  flexDirection: "column",
2195
3392
  width,
2196
3393
  children: [
2197
3394
  /* @__PURE__ */ jsxs(Box, { children: [
2198
3395
  /* @__PURE__ */ jsx(Ell, {
2199
- width: width - 4,
3396
+ width: width - 4 - 1,
2200
3397
  bold: true,
2201
3398
  children: session.name
2202
3399
  }),
2203
3400
  /* @__PURE__ */ jsx(Text, { children: " " }),
2204
3401
  /* @__PURE__ */ jsx(Chip, { cli: session.cli })
2205
3402
  ] }),
2206
- /* @__PURE__ */ jsx(Ell, {
3403
+ sub.map((l) => /* @__PURE__ */ jsx(Ell, {
2207
3404
  width,
2208
3405
  color: c.quiet,
2209
- children: sub
2210
- }),
3406
+ children: l
3407
+ }, l)),
2211
3408
  /* @__PURE__ */ jsx(Box, {
2212
3409
  marginTop: 1,
2213
3410
  children: /* @__PURE__ */ jsx(Label, { children: "Latest" })
@@ -2221,19 +3418,19 @@ function SidePanel$1({ session, state, width }) {
2221
3418
  width,
2222
3419
  color: isFromOwner(m) ? c.entry : c.quiet,
2223
3420
  children: `${clockTime(m.createdAt)} ${isFromOwner(m) ? "you" : m.fromName ?? session.name}`
2224
- }), /* @__PURE__ */ jsx(Ell, {
3421
+ }), wrapLines(messageText(m), width).slice(0, 2).map((l, i) => /* @__PURE__ */ jsx(Ell, {
2225
3422
  width,
2226
- children: messageText(m)
2227
- })]
3423
+ children: l === "" ? " " : l
3424
+ }, i))]
2228
3425
  }, m.id)),
2229
3426
  /* @__PURE__ */ jsx(Box, {
2230
3427
  marginTop: 1,
2231
3428
  children: /* @__PURE__ */ jsx(Label, { children: "Right now" })
2232
3429
  }),
2233
- /* @__PURE__ */ jsx(Ell, {
3430
+ wrapLines(status, width).slice(0, 3).map((l, i) => /* @__PURE__ */ jsx(Ell, {
2234
3431
  width,
2235
- children: session.statusText ?? "No update yet."
2236
- })
3432
+ children: l === "" ? " " : l
3433
+ }, i))
2237
3434
  ]
2238
3435
  });
2239
3436
  }
@@ -2281,7 +3478,7 @@ function HealthLine({ item, width }) {
2281
3478
  children: item.text
2282
3479
  })] });
2283
3480
  }
2284
- function ReviewBox({ review, rows, width }) {
3481
+ function ReviewBox({ review, rows, width, active, onYes, onNo, onScroll }) {
2285
3482
  const { c } = useTheme();
2286
3483
  const body = [];
2287
3484
  for (const f of review.files) {
@@ -2310,47 +3507,78 @@ function ReviewBox({ review, rows, width }) {
2310
3507
  })).slice(start, start + room);
2311
3508
  const hidden = body.length - start - shown.length;
2312
3509
  const inner = width - 4;
2313
- return /* @__PURE__ */ jsxs(Card, {
2314
- accent: c.warn,
2315
- width,
2316
- children: [
2317
- /* @__PURE__ */ jsx(Text, {
2318
- bold: true,
2319
- children: review.title
2320
- }),
2321
- review.error ? /* @__PURE__ */ jsx(Text, {
2322
- ...c.error ? { color: c.error } : {},
2323
- children: `We can't plan this: ${review.error}`
2324
- }) : review.files.length === 0 ? /* @__PURE__ */ jsx(Text, { children: "Nothing to change. It is already how it should be." }) : /* @__PURE__ */ jsxs(Box, {
2325
- flexDirection: "column",
2326
- children: [shown.map((l) => /* @__PURE__ */ jsx(Ell, {
2327
- width: inner,
2328
- bold: l.kind === "path",
2329
- dim: l.kind === "note" || l.kind === "hunk",
2330
- color: l.kind === "add" ? c.ok : l.kind === "del" ? c.error : void 0,
2331
- children: l.text === "" ? " " : l.text
2332
- }, l.id)), hidden > 0 ? /* @__PURE__ */ jsx(Text, {
2333
- dimColor: true,
2334
- children: `… ${hidden} more lines (↑↓ to scroll)`
2335
- }) : null]
2336
- }),
2337
- /* @__PURE__ */ jsx(Text, { children: " " }),
2338
- review.busy ? /* @__PURE__ */ jsx(Text, { children: "Working…" }) : review.error || review.files.length === 0 ? /* @__PURE__ */ jsx(Text, {
2339
- dimColor: true,
2340
- children: "Press n or Esc to close."
2341
- }) : /* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Text, {
2342
- bold: true,
2343
- children: "Apply? y/n"
2344
- }), /* @__PURE__ */ jsx(Text, {
2345
- dimColor: true,
2346
- children: " We back up each file first."
2347
- })] })
2348
- ]
3510
+ return /* @__PURE__ */ jsx(Hit, {
3511
+ onWheel: (d) => onScroll(d < 0 ? -1 : 1),
3512
+ isActive: active,
3513
+ children: /* @__PURE__ */ jsxs(Card, {
3514
+ accent: c.warn,
3515
+ width,
3516
+ children: [
3517
+ /* @__PURE__ */ jsx(Text, {
3518
+ bold: true,
3519
+ children: review.title
3520
+ }),
3521
+ review.error ? /* @__PURE__ */ jsx(Text, {
3522
+ ...c.error ? { color: c.error } : {},
3523
+ children: `We can't plan this: ${review.error}`
3524
+ }) : review.files.length === 0 ? /* @__PURE__ */ jsx(Text, { children: "Nothing to change. It is already how it should be." }) : /* @__PURE__ */ jsxs(Box, {
3525
+ flexDirection: "column",
3526
+ children: [shown.map((l) => /* @__PURE__ */ jsx(Ell, {
3527
+ width: inner,
3528
+ bold: l.kind === "path",
3529
+ dim: l.kind === "note" || l.kind === "hunk",
3530
+ color: l.kind === "add" ? c.ok : l.kind === "del" ? c.error : void 0,
3531
+ children: l.text === "" ? " " : l.text
3532
+ }, l.id)), hidden > 0 ? /* @__PURE__ */ jsx(Text, {
3533
+ dimColor: true,
3534
+ children: `… ${hidden} more lines (↑↓ to scroll)`
3535
+ }) : null]
3536
+ }),
3537
+ /* @__PURE__ */ jsx(Text, { children: " " }),
3538
+ review.busy ? /* @__PURE__ */ jsx(Text, { children: "Working…" }) : review.error || review.files.length === 0 ? /* @__PURE__ */ jsx(Hit, {
3539
+ onClick: onNo,
3540
+ isActive: active,
3541
+ children: /* @__PURE__ */ jsx(Text, {
3542
+ dimColor: true,
3543
+ children: "Press n or Esc to close."
3544
+ })
3545
+ }) : /* @__PURE__ */ jsxs(Box, { children: [
3546
+ /* @__PURE__ */ jsx(Text, {
3547
+ bold: true,
3548
+ children: "Apply? "
3549
+ }),
3550
+ /* @__PURE__ */ jsx(Hit, {
3551
+ onClick: onYes,
3552
+ isActive: active,
3553
+ children: /* @__PURE__ */ jsx(Text, {
3554
+ bold: true,
3555
+ children: "y"
3556
+ })
3557
+ }),
3558
+ /* @__PURE__ */ jsx(Text, {
3559
+ bold: true,
3560
+ children: "/"
3561
+ }),
3562
+ /* @__PURE__ */ jsx(Hit, {
3563
+ onClick: onNo,
3564
+ isActive: active,
3565
+ children: /* @__PURE__ */ jsx(Text, {
3566
+ bold: true,
3567
+ children: "n"
3568
+ })
3569
+ }),
3570
+ /* @__PURE__ */ jsx(Text, {
3571
+ dimColor: true,
3572
+ children: " We back up each file first."
3573
+ })
3574
+ ] })
3575
+ ]
3576
+ })
2349
3577
  });
2350
3578
  }
2351
3579
  function SetupScreen(props) {
2352
3580
  const { state, actions, layout, rows, columns, active, setKeys, setCommands, toast, go } = props;
2353
- const { c } = useTheme();
3581
+ const { c, ascii } = useTheme();
2354
3582
  const m = useMarks();
2355
3583
  const clis = state.setup?.clis ?? [];
2356
3584
  const health = state.setup?.health ?? [];
@@ -2361,8 +3589,10 @@ function SetupScreen(props) {
2361
3589
  helpers: false,
2362
3590
  askBeforeRisky: false
2363
3591
  });
3592
+ const mouse = useMouseControl();
3593
+ const mouseOn = mouse.enabled;
2364
3594
  const asked = useRef(false);
2365
- const total = clis.length + 2;
3595
+ const total = clis.length + 3;
2366
3596
  const at = Math.min(cursor, Math.max(0, total - 1));
2367
3597
  const onCli = at < clis.length ? clis[at] : void 0;
2368
3598
  const extraRow = at >= clis.length ? at - clis.length : -1;
@@ -2418,8 +3648,24 @@ function SetupScreen(props) {
2418
3648
  busy: false
2419
3649
  });
2420
3650
  }, [actions]);
2421
- const setUp = useCallback(() => {
2422
- if (extraRow === 0) {
3651
+ const setUp = useCallback((target) => {
3652
+ const row = target ? target.extra ?? -1 : extraRow;
3653
+ const cur = target ? target.cli : onCli;
3654
+ if (row === 2) {
3655
+ if (mouse.forcedOff) {
3656
+ toast("The mouse is off because CONVENO_MOUSE=0 is set.", "warn");
3657
+ return;
3658
+ }
3659
+ if (!mouse.available) {
3660
+ toast("This terminal can't send mouse clicks.", "warn");
3661
+ return;
3662
+ }
3663
+ const next = !mouseOn;
3664
+ mouse.set(next);
3665
+ toast(next ? "Mouse is on." : "Mouse is off.", "ok");
3666
+ return;
3667
+ }
3668
+ if (row === 0) {
2423
3669
  const next = !extras.helpers;
2424
3670
  actions.setHelpers(next).then(() => {
2425
3671
  setExtras({
@@ -2430,21 +3676,23 @@ function SetupScreen(props) {
2430
3676
  }, () => toast("Couldn't change that. Try again.", "error"));
2431
3677
  return;
2432
3678
  }
2433
- if (extraRow === 1) {
3679
+ if (row === 1) {
2434
3680
  if (extras.askBeforeRisky) return toast("Already on. Each worker stays off until you turn it on for it.", "ok");
2435
3681
  open(["relay:on"], "Ask me before risky commands (beta)");
2436
3682
  return;
2437
3683
  }
2438
- const { ids, skipped } = idsFor(clis, picked, onCli?.cli);
3684
+ const { ids, skipped } = idsFor(clis, picked, cur?.cli);
2439
3685
  if (ids.length === 0) return toast(skipped ?? "Nothing to set up here.", "warn");
2440
3686
  const names = clis.filter((x) => ids.includes(`init:${x.cli}`)).map((x) => x.label);
2441
3687
  open(ids, `Set up ${names.join(", ")}`);
2442
3688
  }, [
2443
3689
  extraRow,
3690
+ onCli,
2444
3691
  extras,
3692
+ mouse,
3693
+ mouseOn,
2445
3694
  clis,
2446
3695
  picked,
2447
- onCli,
2448
3696
  open,
2449
3697
  toast,
2450
3698
  actions
@@ -2543,6 +3791,24 @@ function SetupScreen(props) {
2543
3791
  go,
2544
3792
  toast
2545
3793
  ]);
3794
+ const togglePick = (x) => {
3795
+ const next = new Set(picked);
3796
+ if (next.has(x.cli)) next.delete(x.cli);
3797
+ else next.add(x.cli);
3798
+ setPicked(next);
3799
+ };
3800
+ const fixable = (x) => x.status === "needs-update" || x.status === "not-set-up";
3801
+ const clickRow = (i, x, double) => {
3802
+ if (i === at || double) {
3803
+ setCursor(i);
3804
+ setUp({ cli: x });
3805
+ } else setCursor(i);
3806
+ };
3807
+ const scrollReview = (d) => setReview((r) => r && !r.busy ? {
3808
+ ...r,
3809
+ scroll: Math.max(0, r.scroll + d)
3810
+ } : r);
3811
+ const closeReview = () => setReview((r) => r?.busy ? r : void 0);
2546
3812
  useInput((input, key) => {
2547
3813
  if (review) {
2548
3814
  if (review.busy) return;
@@ -2563,12 +3829,8 @@ function SetupScreen(props) {
2563
3829
  if (key.upArrow) return setCursor(Math.max(0, at - 1));
2564
3830
  if (key.downArrow) return setCursor(Math.min(total - 1, at + 1));
2565
3831
  if (input === " ") {
2566
- if (onCli) {
2567
- const next = new Set(picked);
2568
- if (next.has(onCli.cli)) next.delete(onCli.cli);
2569
- else next.add(onCli.cli);
2570
- setPicked(next);
2571
- } else setUp();
3832
+ if (onCli) togglePick(onCli);
3833
+ else setUp();
2572
3834
  return;
2573
3835
  }
2574
3836
  if (key.return) return setUp();
@@ -2576,27 +3838,39 @@ function SetupScreen(props) {
2576
3838
  if (input === "g") return void refresh();
2577
3839
  }, { isActive: active });
2578
3840
  const wide = layout === "wide";
2579
- const sideWidth = wide ? 40 : 0;
2580
- const mainWidth = Math.max(30, columns - sideWidth - (wide ? 3 : 2));
2581
- const listHeight = Math.max(3, rows - 10);
2582
- const labelW = mainWidth >= 60 ? 20 : 14;
2583
- const statusW = 15;
2584
- const noteW = Math.max(0, mainWidth - 4 - 3 - labelW - statusW - 2);
3841
+ const split = splitWidths(columns, wide, {
3842
+ panelW: 44,
3843
+ maxMain: 110
3844
+ });
3845
+ const sideWidth = paneInner(split.panelW);
3846
+ const mainWidth = wide ? split.mainW - 2 : Math.min(columns, 110);
3847
+ const listHeight = Math.max(3, rows - 11);
3848
+ const longestLabel = clis.reduce((n, x) => Math.max(n, [...x.label].length), 0);
3849
+ const labelW = Math.max(12, Math.min(24, longestLabel + 1));
3850
+ const noteW = Math.max(0, mainWidth - (11 + (labelW + 2) + 15));
2585
3851
  const colourOf = (s) => s === "ready" ? c.ok : s === "needs-update" || s === "not-set-up" ? c.warn : s === "blocked" ? c.error : c.quiet;
2586
3852
  const cliRows = useMemo(() => clis, [clis]);
2587
- if (review) return /* @__PURE__ */ jsx(ReviewBox, {
2588
- review,
2589
- rows,
2590
- width: Math.min(columns - 2, 100)
2591
- });
3853
+ if (review) {
3854
+ const closed = review.error || review.files.length === 0;
3855
+ return /* @__PURE__ */ jsx(ReviewBox, {
3856
+ review,
3857
+ rows,
3858
+ width: Math.min(columns - 2, 100),
3859
+ active,
3860
+ onYes: () => closed ? closeReview() : void apply(),
3861
+ onNo: closeReview,
3862
+ onScroll: scrollReview
3863
+ });
3864
+ }
2592
3865
  const box = (on) => on ? "[x]" : "[ ]";
2593
3866
  const cursorMark = (on) => on ? m.cursor : " ";
2594
3867
  return /* @__PURE__ */ jsxs(Box, {
2595
3868
  flexDirection: "row",
2596
- gap: 2,
3869
+ height: rows,
2597
3870
  children: [/* @__PURE__ */ jsxs(Box, {
2598
3871
  flexDirection: "column",
2599
- width: mainWidth,
3872
+ width: wide ? split.mainW : mainWidth,
3873
+ flexShrink: 0,
2600
3874
  children: [
2601
3875
  /* @__PURE__ */ jsx(Label, { children: "Your CLIs" }),
2602
3876
  !state.setup ? /* @__PURE__ */ jsxs(Text, {
@@ -2605,43 +3879,135 @@ function SetupScreen(props) {
2605
3879
  }) : cliRows.length === 0 ? /* @__PURE__ */ jsx(Text, {
2606
3880
  dimColor: true,
2607
3881
  children: "No supported CLI found. Install one, then press g."
2608
- }) : /* @__PURE__ */ jsx(ScrollList, {
2609
- items: cliRows,
2610
- selected: Math.min(at, cliRows.length - 1),
2611
- height: listHeight,
2612
- keyOf: (x) => x.cli,
2613
- renderItem: (x, sel) => /* @__PURE__ */ jsxs(Box, { children: [
2614
- /* @__PURE__ */ jsx(Text, { children: `${cursorMark(sel && at < clis.length)} ${box(picked.has(x.cli))} ` }),
2615
- /* @__PURE__ */ jsx(Chip, { cli: x.cli }),
2616
- /* @__PURE__ */ jsx(Text, { children: " " }),
2617
- /* @__PURE__ */ jsx(Box, {
2618
- width: labelW,
2619
- children: /* @__PURE__ */ jsx(Ell, {
2620
- width: labelW - 1,
2621
- bold: sel,
2622
- ...x.status === "not-installed" ? { dim: true } : {},
2623
- children: x.label
2624
- })
2625
- }),
2626
- /* @__PURE__ */ jsx(Box, {
2627
- width: statusW,
2628
- children: /* @__PURE__ */ jsx(Ell, {
2629
- width: statusW,
2630
- color: colourOf(x.status),
2631
- children: STATUS_WORD[x.status]
2632
- })
2633
- }),
2634
- noteW > 4 ? /* @__PURE__ */ jsx(Ell, {
2635
- width: noteW,
2636
- dim: true,
2637
- children: x.note ?? (x.version ? x.version : "")
2638
- }) : null
2639
- ] })
2640
- }),
3882
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(HeaderRow, {
3883
+ width: mainWidth,
3884
+ cols: [
3885
+ {
3886
+ w: 6,
3887
+ text: "",
3888
+ gap: 0
3889
+ },
3890
+ {
3891
+ w: 5,
3892
+ text: "",
3893
+ gap: 0
3894
+ },
3895
+ {
3896
+ w: labelW + 2,
3897
+ text: "CLI"
3898
+ },
3899
+ {
3900
+ w: 15,
3901
+ text: "Status"
3902
+ },
3903
+ {
3904
+ w: noteW,
3905
+ text: noteW > 4 ? "Note" : "",
3906
+ gap: 0
3907
+ }
3908
+ ]
3909
+ }), /* @__PURE__ */ jsx(Hit, {
3910
+ flexDirection: "column",
3911
+ onWheel: (d) => setCursor(Math.max(0, Math.min(total - 1, at + (d < 0 ? -1 : 1)))),
3912
+ isActive: active,
3913
+ children: /* @__PURE__ */ jsx(ScrollList, {
3914
+ items: cliRows,
3915
+ selected: Math.min(at, cliRows.length - 1),
3916
+ height: listHeight,
3917
+ keyOf: (x) => x.cli,
3918
+ renderItem: (x, sel, i) => {
3919
+ const off = x.status === "not-installed";
3920
+ return /* @__PURE__ */ jsx(Hit, {
3921
+ onClick: (e) => clickRow(i, x, e.double),
3922
+ isActive: active,
3923
+ children: /* @__PURE__ */ jsxs(Row, {
3924
+ width: mainWidth,
3925
+ selected: sel && at < clis.length,
3926
+ children: [
3927
+ /* @__PURE__ */ jsx(Cell, {
3928
+ w: 2,
3929
+ gap: 0,
3930
+ color: c.entry,
3931
+ children: cursorMark(sel && at < clis.length)
3932
+ }),
3933
+ /* @__PURE__ */ jsx(Hit, {
3934
+ onClick: () => {
3935
+ setCursor(i);
3936
+ togglePick(x);
3937
+ },
3938
+ isActive: active,
3939
+ children: /* @__PURE__ */ jsx(Cell, {
3940
+ w: 4,
3941
+ gap: 0,
3942
+ children: `${box(picked.has(x.cli))} `
3943
+ })
3944
+ }),
3945
+ /* @__PURE__ */ jsx(Box, {
3946
+ width: 5,
3947
+ flexShrink: 0,
3948
+ children: /* @__PURE__ */ jsx(Chip, {
3949
+ cli: x.cli,
3950
+ dim: off
3951
+ })
3952
+ }),
3953
+ /* @__PURE__ */ jsx(Cell, {
3954
+ w: labelW + 2,
3955
+ bold: sel,
3956
+ dim: off,
3957
+ children: x.label
3958
+ }),
3959
+ /* @__PURE__ */ jsx(Hit, {
3960
+ onClick: () => {
3961
+ setCursor(i);
3962
+ if (fixable(x)) setUp({ cli: x });
3963
+ },
3964
+ isActive: active,
3965
+ children: /* @__PURE__ */ jsx(Cell, {
3966
+ w: 15,
3967
+ color: colourOf(x.status),
3968
+ dim: off,
3969
+ children: STATUS_WORD[x.status]
3970
+ })
3971
+ }),
3972
+ noteW > 4 ? /* @__PURE__ */ jsx(Cell, {
3973
+ w: noteW,
3974
+ gap: 0,
3975
+ color: c.quiet,
3976
+ dim: !c.quiet,
3977
+ children: plain(x.note ?? (x.version ? x.version : ""), ascii)
3978
+ }) : null
3979
+ ]
3980
+ })
3981
+ });
3982
+ }
3983
+ })
3984
+ })] }),
2641
3985
  /* @__PURE__ */ jsx(Text, { children: " " }),
2642
3986
  /* @__PURE__ */ jsx(Label, { children: "Extras" }),
2643
- /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 0)} ${box(extras.helpers)} Get the Claude and Codex helpers when needed` }),
2644
- /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 1)} ${box(extras.askBeforeRisky)} Ask me before risky commands (beta)` }),
3987
+ /* @__PURE__ */ jsx(Hit, {
3988
+ onClick: () => {
3989
+ setCursor(clis.length);
3990
+ setUp({ extra: 0 });
3991
+ },
3992
+ isActive: active,
3993
+ children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 0)} ${box(extras.helpers)} Get the Claude and Codex helpers when needed` })
3994
+ }),
3995
+ /* @__PURE__ */ jsx(Hit, {
3996
+ onClick: () => {
3997
+ setCursor(clis.length + 1);
3998
+ setUp({ extra: 1 });
3999
+ },
4000
+ isActive: active,
4001
+ children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 1)} ${box(extras.askBeforeRisky)} Ask me before risky commands (beta)` })
4002
+ }),
4003
+ /* @__PURE__ */ jsx(Hit, {
4004
+ onClick: () => {
4005
+ setCursor(clis.length + 2);
4006
+ setUp({ extra: 2 });
4007
+ },
4008
+ isActive: active,
4009
+ children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 2)} ${box(mouseOn)} Click and scroll with the mouse` })
4010
+ }),
2645
4011
  !wide && health.length > 0 && rows >= 22 ? /* @__PURE__ */ jsxs(Box, {
2646
4012
  flexDirection: "column",
2647
4013
  marginTop: 1,
@@ -2656,9 +4022,9 @@ function SetupScreen(props) {
2656
4022
  children: "You see every change before it happens. We back up each file first."
2657
4023
  })
2658
4024
  ]
2659
- }), wide ? /* @__PURE__ */ jsxs(Box, {
2660
- flexDirection: "column",
2661
- width: sideWidth,
4025
+ }), wide ? /* @__PURE__ */ jsxs(Pane, {
4026
+ width: split.panelW,
4027
+ height: rows,
2662
4028
  children: [
2663
4029
  /* @__PURE__ */ jsx(Label, { children: "Checkup" }),
2664
4030
  health.length === 0 ? /* @__PURE__ */ jsxs(Text, {
@@ -2679,7 +4045,8 @@ function SetupScreen(props) {
2679
4045
  }
2680
4046
  // src/tui/screens/you.tsx
2681
4047
  var you_exports = /* @__PURE__ */ __exportAll({ default: () => You });
2682
- const PANEL_WIDTH = 34;
4048
+ /** Cards stop growing here, so they stay readable on a very wide terminal. */
4049
+ const MAX_MAIN = 110;
2683
4050
  const quiet = (c) => c.quiet ? { color: c.quiet } : { dimColor: true };
2684
4051
  /** `m:ss` left until `iso`, or undefined when there is no time limit. */
2685
4052
  function timeLeft(iso, now) {
@@ -2814,6 +4181,17 @@ function You(props) {
2814
4181
  }, failed);
2815
4182
  }
2816
4183
  };
4184
+ const step = (d) => setSelKey((prev) => {
4185
+ const at = Math.max(0, order.indexOf(prev ?? order[0] ?? ""));
4186
+ return order[Math.max(0, Math.min(order.length - 1, at + d))];
4187
+ });
4188
+ const pick = (key) => {
4189
+ if (typed) {
4190
+ setTyped(void 0);
4191
+ setDraft("");
4192
+ }
4193
+ setSelKey(key);
4194
+ };
2817
4195
  useInput((input, key) => {
2818
4196
  if (typed) {
2819
4197
  if (key.escape) {
@@ -2822,14 +4200,7 @@ function You(props) {
2822
4200
  }
2823
4201
  return;
2824
4202
  }
2825
- if (key.upArrow || key.downArrow) {
2826
- const d = key.upArrow ? -1 : 1;
2827
- setSelKey((prev) => {
2828
- const at = Math.max(0, order.indexOf(prev ?? order[0] ?? ""));
2829
- return order[Math.max(0, Math.min(order.length - 1, at + d))];
2830
- });
2831
- return;
2832
- }
4203
+ if (key.upArrow || key.downArrow) return step(key.upArrow ? -1 : 1);
2833
4204
  if (key.return) {
2834
4205
  if (curTicket && curTicket.kind !== "permission") setTyped({
2835
4206
  kind: "answer",
@@ -2851,7 +4222,8 @@ function You(props) {
2851
4222
  if (opt !== void 0) answer(curTicket, opt);
2852
4223
  }
2853
4224
  }, { isActive: active });
2854
- const listW = wide ? columns - PANEL_WIDTH - 2 : columns;
4225
+ const split = splitWidths(columns, wide, { maxMain: MAX_MAIN });
4226
+ const listW = wide ? split.mainW - 2 : Math.min(columns, MAX_MAIN);
2855
4227
  const inner = listW - 4;
2856
4228
  const dot = ascii ? "!" : "⚑";
2857
4229
  const textBox = (placeholder) => /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Text, {
@@ -2871,7 +4243,7 @@ function You(props) {
2871
4243
  const items = [];
2872
4244
  const head = (text, first) => /* @__PURE__ */ jsx(Box, {
2873
4245
  marginTop: first ? 0 : 1,
2874
- children: /* @__PURE__ */ jsx(Label, { children: text })
4246
+ children: /* @__PURE__ */ jsx(Label, { children: plain(text, ascii) })
2875
4247
  });
2876
4248
  if (open.length === 0) items.push({
2877
4249
  key: "none",
@@ -2910,10 +4282,39 @@ function You(props) {
2910
4282
  width: inner - 2,
2911
4283
  children: l === "" ? " " : l
2912
4284
  }, j))
2913
- }, "c"), /* @__PURE__ */ jsx(Ell, {
4285
+ }, "c"), /* @__PURE__ */ jsxs(Box, {
2914
4286
  width: inner,
2915
- color: c.quiet,
2916
- children: `y allow once n deny${left ? ` denied by itself in ${left}` : ""}`
4287
+ height: 1,
4288
+ overflow: "hidden",
4289
+ children: [
4290
+ /* @__PURE__ */ jsx(Hit, {
4291
+ onClick: () => void decide(t, true),
4292
+ flexShrink: 0,
4293
+ isActive: active,
4294
+ children: /* @__PURE__ */ jsx(Text, {
4295
+ ...quiet(c),
4296
+ children: "y allow once"
4297
+ })
4298
+ }),
4299
+ /* @__PURE__ */ jsx(Text, {
4300
+ ...quiet(c),
4301
+ children: " "
4302
+ }),
4303
+ /* @__PURE__ */ jsx(Hit, {
4304
+ onClick: () => void decide(t, false),
4305
+ flexShrink: 0,
4306
+ isActive: active,
4307
+ children: /* @__PURE__ */ jsx(Text, {
4308
+ ...quiet(c),
4309
+ children: "n deny"
4310
+ })
4311
+ }),
4312
+ /* @__PURE__ */ jsx(Text, {
4313
+ ...quiet(c),
4314
+ wrap: "truncate",
4315
+ children: left ? ` denied by itself in ${left}` : ""
4316
+ })
4317
+ ]
2917
4318
  }, "k"));
2918
4319
  } else {
2919
4320
  const q = wrapLines(t.question, inner).slice(0, 3);
@@ -2921,18 +4322,50 @@ function You(props) {
2921
4322
  width: inner,
2922
4323
  bold: true,
2923
4324
  color: c.stamp,
2924
- children: `${mark}? Question from ${who} · ${clockTime(t.createdAt)}`
4325
+ children: plain(`${mark}? Question from ${who} · ${clockTime(t.createdAt)}`, ascii)
2925
4326
  }, "t"), ...q.map((l, j) => /* @__PURE__ */ jsx(Ell, {
2926
4327
  width: inner,
2927
4328
  children: l === "" ? " " : l
2928
4329
  }, `q${j}`)));
2929
4330
  body = 2 + q.length + (editing ? draft.split("\n").length - 1 : 0);
2930
- const opts = (t.options ?? []).map((o, j) => `[${j + 1}] ${o}`).join(" ");
4331
+ const options = t.options ?? [];
4332
+ const typeOwn = () => {
4333
+ setSelKey(key);
4334
+ setDraft("");
4335
+ setTyped({
4336
+ kind: "answer",
4337
+ ticket: t
4338
+ });
4339
+ };
2931
4340
  if (editing) lines.push(/* @__PURE__ */ jsx(Box, { children: textBox("Type your answer…") }, "b"));
2932
- else lines.push(/* @__PURE__ */ jsx(Ell, {
4341
+ else lines.push(/* @__PURE__ */ jsxs(Box, {
2933
4342
  width: inner,
2934
- color: c.quiet,
2935
- children: opts ? `${opts} or type your own` : "Press Enter to type an answer"
4343
+ height: 1,
4344
+ overflow: "hidden",
4345
+ children: [options.map((o, j) => /* @__PURE__ */ jsxs(Box, {
4346
+ flexShrink: 0,
4347
+ children: [/* @__PURE__ */ jsx(Hit, {
4348
+ onClick: () => void answer(t, o),
4349
+ flexShrink: 0,
4350
+ isActive: active,
4351
+ children: /* @__PURE__ */ jsx(Text, {
4352
+ ...quiet(c),
4353
+ children: `[${j + 1}] ${o}`
4354
+ })
4355
+ }), /* @__PURE__ */ jsx(Text, {
4356
+ ...quiet(c),
4357
+ children: " "
4358
+ })]
4359
+ }, j)), /* @__PURE__ */ jsx(Hit, {
4360
+ onClick: typeOwn,
4361
+ flexShrink: 0,
4362
+ isActive: active,
4363
+ children: /* @__PURE__ */ jsx(Text, {
4364
+ ...quiet(c),
4365
+ wrap: "truncate",
4366
+ children: options.length > 0 ? " or type your own" : "Press Enter to type an answer"
4367
+ })
4368
+ })]
2936
4369
  }, "o"));
2937
4370
  }
2938
4371
  const height = body + 2;
@@ -2941,10 +4374,14 @@ function You(props) {
2941
4374
  height: height + (i === 0 ? 1 : 0),
2942
4375
  node: /* @__PURE__ */ jsxs(Box, {
2943
4376
  flexDirection: "column",
2944
- children: [i === 0 ? head(`Needs you · ${open.length}`, true) : null, /* @__PURE__ */ jsx(Card, {
2945
- accent,
2946
- width: listW,
2947
- children: lines
4377
+ children: [i === 0 ? head(`Needs you · ${open.length}`, true) : null, /* @__PURE__ */ jsx(Hit, {
4378
+ onClick: () => pick(key),
4379
+ isActive: active,
4380
+ children: /* @__PURE__ */ jsx(Card, {
4381
+ accent,
4382
+ width: listW,
4383
+ children: lines
4384
+ })
2948
4385
  })]
2949
4386
  })
2950
4387
  });
@@ -2962,10 +4399,25 @@ function You(props) {
2962
4399
  flexDirection: "column",
2963
4400
  children: [
2964
4401
  i === 0 ? head(`Messages · ${inbox.length}`, false) : null,
2965
- /* @__PURE__ */ jsx(Ell, {
2966
- width: listW,
2967
- bold: isSel,
2968
- children: line
4402
+ /* @__PURE__ */ jsx(Hit, {
4403
+ onClick: () => {
4404
+ setSelKey(key);
4405
+ setDraft("");
4406
+ setTyped({
4407
+ kind: "reply",
4408
+ message: m
4409
+ });
4410
+ },
4411
+ isActive: active,
4412
+ children: /* @__PURE__ */ jsx(Row, {
4413
+ width: listW,
4414
+ selected: isSel,
4415
+ children: /* @__PURE__ */ jsx(Ell, {
4416
+ width: listW,
4417
+ bold: isSel,
4418
+ children: line
4419
+ })
4420
+ })
2969
4421
  }),
2970
4422
  editing ? /* @__PURE__ */ jsx(Box, {
2971
4423
  paddingLeft: 2,
@@ -2999,26 +4451,37 @@ function You(props) {
2999
4451
  }
3000
4452
  return /* @__PURE__ */ jsxs(Box, {
3001
4453
  width: columns,
3002
- children: [/* @__PURE__ */ jsx(Box, {
4454
+ height: rows,
4455
+ children: [/* @__PURE__ */ jsx(Hit, {
3003
4456
  flexDirection: "column",
3004
- width: listW,
4457
+ width: wide ? split.mainW : listW,
4458
+ flexShrink: 0,
4459
+ onWheel: (d) => {
4460
+ if (!typed) step(d < 0 ? -1 : 1);
4461
+ },
4462
+ isActive: active,
3005
4463
  children: shown.map((it) => /* @__PURE__ */ jsx(Box, { children: it.node }, it.key))
3006
- }), wide ? /* @__PURE__ */ jsx(SidePanel, {
3007
- state,
3008
- width: PANEL_WIDTH,
3009
- now,
3010
- nameOf
4464
+ }), wide ? /* @__PURE__ */ jsx(Pane, {
4465
+ width: split.panelW,
4466
+ height: rows,
4467
+ children: /* @__PURE__ */ jsx(SidePanel, {
4468
+ state,
4469
+ width: paneInner(split.panelW),
4470
+ now,
4471
+ nameOf,
4472
+ active,
4473
+ onPick: pick
4474
+ })
3011
4475
  }) : null]
3012
4476
  });
3013
4477
  }
3014
- function SidePanel({ state, width, now, nameOf }) {
4478
+ function SidePanel({ state, width, now, nameOf, active, onPick }) {
3015
4479
  const { c, ascii } = useTheme();
3016
4480
  const open = state.tickets.filter((t) => t.status === "open");
3017
4481
  const doneToday = state.tickets.filter((t) => t.status !== "open" && sameDay(t.answeredAt ?? t.createdAt, now));
3018
4482
  const tick = ascii ? "ok" : "✓";
3019
4483
  return /* @__PURE__ */ jsxs(Box, {
3020
4484
  width,
3021
- marginLeft: 2,
3022
4485
  flexDirection: "column",
3023
4486
  children: [
3024
4487
  /* @__PURE__ */ jsx(Label, { children: `Open · ${open.length}` }),
@@ -3026,10 +4489,14 @@ function SidePanel({ state, width, now, nameOf }) {
3026
4489
  ...quiet(c),
3027
4490
  children: "Nothing open."
3028
4491
  }) : null,
3029
- open.slice(0, 6).map((t) => /* @__PURE__ */ jsx(Ell, {
3030
- width,
3031
- color: c.stamp,
3032
- children: `${t.kind === "permission" ? ascii ? "!" : "⚑" : "?"} ${nameOf(t.fromSession)} ${t.question}`
4492
+ open.slice(0, 6).map((t) => /* @__PURE__ */ jsx(Hit, {
4493
+ onClick: () => onPick(`t:${t.id}`),
4494
+ isActive: active,
4495
+ children: /* @__PURE__ */ jsx(Ell, {
4496
+ width,
4497
+ color: c.stamp,
4498
+ children: `${t.kind === "permission" ? ascii ? "!" : "⚑" : "?"} ${nameOf(t.fromSession)} ${t.question}`
4499
+ })
3033
4500
  }, t.id)),
3034
4501
  /* @__PURE__ */ jsx(Box, {
3035
4502
  marginTop: 1,
@@ -3075,15 +4542,17 @@ const MIN_COLUMNS = 60;
3075
4542
  const needYou = (s) => s.tickets.filter((t) => t.status === "open").length + s.unread;
3076
4543
  const SCREEN_LINE = {
3077
4544
  sessions: (s) => {
4545
+ const total = s.sessions.length;
4546
+ if (total === 0) return "No sessions yet";
3078
4547
  const live = s.sessions.filter((x) => x.status !== "offline").length;
3079
- return live === 1 ? "1 session running" : `${live} sessions running`;
4548
+ return `${total} ${total === 1 ? "session" : "sessions"} · ${live} running`;
3080
4549
  },
3081
4550
  you: () => "Questions and messages for you",
3082
4551
  new: () => "Start something new",
3083
4552
  devices: () => "Your machines",
3084
4553
  setup: () => "Get your tools ready"
3085
4554
  };
3086
- function TopBar({ state, screen, width }) {
4555
+ function TopBar({ state, screen, width, onYou }) {
3087
4556
  const { c, ascii } = useTheme();
3088
4557
  const need = needYou(state);
3089
4558
  const dot = ascii ? "*" : "●";
@@ -3098,10 +4567,11 @@ function TopBar({ state, screen, width }) {
3098
4567
  line = state.connectionDetail ?? "Something went wrong.";
3099
4568
  lineColor = c.error;
3100
4569
  }
3101
- const room = Math.max(0, width - 10 - right.length - 4);
3102
- return /* @__PURE__ */ jsxs(Box, {
4570
+ if (ascii) line = line.replace(/·/g, "-");
4571
+ const inner = width - 2;
4572
+ const room = Math.max(0, inner - 11 - (right ? right.length + 2 : 0));
4573
+ return /* @__PURE__ */ jsxs(Band, {
3103
4574
  width,
3104
- height: 1,
3105
4575
  children: [
3106
4576
  /* @__PURE__ */ jsx(Text, {
3107
4577
  bold: true,
@@ -3120,6 +4590,7 @@ function TopBar({ state, screen, width }) {
3120
4590
  /* @__PURE__ */ jsx(Text, { children: " " }),
3121
4591
  /* @__PURE__ */ jsx(Box, {
3122
4592
  width: room,
4593
+ flexShrink: 0,
3123
4594
  children: /* @__PURE__ */ jsx(Ell, {
3124
4595
  width: room,
3125
4596
  color: lineColor,
@@ -3127,74 +4598,185 @@ function TopBar({ state, screen, width }) {
3127
4598
  })
3128
4599
  }),
3129
4600
  /* @__PURE__ */ jsx(Box, { flexGrow: 1 }),
3130
- right ? /* @__PURE__ */ jsx(Text, {
3131
- bold: true,
3132
- ...c.stamp ? { color: c.stamp } : {},
3133
- children: right
4601
+ right ? /* @__PURE__ */ jsx(Clickable, {
4602
+ onClick: onYou,
4603
+ children: /* @__PURE__ */ jsx(Text, {
4604
+ bold: true,
4605
+ ...c.stamp ? { color: c.stamp } : {},
4606
+ children: right
4607
+ })
3134
4608
  }) : null
3135
4609
  ]
3136
4610
  });
3137
4611
  }
3138
- function Tabs({ screen, layout, youCount, width }) {
3139
- const { c } = useTheme();
4612
+ /** The tab row, and under it the rule with the active tab underlined in the entry colour. */
4613
+ function Tabs({ screen, layout, youCount, width, onGo }) {
4614
+ const { c, ascii } = useTheme();
3140
4615
  const narrow = layout === "narrow";
3141
- return /* @__PURE__ */ jsx(Box, {
4616
+ const labels = SCREENS.map((s) => {
4617
+ const on = s.id === screen;
4618
+ const extra = s.id === "you" && youCount > 0 ? ` (${youCount})` : "";
4619
+ return {
4620
+ id: s.id,
4621
+ on,
4622
+ text: narrow && !on ? s.key : `${s.key} ${s.title}${extra}`
4623
+ };
4624
+ });
4625
+ const gap = 2;
4626
+ let at = 1;
4627
+ let from = 0;
4628
+ let to = 0;
4629
+ for (const l of labels) {
4630
+ if (l.on) {
4631
+ from = at;
4632
+ to = at + l.text.length;
4633
+ }
4634
+ at += l.text.length + gap;
4635
+ }
4636
+ const thin = ascii ? "-" : "─";
4637
+ const heavy = ascii ? "=" : "━";
4638
+ const ruleColor = c.rule ? { color: c.rule } : { dimColor: true };
4639
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Box, {
3142
4640
  width,
3143
4641
  height: 1,
3144
- gap: 2,
3145
- children: SCREENS.map((s) => {
3146
- const on = s.id === screen;
3147
- const extra = s.id === "you" && youCount > 0 ? ` (${youCount})` : "";
3148
- const label = narrow && !on ? s.key : `${s.key} ${s.title}${extra}`;
3149
- return /* @__PURE__ */ jsx(Text, {
3150
- ...on ? {
3151
- bold: true,
3152
- underline: true
3153
- } : {},
3154
- ...on ? c.ink ? { color: c.ink } : {} : c.quiet ? { color: c.quiet } : {},
3155
- children: label
3156
- }, s.id);
4642
+ paddingX: 1,
4643
+ gap,
4644
+ children: labels.map((l) => /* @__PURE__ */ jsx(Clickable, {
4645
+ onClick: () => onGo(l.id),
4646
+ children: /* @__PURE__ */ jsx(Text, {
4647
+ ...l.on ? { bold: true } : {},
4648
+ ...l.on ? c.ink ? { color: c.ink } : {} : c.quiet ? { color: c.quiet } : {},
4649
+ children: l.text
4650
+ })
4651
+ }, l.id))
4652
+ }), /* @__PURE__ */ jsxs(Text, { children: [
4653
+ /* @__PURE__ */ jsx(Text, {
4654
+ ...ruleColor,
4655
+ children: thin.repeat(from)
4656
+ }),
4657
+ /* @__PURE__ */ jsx(Text, {
4658
+ ...c.entry ? { color: c.entry } : {},
4659
+ children: heavy.repeat(to - from)
4660
+ }),
4661
+ /* @__PURE__ */ jsx(Text, {
4662
+ ...ruleColor,
4663
+ children: thin.repeat(Math.max(0, width - to))
3157
4664
  })
3158
- });
4665
+ ] })] });
3159
4666
  }
3160
- function KeyBar({ keys, toast, width }) {
3161
- const { c } = useTheme();
4667
+ /** The bytes a key hint stands for, or undefined when it is not one single key. */
4668
+ function keySequence(key) {
4669
+ const n = {
4670
+ "⏎": "\r",
4671
+ Enter: "\r",
4672
+ Esc: "\x1B",
4673
+ Tab: " ",
4674
+ Space: " ",
4675
+ "↑": "\x1B[A",
4676
+ "↓": "\x1B[B",
4677
+ "→": "\x1B[C",
4678
+ "←": "\x1B[D",
4679
+ PgUp: "\x1B[5~",
4680
+ PgDn: "\x1B[6~"
4681
+ }[key];
4682
+ if (n) return n;
4683
+ const ctrl = /^Ctrl\+([A-Za-z])$/.exec(key);
4684
+ if (ctrl) return String.fromCharCode(ctrl[1].toUpperCase().charCodeAt(0) - 64);
4685
+ return [...key].length === 1 ? key : void 0;
4686
+ }
4687
+ function KeyBar({ keys, toast, width, onKey, onHelp, onDismiss }) {
4688
+ const { c, ascii } = useTheme();
4689
+ const inner = width - 2;
3162
4690
  if (toast) {
3163
4691
  const color = toast.level === "ok" ? c.ok : toast.level === "warn" ? c.warn : c.error;
3164
4692
  const mark = toast.level === "ok" ? "" : toast.level === "warn" ? "! " : "x ";
3165
- return /* @__PURE__ */ jsx(Box, {
4693
+ return /* @__PURE__ */ jsx(Band, {
3166
4694
  width,
3167
- height: 1,
3168
- children: /* @__PURE__ */ jsx(Ell, {
3169
- width,
3170
- color,
3171
- children: mark + toast.text
4695
+ children: /* @__PURE__ */ jsx(Clickable, {
4696
+ onClick: onDismiss,
4697
+ children: /* @__PURE__ */ jsx(Ell, {
4698
+ width: inner,
4699
+ color,
4700
+ children: mark + toast.text
4701
+ })
3172
4702
  })
3173
4703
  });
3174
4704
  }
3175
- const text = [...keys.map((k) => `${k.key} ${k.label}`), "? all keys"].join(" ");
3176
- return /* @__PURE__ */ jsx(Box, {
4705
+ const all = {
4706
+ key: "?",
4707
+ label: "all keys"
4708
+ };
4709
+ const shown = [];
4710
+ let used = all.key.length + 1 + all.label.length;
4711
+ for (const k0 of keys) {
4712
+ const k = {
4713
+ key: plain(k0.key, ascii),
4714
+ label: plain(k0.label, ascii),
4715
+ raw: k0.key
4716
+ };
4717
+ const w = k.key.length + 1 + k.label.length + 2;
4718
+ if (used + w > inner) break;
4719
+ used += w;
4720
+ shown.push(k);
4721
+ }
4722
+ return /* @__PURE__ */ jsx(Band, {
3177
4723
  width,
3178
- height: 1,
3179
- children: /* @__PURE__ */ jsx(Ell, {
3180
- width,
3181
- color: c.quiet,
3182
- children: text
4724
+ children: [...shown, all].map((k, i) => {
4725
+ const seq = k === all ? void 0 : keySequence(k.raw ?? k.key);
4726
+ return /* @__PURE__ */ jsx(Clickable, {
4727
+ isActive: k === all || seq !== void 0,
4728
+ onClick: () => k === all ? onHelp() : seq && onKey(seq),
4729
+ children: /* @__PURE__ */ jsxs(Text, {
4730
+ wrap: "truncate",
4731
+ children: [
4732
+ i > 0 ? " " : "",
4733
+ /* @__PURE__ */ jsx(Text, {
4734
+ bold: true,
4735
+ ...c.ink ? { color: c.ink } : {},
4736
+ children: k.key
4737
+ }),
4738
+ /* @__PURE__ */ jsx(Text, {
4739
+ ...c.quiet ? { color: c.quiet } : {},
4740
+ children: ` ${k.label}`
4741
+ })
4742
+ ]
4743
+ })
4744
+ }, `${k.key}-${k.label}`);
3183
4745
  })
3184
4746
  });
3185
4747
  }
3186
- function App({ store, theme, onQuit, size }) {
4748
+ function App({ store, theme, onQuit, size, mouse }) {
3187
4749
  return /* @__PURE__ */ jsx(ThemeProvider, {
3188
4750
  ...theme ? { theme } : {},
3189
4751
  children: /* @__PURE__ */ jsx(Shell, {
3190
4752
  store,
3191
4753
  onQuit,
3192
- size
4754
+ size,
4755
+ mouse
3193
4756
  })
3194
4757
  });
3195
4758
  }
3196
- function Shell({ store, onQuit, size }) {
4759
+ function Shell({ store, onQuit, size, mouse }) {
3197
4760
  const { exit } = useApp();
4761
+ const { stdin } = useStdin();
4762
+ const stdinRef = useRef(stdin);
4763
+ stdinRef.current = stdin;
4764
+ const [hub] = useState(() => mouse ?? new MouseHub({ inject: (k) => stdinRef.current.write?.(k) }));
4765
+ useEffect(() => {
4766
+ if (mouse) return;
4767
+ const parser = new MouseParser();
4768
+ const onData = (chunk) => {
4769
+ for (const e of parser.push(String(chunk)).events) hub.dispatch(e);
4770
+ };
4771
+ stdin.on("data", onData);
4772
+ return () => {
4773
+ stdin.removeListener("data", onData);
4774
+ };
4775
+ }, [
4776
+ mouse,
4777
+ hub,
4778
+ stdin
4779
+ ]);
3198
4780
  const win = useWindowSize();
3199
4781
  const columns = size?.columns ?? win.columns;
3200
4782
  const rows = size?.rows ?? win.rows;
@@ -3251,17 +4833,26 @@ function Shell({ store, onQuit, size }) {
3251
4833
  bump((n) => n + 1);
3252
4834
  }
3253
4835
  }, []);
3254
- const showToast = useCallback((text, level = "ok") => {
4836
+ const showToast = useCallback((text, level = "ok", ms = TOAST_MS) => {
3255
4837
  toastId.current += 1;
3256
4838
  setToast({
3257
4839
  id: toastId.current,
3258
4840
  text,
3259
- level
4841
+ level,
4842
+ ms
3260
4843
  });
3261
4844
  }, []);
4845
+ useEffect(() => {
4846
+ if (!hub.showHint) return;
4847
+ showToast("Mouse is on. Hold Shift to select text.", "ok", 1e4);
4848
+ hub.hintShown();
4849
+ }, [hub, showToast]);
4850
+ useEffect(() => hub.onUnhandled(() => {
4851
+ if (overlayRef.current !== "none") setOverlay("none");
4852
+ }), [hub]);
3262
4853
  useEffect(() => {
3263
4854
  if (!toast) return;
3264
- const t = setTimeout(() => setToast((cur) => cur?.id === toast.id ? void 0 : cur), TOAST_MS);
4855
+ const t = setTimeout(() => setToast((cur) => cur?.id === toast.id ? void 0 : cur), toast.ms);
3265
4856
  return () => clearTimeout(t);
3266
4857
  }, [toast]);
3267
4858
  useEffect(() => {
@@ -3356,74 +4947,88 @@ function Shell({ store, onQuit, size }) {
3356
4947
  })]
3357
4948
  });
3358
4949
  const Screen = SCREEN_COMPONENTS[screen];
3359
- const bodyRows = Math.max(3, rows - 3);
3360
- const inner = columns - 2;
3361
- const overlayWidth = Math.min(inner, 72);
3362
- return /* @__PURE__ */ jsx(DraftProvider, {
3363
- value: draftCtx,
3364
- children: /* @__PURE__ */ jsxs(Box, {
3365
- width: columns,
3366
- height: rows,
3367
- flexDirection: "column",
3368
- paddingX: 1,
3369
- children: [
3370
- /* @__PURE__ */ jsx(TopBar, {
3371
- state,
3372
- screen,
3373
- width: inner
3374
- }),
3375
- /* @__PURE__ */ jsx(Tabs, {
3376
- screen,
3377
- layout,
3378
- youCount,
3379
- width: inner
3380
- }),
3381
- /* @__PURE__ */ jsxs(Box, {
3382
- height: bodyRows,
3383
- width: inner,
3384
- flexDirection: "column",
3385
- overflow: "hidden",
3386
- children: [
3387
- overlay === "palette" ? /* @__PURE__ */ jsx(Palette, {
3388
- commands,
3389
- width: overlayWidth,
4950
+ const bodyRows = Math.max(3, rows - 4);
4951
+ const inner = columns - 1;
4952
+ const overlayWidth = Math.min(inner - 2, 72);
4953
+ return /* @__PURE__ */ jsx(MouseProvider, {
4954
+ value: hub,
4955
+ children: /* @__PURE__ */ jsx(DraftProvider, {
4956
+ value: draftCtx,
4957
+ children: /* @__PURE__ */ jsxs(Box, {
4958
+ width: columns,
4959
+ height: rows,
4960
+ flexDirection: "column",
4961
+ children: [
4962
+ /* @__PURE__ */ jsx(TopBar, {
4963
+ state,
4964
+ screen,
4965
+ width: columns,
4966
+ onYou: () => go("you")
4967
+ }),
4968
+ /* @__PURE__ */ jsx(Tabs, {
4969
+ screen,
4970
+ layout,
4971
+ youCount,
4972
+ width: columns,
4973
+ onGo: go
4974
+ }),
4975
+ /* @__PURE__ */ jsxs(Box, {
4976
+ height: bodyRows,
4977
+ width: columns,
4978
+ paddingLeft: 1,
4979
+ flexDirection: "column",
4980
+ overflow: "hidden",
4981
+ children: [overlay !== "none" ? /* @__PURE__ */ jsx(Box, {
3390
4982
  height: bodyRows,
3391
- onClose: () => setOverlay("none")
3392
- }) : null,
3393
- overlay === "help" ? /* @__PURE__ */ jsx(Help, {
3394
- screenTitle: SCREENS.find((s) => s.id === screen)?.title ?? "",
3395
- screenKeys: keys,
3396
- width: overlayWidth,
3397
- onClose: () => setOverlay("none")
3398
- }) : null,
3399
- /* @__PURE__ */ jsx(Box, {
4983
+ width: inner,
4984
+ justifyContent: "center",
4985
+ alignItems: "flex-start",
4986
+ paddingTop: 1,
4987
+ children: overlay === "palette" ? /* @__PURE__ */ jsx(Palette, {
4988
+ commands,
4989
+ width: overlayWidth,
4990
+ height: bodyRows,
4991
+ onClose: () => setOverlay("none")
4992
+ }) : /* @__PURE__ */ jsx(Help, {
4993
+ screenTitle: SCREENS.find((s) => s.id === screen)?.title ?? "",
4994
+ screenKeys: keys,
4995
+ width: overlayWidth,
4996
+ onClose: () => setOverlay("none")
4997
+ })
4998
+ }) : null, /* @__PURE__ */ jsx(Box, {
3400
4999
  display: overlay === "none" ? "flex" : "none",
3401
5000
  flexDirection: "column",
3402
5001
  height: bodyRows,
3403
- children: /* @__PURE__ */ jsx(Screen, {
3404
- state,
3405
- actions: store.actions,
3406
- layout,
3407
- rows: bodyRows,
3408
- columns: inner,
5002
+ children: /* @__PURE__ */ jsx(MouseScope, {
3409
5003
  active: overlay === "none",
3410
- focus,
3411
- setKeys,
3412
- setCommands,
3413
- go,
3414
- toast: showToast,
3415
- setTyping,
3416
- claimKeys
3417
- }, screen)
3418
- })
3419
- ]
3420
- }),
3421
- /* @__PURE__ */ jsx(KeyBar, {
3422
- keys,
3423
- ...toast ? { toast } : {},
3424
- width: inner
3425
- })
3426
- ]
5004
+ children: /* @__PURE__ */ jsx(Screen, {
5005
+ state,
5006
+ actions: store.actions,
5007
+ layout,
5008
+ rows: bodyRows,
5009
+ columns: inner,
5010
+ active: overlay === "none",
5011
+ focus,
5012
+ setKeys,
5013
+ setCommands,
5014
+ go,
5015
+ toast: showToast,
5016
+ setTyping,
5017
+ claimKeys
5018
+ }, screen)
5019
+ })
5020
+ })]
5021
+ }),
5022
+ /* @__PURE__ */ jsx(KeyBar, {
5023
+ keys,
5024
+ ...toast ? { toast } : {},
5025
+ width: columns,
5026
+ onKey: (seq) => hub.press(seq),
5027
+ onHelp: () => setOverlay("help"),
5028
+ onDismiss: () => setToast(void 0)
5029
+ })
5030
+ ]
5031
+ })
3427
5032
  })
3428
5033
  });
3429
5034
  }
@@ -3742,6 +5347,10 @@ function setHelpers(ctx, on) {
3742
5347
  * can take. It loads once, then follows `events.subscribe` and polls what has no event (sync and
3743
5348
  * devices). When the daemon goes away it says so and reconnects with a growing wait.
3744
5349
  */
5350
+ /** How many messages the app holds in memory per session's chat. */
5351
+ const HISTORY_KEEP = 1e3;
5352
+ /** Page size when loading a session's chat from the daemon. */
5353
+ const HISTORY_PAGE = 100;
3745
5354
  const POLL_MS = 15e3;
3746
5355
  const WATCH_MS = 5e3;
3747
5356
  const STOP_WAIT_MS = 1e4;
@@ -3758,7 +5367,8 @@ const initial = () => ({
3758
5367
  inbox: [],
3759
5368
  unread: 0,
3760
5369
  tickets: [],
3761
- history: {}
5370
+ history: {},
5371
+ historyMore: {}
3762
5372
  });
3763
5373
  const reason = (e) => e instanceof Error ? e.message : String(e);
3764
5374
  /** The tickets the owner can act on: addressed to them, or a permission request. */
@@ -3770,6 +5380,8 @@ function upsert(list, item) {
3770
5380
  next[i] = item;
3771
5381
  return next;
3772
5382
  }
5383
+ /** Time order; the id (a ULID) breaks ties. */
5384
+ const byTime = (a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id);
3773
5385
  const byCreated = (a, b) => a.createdAt.localeCompare(b.createdAt);
3774
5386
  async function createStore(ctx, opts = {}) {
3775
5387
  const open = opts.connect ?? (() => ctx.connect(connectOpts(ctx, true)));
@@ -3793,10 +5405,23 @@ async function createStore(ctx, opts = {}) {
3793
5405
  return client;
3794
5406
  };
3795
5407
  /** Which session a message belongs to in the chat view: the other side of the conversation. */
3796
- function historyKey(m) {
3797
- if (m.from !== OWNER_SESSION_ID) return m.from;
5408
+ /** Every session whose chat shows this message: the sender and the recipient (not `you`). */
5409
+ function historyKeys(m) {
5410
+ const keys = /* @__PURE__ */ new Set();
5411
+ if (m.from !== OWNER_SESSION_ID) keys.add(m.from);
3798
5412
  const to = m.to;
3799
- return state.sessions.find((s) => s.id === to || s.name === to)?.id;
5413
+ const target = to === "orchestrator" ? state.sessions.find((s) => s.isOrchestrator) : state.sessions.find((s) => s.id === to || s.name === to);
5414
+ if (target) keys.add(target.id);
5415
+ return [...keys];
5416
+ }
5417
+ /** Merge messages into a session's chat: no duplicates, oldest first, at most HISTORY_KEEP. */
5418
+ function mergeHistory(cur, add, keep) {
5419
+ const seen = new Set(cur.map((x) => x.id));
5420
+ const fresh = add.filter((x) => !seen.has(x.id));
5421
+ if (fresh.length === 0) return cur;
5422
+ const all = [...cur, ...fresh].sort(byTime);
5423
+ if (all.length <= 1e3) return all;
5424
+ return keep === "newest" ? all.slice(-1e3) : all.slice(0, HISTORY_KEEP);
3800
5425
  }
3801
5426
  function addMessage(m) {
3802
5427
  const patch = {};
@@ -3804,12 +5429,16 @@ async function createStore(ctx, opts = {}) {
3804
5429
  patch.inbox = [...state.inbox, m].sort(byCreated).slice(-100);
3805
5430
  patch.unread = state.unread + 1;
3806
5431
  }
3807
- const key = historyKey(m);
3808
- if (key) {
3809
- const cur = state.history[key] ?? [];
3810
- if (!cur.some((x) => x.id === m.id)) patch.history = {
3811
- ...state.history,
3812
- [key]: [...cur, m].sort(byCreated).slice(-100)
5432
+ for (const key of historyKeys(m)) {
5433
+ const cur = (patch.history ?? state.history)[key] ?? [];
5434
+ if (cur.some((x) => x.id === m.id)) continue;
5435
+ patch.history = {
5436
+ ...patch.history ?? state.history,
5437
+ [key]: mergeHistory(cur, [m], "newest")
5438
+ };
5439
+ if (cur.length >= 1e3) patch.historyMore = {
5440
+ ...patch.historyMore ?? state.historyMore,
5441
+ [key]: true
3813
5442
  };
3814
5443
  }
3815
5444
  if (patch.inbox || patch.history) set(patch);
@@ -3886,10 +5515,7 @@ async function createStore(ctx, opts = {}) {
3886
5515
  ]);
3887
5516
  const tickets = [...open.tickets, ...answered.tickets].filter(forOwner);
3888
5517
  const history = { ...state.history };
3889
- for (const m of inbox.messages) {
3890
- const cur = history[m.from] ?? [];
3891
- if (!cur.some((x) => x.id === m.id)) history[m.from] = [...cur, m].sort(byCreated).slice(-100);
3892
- }
5518
+ for (const m of inbox.messages) history[m.from] = mergeHistory(history[m.from] ?? [], [m], "newest");
3893
5519
  set({
3894
5520
  sessions: sessions.sessions,
3895
5521
  inbox: inbox.messages.slice(-100),
@@ -4043,7 +5669,50 @@ async function createStore(ctx, opts = {}) {
4043
5669
  }).catch(() => void 0);
4044
5670
  return { sessionId: res.id };
4045
5671
  },
4046
- async loadHistory() {},
5672
+ async loadHistory(sessionId) {
5673
+ const res = await live()["message.history"]({
5674
+ session: sessionId,
5675
+ limit: HISTORY_PAGE
5676
+ });
5677
+ const cur = state.history[sessionId] ?? [];
5678
+ set({
5679
+ history: {
5680
+ ...state.history,
5681
+ [sessionId]: mergeHistory(cur, res.messages, "newest")
5682
+ },
5683
+ historyMore: {
5684
+ ...state.historyMore,
5685
+ [sessionId]: res.more
5686
+ }
5687
+ });
5688
+ },
5689
+ async loadOlder(sessionId) {
5690
+ const cur = state.history[sessionId] ?? [];
5691
+ const oldest = cur[0];
5692
+ if (!oldest) {
5693
+ await actions.loadHistory(sessionId);
5694
+ return (state.history[sessionId]?.length ?? 0) > 0;
5695
+ }
5696
+ if (state.historyMore[sessionId] === false || cur.length >= 1e3) return false;
5697
+ const res = await live()["message.history"]({
5698
+ session: sessionId,
5699
+ limit: HISTORY_PAGE,
5700
+ before: oldest.id
5701
+ });
5702
+ const now = state.history[sessionId] ?? [];
5703
+ const merged = mergeHistory(now, res.messages, "oldest");
5704
+ set({
5705
+ history: {
5706
+ ...state.history,
5707
+ [sessionId]: merged
5708
+ },
5709
+ historyMore: {
5710
+ ...state.historyMore,
5711
+ [sessionId]: res.more && merged.length < 1e3
5712
+ }
5713
+ });
5714
+ return merged.length > now.length;
5715
+ },
4047
5716
  async refreshSetup() {
4048
5717
  await loadSetupData();
4049
5718
  },
@@ -4148,11 +5817,14 @@ async function runTui(ctx) {
4148
5817
  used = true;
4149
5818
  return Promise.resolve(first);
4150
5819
  } });
5820
+ const input = createMouseInput(ctx);
4151
5821
  try {
4152
5822
  await render(/* @__PURE__ */ jsx(App, {
4153
5823
  store,
4154
- theme: uiThemeFrom(ctx.theme)
5824
+ theme: uiThemeFrom(ctx.theme),
5825
+ mouse: input.hub
4155
5826
  }), {
5827
+ stdin: input.stdin,
4156
5828
  alternateScreen: true,
4157
5829
  exitOnCtrlC: false,
4158
5830
  patchConsole: true
@@ -4167,6 +5839,7 @@ async function runTui(ctx) {
4167
5839
  ref: "e_internal"
4168
5840
  });
4169
5841
  } finally {
5842
+ input.dispose();
4170
5843
  await store.close();
4171
5844
  }
4172
5845
  }