@conveno/cli 0.2.0-rc.12 → 0.2.0-rc.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  import { Box, Text, render, useApp, useInput, useStdin, useStdout } from "ink";
2
2
  import { n as connectOpts, t as adapterEnv } from "./ctx-tYftvhz_.js";
3
- import { t as daemonProblem } from "./daemonError-0KnkgIRo.js";
3
+ import { C as saveChoice, D as warmAcpAdapters, E as unifiedDiff, F as openInBrowser, N as stopDaemonIfRunning, O as PAIR_TIMEOUT_MS, S as connectedTools, T as applyChanges, _ as readWorkerAccess, a as applyOptions, c as collectPlans, d as refreshManifest, f as renewedApprovals, g as UNANSWERED_TEXT, h as ACCESS_TEXT, j as replaceStaleDaemon, l as detectAll, n as inspect, o as approvalWrites, r as partState, s as approvedBySetup, t as runUninstall, u as pendingOptions, v as saveWorkerAccess, w as StaleError, x as chosenTools, y as waitText, z as showCode$1 } from "./uninstall-CQoGVhp3.js";
4
+ import { t as daemonProblem } from "./daemonError-CUE_dVn-.js";
4
5
  import { a as fail, n as cmd, s as plainError, u as tilde } from "./fmt-C2SsP5Y0.js";
