@conveno/cli 0.2.0-rc.4 → 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-Bckon1ju.js";
4
- import { d as plainError, l as fail, m as tilde, o as cmd } from "./args-DEYV4Ran.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 { At as readSettings, D as compatStatus, G as fetchAccountStatus, N as dataPaths, Nt as realSpawnDeps, Tt as readAccountTokens, Ut as spawnRecordPath, Wt as spawnSession, _n as PERMISSION_ANSWERS, gn as OWNER_SESSION_ID, in as writeSettings, jt as readSpawnRecord, l as SPAWN_TABLE } from "./dist-DUqXHTRg.js";
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-CuStS_nO.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 + 3;
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;
@@ -3676,11 +2999,6 @@ function SetupScreen(props) {
3676
2999
  }, () => toast("Couldn't change that. Try again.", "error"));
3677
3000
  return;
3678
3001
  }
3679
- if (row === 1) {
3680
- if (extras.askBeforeRisky) return toast("Already on. Each worker stays off until you turn it on for it.", "ok");
3681
- open(["relay:on"], "Ask me before risky commands (beta)");
3682
- return;
3683
- }
3684
3002
  const { ids, skipped } = idsFor(clis, picked, cur?.cli);
3685
3003
  if (ids.length === 0) return toast(skipped ?? "Nothing to set up here.", "warn");
3686
3004
  const names = clis.filter((x) => ids.includes(`init:${x.cli}`)).map((x) => x.label);
@@ -3998,15 +3316,7 @@ function SetupScreen(props) {
3998
3316
  setUp({ extra: 1 });
3999
3317
  },
4000
3318
  isActive: active,
