@conveno/cli 0.2.0-rc.6 → 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.
@@ -0,0 +1 @@
1
+ export { i as runHookEntry } from "./hook-entry-BXmSN--S.js";
@@ -1,13 +1,13 @@
1
- import { At as runLaunchFile, Ft as spawnSession, M as dataPaths, St as realSpawnDeps, d as SPAWN_TABLE, f as SpawnError, qt as CLI_KINDS, u as SPAWN_CLIS } from "./dist-BTLBO1Rp.js";
2
- import { S as runLogout, _ as runDevices, a as detectAll, b as runAccount, c as staleFailure, d as listManifests, f as markRestored, i as confirmAndApply, l as StaleError, m as restoreEntry, n as runDoctor, o as reportFailures, p as previewRestore, r as collectPlans, s as runInit, u as applyChanges, v as runRelay, x as runLogin } from "./doctor-DjwXJvKw.js";
3
- import { i as parseFlags, n as COMMAND_NAMES, r as commandHelp, t as COMMANDS } from "./args-D9T-6TDw.js";
1
+ import { Ct as realSpawnDeps, Lt as spawnSession, M as dataPaths, Mt as runLaunchFile, Xt as CLI_KINDS, d as SPAWN_TABLE, f as SpawnError, u as SPAWN_CLIS } from "./dist-D2hMvcZu.js";
2
+ import { C as runLogout, S as runLogin, a as detectAll, c as runInit, d as applyChanges, f as listManifests, h as restoreEntry, i as confirmAndApply, l as staleFailure, m as previewRestore, n as runDoctor, p as markRestored, r as collectPlans, s as reportFailures, u as StaleError, v as runDevices, x as runAccount, y as runRelay } from "./doctor-BYa-MApu.js";
3
+ import { i as parseFlags, n as COMMAND_NAMES, r as commandHelp, t as COMMANDS } from "./args-C7Agak9f.js";
4
4
  import { access, chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
5
5
  import { n as connectOpts, t as adapterEnv } from "./ctx-tYftvhz_.js";
6
- import { t as daemonProblem } from "./daemonError-CdLataBW.js";
6
+ import { t as daemonProblem } from "./daemonError-DNAKEyRT.js";
7
7
  import { a as fail, c as plural, d as warnBlock, l as seconds, n as cmd, o as localStamp, r as columns, s as plainError, t as closest, u as tilde } from "./fmt-C2SsP5Y0.js";
8
8
  import { join, resolve } from "node:path";
9
- import { t as runHook } from "./hook-BGJc4PHG.js";
10
- import { t as findSession } from "./pick-B-18E4Mx.js";
9
+ import { t as runHook } from "./hook-CQeSn-w4.js";
10
+ import { t as findSession } from "./pick-DoyocW55.js";
11
11
  import { readFileSync } from "node:fs";
12
12
  // src/daemon.ts
13
13
  async function lockPid(ctx) {
@@ -185,7 +185,7 @@ async function runDaemon(ctx, argv) {
185
185
  });
186
186
  }
187
187
  // src/version.ts
188
- const VERSION = "0.2.0-rc.6";
188
+ const VERSION = "0.2.0-rc.7";
189
189
  // src/errorLog.ts
190
190
  /** The message of an unexpected error, as it is. Not the softened text `plainError` gives. */