5
6
  import { createContext, useContext, useEffect, useImperativeHandle, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
6
- import { Bt as requestDeviceCode, It as readSettings, J as fetchAccountStatus, Lt as readSpawnRecord, M as compatStatus, Mt as readAccountTokens, N as completeLogin, Ot as planSpawn, R as dataPaths, Rt as realSpawnDeps, Xt as spawnRecordPath, Y as findOnPath, Zt as spawnSession, ft as logoutAccount, kt as pollDeviceCode, n as AccountError, un as writeSettings, wn as SESSION_NAME_PATTERN } from "./dist-CRj_cuHc.js";
7
- import { A as showCode$1, E as openInBrowser, T as stopDaemonIfRunning, _ as saveChoice, a as applyOptions, b as unifiedDiff, c as collectPlans, d as refreshManifest, f as renewedApprovals, g as connectedTools, h as chosenTools, l as detectAll, n as inspect, o as approvalWrites, r as partState, s as approvedBySetup, t as runUninstall, u as pendingOptions, v as StaleError, x as PAIR_TIMEOUT_MS, y as applyChanges } from "./uninstall-MaS5t1CK.js";
7
+ import { Bt as readAccountTokens, F as compatStatus, Gt as readSettings, I as completeLogin, It as planSpawn, Kt as readSpawnRecord, Ln as SESSION_NAME_PATTERN, Lt as pollDeviceCode, Q as findOnPath, Sn as writeSettings, U as defaultProcessIo, V as dataPaths, Wt as readProcessList, Yt as requestDeviceCode, Z as fetchAccountStatus, an as spawnRecordPath, h as WORKER_UNANSWERED, m as WORKER_ASK_TIMEOUT_CHOICES, n as AccountError, on as spawnSession, p as WORKER_ACCESS, qt as realSpawnDeps, yt as logoutAccount } from "./dist-1k5b8UGF.js";
8
8
  import { i as tokens, n as detectColorLevel, r as detectUnicode } from "./dist-BRjg9CLd.js";
9
9
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
10
  import { readFileSync, statSync, writeFileSync } from "node:fs";
@@ -12,7 +12,7 @@ import { Readable } from "node:stream";
12
12
  import { basename, posix, win32 } from "node:path";
13
13
  import { spawn } from "node:child_process";
14
14
  import { homedir } from "node:os";
15
- import { r as stopRequestPath, t as killProcessTree } from "./dist-4iJnF07i.js";
15
+ import { r as stopRequestPath, t as killProcessTree } from "./dist-BiV6HopA.js";
16
16
  // src/tui/home/deps.ts
17
17
  /**
18
18
  * What home does outside the store: sign in and out, and take Conveno away. Real in the app, fake
@@ -1158,6 +1158,8 @@ const TOOL_NAMES$1 = {
1158
1158
  };
1159
1159
  /** "Claude Code" for `claude`. An unknown id shows as it is. */
1160
1160
  const toolName$1 = (cli) => TOOL_NAMES$1[cli] ?? cli;
1161
+ /** The tool a session runs in: "Antigravity app" for the desktop app, else `toolName`. */
1162
+ const sessionTool = (s) => s.variant === "app" && s.cli === "antigravity" ? "Antigravity app" : toolName$1(s.cli);
1161
1163
  /** The session's own name without the computer it runs on (`laptop:api-fix` is `api-fix`). */
1162
1164
  function shortName(name) {
1163
1165
  const i = name.indexOf(":");
@@ -1168,9 +1170,137 @@ function shortName(name) {
1168
1170
  * the same tool (`Codex (api-fix)`).
1169
1171
  */
1170
1172
  function sessionLabel(s, all) {
1171
- const tool = toolName$1(s.cli);
1173
+ const tool = sessionTool(s);
1172
1174
  return all.some((o) => o.id !== s.id && o.cli === s.cli) ? `${tool} (${shortName(s.name)})` : tool;
1173
1175
  }
1176
+ // src/tui/home/access.tsx
1177
+ /** "Worker access": what background workers may do, how long a question waits, and what then. */
1178
+ /** One question: a list that starts on `current`, tracks its own focus, and answers on enter. */
1179
+ function Pick({ items, current, onPick }) {
1180
+ const [value, setValue] = useState(current);
1181
+ const [focus, setFocus] = useState(Math.max(0, items.findIndex((i) => i.id === current)));
1182
+ const known = (v) => items.find((i) => i.id === v)?.id ?? value;
1183
+ return /* @__PURE__ */ jsx(Choices, {
1184
+ items,
1185
+ value: [value],
1186
+ onChange: (v) => setValue(known(v[0])),
1187
+ onSubmit: (v) => onPick(known(v[0])),
1188
+ focusIndex: focus,
1189
+ onFocusChange: setFocus
1190
+ });
1191
+ }
1192
+ const KEYS = [
1193
+ {
1194
+ k: "↑↓",
1195
+ label: "move"
1196
+ },
1197
+ {
1198
+ k: "enter",
1199
+ label: "choose"
1200
+ },
1201
+ {
1202
+ k: "esc",
1203
+ label: "back"
1204
+ }
1205
+ ];
1206
+ function WorkerAccessScreen({ actions, onBack, onSaved, onFailed }) {
1207
+ const k = useKit();
1208
+ const [phase, setPhase] = useState("access");
1209
+ const [access, setAccess] = useState("edit");
1210
+ const [waitSec, setWaitSec] = useState(120);
1211
+ const [unanswered, setUnanswered] = useState("deny");
1212
+ const [loaded, setLoaded] = useState(false);
1213
+ useEffect(() => {
1214
+ let live = true;
1215
+ actions.getWorkerAccess().then((c) => {
1216
+ if (!live) return;
1217
+ setAccess(c.access);
1218
+ setWaitSec(c.waitSec);
1219
+ setUnanswered(c.unanswered);
1220
+ }).catch(() => void 0).finally(() => {
1221
+ if (live) setLoaded(true);
1222
+ });
1223
+ return () => {
1224
+ live = false;
1225
+ };
1226
+ }, [actions]);
1227
+ useInput((_input, key) => {
1228
+ if (!key.escape) return;
1229
+ if (phase === "unanswered") setPhase("wait");
1230
+ else if (phase === "wait") setPhase("access");
1231
+ else onBack();
1232
+ });
1233
+ const save = (choice) => {
1234
+ actions.setWorkerAccess(choice).then(() => onSaved(choice), onFailed);
1235
+ };
1236
+ if (!loaded) return /* @__PURE__ */ jsx(Frame, {
1237
+ keys: [{
1238
+ k: "esc",
1239
+ label: "back"
1240
+ }],
1241
+ children: /* @__PURE__ */ jsx(Text, {
1242
+ ...k.quiet,
1243
+ children: "Reading your choice…"
1244
+ })
1245
+ });
1246
+ if (phase === "access") return /* @__PURE__ */ jsx(Frame, {
1247
+ title: "What may background workers do?",
1248
+ keys: KEYS,
1249
+ children: /* @__PURE__ */ jsx(Pick, {
1250
+ items: WORKER_ACCESS.map((id) => ({
1251
+ id,
1252
+ label: ACCESS_TEXT[id].label,
1253
+ hint: ACCESS_TEXT[id].hint
1254
+ })),
1255
+ current: access,
1256
+ onPick: (next) => {
1257
+ setAccess(next);
1258
+ if (next === "full") save({
1259
+ access: next,
1260
+ unanswered,
1261
+ waitSec
1262
+ });
1263
+ else setPhase("wait");
1264
+ }
1265
+ }, "access")
1266
+ });
1267
+ if (phase === "wait") return /* @__PURE__ */ jsx(Frame, {
1268
+ title: "Wait for an answer",
1269
+ subtitle: "Asked requests go to the session that started the worker.",
1270
+ keys: KEYS,
1271
+ children: /* @__PURE__ */ jsx(Pick, {
1272
+ items: WORKER_ASK_TIMEOUT_CHOICES.map((sec) => ({
1273
+ id: String(sec),
1274
+ label: waitText(sec)
1275
+ })),
1276
+ current: String(waitSec),
1277
+ onPick: (id) => {
1278
+ setWaitSec(WORKER_ASK_TIMEOUT_CHOICES.find((s) => String(s) === id) ?? waitSec);
1279
+ setPhase("unanswered");
1280
+ }
1281
+ }, "wait")
1282
+ });
1283
+ return /* @__PURE__ */ jsx(Frame, {
1284
+ title: `If nobody answers in ${waitText(waitSec)}`,
1285
+ keys: KEYS,
1286
+ children: /* @__PURE__ */ jsx(Pick, {
1287
+ items: WORKER_UNANSWERED.map((id) => ({
1288
+ id,
1289
+ label: UNANSWERED_TEXT[id].label,
1290
+ hint: UNANSWERED_TEXT[id].hint
1291
+ })),
1292
+ current: unanswered,
1293
+ onPick: (next) => {
1294
+ setUnanswered(next);
1295
+ save({
1296
+ access,
1297
+ unanswered: next,
1298
+ waitSec
1299
+ });
1300
+ }
1301
+ }, "unanswered")
1302
+ });
1303
+ }
1174
1304
  // src/tui/home/hooks.ts
1175
1305
  /** The store's state, re-read whenever it changes. */
1176
1306
  function useStoreState(store) {
@@ -1554,7 +1684,7 @@ function Card({ session, lead, selected, width, onSelect }) {
1554
1684
  }) : /* @__PURE__ */ jsx(Text, { children: " " }), /* @__PURE__ */ jsx(Text, {
1555
1685
  ...strong(k),
1556
1686
  ...k.ink,
1557
- children: cut(toolName$1(session.cli), inner - 2, k.ascii)
1687
+ children: cut(sessionTool(session), inner - 2, k.ascii)
1558
1688
  })]
1559
1689
  }),