4001
- children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 1)} ${box(extras.askBeforeRisky)} Ask me before risky commands (beta)` })
4002
- }),
4003
- /* @__PURE__ */ jsx(Hit, {
4004
- onClick: () => {
4005
- setCursor(clis.length + 2);
4006
- setUp({ extra: 2 });
4007
- },
4008
- isActive: active,
4009
- children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 2)} ${box(mouseOn)} Click and scroll with the mouse` })
3319
+ children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 1)} ${box(mouseOn)} Click and scroll with the mouse` })
4010
3320
  }),
4011
3321
  !wide && health.length > 0 && rows >= 22 ? /* @__PURE__ */ jsxs(Box, {
4012
3322
  flexDirection: "column",
@@ -4043,484 +3353,6 @@ function SetupScreen(props) {
4043
3353
  }) : null]
4044
3354
  });
4045
3355
  }
4046
- // src/tui/screens/you.tsx
4047
- var you_exports = /* @__PURE__ */ __exportAll({ default: () => You });
4048
- /** Cards stop growing here, so they stay readable on a very wide terminal. */
4049
- const MAX_MAIN = 110;
4050
- const quiet = (c) => c.quiet ? { color: c.quiet } : { dimColor: true };
4051
- /** `m:ss` left until `iso`, or undefined when there is no time limit. */
4052
- function timeLeft(iso, now) {
4053
- if (!iso) return void 0;
4054
- const t = Date.parse(iso);
4055
- if (Number.isNaN(t)) return void 0;
4056
- const s = Math.max(0, Math.ceil((t - now) / 1e3));
4057
- return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
4058
- }
4059
- function sameDay(iso, now) {
4060
- if (!iso) return false;
4061
- const a = new Date(iso);
4062
- const b = new Date(now);
4063
- return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
4064
- }
4065
- function You(props) {
4066
- const { state, actions, layout, rows, columns, active, setKeys, setCommands, toast, setTyping, claimKeys } = props;
4067
- const { c, ascii } = useTheme();
4068
- const wide = layout === "wide";
4069
- const [selKey, setSelKey] = useState(props.focus ? `t:${props.focus}` : void 0);
4070
- const [typed, setTyped] = useState(void 0);
4071
- const [draft, setDraft] = useState("");
4072
- const [now, setNow] = useState(() => Date.now());
4073
- const nameOf = (id, fallback) => fallback ?? state.sessions.find((s) => s.id === id)?.name ?? "a session";
4074
- const open = useMemo(() => state.tickets.filter((t) => t.status === "open").sort((a, b) => a.createdAt.localeCompare(b.createdAt)), [state.tickets]);
4075
- const inbox = useMemo(() => state.inbox.filter((m) => !isFromOwner(m)).sort((a, b) => b.createdAt.localeCompare(a.createdAt)), [state.inbox]);
4076
- const order = useMemo(() => [...open.map((t) => `t:${t.id}`), ...inbox.map((m) => `m:${m.id}`)], [open, inbox]);
4077
- const curKey = order[Math.max(0, order.indexOf(selKey ?? ""))];
4078
- const curTicket = curKey?.startsWith("t:") ? open.find((t) => `t:${t.id}` === curKey) : void 0;
4079
- const curMessage = curKey?.startsWith("m:") ? inbox.find((m) => `m:${m.id}` === curKey) : void 0;
4080
- const hasPermission = open.some((t) => t.kind === "permission");
4081
- useEffect(() => {
4082
- if (!hasPermission) return;
4083
- const id = setInterval(() => setNow(Date.now()), 1e3);
4084
- return () => clearInterval(id);
4085
- }, [hasPermission]);
4086
- const optionCount = !typed && curTicket && curTicket.kind !== "permission" ? curTicket.options?.length ?? 0 : 0;
4087
- const claimsDigits = optionCount > 0;
4088
- const typing = active && typed !== void 0;
4089
- useEffect(() => {
4090
- setTyping(typing);
4091
- return () => setTyping(false);
4092
- }, [typing, setTyping]);
4093
- useEffect(() => {
4094
- const keys = active ? Array.from({ length: Math.min(optionCount, 9) }, (_, i) => String(i + 1)) : [];
4095
- claimKeys(keys);
4096
- return () => claimKeys([]);
4097
- }, [
4098
- active,
4099
- optionCount,
4100
- claimKeys
4101
- ]);
4102
- const acked = useRef(/* @__PURE__ */ new Set());
4103
- useEffect(() => {
4104
- if (!active || state.unread === 0) return;
4105
- const ids = inbox.map((m) => m.id).filter((id) => !acked.current.has(id));
4106
- if (ids.length === 0) return;
4107
- for (const id of ids) acked.current.add(id);
4108
- actions.markRead(ids).catch(() => {
4109
- for (const id of ids) acked.current.delete(id);
4110
- });
4111
- }, [
4112
- active,
4113
- state.unread,
4114
- inbox,
4115
- actions
4116
- ]);
4117
- useEffect(() => {
4118
- const keys = typed ? [{
4119
- key: "⏎",
4120
- label: "send"
4121
- }, {
4122
- key: "Esc",
4123
- label: "cancel"
4124
- }] : [{
4125
- key: "↑↓",
4126
- label: "move"
4127
- }];
4128
- if (!typed) {
4129
- if (curTicket?.kind === "permission") keys.push({
4130
- key: "y",
4131
- label: "allow once"
4132
- }, {
4133
- key: "n",
4134
- label: "deny"
4135
- });
4136
- else if (curTicket) {
4137
- if (claimsDigits) keys.push({
4138
- key: "1-9",
4139
- label: "answer"
4140
- });
4141
- keys.push({
4142
- key: "⏎",
4143
- label: "type an answer"
4144
- });
4145
- } else if (curMessage) keys.push({
4146
- key: "⏎",
4147
- label: "reply"
4148
- });
4149
- }
4150
- setKeys(keys);
4151
- }, [
4152
- setKeys,
4153
- typed,
4154
- curTicket,
4155
- curMessage,
4156
- claimsDigits
4157
- ]);
4158
- useEffect(() => {
4159
- setCommands([]);
4160
- }, [setCommands]);
4161
- const done = (text) => {
4162
- setTyped(void 0);
4163
- setDraft("");
4164
- toast(text);
4165
- };
4166
- const failed = () => toast("That didn't go through. Try again.", "error");
4167
- const answer = (t, text) => actions.answerTicket(t.id, text).then(() => done("Sent"), failed);
4168
- const decide = (t, allow) => actions.decide(t.id, allow).then(() => done(allow ? "Allowed" : "Denied"), failed);
4169
- const submit = (text) => {
4170
- const t = text.trim();
4171
- if (!typed || t === "") return;
4172
- if (typed.kind === "answer") answer(typed.ticket, t);
4173
- else {
4174
- const to = typed.message.fromName;
4175
- if (!to) return toast("You can't reply to that one.", "warn");
4176
- const id = typed.message.id;
4177
- actions.send(to, t).then(() => {
4178
- done("Sent");
4179
- acked.current.add(id);
4180
- actions.markRead([id]).catch(() => void 0);
4181
- }, failed);
4182
- }
4183
- };
4184
- const step = (d) => setSelKey((prev) => {
4185
- const at = Math.max(0, order.indexOf(prev ?? order[0] ?? ""));
4186
- return order[Math.max(0, Math.min(order.length - 1, at + d))];
4187
- });
4188
- const pick = (key) => {
4189
- if (typed) {
4190
- setTyped(void 0);
4191
- setDraft("");
4192
- }
4193
- setSelKey(key);
4194
- };
4195
- useInput((input, key) => {
4196
- if (typed) {
4197
- if (key.escape) {
4198
- setTyped(void 0);
4199
- setDraft("");
4200
- }
4201
- return;
4202
- }
4203
- if (key.upArrow || key.downArrow) return step(key.upArrow ? -1 : 1);
4204
- if (key.return) {
4205
- if (curTicket && curTicket.kind !== "permission") setTyped({
4206
- kind: "answer",
4207
- ticket: curTicket
4208
- });
4209
- else if (curMessage) setTyped({
4210
- kind: "reply",
4211
- message: curMessage
4212
- });
4213
- return;
4214
- }
4215
- if (curTicket?.kind === "permission") {
4216
- if (input === "y") decide(curTicket, true);
4217
- else if (input === "n") decide(curTicket, false);
4218
- return;
4219
- }
4220
- if (curTicket && claimsDigits && /^[1-9]$/.test(input)) {
4221
- const opt = curTicket.options?.[Number(input) - 1];
4222
- if (opt !== void 0) answer(curTicket, opt);
4223
- }
4224
- }, { isActive: active });
4225
- const split = splitWidths(columns, wide, { maxMain: MAX_MAIN });
4226
- const listW = wide ? split.mainW - 2 : Math.min(columns, MAX_MAIN);
4227
- const inner = listW - 4;
4228
- const dot = ascii ? "!" : "⚑";
4229
- const textBox = (placeholder) => /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Text, {
4230
- ...c.entry ? { color: c.entry } : {},
4231
- children: ascii ? "> " : "› "
4232
- }), /* @__PURE__ */ jsx(Box, {
4233
- width: Math.max(4, inner - 2),
4234
- children: /* @__PURE__ */ jsx(TextBox, {
4235
- value: draft,
4236
- onChange: setDraft,
4237
- onSubmit: submit,
4238
- focus: active,
4239
- multiline: true,
4240
- placeholder
4241
- })
4242
- })] });
4243
- const items = [];
4244
- const head = (text, first) => /* @__PURE__ */ jsx(Box, {
4245
- marginTop: first ? 0 : 1,
4246
- children: /* @__PURE__ */ jsx(Label, { children: plain(text, ascii) })
4247
- });
4248
- if (open.length === 0) items.push({
4249
- key: "none",
4250
- height: 2,
4251
- node: /* @__PURE__ */ jsxs(Box, {
4252
- flexDirection: "column",
4253
- children: [head("Needs you · 0", true), /* @__PURE__ */ jsx(Text, {
4254
- ...quiet(c),
4255
- children: "Nothing needs you right now."
4256
- })]
4257
- })
4258
- });
4259
- open.forEach((t, i) => {
4260
- const key = `t:${t.id}`;
4261
- const isSel = key === curKey;
4262
- const who = nameOf(t.fromSession);
4263
- const accent = isSel ? c.stamp : c.rule;
4264
- const mark = isSel ? ascii ? "> " : "▸ " : " ";
4265
- const editing = typed?.kind === "answer" && typed.ticket.id === t.id;
4266
- const lines = [];
4267
- let body = 0;
4268
- if (t.kind === "permission") {
4269
- const left = timeLeft(t.expiresAt, now);
4270
- const cmd = wrapLines(t.question, inner - 2).slice(0, 2);
4271
- body = 2 + cmd.length;
4272
- lines.push(/* @__PURE__ */ jsx(Ell, {
4273
- width: inner,
4274
- bold: true,
4275
- color: c.stamp,
4276
- children: `${mark}${dot} Wants to run a command ${who}`
4277
- }, "t"), /* @__PURE__ */ jsx(Box, {
4278
- backgroundColor: c.sunken,
4279
- paddingX: 1,
4280
- flexDirection: "column",
4281
- children: cmd.map((l, j) => /* @__PURE__ */ jsx(Ell, {
4282
- width: inner - 2,
4283
- children: l === "" ? " " : l
4284
- }, j))
4285
- }, "c"), /* @__PURE__ */ jsxs(Box, {
4286
- width: inner,
4287
- height: 1,
4288
- overflow: "hidden",
4289
- children: [
4290
- /* @__PURE__ */ jsx(Hit, {
4291
- onClick: () => void decide(t, true),
4292
- flexShrink: 0,
4293
- isActive: active,
4294
- children: /* @__PURE__ */ jsx(Text, {
4295
- ...quiet(c),
4296
- children: "y allow once"
4297
- })
4298
- }),
4299
- /* @__PURE__ */ jsx(Text, {
4300
- ...quiet(c),
4301
- children: " "
4302
- }),
4303
- /* @__PURE__ */ jsx(Hit, {
4304
- onClick: () => void decide(t, false),
4305
- flexShrink: 0,
4306
- isActive: active,
4307
- children: /* @__PURE__ */ jsx(Text, {
4308
- ...quiet(c),
4309
- children: "n deny"
4310
- })
4311
- }),
4312
- /* @__PURE__ */ jsx(Text, {
4313
- ...quiet(c),
4314
- wrap: "truncate",
4315
- children: left ? ` denied by itself in ${left}` : ""
4316
- })
4317
- ]
4318
- }, "k"));
4319
- } else {
4320
- const q = wrapLines(t.question, inner).slice(0, 3);
4321
- lines.push(/* @__PURE__ */ jsx(Ell, {
4322
- width: inner,
4323
- bold: true,
4324
- color: c.stamp,
4325
- children: plain(`${mark}? Question from ${who} · ${clockTime(t.createdAt)}`, ascii)
4326
- }, "t"), ...q.map((l, j) => /* @__PURE__ */ jsx(Ell, {
4327
- width: inner,
4328
- children: l === "" ? " " : l
4329
- }, `q${j}`)));
4330
- body = 2 + q.length + (editing ? draft.split("\n").length - 1 : 0);
4331
- const options = t.options ?? [];
4332
- const typeOwn = () => {
4333
- setSelKey(key);
4334
- setDraft("");
4335
- setTyped({
4336
- kind: "answer",
4337
- ticket: t
4338
- });
4339
- };
4340
- if (editing) lines.push(/* @__PURE__ */ jsx(Box, { children: textBox("Type your answer…") }, "b"));
4341
- else lines.push(/* @__PURE__ */ jsxs(Box, {
4342
- width: inner,
4343
- height: 1,
4344
- overflow: "hidden",
4345
- children: [options.map((o, j) => /* @__PURE__ */ jsxs(Box, {
4346
- flexShrink: 0,
4347
- children: [/* @__PURE__ */ jsx(Hit, {
4348
- onClick: () => void answer(t, o),
4349
- flexShrink: 0,
4350
- isActive: active,
4351
- children: /* @__PURE__ */ jsx(Text, {
4352
- ...quiet(c),
4353
- children: `[${j + 1}] ${o}`
4354
- })
4355
- }), /* @__PURE__ */ jsx(Text, {
4356
- ...quiet(c),
4357
- children: " "
4358
- })]
4359
- }, j)), /* @__PURE__ */ jsx(Hit, {
4360
- onClick: typeOwn,
4361
- flexShrink: 0,
4362
- isActive: active,
4363
- children: /* @__PURE__ */ jsx(Text, {
4364
- ...quiet(c),
4365
- wrap: "truncate",
4366
- children: options.length > 0 ? " or type your own" : "Press Enter to type an answer"
4367
- })
4368
- })]
4369
- }, "o"));
4370
- }
4371
- const height = body + 2;
4372
- items.push({
4373
- key,
4374
- height: height + (i === 0 ? 1 : 0),
4375
- node: /* @__PURE__ */ jsxs(Box, {
4376
- flexDirection: "column",
4377
- children: [i === 0 ? head(`Needs you · ${open.length}`, true) : null, /* @__PURE__ */ jsx(Hit, {
4378
- onClick: () => pick(key),
4379
- isActive: active,
4380
- children: /* @__PURE__ */ jsx(Card, {
4381
- accent,
4382
- width: listW,
4383
- children: lines
4384
- })
4385
- })]
4386
- })
4387
- });
4388
- });
4389
- inbox.forEach((m, i) => {
4390
- const key = `m:${m.id}`;
4391
- const isSel = key === curKey;
4392
- const who = m.fromName ?? nameOf(m.from);
4393
- const editing = typed?.kind === "reply" && typed.message.id === m.id;
4394
- const line = `${isSel ? ascii ? "> " : "▸ " : " "}${clockTime(m.createdAt)} ${who} ${messageText(m)}`;
4395
- items.push({
4396
- key,
4397
- height: (i === 0 ? 2 : 0) + 1 + (editing ? 1 : 0),
4398
- node: /* @__PURE__ */ jsxs(Box, {
4399
- flexDirection: "column",
4400
- children: [
4401
- i === 0 ? head(`Messages · ${inbox.length}`, false) : null,
4402
- /* @__PURE__ */ jsx(Hit, {
4403
- onClick: () => {
4404
- setSelKey(key);
4405
- setDraft("");
4406
- setTyped({
4407
- kind: "reply",
4408
- message: m
4409
- });
4410
- },
4411
- isActive: active,
4412
- children: /* @__PURE__ */ jsx(Row, {
4413
- width: listW,
4414
- selected: isSel,
4415
- children: /* @__PURE__ */ jsx(Ell, {
4416
- width: listW,
4417
- bold: isSel,
4418
- children: line
4419
- })
4420
- })
4421
- }),
4422
- editing ? /* @__PURE__ */ jsx(Box, {
4423
- paddingLeft: 2,
4424
- children: textBox(`Reply to ${who}…`)
4425
- }) : null
4426
- ]
4427
- })
4428
- });
4429
- });
4430
- if (inbox.length === 0) items.push({
4431
- key: "nomsg",
4432
- height: 3,
4433
- node: /* @__PURE__ */ jsxs(Box, {
4434
- flexDirection: "column",
4435
- children: [head("Messages · 0", false), /* @__PURE__ */ jsx(Text, {
4436
- ...quiet(c),
4437
- children: "No messages yet."
4438
- })]
4439
- })
4440
- });
4441
- const selItem = Math.max(0, items.findIndex((x) => x.key === curKey));
4442
- let start = 0;
4443
- const sum = (a, b) => items.slice(a, b).reduce((n, x) => n + x.height, 0);
4444
- while (start < selItem && sum(start, selItem + 1) > rows) start++;
4445
- const shown = [];
4446
- let used = 0;
4447
- for (const it of items.slice(start)) {
4448
- if (used + it.height > rows && shown.length > 0) break;
4449
- shown.push(it);
4450
- used += it.height;
4451
- }
4452
- return /* @__PURE__ */ jsxs(Box, {
4453
- width: columns,
4454
- height: rows,
4455
- children: [/* @__PURE__ */ jsx(Hit, {
4456
- flexDirection: "column",
4457
- width: wide ? split.mainW : listW,
4458
- flexShrink: 0,
4459
- onWheel: (d) => {
4460
- if (!typed) step(d < 0 ? -1 : 1);
4461
- },
4462
- isActive: active,
4463
- children: shown.map((it) => /* @__PURE__ */ jsx(Box, { children: it.node }, it.key))
4464
- }), wide ? /* @__PURE__ */ jsx(Pane, {
4465
- width: split.panelW,
4466
- height: rows,
4467
- children: /* @__PURE__ */ jsx(SidePanel, {
4468
- state,
4469
- width: paneInner(split.panelW),
4470
- now,
4471
- nameOf,
4472
- active,
4473
- onPick: pick
4474
- })
4475
- }) : null]
4476
- });
4477
- }
4478
- function SidePanel({ state, width, now, nameOf, active, onPick }) {
4479
- const { c, ascii } = useTheme();
4480
- const open = state.tickets.filter((t) => t.status === "open");
4481
- const doneToday = state.tickets.filter((t) => t.status !== "open" && sameDay(t.answeredAt ?? t.createdAt, now));
4482
- const tick = ascii ? "ok" : "✓";
4483
- return /* @__PURE__ */ jsxs(Box, {
4484
- width,
4485
- flexDirection: "column",
4486
- children: [
4487
- /* @__PURE__ */ jsx(Label, { children: `Open · ${open.length}` }),
4488
- open.length === 0 ? /* @__PURE__ */ jsx(Text, {
4489
- ...quiet(c),
4490
- children: "Nothing open."
4491
- }) : null,
4492
- open.slice(0, 6).map((t) => /* @__PURE__ */ jsx(Hit, {
4493
- onClick: () => onPick(`t:${t.id}`),
4494
- isActive: active,
4495
- children: /* @__PURE__ */ jsx(Ell, {
4496
- width,
4497
- color: c.stamp,
4498
- children: `${t.kind === "permission" ? ascii ? "!" : "⚑" : "?"} ${nameOf(t.fromSession)} ${t.question}`
4499
- })
4500
- }, t.id)),
4501
- /* @__PURE__ */ jsx(Box, {
4502
- marginTop: 1,
4503
- children: /* @__PURE__ */ jsx(Label, { children: `Done today · ${doneToday.length}` })
4504
- }),
4505
- doneToday.length === 0 ? /* @__PURE__ */ jsx(Text, {
4506
- ...quiet(c),
4507
- children: "Nothing yet."
4508
- }) : null,
4509
- doneToday.slice(0, 6).map((t) => /* @__PURE__ */ jsx(Ell, {
4510
- width,
4511
- color: c.quiet,
4512
- children: `${tick} ${nameOf(t.fromSession)} ${t.question}`
4513
- }, t.id)),
4514
- /* @__PURE__ */ jsx(Box, {
4515
- marginTop: 1,
4516
- children: /* @__PURE__ */ jsx(Text, {
4517
- ...quiet(c),
4518
- children: "Your answer goes straight back, and the session carries on."
4519
- })
4520
- })
4521
- ]
4522
- });
4523
- }
4524
3356
  // src/tui/screens/index.ts
4525
3357
  /** A screen file exports its component as `default` or as `<Name>Screen`. */
4526
3358
  const pick = (m, name) => {
@@ -4529,7 +3361,6 @@ const pick = (m, name) => {
4529
3361
  };
4530
3362
  const SCREEN_COMPONENTS = {
4531
3363
  sessions: pick(sessions_exports, "Sessions"),
4532
- you: pick(you_exports, "You"),
4533
3364
  new: pick(new_exports, "New"),
4534
3365
  devices: pick(devices_exports, "Devices"),
4535
3366
  setup: pick(setup_exports, "Setup")
@@ -4538,25 +3369,19 @@ const SCREEN_COMPONENTS = {
4538
3369
  /** The app shell: top bar, tabs, one screen, key bar, and the palette and help overlays. */
4539
3370
  const TOAST_MS = 3e3;
4540
3371
  const MIN_COLUMNS = 60;
4541
- /** Questions and permission requests that wait for the owner, plus messages nobody has read. */
4542
- const needYou = (s) => s.tickets.filter((t) => t.status === "open").length + s.unread;
4543
3372
  const SCREEN_LINE = {
4544
3373
  sessions: (s) => {
4545
3374
  const total = s.sessions.length;
4546
- if (total === 0) return "No sessions yet";
4547
- const live = s.sessions.filter((x) => x.status !== "offline").length;
4548
- return `${total} ${total === 1 ? "session" : "sessions"} · ${live} running`;
3375
+ if (total === 0) return "Nothing is running";
3376
+ return `${total} ${total === 1 ? "session" : "sessions"} running`;
4549
3377
  },
4550
- you: () => "Questions and messages for you",
4551
3378
  new: () => "Start something new",
4552
3379
  devices: () => "Your machines",
4553
3380
  setup: () => "Get your tools ready"
4554
3381
  };
4555
- function TopBar({ state, screen, width, onYou }) {
3382
+ function TopBar({ state, screen, width }) {
4556
3383
  const { c, ascii } = useTheme();
4557
- const need = needYou(state);
4558
3384
  const dot = ascii ? "*" : "●";
4559
- const right = need > 0 ? `${dot} ${need} need you` : "";
4560
3385
  let line = SCREEN_LINE[screen](state);
4561
3386
  let lineColor = c.quiet;
4562
3387
  if (state.connection === "connecting") line = "Connecting…";
@@ -4569,7 +3394,7 @@ function TopBar({ state, screen, width, onYou }) {
4569
3394
  }
4570
3395
  if (ascii) line = line.replace(/·/g, "-");
4571
3396
  const inner = width - 2;
4572
- const room = Math.max(0, inner - 11 - (right ? right.length + 2 : 0));
3397
+ const room = Math.max(0, inner - 11);
4573
3398
  return /* @__PURE__ */ jsxs(Band, {
4574
3399
  width,
4575
3400
  children: [
@@ -4596,30 +3421,20 @@ function TopBar({ state, screen, width, onYou }) {
4596
3421
  color: lineColor,
4597
3422
  children: line
4598
3423
  })
4599
- }),
4600
- /* @__PURE__ */ jsx(Box, { flexGrow: 1 }),
4601
- right ? /* @__PURE__ */ jsx(Clickable, {
4602
- onClick: onYou,
4603
- children: /* @__PURE__ */ jsx(Text, {
4604
- bold: true,
4605
- ...c.stamp ? { color: c.stamp } : {},
4606
- children: right
4607
- })
4608
- }) : null
3424
+ })
4609
3425
  ]
4610
3426
  });
4611
3427
  }
4612
3428
  /** The tab row, and under it the rule with the active tab underlined in the entry colour. */
4613
- function Tabs({ screen, layout, youCount, width, onGo }) {
3429
+ function Tabs({ screen, layout, width, onGo }) {
4614
3430
  const { c, ascii } = useTheme();
4615
3431
  const narrow = layout === "narrow";
4616
3432
  const labels = SCREENS.map((s) => {
4617
3433
  const on = s.id === screen;
4618
- const extra = s.id === "you" && youCount > 0 ? ` (${youCount})` : "";
4619
3434
  return {
4620
3435
  id: s.id,
4621
3436
  on,
4622
- text: narrow && !on ? s.key : `${s.key} ${s.title}${extra}`
3437
+ text: narrow && !on ? s.key : `${s.key} ${s.title}`
4623
3438
  };
4624
3439
  });
4625
3440
  const gap = 2;
@@ -4861,7 +3676,6 @@ function Shell({ store, onQuit, size, mouse }) {
4861
3676
  if (movedRef.current) return;
4862
3677
  if (!state.setup.clis.some((c) => c.status === "ready" || c.status === "needs-update") && state.setup.clis.length > 0) go("setup");
4863
3678
  }, [state.setup, go]);
4864
- const youCount = needYou(state);
4865
3679
  const draftCtx = useMemo(() => ({ cleared: () => {
4866
3680
  draftCleared.current = true;
4867
3681
  } }), []);
@@ -4962,13 +3776,11 @@ function Shell({ store, onQuit, size, mouse }) {
4962
3776
  /* @__PURE__ */ jsx(TopBar, {
4963
3777
  state,
4964
3778
  screen,
4965
- width: columns,
4966
- onYou: () => go("you")
3779
+ width: columns
4967
3780
  }),
4968
3781
  /* @__PURE__ */ jsx(Tabs, {
4969
3782
  screen,
4970
3783
  layout,
4971
- youCount,
4972
3784
  width: columns,
4973
3785
  onGo: go
4974
3786
  }),
@@ -5206,7 +4018,7 @@ async function loadSetup(ctx) {
5206
4018
  try {
5207
4019
  const client = await ctx.connect(connectOpts(ctx, false));
5208
4020
  try {
5209
- await client["session.list"]({ includeOffline: true });
4021
+ await client["session.list"]({});
5210
4022
  daemon = "running";
5211
4023
  const relay = await client["relay.status"]({}).catch(() => void 0);
5212
4024
  if (relay) {
@@ -5238,7 +4050,6 @@ function parseFixId(fixId) {
5238
4050
  kind,
5239
4051
  cli
5240
4052
  };
5241
- if (kind === "relay") return { kind };
5242
4053
  }
5243
4054
  async function planFor(ctx, fixId) {
5244
4055
  const parsed = parseFixId(fixId);
@@ -5246,16 +4057,12 @@ async function planFor(ctx, fixId) {
5246
4057
  items: [],
5247
4058
  error: "We don't know that fix."
5248
4059
  };
5249
- let adapters;
5250
- if (parsed.kind === "relay") adapters = ctx.adapters.filter((a) => a.permissionHookInstalled);
5251
- else {
5252
- const a = ctx.adapters.find((x) => x.cli === parsed.cli);
5253
- if (!a) return {
5254
- items: [],
5255
- error: "We don't know that CLI."
5256
- };
5257
- adapters = [a];
5258
- }
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];
5259
4066
  const env = adapterEnv(ctx);
5260
4067
  const found = [];
5261
4068
  for (const adapter of adapters) {
@@ -5272,15 +4079,6 @@ async function planFor(ctx, fixId) {
5272
4079
  items: [],
5273
4080
  error: "It isn't installed."
5274
4081
  };
5275
- if (parsed.kind === "relay") {
5276
- const todo = [];
5277
- for (const f of found) if (!await f.adapter.permissionHookInstalled?.(env).catch(() => false)) todo.push(f);
5278
- const { items, failures } = await collectPlans(ctx, todo, "plan", void 0, { permissionRelay: true });
5279
- return {
5280
- items: items.filter((i) => i.change.component === "hooks"),
5281
- ...failures[0] ? { error: failures[0].message } : {}
5282
- };
5283
- }
5284
4082
  const { items, failures } = await collectPlans(ctx, found, parsed.kind === "init" ? "plan" : "uninstallPlan");
5285
4083
  return {
5286
4084
  items,
@@ -5322,20 +4120,7 @@ async function applyFix(ctx, fixId) {
5322
4120
  }
5323
4121
  }
5324
4122
  async function getExtras(ctx) {
5325
- const helpers = readSettings(dataPaths(ctx.platform, ctx.dataDir).settings).acpAdapterNpx === true;
5326
- const env = adapterEnv(ctx);
5327
- let any = false;
5328
- let all = true;
5329
- for (const a of ctx.adapters) {
5330
- if (!a.permissionHookInstalled) continue;
5331
- if (!(await a.detect(env).catch(() => ({ installed: false }))).installed) continue;
5332
- any = true;
5333
- if (!await a.permissionHookInstalled(env).catch(() => false)) all = false;
5334
- }
5335
- return {
5336
- helpers,
5337
- askBeforeRisky: any && all
5338
- };
4123
+ return { helpers: readSettings(dataPaths(ctx.platform, ctx.dataDir).settings).acpAdapterNpx === true };
5339
4124
  }
5340
4125
  /** Same answer as `conveno init --acp-adapters` / `--no-acp-adapters`. */
5341
4126
  function setHelpers(ctx, on) {
@@ -5347,10 +4132,6 @@ function setHelpers(ctx, on) {
5347
4132
  * can take. It loads once, then follows `events.subscribe` and polls what has no event (sync and
5348
4133
  * devices). When the daemon goes away it says so and reconnects with a growing wait.
5349
4134
  */
5350
- /** How many messages the app holds in memory per session's chat. */
5351
- const HISTORY_KEEP = 1e3;
5352
- /** Page size when loading a session's chat from the daemon. */
5353
- const HISTORY_PAGE = 100;
5354
4135
  const POLL_MS = 15e3;
5355
4136
  const WATCH_MS = 5e3;
5356
4137
  const STOP_WAIT_MS = 1e4;
@@ -5363,16 +4144,9 @@ const BACKOFF_MS = [
5363
4144
  ];
5364
4145
  const initial = () => ({
5365
4146
  connection: "connecting",
5366
- sessions: [],
5367
- inbox: [],
5368
- unread: 0,
5369
- tickets: [],
5370
- history: {},
5371
- historyMore: {}
4147
+ sessions: []
5372
4148
  });
5373
4149
  const reason = (e) => e instanceof Error ? e.message : String(e);
5374
- /** The tickets the owner can act on: addressed to them, or a permission request. */
5375
- const forOwner = (t) => t.toSession === OWNER_SESSION_ID || t.kind === "permission";
5376
4150
  function upsert(list, item) {
5377
4151
  const i = list.findIndex((x) => x.id === item.id);
5378
4152
  if (i < 0) return [...list, item];
@@ -5380,9 +4154,8 @@ function upsert(list, item) {
5380
4154
  next[i] = item;
5381
4155
  return next;
5382
4156
  }
5383
- /** Time order; the id (a ULID) breaks ties. */
5384
- const byTime = (a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id);
5385
- 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");
5386
4159
  async function createStore(ctx, opts = {}) {
5387
4160
  const open = opts.connect ?? (() => ctx.connect(connectOpts(ctx, true)));
5388
4161
  const backoff = opts.backoffMs ?? BACKOFF_MS;
@@ -5404,59 +4177,11 @@ async function createStore(ctx, opts = {}) {
5404
4177
  if (!client || state.connection === "daemon-down") throw new Error("Conveno's background service is not running right now. Trying to reconnect.");
5405
4178
  return client;
5406
4179
  };
5407
- /** Which session a message belongs to in the chat view: the other side of the conversation. */
5408
- /** Every session whose chat shows this message: the sender and the recipient (not `you`). */
5409
- function historyKeys(m) {
5410
- const keys = /* @__PURE__ */ new Set();
5411
- if (m.from !== OWNER_SESSION_ID) keys.add(m.from);
5412
- const to = m.to;
5413
- const target = to === "orchestrator" ? state.sessions.find((s) => s.isOrchestrator) : state.sessions.find((s) => s.id === to || s.name === to);
5414
- if (target) keys.add(target.id);
5415
- return [...keys];
5416
- }
5417
- /** Merge messages into a session's chat: no duplicates, oldest first, at most HISTORY_KEEP. */
5418
- function mergeHistory(cur, add, keep) {
5419
- const seen = new Set(cur.map((x) => x.id));
5420
- const fresh = add.filter((x) => !seen.has(x.id));
5421
- if (fresh.length === 0) return cur;
5422
- const all = [...cur, ...fresh].sort(byTime);
5423
- if (all.length <= 1e3) return all;
5424
- return keep === "newest" ? all.slice(-1e3) : all.slice(0, HISTORY_KEEP);
5425
- }
5426
- function addMessage(m) {
5427
- const patch = {};
5428
- if (m.to === "you" && !state.inbox.some((x) => x.id === m.id)) {
5429
- patch.inbox = [...state.inbox, m].sort(byCreated).slice(-100);
5430
- patch.unread = state.unread + 1;
5431
- }
5432
- for (const key of historyKeys(m)) {
5433
- const cur = (patch.history ?? state.history)[key] ?? [];
5434
- if (cur.some((x) => x.id === m.id)) continue;
5435
- patch.history = {
5436
- ...patch.history ?? state.history,
5437
- [key]: mergeHistory(cur, [m], "newest")
5438
- };
5439
- if (cur.length >= 1e3) patch.historyMore = {
5440
- ...patch.historyMore ?? state.historyMore,
5441
- [key]: true
5442
- };
5443
- }
5444
- if (patch.inbox || patch.history) set(patch);
5445
- }
5446
4180
  function applyEvent(e) {
5447
4181
  switch (e.event) {
5448
- case "message.received":
5449
- addMessage(e.data.message);
5450
- break;
5451
- case "ticket.created":
5452
- case "ticket.answered": {
5453
- const t = e.data.ticket;
5454
- if (forOwner(t)) set({ tickets: upsert(state.tickets, t) });
5455
- break;
5456
- }
5457
4182
  case "session.updated": {
5458
4183
  const s = e.data.session;
5459
- 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) });
5460
4185
  else set({ sessions: upsert(state.sessions, s) });
5461
4186
  break;
5462
4187
  }
@@ -5501,28 +4226,8 @@ async function createStore(ctx, opts = {}) {
5501
4226
  }
5502
4227
  /** Everything the screens need, in one pass. Safe to call again after a reconnect. */
5503
4228
  async function load(c) {
5504
- const [sessions, inbox, open, answered] = await Promise.all([
5505
- c["session.list"]({ includeOffline: true }),
5506
- c["owner.inbox"]({ limit: 200 }),
5507
- c["ticket.list"]({
5508
- status: "open",
5509
- limit: 200
5510
- }),
5511
- c["ticket.list"]({
5512
- status: "answered",
5513
- limit: 50
5514
- }).catch(() => ({ tickets: [] }))
5515
- ]);
5516
- const tickets = [...open.tickets, ...answered.tickets].filter(forOwner);
5517
- const history = { ...state.history };
5518
- for (const m of inbox.messages) history[m.from] = mergeHistory(history[m.from] ?? [], [m], "newest");
5519
- set({
5520
- sessions: sessions.sessions,
5521
- inbox: inbox.messages.slice(-100),
5522
- unread: inbox.unreadCount,
5523
- tickets,
5524
- history
5525
- });
4229
+ const r = await c["session.list"]({});
4230
+ set({ sessions: online(r.sessions) });
5526
4231
  }
5527
4232
  async function attach(c) {
5528
4233
  client = c;
@@ -5568,8 +4273,8 @@ async function createStore(ctx, opts = {}) {
5568
4273
  const c = client;
5569
4274
  if (!c || reconnecting || closed) return;
5570
4275
  try {
5571
- const r = await c["session.list"]({ includeOffline: true });
5572
- set({ sessions: r.sessions });
4276
+ const r = await c["session.list"]({});
4277
+ set({ sessions: online(r.sessions) });
5573
4278
  } catch {
5574
4279
  reconnect();
5575
4280
  }
@@ -5577,43 +4282,34 @@ async function createStore(ctx, opts = {}) {
5577
4282
  const nameOf = (id) => state.sessions.find((s) => s.id === id)?.name;
5578
4283
  const actions = {
5579
4284
  async send(to, text) {
5580
- addMessage((await live()["owner.send"]({
4285
+ await live()["owner.send"]({
5581
4286
  to,
5582
4287
  text
5583
- })).message);
5584
- },
5585
- async answerTicket(ticketId, response) {
5586
- const res = await live()["ticket.answer"]({
5587
- ticketId,
5588
- response
5589
4288
  });
5590
- set({ tickets: upsert(state.tickets, res.ticket) });
5591
4289
  },
5592
- async decide(ticketId, allow) {
5593
- const res = await live()["ticket.answer"]({
5594
- ticketId,
5595
- response: allow ? PERMISSION_ANSWERS[0] : PERMISSION_ANSWERS[1]
5596
- });
5597
- 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
+ })) });
5598
4296
  },
5599
- async setAuto(sessionId, on) {
5600
- const res = await live()["session.setAuto"]({
5601
- session: sessionId,
5602
- auto: on
5603
- });
5604
- 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
+ })) });
5605
4303
  },
5606
4304
  async stop(sessionId) {
5607
4305
  const name = nameOf(sessionId);
5608
4306
  const rec = name ? readSpawnRecord(spawnRecordPath(ctx.dataDir, name)) : void 0;
5609
4307
  if (!name || !rec) throw new Error("Only sessions started from Conveno on this machine can be stopped here.");
5610
- 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.`);
5611
4309
  const alive = () => rec.pid !== void 0 && ctx.isAlive(rec.pid);
