@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.
@@ -2,7 +2,7 @@ import { randomBytes as randomBytes$1 } from "@noble/ciphers/utils.js";
2
2
  import { equalBytes } from "@noble/curves/utils.js";
3
3
  import { sha256 } from "@noble/hashes/sha2.js";
4
4
  import { bytesToHex, concatBytes, utf8ToBytes } from "@noble/hashes/utils.js";
5
- import { An as string, Cn as _enum, Dn as literal, En as discriminatedUnion, On as number, Yt as DeviceId, kn as object, wn as array } from "./dist-BTLBO1Rp.js";
5
+ import { An as literal, Dn as array, En as _enum, Mn as object, Nn as string, Qt as DeviceId, jn as number, kn as discriminatedUnion } from "./dist-D2hMvcZu.js";
6
6
  import { ed25519, x25519 } from "@noble/curves/ed25519.js";
7
7
  import { chacha20poly1305 } from "@noble/ciphers/chacha.js";
8
8
  import { expand, extract } from "@noble/hashes/hkdf.js";
@@ -1,8 +1,8 @@
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-D2hMvcZu.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 { i as parseFlags, t as COMMANDS } from "./args-C7Agak9f.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-DNAKEyRT.js";
6
6
  import { basename, dirname, join } from "node:path";
7
7
  import { spawn } from "node:child_process";
8
8
  import { chmod, mkdir, open, readFile, readdir, realpath, rename as rename$1, rm, rmdir, stat, writeFile } from "node:fs/promises";
@@ -881,7 +881,11 @@ async function applyChanges(ctx, items, opts = {}) {
881
881
  await currentIfUnchanged(change);
882
882
  if (change.deleteFile) {
883
883
  await io.rm(change.path);
884
- if (change.pruneEmptyDir) await rmdir(dirname(change.path)).catch(() => void 0);
884
+ let dir = dirname(change.path);
885
+ for (let n = change.pruneEmptyDir === true ? 1 : change.pruneEmptyDir ?? 0; n > 0; n--) {
886
+ if (!await rmdir(dir).then(() => true, () => false)) break;
887
+ dir = dirname(dir);
888
+ }
885
889
  } else await writeAtomic(change.path, change.after, io);
886
890
  }
887
891
  how.push({
@@ -1013,9 +1017,11 @@ async function detectAll(ctx, adapters = ctx.adapters) {
1013
1017
  }
1014
1018
  }));
1015
1019
  }
