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

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,11 +1,11 @@
1
- import { D as completeLogin, Dt as resolveAcpProgram, E as compatStatus, H as fetchAccountStatus, Kt as writeSettings, M as dataPaths, U as findOnPath, bt as readSettings, d as SPAWN_TABLE, et as logoutAccount, g as adapterNpxCommand, gt as readAccountTokens, h as adapterInstallCommand, m as acpOverrideVar, n as AccountError, pt as pollDeviceCode, qt as CLI_KINDS, ut as pinnedAdapter, wt as requestDeviceCode } from "./dist-BTLBO1Rp.js";
1
+ import { D as completeLogin, E as compatStatus, H as fetchAccountStatus, M as dataPaths, Tt as requestDeviceCode, U as findOnPath, Xt as CLI_KINDS, Yt as writeSettings, _t as readAccountTokens, d as SPAWN_TABLE, dt as pinnedAdapter, g as adapterNpxCommand, h as adapterInstallCommand, kt as resolveAcpProgram, m as acpOverrideVar, mt as pollDeviceCode, n as AccountError, tt as logoutAccount, xt as readSettings } from "./dist-BBdba94T.js";
2
2
  import { a as fail, c as plural, d as warnBlock, i as errorBlock, 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";
3
- import { i as parseFlags, t as COMMANDS } from "./args-D9T-6TDw.js";
3
+ import { a as parseFlags, n as COMMANDS } from "./args-CGL-AmNd.js";
4
4
  import { n as connectOpts, t as adapterEnv } from "./ctx-tYftvhz_.js";
5
- import { t as daemonProblem } from "./daemonError-CdLataBW.js";
5
+ import { t as daemonProblem } from "./daemonError-DJ-P55nH.js";
6
6
  import { basename, dirname, join } from "node:path";
7
7
  import { spawn } from "node:child_process";
8
- import { chmod, mkdir, open, readFile, readdir, realpath, rename as rename$1, rm, rmdir, stat, writeFile } from "node:fs/promises";
8
+ import { access, chmod, mkdir, open, readFile, readdir, realpath, rename as rename$1, rm, rmdir, stat, writeFile } from "node:fs/promises";
9
9
  import { createHash, randomBytes } from "node:crypto";
10
10
  // src/account.ts
11
11
  const accountIo = (ctx, io) => ({
@@ -140,6 +140,193 @@ async function runAccount(ctx, argv, io = {}) {
140
140
  return accountFailure(ctx, e, "Could not read your account");
141
141
  }
142
142
  }
143
+ // src/daemon.ts
144
+ async function lockPid(ctx) {
145
+ try {
146
+ const raw = await readFile(dataPaths(ctx.platform, ctx.dataDir).lock, "utf8");
147
+ const pid = JSON.parse(raw).pid;
148
+ return typeof pid === "number" && Number.isInteger(pid) && pid > 0 ? pid : null;
149
+ } catch {
150
+ return null;
151
+ }
152
+ }
153
+ const sleep$1 = (ms) => new Promise((r) => setTimeout(r, ms));
154
+ /** Does something on the socket answer the Conveno handshake? */
155
+ async function reachable(ctx) {
156
+ try {
157
+ await (await ctx.connect(connectOpts(ctx, false))).close().catch(() => void 0);
158
+ return true;
159
+ } catch {
160
+ return false;
161
+ }
162
+ }
163
+ const lockExists = (ctx) => access(dataPaths(ctx.platform, ctx.dataDir).lock).then(() => true, () => false);
164
+ /** Poll until `done()` holds or `ms` pass. Returns whether it held. */
165
+ async function waitFor(done, ms) {
166
+ const deadline = Date.now() + ms;
167
+ for (;;) {
168
+ if (await done()) return true;
169
+ if (Date.now() >= deadline) return false;
170
+ await sleep$1(50);
171
+ }
172
+ }
173
+ const norm = (text) => text.replaceAll("\\", "/").toLowerCase();
174
+ /**
175
+ * Does this command line belong to the Conveno daemon? It must run the daemon's entry script: the
176
+ * one this install resolved, any installed `@conveno/cli`'s `daemon.js`, or the `bin.js` of the
177
+ * `@conveno/daemon` package that releases before 0.1.1 started.
178
+ */
179
+ function isConvenoDaemonCommand(commandLine, daemonEntry) {
180
+ const line = norm(commandLine);
181
+ if (daemonEntry !== void 0 && line.includes(norm(daemonEntry))) return true;
182
+ return /@conveno\/cli\/(?:[^ ]+\/)?daemon\.js|@conveno\/daemon\/(?:[^ ]+\/)?bin\.js/.test(line);
183
+ }
184
+ const STOP_FIX = (t) => `then run ${cmd(t, "conveno daemon status")}`;
185
+ /**
186
+ * `conveno daemon stop`. The normal path asks the daemon to shut itself down over the control
187
+ * channel (`daemon.shutdown`), the way Docker and pm2 do. That needs no signal and no external
188
+ * tool, so it works for a normal user in a Windows SSH session. Only when the daemon does not answer,
189
+ * and its lock pid is verified to be the daemon, is the process ended directly.
190
+ */
191
+ async function stopDaemon(ctx, plain = false) {
192
+ const t = ctx.theme;
193
+ const lock = dataPaths(ctx.platform, ctx.dataDir).lock;
194
+ const pid = await lockPid(ctx);
195
+ const named = pid === null ? "" : ` (pid ${pid})`;
196
+ let client;
197
+ try {
198
+ client = await ctx.connect(connectOpts(ctx, false));
199
+ } catch {
200
+ client = void 0;
201
+ }
202
+ if (client) {
203
+ try {
204
+ await client["daemon.shutdown"]({});
205
+ } catch (e) {
206
+ await client.close().catch(() => void 0);
207
+ return fail(ctx, {
208
+ what: `The background service${named} did not accept the stop request`,
209
+ detail: [plainError(e)],
210
+ fix: `${pid === null ? "Stop the process that owns the daemon socket yourself" : `Stop pid ${pid} yourself`}, ${STOP_FIX(t)}.`,
211
+ exit: 1,
212
+ ref: "e_daemon_stop"
213
+ });
214
+ }
215
+ await client.close().catch(() => void 0);
216
+ if (!await waitFor(async () => !await reachable(ctx) && !await lockExists(ctx) && (pid === null || !ctx.isAlive(pid)), ctx.stopTimeoutMs)) return fail(ctx, {
217
+ what: `The background service${named} is still running after ${Math.round(ctx.stopTimeoutMs / 1e3)}s`,
218
+ detail: ["It accepted the stop request, but its process, socket or lock file is still there."],
219
+ fix: `${pid === null ? "Stop the process that owns the daemon socket yourself" : `Stop pid ${pid} yourself`}, ${STOP_FIX(t)}.`,
220
+ exit: 1,
221
+ ref: "e_daemon_stop"
222
+ });
223
+ ctx.out(`${t.status("ok")} Stopped ${plain ? "Conveno's background service" : "the daemon"}${named}.\n`);
224
+ return 0;
225
+ }
226
+ if (pid === null) {
227
+ ctx.out(`${t.status("info")} Conveno's background service is not running. Nothing to stop.\n`);
228
+ return 0;
229
+ }
230
+ const stale = async () => {
231
+ await rm(lock, { force: true }).catch(() => void 0);
232
+ ctx.out(`${t.status("info")} Nothing answered as the Conveno daemon, so no process was stopped. Removed the stale lock file (it named pid ${pid}).\n`);
233
+ return 0;
234
+ };
235
+ if (!ctx.isAlive(pid)) return stale();
236
+ const commandLine = await ctx.commandLineOf(pid);
237
+ if (commandLine === null) return fail(ctx, {
238
+ what: `The background service did not answer, and pid ${pid} could not be checked`,
239
+ detail: ["Conveno could not read that process's command line, so it cannot tell whether it is the daemon. It stopped nothing."],
240
+ fix: `If pid ${pid} is the Conveno daemon, end it yourself (Task Manager on Windows, \`kill ${pid}\` elsewhere), ${STOP_FIX(t)}.`,
241
+ exit: 1,
242
+ ref: "e_daemon_lock"
243
+ });
244
+ if (!isConvenoDaemonCommand(commandLine, ctx.daemonEntry)) return stale();
245
+ try {
246
+ ctx.kill(pid);
247
+ } catch (e) {
248
+ return fail(ctx, {
249
+ what: `Could not stop the daemon (pid ${pid})`,
250
+ detail: [plainError(e)],
251
+ fix: `Stop that process yourself, ${STOP_FIX(t)}.`,
252
+ exit: 1,
253
+ ref: "e_daemon_stop"
254
+ });
255
+ }
256
+ if (!await waitFor(() => !ctx.isAlive(pid), ctx.stopTimeoutMs)) return fail(ctx, {
257
+ what: `The background service (pid ${pid}) is still running after ${Math.round(ctx.stopTimeoutMs / 1e3)}s`,
258
+ detail: ["It did not answer, was ended, and has not exited."],
259
+ fix: `Stop that process yourself, ${STOP_FIX(t)}.`,
260
+ exit: 1,
261
+ ref: "e_daemon_stop"
262
+ });
263
+ await rm(lock, { force: true }).catch(() => void 0);
264
+ ctx.out(`${t.status("ok")} Stopped ${plain ? "Conveno's background service" : "the daemon"} (pid ${pid}). It was not answering, so it was ended directly.\n`);
265
+ return 0;
266
+ }
267
+ /**
268
+ * Stop the daemon if one is running, and say nothing when none is. Used before `conveno uninstall`
269
+ * changes any file, because a running daemon keeps files open (on Windows that blocks removing them).
270
+ * Returns 0 when nothing is left running, else the exit code of the failed stop.
271
+ */
272
+ async function stopDaemonIfRunning(ctx) {
273
+ if (!await reachable(ctx)) {
274
+ const pid = await lockPid(ctx);
275
+ if (pid === null || !ctx.isAlive(pid)) return 0;
276
+ }
277
+ return stopDaemon(ctx, true);
278
+ }
279
+ const SUBCOMMANDS = [
280
+ "start",
281
+ "stop",
282
+ "status"
283
+ ];
284
+ async function runDaemon(ctx, argv) {
285
+ const t = ctx.theme;
286
+ const sub = argv[0];
287
+ if (sub === "start") {
288
+ try {
289
+ await (await ctx.connect(connectOpts(ctx, true))).close().catch(() => void 0);
290
+ } catch (e) {
291
+ const problem = daemonProblem(t, e);
292
+ return fail(ctx, {
293
+ what: "The Conveno daemon did not start",
294
+ detail: [problem.why],
295
+ fix: problem.notRunning ? `Run ${cmd(t, "conveno doctor")} to check the install, then try again.` : problem.fix,
296
+ exit: 1,
297
+ ref: "e_daemon_start"
298
+ });
299
+ }
300
+ const pid = await lockPid(ctx);
301
+ ctx.out(`${t.status("ok")} Daemon running${pid ? `, pid ${pid}` : ""}.\n`);
302
+ return 0;
303
+ }
304
+ if (sub === "status") {
305
+ const pid = await lockPid(ctx);
306
+ try {
307
+ await (await ctx.connect(connectOpts(ctx, false))).close().catch(() => void 0);
308
+ ctx.out(`${t.status("ok")} daemon running${pid ? `, pid ${pid}` : ""}\n`);
309
+ return 0;
310
+ } catch (e) {
311
+ const problem = daemonProblem(t, e);
312
+ if (problem.notRunning) ctx.out(`${t.glyph("offline")} daemon not running\n`);
313
+ else {
314
+ ctx.out(`${t.status("error")} daemon cannot be reached\n`);
315
+ ctx.err(warnBlock(t, "Conveno's background service cannot be reached.", problem.fix, problem.why));
316
+ }
317
+ return 1;
318
+ }
319
+ }
320
+ if (sub === "stop") return stopDaemon(ctx);
321
+ const suggestion = sub ? closest(sub, SUBCOMMANDS) : void 0;
322
+ return fail(ctx, {
323
+ what: sub ? `Unknown daemon command "${sub}"` : "conveno daemon needs a command",
324
+ fix: `Run ${cmd(t, "conveno daemon start")}, ${cmd(t, "conveno daemon stop")} or ${cmd(t, "conveno daemon status")}.`,
325
+ ...suggestion ? { didYouMean: `Did you mean ${suggestion}?` } : {},
326
+ exit: 2,
327
+ ref: "e_usage"
328
+ });
329
+ }
143
330
  const PAIR_TIMEOUT_MS = 3e5;
144
331
  /**
145
332
  * Run `run` with a daemon client. Commands that change something start the daemon when needed;
@@ -881,7 +1068,11 @@ async function applyChanges(ctx, items, opts = {}) {
881
1068
  await currentIfUnchanged(change);
882
1069
  if (change.deleteFile) {
883
1070
  await io.rm(change.path);
884
- if (change.pruneEmptyDir) await rmdir(dirname(change.path)).catch(() => void 0);
1071
+ let dir = dirname(change.path);
1072
+ for (let n = change.pruneEmptyDir === true ? 1 : change.pruneEmptyDir ?? 0; n > 0; n--) {
1073
+ if (!await rmdir(dir).then(() => true, () => false)) break;
1074
+ dir = dirname(dir);
1075
+ }
885
1076
  } else await writeAtomic(change.path, change.after, io);
886
1077
  }
887
1078
  how.push({
@@ -991,8 +1182,8 @@ async function markRestored(ctx, found) {
991
1182
  await writeFile(join(found.dir, MANIFEST_NAME), `${JSON.stringify(done, null, 2)}\n`, { mode: 384 });
992
1183
  }
993
1184
  // src/init.ts
994
- const CODEX_NOTE = "Codex asks you to trust new hooks once: run /hooks inside Codex.";
995
- const CURSOR_NOTE = "Cursor CLI can ask to approve the Conveno MCP server when you start it in your home folder. Approve it once there with: cursor-agent mcp enable conveno";
1185
+ const CODEX_NOTE = "Codex asks you to approve Conveno once: run /hooks inside Codex.";
1186
+ const CURSOR_NOTE = "Cursor can ask you to approve Conveno when you start it in your home folder. Approve it once there with: cursor-agent mcp enable conveno";
996
1187
  /** Detect every adapter. A detection that throws counts as not installed. */
997
1188
  async function detectAll(ctx, adapters = ctx.adapters) {
998
1189
  const env = adapterEnv(ctx);
@@ -1013,9 +1204,11 @@ async function detectAll(ctx, adapters = ctx.adapters) {
1013
1204
  }
1014
1205
  }));
