@conveno/cli 0.2.0-rc.5 → 0.2.0-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,17 @@
1
1
  import { Box, Text, render, useApp, useInput, useStdin, useWindowSize } from "ink";
2
- import { n as connectOpts, t as adapterEnv } from "./ctx-CDLE-2f2.js";
3
- import { b as openInBrowser, g as PAIR_TIMEOUT_MS, h as unifiedDiff, l as StaleError, r as collectPlans, t as inspect, u as applyChanges, y as daemonProblem } from "./doctor-CzIGTeNT.js";
4
- import { d as plainError, l as fail, m as tilde, o as cmd } from "./args-BRB8QEQM.js";
5
- import { createContext, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState, useSyncExternalStore } from "react";
2
+ import { n as connectOpts, t as adapterEnv } from "./ctx-tYftvhz_.js";
3
+ import { t as daemonProblem } from "./daemonError-CdLataBW.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
6
  import { readFileSync, readdirSync, writeFileSync } from "node:fs";
7
7
  import { Readable } from "node:stream";
8
- import { D as compatStatus, Dt as readAccountTokens, Fn as isLeadAlias, Ft as realSpawnDeps, G as fetchAccountStatus, Gt as spawnRecordPath, Kt as spawnSession, Mt as readSettings, N as dataPaths, Nt as readSpawnRecord, l as SPAWN_TABLE, on as writeSettings, pt as notifyForcedOff, vn as OWNER_SESSION_ID, yn as PERMISSION_ANSWERS } from "./dist-TrWRppjR.js";
8
+ import { E as compatStatus, Ft as spawnSession, H as fetchAccountStatus, Kt as writeSettings, M as dataPaths, Pt as spawnRecordPath, St as realSpawnDeps, bt as readSettings, gt as readAccountTokens, xt as readSpawnRecord } from "./dist-BTLBO1Rp.js";
9
9
  import { homedir } from "node:os";
10
10
  import { i as tokens, n as detectColorLevel, r as detectUnicode } from "./dist-BRjg9CLd.js";
11
11
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
12
  import { basename, join, resolve } from "node:path";
13
- import { i as stopRequestPath, t as killProcessTree } from "./dist-BPPOKmbH.js";
13
+ import { r as stopRequestPath, t as killProcessTree } from "./dist-BAlMjYqQ.js";
14
+ import { g as PAIR_TIMEOUT_MS, h as unifiedDiff, l as StaleError, r as collectPlans, t as inspect, u as applyChanges, y as openInBrowser } from "./doctor-DjwXJvKw.js";
14
15
  // \0rolldown/runtime.js
15
16
  var __defProp = Object.defineProperty;
16
17
  var __exportAll = (all, flags) => {
@@ -35,24 +36,19 @@ const SCREENS = [
35
36
  key: "1",
36
37
  title: "Sessions"
37
38
  },
38
- {
39
- id: "you",
40
- key: "2",
41
- title: "You"
42
- },
43
39
  {
44
40
  id: "new",
45
- key: "3",
41
+ key: "2",
46
42
  title: "New"
47
43
  },
48
44
  {
49
45
  id: "devices",
50
- key: "4",
46
+ key: "3",
51
47
  title: "Devices"
52
48
  },
53
49
  {
54
50
  id: "setup",
55
- key: "5",
51
+ key: "4",
56
52
  title: "Setup"
57
53
  }
58
54
  ];
@@ -684,17 +680,6 @@ function relTime(iso, now = Date.now()) {
684
680
  const d = Math.floor(h / 24);
685
681
  return d === 1 ? "1 day ago" : `${d} days ago`;
686
682
  }
687
- /** "now", "3m", "2h", "4d": always short enough for a narrow column. */
688
- function relCompact(iso, now = Date.now()) {
689
- const t = Date.parse(iso);
690
- if (Number.isNaN(t)) return "";
691
- const m = Math.floor(Math.max(0, now - t) / 6e4);
692
- if (m < 1) return "now";
693
- if (m < 60) return `${m}m`;
694
- const h = Math.floor(m / 60);
695
- if (h < 24) return `${h}h`;
696
- return `${Math.floor(h / 24)}d`;
697
- }
698
683
  /**
699
684
  * The home folder as `~`. Knows this machine's home and the usual homes of other machines:
700
685
  * `/home/x`, `/Users/x`, and `C:\Users\x` or `C:/Users/x` in any case. Separators stay as given.
@@ -902,84 +887,6 @@ function ScrollList({ items, selected, height, renderItem, keyOf, onSelect, onAc
902
887
  });
903
888
  }
904
889
  /**
905
- * Text that scrolls by line. Each entry of `lines` is exactly one row (cut or wrapped by the
906
- * caller). The wheel scrolls it while the pointer is over it; PgUp/PgDn/Home/End scroll it while
907
- * `isActive`. With `stickToBottom` it follows new lines while you are at the bottom and stays put
908
- * once you scroll up. `onAtBottomChange` says when you are at the bottom or not, and `handleRef`
909
- * lets the screen jump to the newest line ("↓ 3 new").
910
- */
911
- function ScrollView({ lines, height, stickToBottom = false, isActive = true, onAtBottomChange, onReachTop, handleRef, wheelStep = 3 }) {
912
- const box = useRef(null);
913
- const h = Math.max(1, height);
914
- const max = Math.max(0, lines.length - h);
915
- const [pos, setPos] = useState({
916
- top: 0,
917
- pinned: true
918
- });
919
- const top = stickToBottom && pos.pinned ? max : Math.min(pos.top, max);
920
- const atBottom = top >= max;
921
- const cur = useRef({
922
- top,
923
- max,
924
- h
925
- });
926
- cur.current = {
927
- top,
928
- max,
929
- h
930
- };
931
- const moveTo = (to) => {
932
- const n = Math.max(0, Math.min(cur.current.max, to));
933
- cur.current.top = n;
934
- setPos({
935
- top: n,
936
- pinned: n >= cur.current.max
937
- });
938
- return n;
939
- };
940
- const reach = useRef(onReachTop);
941
- reach.current = onReachTop;
942
- const up = (to) => {
943
- if (moveTo(to) === 0) reach.current?.();
944
- };
945
- const by = (d) => d < 0 ? up(cur.current.top + d) : void moveTo(cur.current.top + d);
946
- useImperativeHandle(handleRef, () => ({
947
- scrollToBottom: () => void moveTo(Number.POSITIVE_INFINITY),
948
- scrollToTop: () => void moveTo(0),
949
- scrollBy: (n) => {
950
- const t = Math.max(0, cur.current.top + n);
951
- cur.current.top = t;
952
- setPos({
953
- top: t,
954
- pinned: false
955
- });
956
- }
957
- }));
958
- useWheel(box, (d) => by(d * wheelStep), { isActive });
959
- useInput((_input, key) => {
960
- if (key.pageUp) by(-Math.max(1, cur.current.h - 1));
961
- else if (key.pageDown) by(Math.max(1, cur.current.h - 1));
962
- else if (key.home) up(0);
963
- else if (key.end) moveTo(Number.POSITIVE_INFINITY);
964
- }, { isActive });
965
- const told = useRef(void 0);
966
- useEffect(() => {
967
- if (told.current === atBottom) return;
968
- told.current = atBottom;
969
- onAtBottomChange?.(atBottom);
970
- });
971
- return /* @__PURE__ */ jsx(Box, {
972
- ref: box,
973
- flexDirection: "column",
974
- height: h,
975
- overflow: "hidden",
976
- children: lines.slice(top, top + h).map((line, i) => /* @__PURE__ */ jsx(Box, {
977
- flexShrink: 0,
978
- children: typeof line === "string" ? /* @__PURE__ */ jsx(Text, { children: line }) : line
979
- }, top + i))
980
- });
981
- }
982
- /**
983
890
  * The shell provides this. A text box with unsent text tells it when Ctrl+C cleared that text,
984
891
  * so the shell shows a hint instead of quitting.
985
892
  */
@@ -1190,7 +1097,7 @@ function Help({ screenTitle, screenKeys, width, onClose }) {
1190
1097
  });