1020
+ /** The `--cli` example in error fixes: every CLI this version supports. */
1021
+ const cliListExample = (ctx) => `--cli ${ctx.adapters.map((a) => a.cli).join(",")}`;
1016
1022
  function parseCliList(raw, ctx) {
1017
1023
  if (raw === void 0) return ctx.adapters;
1018
- const names = raw.split(",").map((s) => s.trim()).filter(Boolean);
1024
+ const names = raw.split(/[\s,]+/).filter(Boolean);
1019
1025
  const out = [];
1020
1026
  for (const n of names) {
1021
1027
  if (!CLI_KINDS.includes(n)) {
@@ -1043,12 +1049,12 @@ function printDetections(ctx, found) {
1043
1049
  ctx.out(`${columns(rows).join("\n")}\n\n`);
1044
1050
  }
1045
1051
  /** Collect plans from installed adapters. Returns failures instead of throwing. */
1046
- async function collectPlans(ctx, found, which, baseline) {
1052
+ async function collectPlans(ctx, found, which, baseline, accept = []) {
1047
1053
  const env = adapterEnv(ctx);
1048
1054
  const items = [];
1049
1055
  const failures = [];
1050
1056
  for (const { adapter, detection } of found) try {
1051
- for (const change of await (which === "plan" ? adapter.plan(env) : adapter.uninstallPlan(env, baseline))) items.push({
1057
+ for (const change of await (which === "plan" ? adapter.plan(env, { accept }) : adapter.uninstallPlan(env, baseline))) items.push({
1052
1058
  cli: adapter.cli,
1053
1059
  installed: detection.installed,
1054
1060
  change
@@ -1122,6 +1128,25 @@ async function confirmAndApply(ctx, items, opts) {
1122
1128
  }) };
1123
1129
  }
1124
1130
  }
1131
+ /** Every optional question for these CLIs that is not yet turned on. `enabled` throwing counts as on: nothing to offer. */
1132
+ async function pendingOptions(ctx, adapters) {
1133
+ const env = adapterEnv(ctx);
1134
+ const out = [];
1135
+ for (const a of adapters) for (const o of a.optional ?? []) {
1136
+ if (await o.enabled(env).catch(() => true)) continue;
1137
+ out.push({
1138
+ cli: a.cli,
1139
+ id: o.id,
1140
+ question: o.question
1141
+ });
1142
+ }
1143
+ return out;
1144
+ }
1145
+ /** The changes `with` has that `base` does not: a different file, or the same file with other text. */
1146
+ function extraChanges(base, withOpt) {
1147
+ const had = new Set(base.map((i) => `${i.change.path}\0${i.change.after}\0${i.change.kind}`));
1148
+ return withOpt.filter((i) => !had.has(`${i.change.path}\0${i.change.after}\0${i.change.kind}`));
1149
+ }
1125
1150
  async function runInit(ctx, argv) {
1126
1151
  const outcome = {};
1127
1152
  const code = await initSetup(ctx, argv, outcome);
@@ -1153,7 +1178,7 @@ async function initSetup(ctx, argv, outcome) {
1153
1178
  const chosen = parseCliList(typeof values.cli === "string" ? values.cli : void 0, ctx);
1154
1179
  if (!Array.isArray(chosen)) return fail(ctx, {
1155
1180
  what: chosen.message,
1156
- fix: `Pass ${cmd(t, "--cli claude,codex,opencode")} or leave it out.`,
1181
+ fix: `Pass ${cmd(t, cliListExample(ctx))} or leave it out.`,
1157
1182
  ...chosen.suggestion ? { didYouMean: chosen.suggestion } : {},
1158
1183
  exit: 2,
1159
1184
  ref: "e_usage"
@@ -1168,20 +1193,55 @@ async function initSetup(ctx, argv, outcome) {
1168
1193
  exit: 1,
1169
1194
  ref: "e_no_cli"
1170
1195
  });
1171
- const { items, failures } = await collectPlans(ctx, installed, "plan");
1196
+ const accepted = /* @__PURE__ */ new Set();
1197
+ const acceptRaw = typeof values.accept === "string" ? values.accept : void 0;
1198
+ if (acceptRaw !== void 0) {
1199
+ const known = new Set(ctx.adapters.flatMap((a) => (a.optional ?? []).map((o) => o.id)));
1200
+ for (const id of acceptRaw.split(/[\s,]+/).filter(Boolean)) {
1201
+ if (!known.has(id)) return fail(ctx, {
1202
+ what: `Unknown option "${id}" for --accept`,
1203
+ detail: [known.size > 0 ? `Known: ${[...known].join(", ")}.` : "There are none."],
1204
+ fix: `Run ${cmd(t, "conveno init --help")} to see the options.`,
1205
+ exit: 2,
1206
+ ref: "e_usage"
1207
+ });
1208
+ accepted.add(id);
1209
+ }
1210
+ }
1211
+ const pending = await pendingOptions(ctx, installed.map((f) => f.adapter));
1212
+ const dryRun = Boolean(values["dry-run"]);
1213
+ for (const o of pending) {
1214
+ if (accepted.has(o.id)) continue;
1215
+ if (dryRun || values.yes === true || !ctx.interactive) continue;
1216
+ if (await ctx.confirm(o.question, false)) accepted.add(o.id);
1217
+ }
1218
+ const { items, failures } = await collectPlans(ctx, installed, "plan", void 0, [...accepted]);
1172
1219
  if (failures.length > 0) {
1173
1220
  reportFailures(ctx, failures, "conveno init --cli <others>");
1174
1221
  return 1;
1175
1222
  }
1176
- if (items.length === 0) {
1223
+ const extras = [];
1224
+ if (dryRun) for (const o of pending) {
1225
+ if (accepted.has(o.id)) continue;
1226
+ const more = extraChanges(items, (await collectPlans(ctx, installed, "plan", void 0, [...accepted, o.id])).items);
1227
+ if (more.length > 0) extras.push({
1228
+ option: o,
1229
+ items: more
1230
+ });
1231
+ }
1232
+ if (items.length === 0 && extras.length === 0) {
1177
1233
  ctx.out(`${t.status("ok")} Conveno is already set up for ${installed.map((f) => f.adapter.cli).join(", ")}. Nothing to change.\n`);
1178
1234
  outcome.offer = installed.map((f) => f.adapter);
1179
1235
  return 0;
1180
1236
  }
1181
- if (values["dry-run"]) {
1237
+ if (dryRun) {
1182
1238
  const files = new Set(items.map((i) => i.change.path)).size;
1183
1239
  ctx.out(`${t.bold(`Conveno would change ${plural(files, "file")}.`)} Nothing else is touched.\n\n`);
1184
1240
  presentChanges(ctx, items);
1241
+ for (const x of extras) {
1242
+ 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`);
1243
+ presentChanges(ctx, x.items);
1244
+ }
1185
1245
  ctx.out(`${t.status("info")} Dry run: nothing was written. Run ${cmd(t, "conveno init")} to apply.\n`);
1186
1246
  return 0;
1187
1247
  }
@@ -1220,7 +1280,11 @@ const hasAny = (c) => c !== void 0 && (c.nextTurn || c.endOfTurn || c.idleWake);
1220
1280
  * once its hooks (or plugin) are in place. Without them only the inbox tool is left.
1221
1281
  */
1222
1282
  function activeTiers(row) {
1223
- const caps = row.adapter.delivery?.(row.detection);
1283
+ const base = row.adapter.delivery?.(row.detection);
1284
+ const caps = base && row.idleWake !== void 0 ? {
1285
+ ...base,
1286
+ idleWake: base.idleWake && row.idleWake
1287
+ } : base;
1224
1288
  if (!caps) return row.adapter.deliveryTier === "inbox" || row.hooks === "ok" ? [tierWord(row.adapter.deliveryTier)] : ["inbox"];
1225
1289
  if (!hasAny(caps) || row.hooks !== "ok") return ["inbox"];
1226
1290
  return [
@@ -1247,6 +1311,12 @@ async function inspect(ctx, adapter) {
1247
1311
  hooks: null
1248
1312
  };
1249
1313
  const hasHooks = adapter.deliveryTier !== "inbox" || hasAny(adapter.delivery?.(detection));
1314
+ let idleWake;
1315
+ if (adapter.optional && adapter.optional.length > 0) {
1316
+ idleWake = true;
1317
+ for (const o of adapter.optional) if (!await o.enabled(env).catch(() => false)) idleWake = false;
1318
+ }
1319
+ const adapterNotes = await adapter.doctorNotes?.(env).catch(() => []);
1250
1320
  try {
1251
1321
  const changes = await adapter.plan(env);
1252
1322
  return {
@@ -1254,7 +1324,9 @@ async function inspect(ctx, adapter) {
1254
1324
  detection,
1255
1325
  mcp: partState(changes, "mcp"),
1256
1326
  hooks: hasHooks ? partState(changes, "hooks") : null,
1257
- changes
1327
+ changes,
1328
+ ...idleWake === void 0 ? {} : { idleWake },
1329
+ ...adapterNotes?.length ? { adapterNotes } : {}
1258
1330
  };
1259
1331
  } catch (e) {
1260
1332
  return {
@@ -1262,7 +1334,9 @@ async function inspect(ctx, adapter) {
1262
1334
  detection,
1263
1335
  mcp: "missing",
1264
1336
  hooks: hasHooks ? "missing" : null,
1265
- planError: plainError(e)
1337
+ planError: plainError(e),
1338
+ ...idleWake === void 0 ? {} : { idleWake },
1339
+ ...adapterNotes?.length ? { adapterNotes } : {}
1266
1340
  };
1267
1341
  }
1268
1342
  }
@@ -1298,7 +1372,7 @@ async function runDoctor(ctx, argv = []) {
1298
1372
  const chosen = parseCliList(typeof parsed.values.cli === "string" ? parsed.values.cli : void 0, ctx);
1299
1373
  if (!Array.isArray(chosen)) return fail(ctx, {
1300
1374
  what: chosen.message,
1301
- fix: `Pass ${cmd(t, "--cli claude,codex,opencode")} or leave it out.`,
1375
+ fix: `Pass ${cmd(t, cliListExample(ctx))} or leave it out.`,
1302
1376
  ...chosen.suggestion ? { didYouMean: chosen.suggestion } : {},
1303
1377
  exit: 2,
1304
1378
  ref: "e_usage"
@@ -1385,6 +1459,7 @@ async function runDoctor(ctx, argv = []) {
1385
1459
  tiers.join(", "),
1386
1460
  q(note)
1387
1461
  ]);
1462
+ for (const line of r.adapterNotes ?? []) notes.push(`${q(`${adapter.displayName}:`)} ${line}`);
1388
1463
  if (r.planError) {
1389
1464
  problems++;
1390
1465
  notes.push(errorBlock(t, {
@@ -1423,4 +1498,4 @@ async function runDoctor(ctx, argv = []) {
1423
1498
  ctx.out(`\n${ok} ok, ${plural(warnings, "warning")}, ${plural(problems, "problem")}\n`);
1424
1499
  return problems > 0 ? 1 : 0;
1425
1500
  }
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 };
1501
+ export { runLogout as C, runLogin as S, PAIR_TIMEOUT_MS as _, detectAll as a, openInBrowser as b, runInit as c, applyChanges as d, listManifests as f, unifiedDiff as g, restoreEntry as h, confirmAndApply as i, staleFailure as l, previewRestore as m, runDoctor as n, pendingOptions as o, markRestored as p, collectPlans as r, reportFailures as s, inspect as t, StaleError as u, runDevices as v, runAccount as x, runRelay as y };
@@ -40,11 +40,14 @@ async function findHostPid(ctx, client, cli, local) {
40
40
  * the message on stderr (Claude Code's `asyncRewake`). They stop on their own when the host CLI
41
41
  * exits, the session goes offline, or a newer listener replaces them.
42
42
  */
43
+ /** How long before the hook's timeout its messages count as too late to print. */
44
+ const DEADLINE_MARGIN_MS = 300;
43
45
  async function runHook(ctx, argv) {
44
46
  const [cli, event] = argv;
45
47
  const adapter = ctx.adapters.find((a) => a.cli === cli);
46
48
  if (!adapter || !event) return 0;
47
49
  const listener = adapter.listenEvents?.includes(event) === true;
50
+ const deadline = listener ? void 0 : Date.now() + ctx.hookTimeoutMs - DEADLINE_MARGIN_MS;
48
51
  let client;
49
52
  let timer;
50
53
  const early = ctx.hostLookup ? void 0 : ctx.ancestry(HOOK_ANCESTRY_TIMEOUT_MS);
@@ -65,7 +68,8 @@ async function runHook(ctx, argv) {
65
68
  client,
66
69
  hostPid,
67
70
  cli: adapter.cli,
68
- isAlive: ctx.isAlive
71
+ isAlive: ctx.isAlive,
72
+ ...deadline === void 0 ? {} : { deadline }
69
73
  });
70
74
  })();
71
75
  const timeout = listener ? new Promise(() => void 0) : new Promise((resolve) => {