1560
1690
  /* @__PURE__ */ jsx(Text, {
@@ -2120,10 +2250,18 @@ const MENU_ITEMS = [
2120
2250
  id: "rename",
2121
2251
  label: "Rename"
2122
2252
  },
2253
+ {
2254
+ id: "remove",
2255
+ label: "Remove this session"
2256
+ },
2123
2257
  {
2124
2258
  id: "setup",
2125
2259
  label: "Set up tools"
2126
2260
  },
2261
+ {
2262
+ id: "workers",
2263
+ label: "Worker access"
2264
+ },
2127
2265
  {
2128
2266
  id: "computers",
2129
2267
  label: "Other computers"
@@ -2256,6 +2394,7 @@ function Help({ onClose }) {
2256
2394
  ["m or enter", "send a message to the one you picked"],
2257
2395
  ["l", "put it in charge"],
2258
2396
  ["r", "rename it"],
2397
+ ["x", "take it off the list"],
2259
2398
  ["f", "fix a tool that needs it"],
2260
2399
  ["ctrl+p or /", "the menu"],
2261
2400
  ["?", "this list"],
@@ -2452,12 +2591,25 @@ function Home({ store, deps, size, onSetup, onQuit }) {
2452
2591
  say(reasonOf(e, "That did not send."), "error");
2453
2592
  }
2454
2593
  };
2455
- const makeLead = async () => {
2594
+ const startLead = () => {
2456
2595
  const who = target();
2457
2596
  if (!who) return;
2458
2597
  const label = sessionLabel(who, state.sessions);
2459
- if (who.isOrchestrator) return say(`${label} is already in charge.`, "info");
2460
- if (who.remote) return say("That one's on another computer. Pick one here.", "warn");
2598
+ if (who.isOrchestrator) {
2599
+ say(`${label} is already in charge.`, "info");
2600
+ return;
2601
+ }
2602
+ if (who.remote) {
2603
+ say("That one's on another computer. Pick one here.", "warn");
2604
+ return;
2605
+ }
2606
+ setMode("lead");
2607
+ };
2608
+ const makeLead = async () => {
2609
+ const who = sel;
2610
+ setMode("board");
2611
+ if (!who) return;
2612
+ const label = sessionLabel(who, state.sessions);
2461
2613
  try {
2462
2614
  await actions.setLead(who.id);
2463
2615
  say(`${label} is in charge now.`);
@@ -2491,6 +2643,26 @@ function Home({ store, deps, size, onSetup, onQuit }) {
2491
2643
  say(reasonOf(e), "error");
2492
2644
  }
2493
2645
  };
2646
+ const startRemove = () => {
2647
+ const who = target();
2648
+ if (!who) return;
2649
+ if (who.remote) {
2650
+ say("That one's on another computer. Remove it there.", "warn");
2651
+ return;
2652
+ }
2653
+ setMode("remove");
2654
+ };
2655
+ const remove = async () => {
2656
+ const who = sel;
2657
+ setMode("board");
2658
+ if (!who) return;
2659
+ try {
2660
+ await actions.remove(who.id);
2661
+ say(`Removed ${who.name}.`);
2662
+ } catch (e) {
2663
+ say(reasonOf(e, "That did not work."), "error");
2664
+ }
2665
+ };
2494
2666
  const startFix = () => {
2495
2667
  if (problems.length === 0) {
2496
2668
  say("Everything is in order.", "info");
@@ -2502,10 +2674,11 @@ function Home({ store, deps, size, onSetup, onQuit }) {
2502
2674
  const pick = (id) => {
2503
2675
  setMode("board");
2504
2676
  if (id === "send") startMessage();
2505
- else if (id === "lead") makeLead();
2677
+ else if (id === "lead") startLead();
2506
2678
  else if (id === "rename") startRename();
2679
+ else if (id === "remove") startRemove();
2507
2680
  else if (id === "setup") onSetup();
2508
- else if (id === "computers" || id === "account" || id === "uninstall") setMode(id);
2681
+ else if (id === "computers" || id === "account" || id === "uninstall" || id === "workers") setMode(id);
2509
2682
  else if (id === "quit") onQuit();
2510
2683
  };
2511
2684
  const move = (to) => {
@@ -2529,13 +2702,22 @@ function Home({ store, deps, size, onSetup, onQuit }) {
2529
2702
  return lead && first ? setSelId(first.id) : void 0;
2530
2703
  }
2531
2704
  if (key.return || input === "m") return startMessage();
2532
- if (input === "l") return void makeLead();
2705
+ if (input === "l") return startLead();
2533
2706
  if (input === "r") return startRename();
2707
+ if (input === "x") return startRemove();
2534
2708
  if (input === "f") return startFix();
2535
2709
  if (input === "/") return setMode("menu");
2536
2710
  if (input === "?") return setMode("help");
2537
2711
  if (input === "q") return onQuit();
2538
2712
  }, { isActive: mode === "board" });
2713
+ useInput((input, key) => {
2714
+ if (input === "y" || input === "Y") remove();
2715
+ else if (input === "n" || input === "N" || key.escape || key.return) setMode("board");
2716
+ }, { isActive: mode === "remove" });
2717
+ useInput((input, key) => {
2718
+ if (input === "y" || input === "Y") makeLead();
2719
+ else if (input === "n" || input === "N" || key.escape || key.return) setMode("board");
2720
+ }, { isActive: mode === "lead" });
2539
2721
  useWheel(boardRef, (d) => move(selIdx + d), { isActive: mode === "board" });
2540
2722
  const back = () => setMode("board");
2541
2723
  if (mode === "menu") return /* @__PURE__ */ jsx(Menu, {
@@ -2553,6 +2735,18 @@ function Home({ store, deps, size, onSetup, onQuit }) {
2553
2735
  deps,
2554
2736
  onBack: back
2555
2737
  });
2738
+ if (mode === "workers") return /* @__PURE__ */ jsx(WorkerAccessScreen, {
2739
+ actions,
2740
+ onBack: back,
2741
+ onSaved: (c) => {
2742
+ back();
2743
+ say(`Workers now get ${c.access} access.`);
2744
+ },
2745
+ onFailed: (e) => {
2746
+ back();
2747
+ say(reasonOf(e, "That did not save."), "error");
2748
+ }
2749
+ });
2556
2750
  if (mode === "fix") return /* @__PURE__ */ jsx(FixScreen, {
2557
2751
  problems: fixing,
2558
2752
  actions,
@@ -2578,7 +2772,8 @@ function Home({ store, deps, size, onSetup, onQuit }) {
2578
2772
  const hint = !lead && !empty;
2579
2773
  const entries = state.activity;
2580
2774
  let act = Math.min(ACTIVITY_LINES, Math.max(1, entries.length));
2581
- const fixed = 2 + (problems.length > 0 ? 2 : 0) + 1 + (typing ? 1 : 0) + 1 + 1 + (hint ? 1 : 0);
2775
+ const asking = mode === "remove" || mode === "lead";
2776
+ const fixed = 2 + (problems.length > 0 ? 2 : 0) + 1 + (typing || asking ? 1 : 0) + 1 + 1 + (hint ? 1 : 0);
2582
2777
  const need = lead && modeFor(columns) === "compact" ? 11 : 5;
2583
2778
  while (act > 1 && rows - fixed - act < need) act -= 1;
2584
2779
  const budget = Math.max(5, rows - fixed - act);
@@ -2637,6 +2832,10 @@ function Home({ store, deps, size, onSetup, onQuit }) {
2637
2832
  k: "r",
2638
2833
  label: "rename"
2639
2834
  },
2835
+ {
2836
+ k: "x",
2837
+ label: "remove"
2838
+ },
2640
2839
  ...problems.length > 0 ? [{
2641
2840
  k: "f",
2642
2841
  label: "fix"
@@ -2723,6 +2922,16 @@ function Home({ store, deps, size, onSetup, onQuit }) {
2723
2922
  })
2724
2923
  ]
2725
2924
  }),
2925
+ mode === "remove" && sel ? /* @__PURE__ */ jsx(Text, {
2926
+ wrap: "truncate",
2927
+ ...tint(k.c.warn),
2928
+ children: cut(`Remove ${sel.name} from the list? Its unread messages go too. y/n`, width, k.ascii)
2929
+ }) : null,
2930
+ mode === "lead" && sel ? /* @__PURE__ */ jsx(Text, {
2931
+ wrap: "truncate",
2932
+ ...tint(k.c.warn),
2933
+ children: cut(`Make ${sessionLabel(sel, state.sessions)} the lead? y/n`, width, k.ascii)
2934
+ }) : null,
2726
2935
  typing && sel ? /* @__PURE__ */ jsxs(Box, { children: [
2727
2936
  /* @__PURE__ */ jsx(Text, {
2728
2937
  wrap: "truncate",
@@ -3880,6 +4089,7 @@ async function changeTool(ctx, cli, fixId, failed, io) {
3880
4089
  for (const p of done.problems) io.line(p);
3881
4090
  return {
3882
4091
  ok: true,
4092
+ changed: files.length > 0,
3883
4093
  ...files.length === 0 ? { note: "already connected" } : {},
3884
4094
  ...done.approved === void 0 ? {} : { approved: done.approved }
3885
4095
  };
@@ -3904,23 +4114,56 @@ const PROCESS_NAMES = {
3904
4114
  antigravity: "agy",
3905
4115
  grok: "grok"
3906
4116
  };
3907
- /** Names of the programs running now, lowercase, without folders or `.exe`. */
3908
- async function runningNames(ctx) {
4117
+ /** Words in a command line that mark a background server, helper or protocol process, not a window. */
4118
+ const SERVER_ARGS = /(?:^|\s)(?:app-server|serve|daemon|mcp|acp|--managed-daemon|--service)(?=\s|$)/i;
4119
+ /**
4120
+ * The program name and the rest of a command line: `"C:\Program Files\x\codex.exe" app-server`
4121
+ * gives { name: "codex", args: "app-server" }. Lowercase, without folders or `.exe`.
4122
+ */
4123
+ function splitCommand(command) {
4124
+ const line = command.trim();
4125
+ let exe;
4126
+ let rest;
4127
+ const quoted = /^"([^"]*)"\s*(.*)$/.exec(line);
4128
+ if (quoted) {
4129
+ exe = quoted[1] ?? "";
4130
+ rest = quoted[2] ?? "";
4131
+ } else {
4132
+ const m = /^(.*?\.exe)(?:\s+(.*))?$/i.exec(line) ?? /^(\S+)(?:\s+(.*))?$/.exec(line);
4133
+ exe = m?.[1] ?? "";
4134
+ rest = m?.[2] ?? "";
4135
+ }
4136
+ const name = basename(exe.replaceAll("\\", "/")).replace(/\.exe$/i, "").toLowerCase();
4137
+ return name === "" ? void 0 : {
4138
+ name,
4139
+ args: rest
4140
+ };
4141
+ }
4142
+ /**
4143
+ * Which of `clis` have a window-like process running: a process of that name whose command line
4144
+ * is not a server, daemon, helper or protocol process (`codex app-server --managed-daemon`,
4145
+ * `opencode serve --service`). Those outlive every window, so they say nothing about whether the
4146
+ * tool is open.
4147
+ */
4148
+ function openTools(processes, clis) {
4149
+ const open = /* @__PURE__ */ new Set();
4150
+ for (const p of processes) {
4151
+ if (p.command === void 0) continue;
4152
+ const parts = splitCommand(p.command);
4153
+ if (parts && !SERVER_ARGS.test(parts.args)) open.add(parts.name);
4154
+ }
4155
+ return clis.filter((c) => open.has(PROCESS_NAMES[c]));
4156
+ }
4157
+ async function runningTools(ctx, clis) {
3909
4158
  try {
3910
- const win = ctx.platform === "win32";
3911
- const r = await (win ? ctx.exec("tasklist", [
3912
- "/FO",
3913
- "CSV",
3914
- "/NH"
3915
- ]) : ctx.exec("ps", [
3916
- "-A",
3917
- "-o",
3918
- "comm="
3919
- ]));
3920
- if (r.code !== 0) return /* @__PURE__ */ new Set();
3921
- return new Set(r.stdout.split(/\r?\n/).map((l) => win ? (l.split("\",\"")[0] ?? "").replace(/^"/, "") : l.trim()).filter(Boolean).map((n) => basename(n.replaceAll("\\", "/")).replace(/\.exe$/i, "").toLowerCase()));
4159
+ const io = ctx.processIo ?? {
4160
+ ...defaultProcessIo,
4161
+ platform: ctx.platform
4162
+ };
4163
+ const list = await readProcessList(io);
4164
+ return list ? openTools(list, clis) : [];
3922
4165
  } catch {
3923
- return /* @__PURE__ */ new Set();
4166
+ return [];
3924
4167
  }
3925
4168
  }
3926
4169
  const SIGN_IN_FAILED = "Couldn't sign you in. You can try again any time with conveno login.";
@@ -3936,6 +4179,10 @@ function createOnboardingDeps(ctx) {
3936
4179
  saveChoice: async (tools, lead) => {
3937
4180
  saveChoice(ctx, tools, lead);
3938
4181
  },
4182
+ workerAccess: async () => readWorkerAccess(ctx).access,
4183
+ saveWorkerAccess: async (access) => {
4184
+ saveWorkerAccess(ctx, { access });
4185
+ },
3939
4186
  signedIn: async () => await readAccountTokens(tokenFile(ctx)).catch(() => null) !== null,
3940
4187
  signIn: async ({ signal, onCode }) => {
3941
4188
  const io = accountIo(ctx);
@@ -3968,8 +4215,13 @@ function createOnboardingDeps(ctx) {
3968
4215
  }
3969
4216
  },
3970
4217
  running: async (clis) => {
3971
- const names = await runningNames(ctx);
3972
- return clis.filter((c) => names.has(PROCESS_NAMES[c]));
4218
+ return runningTools(ctx, clis);
4219
+ },
4220
+ prepareWorkers: async (clis, io) => {
4221
+ return (await warmAcpAdapters(ctx, clis, {
4222
+ onStart: io.start,
4223
+ onLine: io.line
4224
+ }).catch(() => void 0))?.status === "ready";
3973
4225
  }
3974
4226
  };
3975
4227
  }
@@ -3980,6 +4232,7 @@ const initialState = (start) => ({
3980
4232
  tools: null,
3981
4233
  signedIn: false,
3982
4234
  picked: [],
4235
+ access: "edit",
3983
4236
  dropped: [],
3984
4237
  questions: [],
3985
4238
  qIndex: 0,
@@ -4083,8 +4336,21 @@ function buildRows(s) {
4083
4336
  });
4084
4337
  return rows;
4085
4338
  }
4086
- /** Leave the questions: set up the rows, or send the person back when nothing is left to do. */
4339
+ /** Leave the questions: ask what workers may do, or send the person back when nothing is left. */
4087
4340
  function startWorking(s) {
4341
+ if (buildRows(s).length === 0) return {
4342
+ ...s,
4343
+ step: "tools",
4344
+ notice: "Pick a tool to go on."
4345
+ };
4346
+ const { notice: _n, ...rest } = s;
4347
+ return {
4348
+ ...rest,
4349
+ step: "access"
4350
+ };
4351
+ }
4352
+ /** Set up the rows. */
4353
+ function runRows(s) {
4088
4354
  const active = activeTools(s);
4089
4355
  const lead = s.lead && active.some((t) => t.cli === s.lead) ? s.lead : s.lead && active[0]?.cli;
4090
4356
  const next = {
@@ -4150,9 +4416,14 @@ function reduce(s, a) {
4150
4416
  ...s,
4151
4417
  tools: a.tools,
4152
4418
  signedIn: a.signedIn,
4153
- picked: a.chosen.filter((c) => known.has(c))
4419
+ picked: a.chosen.filter((c) => known.has(c)),
4420
+ ...a.access ? { access: a.access } : {}
4154
4421
  };
4155
4422
  }
4423
+ case "chooseAccess": return s.step === "access" ? runRows({
4424
+ ...s,
4425
+ access: a.access
4426
+ }) : s;
4156
4427
  case "begin": return s.step === "welcome" && s.tools ? {
4157
4428
  ...s,
4158
4429
  step: "tools"
@@ -4241,6 +4512,15 @@ function reduce(s, a) {
4241
4512
  ...rest,
4242
4513
  step: "tools"
4243
4514
  };
4515
+ case "access":
4516
+ if (s.questions.length > 0) return toQuestionsAt(rest, s.questions.length - 1);
4517
+ return activeTools(rest).length >= 2 ? {
4518
+ ...rest,
4519
+ step: "lead"
4520
+ } : {
4521
+ ...rest,
4522
+ step: "tools"
4523
+ };
4244
4524
  default: return s;
4245
4525
  }
4246
4526
  }
@@ -4276,6 +4556,7 @@ function reduce(s, a) {
4276
4556
  return {
4277
4557
  ...rest,
4278
4558
  ...a.result.approved === void 0 ? {} : { approved: a.result.approved },
4559
+ ...a.result.changed === void 0 ? {} : { changed: a.result.changed },
4279
4560
  state: "done",
4280
4561
  note: a.result.note ?? (r.kind === "remove" ? "removed" : r.installedNow ? "installed and connected" : "connected")
4281
4562
  };
@@ -4362,6 +4643,27 @@ function reduce(s, a) {
4362
4643
  ...s,
4363
4644
  runningTools: a.clis
4364
4645
  };
4646
+ case "workersStart": return {
4647
+ ...s,
4648
+ workers: {
4649
+ state: "working",
4650
+ log: []
4651
+ }
4652
+ };
4653
+ case "workersLine": return s.workers ? {
4654
+ ...s,
4655
+ workers: {
4656
+ ...s.workers,
4657
+ log: [...s.workers.log, a.line]
4658
+ }
4659
+ } : s;
4660
+ case "workersDone": return s.workers ? {
4661
+ ...s,
4662
+ workers: {
4663
+ ...s.workers,
4664
+ state: a.ready ? "done" : "skipped"
4665
+ }
4666
+ } : s;
4365
4667
  }
4366
4668
  }
4367
4669
  /** Show question `index` again, forgetting the answers from there on. */
@@ -4577,6 +4879,45 @@ function LeadStep({ s, dispatch }) {
4577
4879
  })
4578
4880
  });
4579
4881
  }
4882
+ function AccessStep({ s, dispatch }) {
4883
+ const [pick, setPick] = useState([s.access]);
4884
+ const [focus, setFocus] = useState(WORKER_ACCESS.indexOf(s.access));
4885
+ return /* @__PURE__ */ jsx(Frame, {
4886
+ title: "What may background workers do?",
4887
+ subtitle: "Workers are sessions Conveno starts for you. You can change this later.",
4888
+ keys: [
4889
+ {
4890
+ k: "↑↓",
4891
+ label: "move"
4892
+ },
4893
+ {
4894
+ k: "enter",
4895
+ label: "choose"
4896
+ },
4897
+ {
4898
+ k: "esc",
4899
+ label: "back"
4900
+ }
4901
+ ],
4902
+ children: /* @__PURE__ */ jsx(Choices, {
4903
+ items: WORKER_ACCESS.map((id) => ({
4904
+ id,
4905
+ label: ACCESS_TEXT[id].label,
4906
+ hint: ACCESS_TEXT[id].hint
4907
+ })),
4908
+ value: pick,
4909
+ onChange: setPick,
4910
+ onSubmit: (ids) => {
4911
+ dispatch({
4912
+ type: "chooseAccess",
4913
+ access: WORKER_ACCESS.find((a) => a === (ids[0] ?? s.access)) ?? s.access
4914
+ });
4915
+ },
4916
+ focusIndex: focus,
4917
+ onFocusChange: setFocus
4918
+ })
4919
+ });
4920
+ }
4580
4921
  function QuestionStep({ s, dispatch }) {
4581
4922
  const q = s.questions[s.qIndex];
4582
4923
  const [choice, setChoice] = useState(q?.defaultYes ? "yes" : "no");
@@ -4631,10 +4972,12 @@ function detailLines(rows, width, ascii) {
4631
4972
  }
4632
4973
  return out;
4633
4974
  }
4634
- function DetailsPanel({ rows }) {
4975
+ function DetailsPanel({ rows, workers }) {
4635
4976
  const { ascii, c } = useTheme();
4636
4977
  const width = useFrameWidth();
4637
- const lines = detailLines(rows, Math.max(10, width - 4), ascii);
4978
+ const inner = Math.max(10, width - 4);
4979
+ const lines = detailLines(rows, inner, ascii);
4980
+ if (workers.length > 0) lines.push("Getting workers ready", ...workers.map((l) => ` ${cut(l, inner - 2, ascii)}`));
4638
4981
  return /* @__PURE__ */ jsx(Panel, {
4639
4982
  title: "Details",
4640
4983
  width,
@@ -4679,11 +5022,20 @@ function WorkingStep({ s }) {
4679
5022
  state: r.state,
4680
5023
  ...r.note ? { note: w(r.note) } : {}
4681
5024
  })) }),
5025
+ s.workers ? /* @__PURE__ */ jsx(Steps, { rows: [{
5026
+ id: "workers",
5027
+ label: "Getting workers ready",
5028
+ state: s.workers.state,
5029
+ ...s.workers.state === "done" ? { note: "ready" } : s.workers.state === "skipped" ? { note: "they will download on first use" } : {}
5030
+ }] }) : null,
4682
5031
  failed.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Gap, {}), failed.map((r) => /* @__PURE__ */ jsx(Line, {
4683
5032
  tone: "error",
4684
5033
  children: r.reason ?? "Something went wrong."
4685
5034
  }, r.cli))] }) : null,
4686
- s.showDetails ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Gap, {}), /* @__PURE__ */ jsx(DetailsPanel, { rows: s.rows })] }) : null
5035
+ s.showDetails ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Gap, {}), /* @__PURE__ */ jsx(DetailsPanel, {
5036
+ rows: s.rows,
5037
+ workers: s.workers?.log ?? []
5038
+ })] }) : null
4687
5039
  ]