1191
1098
  const global = [
1192
1099
  {
1193
- key: "1-5",
1100
+ key: "1-4",
1194
1101
  label: "go to a screen"
1195
1102
  },
1196
1103
  {
@@ -1925,15 +1832,14 @@ function DevicesScreen(props) {
1925
1832
  return showPair ? pairPanel(Math.min(columns - 2, 70)) : table;
1926
1833
  }
1927
1834
  // src/tui/screens/new.tsx
1928
- /** Screen 3: Start a new worker. */
1835
+ /** Screen 2: Start a new worker. */
1929
1836
  var new_exports = /* @__PURE__ */ __exportAll({
1930
1837
  completeDir: () => completeDir,
1931
1838
  default: () => NewScreen,
1932
1839
  expandPath: () => expandPath,
1933
1840
  shortPath: () => shortPath,
1934
1841
  spawnCommand: () => spawnCommand,
1935
- suggestName: () => suggestName,
1936
- supportsAlwaysOn: () => supportsAlwaysOn
1842
+ suggestName: () => suggestName
1937
1843
  });
1938
1844
  /** `~/code/api` to an absolute path. */
1939
1845
  function expandPath(input, home, cwd) {
@@ -1986,40 +1892,16 @@ function spawnCommand(p) {
1986
1892
  quote(p.folder)
1987
1893
  ];
1988
1894
  if (p.name) parts.push("--name", quote(p.name));
1989
- if (p.mode === "acp") parts.push("--acp");
1990
- if (p.mode === "headless") parts.push("--headless", "--one-shot");
1895
+ if (p.window) parts.push("--window");
1991
1896
  if (p.task.trim()) parts.push("--task", quote(p.task.trim().replace(/\s*\n\s*/g, " ")));
1992
- const lines = [parts.join(" ")];
1993
- if (p.auto) lines.push(`conveno auto on ${p.name || "<name>"}`);
1994
- return lines;
1897
+ return [parts.join(" ")];
1995
1898
  }
1996
- /** Can this CLI be driven in the background and kept running (the ACP route)? */
1997
- const supportsAlwaysOn = (cli) => Boolean(SPAWN_TABLE[cli]?.acp);
1998
- const needsHelper = (cli) => Boolean(SPAWN_TABLE[cli]?.acp?.adapterPackage);
1999
- const MODES = [
2000
- {
2001
- id: "acp",
2002
- title: "Always on",
2003
- hint: "wakes up whenever it gets a message"
2004
- },
2005
- {
2006
- id: "visible",
2007
- title: "In a new window",
2008
- hint: "you can watch it work"
2009
- },
2010
- {
2011
- id: "headless",
2012
- title: "One task",
2013
- hint: "does the job, then stops"
2014
- }
2015
- ];
2016
1899
  const ORDER = [
2017
1900
  "cli",
2018
1901
  "folder",
2019
- "mode",
2020
1902
  "name",
2021
1903
  "task",
2022
- "auto"
1904
+ "window"
2023
1905
  ];
2024
1906
  const TEXT_FIELDS = [
2025
1907
  "folder",
@@ -2037,16 +1919,13 @@ function NewScreen(props) {
2037
1919
  const [cliIx, setCliIx] = useState(0);
2038
1920
  const [folder, setFolder] = useState(shortPath(cwd, home));
2039
1921
  const [folderKey, setFolderKey] = useState(0);
2040
- const [modeIx, setModeIx] = useState(1);
2041
1922
  const [name, setName] = useState("");
2042
1923
  const [task, setTask] = useState("");
2043
- const [auto, setAuto] = useState(false);
1924
+ const [inWindow, setInWindow] = useState(false);
2044
1925
  const [busy, setBusy] = useState(false);
2045
1926
  const [error, setError] = useState();
2046
1927
  const asked = useRef(false);
2047
1928
  const cli = installed[Math.min(cliIx, installed.length - 1)];
2048
- const modes = useMemo(() => MODES.filter((x) => x.id !== "acp" || (cli ? supportsAlwaysOn(cli.cli) : false)), [cli]);
2049
- const mode = modes[Math.min(modeIx, modes.length - 1)]?.id ?? "visible";
2050
1929
  const suggested = cli ? suggestName(cli.cli, folder) : "";
2051
1930
  const finalName = name.trim() || suggested;
2052
1931
  const typing = TEXT_FIELDS.includes(field);
@@ -2073,7 +1952,7 @@ function NewScreen(props) {
2073
1952
  },
2074
1953
  {
2075
1954
  key: "Space",
2076
- label: "choose"
1955
+ label: "tick"
2077
1956
  },
2078
1957
  {
2079
1958
  key: m.enter,
@@ -2087,21 +1966,16 @@ function NewScreen(props) {
2087
1966
  }, [setKeys, m.enter]);
2088
1967
  const start = useCallback(async () => {
2089
1968
  if (busy) return;
2090
- if (!cli) return setError("No CLI found yet. Set one up on screen 5.");
2091
- if (mode === "headless" && !task.trim()) {
2092
- setField("task");
2093
- return setError("Say what the task is. A one-task worker stops when it's done.");
2094
- }
1969
+ if (!cli) return setError("No CLI found yet. Set one up on screen 4.");
2095
1970
  setError(void 0);
2096
1971
  setBusy(true);
2097
1972
  try {
2098
1973
  const res = await actions.spawn({
2099
1974
  cli: cli.cli,
2100
1975
  cwd: expandPath(folder, home, cwd),
2101
- mode,
1976
+ window: inWindow,
2102
1977
  name: finalName,
2103
- prompt: task.trim(),
2104
- auto
1978
+ prompt: task.trim()
2105
1979
  });
2106
1980
  toast(`Started ${finalName}`, "ok");
2107
1981
  if (res.sessionId) go("sessions", res.sessionId);
@@ -2113,14 +1987,13 @@ function NewScreen(props) {
2113
1987
  }, [
2114
1988
  busy,
2115
1989
  cli,
2116
- mode,
2117
1990
  task,
2118
1991
  actions,
2119
1992
  folder,
2120
1993
  home,
2121
1994
  cwd,
2122
1995
  finalName,
2123
- auto,
1996
+ inWindow,
2124
1997
  toast,
2125
1998
  go
2126
1999
  ]);
@@ -2158,14 +2031,8 @@ function NewScreen(props) {
2158
2031
  if (key.return) return move(1);
2159
2032
  return;
2160
2033
  }
2161
- if (field === "mode") {
2162
- if (key.upArrow) return setModeIx(Math.max(0, modeIx - 1));
2163
- if (key.downArrow) return setModeIx(Math.min(modes.length - 1, modeIx + 1));
2164
- if (key.return) return move(1);
2165
- return;
2166
- }
2167
- if (field === "auto") {
2168
- if (input === " ") return setAuto(!auto);
2034
+ if (field === "window") {
2035
+ if (input === " ") return setInWindow(!inWindow);
2169
2036
  if (key.upArrow) return move(-1);
2170
2037
  if (key.return) return void start();
2171
2038
  return;
@@ -2200,18 +2067,13 @@ function NewScreen(props) {
2200
2067
  children: `${field === f ? m.cursor : " "} ${text.toUpperCase()}`
2201
2068
  })
2202
2069
  });
2203
- const steps = [
2204
- ...mode === "acp" && cli && needsHelper(cli.cli) ? [{ text: `getting the ${cli.label} helper (first time only)` }] : [],
2205
- { text: `${finalName || "your worker"} is ready` },
2206
- { text: "waiting for its first reply" }
2207
- ];
2070
+ const steps = [{ text: `${finalName || "your worker"} is ready` }, { text: "waiting for its first reply" }];
2208
2071
  const cmdLines = cli ? spawnCommand({
2209
2072
  cli: cli.cli,
2210
2073
  folder,
2211
- mode,
2074
+ window: inWindow,
2212
2075
  name: finalName,
2213
- task,
2214
- auto
2076
+ task
2215
2077
  }) : [];
2216
2078
  return /* @__PURE__ */ jsxs(Box, {
2217
2079
  flexDirection: "row",
@@ -2222,7 +2084,7 @@ function NewScreen(props) {
2222
2084
  flexShrink: 0,
2223
2085
  children: installed.length === 0 ? /* @__PURE__ */ jsx(Text, {
2224
2086
  dimColor: true,
2225
- children: state.setup ? "No CLI found. Set one up on screen 5 first." : `Looking for your CLIs${m.ellipsis}`
2087
+ children: state.setup ? "No CLI found. Set one up on screen 4 first." : `Looking for your CLIs${m.ellipsis}`
2226
2088
  }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2227
2089
  label("cli", "CLI"),
2228
2090
  /* @__PURE__ */ jsx(Box, {
@@ -2248,28 +2110,6 @@ function NewScreen(props) {
2248
2110
  focus: active && field === "folder",
2249
2111
  placeholder: "~/code/my-project"
2250
2112
  }, folderKey)),
2251
- label("mode", "How it runs"),
2252
- /* @__PURE__ */ jsx(Box, {
2253
- flexDirection: "column",
2254
- marginLeft: 2,
2255
- children: modes.map((x, i) => /* @__PURE__ */ jsx(Hit, {
2256
- onClick: () => {
2257
- if (busy) return;
2258
- setModeIx(i);
2259
- setField("mode");
2260
- },
2261
- children: /* @__PURE__ */ jsxs(Text, {
2262
- wrap: "truncate-end",
2263
- children: [/* @__PURE__ */ jsx(Text, {
2264
- ...i === modeIx && field === "mode" ? { bold: true } : {},
2265
- children: `${i === modeIx ? m.radioOn : m.radioOff} ${x.title}`
2266
- }), /* @__PURE__ */ jsx(Text, {
2267
- dimColor: true,
2268
- children: ` ${x.hint}`
2269
- })]
2270
- })
2271
- }, x.id))
2272
- }),
2273
2113
  label("name", "Name"),
2274
2114
  field_("name", /* @__PURE__ */ jsx(TextBox, {
2275
2115
  value: name,
@@ -2285,17 +2125,17 @@ function NewScreen(props) {
2285
2125
  onSubmit: () => void start(),
2286
2126
  focus: active && field === "task",
2287
2127
  multiline: true,
2288
- placeholder: mode === "headless" ? "What should it do?" : "What should it start on? (optional)"
2128
+ placeholder: "What should it start on? (optional)"
2289
2129
  })),
2290
- label("auto", "Auto"),
2130
+ label("window", "Where"),
2291
2131
  /* @__PURE__ */ jsx(Hit, {
2292
2132
  marginLeft: 2,
2293
2133
  onClick: () => {
2294
2134
  if (busy) return;
2295
- setField("auto");
2296
- setAuto(!auto);
2135
+ setField("window");
2136
+ setInWindow(!inWindow);
2297
2137
  },
2298
- children: /* @__PURE__ */ jsx(Text, { children: `${auto ? "[x]" : "[ ]"} reply on its own, without waiting for you` })
2138
+ children: /* @__PURE__ */ jsx(Text, { children: `${inWindow ? "[x]" : "[ ]"} in a window, so you can watch it` })
2299
2139
  }),
2300
2140
  /* @__PURE__ */ jsx(Text, { children: " " }),
2301
2141
  busy ? /* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Spinner, { tick }), ` Starting ${finalName}${m.ellipsis}`] }) : /* @__PURE__ */ jsxs(Box, { children: [
@@ -2353,528 +2193,19 @@ function NewScreen(props) {
2353
2193
  }) : null]
2354
2194
  });
2355
2195
  }
2356
- // src/tui/screens/session-view.tsx
2357
- /** One session, opened from the Sessions screen: Chat, Live view and Info. */
2358
- /** `10:41` in local time. */
2359
- function clockTime(iso) {
2360
- const d = new Date(iso);
2361
- if (Number.isNaN(d.getTime())) return "";
2362
- return `${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`;
2363
- }
2364
- /** "41m ago", "just now". */
2365
- function agoText(iso) {
2366
- const r = relTime(iso);
2367
- if (r === "") return "";
2368
- if (r === "now") return "just now";
2369
- return r.endsWith("ago") ? r : `${r} ago`;
2370
- }
2371
- /** The plain text of a message, whatever its kind. */
2372
- function messageText(m) {
2373
- switch (m.kind) {
2374
- case "text": return m.body.text;
2375
- case "question": return m.body.question;
2376
- case "answer": return m.body.response;
2377
- case "handoff": return `Handoff: ${m.body.goal}`;
2378
- case "system": return m.body.detail ? `${m.body.event}: ${m.body.detail}` : m.body.event;
2379
- }
2380
- }
2381
- const isFromOwner = (m) => m.from === OWNER_SESSION_ID;
2382
- /** Break text into lines of at most `width` characters. Keeps blank lines. */
2383
- function wrapLines(text, width) {
2384
- const w = Math.max(4, width);
2385
- const out = [];
2386
- for (const para of text.replace(/\r\n?/g, "\n").split("\n")) {
2387
- if (para === "") {
2388
- out.push("");
2389
- continue;
2390
- }
2391
- let line = "";
2392
- for (const word of para.split(/ +/)) {
2393
- let rest = word;
2394
- while ([...rest].length > w) {
2395
- if (line) {
2396
- out.push(line);
2397
- line = "";
2398
- }
2399
- const chars = [...rest];
2400
- out.push(chars.slice(0, w).join(""));
2401
- rest = chars.slice(w).join("");
2402
- }
2403
- if (line === "") line = rest;
2404
- else if ([...line].length + 1 + [...rest].length <= w) line += ` ${rest}`;
2405
- else {
2406
- out.push(line);
2407
- line = rest;
2408
- }
2409
- }
2410
- out.push(line);
2411
- }
2412
- return out;
2413
- }
2414
- function wakesUp(tier) {
2415
- switch (tier) {
2416
- case "live":
2417
- case "acp": return "any time it gets a message";
2418
- case "next_turn": return "when it finishes a step";
2419
- case "inbox": return "on its next prompt";
2420
- }
2421
- }
2422
- const quiet$2 = (c) => c.quiet ? { color: c.quiet } : { dimColor: true };
2423
- const TABS = [
2424
- {
2425
- id: "chat",
2426
- title: "Chat"
2427
- },
2428
- {
2429
- id: "live",
2430
- title: "Live view"
2431
- },
2432
- {
2433
- id: "info",
2434
- title: "Info"
2435
- }
2436
- ];
2437
- const PANEL_WIDTH = 44;
2438
- function SessionView(props) {
2439
- const { session, state, actions, layout, rows, columns, active, setTyping, toast, onClose } = props;
2440
- const { c, ascii } = useTheme();
2441
- const wide = layout === "wide";
2442
- const [tab, setTab] = useState("chat");
2443
- const [boxFocus, setBoxFocus] = useState(props.focusBox);
2444
- const [draft, setDraft] = useState("");
2445
- const [note, setNote] = useState("");
2446
- const sending = useRef(false);
2447
- const typing = active && tab === "chat" && boxFocus;
2448
- useEffect(() => {
2449
- setTyping(typing);
2450
- return () => setTyping(false);
2451
- }, [typing, setTyping]);
2452
- useEffect(() => {
2453
- actions.loadHistory(session.id).catch(() => void 0);
2454
- }, [actions, session.id]);
2455
- useInput((input, key) => {
2456
- if (key.escape) {
2457
- if (draft !== "") setDraft("");
2458
- else onClose();
2459
- return;
2460
- }
2461
- if (key.tab && !wide) {
2462
- const i = TABS.findIndex((t) => t.id === tab);
2463
- const next = TABS[(i + (key.shift ? TABS.length - 1 : 1)) % TABS.length];
2464
- if (next) setTab(next.id);
2465
- return;
2466
- }
2467
- if (!boxFocus && tab === "chat" && (key.return || input === "i")) setBoxFocus(true);
2468
- }, { isActive: active });
2469
- const send = (text) => {
2470
- const t = text.trim();
2471
- if (t === "" || sending.current) return;
2472
- sending.current = true;
2473
- actions.send(session.name, t).then(() => {
2474
- setDraft("");
2475
- setNote(session.status === "busy" ? "It gets this when it finishes its current step." : "");
2476
- toast(`Sent to ${session.name}`);
2477
- }).catch(() => toast("Couldn't send that. Try again.", "error")).finally(() => {
2478
- sending.current = false;
2479
- });
2480
- };
2481
- const where = session.remote ? session.deviceName ?? "another machine" : "this PC";
2482
- const starter = session.spawnedBy ? state.sessions.find((s) => s.id === session.spawnedBy)?.name ?? "another session" : "you";
2483
- const status = statusWord(session);
2484
- const sep = ascii ? " - " : " › ";
2485
- const right = `auto ${session.auto ? "on" : "off"} ${status.text}`;
2486
- const left = plain(`Sessions${sep}${session.name} ${chipText(session.cli)} · ${shortPath$1(session.cwd, 40, ascii)} · ${where} · started by ${starter}`, ascii);
2487
- const split = splitWidths(columns, wide, { panelW: PANEL_WIDTH });
2488
- const frameW = wide ? split.mainW + split.panelW : Math.min(columns, 130);
2489
- const headWidth = Math.max(10, frameW - right.length - 2);
2490
- const panelW = split.panelW;
2491
- const mainW = wide ? split.mainW - 2 : Math.min(columns, 130);
2492
- const boxLines = Math.max(1, Math.min(4, draft.split("\n").length));
2493
- const chrome = 1 + (wide ? 0 : 1) + 1 + boxLines + (note ? 1 : 0);
2494
- const chatH = Math.max(2, rows - chrome);
2495
- const chat = /* @__PURE__ */ jsxs(Box, {
2496
- flexDirection: "column",
2497
- width: mainW,
2498
- children: [
2499
- /* @__PURE__ */ jsx(ChatLines, {
2500
- session,
2501
- messages: state.history[session.id] ?? [],
2502
- width: mainW,
2503
- height: chatH,
2504
- active: active && tab === "chat",
2505
- more: state.historyMore[session.id] === true,
2506
- loadOlder: () => actions.loadOlder(session.id)
2507
- }),
2508
- /* @__PURE__ */ jsx(Rule, { width: mainW }),
2509
- /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Text, {
2510
- ...c.entry ? { color: c.entry } : {},
2511
- children: ascii ? "> " : "› "
2512
- }), /* @__PURE__ */ jsx(Box, {
2513
- width: Math.max(4, mainW - 2),
2514
- children: /* @__PURE__ */ jsx(TextBox, {
2515
- value: draft,
2516
- onChange: setDraft,
2517
- onSubmit: send,
2518
- focus: active && tab === "chat" && boxFocus,
2519
- onFocusRequest: () => setBoxFocus(true),
2520
- multiline: true,
2521
- placeholder: boxFocus ? `Message ${session.name}…` : `Press Enter to message ${session.name}`
2522
- })
2523
- })] }),
2524
- note ? /* @__PURE__ */ jsx(Ell, {
2525
- width: mainW,
2526
- color: c.info,
2527
- children: note
2528
- }) : null
2529
- ]
2530
- });
2531
- const bodyH = rows - 2;
2532
- return /* @__PURE__ */ jsxs(Box, {
2533
- flexDirection: "column",
2534
- width: columns,
2535
- children: [/* @__PURE__ */ jsxs(Box, {
2536
- width: frameW,
2537
- children: [
2538
- /* @__PURE__ */ jsx(Box, {
2539
- width: headWidth,
2540
- children: /* @__PURE__ */ jsx(Ell, {
2541
- width: headWidth,
2542
- bold: true,
2543
- children: left
2544
- })
2545
- }),
2546
- /* @__PURE__ */ jsx(Box, { flexGrow: 1 }),
2547
- /* @__PURE__ */ jsx(Text, {
2548
- ...statusColor(status.kind, c) ? { color: statusColor(status.kind, c) } : {},
2549
- children: right
2550
- })
2551
- ]
2552
- }), wide ? /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Box, {
2553
- width: split.mainW,
2554
- flexShrink: 0,
2555
- children: chat
2556
- }), /* @__PURE__ */ jsxs(Pane, {
2557
- width: panelW,
2558
- height: rows - 1,
2559
- children: [/* @__PURE__ */ jsx(LiveView, {
2560
- session,
2561
- actions,
2562
- active,
2563
- width: paneInner(panelW),
2564
- height: Math.max(4, Math.floor(bodyH / 2))
2565
- }), /* @__PURE__ */ jsx(Box, {
2566
- marginTop: 1,
2567
- flexDirection: "column",
2568
- children: /* @__PURE__ */ jsx(InfoPanel, {
2569
- session,
2570
- width: paneInner(panelW)
2571
- })
2572
- })]
2573
- })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2574
- /* @__PURE__ */ jsxs(Box, {
2575
- gap: 2,
2576
- children: [TABS.map((t) => /* @__PURE__ */ jsx(Hit, {
2577
- onClick: () => setTab(t.id),
2578
- isActive: active,
2579
- children: /* @__PURE__ */ jsx(Text, {
2580
- ...t.id === tab ? {
2581
- bold: true,
2582
- underline: true,
2583
- ...c.ink ? { color: c.ink } : {}
2584
- } : quiet$2(c),
2585
- children: t.title
2586
- })
2587
- }, t.id)), /* @__PURE__ */ jsx(Text, {
2588
- ...quiet$2(c),
2589
- children: "Tab switches"
2590
- })]
2591
- }),
2592
- tab === "chat" ? chat : null,
2593
- tab === "live" ? /* @__PURE__ */ jsx(LiveView, {
2594
- session,
2595
- actions,
2596
- active,
2597
- width: columns,
2598
- height: Math.max(3, rows - 2)
2599
- }) : null,
2600
- tab === "info" ? /* @__PURE__ */ jsx(InfoPanel, {
2601
- session,
2602
- width: columns
2603
- }) : null
2604
- ] })]
2605
- });
2606
- }
2607
- /** The word for a session's state. State is always in the word, never in colour alone. */
2608
- function statusWord(s) {
2609
- if (s.status === "offline") {
2610
- const r = relCompact(s.lastSeenAt);
2611
- return {
2612
- text: r === "" || r === "now" ? "offline" : `offline ${r}`,
2613
- kind: "offline"
2614
- };
2615
- }
2616
- if ((s.unreadCount ?? 0) > 0) return {
2617
- text: `${s.unreadCount} new`,
2618
- kind: "new"
2619
- };
2620
- if (s.status === "busy") return {
2621
- text: "working",
2622
- kind: "working"
2623
- };
2624
- if (s.status === "waiting_on_question") return {
2625
- text: "asking",
2626
- kind: "asking"
2627
- };
2628
- return {
2629
- text: "waiting",
2630
- kind: "waiting"
2631
- };
2632
- }
2633
- function statusColor(kind, c) {
2634
- if (kind === "new" || kind === "asking") return c.stamp;
2635
- if (kind === "working") return c.info;
2636
- return c.quiet;
2637
- }
2638
- function ChatLines({ session, messages, width, height, active, more, loadOlder }) {
2639
- const { c, ascii } = useTheme();
2640
- const mouse = useMouseEnabled();
2641
- const handle = useRef(null);
2642
- const [atBottom, setAtBottom] = useState(true);
2643
- const atBottomRef = useRef(true);
2644
- atBottomRef.current = atBottom;
2645
- const [seen, setSeen] = useState(void 0);
2646
- const { lines, sorted } = useMemo(() => {
2647
- const sorted = [...messages].sort((a, b) => a.createdAt.localeCompare(b.createdAt));
2648
- let lastMine = -1;
2649
- sorted.forEach((m, i) => {
2650
- if (isFromOwner(m)) lastMine = i;
2651
- });
2652
- const out = [];
2653
- if (more && sorted.length > 0) out.push({
2654
- key: "more",
2655
- text: "Scroll up for older messages",
2656
- own: false,
2657
- marker: true
2658
- });
2659
- sorted.forEach((m, i) => {
2660
- const own = isFromOwner(m);
2661
- const who = own ? "you" : m.fromName ?? session.name;
2662
- out.push({
2663
- key: `${m.id}h`,
2664
- text: `${clockTime(m.createdAt)} ${who}`,
2665
- own,
2666
- head: true
2667
- });
2668
- wrapLines(messageText(m), width).forEach((t, j) => {
2669
- out.push({
2670
- key: `${m.id}b${j}`,
2671
- text: t,
2672
- own
2673
- });
2674
- });
2675
- if (i === lastMine && (session.unreadCount ?? 0) === 0) out.push({
2676
- key: `${m.id}s`,
2677
- text: `${ascii ? "ok" : "✓"} seen`,
2678
- own: false,
2679
- tail: true
2680
- });
2681
- });
2682
- return {
2683
- lines: out,
2684
- sorted
2685
- };
2686
- }, [
2687
- messages,
2688
- more,
2689
- session.name,
2690
- session.unreadCount,
2691
- width,
2692
- ascii
2693
- ]);
2694
- const newest = sorted[sorted.length - 1];
2695
- useEffect(() => {
2696
- if (atBottom) setSeen(newest?.id);
2697
- }, [atBottom, newest?.id]);
2698
- useEffect(() => {
2699
- if (newest && isFromOwner(newest)) handle.current?.scrollToBottom();
2700
- }, [newest?.id, newest]);
2701
- const seenAt = seen === void 0 ? -1 : sorted.findIndex((m) => m.id === seen);
2702
- const fresh = atBottom || seenAt < 0 ? 0 : sorted.slice(seenAt + 1).filter((m) => !isFromOwner(m)).length;
2703
- const first = useRef(void 0);
2704
- useEffect(() => {
2705
- const real = lines.find((l) => !l.marker);
2706
- const prev = first.current;
2707
- if (!real) {
2708
- first.current = void 0;
2709
- return;
2710
- }
2711
- first.current = {
2712
- key: real.key,
2713
- at: lines.indexOf(real)
2714
- };
2715
- if (!prev || prev.key === real.key || atBottomRef.current) return;
2716
- const was = lines.findIndex((l) => l.key === prev.key);
2717
- if (was > prev.at) handle.current?.scrollBy(was - prev.at);
2718
- }, [lines]);
2719
- const loading = useRef(false);
2720
- const reachTop = useCallback(() => {
2721
- if (!more || loading.current) return;
2722
- loading.current = true;
2723
- loadOlder().catch(() => false).finally(() => {
2724
- loading.current = false;
2725
- });
2726
- }, [more, loadOlder]);
2727
- if (lines.length === 0) return /* @__PURE__ */ jsx(Box, {
2728
- height,
2729
- children: /* @__PURE__ */ jsx(Text, {
2730
- ...quiet$2(c),
2731
- children: "No messages yet. Type one below."
2732
- })
2733
- });
2734
- const room = fresh > 0 ? Math.max(1, height - 1) : height;
2735
- const rows = lines.map((l) => /* @__PURE__ */ jsx(Ell, {
2736
- width,
2737
- color: l.own ? c.entry : l.head || l.tail || l.marker ? c.quiet : void 0,
2738
- ...l.head || l.tail || l.marker ? { dim: !c.quiet } : {},
2739
- children: l.text === "" ? " " : l.text
2740
- }, l.key));
2741
- const padded = [...Array.from({ length: Math.max(0, room - rows.length) }, (_, i) => /* @__PURE__ */ jsx(Text, { children: " " }, `pad${i}`)), ...rows];
2742
- return /* @__PURE__ */ jsxs(Box, {
2743
- flexDirection: "column",
2744
- height,
2745
- children: [/* @__PURE__ */ jsx(ScrollView, {
2746
- lines: padded,
2747
- height: room,
2748
- stickToBottom: true,
2749
- isActive: active,
2750
- onAtBottomChange: setAtBottom,
2751
- handleRef: handle,
2752
- onReachTop: reachTop
2753
- }), fresh > 0 ? /* @__PURE__ */ jsxs(Hit, {
2754
- onClick: () => handle.current?.scrollToBottom(),
2755
- isActive: active,
2756
- children: [/* @__PURE__ */ jsx(Text, {
2757
- bold: true,
2758
- ...c.stamp ? { color: c.stamp } : {},
2759
- children: `${ascii ? "v" : "↓"} ${fresh} new`
2760
- }), /* @__PURE__ */ jsx(Text, {
2761
- ...quiet$2(c),
2762
- children: mouse ? " click or End" : " End"
2763
- })]
2764
- }) : null]
2765
- });
2766
- }
2767
- const PEEK_EVERY_MS = 3e3;
2768
- function LiveView({ session, actions, active, width, height }) {
2769
- const { c } = useTheme();
2770
- const [peek, setPeek] = useState();
2771
- const [failed, setFailed] = useState(false);
2772
- const off = session.peekable === false;
2773
- useEffect(() => {
2774
- if (off || !active) return;
2775
- let gone = false;
2776
- const load = () => {
2777
- actions.peek(session.id).then((r) => {
2778
- if (gone) return;
2779
- setPeek(r);
2780
- setFailed(false);
2781
- }, () => {
2782
- if (!gone) setFailed(true);
2783
- });
2784
- };
2785
- load();
2786
- const id = setInterval(load, PEEK_EVERY_MS);
2787
- return () => {
2788
- gone = true;
2789
- clearInterval(id);
2790
- };
2791
- }, [
2792
- actions,
2793
- session.id,
2794
- off,
2795
- active
2796
- ]);
2797
- let body;
2798
- if (off || failed && !peek) body = /* @__PURE__ */ jsx(Text, {
2799
- ...quiet$2(c),
2800
- children: "This session doesn't share a live view."
2801
- });
2802
- else if (!peek) body = /* @__PURE__ */ jsx(Text, {
2803
- ...quiet$2(c),
2804
- children: "Looking…"
2805
- });
2806
- else if (peek.turns.length === 0) body = /* @__PURE__ */ jsx(Text, {
2807
- ...quiet$2(c),
2808
- children: "Nothing to show yet."
2809
- });
2810
- else {
2811
- const lines = [];
2812
- peek.turns.forEach((t, i) => {
2813
- const label = t.role === "assistant" ? session.name : t.role === "user" ? "prompt" : "tool";
2814
- lines.push({
2815
- key: `${i}r`,
2816
- text: label,
2817
- role: true
2818
- });
2819
- wrapLines(t.text, width).forEach((l, j) => {
2820
- lines.push({
2821
- key: `${i}:${j}`,
2822
- text: l,
2823
- role: false
2824
- });
2825
- });
2826
- });
2827
- body = /* @__PURE__ */ jsx(Box, {
2828
- flexDirection: "column",
2829
- height: Math.max(1, height - 1),
2830
- justifyContent: "flex-end",
2831
- children: lines.slice(-(height - 1)).map((l) => /* @__PURE__ */ jsx(Ell, {
2832
- width,
2833
- ...l.role ? { color: c.quiet } : {},
2834
- children: l.text === "" ? " " : l.text
2835
- }, l.key))
2836
- });
2837
- }
2838
- return /* @__PURE__ */ jsxs(Box, {
2839
- flexDirection: "column",
2840
- width,
2841
- children: [/* @__PURE__ */ jsx(Label, { children: "Live view · secrets hidden" }), body]
2842
- });
2843
- }
2844
- function InfoPanel({ session, width }) {
2845
- const { c, ascii } = useTheme();
2846
- const row = (label, value) => /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Box, {
2847
- width: 12,
2848
- children: /* @__PURE__ */ jsx(Text, {
2849
- ...quiet$2(c),
2850
- children: label
2851
- })
2852
- }), /* @__PURE__ */ jsx(Ell, {
2853
- width: Math.max(4, width - 12),
2854
- children: value
2855
- })] }, label);
2856
- const rowsOut = [row("Wakes up", wakesUp(session.deliveryTier)), row("Auto", session.auto ? "on" : "off")];
2857
- if (session.autoPausedAt) rowsOut.push(row("Paused", "it hit its auto limit"));
2858
- if (session.autoLimit) rowsOut.push(row("Auto limit", `${session.autoLimit} turns`));
2859
- rowsOut.push(row("Folder", shortPath$1(session.cwd, Math.max(4, width - 12), ascii)));
2860
- rowsOut.push(row("Started", agoText(session.startedAt)));
2861
- return /* @__PURE__ */ jsxs(Box, {
2862
- flexDirection: "column",
2863
- width,
2864
- children: [/* @__PURE__ */ jsx(Label, { children: "Info" }), rowsOut]
2865
- });
2866
- }
2867
2196
  // src/tui/screens/sessions.tsx