5612
- if (rec.acp) {
5613
- writeFileSync(stopRequestPath(spawnRecordPath(ctx.dataDir, rec.name)), "", { mode: 384 });
5614
- const end = Date.now() + STOP_WAIT_MS;
5615
- while (alive() && Date.now() < end) await new Promise((r) => setTimeout(r, 100));
5616
- }
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));
5617
4313
  if (alive() && rec.pid !== void 0) killProcessTree(rec.pid, ctx.platform);
5618
4314
  if (rec.agentPid !== void 0 && ctx.isAlive(rec.agentPid)) killProcessTree(rec.agentPid, ctx.platform);
5619
4315
  },
@@ -5624,24 +4320,6 @@ async function createStore(ctx, opts = {}) {
5624
4320
  });
5625
4321
  set({ sessions: upsert(state.sessions, res.session) });
5626
4322
  },
5627
- async forget(sessionId) {
5628
- await live()["session.forget"]({ ids: [sessionId] });
5629
- set({ sessions: state.sessions.filter((s) => s.id !== sessionId) });
5630
- },
5631
- async peek(sessionId) {
5632
- const r = await live()["session.peek"]({ target: sessionId });
5633
- return {
5634
- session: r.session.id,
5635
- mode: "recent",
5636
- turns: r.turns.map((t) => ({
5637
- role: t.role,
5638
- text: t.text,
5639
- ...t.at ? { ts: t.at } : {}
5640
- })),
5641
- truncated: r.truncated,
5642
- redacted: true
5643
- };
5644
- },
5645
4323
  async spawn(p) {
5646
4324
  const c = live();
5647
4325
  const runner = ctx.spawnRunner ?? [process.execPath, process.argv[1] ?? "conveno"];
@@ -5653,65 +4331,15 @@ async function createStore(ctx, opts = {}) {
5653
4331
  client: c,
5654
4332
  runner
5655
4333
  });