4688
5040
  });
4689
5041
  }
@@ -4750,7 +5102,7 @@ function firstRunApprovals(s) {
4750
5102
  });
4751
5103
  }
4752
5104
  function FinishStep({ s }) {
4753
- const open = connectedRows(s).filter((r) => s.runningTools.includes(r.cli));
5105
+ const open = connectedRows(s).filter((r) => r.changed !== false && s.runningTools.includes(r.cli));
4754
5106
  const any = connectedRows(s).length > 0;
4755
5107
  const approvals = firstRunApprovals(s);
4756
5108
  return /* @__PURE__ */ jsxs(Frame, {
@@ -4807,13 +5159,15 @@ function Onboarding({ deps, start, onDone }) {
4807
5159
  Promise.all([
4808
5160
  d.detect(),
4809
5161
  d.signedIn().catch(() => false),
4810
- d.chosen().catch(() => [])
4811
- ]).then(([tools, signedIn, chosen]) => {
5162
+ d.chosen().catch(() => []),
5163
+ d.workerAccess().catch(() => void 0)
5164
+ ]).then(([tools, signedIn, chosen, access]) => {
4812
5165
  if (live.current) dispatch({
4813
5166
  type: "loaded",
4814
5167
  tools,
4815
5168
  signedIn,
4816
- chosen
5169
+ chosen,
5170
+ ...access ? { access } : {}
4817
5171
  });
4818
5172
  });
4819
5173
  }, []);
@@ -4821,6 +5175,7 @@ function Onboarding({ deps, start, onDone }) {
4821
5175
  if (s.step !== "account" && s.step !== "finish") return;
4822
5176
  if (led.current) return;
4823
5177
  led.current = true;
5178
+ depsRef.current.saveWorkerAccess(s.access).catch(() => {});
4824
5179
  const tools = connectedRows(s).map((r) => r.cli);
4825
5180
  if (tools.length === 0) return;
4826
5181
  const lead = s.lead && tools.includes(s.lead) ? s.lead : void 0;
@@ -4897,6 +5252,25 @@ function Onboarding({ deps, start, onDone }) {
4897
5252
  }
4898
5253
  })();
4899
5254
  }, [s.step, s.rows]);