2868
2197
  var sessions_exports = /* @__PURE__ */ __exportAll({
2198
+ agoText: () => agoText,
2869
2199
  default: () => Sessions,
2870
2200
  groupSessions: () => groupSessions,
2871
- listColumns: () => listColumns
2201
+ listColumns: () => listColumns,
2202
+ statusWord: () => statusWord
2872
2203
  });
2873
- const AUTO_WIDTH = 4;
2204
+ const STATUS_WIDTH = 10;
2874
2205
  const GAP = 2;
2875
2206
  /** Column widths for the list. The name takes what it needs, the folder takes the rest. */
2876
2207
  function listColumns(width, longestName) {
2877
- const fixed = 32;
2208
+ const fixed = 24;
2878
2209
  let name = Math.max(12, Math.min(32, longestName + 1));
2879
2210
  let folder = width - fixed - name;
2880
2211
  if (folder < 10) {
@@ -2890,12 +2221,22 @@ function listColumns(width, longestName) {
2890
2221
  const BOUND = /* @__PURE__ */ new Set([
2891
2222
  "m",
2892
2223
  "n",
2893
- "a",
2224
+ "l",
2225
+ "r",
2894
2226
  "x",
2895
2227
  "q",
2896
2228
  "f"
2897
2229
  ]);
2898
- const quiet$1 = (c) => c.quiet ? { color: c.quiet } : { dimColor: true };
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
+ }
2899
2240
  function matches(s, q) {
2900
2241
  const needle = q.toLowerCase();
2901
2242
  return [
@@ -2934,10 +2275,12 @@ function Sessions(props) {
2934
2275
  const wide = layout === "wide";
2935
2276
  const [selectedId, setSelectedId] = useState(props.focus);
2936
2277
  const [filter, setFilter] = useState(void 0);
2937
- const [confirm, setConfirm] = useState(void 0);
2938
- const [view, setView] = useState(void 0);
2278
+ const [mode, setMode] = useState(void 0);
2279
+ const [draft, setDraft] = useState("");
2280
+ const sending = useRef(false);
2939
2281
  const groups = useMemo(() => {
2940
- return groupSessions(filter ? state.sessions.filter((s) => matches(s, filter)) : state.sessions);
2282
+ const live = state.sessions.filter((s) => s.status !== "offline");
2283
+ return groupSessions(filter ? live.filter((s) => matches(s, filter)) : live);
2941
2284
  }, [state.sessions, filter]);
2942
2285
  const flat = useMemo(() => groups.flatMap((g) => g.items), [groups]);
2943
2286
  const rowsList = useMemo(() => groups.flatMap((g) => [{
@@ -2952,77 +2295,108 @@ function Sessions(props) {
2952
2295
  const found = flat.findIndex((s) => s.id === selectedId);
2953
2296
  const selected = flat[Math.max(found, 0)];
2954
2297
  const selRow = rowsList.findIndex((r) => r.t === "session" && r.s.id === selected?.id);
2955
- const viewSession = view ? state.sessions.find((s) => s.id === view.id) : void 0;
2956
2298
  const filtering = filter !== void 0;
2957
- const selectedKey = selected?.id;
2958
- useEffect(() => {
2959
- if (!wide || !selectedKey) return;
2960
- actions.loadHistory(selectedKey).catch(() => void 0);
2961
- }, [
2962
- wide,
2963
- selectedKey,
2964
- actions
2965
- ]);
2966
- const typing = active && !viewSession && filtering;
2299
+ const taking = mode?.kind === "message" || mode?.kind === "rename";
2300
+ const typing = active && (taking || filtering);
2967
2301
  useEffect(() => {
2968
2302
  setTyping(typing);
2969
2303
  return () => setTyping(false);
2970
2304
  }, [typing, setTyping]);
2971
- const asking = active && !viewSession && confirm !== void 0;
2305
+ const asking = active && mode?.kind === "stop";
2972
2306
  useEffect(() => {
2973
2307
  claimKeys(asking ? ["y", "n"] : []);
2974
2308
  return () => claimKeys([]);
2975
2309
  }, [asking, claimKeys]);
2976
2310
  useEffect(() => {
2977
- setKeys(viewSession ? [
2978
- {
2979
- key: "⏎",
2980
- label: "send"
2981
- },
2982
- {
2983
- key: "Tab",
2984
- label: "switch tab"
2985
- },
2986
- {
2987
- key: "Esc",
2988
- label: "back"
2989
- }
2990
- ] : [
2311
+ setKeys(taking ? [{
2312
+ key: "⏎",
2313
+ label: "send"
2314
+ }, {
2315
+ key: "Esc",
2316
+ label: "cancel"
2317
+ }] : [
2991
2318
  {
2992
2319
  key: "↑↓",
2993
2320
  label: "move"
2994
2321
  },
2995
2322
  {
2996
- key: "⏎",
2997
- label: "open"
2323
+ key: "l",
2324
+ label: "make lead"
2998
2325
  },
2999
2326
  {
3000
2327
  key: "m",
3001
2328
  label: "message"
3002
2329
  },
3003
2330
  {
3004
- key: "n",
3005
- label: "new worker"
3006
- },
3007
- {
3008
- key: "a",
3009
- label: "auto"
2331
+ key: "r",
2332
+ label: "rename"
3010
2333
  },
3011
2334
  {
3012
2335
  key: "x",
3013
2336
  label: "stop"
3014
2337
  },
2338
+ {
2339
+ key: "n",
2340
+ label: "new"
2341
+ },
3015
2342
  {
3016
2343
  key: "f",
3017
2344
  label: "filter"
3018
2345
  }
3019
2346
  ]);
3020
- }, [setKeys, viewSession]);
3021
- const setAuto = useCallback((s) => {
3022
- const on = !s.auto;
3023
- actions.setAuto(s.id, on).then(() => toast(`Auto ${on ? "on" : "off"} for ${s.name}`), () => toast("Couldn't change auto. Try again.", "error"));
3024
- }, [actions, toast]);
3025
- const selAuto = selected?.auto ?? false;
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
+ };
3026
2400
  useEffect(() => {
3027
2401
  const cmds = [{
3028
2402
  id: "sessions-new",
@@ -3033,31 +2407,26 @@ function Sessions(props) {
3033
2407
  if (selected) {
3034
2408
  const s = selected;
3035
2409
  cmds.push({
3036
- id: "sessions-open",
3037
- label: `Open ${s.name}`,
3038
- key: "⏎",
3039
- run: () => setView({
3040
- id: s.id,
3041
- focusBox: false
3042
- })
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)
3043
2414
  }, {
3044
2415
  id: "sessions-message",
3045
2416
  label: `Message ${s.name}`,
3046
2417
  key: "m",
3047
- run: () => setView({
3048
- id: s.id,
3049
- focusBox: true
3050
- })
3051
- }, {
3052
- id: "sessions-auto",
3053
- label: `Turn auto ${selAuto ? "off" : "on"} for ${s.name}`,
3054
- key: "a",
3055
- run: () => setAuto(s)
2418
+ run: () => fn.current.startText("message", s)
3056
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({
3057
2426
  id: "sessions-stop",
3058
2427
  label: `Stop ${s.name}`,
3059
2428
  key: "x",
3060
- run: () => setConfirm(s)
2429
+ run: () => fn.current.askStop(s)
3061
2430
  });
3062
2431
  }
3063
2432
  cmds.push({
@@ -3070,13 +2439,8 @@ function Sessions(props) {
3070
2439
  }, [
3071
2440
  setCommands,
3072
2441
  go,
3073
- selected,
3074
- selAuto,
3075
- setAuto
2442
+ selected
3076
2443
  ]);
3077
- function stop(s) {
3078
- actions.stop(s.id).then(() => toast(`Stopped ${s.name}`), () => toast(`Couldn't stop ${s.name}.`, "error"));
3079
- }
3080
2444
  function move(delta) {
3081
2445
  if (flat.length === 0) return;
3082
2446
  setSelectedId((prev) => {
@@ -3085,56 +2449,39 @@ function Sessions(props) {
3085
2449
  });
3086
2450
  }
3087
2451
  useInput((input, key) => {
3088
- if (confirm) {
3089
- if (input === "y") stop(confirm);
3090
- setConfirm(void 0);
2452
+ if (mode?.kind === "stop") {
2453
+ if (input === "y") stop(mode.s);
2454
+ setMode(void 0);
3091
2455
  return;
3092
2456
  }
3093
2457
  if (key.upArrow) return move(-1);
3094
2458
  if (key.downArrow) return move(1);
3095
- if (key.return) {
3096
- if (selected) setView({
3097
- id: selected.id,
3098
- focusBox: false
3099
- });
3100
- return;
3101
- }
3102
2459
  if (filtering) {
3103
2460
  if (key.escape) return setFilter(void 0);
2461
+ if (key.return) return;
3104
2462
  if (key.backspace || key.delete) return setFilter(filter && filter.length > 1 ? filter.slice(0, -1) : filter === "" ? void 0 : "");
3105
2463
  if (input && !key.ctrl && !key.meta && !key.tab) setFilter((f) => (f ?? "") + input);
3106
2464
  return;
3107
2465
  }
2466
+ if (key.return) {
2467
+ if (selected) startText("message", selected);
2468
+ return;
2469
+ }
3108
2470
  if (key.ctrl || key.meta || key.tab || key.escape || input.length !== 1) return;
3109
- if (input === "m" && selected) return setView({
3110
- id: selected.id,
3111
- focusBox: true
3112
- });
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);
3113
2475
  if (input === "n") return go("new");
3114
- if (input === "a" && selected) return setAuto(selected);
3115
- if (input === "x" && selected) return setConfirm(selected);
3116
2476
  if (input === "f") return setFilter("");
3117
2477
  if (/\p{L}/u.test(input) && !BOUND.has(input.toLowerCase())) setFilter(input);
3118
- }, { isActive: active && !viewSession });
3119
- if (viewSession) return /* @__PURE__ */ jsx(SessionView, {
3120
- session: viewSession,
3121
- state,
3122
- actions,
3123
- layout,
3124
- rows,
3125
- columns,
3126
- active,
3127
- focusBox: view?.focusBox ?? false,
3128
- setTyping,
3129
- toast,
3130
- onClose: () => setView(void 0)
3131
- });
2478
+ }, { isActive: active && !taking });
3132
2479
  if (state.sessions.length === 0) return /* @__PURE__ */ jsx(Box, {
3133
2480
  flexDirection: "column",
3134
2481
  paddingTop: 1,
3135
2482
  children: /* @__PURE__ */ jsx(Text, {
3136
- ...quiet$1(c),
3137
- children: "No sessions yet. Open Claude Code, Codex or another CLI you set up, or press n to start one."
2483
+ ...quiet(c),
2484
+ children: "Nothing is running yet. Open one of your CLIs, or press n to start one."
3138
2485
  })
3139
2486
  });
3140
2487
  const { mainW, panelW } = splitWidths(columns, wide);
@@ -3145,32 +2492,23 @@ function Sessions(props) {
3145
2492
  const mid = ascii ? "-" : "·";
3146
2493
  const { name: nameW, folder: folderW } = listColumns(listW, flat.reduce((n, s) => Math.max(n, [...s.name].length), 0));
3147
2494
  const clickRow = (s, isSel, double) => {
3148
- setConfirm(void 0);
3149
- if (isSel || double) {
3150
- setSelectedId(s.id);
3151
- setView({
3152
- id: s.id,
3153
- focusBox: false
3154
- });
3155
- } else setSelectedId(s.id);
2495
+ setMode(void 0);
2496
+ setSelectedId(s.id);
2497
+ if (isSel || double) startText("message", s);
3156
2498
  };
3157
2499
  const renderRow = (r, isSel) => {
3158
2500
  if (r.t === "head") return /* @__PURE__ */ jsxs(Box, {
3159
2501
  width: listW,
3160
2502
  children: [/* @__PURE__ */ jsx(Label, { children: plain(r.text, ascii) }), r.synced ? /* @__PURE__ */ jsx(Text, {
3161
- ...quiet$1(c),
2503
+ ...quiet(c),
3162
2504
  children: ` synced`
3163
2505
  }) : null]
3164
2506
  });
3165
2507
  const s = r.s;
3166
- const st = statusWord(s);
3167
- const off = st.kind === "offline";
3168
- const tone = off ? c.quiet : void 0;
3169
- const sc = off ? c.quiet : statusColor(st.kind, c);
3170
2508
  const lead = s.isOrchestrator;
3171
2509
  return /* @__PURE__ */ jsx(Hit, {
3172
2510
  onClick: (e) => clickRow(s, isSel, e.double),
3173
- isActive: active,
2511
+ isActive: active && !taking,
3174
2512
  children: /* @__PURE__ */ jsxs(Row, {
3175
2513
  width: listW,
3176
2514
  selected: isSel,
@@ -3184,51 +2522,36 @@ function Sessions(props) {
3184
2522
  /* @__PURE__ */ jsx(Cell, {
3185
2523
  w: 2,
3186
2524
  gap: 0,
3187
- color: lead && !off ? c.entry : c.quiet,
3188
- dim: off,
2525
+ color: lead ? c.entry : c.quiet,
3189
2526
  children: lead ? `${dot} ` : `${mid} `
3190
2527
  }),
3191
2528
  /* @__PURE__ */ jsx(Cell, {
3192
2529
  w: nameW + GAP,
3193
2530
  bold: isSel,
3194
- color: tone,
3195
- dim: off,
3196
2531
  children: s.name
3197
2532
  }),
3198
2533
  /* @__PURE__ */ jsx(Box, {
3199
2534
  width: 6,
3200
2535
  flexShrink: 0,
3201
- children: /* @__PURE__ */ jsx(Chip, {
3202
- cli: s.cli,
3203
- dim: off
3204
- })
2536
+ children: /* @__PURE__ */ jsx(Chip, { cli: s.cli })
3205
2537
  }),
3206
2538
  /* @__PURE__ */ jsx(Cell, {
3207
2539
  w: folderW + GAP,
3208
2540
  color: c.quiet,
3209
- dim: off,
3210
2541
  children: shortPath$1(s.cwd, folderW - GAP, ascii)
3211
2542
  }),
3212
2543
  /* @__PURE__ */ jsx(Cell, {
3213
- w: 14,
3214
- bold: st.kind === "new",
3215
- color: sc,
3216
- dim: off,
3217
- children: st.text
3218
- }),
3219
- /* @__PURE__ */ jsx(Cell, {
3220
- w: AUTO_WIDTH,
2544
+ w: STATUS_WIDTH,
3221
2545
  gap: 0,
3222
- color: c.quiet,
3223
- dim: off,
3224
- children: off ? "" : s.auto ? "on" : "off"
2546
+ color: s.status === "busy" ? c.info : c.quiet,
2547
+ children: statusWord(s)
3225
2548
  })
3226
2549
  ]
3227
2550
  })
3228
2551
  });
3229
2552
  };
3230
2553
  const list = flat.length === 0 ? /* @__PURE__ */ jsx(Text, {
3231
- ...quiet$1(c),
2554
+ ...quiet(c),
3232
2555
  children: `Nothing matches “${filter}”.`
3233
2556
  }) : /* @__PURE__ */ jsx(ScrollList, {
3234
2557
  items: rowsList,
@@ -3237,44 +2560,64 @@ function Sessions(props) {
3237
2560
  keyOf: (r, i) => r.t === "head" ? r.key : `${r.s.id}:${i}`,
3238
2561
  renderItem: (r, _sel, i) => renderRow(r, i === selRow)
3239
2562
  });
3240
- const unreadTotal = state.sessions.reduce((n, s) => n + (s.unreadCount ?? 0), 0);
3241
2563
  let bottom;
3242
- if (confirm) bottom = /* @__PURE__ */ jsxs(Box, { children: [
3243
- /* @__PURE__ */ jsx(Text, {
3244
- bold: true,
3245
- ...c.stamp ? { color: c.stamp } : {},
3246
- children: `Stop ${confirm.name}? `
3247
- }),
3248
- /* @__PURE__ */ jsx(Hit, {
3249
- onClick: () => {
3250
- stop(confirm);
3251
- setConfirm(void 0);
3252
- },
3253
- isActive: active,
3254
- children: /* @__PURE__ */ jsx(Text, {
2564
+ if (mode?.kind === "stop") {
2565
+ const target = mode.s;
2566
+ bottom = /* @__PURE__ */ jsxs(Box, { children: [
2567
+ /* @__PURE__ */ jsx(Text, {
3255
2568
  bold: true,
3256
2569
  ...c.stamp ? { color: c.stamp } : {},
3257
- children: "y"
3258
- })
3259
- }),
3260
- /* @__PURE__ */ jsx(Text, {
3261
- bold: true,
3262
- ...c.stamp ? { color: c.stamp } : {},
3263
- children: "/"
3264
- }),
3265
- /* @__PURE__ */ jsx(Hit, {
3266
- onClick: () => setConfirm(void 0),
3267
- isActive: active,
3268
- children: /* @__PURE__ */ jsx(Text, {
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, {
3269
2585
  bold: true,
3270
2586
  ...c.stamp ? { color: c.stamp } : {},
3271
- children: "n"
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
+ })
3272
2597
  })
3273
- })
3274
- ] });
3275
- else if (filtering) bottom = /* @__PURE__ */ jsxs(Text, { children: [
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: [
3276
2619
  /* @__PURE__ */ jsx(Text, {
3277
- ...quiet$1(c),
2620
+ ...quiet(c),
3278
2621
  children: "Filter "
3279
2622
  }),
3280
2623
  /* @__PURE__ */ jsx(Text, {
@@ -3286,16 +2629,15 @@ function Sessions(props) {
3286
2629
  children: " "
3287
2630
  }),
3288
2631
  /* @__PURE__ */ jsx(Text, {
3289
- ...quiet$1(c),
3290
- children: ` Esc clears ⏎ opens`
2632
+ ...quiet(c),
2633
+ children: ` Esc clears`
3291
2634
  })
3292
2635
  ] });
3293
2636
  else {
3294
- const n = unreadTotal > 0 ? `${unreadTotal} new` : "N new";
3295
2637
  const variants = [
3296
- `${dot} lead session working = busy right now ${n} = unread messages type to filter`,
3297
- `${dot} lead working = busy ${n} = unread type to filter`,
3298
- `${dot} lead ${n} = unread type to filter`
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`
3299
2641
  ];
3300
2642
  const legend = variants.find((v) => [...v].length <= columns) ?? variants[2] ?? "";
3301
2643
  const tail = "type to filter";
@@ -3347,12 +2689,8 @@ function Sessions(props) {
3347
2689
  text: "Folder"
3348
2690
  },
3349
2691
  {
3350
- w: 14,
3351
- text: "Status"
3352
- },
3353
- {
3354
- w: AUTO_WIDTH,
3355
- text: "Auto",
2692
+ w: STATUS_WIDTH,
2693
+ text: "Status",
3356
2694
  gap: 0
3357
2695
  }
3358
2696
  ]
@@ -3360,9 +2698,8 @@ function Sessions(props) {
3360
2698
  }), wide ? /* @__PURE__ */ jsx(Pane, {
3361
2699
  width: panelW,
3362
2700
  height: bodyH,
3363
- children: selected ? /* @__PURE__ */ jsx(SidePanel$1, {
2701
+ children: selected ? /* @__PURE__ */ jsx(SidePanel, {
3364
2702
  session: selected,
3365
- state,
3366
2703
  width: paneInner(panelW)
3367
2704
  }) : null
3368
2705
  }) : null]
@@ -3378,9 +2715,8 @@ function Sessions(props) {
3378
2715
  ]
3379
2716
  });
3380
2717
  }
3381
- function SidePanel$1({ session, state, width }) {
2718
+ function SidePanel({ session, width }) {
3382
2719
  const { c, ascii } = useTheme();
3383
- const history = [...state.history[session.id] ?? []].sort((a, b) => a.createdAt.localeCompare(b.createdAt)).slice(-3);
3384
2720
  const role = session.isOrchestrator ? "lead" : "worker";
3385
2721
  const sep = ascii ? "-" : "·";
3386
2722
  const started = `started ${agoText(session.startedAt)}`;
@@ -3405,37 +2741,19 @@ function SidePanel$1({ session, state, width }) {
3405
2741
  color: c.quiet,
3406
2742
  children: l
3407
2743
  }, l)),
3408
- /* @__PURE__ */ jsx(Box, {
3409
- marginTop: 1,
3410
- children: /* @__PURE__ */ jsx(Label, { children: "Latest" })
3411
- }),
3412
- history.length === 0 ? /* @__PURE__ */ jsx(Text, {
3413
- ...quiet$1(c),
3414
- children: "Nothing yet."
3415
- }) : history.map((m) => /* @__PURE__ */ jsxs(Box, {
3416
- flexDirection: "column",
3417
- children: [/* @__PURE__ */ jsx(Ell, {
3418
- width,
3419
- color: isFromOwner(m) ? c.entry : c.quiet,
3420
- children: `${clockTime(m.createdAt)} ${isFromOwner(m) ? "you" : m.fromName ?? session.name}`
3421
- }), wrapLines(messageText(m), width).slice(0, 2).map((l, i) => /* @__PURE__ */ jsx(Ell, {
3422
- width,
3423
- children: l === "" ? " " : l
3424
- }, i))]
3425
- }, m.id)),
3426
2744
  /* @__PURE__ */ jsx(Box, {
3427
2745
  marginTop: 1,
3428
2746
  children: /* @__PURE__ */ jsx(Label, { children: "Right now" })
3429
2747
  }),
3430
- wrapLines(status, width).slice(0, 3).map((l, i) => /* @__PURE__ */ jsx(Ell, {
3431
- width,
3432
- children: l === "" ? " " : l
3433
- }, i))
2748
+ /* @__PURE__ */ jsx(Text, {
2749
+ wrap: "truncate-end",
2750
+ children: status
2751
+ })
3434
2752
  ]
3435
2753
  });
3436
2754
  }
3437
2755
  // src/tui/screens/setup.tsx
3438
- /** Screen 5: Setup. Your CLIs, extras and the checkup. */
2756
+ /** Screen 4: Setup. Your CLIs, extras and the checkup. */
3439
2757
  var setup_exports = /* @__PURE__ */ __exportAll({
3440
2758
  default: () => SetupScreen,
3441
2759
  idsFor: () => idsFor
@@ -3585,14 +2903,11 @@ function SetupScreen(props) {
3585
2903
  const [cursor, setCursor] = useState(0);
3586
2904
  const [picked, setPicked] = useState(/* @__PURE__ */ new Set());
3587
2905
  const [review, setReview] = useState();
3588
- const [extras, setExtras] = useState({
3589
- helpers: false,
3590
- askBeforeRisky: false
3591
- });
2906
+ const [extras, setExtras] = useState({ helpers: false });
3592
2907
  const mouse = useMouseControl();
3593
2908
  const mouseOn = mouse.enabled;
3594
2909
  const asked = useRef(false);
3595
- const total = clis.length + 4;
2910
+ const total = clis.length + 2;
3596
2911
  const at = Math.min(cursor, Math.max(0, total - 1));
3597
2912
  const onCli = at < clis.length ? clis[at] : void 0;
3598
2913
  const extraRow = at >= clis.length ? at - clis.length : -1;
@@ -3621,6 +2936,14 @@ function SetupScreen(props) {
3621
2936
  refresh,
3622
2937
  loadExtras
3623
2938
  ]);
2939
+ const preset = useRef(false);
2940
+ useEffect(() => {
2941
+ if (preset.current || !state.setup || state.setup.clis.length === 0) return;
2942
+ preset.current = true;
2943
+ const all = state.setup.clis;
2944
+ if (all.some((x) => x.status === "ready")) return;
2945
+ setPicked(new Set(all.filter((x) => x.status === "not-set-up" || x.status === "needs-update").map((x) => x.cli)));
2946
+ }, [state.setup]);
3624
2947
  const open = useCallback(async (ids, title) => {
3625
2948
  setReview({
3626
2949
  title,
@@ -3651,7 +2974,7 @@ function SetupScreen(props) {
3651
2974
  const setUp = useCallback((target) => {
3652
2975
  const row = target ? target.extra ?? -1 : extraRow;
3653
2976
  const cur = target ? target.cli : onCli;
3654
- if (row === 2) {
2977
+ if (row === 1) {
3655
2978
  if (mouse.forcedOff) {
3656
2979
  toast("The mouse is off because CONVENO_MOUSE=0 is set.", "warn");
3657
2980
  return;
@@ -3665,21 +2988,6 @@ function SetupScreen(props) {
3665
2988
  toast(next ? "Mouse is on." : "Mouse is off.", "ok");
3666
2989
  return;
3667
2990
  }
3668
- if (row === 3) {
3669
- if (extras.notifyForcedOff) {
3670
- toast("Desktop alerts are off because CONVENO_NOTIFY=0 is set.", "warn");
3671
- return;
3672
- }
3673
- const next = extras.notifyDesktop === false;
3674
- actions.setNotify(next).then(() => {
3675
- setExtras({
3676
- ...extras,
3677
- notifyDesktop: next
3678
- });
3679
- toast(next ? "I'll tell you on the desktop." : "No desktop alerts.", "ok");
3680
- }, () => toast("Couldn't change that. Try again.", "error"));
3681
- return;
3682
- }
3683
2991
  if (row === 0) {
3684
2992
  const next = !extras.helpers;
3685
2993
  actions.setHelpers(next).then(() => {
@@ -3691,11 +2999,6 @@ function SetupScreen(props) {
3691
2999
  }, () => toast("Couldn't change that. Try again.", "error"));
3692
3000
  return;
3693
3001
  }
3694
- if (row === 1) {
3695
- if (extras.askBeforeRisky) return toast("Already on. Each worker stays off until you turn it on for it.", "ok");
3696
- open(["relay:on"], "Ask me before risky commands (beta)");
3697
- return;
3698
- }
3699
3002
  const { ids, skipped } = idsFor(clis, picked, cur?.cli);
3700
3003
  if (ids.length === 0) return toast(skipped ?? "Nothing to set up here.", "warn");
3701
3004
  const names = clis.filter((x) => ids.includes(`init:${x.cli}`)).map((x) => x.label);
@@ -4013,23 +3316,7 @@ function SetupScreen(props) {
4013
3316
  setUp({ extra: 1 });
4014
3317
  },
4015
3318
  isActive: active,
4016
- children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 1)} ${box(extras.askBeforeRisky)} Ask me before risky commands (beta)` })
4017
- }),
4018
- /* @__PURE__ */ jsx(Hit, {
4019
- onClick: () => {
4020
- setCursor(clis.length + 2);
4021
- setUp({ extra: 2 });
4022
- },
4023
- isActive: active,
4024
- children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 2)} ${box(mouseOn)} Click and scroll with the mouse` })
4025
- }),
4026
- /* @__PURE__ */ jsx(Hit, {
4027
- onClick: () => {
4028
- setCursor(clis.length + 3);
4029
- setUp({ extra: 3 });
4030
- },
4031
- isActive: active,
4032
- children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 3)} ${box(extras.notifyDesktop !== false && !extras.notifyForcedOff)} Tell me on the desktop when something needs me` })
3319
+ children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 1)} ${box(mouseOn)} Click and scroll with the mouse` })
4033
3320
  }),
4034
3321
  !wide && health.length > 0 && rows >= 22 ? /* @__PURE__ */ jsxs(Box, {
4035
3322
  flexDirection: "column",
@@ -4066,484 +3353,6 @@ function SetupScreen(props) {
4066
3353
  }) : null]
4067
3354
  });
4068
3355
  }
4069
- // src/tui/screens/you.tsx
4070
- var you_exports = /* @__PURE__ */ __exportAll({ default: () => You });
4071
- /** Cards stop growing here, so they stay readable on a very wide terminal. */
4072
- const MAX_MAIN = 110;
4073
- const quiet = (c) => c.quiet ? { color: c.quiet } : { dimColor: true };
4074
- /** `m:ss` left until `iso`, or undefined when there is no time limit. */
4075
- function timeLeft(iso, now) {
4076
- if (!iso) return void 0;
4077
- const t = Date.parse(iso);
4078
- if (Number.isNaN(t)) return void 0;
4079
- const s = Math.max(0, Math.ceil((t - now) / 1e3));
4080
- return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
4081
- }
4082
- function sameDay(iso, now) {
4083
- if (!iso) return false;
4084
- const a = new Date(iso);
4085
- const b = new Date(now);
4086
- return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
4087
- }
4088
- function You(props) {
4089
- const { state, actions, layout, rows, columns, active, setKeys, setCommands, toast, setTyping, claimKeys } = props;
4090
- const { c, ascii } = useTheme();
4091
- const wide = layout === "wide";
4092
- const [selKey, setSelKey] = useState(props.focus ? `t:${props.focus}` : void 0);
4093
- const [typed, setTyped] = useState(void 0);
4094
- const [draft, setDraft] = useState("");
4095
- const [now, setNow] = useState(() => Date.now());
4096
- const nameOf = (id, fallback) => fallback ?? state.sessions.find((s) => s.id === id)?.name ?? "a session";
4097
- const open = useMemo(() => state.tickets.filter((t) => t.status === "open").sort((a, b) => a.createdAt.localeCompare(b.createdAt)), [state.tickets]);
4098
- const inbox = useMemo(() => state.inbox.filter((m) => !isFromOwner(m)).sort((a, b) => b.createdAt.localeCompare(a.createdAt)), [state.inbox]);
4099
- const order = useMemo(() => [...open.map((t) => `t:${t.id}`), ...inbox.map((m) => `m:${m.id}`)], [open, inbox]);
4100
- const curKey = order[Math.max(0, order.indexOf(selKey ?? ""))];
4101
- const curTicket = curKey?.startsWith("t:") ? open.find((t) => `t:${t.id}` === curKey) : void 0;
4102
- const curMessage = curKey?.startsWith("m:") ? inbox.find((m) => `m:${m.id}` === curKey) : void 0;
4103
- const hasPermission = open.some((t) => t.kind === "permission");
4104
- useEffect(() => {
4105
- if (!hasPermission) return;
4106
- const id = setInterval(() => setNow(Date.now()), 1e3);
4107
- return () => clearInterval(id);
4108
- }, [hasPermission]);
4109
- const optionCount = !typed && curTicket && curTicket.kind !== "permission" ? curTicket.options?.length ?? 0 : 0;
4110
- const claimsDigits = optionCount > 0;
4111
- const typing = active && typed !== void 0;
4112
- useEffect(() => {
4113
- setTyping(typing);
4114
- return () => setTyping(false);
4115
- }, [typing, setTyping]);
4116
- useEffect(() => {
4117
- const keys = active ? Array.from({ length: Math.min(optionCount, 9) }, (_, i) => String(i + 1)) : [];
4118
- claimKeys(keys);
4119
- return () => claimKeys([]);
4120
- }, [
4121
- active,
4122
- optionCount,
4123
- claimKeys
4124
- ]);
4125
- const acked = useRef(/* @__PURE__ */ new Set());
4126
- useEffect(() => {
4127
- if (!active || state.unread === 0) return;
4128
- const ids = inbox.map((m) => m.id).filter((id) => !acked.current.has(id));
4129
- if (ids.length === 0) return;
4130
- for (const id of ids) acked.current.add(id);
4131
- actions.markRead(ids).catch(() => {
4132
- for (const id of ids) acked.current.delete(id);
4133
- });
4134
- }, [
4135
- active,
4136
- state.unread,
4137
- inbox,
4138
- actions
4139
- ]);
4140
- useEffect(() => {
4141
- const keys = typed ? [{
4142
- key: "⏎",
4143
- label: "send"
4144
- }, {
4145
- key: "Esc",
4146
- label: "cancel"
4147
- }] : [{
4148
- key: "↑↓",
4149
- label: "move"
4150
- }];
4151
- if (!typed) {
4152
- if (curTicket?.kind === "permission") keys.push({
4153
- key: "y",
4154
- label: "allow once"
4155
- }, {
4156
- key: "n",
4157
- label: "deny"
4158
- });
4159
- else if (curTicket) {
4160
- if (claimsDigits) keys.push({
4161
- key: "1-9",
4162
- label: "answer"
4163
- });
4164
- keys.push({
4165
- key: "⏎",
4166
- label: "type an answer"
4167
- });
4168
- } else if (curMessage) keys.push({
4169
- key: "⏎",
4170
- label: "reply"
4171
- });
4172
- }
4173
- setKeys(keys);
4174
- }, [
4175
- setKeys,
4176
- typed,
4177
- curTicket,
4178
- curMessage,
4179
- claimsDigits
4180
- ]);
4181
- useEffect(() => {
4182
- setCommands([]);
4183
- }, [setCommands]);
4184
- const done = (text) => {
4185
- setTyped(void 0);
4186
- setDraft("");
4187
- toast(text);
4188
- };
4189
- const failed = () => toast("That didn't go through. Try again.", "error");
4190
- const answer = (t, text) => actions.answerTicket(t.id, text).then(() => done("Sent"), failed);
4191
- const decide = (t, allow) => actions.decide(t.id, allow).then(() => done(allow ? "Allowed" : "Denied"), failed);
4192
- const submit = (text) => {
4193
- const t = text.trim();
4194
- if (!typed || t === "") return;
4195
- if (typed.kind === "answer") answer(typed.ticket, t);
4196
- else {
4197
- const to = typed.message.fromName;
4198
- if (!to) return toast("You can't reply to that one.", "warn");
4199
- const id = typed.message.id;
4200
- actions.send(to, t).then(() => {
4201
- done("Sent");
4202
- acked.current.add(id);
4203
- actions.markRead([id]).catch(() => void 0);
4204
- }, failed);
4205
- }
4206
- };
4207
- const step = (d) => setSelKey((prev) => {
4208
- const at = Math.max(0, order.indexOf(prev ?? order[0] ?? ""));
4209
- return order[Math.max(0, Math.min(order.length - 1, at + d))];
4210
- });
4211
- const pick = (key) => {
4212
- if (typed) {
4213
- setTyped(void 0);
4214
- setDraft("");
4215
- }
4216
- setSelKey(key);
4217
- };
4218
- useInput((input, key) => {
4219
- if (typed) {
4220
- if (key.escape) {
4221
- setTyped(void 0);
4222
- setDraft("");
4223
- }
4224
- return;
4225
- }
4226
- if (key.upArrow || key.downArrow) return step(key.upArrow ? -1 : 1);
4227
- if (key.return) {
4228
- if (curTicket && curTicket.kind !== "permission") setTyped({
4229
- kind: "answer",
4230
- ticket: curTicket
4231
- });
4232
- else if (curMessage) setTyped({
4233
- kind: "reply",
4234
- message: curMessage
4235
- });
4236
- return;
4237
- }
4238
- if (curTicket?.kind === "permission") {
4239
- if (input === "y") decide(curTicket, true);
4240
- else if (input === "n") decide(curTicket, false);
4241
- return;
4242
- }
4243
- if (curTicket && claimsDigits && /^[1-9]$/.test(input)) {
4244
- const opt = curTicket.options?.[Number(input) - 1];
4245
- if (opt !== void 0) answer(curTicket, opt);
4246
- }
4247
- }, { isActive: active });
4248
- const split = splitWidths(columns, wide, { maxMain: MAX_MAIN });
4249
- const listW = wide ? split.mainW - 2 : Math.min(columns, MAX_MAIN);
4250
- const inner = listW - 4;
4251
- const dot = ascii ? "!" : "⚑";
4252
- const textBox = (placeholder) => /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Text, {
4253
- ...c.entry ? { color: c.entry } : {},
4254
- children: ascii ? "> " : "› "
4255
- }), /* @__PURE__ */ jsx(Box, {
4256
- width: Math.max(4, inner - 2),
4257
- children: /* @__PURE__ */ jsx(TextBox, {
4258
- value: draft,
4259
- onChange: setDraft,
4260
- onSubmit: submit,
4261
- focus: active,
4262
- multiline: true,
4263
- placeholder
4264
- })
4265
- })] });
4266
- const items = [];
4267
- const head = (text, first) => /* @__PURE__ */ jsx(Box, {
4268
- marginTop: first ? 0 : 1,
4269
- children: /* @__PURE__ */ jsx(Label, { children: plain(text, ascii) })
4270
- });
4271
- if (open.length === 0) items.push({
4272
- key: "none",
4273
- height: 2,
4274
- node: /* @__PURE__ */ jsxs(Box, {
4275
- flexDirection: "column",
4276
- children: [head("Needs you · 0", true), /* @__PURE__ */ jsx(Text, {
4277
- ...quiet(c),
4278
- children: "Nothing needs you right now."
4279
- })]
4280
- })
4281
- });
4282
- open.forEach((t, i) => {
4283
- const key = `t:${t.id}`;
4284
- const isSel = key === curKey;
4285
- const who = nameOf(t.fromSession);
4286
- const accent = isSel ? c.stamp : c.rule;
4287
- const mark = isSel ? ascii ? "> " : "▸ " : " ";
4288
- const editing = typed?.kind === "answer" && typed.ticket.id === t.id;
4289
- const lines = [];
4290
- let body = 0;
4291
- if (t.kind === "permission") {
4292
- const left = timeLeft(t.expiresAt, now);
4293
- const cmd = wrapLines(t.question, inner - 2).slice(0, 2);
4294
- body = 2 + cmd.length;
4295
- lines.push(/* @__PURE__ */ jsx(Ell, {
4296
- width: inner,
4297
- bold: true,
4298
- color: c.stamp,
4299
- children: `${mark}${dot} Wants to run a command ${who}`
4300
- }, "t"), /* @__PURE__ */ jsx(Box, {
4301
- backgroundColor: c.sunken,
4302
- paddingX: 1,
4303
- flexDirection: "column",
4304
- children: cmd.map((l, j) => /* @__PURE__ */ jsx(Ell, {
4305
- width: inner - 2,
4306
- children: l === "" ? " " : l
4307
- }, j))
4308
- }, "c"), /* @__PURE__ */ jsxs(Box, {
4309
- width: inner,
4310
- height: 1,
4311
- overflow: "hidden",
4312
- children: [
4313
- /* @__PURE__ */ jsx(Hit, {
4314
- onClick: () => void decide(t, true),
4315
- flexShrink: 0,
4316
- isActive: active,
4317
- children: /* @__PURE__ */ jsx(Text, {
4318
- ...quiet(c),
4319
- children: "y allow once"
4320
- })
4321
- }),
4322
- /* @__PURE__ */ jsx(Text, {
4323
- ...quiet(c),
4324
- children: " "
4325
- }),
4326
- /* @__PURE__ */ jsx(Hit, {
4327
- onClick: () => void decide(t, false),
4328
- flexShrink: 0,
4329
- isActive: active,
4330
- children: /* @__PURE__ */ jsx(Text, {
4331
- ...quiet(c),
4332
- children: "n deny"
4333
- })
4334
- }),
4335
- /* @__PURE__ */ jsx(Text, {
4336
- ...quiet(c),
4337
- wrap: "truncate",
4338
- children: left ? ` denied by itself in ${left}` : ""
4339
- })
4340
- ]
4341
- }, "k"));
4342
- } else {
4343
- const q = wrapLines(t.question, inner).slice(0, 3);
4344
- lines.push(/* @__PURE__ */ jsx(Ell, {
4345
- width: inner,
4346
- bold: true,
4347
- color: c.stamp,
4348
- children: plain(`${mark}? Question from ${who} · ${clockTime(t.createdAt)}`, ascii)
4349
- }, "t"), ...q.map((l, j) => /* @__PURE__ */ jsx(Ell, {
4350
- width: inner,
4351
- children: l === "" ? " " : l
4352
- }, `q${j}`)));
4353
- body = 2 + q.length + (editing ? draft.split("\n").length - 1 : 0);
4354
- const options = t.options ?? [];
4355
- const typeOwn = () => {
4356
- setSelKey(key);
4357
- setDraft("");
4358
- setTyped({
4359
- kind: "answer",
4360
- ticket: t
4361
- });
4362
- };
4363
- if (editing) lines.push(/* @__PURE__ */ jsx(Box, { children: textBox("Type your answer…") }, "b"));
4364
- else lines.push(/* @__PURE__ */ jsxs(Box, {
4365
- width: inner,
4366
- height: 1,
4367
- overflow: "hidden",
4368
- children: [options.map((o, j) => /* @__PURE__ */ jsxs(Box, {
4369
- flexShrink: 0,
4370
- children: [/* @__PURE__ */ jsx(Hit, {
4371
- onClick: () => void answer(t, o),
4372
- flexShrink: 0,
4373
- isActive: active,
4374
- children: /* @__PURE__ */ jsx(Text, {
4375
- ...quiet(c),
4376
- children: `[${j + 1}] ${o}`
4377
- })
4378
- }), /* @__PURE__ */ jsx(Text, {
4379
- ...quiet(c),
4380
- children: " "
4381
- })]
4382
- }, j)), /* @__PURE__ */ jsx(Hit, {
4383
- onClick: typeOwn,
4384
- flexShrink: 0,
4385
- isActive: active,
4386
- children: /* @__PURE__ */ jsx(Text, {
4387
- ...quiet(c),
4388
- wrap: "truncate",
4389
- children: options.length > 0 ? " or type your own" : "Press Enter to type an answer"
4390
- })
4391
- })]
4392
- }, "o"));
4393
- }
4394
- const height = body + 2;
4395
- items.push({
4396
- key,
4397
- height: height + (i === 0 ? 1 : 0),
4398
- node: /* @__PURE__ */ jsxs(Box, {
4399
- flexDirection: "column",
4400
- children: [i === 0 ? head(`Needs you · ${open.length}`, true) : null, /* @__PURE__ */ jsx(Hit, {
4401
- onClick: () => pick(key),
4402
- isActive: active,
4403
- children: /* @__PURE__ */ jsx(Card, {
4404
- accent,
4405
- width: listW,
4406
- children: lines
4407
- })
4408
- })]
4409
- })
4410
- });
4411
- });
4412
- inbox.forEach((m, i) => {
4413
- const key = `m:${m.id}`;
4414
- const isSel = key === curKey;
4415
- const who = m.fromName ?? nameOf(m.from);
4416
- const editing = typed?.kind === "reply" && typed.message.id === m.id;
4417
- const line = `${isSel ? ascii ? "> " : "▸ " : " "}${clockTime(m.createdAt)} ${who} ${messageText(m)}`;
4418
- items.push({
4419
- key,
4420
- height: (i === 0 ? 2 : 0) + 1 + (editing ? 1 : 0),
4421
- node: /* @__PURE__ */ jsxs(Box, {
4422
- flexDirection: "column",
4423
- children: [
4424
- i === 0 ? head(`Messages · ${inbox.length}`, false) : null,
4425
- /* @__PURE__ */ jsx(Hit, {
4426
- onClick: () => {
4427
- setSelKey(key);
4428
- setDraft("");
4429
- setTyped({
4430
- kind: "reply",
4431
- message: m
4432
- });
4433
- },
4434
- isActive: active,
4435
- children: /* @__PURE__ */ jsx(Row, {
4436
- width: listW,
4437
- selected: isSel,
4438
- children: /* @__PURE__ */ jsx(Ell, {
4439
- width: listW,
4440
- bold: isSel,
4441
- children: line
4442
- })
4443
- })
4444
- }),
4445
- editing ? /* @__PURE__ */ jsx(Box, {
4446
- paddingLeft: 2,
4447
- children: textBox(`Reply to ${who}…`)
4448
- }) : null
4449
- ]
4450
- })
4451
- });
4452
- });
4453
- if (inbox.length === 0) items.push({
4454
- key: "nomsg",
4455
- height: 3,
4456
- node: /* @__PURE__ */ jsxs(Box, {
4457
- flexDirection: "column",
4458
- children: [head("Messages · 0", false), /* @__PURE__ */ jsx(Text, {
4459
- ...quiet(c),
4460
- children: "No messages yet."
4461
- })]
4462
- })
4463
- });
4464
- const selItem = Math.max(0, items.findIndex((x) => x.key === curKey));
4465
- let start = 0;
4466
- const sum = (a, b) => items.slice(a, b).reduce((n, x) => n + x.height, 0);
4467
- while (start < selItem && sum(start, selItem + 1) > rows) start++;
4468
- const shown = [];
4469
- let used = 0;
4470
- for (const it of items.slice(start)) {
4471
- if (used + it.height > rows && shown.length > 0) break;
4472
- shown.push(it);
4473
- used += it.height;
4474
- }
4475
- return /* @__PURE__ */ jsxs(Box, {
4476
- width: columns,
4477
- height: rows,
4478
- children: [/* @__PURE__ */ jsx(Hit, {
4479
- flexDirection: "column",
4480
- width: wide ? split.mainW : listW,
4481
- flexShrink: 0,
4482
- onWheel: (d) => {
4483
- if (!typed) step(d < 0 ? -1 : 1);
4484
- },
4485
- isActive: active,
4486
- children: shown.map((it) => /* @__PURE__ */ jsx(Box, { children: it.node }, it.key))
4487
- }), wide ? /* @__PURE__ */ jsx(Pane, {
4488
- width: split.panelW,
4489
- height: rows,
4490
- children: /* @__PURE__ */ jsx(SidePanel, {
4491
- state,
4492
- width: paneInner(split.panelW),
4493
- now,
4494
- nameOf,
4495
- active,
4496
- onPick: pick
4497
- })
4498
- }) : null]
4499
- });
4500
- }
4501
- function SidePanel({ state, width, now, nameOf, active, onPick }) {
4502
- const { c, ascii } = useTheme();
4503
- const open = state.tickets.filter((t) => t.status === "open");
4504
- const doneToday = state.tickets.filter((t) => t.status !== "open" && sameDay(t.answeredAt ?? t.createdAt, now));
4505
- const tick = ascii ? "ok" : "✓";
4506
- return /* @__PURE__ */ jsxs(Box, {
4507
- width,
4508
- flexDirection: "column",
4509
- children: [
4510
- /* @__PURE__ */ jsx(Label, { children: `Open · ${open.length}` }),
4511
- open.length === 0 ? /* @__PURE__ */ jsx(Text, {
4512
- ...quiet(c),
4513
- children: "Nothing open."
4514
- }) : null,
4515
- open.slice(0, 6).map((t) => /* @__PURE__ */ jsx(Hit, {
4516
- onClick: () => onPick(`t:${t.id}`),
4517
- isActive: active,
4518
- children: /* @__PURE__ */ jsx(Ell, {
4519
- width,
4520
- color: c.stamp,
4521
- children: `${t.kind === "permission" ? ascii ? "!" : "⚑" : "?"} ${nameOf(t.fromSession)} ${t.question}`
4522
- })
4523
- }, t.id)),
4524
- /* @__PURE__ */ jsx(Box, {
4525
- marginTop: 1,
4526
- children: /* @__PURE__ */ jsx(Label, { children: `Done today · ${doneToday.length}` })
4527
- }),
4528
- doneToday.length === 0 ? /* @__PURE__ */ jsx(Text, {
4529
- ...quiet(c),
4530
- children: "Nothing yet."
4531
- }) : null,
4532
- doneToday.slice(0, 6).map((t) => /* @__PURE__ */ jsx(Ell, {
4533
- width,
4534
- color: c.quiet,
4535
- children: `${tick} ${nameOf(t.fromSession)} ${t.question}`
4536
- }, t.id)),
4537
- /* @__PURE__ */ jsx(Box, {
4538
- marginTop: 1,
4539
- children: /* @__PURE__ */ jsx(Text, {
4540
- ...quiet(c),
4541
- children: "Your answer goes straight back, and the session carries on."
4542
- })
4543
- })
4544
- ]
4545
- });
4546
- }
4547
3356
  // src/tui/screens/index.ts
4548
3357
  /** A screen file exports its component as `default` or as `<Name>Screen`. */
4549
3358
  const pick = (m, name) => {
@@ -4552,7 +3361,6 @@ const pick = (m, name) => {
4552
3361
  };
4553
3362
  const SCREEN_COMPONENTS = {
4554
3363
  sessions: pick(sessions_exports, "Sessions"),
4555
- you: pick(you_exports, "You"),
4556
3364
  new: pick(new_exports, "New"),
4557
3365
  devices: pick(devices_exports, "Devices"),
4558
3366
  setup: pick(setup_exports, "Setup")
@@ -4561,25 +3369,19 @@ const SCREEN_COMPONENTS = {
4561
3369
  /** The app shell: top bar, tabs, one screen, key bar, and the palette and help overlays. */
4562
3370
  const TOAST_MS = 3e3;
4563
3371
  const MIN_COLUMNS = 60;
4564
- /** Questions and permission requests that wait for the owner, plus messages nobody has read. */
4565
- const needYou = (s) => s.tickets.filter((t) => t.status === "open").length + s.unread;
4566
3372
  const SCREEN_LINE = {
4567
3373
  sessions: (s) => {
4568
3374
  const total = s.sessions.length;
4569
- if (total === 0) return "No sessions yet";
4570
- const live = s.sessions.filter((x) => x.status !== "offline").length;
4571
- return `${total} ${total === 1 ? "session" : "sessions"} · ${live} running`;
3375
+ if (total === 0) return "Nothing is running";
3376
+ return `${total} ${total === 1 ? "session" : "sessions"} running`;
4572
3377
  },
4573
- you: () => "Questions and messages for you",
4574
3378
  new: () => "Start something new",
4575
3379
  devices: () => "Your machines",
4576
3380
  setup: () => "Get your tools ready"
4577
3381
  };
4578
- function TopBar({ state, screen, width, onYou }) {
3382
+ function TopBar({ state, screen, width }) {
4579
3383
  const { c, ascii } = useTheme();
4580
- const need = needYou(state);
4581
3384
  const dot = ascii ? "*" : "●";
4582
- const right = need > 0 ? `${dot} ${need} need you` : "";
4583
3385
  let line = SCREEN_LINE[screen](state);
4584
3386
  let lineColor = c.quiet;
4585
3387
  if (state.connection === "connecting") line = "Connecting…";
@@ -4592,7 +3394,7 @@ function TopBar({ state, screen, width, onYou }) {
4592
3394
  }
4593
3395
  if (ascii) line = line.replace(/·/g, "-");
4594
3396
  const inner = width - 2;
4595
- const room = Math.max(0, inner - 11 - (right ? right.length + 2 : 0));
3397
+ const room = Math.max(0, inner - 11);
4596
3398
  return /* @__PURE__ */ jsxs(Band, {
4597
3399
  width,
4598
3400
  children: [
@@ -4619,30 +3421,20 @@ function TopBar({ state, screen, width, onYou }) {
4619
3421
  color: lineColor,
4620
3422
  children: line
4621
3423
  })
4622
- }),
4623
- /* @__PURE__ */ jsx(Box, { flexGrow: 1 }),
4624
- right ? /* @__PURE__ */ jsx(Clickable, {
4625
- onClick: onYou,
4626
- children: /* @__PURE__ */ jsx(Text, {
4627
- bold: true,
4628
- ...c.stamp ? { color: c.stamp } : {},
4629
- children: right
4630
- })
4631
- }) : null
3424
+ })
4632
3425
  ]
4633
3426
  });
4634
3427
  }
4635
3428
  /** The tab row, and under it the rule with the active tab underlined in the entry colour. */
4636
- function Tabs({ screen, layout, youCount, width, onGo }) {
3429
+ function Tabs({ screen, layout, width, onGo }) {
4637
3430
  const { c, ascii } = useTheme();
4638
3431
  const narrow = layout === "narrow";
4639
3432
  const labels = SCREENS.map((s) => {
4640
3433
  const on = s.id === screen;
4641
- const extra = s.id === "you" && youCount > 0 ? ` (${youCount})` : "";
4642
3434
  return {
4643
3435
  id: s.id,
4644
3436
  on,
4645
- text: narrow && !on ? s.key : `${s.key} ${s.title}${extra}`
3437
+ text: narrow && !on ? s.key : `${s.key} ${s.title}`
4646
3438
  };
4647
3439
  });
4648
3440
  const gap = 2;
@@ -4884,7 +3676,6 @@ function Shell({ store, onQuit, size, mouse }) {
4884
3676
  if (movedRef.current) return;
4885
3677
  if (!state.setup.clis.some((c) => c.status === "ready" || c.status === "needs-update") && state.setup.clis.length > 0) go("setup");
4886
3678
  }, [state.setup, go]);
4887
- const youCount = needYou(state);
4888
3679
  const draftCtx = useMemo(() => ({ cleared: () => {
4889
3680
  draftCleared.current = true;
4890
3681
  } }), []);
@@ -4985,13 +3776,11 @@ function Shell({ store, onQuit, size, mouse }) {
4985
3776
  /* @__PURE__ */ jsx(TopBar, {
4986
3777
  state,
4987
3778
  screen,
4988
- width: columns,
4989
- onYou: () => go("you")
3779
+ width: columns
4990
3780
  }),
4991
3781
  /* @__PURE__ */ jsx(Tabs, {
4992
3782
  screen,
4993
3783
  layout,
4994
- youCount,
4995
3784
  width: columns,
4996
3785
  onGo: go
4997
3786
  }),
@@ -5229,7 +4018,7 @@ async function loadSetup(ctx) {
5229
4018
  try {
5230
4019
  const client = await ctx.connect(connectOpts(ctx, false));
5231
4020
  try {
5232
- await client["session.list"]({ includeOffline: true });
4021
+ await client["session.list"]({});
5233
4022
  daemon = "running";
5234
4023
  const relay = await client["relay.status"]({}).catch(() => void 0);
5235
4024
  if (relay) {
@@ -5261,7 +4050,6 @@ function parseFixId(fixId) {
5261
4050
  kind,
5262
4051
  cli
5263
4052
  };
5264
- if (kind === "relay") return { kind };
5265
4053
  }
5266
4054
  async function planFor(ctx, fixId) {
5267
4055
  const parsed = parseFixId(fixId);
@@ -5269,16 +4057,12 @@ async function planFor(ctx, fixId) {
5269
4057
  items: [],
5270
4058
  error: "We don't know that fix."
5271
4059
  };
5272
- let adapters;
5273
- if (parsed.kind === "relay") adapters = ctx.adapters.filter((a) => a.permissionHookInstalled);
5274
- else {
5275
- const a = ctx.adapters.find((x) => x.cli === parsed.cli);
5276
- if (!a) return {
5277
- items: [],
5278
- error: "We don't know that CLI."
5279
- };
5280
- adapters = [a];
5281
- }
4060
+ const a = ctx.adapters.find((x) => x.cli === parsed.cli);
4061
+ if (!a) return {
4062
+ items: [],
4063
+ error: "We don't know that CLI."
4064
+ };
4065
+ const adapters = [a];
5282
4066
  const env = adapterEnv(ctx);
5283
4067
  const found = [];
5284
4068
  for (const adapter of adapters) {
@@ -5295,15 +4079,6 @@ async function planFor(ctx, fixId) {
5295
4079
  items: [],
5296
4080
  error: "It isn't installed."
5297
4081
  };
5298
- if (parsed.kind === "relay") {
5299
- const todo = [];
5300
- for (const f of found) if (!await f.adapter.permissionHookInstalled?.(env).catch(() => false)) todo.push(f);
5301
- const { items, failures } = await collectPlans(ctx, todo, "plan", void 0, { permissionRelay: true });
5302
- return {
5303
- items: items.filter((i) => i.change.component === "hooks"),
5304
- ...failures[0] ? { error: failures[0].message } : {}
5305
- };
5306
- }
5307
4082
  const { items, failures } = await collectPlans(ctx, found, parsed.kind === "init" ? "plan" : "uninstallPlan");
5308
4083
  return {
5309
4084
  items,
@@ -5345,41 +4120,18 @@ async function applyFix(ctx, fixId) {
5345
4120
  }
5346
4121
  }
5347
4122
  async function getExtras(ctx) {
5348
- const helpers = readSettings(dataPaths(ctx.platform, ctx.dataDir).settings).acpAdapterNpx === true;
5349
- const env = adapterEnv(ctx);
5350
- let any = false;
5351
- let all = true;
5352
- for (const a of ctx.adapters) {
5353
- if (!a.permissionHookInstalled) continue;
5354
- if (!(await a.detect(env).catch(() => ({ installed: false }))).installed) continue;
5355
- any = true;
5356
- if (!await a.permissionHookInstalled(env).catch(() => false)) all = false;
5357
- }
5358
- return {
5359
- helpers,
5360
- askBeforeRisky: any && all,
5361
- notifyDesktop: readSettings(dataPaths(ctx.platform, ctx.dataDir).settings).notifyDesktop !== false,
5362
- notifyForcedOff: notifyForcedOff(ctx.env)
5363
- };
4123
+ return { helpers: readSettings(dataPaths(ctx.platform, ctx.dataDir).settings).acpAdapterNpx === true };
5364
4124
  }
5365
4125
  /** Same answer as `conveno init --acp-adapters` / `--no-acp-adapters`. */
5366
4126
  function setHelpers(ctx, on) {
5367
4127
  writeSettings(dataPaths(ctx.platform, ctx.dataDir).settings, { acpAdapterNpx: on });
5368
4128
  }
5369
- /** Save the desktop notification choice. The daemon reads it on its next notification. */
5370
- function setNotify(ctx, on) {
5371
- writeSettings(dataPaths(ctx.platform, ctx.dataDir).settings, { notifyDesktop: on });
5372
- }
5373
4129
  // src/tui/store.ts
5374
4130
  /**
5375
4131
  * The app's data layer: one daemon connection, the state the screens read, and every action they
5376
4132
  * can take. It loads once, then follows `events.subscribe` and polls what has no event (sync and
5377
4133
  * devices). When the daemon goes away it says so and reconnects with a growing wait.
5378
4134
  */
5379
- /** How many messages the app holds in memory per session's chat. */
5380
- const HISTORY_KEEP = 1e3;
5381
- /** Page size when loading a session's chat from the daemon. */
5382
- const HISTORY_PAGE = 100;
5383
4135
  const POLL_MS = 15e3;
5384
4136
  const WATCH_MS = 5e3;
5385
4137
  const STOP_WAIT_MS = 1e4;
@@ -5392,16 +4144,9 @@ const BACKOFF_MS = [
5392
4144
  ];
5393
4145
  const initial = () => ({
5394
4146
  connection: "connecting",
5395
- sessions: [],
5396
- inbox: [],
5397
- unread: 0,
5398
- tickets: [],
5399
- history: {},
5400
- historyMore: {}
4147
+ sessions: []
5401
4148
  });
5402
4149
  const reason = (e) => e instanceof Error ? e.message : String(e);
5403
- /** The tickets the owner can act on: addressed to them, or a permission request. */
5404
- const forOwner = (t) => t.toSession === OWNER_SESSION_ID || t.kind === "permission";
5405
4150
  function upsert(list, item) {
5406
4151
  const i = list.findIndex((x) => x.id === item.id);
5407
4152
  if (i < 0) return [...list, item];
@@ -5409,9 +4154,8 @@ function upsert(list, item) {
5409
4154
  next[i] = item;
5410
4155
  return next;
5411
4156
  }
5412
- /** Time order; the id (a ULID) breaks ties. */
5413
- const byTime = (a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id);
5414
- const byCreated = (a, b) => a.createdAt.localeCompare(b.createdAt);
4157
+ /** Only sessions that are online show in the app. */
4158
+ const online = (list) => list.filter((s) => s.status !== "offline");
5415
4159
  async function createStore(ctx, opts = {}) {
5416
4160
  const open = opts.connect ?? (() => ctx.connect(connectOpts(ctx, true)));
5417
4161
  const backoff = opts.backoffMs ?? BACKOFF_MS;
@@ -5433,59 +4177,11 @@ async function createStore(ctx, opts = {}) {
5433
4177
  if (!client || state.connection === "daemon-down") throw new Error("Conveno's background service is not running right now. Trying to reconnect.");
5434
4178
  return client;
5435
4179
  };
5436
- /** Which session a message belongs to in the chat view: the other side of the conversation. */
5437
- /** Every session whose chat shows this message: the sender and the recipient (not `you`). */
5438
- function historyKeys(m) {
5439
- const keys = /* @__PURE__ */ new Set();
5440
- if (m.from !== OWNER_SESSION_ID) keys.add(m.from);
5441
- const to = m.to;
5442
- const target = isLeadAlias(to) ? state.sessions.find((s) => s.isOrchestrator) : state.sessions.find((s) => s.id === to || s.name === to);
5443
- if (target) keys.add(target.id);
5444
- return [...keys];
5445
- }
5446
- /** Merge messages into a session's chat: no duplicates, oldest first, at most HISTORY_KEEP. */
5447
- function mergeHistory(cur, add, keep) {
5448
- const seen = new Set(cur.map((x) => x.id));
5449
- const fresh = add.filter((x) => !seen.has(x.id));
5450
- if (fresh.length === 0) return cur;
5451
- const all = [...cur, ...fresh].sort(byTime);
5452
- if (all.length <= 1e3) return all;
5453
- return keep === "newest" ? all.slice(-1e3) : all.slice(0, HISTORY_KEEP);
5454
- }
5455
- function addMessage(m) {
5456
- const patch = {};
5457
- if (m.to === "you" && !state.inbox.some((x) => x.id === m.id)) {
5458
- patch.inbox = [...state.inbox, m].sort(byCreated).slice(-100);
5459
- patch.unread = state.unread + 1;
5460
- }
5461
- for (const key of historyKeys(m)) {
5462
- const cur = (patch.history ?? state.history)[key] ?? [];
5463
- if (cur.some((x) => x.id === m.id)) continue;
5464
- patch.history = {
5465
- ...patch.history ?? state.history,
5466
- [key]: mergeHistory(cur, [m], "newest")
5467
- };
5468
- if (cur.length >= 1e3) patch.historyMore = {
5469
- ...patch.historyMore ?? state.historyMore,
5470
- [key]: true
5471
- };
5472
- }
5473
- if (patch.inbox || patch.history) set(patch);
5474
- }
5475
4180
  function applyEvent(e) {
5476
4181
  switch (e.event) {
5477
- case "message.received":
5478
- addMessage(e.data.message);
5479
- break;
5480
- case "ticket.created":
5481
- case "ticket.answered": {
5482
- const t = e.data.ticket;
5483
- if (forOwner(t)) set({ tickets: upsert(state.tickets, t) });
5484
- break;
5485
- }
5486
4182
  case "session.updated": {
5487
4183
  const s = e.data.session;
5488
- if (e.data.change === "unregistered") set({ sessions: state.sessions.filter((x) => x.id !== s.id) });
4184
+ if (e.data.change === "unregistered" || s.status === "offline") set({ sessions: state.sessions.filter((x) => x.id !== s.id) });
5489
4185
  else set({ sessions: upsert(state.sessions, s) });
5490
4186
  break;
5491
4187
  }
@@ -5530,28 +4226,8 @@ async function createStore(ctx, opts = {}) {
5530
4226
  }
5531
4227
  /** Everything the screens need, in one pass. Safe to call again after a reconnect. */
5532
4228
  async function load(c) {
5533
- const [sessions, inbox, open, answered] = await Promise.all([
5534
- c["session.list"]({ includeOffline: true }),
5535
- c["owner.inbox"]({ limit: 200 }),
5536
- c["ticket.list"]({
5537
- status: "open",
5538
- limit: 200
5539
- }),
5540
- c["ticket.list"]({
5541
- status: "answered",
5542
- limit: 50
5543
- }).catch(() => ({ tickets: [] }))
5544
- ]);
5545
- const tickets = [...open.tickets, ...answered.tickets].filter(forOwner);
5546
- const history = { ...state.history };
5547
- for (const m of inbox.messages) history[m.from] = mergeHistory(history[m.from] ?? [], [m], "newest");
5548
- set({
5549
- sessions: sessions.sessions,
5550
- inbox: inbox.messages.slice(-100),
5551
- unread: inbox.unreadCount,
5552
- tickets,
5553
- history
5554
- });
4229
+ const r = await c["session.list"]({});
4230
+ set({ sessions: online(r.sessions) });
5555
4231
  }
5556
4232
  async function attach(c) {
5557
4233
  client = c;
@@ -5597,8 +4273,8 @@ async function createStore(ctx, opts = {}) {
5597
4273
  const c = client;
5598
4274
  if (!c || reconnecting || closed) return;
5599
4275
  try {
5600
- const r = await c["session.list"]({ includeOffline: true });
5601
- set({ sessions: r.sessions });
4276
+ const r = await c["session.list"]({});
4277
+ set({ sessions: online(r.sessions) });
5602
4278
  } catch {
5603
4279
  reconnect();
5604
4280
  }
@@ -5606,43 +4282,34 @@ async function createStore(ctx, opts = {}) {
5606
4282
  const nameOf = (id) => state.sessions.find((s) => s.id === id)?.name;
5607
4283
  const actions = {
5608
4284
  async send(to, text) {
5609
- addMessage((await live()["owner.send"]({
4285
+ await live()["owner.send"]({
5610
4286
  to,
5611
4287
  text
5612
- })).message);
5613
- },
5614
- async answerTicket(ticketId, response) {
5615
- const res = await live()["ticket.answer"]({
5616
- ticketId,
5617
- response
5618
4288
  });
5619
- set({ tickets: upsert(state.tickets, res.ticket) });
5620
4289
  },
5621
- async decide(ticketId, allow) {
5622
- const res = await live()["ticket.answer"]({
5623
- ticketId,
5624
- response: allow ? PERMISSION_ANSWERS[0] : PERMISSION_ANSWERS[1]
5625
- });
5626
- set({ tickets: upsert(state.tickets, res.ticket) });
4290
+ async setLead(sessionId) {
4291
+ await live()["orchestrator.claim"]({ sessionId });
4292
+ set({ sessions: state.sessions.map((s) => ({
4293
+ ...s,
4294
+ isOrchestrator: s.id === sessionId
4295
+ })) });
5627
4296
  },
5628
- async setAuto(sessionId, on) {
5629
- const res = await live()["session.setAuto"]({
5630
- session: sessionId,
5631
- auto: on
5632
- });
5633
- set({ sessions: upsert(state.sessions, res.session) });
4297
+ async clearLead() {
4298
+ await live()["orchestrator.clear"]({});
4299
+ set({ sessions: state.sessions.map((s) => ({
4300
+ ...s,
4301
+ isOrchestrator: false
4302
+ })) });
5634
4303
  },
5635
4304
  async stop(sessionId) {
5636
4305
  const name = nameOf(sessionId);
5637
4306
  const rec = name ? readSpawnRecord(spawnRecordPath(ctx.dataDir, name)) : void 0;
5638
4307
  if (!name || !rec) throw new Error("Only sessions started from Conveno on this machine can be stopped here.");
5639
- if (!rec.headless) throw new Error(`${name} runs in a window. Close it there.`);
4308
+ if (!rec.acp) throw new Error(`${name} runs in a window. Close it there.`);
5640
4309
  const alive = () => rec.pid !== void 0 && ctx.isAlive(rec.pid);
5641
- if (rec.acp) {
5642
- writeFileSync(stopRequestPath(spawnRecordPath(ctx.dataDir, rec.name)), "", { mode: 384 });
5643
- const end = Date.now() + STOP_WAIT_MS;
5644
- while (alive() && Date.now() < end) await new Promise((r) => setTimeout(r, 100));
5645
- }
4310
+ writeFileSync(stopRequestPath(spawnRecordPath(ctx.dataDir, rec.name)), "", { mode: 384 });
4311
+ const end = Date.now() + STOP_WAIT_MS;
4312
+ while (alive() && Date.now() < end) await new Promise((r) => setTimeout(r, 100));
5646
4313
  if (alive() && rec.pid !== void 0) killProcessTree(rec.pid, ctx.platform);
5647
4314
  if (rec.agentPid !== void 0 && ctx.isAlive(rec.agentPid)) killProcessTree(rec.agentPid, ctx.platform);
5648
4315
  },
@@ -5653,24 +4320,6 @@ async function createStore(ctx, opts = {}) {
5653
4320
  });
5654
4321
  set({ sessions: upsert(state.sessions, res.session) });
5655
4322
  },
5656
- async forget(sessionId) {
5657
- await live()["session.forget"]({ ids: [sessionId] });
5658
- set({ sessions: state.sessions.filter((s) => s.id !== sessionId) });
5659
- },
5660
- async peek(sessionId) {
5661
- const r = await live()["session.peek"]({ target: sessionId });
5662
- return {
5663
- session: r.session.id,
5664
- mode: "recent",
5665
- turns: r.turns.map((t) => ({
5666
- role: t.role,
5667
- text: t.text,
5668
- ...t.at ? { ts: t.at } : {}
5669
- })),
5670
- truncated: r.truncated,
5671
- redacted: true
5672
- };
5673
- },
5674
4323
  async spawn(p) {
5675
4324
  const c = live();
5676
4325
  const runner = ctx.spawnRunner ?? [process.execPath, process.argv[1] ?? "conveno"];
@@ -5682,65 +4331,15 @@ async function createStore(ctx, opts = {}) {
5682
4331
  client: c,
5683
4332
  runner
5684
4333
  });
5685
- const res = await spawnSession(deps, {
4334
+ return { sessionId: (await spawnSession(deps, {
5686
4335
  cli: p.cli,
5687
4336
  callerCwd: ctx.cwd,
5688
4337
  cwd: p.cwd,
5689
4338
  name: p.name,
5690
4339
  task: p.prompt,
5691
- headless: p.mode !== "visible",
5692
- acp: p.mode === "acp" ? "require" : void 0,
4340
+ window: p.window,
5693
4341
  confineToHome: false
5694
- });
5695
- if (p.auto) await c["session.setAuto"]({
5696
- session: res.id,
5697
- auto: true
5698
- }).catch(() => void 0);
5699
- return { sessionId: res.id };
5700
- },
5701
- async loadHistory(sessionId) {
5702
- const res = await live()["message.history"]({
5703
- session: sessionId,
5704
- limit: HISTORY_PAGE
5705
- });
5706
- const cur = state.history[sessionId] ?? [];
5707
- set({
5708
- history: {
5709
- ...state.history,
5710
- [sessionId]: mergeHistory(cur, res.messages, "newest")
5711
- },
5712
- historyMore: {
5713
- ...state.historyMore,
5714
- [sessionId]: res.more
5715
- }
5716
- });
5717
- },
5718
- async loadOlder(sessionId) {
5719
- const cur = state.history[sessionId] ?? [];
5720
- const oldest = cur[0];
5721
- if (!oldest) {
5722
- await actions.loadHistory(sessionId);
5723
- return (state.history[sessionId]?.length ?? 0) > 0;
5724
- }
5725
- if (state.historyMore[sessionId] === false || cur.length >= 1e3) return false;
5726
- const res = await live()["message.history"]({
5727
- session: sessionId,
5728
- limit: HISTORY_PAGE,
5729
- before: oldest.id
5730
- });
5731
- const now = state.history[sessionId] ?? [];
5732
- const merged = mergeHistory(now, res.messages, "oldest");
5733
- set({
5734
- history: {
5735
- ...state.history,
5736
- [sessionId]: merged
5737
- },
5738
- historyMore: {
5739
- ...state.historyMore,
5740
- [sessionId]: res.more && merged.length < 1e3
5741
- }
5742
- });
5743
- return merged.length > now.length;
4342
+ })).id };
5744
4343
  },
5745
4344
  async refreshSetup() {
5746
4345
  await loadSetupData();
@@ -5754,9 +4353,6 @@ async function createStore(ctx, opts = {}) {
5754
4353
  async setHelpers(on) {
5755
4354
  setHelpers(ctx, on);
5756
4355
  },
5757
- async setNotify(on) {
5758
- setNotify(ctx, on);
5759
- },
5760
4356
  pair: async () => {
5761
4357
  const r = await startPair(live());
5762
4358
  return {
@@ -5778,15 +4374,6 @@ async function createStore(ctx, opts = {}) {
5778
4374
  async cancelPair() {
5779
4375
  await cancelPair(live());
5780
4376
  },
5781
- async markRead(ids) {
5782
- const c = live();
5783
- let acked = 0;
5784
- for (let i = 0; i < ids.length; i += 100) {
5785
- const res = await c["owner.ack"]({ ids: ids.slice(i, i + 100) });
5786
- acked += res.acked;
5787
- }
5788
- if (acked > 0) set({ unread: Math.max(0, state.unread - acked) });
5789
- },
5790
4377
  async revokeDevice(deviceId) {
5791
4378
  await live()["devices.revoke"]({ device: deviceId });
5792
4379
  await pollRelay(live());