5656
- const res = await spawnSession(deps, {
4334
+ return { sessionId: (await spawnSession(deps, {
5657
4335
  cli: p.cli,
5658
4336
  callerCwd: ctx.cwd,
5659
4337
  cwd: p.cwd,
5660
4338
  name: p.name,
5661
4339
  task: p.prompt,
5662
- headless: p.mode !== "visible",
5663
- acp: p.mode === "acp" ? "require" : void 0,
4340
+ window: p.window,
5664
4341
  confineToHome: false
5665
- });
5666
- if (p.auto) await c["session.setAuto"]({
5667
- session: res.id,
5668
- auto: true
5669
- }).catch(() => void 0);
5670
- return { sessionId: res.id };
5671
- },
5672
- async loadHistory(sessionId) {
5673
- const res = await live()["message.history"]({
5674
- session: sessionId,
5675
- limit: HISTORY_PAGE
5676
- });
5677
- const cur = state.history[sessionId] ?? [];
5678
- set({
5679
- history: {
5680
- ...state.history,
5681
- [sessionId]: mergeHistory(cur, res.messages, "newest")
5682
- },
5683
- historyMore: {
5684
- ...state.historyMore,
5685
- [sessionId]: res.more
5686
- }
5687
- });
5688
- },
5689
- async loadOlder(sessionId) {
5690
- const cur = state.history[sessionId] ?? [];
5691
- const oldest = cur[0];
5692
- if (!oldest) {
5693
- await actions.loadHistory(sessionId);
5694
- return (state.history[sessionId]?.length ?? 0) > 0;
5695
- }
5696
- if (state.historyMore[sessionId] === false || cur.length >= 1e3) return false;
5697
- const res = await live()["message.history"]({
5698
- session: sessionId,
5699
- limit: HISTORY_PAGE,
5700
- before: oldest.id
5701
- });
5702
- const now = state.history[sessionId] ?? [];
5703
- const merged = mergeHistory(now, res.messages, "oldest");
5704
- set({
5705
- history: {
5706
- ...state.history,
5707
- [sessionId]: merged
5708
- },
5709
- historyMore: {
5710
- ...state.historyMore,
5711
- [sessionId]: res.more && merged.length < 1e3
5712
- }
5713
- });
5714
- return merged.length > now.length;
4342
+ })).id };
5715
4343
  },
5716
4344
  async refreshSetup() {
5717
4345
  await loadSetupData();
@@ -5746,15 +4374,6 @@ async function createStore(ctx, opts = {}) {
5746
4374
  async cancelPair() {
5747
4375
  await cancelPair(live());
5748
4376
  },
5749
- async markRead(ids) {
5750
- const c = live();
5751
- let acked = 0;
5752
- for (let i = 0; i < ids.length; i += 100) {
5753
- const res = await c["owner.ack"]({ ids: ids.slice(i, i + 100) });
5754
- acked += res.acked;
5755
- }
5756
- if (acked > 0) set({ unread: Math.max(0, state.unread - acked) });
5757
- },
5758
4377
  async revokeDevice(deviceId) {
5759
4378
  await live()["devices.revoke"]({ device: deviceId });
5760
4379
  await pollRelay(live());