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

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.
Files changed (33) hide show
  1. package/README.md +22 -30
  2. package/dist/acp-9pRRszwU.js +82 -0
  3. package/dist/agy-relay-C-nqvieJ.js +137 -0
  4. package/dist/args-C7Agak9f.js +321 -0
  5. package/dist/bin.js +2 -2
  6. package/dist/{ctx-CDLE-2f2.js → ctx-tYftvhz_.js} +2 -3
  7. package/dist/daemon.js +410 -1423
  8. package/dist/daemonError-DNAKEyRT.js +66 -0
  9. package/dist/{dist-TrWRppjR.js → dist-D2hMvcZu.js} +592 -1216
  10. package/dist/dist-D9Gu-mQm.js +547 -0
  11. package/dist/dist-DOGlDbRb.js +504 -0
  12. package/dist/{dist-BPPOKmbH.js → dist-DOKVrSIw.js} +39 -148
  13. package/dist/dist-Dd31Fg0h.js +671 -0
  14. package/dist/{dist-CEJ2-wxh.js → dist-ftx5RNCp.js} +4 -17
  15. package/dist/{dist-E3XvoT1Q.js → dist-iFaY42Bs.js} +1 -1
  16. package/dist/{doctor-CzIGTeNT.js → doctor-BYa-MApu.js} +109 -102
  17. package/dist/fmt-C2SsP5Y0.js +96 -0
  18. package/dist/{hook-CLB_muZS.js → hook-CQeSn-w4.js} +7 -5
  19. package/dist/hook-entry-BXmSN--S.js +2490 -0
  20. package/dist/hook-entry-CgiSN-Oj.js +1 -0
  21. package/dist/main-seh-HPZO.js +971 -0
  22. package/dist/pick-DoyocW55.js +9 -0
  23. package/dist/{run-CYH0CRbp.js → run-B-WfNtCX.js} +627 -1998
  24. package/dist/{runtime-B1Pb9Qqg.js → runtime-Bnjh9BQ8.js} +119 -210
  25. package/dist/{dist-C8JRuLiZ.js → toml-patch-DGzVRdd1.js} +20 -1890
  26. package/dist/watch-Dr2RdyGo.js +185 -0
  27. package/package.json +15 -15
  28. package/dist/acp-BD7Oaerg.js +0 -142
  29. package/dist/args-BRB8QEQM.js +0 -554
  30. package/dist/dist-DcmKjrmu.js +0 -271
  31. package/dist/hook-entry-BlvSoNMm.js +0 -1289
  32. package/dist/hook-entry-CRDh36pe.js +0 -1
  33. package/dist/main-CsCsyq2G.js +0 -1645
@@ -1,16 +1,17 @@
1
1
  import { Box, Text, render, useApp, useInput, useStdin, useWindowSize } from "ink";
2
- import { n as connectOpts, t as adapterEnv } from "./ctx-CDLE-2f2.js";
3
- import { b as openInBrowser, g as PAIR_TIMEOUT_MS, h as unifiedDiff, l as StaleError, r as collectPlans, t as inspect, u as applyChanges, y as daemonProblem } from "./doctor-CzIGTeNT.js";
4
- import { d as plainError, l as fail, m as tilde, o as cmd } from "./args-BRB8QEQM.js";
5
- import { createContext, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState, useSyncExternalStore } from "react";
2
+ import { n as connectOpts, t as adapterEnv } from "./ctx-tYftvhz_.js";
3
+ import { t as daemonProblem } from "./daemonError-DNAKEyRT.js";
4
+ import { a as fail, n as cmd, s as plainError, u as tilde } from "./fmt-C2SsP5Y0.js";
5
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
6
6
  import { readFileSync, readdirSync, writeFileSync } from "node:fs";
7
7
  import { Readable } from "node:stream";
8
- import { D as compatStatus, Dt as readAccountTokens, Fn as isLeadAlias, Ft as realSpawnDeps, G as fetchAccountStatus, Gt as spawnRecordPath, Kt as spawnSession, Mt as readSettings, N as dataPaths, Nt as readSpawnRecord, l as SPAWN_TABLE, on as writeSettings, pt as notifyForcedOff, vn as OWNER_SESSION_ID, yn as PERMISSION_ANSWERS } from "./dist-TrWRppjR.js";
8
+ import { Ct as realSpawnDeps, E as compatStatus, H as fetchAccountStatus, It as spawnRecordPath, Lt as spawnSession, M as dataPaths, St as readSpawnRecord, Yt as writeSettings, _t as readAccountTokens, xt as readSettings } from "./dist-D2hMvcZu.js";
9
9
  import { homedir } from "node:os";
10
10
  import { i as tokens, n as detectColorLevel, r as detectUnicode } from "./dist-BRjg9CLd.js";
11
11
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
12
  import { basename, join, resolve } from "node:path";