191
191
  function rawMessage(e) {
@@ -893,11 +893,11 @@ async function dispatch(name, rest, ctx) {
893
893
  case "rename": return runRename(ctx, rest);
894
894
  case "lead": return runLead(ctx, rest);
895
895
  case "spawn": return runSpawn(ctx, rest);
896
- case "acp-host": return (await import("./acp-3xehqLdo.js")).runAcpHostCmd(ctx, rest);
897
- case "stop": return (await import("./acp-3xehqLdo.js")).runStop(ctx, rest);
896
+ case "acp-host": return (await import("./acp-9pRRszwU.js")).runAcpHostCmd(ctx, rest);
897
+ case "stop": return (await import("./acp-9pRRszwU.js")).runStop(ctx, rest);
898
898
  case "spawn-run": return runSpawnRun(ctx, rest);
899
- case "sidecar": return (await import("./sidecar-CTKxOMie.js")).runSidecar(ctx, rest);
900
- case "watch": return (await import("./watch-CfYanJvt.js")).runWatch(ctx, rest);
899
+ case "agy-relay": return (await import("./agy-relay-C-nqvieJ.js")).runAgyRelay(ctx, rest);
900
+ case "watch": return (await import("./watch-Dr2RdyGo.js")).runWatch(ctx, rest);
901
901
  case "devices": return runDevices(ctx, rest);
902
902
  case "relay": return runRelay(ctx, rest);
903
903
  case "doctor": return runDoctor(ctx, rest);
@@ -936,7 +936,7 @@ function opensApp(env, tty = {
936
936
  async function main(argv, ctx) {
937
937
  const [command, ...rest] = argv;
938
938
  if (command === void 0 && opensApp(ctx.env)) try {
939
- return await (await import("./run-Yi48fiJN.js")).runTui(ctx);
939
+ return await (await import("./run-B-WfNtCX.js")).runTui(ctx);
940
940
  } catch (e) {
941
941
  ctx.err(`The app could not start (${rawMessage(e)}). Showing the help instead.\n`);
942
942
  ctx.out(helpText(ctx));
@@ -1,4 +1,4 @@
1
- import { on as SessionId } from "./dist-BTLBO1Rp.js";
1
+ import { ln as SessionId } from "./dist-D2hMvcZu.js";
2
2
  // src/pick.ts
3
3
  /** The online session a name or id means, or undefined when nothing matches. */
4
4
  async function findSession(client, text) {
@@ -1,17 +1,17 @@
1
1
  import { Box, Text, render, useApp, useInput, useStdin, useWindowSize } from "ink";
2
2
  import { n as connectOpts, t as adapterEnv } from "./ctx-tYftvhz_.js";
3
- import { t as daemonProblem } from "./daemonError-CdLataBW.js";
3
+ import { t as daemonProblem } from "./daemonError-DNAKEyRT.js";
4
4
  import { a as fail, n as cmd, s as plainError, u as tilde } from "./fmt-C2SsP5Y0.js";
5
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 { E as compatStatus, Ft as spawnSession, H as fetchAccountStatus, Kt as writeSettings, M as dataPaths, Pt as spawnRecordPath, St as realSpawnDeps, bt as readSettings, gt as readAccountTokens, xt as readSpawnRecord } from "./dist-BTLBO1Rp.js";
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 { r as stopRequestPath, t as killProcessTree } from "./dist-BAlMjYqQ.js";
14
- import { g as PAIR_TIMEOUT_MS, h as unifiedDiff, l as StaleError, r as collectPlans, t as inspect, u as applyChanges, y as openInBrowser } from "./doctor-DjwXJvKw.js";
13
+ import { _ as PAIR_TIMEOUT_MS, b as openInBrowser, d as applyChanges, g as unifiedDiff, o as pendingOptions, r as collectPlans, t as inspect, u as StaleError } from "./doctor-BYa-MApu.js";
14
+ import { r as stopRequestPath, t as killProcessTree } from "./dist-DOKVrSIw.js";
15
15
  // \0rolldown/runtime.js
16
16
  var __defProp = Object.defineProperty;
17
17
  var __exportAll = (all, flags) => {
@@ -2752,11 +2752,241 @@ function SidePanel({ session, width }) {
2752
2752
  ]
2753
2753
  });
2754
2754
  }
2755
+ // src/tui/setup-data.ts
2756
+ /**
2757
+ * What the Setup screen reads and does. Same facts as `conveno doctor`, in plain words, and the
2758
+ * same code path as `conveno init` / `conveno uninstall` for changing files.
2759
+ *
2760
+ * No Ink or React in here: the store imports it.
2761
+ */
2762
+ const ready = (r) => r.mcp === "ok" && (r.hooks === null || r.hooks === "ok");
2763
+ /** One CLI's row, from what `conveno doctor` found. Exported for tests. */
2764
+ function checkFromRow(r, compat) {
2765
+ const { adapter, detection } = r;
2766
+ const base = {
2767
+ cli: adapter.cli,
2768
+ label: adapter.displayName
2769
+ };
2770
+ const version = detection.version;
2771
+ const withVersion = version ? { version } : {};
2772
+ if (!detection.installed) return {
2773
+ ...base,
2774
+ status: "not-installed",
2775
+ note: "install it, then press g"
2776
+ };
2777
+ const c = compatStatus(adapter.cli, version, compat);
2778
+ if (r.planError) return {
2779
+ ...base,
2780
+ ...withVersion,
2781
+ status: "blocked",
2782
+ note: "we can't read its settings file"
2783
+ };
2784
+ if (c.kind === "older") return {
2785
+ ...base,
2786
+ ...withVersion,
2787
+ status: "blocked",
2788
+ note: `too old, update it first (needs ${c.minimum} or newer)`
2789
+ };
2790
+ if (ready(r)) return {
2791
+ ...base,
2792
+ ...withVersion,
2793
+ status: "ready",
2794
+ ...c.kind === "newer" && c.minor ? { note: "a bit newer than we tested, should be fine" } : {}
2795
+ };
2796
+ const allMissing = [r.mcp, r.hooks].filter((p) => p !== null).every((p) => p === "missing");
2797
+ return {
2798
+ ...base,
2799
+ ...withVersion,
2800
+ status: allMissing ? "not-set-up" : "needs-update",
2801
+ note: "press ⏎ to fix"
2802
+ };
2803
+ }
2804
+ /** The checkup list. Exported for tests. */
2805
+ function healthFrom(input) {
2806
+ const out = [];
2807
+ out.push(input.daemon === "running" ? {
2808
+ level: "ok",
2809
+ text: "Conveno is running"
2810
+ } : input.daemon === "stopped" ? {
2811
+ level: "warn",
2812
+ text: "Conveno is not running yet. It starts with your first session."
2813
+ } : {
2814
+ level: "error",
2815
+ text: "Conveno can't be reached"
2816
+ });
2817
+ const installed = input.clis.filter((c) => c.status !== "not-installed");
2818
+ const good = installed.filter((c) => c.status === "ready").length;
2819
+ out.push(installed.length === 0 ? {
2820
+ level: "warn",
2821
+ text: "No supported CLI found on this machine"
2822
+ } : {
2823
+ level: good === installed.length ? "ok" : "info",
2824
+ text: `${good} of ${installed.length} CLIs ready`
2825
+ });
2826
+ let fixes = 0;
2827
+ for (const c of installed) if (c.status === "needs-update") {
2828
+ fixes++;
2829
+ out.push({
2830
+ level: "warn",
2831
+ text: `${c.label} needs an update`,
2832
+ fixId: `init:${c.cli}`
2833
+ });
2834
+ } else if (c.status === "not-set-up") {
2835
+ fixes++;
2836
+ out.push({
2837
+ level: "warn",
2838
+ text: `${c.label} is not set up yet`,
2839
+ fixId: `init:${c.cli}`
2840
+ });
2841
+ } else if (c.status === "blocked") out.push({
2842
+ level: "error",
2843
+ text: `${c.label} is blocked: ${c.note ?? "see Setup"}`
2844
+ });
2845
+ if (input.sync === "online") out.push({
2846
+ level: "ok",
2847
+ text: "Sync is online"
2848
+ });
2849
+ else if (input.sync === "offline") out.push({
2850
+ level: "warn",
2851
+ text: "Sync is offline, it keeps trying"
2852
+ });
2853
+ if (fixes === 0) out.push({
2854
+ level: "ok",
2855
+ text: "Up to date"
2856
+ });
2857
+ return out;
2858
+ }
2859
+ /** The same facts as `conveno doctor`, as friendly rows. Never throws. */
2860
+ async function loadSetup(ctx) {
2861
+ const clis = (await Promise.all(ctx.adapters.map((a) => inspect(ctx, a)))).map((r) => checkFromRow(r, ctx.compat));
2862
+ let daemon = "stopped";
2863
+ let sync;
2864
+ try {
2865
+ const client = await ctx.connect(connectOpts(ctx, false));
2866
+ try {
2867
+ await client["session.list"]({});
2868
+ daemon = "running";
2869
+ const relay = await client["relay.status"]({}).catch(() => void 0);
2870
+ if (relay) {
2871
+ if (relay.state === "connected") sync = "online";
2872
+ else if (relay.state === "connecting" || relay.state === "disconnected") sync = "offline";
2873
+ }
2874
+ } finally {
2875
+ await client.close().catch(() => void 0);
2876
+ }
2877
+ } catch (e) {
2878
+ daemon = daemonProblem(ctx.theme, e).notRunning ? "stopped" : "unreachable";
2879
+ }
2880
+ return {
2881
+ clis,
2882
+ health: healthFrom({
2883
+ daemon,
2884
+ ...sync ? { sync } : {},
2885
+ clis
2886
+ })
2887
+ };
2888
+ }
2889
+ function parseFixId(fixId) {
2890
+ const [kind, cli, accept] = fixId.split(":");
2891
+ const ids = accept ? accept.split(",").filter(Boolean) : [];
2892
+ if (kind === "init" && cli) return {
2893
+ kind,
2894
+ cli,
2895
+ accept: ids
2896
+ };
2897
+ if (kind === "uninstall" && cli) return {
2898
+ kind,
2899
+ cli,
2900
+ accept: []
2901
+ };
2902
+ }
2903
+ /** The fix id that says yes to these optional setups. */
2904
+ const fixIdWith = (cli, accept) => accept.length > 0 ? `init:${cli}:${accept.join(",")}` : `init:${cli}`;
2905
+ async function planFor(ctx, fixId) {
2906
+ const parsed = parseFixId(fixId);
2907
+ if (!parsed) return {
2908
+ items: [],
2909
+ error: "We don't know that fix."
2910
+ };
2911
+ const a = ctx.adapters.find((x) => x.cli === parsed.cli);
2912
+ if (!a) return {
2913
+ items: [],
2914
+ error: "We don't know that CLI."
2915
+ };
2916
+ const adapters = [a];
2917
+ const env = adapterEnv(ctx);
2918
+ const found = [];
2919
+ for (const adapter of adapters) {
2920
+ const detection = await adapter.detect(env).catch(() => ({
2921
+ installed: false,
2922
+ configPaths: []
2923
+ }));
2924
+ if (detection.installed) found.push({
2925
+ adapter,
2926
+ detection
2927
+ });
2928
+ }
2929
+ if (found.length === 0) return {
2930
+ items: [],
2931
+ error: "It isn't installed."
2932
+ };
2933
+ const { items, failures } = await collectPlans(ctx, found, parsed.kind === "init" ? "plan" : "uninstallPlan", void 0, parsed.accept);
2934
+ return {
2935
+ items,
2936
+ ...failures[0] ? { error: failures[0].message } : {}
2937
+ };
2938
+ }
2939
+ /** Cap on diff lines kept per file, so one big file cannot fill the overlay. */
2940
+ const MAX_DIFF_LINES = 60;
2941
+ /** What `applyFix` would change, without changing anything. */
2942
+ async function planFix(ctx, fixId) {
2943
+ const { items, error } = await planFor(ctx, fixId);
2944
+ const parsed = parseFixId(fixId);
2945
+ const adapter = parsed && ctx.adapters.find((x) => x.cli === parsed.cli);
2946
+ const options = parsed?.kind === "init" && adapter ? await pendingOptions(ctx, [adapter]) : [];
2947
+ return {
2948
+ files: items.map(({ change }) => {
2949
+ const lines = unifiedDiff(change.before, change.after);
2950
+ return {
2951
+ path: tilde(change.path, ctx.home),
2952
+ isNew: change.before === null,
2953
+ deleted: Boolean(change.deleteFile),
2954
+ summary: change.description,
2955
+ lines: lines.length > MAX_DIFF_LINES ? lines.slice(0, MAX_DIFF_LINES) : lines
2956
+ };
2957
+ }),
2958
+ ...options.length > 0 ? { options } : {},
2959
+ ...error ? { error } : {}
2960
+ };
2961
+ }
2962
+ /**
2963
+ * Make the change `planFix` showed: back up each file, then write. Same code path as
2964
+ * `conveno init` (and `conveno uninstall` without a backup on record). Throws a friendly error.
2965
+ */
2966
+ async function applyFix(ctx, fixId) {
2967
+ const { items, error } = await planFor(ctx, fixId);
2968
+ if (error) throw new Error(error);
2969
+ if (items.length === 0) return;
2970
+ try {
2971
+ await applyChanges(ctx, items, parseFixId(fixId)?.kind === "uninstall" ? { markRestored: true } : {});
2972
+ } catch (e) {
2973
+ if (e instanceof StaleError) throw new Error("A settings file changed while we waited. Press g, then try again.");
2974
+ throw new Error(plainError(e));
2975
+ }
2976
+ }
2977
+ async function getExtras(ctx) {
2978
+ return { helpers: readSettings(dataPaths(ctx.platform, ctx.dataDir).settings).acpAdapterNpx === true };
2979
+ }
2980
+ /** Same answer as `conveno init --acp-adapters` / `--no-acp-adapters`. */
2981
+ function setHelpers(ctx, on) {
2982
+ writeSettings(dataPaths(ctx.platform, ctx.dataDir).settings, { acpAdapterNpx: on });
2983
+ }
2755
2984
  // src/tui/screens/setup.tsx
2756
2985
  /** Screen 4: Setup. Your CLIs, extras and the checkup. */
2757
2986
  var setup_exports = /* @__PURE__ */ __exportAll({
2758
2987
  default: () => SetupScreen,
2759
- idsFor: () => idsFor
2988
+ idsFor: () => idsFor,
2989
+ idsWithOptions: () => idsWithOptions
2760
2990
  });
2761
2991
  const STATUS_WORD = {
2762
2992
  ready: "ready",
@@ -2765,6 +2995,14 @@ const STATUS_WORD = {
2765
2995
  blocked: "blocked",
2766
2996
  "not-installed": "not installed"
2767
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
+ }
2768
3006
  /** `init:<cli>` ids for the picked rows, or the row under the cursor. Pure, for tests. */
2769
3007
  function idsFor(clis, picked, cursorCli) {
2770
3008
  const wanted = picked.size > 0 ? clis.filter((c) => picked.has(c.cli)) : clis.filter((c) => c.cli === cursorCli);
@@ -2852,6 +3090,11 @@ function ReviewBox({ review, rows, width, active, onYes, onNo, onScroll }) {
2852
3090
  children: `… ${hidden} more lines (↑↓ to scroll)`
2853
3091
  }) : null]
2854
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)),
2855
3098
  /* @__PURE__ */ jsx(Text, { children: " " }),
2856
3099
  review.busy ? /* @__PURE__ */ jsx(Text, { children: "Working…" }) : review.error || review.files.length === 0 ? /* @__PURE__ */ jsx(Hit, {
2857
3100
  onClick: onNo,
@@ -2944,33 +3187,47 @@ function SetupScreen(props) {
2944
3187
  if (all.some((x) => x.status === "ready")) return;
2945
3188
  setPicked(new Set(all.filter((x) => x.status === "not-set-up" || x.status === "needs-update").map((x) => x.cli)));
2946
3189
  }, [state.setup]);
2947
- const open = useCallback(async (ids, title) => {
3190
+ const open = useCallback(async (ids, title, options = [], accepted = []) => {
2948
3191
  setReview({
2949
3192
  title,
2950
3193
  ids,
2951
3194
  files: [],
3195
+ options,
3196
+ accepted,
2952
3197
  scroll: 0,
2953
3198
  busy: true
2954
3199
  });
2955
3200
  const files = [];
3201
+ const found = new Map(options.map((o) => [o.id, o]));
2956
3202
  let error;
2957
- for (const id of ids) {
3203
+ for (const id of idsWithOptions(ids, options, accepted)) {
2958
3204
  const plan = await actions.planFix(id).catch((e) => ({
2959
3205
  files: [],
3206
+ options: [],
2960
3207
  error: e instanceof Error ? e.message : String(e)
2961
3208
  }));
2962
3209
  files.push(...plan.files);
3210
+ for (const o of plan.options ?? []) found.set(o.id, o);
2963
3211
  error ??= plan.error;
2964
3212
  }
2965
3213
  setReview({
2966
3214
  title,
2967
3215
  ids,
2968
3216
  files,
3217
+ options: [...found.values()],
3218
+ accepted,
2969
3219
  ...error ? { error } : {},
2970
3220
  scroll: 0,
2971
3221
  busy: false
2972
3222
  });
2973
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]);
2974
3231
  const setUp = useCallback((target) => {
2975
3232
  const row = target ? target.extra ?? -1 : extraRow;
2976
3233
  const cur = target ? target.cli : onCli;
@@ -3031,7 +3288,7 @@ function SetupScreen(props) {
3031
3288
  busy: true
3032
3289
  });
3033
3290
  try {
3034
- 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);
3035
3292
  toast("Done. Restart open sessions to pick it up.", "ok");
3036
3293
  setReview(void 0);
3037
3294
  setPicked(/* @__PURE__ */ new Set());
@@ -3059,7 +3316,11 @@ function SetupScreen(props) {
3059
3316
  {
3060
3317
  key: "↑↓",
3061
3318
  label: "scroll"
3062
- }
3319
+ },
3320
+ ...review.options.length > 0 ? [{
3321
+ key: "1-9",
3322
+ label: "tick option"
3323
+ }] : []
3063
3324
  ]);
3064
3325
  else setKeys([
3065
3326
  {
@@ -3139,6 +3400,7 @@ function SetupScreen(props) {
3139
3400
  scroll: review.scroll + 1
3140
3401
  });
3141
3402
  const closed = review.error || review.files.length === 0;
3403
+ if (/^[1-9]$/.test(input)) return toggleOption(Number(input) - 1);
3142
3404
  if (input === "n" || key.escape || closed && (key.return || input === "y")) return setReview(void 0);
3143
3405
  if (input === "y" && !closed) apply();
3144
3406
  return;
@@ -3906,226 +4168,6 @@ async function confirmPair(client, match, code) {
3906
4168
  if (s.state === "done") current.delete(client);
3907
4169
  return s;
3908
4170
  }
3909
- // src/tui/setup-data.ts
3910
- /**
3911
- * What the Setup screen reads and does. Same facts as `conveno doctor`, in plain words, and the
3912
- * same code path as `conveno init` / `conveno uninstall` for changing files.
3913
- *
3914
- * No Ink or React in here: the store imports it.
3915
- */
3916
- const ready = (r) => r.mcp === "ok" && (r.hooks === null || r.hooks === "ok");
3917
- /** One CLI's row, from what `conveno doctor` found. Exported for tests. */
3918
- function checkFromRow(r, compat) {
3919
- const { adapter, detection } = r;
3920
- const base = {
3921
- cli: adapter.cli,
3922
- label: adapter.displayName
3923
- };
3924
- const version = detection.version;
3925
- const withVersion = version ? { version } : {};
3926
- if (!detection.installed) return {
3927
- ...base,
3928
- status: "not-installed",
3929
- note: "install it, then press g"
3930
- };
3931
- const c = compatStatus(adapter.cli, version, compat);
3932
- if (r.planError) return {
3933
- ...base,
3934
- ...withVersion,
3935
- status: "blocked",
3936
- note: "we can't read its settings file"
3937
- };
3938
- if (c.kind === "older") return {
3939
- ...base,
3940
- ...withVersion,
3941
- status: "blocked",
3942
- note: `too old, update it first (needs ${c.minimum} or newer)`
3943
- };
3944
- if (ready(r)) return {
3945
- ...base,
3946
- ...withVersion,
3947
- status: "ready",
3948
- ...c.kind === "newer" && c.minor ? { note: "a bit newer than we tested, should be fine" } : {}
3949
- };
3950
- const allMissing = [r.mcp, r.hooks].filter((p) => p !== null).every((p) => p === "missing");
3951
- return {
3952
- ...base,
3953
- ...withVersion,
3954
- status: allMissing ? "not-set-up" : "needs-update",
3955
- note: "press ⏎ to fix"
3956
- };
3957
- }
3958
- /** The checkup list. Exported for tests. */
3959
- function healthFrom(input) {
3960
- const out = [];
3961
- out.push(input.daemon === "running" ? {
3962
- level: "ok",
3963
- text: "Conveno is running"
3964
- } : input.daemon === "stopped" ? {
3965
- level: "warn",
3966
- text: "Conveno is not running yet. It starts with your first session."
3967
- } : {
3968
- level: "error",
3969
- text: "Conveno can't be reached"
3970
- });
3971
- const installed = input.clis.filter((c) => c.status !== "not-installed");
3972
- const good = installed.filter((c) => c.status === "ready").length;
3973
- out.push(installed.length === 0 ? {
3974
- level: "warn",
3975
- text: "No supported CLI found on this machine"
3976
- } : {
3977
- level: good === installed.length ? "ok" : "info",
3978
- text: `${good} of ${installed.length} CLIs ready`
3979
- });
3980
- let fixes = 0;
3981
- for (const c of installed) if (c.status === "needs-update") {
3982
- fixes++;
3983
- out.push({
3984
- level: "warn",
3985
- text: `${c.label} needs an update`,
3986
- fixId: `init:${c.cli}`
3987
- });
3988
- } else if (c.status === "not-set-up") {
3989
- fixes++;
3990
- out.push({
3991
- level: "warn",
3992
- text: `${c.label} is not set up yet`,
3993
- fixId: `init:${c.cli}`
3994
- });
3995
- } else if (c.status === "blocked") out.push({
3996
- level: "error",
3997
- text: `${c.label} is blocked: ${c.note ?? "see Setup"}`
3998
- });
3999
- if (input.sync === "online") out.push({
4000
- level: "ok",
4001
- text: "Sync is online"
4002
- });
4003
- else if (input.sync === "offline") out.push({
4004
- level: "warn",
4005
- text: "Sync is offline, it keeps trying"
4006
- });
4007
- if (fixes === 0) out.push({
4008
- level: "ok",
4009
- text: "Up to date"
4010
- });
4011
- return out;
4012
- }
4013
- /** The same facts as `conveno doctor`, as friendly rows. Never throws. */
4014
- async function loadSetup(ctx) {
4015
- const clis = (await Promise.all(ctx.adapters.map((a) => inspect(ctx, a)))).map((r) => checkFromRow(r, ctx.compat));
4016
- let daemon = "stopped";
4017
- let sync;
4018
- try {
4019
- const client = await ctx.connect(connectOpts(ctx, false));
4020
- try {
4021
- await client["session.list"]({});
4022
- daemon = "running";
4023
- const relay = await client["relay.status"]({}).catch(() => void 0);
4024
- if (relay) {
4025
- if (relay.state === "connected") sync = "online";
4026
- else if (relay.state === "connecting" || relay.state === "disconnected") sync = "offline";
4027
- }
4028
- } finally {
4029
- await client.close().catch(() => void 0);
4030
- }
4031
- } catch (e) {
4032
- daemon = daemonProblem(ctx.theme, e).notRunning ? "stopped" : "unreachable";
4033
- }
4034
- return {
4035
- clis,
4036
- health: healthFrom({
4037
- daemon,
4038
- ...sync ? { sync } : {},
4039
- clis
4040
- })
4041
- };
4042
- }
4043
- function parseFixId(fixId) {
4044
- const [kind, cli] = fixId.split(":");
4045
- if (kind === "init" && cli) return {
4046
- kind,
4047
- cli
4048
- };
4049
- if (kind === "uninstall" && cli) return {
4050
- kind,
4051
- cli
4052
- };
4053
- }
4054
- async function planFor(ctx, fixId) {
4055
- const parsed = parseFixId(fixId);
4056
- if (!parsed) return {
4057
- items: [],
4058
- error: "We don't know that fix."
4059
- };
4060
- const a = ctx.adapters.find((x) => x.cli === parsed.cli);
4061
- if (!a) return {
4062
- items: [],
4063
- error: "We don't know that CLI."
4064
- };
4065
- const adapters = [a];
4066
- const env = adapterEnv(ctx);
4067
- const found = [];
4068
- for (const adapter of adapters) {
4069
- const detection = await adapter.detect(env).catch(() => ({
4070
- installed: false,
4071
- configPaths: []
4072
- }));
4073
- if (detection.installed) found.push({
4074
- adapter,
4075
- detection
4076
- });
4077
- }
4078
- if (found.length === 0) return {
4079
- items: [],
4080
- error: "It isn't installed."
4081
- };
4082
- const { items, failures } = await collectPlans(ctx, found, parsed.kind === "init" ? "plan" : "uninstallPlan");
4083
- return {
4084
- items,
4085
- ...failures[0] ? { error: failures[0].message } : {}
4086
- };
4087
- }
4088
- /** Cap on diff lines kept per file, so one big file cannot fill the overlay. */
4089
- const MAX_DIFF_LINES = 60;
4090
- /** What `applyFix` would change, without changing anything. */
4091
- async function planFix(ctx, fixId) {
4092
- const { items, error } = await planFor(ctx, fixId);
4093
- return {
4094
- files: items.map(({ change }) => {
4095
- const lines = unifiedDiff(change.before, change.after);
4096
- return {
4097
- path: tilde(change.path, ctx.home),
4098
- isNew: change.before === null,
4099
- deleted: Boolean(change.deleteFile),
4100
- summary: change.description,
4101
- lines: lines.length > MAX_DIFF_LINES ? lines.slice(0, MAX_DIFF_LINES) : lines
4102
- };
4103
- }),
4104
- ...error ? { error } : {}
4105
- };
4106
- }
4107
- /**
4108
- * Make the change `planFix` showed: back up each file, then write. Same code path as
4109
- * `conveno init` (and `conveno uninstall` without a backup on record). Throws a friendly error.
4110
- */
4111
- async function applyFix(ctx, fixId) {
4112
- const { items, error } = await planFor(ctx, fixId);
4113
- if (error) throw new Error(error);
4114
- if (items.length === 0) return;
4115
- try {
4116
- await applyChanges(ctx, items, parseFixId(fixId)?.kind === "uninstall" ? { markRestored: true } : {});
4117
- } catch (e) {
4118
- if (e instanceof StaleError) throw new Error("A settings file changed while we waited. Press g, then try again.");
4119
- throw new Error(plainError(e));
4120
- }
4121
- }
4122
- async function getExtras(ctx) {
4123
- return { helpers: readSettings(dataPaths(ctx.platform, ctx.dataDir).settings).acpAdapterNpx === true };
4124
- }
4125
- /** Same answer as `conveno init --acp-adapters` / `--no-acp-adapters`. */
4126
- function setHelpers(ctx, on) {
4127
- writeSettings(dataPaths(ctx.platform, ctx.dataDir).settings, { acpAdapterNpx: on });
4128
- }
4129
4171
  // src/tui/store.ts
4130
4172
  /**
4131
4173
  * The app's data layer: one daemon connection, the state the screens read, and every action they