5255
+ const warmed = useRef(false);
5256
+ useEffect(() => {
5257
+ if (s.step !== "working" || warmed.current) return;
5258
+ warmed.current = true;
5259
+ const clis = s.rows.filter((r) => r.kind === "setup" && r.state !== "skipped").map((r) => r.cli);
5260
+ if (clis.length === 0) return;
5261
+ depsRef.current.prepareWorkers(clis, {
5262
+ start: () => live.current && dispatch({ type: "workersStart" }),
5263
+ line: (line) => live.current && dispatch({
5264
+ type: "workersLine",
5265
+ line
5266
+ })
5267
+ }).catch(() => false).then((ready) => {
5268
+ if (live.current) dispatch({
5269
+ type: "workersDone",
5270
+ ready
5271
+ });
5272
+ });
5273
+ }, [s.step, s.rows]);
4900
5274
  useEffect(() => {
4901
5275
  if (s.step !== "finish") return;
4902
5276
  const clis = connectedRows(s).map((r) => r.cli);
@@ -4943,7 +5317,8 @@ function Onboarding({ deps, start, onDone }) {
4943
5317
  "tools",
4944
5318
  "remove",
4945
5319
  "lead",
4946
- "question"
5320
+ "question",
5321
+ "access"
4947
5322
  ].includes(s.step)) dispatch({ type: "back" });
4948
5323
  return;
4949
5324
  }