1015
1206
  }
1207
+ /** The `--cli` example in error fixes: every CLI this version supports. */
1208
+ const cliListExample = (ctx) => `--cli ${ctx.adapters.map((a) => a.cli).join(",")}`;
1016
1209
  function parseCliList(raw, ctx) {
1017
1210
  if (raw === void 0) return ctx.adapters;
1018
- const names = raw.split(",").map((s) => s.trim()).filter(Boolean);
1211
+ const names = raw.split(/[\s,]+/).filter(Boolean);
1019
1212
  const out = [];
1020
1213
  for (const n of names) {
1021
1214
  if (!CLI_KINDS.includes(n)) {
@@ -1033,7 +1226,7 @@ function parseCliList(raw, ctx) {
1033
1226
  }
1034
1227
  function printDetections(ctx, found) {
1035
1228
  const t = ctx.theme;
1036
- ctx.out(`${t.bold("Looking for AI coding CLIs on this machine")}\n`);
1229
+ ctx.out(`${t.bold("Looking for AI tools on this machine")}\n`);
1037
1230
  const rows = found.map(({ adapter, detection }) => detection.installed ? [
1038
1231
  ` ${t.status("ok")} ${adapter.cli}`,
1039
1232
  adapter.displayName,
@@ -1043,12 +1236,12 @@ function printDetections(ctx, found) {
1043
1236
  ctx.out(`${columns(rows).join("\n")}\n\n`);
1044
1237
  }
1045
1238
  /** Collect plans from installed adapters. Returns failures instead of throwing. */
1046
- async function collectPlans(ctx, found, which, baseline) {
1239
+ async function collectPlans(ctx, found, which, baseline, accept = []) {
1047
1240
  const env = adapterEnv(ctx);
1048
1241
  const items = [];
1049
1242
  const failures = [];
1050
1243
  for (const { adapter, detection } of found) try {
1051
- for (const change of await (which === "plan" ? adapter.plan(env) : adapter.uninstallPlan(env, baseline))) items.push({
1244
+ for (const change of await (which === "plan" ? adapter.plan(env, { accept }) : adapter.uninstallPlan(env, baseline))) items.push({
1052
1245
  cli: adapter.cli,
1053
1246
  installed: detection.installed,
1054
1247
  change
@@ -1102,6 +1295,10 @@ async function confirmAndApply(ctx, items, opts) {
1102
1295
  return { exit: 0 };
1103
1296
  }
1104
1297
  }
1298
+ if (opts.beforeApply) {
1299
+ const code = await opts.beforeApply();
1300
+ if (code !== 0) return { exit: code };
1301
+ }
1105
1302
  try {
1106
1303
  return { applied: await applyChanges(ctx, items, opts.markRestored ? { markRestored: true } : {}) };
1107
1304
  } catch (e) {
@@ -1122,11 +1319,52 @@ async function confirmAndApply(ctx, items, opts) {
1122
1319
  }) };
1123
1320
  }
1124
1321
  }
1125
- async function runInit(ctx, argv) {
1322
+ /** Every optional question for these CLIs that is not yet turned on. `enabled` throwing counts as on: nothing to offer. */
1323
+ async function pendingOptions(ctx, adapters) {
1324
+ const env = adapterEnv(ctx);
1325
+ const out = [];
1326
+ for (const a of adapters) for (const o of a.optional ?? []) {
1327
+ if (await o.enabled(env).catch(() => true)) continue;
1328
+ out.push({
1329
+ cli: a.cli,
1330
+ id: o.id,
1331
+ question: o.question
1332
+ });
1333
+ }
1334
+ return out;
1335
+ }
1336
+ /** The changes `with` has that `base` does not: a different file, or the same file with other text. */
1337
+ function extraChanges(base, withOpt) {
1338
+ const had = new Set(base.map((i) => `${i.change.path}\0${i.change.after}\0${i.change.kind}`));
1339
+ return withOpt.filter((i) => !had.has(`${i.change.path}\0${i.change.after}\0${i.change.kind}`));
1340
+ }
1341
+ /** `conveno setup` and its older name `conveno init`. Both end here. */
1342
+ async function runInit(ctx, argv, name = "init") {
1343
+ const first = COMMANDS.find((c) => c.name === name);
1344
+ const early = first ? parseFlags(ctx, first, argv) : void 0;
1345
+ if (typeof early === "number") return early;
1346
+ const lead = early?.values.lead;
1347
+ if (typeof lead === "string" && !CLI_KINDS.includes(lead)) {
1348
+ const suggestion = closest(lead, [...CLI_KINDS]);
1349
+ return fail(ctx, {
1350
+ what: `Unknown AI tool "${lead}" for --lead`,
1351
+ detail: [`Known AI tools: ${CLI_KINDS.join(", ")}.`],
1352
+ fix: `Pass ${cmd(ctx.theme, `--lead ${CLI_KINDS[0]}`)} or leave it out.`,
1353
+ ...suggestion ? { didYouMean: `Did you mean ${suggestion}?` } : {},
1354
+ exit: 2,
1355
+ ref: "e_usage"
1356
+ });
1357
+ }
1126
1358
  const outcome = {};
1127
- const code = await initSetup(ctx, argv, outcome);
1128
- if (code !== 0 || !outcome.offer) return code;
1129
- const spec = COMMANDS.find((c) => c.name === "init");
1359
+ const code = await initSetup(ctx, argv, outcome, name);
1360
+ if (code !== 0) return code;
1361
+ if (typeof lead === "string" && early?.values["dry-run"] !== true) {
1362
+ writeSettings(dataPaths(ctx.platform, ctx.dataDir).settings, { leadCli: lead });
1363
+ const shown = ctx.adapters.find((a) => a.cli === lead)?.displayName ?? lead;
1364
+ ctx.out(`${ctx.theme.status("ok")} ${shown} will lead when it starts and nobody else leads.\n`);
1365
+ }
1366
+ if (!outcome.offer) return code;
1367
+ const spec = COMMANDS.find((c) => c.name === name);
1130
1368
  const parsed = spec ? parseFlags(ctx, spec, argv) : void 0;
1131
1369
  const values = typeof parsed === "object" ? parsed.values : {};
1132
1370
  await offerAcpAdapters(ctx, {
@@ -1136,24 +1374,24 @@ async function runInit(ctx, argv) {
1136
1374
  });
1137
1375
  return 0;
1138
1376
  }
1139
- async function initSetup(ctx, argv, outcome) {
1377
+ async function initSetup(ctx, argv, outcome, name) {
1140
1378
  const t = ctx.theme;
1141
1379
  const started = ctx.now();
1142
- const spec = COMMANDS.find((c) => c.name === "init");
1380
+ const spec = COMMANDS.find((c) => c.name === name);
1143
1381
  if (!spec) return 2;
1144
1382
  const parsed = parseFlags(ctx, spec, argv);
1145
1383
  if (typeof parsed === "number") return parsed;
1146
1384
  const values = parsed.values;
1147
1385
  if (values["acp-adapters"] === true && values["no-acp-adapters"] === true) return fail(ctx, {
1148
1386
  what: "Use --acp-adapters or --no-acp-adapters, not both",
1149
- fix: `Run ${cmd(t, "conveno init --help")} to see the options.`,
1387
+ fix: `Run ${cmd(t, `conveno ${name} --help`)} to see the options.`,
1150
1388
  exit: 2,
1151
1389
  ref: "e_usage"
1152
1390
  });
1153
1391
  const chosen = parseCliList(typeof values.cli === "string" ? values.cli : void 0, ctx);
1154
1392
  if (!Array.isArray(chosen)) return fail(ctx, {
1155
1393
  what: chosen.message,
1156
- fix: `Pass ${cmd(t, "--cli claude,codex,opencode")} or leave it out.`,
1394
+ fix: `Pass ${cmd(t, cliListExample(ctx))} or leave it out.`,
1157
1395
  ...chosen.suggestion ? { didYouMean: chosen.suggestion } : {},
1158
1396
  exit: 2,
1159
1397
  ref: "e_usage"
@@ -1162,38 +1400,73 @@ async function initSetup(ctx, argv, outcome) {
1162
1400
  printDetections(ctx, found);
1163
1401
  const installed = found.filter((f) => f.detection.installed);
1164
1402
  if (installed.length === 0) return fail(ctx, {
1165
- what: "No supported AI coding CLI was found",
1403
+ what: "No supported AI tool was found",
1166
1404
  detail: [`Looked for ${chosen.map((a) => a.displayName).join(", ")} on PATH.`],
1167
- fix: "Install one of them, then run conveno init again.",
1405
+ fix: `Install one of them, then run conveno ${name} again.`,
1168
1406
  exit: 1,
1169
1407
  ref: "e_no_cli"
1170
1408
  });
1171
- const { items, failures } = await collectPlans(ctx, installed, "plan");
1409
+ const accepted = /* @__PURE__ */ new Set();
1410
+ const acceptRaw = typeof values.accept === "string" ? values.accept : void 0;
1411
+ if (acceptRaw !== void 0) {
1412
+ const known = new Set(ctx.adapters.flatMap((a) => (a.optional ?? []).map((o) => o.id)));
1413
+ for (const id of acceptRaw.split(/[\s,]+/).filter(Boolean)) {
1414
+ if (!known.has(id)) return fail(ctx, {
1415
+ what: `Unknown option "${id}" for --accept`,
1416
+ detail: [known.size > 0 ? `Known: ${[...known].join(", ")}.` : "There are none."],
1417
+ fix: `Run ${cmd(t, `conveno ${name} --help`)} to see the options.`,
1418
+ exit: 2,
1419
+ ref: "e_usage"
1420
+ });
1421
+ accepted.add(id);
1422
+ }
1423
+ }
1424
+ const pending = await pendingOptions(ctx, installed.map((f) => f.adapter));
1425
+ const dryRun = Boolean(values["dry-run"]);
1426
+ for (const o of pending) {
1427
+ if (accepted.has(o.id)) continue;
1428
+ if (dryRun || values.yes === true || !ctx.interactive) continue;
1429
+ if (await ctx.confirm(o.question, false)) accepted.add(o.id);
1430
+ }
1431
+ const { items, failures } = await collectPlans(ctx, installed, "plan", void 0, [...accepted]);
1172
1432
  if (failures.length > 0) {
1173
- reportFailures(ctx, failures, "conveno init --cli <others>");
1433
+ reportFailures(ctx, failures, `conveno ${name} --cli <others>`);
1174
1434
  return 1;
1175
1435
  }
1176
- if (items.length === 0) {
1436
+ const extras = [];
1437
+ if (dryRun) for (const o of pending) {
1438
+ if (accepted.has(o.id)) continue;
1439
+ const more = extraChanges(items, (await collectPlans(ctx, installed, "plan", void 0, [...accepted, o.id])).items);
1440
+ if (more.length > 0) extras.push({
1441
+ option: o,
1442
+ items: more
1443
+ });
1444
+ }
1445
+ if (items.length === 0 && extras.length === 0) {
1177
1446
  ctx.out(`${t.status("ok")} Conveno is already set up for ${installed.map((f) => f.adapter.cli).join(", ")}. Nothing to change.\n`);
1178
1447
  outcome.offer = installed.map((f) => f.adapter);
1179
1448
  return 0;
1180
1449
  }
1181
- if (values["dry-run"]) {
1450
+ if (dryRun) {
1182
1451
  const files = new Set(items.map((i) => i.change.path)).size;
1183
1452
  ctx.out(`${t.bold(`Conveno would change ${plural(files, "file")}.`)} Nothing else is touched.\n\n`);
1184
1453
  presentChanges(ctx, items);
1185
- ctx.out(`${t.status("info")} Dry run: nothing was written. Run ${cmd(t, "conveno init")} to apply.\n`);
1454
+ for (const x of extras) {
1455
+ ctx.out(`${t.bold(x.option.question)}\n ${t.paint("quiet", `Not turned on. With --accept ${x.option.id} Conveno would also change:`)}\n\n`);
1456
+ presentChanges(ctx, x.items);
1457
+ }
1458
+ ctx.out(`${t.status("info")} Dry run: nothing was written. Run ${cmd(t, `conveno ${name}`)} to apply.\n`);
1186
1459
  return 0;
1187
1460
  }
1188
1461
  const result = await confirmAndApply(ctx, items, {
1189
1462
  yes: values.yes === true,
1190
1463
  verb: "Apply",
1191
- rerun: "conveno init"
1464
+ rerun: `conveno ${name}`
1192
1465
  });
1193
1466
  if ("exit" in result) return result.exit;
1194
1467
  const byCli = /* @__PURE__ */ new Map();
1195
1468
  for (const h of result.applied.how) byCli.set(h.cli, [...byCli.get(h.cli) ?? [], h.via]);
1196
- const rows = [...byCli].map(([cli, vias]) => [` ${t.status("ok")} ${cli}`, vias.every((v) => v === "command") ? "configured with the CLI's own command" : "configured"]);
1469
+ const rows = [...byCli].map(([cli, vias]) => [` ${t.status("ok")} ${cli}`, vias.every((v) => v === "command") ? "set up with its own command" : "configured"]);
1197
1470
  ctx.out(`${columns(rows).join("\n")}\n\n`);
1198
1471
  ctx.out(`${t.status("ok")} ${t.bold("Done.")} ${seconds(started, ctx.now())}\n`);
1199
1472
  ctx.out(` Backups are in ${tilde(result.applied.backupDir, ctx.home)}.\n`);
@@ -1204,6 +1477,19 @@ async function initSetup(ctx, argv, outcome) {
1204
1477
  outcome.offer = installed.map((f) => f.adapter);
1205
1478
  return 0;
1206
1479
  }
1480
+ /**
1481
+ * `conveno setup`. In a terminal with no --yes it opens the onboarding in the app. Anywhere else
1482
+ * it does what `conveno init` does, and also saves --lead.
1483
+ */
1484
+ async function runSetup(ctx, argv) {
1485
+ const spec = COMMANDS.find((c) => c.name === "setup");
1486
+ if (!spec) return 2;
1487
+ const parsed = parseFlags(ctx, spec, argv);
1488
+ if (typeof parsed === "number") return parsed;
1489
+ const v = parsed.values;
1490
+ if (ctx.interactive && v.yes !== true && v["dry-run"] !== true) return (await import("./run-C32oP2c_.js")).runTui(ctx, { start: "setup" });
1491
+ return runInit(ctx, argv, "setup");
1492
+ }
1207
1493
  // src/doctor.ts
1208
1494
  /** What the plan says about one part: nothing to do, an addition, or an update to what is there. */
1209
1495
  function partState(changes, component) {
@@ -1220,7 +1506,11 @@ const hasAny = (c) => c !== void 0 && (c.nextTurn || c.endOfTurn || c.idleWake);
1220
1506
  * once its hooks (or plugin) are in place. Without them only the inbox tool is left.
1221
1507
  */
1222
1508
  function activeTiers(row) {
1223
- const caps = row.adapter.delivery?.(row.detection);
1509
+ const base = row.adapter.delivery?.(row.detection);
1510
+ const caps = base && row.idleWake !== void 0 ? {
1511
+ ...base,
1512
+ idleWake: base.idleWake && row.idleWake
1513
+ } : base;
1224
1514
  if (!caps) return row.adapter.deliveryTier === "inbox" || row.hooks === "ok" ? [tierWord(row.adapter.deliveryTier)] : ["inbox"];
1225
1515
  if (!hasAny(caps) || row.hooks !== "ok") return ["inbox"];
1226
1516
  return [
@@ -1247,6 +1537,12 @@ async function inspect(ctx, adapter) {
1247
1537
  hooks: null
1248
1538
  };
1249
1539
  const hasHooks = adapter.deliveryTier !== "inbox" || hasAny(adapter.delivery?.(detection));
1540
+ let idleWake;
1541
+ if (adapter.optional && adapter.optional.length > 0) {
1542
+ idleWake = true;
1543
+ for (const o of adapter.optional) if (!await o.enabled(env).catch(() => false)) idleWake = false;
1544
+ }
1545
+ const adapterNotes = await adapter.doctorNotes?.(env).catch(() => []);
1250
1546
  try {
1251
1547
  const changes = await adapter.plan(env);
1252
1548
  return {
@@ -1254,7 +1550,9 @@ async function inspect(ctx, adapter) {
1254
1550
  detection,
1255
1551
  mcp: partState(changes, "mcp"),
1256
1552
  hooks: hasHooks ? partState(changes, "hooks") : null,
1257
- changes
1553
+ changes,
1554
+ ...idleWake === void 0 ? {} : { idleWake },
1555
+ ...adapterNotes?.length ? { adapterNotes } : {}
1258
1556
  };
1259
1557
  } catch (e) {
1260
1558
  return {
@@ -1262,7 +1560,9 @@ async function inspect(ctx, adapter) {
1262
1560
  detection,
1263
1561
  mcp: "missing",
1264
1562
  hooks: hasHooks ? "missing" : null,
1265
- planError: plainError(e)
1563
+ planError: plainError(e),
1564
+ ...idleWake === void 0 ? {} : { idleWake },
1565
+ ...adapterNotes?.length ? { adapterNotes } : {}
1266
1566
  };
1267
1567
  }
1268
1568
  }
@@ -1298,7 +1598,7 @@ async function runDoctor(ctx, argv = []) {
1298
1598
  const chosen = parseCliList(typeof parsed.values.cli === "string" ? parsed.values.cli : void 0, ctx);
1299
1599
  if (!Array.isArray(chosen)) return fail(ctx, {
1300
1600
  what: chosen.message,
1301
- fix: `Pass ${cmd(t, "--cli claude,codex,opencode")} or leave it out.`,
1601
+ fix: `Pass ${cmd(t, cliListExample(ctx))} or leave it out.`,
1302
1602
  ...chosen.suggestion ? { didYouMean: chosen.suggestion } : {},
1303
1603
  exit: 2,
1304
1604
  ref: "e_usage"
@@ -1385,6 +1685,7 @@ async function runDoctor(ctx, argv = []) {
1385
1685
  tiers.join(", "),
1386
1686
  q(note)
1387
1687
  ]);
1688
+ for (const line of r.adapterNotes ?? []) notes.push(`${q(`${adapter.displayName}:`)} ${line}`);
1388
1689
  if (r.planError) {
1389
1690
  problems++;
1390
1691
  notes.push(errorBlock(t, {
@@ -1423,4 +1724,137 @@ async function runDoctor(ctx, argv = []) {
1423
1724
  ctx.out(`\n${ok} ok, ${plural(warnings, "warning")}, ${plural(problems, "problem")}\n`);
1424
1725
  return problems > 0 ? 1 : 0;
1425
1726
  }
1426
- export { runLogout as S, runDevices as _, detectAll as a, runAccount as b, staleFailure as c, listManifests as d, markRestored as f, PAIR_TIMEOUT_MS as g, unifiedDiff as h, confirmAndApply as i, StaleError as l, restoreEntry as m, runDoctor as n, reportFailures as o, previewRestore as p, collectPlans as r, runInit as s, inspect as t, applyChanges as u, runRelay as v, runLogin as x, openInBrowser as y };
1727
+ // src/uninstall.ts
1728
+ const NOTE = {
1729
+ restore: "restored byte for byte",
1730
+ remove: "removed, it did not exist before",
1731
+ edit: "edited since setup, so only Conveno's entries are removed",
1732
+ gone: "already gone, left as it is"
1733
+ };
1734
+ /**
1735
+ * The files as init found them, from the backups: their text, or null when they did not exist. A
1736
+ * backup that cannot be read leaves its file out, and the adapter then treats what it finds as
1737
+ * Conveno's own.
1738
+ */
1739
+ async function baselineOf(dir, entries) {
1740
+ const out = /* @__PURE__ */ new Map();
1741
+ for (const e of entries) if (e.backup === null) out.set(e.path, null);
1742
+ else try {
1743
+ out.set(e.path, await readFile(join(dir, e.backup), "utf8"));
1744
+ } catch {}
1745
+ return out;
1746
+ }
1747
+ /** Remove Conveno's own entries from files that changed since init, through each adapter. */
1748
+ async function removeOwnEntries(ctx, dir, entries) {
1749
+ if (entries.length === 0) return {
1750
+ edited: [],
1751
+ failures: []
1752
+ };
1753
+ const clis = new Set(entries.map((e) => e.cli));
1754
+ const { items, failures } = await collectPlans(ctx, (await detectAll(ctx)).filter((f) => clis.has(f.adapter.cli)), "uninstallPlan", await baselineOf(dir, entries));
1755
+ const wanted = new Set(entries.map((e) => e.path));
1756
+ const mine = items.filter((i) => wanted.has(i.change.path));
1757
+ if (mine.length > 0) await applyChanges(ctx, mine, { markRestored: true });
1758
+ return {
1759
+ edited: mine.map((i) => i.change.path),
1760
+ failures
1761
+ };
1762
+ }
1763
+ async function restoreAll(ctx, manifests) {
1764
+ const restored = [];
1765
+ const edited = [];
1766
+ const untouched = [];
1767
+ for (const found of manifests) {
1768
+ const needEdit = [];
1769
+ for (const entry of found.manifest.entries) {
1770
+ const action = await restoreEntry(found.dir, entry);
1771
+ if (action === "edit") needEdit.push(entry);
1772
+ else if (action === "gone") untouched.push(entry.path);
1773
+ else restored.push(entry.path);
1774
+ }
1775
+ const r = await removeOwnEntries(ctx, found.dir, needEdit);
1776
+ if (r.failures.length > 0) {
1777
+ reportFailures(ctx, r.failures, "conveno uninstall");
1778
+ throw new Error("A config file could not be read, so it was left as it is.");
1779
+ }
1780
+ edited.push(...r.edited);
1781
+ for (const e of needEdit) if (!r.edited.includes(e.path)) untouched.push(e.path);
1782
+ await markRestored(ctx, found);
1783
+ }
1784
+ return {
1785
+ restored,
1786
+ edited,
1787
+ untouched
1788
+ };
1789
+ }
1790
+ async function runUninstall(ctx, argv) {
1791
+ const t = ctx.theme;
1792
+ const started = ctx.now();
1793
+ const spec = COMMANDS.find((c) => c.name === "uninstall");
1794
+ if (!spec) return 2;
1795
+ const parsed = parseFlags(ctx, spec, argv);
1796
+ if (typeof parsed === "number") return parsed;
1797
+ const yes = parsed.values.yes === true;
1798
+ const manifests = await listManifests(ctx).catch(() => []);
1799
+ if (manifests.length > 0) {
1800
+ const rows = await previewRestore(manifests);
1801
+ const made = manifests.map((m) => localStamp(m.manifest.createdAt));
1802
+ ctx.out(`${t.bold(`Conveno will undo ${plural(manifests.length, "install")}`)}, made ${made.join(", ")} (local time).\n\n`);
1803
+ ctx.out(`${columns(rows.map((r) => [` ${tilde(r.entry.path, ctx.home)}`, t.paint("quiet", NOTE[r.action])])).join("\n")}\n\n`);
1804
+ if (!yes) {
1805
+ if (!ctx.interactive) return fail(ctx, {
1806
+ what: "Needs a terminal to confirm",
1807
+ detail: ["No files were changed."],
1808
+ fix: `Run ${cmd(t, "conveno uninstall --yes")} to undo the changes listed above.`,
1809
+ exit: 2,
1810
+ ref: "e_no_tty"
1811
+ });
1812
+ if (!await ctx.confirm("Undo these changes?", false)) {
1813
+ ctx.out(`${t.status("info")} Nothing was changed.\n`);
1814
+ return 0;
1815
+ }
1816
+ }
1817
+ const stopped = await stopDaemonIfRunning(ctx);
1818
+ if (stopped !== 0) return stopped;
1819
+ let result;
1820
+ try {
1821
+ result = await restoreAll(ctx, manifests);
1822
+ } catch (e) {
1823
+ if (e instanceof StaleError) return staleFailure(ctx, e, "conveno uninstall");
1824
+ return fail(ctx, {
1825
+ what: "Could not restore a file",
1826
+ detail: [plainError(e), `The backups are still in ${tilde(manifests[0]?.dir ?? ctx.dataDir, ctx.home)} and the other backup folders next to it.`],
1827
+ fix: "Fix the problem above, then run conveno uninstall again.",
1828
+ exit: 1,
1829
+ ref: "e_restore"
1830
+ });
1831
+ }
1832
+ ctx.out(`${t.status("ok")} ${t.bold("Done.")} ${seconds(started, ctx.now())}\n`);
1833
+ ctx.out(` Restored ${plural(result.restored.length, "file")} to how they were before setup.\n`);
1834
+ if (result.edited.length > 0) ctx.out(` Edited, not restored, because they changed since setup: ${result.edited.map((p) => tilde(p, ctx.home)).join(", ")}. Only Conveno's entries were removed.\n`);
1835
+ ctx.out(" Restart open sessions to drop Conveno.\n");
1836
+ return 0;
1837
+ }
1838
+ const { items, failures } = await collectPlans(ctx, await detectAll(ctx), "uninstallPlan");
1839
+ if (failures.length > 0) {
1840
+ reportFailures(ctx, failures, "conveno uninstall");
1841
+ return 1;
1842
+ }
1843
+ if (items.length === 0) {
1844
+ ctx.out(`${t.status("ok")} Nothing to remove. No Conveno entries were found in any supported CLI.\n`);
1845
+ return 0;
1846
+ }
1847
+ ctx.out(`${t.status("info")} No install backup found, so Conveno will remove only its own entries.\n\n`);
1848
+ const result = await confirmAndApply(ctx, items, {
1849
+ yes,
1850
+ verb: "Remove",
1851
+ rerun: "conveno uninstall",
1852
+ markRestored: true,
1853
+ beforeApply: () => stopDaemonIfRunning(ctx)
1854
+ });
1855
+ if ("exit" in result) return result.exit;
1856
+ ctx.out(`${t.status("ok")} ${t.bold("Done.")} ${seconds(started, ctx.now())}\n`);
1857
+ ctx.out(" Removed the Conveno entries. Restart open sessions to drop Conveno.\n");
1858
+ return 0;
1859
+ }
1860
+ export { showCode as S, stopDaemonIfRunning as _, collectPlans as a, runLogin as b, runInit as c, applyChanges as d, unifiedDiff as f, runDaemon as g, runRelay as h, runDoctor as i, runSetup as l, runDevices as m, inspect as n, detectAll as o, PAIR_TIMEOUT_MS as p, partState as r, pendingOptions as s, runUninstall as t, StaleError as u, openInBrowser as v, runLogout as x, runAccount as y };