13
- import { i as stopRequestPath, t as killProcessTree } from "./dist-BPPOKmbH.js";
13
+ import { _ as PAIR_TIMEOUT_MS, b as openInBrowser, d as applyChanges, g as unifiedDiff, o as pendingOptions, r as collectPlans, t as inspect, u as StaleError } from "./doctor-BYa-MApu.js";
14
+ import { r as stopRequestPath, t as killProcessTree } from "./dist-DOKVrSIw.js";
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,126 +2741,346 @@ 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
- // src/tui/screens/setup.tsx
3438
- /** Screen 5: Setup. Your CLIs, extras and the checkup. */
3439
- var setup_exports = /* @__PURE__ */ __exportAll({
3440
- default: () => SetupScreen,
3441
- idsFor: () => idsFor
3442
- });
3443
- const STATUS_WORD = {
3444
- ready: "ready",
3445
- "needs-update": "needs update",
3446
- "not-set-up": "not set up",
3447
- blocked: "blocked",
3448
- "not-installed": "not installed"
3449
- };
3450
- /** `init:<cli>` ids for the picked rows, or the row under the cursor. Pure, for tests. */
3451
- function idsFor(clis, picked, cursorCli) {
3452
- const wanted = picked.size > 0 ? clis.filter((c) => picked.has(c.cli)) : clis.filter((c) => c.cli === cursorCli);
3453
- const ids = wanted.filter((c) => c.status !== "not-installed" && c.status !== "blocked").map((c) => `init:${c.cli}`);
3454
- if (ids.length > 0) return {
3455
- ids,
3456
- skipped: void 0
2755
+ // src/tui/setup-data.ts
2756
+ /**
2757
+ * What the Setup screen reads and does. Same facts as `conveno doctor`, in plain words, and the
2758
+ * same code path as `conveno init` / `conveno uninstall` for changing files.
2759
+ *
2760
+ * No Ink or React in here: the store imports it.
2761
+ */
2762
+ const ready = (r) => r.mcp === "ok" && (r.hooks === null || r.hooks === "ok");
2763
+ /** One CLI's row, from what `conveno doctor` found. Exported for tests. */
2764
+ function checkFromRow(r, compat) {
2765
+ const { adapter, detection } = r;
2766
+ const base = {
2767
+ cli: adapter.cli,
2768
+ label: adapter.displayName
3457
2769
  };
3458
- const first = wanted[0];
3459
- if (!first) return {
3460
- ids,
3461
- skipped: "Nothing to set up here."
2770
+ const version = detection.version;
2771
+ const withVersion = version ? { version } : {};
2772
+ if (!detection.installed) return {
2773
+ ...base,
2774
+ status: "not-installed",
2775
+ note: "install it, then press g"
2776
+ };
2777
+ const c = compatStatus(adapter.cli, version, compat);
2778
+ if (r.planError) return {
2779
+ ...base,
2780
+ ...withVersion,
2781
+ status: "blocked",
2782
+ note: "we can't read its settings file"
3462
2783
  };
2784
+ if (c.kind === "older") return {
2785
+ ...base,
2786
+ ...withVersion,
2787
+ status: "blocked",
2788
+ note: `too old, update it first (needs ${c.minimum} or newer)`
2789
+ };
2790
+ if (ready(r)) return {
2791
+ ...base,
2792
+ ...withVersion,
2793
+ status: "ready",
2794
+ ...c.kind === "newer" && c.minor ? { note: "a bit newer than we tested, should be fine" } : {}
2795
+ };
2796
+ const allMissing = [r.mcp, r.hooks].filter((p) => p !== null).every((p) => p === "missing");
3463
2797
  return {
3464
- ids,
3465
- skipped: first.status === "not-installed" ? `Install ${first.label} first, then press g.` : `${first.label} is blocked: ${first.note ?? "see the note"}.`
2798
+ ...base,
2799
+ ...withVersion,
2800
+ status: allMissing ? "not-set-up" : "needs-update",
2801
+ note: "press ⏎ to fix"
3466
2802
  };
3467
2803
  }
3468
- function HealthLine({ item, width }) {
3469
- const { c } = useTheme();
3470
- const m = useMarks();
3471
- const mark = item.level === "ok" ? m.ok : item.level === "warn" ? m.warn : item.level === "error" ? m.error : m.info;
3472
- const color = item.level === "ok" ? c.ok : item.level === "warn" ? c.warn : item.level === "error" ? c.error : c.quiet;
3473
- return /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Text, {
3474
- ...color ? { color } : {},
3475
- children: `${mark} `
3476
- }), /* @__PURE__ */ jsx(Ell, {
3477
- width: width - 2,
3478
- children: item.text
3479
- })] });
3480
- }
3481
- function ReviewBox({ review, rows, width, active, onYes, onNo, onScroll }) {
3482
- const { c } = useTheme();
3483
- const body = [];
3484
- for (const f of review.files) {
3485
- body.push({
3486
- text: `${f.path}${f.isNew ? " (new file)" : f.deleted ? " (deleted)" : ""}`,
3487
- kind: "path"
3488
- });
3489
- body.push({
3490
- text: f.summary,
3491
- kind: "note"
3492
- });
3493
- for (const l of f.lines) body.push({
3494
- text: l,
3495
- kind: l.startsWith("@@") ? "hunk" : l.startsWith("+") ? "add" : l.startsWith("-") ? "del" : "plain"
2804
+ /** The checkup list. Exported for tests. */
2805
+ function healthFrom(input) {
2806
+ const out = [];
2807
+ out.push(input.daemon === "running" ? {
2808
+ level: "ok",
2809
+ text: "Conveno is running"
2810
+ } : input.daemon === "stopped" ? {
2811
+ level: "warn",
2812
+ text: "Conveno is not running yet. It starts with your first session."
2813
+ } : {
2814
+ level: "error",
2815
+ text: "Conveno can't be reached"
2816
+ });
2817
+ const installed = input.clis.filter((c) => c.status !== "not-installed");
2818
+ const good = installed.filter((c) => c.status === "ready").length;
2819
+ out.push(installed.length === 0 ? {
2820
+ level: "warn",
2821
+ text: "No supported CLI found on this machine"
2822
+ } : {
2823
+ level: good === installed.length ? "ok" : "info",
2824
+ text: `${good} of ${installed.length} CLIs ready`
2825
+ });
2826
+ let fixes = 0;
2827
+ for (const c of installed) if (c.status === "needs-update") {
2828
+ fixes++;
2829
+ out.push({
2830
+ level: "warn",
2831
+ text: `${c.label} needs an update`,
2832
+ fixId: `init:${c.cli}`
3496
2833
  });
3497
- body.push({
3498
- text: "",
3499
- kind: "plain"
2834
+ } else if (c.status === "not-set-up") {
2835
+ fixes++;
2836
+ out.push({
2837
+ level: "warn",
2838
+ text: `${c.label} is not set up yet`,
2839
+ fixId: `init:${c.cli}`
3500
2840
  });
3501
- }
3502
- const room = Math.max(3, rows - 8);
3503
- const start = Math.min(review.scroll, Math.max(0, body.length - room));
3504
- const shown = body.map((l, id) => ({
3505
- ...l,
3506
- id
3507
- })).slice(start, start + room);
3508
- const hidden = body.length - start - shown.length;
3509
- const inner = width - 4;
3510
- return /* @__PURE__ */ jsx(Hit, {
3511
- onWheel: (d) => onScroll(d < 0 ? -1 : 1),
3512
- isActive: active,
3513
- children: /* @__PURE__ */ jsxs(Card, {
3514
- accent: c.warn,
3515
- width,
3516
- children: [
3517
- /* @__PURE__ */ jsx(Text, {
3518
- bold: true,
3519
- children: review.title
3520
- }),
3521
- review.error ? /* @__PURE__ */ jsx(Text, {
3522
- ...c.error ? { color: c.error } : {},
3523
- children: `We can't plan this: ${review.error}`
3524
- }) : review.files.length === 0 ? /* @__PURE__ */ jsx(Text, { children: "Nothing to change. It is already how it should be." }) : /* @__PURE__ */ jsxs(Box, {
3525
- flexDirection: "column",
3526
- children: [shown.map((l) => /* @__PURE__ */ jsx(Ell, {
3527
- width: inner,
2841
+ } else if (c.status === "blocked") out.push({
2842
+ level: "error",
2843
+ text: `${c.label} is blocked: ${c.note ?? "see Setup"}`
2844
+ });
2845
+ if (input.sync === "online") out.push({
2846
+ level: "ok",
2847
+ text: "Sync is online"
2848
+ });
2849
+ else if (input.sync === "offline") out.push({
2850
+ level: "warn",
2851
+ text: "Sync is offline, it keeps trying"
2852
+ });
2853
+ if (fixes === 0) out.push({
2854
+ level: "ok",
2855
+ text: "Up to date"
2856
+ });
2857
+ return out;
2858
+ }
2859
+ /** The same facts as `conveno doctor`, as friendly rows. Never throws. */
2860
+ async function loadSetup(ctx) {
2861
+ const clis = (await Promise.all(ctx.adapters.map((a) => inspect(ctx, a)))).map((r) => checkFromRow(r, ctx.compat));
2862
+ let daemon = "stopped";
2863
+ let sync;
2864
+ try {
2865
+ const client = await ctx.connect(connectOpts(ctx, false));
2866
+ try {
2867
+ await client["session.list"]({});
2868
+ daemon = "running";
2869
+ const relay = await client["relay.status"]({}).catch(() => void 0);
2870
+ if (relay) {
2871
+ if (relay.state === "connected") sync = "online";
2872
+ else if (relay.state === "connecting" || relay.state === "disconnected") sync = "offline";
2873
+ }
2874
+ } finally {
2875
+ await client.close().catch(() => void 0);
2876
+ }
2877
+ } catch (e) {
2878
+ daemon = daemonProblem(ctx.theme, e).notRunning ? "stopped" : "unreachable";
2879
+ }
2880
+ return {
2881
+ clis,
2882
+ health: healthFrom({
2883
+ daemon,
2884
+ ...sync ? { sync } : {},
2885
+ clis
2886
+ })
2887
+ };
2888
+ }
2889
+ function parseFixId(fixId) {
2890
+ const [kind, cli, accept] = fixId.split(":");
2891
+ const ids = accept ? accept.split(",").filter(Boolean) : [];
2892
+ if (kind === "init" && cli) return {
2893
+ kind,
2894
+ cli,
2895
+ accept: ids
2896
+ };
2897
+ if (kind === "uninstall" && cli) return {
2898
+ kind,
2899
+ cli,
2900
+ accept: []
2901
+ };
2902
+ }
2903
+ /** The fix id that says yes to these optional setups. */
2904
+ const fixIdWith = (cli, accept) => accept.length > 0 ? `init:${cli}:${accept.join(",")}` : `init:${cli}`;
2905
+ async function planFor(ctx, fixId) {
2906
+ const parsed = parseFixId(fixId);
2907
+ if (!parsed) return {
2908
+ items: [],
2909
+ error: "We don't know that fix."
2910
+ };
2911
+ const a = ctx.adapters.find((x) => x.cli === parsed.cli);
2912
+ if (!a) return {
2913
+ items: [],
2914
+ error: "We don't know that CLI."
2915
+ };
2916
+ const adapters = [a];
2917
+ const env = adapterEnv(ctx);
2918
+ const found = [];
2919
+ for (const adapter of adapters) {
2920
+ const detection = await adapter.detect(env).catch(() => ({
2921
+ installed: false,
2922
+ configPaths: []
2923
+ }));
2924
+ if (detection.installed) found.push({
2925
+ adapter,
2926
+ detection
2927
+ });
2928
+ }
2929
+ if (found.length === 0) return {
2930
+ items: [],
2931
+ error: "It isn't installed."
2932
+ };
2933
+ const { items, failures } = await collectPlans(ctx, found, parsed.kind === "init" ? "plan" : "uninstallPlan", void 0, parsed.accept);
2934
+ return {
2935
+ items,
2936
+ ...failures[0] ? { error: failures[0].message } : {}
2937
+ };
2938
+ }
2939
+ /** Cap on diff lines kept per file, so one big file cannot fill the overlay. */
2940
+ const MAX_DIFF_LINES = 60;
2941
+ /** What `applyFix` would change, without changing anything. */
2942
+ async function planFix(ctx, fixId) {
2943
+ const { items, error } = await planFor(ctx, fixId);
2944
+ const parsed = parseFixId(fixId);
2945
+ const adapter = parsed && ctx.adapters.find((x) => x.cli === parsed.cli);
2946
+ const options = parsed?.kind === "init" && adapter ? await pendingOptions(ctx, [adapter]) : [];
2947
+ return {
2948
+ files: items.map(({ change }) => {
2949
+ const lines = unifiedDiff(change.before, change.after);
2950
+ return {
2951
+ path: tilde(change.path, ctx.home),
2952
+ isNew: change.before === null,
2953
+ deleted: Boolean(change.deleteFile),
2954
+ summary: change.description,
2955
+ lines: lines.length > MAX_DIFF_LINES ? lines.slice(0, MAX_DIFF_LINES) : lines
2956
+ };
2957
+ }),
2958
+ ...options.length > 0 ? { options } : {},
2959
+ ...error ? { error } : {}
2960
+ };
2961
+ }
2962
+ /**
2963
+ * Make the change `planFix` showed: back up each file, then write. Same code path as
2964
+ * `conveno init` (and `conveno uninstall` without a backup on record). Throws a friendly error.
2965
+ */
2966
+ async function applyFix(ctx, fixId) {
2967
+ const { items, error } = await planFor(ctx, fixId);
2968
+ if (error) throw new Error(error);
2969
+ if (items.length === 0) return;
2970
+ try {
2971
+ await applyChanges(ctx, items, parseFixId(fixId)?.kind === "uninstall" ? { markRestored: true } : {});
2972
+ } catch (e) {
2973
+ if (e instanceof StaleError) throw new Error("A settings file changed while we waited. Press g, then try again.");
2974
+ throw new Error(plainError(e));
2975
+ }
2976
+ }
2977
+ async function getExtras(ctx) {
2978
+ return { helpers: readSettings(dataPaths(ctx.platform, ctx.dataDir).settings).acpAdapterNpx === true };
2979
+ }
2980
+ /** Same answer as `conveno init --acp-adapters` / `--no-acp-adapters`. */
2981
+ function setHelpers(ctx, on) {
2982
+ writeSettings(dataPaths(ctx.platform, ctx.dataDir).settings, { acpAdapterNpx: on });
2983
+ }
2984
+ // src/tui/screens/setup.tsx
2985
+ /** Screen 4: Setup. Your CLIs, extras and the checkup. */
2986
+ var setup_exports = /* @__PURE__ */ __exportAll({
2987
+ default: () => SetupScreen,
2988
+ idsFor: () => idsFor,
2989
+ idsWithOptions: () => idsWithOptions
2990
+ });
2991
+ const STATUS_WORD = {
2992
+ ready: "ready",
2993
+ "needs-update": "needs update",
2994
+ "not-set-up": "not set up",
2995
+ blocked: "blocked",
2996
+ "not-installed": "not installed"
2997
+ };
2998
+ /** `init:<cli>` ids with the ticked options for that CLI added. */
2999
+ function idsWithOptions(ids, options, accepted) {
3000
+ return ids.map((id) => {
3001
+ const cli = id.startsWith("init:") ? id.slice(5) : void 0;
3002
+ if (!cli) return id;
3003
+ return fixIdWith(cli, options.filter((o) => o.cli === cli && accepted.includes(o.id)).map((o) => o.id));
3004
+ });
3005
+ }
3006
+ /** `init:<cli>` ids for the picked rows, or the row under the cursor. Pure, for tests. */
3007
+ function idsFor(clis, picked, cursorCli) {
3008
+ const wanted = picked.size > 0 ? clis.filter((c) => picked.has(c.cli)) : clis.filter((c) => c.cli === cursorCli);
3009
+ const ids = wanted.filter((c) => c.status !== "not-installed" && c.status !== "blocked").map((c) => `init:${c.cli}`);
3010
+ if (ids.length > 0) return {
3011
+ ids,
3012
+ skipped: void 0
3013
+ };
3014
+ const first = wanted[0];
3015
+ if (!first) return {
3016
+ ids,
3017
+ skipped: "Nothing to set up here."
3018
+ };
3019
+ return {
3020
+ ids,
3021
+ skipped: first.status === "not-installed" ? `Install ${first.label} first, then press g.` : `${first.label} is blocked: ${first.note ?? "see the note"}.`
3022
+ };
3023
+ }
3024
+ function HealthLine({ item, width }) {
3025
+ const { c } = useTheme();
3026
+ const m = useMarks();
3027
+ const mark = item.level === "ok" ? m.ok : item.level === "warn" ? m.warn : item.level === "error" ? m.error : m.info;
3028
+ const color = item.level === "ok" ? c.ok : item.level === "warn" ? c.warn : item.level === "error" ? c.error : c.quiet;
3029
+ return /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Text, {
3030
+ ...color ? { color } : {},
3031
+ children: `${mark} `
3032
+ }), /* @__PURE__ */ jsx(Ell, {
3033
+ width: width - 2,
3034
+ children: item.text
3035
+ })] });
3036
+ }
3037
+ function ReviewBox({ review, rows, width, active, onYes, onNo, onScroll }) {
3038
+ const { c } = useTheme();
3039
+ const body = [];
3040
+ for (const f of review.files) {
3041
+ body.push({
3042
+ text: `${f.path}${f.isNew ? " (new file)" : f.deleted ? " (deleted)" : ""}`,
3043
+ kind: "path"
3044
+ });
3045
+ body.push({
3046
+ text: f.summary,
3047
+ kind: "note"
3048
+ });
3049
+ for (const l of f.lines) body.push({
3050
+ text: l,
3051
+ kind: l.startsWith("@@") ? "hunk" : l.startsWith("+") ? "add" : l.startsWith("-") ? "del" : "plain"
3052
+ });
3053
+ body.push({
3054
+ text: "",
3055
+ kind: "plain"
3056
+ });
3057
+ }
3058
+ const room = Math.max(3, rows - 8);
3059
+ const start = Math.min(review.scroll, Math.max(0, body.length - room));
3060
+ const shown = body.map((l, id) => ({
3061
+ ...l,
3062
+ id
3063
+ })).slice(start, start + room);
3064
+ const hidden = body.length - start - shown.length;
3065
+ const inner = width - 4;
3066
+ return /* @__PURE__ */ jsx(Hit, {
3067
+ onWheel: (d) => onScroll(d < 0 ? -1 : 1),
3068
+ isActive: active,
3069
+ children: /* @__PURE__ */ jsxs(Card, {
3070
+ accent: c.warn,
3071
+ width,
3072
+ children: [
3073
+ /* @__PURE__ */ jsx(Text, {
3074
+ bold: true,
3075
+ children: review.title
3076
+ }),
3077
+ review.error ? /* @__PURE__ */ jsx(Text, {
3078
+ ...c.error ? { color: c.error } : {},
3079
+ children: `We can't plan this: ${review.error}`
3080
+ }) : review.files.length === 0 ? /* @__PURE__ */ jsx(Text, { children: "Nothing to change. It is already how it should be." }) : /* @__PURE__ */ jsxs(Box, {
3081
+ flexDirection: "column",
3082
+ children: [shown.map((l) => /* @__PURE__ */ jsx(Ell, {
3083
+ width: inner,
3528
3084
  bold: l.kind === "path",
3529
3085
  dim: l.kind === "note" || l.kind === "hunk",
3530
3086
  color: l.kind === "add" ? c.ok : l.kind === "del" ? c.error : void 0,
@@ -3534,6 +3090,11 @@ function ReviewBox({ review, rows, width, active, onYes, onNo, onScroll }) {
3534
3090
  children: `… ${hidden} more lines (↑↓ to scroll)`
3535
3091
  }) : null]
3536
3092
  }),
3093
+ review.options.length > 0 ? /* @__PURE__ */ jsx(Text, { children: " " }) : null,
3094
+ review.options.map((o, i) => /* @__PURE__ */ jsx(Ell, {
3095
+ width: inner,
3096
+ children: `${review.accepted.includes(o.id) ? "[x]" : "[ ]"} ${i + 1} ${o.question}`
3097
+ }, o.id)),
3537
3098
  /* @__PURE__ */ jsx(Text, { children: " " }),
3538
3099
  review.busy ? /* @__PURE__ */ jsx(Text, { children: "Working…" }) : review.error || review.files.length === 0 ? /* @__PURE__ */ jsx(Hit, {
3539
3100
  onClick: onNo,
@@ -3585,14 +3146,11 @@ function SetupScreen(props) {
3585
3146
  const [cursor, setCursor] = useState(0);
3586
3147
  const [picked, setPicked] = useState(/* @__PURE__ */ new Set());
3587
3148
  const [review, setReview] = useState();
3588
- const [extras, setExtras] = useState({
3589
- helpers: false,
3590
- askBeforeRisky: false
3591
- });
3149
+ const [extras, setExtras] = useState({ helpers: false });
3592
3150
  const mouse = useMouseControl();
3593
3151
  const mouseOn = mouse.enabled;
3594
3152
  const asked = useRef(false);
3595
- const total = clis.length + 4;
3153
+ const total = clis.length + 2;
3596
3154
  const at = Math.min(cursor, Math.max(0, total - 1));
3597
3155
  const onCli = at < clis.length ? clis[at] : void 0;
3598
3156
  const extraRow = at >= clis.length ? at - clis.length : -1;
@@ -3621,37 +3179,59 @@ function SetupScreen(props) {
3621
3179
  refresh,
3622
3180
  loadExtras
3623
3181
  ]);
3624
- const open = useCallback(async (ids, title) => {
3182
+ const preset = useRef(false);
3183
+ useEffect(() => {
3184
+ if (preset.current || !state.setup || state.setup.clis.length === 0) return;
3185
+ preset.current = true;
3186
+ const all = state.setup.clis;
3187
+ if (all.some((x) => x.status === "ready")) return;
3188
+ setPicked(new Set(all.filter((x) => x.status === "not-set-up" || x.status === "needs-update").map((x) => x.cli)));
3189
+ }, [state.setup]);
3190
+ const open = useCallback(async (ids, title, options = [], accepted = []) => {
3625
3191
  setReview({
3626
3192
  title,
3627
3193
  ids,
3628
3194
  files: [],
3195
+ options,
3196
+ accepted,
3629
3197
  scroll: 0,
3630
3198
  busy: true
3631
3199
  });
3632
3200
  const files = [];
3201
+ const found = new Map(options.map((o) => [o.id, o]));
3633
3202
  let error;
3634
- for (const id of ids) {
3203
+ for (const id of idsWithOptions(ids, options, accepted)) {
3635
3204
  const plan = await actions.planFix(id).catch((e) => ({
3636
3205
  files: [],
3206
+ options: [],
3637
3207
  error: e instanceof Error ? e.message : String(e)
3638
3208
  }));
3639
3209
  files.push(...plan.files);
3210
+ for (const o of plan.options ?? []) found.set(o.id, o);
3640
3211
  error ??= plan.error;
3641
3212
  }
3642
3213
  setReview({
3643
3214
  title,
3644
3215
  ids,
3645
3216
  files,
3217
+ options: [...found.values()],
3218
+ accepted,
3646
3219
  ...error ? { error } : {},
3647
3220
  scroll: 0,
3648
3221
  busy: false
3649
3222
  });
3650
3223
  }, [actions]);
3224
+ const toggleOption = useCallback((n) => {
3225
+ if (!review || review.busy) return;
3226
+ const o = review.options[n];
3227
+ if (!o) return;
3228
+ const accepted = review.accepted.includes(o.id) ? review.accepted.filter((x) => x !== o.id) : [...review.accepted, o.id];
3229
+ open(review.ids, review.title, review.options, accepted);
3230
+ }, [review, open]);
3651
3231
  const setUp = useCallback((target) => {
3652
3232
  const row = target ? target.extra ?? -1 : extraRow;
3653
3233
  const cur = target ? target.cli : onCli;
3654
- if (row === 2) {
3234
+ if (row === 1) {
3655
3235
  if (mouse.forcedOff) {
3656
3236
  toast("The mouse is off because CONVENO_MOUSE=0 is set.", "warn");
3657
3237
  return;
@@ -3665,21 +3245,6 @@ function SetupScreen(props) {
3665
3245
  toast(next ? "Mouse is on." : "Mouse is off.", "ok");
3666
3246
  return;
3667
3247
  }
3668
- if (row === 3) {
3669
- if (extras.notifyForcedOff) {
3670
- toast("Desktop alerts are off because CONVENO_NOTIFY=0 is set.", "warn");
3671
- return;
3672
- }
3673
- const next = extras.notifyDesktop === false;
3674
- actions.setNotify(next).then(() => {
3675
- setExtras({
3676
- ...extras,
3677
- notifyDesktop: next
3678
- });
3679
- toast(next ? "I'll tell you on the desktop." : "No desktop alerts.", "ok");
3680
- }, () => toast("Couldn't change that. Try again.", "error"));
3681
- return;
3682
- }
3683
3248
  if (row === 0) {
3684
3249
  const next = !extras.helpers;
3685
3250
  actions.setHelpers(next).then(() => {
@@ -3691,11 +3256,6 @@ function SetupScreen(props) {
3691
3256
  }, () => toast("Couldn't change that. Try again.", "error"));
3692
3257
  return;
3693
3258
  }
3694
- if (row === 1) {
3695
- if (extras.askBeforeRisky) return toast("Already on. Each worker stays off until you turn it on for it.", "ok");
3696
- open(["relay:on"], "Ask me before risky commands (beta)");
3697
- return;
3698
- }
3699
3259
  const { ids, skipped } = idsFor(clis, picked, cur?.cli);
3700
3260
  if (ids.length === 0) return toast(skipped ?? "Nothing to set up here.", "warn");
3701
3261
  const names = clis.filter((x) => ids.includes(`init:${x.cli}`)).map((x) => x.label);
@@ -3728,7 +3288,7 @@ function SetupScreen(props) {
3728
3288
  busy: true
3729
3289
  });
3730
3290
  try {
3731
- for (const id of review.ids) await actions.applyFix(id);
3291
+ for (const id of idsWithOptions(review.ids, review.options, review.accepted)) await actions.applyFix(id);
3732
3292
  toast("Done. Restart open sessions to pick it up.", "ok");
3733
3293
  setReview(void 0);
3734
3294
  setPicked(/* @__PURE__ */ new Set());
@@ -3756,7 +3316,11 @@ function SetupScreen(props) {
3756
3316
  {
3757
3317
  key: "↑↓",
3758
3318
  label: "scroll"
3759
- }
3319
+ },
3320
+ ...review.options.length > 0 ? [{
3321
+ key: "1-9",
3322
+ label: "tick option"
3323
+ }] : []
3760
3324
  ]);
3761
3325
  else setKeys([
3762
3326
  {
@@ -3836,6 +3400,7 @@ function SetupScreen(props) {
3836
3400
  scroll: review.scroll + 1
3837
3401
  });
3838
3402
  const closed = review.error || review.files.length === 0;
3403
+ if (/^[1-9]$/.test(input)) return toggleOption(Number(input) - 1);
3839
3404
  if (input === "n" || key.escape || closed && (key.return || input === "y")) return setReview(void 0);
3840
3405
  if (input === "y" && !closed) apply();
3841
3406
  return;
@@ -4013,23 +3578,7 @@ function SetupScreen(props) {
4013
3578
  setUp({ extra: 1 });
4014
3579
  },
4015
3580
  isActive: active,
4016
- children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 1)} ${box(extras.askBeforeRisky)} Ask me before risky commands (beta)` })
4017
- }),
4018
- /* @__PURE__ */ jsx(Hit, {
4019
- onClick: () => {
4020
- setCursor(clis.length + 2);
4021
- setUp({ extra: 2 });
4022
- },
4023
- isActive: active,
4024
- children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 2)} ${box(mouseOn)} Click and scroll with the mouse` })
4025
- }),
4026
- /* @__PURE__ */ jsx(Hit, {
4027
- onClick: () => {
4028
- setCursor(clis.length + 3);
4029
- setUp({ extra: 3 });
4030
- },
4031
- isActive: active,
4032
- children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 3)} ${box(extras.notifyDesktop !== false && !extras.notifyForcedOff)} Tell me on the desktop when something needs me` })
3581
+ children: /* @__PURE__ */ jsx(Text, { children: `${cursorMark(extraRow === 1)} ${box(mouseOn)} Click and scroll with the mouse` })
4033
3582
  }),
4034
3583
  !wide && health.length > 0 && rows >= 22 ? /* @__PURE__ */ jsxs(Box, {
4035
3584
  flexDirection: "column",
@@ -4066,484 +3615,6 @@ function SetupScreen(props) {
4066
3615
  }) : null]
4067
3616
  });
4068
3617
  }
4069
- // src/tui/screens/you.tsx
4070
- var you_exports = /* @__PURE__ */ __exportAll({ default: () => You });
4071
- /** Cards stop growing here, so they stay readable on a very wide terminal. */
4072
- const MAX_MAIN = 110;
4073
- const quiet = (c) => c.quiet ? { color: c.quiet } : { dimColor: true };
4074
- /** `m:ss` left until `iso`, or undefined when there is no time limit. */
4075
- function timeLeft(iso, now) {
4076
- if (!iso) return void 0;
4077
- const t = Date.parse(iso);
4078
- if (Number.isNaN(t)) return void 0;
4079
- const s = Math.max(0, Math.ceil((t - now) / 1e3));
4080
- return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
4081
- }
4082
- function sameDay(iso, now) {
4083
- if (!iso) return false;
4084
- const a = new Date(iso);
4085
- const b = new Date(now);
4086
- return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
4087
- }
4088
- function You(props) {
4089
- const { state, actions, layout, rows, columns, active, setKeys, setCommands, toast, setTyping, claimKeys } = props;
4090
- const { c, ascii } = useTheme();
4091
- const wide = layout === "wide";
4092
- const [selKey, setSelKey] = useState(props.focus ? `t:${props.focus}` : void 0);
4093
- const [typed, setTyped] = useState(void 0);
4094
- const [draft, setDraft] = useState("");
4095
- const [now, setNow] = useState(() => Date.now());
4096
- const nameOf = (id, fallback) => fallback ?? state.sessions.find((s) => s.id === id)?.name ?? "a session";
4097
- const open = useMemo(() => state.tickets.filter((t) => t.status === "open").sort((a, b) => a.createdAt.localeCompare(b.createdAt)), [state.tickets]);
4098
- const inbox = useMemo(() => state.inbox.filter((m) => !isFromOwner(m)).sort((a, b) => b.createdAt.localeCompare(a.createdAt)), [state.inbox]);
4099
- const order = useMemo(() => [...open.map((t) => `t:${t.id}`), ...inbox.map((m) => `m:${m.id}`)], [open, inbox]);
4100
- const curKey = order[Math.max(0, order.indexOf(selKey ?? ""))];
4101
- const curTicket = curKey?.startsWith("t:") ? open.find((t) => `t:${t.id}` === curKey) : void 0;
4102
- const curMessage = curKey?.startsWith("m:") ? inbox.find((m) => `m:${m.id}` === curKey) : void 0;
4103
- const hasPermission = open.some((t) => t.kind === "permission");
4104
- useEffect(() => {
4105
- if (!hasPermission) return;
4106
- const id = setInterval(() => setNow(Date.now()), 1e3);
4107
- return () => clearInterval(id);
4108
- }, [hasPermission]);
4109
- const optionCount = !typed && curTicket && curTicket.kind !== "permission" ? curTicket.options?.length ?? 0 : 0;
4110
- const claimsDigits = optionCount > 0;
4111
- const typing = active && typed !== void 0;
4112
- useEffect(() => {
4113
- setTyping(typing);
4114
- return () => setTyping(false);
4115
- }, [typing, setTyping]);
4116
- useEffect(() => {
4117
- const keys = active ? Array.from({ length: Math.min(optionCount, 9) }, (_, i) => String(i + 1)) : [];
4118
- claimKeys(keys);
4119
- return () => claimKeys([]);
4120
- }, [
4121
- active,
4122
- optionCount,
4123
- claimKeys
4124
- ]);
4125
- const acked = useRef(/* @__PURE__ */ new Set());
4126
- useEffect(() => {
4127
- if (!active || state.unread === 0) return;
4128
- const ids = inbox.map((m) => m.id).filter((id) => !acked.current.has(id));
4129
- if (ids.length === 0) return;
4130
- for (const id of ids) acked.current.add(id);
4131
- actions.markRead(ids).catch(() => {
4132
- for (const id of ids) acked.current.delete(id);
4133
- });
4134
- }, [
4135
- active,
4136
- state.unread,
4137
- inbox,
4138
- actions
4139
- ]);
4140
- useEffect(() => {
4141
- const keys = typed ? [{
4142
- key: "⏎",
4143
- label: "send"
4144
- }, {
4145
- key: "Esc",
4146
- label: "cancel"
4147
- }] : [{
4148
- key: "↑↓",
4149
- label: "move"
4150
- }];
4151
- if (!typed) {
4152
- if (curTicket?.kind === "permission") keys.push({
4153
- key: "y",
4154
- label: "allow once"
4155
- }, {
4156
- key: "n",
4157
- label: "deny"
4158
- });
4159
- else if (curTicket) {
4160
- if (claimsDigits) keys.push({
4161
- key: "1-9",
4162
- label: "answer"
4163
- });
4164
- keys.push({
4165
- key: "⏎",
4166
- label: "type an answer"
4167
- });
4168
- } else if (curMessage) keys.push({
4169
- key: "⏎",
4170
- label: "reply"
4171
- });
4172
- }
4173
- setKeys(keys);
4174
- }, [
4175
- setKeys,
4176
- typed,
4177
- curTicket,
4178
- curMessage,
4179
- claimsDigits
4180
- ]);
4181
- useEffect(() => {
4182
- setCommands([]);
4183
- }, [setCommands]);
4184
- const done = (text) => {
4185
- setTyped(void 0);
4186
- setDraft("");
4187
- toast(text);
4188
- };
4189
- const failed = () => toast("That didn't go through. Try again.", "error");
4190
- const answer = (t, text) => actions.answerTicket(t.id, text).then(() => done("Sent"), failed);
4191
- const decide = (t, allow) => actions.decide(t.id, allow).then(() => done(allow ? "Allowed" : "Denied"), failed);
4192
- const submit = (text) => {
4193
- const t = text.trim();
4194
- if (!typed || t === "") return;
4195
- if (typed.kind === "answer") answer(typed.ticket, t);
4196
- else {
4197
- const to = typed.message.fromName;
4198
- if (!to) return toast("You can't reply to that one.", "warn");
4199
- const id = typed.message.id;
4200
- actions.send(to, t).then(() => {
4201
- done("Sent");
4202
- acked.current.add(id);
4203
- actions.markRead([id]).catch(() => void 0);
4204
- }, failed);
4205
- }
4206
- };
4207
- const step = (d) => setSelKey((prev) => {
4208
- const at = Math.max(0, order.indexOf(prev ?? order[0] ?? ""));
4209
- return order[Math.max(0, Math.min(order.length - 1, at + d))];
4210
- });
4211
- const pick = (key) => {
4212
- if (typed) {
4213
- setTyped(void 0);
4214
- setDraft("");
4215
- }
4216
- setSelKey(key);
4217
- };
4218
- useInput((input, key) => {
4219
- if (typed) {
4220
- if (key.escape) {
4221
- setTyped(void 0);
4222
- setDraft("");
4223
- }
4224
- return;
4225
- }
4226
- if (key.upArrow || key.downArrow) return step(key.upArrow ? -1 : 1);
4227
- if (key.return) {
4228
- if (curTicket && curTicket.kind !== "permission") setTyped({
4229
- kind: "answer",
4230
- ticket: curTicket
4231
- });
4232
- else if (curMessage) setTyped({
4233
- kind: "reply",
4234
- message: curMessage
4235
- });
4236
- return;
4237
- }
4238
- if (curTicket?.kind === "permission") {
4239
- if (input === "y") decide(curTicket, true);
4240
- else if (input === "n") decide(curTicket, false);
4241
- return;
4242
- }
4243
- if (curTicket && claimsDigits && /^[1-9]$/.test(input)) {
4244
- const opt = curTicket.options?.[Number(input) - 1];
4245
- if (opt !== void 0) answer(curTicket, opt);
4246
- }
4247
- }, { isActive: active });
4248
- const split = splitWidths(columns, wide, { maxMain: MAX_MAIN });
4249
- const listW = wide ? split.mainW - 2 : Math.min(columns, MAX_MAIN);
4250
- const inner = listW - 4;
4251
- const dot = ascii ? "!" : "⚑";
4252
- const textBox = (placeholder) => /* @__PURE__ */ jsxs(Box, { children: [/* @__PURE__ */ jsx(Text, {
4253
- ...c.entry ? { color: c.entry } : {},
4254
- children: ascii ? "> " : "› "
4255
- }), /* @__PURE__ */ jsx(Box, {
4256
- width: Math.max(4, inner - 2),
4257
- children: /* @__PURE__ */ jsx(TextBox, {
4258
- value: draft,
4259
- onChange: setDraft,
4260
- onSubmit: submit,
4261
- focus: active,
4262
- multiline: true,
4263
- placeholder
4264
- })
4265
- })] });
4266
- const items = [];
4267
- const head = (text, first) => /* @__PURE__ */ jsx(Box, {
4268
- marginTop: first ? 0 : 1,
4269
- children: /* @__PURE__ */ jsx(Label, { children: plain(text, ascii) })
4270
- });
4271
- if (open.length === 0) items.push({
4272
- key: "none",
4273
- height: 2,
4274
- node: /* @__PURE__ */ jsxs(Box, {
4275
- flexDirection: "column",
4276
- children: [head("Needs you · 0", true), /* @__PURE__ */ jsx(Text, {
4277
- ...quiet(c),
4278
- children: "Nothing needs you right now."
4279
- })]
4280
- })
4281
- });
4282
- open.forEach((t, i) => {
4283
- const key = `t:${t.id}`;
4284
- const isSel = key === curKey;
4285
- const who = nameOf(t.fromSession);
4286
- const accent = isSel ? c.stamp : c.rule;
4287
- const mark = isSel ? ascii ? "> " : "▸ " : " ";
4288
- const editing = typed?.kind === "answer" && typed.ticket.id === t.id;
4289
- const lines = [];
4290
- let body = 0;
4291
- if (t.kind === "permission") {
4292
- const left = timeLeft(t.expiresAt, now);
4293
- const cmd = wrapLines(t.question, inner - 2).slice(0, 2);
4294
- body = 2 + cmd.length;
4295
- lines.push(/* @__PURE__ */ jsx(Ell, {
4296
- width: inner,
4297
- bold: true,
4298
- color: c.stamp,
4299
- children: `${mark}${dot} Wants to run a command ${who}`
4300
- }, "t"), /* @__PURE__ */ jsx(Box, {
4301
- backgroundColor: c.sunken,
4302
- paddingX: 1,
4303
- flexDirection: "column",
4304
- children: cmd.map((l, j) => /* @__PURE__ */ jsx(Ell, {
4305
- width: inner - 2,
4306
- children: l === "" ? " " : l
4307
- }, j))
4308
- }, "c"), /* @__PURE__ */ jsxs(Box, {
4309
- width: inner,
4310
- height: 1,
4311
- overflow: "hidden",
4312
- children: [
4313
- /* @__PURE__ */ jsx(Hit, {
4314
- onClick: () => void decide(t, true),
4315
- flexShrink: 0,
4316
- isActive: active,
4317
- children: /* @__PURE__ */ jsx(Text, {
4318
- ...quiet(c),
4319
- children: "y allow once"
4320
- })
4321
- }),
4322
- /* @__PURE__ */ jsx(Text, {
4323
- ...quiet(c),
4324
- children: " "
4325
- }),
4326
- /* @__PURE__ */ jsx(Hit, {
4327
- onClick: () => void decide(t, false),
4328
- flexShrink: 0,
4329
- isActive: active,
4330
- children: /* @__PURE__ */ jsx(Text, {
4331
- ...quiet(c),
4332
- children: "n deny"
4333
- })
4334
- }),
4335
- /* @__PURE__ */ jsx(Text, {
4336
- ...quiet(c),
4337
- wrap: "truncate",
4338
- children: left ? ` denied by itself in ${left}` : ""
4339
- })
4340
- ]
4341
- }, "k"));
4342
- } else {
4343
- const q = wrapLines(t.question, inner).slice(0, 3);
4344
- lines.push(/* @__PURE__ */ jsx(Ell, {
4345
- width: inner,
4346
- bold: true,
4347
- color: c.stamp,
4348
- children: plain(`${mark}? Question from ${who} · ${clockTime(t.createdAt)}`, ascii)
4349
- }, "t"), ...q.map((l, j) => /* @__PURE__ */ jsx(Ell, {
4350
- width: inner,
4351
- children: l === "" ? " " : l
4352
- }, `q${j}`)));
4353
- body = 2 + q.length + (editing ? draft.split("\n").length - 1 : 0);
4354
- const options = t.options ?? [];
4355
- const typeOwn = () => {
4356
- setSelKey(key);
4357
- setDraft("");
4358
- setTyped({
4359
- kind: "answer",
4360
- ticket: t
4361
- });
4362
- };
4363
- if (editing) lines.push(/* @__PURE__ */ jsx(Box, { children: textBox("Type your answer…") }, "b"));
4364
- else lines.push(/* @__PURE__ */ jsxs(Box, {
4365
- width: inner,
4366
- height: 1,
4367
- overflow: "hidden",
4368
- children: [options.map((o, j) => /* @__PURE__ */ jsxs(Box, {
4369
- flexShrink: 0,
4370
- children: [/* @__PURE__ */ jsx(Hit, {
4371
- onClick: () => void answer(t, o),
4372
- flexShrink: 0,
4373
- isActive: active,
4374
- children: /* @__PURE__ */ jsx(Text, {
4375
- ...quiet(c),
4376
- children: `[${j + 1}] ${o}`
4377
- })
4378
- }), /* @__PURE__ */ jsx(Text, {
4379
- ...quiet(c),
4380
- children: " "
4381
- })]
4382
- }, j)), /* @__PURE__ */ jsx(Hit, {
4383
- onClick: typeOwn,
4384
- flexShrink: 0,
4385
- isActive: active,
4386
- children: /* @__PURE__ */ jsx(Text, {
4387
- ...quiet(c),
4388
- wrap: "truncate",
4389
- children: options.length > 0 ? " or type your own" : "Press Enter to type an answer"
4390
- })
4391
- })]
4392
- }, "o"));
4393
- }
4394
- const height = body + 2;
4395
- items.push({
4396
- key,
4397
- height: height + (i === 0 ? 1 : 0),
4398
- node: /* @__PURE__ */ jsxs(Box, {
4399
- flexDirection: "column",
4400
- children: [i === 0 ? head(`Needs you · ${open.length}`, true) : null, /* @__PURE__ */ jsx(Hit, {
4401
- onClick: () => pick(key),
4402
- isActive: active,
4403
- children: /* @__PURE__ */ jsx(Card, {
4404
- accent,
4405
- width: listW,
4406
- children: lines
4407
- })
4408
- })]
4409
- })
4410
- });
4411
- });
4412
- inbox.forEach((m, i) => {
4413
- const key = `m:${m.id}`;
4414
- const isSel = key === curKey;
4415
- const who = m.fromName ?? nameOf(m.from);
4416
- const editing = typed?.kind === "reply" && typed.message.id === m.id;
4417
- const line = `${isSel ? ascii ? "> " : "▸ " : " "}${clockTime(m.createdAt)} ${who} ${messageText(m)}`;
4418
- items.push({
4419
- key,
4420
- height: (i === 0 ? 2 : 0) + 1 + (editing ? 1 : 0),
4421
- node: /* @__PURE__ */ jsxs(Box, {
4422
- flexDirection: "column",
4423
- children: [
4424
- i === 0 ? head(`Messages · ${inbox.length}`, false) : null,
4425
- /* @__PURE__ */ jsx(Hit, {
4426
- onClick: () => {
4427
- setSelKey(key);
4428
- setDraft("");
4429
- setTyped({
4430
- kind: "reply",
4431
- message: m
4432
- });
4433
- },
4434
- isActive: active,
4435
- children: /* @__PURE__ */ jsx(Row, {
4436
- width: listW,
4437
- selected: isSel,
4438
- children: /* @__PURE__ */ jsx(Ell, {
4439
- width: listW,
4440
- bold: isSel,
4441
- children: line
4442
- })
4443
- })
4444
- }),
4445
- editing ? /* @__PURE__ */ jsx(Box, {
4446
- paddingLeft: 2,
4447
- children: textBox(`Reply to ${who}…`)
4448
- }) : null
4449
- ]
4450
- })
4451
- });
4452
- });
4453
- if (inbox.length === 0) items.push({
4454
- key: "nomsg",
4455
- height: 3,
4456
- node: /* @__PURE__ */ jsxs(Box, {
4457
- flexDirection: "column",
4458
- children: [head("Messages · 0", false), /* @__PURE__ */ jsx(Text, {
4459
- ...quiet(c),
4460
- children: "No messages yet."
4461
- })]
4462
- })
4463
- });
4464
- const selItem = Math.max(0, items.findIndex((x) => x.key === curKey));
4465
- let start = 0;
4466
- const sum = (a, b) => items.slice(a, b).reduce((n, x) => n + x.height, 0);
4467
- while (start < selItem && sum(start, selItem + 1) > rows) start++;
4468
- const shown = [];
4469
- let used = 0;
4470
- for (const it of items.slice(start)) {
4471
- if (used + it.height > rows && shown.length > 0) break;
4472
- shown.push(it);
4473
- used += it.height;
4474
- }
4475
- return /* @__PURE__ */ jsxs(Box, {
4476
- width: columns,
4477
- height: rows,
4478
- children: [/* @__PURE__ */ jsx(Hit, {
4479
- flexDirection: "column",
4480
- width: wide ? split.mainW : listW,
4481
- flexShrink: 0,
4482
- onWheel: (d) => {
4483
- if (!typed) step(d < 0 ? -1 : 1);
4484
- },
4485
- isActive: active,
4486
- children: shown.map((it) => /* @__PURE__ */ jsx(Box, { children: it.node }, it.key))
4487
- }), wide ? /* @__PURE__ */ jsx(Pane, {
4488
- width: split.panelW,
4489
- height: rows,
4490
- children: /* @__PURE__ */ jsx(SidePanel, {
4491
- state,
4492
- width: paneInner(split.panelW),
4493
- now,
4494
- nameOf,
4495
- active,
4496
- onPick: pick
4497
- })
4498
- }) : null]
4499
- });
4500
- }
4501
- function SidePanel({ state, width, now, nameOf, active, onPick }) {
4502
- const { c, ascii } = useTheme();
4503
- const open = state.tickets.filter((t) => t.status === "open");
4504
- const doneToday = state.tickets.filter((t) => t.status !== "open" && sameDay(t.answeredAt ?? t.createdAt, now));
4505
- const tick = ascii ? "ok" : "✓";
4506
- return /* @__PURE__ */ jsxs(Box, {
4507
- width,
4508
- flexDirection: "column",
4509
- children: [
4510
- /* @__PURE__ */ jsx(Label, { children: `Open · ${open.length}` }),
4511
- open.length === 0 ? /* @__PURE__ */ jsx(Text, {
4512
- ...quiet(c),
4513
- children: "Nothing open."
4514
- }) : null,
4515
- open.slice(0, 6).map((t) => /* @__PURE__ */ jsx(Hit, {
4516
- onClick: () => onPick(`t:${t.id}`),
4517
- isActive: active,
4518
- children: /* @__PURE__ */ jsx(Ell, {
4519
- width,
4520
- color: c.stamp,
4521
- children: `${t.kind === "permission" ? ascii ? "!" : "⚑" : "?"} ${nameOf(t.fromSession)} ${t.question}`
4522
- })
4523
- }, t.id)),
4524
- /* @__PURE__ */ jsx(Box, {
4525
- marginTop: 1,
4526
- children: /* @__PURE__ */ jsx(Label, { children: `Done today · ${doneToday.length}` })
4527
- }),
4528
- doneToday.length === 0 ? /* @__PURE__ */ jsx(Text, {
4529
- ...quiet(c),
4530
- children: "Nothing yet."
4531
- }) : null,
4532
- doneToday.slice(0, 6).map((t) => /* @__PURE__ */ jsx(Ell, {
4533
- width,
4534
- color: c.quiet,
4535
- children: `${tick} ${nameOf(t.fromSession)} ${t.question}`
4536
- }, t.id)),
4537
- /* @__PURE__ */ jsx(Box, {
4538
- marginTop: 1,
4539
- children: /* @__PURE__ */ jsx(Text, {
4540
- ...quiet(c),
4541
- children: "Your answer goes straight back, and the session carries on."
4542
- })
4543
- })
4544
- ]
4545
- });
4546
- }
4547
3618
  // src/tui/screens/index.ts
4548
3619
  /** A screen file exports its component as `default` or as `<Name>Screen`. */
4549
3620
  const pick = (m, name) => {
@@ -4552,7 +3623,6 @@ const pick = (m, name) => {
4552
3623
  };
4553
3624
  const SCREEN_COMPONENTS = {
4554
3625
  sessions: pick(sessions_exports, "Sessions"),
4555
- you: pick(you_exports, "You"),
4556
3626
  new: pick(new_exports, "New"),
4557
3627
  devices: pick(devices_exports, "Devices"),
4558
3628
  setup: pick(setup_exports, "Setup")
@@ -4561,25 +3631,19 @@ const SCREEN_COMPONENTS = {
4561
3631
  /** The app shell: top bar, tabs, one screen, key bar, and the palette and help overlays. */
4562
3632
  const TOAST_MS = 3e3;
4563
3633
  const MIN_COLUMNS = 60;
4564
- /** Questions and permission requests that wait for the owner, plus messages nobody has read. */
4565
- const needYou = (s) => s.tickets.filter((t) => t.status === "open").length + s.unread;
4566
3634
  const SCREEN_LINE = {
4567
3635
  sessions: (s) => {
4568
3636
  const total = s.sessions.length;
4569
- if (total === 0) return "No sessions yet";
4570
- const live = s.sessions.filter((x) => x.status !== "offline").length;
4571
- return `${total} ${total === 1 ? "session" : "sessions"} · ${live} running`;
3637
+ if (total === 0) return "Nothing is running";
3638
+ return `${total} ${total === 1 ? "session" : "sessions"} running`;
4572
3639
  },
4573
- you: () => "Questions and messages for you",
4574
3640
  new: () => "Start something new",
4575
3641
  devices: () => "Your machines",
4576
3642
  setup: () => "Get your tools ready"
4577
3643
  };
4578
- function TopBar({ state, screen, width, onYou }) {
3644
+ function TopBar({ state, screen, width }) {
4579
3645
  const { c, ascii } = useTheme();
4580
- const need = needYou(state);
4581
3646
  const dot = ascii ? "*" : "●";
4582
- const right = need > 0 ? `${dot} ${need} need you` : "";
4583
3647
  let line = SCREEN_LINE[screen](state);
4584
3648
  let lineColor = c.quiet;
4585
3649
  if (state.connection === "connecting") line = "Connecting…";
@@ -4592,7 +3656,7 @@ function TopBar({ state, screen, width, onYou }) {
4592
3656
  }
4593
3657
  if (ascii) line = line.replace(/·/g, "-");
4594
3658
  const inner = width - 2;
4595
- const room = Math.max(0, inner - 11 - (right ? right.length + 2 : 0));
3659
+ const room = Math.max(0, inner - 11);
4596
3660
  return /* @__PURE__ */ jsxs(Band, {
4597
3661
  width,
4598
3662
  children: [
@@ -4619,30 +3683,20 @@ function TopBar({ state, screen, width, onYou }) {
4619
3683
  color: lineColor,
4620
3684
  children: line
4621
3685
  })
4622
- }),
4623
- /* @__PURE__ */ jsx(Box, { flexGrow: 1 }),
4624
- right ? /* @__PURE__ */ jsx(Clickable, {
4625
- onClick: onYou,
4626
- children: /* @__PURE__ */ jsx(Text, {
4627
- bold: true,
4628
- ...c.stamp ? { color: c.stamp } : {},
4629
- children: right
4630
- })
4631
- }) : null
3686
+ })
4632
3687
  ]
4633
3688
  });
4634
3689
  }
4635
3690
  /** The tab row, and under it the rule with the active tab underlined in the entry colour. */
4636
- function Tabs({ screen, layout, youCount, width, onGo }) {
3691
+ function Tabs({ screen, layout, width, onGo }) {
4637
3692
  const { c, ascii } = useTheme();
4638
3693
  const narrow = layout === "narrow";
4639
3694
  const labels = SCREENS.map((s) => {
4640
3695
  const on = s.id === screen;
4641
- const extra = s.id === "you" && youCount > 0 ? ` (${youCount})` : "";
4642
3696
  return {
4643
3697
  id: s.id,
4644
3698
  on,
4645
- text: narrow && !on ? s.key : `${s.key} ${s.title}${extra}`
3699
+ text: narrow && !on ? s.key : `${s.key} ${s.title}`
4646
3700
  };
4647
3701
  });
4648
3702
  const gap = 2;
@@ -4884,7 +3938,6 @@ function Shell({ store, onQuit, size, mouse }) {
4884
3938
  if (movedRef.current) return;
4885
3939
  if (!state.setup.clis.some((c) => c.status === "ready" || c.status === "needs-update") && state.setup.clis.length > 0) go("setup");
4886
3940
  }, [state.setup, go]);
4887
- const youCount = needYou(state);
4888
3941
  const draftCtx = useMemo(() => ({ cleared: () => {
4889
3942
  draftCleared.current = true;
4890
3943
  } }), []);
@@ -4985,13 +4038,11 @@ function Shell({ store, onQuit, size, mouse }) {
4985
4038
  /* @__PURE__ */ jsx(TopBar, {
4986
4039
  state,
4987
4040
  screen,
4988
- width: columns,
4989
- onYou: () => go("you")
4041
+ width: columns
4990
4042
  }),
4991
4043
  /* @__PURE__ */ jsx(Tabs, {
4992
4044
  screen,
4993
4045
  layout,
4994
- youCount,
4995
4046
  width: columns,
4996
4047
  onGo: go
4997
4048
  }),
@@ -5117,269 +4168,12 @@ async function confirmPair(client, match, code) {
5117
4168
  if (s.state === "done") current.delete(client);
5118
4169
  return s;
5119
4170
  }
5120
- // src/tui/setup-data.ts
5121
- /**
5122
- * What the Setup screen reads and does. Same facts as `conveno doctor`, in plain words, and the
5123
- * same code path as `conveno init` / `conveno uninstall` for changing files.
5124
- *
5125
- * No Ink or React in here: the store imports it.
5126
- */
5127
- const ready = (r) => r.mcp === "ok" && (r.hooks === null || r.hooks === "ok");
5128
- /** One CLI's row, from what `conveno doctor` found. Exported for tests. */
5129
- function checkFromRow(r, compat) {
5130
- const { adapter, detection } = r;
5131
- const base = {
5132
- cli: adapter.cli,
5133
- label: adapter.displayName
5134
- };
5135
- const version = detection.version;
5136
- const withVersion = version ? { version } : {};
5137
- if (!detection.installed) return {
5138
- ...base,
5139
- status: "not-installed",
5140
- note: "install it, then press g"
5141
- };
5142
- const c = compatStatus(adapter.cli, version, compat);
5143
- if (r.planError) return {
5144
- ...base,
5145
- ...withVersion,
5146
- status: "blocked",
5147
- note: "we can't read its settings file"
5148
- };
5149
- if (c.kind === "older") return {
5150
- ...base,
5151
- ...withVersion,
5152
- status: "blocked",
5153
- note: `too old, update it first (needs ${c.minimum} or newer)`
5154
- };
5155
- if (ready(r)) return {
5156
- ...base,
5157
- ...withVersion,
5158
- status: "ready",
5159
- ...c.kind === "newer" && c.minor ? { note: "a bit newer than we tested, should be fine" } : {}
5160
- };
5161
- const allMissing = [r.mcp, r.hooks].filter((p) => p !== null).every((p) => p === "missing");
5162
- return {
5163
- ...base,
5164
- ...withVersion,
5165
- status: allMissing ? "not-set-up" : "needs-update",
5166
- note: "press ⏎ to fix"
5167
- };
5168
- }
5169
- /** The checkup list. Exported for tests. */
5170
- function healthFrom(input) {
5171
- const out = [];
5172
- out.push(input.daemon === "running" ? {
5173
- level: "ok",
5174
- text: "Conveno is running"
5175
- } : input.daemon === "stopped" ? {
5176
- level: "warn",
5177
- text: "Conveno is not running yet. It starts with your first session."
5178
- } : {
5179
- level: "error",
5180
- text: "Conveno can't be reached"
5181
- });
5182
- const installed = input.clis.filter((c) => c.status !== "not-installed");
5183
- const good = installed.filter((c) => c.status === "ready").length;
5184
- out.push(installed.length === 0 ? {
5185
- level: "warn",
5186
- text: "No supported CLI found on this machine"
5187
- } : {
5188
- level: good === installed.length ? "ok" : "info",
5189
- text: `${good} of ${installed.length} CLIs ready`
5190
- });
5191
- let fixes = 0;
5192
- for (const c of installed) if (c.status === "needs-update") {
5193
- fixes++;
5194
- out.push({
5195
- level: "warn",
5196
- text: `${c.label} needs an update`,
5197
- fixId: `init:${c.cli}`
5198
- });
5199
- } else if (c.status === "not-set-up") {
5200
- fixes++;
5201
- out.push({
5202
- level: "warn",
5203
- text: `${c.label} is not set up yet`,
5204
- fixId: `init:${c.cli}`
5205
- });
5206
- } else if (c.status === "blocked") out.push({
5207
- level: "error",
5208
- text: `${c.label} is blocked: ${c.note ?? "see Setup"}`
5209
- });
5210
- if (input.sync === "online") out.push({
5211
- level: "ok",
5212
- text: "Sync is online"
5213
- });
5214
- else if (input.sync === "offline") out.push({
5215
- level: "warn",
5216
- text: "Sync is offline, it keeps trying"
5217
- });
5218
- if (fixes === 0) out.push({
5219
- level: "ok",
5220
- text: "Up to date"
5221
- });
5222
- return out;
5223
- }
5224
- /** The same facts as `conveno doctor`, as friendly rows. Never throws. */
5225
- async function loadSetup(ctx) {
5226
- const clis = (await Promise.all(ctx.adapters.map((a) => inspect(ctx, a)))).map((r) => checkFromRow(r, ctx.compat));
5227
- let daemon = "stopped";
5228
- let sync;
5229
- try {
5230
- const client = await ctx.connect(connectOpts(ctx, false));
5231
- try {
5232
- await client["session.list"]({ includeOffline: true });
5233
- daemon = "running";
5234
- const relay = await client["relay.status"]({}).catch(() => void 0);
5235
- if (relay) {
5236
- if (relay.state === "connected") sync = "online";
5237
- else if (relay.state === "connecting" || relay.state === "disconnected") sync = "offline";
5238
- }
5239
- } finally {
5240
- await client.close().catch(() => void 0);
5241
- }
5242
- } catch (e) {
5243
- daemon = daemonProblem(ctx.theme, e).notRunning ? "stopped" : "unreachable";
5244
- }
5245
- return {
5246
- clis,
5247
- health: healthFrom({
5248
- daemon,
5249
- ...sync ? { sync } : {},
5250
- clis
5251
- })
5252
- };
5253
- }
5254
- function parseFixId(fixId) {
5255
- const [kind, cli] = fixId.split(":");
5256
- if (kind === "init" && cli) return {
5257
- kind,
5258
- cli
5259
- };
5260
- if (kind === "uninstall" && cli) return {
5261
- kind,
5262
- cli
5263
- };
5264
- if (kind === "relay") return { kind };
5265
- }
5266
- async function planFor(ctx, fixId) {
5267
- const parsed = parseFixId(fixId);
5268
- if (!parsed) return {
5269
- items: [],
5270
- error: "We don't know that fix."
5271
- };
5272
- let adapters;
5273
- if (parsed.kind === "relay") adapters = ctx.adapters.filter((a) => a.permissionHookInstalled);
5274
- else {
5275
- const a = ctx.adapters.find((x) => x.cli === parsed.cli);
5276
- if (!a) return {
5277
- items: [],
5278
- error: "We don't know that CLI."
5279
- };
5280
- adapters = [a];
5281
- }
5282
- const env = adapterEnv(ctx);
5283
- const found = [];
5284
- for (const adapter of adapters) {
5285
- const detection = await adapter.detect(env).catch(() => ({
5286
- installed: false,
5287
- configPaths: []
5288
- }));
5289
- if (detection.installed) found.push({
5290
- adapter,
5291
- detection
5292
- });
5293
- }
5294
- if (found.length === 0) return {
5295
- items: [],
5296
- error: "It isn't installed."
5297
- };
5298
- if (parsed.kind === "relay") {
5299
- const todo = [];
5300
- for (const f of found) if (!await f.adapter.permissionHookInstalled?.(env).catch(() => false)) todo.push(f);
5301
- const { items, failures } = await collectPlans(ctx, todo, "plan", void 0, { permissionRelay: true });
5302
- return {
5303
- items: items.filter((i) => i.change.component === "hooks"),
5304
- ...failures[0] ? { error: failures[0].message } : {}
5305
- };
5306
- }
5307
- const { items, failures } = await collectPlans(ctx, found, parsed.kind === "init" ? "plan" : "uninstallPlan");
5308
- return {
5309
- items,
5310
- ...failures[0] ? { error: failures[0].message } : {}
5311
- };
5312
- }
5313
- /** Cap on diff lines kept per file, so one big file cannot fill the overlay. */
5314
- const MAX_DIFF_LINES = 60;
5315
- /** What `applyFix` would change, without changing anything. */
5316
- async function planFix(ctx, fixId) {
5317
- const { items, error } = await planFor(ctx, fixId);
5318
- return {
5319
- files: items.map(({ change }) => {
5320
- const lines = unifiedDiff(change.before, change.after);
5321
- return {
5322
- path: tilde(change.path, ctx.home),
5323
- isNew: change.before === null,
5324
- deleted: Boolean(change.deleteFile),
5325
- summary: change.description,
5326
- lines: lines.length > MAX_DIFF_LINES ? lines.slice(0, MAX_DIFF_LINES) : lines
5327
- };
5328
- }),
5329
- ...error ? { error } : {}
5330
- };
5331
- }
5332
- /**
5333
- * Make the change `planFix` showed: back up each file, then write. Same code path as
5334
- * `conveno init` (and `conveno uninstall` without a backup on record). Throws a friendly error.
5335
- */
5336
- async function applyFix(ctx, fixId) {
5337
- const { items, error } = await planFor(ctx, fixId);
5338
- if (error) throw new Error(error);
5339
- if (items.length === 0) return;
5340
- try {
5341
- await applyChanges(ctx, items, parseFixId(fixId)?.kind === "uninstall" ? { markRestored: true } : {});
5342
- } catch (e) {
5343
- if (e instanceof StaleError) throw new Error("A settings file changed while we waited. Press g, then try again.");
5344
- throw new Error(plainError(e));
5345
- }
5346
- }
5347
- async function getExtras(ctx) {
5348
- const helpers = readSettings(dataPaths(ctx.platform, ctx.dataDir).settings).acpAdapterNpx === true;
5349
- const env = adapterEnv(ctx);
5350
- let any = false;
5351
- let all = true;
5352
- for (const a of ctx.adapters) {
5353
- if (!a.permissionHookInstalled) continue;
5354
- if (!(await a.detect(env).catch(() => ({ installed: false }))).installed) continue;
5355
- any = true;
5356
- if (!await a.permissionHookInstalled(env).catch(() => false)) all = false;
5357
- }
5358
- return {
5359
- helpers,
5360
- askBeforeRisky: any && all,
5361
- notifyDesktop: readSettings(dataPaths(ctx.platform, ctx.dataDir).settings).notifyDesktop !== false,
5362
- notifyForcedOff: notifyForcedOff(ctx.env)
5363
- };
5364
- }
5365
- /** Same answer as `conveno init --acp-adapters` / `--no-acp-adapters`. */
5366
- function setHelpers(ctx, on) {
5367
- writeSettings(dataPaths(ctx.platform, ctx.dataDir).settings, { acpAdapterNpx: on });
5368
- }
5369
- /** Save the desktop notification choice. The daemon reads it on its next notification. */
5370
- function setNotify(ctx, on) {
5371
- writeSettings(dataPaths(ctx.platform, ctx.dataDir).settings, { notifyDesktop: on });
5372
- }
5373
4171
  // src/tui/store.ts
5374
4172
  /**
5375
4173
  * The app's data layer: one daemon connection, the state the screens read, and every action they
5376
4174
  * can take. It loads once, then follows `events.subscribe` and polls what has no event (sync and
5377
4175
  * devices). When the daemon goes away it says so and reconnects with a growing wait.
5378
4176
  */
5379
- /** How many messages the app holds in memory per session's chat. */
5380
- const HISTORY_KEEP = 1e3;
5381
- /** Page size when loading a session's chat from the daemon. */
5382
- const HISTORY_PAGE = 100;
5383
4177
  const POLL_MS = 15e3;
5384
4178
  const WATCH_MS = 5e3;
5385
4179
  const STOP_WAIT_MS = 1e4;
@@ -5392,16 +4186,9 @@ const BACKOFF_MS = [
5392
4186
  ];
5393
4187
  const initial = () => ({
5394
4188
  connection: "connecting",
5395
- sessions: [],
5396
- inbox: [],
5397
- unread: 0,
5398
- tickets: [],
5399
- history: {},
5400
- historyMore: {}
4189
+ sessions: []
5401
4190
  });
5402
4191
  const reason = (e) => e instanceof Error ? e.message : String(e);
5403
- /** The tickets the owner can act on: addressed to them, or a permission request. */
5404
- const forOwner = (t) => t.toSession === OWNER_SESSION_ID || t.kind === "permission";
5405
4192
  function upsert(list, item) {
5406
4193
  const i = list.findIndex((x) => x.id === item.id);
5407
4194
  if (i < 0) return [...list, item];
@@ -5409,9 +4196,8 @@ function upsert(list, item) {
5409
4196
  next[i] = item;
5410
4197
  return next;
5411
4198
  }
5412
- /** Time order; the id (a ULID) breaks ties. */
5413
- const byTime = (a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id);
5414
- const byCreated = (a, b) => a.createdAt.localeCompare(b.createdAt);
4199
+ /** Only sessions that are online show in the app. */
4200
+ const online = (list) => list.filter((s) => s.status !== "offline");
5415
4201
  async function createStore(ctx, opts = {}) {
5416
4202
  const open = opts.connect ?? (() => ctx.connect(connectOpts(ctx, true)));
5417
4203
  const backoff = opts.backoffMs ?? BACKOFF_MS;
@@ -5433,59 +4219,11 @@ async function createStore(ctx, opts = {}) {
5433
4219
  if (!client || state.connection === "daemon-down") throw new Error("Conveno's background service is not running right now. Trying to reconnect.");
5434
4220
  return client;
5435
4221
  };
5436
- /** Which session a message belongs to in the chat view: the other side of the conversation. */
5437
- /** Every session whose chat shows this message: the sender and the recipient (not `you`). */
5438
- function historyKeys(m) {
5439
- const keys = /* @__PURE__ */ new Set();
5440
- if (m.from !== OWNER_SESSION_ID) keys.add(m.from);
5441
- const to = m.to;
5442
- const target = isLeadAlias(to) ? state.sessions.find((s) => s.isOrchestrator) : state.sessions.find((s) => s.id === to || s.name === to);
5443
- if (target) keys.add(target.id);
5444
- return [...keys];
5445
- }
5446
- /** Merge messages into a session's chat: no duplicates, oldest first, at most HISTORY_KEEP. */
5447
- function mergeHistory(cur, add, keep) {
5448
- const seen = new Set(cur.map((x) => x.id));
5449
- const fresh = add.filter((x) => !seen.has(x.id));
5450
- if (fresh.length === 0) return cur;
5451
- const all = [...cur, ...fresh].sort(byTime);
5452
- if (all.length <= 1e3) return all;
5453
- return keep === "newest" ? all.slice(-1e3) : all.slice(0, HISTORY_KEEP);
5454
- }
5455
- function addMessage(m) {
5456
- const patch = {};
5457
- if (m.to === "you" && !state.inbox.some((x) => x.id === m.id)) {
5458
- patch.inbox = [...state.inbox, m].sort(byCreated).slice(-100);
5459
- patch.unread = state.unread + 1;
5460
- }
5461
- for (const key of historyKeys(m)) {
5462
- const cur = (patch.history ?? state.history)[key] ?? [];
5463
- if (cur.some((x) => x.id === m.id)) continue;
5464
- patch.history = {
5465
- ...patch.history ?? state.history,
5466
- [key]: mergeHistory(cur, [m], "newest")
5467
- };
5468
- if (cur.length >= 1e3) patch.historyMore = {
5469
- ...patch.historyMore ?? state.historyMore,
5470
- [key]: true
5471
- };
5472
- }
5473
- if (patch.inbox || patch.history) set(patch);
5474
- }
5475
4222
  function applyEvent(e) {
5476
4223
  switch (e.event) {
5477
- case "message.received":
5478
- addMessage(e.data.message);
5479
- break;
5480
- case "ticket.created":
5481
- case "ticket.answered": {
5482
- const t = e.data.ticket;
5483
- if (forOwner(t)) set({ tickets: upsert(state.tickets, t) });
5484
- break;
5485
- }
5486
4224
  case "session.updated": {
5487
4225
  const s = e.data.session;
5488
- if (e.data.change === "unregistered") set({ sessions: state.sessions.filter((x) => x.id !== s.id) });
4226
+ if (e.data.change === "unregistered" || s.status === "offline") set({ sessions: state.sessions.filter((x) => x.id !== s.id) });
5489
4227
  else set({ sessions: upsert(state.sessions, s) });
5490
4228
  break;
5491
4229
  }
@@ -5530,28 +4268,8 @@ async function createStore(ctx, opts = {}) {
5530
4268
  }
5531
4269
  /** Everything the screens need, in one pass. Safe to call again after a reconnect. */
5532
4270
  async function load(c) {
5533
- const [sessions, inbox, open, answered] = await Promise.all([
5534
- c["session.list"]({ includeOffline: true }),
5535
- c["owner.inbox"]({ limit: 200 }),
5536
- c["ticket.list"]({
5537
- status: "open",
5538
- limit: 200
5539
- }),
5540
- c["ticket.list"]({
5541
- status: "answered",
5542
- limit: 50
5543
- }).catch(() => ({ tickets: [] }))
5544
- ]);
5545
- const tickets = [...open.tickets, ...answered.tickets].filter(forOwner);
5546
- const history = { ...state.history };
5547
- for (const m of inbox.messages) history[m.from] = mergeHistory(history[m.from] ?? [], [m], "newest");
5548
- set({
5549
- sessions: sessions.sessions,
5550
- inbox: inbox.messages.slice(-100),
5551
- unread: inbox.unreadCount,
5552
- tickets,
5553
- history
5554
- });
4271
+ const r = await c["session.list"]({});
4272
+ set({ sessions: online(r.sessions) });
5555
4273
  }
5556
4274
  async function attach(c) {
5557
4275
  client = c;
@@ -5597,8 +4315,8 @@ async function createStore(ctx, opts = {}) {
5597
4315
  const c = client;
5598
4316
  if (!c || reconnecting || closed) return;
5599
4317
  try {
5600
- const r = await c["session.list"]({ includeOffline: true });
5601
- set({ sessions: r.sessions });
4318
+ const r = await c["session.list"]({});
4319
+ set({ sessions: online(r.sessions) });
5602
4320
  } catch {
5603
4321
  reconnect();
5604
4322
  }
@@ -5606,43 +4324,34 @@ async function createStore(ctx, opts = {}) {
5606
4324
  const nameOf = (id) => state.sessions.find((s) => s.id === id)?.name;
5607
4325
  const actions = {
5608
4326
  async send(to, text) {
5609
- addMessage((await live()["owner.send"]({
4327
+ await live()["owner.send"]({
5610
4328
  to,
5611
4329
  text
5612
- })).message);
5613
- },
5614
- async answerTicket(ticketId, response) {
5615
- const res = await live()["ticket.answer"]({
5616
- ticketId,
5617
- response
5618
4330
  });
5619
- set({ tickets: upsert(state.tickets, res.ticket) });
5620
4331
  },
5621
- async decide(ticketId, allow) {
5622
- const res = await live()["ticket.answer"]({
5623
- ticketId,
5624
- response: allow ? PERMISSION_ANSWERS[0] : PERMISSION_ANSWERS[1]
5625
- });
5626
- set({ tickets: upsert(state.tickets, res.ticket) });
4332
+ async setLead(sessionId) {
4333
+ await live()["orchestrator.claim"]({ sessionId });
4334
+ set({ sessions: state.sessions.map((s) => ({
4335
+ ...s,
4336
+ isOrchestrator: s.id === sessionId
4337
+ })) });
5627
4338
  },
5628
- async setAuto(sessionId, on) {
5629
- const res = await live()["session.setAuto"]({
5630
- session: sessionId,
5631
- auto: on
5632
- });
5633
- set({ sessions: upsert(state.sessions, res.session) });
4339
+ async clearLead() {
4340
+ await live()["orchestrator.clear"]({});
4341
+ set({ sessions: state.sessions.map((s) => ({
4342
+ ...s,
4343
+ isOrchestrator: false
4344
+ })) });
5634
4345
  },
5635
4346
  async stop(sessionId) {
5636
4347
  const name = nameOf(sessionId);
5637
4348
  const rec = name ? readSpawnRecord(spawnRecordPath(ctx.dataDir, name)) : void 0;
5638
4349
  if (!name || !rec) throw new Error("Only sessions started from Conveno on this machine can be stopped here.");
5639
- if (!rec.headless) throw new Error(`${name} runs in a window. Close it there.`);
4350
+ if (!rec.acp) throw new Error(`${name} runs in a window. Close it there.`);
5640
4351
  const alive = () => rec.pid !== void 0 && ctx.isAlive(rec.pid);
5641
- if (rec.acp) {
5642
- writeFileSync(stopRequestPath(spawnRecordPath(ctx.dataDir, rec.name)), "", { mode: 384 });
5643
- const end = Date.now() + STOP_WAIT_MS;
5644
- while (alive() && Date.now() < end) await new Promise((r) => setTimeout(r, 100));
5645
- }
4352
+ writeFileSync(stopRequestPath(spawnRecordPath(ctx.dataDir, rec.name)), "", { mode: 384 });
4353
+ const end = Date.now() + STOP_WAIT_MS;
4354
+ while (alive() && Date.now() < end) await new Promise((r) => setTimeout(r, 100));
5646
4355
  if (alive() && rec.pid !== void 0) killProcessTree(rec.pid, ctx.platform);
5647
4356
  if (rec.agentPid !== void 0 && ctx.isAlive(rec.agentPid)) killProcessTree(rec.agentPid, ctx.platform);
5648
4357
  },
@@ -5653,24 +4362,6 @@ async function createStore(ctx, opts = {}) {
5653
4362
  });
5654
4363
  set({ sessions: upsert(state.sessions, res.session) });
5655
4364
  },
5656
- async forget(sessionId) {
5657
- await live()["session.forget"]({ ids: [sessionId] });
5658
- set({ sessions: state.sessions.filter((s) => s.id !== sessionId) });
5659
- },
5660
- async peek(sessionId) {
5661
- const r = await live()["session.peek"]({ target: sessionId });
5662
- return {
5663
- session: r.session.id,
5664
- mode: "recent",
5665
- turns: r.turns.map((t) => ({
5666
- role: t.role,
5667
- text: t.text,
5668
- ...t.at ? { ts: t.at } : {}
5669
- })),
5670
- truncated: r.truncated,
5671
- redacted: true
5672
- };
5673
- },
5674
4365
  async spawn(p) {
5675
4366
  const c = live();
5676
4367
  const runner = ctx.spawnRunner ?? [process.execPath, process.argv[1] ?? "conveno"];
@@ -5682,65 +4373,15 @@ async function createStore(ctx, opts = {}) {
5682
4373
  client: c,
5683
4374
  runner
5684
4375
  });
5685
- const res = await spawnSession(deps, {
4376
+ return { sessionId: (await spawnSession(deps, {
5686
4377
  cli: p.cli,
5687
4378
  callerCwd: ctx.cwd,
5688
4379
  cwd: p.cwd,
5689
4380
  name: p.name,
5690
4381
  task: p.prompt,
5691
- headless: p.mode !== "visible",
5692
- acp: p.mode === "acp" ? "require" : void 0,
4382
+ window: p.window,
5693
4383
  confineToHome: false
5694
- });
5695
- if (p.auto) await c["session.setAuto"]({
5696
- session: res.id,
5697
- auto: true
5698
- }).catch(() => void 0);
5699
- return { sessionId: res.id };
5700
- },
5701
- async loadHistory(sessionId) {
5702
- const res = await live()["message.history"]({
5703
- session: sessionId,
5704
- limit: HISTORY_PAGE
5705
- });
5706
- const cur = state.history[sessionId] ?? [];
5707
- set({
5708
- history: {
5709
- ...state.history,
5710
- [sessionId]: mergeHistory(cur, res.messages, "newest")
5711
- },
5712
- historyMore: {
5713
- ...state.historyMore,
5714
- [sessionId]: res.more
5715
- }
5716
- });
5717
- },
5718
- async loadOlder(sessionId) {
5719
- const cur = state.history[sessionId] ?? [];
5720
- const oldest = cur[0];
5721
- if (!oldest) {
5722
- await actions.loadHistory(sessionId);
5723
- return (state.history[sessionId]?.length ?? 0) > 0;
5724
- }
5725
- if (state.historyMore[sessionId] === false || cur.length >= 1e3) return false;
5726
- const res = await live()["message.history"]({
5727
- session: sessionId,
5728
- limit: HISTORY_PAGE,
5729
- before: oldest.id
5730
- });
5731
- const now = state.history[sessionId] ?? [];
5732
- const merged = mergeHistory(now, res.messages, "oldest");
5733
- set({
5734
- history: {
5735
- ...state.history,
5736
- [sessionId]: merged
5737
- },
5738
- historyMore: {
5739
- ...state.historyMore,
5740
- [sessionId]: res.more && merged.length < 1e3
5741
- }
5742
- });
5743
- return merged.length > now.length;
4384
+ })).id };
5744
4385
  },
5745
4386
  async refreshSetup() {
5746
4387
  await loadSetupData();
@@ -5754,9 +4395,6 @@ async function createStore(ctx, opts = {}) {
5754
4395
  async setHelpers(on) {
5755
4396
  setHelpers(ctx, on);
5756
4397
  },
5757
- async setNotify(on) {
5758
- setNotify(ctx, on);
5759
- },
5760
4398
  pair: async () => {
5761
4399
  const r = await startPair(live());
5762
4400
  return {
@@ -5778,15 +4416,6 @@ async function createStore(ctx, opts = {}) {
5778
4416
  async cancelPair() {
5779
4417
  await cancelPair(live());
5780
4418
  },
5781
- async markRead(ids) {
5782
- const c = live();
5783
- let acked = 0;
5784
- for (let i = 0; i < ids.length; i += 100) {
5785
- const res = await c["owner.ack"]({ ids: ids.slice(i, i + 100) });
5786
- acked += res.acked;
5787
- }
5788
- if (acked > 0) set({ unread: Math.max(0, state.unread - acked) });
5789
- },
5790
4419
  async revokeDevice(deviceId) {
5791
4420
  await live()["devices.revoke"]({ device: deviceId });
5792
4421
  await pollRelay(live());