@conveno/cli 0.2.0-rc.7 → 0.2.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{acp-9pRRszwU.js → acp-BVk6rmXR.js} +3 -3
- package/dist/{agy-relay-C-nqvieJ.js → agy-relay-D8eZcLuc.js} +2 -2
- package/dist/{args-C7Agak9f.js → args-B3Cj2Ie4.js} +90 -50
- package/dist/bin.js +2 -2
- package/dist/daemon.js +20 -7
- package/dist/{daemonError-DNAKEyRT.js → daemonError-C05GqdhQ.js} +1 -1
- package/dist/{dist-D9Gu-mQm.js → dist-BjdBeCHy.js} +143 -48
- package/dist/{dist-iFaY42Bs.js → dist-CVdpCNJo.js} +1 -1
- package/dist/{dist-ftx5RNCp.js → dist-D_O_JLLq.js} +1 -1
- package/dist/{dist-Dd31Fg0h.js → dist-DaIpdMke.js} +46 -50
- package/dist/{dist-DOKVrSIw.js → dist-DzpERiRx.js} +3 -3
- package/dist/{dist-DOGlDbRb.js → dist-MK-cK1JY.js} +487 -22
- package/dist/{dist-D2hMvcZu.js → dist-STNJjbNH.js} +186 -56
- package/dist/{hook-CQeSn-w4.js → hook-CDF1A8AY.js} +26 -3
- package/dist/{hook-entry-BXmSN--S.js → hook-entry-BTJK7aO0.js} +19 -9
- package/dist/hook-entry-D6zup0QV.js +1 -0
- package/dist/{main-seh-HPZO.js → main-Kv31Qxro.js} +61 -382
- package/dist/{pick-DoyocW55.js → pick-DLp6w_-z.js} +1 -1
- package/dist/run-BPtFUGtu.js +5609 -0
- package/dist/{runtime-Bnjh9BQ8.js → runtime-xjPzIGmp.js} +72 -13
- package/dist/{doctor-BYa-MApu.js → uninstall-8AHErPRN.js} +581 -48
- package/dist/{watch-Dr2RdyGo.js → watch-D0KIPowJ.js} +4 -4
- package/package.json +19 -16
- package/dist/hook-entry-CgiSN-Oj.js +0 -1
- package/dist/run-B-WfNtCX.js +0 -4507
package/dist/run-B-WfNtCX.js
DELETED
|
@@ -1,4507 +0,0 @@
|
|
|
1
|
-
import { Box, Text, render, useApp, useInput, useStdin, useWindowSize } from "ink";
|
|
2
|
-
import { n as connectOpts, t as adapterEnv } from "./ctx-tYftvhz_.js";
|
|
3
|
-
import { t as daemonProblem } from "./daemonError-DNAKEyRT.js";
|
|
4
|
-
import { a as fail, n as cmd, s as plainError, u as tilde } from "./fmt-C2SsP5Y0.js";
|
|
5
|
-
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
6
|
-
import { readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
7
|
-
import { Readable } from "node:stream";
|
|
8
|
-
import { Ct as realSpawnDeps, E as compatStatus, H as fetchAccountStatus, It as spawnRecordPath, Lt as spawnSession, M as dataPaths, St as readSpawnRecord, Yt as writeSettings, _t as readAccountTokens, xt as readSettings } from "./dist-D2hMvcZu.js";
|
|
9
|
-
import { homedir } from "node:os";
|
|
10
|
-
import { i as tokens, n as detectColorLevel, r as detectUnicode } from "./dist-BRjg9CLd.js";
|
|
11
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
-
import { basename, join, resolve } from "node:path";
|
|
13
|
-
import { _ as PAIR_TIMEOUT_MS, b as openInBrowser, d as applyChanges, g as unifiedDiff, o as pendingOptions, r as collectPlans, t as inspect, u as StaleError } from "./doctor-BYa-MApu.js";
|
|
14
|
-
import { r as stopRequestPath, t as killProcessTree } from "./dist-DOKVrSIw.js";
|
|
15
|
-
// \0rolldown/runtime.js
|
|
16
|
-
var __defProp = Object.defineProperty;
|
|
17
|
-
var __exportAll = (all, flags) => {
|
|
18
|
-
let target = Object.setPrototypeOf({}, null);
|
|
19
|
-
for (var name in all) __defProp(target, name, {
|
|
20
|
-
get: all[name],
|
|
21
|
-
enumerable: true
|
|
22
|
-
});
|
|
23
|
-
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
24
|
-
return flags & 2 ? target : Object.preventExtensions(target);
|
|
25
|
-
};
|
|
26
|
-
// src/tui/contract.ts
|
|
27
|
-
function layoutFor(columns) {
|
|
28
|
-
if (columns >= 120) return "wide";
|
|
29
|
-
if (columns >= 80) return "normal";
|
|
30
|
-
if (columns >= 60) return "narrow";
|
|
31
|
-
return "tiny";
|
|
32
|
-
}
|
|
33
|
-
const SCREENS = [
|
|
34
|
-
{
|
|
35
|
-
id: "sessions",
|
|
36
|
-
key: "1",
|
|
37
|
-
title: "Sessions"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
id: "new",
|
|
41
|
-
key: "2",
|
|
42
|
-
title: "New"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
id: "devices",
|
|
46
|
-
key: "3",
|
|
47
|
-
title: "Devices"
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
id: "setup",
|
|
51
|
-
key: "4",
|
|
52
|
-
title: "Setup"
|
|
53
|
-
}
|
|
54
|
-
];
|
|
55
|
-
// src/tui/mouse.ts
|
|
56
|
-
/**
|
|
57
|
-
* Mouse support for the app, with no React in it: an SGR mouse parser, a stream that sits between
|
|
58
|
-
* the real stdin and Ink and strips mouse reports out of the bytes, and a hub that hit-tests
|
|
59
|
-
* registered boxes. `ui.tsx` wraps the hub in hooks.
|
|
60
|
-
*/
|
|
61
|
-
const ESC = "\x1B";
|
|
62
|
-
const PASTE_START = `${ESC}[200~`;
|
|
63
|
-
const PASTE_END = `${ESC}[201~`;
|
|
64
|
-
const SGR = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])/;
|
|
65
|
-
const SGR_PREFIX = /^\x1b(?:\[(?:<[0-9;]*)?)?$/;
|
|
66
|
-
/** Turn the numbers of an SGR report into an event. */
|
|
67
|
-
function sgrEvent(b, x, y, final) {
|
|
68
|
-
const wheel = (b & 64) !== 0;
|
|
69
|
-
const motion = (b & 32) !== 0;
|
|
70
|
-
const low = b & 3;
|
|
71
|
-
return {
|
|
72
|
-
kind: wheel ? "wheel" : motion ? "move" : final === "m" ? "release" : "press",
|
|
73
|
-
button: wheel ? "left" : low === 1 ? "middle" : low === 2 ? "right" : "left",
|
|
74
|
-
x: Math.max(0, x - 1),
|
|
75
|
-
y: Math.max(0, y - 1),
|
|
76
|
-
delta: wheel ? (b & 1) === 0 ? -1 : 1 : 0,
|
|
77
|
-
shift: (b & 4) !== 0,
|
|
78
|
-
alt: (b & 8) !== 0,
|
|
79
|
-
ctrl: (b & 16) !== 0
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Takes the bytes the terminal sends and splits them into the text Ink should see and mouse
|
|
84
|
-
* events. A report cut by a chunk boundary is held until the rest arrives (`flush` gives it up
|
|
85
|
-
* when nothing follows). Bracketed paste passes through as it is, mouse-looking text included.
|
|
86
|
-
*/
|
|
87
|
-
var MouseParser = class {
|
|
88
|
-
held = "";
|
|
89
|
-
inPaste = false;
|
|
90
|
-
push(chunk) {
|
|
91
|
-
const s = this.held + chunk;
|
|
92
|
-
this.held = "";
|
|
93
|
-
const events = [];
|
|
94
|
-
let text = "";
|
|
95
|
-
let i = 0;
|
|
96
|
-
while (i < s.length) {
|
|
97
|
-
if (this.inPaste) {
|
|
98
|
-
const end = s.indexOf(PASTE_END, i);
|
|
99
|
-
if (end >= 0) {
|
|
100
|
-
text += s.slice(i, end + PASTE_END.length);
|
|
101
|
-
i = end + PASTE_END.length;
|
|
102
|
-
this.inPaste = false;
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
let keep = 0;
|
|
106
|
-
for (let n = Math.min(PASTE_END.length - 1, s.length - i); n > 0; n--) if (PASTE_END.startsWith(s.slice(s.length - n))) {
|
|
107
|
-
keep = n;
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
text += s.slice(i, s.length - keep);
|
|
111
|
-
this.held = s.slice(s.length - keep);
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
const esc = s.indexOf(ESC, i);
|
|
115
|
-
if (esc < 0) {
|
|
116
|
-
text += s.slice(i);
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
text += s.slice(i, esc);
|
|
120
|
-
const rest = s.slice(esc);
|
|
121
|
-
const m = SGR.exec(rest);
|
|
122
|
-
if (m) {
|
|
123
|
-
events.push(sgrEvent(Number(m[1]), Number(m[2]), Number(m[3]), m[4]));
|
|
124
|
-
i = esc + m[0].length;
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
if (rest.startsWith(PASTE_START)) {
|
|
128
|
-
text += PASTE_START;
|
|
129
|
-
this.inPaste = true;
|
|
130
|
-
i = esc + PASTE_START.length;
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
if (SGR_PREFIX.test(rest) || rest.length < PASTE_START.length && isPasteStartPrefix(rest)) {
|
|
134
|
-
this.held = rest;
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
text += ESC;
|
|
138
|
-
i = esc + 1;
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
text,
|
|
142
|
-
events
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
/** Whether bytes are being held back. */
|
|
146
|
-
get pending() {
|
|
147
|
-
return this.held !== "";
|
|
148
|
-
}
|
|
149
|
-
/** Give up what is held: it was not a mouse report after all. */
|
|
150
|
-
flush() {
|
|
151
|
-
const h = this.held;
|
|
152
|
-
this.held = "";
|
|
153
|
-
return h;
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
function isPasteStartPrefix(s) {
|
|
157
|
-
return PASTE_START.startsWith(s);
|
|
158
|
-
}
|
|
159
|
-
/** Position of a box on the screen, in cells. Zero size when it is not laid out or hidden. */
|
|
160
|
-
function boxRect(node) {
|
|
161
|
-
const own = node.yogaNode;
|
|
162
|
-
if (!own) return {
|
|
163
|
-
x: 0,
|
|
164
|
-
y: 0,
|
|
165
|
-
w: 0,
|
|
166
|
-
h: 0
|
|
167
|
-
};
|
|
168
|
-
let x = own.getComputedLeft();
|
|
169
|
-
let y = own.getComputedTop();
|
|
170
|
-
for (let p = node.parentNode; p; p = p.parentNode) if (p.yogaNode) {
|
|
171
|
-
x += p.yogaNode.getComputedLeft();
|
|
172
|
-
y += p.yogaNode.getComputedTop();
|
|
173
|
-
}
|
|
174
|
-
return {
|
|
175
|
-
x,
|
|
176
|
-
y,
|
|
177
|
-
w: own.getComputedWidth(),
|
|
178
|
-
h: own.getComputedHeight()
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
function depthOf(node) {
|
|
182
|
-
let d = 0;
|
|
183
|
-
for (let p = node.parentNode; p; p = p.parentNode) d++;
|
|
184
|
-
return d;
|
|
185
|
-
}
|
|
186
|
-
const ENABLE_SEQ = "\x1B[?1000h\x1B[?1006h";
|
|
187
|
-
const DISABLE_SEQ = "\x1B[?1006l\x1B[?1002l\x1B[?1000l";
|
|
188
|
-
/** Hit testing and dispatch. One per running app. */
|
|
189
|
-
var MouseHub = class {
|
|
190
|
-
targets = [];
|
|
191
|
-
listeners = /* @__PURE__ */ new Set();
|
|
192
|
-
fallbacks = /* @__PURE__ */ new Set();
|
|
193
|
-
last;
|
|
194
|
-
on;
|
|
195
|
-
reporter;
|
|
196
|
-
available;
|
|
197
|
-
forcedOff;
|
|
198
|
-
showHint;
|
|
199
|
-
inject;
|
|
200
|
-
persist;
|
|
201
|
-
markHint;
|
|
202
|
-
now;
|
|
203
|
-
constructor(opts = {}) {
|
|
204
|
-
this.available = opts.available ?? true;
|
|
205
|
-
this.forcedOff = opts.forcedOff ?? false;
|
|
206
|
-
this.on = this.available && !this.forcedOff && (opts.enabled ?? true);
|
|
207
|
-
this.showHint = (opts.showHint ?? false) && this.on;
|
|
208
|
-
this.inject = opts.inject ?? (() => void 0);
|
|
209
|
-
this.persist = opts.persist;
|
|
210
|
-
this.markHint = opts.markHintShown;
|
|
211
|
-
this.now = opts.now ?? Date.now;
|
|
212
|
-
}
|
|
213
|
-
get enabled() {
|
|
214
|
-
return this.on;
|
|
215
|
-
}
|
|
216
|
-
/** Switch the mouse on or off at once; with `persist` the choice is also kept. */
|
|
217
|
-
setEnabled(on, persist = false) {
|
|
218
|
-
if (persist) this.persist?.(on);
|
|
219
|
-
const next = on && this.available && !this.forcedOff;
|
|
220
|
-
if (next === this.on) return;
|
|
221
|
-
this.on = next;
|
|
222
|
-
this.last = void 0;
|
|
223
|
-
this.reporter?.(next);
|
|
224
|
-
for (const l of this.listeners) l();
|
|
225
|
-
}
|
|
226
|
-
/** Called by the stream that sends the enable and disable sequences. */
|
|
227
|
-
attachReporter(fn) {
|
|
228
|
-
this.reporter = fn;
|
|
229
|
-
}
|
|
230
|
-
subscribe = (l) => {
|
|
231
|
-
this.listeners.add(l);
|
|
232
|
-
return () => this.listeners.delete(l);
|
|
233
|
-
};
|
|
234
|
-
getEnabled = () => this.on;
|
|
235
|
-
hintShown() {
|
|
236
|
-
this.markHint?.();
|
|
237
|
-
}
|
|
238
|
-
/** Type keys into the app, as if pressed. */
|
|
239
|
-
press(keys) {
|
|
240
|
-
this.inject(keys);
|
|
241
|
-
}
|
|
242
|
-
register(t) {
|
|
243
|
-
this.targets.push(t);
|
|
244
|
-
return () => {
|
|
245
|
-
this.targets = this.targets.filter((x) => x !== t);
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
/** Called with a press that no box took. */
|
|
249
|
-
onUnhandled(fn) {
|
|
250
|
-
this.fallbacks.add(fn);
|
|
251
|
-
return () => this.fallbacks.delete(fn);
|
|
252
|
-
}
|
|
253
|
-
/** The innermost active target of a kind under a cell. */
|
|
254
|
-
hit(kind, x, y) {
|
|
255
|
-
let best;
|
|
256
|
-
for (const t of this.targets) {
|
|
257
|
-
if (t.kind !== kind || !t.active()) continue;
|
|
258
|
-
const el = t.el();
|
|
259
|
-
if (!el) continue;
|
|
260
|
-
const r = boxRect(el);
|
|
261
|
-
if (r.w <= 0 || r.h <= 0) continue;
|
|
262
|
-
if (x < r.x || x >= r.x + r.w || y < r.y || y >= r.y + r.h) continue;
|
|
263
|
-
const depth = depthOf(el);
|
|
264
|
-
if (!best || depth >= best.depth) best = {
|
|
265
|
-
t,
|
|
266
|
-
rx: x - r.x,
|
|
267
|
-
ry: y - r.y,
|
|
268
|
-
depth
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
return best;
|
|
272
|
-
}
|
|
273
|
-
/** Handle one mouse event from the terminal. */
|
|
274
|
-
dispatch(e) {
|
|
275
|
-
if (!this.on) return;
|
|
276
|
-
if (e.kind === "wheel") {
|
|
277
|
-
this.hit("wheel", e.x, e.y)?.t.wheel?.(e.delta);
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
if (e.kind !== "press") return;
|
|
281
|
-
let double = false;
|
|
282
|
-
if (e.button === "left") {
|
|
283
|
-
const t = this.now();
|
|
284
|
-
double = this.last !== void 0 && this.last.x === e.x && this.last.y === e.y && t - this.last.t <= 400;
|
|
285
|
-
this.last = double ? void 0 : {
|
|
286
|
-
x: e.x,
|
|
287
|
-
y: e.y,
|
|
288
|
-
t
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
const h = this.hit("click", e.x, e.y);
|
|
292
|
-
if (h) {
|
|
293
|
-
h.t.click?.({
|
|
294
|
-
x: h.rx,
|
|
295
|
-
y: h.ry,
|
|
296
|
-
button: e.button,
|
|
297
|
-
double,
|
|
298
|
-
shift: e.shift
|
|
299
|
-
});
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
for (const f of this.fallbacks) f(e);
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
const HOLD_MS = 15;
|
|
306
|
-
/** The stream Ink reads. Looks like the terminal's stdin, without the mouse reports. */
|
|
307
|
-
var FilteredStdin = class extends Readable {
|
|
308
|
-
real;
|
|
309
|
-
out;
|
|
310
|
-
hub;
|
|
311
|
-
isTTY = true;
|
|
312
|
-
isRaw = false;
|
|
313
|
-
parser = new MouseParser();
|
|
314
|
-
timer;
|
|
315
|
-
reporting = false;
|
|
316
|
-
raw = false;
|
|
317
|
-
shut = false;
|
|
318
|
-
onData = (chunk) => {
|
|
319
|
-
const { text, events } = this.parser.push(typeof chunk === "string" ? chunk : chunk.toString("utf8"));
|
|
320
|
-
for (const e of events) this.hub.dispatch(e);
|
|
321
|
-
if (text) this.push(text);
|
|
322
|
-
if (this.timer) clearTimeout(this.timer);
|
|
323
|
-
this.timer = void 0;
|
|
324
|
-
if (this.parser.pending) this.timer = setTimeout(() => {
|
|
325
|
-
this.timer = void 0;
|
|
326
|
-
const rest = this.parser.flush();
|
|
327
|
-
if (rest) this.push(rest);
|
|
328
|
-
}, HOLD_MS);
|
|
329
|
-
};
|
|
330
|
-
constructor(real, out, hub) {
|
|
331
|
-
super();
|
|
332
|
-
this.real = real;
|
|
333
|
-
this.out = out;
|
|
334
|
-
this.hub = hub;
|
|
335
|
-
real.setEncoding("utf8");
|
|
336
|
-
real.on("data", this.onData);
|
|
337
|
-
hub.attachReporter((on) => this.report(on));
|
|
338
|
-
}
|
|
339
|
-
_read() {}
|
|
340
|
-
setRawMode(on) {
|
|
341
|
-
this.real.setRawMode?.(on);
|
|
342
|
-
this.raw = on;
|
|
343
|
-
this.isRaw = on;
|
|
344
|
-
this.report(on && this.hub.enabled);
|
|
345
|
-
return this;
|
|
346
|
-
}
|
|
347
|
-
ref() {
|
|
348
|
-
this.real.ref?.();
|
|
349
|
-
return this;
|
|
350
|
-
}
|
|
351
|
-
unref() {
|
|
352
|
-
this.real.unref?.();
|
|
353
|
-
return this;
|
|
354
|
-
}
|
|
355
|
-
/** Put keys in front of Ink as if typed. */
|
|
356
|
-
inject(keys) {
|
|
357
|
-
this.push(keys);
|
|
358
|
-
}
|
|
359
|
-
report(on) {
|
|
360
|
-
const want = on && this.raw && !this.shut;
|
|
361
|
-
if (want === this.reporting) return;
|
|
362
|
-
this.reporting = want;
|
|
363
|
-
try {
|
|
364
|
-
this.out.write(want ? ENABLE_SEQ : DISABLE_SEQ);
|
|
365
|
-
} catch {}
|
|
366
|
-
}
|
|
367
|
-
/** Stop reading and make sure the terminal is out of mouse mode. */
|
|
368
|
-
close() {
|
|
369
|
-
if (this.shut) return;
|
|
370
|
-
this.shut = true;
|
|
371
|
-
if (this.timer) clearTimeout(this.timer);
|
|
372
|
-
this.real.removeListener("data", this.onData);
|
|
373
|
-
this.hub.attachReporter(void 0);
|
|
374
|
-
try {
|
|
375
|
-
this.real.pause();
|
|
376
|
-
} catch {}
|
|
377
|
-
this.out.write(DISABLE_SEQ);
|
|
378
|
-
this.reporting = false;
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
/**
|
|
382
|
-
* Put the mouse filter between the real stdin and Ink. Reporting is switched on when Ink turns raw
|
|
383
|
-
* mode on and off again on every way out: dispose, process exit (which also covers an uncaught
|
|
384
|
-
* error), SIGTERM and SIGHUP.
|
|
385
|
-
*/
|
|
386
|
-
function createMouseInput(ctx, real = process.stdin, out = process.stdout) {
|
|
387
|
-
const usable = real.isTTY === true && out.isTTY === true && typeof real.setRawMode === "function";
|
|
388
|
-
const forcedOff = mouseForcedOff(ctx);
|
|
389
|
-
const hint = usable && getMouseSetting(ctx) && !hintWasShown(ctx);
|
|
390
|
-
let stream;
|
|
391
|
-
const hub = new MouseHub({
|
|
392
|
-
available: usable,
|
|
393
|
-
forcedOff,
|
|
394
|
-
enabled: getMouseSetting(ctx),
|
|
395
|
-
showHint: hint,
|
|
396
|
-
inject: (k) => stream?.inject(k),
|
|
397
|
-
persist: (on) => saveSetting(ctx, { appMouse: on }),
|
|
398
|
-
markHintShown: () => saveSetting(ctx, { appMouseHintShown: true })
|
|
399
|
-
});
|
|
400
|
-
if (!usable) return {
|
|
401
|
-
stdin: real,
|
|
402
|
-
hub,
|
|
403
|
-
dispose: () => void 0
|
|
404
|
-
};
|
|
405
|
-
stream = new FilteredStdin(real, out, hub);
|
|
406
|
-
const restore = () => {
|
|
407
|
-
try {
|
|
408
|
-
out.write(DISABLE_SEQ);
|
|
409
|
-
} catch {}
|
|
410
|
-
};
|
|
411
|
-
const onTerm = (sig) => {
|
|
412
|
-
restore();
|
|
413
|
-
process.removeListener("SIGTERM", onTerm);
|
|
414
|
-
process.removeListener("SIGHUP", onTerm);
|
|
415
|
-
process.kill(process.pid, sig);
|
|
416
|
-
};
|
|
417
|
-
process.on("exit", restore);
|
|
418
|
-
process.on("SIGTERM", onTerm);
|
|
419
|
-
process.on("SIGHUP", onTerm);
|
|
420
|
-
let done = false;
|
|
421
|
-
return {
|
|
422
|
-
stdin: stream,
|
|
423
|
-
hub,
|
|
424
|
-
dispose() {
|
|
425
|
-
if (done) return;
|
|
426
|
-
done = true;
|
|
427
|
-
stream?.close();
|
|
428
|
-
process.removeListener("exit", restore);
|
|
429
|
-
process.removeListener("SIGTERM", onTerm);
|
|
430
|
-
process.removeListener("SIGHUP", onTerm);
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
function settingsFile(ctx) {
|
|
435
|
-
return dataPaths(ctx.platform, ctx.dataDir).settings;
|
|
436
|
-
}
|
|
437
|
-
function readRaw(ctx) {
|
|
438
|
-
try {
|
|
439
|
-
const v = JSON.parse(readFileSync(settingsFile(ctx), "utf8"));
|
|
440
|
-
return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
|
|
441
|
-
} catch {
|
|
442
|
-
return {};
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
function saveSetting(ctx, patch) {
|
|
446
|
-
try {
|
|
447
|
-
writeSettings(settingsFile(ctx), patch);
|
|
448
|
-
} catch {}
|
|
449
|
-
}
|
|
450
|
-
function hintWasShown(ctx) {
|
|
451
|
-
return readRaw(ctx).appMouseHintShown === true;
|
|
452
|
-
}
|
|
453
|
-
/** `CONVENO_MOUSE=0` (or `off`, `false`) switches the mouse off whatever was saved. */
|
|
454
|
-
function mouseForcedOff(ctx) {
|
|
455
|
-
const v = ctx.env.CONVENO_MOUSE?.trim().toLowerCase();
|
|
456
|
-
return v === "0" || v === "off" || v === "false" || v === "no";
|
|
457
|
-
}
|
|
458
|
-
/** Whether the mouse should be on: on unless forced off or saved as off (`appMouse: false`). */
|
|
459
|
-
function getMouseSetting(ctx) {
|
|
460
|
-
if (mouseForcedOff(ctx)) return false;
|
|
461
|
-
return readRaw(ctx).appMouse !== false;
|
|
462
|
-
}
|
|
463
|
-
// src/tui/ui.tsx
|
|
464
|
-
/**
|
|
465
|
-
* Small building blocks every screen shares. Colours come from the brand tokens; with NO_COLOR or
|
|
466
|
-
* a terminal without colour every colour is undefined and state is carried by words.
|
|
467
|
-
*/
|
|
468
|
-
/** The selected-row highlight from the approved mockup. */
|
|
469
|
-
const SELECT_BG = "#1B2A40";
|
|
470
|
-
const NAMES = [
|
|
471
|
-
"ground",
|
|
472
|
-
"surface",
|
|
473
|
-
"sunken",
|
|
474
|
-
"ink",
|
|
475
|
-
"quiet",
|
|
476
|
-
"rule",
|
|
477
|
-
"entry",
|
|
478
|
-
"stamp",
|
|
479
|
-
"ok",
|
|
480
|
-
"warn",
|
|
481
|
-
"error",
|
|
482
|
-
"info"
|
|
483
|
-
];
|
|
484
|
-
/** Build the UI theme from the environment. Tests pass their own. */
|
|
485
|
-
function makeUiTheme(env = process.env, opts = {}) {
|
|
486
|
-
const ctx = {
|
|
487
|
-
env,
|
|
488
|
-
isTTY: Boolean(process.stdout.isTTY),
|
|
489
|
-
platform: process.platform
|
|
490
|
-
};
|
|
491
|
-
const level = opts.colourLevel ?? detectColorLevel(ctx);
|
|
492
|
-
const unicode = opts.unicode ?? detectUnicode(ctx);
|
|
493
|
-
const c = {};
|
|
494
|
-
if (level > 0) {
|
|
495
|
-
for (const n of NAMES) c[n] = tokens.color.dark[n];
|
|
496
|
-
c.select = SELECT_BG;
|
|
497
|
-
}
|
|
498
|
-
return {
|
|
499
|
-
c,
|
|
500
|
-
ascii: !unicode,
|
|
501
|
-
colour: level > 0
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
/** Same as `makeUiTheme` but from a CLI `Theme`, so the app follows the command line's choices. */
|
|
505
|
-
function uiThemeFrom(theme) {
|
|
506
|
-
return makeUiTheme(process.env, {
|
|
507
|
-
colourLevel: theme.colorLevel,
|
|
508
|
-
unicode: theme.unicode
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
const ThemeContext = createContext(void 0);
|
|
512
|
-
function ThemeProvider({ theme, children }) {
|
|
513
|
-
const value = useMemo(() => theme ?? makeUiTheme(), [theme]);
|
|
514
|
-
return /* @__PURE__ */ jsx(ThemeContext.Provider, {
|
|
515
|
-
value,
|
|
516
|
-
children
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
function useTheme() {
|
|
520
|
-
return useContext(ThemeContext) ?? FALLBACK;
|
|
521
|
-
}
|
|
522
|
-
const FALLBACK = {
|
|
523
|
-
c: {},
|
|
524
|
-
ascii: true,
|
|
525
|
-
colour: false
|
|
526
|
-
};
|
|
527
|
-
const MouseContext = createContext(void 0);
|
|
528
|
-
/** The shell provides the hub that turns terminal mouse reports into clicks and wheel turns. */
|
|
529
|
-
const MouseProvider = MouseContext.Provider;
|
|
530
|
-
const ScopeContext = createContext(true);
|
|
531
|
-
/** Everything below gets no mouse events while `active` is false (a screen under an overlay). */
|
|
532
|
-
function MouseScope({ active, children }) {
|
|
533
|
-
const outer = useContext(ScopeContext);
|
|
534
|
-
return /* @__PURE__ */ jsx(ScopeContext.Provider, {
|
|
535
|
-
value: outer && active,
|
|
536
|
-
children
|
|
537
|
-
});
|
|
538
|
-
}
|
|
539
|
-
function useTarget(kind, ref, fn, isActive) {
|
|
540
|
-
const hub = useContext(MouseContext);
|
|
541
|
-
const scope = useContext(ScopeContext);
|
|
542
|
-
const fnRef = useRef(fn);
|
|
543
|
-
fnRef.current = fn;
|
|
544
|
-
const activeRef = useRef(true);
|
|
545
|
-
activeRef.current = (isActive ?? true) && scope;
|
|
546
|
-
useEffect(() => {
|
|
547
|
-
if (!hub) return;
|
|
548
|
-
const call = (a) => fnRef.current(a);
|
|
549
|
-
return hub.register({
|
|
550
|
-
kind,
|
|
551
|
-
el: () => ref.current,
|
|
552
|
-
active: () => activeRef.current,
|
|
553
|
-
...kind === "click" ? { click: call } : { wheel: call }
|
|
554
|
-
});
|
|
555
|
-
}, [
|
|
556
|
-
hub,
|
|
557
|
-
kind,
|
|
558
|
-
ref
|
|
559
|
-
]);
|
|
560
|
-
}
|
|
561
|
-
/** Make a Box react to clicks. The handler gets the position inside the box. */
|
|
562
|
-
function useClick(ref, onClick, opts) {
|
|
563
|
-
useTarget("click", ref, onClick, opts?.isActive);
|
|
564
|
-
}
|
|
565
|
-
/** Make a Box a wheel target. `delta` is -1 (up) or +1 (down) per notch. */
|
|
566
|
-
function useWheel(ref, onWheel, opts) {
|
|
567
|
-
useTarget("wheel", ref, onWheel, opts?.isActive);
|
|
568
|
-
}
|
|
569
|
-
const NO_SUBSCRIBE = () => () => void 0;
|
|
570
|
-
/** Whether the mouse is on, to show hints like "click to open". */
|
|
571
|
-
function useMouseEnabled() {
|
|
572
|
-
const hub = useContext(MouseContext);
|
|
573
|
-
return useSyncExternalStore(hub?.subscribe ?? NO_SUBSCRIBE, hub?.getEnabled ?? (() => false));
|
|
574
|
-
}
|
|
575
|
-
/** For the Setup switch: the state, whether it can be on at all, and a setter that is kept. */
|
|
576
|
-
function useMouseControl() {
|
|
577
|
-
const hub = useContext(MouseContext);
|
|
578
|
-
return {
|
|
579
|
-
enabled: useMouseEnabled(),
|
|
580
|
-
available: hub?.available ?? false,
|
|
581
|
-
forcedOff: hub?.forcedOff ?? false,
|
|
582
|
-
set: (on) => hub?.setEnabled(on, true)
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
/** A ready-made clickable piece of text. */
|
|
586
|
-
function Clickable({ onClick, children, isActive }) {
|
|
587
|
-
const ref = useRef(null);
|
|
588
|
-
useClick(ref, onClick, isActive === void 0 ? void 0 : { isActive });
|
|
589
|
-
return /* @__PURE__ */ jsx(Box, {
|
|
590
|
-
ref,
|
|
591
|
-
children
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
/** Cut a string to `width` columns, with an ellipsis. */
|
|
595
|
-
function cut(text, width, ascii = false) {
|
|
596
|
-
const dots = ascii ? "..." : "…";
|
|
597
|
-
const chars = [...text];
|
|
598
|
-
if (width <= 0) return "";
|
|
599
|
-
if (chars.length <= width) return text;
|
|
600
|
-
if (width <= dots.length) return dots.slice(0, width);
|
|
601
|
-
return chars.slice(0, width - dots.length).join("") + dots;
|
|
602
|
-
}
|
|
603
|
-
/** Swap the few Unicode glyphs the app uses for plain ones, when the terminal needs that. */
|
|
604
|
-
function plain(text, ascii) {
|
|
605
|
-
if (!ascii) return text;
|
|
606
|
-
return text.replace(/·/g, "-").replace(/⏎/g, "Enter").replace(/↑↓/g, "Up/Down").replace(/›/g, ">").replace(/…/g, "...");
|
|
607
|
-
}
|
|
608
|
-
/** One line of text, cut with `…`. Never wraps. */
|
|
609
|
-
function Ell({ width, color, bold, dim, children }) {
|
|
610
|
-
const { ascii } = useTheme();
|
|
611
|
-
const one = children.replace(/\s*\n\s*/g, " ");
|
|
612
|
-
return /* @__PURE__ */ jsx(Text, {
|
|
613
|
-
wrap: "truncate",
|
|
614
|
-
...color ? { color } : {},
|
|
615
|
-
...bold ? { bold } : {},
|
|
616
|
-
...dim ? { dimColor: dim } : {},
|
|
617
|
-
children: cut(one, width, ascii)
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
const CHIPS = {
|
|
621
|
-
claude: "cl",
|
|
622
|
-
codex: "cx",
|
|
623
|
-
opencode: "oc",
|
|
624
|
-
antigravity: "ag",
|
|
625
|
-
grok: "gr",
|
|
626
|
-
cursor: "cu",
|
|
627
|
-
copilot: "cp"
|
|
628
|
-
};
|
|
629
|
-
/** Two-letter monogram of a CLI. */
|
|
630
|
-
function chipText(cli) {
|
|
631
|
-
return CHIPS[cli] ?? cli.slice(0, 2).toLowerCase();
|
|
632
|
-
}
|
|
633
|
-
function Chip({ cli, dim }) {
|
|
634
|
-
const { c } = useTheme();
|
|
635
|
-
const text = chipText(cli).padEnd(2).slice(0, 2);
|
|
636
|
-
if (!c.surface) return /* @__PURE__ */ jsx(Text, {
|
|
637
|
-
...dim ? { dimColor: true } : {},
|
|
638
|
-
children: `[${text}]`
|
|
639
|
-
});
|
|
640
|
-
return /* @__PURE__ */ jsx(Text, {
|
|
641
|
-
bold: true,
|
|
642
|
-
backgroundColor: c.surface,
|
|
643
|
-
...c.entry ? { color: c.entry } : {},
|
|
644
|
-
...dim ? { dimColor: true } : {},
|
|
645
|
-
children: ` ${text} `
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
/** A small, dim, uppercase section label. */
|
|
649
|
-
function Label({ children }) {
|
|
650
|
-
const { c, ascii } = useTheme();
|
|
651
|
-
return /* @__PURE__ */ jsx(Text, {
|
|
652
|
-
...c.quiet ? { color: c.quiet } : { dimColor: true },
|
|
653
|
-
children: plain(children.toUpperCase(), ascii)
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
/** A bordered box. */
|
|
657
|
-
function Card({ accent, width, fill, children }) {
|
|
658
|
-
const { c, ascii } = useTheme();
|
|
659
|
-
const color = accent ?? c.rule;
|
|
660
|
-
return /* @__PURE__ */ jsx(Box, {
|
|
661
|
-
flexDirection: "column",
|
|
662
|
-
borderStyle: ascii ? "classic" : "round",
|
|
663
|
-
...color ? { borderColor: color } : {},
|
|
664
|
-
paddingX: 1,
|
|
665
|
-
...fill && c.surface ? { backgroundColor: c.surface } : {},
|
|
666
|
-
...width !== void 0 ? { width } : {},
|
|
667
|
-
children
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
/** "now", "3m", "2h", "2 days ago". */
|
|
671
|
-
function relTime(iso, now = Date.now()) {
|
|
672
|
-
const t = Date.parse(iso);
|
|
673
|
-
if (Number.isNaN(t)) return "";
|
|
674
|
-
const s = Math.max(0, Math.floor((now - t) / 1e3));
|
|
675
|
-
if (s < 60) return "now";
|
|
676
|
-
const m = Math.floor(s / 60);
|
|
677
|
-
if (m < 60) return `${m}m`;
|
|
678
|
-
const h = Math.floor(m / 60);
|
|
679
|
-
if (h < 24) return `${h}h`;
|
|
680
|
-
const d = Math.floor(h / 24);
|
|
681
|
-
return d === 1 ? "1 day ago" : `${d} days ago`;
|
|
682
|
-
}
|
|
683
|
-
/**
|
|
684
|
-
* The home folder as `~`. Knows this machine's home and the usual homes of other machines:
|
|
685
|
-
* `/home/x`, `/Users/x`, and `C:\Users\x` or `C:/Users/x` in any case. Separators stay as given.
|
|
686
|
-
*/
|
|
687
|
-
function homePath(path, home = homedir()) {
|
|
688
|
-
const h = home.replace(/[\\/]+$/, "");
|
|
689
|
-
if (h !== "" && path.length >= h.length) {
|
|
690
|
-
const head = path.slice(0, h.length);
|
|
691
|
-
const next = path[h.length];
|
|
692
|
-
if ((/^[A-Za-z]:/.test(h) ? head.toLowerCase() === h.toLowerCase() : head === h) && (next === void 0 || next === "/" || next === "\\")) return `~${path.slice(h.length)}`;
|
|
693
|
-
}
|
|
694
|
-
return path.replace(/^(?:\/home\/[^/]+|\/Users\/[^/]+|[A-Za-z]:[\\/]Users[\\/][^\\/]+)(?=[\\/]|$)/i, "~");
|
|
695
|
-
}
|
|
696
|
-
/**
|
|
697
|
-
* A folder for a column `width` wide: home as `~`, and when it is too long, cut from the left so
|
|
698
|
-
* the end stays: `…/NOV-2026/win-trouble`. Separators are kept as the path has them.
|
|
699
|
-
*/
|
|
700
|
-
function shortPath$1(path, width, ascii = false, home) {
|
|
701
|
-
const dots = ascii ? "..." : "…";
|
|
702
|
-
const p = homePath(path, home);
|
|
703
|
-
if (width <= 0) return "";
|
|
704
|
-
if ([...p].length <= width) return p;
|
|
705
|
-
const sep = p.lastIndexOf("\\") > p.lastIndexOf("/") ? "\\" : "/";
|
|
706
|
-
const parts = p.split(/[\\/]+/).filter((x) => x !== "");
|
|
707
|
-
const kept = [];
|
|
708
|
-
let used = dots.length + 1;
|
|
709
|
-
for (let i = parts.length - 1; i >= 0; i--) {
|
|
710
|
-
const part = parts[i] ?? "";
|
|
711
|
-
const add = [...part].length + (kept.length > 0 ? 1 : 0);
|
|
712
|
-
if (used + add > width) break;
|
|
713
|
-
used += add;
|
|
714
|
-
kept.unshift(part);
|
|
715
|
-
}
|
|
716
|
-
if (kept.length > 0) return `${dots}${sep}${kept.join(sep)}`;
|
|
717
|
-
const last = [...parts[parts.length - 1] ?? p];
|
|
718
|
-
return dots + last.slice(Math.max(0, last.length - (width - dots.length))).join("");
|
|
719
|
-
}
|
|
720
|
-
/** A full-width bar on the surface colour. */
|
|
721
|
-
function Band({ width, children }) {
|
|
722
|
-
const { c } = useTheme();
|
|
723
|
-
return /* @__PURE__ */ jsx(Box, {
|
|
724
|
-
width,
|
|
725
|
-
height: 1,
|
|
726
|
-
flexShrink: 0,
|
|
727
|
-
paddingX: 1,
|
|
728
|
-
...c.surface ? { backgroundColor: c.surface } : {},
|
|
729
|
-
children
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
/** A horizontal rule. */
|
|
733
|
-
function Rule({ width }) {
|
|
734
|
-
const { c, ascii } = useTheme();
|
|
735
|
-
return /* @__PURE__ */ jsx(Text, {
|
|
736
|
-
...c.rule ? { color: c.rule } : { dimColor: true },
|
|
737
|
-
children: (ascii ? "-" : "─").repeat(Math.max(0, width))
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
/**
|
|
741
|
-
* The side panel: sunken colour, a vertical rule on its left. `width` includes the rule and one
|
|
742
|
-
* column of padding each side, so the text inside gets `width - 3`.
|
|
743
|
-
*/
|
|
744
|
-
const paneInner = (width) => Math.max(4, width - 3);
|
|
745
|
-
function Pane({ width, height, children }) {
|
|
746
|
-
const { c, ascii } = useTheme();
|
|
747
|
-
return /* @__PURE__ */ jsx(Box, {
|
|
748
|
-
width,
|
|
749
|
-
flexShrink: 0,
|
|
750
|
-
flexDirection: "column",
|
|
751
|
-
overflow: "hidden",
|
|
752
|
-
borderStyle: ascii ? "classic" : "single",
|
|
753
|
-
borderTop: false,
|
|
754
|
-
borderRight: false,
|
|
755
|
-
borderBottom: false,
|
|
756
|
-
...c.rule ? { borderColor: c.rule } : { borderDimColor: true },
|
|
757
|
-
...c.sunken ? {
|
|
758
|
-
backgroundColor: c.sunken,
|
|
759
|
-
borderLeftBackgroundColor: c.sunken
|
|
760
|
-
} : {},
|
|
761
|
-
paddingX: 1,
|
|
762
|
-
...height !== void 0 ? { height } : {},
|
|
763
|
-
children
|
|
764
|
-
});
|
|
765
|
-
}
|
|
766
|
-
/**
|
|
767
|
-
* Split a screen into main part and side panel. On very wide terminals the main part stops at
|
|
768
|
-
* `maxMain` and the panel sits right after it. Without a panel, main is capped alone.
|
|
769
|
-
*/
|
|
770
|
-
function splitWidths(columns, panel, opts = {}) {
|
|
771
|
-
const maxMain = opts.maxMain ?? 130;
|
|
772
|
-
if (!panel) return {
|
|
773
|
-
mainW: Math.min(columns, maxMain),
|
|
774
|
-
panelW: 0
|
|
775
|
-
};
|
|
776
|
-
const panelW = opts.panelW ?? (columns >= 160 ? 40 : 36);
|
|
777
|
-
return {
|
|
778
|
-
mainW: Math.min(maxMain, Math.max(30, columns - panelW)),
|
|
779
|
-
panelW
|
|
780
|
-
};
|
|
781
|
-
}
|
|
782
|
-
/** One cell of a table row: `w` columns wide, the last `gap` of them empty. Never overflows. */
|
|
783
|
-
function Cell({ w, gap = 2, color, bold, dim, children }) {
|
|
784
|
-
return /* @__PURE__ */ jsx(Box, {
|
|
785
|
-
width: w,
|
|
786
|
-
flexShrink: 0,
|
|
787
|
-
children: /* @__PURE__ */ jsx(Ell, {
|
|
788
|
-
width: Math.max(0, w - gap),
|
|
789
|
-
color,
|
|
790
|
-
...bold ? { bold } : {},
|
|
791
|
-
...dim ? { dim } : {},
|
|
792
|
-
children
|
|
793
|
-
})
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
/** A table row. The selected one gets the highlight across the whole width. */
|
|
797
|
-
function Row({ width, selected, children }) {
|
|
798
|
-
const { c } = useTheme();
|
|
799
|
-
return /* @__PURE__ */ jsx(Box, {
|
|
800
|
-
width,
|
|
801
|
-
flexShrink: 0,
|
|
802
|
-
...selected && c.select ? { backgroundColor: c.select } : {},
|
|
803
|
-
children
|
|
804
|
-
});
|
|
805
|
-
}
|
|
806
|
-
/** The header row of a table: small, dim capitals. */
|
|
807
|
-
function HeaderRow({ width, cols }) {
|
|
808
|
-
const { c } = useTheme();
|
|
809
|
-
return /* @__PURE__ */ jsx(Box, {
|
|
810
|
-
width,
|
|
811
|
-
flexShrink: 0,
|
|
812
|
-
children: cols.map((col) => /* @__PURE__ */ jsx(Cell, {
|
|
813
|
-
w: col.w,
|
|
814
|
-
...col.gap !== void 0 ? { gap: col.gap } : {},
|
|
815
|
-
color: c.quiet,
|
|
816
|
-
dim: !c.quiet,
|
|
817
|
-
children: col.text.toUpperCase()
|
|
818
|
-
}, col.text || col.w))
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
/** A list that keeps the selected row in view and says how many rows are hidden. */
|
|
822
|
-
function ScrollList({ items, selected, height, renderItem, keyOf, onSelect, onActivate, isActive }) {
|
|
823
|
-
const { c, ascii } = useTheme();
|
|
824
|
-
const box = useRef(null);
|
|
825
|
-
const h = Math.max(1, height);
|
|
826
|
-
const total = items.length;
|
|
827
|
-
let slots = h;
|
|
828
|
-
let start = 0;
|
|
829
|
-
if (total > h) for (let pass = 0; pass < 3; pass++) {
|
|
830
|
-
slots = Math.max(1, h - (start > 0 ? 1 : 0) - (start + slots < total ? 1 : 0));
|
|
831
|
-
if (selected < start) start = selected;
|
|
832
|
-
if (selected >= start + slots) start = selected - slots + 1;
|
|
833
|
-
start = Math.max(0, Math.min(start, total - slots));
|
|
834
|
-
}
|
|
835
|
-
const end = Math.min(total, start + slots);
|
|
836
|
-
const view = useRef({
|
|
837
|
-
start,
|
|
838
|
-
end,
|
|
839
|
-
selected,
|
|
840
|
-
total
|
|
841
|
-
});
|
|
842
|
-
view.current = {
|
|
843
|
-
start,
|
|
844
|
-
end,
|
|
845
|
-
selected,
|
|
846
|
-
total
|
|
847
|
-
};
|
|
848
|
-
useClick(box, (e) => {
|
|
849
|
-
if (e.button !== "left") return;
|
|
850
|
-
const v = view.current;
|
|
851
|
-
const kids = box.current?.childNodes ?? [];
|
|
852
|
-
const first = v.start > 0 ? 1 : 0;
|
|
853
|
-
for (let i = v.start; i < v.end; i++) {
|
|
854
|
-
const kid = kids[first + i - v.start];
|
|
855
|
-
const y = kid && "yogaNode" in kid ? kid.yogaNode : void 0;
|
|
856
|
-
if (!y) continue;
|
|
857
|
-
const top = y.getComputedTop();
|
|
858
|
-
if (e.y < top || e.y >= top + y.getComputedHeight()) continue;
|
|
859
|
-
if (i !== v.selected) onSelect?.(i);
|
|
860
|
-
if (i === v.selected || e.double) onActivate?.(i);
|
|
861
|
-
return;
|
|
862
|
-
}
|
|
863
|
-
}, { isActive: (isActive ?? true) && (onSelect !== void 0 || onActivate !== void 0) });
|
|
864
|
-
useWheel(box, (d) => {
|
|
865
|
-
const v = view.current;
|
|
866
|
-
onSelect?.(Math.max(0, Math.min(v.total - 1, v.selected + d)));
|
|
867
|
-
}, { isActive: (isActive ?? true) && onSelect !== void 0 });
|
|
868
|
-
if (total === 0) return null;
|
|
869
|
-
const above = start;
|
|
870
|
-
const below = total - end;
|
|
871
|
-
const dots = ascii ? "..." : "…";
|
|
872
|
-
const quiet = c.quiet ? { color: c.quiet } : { dimColor: true };
|
|
873
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
874
|
-
ref: box,
|
|
875
|
-
flexDirection: "column",
|
|
876
|
-
children: [
|
|
877
|
-
above > 0 ? /* @__PURE__ */ jsx(Text, {
|
|
878
|
-
...quiet,
|
|
879
|
-
children: `${dots} ${above} more`
|
|
880
|
-
}) : null,
|
|
881
|
-
items.slice(start, end).map((item, i) => /* @__PURE__ */ jsx(Box, { children: renderItem(item, start + i === selected, start + i) }, keyOf(item, start + i))),
|
|
882
|
-
below > 0 ? /* @__PURE__ */ jsx(Text, {
|
|
883
|
-
...quiet,
|
|
884
|
-
children: `${dots} ${below} more`
|
|
885
|
-
}) : null
|
|
886
|
-
]
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* The shell provides this. A text box with unsent text tells it when Ctrl+C cleared that text,
|
|
891
|
-
* so the shell shows a hint instead of quitting.
|
|
892
|
-
*/
|
|
893
|
-
const DraftContext = createContext({ cleared: () => void 0 });
|
|
894
|
-
const DraftProvider = DraftContext.Provider;
|
|
895
|
-
/** A small input. Enter sends; Shift+Enter (or Ctrl+J) adds a line when `multiline`. */
|
|
896
|
-
function TextBox({ value, onChange, onSubmit, placeholder, focus, multiline, onCancel, onFocusRequest }) {
|
|
897
|
-
const { c, ascii } = useTheme();
|
|
898
|
-
const area = useRef(null);
|
|
899
|
-
useClick(area, () => onFocusRequest?.(), { isActive: onFocusRequest !== void 0 });
|
|
900
|
-
const [cursor, setCursor] = useState(value.length);
|
|
901
|
-
const pos = Math.min(cursor, value.length);
|
|
902
|
-
const draft = useContext(DraftContext);
|
|
903
|
-
useInput((input, key) => {
|
|
904
|
-
if (key.ctrl && input === "c") {
|
|
905
|
-
if (value !== "") {
|
|
906
|
-
onChange("");
|
|
907
|
-
setCursor(0);
|
|
908
|
-
draft.cleared();
|
|
909
|
-
}
|
|
910
|
-
return;
|
|
911
|
-
}
|
|
912
|
-
if (key.escape) {
|
|
913
|
-
onCancel?.();
|
|
914
|
-
return;
|
|
915
|
-
}
|
|
916
|
-
if (key.return) {
|
|
917
|
-
if (multiline && key.shift) {
|
|
918
|
-
onChange(`${value.slice(0, pos)}\n${value.slice(pos)}`);
|
|
919
|
-
setCursor(pos + 1);
|
|
920
|
-
} else onSubmit(value);
|
|
921
|
-
return;
|
|
922
|
-
}
|
|
923
|
-
if (key.leftArrow) return setCursor(Math.max(0, pos - 1));
|
|
924
|
-
if (key.rightArrow) return setCursor(Math.min(value.length, pos + 1));
|
|
925
|
-
if (key.ctrl && input === "a") return setCursor(0);
|
|
926
|
-
if (key.ctrl && input === "e") return setCursor(value.length);
|
|
927
|
-
if (key.ctrl && input === "u") {
|
|
928
|
-
onChange(value.slice(pos));
|
|
929
|
-
return setCursor(0);
|
|
930
|
-
}
|
|
931
|
-
if (key.backspace || key.delete) {
|
|
932
|
-
if (pos === 0) return;
|
|
933
|
-
onChange(value.slice(0, pos - 1) + value.slice(pos));
|
|
934
|
-
return setCursor(pos - 1);
|
|
935
|
-
}
|
|
936
|
-
if (key.ctrl && input === "j" && multiline) {
|
|
937
|
-
onChange(`${value.slice(0, pos)}\n${value.slice(pos)}`);
|
|
938
|
-
return setCursor(pos + 1);
|
|
939
|
-
}
|
|
940
|
-
if (key.ctrl || key.meta || key.upArrow || key.downArrow || key.tab) return;
|
|
941
|
-
if (input) {
|
|
942
|
-
const clean = multiline ? input.replace(/\r\n?/g, "\n") : input.replace(/[\r\n]+/g, " ");
|
|
943
|
-
onChange(value.slice(0, pos) + clean + value.slice(pos));
|
|
944
|
-
setCursor(pos + clean.length);
|
|
945
|
-
}
|
|
946
|
-
}, { isActive: focus });
|
|
947
|
-
const quiet = c.quiet ? { color: c.quiet } : { dimColor: true };
|
|
948
|
-
const wrap = (node) => onFocusRequest ? /* @__PURE__ */ jsx(Box, {
|
|
949
|
-
ref: area,
|
|
950
|
-
children: node
|
|
951
|
-
}) : node;
|
|
952
|
-
if (value.length === 0) return wrap(/* @__PURE__ */ jsxs(Text, { children: [focus ? /* @__PURE__ */ jsx(Text, {
|
|
953
|
-
inverse: true,
|
|
954
|
-
children: " "
|
|
955
|
-
}) : null, /* @__PURE__ */ jsx(Text, {
|
|
956
|
-
...quiet,
|
|
957
|
-
children: placeholder ?? ""
|
|
958
|
-
})] }));
|
|
959
|
-
const before = value.slice(0, pos);
|
|
960
|
-
const at = value[pos] ?? " ";
|
|
961
|
-
const after = value.slice(pos + 1);
|
|
962
|
-
return wrap(/* @__PURE__ */ jsxs(Text, { children: [
|
|
963
|
-
before,
|
|
964
|
-
focus ? /* @__PURE__ */ jsx(Text, {
|
|
965
|
-
inverse: true,
|
|
966
|
-
children: at === "\n" ? " \n" : at
|
|
967
|
-
}) : at,
|
|
968
|
-
after
|
|
969
|
-
] }));
|
|
970
|
-
}
|
|
971
|
-
// src/tui/palette.tsx
|
|
972
|
-
/** The command palette and the all-keys help, drawn over the screen body. */
|
|
973
|
-
/**
|
|
974
|
-
* Subsequence match. Higher is better; undefined means no match. Starts of words and runs of
|
|
975
|
-
* letters score more, so "ses" finds "Go to Sessions" before "Pause everything".
|
|
976
|
-
*/
|
|
977
|
-
function fuzzy(query, text) {
|
|
978
|
-
const q = query.toLowerCase().replace(/\s+/g, "");
|
|
979
|
-
if (q === "") return 0;
|
|
980
|
-
const t = text.toLowerCase();
|
|
981
|
-
let score = 0;
|
|
982
|
-
let from = 0;
|
|
983
|
-
let run = 0;
|
|
984
|
-
for (const ch of q) {
|
|
985
|
-
const i = t.indexOf(ch, from);
|
|
986
|
-
if (i < 0) return void 0;
|
|
987
|
-
const startOfWord = i === 0 || t[i - 1] === " ";
|
|
988
|
-
run = i === from ? run + 1 : 0;
|
|
989
|
-
score += 1 + run * 2 + (startOfWord ? 4 : 0) - Math.min(i - from, 5) * .2;
|
|
990
|
-
from = i + 1;
|
|
991
|
-
}
|
|
992
|
-
return score;
|
|
993
|
-
}
|
|
994
|
-
function filterCommands(cmds, query) {
|
|
995
|
-
return cmds.map((c, i) => ({
|
|
996
|
-
c,
|
|
997
|
-
i,
|
|
998
|
-
s: fuzzy(query, c.label)
|
|
999
|
-
})).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);
|
|
1000
|
-
}
|
|
1001
|
-
function Palette({ commands, width, height, onClose }) {
|
|
1002
|
-
const { c, ascii } = useTheme();
|
|
1003
|
-
const [query, setQuery] = useState("");
|
|
1004
|
-
const [sel, setSel] = useState(0);
|
|
1005
|
-
const shown = useMemo(() => filterCommands(commands, query), [commands, query]);
|
|
1006
|
-
const index = Math.min(sel, Math.max(0, shown.length - 1));
|
|
1007
|
-
const rowsMax = Math.max(1, height - 5);
|
|
1008
|
-
useInput((_input, key) => {
|
|
1009
|
-
if (key.upArrow) setSel(Math.max(0, index - 1));
|
|
1010
|
-
else if (key.downArrow) setSel(Math.min(shown.length - 1, index + 1));
|
|
1011
|
-
});
|
|
1012
|
-
const runCmd = (cmd) => {
|
|
1013
|
-
onClose();
|
|
1014
|
-
if (cmd) Promise.resolve(cmd.run()).catch(() => void 0);
|
|
1015
|
-
};
|
|
1016
|
-
const run = () => runCmd(shown[index]);
|
|
1017
|
-
const list = useRef(null);
|
|
1018
|
-
useWheel(list, (d) => setSel(Math.max(0, Math.min(shown.length - 1, index + d))));
|
|
1019
|
-
const inner = Math.max(10, width - 4);
|
|
1020
|
-
const start = Math.max(0, Math.min(index - rowsMax + 1, shown.length - rowsMax));
|
|
1021
|
-
const view = shown.slice(start, start + rowsMax);
|
|
1022
|
-
return /* @__PURE__ */ jsx(Clickable, {
|
|
1023
|
-
onClick: () => void 0,
|
|
1024
|
-
children: /* @__PURE__ */ jsxs(Card, {
|
|
1025
|
-
...c.entry ? { accent: c.entry } : {},
|
|
1026
|
-
fill: true,
|
|
1027
|
-
width,
|
|
1028
|
-
children: [
|
|
1029
|
-
/* @__PURE__ */ jsx(TextBox, {
|
|
1030
|
-
value: query,
|
|
1031
|
-
onChange: (v) => {
|
|
1032
|
-
setQuery(v);
|
|
1033
|
-
setSel(0);
|
|
1034
|
-
},
|
|
1035
|
-
onSubmit: run,
|
|
1036
|
-
onCancel: onClose,
|
|
1037
|
-
placeholder: "Type to find something to do",
|
|
1038
|
-
focus: true
|
|
1039
|
-
}),
|
|
1040
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1041
|
-
ref: list,
|
|
1042
|
-
flexDirection: "column",
|
|
1043
|
-
marginTop: 1,
|
|
1044
|
-
children: view.length === 0 ? /* @__PURE__ */ jsx(Text, {
|
|
1045
|
-
...c.quiet ? { color: c.quiet } : { dimColor: true },
|
|
1046
|
-
children: "Nothing matches that."
|
|
1047
|
-
}) : view.map((cmd) => {
|
|
1048
|
-
const on = cmd === shown[index];
|
|
1049
|
-
return /* @__PURE__ */ jsxs(PaletteRow, {
|
|
1050
|
-
onPick: () => runCmd(cmd),
|
|
1051
|
-
children: [
|
|
1052
|
-
/* @__PURE__ */ jsxs(Text, {
|
|
1053
|
-
...on ? c.select ? {
|
|
1054
|
-
backgroundColor: c.select,
|
|
1055
|
-
bold: true
|
|
1056
|
-
} : { inverse: true } : {},
|
|
1057
|
-
children: [on ? ascii ? "> " : "› " : " ", /* @__PURE__ */ jsx(Ell, {
|
|
1058
|
-
width: Math.max(4, inner - 12),
|
|
1059
|
-
children: cmd.label
|
|
1060
|
-
})]
|
|
1061
|
-
}),
|
|
1062
|
-
/* @__PURE__ */ jsx(Box, { flexGrow: 1 }),
|
|
1063
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1064
|
-
...c.quiet ? { color: c.quiet } : { dimColor: true },
|
|
1065
|
-
children: plain(cmd.key ?? "", ascii)
|
|
1066
|
-
})
|
|
1067
|
-
]
|
|
1068
|
-
}, cmd.id);
|
|
1069
|
-
})
|
|
1070
|
-
}),
|
|
1071
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1072
|
-
marginTop: 1,
|
|
1073
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1074
|
-
...c.quiet ? { color: c.quiet } : { dimColor: true },
|
|
1075
|
-
children: plain("↑↓ move · ⏎ run · Esc close", ascii)
|
|
1076
|
-
})
|
|
1077
|
-
})
|
|
1078
|
-
]
|
|
1079
|
-
})
|
|
1080
|
-
});
|
|
1081
|
-
}
|
|
1082
|
-
/** One palette row: a click selects it and runs it. */
|
|
1083
|
-
function PaletteRow({ onPick, children }) {
|
|
1084
|
-
const ref = useRef(null);
|
|
1085
|
-
useClick(ref, (e) => {
|
|
1086
|
-
if (e.button === "left") onPick();
|
|
1087
|
-
});
|
|
1088
|
-
return /* @__PURE__ */ jsx(Box, {
|
|
1089
|
-
ref,
|
|
1090
|
-
children
|
|
1091
|
-
});
|
|
1092
|
-
}
|
|
1093
|
-
function Help({ screenTitle, screenKeys, width, onClose }) {
|
|
1094
|
-
const { c, ascii } = useTheme();
|
|
1095
|
-
useInput((input, key) => {
|
|
1096
|
-
if (key.escape || input === "?" || input === "q" || key.return) onClose();
|
|
1097
|
-
});
|
|
1098
|
-
const global = [
|
|
1099
|
-
{
|
|
1100
|
-
key: "1-4",
|
|
1101
|
-
label: "go to a screen"
|
|
1102
|
-
},
|
|
1103
|
-
{
|
|
1104
|
-
key: "/ or Ctrl+K",
|
|
1105
|
-
label: "find anything to do"
|
|
1106
|
-
},
|
|
1107
|
-
{
|
|
1108
|
-
key: "?",
|
|
1109
|
-
label: "this list"
|
|
1110
|
-
},
|
|
1111
|
-
{
|
|
1112
|
-
key: "Esc",
|
|
1113
|
-
label: "back"
|
|
1114
|
-
},
|
|
1115
|
-
{
|
|
1116
|
-
key: "q",
|
|
1117
|
-
label: "quit (sessions keep running)"
|
|
1118
|
-
},
|
|
1119
|
-
{
|
|
1120
|
-
key: "Ctrl+C",
|
|
1121
|
-
label: "quit now"
|
|
1122
|
-
}
|
|
1123
|
-
];
|
|
1124
|
-
const row = (k) => /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Box, {
|
|
1125
|
-
width: 14,
|
|
1126
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1127
|
-
bold: true,
|
|
1128
|
-
...c.ink ? { color: c.ink } : {},
|
|
1129
|
-
children: plain(k.key, ascii)
|
|
1130
|
-
})
|
|
1131
|
-
}), /* @__PURE__ */ jsx(Ell, {
|
|
1132
|
-
width: Math.max(8, width - 20),
|
|
1133
|
-
children: plain(k.label, ascii)
|
|
1134
|
-
})] }, `${k.key}-${k.label}`);
|
|
1135
|
-
return /* @__PURE__ */ jsx(Clickable, {
|
|
1136
|
-
onClick: () => void 0,
|
|
1137
|
-
children: /* @__PURE__ */ jsxs(Card, {
|
|
1138
|
-
...c.entry ? { accent: c.entry } : {},
|
|
1139
|
-
fill: true,
|
|
1140
|
-
width,
|
|
1141
|
-
children: [
|
|
1142
|
-
/* @__PURE__ */ jsx(Label, { children: "Everywhere" }),
|
|
1143
|
-
global.map(row),
|
|
1144
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1145
|
-
marginTop: 1,
|
|
1146
|
-
children: /* @__PURE__ */ jsx(Label, { children: screenTitle })
|
|
1147
|
-
}),
|
|
1148
|
-
screenKeys.length === 0 ? /* @__PURE__ */ jsx(Text, {
|
|
1149
|
-
...c.quiet ? { color: c.quiet } : { dimColor: true },
|
|
1150
|
-
children: "No other keys here."
|
|
1151
|
-
}) : screenKeys.map(row),
|
|
1152
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1153
|
-
marginTop: 1,
|
|
1154
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1155
|
-
...c.quiet ? { color: c.quiet } : { dimColor: true },
|
|
1156
|
-
children: "Esc or ? to close"
|
|
1157
|
-
})
|
|
1158
|
-
})
|
|
1159
|
-
]
|
|
1160
|
-
})
|
|
1161
|
-
});
|
|
1162
|
-
}
|
|
1163
|
-
// src/tui/screens/kit.tsx
|
|
1164
|
-
/** Small helpers the New, Devices and Setup screens share. */
|
|
1165
|
-
/** A Box that takes left clicks and/or the wheel. Other props go to the Box. */
|
|
1166
|
-
function Hit({ onClick, onWheel, isActive = true, children, ...box }) {
|
|
1167
|
-
const ref = useRef(null);
|
|
1168
|
-
useClick(ref, (e) => {
|
|
1169
|
-
if (e.button === "left") onClick?.(e);
|
|
1170
|
-
}, { isActive: isActive && onClick !== void 0 });
|
|
1171
|
-
useWheel(ref, (d) => onWheel?.(d), { isActive: isActive && onWheel !== void 0 });
|
|
1172
|
-
return /* @__PURE__ */ jsx(Box, {
|
|
1173
|
-
ref,
|
|
1174
|
-
...box,
|
|
1175
|
-
children
|
|
1176
|
-
});
|
|
1177
|
-
}
|
|
1178
|
-
/** A counter that ticks every `ms` while `on`. Drives spinners and countdowns. */
|
|
1179
|
-
function useTick(on, ms = 120) {
|
|
1180
|
-
const [n, setN] = useState(0);
|
|
1181
|
-
useEffect(() => {
|
|
1182
|
-
if (!on) return;
|
|
1183
|
-
const id = setInterval(() => setN((x) => x + 1), ms);
|
|
1184
|
-
return () => clearInterval(id);
|
|
1185
|
-
}, [on, ms]);
|
|
1186
|
-
return n;
|
|
1187
|
-
}
|
|
1188
|
-
const FRAMES = [
|
|
1189
|
-
"⠋",
|
|
1190
|
-
"⠙",
|
|
1191
|
-
"⠹",
|
|
1192
|
-
"⠸",
|
|
1193
|
-
"⠼",
|
|
1194
|
-
"⠴",
|
|
1195
|
-
"⠦",
|
|
1196
|
-
"⠧",
|
|
1197
|
-
"⠇",
|
|
1198
|
-
"⠏"
|
|
1199
|
-
];
|
|
1200
|
-
const ASCII_FRAMES = [
|
|
1201
|
-
"|",
|
|
1202
|
-
"/",
|
|
1203
|
-
"-",
|
|
1204
|
-
"\\"
|
|
1205
|
-
];
|
|
1206
|
-
function Spinner({ tick }) {
|
|
1207
|
-
const { ascii, c } = useTheme();
|
|
1208
|
-
const f = ascii ? ASCII_FRAMES : FRAMES;
|
|
1209
|
-
return /* @__PURE__ */ jsx(Text, {
|
|
1210
|
-
...c.info ? { color: c.info } : {},
|
|
1211
|
-
children: f[tick % f.length]
|
|
1212
|
-
});
|
|
1213
|
-
}
|
|
1214
|
-
/** Marks that carry meaning without colour. */
|
|
1215
|
-
function useMarks() {
|
|
1216
|
-
const { ascii } = useTheme();
|
|
1217
|
-
return {
|
|
1218
|
-
ok: ascii ? "ok" : "✓",
|
|
1219
|
-
warn: "!",
|
|
1220
|
-
error: ascii ? "x" : "✗",
|
|
1221
|
-
info: ascii ? "-" : "·",
|
|
1222
|
-
pending: ascii ? "." : "○",
|
|
1223
|
-
enter: ascii ? "Enter" : "⏎",
|
|
1224
|
-
ellipsis: ascii ? "..." : "…",
|
|
1225
|
-
radioOn: ascii ? "(*)" : "◉",
|
|
1226
|
-
radioOff: ascii ? "( )" : "○",
|
|
1227
|
-
cursor: ascii ? ">" : "▸"
|
|
1228
|
-
};
|
|
1229
|
-
}
|
|
1230
|
-
/** `m:ss` from milliseconds. */
|
|
1231
|
-
function clock(ms) {
|
|
1232
|
-
const s = Math.max(0, Math.ceil(ms / 1e3));
|
|
1233
|
-
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
|
|
1234
|
-
}
|
|
1235
|
-
// src/tui/screens/devices.tsx
|
|
1236
|
-
var devices_exports = /* @__PURE__ */ __exportAll({
|
|
1237
|
-
accountLine: () => accountLine,
|
|
1238
|
-
default: () => DevicesScreen,
|
|
1239
|
-
machinesOf: () => machinesOf
|
|
1240
|
-
});
|
|
1241
|
-
/** Machines to list, this one first. Pure, for tests. */
|
|
1242
|
-
function machinesOf(state) {
|
|
1243
|
-
const list = state.devices?.devices;
|
|
1244
|
-
if (list && list.length > 0) return [...list].sort((a, b) => Number(b.self) - Number(a.self));
|
|
1245
|
-
const r = state.relay;
|
|
1246
|
-
if (!r) return [];
|
|
1247
|
-
return [{
|
|
1248
|
-
deviceId: r.device.deviceId,
|
|
1249
|
-
name: r.device.name,
|
|
1250
|
-
fingerprint: r.device.fingerprint,
|
|
1251
|
-
self: true,
|
|
1252
|
-
online: true,
|
|
1253
|
-
sessions: 0
|
|
1254
|
-
}, ...r.peers];
|
|
1255
|
-
}
|
|
1256
|
-
/** `Signed in · Pro trial, 12 days left (u to manage)`. Pure, for tests. */
|
|
1257
|
-
function accountLine(a) {
|
|
1258
|
-
if (!a?.signedIn) return "Not signed in";
|
|
1259
|
-
const plan = a.plan ?? "";
|
|
1260
|
-
const days = a.trialDaysLeft;
|
|
1261
|
-
const trial = days !== void 0 && days >= 0;
|
|
1262
|
-
return `Signed in · ${/pro/i.test(plan) ? trial ? `Pro trial, ${days} ${days === 1 ? "day" : "days"} left` : "Pro" : plan || "Free"} (u to manage)`;
|
|
1263
|
-
}
|
|
1264
|
-
function DevicesScreen(props) {
|
|
1265
|
-
const { state, actions, layout, rows, columns, active, setKeys, setCommands, toast, setTyping } = props;
|
|
1266
|
-
const { c } = useTheme();
|
|
1267
|
-
const m = useMarks();
|
|
1268
|
-
const [sel, setSel] = useState(0);
|
|
1269
|
-
const [phase, setPhase] = useState({ k: "idle" });
|
|
1270
|
-
const [ask, setAsk] = useState();
|
|
1271
|
-
const cancelled = useRef(false);
|
|
1272
|
-
const startCount = useRef(0);
|
|
1273
|
-
const machines = useMemo(() => machinesOf(state), [state]);
|
|
1274
|
-
const relayState = state.relay?.state;
|
|
1275
|
-
const pitch = state.connection === "ready" && ((state.account ? !state.account.signedIn : false) || relayState === "logged_out" || relayState === "not_pro");
|
|
1276
|
-
const pairing = phase.k !== "idle" && phase.k !== "done" && phase.k !== "failed";
|
|
1277
|
-
const typing = phase.k === "confirm" && !phase.sending;
|
|
1278
|
-
const at = Math.min(sel, Math.max(0, machines.length - 1));
|
|
1279
|
-
const tick = useTick(phase.k === "waiting" || phase.k === "finishing" || phase.k === "confirm");
|
|
1280
|
-
useEffect(() => {
|
|
1281
|
-
setTyping(typing && active);
|
|
1282
|
-
return () => setTyping(false);
|
|
1283
|
-
}, [
|
|
1284
|
-
typing,
|
|
1285
|
-
active,
|
|
1286
|
-
setTyping
|
|
1287
|
-
]);
|
|
1288
|
-
const startPairing = useCallback(async () => {
|
|
1289
|
-
if (pairing) return;
|
|
1290
|
-
if (pitch || !state.relay || state.relay.state === "revoked") return toast("Sync isn't on for this machine yet. Press u to sign in.", "warn");
|
|
1291
|
-
cancelled.current = false;
|
|
1292
|
-
startCount.current = state.devices?.devices.length ?? 0;
|
|
1293
|
-
const since = Date.now();
|
|
1294
|
-
setPhase({
|
|
1295
|
-
k: "waiting",
|
|
1296
|
-
since
|
|
1297
|
-
});
|
|
1298
|
-
try {
|
|
1299
|
-
const r = await actions.pair();
|
|
1300
|
-
if (cancelled.current) return;
|
|
1301
|
-
setPhase({
|
|
1302
|
-
k: "confirm",
|
|
1303
|
-
words: r.words,
|
|
1304
|
-
expiresAt: Date.parse(r.expiresAt) || since + 3e5,
|
|
1305
|
-
code: ""
|
|
1306
|
-
});
|
|
1307
|
-
} catch (e) {
|
|
1308
|
-
if (cancelled.current) return;
|
|
1309
|
-
setPhase({
|
|
1310
|
-
k: "failed",
|
|
1311
|
-
error: e instanceof Error ? e.message : "Pairing did not start."
|
|
1312
|
-
});
|
|
1313
|
-
}
|
|
1314
|
-
}, [
|
|
1315
|
-
pairing,
|
|
1316
|
-
pitch,
|
|
1317
|
-
state.relay,
|
|
1318
|
-
state.devices,
|
|
1319
|
-
actions,
|
|
1320
|
-
toast
|
|
1321
|
-
]);
|
|
1322
|
-
const decline = useCallback(async () => {
|
|
1323
|
-
cancelled.current = true;
|
|
1324
|
-
setPhase({ k: "idle" });
|
|
1325
|
-
await actions.cancelPair().catch(() => void 0);
|
|
1326
|
-
toast("Nothing got linked.", "ok");
|
|
1327
|
-
}, [actions, toast]);
|
|
1328
|
-
const submitCode = useCallback(async (code) => {
|
|
1329
|
-
if (phase.k !== "confirm" || phase.sending) return;
|
|
1330
|
-
const clean = code.trim();
|
|
1331
|
-
if (!clean) return;
|
|
1332
|
-
setPhase({
|
|
1333
|
-
...phase,
|
|
1334
|
-
sending: true
|
|
1335
|
-
});
|
|
1336
|
-
try {
|
|
1337
|
-
await actions.confirmPair(clean);
|
|
1338
|
-
setPhase({ k: "finishing" });
|
|
1339
|
-
} catch (e) {
|
|
1340
|
-
setPhase({
|
|
1341
|
-
...phase,
|
|
1342
|
-
sending: false,
|
|
1343
|
-
code: "",
|
|
1344
|
-
error: e instanceof Error ? e.message : "That is not the code the other machine shows."
|
|
1345
|
-
});
|
|
1346
|
-
}
|
|
1347
|
-
}, [phase, actions]);
|
|
1348
|
-
useEffect(() => {
|
|
1349
|
-
if (phase.k !== "finishing") return;
|
|
1350
|
-
const id = setInterval(() => {
|
|
1351
|
-
(async () => {
|
|
1352
|
-
const s = await actions.pairStatus().catch(() => void 0);
|
|
1353
|
-
if (s?.state === "done") setPhase({ k: "done" });
|
|
1354
|
-
else if (s?.state === "failed") setPhase({
|
|
1355
|
-
k: "failed",
|
|
1356
|
-
error: s.error ?? "The other machine stopped."
|
|
1357
|
-
});
|
|
1358
|
-
})();
|
|
1359
|
-
}, 500);
|
|
1360
|
-
return () => clearInterval(id);
|
|
1361
|
-
}, [phase.k, actions]);
|
|
1362
|
-
useEffect(() => {
|
|
1363
|
-
if (phase.k === "finishing" && (state.devices?.devices.length ?? 0) > startCount.current) setPhase({ k: "done" });
|
|
1364
|
-
}, [phase.k, state.devices]);
|
|
1365
|
-
useEffect(() => {
|
|
1366
|
-
if (phase.k === "done") toast("Linked. The two machines now see each other.", "ok");
|
|
1367
|
-
}, [phase.k, toast]);
|
|
1368
|
-
useEffect(() => {
|
|
1369
|
-
if (phase.k !== "confirm") return;
|
|
1370
|
-
const left = phase.expiresAt - Date.now();
|
|
1371
|
-
if (left <= 0) return setPhase({
|
|
1372
|
-
k: "failed",
|
|
1373
|
-
error: "The code ran out. Start again on both machines."
|
|
1374
|
-
});
|
|
1375
|
-
const id = setTimeout(() => setPhase({
|
|
1376
|
-
k: "failed",
|
|
1377
|
-
error: "The code ran out. Start again on both machines."
|
|
1378
|
-
}), left);
|
|
1379
|
-
return () => clearTimeout(id);
|
|
1380
|
-
}, [phase]);
|
|
1381
|
-
useEffect(() => {
|
|
1382
|
-
if (phase.k === "confirm" && !phase.sending) setKeys([{
|
|
1383
|
-
key: m.enter,
|
|
1384
|
-
label: "confirm code"
|
|
1385
|
-
}, {
|
|
1386
|
-
key: "Esc",
|
|
1387
|
-
label: "different? stop"
|
|
1388
|
-
}]);
|
|
1389
|
-
else if (pairing) setKeys([{
|
|
1390
|
-
key: "Esc",
|
|
1391
|
-
label: "stop"
|
|
1392
|
-
}]);
|
|
1393
|
-
else if (pitch) setKeys([{
|
|
1394
|
-
key: "u",
|
|
1395
|
-
label: "sign in"
|
|
1396
|
-
}]);
|
|
1397
|
-
else setKeys([
|
|
1398
|
-
{
|
|
1399
|
-
key: "p",
|
|
1400
|
-
label: "add a machine"
|
|
1401
|
-
},
|
|
1402
|
-
{
|
|
1403
|
-
key: "r",
|
|
1404
|
-
label: "remove"
|
|
1405
|
-
},
|
|
1406
|
-
{
|
|
1407
|
-
key: "R",
|
|
1408
|
-
label: "remove all"
|
|
1409
|
-
},
|
|
1410
|
-
{
|
|
1411
|
-
key: "u",
|
|
1412
|
-
label: "account"
|
|
1413
|
-
}
|
|
1414
|
-
]);
|
|
1415
|
-
}, [
|
|
1416
|
-
phase,
|
|
1417
|
-
pairing,
|
|
1418
|
-
pitch,
|
|
1419
|
-
setKeys,
|
|
1420
|
-
m.enter
|
|
1421
|
-
]);
|
|
1422
|
-
useEffect(() => {
|
|
1423
|
-
setCommands([{
|
|
1424
|
-
id: "devices.pair",
|
|
1425
|
-
label: "Add a machine",
|
|
1426
|
-
key: "p",
|
|
1427
|
-
run: () => void startPairing()
|
|
1428
|
-
}, {
|
|
1429
|
-
id: "devices.account",
|
|
1430
|
-
label: "Sign in or manage my account",
|
|
1431
|
-
key: "u",
|
|
1432
|
-
run: () => void actions.openAccountPage()
|
|
1433
|
-
}]);
|
|
1434
|
-
}, [
|
|
1435
|
-
setCommands,
|
|
1436
|
-
startPairing,
|
|
1437
|
-
actions
|
|
1438
|
-
]);
|
|
1439
|
-
const answer = useCallback(async (yes) => {
|
|
1440
|
-
const a = ask;
|
|
1441
|
-
setAsk(void 0);
|
|
1442
|
-
if (!yes || !a) return;
|
|
1443
|
-
try {
|
|
1444
|
-
if (a.k === "revoke") {
|
|
1445
|
-
await actions.revokeDevice(a.device.deviceId);
|
|
1446
|
-
toast(`Removed ${a.device.name}`, "ok");
|
|
1447
|
-
} else {
|
|
1448
|
-
await actions.openAccountPage();
|
|
1449
|
-
toast("Sign in in your browser. Then run conveno devices reset here.", "ok");
|
|
1450
|
-
}
|
|
1451
|
-
} catch (e) {
|
|
1452
|
-
toast(e instanceof Error ? e.message : "That did not work.", "error");
|
|
1453
|
-
}
|
|
1454
|
-
}, [
|
|
1455
|
-
ask,
|
|
1456
|
-
actions,
|
|
1457
|
-
toast
|
|
1458
|
-
]);
|
|
1459
|
-
const removeSelected = () => {
|
|
1460
|
-
const d = machines[at];
|
|
1461
|
-
if (!d) return;
|
|
1462
|
-
if (d.self) return toast("That's this machine. Remove it from another machine.", "warn");
|
|
1463
|
-
setAsk({
|
|
1464
|
-
k: "revoke",
|
|
1465
|
-
device: d
|
|
1466
|
-
});
|
|
1467
|
-
};
|
|
1468
|
-
const closePair = () => setPhase({ k: "idle" });
|
|
1469
|
-
useInput((input, key) => {
|
|
1470
|
-
if (ask) {
|
|
1471
|
-
if (input === "y") return void answer(true);
|
|
1472
|
-
if (input === "n" || key.escape) return void answer(false);
|
|
1473
|
-
return;
|
|
1474
|
-
}
|
|
1475
|
-
if (phase.k === "waiting" || phase.k === "finishing") {
|
|
1476
|
-
if (input === "n" || key.escape) return void decline();
|
|
1477
|
-
return;
|
|
1478
|
-
}
|
|
1479
|
-
if (phase.k === "confirm") return;
|
|
1480
|
-
if (phase.k === "done" || phase.k === "failed") {
|
|
1481
|
-
if (key.return || key.escape || input === "p") setPhase({ k: "idle" });
|
|
1482
|
-
return;
|
|
1483
|
-
}
|
|
1484
|
-
if (key.upArrow) return setSel(Math.max(0, at - 1));
|
|
1485
|
-
if (key.downArrow) return setSel(Math.min(machines.length - 1, at + 1));
|
|
1486
|
-
if (input === "p") return void startPairing();
|
|
1487
|
-
if (input === "u") return void actions.openAccountPage();
|
|
1488
|
-
if (input === "r") return removeSelected();
|
|
1489
|
-
if (input === "R") return setAsk({ k: "all" });
|
|
1490
|
-
}, { isActive: active && !typing });
|
|
1491
|
-
const wide = layout === "wide";
|
|
1492
|
-
const split = splitWidths(columns, wide, {
|
|
1493
|
-
panelW: 50,
|
|
1494
|
-
maxMain: 100
|
|
1495
|
-
});
|
|
1496
|
-
const sideW = paneInner(split.panelW);
|
|
1497
|
-
const mainW = wide ? split.mainW - 2 : Math.min(columns, 100);
|
|
1498
|
-
const quiet = c.quiet ? { color: c.quiet } : { dimColor: true };
|
|
1499
|
-
const pairPanel = (width) => /* @__PURE__ */ jsxs(Box, {
|
|
1500
|
-
flexDirection: "column",
|
|
1501
|
-
width,
|
|
1502
|
-
children: [/* @__PURE__ */ jsx(Label, { children: "Add a machine" }), phase.k === "idle" ? /* @__PURE__ */ jsx(Hit, {
|
|
1503
|
-
onClick: () => void (pitch || !state.relay ? actions.openAccountPage() : startPairing()),
|
|
1504
|
-
isActive: active,
|
|
1505
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1506
|
-
...quiet,
|
|
1507
|
-
children: pitch || !state.relay ? "Sign in first (u)." : "Press p to link another machine."
|
|
1508
|
-
})
|
|
1509
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1510
|
-
/* @__PURE__ */ jsx(Text, { children: "1. On the other machine, run" }),
|
|
1511
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1512
|
-
bold: true,
|
|
1513
|
-
children: " conveno devices join"
|
|
1514
|
-
}),
|
|
1515
|
-
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, {
|
|
1516
|
-
onClick: () => void decline(),
|
|
1517
|
-
isActive: active,
|
|
1518
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1519
|
-
...quiet,
|
|
1520
|
-
children: "Esc stops"
|
|
1521
|
-
})
|
|
1522
|
-
})] }) : null,
|
|
1523
|
-
phase.k === "confirm" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1524
|
-
/* @__PURE__ */ jsx(Text, { children: "2. This machine shows" }),
|
|
1525
|
-
/* @__PURE__ */ jsx(Card, {
|
|
1526
|
-
accent: c.info,
|
|
1527
|
-
width: Math.min(width, 30),
|
|
1528
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1529
|
-
bold: true,
|
|
1530
|
-
children: ` ${phase.words.join(" ")}`
|
|
1531
|
-
})
|
|
1532
|
-
}),
|
|
1533
|
-
/* @__PURE__ */ jsx(Text, { children: "3. Type that on the other machine. It shows a different code. Type it here:" }),
|
|
1534
|
-
/* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Text, {
|
|
1535
|
-
bold: true,
|
|
1536
|
-
children: " > "
|
|
1537
|
-
}), /* @__PURE__ */ jsx(TextBox, {
|
|
1538
|
-
value: phase.code,
|
|
1539
|
-
onChange: (v) => setPhase({
|
|
1540
|
-
...phase,
|
|
1541
|
-
code: v
|
|
1542
|
-
}),
|
|
1543
|
-
onSubmit: (v) => void submitCode(v),
|
|
1544
|
-
onCancel: () => void decline(),
|
|
1545
|
-
focus: active && !phase.sending,
|
|
1546
|
-
placeholder: "the other machine's code"
|
|
1547
|
-
})] }),
|
|
1548
|
-
phase.error ? /* @__PURE__ */ jsx(Text, {
|
|
1549
|
-
...c.error ? { color: c.error } : {},
|
|
1550
|
-
children: phase.error
|
|
1551
|
-
}) : null,
|
|
1552
|
-
/* @__PURE__ */ jsxs(Box, {
|
|
1553
|
-
flexWrap: "wrap",
|
|
1554
|
-
children: [
|
|
1555
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1556
|
-
...quiet,
|
|
1557
|
-
children: "Wrong or different? "
|
|
1558
|
-
}),
|
|
1559
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
1560
|
-
onClick: () => void decline(),
|
|
1561
|
-
isActive: active,
|
|
1562
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1563
|
-
...quiet,
|
|
1564
|
-
children: "Press Esc"
|
|
1565
|
-
})
|
|
1566
|
-
}),
|
|
1567
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1568
|
-
...quiet,
|
|
1569
|
-
children: ` and nothing gets linked. ${clock(phase.expiresAt - Date.now())} left`
|
|
1570
|
-
})
|
|
1571
|
-
]
|
|
1572
|
-
})
|
|
1573
|
-
] }) : null,
|
|
1574
|
-
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, {
|
|
1575
|
-
onClick: () => void decline(),
|
|
1576
|
-
isActive: active,
|
|
1577
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1578
|
-
...quiet,
|
|
1579
|
-
children: "Esc stops"
|
|
1580
|
-
})
|
|
1581
|
-
})] }) : null,
|
|
1582
|
-
phase.k === "done" ? /* @__PURE__ */ jsx(Hit, {
|
|
1583
|
-
onClick: closePair,
|
|
1584
|
-
isActive: active,
|
|
1585
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1586
|
-
...c.ok ? { color: c.ok } : {},
|
|
1587
|
-
children: `${m.ok} Linked. Press ${m.enter}.`
|
|
1588
|
-
})
|
|
1589
|
-
}) : null,
|
|
1590
|
-
phase.k === "failed" ? /* @__PURE__ */ jsx(Hit, {
|
|
1591
|
-
onClick: closePair,
|
|
1592
|
-
isActive: active,
|
|
1593
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1594
|
-
...c.error ? { color: c.error } : {},
|
|
1595
|
-
wrap: "wrap",
|
|
1596
|
-
children: `${m.error} ${phase.error} (${m.enter} to close)`
|
|
1597
|
-
})
|
|
1598
|
-
}) : null
|
|
1599
|
-
] })]
|
|
1600
|
-
});
|
|
1601
|
-
if (!state.relay && state.connection === "ready" && !state.account) return /* @__PURE__ */ jsx(Text, {
|
|
1602
|
-
...quiet,
|
|
1603
|
-
children: `Checking sync${m.ellipsis}`
|
|
1604
|
-
});
|
|
1605
|
-
if (pitch) return /* @__PURE__ */ jsxs(Box, {
|
|
1606
|
-
flexDirection: "column",
|
|
1607
|
-
width: Math.min(mainW, 70),
|
|
1608
|
-
children: [
|
|
1609
|
-
/* @__PURE__ */ jsx(Label, { children: "Your machines" }),
|
|
1610
|
-
/* @__PURE__ */ jsx(Text, { children: "Pro links your machines so sessions can talk across them." }),
|
|
1611
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
1612
|
-
onClick: () => void actions.openAccountPage(),
|
|
1613
|
-
isActive: active,
|
|
1614
|
-
children: /* @__PURE__ */ jsxs(Text, { children: [
|
|
1615
|
-
"Press ",
|
|
1616
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1617
|
-
bold: true,
|
|
1618
|
-
children: "u"
|
|
1619
|
-
}),
|
|
1620
|
-
" to sign in."
|
|
1621
|
-
] })
|
|
1622
|
-
}),
|
|
1623
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1624
|
-
...quiet,
|
|
1625
|
-
children: "We only see machine names and message sizes. Never what's inside."
|
|
1626
|
-
})
|
|
1627
|
-
]
|
|
1628
|
-
});
|
|
1629
|
-
if (relayState === "revoked") return /* @__PURE__ */ jsxs(Box, {
|
|
1630
|
-
flexDirection: "column",
|
|
1631
|
-
width: mainW,
|
|
1632
|
-
children: [/* @__PURE__ */ jsx(Text, {
|
|
1633
|
-
...c.error ? { color: c.error } : {},
|
|
1634
|
-
children: "This machine was removed from your account."
|
|
1635
|
-
}), /* @__PURE__ */ jsx(Text, { children: "Run conveno devices reset here, then link it again." })]
|
|
1636
|
-
});
|
|
1637
|
-
const longest = machines.reduce((n, d) => Math.max(n, [...d.self ? `${d.name} (this one)` : d.name].length), 0);
|
|
1638
|
-
const nameW = Math.max(12, Math.min(40, longest + 1));
|
|
1639
|
-
const sessionsW = Math.max(0, mainW - 2 - nameW - 2 - 9 - 2 - 20 - 2);
|
|
1640
|
-
const showPair = pairing || phase.k === "done" || phase.k === "failed";
|
|
1641
|
-
const table = /* @__PURE__ */ jsxs(Box, {
|
|
1642
|
-
flexDirection: "column",
|
|
1643
|
-
width: mainW,
|
|
1644
|
-
children: [
|
|
1645
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
1646
|
-
onClick: () => void actions.openAccountPage(),
|
|
1647
|
-
isActive: active,
|
|
1648
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1649
|
-
...quiet,
|
|
1650
|
-
children: accountLine(state.account)
|
|
1651
|
-
})
|
|
1652
|
-
}),
|
|
1653
|
-
state.relay && state.relay.state !== "connected" && state.relay.state !== "unpaired" ? /* @__PURE__ */ jsx(Text, {
|
|
1654
|
-
...quiet,
|
|
1655
|
-
children: state.relay.detail ?? (state.relay.state === "connecting" ? "Connecting…" : "Sync is offline, it keeps trying.")
|
|
1656
|
-
}) : null,
|
|
1657
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
1658
|
-
/* @__PURE__ */ jsx(Label, { children: `Your machines · ${machines.length}` }),
|
|
1659
|
-
machines.length === 0 ? /* @__PURE__ */ jsx(Hit, {
|
|
1660
|
-
onClick: () => void startPairing(),
|
|
1661
|
-
isActive: active,
|
|
1662
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1663
|
-
...quiet,
|
|
1664
|
-
children: "Only this machine so far. Press p to add another."
|
|
1665
|
-
})
|
|
1666
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(HeaderRow, {
|
|
1667
|
-
width: mainW,
|
|
1668
|
-
cols: [
|
|
1669
|
-
{
|
|
1670
|
-
w: 2,
|
|
1671
|
-
text: "",
|
|
1672
|
-
gap: 0
|
|
1673
|
-
},
|
|
1674
|
-
{
|
|
1675
|
-
w: nameW + 2,
|
|
1676
|
-
text: "Machine"
|
|
1677
|
-
},
|
|
1678
|
-
{
|
|
1679
|
-
w: 11,
|
|
1680
|
-
text: "Status"
|
|
1681
|
-
},
|
|
1682
|
-
{
|
|
1683
|
-
w: 22,
|
|
1684
|
-
text: "Added"
|
|
1685
|
-
},
|
|
1686
|
-
{
|
|
1687
|
-
w: sessionsW,
|
|
1688
|
-
text: "Sessions",
|
|
1689
|
-
gap: 0
|
|
1690
|
-
}
|
|
1691
|
-
]
|
|
1692
|
-
}), /* @__PURE__ */ jsx(Hit, {
|
|
1693
|
-
onWheel: (d) => setSel(Math.max(0, Math.min(machines.length - 1, at + (d < 0 ? -1 : 1)))),
|
|
1694
|
-
isActive: active,
|
|
1695
|
-
flexDirection: "column",
|
|
1696
|
-
children: /* @__PURE__ */ jsx(ScrollList, {
|
|
1697
|
-
items: machines,
|
|
1698
|
-
selected: at,
|
|
1699
|
-
height: Math.max(3, rows - 12),
|
|
1700
|
-
keyOf: (d) => d.deviceId,
|
|
1701
|
-
renderItem: (d, isSel, i) => /* @__PURE__ */ jsx(Hit, {
|
|
1702
|
-
onClick: () => setSel(i),
|
|
1703
|
-
isActive: active,
|
|
1704
|
-
children: /* @__PURE__ */ jsxs(Row, {
|
|
1705
|
-
width: mainW,
|
|
1706
|
-
selected: isSel,
|
|
1707
|
-
children: [
|
|
1708
|
-
/* @__PURE__ */ jsx(Cell, {
|
|
1709
|
-
w: 2,
|
|
1710
|
-
gap: 0,
|
|
1711
|
-
color: c.entry,
|
|
1712
|
-
children: isSel ? `${m.cursor} ` : " "
|
|
1713
|
-
}),
|
|
1714
|
-
/* @__PURE__ */ jsx(Cell, {
|
|
1715
|
-
w: nameW + 2,
|
|
1716
|
-
bold: isSel,
|
|
1717
|
-
children: d.self ? `${d.name} (this one)` : d.name
|
|
1718
|
-
}),
|
|
1719
|
-
/* @__PURE__ */ jsx(Cell, {
|
|
1720
|
-
w: 11,
|
|
1721
|
-
color: d.online ? c.ok : c.quiet,
|
|
1722
|
-
dim: !d.online,
|
|
1723
|
-
children: d.online ? "online" : "offline"
|
|
1724
|
-
}),
|
|
1725
|
-
/* @__PURE__ */ jsx(Cell, {
|
|
1726
|
-
w: 22,
|
|
1727
|
-
color: c.quiet,
|
|
1728
|
-
children: d.self ? "" : d.addedAt ? `added ${relTime(d.addedAt)}` : ""
|
|
1729
|
-
}),
|
|
1730
|
-
/* @__PURE__ */ jsx(Cell, {
|
|
1731
|
-
w: sessionsW,
|
|
1732
|
-
gap: 0,
|
|
1733
|
-
color: c.quiet,
|
|
1734
|
-
children: d.self ? "" : `${d.sessions} ${d.sessions === 1 ? "session" : "sessions"}`
|
|
1735
|
-
})
|
|
1736
|
-
]
|
|
1737
|
-
})
|
|
1738
|
-
})
|
|
1739
|
-
})
|
|
1740
|
-
})] }),
|
|
1741
|
-
state.devices?.conflict ? /* @__PURE__ */ jsx(Text, {
|
|
1742
|
-
...c.error ? { color: c.error } : {},
|
|
1743
|
-
wrap: "wrap",
|
|
1744
|
-
children: `${m.error} Your machines' lists don't match. Run conveno devices for the steps.`
|
|
1745
|
-
}) : null,
|
|
1746
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
1747
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1748
|
-
...quiet,
|
|
1749
|
-
children: "We only see machine names and message sizes. Never what's inside."
|
|
1750
|
-
}),
|
|
1751
|
-
ask ? /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Box, {
|
|
1752
|
-
flexShrink: 1,
|
|
1753
|
-
children: /* @__PURE__ */ jsxs(Text, {
|
|
1754
|
-
wrap: "wrap",
|
|
1755
|
-
children: [/* @__PURE__ */ jsx(Text, {
|
|
1756
|
-
bold: true,
|
|
1757
|
-
children: ask.k === "revoke" ? `Remove ${ask.device.name}?` : "Remove all machines?"
|
|
1758
|
-
}), 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."]
|
|
1759
|
-
})
|
|
1760
|
-
}), /* @__PURE__ */ jsxs(Box, {
|
|
1761
|
-
flexShrink: 0,
|
|
1762
|
-
children: [
|
|
1763
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
1764
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
1765
|
-
onClick: () => void answer(true),
|
|
1766
|
-
isActive: active,
|
|
1767
|
-
children: /* @__PURE__ */ jsx(Text, { children: "y" })
|
|
1768
|
-
}),
|
|
1769
|
-
/* @__PURE__ */ jsx(Text, { children: "/" }),
|
|
1770
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
1771
|
-
onClick: () => void answer(false),
|
|
1772
|
-
isActive: active,
|
|
1773
|
-
children: /* @__PURE__ */ jsx(Text, { children: "n" })
|
|
1774
|
-
})
|
|
1775
|
-
]
|
|
1776
|
-
})] }) : /* @__PURE__ */ jsxs(Box, {
|
|
1777
|
-
flexWrap: "wrap",
|
|
1778
|
-
children: [
|
|
1779
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
1780
|
-
onClick: () => void startPairing(),
|
|
1781
|
-
isActive: active,
|
|
1782
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1783
|
-
...quiet,
|
|
1784
|
-
children: "p adds a machine"
|
|
1785
|
-
})
|
|
1786
|
-
}),
|
|
1787
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1788
|
-
...quiet,
|
|
1789
|
-
children: ". Lost a machine? "
|
|
1790
|
-
}),
|
|
1791
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
1792
|
-
onClick: removeSelected,
|
|
1793
|
-
isActive: active,
|
|
1794
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1795
|
-
...quiet,
|
|
1796
|
-
children: "r removes it"
|
|
1797
|
-
})
|
|
1798
|
-
}),
|
|
1799
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1800
|
-
...quiet,
|
|
1801
|
-
children: ". "
|
|
1802
|
-
}),
|
|
1803
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
1804
|
-
onClick: () => setAsk({ k: "all" }),
|
|
1805
|
-
isActive: active,
|
|
1806
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1807
|
-
...quiet,
|
|
1808
|
-
children: "R removes all of them"
|
|
1809
|
-
})
|
|
1810
|
-
}),
|
|
1811
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1812
|
-
...quiet,
|
|
1813
|
-
children: " (you sign in again first)."
|
|
1814
|
-
})
|
|
1815
|
-
]
|
|
1816
|
-
})
|
|
1817
|
-
]
|
|
1818
|
-
});
|
|
1819
|
-
if (wide) return /* @__PURE__ */ jsxs(Box, {
|
|
1820
|
-
flexDirection: "row",
|
|
1821
|
-
height: rows,
|
|
1822
|
-
children: [/* @__PURE__ */ jsx(Box, {
|
|
1823
|
-
width: split.mainW,
|
|
1824
|
-
flexShrink: 0,
|
|
1825
|
-
children: table
|
|
1826
|
-
}), /* @__PURE__ */ jsx(Pane, {
|
|
1827
|
-
width: split.panelW,
|
|
1828
|
-
height: rows,
|
|
1829
|
-
children: pairPanel(sideW)
|
|
1830
|
-
})]
|
|
1831
|
-
});
|
|
1832
|
-
return showPair ? pairPanel(Math.min(columns - 2, 70)) : table;
|
|
1833
|
-
}
|
|
1834
|
-
// src/tui/screens/new.tsx
|
|
1835
|
-
/** Screen 2: Start a new worker. */
|
|
1836
|
-
var new_exports = /* @__PURE__ */ __exportAll({
|
|
1837
|
-
completeDir: () => completeDir,
|
|
1838
|
-
default: () => NewScreen,
|
|
1839
|
-
expandPath: () => expandPath,
|
|
1840
|
-
shortPath: () => shortPath,
|
|
1841
|
-
spawnCommand: () => spawnCommand,
|
|
1842
|
-
suggestName: () => suggestName
|
|
1843
|
-
});
|
|
1844
|
-
/** `~/code/api` to an absolute path. */
|
|
1845
|
-
function expandPath(input, home, cwd) {
|
|
1846
|
-
if (input === "~") return home;
|
|
1847
|
-
if (input.startsWith("~/")) return join(home, input.slice(2));
|
|
1848
|
-
return resolve(cwd, input);
|
|
1849
|
-
}
|
|
1850
|
-
/** An absolute path with `~` for the home folder. */
|
|
1851
|
-
function shortPath(abs, home) {
|
|
1852
|
-
if (abs === home) return "~";
|
|
1853
|
-
return abs.startsWith(`${home}/`) ? `~/${abs.slice(home.length + 1)}` : abs;
|
|
1854
|
-
}
|
|
1855
|
-
/** Longest shared start of some strings. */
|
|
1856
|
-
function commonStart(words) {
|
|
1857
|
-
let out = words[0] ?? "";
|
|
1858
|
-
for (const w of words) while (!w.startsWith(out)) out = out.slice(0, -1);
|
|
1859
|
-
return out;
|
|
1860
|
-
}
|
|
1861
|
-
/** Tab completion for a folder: extends what is typed, or adds `/` when one folder fits. */
|
|
1862
|
-
function completeDir(input, home, cwd) {
|
|
1863
|
-
const slash = input.lastIndexOf("/");
|
|
1864
|
-
const parentTyped = slash >= 0 ? input.slice(0, slash + 1) : "";
|
|
1865
|
-
const prefix = slash >= 0 ? input.slice(slash + 1) : input;
|
|
1866
|
-
const parentAbs = expandPath(parentTyped === "" ? "." : parentTyped, home, cwd);
|
|
1867
|
-
let names;
|
|
1868
|
-
try {
|
|
1869
|
-
names = readdirSync(parentAbs, { withFileTypes: true }).filter((d) => d.isDirectory() && d.name.startsWith(prefix) && (prefix.startsWith(".") || !d.name.startsWith("."))).map((d) => d.name).sort();
|
|
1870
|
-
} catch {
|
|
1871
|
-
return input;
|
|
1872
|
-
}
|
|
1873
|
-
if (names.length === 0) return input;
|
|
1874
|
-
if (names.length === 1) return `${parentTyped}${names[0]}/`;
|
|
1875
|
-
const common = commonStart(names);
|
|
1876
|
-
return common.length > prefix.length ? `${parentTyped}${common}` : input;
|
|
1877
|
-
}
|
|
1878
|
-
/** `<cli>-<folder>`, safe for a session name. */
|
|
1879
|
-
function suggestName(cli, folder) {
|
|
1880
|
-
const raw = basename(folder.replace(/\/+$/, ""));
|
|
1881
|
-
const clean = (raw === "~" ? "home" : raw || "home").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
1882
|
-
return clean ? `${cli}-${clean}` : cli;
|
|
1883
|
-
}
|
|
1884
|
-
const quote = (s) => /^[\w@%+=:,./~-]+$/.test(s) ? s : `'${s.replace(/'/g, "'\\''")}'`;
|
|
1885
|
-
/** The `conveno spawn …` line that does the same. */
|
|
1886
|
-
function spawnCommand(p) {
|
|
1887
|
-
const parts = [
|
|
1888
|
-
"conveno",
|
|
1889
|
-
"spawn",
|
|
1890
|
-
p.cli,
|
|
1891
|
-
"--cwd",
|
|
1892
|
-
quote(p.folder)
|
|
1893
|
-
];
|
|
1894
|
-
if (p.name) parts.push("--name", quote(p.name));
|
|
1895
|
-
if (p.window) parts.push("--window");
|
|
1896
|
-
if (p.task.trim()) parts.push("--task", quote(p.task.trim().replace(/\s*\n\s*/g, " ")));
|
|
1897
|
-
return [parts.join(" ")];
|
|
1898
|
-
}
|
|
1899
|
-
const ORDER = [
|
|
1900
|
-
"cli",
|
|
1901
|
-
"folder",
|
|
1902
|
-
"name",
|
|
1903
|
-
"task",
|
|
1904
|
-
"window"
|
|
1905
|
-
];
|
|
1906
|
-
const TEXT_FIELDS = [
|
|
1907
|
-
"folder",
|
|
1908
|
-
"name",
|
|
1909
|
-
"task"
|
|
1910
|
-
];
|
|
1911
|
-
function NewScreen(props) {
|
|
1912
|
-
const { state, actions, layout, columns, active, setKeys, setCommands, go, toast, setTyping } = props;
|
|
1913
|
-
const { c } = useTheme();
|
|
1914
|
-
const m = useMarks();
|
|
1915
|
-
const home = homedir();
|
|
1916
|
-
const cwd = process.cwd();
|
|
1917
|
-
const installed = useMemo(() => (state.setup?.clis ?? []).filter((x) => x.status !== "not-installed"), [state.setup]);
|
|
1918
|
-
const [field, setField] = useState("cli");
|
|
1919
|
-
const [cliIx, setCliIx] = useState(0);
|
|
1920
|
-
const [folder, setFolder] = useState(shortPath(cwd, home));
|
|
1921
|
-
const [folderKey, setFolderKey] = useState(0);
|
|
1922
|
-
const [name, setName] = useState("");
|
|
1923
|
-
const [task, setTask] = useState("");
|
|
1924
|
-
const [inWindow, setInWindow] = useState(false);
|
|
1925
|
-
const [busy, setBusy] = useState(false);
|
|
1926
|
-
const [error, setError] = useState();
|
|
1927
|
-
const asked = useRef(false);
|
|
1928
|
-
const cli = installed[Math.min(cliIx, installed.length - 1)];
|
|
1929
|
-
const suggested = cli ? suggestName(cli.cli, folder) : "";
|
|
1930
|
-
const finalName = name.trim() || suggested;
|
|
1931
|
-
const typing = TEXT_FIELDS.includes(field);
|
|
1932
|
-
const tick = useTick(busy);
|
|
1933
|
-
useEffect(() => {
|
|
1934
|
-
if (!asked.current && !state.setup) {
|
|
1935
|
-
asked.current = true;
|
|
1936
|
-
actions.refreshSetup().catch(() => void 0);
|
|
1937
|
-
}
|
|
1938
|
-
}, [state.setup, actions]);
|
|
1939
|
-
useEffect(() => {
|
|
1940
|
-
setTyping(typing && active);
|
|
1941
|
-
return () => setTyping(false);
|
|
1942
|
-
}, [
|
|
1943
|
-
typing,
|
|
1944
|
-
active,
|
|
1945
|
-
setTyping
|
|
1946
|
-
]);
|
|
1947
|
-
useEffect(() => {
|
|
1948
|
-
setKeys([
|
|
1949
|
-
{
|
|
1950
|
-
key: "Tab",
|
|
1951
|
-
label: "next"
|
|
1952
|
-
},
|
|
1953
|
-
{
|
|
1954
|
-
key: "Space",
|
|
1955
|
-
label: "tick"
|
|
1956
|
-
},
|
|
1957
|
-
{
|
|
1958
|
-
key: m.enter,
|
|
1959
|
-
label: "start"
|
|
1960
|
-
},
|
|
1961
|
-
{
|
|
1962
|
-
key: "Esc",
|
|
1963
|
-
label: "cancel"
|
|
1964
|
-
}
|
|
1965
|
-
]);
|
|
1966
|
-
}, [setKeys, m.enter]);
|
|
1967
|
-
const start = useCallback(async () => {
|
|
1968
|
-
if (busy) return;
|
|
1969
|
-
if (!cli) return setError("No CLI found yet. Set one up on screen 4.");
|
|
1970
|
-
setError(void 0);
|
|
1971
|
-
setBusy(true);
|
|
1972
|
-
try {
|
|
1973
|
-
const res = await actions.spawn({
|
|
1974
|
-
cli: cli.cli,
|
|
1975
|
-
cwd: expandPath(folder, home, cwd),
|
|
1976
|
-
window: inWindow,
|
|
1977
|
-
name: finalName,
|
|
1978
|
-
prompt: task.trim()
|
|
1979
|
-
});
|
|
1980
|
-
toast(`Started ${finalName}`, "ok");
|
|
1981
|
-
if (res.sessionId) go("sessions", res.sessionId);
|
|
1982
|
-
else go("sessions");
|
|
1983
|
-
} catch (e) {
|
|
1984
|
-
setBusy(false);
|
|
1985
|
-
setError(e instanceof Error ? e.message : "It did not start.");
|
|
1986
|
-
}
|
|
1987
|
-
}, [
|
|
1988
|
-
busy,
|
|
1989
|
-
cli,
|
|
1990
|
-
task,
|
|
1991
|
-
actions,
|
|
1992
|
-
folder,
|
|
1993
|
-
home,
|
|
1994
|
-
cwd,
|
|
1995
|
-
finalName,
|
|
1996
|
-
inWindow,
|
|
1997
|
-
toast,
|
|
1998
|
-
go
|
|
1999
|
-
]);
|
|
2000
|
-
useEffect(() => {
|
|
2001
|
-
setCommands([{
|
|
2002
|
-
id: "new.start",
|
|
2003
|
-
label: "Start this worker",
|
|
2004
|
-
key: "⏎",
|
|
2005
|
-
rank: 5,
|
|
2006
|
-
run: () => void start()
|
|
2007
|
-
}]);
|
|
2008
|
-
}, [setCommands, start]);
|
|
2009
|
-
const move = (d) => {
|
|
2010
|
-
const i = ORDER.indexOf(field);
|
|
2011
|
-
const next = ORDER[(i + d + ORDER.length) % ORDER.length];
|
|
2012
|
-
if (next) setField(next);
|
|
2013
|
-
};
|
|
2014
|
-
useInput((input, key) => {
|
|
2015
|
-
if (busy) return;
|
|
2016
|
-
if (key.escape) return go("sessions");
|
|
2017
|
-
if (key.tab) {
|
|
2018
|
-
if (field === "folder" && !key.shift) {
|
|
2019
|
-
const next = completeDir(folder, home, cwd);
|
|
2020
|
-
if (next !== folder) {
|
|
2021
|
-
setFolder(next);
|
|
2022
|
-
setFolderKey((k) => k + 1);
|
|
2023
|
-
}
|
|
2024
|
-
return;
|
|
2025
|
-
}
|
|
2026
|
-
return move(key.shift ? -1 : 1);
|
|
2027
|
-
}
|
|
2028
|
-
if (field === "cli") {
|
|
2029
|
-
if (key.upArrow) return setCliIx(Math.max(0, cliIx - 1));
|
|
2030
|
-
if (key.downArrow) return setCliIx(Math.min(installed.length - 1, cliIx + 1));
|
|
2031
|
-
if (key.return) return move(1);
|
|
2032
|
-
return;
|
|
2033
|
-
}
|
|
2034
|
-
if (field === "window") {
|
|
2035
|
-
if (input === " ") return setInWindow(!inWindow);
|
|
2036
|
-
if (key.upArrow) return move(-1);
|
|
2037
|
-
if (key.return) return void start();
|
|
2038
|
-
return;
|
|
2039
|
-
}
|
|
2040
|
-
if (key.upArrow) return move(-1);
|
|
2041
|
-
if (key.downArrow) return move(1);
|
|
2042
|
-
}, { isActive: active });
|
|
2043
|
-
const wide = layout === "wide";
|
|
2044
|
-
const split = splitWidths(columns, wide, {
|
|
2045
|
-
panelW: 46,
|
|
2046
|
-
maxMain: 100
|
|
2047
|
-
});
|
|
2048
|
-
const sideW = paneInner(split.panelW);
|
|
2049
|
-
const mainW = wide ? split.mainW - 2 : Math.min(columns, 100);
|
|
2050
|
-
const fieldW = Math.max(20, Math.min(72, mainW - 4));
|
|
2051
|
-
const focusField = (f) => {
|
|
2052
|
-
if (!busy) setField(f);
|
|
2053
|
-
};
|
|
2054
|
-
const field_ = (f, node) => /* @__PURE__ */ jsx(Hit, {
|
|
2055
|
-
onClick: () => focusField(f),
|
|
2056
|
-
marginLeft: 2,
|
|
2057
|
-
width: fieldW,
|
|
2058
|
-
paddingX: 1,
|
|
2059
|
-
...c.surface ? { backgroundColor: c.surface } : {},
|
|
2060
|
-
children: node
|
|
2061
|
-
});
|
|
2062
|
-
const label = (f, text) => /* @__PURE__ */ jsx(Hit, {
|
|
2063
|
-
onClick: () => focusField(f),
|
|
2064
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
2065
|
-
...field === f ? { bold: true } : {},
|
|
2066
|
-
...c.quiet && field !== f ? { color: c.quiet } : {},
|
|
2067
|
-
children: `${field === f ? m.cursor : " "} ${text.toUpperCase()}`
|
|
2068
|
-
})
|
|
2069
|
-
});
|
|
2070
|
-
const steps = [{ text: `${finalName || "your worker"} is ready` }, { text: "waiting for its first reply" }];
|
|
2071
|
-
const cmdLines = cli ? spawnCommand({
|
|
2072
|
-
cli: cli.cli,
|
|
2073
|
-
folder,
|
|
2074
|
-
window: inWindow,
|
|
2075
|
-
name: finalName,
|
|
2076
|
-
task
|
|
2077
|
-
}) : [];
|
|
2078
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
2079
|
-
flexDirection: "row",
|
|
2080
|
-
height: props.rows,
|
|
2081
|
-
children: [/* @__PURE__ */ jsx(Box, {
|
|
2082
|
-
flexDirection: "column",
|
|
2083
|
-
width: wide ? split.mainW : mainW,
|
|
2084
|
-
flexShrink: 0,
|
|
2085
|
-
children: installed.length === 0 ? /* @__PURE__ */ jsx(Text, {
|
|
2086
|
-
dimColor: true,
|
|
2087
|
-
children: state.setup ? "No CLI found. Set one up on screen 4 first." : `Looking for your CLIs${m.ellipsis}`
|
|
2088
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2089
|
-
label("cli", "CLI"),
|
|
2090
|
-
/* @__PURE__ */ jsx(Box, {
|
|
2091
|
-
flexDirection: "column",
|
|
2092
|
-
marginLeft: 2,
|
|
2093
|
-
children: installed.map((x, i) => /* @__PURE__ */ jsxs(Hit, {
|
|
2094
|
-
onClick: () => {
|
|
2095
|
-
if (busy) return;
|
|
2096
|
-
setCliIx(i);
|
|
2097
|
-
setField("cli");
|
|
2098
|
-
},
|
|
2099
|
-
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, {
|
|
2100
|
-
dimColor: true,
|
|
2101
|
-
children: ` ${x.status === "not-set-up" ? "not set up yet" : "needs update"}`
|
|
2102
|
-
}) : null]
|
|
2103
|
-
}, x.cli))
|
|
2104
|
-
}),
|
|
2105
|
-
label("folder", "Folder"),
|
|
2106
|
-
field_("folder", /* @__PURE__ */ jsx(TextBox, {
|
|
2107
|
-
value: folder,
|
|
2108
|
-
onChange: setFolder,
|
|
2109
|
-
onSubmit: () => move(1),
|
|
2110
|
-
focus: active && field === "folder",
|
|
2111
|
-
placeholder: "~/code/my-project"
|
|
2112
|
-
}, folderKey)),
|
|
2113
|
-
label("name", "Name"),
|
|
2114
|
-
field_("name", /* @__PURE__ */ jsx(TextBox, {
|
|
2115
|
-
value: name,
|
|
2116
|
-
onChange: setName,
|
|
2117
|
-
onSubmit: () => move(1),
|
|
2118
|
-
focus: active && field === "name",
|
|
2119
|
-
placeholder: suggested
|
|
2120
|
-
})),
|
|
2121
|
-
label("task", "Task"),
|
|
2122
|
-
field_("task", /* @__PURE__ */ jsx(TextBox, {
|
|
2123
|
-
value: task,
|
|
2124
|
-
onChange: setTask,
|
|
2125
|
-
onSubmit: () => void start(),
|
|
2126
|
-
focus: active && field === "task",
|
|
2127
|
-
multiline: true,
|
|
2128
|
-
placeholder: "What should it start on? (optional)"
|
|
2129
|
-
})),
|
|
2130
|
-
label("window", "Where"),
|
|
2131
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
2132
|
-
marginLeft: 2,
|
|
2133
|
-
onClick: () => {
|
|
2134
|
-
if (busy) return;
|
|
2135
|
-
setField("window");
|
|
2136
|
-
setInWindow(!inWindow);
|
|
2137
|
-
},
|
|
2138
|
-
children: /* @__PURE__ */ jsx(Text, { children: `${inWindow ? "[x]" : "[ ]"} in a window, so you can watch it` })
|
|
2139
|
-
}),
|
|
2140
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
2141
|
-
busy ? /* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Spinner, { tick }), ` Starting ${finalName}${m.ellipsis}`] }) : /* @__PURE__ */ jsxs(Box, { children: [
|
|
2142
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
2143
|
-
onClick: () => void start(),
|
|
2144
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
2145
|
-
bold: true,
|
|
2146
|
-
children: `${m.enter} Start`
|
|
2147
|
-
})
|
|
2148
|
-
}),
|
|
2149
|
-
/* @__PURE__ */ jsx(Text, {
|
|
2150
|
-
dimColor: true,
|
|
2151
|
-
children: " Tab next "
|
|
2152
|
-
}),
|
|
2153
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
2154
|
-
onClick: () => go("sessions"),
|
|
2155
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
2156
|
-
dimColor: true,
|
|
2157
|
-
children: "Esc cancel"
|
|
2158
|
-
})
|
|
2159
|
-
})
|
|
2160
|
-
] }),
|
|
2161
|
-
error ? /* @__PURE__ */ jsx(Text, {
|
|
2162
|
-
...c.error ? { color: c.error } : {},
|
|
2163
|
-
children: `${m.error} ${error}`
|
|
2164
|
-
}) : null
|
|
2165
|
-
] })
|
|
2166
|
-
}), wide ? /* @__PURE__ */ jsxs(Pane, {
|
|
2167
|
-
width: split.panelW,
|
|
2168
|
-
height: props.rows,
|
|
2169
|
-
children: [
|
|
2170
|
-
/* @__PURE__ */ jsx(Label, { children: "After you press ⏎" }),
|
|
2171
|
-
steps.map((s, i) => /* @__PURE__ */ jsxs(Box, { children: [
|
|
2172
|
-
busy && i === 0 ? /* @__PURE__ */ jsx(Spinner, { tick }) : /* @__PURE__ */ jsx(Text, {
|
|
2173
|
-
dimColor: true,
|
|
2174
|
-
children: m.pending
|
|
2175
|
-
}),
|
|
2176
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
2177
|
-
/* @__PURE__ */ jsx(Ell, {
|
|
2178
|
-
width: sideW - 2,
|
|
2179
|
-
...busy ? {} : { dim: true },
|
|
2180
|
-
children: s.text
|
|
2181
|
-
})
|
|
2182
|
-
] }, s.text)),
|
|
2183
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
2184
|
-
/* @__PURE__ */ jsx(Label, { children: "Same as typing" }),
|
|
2185
|
-
/* @__PURE__ */ jsx(Card, {
|
|
2186
|
-
width: sideW,
|
|
2187
|
-
children: cmdLines.map((l) => /* @__PURE__ */ jsx(Text, {
|
|
2188
|
-
wrap: "wrap",
|
|
2189
|
-
children: l
|
|
2190
|
-
}, l))
|
|
2191
|
-
})
|
|
2192
|
-
]
|
|
2193
|
-
}) : null]
|
|
2194
|
-
});
|
|
2195
|
-
}
|
|
2196
|
-
// src/tui/screens/sessions.tsx
|
|
2197
|
-
var sessions_exports = /* @__PURE__ */ __exportAll({
|
|
2198
|
-
agoText: () => agoText,
|
|
2199
|
-
default: () => Sessions,
|
|
2200
|
-
groupSessions: () => groupSessions,
|
|
2201
|
-
listColumns: () => listColumns,
|
|
2202
|
-
statusWord: () => statusWord
|
|
2203
|
-
});
|
|
2204
|
-
const STATUS_WIDTH = 10;
|
|
2205
|
-
const GAP = 2;
|
|
2206
|
-
/** Column widths for the list. The name takes what it needs, the folder takes the rest. */
|
|
2207
|
-
function listColumns(width, longestName) {
|
|
2208
|
-
const fixed = 24;
|
|
2209
|
-
let name = Math.max(12, Math.min(32, longestName + 1));
|
|
2210
|
-
let folder = width - fixed - name;
|
|
2211
|
-
if (folder < 10) {
|
|
2212
|
-
name = Math.max(8, name - (10 - folder));
|
|
2213
|
-
folder = width - fixed - name;
|
|
2214
|
-
}
|
|
2215
|
-
return {
|
|
2216
|
-
name,
|
|
2217
|
-
folder: Math.max(0, folder)
|
|
2218
|
-
};
|
|
2219
|
-
}
|
|
2220
|
-
/** Letters that are keys on this screen. A word starting with one of them needs `f` first. */
|
|
2221
|
-
const BOUND = /* @__PURE__ */ new Set([
|
|
2222
|
-
"m",
|
|
2223
|
-
"n",
|
|
2224
|
-
"l",
|
|
2225
|
-
"r",
|
|
2226
|
-
"x",
|
|
2227
|
-
"q",
|
|
2228
|
-
"f"
|
|
2229
|
-
]);
|
|
2230
|
-
const quiet = (c) => c.quiet ? { color: c.quiet } : { dimColor: true };
|
|
2231
|
-
/** `working` or `idle`. State is always in the word, never in colour alone. */
|
|
2232
|
-
const statusWord = (s) => s.status === "busy" ? "working" : "idle";
|
|
2233
|
-
/** "41m ago", "just now". */
|
|
2234
|
-
function agoText(iso) {
|
|
2235
|
-
const r = relTime(iso);
|
|
2236
|
-
if (r === "") return "";
|
|
2237
|
-
if (r === "now") return "just now";
|
|
2238
|
-
return r.endsWith("ago") ? r : `${r} ago`;
|
|
2239
|
-
}
|
|
2240
|
-
function matches(s, q) {
|
|
2241
|
-
const needle = q.toLowerCase();
|
|
2242
|
-
return [
|
|
2243
|
-
s.name,
|
|
2244
|
-
s.cwd,
|
|
2245
|
-
s.cli,
|
|
2246
|
-
s.deviceName ?? ""
|
|
2247
|
-
].some((x) => x.toLowerCase().includes(needle));
|
|
2248
|
-
}
|
|
2249
|
-
/** Sessions grouped by machine: this one first, then the others by name. */
|
|
2250
|
-
function groupSessions(sessions) {
|
|
2251
|
-
const byLead = (a, b) => Number(b.isOrchestrator) - Number(a.isOrchestrator) || a.name.localeCompare(b.name);
|
|
2252
|
-
const local = sessions.filter((s) => !s.remote).sort(byLead);
|
|
2253
|
-
const remotes = /* @__PURE__ */ new Map();
|
|
2254
|
-
for (const s of sessions) {
|
|
2255
|
-
if (!s.remote) continue;
|
|
2256
|
-
const k = s.deviceName ?? "OTHER PC";
|
|
2257
|
-
remotes.set(k, [...remotes.get(k) ?? [], s]);
|
|
2258
|
-
}
|
|
2259
|
-
const groups = [];
|
|
2260
|
-
if (local.length > 0) groups.push({
|
|
2261
|
-
title: "THIS PC",
|
|
2262
|
-
synced: false,
|
|
2263
|
-
items: local
|
|
2264
|
-
});
|
|
2265
|
-
for (const k of [...remotes.keys()].sort()) groups.push({
|
|
2266
|
-
title: k.toUpperCase(),
|
|
2267
|
-
synced: true,
|
|
2268
|
-
items: (remotes.get(k) ?? []).sort(byLead)
|
|
2269
|
-
});
|
|
2270
|
-
return groups;
|
|
2271
|
-
}
|
|
2272
|
-
function Sessions(props) {
|
|
2273
|
-
const { state, actions, layout, rows, columns, active, setKeys, setCommands, go, toast, setTyping, claimKeys } = props;
|
|
2274
|
-
const { c, ascii } = useTheme();
|
|
2275
|
-
const wide = layout === "wide";
|
|
2276
|
-
const [selectedId, setSelectedId] = useState(props.focus);
|
|
2277
|
-
const [filter, setFilter] = useState(void 0);
|
|
2278
|
-
const [mode, setMode] = useState(void 0);
|
|
2279
|
-
const [draft, setDraft] = useState("");
|
|
2280
|
-
const sending = useRef(false);
|
|
2281
|
-
const groups = useMemo(() => {
|
|
2282
|
-
const live = state.sessions.filter((s) => s.status !== "offline");
|
|
2283
|
-
return groupSessions(filter ? live.filter((s) => matches(s, filter)) : live);
|
|
2284
|
-
}, [state.sessions, filter]);
|
|
2285
|
-
const flat = useMemo(() => groups.flatMap((g) => g.items), [groups]);
|
|
2286
|
-
const rowsList = useMemo(() => groups.flatMap((g) => [{
|
|
2287
|
-
t: "head",
|
|
2288
|
-
key: `h:${g.title}`,
|
|
2289
|
-
text: `${g.title} · ${g.items.length}`,
|
|
2290
|
-
synced: g.synced
|
|
2291
|
-
}, ...g.items.map((s) => ({
|
|
2292
|
-
t: "session",
|
|
2293
|
-
s
|
|
2294
|
-
}))]), [groups]);
|
|
2295
|
-
const found = flat.findIndex((s) => s.id === selectedId);
|
|
2296
|
-
const selected = flat[Math.max(found, 0)];
|
|
2297
|
-
const selRow = rowsList.findIndex((r) => r.t === "session" && r.s.id === selected?.id);
|
|
2298
|
-
const filtering = filter !== void 0;
|
|
2299
|
-
const taking = mode?.kind === "message" || mode?.kind === "rename";
|
|
2300
|
-
const typing = active && (taking || filtering);
|
|
2301
|
-
useEffect(() => {
|
|
2302
|
-
setTyping(typing);
|
|
2303
|
-
return () => setTyping(false);
|
|
2304
|
-
}, [typing, setTyping]);
|
|
2305
|
-
const asking = active && mode?.kind === "stop";
|
|
2306
|
-
useEffect(() => {
|
|
2307
|
-
claimKeys(asking ? ["y", "n"] : []);
|
|
2308
|
-
return () => claimKeys([]);
|
|
2309
|
-
}, [asking, claimKeys]);
|
|
2310
|
-
useEffect(() => {
|
|
2311
|
-
setKeys(taking ? [{
|
|
2312
|
-
key: "⏎",
|
|
2313
|
-
label: "send"
|
|
2314
|
-
}, {
|
|
2315
|
-
key: "Esc",
|
|
2316
|
-
label: "cancel"
|
|
2317
|
-
}] : [
|
|
2318
|
-
{
|
|
2319
|
-
key: "↑↓",
|
|
2320
|
-
label: "move"
|
|
2321
|
-
},
|
|
2322
|
-
{
|
|
2323
|
-
key: "l",
|
|
2324
|
-
label: "make lead"
|
|
2325
|
-
},
|
|
2326
|
-
{
|
|
2327
|
-
key: "m",
|
|
2328
|
-
label: "message"
|
|
2329
|
-
},
|
|
2330
|
-
{
|
|
2331
|
-
key: "r",
|
|
2332
|
-
label: "rename"
|
|
2333
|
-
},
|
|
2334
|
-
{
|
|
2335
|
-
key: "x",
|
|
2336
|
-
label: "stop"
|
|
2337
|
-
},
|
|
2338
|
-
{
|
|
2339
|
-
key: "n",
|
|
2340
|
-
label: "new"
|
|
2341
|
-
},
|
|
2342
|
-
{
|
|
2343
|
-
key: "f",
|
|
2344
|
-
label: "filter"
|
|
2345
|
-
}
|
|
2346
|
-
]);
|
|
2347
|
-
}, [setKeys, taking]);
|
|
2348
|
-
const local = (s) => {
|
|
2349
|
-
if (!s.remote) return true;
|
|
2350
|
-
toast("That session is on another machine. Change it there.", "warn");
|
|
2351
|
-
return false;
|
|
2352
|
-
};
|
|
2353
|
-
function makeLead(s) {
|
|
2354
|
-
if (!local(s)) return;
|
|
2355
|
-
(s.isOrchestrator ? actions.clearLead() : actions.setLead(s.id)).then(() => toast(s.isOrchestrator ? "No lead now" : `${s.name} is the lead`), () => toast("Couldn't change the lead. Try again.", "error"));
|
|
2356
|
-
}
|
|
2357
|
-
function askStop(s) {
|
|
2358
|
-
if (!local(s)) return;
|
|
2359
|
-
if (!s.spawned) return toast("Conveno didn't start this one. Close it where it runs.", "warn");
|
|
2360
|
-
setMode({
|
|
2361
|
-
kind: "stop",
|
|
2362
|
-
s
|
|
2363
|
-
});
|
|
2364
|
-
}
|
|
2365
|
-
function startText(kind, s) {
|
|
2366
|
-
if (kind === "rename" && !local(s)) return;
|
|
2367
|
-
setDraft(kind === "rename" ? s.name : "");
|
|
2368
|
-
setMode({
|
|
2369
|
-
kind,
|
|
2370
|
-
s
|
|
2371
|
-
});
|
|
2372
|
-
}
|
|
2373
|
-
function stop(s) {
|
|
2374
|
-
actions.stop(s.id).then(() => toast(`Stopped ${s.name}`), (e) => toast(e instanceof Error ? e.message : `Couldn't stop ${s.name}.`, "error"));
|
|
2375
|
-
}
|
|
2376
|
-
function submit(text) {
|
|
2377
|
-
const t = text.trim();
|
|
2378
|
-
if (!mode || t === "" || sending.current) return;
|
|
2379
|
-
const { kind, s } = mode;
|
|
2380
|
-
if (kind === "stop") return;
|
|
2381
|
-
sending.current = true;
|
|
2382
|
-
(kind === "message" ? actions.send(s.name, t) : actions.rename(s.id, t)).then(() => {
|
|
2383
|
-
setMode(void 0);
|
|
2384
|
-
setDraft("");
|
|
2385
|
-
toast(kind === "message" ? s.status === "busy" ? `Sent to ${s.name}. It gets this when it finishes its step.` : `Sent to ${s.name}` : `Renamed to ${t}`);
|
|
2386
|
-
}, (e) => toast(kind === "message" ? "Couldn't send that. Try again." : e instanceof Error ? e.message : "Couldn't rename it. Try again.", "error")).finally(() => {
|
|
2387
|
-
sending.current = false;
|
|
2388
|
-
});
|
|
2389
|
-
}
|
|
2390
|
-
const fn = useRef({
|
|
2391
|
-
makeLead,
|
|
2392
|
-
askStop,
|
|
2393
|
-
startText
|
|
2394
|
-
});
|
|
2395
|
-
fn.current = {
|
|
2396
|
-
makeLead,
|
|
2397
|
-
askStop,
|
|
2398
|
-
startText
|
|
2399
|
-
};
|
|
2400
|
-
useEffect(() => {
|
|
2401
|
-
const cmds = [{
|
|
2402
|
-
id: "sessions-new",
|
|
2403
|
-
label: "Start a new worker",
|
|
2404
|
-
key: "n",
|
|
2405
|
-
run: () => go("new")
|
|
2406
|
-
}];
|
|
2407
|
-
if (selected) {
|
|
2408
|
-
const s = selected;
|
|
2409
|
-
cmds.push({
|
|
2410
|
-
id: "sessions-lead",
|
|
2411
|
-
label: s.isOrchestrator ? "Clear the lead" : `Make ${s.name} the lead`,
|
|
2412
|
-
key: "l",
|
|
2413
|
-
run: () => fn.current.makeLead(s)
|
|
2414
|
-
}, {
|
|
2415
|
-
id: "sessions-message",
|
|
2416
|
-
label: `Message ${s.name}`,
|
|
2417
|
-
key: "m",
|
|
2418
|
-
run: () => fn.current.startText("message", s)
|
|
2419
|
-
}, {
|
|
2420
|
-
id: "sessions-rename",
|
|
2421
|
-
label: `Rename ${s.name}`,
|
|
2422
|
-
key: "r",
|
|
2423
|
-
run: () => fn.current.startText("rename", s)
|
|
2424
|
-
});
|
|
2425
|
-
if (s.spawned && !s.remote) cmds.push({
|
|
2426
|
-
id: "sessions-stop",
|
|
2427
|
-
label: `Stop ${s.name}`,
|
|
2428
|
-
key: "x",
|
|
2429
|
-
run: () => fn.current.askStop(s)
|
|
2430
|
-
});
|
|
2431
|
-
}
|
|
2432
|
-
cmds.push({
|
|
2433
|
-
id: "sessions-filter",
|
|
2434
|
-
label: "Filter sessions",
|
|
2435
|
-
key: "f",
|
|
2436
|
-
run: () => setFilter("")
|
|
2437
|
-
});
|
|
2438
|
-
setCommands(cmds);
|
|
2439
|
-
}, [
|
|
2440
|
-
setCommands,
|
|
2441
|
-
go,
|
|
2442
|
-
selected
|
|
2443
|
-
]);
|
|
2444
|
-
function move(delta) {
|
|
2445
|
-
if (flat.length === 0) return;
|
|
2446
|
-
setSelectedId((prev) => {
|
|
2447
|
-
const at = Math.max(0, flat.findIndex((s) => s.id === prev));
|
|
2448
|
-
return flat[Math.max(0, Math.min(flat.length - 1, at + delta))]?.id;
|
|
2449
|
-
});
|
|
2450
|
-
}
|
|
2451
|
-
useInput((input, key) => {
|
|
2452
|
-
if (mode?.kind === "stop") {
|
|
2453
|
-
if (input === "y") stop(mode.s);
|
|
2454
|
-
setMode(void 0);
|
|
2455
|
-
return;
|
|
2456
|
-
}
|
|
2457
|
-
if (key.upArrow) return move(-1);
|
|
2458
|
-
if (key.downArrow) return move(1);
|
|
2459
|
-
if (filtering) {
|
|
2460
|
-
if (key.escape) return setFilter(void 0);
|
|
2461
|
-
if (key.return) return;
|
|
2462
|
-
if (key.backspace || key.delete) return setFilter(filter && filter.length > 1 ? filter.slice(0, -1) : filter === "" ? void 0 : "");
|
|
2463
|
-
if (input && !key.ctrl && !key.meta && !key.tab) setFilter((f) => (f ?? "") + input);
|
|
2464
|
-
return;
|
|
2465
|
-
}
|
|
2466
|
-
if (key.return) {
|
|
2467
|
-
if (selected) startText("message", selected);
|
|
2468
|
-
return;
|
|
2469
|
-
}
|
|
2470
|
-
if (key.ctrl || key.meta || key.tab || key.escape || input.length !== 1) return;
|
|
2471
|
-
if (input === "m" && selected) return startText("message", selected);
|
|
2472
|
-
if (input === "r" && selected) return startText("rename", selected);
|
|
2473
|
-
if (input === "l" && selected) return makeLead(selected);
|
|
2474
|
-
if (input === "x" && selected) return askStop(selected);
|
|
2475
|
-
if (input === "n") return go("new");
|
|
2476
|
-
if (input === "f") return setFilter("");
|
|
2477
|
-
if (/\p{L}/u.test(input) && !BOUND.has(input.toLowerCase())) setFilter(input);
|
|
2478
|
-
}, { isActive: active && !taking });
|
|
2479
|
-
if (state.sessions.length === 0) return /* @__PURE__ */ jsx(Box, {
|
|
2480
|
-
flexDirection: "column",
|
|
2481
|
-
paddingTop: 1,
|
|
2482
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
2483
|
-
...quiet(c),
|
|
2484
|
-
children: "Nothing is running yet. Open one of your CLIs, or press n to start one."
|
|
2485
|
-
})
|
|
2486
|
-
});
|
|
2487
|
-
const { mainW, panelW } = splitWidths(columns, wide);
|
|
2488
|
-
const listW = wide ? mainW - 2 : columns;
|
|
2489
|
-
const bodyH = Math.max(3, rows - 2);
|
|
2490
|
-
const listH = Math.max(2, bodyH - 1);
|
|
2491
|
-
const dot = ascii ? "*" : "◆";
|
|
2492
|
-
const mid = ascii ? "-" : "·";
|
|
2493
|
-
const { name: nameW, folder: folderW } = listColumns(listW, flat.reduce((n, s) => Math.max(n, [...s.name].length), 0));
|
|
2494
|
-
const clickRow = (s, isSel, double) => {
|
|
2495
|
-
setMode(void 0);
|
|
2496
|
-
setSelectedId(s.id);
|
|
2497
|
-
if (isSel || double) startText("message", s);
|
|
2498
|
-
};
|
|
2499
|
-
const renderRow = (r, isSel) => {
|
|
2500
|
-
if (r.t === "head") return /* @__PURE__ */ jsxs(Box, {
|
|
2501
|
-
width: listW,
|
|
2502
|
-
children: [/* @__PURE__ */ jsx(Label, { children: plain(r.text, ascii) }), r.synced ? /* @__PURE__ */ jsx(Text, {
|
|
2503
|
-
...quiet(c),
|
|
2504
|
-
children: ` synced`
|
|
2505
|
-
}) : null]
|
|
2506
|
-
});
|
|
2507
|
-
const s = r.s;
|
|
2508
|
-
const lead = s.isOrchestrator;
|
|
2509
|
-
return /* @__PURE__ */ jsx(Hit, {
|
|
2510
|
-
onClick: (e) => clickRow(s, isSel, e.double),
|
|
2511
|
-
isActive: active && !taking,
|
|
2512
|
-
children: /* @__PURE__ */ jsxs(Row, {
|
|
2513
|
-
width: listW,
|
|
2514
|
-
selected: isSel,
|
|
2515
|
-
children: [
|
|
2516
|
-
/* @__PURE__ */ jsx(Cell, {
|
|
2517
|
-
w: 2,
|
|
2518
|
-
gap: 0,
|
|
2519
|
-
color: c.entry,
|
|
2520
|
-
children: isSel ? ascii ? "> " : "▸ " : " "
|
|
2521
|
-
}),
|
|
2522
|
-
/* @__PURE__ */ jsx(Cell, {
|
|
2523
|
-
w: 2,
|
|
2524
|
-
gap: 0,
|
|
2525
|
-
color: lead ? c.entry : c.quiet,
|
|
2526
|
-
children: lead ? `${dot} ` : `${mid} `
|
|
2527
|
-
}),
|
|
2528
|
-
/* @__PURE__ */ jsx(Cell, {
|
|
2529
|
-
w: nameW + GAP,
|
|
2530
|
-
bold: isSel,
|
|
2531
|
-
children: s.name
|
|
2532
|
-
}),
|
|
2533
|
-
/* @__PURE__ */ jsx(Box, {
|
|
2534
|
-
width: 6,
|
|
2535
|
-
flexShrink: 0,
|
|
2536
|
-
children: /* @__PURE__ */ jsx(Chip, { cli: s.cli })
|
|
2537
|
-
}),
|
|
2538
|
-
/* @__PURE__ */ jsx(Cell, {
|
|
2539
|
-
w: folderW + GAP,
|
|
2540
|
-
color: c.quiet,
|
|
2541
|
-
children: shortPath$1(s.cwd, folderW - GAP, ascii)
|
|
2542
|
-
}),
|
|
2543
|
-
/* @__PURE__ */ jsx(Cell, {
|
|
2544
|
-
w: STATUS_WIDTH,
|
|
2545
|
-
gap: 0,
|
|
2546
|
-
color: s.status === "busy" ? c.info : c.quiet,
|
|
2547
|
-
children: statusWord(s)
|
|
2548
|
-
})
|
|
2549
|
-
]
|
|
2550
|
-
})
|
|
2551
|
-
});
|
|
2552
|
-
};
|
|
2553
|
-
const list = flat.length === 0 ? /* @__PURE__ */ jsx(Text, {
|
|
2554
|
-
...quiet(c),
|
|
2555
|
-
children: `Nothing matches “${filter}”.`
|
|
2556
|
-
}) : /* @__PURE__ */ jsx(ScrollList, {
|
|
2557
|
-
items: rowsList,
|
|
2558
|
-
selected: Math.max(0, selRow),
|
|
2559
|
-
height: listH,
|
|
2560
|
-
keyOf: (r, i) => r.t === "head" ? r.key : `${r.s.id}:${i}`,
|
|
2561
|
-
renderItem: (r, _sel, i) => renderRow(r, i === selRow)
|
|
2562
|
-
});
|
|
2563
|
-
let bottom;
|
|
2564
|
-
if (mode?.kind === "stop") {
|
|
2565
|
-
const target = mode.s;
|
|
2566
|
-
bottom = /* @__PURE__ */ jsxs(Box, { children: [
|
|
2567
|
-
/* @__PURE__ */ jsx(Text, {
|
|
2568
|
-
bold: true,
|
|
2569
|
-
...c.stamp ? { color: c.stamp } : {},
|
|
2570
|
-
children: `Stop ${target.name}? `
|
|
2571
|
-
}),
|
|
2572
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
2573
|
-
onClick: () => {
|
|
2574
|
-
stop(target);
|
|
2575
|
-
setMode(void 0);
|
|
2576
|
-
},
|
|
2577
|
-
isActive: active,
|
|
2578
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
2579
|
-
bold: true,
|
|
2580
|
-
...c.stamp ? { color: c.stamp } : {},
|
|
2581
|
-
children: "y"
|
|
2582
|
-
})
|
|
2583
|
-
}),
|
|
2584
|
-
/* @__PURE__ */ jsx(Text, {
|
|
2585
|
-
bold: true,
|
|
2586
|
-
...c.stamp ? { color: c.stamp } : {},
|
|
2587
|
-
children: "/"
|
|
2588
|
-
}),
|
|
2589
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
2590
|
-
onClick: () => setMode(void 0),
|
|
2591
|
-
isActive: active,
|
|
2592
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
2593
|
-
bold: true,
|
|
2594
|
-
...c.stamp ? { color: c.stamp } : {},
|
|
2595
|
-
children: "n"
|
|
2596
|
-
})
|
|
2597
|
-
})
|
|
2598
|
-
] });
|
|
2599
|
-
} else if (mode) {
|
|
2600
|
-
const label = mode.kind === "message" ? `Message ${mode.s.name}` : `Rename ${mode.s.name} to`;
|
|
2601
|
-
bottom = /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Text, {
|
|
2602
|
-
...quiet(c),
|
|
2603
|
-
children: `${label} `
|
|
2604
|
-
}), /* @__PURE__ */ jsx(Box, {
|
|
2605
|
-
flexGrow: 1,
|
|
2606
|
-
children: /* @__PURE__ */ jsx(TextBox, {
|
|
2607
|
-
value: draft,
|
|
2608
|
-
onChange: setDraft,
|
|
2609
|
-
onSubmit: submit,
|
|
2610
|
-
onCancel: () => {
|
|
2611
|
-
setMode(void 0);
|
|
2612
|
-
setDraft("");
|
|
2613
|
-
},
|
|
2614
|
-
focus: active,
|
|
2615
|
-
placeholder: mode.kind === "message" ? "Type, then Enter" : "A new name"
|
|
2616
|
-
})
|
|
2617
|
-
})] });
|
|
2618
|
-
} else if (filtering) bottom = /* @__PURE__ */ jsxs(Text, { children: [
|
|
2619
|
-
/* @__PURE__ */ jsx(Text, {
|
|
2620
|
-
...quiet(c),
|
|
2621
|
-
children: "Filter "
|
|
2622
|
-
}),
|
|
2623
|
-
/* @__PURE__ */ jsx(Text, {
|
|
2624
|
-
bold: true,
|
|
2625
|
-
children: filter
|
|
2626
|
-
}),
|
|
2627
|
-
/* @__PURE__ */ jsx(Text, {
|
|
2628
|
-
inverse: true,
|
|
2629
|
-
children: " "
|
|
2630
|
-
}),
|
|
2631
|
-
/* @__PURE__ */ jsx(Text, {
|
|
2632
|
-
...quiet(c),
|
|
2633
|
-
children: ` Esc clears`
|
|
2634
|
-
})
|
|
2635
|
-
] });
|
|
2636
|
-
else {
|
|
2637
|
-
const variants = [
|
|
2638
|
-
`${dot} lead working = busy right now idle = ready for a message type to filter`,
|
|
2639
|
-
`${dot} lead working = busy type to filter`,
|
|
2640
|
-
`${dot} lead type to filter`
|
|
2641
|
-
];
|
|
2642
|
-
const legend = variants.find((v) => [...v].length <= columns) ?? variants[2] ?? "";
|
|
2643
|
-
const tail = "type to filter";
|
|
2644
|
-
const head = legend.endsWith(tail) ? legend.slice(0, -14) : legend;
|
|
2645
|
-
bottom = /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Ell, {
|
|
2646
|
-
width: Math.min([...head].length, Math.max(0, columns - 14)),
|
|
2647
|
-
color: c.quiet,
|
|
2648
|
-
children: head
|
|
2649
|
-
}), legend.endsWith(tail) ? /* @__PURE__ */ jsx(Hit, {
|
|
2650
|
-
onClick: () => setFilter((f) => f ?? ""),
|
|
2651
|
-
isActive: active,
|
|
2652
|
-
children: /* @__PURE__ */ jsx(Ell, {
|
|
2653
|
-
width: 14,
|
|
2654
|
-
color: c.quiet,
|
|
2655
|
-
children: tail
|
|
2656
|
-
})
|
|
2657
|
-
}) : null] });
|
|
2658
|
-
}
|
|
2659
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
2660
|
-
flexDirection: "column",
|
|
2661
|
-
width: columns,
|
|
2662
|
-
children: [
|
|
2663
|
-
/* @__PURE__ */ jsxs(Box, {
|
|
2664
|
-
height: bodyH,
|
|
2665
|
-
children: [/* @__PURE__ */ jsxs(Hit, {
|
|
2666
|
-
flexDirection: "column",
|
|
2667
|
-
width: wide ? mainW : columns,
|
|
2668
|
-
flexShrink: 0,
|
|
2669
|
-
onWheel: (d) => move(d < 0 ? -1 : 1),
|
|
2670
|
-
isActive: active,
|
|
2671
|
-
children: [/* @__PURE__ */ jsx(HeaderRow, {
|
|
2672
|
-
width: listW,
|
|
2673
|
-
cols: [
|
|
2674
|
-
{
|
|
2675
|
-
w: 4,
|
|
2676
|
-
text: "",
|
|
2677
|
-
gap: 0
|
|
2678
|
-
},
|
|
2679
|
-
{
|
|
2680
|
-
w: nameW + GAP,
|
|
2681
|
-
text: "Name"
|
|
2682
|
-
},
|
|
2683
|
-
{
|
|
2684
|
-
w: 6,
|
|
2685
|
-
text: "CLI"
|
|
2686
|
-
},
|
|
2687
|
-
{
|
|
2688
|
-
w: folderW + GAP,
|
|
2689
|
-
text: "Folder"
|
|
2690
|
-
},
|
|
2691
|
-
{
|
|
2692
|
-
w: STATUS_WIDTH,
|
|
2693
|
-
text: "Status",
|
|
2694
|
-
gap: 0
|
|
2695
|
-
}
|
|
2696
|
-
]
|
|
2697
|
-
}), list]
|
|
2698
|
-
}), wide ? /* @__PURE__ */ jsx(Pane, {
|
|
2699
|
-
width: panelW,
|
|
2700
|
-
height: bodyH,
|
|
2701
|
-
children: selected ? /* @__PURE__ */ jsx(SidePanel, {
|
|
2702
|
-
session: selected,
|
|
2703
|
-
width: paneInner(panelW)
|
|
2704
|
-
}) : null
|
|
2705
|
-
}) : null]
|
|
2706
|
-
}),
|
|
2707
|
-
/* @__PURE__ */ jsx(Box, {
|
|
2708
|
-
marginLeft: -1,
|
|
2709
|
-
children: /* @__PURE__ */ jsx(Rule, { width: columns + 1 })
|
|
2710
|
-
}),
|
|
2711
|
-
/* @__PURE__ */ jsx(Box, {
|
|
2712
|
-
height: 1,
|
|
2713
|
-
children: bottom
|
|
2714
|
-
})
|
|
2715
|
-
]
|
|
2716
|
-
});
|
|
2717
|
-
}
|
|
2718
|
-
function SidePanel({ session, width }) {
|
|
2719
|
-
const { c, ascii } = useTheme();
|
|
2720
|
-
const role = session.isOrchestrator ? "lead" : "worker";
|
|
2721
|
-
const sep = ascii ? "-" : "·";
|
|
2722
|
-
const started = `started ${agoText(session.startedAt)}`;
|
|
2723
|
-
const whole = `${role} ${sep} ${shortPath$1(session.cwd, 200, ascii)} ${sep} ${started}`;
|
|
2724
|
-
const sub = [...whole].length <= width ? [whole] : [`${role} ${sep} ${started}`, shortPath$1(session.cwd, width, ascii)];
|
|
2725
|
-
const status = session.statusText ?? "No update yet.";
|
|
2726
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
2727
|
-
flexDirection: "column",
|
|
2728
|
-
width,
|
|
2729
|
-
children: [
|
|
2730
|
-
/* @__PURE__ */ jsxs(Box, { children: [
|
|
2731
|
-
/* @__PURE__ */ jsx(Ell, {
|
|
2732
|
-
width: width - 4 - 1,
|
|
2733
|
-
bold: true,
|
|
2734
|
-
children: session.name
|
|
2735
|
-
}),
|
|
2736
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
2737
|
-
/* @__PURE__ */ jsx(Chip, { cli: session.cli })
|
|
2738
|
-
] }),
|
|
2739
|
-
sub.map((l) => /* @__PURE__ */ jsx(Ell, {
|
|
2740
|
-
width,
|
|
2741
|
-
color: c.quiet,
|
|
2742
|
-
children: l
|
|
2743
|
-
}, l)),
|
|
2744
|
-
/* @__PURE__ */ jsx(Box, {
|
|
2745
|
-
marginTop: 1,
|
|
2746
|
-
children: /* @__PURE__ */ jsx(Label, { children: "Right now" })
|
|
2747
|
-
}),
|
|
2748
|
-
/* @__PURE__ */ jsx(Text, {
|
|
2749
|
-
wrap: "truncate-end",
|
|
2750
|
-
children: status
|
|
2751
|
-
})
|
|
2752
|
-
]
|
|
2753
|
-
});
|
|
2754
|
-
}
|
|
2755
|
-
// src/tui/setup-data.ts
|
|
2756
|
-
/**
|
|
2757
|
-
* What the Setup screen reads and does. Same facts as `conveno doctor`, in plain words, and the
|
|
2758
|
-
* same code path as `conveno init` / `conveno uninstall` for changing files.
|
|
2759
|
-
*
|
|
2760
|
-
* No Ink or React in here: the store imports it.
|
|
2761
|
-
*/
|
|
2762
|
-
const ready = (r) => r.mcp === "ok" && (r.hooks === null || r.hooks === "ok");
|
|
2763
|
-
/** One CLI's row, from what `conveno doctor` found. Exported for tests. */
|
|
2764
|
-
function checkFromRow(r, compat) {
|
|
2765
|
-
const { adapter, detection } = r;
|
|
2766
|
-
const base = {
|
|
2767
|
-
cli: adapter.cli,
|
|
2768
|
-
label: adapter.displayName
|
|
2769
|
-
};
|
|
2770
|
-
const version = detection.version;
|
|
2771
|
-
const withVersion = version ? { version } : {};
|
|
2772
|
-
if (!detection.installed) return {
|
|
2773
|
-
...base,
|
|
2774
|
-
status: "not-installed",
|
|
2775
|
-
note: "install it, then press g"
|
|
2776
|
-
};
|
|
2777
|
-
const c = compatStatus(adapter.cli, version, compat);
|
|
2778
|
-
if (r.planError) return {
|
|
2779
|
-
...base,
|
|
2780
|
-
...withVersion,
|
|
2781
|
-
status: "blocked",
|
|
2782
|
-
note: "we can't read its settings file"
|
|
2783
|
-
};
|
|
2784
|
-
if (c.kind === "older") return {
|
|
2785
|
-
...base,
|
|
2786
|
-
...withVersion,
|
|
2787
|
-
status: "blocked",
|
|
2788
|
-
note: `too old, update it first (needs ${c.minimum} or newer)`
|
|
2789
|
-
};
|
|
2790
|
-
if (ready(r)) return {
|
|
2791
|
-
...base,
|
|
2792
|
-
...withVersion,
|
|
2793
|
-
status: "ready",
|
|
2794
|
-
...c.kind === "newer" && c.minor ? { note: "a bit newer than we tested, should be fine" } : {}
|
|
2795
|
-
};
|
|
2796
|
-
const allMissing = [r.mcp, r.hooks].filter((p) => p !== null).every((p) => p === "missing");
|
|
2797
|
-
return {
|
|
2798
|
-
...base,
|
|
2799
|
-
...withVersion,
|
|
2800
|
-
status: allMissing ? "not-set-up" : "needs-update",
|
|
2801
|
-
note: "press ⏎ to fix"
|
|
2802
|
-
};
|
|
2803
|
-
}
|
|
2804
|
-
/** The checkup list. Exported for tests. */
|
|
2805
|
-
function healthFrom(input) {
|
|
2806
|
-
const out = [];
|
|
2807
|
-
out.push(input.daemon === "running" ? {
|
|
2808
|
-
level: "ok",
|
|
2809
|
-
text: "Conveno is running"
|
|
2810
|
-
} : input.daemon === "stopped" ? {
|
|
2811
|
-
level: "warn",
|
|
2812
|
-
text: "Conveno is not running yet. It starts with your first session."
|
|
2813
|
-
} : {
|
|
2814
|
-
level: "error",
|
|
2815
|
-
text: "Conveno can't be reached"
|
|
2816
|
-
});
|
|
2817
|
-
const installed = input.clis.filter((c) => c.status !== "not-installed");
|
|
2818
|
-
const good = installed.filter((c) => c.status === "ready").length;
|
|
2819
|
-
out.push(installed.length === 0 ? {
|
|
2820
|
-
level: "warn",
|
|
2821
|
-
text: "No supported CLI found on this machine"
|
|
2822
|
-
} : {
|
|
2823
|
-
level: good === installed.length ? "ok" : "info",
|
|
2824
|
-
text: `${good} of ${installed.length} CLIs ready`
|
|
2825
|
-
});
|
|
2826
|
-
let fixes = 0;
|
|
2827
|
-
for (const c of installed) if (c.status === "needs-update") {
|
|
2828
|
-
fixes++;
|
|
2829
|
-
out.push({
|
|
2830
|
-
level: "warn",
|
|
2831
|
-
text: `${c.label} needs an update`,
|
|
2832
|
-
fixId: `init:${c.cli}`
|
|
2833
|
-
});
|
|
2834
|
-
} else if (c.status === "not-set-up") {
|
|
2835
|
-
fixes++;
|
|
2836
|
-
out.push({
|
|
2837
|
-
level: "warn",
|
|
2838
|
-
text: `${c.label} is not set up yet`,
|
|
2839
|
-
fixId: `init:${c.cli}`
|
|
2840
|
-
});
|
|
2841
|
-
} else if (c.status === "blocked") out.push({
|
|
2842
|
-
level: "error",
|
|
2843
|
-
text: `${c.label} is blocked: ${c.note ?? "see Setup"}`
|
|
2844
|
-
});
|
|
2845
|
-
if (input.sync === "online") out.push({
|
|
2846
|
-
level: "ok",
|
|
2847
|
-
text: "Sync is online"
|
|
2848
|
-
});
|
|
2849
|
-
else if (input.sync === "offline") out.push({
|
|
2850
|
-
level: "warn",
|
|
2851
|
-
text: "Sync is offline, it keeps trying"
|
|
2852
|
-
});
|
|
2853
|
-
if (fixes === 0) out.push({
|
|
2854
|
-
level: "ok",
|
|
2855
|
-
text: "Up to date"
|
|
2856
|
-
});
|
|
2857
|
-
return out;
|
|
2858
|
-
}
|
|
2859
|
-
/** The same facts as `conveno doctor`, as friendly rows. Never throws. */
|
|
2860
|
-
async function loadSetup(ctx) {
|
|
2861
|
-
const clis = (await Promise.all(ctx.adapters.map((a) => inspect(ctx, a)))).map((r) => checkFromRow(r, ctx.compat));
|
|
2862
|
-
let daemon = "stopped";
|
|
2863
|
-
let sync;
|
|
2864
|
-
try {
|
|
2865
|
-
const client = await ctx.connect(connectOpts(ctx, false));
|
|
2866
|
-
try {
|
|
2867
|
-
await client["session.list"]({});
|
|
2868
|
-
daemon = "running";
|
|
2869
|
-
const relay = await client["relay.status"]({}).catch(() => void 0);
|
|
2870
|
-
if (relay) {
|
|
2871
|
-
if (relay.state === "connected") sync = "online";
|
|
2872
|
-
else if (relay.state === "connecting" || relay.state === "disconnected") sync = "offline";
|
|
2873
|
-
}
|
|
2874
|
-
} finally {
|
|
2875
|
-
await client.close().catch(() => void 0);
|
|
2876
|
-
}
|
|
2877
|
-
} catch (e) {
|
|
2878
|
-
daemon = daemonProblem(ctx.theme, e).notRunning ? "stopped" : "unreachable";
|
|
2879
|
-
}
|
|
2880
|
-
return {
|
|
2881
|
-
clis,
|
|
2882
|
-
health: healthFrom({
|
|
2883
|
-
daemon,
|
|
2884
|
-
...sync ? { sync } : {},
|
|
2885
|
-
clis
|
|
2886
|
-
})
|
|
2887
|
-
};
|
|
2888
|
-
}
|
|
2889
|
-
function parseFixId(fixId) {
|
|
2890
|
-
const [kind, cli, accept] = fixId.split(":");
|
|
2891
|
-
const ids = accept ? accept.split(",").filter(Boolean) : [];
|
|
2892
|
-
if (kind === "init" && cli) return {
|
|
2893
|
-
kind,
|
|
2894
|
-
cli,
|
|
2895
|
-
accept: ids
|
|
2896
|
-
};
|
|
2897
|
-
if (kind === "uninstall" && cli) return {
|
|
2898
|
-
kind,
|
|
2899
|
-
cli,
|
|
2900
|
-
accept: []
|
|
2901
|
-
};
|
|
2902
|
-
}
|
|
2903
|
-
/** The fix id that says yes to these optional setups. */
|
|
2904
|
-
const fixIdWith = (cli, accept) => accept.length > 0 ? `init:${cli}:${accept.join(",")}` : `init:${cli}`;
|
|
2905
|
-
async function planFor(ctx, fixId) {
|
|
2906
|
-
const parsed = parseFixId(fixId);
|
|
2907
|
-
if (!parsed) return {
|
|
2908
|
-
items: [],
|
|
2909
|
-
error: "We don't know that fix."
|
|
2910
|
-
};
|
|
2911
|
-
const a = ctx.adapters.find((x) => x.cli === parsed.cli);
|
|
2912
|
-
if (!a) return {
|
|
2913
|
-
items: [],
|
|
2914
|
-
error: "We don't know that CLI."
|
|
2915
|
-
};
|
|
2916
|
-
const adapters = [a];
|
|
2917
|
-
const env = adapterEnv(ctx);
|
|
2918
|
-
const found = [];
|
|
2919
|
-
for (const adapter of adapters) {
|
|
2920
|
-
const detection = await adapter.detect(env).catch(() => ({
|
|
2921
|
-
installed: false,
|
|
2922
|
-
configPaths: []
|
|
2923
|
-
}));
|
|
2924
|
-
if (detection.installed) found.push({
|
|
2925
|
-
adapter,
|
|
2926
|
-
detection
|
|
2927
|
-
});
|
|
2928
|
-
}
|
|
2929
|
-
if (found.length === 0) return {
|
|
2930
|
-
items: [],
|
|
2931
|
-
error: "It isn't installed."
|
|
2932
|
-
};
|
|
2933
|
-
const { items, failures } = await collectPlans(ctx, found, parsed.kind === "init" ? "plan" : "uninstallPlan", void 0, parsed.accept);
|
|
2934
|
-
return {
|
|
2935
|
-
items,
|
|
2936
|
-
...failures[0] ? { error: failures[0].message } : {}
|
|
2937
|
-
};
|
|
2938
|
-
}
|
|
2939
|
-
/** Cap on diff lines kept per file, so one big file cannot fill the overlay. */
|
|
2940
|
-
const MAX_DIFF_LINES = 60;
|
|
2941
|
-
/** What `applyFix` would change, without changing anything. */
|
|
2942
|
-
async function planFix(ctx, fixId) {
|
|
2943
|
-
const { items, error } = await planFor(ctx, fixId);
|
|
2944
|
-
const parsed = parseFixId(fixId);
|
|
2945
|
-
const adapter = parsed && ctx.adapters.find((x) => x.cli === parsed.cli);
|
|
2946
|
-
const options = parsed?.kind === "init" && adapter ? await pendingOptions(ctx, [adapter]) : [];
|
|
2947
|
-
return {
|
|
2948
|
-
files: items.map(({ change }) => {
|
|
2949
|
-
const lines = unifiedDiff(change.before, change.after);
|
|
2950
|
-
return {
|
|
2951
|
-
path: tilde(change.path, ctx.home),
|
|
2952
|
-
isNew: change.before === null,
|
|
2953
|
-
deleted: Boolean(change.deleteFile),
|
|
2954
|
-
summary: change.description,
|
|
2955
|
-
lines: lines.length > MAX_DIFF_LINES ? lines.slice(0, MAX_DIFF_LINES) : lines
|
|
2956
|
-
};
|
|
2957
|
-
}),
|
|
2958
|
-
...options.length > 0 ? { options } : {},
|
|
2959
|
-
...error ? { error } : {}
|
|
2960
|
-
};
|
|
2961
|
-
}
|
|
2962
|
-
/**
|
|
2963
|
-
* Make the change `planFix` showed: back up each file, then write. Same code path as
|
|
2964
|
-
* `conveno init` (and `conveno uninstall` without a backup on record). Throws a friendly error.
|
|
2965
|
-
*/
|
|
2966
|
-
async function applyFix(ctx, fixId) {
|
|
2967
|
-
const { items, error } = await planFor(ctx, fixId);
|
|
2968
|
-
if (error) throw new Error(error);
|
|
2969
|
-
if (items.length === 0) return;
|
|
2970
|
-
try {
|
|
2971
|
-
await applyChanges(ctx, items, parseFixId(fixId)?.kind === "uninstall" ? { markRestored: true } : {});
|
|
2972
|
-
} catch (e) {
|
|
2973
|
-
if (e instanceof StaleError) throw new Error("A settings file changed while we waited. Press g, then try again.");
|
|
2974
|
-
throw new Error(plainError(e));
|
|
2975
|
-
}
|
|
2976
|
-
}
|
|
2977
|
-
async function getExtras(ctx) {
|
|
2978
|
-
return { helpers: readSettings(dataPaths(ctx.platform, ctx.dataDir).settings).acpAdapterNpx === true };
|
|
2979
|
-
}
|
|
2980
|
-
/** Same answer as `conveno init --acp-adapters` / `--no-acp-adapters`. */
|
|
2981
|
-
function setHelpers(ctx, on) {
|
|
2982
|
-
writeSettings(dataPaths(ctx.platform, ctx.dataDir).settings, { acpAdapterNpx: on });
|
|
2983
|
-
}
|
|
2984
|
-
// src/tui/screens/setup.tsx
|
|
2985
|
-
/** Screen 4: Setup. Your CLIs, extras and the checkup. */
|
|
2986
|
-
var setup_exports = /* @__PURE__ */ __exportAll({
|
|
2987
|
-
default: () => SetupScreen,
|
|
2988
|
-
idsFor: () => idsFor,
|
|
2989
|
-
idsWithOptions: () => idsWithOptions
|
|
2990
|
-
});
|
|
2991
|
-
const STATUS_WORD = {
|
|
2992
|
-
ready: "ready",
|
|
2993
|
-
"needs-update": "needs update",
|
|
2994
|
-
"not-set-up": "not set up",
|
|
2995
|
-
blocked: "blocked",
|
|
2996
|
-
"not-installed": "not installed"
|
|
2997
|
-
};
|
|
2998
|
-
/** `init:<cli>` ids with the ticked options for that CLI added. */
|
|
2999
|
-
function idsWithOptions(ids, options, accepted) {
|
|
3000
|
-
return ids.map((id) => {
|
|
3001
|
-
const cli = id.startsWith("init:") ? id.slice(5) : void 0;
|
|
3002
|
-
if (!cli) return id;
|
|
3003
|
-
return fixIdWith(cli, options.filter((o) => o.cli === cli && accepted.includes(o.id)).map((o) => o.id));
|
|
3004
|
-
});
|
|
3005
|
-
}
|
|
3006
|
-
/** `init:<cli>` ids for the picked rows, or the row under the cursor. Pure, for tests. */
|
|
3007
|
-
function idsFor(clis, picked, cursorCli) {
|
|
3008
|
-
const wanted = picked.size > 0 ? clis.filter((c) => picked.has(c.cli)) : clis.filter((c) => c.cli === cursorCli);
|
|
3009
|
-
const ids = wanted.filter((c) => c.status !== "not-installed" && c.status !== "blocked").map((c) => `init:${c.cli}`);
|
|
3010
|
-
if (ids.length > 0) return {
|
|
3011
|
-
ids,
|
|
3012
|
-
skipped: void 0
|
|
3013
|
-
};
|
|
3014
|
-
const first = wanted[0];
|
|
3015
|
-
if (!first) return {
|
|
3016
|
-
ids,
|
|
3017
|
-
skipped: "Nothing to set up here."
|
|
3018
|
-
};
|
|
3019
|
-
return {
|
|
3020
|
-
ids,
|
|
3021
|
-
skipped: first.status === "not-installed" ? `Install ${first.label} first, then press g.` : `${first.label} is blocked: ${first.note ?? "see the note"}.`
|
|
3022
|
-
};
|
|
3023
|
-
}
|
|
3024
|
-
function HealthLine({ item, width }) {
|
|
3025
|
-
const { c } = useTheme();
|
|
3026
|
-
const m = useMarks();
|
|
3027
|
-
const mark = item.level === "ok" ? m.ok : item.level === "warn" ? m.warn : item.level === "error" ? m.error : m.info;
|
|
3028
|
-
const color = item.level === "ok" ? c.ok : item.level === "warn" ? c.warn : item.level === "error" ? c.error : c.quiet;
|
|
3029
|
-
return /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Text, {
|
|
3030
|
-
...color ? { color } : {},
|
|
3031
|
-
children: `${mark} `
|
|
3032
|
-
}), /* @__PURE__ */ jsx(Ell, {
|
|
3033
|
-
width: width - 2,
|
|
3034
|
-
children: item.text
|
|
3035
|
-
})] });
|
|
3036
|
-
}
|
|
3037
|
-
function ReviewBox({ review, rows, width, active, onYes, onNo, onScroll }) {
|
|
3038
|
-
const { c } = useTheme();
|
|
3039
|
-
const body = [];
|
|
3040
|
-
for (const f of review.files) {
|
|
3041
|
-
body.push({
|
|
3042
|
-
text: `${f.path}${f.isNew ? " (new file)" : f.deleted ? " (deleted)" : ""}`,
|
|
3043
|
-
kind: "path"
|
|
3044
|
-
});
|
|
3045
|
-
body.push({
|
|
3046
|
-
text: f.summary,
|
|
3047
|
-
kind: "note"
|
|
3048
|
-
});
|
|
3049
|
-
for (const l of f.lines) body.push({
|
|
3050
|
-
text: l,
|
|
3051
|
-
kind: l.startsWith("@@") ? "hunk" : l.startsWith("+") ? "add" : l.startsWith("-") ? "del" : "plain"
|
|
3052
|
-
});
|
|
3053
|
-
body.push({
|
|
3054
|
-
text: "",
|
|
3055
|
-
kind: "plain"
|
|
3056
|
-
});
|
|
3057
|
-
}
|
|
3058
|
-
const room = Math.max(3, rows - 8);
|
|
3059
|
-
const start = Math.min(review.scroll, Math.max(0, body.length - room));
|
|
3060
|
-
const shown = body.map((l, id) => ({
|
|
3061
|
-
...l,
|
|
3062
|
-
id
|
|
3063
|
-
})).slice(start, start + room);
|
|
3064
|
-
const hidden = body.length - start - shown.length;
|
|
3065
|
-
const inner = width - 4;
|
|
3066
|
-
return /* @__PURE__ */ jsx(Hit, {
|
|
3067
|
-
onWheel: (d) => onScroll(d < 0 ? -1 : 1),
|
|
3068
|
-
isActive: active,
|
|
3069
|
-
children: /* @__PURE__ */ jsxs(Card, {
|
|
3070
|
-
accent: c.warn,
|
|
3071
|
-
width,
|
|
3072
|
-
children: [
|
|
3073
|
-
/* @__PURE__ */ jsx(Text, {
|
|
3074
|
-
bold: true,
|
|
3075
|
-
children: review.title
|
|
3076
|
-
}),
|
|
3077
|
-
review.error ? /* @__PURE__ */ jsx(Text, {
|
|
3078
|
-
...c.error ? { color: c.error } : {},
|
|
3079
|
-
children: `We can't plan this: ${review.error}`
|
|
3080
|
-
}) : review.files.length === 0 ? /* @__PURE__ */ jsx(Text, { children: "Nothing to change. It is already how it should be." }) : /* @__PURE__ */ jsxs(Box, {
|
|
3081
|
-
flexDirection: "column",
|
|
3082
|
-
children: [shown.map((l) => /* @__PURE__ */ jsx(Ell, {
|
|
3083
|
-
width: inner,
|
|
3084
|
-
bold: l.kind === "path",
|
|
3085
|
-
dim: l.kind === "note" || l.kind === "hunk",
|
|
3086
|
-
color: l.kind === "add" ? c.ok : l.kind === "del" ? c.error : void 0,
|
|
3087
|
-
children: l.text === "" ? " " : l.text
|
|
3088
|
-
}, l.id)), hidden > 0 ? /* @__PURE__ */ jsx(Text, {
|
|
3089
|
-
dimColor: true,
|
|
3090
|
-
children: `… ${hidden} more lines (↑↓ to scroll)`
|
|
3091
|
-
}) : null]
|
|
3092
|
-
}),
|
|
3093
|
-
review.options.length > 0 ? /* @__PURE__ */ jsx(Text, { children: " " }) : null,
|
|
3094
|
-
review.options.map((o, i) => /* @__PURE__ */ jsx(Ell, {
|
|
3095
|
-
width: inner,
|
|
3096
|
-
children: `${review.accepted.includes(o.id) ? "[x]" : "[ ]"} ${i + 1} ${o.question}`
|
|
3097
|
-
}, o.id)),
|
|
3098
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
3099
|
-
review.busy ? /* @__PURE__ */ jsx(Text, { children: "Working…" }) : review.error || review.files.length === 0 ? /* @__PURE__ */ jsx(Hit, {
|
|
3100
|
-
onClick: onNo,
|
|
3101
|
-
isActive: active,
|
|
3102
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
3103
|
-
dimColor: true,
|
|
3104
|
-
children: "Press n or Esc to close."
|
|
3105
|
-
})
|
|
3106
|
-
}) : /* @__PURE__ */ jsxs(Box, { children: [
|
|
3107
|
-
/* @__PURE__ */ jsx(Text, {
|
|
3108
|
-
bold: true,
|
|
3109
|
-
children: "Apply? "
|
|
3110
|
-
}),
|
|
3111
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
3112
|
-
onClick: onYes,
|
|
3113
|
-
isActive: active,
|
|
3114
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
3115
|
-
bold: true,
|
|
3116
|
-
children: "y"
|
|
3117
|
-
})
|
|
3118
|
-
}),
|
|
3119
|
-
/* @__PURE__ */ jsx(Text, {
|
|
3120
|
-
bold: true,
|
|
3121
|
-
children: "/"
|
|
3122
|
-
}),
|
|
3123
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
3124
|
-
onClick: onNo,
|
|
3125
|
-
isActive: active,
|
|
3126
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
3127
|
-
bold: true,
|
|
3128
|
-
children: "n"
|
|
3129
|
-
})
|
|
3130
|
-
}),
|
|
3131
|
-
/* @__PURE__ */ jsx(Text, {
|
|
3132
|
-
dimColor: true,
|
|
3133
|
-
children: " We back up each file first."
|
|
3134
|
-
})
|
|
3135
|
-
] })
|
|
3136
|
-
]
|
|
3137
|
-
})
|
|
3138
|
-
});
|
|
3139
|
-
}
|
|
3140
|
-
function SetupScreen(props) {
|
|
3141
|
-
const { state, actions, layout, rows, columns, active, setKeys, setCommands, toast, go } = props;
|
|
3142
|
-
const { c, ascii } = useTheme();
|
|
3143
|
-
const m = useMarks();
|
|
3144
|
-
const clis = state.setup?.clis ?? [];
|
|
3145
|
-
const health = state.setup?.health ?? [];
|
|
3146
|
-
const [cursor, setCursor] = useState(0);
|
|
3147
|
-
const [picked, setPicked] = useState(/* @__PURE__ */ new Set());
|
|
3148
|
-
const [review, setReview] = useState();
|
|
3149
|
-
const [extras, setExtras] = useState({ helpers: false });
|
|
3150
|
-
const mouse = useMouseControl();
|
|
3151
|
-
const mouseOn = mouse.enabled;
|
|
3152
|
-
const asked = useRef(false);
|
|
3153
|
-
const total = clis.length + 2;
|
|
3154
|
-
const at = Math.min(cursor, Math.max(0, total - 1));
|
|
3155
|
-
const onCli = at < clis.length ? clis[at] : void 0;
|
|
3156
|
-
const extraRow = at >= clis.length ? at - clis.length : -1;
|
|
3157
|
-
const loadExtras = useCallback(() => {
|
|
3158
|
-
actions.getExtras().then(setExtras).catch(() => void 0);
|
|
3159
|
-
}, [actions]);
|
|
3160
|
-
const refresh = useCallback(async () => {
|
|
3161
|
-
try {
|
|
3162
|
-
await actions.refreshSetup();
|
|
3163
|
-
loadExtras();
|
|
3164
|
-
} catch {
|
|
3165
|
-
toast("Could not check your CLIs. Try g again.", "error");
|
|
3166
|
-
}
|
|
3167
|
-
}, [
|
|
3168
|
-
actions,
|
|
3169
|
-
loadExtras,
|
|
3170
|
-
toast
|
|
3171
|
-
]);
|
|
3172
|
-
useEffect(() => {
|
|
3173
|
-
if (asked.current) return;
|
|
3174
|
-
asked.current = true;
|
|
3175
|
-
if (!state.setup) refresh();
|
|
3176
|
-
else loadExtras();
|
|
3177
|
-
}, [
|
|
3178
|
-
state.setup,
|
|
3179
|
-
refresh,
|
|
3180
|
-
loadExtras
|
|
3181
|
-
]);
|
|
3182
|
-
const preset = useRef(false);
|
|
3183
|
-
useEffect(() => {
|
|
3184
|
-
if (preset.current || !state.setup || state.setup.clis.length === 0) return;
|
|
3185
|
-
preset.current = true;
|
|
3186
|
-
const all = state.setup.clis;
|
|
3187
|
-
if (all.some((x) => x.status === "ready")) return;
|
|
3188
|
-
setPicked(new Set(all.filter((x) => x.status === "not-set-up" || x.status === "needs-update").map((x) => x.cli)));
|
|
3189
|
-
}, [state.setup]);
|
|
3190
|
-
const open = useCallback(async (ids, title, options = [], accepted = []) => {
|
|
3191
|
-
setReview({
|
|
3192
|
-
title,
|
|
3193
|
-
ids,
|
|
3194
|
-
files: [],
|
|
3195
|
-
options,
|
|
3196
|
-
accepted,
|
|
3197
|
-
scroll: 0,
|
|
3198
|
-
busy: true
|
|
3199
|
-
});
|
|
3200
|
-
const files = [];
|
|
3201
|
-
const found = new Map(options.map((o) => [o.id, o]));
|
|
3202
|
-
let error;
|
|
3203
|
-
for (const id of idsWithOptions(ids, options, accepted)) {
|
|
3204
|
-
const plan = await actions.planFix(id).catch((e) => ({
|
|
3205
|
-
files: [],
|
|
3206
|
-
options: [],
|
|
3207
|
-
error: e instanceof Error ? e.message : String(e)
|
|
3208
|
-
}));
|
|
3209
|
-
files.push(...plan.files);
|
|
3210
|
-
for (const o of plan.options ?? []) found.set(o.id, o);
|
|
3211
|
-
error ??= plan.error;
|
|
3212
|
-
}
|
|
3213
|
-
setReview({
|
|
3214
|
-
title,
|
|
3215
|
-
ids,
|
|
3216
|
-
files,
|
|
3217
|
-
options: [...found.values()],
|
|
3218
|
-
accepted,
|
|
3219
|
-
...error ? { error } : {},
|
|
3220
|
-
scroll: 0,
|
|
3221
|
-
busy: false
|
|
3222
|
-
});
|
|
3223
|
-
}, [actions]);
|
|
3224
|
-
const toggleOption = useCallback((n) => {
|
|
3225
|
-
if (!review || review.busy) return;
|
|
3226
|
-
const o = review.options[n];
|
|
3227
|
-
if (!o) return;
|
|
3228
|
-
const accepted = review.accepted.includes(o.id) ? review.accepted.filter((x) => x !== o.id) : [...review.accepted, o.id];
|
|
3229
|
-
open(review.ids, review.title, review.options, accepted);
|
|
3230
|
-
}, [review, open]);
|
|
3231
|
-
const setUp = useCallback((target) => {
|
|
3232
|
-
const row = target ? target.extra ?? -1 : extraRow;
|
|
3233
|
-
const cur = target ? target.cli : onCli;
|
|
3234
|
-
if (row === 1) {
|
|
3235
|
-
if (mouse.forcedOff) {
|
|
3236
|
-
toast("The mouse is off because CONVENO_MOUSE=0 is set.", "warn");
|
|
3237
|
-
return;
|
|
3238
|
-
}
|
|
3239
|
-
if (!mouse.available) {
|
|
3240
|
-
toast("This terminal can't send mouse clicks.", "warn");
|
|
3241
|
-
return;
|
|
3242
|
-
}
|
|
3243
|
-
const next = !mouseOn;
|
|
3244
|
-
mouse.set(next);
|
|
3245
|
-
toast(next ? "Mouse is on." : "Mouse is off.", "ok");
|
|
3246
|
-
return;
|
|
3247
|
-
}
|
|
3248
|
-
if (row === 0) {
|
|
3249
|
-
const next = !extras.helpers;
|
|
3250
|
-
actions.setHelpers(next).then(() => {
|
|
3251
|
-
setExtras({
|
|
3252
|
-
...extras,
|
|
3253
|
-
helpers: next
|
|
3254
|
-
});
|
|
3255
|
-
toast(next ? "Workers may get the helpers when needed." : "Workers won't fetch helpers.", "ok");
|
|
3256
|
-
}, () => toast("Couldn't change that. Try again.", "error"));
|
|
3257
|
-
return;
|
|
3258
|
-
}
|
|
3259
|
-
const { ids, skipped } = idsFor(clis, picked, cur?.cli);
|
|
3260
|
-
if (ids.length === 0) return toast(skipped ?? "Nothing to set up here.", "warn");
|
|
3261
|
-
const names = clis.filter((x) => ids.includes(`init:${x.cli}`)).map((x) => x.label);
|
|
3262
|
-
open(ids, `Set up ${names.join(", ")}`);
|
|
3263
|
-
}, [
|
|
3264
|
-
extraRow,
|
|
3265
|
-
onCli,
|
|
3266
|
-
extras,
|
|
3267
|
-
mouse,
|
|
3268
|
-
mouseOn,
|
|
3269
|
-
clis,
|
|
3270
|
-
picked,
|
|
3271
|
-
open,
|
|
3272
|
-
toast,
|
|
3273
|
-
actions
|
|
3274
|
-
]);
|
|
3275
|
-
const remove = useCallback(() => {
|
|
3276
|
-
if (!onCli) return toast("Pick a CLI in the list first.", "warn");
|
|
3277
|
-
if (onCli.status === "not-installed") return toast(`${onCli.label} is not installed.`, "warn");
|
|
3278
|
-
open([`uninstall:${onCli.cli}`], `Remove Conveno from ${onCli.label}`);
|
|
3279
|
-
}, [
|
|
3280
|
-
onCli,
|
|
3281
|
-
open,
|
|
3282
|
-
toast
|
|
3283
|
-
]);
|
|
3284
|
-
const apply = useCallback(async () => {
|
|
3285
|
-
if (!review) return;
|
|
3286
|
-
setReview({
|
|
3287
|
-
...review,
|
|
3288
|
-
busy: true
|
|
3289
|
-
});
|
|
3290
|
-
try {
|
|
3291
|
-
for (const id of idsWithOptions(review.ids, review.options, review.accepted)) await actions.applyFix(id);
|
|
3292
|
-
toast("Done. Restart open sessions to pick it up.", "ok");
|
|
3293
|
-
setReview(void 0);
|
|
3294
|
-
setPicked(/* @__PURE__ */ new Set());
|
|
3295
|
-
await refresh();
|
|
3296
|
-
} catch (e) {
|
|
3297
|
-
setReview(void 0);
|
|
3298
|
-
toast(e instanceof Error ? e.message : "That did not work.", "error");
|
|
3299
|
-
}
|
|
3300
|
-
}, [
|
|
3301
|
-
review,
|
|
3302
|
-
actions,
|
|
3303
|
-
toast,
|
|
3304
|
-
refresh
|
|
3305
|
-
]);
|
|
3306
|
-
useEffect(() => {
|
|
3307
|
-
if (review) setKeys([
|
|
3308
|
-
{
|
|
3309
|
-
key: "y",
|
|
3310
|
-
label: "apply"
|
|
3311
|
-
},
|
|
3312
|
-
{
|
|
3313
|
-
key: "n",
|
|
3314
|
-
label: "cancel"
|
|
3315
|
-
},
|
|
3316
|
-
{
|
|
3317
|
-
key: "↑↓",
|
|
3318
|
-
label: "scroll"
|
|
3319
|
-
},
|
|
3320
|
-
...review.options.length > 0 ? [{
|
|
3321
|
-
key: "1-9",
|
|
3322
|
-
label: "tick option"
|
|
3323
|
-
}] : []
|
|
3324
|
-
]);
|
|
3325
|
-
else setKeys([
|
|
3326
|
-
{
|
|
3327
|
-
key: "Space",
|
|
3328
|
-
label: "pick"
|
|
3329
|
-
},
|
|
3330
|
-
{
|
|
3331
|
-
key: m.enter,
|
|
3332
|
-
label: "set up · fix"
|
|
3333
|
-
},
|
|
3334
|
-
{
|
|
3335
|
-
key: "u",
|
|
3336
|
-
label: "remove"
|
|
3337
|
-
},
|
|
3338
|
-
{
|
|
3339
|
-
key: "g",
|
|
3340
|
-
label: "refresh"
|
|
3341
|
-
}
|
|
3342
|
-
]);
|
|
3343
|
-
}, [
|
|
3344
|
-
review,
|
|
3345
|
-
setKeys,
|
|
3346
|
-
m.enter
|
|
3347
|
-
]);
|
|
3348
|
-
useEffect(() => {
|
|
3349
|
-
setCommands([{
|
|
3350
|
-
id: "setup.refresh",
|
|
3351
|
-
label: "Check my CLIs again",
|
|
3352
|
-
key: "g",
|
|
3353
|
-
run: () => void refresh()
|
|
3354
|
-
}, {
|
|
3355
|
-
id: "setup.all",
|
|
3356
|
-
label: "Set up every CLI that needs it",
|
|
3357
|
-
rank: 5,
|
|
3358
|
-
run: () => {
|
|
3359
|
-
const ids = clis.filter((x) => x.status === "needs-update" || x.status === "not-set-up").map((x) => `init:${x.cli}`);
|
|
3360
|
-
if (ids.length === 0) return toast("Everything is already set up.", "ok");
|
|
3361
|
-
go("setup");
|
|
3362
|
-
open(ids, "Set up every CLI that needs it");
|
|
3363
|
-
}
|
|
3364
|
-
}]);
|
|
3365
|
-
}, [
|
|
3366
|
-
setCommands,
|
|
3367
|
-
refresh,
|
|
3368
|
-
clis,
|
|
3369
|
-
open,
|
|
3370
|
-
go,
|
|
3371
|
-
toast
|
|
3372
|
-
]);
|
|
3373
|
-
const togglePick = (x) => {
|
|
3374
|
-
const next = new Set(picked);
|
|
3375
|
-
if (next.has(x.cli)) next.delete(x.cli);
|
|
3376
|
-
else next.add(x.cli);
|
|
3377
|
-
setPicked(next);
|
|
3378
|
-
};
|
|
3379
|
-
const fixable = (x) => x.status === "needs-update" || x.status === "not-set-up";
|
|
3380
|
-
const clickRow = (i, x, double) => {
|
|
3381
|
-
if (i === at || double) {
|
|
3382
|
-
setCursor(i);
|
|
3383
|
-
setUp({ cli: x });
|
|
3384
|
-
} else setCursor(i);
|
|
3385
|
-
};
|
|
3386
|
-
const scrollReview = (d) => setReview((r) => r && !r.busy ? {
|
|
3387
|
-
...r,
|
|
3388
|
-
scroll: Math.max(0, r.scroll + d)
|
|
3389
|
-
} : r);
|
|
3390
|
-
const closeReview = () => setReview((r) => r?.busy ? r : void 0);
|
|
3391
|
-
useInput((input, key) => {
|
|
3392
|
-
if (review) {
|
|
3393
|
-
if (review.busy) return;
|
|
3394
|
-
if (key.upArrow) return setReview({
|
|
3395
|
-
...review,
|
|
3396
|
-
scroll: Math.max(0, review.scroll - 1)
|
|
3397
|
-
});
|
|
3398
|
-
if (key.downArrow) return setReview({
|
|
3399
|
-
...review,
|
|
3400
|
-
scroll: review.scroll + 1
|
|
3401
|
-
});
|
|
3402
|
-
const closed = review.error || review.files.length === 0;
|
|
3403
|
-
if (/^[1-9]$/.test(input)) return toggleOption(Number(input) - 1);
|
|
3404
|
-
if (input === "n" || key.escape || closed && (key.return || input === "y")) return setReview(void 0);
|
|
3405
|
-
if (input === "y" && !closed) apply();
|
|
3406
|
-
return;
|
|
3407
|
-
}
|
|
3408
|
-
if (key.escape) return setPicked(/* @__PURE__ */ new Set());
|
|
3409
|
-
if (key.upArrow) return setCursor(Math.max(0, at - 1));
|
|
3410
|
-
if (key.downArrow) return setCursor(Math.min(total - 1, at + 1));
|
|
3411
|
-
if (input === " ") {
|
|
3412
|
-
if (onCli) togglePick(onCli);
|
|
3413
|
-
else setUp();
|
|
3414
|
-
return;
|
|
3415
|
-
}
|
|
3416
|
-
if (key.return) return setUp();
|
|
3417
|
-
if (input === "u") return remove();
|
|
3418
|
-
if (input === "g") return void refresh();
|
|
3419
|
-
}, { isActive: active });
|
|
3420
|
-
const wide = layout === "wide";
|
|
3421
|
-
const split = splitWidths(columns, wide, {
|
|
3422
|
-
panelW: 44,
|
|
3423
|
-
maxMain: 110
|
|
3424
|
-
});
|
|
3425
|
-
const sideWidth = paneInner(split.panelW);
|
|
3426
|
-
const mainWidth = wide ? split.mainW - 2 : Math.min(columns, 110);
|
|
3427
|
-
const listHeight = Math.max(3, rows - 11);
|
|
3428
|
-
const longestLabel = clis.reduce((n, x) => Math.max(n, [...x.label].length), 0);
|
|
3429
|
-
const labelW = Math.max(12, Math.min(24, longestLabel + 1));
|
|
3430
|
-
const noteW = Math.max(0, mainWidth - (11 + (labelW + 2) + 15));
|
|
3431
|
-
const colourOf = (s) => s === "ready" ? c.ok : s === "needs-update" || s === "not-set-up" ? c.warn : s === "blocked" ? c.error : c.quiet;
|
|
3432
|
-
const cliRows = useMemo(() => clis, [clis]);
|
|
3433
|
-
if (review) {
|
|
3434
|
-
const closed = review.error || review.files.length === 0;
|
|
3435
|
-
return /* @__PURE__ */ jsx(ReviewBox, {
|
|
3436
|
-
review,
|
|
3437
|
-
rows,
|
|
3438
|
-
width: Math.min(columns - 2, 100),
|
|
3439
|
-
active,
|
|
3440
|
-
onYes: () => closed ? closeReview() : void apply(),
|
|
3441
|
-
onNo: closeReview,
|
|
3442
|
-
onScroll: scrollReview
|
|
3443
|
-
});
|
|
3444
|
-
}
|
|
3445
|
-
const box = (on) => on ? "[x]" : "[ ]";
|
|
3446
|
-
const cursorMark = (on) => on ? m.cursor : " ";
|
|
3447
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
3448
|
-
flexDirection: "row",
|
|
3449
|
-
height: rows,
|
|
3450
|
-
children: [/* @__PURE__ */ jsxs(Box, {
|
|
3451
|
-
flexDirection: "column",
|
|
3452
|
-
width: wide ? split.mainW : mainWidth,
|
|
3453
|
-
flexShrink: 0,
|
|
3454
|
-
children: [
|
|
3455
|
-
/* @__PURE__ */ jsx(Label, { children: "Your CLIs" }),
|
|
3456
|
-
!state.setup ? /* @__PURE__ */ jsxs(Text, {
|
|
3457
|
-
dimColor: true,
|
|
3458
|
-
children: ["Looking for your CLIs", m.ellipsis]
|
|
3459
|
-
}) : cliRows.length === 0 ? /* @__PURE__ */ jsx(Text, {
|
|
3460
|
-
dimColor: true,
|
|
3461
|
-
children: "No supported CLI found. Install one, then press g."
|
|
3462
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(HeaderRow, {
|
|
3463
|
-
width: mainWidth,
|
|
3464
|
-
cols: [
|
|
3465
|
-
{
|
|
3466
|
-
w: 6,
|
|
3467
|
-
text: "",
|
|
3468
|
-
gap: 0
|
|
3469
|
-
},
|
|
3470
|
-
{
|
|
3471
|
-
w: 5,
|
|
3472
|
-
text: "",
|
|
3473
|
-
gap: 0
|
|
3474
|
-
},
|
|
3475
|
-
{
|
|
3476
|
-
w: labelW + 2,
|
|
3477
|
-
text: "CLI"
|
|
3478
|
-
},
|
|
3479
|
-
{
|
|
3480
|
-
w: 15,
|
|
3481
|
-
text: "Status"
|
|
3482
|
-
},
|
|
3483
|
-
{
|
|
3484
|
-
w: noteW,
|
|
3485
|
-
text: noteW > 4 ? "Note" : "",
|
|
3486
|
-
gap: 0
|
|
3487
|
-
}
|
|
3488
|
-
]
|
|
3489
|
-
}), /* @__PURE__ */ jsx(Hit, {
|
|
3490
|
-
flexDirection: "column",
|
|
3491
|
-
onWheel: (d) => setCursor(Math.max(0, Math.min(total - 1, at + (d < 0 ? -1 : 1)))),
|
|
3492
|
-
isActive: active,
|
|
3493
|
-
children: /* @__PURE__ */ jsx(ScrollList, {
|
|
3494
|
-
items: cliRows,
|
|
3495
|
-
selected: Math.min(at, cliRows.length - 1),
|
|
3496
|
-
height: listHeight,
|
|
3497
|
-
keyOf: (x) => x.cli,
|
|
3498
|
-
renderItem: (x, sel, i) => {
|
|
3499
|
-
const off = x.status === "not-installed";
|
|
3500
|
-
return /* @__PURE__ */ jsx(Hit, {
|
|
3501
|
-
onClick: (e) => clickRow(i, x, e.double),
|
|
3502
|
-
isActive: active,
|
|
3503
|
-
children: /* @__PURE__ */ jsxs(Row, {
|
|
3504
|
-
width: mainWidth,
|
|
3505
|
-
selected: sel && at < clis.length,
|
|
3506
|
-
children: [
|
|
3507
|
-
/* @__PURE__ */ jsx(Cell, {
|
|
3508
|
-
w: 2,
|
|
3509
|
-
gap: 0,
|
|
3510
|
-
color: c.entry,
|
|
3511
|
-
children: cursorMark(sel && at < clis.length)
|
|
3512
|
-
}),
|
|
3513
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
3514
|
-
onClick: () => {
|
|
3515
|
-
setCursor(i);
|
|
3516
|
-
togglePick(x);
|
|
3517
|
-
},
|
|
3518
|
-
isActive: active,
|
|
3519
|
-
children: /* @__PURE__ */ jsx(Cell, {
|
|
3520
|
-
w: 4,
|
|
3521
|
-
gap: 0,
|
|
3522
|
-
children: `${box(picked.has(x.cli))} `
|
|
3523
|
-
})
|
|
3524
|
-
}),
|
|
3525
|
-
/* @__PURE__ */ jsx(Box, {
|
|
3526
|
-
width: 5,
|
|
3527
|
-
flexShrink: 0,
|
|
3528
|
-
children: /* @__PURE__ */ jsx(Chip, {
|
|
3529
|
-
cli: x.cli,
|
|
3530
|
-
dim: off
|
|
3531
|
-
})
|
|
3532
|
-
}),
|
|
3533
|
-
/* @__PURE__ */ jsx(Cell, {
|
|
3534
|
-
w: labelW + 2,
|
|
3535
|
-
bold: sel,
|
|
3536
|
-
dim: off,
|
|
3537
|
-
children: x.label
|
|
3538
|
-
}),
|
|
3539
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
3540
|
-
onClick: () => {
|
|
3541
|
-
setCursor(i);
|
|
3542
|
-
if (fixable(x)) setUp({ cli: x });
|
|
3543
|
-
},
|
|
3544
|
-
isActive: active,
|
|
3545
|
-
children: /* @__PURE__ */ jsx(Cell, {
|
|
3546
|
-
w: 15,
|
|
3547
|
-
color: colourOf(x.status),
|
|
3548
|
-
dim: off,
|
|
3549
|
-
children: STATUS_WORD[x.status]
|
|
3550
|
-
})
|
|
3551
|
-
}),
|
|
3552
|
-
noteW > 4 ? /* @__PURE__ */ jsx(Cell, {
|
|
3553
|
-
w: noteW,
|
|
3554
|
-
gap: 0,
|
|
3555
|
-
color: c.quiet,
|
|
3556
|
-
dim: !c.quiet,
|
|
3557
|
-
children: plain(x.note ?? (x.version ? x.version : ""), ascii)
|
|
3558
|
-
}) : null
|
|
3559
|
-
]
|
|
3560
|
-
})
|
|
3561
|
-
});
|
|
3562
|
-
}
|
|
3563
|
-
})
|
|
3564
|
-
})] }),
|
|
3565
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
3566
|
-
/* @__PURE__ */ jsx(Label, { children: "Extras" }),
|
|
3567
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
3568
|
-
onClick: () => {
|
|
3569
|
-
setCursor(clis.length);
|
|
3570
|
-
setUp({ extra: 0 });
|
|
3571
|
-
},
|
|
3572
|
-
isActive: active,
|
|
3573
|
-
children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 0)} ${box(extras.helpers)} Get the Claude and Codex helpers when needed` })
|
|
3574
|
-
}),
|
|
3575
|
-
/* @__PURE__ */ jsx(Hit, {
|
|
3576
|
-
onClick: () => {
|
|
3577
|
-
setCursor(clis.length + 1);
|
|
3578
|
-
setUp({ extra: 1 });
|
|
3579
|
-
},
|
|
3580
|
-
isActive: active,
|
|
3581
|
-
children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 1)} ${box(mouseOn)} Click and scroll with the mouse` })
|
|
3582
|
-
}),
|
|
3583
|
-
!wide && health.length > 0 && rows >= 22 ? /* @__PURE__ */ jsxs(Box, {
|
|
3584
|
-
flexDirection: "column",
|
|
3585
|
-
marginTop: 1,
|
|
3586
|
-
children: [/* @__PURE__ */ jsx(Label, { children: "Checkup" }), health.slice(0, 4).map((h) => /* @__PURE__ */ jsx(HealthLine, {
|
|
3587
|
-
item: h,
|
|
3588
|
-
width: mainWidth
|
|
3589
|
-
}, h.text))]
|
|
3590
|
-
}) : null,
|
|
3591
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
3592
|
-
/* @__PURE__ */ jsx(Text, {
|
|
3593
|
-
dimColor: true,
|
|
3594
|
-
children: "You see every change before it happens. We back up each file first."
|
|
3595
|
-
})
|
|
3596
|
-
]
|
|
3597
|
-
}), wide ? /* @__PURE__ */ jsxs(Pane, {
|
|
3598
|
-
width: split.panelW,
|
|
3599
|
-
height: rows,
|
|
3600
|
-
children: [
|
|
3601
|
-
/* @__PURE__ */ jsx(Label, { children: "Checkup" }),
|
|
3602
|
-
health.length === 0 ? /* @__PURE__ */ jsxs(Text, {
|
|
3603
|
-
dimColor: true,
|
|
3604
|
-
children: ["Checking", m.ellipsis]
|
|
3605
|
-
}) : null,
|
|
3606
|
-
health.map((h) => /* @__PURE__ */ jsx(HealthLine, {
|
|
3607
|
-
item: h,
|
|
3608
|
-
width: sideWidth
|
|
3609
|
-
}, h.text)),
|
|
3610
|
-
health.some((h) => h.fixId) ? /* @__PURE__ */ jsx(Text, {
|
|
3611
|
-
dimColor: true,
|
|
3612
|
-
children: `Press ${m.enter} on a CLI to fix it.`
|
|
3613
|
-
}) : null
|
|
3614
|
-
]
|
|
3615
|
-
}) : null]
|
|
3616
|
-
});
|
|
3617
|
-
}
|
|
3618
|
-
// src/tui/screens/index.ts
|
|
3619
|
-
/** A screen file exports its component as `default` or as `<Name>Screen`. */
|
|
3620
|
-
const pick = (m, name) => {
|
|
3621
|
-
const mod = m;
|
|
3622
|
-
return mod.default ?? mod[`${name}Screen`];
|
|
3623
|
-
};
|
|
3624
|
-
const SCREEN_COMPONENTS = {
|
|
3625
|
-
sessions: pick(sessions_exports, "Sessions"),
|
|
3626
|
-
new: pick(new_exports, "New"),
|
|
3627
|
-
devices: pick(devices_exports, "Devices"),
|
|
3628
|
-
setup: pick(setup_exports, "Setup")
|
|
3629
|
-
};
|
|
3630
|
-
// src/tui/App.tsx
|
|
3631
|
-
/** The app shell: top bar, tabs, one screen, key bar, and the palette and help overlays. */
|
|
3632
|
-
const TOAST_MS = 3e3;
|
|
3633
|
-
const MIN_COLUMNS = 60;
|
|
3634
|
-
const SCREEN_LINE = {
|
|
3635
|
-
sessions: (s) => {
|
|
3636
|
-
const total = s.sessions.length;
|
|
3637
|
-
if (total === 0) return "Nothing is running";
|
|
3638
|
-
return `${total} ${total === 1 ? "session" : "sessions"} running`;
|
|
3639
|
-
},
|
|
3640
|
-
new: () => "Start something new",
|
|
3641
|
-
devices: () => "Your machines",
|
|
3642
|
-
setup: () => "Get your tools ready"
|
|
3643
|
-
};
|
|
3644
|
-
function TopBar({ state, screen, width }) {
|
|
3645
|
-
const { c, ascii } = useTheme();
|
|
3646
|
-
const dot = ascii ? "*" : "●";
|
|
3647
|
-
let line = SCREEN_LINE[screen](state);
|
|
3648
|
-
let lineColor = c.quiet;
|
|
3649
|
-
if (state.connection === "connecting") line = "Connecting…";
|
|
3650
|
-
else if (state.connection === "daemon-down") {
|
|
3651
|
-
line = "Can't reach the background service. Trying again…";
|
|
3652
|
-
lineColor = c.warn;
|
|
3653
|
-
} else if (state.connection === "error") {
|
|
3654
|
-
line = state.connectionDetail ?? "Something went wrong.";
|
|
3655
|
-
lineColor = c.error;
|
|
3656
|
-
}
|
|
3657
|
-
if (ascii) line = line.replace(/·/g, "-");
|
|
3658
|
-
const inner = width - 2;
|
|
3659
|
-
const room = Math.max(0, inner - 11);
|
|
3660
|
-
return /* @__PURE__ */ jsxs(Band, {
|
|
3661
|
-
width,
|
|
3662
|
-
children: [
|
|
3663
|
-
/* @__PURE__ */ jsx(Text, {
|
|
3664
|
-
bold: true,
|
|
3665
|
-
...c.ink ? { color: c.ink } : {},
|
|
3666
|
-
children: "c"
|
|
3667
|
-
}),
|
|
3668
|
-
/* @__PURE__ */ jsx(Text, {
|
|
3669
|
-
...c.entry ? { color: c.entry } : {},
|
|
3670
|
-
children: dot
|
|
3671
|
-
}),
|
|
3672
|
-
/* @__PURE__ */ jsxs(Text, {
|
|
3673
|
-
bold: true,
|
|
3674
|
-
...c.ink ? { color: c.ink } : {},
|
|
3675
|
-
children: [" ", "conveno"]
|
|
3676
|
-
}),
|
|
3677
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
3678
|
-
/* @__PURE__ */ jsx(Box, {
|
|
3679
|
-
width: room,
|
|
3680
|
-
flexShrink: 0,
|
|
3681
|
-
children: /* @__PURE__ */ jsx(Ell, {
|
|
3682
|
-
width: room,
|
|
3683
|
-
color: lineColor,
|
|
3684
|
-
children: line
|
|
3685
|
-
})
|
|
3686
|
-
})
|
|
3687
|
-
]
|
|
3688
|
-
});
|
|
3689
|
-
}
|
|
3690
|
-
/** The tab row, and under it the rule with the active tab underlined in the entry colour. */
|
|
3691
|
-
function Tabs({ screen, layout, width, onGo }) {
|
|
3692
|
-
const { c, ascii } = useTheme();
|
|
3693
|
-
const narrow = layout === "narrow";
|
|
3694
|
-
const labels = SCREENS.map((s) => {
|
|
3695
|
-
const on = s.id === screen;
|
|
3696
|
-
return {
|
|
3697
|
-
id: s.id,
|
|
3698
|
-
on,
|
|
3699
|
-
text: narrow && !on ? s.key : `${s.key} ${s.title}`
|
|
3700
|
-
};
|
|
3701
|
-
});
|
|
3702
|
-
const gap = 2;
|
|
3703
|
-
let at = 1;
|
|
3704
|
-
let from = 0;
|
|
3705
|
-
let to = 0;
|
|
3706
|
-
for (const l of labels) {
|
|
3707
|
-
if (l.on) {
|
|
3708
|
-
from = at;
|
|
3709
|
-
to = at + l.text.length;
|
|
3710
|
-
}
|
|
3711
|
-
at += l.text.length + gap;
|
|
3712
|
-
}
|
|
3713
|
-
const thin = ascii ? "-" : "─";
|
|
3714
|
-
const heavy = ascii ? "=" : "━";
|
|
3715
|
-
const ruleColor = c.rule ? { color: c.rule } : { dimColor: true };
|
|
3716
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Box, {
|
|
3717
|
-
width,
|
|
3718
|
-
height: 1,
|
|
3719
|
-
paddingX: 1,
|
|
3720
|
-
gap,
|
|
3721
|
-
children: labels.map((l) => /* @__PURE__ */ jsx(Clickable, {
|
|
3722
|
-
onClick: () => onGo(l.id),
|
|
3723
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
3724
|
-
...l.on ? { bold: true } : {},
|
|
3725
|
-
...l.on ? c.ink ? { color: c.ink } : {} : c.quiet ? { color: c.quiet } : {},
|
|
3726
|
-
children: l.text
|
|
3727
|
-
})
|
|
3728
|
-
}, l.id))
|
|
3729
|
-
}), /* @__PURE__ */ jsxs(Text, { children: [
|
|
3730
|
-
/* @__PURE__ */ jsx(Text, {
|
|
3731
|
-
...ruleColor,
|
|
3732
|
-
children: thin.repeat(from)
|
|
3733
|
-
}),
|
|
3734
|
-
/* @__PURE__ */ jsx(Text, {
|
|
3735
|
-
...c.entry ? { color: c.entry } : {},
|
|
3736
|
-
children: heavy.repeat(to - from)
|
|
3737
|
-
}),
|
|
3738
|
-
/* @__PURE__ */ jsx(Text, {
|
|
3739
|
-
...ruleColor,
|
|
3740
|
-
children: thin.repeat(Math.max(0, width - to))
|
|
3741
|
-
})
|
|
3742
|
-
] })] });
|
|
3743
|
-
}
|
|
3744
|
-
/** The bytes a key hint stands for, or undefined when it is not one single key. */
|
|
3745
|
-
function keySequence(key) {
|
|
3746
|
-
const n = {
|
|
3747
|
-
"⏎": "\r",
|
|
3748
|
-
Enter: "\r",
|
|
3749
|
-
Esc: "\x1B",
|
|
3750
|
-
Tab: " ",
|
|
3751
|
-
Space: " ",
|
|
3752
|
-
"↑": "\x1B[A",
|
|
3753
|
-
"↓": "\x1B[B",
|
|
3754
|
-
"→": "\x1B[C",
|
|
3755
|
-
"←": "\x1B[D",
|
|
3756
|
-
PgUp: "\x1B[5~",
|
|
3757
|
-
PgDn: "\x1B[6~"
|
|
3758
|
-
}[key];
|
|
3759
|
-
if (n) return n;
|
|
3760
|
-
const ctrl = /^Ctrl\+([A-Za-z])$/.exec(key);
|
|
3761
|
-
if (ctrl) return String.fromCharCode(ctrl[1].toUpperCase().charCodeAt(0) - 64);
|
|
3762
|
-
return [...key].length === 1 ? key : void 0;
|
|
3763
|
-
}
|
|
3764
|
-
function KeyBar({ keys, toast, width, onKey, onHelp, onDismiss }) {
|
|
3765
|
-
const { c, ascii } = useTheme();
|
|
3766
|
-
const inner = width - 2;
|
|
3767
|
-
if (toast) {
|
|
3768
|
-
const color = toast.level === "ok" ? c.ok : toast.level === "warn" ? c.warn : c.error;
|
|
3769
|
-
const mark = toast.level === "ok" ? "" : toast.level === "warn" ? "! " : "x ";
|
|
3770
|
-
return /* @__PURE__ */ jsx(Band, {
|
|
3771
|
-
width,
|
|
3772
|
-
children: /* @__PURE__ */ jsx(Clickable, {
|
|
3773
|
-
onClick: onDismiss,
|
|
3774
|
-
children: /* @__PURE__ */ jsx(Ell, {
|
|
3775
|
-
width: inner,
|
|
3776
|
-
color,
|
|
3777
|
-
children: mark + toast.text
|
|
3778
|
-
})
|
|
3779
|
-
})
|
|
3780
|
-
});
|
|
3781
|
-
}
|
|
3782
|
-
const all = {
|
|
3783
|
-
key: "?",
|
|
3784
|
-
label: "all keys"
|
|
3785
|
-
};
|
|
3786
|
-
const shown = [];
|
|
3787
|
-
let used = all.key.length + 1 + all.label.length;
|
|
3788
|
-
for (const k0 of keys) {
|
|
3789
|
-
const k = {
|
|
3790
|
-
key: plain(k0.key, ascii),
|
|
3791
|
-
label: plain(k0.label, ascii),
|
|
3792
|
-
raw: k0.key
|
|
3793
|
-
};
|
|
3794
|
-
const w = k.key.length + 1 + k.label.length + 2;
|
|
3795
|
-
if (used + w > inner) break;
|
|
3796
|
-
used += w;
|
|
3797
|
-
shown.push(k);
|
|
3798
|
-
}
|
|
3799
|
-
return /* @__PURE__ */ jsx(Band, {
|
|
3800
|
-
width,
|
|
3801
|
-
children: [...shown, all].map((k, i) => {
|
|
3802
|
-
const seq = k === all ? void 0 : keySequence(k.raw ?? k.key);
|
|
3803
|
-
return /* @__PURE__ */ jsx(Clickable, {
|
|
3804
|
-
isActive: k === all || seq !== void 0,
|
|
3805
|
-
onClick: () => k === all ? onHelp() : seq && onKey(seq),
|
|
3806
|
-
children: /* @__PURE__ */ jsxs(Text, {
|
|
3807
|
-
wrap: "truncate",
|
|
3808
|
-
children: [
|
|
3809
|
-
i > 0 ? " " : "",
|
|
3810
|
-
/* @__PURE__ */ jsx(Text, {
|
|
3811
|
-
bold: true,
|
|
3812
|
-
...c.ink ? { color: c.ink } : {},
|
|
3813
|
-
children: k.key
|
|
3814
|
-
}),
|
|
3815
|
-
/* @__PURE__ */ jsx(Text, {
|
|
3816
|
-
...c.quiet ? { color: c.quiet } : {},
|
|
3817
|
-
children: ` ${k.label}`
|
|
3818
|
-
})
|
|
3819
|
-
]
|
|
3820
|
-
})
|
|
3821
|
-
}, `${k.key}-${k.label}`);
|
|
3822
|
-
})
|
|
3823
|
-
});
|
|
3824
|
-
}
|
|
3825
|
-
function App({ store, theme, onQuit, size, mouse }) {
|
|
3826
|
-
return /* @__PURE__ */ jsx(ThemeProvider, {
|
|
3827
|
-
...theme ? { theme } : {},
|
|
3828
|
-
children: /* @__PURE__ */ jsx(Shell, {
|
|
3829
|
-
store,
|
|
3830
|
-
onQuit,
|
|
3831
|
-
size,
|
|
3832
|
-
mouse
|
|
3833
|
-
})
|
|
3834
|
-
});
|
|
3835
|
-
}
|
|
3836
|
-
function Shell({ store, onQuit, size, mouse }) {
|
|
3837
|
-
const { exit } = useApp();
|
|
3838
|
-
const { stdin } = useStdin();
|
|
3839
|
-
const stdinRef = useRef(stdin);
|
|
3840
|
-
stdinRef.current = stdin;
|
|
3841
|
-
const [hub] = useState(() => mouse ?? new MouseHub({ inject: (k) => stdinRef.current.write?.(k) }));
|
|
3842
|
-
useEffect(() => {
|
|
3843
|
-
if (mouse) return;
|
|
3844
|
-
const parser = new MouseParser();
|
|
3845
|
-
const onData = (chunk) => {
|
|
3846
|
-
for (const e of parser.push(String(chunk)).events) hub.dispatch(e);
|
|
3847
|
-
};
|
|
3848
|
-
stdin.on("data", onData);
|
|
3849
|
-
return () => {
|
|
3850
|
-
stdin.removeListener("data", onData);
|
|
3851
|
-
};
|
|
3852
|
-
}, [
|
|
3853
|
-
mouse,
|
|
3854
|
-
hub,
|
|
3855
|
-
stdin
|
|
3856
|
-
]);
|
|
3857
|
-
const win = useWindowSize();
|
|
3858
|
-
const columns = size?.columns ?? win.columns;
|
|
3859
|
-
const rows = size?.rows ?? win.rows;
|
|
3860
|
-
const layout = layoutFor(columns);
|
|
3861
|
-
const state = useSyncExternalStore(store.subscribe, store.getState);
|
|
3862
|
-
const [screen, setScreen] = useState("sessions");
|
|
3863
|
-
const screenRef = useRef("sessions");
|
|
3864
|
-
const movedRef = useRef(false);
|
|
3865
|
-
const [focus, setFocus] = useState();
|
|
3866
|
-
const [overlay, setOverlay] = useState("none");
|
|
3867
|
-
const typingRef = useRef(false);
|
|
3868
|
-
const overlayRef = useRef("none");
|
|
3869
|
-
const [keys, setKeysState] = useState([]);
|
|
3870
|
-
const [toast, setToast] = useState();
|
|
3871
|
-
const [, bump] = useState(0);
|
|
3872
|
-
const screenCommands = useRef([]);
|
|
3873
|
-
const commandSig = useRef("");
|
|
3874
|
-
const toastId = useRef(0);
|
|
3875
|
-
const claimedRef = useRef(/* @__PURE__ */ new Set());
|
|
3876
|
-
const draftCleared = useRef(false);
|
|
3877
|
-
const askedSetup = useRef(false);
|
|
3878
|
-
overlayRef.current = overlay;
|
|
3879
|
-
const setTyping = useCallback((v) => {
|
|
3880
|
-
typingRef.current = v;
|
|
3881
|
-
}, []);
|
|
3882
|
-
const claimKeys = useCallback((keys) => {
|
|
3883
|
-
claimedRef.current = new Set(keys);
|
|
3884
|
-
}, []);
|
|
3885
|
-
const quit = useCallback(() => {
|
|
3886
|
-
onQuit?.();
|
|
3887
|
-
exit();
|
|
3888
|
-
}, [exit, onQuit]);
|
|
3889
|
-
const go = useCallback((to, f) => {
|
|
3890
|
-
movedRef.current = true;
|
|
3891
|
-
setFocus(f);
|
|
3892
|
-
setOverlay("none");
|
|
3893
|
-
if (to === screenRef.current) return;
|
|
3894
|
-
screenRef.current = to;
|
|
3895
|
-
setScreen(to);
|
|
3896
|
-
setKeysState([]);
|
|
3897
|
-
screenCommands.current = [];
|
|
3898
|
-
commandSig.current = "";
|
|
3899
|
-
typingRef.current = false;
|
|
3900
|
-
claimedRef.current = /* @__PURE__ */ new Set();
|
|
3901
|
-
}, []);
|
|
3902
|
-
const setKeys = useCallback((next) => {
|
|
3903
|
-
setKeysState((cur) => cur.length === next.length && cur.every((k, i) => k.key === next[i]?.key && k.label === next[i]?.label) ? cur : next);
|
|
3904
|
-
}, []);
|
|
3905
|
-
const setCommands = useCallback((cmds) => {
|
|
3906
|
-
screenCommands.current = cmds;
|
|
3907
|
-
const sig = cmds.map((c) => `${c.id}|${c.label}|${c.key ?? ""}`).join("\n");
|
|
3908
|
-
if (sig !== commandSig.current) {
|
|
3909
|
-
commandSig.current = sig;
|
|
3910
|
-
bump((n) => n + 1);
|
|
3911
|
-
}
|
|
3912
|
-
}, []);
|
|
3913
|
-
const showToast = useCallback((text, level = "ok", ms = TOAST_MS) => {
|
|
3914
|
-
toastId.current += 1;
|
|
3915
|
-
setToast({
|
|
3916
|
-
id: toastId.current,
|
|
3917
|
-
text,
|
|
3918
|
-
level,
|
|
3919
|
-
ms
|
|
3920
|
-
});
|
|
3921
|
-
}, []);
|
|
3922
|
-
useEffect(() => {
|
|
3923
|
-
if (!hub.showHint) return;
|
|
3924
|
-
showToast("Mouse is on. Hold Shift to select text.", "ok", 1e4);
|
|
3925
|
-
hub.hintShown();
|
|
3926
|
-
}, [hub, showToast]);
|
|
3927
|
-
useEffect(() => hub.onUnhandled(() => {
|
|
3928
|
-
if (overlayRef.current !== "none") setOverlay("none");
|
|
3929
|
-
}), [hub]);
|
|
3930
|
-
useEffect(() => {
|
|
3931
|
-
if (!toast) return;
|
|
3932
|
-
const t = setTimeout(() => setToast((cur) => cur?.id === toast.id ? void 0 : cur), toast.ms);
|
|
3933
|
-
return () => clearTimeout(t);
|
|
3934
|
-
}, [toast]);
|
|
3935
|
-
useEffect(() => {
|
|
3936
|
-
if (askedSetup.current || !state.setup) return;
|
|
3937
|
-
askedSetup.current = true;
|
|
3938
|
-
if (movedRef.current) return;
|
|
3939
|
-
if (!state.setup.clis.some((c) => c.status === "ready" || c.status === "needs-update") && state.setup.clis.length > 0) go("setup");
|
|
3940
|
-
}, [state.setup, go]);
|
|
3941
|
-
const draftCtx = useMemo(() => ({ cleared: () => {
|
|
3942
|
-
draftCleared.current = true;
|
|
3943
|
-
} }), []);
|
|
3944
|
-
const globalCommands = useMemo(() => [
|
|
3945
|
-
...SCREENS.map((s) => ({
|
|
3946
|
-
id: `go-${s.id}`,
|
|
3947
|
-
label: `Go to ${s.title}`,
|
|
3948
|
-
key: s.key,
|
|
3949
|
-
rank: 90,
|
|
3950
|
-
run: () => go(s.id)
|
|
3951
|
-
})),
|
|
3952
|
-
{
|
|
3953
|
-
id: "help",
|
|
3954
|
-
label: "Show all keys",
|
|
3955
|
-
key: "?",
|
|
3956
|
-
rank: 95,
|
|
3957
|
-
run: () => setOverlay("help")
|
|
3958
|
-
},
|
|
3959
|
-
{
|
|
3960
|
-
id: "account",
|
|
3961
|
-
label: "Open my account page",
|
|
3962
|
-
rank: 96,
|
|
3963
|
-
run: () => store.actions.openAccountPage().catch(() => showToast("Couldn't open the browser.", "warn"))
|
|
3964
|
-
},
|
|
3965
|
-
{
|
|
3966
|
-
id: "quit",
|
|
3967
|
-
label: "Quit (sessions keep running)",
|
|
3968
|
-
key: "q",
|
|
3969
|
-
rank: 99,
|
|
3970
|
-
run: quit
|
|
3971
|
-
}
|
|
3972
|
-
], [
|
|
3973
|
-
go,
|
|
3974
|
-
quit,
|
|
3975
|
-
showToast,
|
|
3976
|
-
store
|
|
3977
|
-
]);
|
|
3978
|
-
const commands = [...screenCommands.current.map((c) => ({
|
|
3979
|
-
...c,
|
|
3980
|
-
rank: c.rank ?? 10
|
|
3981
|
-
})), ...globalCommands];
|
|
3982
|
-
useInput((input, key) => {
|
|
3983
|
-
const overlayAtKey = overlayRef.current;
|
|
3984
|
-
queueMicrotask(() => {
|
|
3985
|
-
if (key.ctrl && input === "c") {
|
|
3986
|
-
if (draftCleared.current) {
|
|
3987
|
-
draftCleared.current = false;
|
|
3988
|
-
return showToast("Press Ctrl+C again to quit", "warn");
|
|
3989
|
-
}
|
|
3990
|
-
return quit();
|
|
3991
|
-
}
|
|
3992
|
-
if (overlayAtKey !== "none" || overlayRef.current !== "none") return;
|
|
3993
|
-
if (key.ctrl && input === "k") return setOverlay("palette");
|
|
3994
|
-
if (typingRef.current) return;
|
|
3995
|
-
if (claimedRef.current.has(input)) return;
|
|
3996
|
-
if (layout === "tiny") {
|
|
3997
|
-
if (input === "q") quit();
|
|
3998
|
-
return;
|
|
3999
|
-
}
|
|
4000
|
-
const hit = SCREENS.find((s) => s.key === input);
|
|
4001
|
-
if (hit) return go(hit.id);
|
|
4002
|
-
if (input === "/") return setOverlay("palette");
|
|
4003
|
-
if (input === "?") return setOverlay("help");
|
|
4004
|
-
if (input === "q") return quit();
|
|
4005
|
-
if (key.escape) setToast(void 0);
|
|
4006
|
-
});
|
|
4007
|
-
});
|
|
4008
|
-
if (layout === "tiny") return /* @__PURE__ */ jsxs(Box, {
|
|
4009
|
-
width: columns,
|
|
4010
|
-
height: rows,
|
|
4011
|
-
flexDirection: "column",
|
|
4012
|
-
paddingX: 1,
|
|
4013
|
-
children: [/* @__PURE__ */ jsx(Text, {
|
|
4014
|
-
bold: true,
|
|
4015
|
-
children: "Make the window a bit wider"
|
|
4016
|
-
}), /* @__PURE__ */ jsxs(Text, {
|
|
4017
|
-
dimColor: true,
|
|
4018
|
-
children: [
|
|
4019
|
-
"Conveno needs at least ",
|
|
4020
|
-
MIN_COLUMNS,
|
|
4021
|
-
" columns."
|
|
4022
|
-
]
|
|
4023
|
-
})]
|
|
4024
|
-
});
|
|
4025
|
-
const Screen = SCREEN_COMPONENTS[screen];
|
|
4026
|
-
const bodyRows = Math.max(3, rows - 4);
|
|
4027
|
-
const inner = columns - 1;
|
|
4028
|
-
const overlayWidth = Math.min(inner - 2, 72);
|
|
4029
|
-
return /* @__PURE__ */ jsx(MouseProvider, {
|
|
4030
|
-
value: hub,
|
|
4031
|
-
children: /* @__PURE__ */ jsx(DraftProvider, {
|
|
4032
|
-
value: draftCtx,
|
|
4033
|
-
children: /* @__PURE__ */ jsxs(Box, {
|
|
4034
|
-
width: columns,
|
|
4035
|
-
height: rows,
|
|
4036
|
-
flexDirection: "column",
|
|
4037
|
-
children: [
|
|
4038
|
-
/* @__PURE__ */ jsx(TopBar, {
|
|
4039
|
-
state,
|
|
4040
|
-
screen,
|
|
4041
|
-
width: columns
|
|
4042
|
-
}),
|
|
4043
|
-
/* @__PURE__ */ jsx(Tabs, {
|
|
4044
|
-
screen,
|
|
4045
|
-
layout,
|
|
4046
|
-
width: columns,
|
|
4047
|
-
onGo: go
|
|
4048
|
-
}),
|
|
4049
|
-
/* @__PURE__ */ jsxs(Box, {
|
|
4050
|
-
height: bodyRows,
|
|
4051
|
-
width: columns,
|
|
4052
|
-
paddingLeft: 1,
|
|
4053
|
-
flexDirection: "column",
|
|
4054
|
-
overflow: "hidden",
|
|
4055
|
-
children: [overlay !== "none" ? /* @__PURE__ */ jsx(Box, {
|
|
4056
|
-
height: bodyRows,
|
|
4057
|
-
width: inner,
|
|
4058
|
-
justifyContent: "center",
|
|
4059
|
-
alignItems: "flex-start",
|
|
4060
|
-
paddingTop: 1,
|
|
4061
|
-
children: overlay === "palette" ? /* @__PURE__ */ jsx(Palette, {
|
|
4062
|
-
commands,
|
|
4063
|
-
width: overlayWidth,
|
|
4064
|
-
height: bodyRows,
|
|
4065
|
-
onClose: () => setOverlay("none")
|
|
4066
|
-
}) : /* @__PURE__ */ jsx(Help, {
|
|
4067
|
-
screenTitle: SCREENS.find((s) => s.id === screen)?.title ?? "",
|
|
4068
|
-
screenKeys: keys,
|
|
4069
|
-
width: overlayWidth,
|
|
4070
|
-
onClose: () => setOverlay("none")
|
|
4071
|
-
})
|
|
4072
|
-
}) : null, /* @__PURE__ */ jsx(Box, {
|
|
4073
|
-
display: overlay === "none" ? "flex" : "none",
|
|
4074
|
-
flexDirection: "column",
|
|
4075
|
-
height: bodyRows,
|
|
4076
|
-
children: /* @__PURE__ */ jsx(MouseScope, {
|
|
4077
|
-
active: overlay === "none",
|
|
4078
|
-
children: /* @__PURE__ */ jsx(Screen, {
|
|
4079
|
-
state,
|
|
4080
|
-
actions: store.actions,
|
|
4081
|
-
layout,
|
|
4082
|
-
rows: bodyRows,
|
|
4083
|
-
columns: inner,
|
|
4084
|
-
active: overlay === "none",
|
|
4085
|
-
focus,
|
|
4086
|
-
setKeys,
|
|
4087
|
-
setCommands,
|
|
4088
|
-
go,
|
|
4089
|
-
toast: showToast,
|
|
4090
|
-
setTyping,
|
|
4091
|
-
claimKeys
|
|
4092
|
-
}, screen)
|
|
4093
|
-
})
|
|
4094
|
-
})]
|
|
4095
|
-
}),
|
|
4096
|
-
/* @__PURE__ */ jsx(KeyBar, {
|
|
4097
|
-
keys,
|
|
4098
|
-
...toast ? { toast } : {},
|
|
4099
|
-
width: columns,
|
|
4100
|
-
onKey: (seq) => hub.press(seq),
|
|
4101
|
-
onHelp: () => setOverlay("help"),
|
|
4102
|
-
onDismiss: () => setToast(void 0)
|
|
4103
|
-
})
|
|
4104
|
-
]
|
|
4105
|
-
})
|
|
4106
|
-
})
|
|
4107
|
-
});
|
|
4108
|
-
}
|
|
4109
|
-
// src/tui/pair.ts
|
|
4110
|
-
/** The pairing each client started, so `confirmPair` and `pairStatus` need no id. */
|
|
4111
|
-
const current = /* @__PURE__ */ new WeakMap();
|
|
4112
|
-
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
4113
|
-
/** `1234 5678` to `["1234", "5678"]`. */
|
|
4114
|
-
const wordsOf = (sas) => sas.split(/\s+/).filter(Boolean);
|
|
4115
|
-
/**
|
|
4116
|
-
* Start pairing and wait until the other machine has joined and both codes are known. Takes
|
|
4117
|
-
* as long as the other machine does, up to five minutes. Throws when the pairing fails.
|
|
4118
|
-
*/
|
|
4119
|
-
async function startPair(client, opts = {}) {
|
|
4120
|
-
const now = opts.now ?? Date.now;
|
|
4121
|
-
const poll = opts.pollMs ?? 400;
|
|
4122
|
-
const started = now();
|
|
4123
|
-
const expiresAt = new Date(started + PAIR_TIMEOUT_MS).toISOString();
|
|
4124
|
-
let s = await client["devices.pair"]({ role: "invite" });
|
|
4125
|
-
current.set(client, s.pairingId);
|
|
4126
|
-
while (now() < started + PAIR_TIMEOUT_MS) {
|
|
4127
|
-
if (s.state === "failed") throw new Error(s.error ?? "The pairing failed.");
|
|
4128
|
-
if (s.state === "done") throw new Error("That pairing already finished.");
|
|
4129
|
-
if (s.state === "confirm" && s.sas) return {
|
|
4130
|
-
words: wordsOf(s.sas),
|
|
4131
|
-
expiresAt,
|
|
4132
|
-
...s.peer ? { peerName: s.peer.name } : {}
|
|
4133
|
-
};
|
|
4134
|
-
await sleep(poll);
|
|
4135
|
-
s = await client["devices.pairStatus"]({ pairingId: s.pairingId });
|
|
4136
|
-
}
|
|
4137
|
-
throw new Error("Nobody joined in time. Start again on both machines.");
|
|
4138
|
-
}
|
|
4139
|
-
/** Where the pairing stands now. */
|
|
4140
|
-
async function pairStatus(client) {
|
|
4141
|
-
const pairingId = current.get(client);
|
|
4142
|
-
if (!pairingId) return void 0;
|
|
4143
|
-
return client["devices.pairStatus"]({ pairingId });
|
|
4144
|
-
}
|
|
4145
|
-
/** Stop pairing: nothing gets linked. A no-op when no pairing is running. */
|
|
4146
|
-
async function cancelPair(client) {
|
|
4147
|
-
if (!current.has(client)) return;
|
|
4148
|
-
await confirmPair(client, false);
|
|
4149
|
-
}
|
|
4150
|
-
/**
|
|
4151
|
-
* `match` false: stop, nothing gets linked. `match` true: `code` is what the other machine
|
|
4152
|
-
* shows, as the owner typed it. Throws with the daemon's words when the code is wrong.
|
|
4153
|
-
*/
|
|
4154
|
-
async function confirmPair(client, match, code) {
|
|
4155
|
-
const pairingId = current.get(client);
|
|
4156
|
-
if (!pairingId) throw new Error("No pairing is running.");
|
|
4157
|
-
const s = await client["devices.pairConfirm"]({
|
|
4158
|
-
pairingId,
|
|
4159
|
-
accept: match,
|
|
4160
|
-
...match && code ? { code } : {}
|
|
4161
|
-
});
|
|
4162
|
-
if (!match) {
|
|
4163
|
-
current.delete(client);
|
|
4164
|
-
return s;
|
|
4165
|
-
}
|
|
4166
|
-
if (s.state === "confirm") throw new Error(s.error ?? "That is not the code the other machine shows.");
|
|
4167
|
-
if (s.state === "failed") throw new Error(s.error ?? "The pairing failed.");
|
|
4168
|
-
if (s.state === "done") current.delete(client);
|
|
4169
|
-
return s;
|
|
4170
|
-
}
|
|
4171
|
-
// src/tui/store.ts
|
|
4172
|
-
/**
|
|
4173
|
-
* The app's data layer: one daemon connection, the state the screens read, and every action they
|
|
4174
|
-
* can take. It loads once, then follows `events.subscribe` and polls what has no event (sync and
|
|
4175
|
-
* devices). When the daemon goes away it says so and reconnects with a growing wait.
|
|
4176
|
-
*/
|
|
4177
|
-
const POLL_MS = 15e3;
|
|
4178
|
-
const WATCH_MS = 5e3;
|
|
4179
|
-
const STOP_WAIT_MS = 1e4;
|
|
4180
|
-
const BACKOFF_MS = [
|
|
4181
|
-
500,
|
|
4182
|
-
1e3,
|
|
4183
|
-
2e3,
|
|
4184
|
-
4e3,
|
|
4185
|
-
8e3
|
|
4186
|
-
];
|
|
4187
|
-
const initial = () => ({
|
|
4188
|
-
connection: "connecting",
|
|
4189
|
-
sessions: []
|
|
4190
|
-
});
|
|
4191
|
-
const reason = (e) => e instanceof Error ? e.message : String(e);
|
|
4192
|
-
function upsert(list, item) {
|
|
4193
|
-
const i = list.findIndex((x) => x.id === item.id);
|
|
4194
|
-
if (i < 0) return [...list, item];
|
|
4195
|
-
const next = list.slice();
|
|
4196
|
-
next[i] = item;
|
|
4197
|
-
return next;
|
|
4198
|
-
}
|
|
4199
|
-
/** Only sessions that are online show in the app. */
|
|
4200
|
-
const online = (list) => list.filter((s) => s.status !== "offline");
|
|
4201
|
-
async function createStore(ctx, opts = {}) {
|
|
4202
|
-
const open = opts.connect ?? (() => ctx.connect(connectOpts(ctx, true)));
|
|
4203
|
-
const backoff = opts.backoffMs ?? BACKOFF_MS;
|
|
4204
|
-
let state = initial();
|
|
4205
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
4206
|
-
let client;
|
|
4207
|
-
let offEvent;
|
|
4208
|
-
let closed = false;
|
|
4209
|
-
let reconnecting = false;
|
|
4210
|
-
const timers = /* @__PURE__ */ new Set();
|
|
4211
|
-
const set = (patch) => {
|
|
4212
|
-
state = {
|
|
4213
|
-
...state,
|
|
4214
|
-
...patch
|
|
4215
|
-
};
|
|
4216
|
-
for (const l of [...listeners]) l();
|
|
4217
|
-
};
|
|
4218
|
-
const live = () => {
|
|
4219
|
-
if (!client || state.connection === "daemon-down") throw new Error("Conveno's background service is not running right now. Trying to reconnect.");
|
|
4220
|
-
return client;
|
|
4221
|
-
};
|
|
4222
|
-
function applyEvent(e) {
|
|
4223
|
-
switch (e.event) {
|
|
4224
|
-
case "session.updated": {
|
|
4225
|
-
const s = e.data.session;
|
|
4226
|
-
if (e.data.change === "unregistered" || s.status === "offline") set({ sessions: state.sessions.filter((x) => x.id !== s.id) });
|
|
4227
|
-
else set({ sessions: upsert(state.sessions, s) });
|
|
4228
|
-
break;
|
|
4229
|
-
}
|
|
4230
|
-
case "orchestrator.changed": {
|
|
4231
|
-
const id = e.data.orchestrator;
|
|
4232
|
-
set({ sessions: state.sessions.map((s) => ({
|
|
4233
|
-
...s,
|
|
4234
|
-
isOrchestrator: s.id === id
|
|
4235
|
-
})) });
|
|
4236
|
-
break;
|
|
4237
|
-
}
|
|
4238
|
-
}
|
|
4239
|
-
}
|
|
4240
|
-
async function pollRelay(c) {
|
|
4241
|
-
const [relay, devices] = await Promise.all([c["relay.status"]({}).catch(() => void 0), c["devices.list"]({}).catch(() => void 0)]);
|
|
4242
|
-
const patch = {};
|
|
4243
|
-
if (relay) patch.relay = relay;
|
|
4244
|
-
if (devices) patch.devices = devices;
|
|
4245
|
-
if (relay || devices || state.relay || state.devices) set(patch);
|
|
4246
|
-
}
|
|
4247
|
-
async function loadAccount() {
|
|
4248
|
-
const file = dataPaths(ctx.platform, ctx.dataDir).account;
|
|
4249
|
-
const tokens = await readAccountTokens(file).catch(() => void 0);
|
|
4250
|
-
if (!tokens) return set({ account: { signedIn: false } });
|
|
4251
|
-
set({ account: { signedIn: true } });
|
|
4252
|
-
try {
|
|
4253
|
-
const s = await fetchAccountStatus(tokens.refreshToken, {
|
|
4254
|
-
apiBase: ctx.env.CONVENO_API_URL || "https://api.conveno.dev",
|
|
4255
|
-
now: () => ctx.now().getTime()
|
|
4256
|
-
});
|
|
4257
|
-
set({ account: {
|
|
4258
|
-
signedIn: true,
|
|
4259
|
-
plan: s.plan,
|
|
4260
|
-
...s.status === "trialing" && s.trialDaysLeft !== null && s.trialDaysLeft !== void 0 ? { trialDaysLeft: s.trialDaysLeft } : {}
|
|
4261
|
-
} });
|
|
4262
|
-
} catch {}
|
|
4263
|
-
}
|
|
4264
|
-
async function loadSetupData() {
|
|
4265
|
-
try {
|
|
4266
|
-
set({ setup: await loadSetup(ctx) });
|
|
4267
|
-
} catch {}
|
|
4268
|
-
}
|
|
4269
|
-
/** Everything the screens need, in one pass. Safe to call again after a reconnect. */
|
|
4270
|
-
async function load(c) {
|
|
4271
|
-
const r = await c["session.list"]({});
|
|
4272
|
-
set({ sessions: online(r.sessions) });
|
|
4273
|
-
}
|
|
4274
|
-
async function attach(c) {
|
|
4275
|
-
client = c;
|
|
4276
|
-
offEvent?.();
|
|
4277
|
-
offEvent = c.onEvent(applyEvent);
|
|
4278
|
-
await c["events.subscribe"]({});
|
|
4279
|
-
await load(c);
|
|
4280
|
-
await pollRelay(c);
|
|
4281
|
-
set({ connection: "ready" });
|
|
4282
|
-
}
|
|
4283
|
-
async function reconnect() {
|
|
4284
|
-
if (reconnecting || closed) return;
|
|
4285
|
-
reconnecting = true;
|
|
4286
|
-
if (state.connection !== "daemon-down") set({
|
|
4287
|
-
connection: "daemon-down",
|
|
4288
|
-
connectionDetail: "The background service stopped. Trying again."
|
|
4289
|
-
});
|
|
4290
|
-
const old = client;
|
|
4291
|
-
client = void 0;
|
|
4292
|
-
offEvent?.();
|
|
4293
|
-
offEvent = void 0;
|
|
4294
|
-
old?.close().catch(() => void 0);
|
|
4295
|
-
for (let attempt = 0; !closed; attempt++) {
|
|
4296
|
-
await new Promise((r) => setTimeout(r, backoff[Math.min(attempt, backoff.length - 1)] ?? 1e3));
|
|
4297
|
-
if (closed) break;
|
|
4298
|
-
try {
|
|
4299
|
-
await attach(await open());
|
|
4300
|
-
const { connectionDetail: _gone, ...rest } = state;
|
|
4301
|
-
state = rest;
|
|
4302
|
-
set({});
|
|
4303
|
-
break;
|
|
4304
|
-
} catch (e) {
|
|
4305
|
-
set({
|
|
4306
|
-
connection: "daemon-down",
|
|
4307
|
-
connectionDetail: reason(e)
|
|
4308
|
-
});
|
|
4309
|
-
}
|
|
4310
|
-
}
|
|
4311
|
-
reconnecting = false;
|
|
4312
|
-
}
|
|
4313
|
-
/** A cheap call that tells us the daemon is still there, and fixes any events we missed. */
|
|
4314
|
-
async function watch() {
|
|
4315
|
-
const c = client;
|
|
4316
|
-
if (!c || reconnecting || closed) return;
|
|
4317
|
-
try {
|
|
4318
|
-
const r = await c["session.list"]({});
|
|
4319
|
-
set({ sessions: online(r.sessions) });
|
|
4320
|
-
} catch {
|
|
4321
|
-
reconnect();
|
|
4322
|
-
}
|
|
4323
|
-
}
|
|
4324
|
-
const nameOf = (id) => state.sessions.find((s) => s.id === id)?.name;
|
|
4325
|
-
const actions = {
|
|
4326
|
-
async send(to, text) {
|
|
4327
|
-
await live()["owner.send"]({
|
|
4328
|
-
to,
|
|
4329
|
-
text
|
|
4330
|
-
});
|
|
4331
|
-
},
|
|
4332
|
-
async setLead(sessionId) {
|
|
4333
|
-
await live()["orchestrator.claim"]({ sessionId });
|
|
4334
|
-
set({ sessions: state.sessions.map((s) => ({
|
|
4335
|
-
...s,
|
|
4336
|
-
isOrchestrator: s.id === sessionId
|
|
4337
|
-
})) });
|
|
4338
|
-
},
|
|
4339
|
-
async clearLead() {
|
|
4340
|
-
await live()["orchestrator.clear"]({});
|
|
4341
|
-
set({ sessions: state.sessions.map((s) => ({
|
|
4342
|
-
...s,
|
|
4343
|
-
isOrchestrator: false
|
|
4344
|
-
})) });
|
|
4345
|
-
},
|
|
4346
|
-
async stop(sessionId) {
|
|
4347
|
-
const name = nameOf(sessionId);
|
|
4348
|
-
const rec = name ? readSpawnRecord(spawnRecordPath(ctx.dataDir, name)) : void 0;
|
|
4349
|
-
if (!name || !rec) throw new Error("Only sessions started from Conveno on this machine can be stopped here.");
|
|
4350
|
-
if (!rec.acp) throw new Error(`${name} runs in a window. Close it there.`);
|
|
4351
|
-
const alive = () => rec.pid !== void 0 && ctx.isAlive(rec.pid);
|
|
4352
|
-
writeFileSync(stopRequestPath(spawnRecordPath(ctx.dataDir, rec.name)), "", { mode: 384 });
|
|
4353
|
-
const end = Date.now() + STOP_WAIT_MS;
|
|
4354
|
-
while (alive() && Date.now() < end) await new Promise((r) => setTimeout(r, 100));
|
|
4355
|
-
if (alive() && rec.pid !== void 0) killProcessTree(rec.pid, ctx.platform);
|
|
4356
|
-
if (rec.agentPid !== void 0 && ctx.isAlive(rec.agentPid)) killProcessTree(rec.agentPid, ctx.platform);
|
|
4357
|
-
},
|
|
4358
|
-
async rename(sessionId, name) {
|
|
4359
|
-
const res = await live()["session.rename"]({
|
|
4360
|
-
sessionId,
|
|
4361
|
-
name
|
|
4362
|
-
});
|
|
4363
|
-
set({ sessions: upsert(state.sessions, res.session) });
|
|
4364
|
-
},
|
|
4365
|
-
async spawn(p) {
|
|
4366
|
-
const c = live();
|
|
4367
|
-
const runner = ctx.spawnRunner ?? [process.execPath, process.argv[1] ?? "conveno"];
|
|
4368
|
-
const deps = realSpawnDeps({
|
|
4369
|
-
platform: ctx.platform,
|
|
4370
|
-
env: ctx.env,
|
|
4371
|
-
home: ctx.home,
|
|
4372
|
-
dataDir: ctx.dataDir,
|
|
4373
|
-
client: c,
|
|
4374
|
-
runner
|
|
4375
|
-
});
|
|
4376
|
-
return { sessionId: (await spawnSession(deps, {
|
|
4377
|
-
cli: p.cli,
|
|
4378
|
-
callerCwd: ctx.cwd,
|
|
4379
|
-
cwd: p.cwd,
|
|
4380
|
-
name: p.name,
|
|
4381
|
-
task: p.prompt,
|
|
4382
|
-
window: p.window,
|
|
4383
|
-
confineToHome: false
|
|
4384
|
-
})).id };
|
|
4385
|
-
},
|
|
4386
|
-
async refreshSetup() {
|
|
4387
|
-
await loadSetupData();
|
|
4388
|
-
},
|
|
4389
|
-
planFix: (fixId) => planFix(ctx, fixId),
|
|
4390
|
-
async applyFix(fixId) {
|
|
4391
|
-
await applyFix(ctx, fixId);
|
|
4392
|
-
await loadSetupData();
|
|
4393
|
-
},
|
|
4394
|
-
getExtras: () => getExtras(ctx),
|
|
4395
|
-
async setHelpers(on) {
|
|
4396
|
-
setHelpers(ctx, on);
|
|
4397
|
-
},
|
|
4398
|
-
pair: async () => {
|
|
4399
|
-
const r = await startPair(live());
|
|
4400
|
-
return {
|
|
4401
|
-
words: r.words,
|
|
4402
|
-
expiresAt: r.expiresAt
|
|
4403
|
-
};
|
|
4404
|
-
},
|
|
4405
|
-
async pairStatus() {
|
|
4406
|
-
const s = await pairStatus(live());
|
|
4407
|
-
return s ? {
|
|
4408
|
-
state: s.state,
|
|
4409
|
-
...s.error ? { error: s.error } : {}
|
|
4410
|
-
} : void 0;
|
|
4411
|
-
},
|
|
4412
|
-
async confirmPair(code) {
|
|
4413
|
-
await confirmPair(live(), true, code);
|
|
4414
|
-
await pollRelay(live());
|
|
4415
|
-
},
|
|
4416
|
-
async cancelPair() {
|
|
4417
|
-
await cancelPair(live());
|
|
4418
|
-
},
|
|
4419
|
-
async revokeDevice(deviceId) {
|
|
4420
|
-
await live()["devices.revoke"]({ device: deviceId });
|
|
4421
|
-
await pollRelay(live());
|
|
4422
|
-
},
|
|
4423
|
-
async openAccountPage() {
|
|
4424
|
-
const base = ctx.env.CONVENO_API_URL || "https://api.conveno.dev";
|
|
4425
|
-
openInBrowser(ctx.platform, `${base}/account`);
|
|
4426
|
-
}
|
|
4427
|
-
};
|
|
4428
|
-
try {
|
|
4429
|
-
await attach(await open());
|
|
4430
|
-
} catch (e) {
|
|
4431
|
-
set({
|
|
4432
|
-
connection: "daemon-down",
|
|
4433
|
-
connectionDetail: reason(e)
|
|
4434
|
-
});
|
|
4435
|
-
reconnect();
|
|
4436
|
-
}
|
|
4437
|
-
if (!opts.skipExtras) {
|
|
4438
|
-
loadAccount();
|
|
4439
|
-
loadSetupData();
|
|
4440
|
-
}
|
|
4441
|
-
timers.add(setInterval(() => client && void pollRelay(client), opts.pollMs ?? POLL_MS));
|
|
4442
|
-
timers.add(setInterval(() => void watch(), opts.watchMs ?? WATCH_MS));
|
|
4443
|
-
for (const t of timers) t.unref();
|
|
4444
|
-
return {
|
|
4445
|
-
getState: () => state,
|
|
4446
|
-
subscribe(l) {
|
|
4447
|
-
listeners.add(l);
|
|
4448
|
-
return () => listeners.delete(l);
|
|
4449
|
-
},
|
|
4450
|
-
actions,
|
|
4451
|
-
async close() {
|
|
4452
|
-
closed = true;
|
|
4453
|
-
for (const t of timers) clearInterval(t);
|
|
4454
|
-
offEvent?.();
|
|
4455
|
-
await client?.close().catch(() => void 0);
|
|
4456
|
-
}
|
|
4457
|
-
};
|
|
4458
|
-
}
|
|
4459
|
-
// src/tui/run.tsx
|
|
4460
|
-
/** Opens the app: connects to the daemon, draws the screen and puts the terminal back on exit. */
|
|
4461
|
-
async function runTui(ctx) {
|
|
4462
|
-
let first;
|
|
4463
|
-
try {
|
|
4464
|
-
first = await ctx.connect(connectOpts(ctx, true));
|
|
4465
|
-
} catch (e) {
|
|
4466
|
-
const problem = daemonProblem(ctx.theme, e);
|
|
4467
|
-
return fail(ctx, {
|
|
4468
|
-
what: "Conveno can't start its background service",
|
|
4469
|
-
detail: [problem.why],
|
|
4470
|
-
fix: problem.fix,
|
|
4471
|
-
exit: 1,
|
|
4472
|
-
ref: "e_daemon"
|
|
4473
|
-
});
|
|
4474
|
-
}
|
|
4475
|
-
let used = false;
|
|
4476
|
-
const store = await createStore(ctx, { connect: () => {
|
|
4477
|
-
if (used) return ctx.connect(connectOpts(ctx, true));
|
|
4478
|
-
used = true;
|
|
4479
|
-
return Promise.resolve(first);
|
|
4480
|
-
} });
|
|
4481
|
-
const input = createMouseInput(ctx);
|
|
4482
|
-
try {
|
|
4483
|
-
await render(/* @__PURE__ */ jsx(App, {
|
|
4484
|
-
store,
|
|
4485
|
-
theme: uiThemeFrom(ctx.theme),
|
|
4486
|
-
mouse: input.hub
|
|
4487
|
-
}), {
|
|
4488
|
-
stdin: input.stdin,
|
|
4489
|
-
alternateScreen: true,
|
|
4490
|
-
exitOnCtrlC: false,
|
|
4491
|
-
patchConsole: true
|
|
4492
|
-
}).waitUntilExit();
|
|
4493
|
-
return 0;
|
|
4494
|
-
} catch (e) {
|
|
4495
|
-
return fail(ctx, {
|
|
4496
|
-
what: "The Conveno app stopped",
|
|
4497
|
-
detail: [e instanceof Error ? e.message : String(e)],
|
|
4498
|
-
fix: `Run ${cmd(ctx.theme, "conveno doctor")}, or use the commands, such as ${cmd(ctx.theme, "conveno status")}.`,
|
|
4499
|
-
exit: 1,
|
|
4500
|
-
ref: "e_internal"
|
|
4501
|
-
});
|
|
4502
|
-
} finally {
|
|
4503
|
-
input.dispose();
|
|
4504
|
-
await store.close();
|
|
4505
|
-
}
|
|
4506
|
-
}
|
|
4507
|
-
export { runTui };
|