@@ -4989,6 +5364,10 @@ function OnboardingView({ s, dispatch, signIn }) {
4989
5364
  s,
4990
5365
  dispatch
4991
5366
  });
5367
+ case "access": return /* @__PURE__ */ jsx(AccessStep, {
5368
+ s,
5369
+ dispatch
5370
+ });
4992
5371
  case "working": return /* @__PURE__ */ jsx(WorkingStep, { s });
4993
5372
  case "account": return /* @__PURE__ */ jsx(AccountStep, {
4994
5373
  s,
@@ -5391,7 +5770,10 @@ async function createStore(ctx, opts = {}) {
5391
5770
  });
5392
5771
  },
5393
5772
  async setLead(sessionId) {
5394
- await live()["orchestrator.claim"]({ sessionId });
5773
+ await live()["orchestrator.claim"]({
5774
+ sessionId,
5775
+ via: "home"
5776
+ });
5395
5777
  set({ sessions: state.sessions.map((s) => ({
5396
5778
  ...s,
5397
5779
  isOrchestrator: s.id === sessionId
@@ -5423,6 +5805,10 @@ async function createStore(ctx, opts = {}) {
5423
5805
  });
5424
5806
  set({ sessions: upsert(state.sessions, res.session) });
5425
5807
  },
5808
+ async remove(sessionId) {
5809
+ await live()["session.remove"]({ sessionId });
5810
+ set({ sessions: state.sessions.filter((s) => s.id !== sessionId) });
5811
+ },
5426
5812
  async spawn(p) {
5427
5813
  const c = live();
5428
5814
  const runner = ctx.spawnRunner ?? [process.execPath, process.argv[1] ?? "conveno"];
@@ -5481,6 +5867,12 @@ async function createStore(ctx, opts = {}) {
5481
5867
  await live()["devices.revoke"]({ device: deviceId });
5482
5868
  await pollRelay(live());
5483
5869
  },
5870
+ async getWorkerAccess() {
5871
+ return readWorkerAccess(ctx);
5872
+ },
5873
+ async setWorkerAccess(choice) {
5874
+ saveWorkerAccess(ctx, choice);
5875
+ },
5484
5876
  async openAccountPage() {
5485
5877
  const base = ctx.env.CONVENO_API_URL || "https://api.conveno.dev";
5486
5878
  openInBrowser(ctx.platform, `${base}/account`);
@@ -5526,6 +5918,7 @@ async function createStore(ctx, opts = {}) {
5526
5918
  /** `start: "setup"` opens the onboarding at the tool list; otherwise it picks onboarding or home. */
5527
5919
  async function runTui(ctx, opts = {}) {
5528
5920
  let first;
5921
+ const restarted = await replaceStaleDaemon(ctx);
5529
5922
  try {
5530
5923
  first = await ctx.connect(connectOpts(ctx, true));
5531
5924
  } catch (e) {
@@ -5576,6 +5969,7 @@ async function runTui(ctx, opts = {}) {
5576
5969
  input.dispose();
5577
5970
  await store.close();
5578
5971
  if (farewell) ctx.out(`${farewell}\n`);
5972
+ if (restarted) ctx.out(`${restarted}\n`);
5579
5973
  }
5580
5974
  }
5581
5975
  export { runTui };