@conveno/cli 0.2.0-rc.1 → 0.2.0-rc.3
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.
- package/README.md +1 -1
- package/dist/acp-BD19nka6.js +142 -0
- package/dist/{args-DHkLY6_f.js → args-DEYV4Ran.js} +6 -2
- package/dist/bin.js +4 -4
- package/dist/ctx-CDLE-2f2.js +18 -0
- package/dist/daemon.js +160 -68
- package/dist/{dist-DsRTUePN.js → dist-B3mH66Y1.js} +5 -1
- package/dist/{dist-D8gPpZKN.js → dist-B7znzc5U.js} +3 -2
- package/dist/dist-BRjg9CLd.js +731 -0
- package/dist/{acp-BlKK0v-B.js → dist-BiAm0SS8.js} +5 -143
- package/dist/{dist-CWvQqhPj.js → dist-DIJhGLVn.js} +1 -1
- package/dist/{dist-_qrCNXUP.js → dist-M9Gs7e_K.js} +78 -27
- package/dist/{main-sIWDc4jt.js → doctor-D1sP9gCl.js} +245 -1650
- package/dist/{hook-bfp9_AVT.js → hook-W7tV131z.js} +3 -19
- package/dist/hook-entry-B8Iiwe99.js +1 -0
- package/dist/{hook-entry-RlH2cG3S.js → hook-entry-CvmuMVWY.js} +4 -4
- package/dist/main-Cf0q06gR.js +1448 -0
- package/dist/run-BlRhoflZ.js +4173 -0
- package/dist/{runtime-5nEur1P5.js → runtime-BPG36vYD.js} +13 -741
- package/package.json +19 -15
- package/dist/hook-entry-Daxws9EC.js +0 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { At as readSettings,
|
|
2
|
-
import {
|
|
3
|
-
import { a as closest, c as errorBlock, d as plainError, f as plural, h as warnBlock, i as parseFlags, l as fail, m as tilde,
|
|
4
|
-
import { n as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
1
|
+
import { At as readSettings, D as compatStatus, G as fetchAccountStatus, It as requestDeviceCode, K as findOnPath, Lt as resolveAcpProgram, N as dataPaths, O as completeLogin, St as pollDeviceCode, Tt as readAccountTokens, bt as pinnedAdapter, f as acpOverrideVar, g as adapterNpxCommand, h as adapterInstallCommand, in as writeSettings, l as SPAWN_TABLE, n as AccountError, on as CLI_KINDS, st as logoutAccount } from "./dist-M9Gs7e_K.js";
|
|
2
|
+
import { t as ClientError } from "./dist-B3mH66Y1.js";
|
|
3
|
+
import { a as closest, c as errorBlock, d as plainError, f as plural, h as warnBlock, i as parseFlags, l as fail, m as tilde, o as cmd, p as seconds, s as columns, t as COMMANDS, u as localStamp } from "./args-DEYV4Ran.js";
|
|
4
|
+
import { n as connectOpts, t as adapterEnv } from "./ctx-CDLE-2f2.js";
|
|
5
|
+
import { basename, dirname, join } from "node:path";
|
|
6
|
+
import { chmod, mkdir, open, readFile, readdir, realpath, rename as rename$1, rm, stat, writeFile } from "node:fs/promises";
|
|
8
7
|
import { createHash, randomBytes } from "node:crypto";
|
|
9
|
-
import {
|
|
8
|
+
import { spawn } from "node:child_process";
|
|
10
9
|
// src/account.ts
|
|
11
10
|
const accountIo = (ctx, io) => ({
|
|
12
11
|
apiBase: ctx.env.CONVENO_API_URL || "https://api.conveno.dev",
|
|
@@ -203,452 +202,6 @@ function daemonProblem(t, e) {
|
|
|
203
202
|
};
|
|
204
203
|
}
|
|
205
204
|
}
|
|
206
|
-
// src/status.ts
|
|
207
|
-
const CLI_SHORT = {
|
|
208
|
-
claude: "cl",
|
|
209
|
-
codex: "cx",
|
|
210
|
-
opencode: "oc",
|
|
211
|
-
antigravity: "ag",
|
|
212
|
-
cursor: "cu",
|
|
213
|
-
copilot: "cp",
|
|
214
|
-
grok: "gk"
|
|
215
|
-
};
|
|
216
|
-
const pad2 = (n) => String(n).padStart(2, "0");
|
|
217
|
-
/** Local `HH:MM:SS`, with the date in front when it is not today. */
|
|
218
|
-
function stamp(iso, now) {
|
|
219
|
-
const d = new Date(iso);
|
|
220
|
-
const time = `${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`;
|
|
221
|
-
const day = `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`;
|
|
222
|
-
return day === `${now.getFullYear()}-${pad2(now.getMonth() + 1)}-${pad2(now.getDate())}` ? time : `${day} ${time}`;
|
|
223
|
-
}
|
|
224
|
-
function tierText(theme, tier) {
|
|
225
|
-
switch (tier) {
|
|
226
|
-
case "live": return theme.paint("entry", "live");
|
|
227
|
-
case "next_turn": return "next turn";
|
|
228
|
-
case "acp": return "ACP";
|
|
229
|
-
case "inbox": return theme.paint("quiet", "inbox");
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
function stateCell(theme, s) {
|
|
233
|
-
if (s.status === "offline") return {
|
|
234
|
-
glyph: theme.status("offline"),
|
|
235
|
-
word: "offline"
|
|
236
|
-
};
|
|
237
|
-
if (s.status === "waiting_on_question") return {
|
|
238
|
-
glyph: theme.status("waiting"),
|
|
239
|
-
word: "waiting"
|
|
240
|
-
};
|
|
241
|
-
if (s.isOrchestrator) return {
|
|
242
|
-
glyph: theme.status("orchestrator"),
|
|
243
|
-
word: s.status
|
|
244
|
-
};
|
|
245
|
-
if (s.status === "busy") return {
|
|
246
|
-
glyph: theme.glyph("busy"),
|
|
247
|
-
word: "busy"
|
|
248
|
-
};
|
|
249
|
-
return {
|
|
250
|
-
glyph: theme.status("idle"),
|
|
251
|
-
word: "idle"
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
/** `on`, `off` or `paused by limit`. */
|
|
255
|
-
function autoText(theme, s) {
|
|
256
|
-
if (s.auto === true && s.autoPausedBy !== void 0) return theme.paint("warn", pauseLabel(s.autoPausedBy));
|
|
257
|
-
return s.auto === true ? "on" : theme.paint("quiet", "off");
|
|
258
|
-
}
|
|
259
|
-
/** Sessions grouped by repository, the way brand/components/terminal.md lays them out. */
|
|
260
|
-
function renderSessions(ctx, sessions) {
|
|
261
|
-
const t = ctx.theme;
|
|
262
|
-
const now = ctx.now();
|
|
263
|
-
const groups = /* @__PURE__ */ new Map();
|
|
264
|
-
const keyOf = (s) => s.remote ? `${s.repo?.root ?? s.cwd}\u0000${s.deviceName ?? ""}` : s.repo?.root ?? s.cwd;
|
|
265
|
-
for (const s of sessions) {
|
|
266
|
-
const key = keyOf(s);
|
|
267
|
-
groups.set(key, [...groups.get(key) ?? [], s]);
|
|
268
|
-
}
|
|
269
|
-
const blocks = [];
|
|
270
|
-
for (const key of [...groups.keys()].sort()) {
|
|
271
|
-
const list = (groups.get(key) ?? []).sort((a, b) => a.name.localeCompare(b.name));
|
|
272
|
-
const q = (w) => t.paint("quiet", w);
|
|
273
|
-
const head = [
|
|
274
|
-
` ${q("SESSION")}`,
|
|
275
|
-
q("CLI"),
|
|
276
|
-
q("TIER"),
|
|
277
|
-
q("STATE"),
|
|
278
|
-
q("AUTO"),
|
|
279
|
-
q("UNREAD"),
|
|
280
|
-
q("LAST SEEN")
|
|
281
|
-
];
|
|
282
|
-
const rows = list.map((s) => {
|
|
283
|
-
const st = stateCell(t, s);
|
|
284
|
-
return [
|
|
285
|
-
`${st.glyph} ${t.bold(s.name)}`,
|
|
286
|
-
CLI_SHORT[s.cli] ?? s.cli,
|
|
287
|
-
tierText(t, s.deliveryTier),
|
|
288
|
-
st.word,
|
|
289
|
-
autoText(t, s),
|
|
290
|
-
s.unreadCount ? String(s.unreadCount) : q("0"),
|
|
291
|
-
t.paint("quiet", stamp(s.lastSeenAt, now)),
|
|
292
|
-
...s.isOrchestrator ? [t.paint("entry", "orchestrator")] : [],
|
|
293
|
-
...s.spawned || s.spawnedBy ? [t.paint("quiet", "spawned")] : []
|
|
294
|
-
];
|
|
295
|
-
});
|
|
296
|
-
const [headLine, ...rowLines] = columns([head, ...rows]);
|
|
297
|
-
const [path, device] = key.split("\0");
|
|
298
|
-
const title = device === void 0 ? t.bold(tilde(key, ctx.home)) : `${t.bold(path ?? "")} ${t.paint("quiet", `on ${device || "another device"}`)}`;
|
|
299
|
-
blocks.push([
|
|
300
|
-
` ${title}`,
|
|
301
|
-
` ${headLine}`,
|
|
302
|
-
...rowLines.map((l) => ` ${l}`)
|
|
303
|
-
].join("\n"));
|
|
304
|
-
}
|
|
305
|
-
return blocks.join("\n\n");
|
|
306
|
-
}
|
|
307
|
-
/** The relay part of the status header line. */
|
|
308
|
-
function relaySummary(r) {
|
|
309
|
-
if (!r) return "off (local only)";
|
|
310
|
-
switch (r.state) {
|
|
311
|
-
case "connected": {
|
|
312
|
-
const online = r.peers.filter((p) => p.online).length;
|
|
313
|
-
return `connected (${plural(online, "other device")} online)`;
|
|
314
|
-
}
|
|
315
|
-
case "connecting": return "connecting";
|
|
316
|
-
case "disconnected": return "disconnected, retrying";
|
|
317
|
-
case "revoked": return "off (this device was revoked)";
|
|
318
|
-
case "unpaired": return "off (no paired devices)";
|
|
319
|
-
default: return "off (local only)";
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
async function runStatus(ctx, argv = []) {
|
|
323
|
-
const t = ctx.theme;
|
|
324
|
-
const spec = COMMANDS.find((c) => c.name === "status");
|
|
325
|
-
let all = false;
|
|
326
|
-
if (spec) {
|
|
327
|
-
const parsed = parseFlags(ctx, spec, argv);
|
|
328
|
-
if (typeof parsed === "number") return parsed;
|
|
329
|
-
all = parsed.values.all === true;
|
|
330
|
-
}
|
|
331
|
-
let client;
|
|
332
|
-
try {
|
|
333
|
-
client = await ctx.connect(connectOpts(ctx, false));
|
|
334
|
-
} catch (e) {
|
|
335
|
-
const problem = daemonProblem(t, e);
|
|
336
|
-
ctx.err(problem.notRunning ? warnBlock(t, "The Conveno daemon is not running.", `Run ${cmd(t, "conveno daemon start")}, or open a supported CLI after ${cmd(t, "conveno init")}.`, "Sessions are listed by the daemon, and nothing is listening on its socket.") : warnBlock(t, "The Conveno daemon cannot be reached.", problem.fix, problem.why));
|
|
337
|
-
return 0;
|
|
338
|
-
}
|
|
339
|
-
try {
|
|
340
|
-
const everyone = (await client["session.list"]({ includeOffline: true })).sessions;
|
|
341
|
-
const sessions = all ? everyone : everyone.filter((s) => s.status !== "offline");
|
|
342
|
-
const hidden = everyone.length - sessions.length;
|
|
343
|
-
const repos = new Set(sessions.map((s) => s.repo?.root ?? s.cwd)).size;
|
|
344
|
-
const hint = hidden > 0 ? `${hidden} offline hidden, ${cmd(t, "conveno status --all")} shows them` : "";
|
|
345
|
-
const relay = await (async () => client["relay.status"]({}))().catch(() => void 0);
|
|
346
|
-
ctx.out(`daemon up ${t.status("bullet")} relay: ${relaySummary(relay)} ${t.status("bullet")} ${plural(sessions.length, "session")}\n`);
|
|
347
|
-
if (sessions.length === 0) {
|
|
348
|
-
ctx.out(hidden > 0 ? `\nNo sessions online. ${hint}.\n` : `\nNo sessions yet. Open a supported CLI after ${cmd(t, "conveno init")} and it appears here.\n`);
|
|
349
|
-
return 0;
|
|
350
|
-
}
|
|
351
|
-
ctx.out(`\n${renderSessions(ctx, sessions)}\n\n`);
|
|
352
|
-
ctx.out(`${plural(sessions.length, "session")} in ${plural(repos, "repo")}${hint ? ` ${t.status("bullet")} ${hint}` : ""}\n`);
|
|
353
|
-
const paused = sessions.filter((s) => s.auto === true && s.autoPausedBy !== void 0);
|
|
354
|
-
for (const s of paused) ctx.err(warnBlock(t, `Auto mode for ${s.name} is paused by limit.`, `Run ${cmd(t, `conveno auto resume ${s.name}`)}, or let the orchestrator resume it (once per hour).`, "It took as many automatic turns as its limit allows in the window, or a message reached it after that many automatic turns with no person in between (sessions answering each other). Its messages still arrive at the next prompt."));
|
|
355
|
-
const open = await client["ticket.list"]({
|
|
356
|
-
status: "open",
|
|
357
|
-
limit: 1
|
|
358
|
-
}).catch(() => void 0);
|
|
359
|
-
if (open && open.openCount > 0) ctx.out(`${t.paint("entry", plural(open.openCount, "open ticket"))} waiting for an answer ${t.status("bullet")} ${cmd(t, "conveno tickets --open")}\n`);
|
|
360
|
-
return 0;
|
|
361
|
-
} finally {
|
|
362
|
-
await client.close().catch(() => void 0);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
// src/auto.ts
|
|
366
|
-
/** Time allowed for the process-table query that finds the session this command runs in. */
|
|
367
|
-
const ANCESTRY_TIMEOUT_MS$1 = 5e3;
|
|
368
|
-
/**
|
|
369
|
-
* The session this command runs inside, when it is typed in a CLI's own shell (for example
|
|
370
|
-
* `! conveno auto on` in Claude Code): the nearest ancestor that hosts exactly one session. A
|
|
371
|
-
* command the user types may look past its first ancestor, because the user asked for it and is
|
|
372
|
-
* told which session changed; hooks never do this.
|
|
373
|
-
*/
|
|
374
|
-
async function enclosingSession(ctx, client) {
|
|
375
|
-
const { pids } = await ctx.ancestry(ANCESTRY_TIMEOUT_MS$1);
|
|
376
|
-
for (const pid of pids) {
|
|
377
|
-
const { session } = await client["session.byHost"]({ pid });
|
|
378
|
-
if (session) return session;
|
|
379
|
-
}
|
|
380
|
-
return null;
|
|
381
|
-
}
|
|
382
|
-
const isTarget = (s) => SessionName.safeParse(s).success || SessionId.safeParse(s).success;
|
|
383
|
-
/** `conveno auto [on|off|resume|limit <n|default>] [<session>]`. */
|
|
384
|
-
async function runAuto(ctx, argv) {
|
|
385
|
-
const t = ctx.theme;
|
|
386
|
-
const spec = COMMANDS.find((c) => c.name === "auto");
|
|
387
|
-
if (!spec) return 2;
|
|
388
|
-
const parsed = parseFlags(ctx, spec, argv);
|
|
389
|
-
if (typeof parsed === "number") return parsed;
|
|
390
|
-
const [mode, ...rest] = parsed.positionals;
|
|
391
|
-
const usage = `Run ${cmd(t, "conveno auto --help")} to see the usage.`;
|
|
392
|
-
const usageError = (what) => fail(ctx, {
|
|
393
|
-
what,
|
|
394
|
-
fix: usage,
|
|
395
|
-
exit: 2,
|
|
396
|
-
ref: "e_usage"
|
|
397
|
-
});
|
|
398
|
-
let change;
|
|
399
|
-
let args = rest;
|
|
400
|
-
switch (mode) {
|
|
401
|
-
case void 0: break;
|
|
402
|
-
case "on":
|
|
403
|
-
case "off":
|
|
404
|
-
change = { auto: mode === "on" };
|
|
405
|
-
break;
|
|
406
|
-
case "resume":
|
|
407
|
-
change = { resume: true };
|
|
408
|
-
break;
|
|
409
|
-
case "limit": {
|
|
410
|
-
const [value, ...after] = rest;
|
|
411
|
-
if (value === void 0) return usageError("conveno auto limit needs a number or default");
|
|
412
|
-
if (value === "default") change = { limit: null };
|
|
413
|
-
else if (/^\d+$/.test(value) && Number(value) >= 1 && Number(value) <= 1e3) change = { limit: Number(value) };
|
|
414
|
-
else return usageError(`"${value}" is not a limit from 1 to ${AUTO_LIMIT_MAX}, or default`);
|
|
415
|
-
args = after;
|
|
416
|
-
break;
|
|
417
|
-
}
|
|
418
|
-
default: return usageError(`Unexpected argument "${mode}" for conveno auto`);
|
|
419
|
-
}
|
|
420
|
-
const [target, ...extra] = args;
|
|
421
|
-
if (extra.length > 0) return usageError(`Unexpected argument "${extra[0]}" for conveno auto`);
|
|
422
|
-
if (target !== void 0 && !isTarget(target)) return fail(ctx, {
|
|
423
|
-
what: `"${target}" is not a session name or id`,
|
|
424
|
-
fix: `Run ${cmd(t, "conveno status")} to see the names.`,
|
|
425
|
-
exit: 2,
|
|
426
|
-
ref: "e_usage"
|
|
427
|
-
});
|
|
428
|
-
let client;
|
|
429
|
-
try {
|
|
430
|
-
client = await ctx.connect(connectOpts(ctx, false));
|
|
431
|
-
} catch (e) {
|
|
432
|
-
const problem = daemonProblem(t, e);
|
|
433
|
-
return fail(ctx, {
|
|
434
|
-
what: "The Conveno daemon cannot be reached",
|
|
435
|
-
detail: [problem.why],
|
|
436
|
-
fix: problem.fix,
|
|
437
|
-
exit: 1,
|
|
438
|
-
ref: "e_daemon"
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
try {
|
|
442
|
-
if (change === void 0) {
|
|
443
|
-
const { sessions } = await client["session.list"]({});
|
|
444
|
-
ctx.out(sessions.length === 0 ? "No sessions online.\n" : `${renderSessions(ctx, sessions)}\n`);
|
|
445
|
-
return 0;
|
|
446
|
-
}
|
|
447
|
-
const session = target ?? (await enclosingSession(ctx, client))?.id;
|
|
448
|
-
if (session === void 0) return fail(ctx, {
|
|
449
|
-
what: "conveno auto needs a session",
|
|
450
|
-
detail: ["This command does not run inside a session Conveno knows."],
|
|
451
|
-
fix: `Name one, such as ${cmd(t, "conveno auto on api-worker")}. ${cmd(t, "conveno status")} lists the names.`,
|
|
452
|
-
exit: 2,
|
|
453
|
-
ref: "e_usage"
|
|
454
|
-
});
|
|
455
|
-
const s = (await client["session.setAuto"]({
|
|
456
|
-
session,
|
|
457
|
-
...change
|
|
458
|
-
})).session;
|
|
459
|
-
ctx.out(`Auto mode for ${t.bold(s.name)} is ${autoText(t, s)}.\n`);
|
|
460
|
-
if (change.limit !== void 0) ctx.out(s.autoLimit !== void 0 ? `It may take ${s.autoLimit} automatic turns per window.\n` : "It uses the daemon's limit again.\n");
|
|
461
|
-
else if (s.auto) ctx.out("Waiting messages become its next prompt when a turn ends, or right away while it is idle where its CLI allows.\n");
|
|
462
|
-
else ctx.out("Messages still reach it at the next prompt and through the inbox tool.\n");
|
|
463
|
-
return 0;
|
|
464
|
-
} catch (e) {
|
|
465
|
-
const problem = daemonProblem(t, e);
|
|
466
|
-
return fail(ctx, {
|
|
467
|
-
what: "Auto mode was not changed",
|
|
468
|
-
detail: [problem.why],
|
|
469
|
-
fix: `Run ${cmd(t, "conveno status")} to see the sessions.`,
|
|
470
|
-
exit: 1,
|
|
471
|
-
ref: "e_auto"
|
|
472
|
-
});
|
|
473
|
-
} finally {
|
|
474
|
-
await client.close().catch(() => void 0);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
// src/daemon.ts
|
|
478
|
-
async function lockPid(ctx) {
|
|
479
|
-
try {
|
|
480
|
-
const raw = await readFile(dataPaths(ctx.platform, ctx.dataDir).lock, "utf8");
|
|
481
|
-
const pid = JSON.parse(raw).pid;
|
|
482
|
-
return typeof pid === "number" && Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
483
|
-
} catch {
|
|
484
|
-
return null;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
const sleep$1 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
488
|
-
/** Does something on the socket answer the Conveno handshake? */
|
|
489
|
-
async function reachable(ctx) {
|
|
490
|
-
try {
|
|
491
|
-
await (await ctx.connect(connectOpts(ctx, false))).close().catch(() => void 0);
|
|
492
|
-
return true;
|
|
493
|
-
} catch {
|
|
494
|
-
return false;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
const lockExists = (ctx) => access(dataPaths(ctx.platform, ctx.dataDir).lock).then(() => true, () => false);
|
|
498
|
-
/** Poll until `done()` holds or `ms` pass. Returns whether it held. */
|
|
499
|
-
async function waitFor(done, ms) {
|
|
500
|
-
const deadline = Date.now() + ms;
|
|
501
|
-
for (;;) {
|
|
502
|
-
if (await done()) return true;
|
|
503
|
-
if (Date.now() >= deadline) return false;
|
|
504
|
-
await sleep$1(50);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
const norm = (text) => text.replaceAll("\\", "/").toLowerCase();
|
|
508
|
-
/**
|
|
509
|
-
* Does this command line belong to the Conveno daemon? It must run the daemon's entry script: the
|
|
510
|
-
* one this install resolved, any installed `@conveno/cli`'s `daemon.js`, or the `bin.js` of the
|
|
511
|
-
* `@conveno/daemon` package that releases before 0.1.1 started.
|
|
512
|
-
*/
|
|
513
|
-
function isConvenoDaemonCommand(commandLine, daemonEntry) {
|
|
514
|
-
const line = norm(commandLine);
|
|
515
|
-
if (daemonEntry !== void 0 && line.includes(norm(daemonEntry))) return true;
|
|
516
|
-
return /@conveno\/cli\/(?:[^ ]+\/)?daemon\.js|@conveno\/daemon\/(?:[^ ]+\/)?bin\.js/.test(line);
|
|
517
|
-
}
|
|
518
|
-
const STOP_FIX = (t) => `then run ${cmd(t, "conveno daemon status")}`;
|
|
519
|
-
/**
|
|
520
|
-
* `conveno daemon stop`. The normal path asks the daemon to shut itself down over the control
|
|
521
|
-
* channel (`daemon.shutdown`), the way Docker and pm2 do. That needs no signal and no external
|
|
522
|
-
* tool, so it works for a normal user in a Windows SSH session. Only when the daemon does not answer,
|
|
523
|
-
* and its lock pid is verified to be the daemon, is the process ended directly.
|
|
524
|
-
*/
|
|
525
|
-
async function stopDaemon(ctx) {
|
|
526
|
-
const t = ctx.theme;
|
|
527
|
-
const lock = dataPaths(ctx.platform, ctx.dataDir).lock;
|
|
528
|
-
const pid = await lockPid(ctx);
|
|
529
|
-
const named = pid === null ? "" : ` (pid ${pid})`;
|
|
530
|
-
let client;
|
|
531
|
-
try {
|
|
532
|
-
client = await ctx.connect(connectOpts(ctx, false));
|
|
533
|
-
} catch {
|
|
534
|
-
client = void 0;
|
|
535
|
-
}
|
|
536
|
-
if (client) {
|
|
537
|
-
try {
|
|
538
|
-
await client["daemon.shutdown"]({});
|
|
539
|
-
} catch (e) {
|
|
540
|
-
await client.close().catch(() => void 0);
|
|
541
|
-
return fail(ctx, {
|
|
542
|
-
what: `The daemon${named} did not accept the stop request`,
|
|
543
|
-
detail: [plainError(e)],
|
|
544
|
-
fix: `${pid === null ? "Stop the process that owns the daemon socket yourself" : `Stop pid ${pid} yourself`}, ${STOP_FIX(t)}.`,
|
|
545
|
-
exit: 1,
|
|
546
|
-
ref: "e_daemon_stop"
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
await client.close().catch(() => void 0);
|
|
550
|
-
if (!await waitFor(async () => !await reachable(ctx) && !await lockExists(ctx) && (pid === null || !ctx.isAlive(pid)), ctx.stopTimeoutMs)) return fail(ctx, {
|
|
551
|
-
what: `The daemon${named} is still running after ${Math.round(ctx.stopTimeoutMs / 1e3)}s`,
|
|
552
|
-
detail: ["It accepted the stop request, but its process, socket or lock file is still there."],
|
|
553
|
-
fix: `${pid === null ? "Stop the process that owns the daemon socket yourself" : `Stop pid ${pid} yourself`}, ${STOP_FIX(t)}.`,
|
|
554
|
-
exit: 1,
|
|
555
|
-
ref: "e_daemon_stop"
|
|
556
|
-
});
|
|
557
|
-
ctx.out(`${t.status("ok")} Stopped the daemon${named}.\n`);
|
|
558
|
-
return 0;
|
|
559
|
-
}
|
|
560
|
-
if (pid === null) {
|
|
561
|
-
ctx.out(`${t.status("info")} The daemon is not running. Nothing to stop.\n`);
|
|
562
|
-
return 0;
|
|
563
|
-
}
|
|
564
|
-
const stale = async () => {
|
|
565
|
-
await rm(lock, { force: true }).catch(() => void 0);
|
|
566
|
-
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`);
|
|
567
|
-
return 0;
|
|
568
|
-
};
|
|
569
|
-
if (!ctx.isAlive(pid)) return stale();
|
|
570
|
-
const commandLine = await ctx.commandLineOf(pid);
|
|
571
|
-
if (commandLine === null) return fail(ctx, {
|
|
572
|
-
what: `The daemon did not answer, and pid ${pid} could not be checked`,
|
|
573
|
-
detail: ["Conveno could not read that process's command line, so it cannot tell whether it is the daemon. It stopped nothing."],
|
|
574
|
-
fix: `If pid ${pid} is the Conveno daemon, end it yourself (Task Manager on Windows, \`kill ${pid}\` elsewhere), ${STOP_FIX(t)}.`,
|
|
575
|
-
exit: 1,
|
|
576
|
-
ref: "e_daemon_lock"
|
|
577
|
-
});
|
|
578
|
-
if (!isConvenoDaemonCommand(commandLine, ctx.daemonEntry)) return stale();
|
|
579
|
-
try {
|
|
580
|
-
ctx.kill(pid);
|
|
581
|
-
} catch (e) {
|
|
582
|
-
return fail(ctx, {
|
|
583
|
-
what: `Could not stop the daemon (pid ${pid})`,
|
|
584
|
-
detail: [plainError(e)],
|
|
585
|
-
fix: `Stop that process yourself, ${STOP_FIX(t)}.`,
|
|
586
|
-
exit: 1,
|
|
587
|
-
ref: "e_daemon_stop"
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
if (!await waitFor(() => !ctx.isAlive(pid), ctx.stopTimeoutMs)) return fail(ctx, {
|
|
591
|
-
what: `The daemon (pid ${pid}) is still running after ${Math.round(ctx.stopTimeoutMs / 1e3)}s`,
|
|
592
|
-
detail: ["It did not answer, was ended, and has not exited."],
|
|
593
|
-
fix: `Stop that process yourself, ${STOP_FIX(t)}.`,
|
|
594
|
-
exit: 1,
|
|
595
|
-
ref: "e_daemon_stop"
|
|
596
|
-
});
|
|
597
|
-
await rm(lock, { force: true }).catch(() => void 0);
|
|
598
|
-
ctx.out(`${t.status("ok")} Stopped the daemon (pid ${pid}). It was not answering, so it was ended directly.\n`);
|
|
599
|
-
return 0;
|
|
600
|
-
}
|
|
601
|
-
const SUBCOMMANDS = [
|
|
602
|
-
"start",
|
|
603
|
-
"stop",
|
|
604
|
-
"status"
|
|
605
|
-
];
|
|
606
|
-
async function runDaemon(ctx, argv) {
|
|
607
|
-
const t = ctx.theme;
|
|
608
|
-
const sub = argv[0];
|
|
609
|
-
if (sub === "start") {
|
|
610
|
-
try {
|
|
611
|
-
await (await ctx.connect(connectOpts(ctx, true))).close().catch(() => void 0);
|
|
612
|
-
} catch (e) {
|
|
613
|
-
const problem = daemonProblem(t, e);
|
|
614
|
-
return fail(ctx, {
|
|
615
|
-
what: "The Conveno daemon did not start",
|
|
616
|
-
detail: [problem.why],
|
|
617
|
-
fix: problem.notRunning ? `Run ${cmd(t, "conveno doctor")} to check the install, then try again.` : problem.fix,
|
|
618
|
-
exit: 1,
|
|
619
|
-
ref: "e_daemon_start"
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
const pid = await lockPid(ctx);
|
|
623
|
-
ctx.out(`${t.status("ok")} Daemon running${pid ? `, pid ${pid}` : ""}.\n`);
|
|
624
|
-
return 0;
|
|
625
|
-
}
|
|
626
|
-
if (sub === "status") {
|
|
627
|
-
const pid = await lockPid(ctx);
|
|
628
|
-
try {
|
|
629
|
-
await (await ctx.connect(connectOpts(ctx, false))).close().catch(() => void 0);
|
|
630
|
-
ctx.out(`${t.status("ok")} daemon running${pid ? `, pid ${pid}` : ""}\n`);
|
|
631
|
-
return 0;
|
|
632
|
-
} catch (e) {
|
|
633
|
-
const problem = daemonProblem(t, e);
|
|
634
|
-
if (problem.notRunning) ctx.out(`${t.glyph("offline")} daemon not running\n`);
|
|
635
|
-
else {
|
|
636
|
-
ctx.out(`${t.status("error")} daemon cannot be reached\n`);
|
|
637
|
-
ctx.err(warnBlock(t, "The Conveno daemon cannot be reached.", problem.fix, problem.why));
|
|
638
|
-
}
|
|
639
|
-
return 1;
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
if (sub === "stop") return stopDaemon(ctx);
|
|
643
|
-
const suggestion = sub ? closest(sub, SUBCOMMANDS) : void 0;
|
|
644
|
-
return fail(ctx, {
|
|
645
|
-
what: sub ? `Unknown daemon command "${sub}"` : "conveno daemon needs a command",
|
|
646
|
-
fix: `Run ${cmd(t, "conveno daemon start")}, ${cmd(t, "conveno daemon stop")} or ${cmd(t, "conveno daemon status")}.`,
|
|
647
|
-
...suggestion ? { didYouMean: `Did you mean ${suggestion}?` } : {},
|
|
648
|
-
exit: 2,
|
|
649
|
-
ref: "e_usage"
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
205
|
const PAIR_TIMEOUT_MS = 3e5;
|
|
653
206
|
/**
|
|
654
207
|
* Run `run` with a daemon client. Commands that change something start the daemon when needed;
|
|
@@ -1019,424 +572,51 @@ function acpDoctorLines(ctx, clis) {
|
|
|
1019
572
|
...rows.some((r) => r.install || r.onDemand) ? [q("Adapters are third-party npm packages, fetched by npx on first use. They use the CLI's own sign-in.")] : []
|
|
1020
573
|
];
|
|
1021
574
|
}
|
|
1022
|
-
// src/
|
|
1023
|
-
/**
|
|
1024
|
-
function
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1027
|
-
|
|
575
|
+
// src/acp-offer.ts
|
|
576
|
+
/** The adapter packages an installed CLI needs and that are not on PATH (nor overridden). */
|
|
577
|
+
function missingAdapters(ctx, installed) {
|
|
578
|
+
const out = [];
|
|
579
|
+
for (const { cli, displayName } of installed) {
|
|
580
|
+
const acp = SPAWN_TABLE[cli]?.acp;
|
|
581
|
+
if (!acp?.adapterPackage) continue;
|
|
582
|
+
if (!resolveAcpProgram(cli, acp, {
|
|
583
|
+
env: ctx.env,
|
|
584
|
+
which: (n) => findOnPath(n, ctx.env, ctx.platform),
|
|
585
|
+
npxConsent: false
|
|
586
|
+
}).ok) out.push({
|
|
587
|
+
pkg: acp.adapterPackage,
|
|
588
|
+
cli: displayName
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
return out;
|
|
592
|
+
}
|
|
593
|
+
function printManual(ctx, missing) {
|
|
594
|
+
const q = (w) => ctx.theme.paint("quiet", w);
|
|
595
|
+
for (const { pkg } of missing) {
|
|
596
|
+
ctx.out(` ${adapterInstallCommand(pkg)}\n`);
|
|
597
|
+
ctx.out(` ${q(`or run it on demand: ${adapterNpxCommand(pkg)}`)}\n`);
|
|
598
|
+
}
|
|
1028
599
|
}
|
|
1029
|
-
/** Time allowed for the one process-table query. */
|
|
1030
|
-
const ANCESTRY_TIMEOUT_MS = 5e3;
|
|
1031
|
-
const tierWord = (t) => t === "next_turn" ? "next turn" : t;
|
|
1032
|
-
const hasAny = (c) => c !== void 0 && (c.nextTurn || c.endOfTurn || c.idleWake);
|
|
1033
600
|
/**
|
|
1034
|
-
*
|
|
1035
|
-
*
|
|
601
|
+
* Ask once whether ACP workers may fetch the adapters with npx. `--acp-adapters` and
|
|
602
|
+
* `--no-acp-adapters` answer without asking and replace an earlier answer. Without a terminal, or
|
|
603
|
+
* with `--yes`, nothing is asked and nothing is saved.
|
|
1036
604
|
*/
|
|
1037
|
-
function
|
|
1038
|
-
const
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
} catch {
|
|
1053
|
-
detection = {
|
|
1054
|
-
installed: false,
|
|
1055
|
-
configPaths: []
|
|
1056
|
-
};
|
|
1057
|
-
}
|
|
1058
|
-
if (!detection.installed) return {
|
|
1059
|
-
adapter,
|
|
1060
|
-
detection,
|
|
1061
|
-
mcp: null,
|
|
1062
|
-
hooks: null
|
|
1063
|
-
};
|
|
1064
|
-
const hasHooks = adapter.deliveryTier !== "inbox" || hasAny(adapter.delivery?.(detection));
|
|
1065
|
-
try {
|
|
1066
|
-
const changes = await adapter.plan(env);
|
|
1067
|
-
return {
|
|
1068
|
-
adapter,
|
|
1069
|
-
detection,
|
|
1070
|
-
mcp: partState(changes, "mcp"),
|
|
1071
|
-
hooks: hasHooks ? partState(changes, "hooks") : null
|
|
1072
|
-
};
|
|
1073
|
-
} catch (e) {
|
|
1074
|
-
return {
|
|
1075
|
-
adapter,
|
|
1076
|
-
detection,
|
|
1077
|
-
mcp: "missing",
|
|
1078
|
-
hooks: hasHooks ? "missing" : null,
|
|
1079
|
-
planError: plainError(e)
|
|
1080
|
-
};
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
/** A note for a CLI outside the tested range. Newer is a warning, older than the minimum a problem. */
|
|
1084
|
-
function versionBlock(t, adapter, version, status) {
|
|
1085
|
-
const name = adapter.displayName;
|
|
1086
|
-
if (status.kind === "older") return {
|
|
1087
|
-
problem: true,
|
|
1088
|
-
text: errorBlock(t, {
|
|
1089
|
-
what: `${name} ${version} is older than Conveno supports`,
|
|
1090
|
-
detail: [`Conveno needs ${name} ${status.minimum} or newer.`],
|
|
1091
|
-
fix: `Upgrade ${name}, then run ${cmd(t, "conveno doctor")} again.`,
|
|
1092
|
-
exit: 1,
|
|
1093
|
-
ref: "e_cli_old"
|
|
1094
|
-
})
|
|
1095
|
-
};
|
|
1096
|
-
if (status.kind === "newer") return {
|
|
1097
|
-
problem: false,
|
|
1098
|
-
text: warnBlock(t, `${name} ${version} is newer than the ${status.verified} Conveno was tested with.`, "Nothing to do unless messages stop arriving. Please report it at https://github.com/0xPixelNinja/conveno/issues if something breaks.", "CLI vendors change config and hook formats often. A nightly check tests the newest releases and raises the tested version when they pass.")
|
|
1099
|
-
};
|
|
1100
|
-
}
|
|
1101
|
-
async function runDoctor(ctx, argv = []) {
|
|
1102
|
-
const t = ctx.theme;
|
|
1103
|
-
const spec = COMMANDS.find((c) => c.name === "doctor");
|
|
1104
|
-
if (spec) {
|
|
1105
|
-
const parsed = parseFlags(ctx, spec, argv);
|
|
1106
|
-
if (typeof parsed === "number") return parsed;
|
|
1107
|
-
}
|
|
1108
|
-
let ok = 0;
|
|
1109
|
-
let warnings = 0;
|
|
1110
|
-
let problems = 0;
|
|
1111
|
-
const notes = [];
|
|
1112
|
-
let daemonLine;
|
|
1113
|
-
try {
|
|
1114
|
-
const client = await ctx.connect(connectOpts(ctx, false));
|
|
1115
|
-
try {
|
|
1116
|
-
const { sessions } = await client["session.list"]({ includeOffline: true });
|
|
1117
|
-
daemonLine = [` ${t.status("ok")} daemon`, `running, ${plural(sessions.length, "session")}`];
|
|
1118
|
-
ok++;
|
|
1119
|
-
} finally {
|
|
1120
|
-
await client.close().catch(() => void 0);
|
|
1121
|
-
}
|
|
1122
|
-
} catch (e) {
|
|
1123
|
-
const problem = daemonProblem(t, e);
|
|
1124
|
-
if (problem.notRunning) {
|
|
1125
|
-
daemonLine = [` ${t.status("warn")} daemon`, "not running"];
|
|
1126
|
-
warnings++;
|
|
1127
|
-
notes.push(warnBlock(t, "The Conveno daemon is not running.", problem.fix, problem.why));
|
|
1128
|
-
} else {
|
|
1129
|
-
daemonLine = [` ${t.status("error")} daemon`, "cannot be reached"];
|
|
1130
|
-
problems++;
|
|
1131
|
-
notes.push(errorBlock(t, {
|
|
1132
|
-
what: "The Conveno daemon cannot be reached",
|
|
1133
|
-
detail: [problem.why],
|
|
1134
|
-
fix: problem.fix,
|
|
1135
|
-
exit: 1,
|
|
1136
|
-
ref: "e_daemon"
|
|
1137
|
-
}));
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
ctx.out(`${columns([daemonLine]).join("\n")}\n\n`);
|
|
1141
|
-
if (!(await ctx.ancestry(ANCESTRY_TIMEOUT_MS)).complete) {
|
|
1142
|
-
warnings++;
|
|
1143
|
-
notes.push(warnBlock(t, "Process ancestry is unavailable.", `Run ${cmd(t, "conveno doctor")} from a normal desktop session, or allow this user to read the process list. Messages still reach the inbox tool either way.`, ctx.platform === "win32" ? "Windows refused the process list (WMI denies it to non-admin remote logons such as SSH). A hook can then only match a session whose CLI is its direct parent, so next-turn delivery can miss sessions started through a launcher such as conveno.cmd." : "The process list could not be read. A hook can then only match a session whose CLI is its direct parent, so next-turn delivery can miss sessions started through a launcher or a shell."));
|
|
1144
|
-
}
|
|
1145
|
-
const rows = await Promise.all(ctx.adapters.map((a) => inspect(ctx, a)));
|
|
1146
|
-
const q = (w) => t.paint("quiet", w);
|
|
1147
|
-
const table = [[
|
|
1148
|
-
` ${q("CLI")}`,
|
|
1149
|
-
q("NAME"),
|
|
1150
|
-
q("VERSION"),
|
|
1151
|
-
q("MCP"),
|
|
1152
|
-
q("HOOKS"),
|
|
1153
|
-
q("DELIVERY"),
|
|
1154
|
-
q("NOTE")
|
|
1155
|
-
]];
|
|
1156
|
-
const yesNo = (v) => v === null ? q("n/a") : v === "ok" ? "yes" : t.paint("warn", v === "missing" ? "not configured" : "needs update");
|
|
1157
|
-
for (const r of rows) {
|
|
1158
|
-
const { adapter, detection } = r;
|
|
1159
|
-
if (!detection.installed) {
|
|
1160
|
-
table.push([
|
|
1161
|
-
` ${t.glyph("offline")} ${adapter.cli}`,
|
|
1162
|
-
adapter.displayName,
|
|
1163
|
-
"",
|
|
1164
|
-
"",
|
|
1165
|
-
"",
|
|
1166
|
-
"",
|
|
1167
|
-
q("not found on PATH")
|
|
1168
|
-
]);
|
|
1169
|
-
continue;
|
|
1170
|
-
}
|
|
1171
|
-
const good = r.mcp === "ok" && (r.hooks === null || r.hooks === "ok") && !r.planError;
|
|
1172
|
-
const compat = compatStatus(adapter.cli, detection.version, ctx.compat);
|
|
1173
|
-
const tiers = activeTiers(r);
|
|
1174
|
-
let note = tiers.includes("idle wake") ? "auto mode wakes idle sessions" : tiers.includes("end of turn") ? "auto mode: at the end of a turn, no idle wake" : tiers.includes("next turn") ? "delivered at the next prompt" : "read through the inbox tool";
|
|
1175
|
-
if (!good) note = r.planError ? "config could not be read" : r.mcp === "outdated" || r.hooks === "outdated" ? "needs an update" : "not fully configured";
|
|
1176
|
-
if (compat.kind === "older") note = `older than the minimum ${compat.minimum}`;
|
|
1177
|
-
else if (compat.kind === "newer" && good) note = `newer than tested (${compat.verified})`;
|
|
1178
|
-
const glyph = compat.kind === "older" ? t.status("error") : good && compat.kind !== "newer" ? t.status("ok") : t.status("warn");
|
|
1179
|
-
table.push([
|
|
1180
|
-
` ${glyph} ${adapter.cli}`,
|
|
1181
|
-
adapter.displayName,
|
|
1182
|
-
detection.version ?? "",
|
|
1183
|
-
yesNo(r.mcp),
|
|
1184
|
-
yesNo(r.hooks),
|
|
1185
|
-
tiers.join(", "),
|
|
1186
|
-
q(note)
|
|
1187
|
-
]);
|
|
1188
|
-
if (r.planError) {
|
|
1189
|
-
problems++;
|
|
1190
|
-
notes.push(errorBlock(t, {
|
|
1191
|
-
what: `${adapter.displayName} config could not be read`,
|
|
1192
|
-
detail: [r.planError],
|
|
1193
|
-
fix: "Repair the file named above, then run conveno doctor again.",
|
|
1194
|
-
exit: 1,
|
|
1195
|
-
ref: "e_config"
|
|
1196
|
-
}));
|
|
1197
|
-
} else if (good) {
|
|
1198
|
-
if (compat.kind === "ok" || compat.kind === "unknown") ok++;
|
|
1199
|
-
} else {
|
|
1200
|
-
warnings++;
|
|
1201
|
-
const named = [["the MCP server", r.mcp], ["the hooks", r.hooks]];
|
|
1202
|
-
const list = (state) => named.filter(([, s]) => s === state).map(([n]) => n).join(" and ");
|
|
1203
|
-
const missing = list("missing");
|
|
1204
|
-
const outdated = list("outdated");
|
|
1205
|
-
const fix = `Run ${cmd(t, "conveno init")}, then restart open ${adapter.displayName} sessions.`;
|
|
1206
|
-
notes.push(missing && outdated ? warnBlock(t, `${adapter.displayName} is missing ${missing} and needs an update to ${outdated}.`, fix) : missing ? warnBlock(t, `${adapter.displayName} is missing ${missing}.`, fix) : warnBlock(t, `${adapter.displayName} needs an update.`, fix, `Conveno's setup for ${outdated} is from an older version. ${cmd(t, "conveno init")} shows exactly which lines change.`));
|
|
1207
|
-
}
|
|
1208
|
-
const versionNote = versionBlock(t, adapter, detection.version, compat);
|
|
1209
|
-
if (versionNote) {
|
|
1210
|
-
notes.push(versionNote.text);
|
|
1211
|
-
if (versionNote.problem) problems++;
|
|
1212
|
-
else warnings++;
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
ctx.out(`${columns(table).join("\n")}\n`);
|
|
1216
|
-
if (rows.some((r) => r.detection.installed && activeTiers(r).some((t) => t !== "next turn" && t !== "inbox"))) ctx.out(`${q("End of turn and idle wake apply to sessions in auto mode; see conveno auto.")}\n`);
|
|
1217
|
-
const acpLines = acpDoctorLines(ctx, rows.filter((r) => r.detection.installed).map((r) => r.adapter.cli));
|
|
1218
|
-
if (acpLines.length > 0) ctx.out(`${acpLines.join("\n")}\n`);
|
|
1219
|
-
const relayRows = [];
|
|
1220
|
-
for (const r of rows) {
|
|
1221
|
-
if (!r.detection.installed || !r.adapter.permissionHookInstalled || r.planError) continue;
|
|
1222
|
-
const installed = await r.adapter.permissionHookInstalled(adapterEnv(ctx)).catch(() => false);
|
|
1223
|
-
relayRows.push([` ${r.adapter.cli}`, q(installed ? "permission relay: hook installed (off until turned on per session)" : "permission relay: not installed (optional)")]);
|
|
1224
|
-
}
|
|
1225
|
-
if (relayRows.length > 0) ctx.out(`\n${columns(relayRows).join("\n")}\n`);
|
|
1226
|
-
if (!rows.some((r) => r.detection.installed)) {
|
|
1227
|
-
notes.push(warnBlock(t, "No supported AI coding CLI was found on PATH.", "Install Claude Code, Codex CLI or OpenCode, then run conveno init."));
|
|
1228
|
-
warnings++;
|
|
1229
|
-
}
|
|
1230
|
-
for (const n of notes) ctx.err(`\n${n.trimEnd()}\n`);
|
|
1231
|
-
ctx.out(`\n${ok} ok, ${plural(warnings, "warning")}, ${plural(problems, "problem")}\n`);
|
|
1232
|
-
return problems > 0 ? 1 : 0;
|
|
1233
|
-
}
|
|
1234
|
-
// src/version.ts
|
|
1235
|
-
const VERSION = "0.2.0-rc.1";
|
|
1236
|
-
// src/errorLog.ts
|
|
1237
|
-
/** The message of an unexpected error, as it is. Not the softened text `plainError` gives. */
|
|
1238
|
-
function rawMessage(e) {
|
|
1239
|
-
if (e instanceof Error) return `${e.name}: ${e.message}`;
|
|
1240
|
-
return String(e);
|
|
1241
|
-
}
|
|
1242
|
-
/**
|
|
1243
|
-
* Write the full stack of an unexpected error to `<data dir>/logs/<timestamp>-error.log`, readable
|
|
1244
|
-
* by the user only. Returns the path, or undefined when the log could not be written (the error is
|
|
1245
|
-
* still reported, just without a log).
|
|
1246
|
-
*/
|
|
1247
|
-
async function writeErrorLog(ctx, argv, e) {
|
|
1248
|
-
try {
|
|
1249
|
-
const dir = dataPaths(ctx.platform, ctx.dataDir).logs;
|
|
1250
|
-
await mkdir(dir, {
|
|
1251
|
-
recursive: true,
|
|
1252
|
-
mode: 448
|
|
1253
|
-
});
|
|
1254
|
-
const stamp = ctx.now().toISOString().replace(/[:.]/g, "-");
|
|
1255
|
-
const file = join(dir, `${stamp}-error.log`);
|
|
1256
|
-
const command = argv.slice(0, 2).join(" ");
|
|
1257
|
-
const text = [
|
|
1258
|
-
`conveno ${VERSION} ${command}`,
|
|
1259
|
-
"ref e_internal",
|
|
1260
|
-
`time ${ctx.now().toISOString()}`,
|
|
1261
|
-
`platform ${ctx.platform}, node ${process.version}`,
|
|
1262
|
-
"",
|
|
1263
|
-
e instanceof Error ? e.stack ?? rawMessage(e) : rawMessage(e),
|
|
1264
|
-
e instanceof Error && e.cause !== void 0 ? `\nCaused by: ${e.cause instanceof Error ? e.cause.stack ?? rawMessage(e.cause) : String(e.cause)}` : "",
|
|
1265
|
-
""
|
|
1266
|
-
].join("\n");
|
|
1267
|
-
await writeFile(file, text, { mode: 384 });
|
|
1268
|
-
await chmod(file, 384).catch(() => void 0);
|
|
1269
|
-
return file;
|
|
1270
|
-
} catch {
|
|
1271
|
-
return;
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
// src/forget.ts
|
|
1275
|
-
const UNIT_MS = {
|
|
1276
|
-
m: 6e4,
|
|
1277
|
-
h: 36e5,
|
|
1278
|
-
d: 864e5
|
|
1279
|
-
};
|
|
1280
|
-
/** `30m`, `24h` or `7d` as milliseconds, or undefined when the text is anything else. */
|
|
1281
|
-
function parseDuration(text) {
|
|
1282
|
-
const m = /^(\d{1,6})([mhd])$/.exec(text);
|
|
1283
|
-
if (!m) return void 0;
|
|
1284
|
-
const ms = Number(m[1]) * UNIT_MS[m[2]];
|
|
1285
|
-
return ms > 0 ? ms : void 0;
|
|
1286
|
-
}
|
|
1287
|
-
/** Rebuild the command line the user typed, for the "run it again with --yes" hint. */
|
|
1288
|
-
function rerunLine(names, flags) {
|
|
1289
|
-
return [
|
|
1290
|
-
"conveno forget",
|
|
1291
|
-
...names.map((n) => n.includes("*") ? `'${n}'` : n),
|
|
1292
|
-
...flags.offline ? ["--offline"] : [],
|
|
1293
|
-
...flags.olderThan ? ["--older-than", flags.olderThan] : []
|
|
1294
|
-
].join(" ");
|
|
1295
|
-
}
|
|
1296
|
-
async function runForget(ctx, argv) {
|
|
1297
|
-
const t = ctx.theme;
|
|
1298
|
-
const spec = COMMANDS.find((c) => c.name === "forget");
|
|
1299
|
-
if (!spec) return 2;
|
|
1300
|
-
const parsed = parseFlags(ctx, spec, argv);
|
|
1301
|
-
if (typeof parsed === "number") return parsed;
|
|
1302
|
-
const names = parsed.positionals;
|
|
1303
|
-
const offline = parsed.values.offline === true;
|
|
1304
|
-
const olderThan = typeof parsed.values["older-than"] === "string" ? parsed.values["older-than"] : void 0;
|
|
1305
|
-
const dryRun = parsed.values["dry-run"] === true;
|
|
1306
|
-
const yes = parsed.values.yes === true;
|
|
1307
|
-
const help = `Run ${cmd(t, "conveno forget --help")} to see the options.`;
|
|
1308
|
-
for (const n of names) if (!SessionNamePattern.safeParse(n).success) return fail(ctx, {
|
|
1309
|
-
what: `"${n}" is not a session name or pattern`,
|
|
1310
|
-
detail: ["Names use lowercase letters, digits and \".\", \"_\", \"@\" or \"-\". A \"*\" matches any run of characters."],
|
|
1311
|
-
fix: `Run ${cmd(t, "conveno status --all")} to see the names.`,
|
|
1312
|
-
exit: 2,
|
|
1313
|
-
ref: "e_usage"
|
|
1314
|
-
});
|
|
1315
|
-
let olderThanMs;
|
|
1316
|
-
if (olderThan !== void 0) {
|
|
1317
|
-
olderThanMs = parseDuration(olderThan);
|
|
1318
|
-
if (olderThanMs === void 0) return fail(ctx, {
|
|
1319
|
-
what: `"${olderThan}" is not a duration`,
|
|
1320
|
-
detail: ["Use a whole number and a unit: 30m for minutes, 24h for hours, 7d for days."],
|
|
1321
|
-
fix: help,
|
|
1322
|
-
exit: 2,
|
|
1323
|
-
ref: "e_usage"
|
|
1324
|
-
});
|
|
1325
|
-
}
|
|
1326
|
-
if (names.length === 0 && !offline && olderThanMs === void 0) return fail(ctx, {
|
|
1327
|
-
what: "conveno forget needs to know which sessions to forget",
|
|
1328
|
-
detail: ["Name them, or pass --offline for every offline session."],
|
|
1329
|
-
fix: `For example ${cmd(t, "conveno forget 'conveno-real-*'")} or ${cmd(t, "conveno forget --offline --older-than 7d")}.`,
|
|
1330
|
-
exit: 2,
|
|
1331
|
-
ref: "e_usage"
|
|
1332
|
-
});
|
|
1333
|
-
let client;
|
|
1334
|
-
try {
|
|
1335
|
-
client = await ctx.connect(connectOpts(ctx, false));
|
|
1336
|
-
} catch (e) {
|
|
1337
|
-
const problem = daemonProblem(t, e);
|
|
1338
|
-
return fail(ctx, {
|
|
1339
|
-
what: problem.notRunning ? "The Conveno daemon is not running" : "The Conveno daemon cannot be reached",
|
|
1340
|
-
detail: [problem.notRunning ? "Sessions live in the daemon, so there is nothing to forget until it runs." : problem.why],
|
|
1341
|
-
fix: problem.notRunning ? `Run ${cmd(t, "conveno daemon start")}.` : problem.fix,
|
|
1342
|
-
exit: 1,
|
|
1343
|
-
ref: "e_daemon"
|
|
1344
|
-
});
|
|
1345
|
-
}
|
|
1346
|
-
try {
|
|
1347
|
-
const selector = {
|
|
1348
|
-
...names.length > 0 ? { names } : {},
|
|
1349
|
-
...names.length === 0 || olderThanMs !== void 0 ? { olderThanMs: olderThanMs ?? 0 } : {}
|
|
1350
|
-
};
|
|
1351
|
-
const preview = await client["session.forget"]({
|
|
1352
|
-
...selector,
|
|
1353
|
-
dryRun: true
|
|
1354
|
-
});
|
|
1355
|
-
const ids = new Set(preview.forgotten.map((s) => s.id));
|
|
1356
|
-
const picked = (await client["session.list"]({ includeOffline: true })).sessions.filter((s) => ids.has(s.id));
|
|
1357
|
-
if (preview.skippedOnline.length > 0) {
|
|
1358
|
-
ctx.out(`${t.status("warn")} ${t.bold(`Skipped ${plural(preview.skippedOnline.length, "online session")}`)}\n`);
|
|
1359
|
-
ctx.out(`${columns(preview.skippedOnline.map((s) => [` ${t.status("idle")} ${t.bold(s.name)}`, t.paint("quiet", "online, a running session is never forgotten")])).join("\n")}\n\n`);
|
|
1360
|
-
}
|
|
1361
|
-
if (picked.length === 0) {
|
|
1362
|
-
ctx.out(`${t.status("info")} Nothing to forget. ${t.paint("quiet", `${cmd(t, "conveno status --all")} lists the offline sessions.`)}\n`);
|
|
1363
|
-
return 0;
|
|
1364
|
-
}
|
|
1365
|
-
ctx.out(`${t.bold(dryRun ? `Would forget ${plural(picked.length, "session")}` : `Will forget ${plural(picked.length, "session")}`)}\n\n`);
|
|
1366
|
-
ctx.out(`${renderSessions(ctx, picked)}\n\n`);
|
|
1367
|
-
ctx.out(` ${t.paint("quiet", "Their queued messages are deleted too. Messages they sent stay with the receivers.")}\n\n`);
|
|
1368
|
-
if (dryRun) {
|
|
1369
|
-
ctx.out(`${t.status("info")} Dry run. Nothing was changed.\n`);
|
|
1370
|
-
return 0;
|
|
1371
|
-
}
|
|
1372
|
-
if (!yes) {
|
|
1373
|
-
if (!ctx.interactive) return fail(ctx, {
|
|
1374
|
-
what: "Needs a terminal to confirm",
|
|
1375
|
-
detail: ["No sessions were forgotten."],
|
|
1376
|
-
fix: `Run ${cmd(t, `${rerunLine(names, {
|
|
1377
|
-
offline,
|
|
1378
|
-
...olderThan ? { olderThan } : {}
|
|
1379
|
-
})} --yes`)} to forget the sessions listed above.`,
|
|
1380
|
-
exit: 2,
|
|
1381
|
-
ref: "e_no_tty"
|
|
1382
|
-
});
|
|
1383
|
-
if (!await ctx.confirm(`Forget ${plural(picked.length, "session")}?`, false)) {
|
|
1384
|
-
ctx.out(`${t.status("info")} Nothing was changed.\n`);
|
|
1385
|
-
return 0;
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
const done = await client["session.forget"]({ ids: [...ids] });
|
|
1389
|
-
ctx.out(`${t.status("ok")} ${t.bold("Done.")} Forgot ${plural(done.forgotten.length, "session")}.\n`);
|
|
1390
|
-
return 0;
|
|
1391
|
-
} finally {
|
|
1392
|
-
await client.close().catch(() => void 0);
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
// src/acp-offer.ts
|
|
1396
|
-
/** The adapter packages an installed CLI needs and that are not on PATH (nor overridden). */
|
|
1397
|
-
function missingAdapters(ctx, installed) {
|
|
1398
|
-
const out = [];
|
|
1399
|
-
for (const { cli, displayName } of installed) {
|
|
1400
|
-
const acp = SPAWN_TABLE[cli]?.acp;
|
|
1401
|
-
if (!acp?.adapterPackage) continue;
|
|
1402
|
-
if (!resolveAcpProgram(cli, acp, {
|
|
1403
|
-
env: ctx.env,
|
|
1404
|
-
which: (n) => findOnPath(n, ctx.env, ctx.platform),
|
|
1405
|
-
npxConsent: false
|
|
1406
|
-
}).ok) out.push({
|
|
1407
|
-
pkg: acp.adapterPackage,
|
|
1408
|
-
cli: displayName
|
|
1409
|
-
});
|
|
1410
|
-
}
|
|
1411
|
-
return out;
|
|
1412
|
-
}
|
|
1413
|
-
function printManual(ctx, missing) {
|
|
1414
|
-
const q = (w) => ctx.theme.paint("quiet", w);
|
|
1415
|
-
for (const { pkg } of missing) {
|
|
1416
|
-
ctx.out(` ${adapterInstallCommand(pkg)}\n`);
|
|
1417
|
-
ctx.out(` ${q(`or run it on demand: ${adapterNpxCommand(pkg)}`)}\n`);
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
/**
|
|
1421
|
-
* Ask once whether ACP workers may fetch the adapters with npx. `--acp-adapters` and
|
|
1422
|
-
* `--no-acp-adapters` answer without asking and replace an earlier answer. Without a terminal, or
|
|
1423
|
-
* with `--yes`, nothing is asked and nothing is saved.
|
|
1424
|
-
*/
|
|
1425
|
-
async function offerAcpAdapters(ctx, opts) {
|
|
1426
|
-
const t = ctx.theme;
|
|
1427
|
-
const path = dataPaths(ctx.platform, ctx.dataDir).settings;
|
|
1428
|
-
const missing = missingAdapters(ctx, opts.installed);
|
|
1429
|
-
if (opts.flag !== void 0) {
|
|
1430
|
-
writeSettings(path, { acpAdapterNpx: opts.flag });
|
|
1431
|
-
if (opts.flag) ctx.out(`${t.status("ok")} ACP workers may fetch adapters with npx (pinned versions).\n`);
|
|
1432
|
-
else {
|
|
1433
|
-
ctx.out(`${t.status("info")} ACP workers will not fetch adapters with npx.\n`);
|
|
1434
|
-
if (missing.length > 0) {
|
|
1435
|
-
ctx.out(" To use ACP workers, install the adapters yourself:\n");
|
|
1436
|
-
printManual(ctx, missing);
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
return;
|
|
605
|
+
async function offerAcpAdapters(ctx, opts) {
|
|
606
|
+
const t = ctx.theme;
|
|
607
|
+
const path = dataPaths(ctx.platform, ctx.dataDir).settings;
|
|
608
|
+
const missing = missingAdapters(ctx, opts.installed);
|
|
609
|
+
if (opts.flag !== void 0) {
|
|
610
|
+
writeSettings(path, { acpAdapterNpx: opts.flag });
|
|
611
|
+
if (opts.flag) ctx.out(`${t.status("ok")} ACP workers may fetch adapters with npx (pinned versions).\n`);
|
|
612
|
+
else {
|
|
613
|
+
ctx.out(`${t.status("info")} ACP workers will not fetch adapters with npx.\n`);
|
|
614
|
+
if (missing.length > 0) {
|
|
615
|
+
ctx.out(" To use ACP workers, install the adapters yourself:\n");
|
|
616
|
+
printManual(ctx, missing);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
return;
|
|
1440
620
|
}
|
|
1441
621
|
if (missing.length === 0) return;
|
|
1442
622
|
if (readSettings(path).acpAdapterNpx !== void 0) return;
|
|
@@ -2085,815 +1265,230 @@ async function initSetup(ctx, argv, outcome) {
|
|
|
2085
1265
|
outcome.offer = installed.map((f) => f.adapter);
|
|
2086
1266
|
return 0;
|
|
2087
1267
|
}
|
|
2088
|
-
// src/
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
const problem = daemonProblem(t, e);
|
|
2095
|
-
return fail(ctx, {
|
|
2096
|
-
what: problem.notRunning ? "The Conveno daemon is not running" : "The Conveno daemon cannot be reached",
|
|
2097
|
-
detail: [problem.notRunning ? "Sessions live in the daemon, so there is nothing to peek at until it runs." : problem.why],
|
|
2098
|
-
fix: problem.notRunning ? `Run ${cmd(t, "conveno daemon start")}.` : problem.fix,
|
|
2099
|
-
exit: 1,
|
|
2100
|
-
ref: "e_daemon"
|
|
2101
|
-
});
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
|
-
const isSessionRef = (s) => SessionId.safeParse(s).success || SessionNameInput.safeParse(s).success;
|
|
2105
|
-
function badSession(ctx, name) {
|
|
2106
|
-
return fail(ctx, {
|
|
2107
|
-
what: `"${name}" is not a session name`,
|
|
2108
|
-
detail: ["Names use lowercase letters, digits and \".\", \"_\", \"@\" or \"-\"."],
|
|
2109
|
-
fix: `Run ${cmd(ctx.theme, "conveno status")} to see the names.`,
|
|
2110
|
-
exit: 2,
|
|
2111
|
-
ref: "e_usage"
|
|
2112
|
-
});
|
|
2113
|
-
}
|
|
2114
|
-
/** `conveno peek on|off [session]`: the owner's switch. */
|
|
2115
|
-
async function runSwitch(ctx, peekable, session) {
|
|
2116
|
-
const t = ctx.theme;
|
|
2117
|
-
if (session !== void 0 && !isSessionRef(session)) return badSession(ctx, session);
|
|
2118
|
-
const client = await connectOrFail(ctx);
|
|
2119
|
-
if (typeof client === "number") return client;
|
|
2120
|
-
try {
|
|
2121
|
-
const res = await client["session.setPeekable"]({
|
|
2122
|
-
peekable,
|
|
2123
|
-
...session !== void 0 ? { session } : {}
|
|
2124
|
-
});
|
|
2125
|
-
if (res.sessions.length === 0) {
|
|
2126
|
-
ctx.out(`${t.status("info")} No online sessions, so nothing changed.\n`);
|
|
2127
|
-
return 0;
|
|
2128
|
-
}
|
|
2129
|
-
const names = res.sessions.map((s) => s.name).join(", ");
|
|
2130
|
-
ctx.out(`${t.status("ok")} Peek is ${t.bold(peekable ? "on" : "off")} for ${plural(res.sessions.length, "session")}: ${names}\n`);
|
|
2131
|
-
if (session === void 0) ctx.out(` ${t.paint("quiet", "Sessions that start later are peekable by default. Run it again after they start.")}\n`);
|
|
2132
|
-
return 0;
|
|
2133
|
-
} catch (e) {
|
|
2134
|
-
return daemonFailure(ctx, e);
|
|
2135
|
-
} finally {
|
|
2136
|
-
await client.close().catch(() => void 0);
|
|
2137
|
-
}
|
|
2138
|
-
}
|
|
2139
|
-
function daemonFailure(ctx, e) {
|
|
2140
|
-
const t = ctx.theme;
|
|
2141
|
-
if (e instanceof ConvenoError) {
|
|
2142
|
-
const permission = e.code === RpcErrorCode.PermissionRequired;
|
|
2143
|
-
return fail(ctx, {
|
|
2144
|
-
what: permission ? "Peek is turned off for that session" : e.message,
|
|
2145
|
-
...permission ? { detail: [e.message] } : {},
|
|
2146
|
-
fix: e.code === RpcErrorCode.NotFound ? `Run ${cmd(t, "conveno status")} to see the sessions that are online.` : permission ? "Its owner turns peek on again with the command above." : `Run ${cmd(t, "conveno doctor")} if this keeps happening.`,
|
|
2147
|
-
exit: 1,
|
|
2148
|
-
ref: permission ? "e_peek_off" : "e_peek"
|
|
2149
|
-
});
|
|
2150
|
-
}
|
|
2151
|
-
const problem = daemonProblem(t, e);
|
|
2152
|
-
return fail(ctx, {
|
|
2153
|
-
what: "The Conveno daemon could not answer",
|
|
2154
|
-
detail: [problem.why],
|
|
2155
|
-
fix: problem.fix,
|
|
2156
|
-
exit: 1,
|
|
2157
|
-
ref: "e_daemon"
|
|
2158
|
-
});
|
|
2159
|
-
}
|
|
2160
|
-
/** `conveno peek <session> [-n N] [--raw-json]`: what another session did lately, secrets redacted. */
|
|
2161
|
-
async function runPeek(ctx, argv) {
|
|
2162
|
-
const t = ctx.theme;
|
|
2163
|
-
const spec = COMMANDS.find((c) => c.name === "peek");
|
|
2164
|
-
if (!spec) return 2;
|
|
2165
|
-
const parsed = parseFlags(ctx, spec, argv);
|
|
2166
|
-
if (typeof parsed === "number") return parsed;
|
|
2167
|
-
const [first, second] = parsed.positionals;
|
|
2168
|
-
if (first === void 0) return fail(ctx, {
|
|
2169
|
-
what: "conveno peek needs a session",
|
|
2170
|
-
detail: ["Name the session to read, or use on or off to switch peek for your sessions."],
|
|
2171
|
-
fix: `For example ${cmd(t, "conveno peek claude@api-1")} or ${cmd(t, "conveno peek off")}.`,
|
|
2172
|
-
exit: 2,
|
|
2173
|
-
ref: "e_usage"
|
|
2174
|
-
});
|
|
2175
|
-
if (first === "on" || first === "off") return runSwitch(ctx, first === "on", second);
|
|
2176
|
-
if (!isSessionRef(first)) return badSession(ctx, first);
|
|
2177
|
-
const nText = typeof parsed.values.n === "string" ? parsed.values.n : void 0;
|
|
2178
|
-
const n = nText === void 0 ? 10 : Number(nText);
|
|
2179
|
-
if (!Number.isInteger(n) || n < 1 || n > 50) return fail(ctx, {
|
|
2180
|
-
what: `"${nText}" is not a number of turns`,
|
|
2181
|
-
detail: [`Use a whole number from 1 to 50.`],
|
|
2182
|
-
fix: `For example ${cmd(t, `conveno peek ${first} -n 20`)}.`,
|
|
2183
|
-
exit: 2,
|
|
2184
|
-
ref: "e_usage"
|
|
2185
|
-
});
|
|
2186
|
-
const client = await connectOrFail(ctx);
|
|
2187
|
-
if (typeof client === "number") return client;
|
|
2188
|
-
try {
|
|
2189
|
-
const res = await client["session.peek"]({
|
|
2190
|
-
target: first,
|
|
2191
|
-
lastTurns: n
|
|
2192
|
-
});
|
|
2193
|
-
if (parsed.values["raw-json"] === true) {
|
|
2194
|
-
ctx.out(`${JSON.stringify(res, null, 2)}\n`);
|
|
2195
|
-
return 0;
|
|
2196
|
-
}
|
|
2197
|
-
ctx.out(`${t.bold(res.session.name)} ${t.paint("quiet", `${res.session.cli}, last ${plural(res.turns.length, "turn")}, secrets redacted (best effort)`)}\n`);
|
|
2198
|
-
if (res.turns.length === 0) ctx.out(`\n${t.paint("quiet", "The transcript has no turns yet.")}\n`);
|
|
2199
|
-
for (const turn of res.turns) {
|
|
2200
|
-
const stamp = turn.at ? ` ${t.paint("quiet", localStamp(turn.at))}` : "";
|
|
2201
|
-
ctx.out(`\n${t.bold(turn.role)}${stamp}\n${turn.text.replace(/\n/g, "\n ").replace(/^/, " ")}\n`);
|
|
2202
|
-
}
|
|
2203
|
-
if (res.truncated) ctx.out(`\n${t.paint("quiet", `Earlier turns, or long text, are left out. ${cmd(t, `conveno peek ${first} -n 50`)} reads more.`)}\n`);
|
|
2204
|
-
return 0;
|
|
2205
|
-
} catch (e) {
|
|
2206
|
-
return daemonFailure(ctx, e);
|
|
2207
|
-
} finally {
|
|
2208
|
-
await client.close().catch(() => void 0);
|
|
2209
|
-
}
|
|
1268
|
+
// src/doctor.ts
|
|
1269
|
+
/** What the plan says about one part: nothing to do, an addition, or an update to what is there. */
|
|
1270
|
+
function partState(changes, component) {
|
|
1271
|
+
const mine = changes.filter((c) => c.component === component);
|
|
1272
|
+
if (mine.length === 0) return "ok";
|
|
1273
|
+
return mine.some((c) => c.kind === "add") ? "missing" : "outdated";
|
|
2210
1274
|
}
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
1275
|
+
/** Time allowed for the one process-table query. */
|
|
1276
|
+
const ANCESTRY_TIMEOUT_MS = 5e3;
|
|
1277
|
+
const tierWord = (t) => t === "next_turn" ? "next turn" : t;
|
|
1278
|
+
const hasAny = (c) => c !== void 0 && (c.nextTurn || c.endOfTurn || c.idleWake);
|
|
1279
|
+
/**
|
|
1280
|
+
* The delivery tiers that work right now for one CLI: what the adapter can do for this version,
|
|
1281
|
+
* once its hooks (or plugin) are in place. Without them only the inbox tool is left.
|
|
1282
|
+
*/
|
|
1283
|
+
function activeTiers(row) {
|
|
1284
|
+
const caps = row.adapter.delivery?.(row.detection);
|
|
1285
|
+
if (!caps) return row.adapter.deliveryTier === "inbox" || row.hooks === "ok" ? [tierWord(row.adapter.deliveryTier)] : ["inbox"];
|
|
1286
|
+
if (!hasAny(caps) || row.hooks !== "ok") return ["inbox"];
|
|
1287
|
+
return [
|
|
1288
|
+
...caps.nextTurn ? ["next turn"] : [],
|
|
1289
|
+
...caps.endOfTurn ? ["end of turn"] : [],
|
|
1290
|
+
...caps.idleWake ? ["idle wake"] : []
|
|
1291
|
+
];
|
|
2227
1292
|
}
|
|
2228
|
-
|
|
2229
|
-
const
|
|
2230
|
-
|
|
2231
|
-
};
|
|
2232
|
-
/** The first line of a ticket, which for a permission request is its title line. */
|
|
2233
|
-
const headline = (t) => oneLine(t.question.split("\n")[0] ?? "", 70);
|
|
2234
|
-
async function runTickets(ctx, argv) {
|
|
2235
|
-
const t = ctx.theme;
|
|
2236
|
-
const spec = COMMANDS.find((c) => c.name === "tickets");
|
|
2237
|
-
if (!spec) return 2;
|
|
2238
|
-
const parsed = parseFlags(ctx, spec, argv);
|
|
2239
|
-
if (typeof parsed === "number") return parsed;
|
|
2240
|
-
const openOnly = parsed.values.open === true;
|
|
2241
|
-
const client = await connectRunning(ctx, "Tickets live in the daemon, so there are none to list.");
|
|
2242
|
-
if ("exit" in client) return client.exit;
|
|
1293
|
+
async function inspect(ctx, adapter) {
|
|
1294
|
+
const env = adapterEnv(ctx);
|
|
1295
|
+
let detection;
|
|
2243
1296
|
try {
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
if (res.tickets.length === 0) {
|
|
2251
|
-
ctx.out(`${t.status("info")} ${openOnly ? "No open tickets." : "No tickets yet."} ${t.paint("quiet", "Workers raise them with the ask tool.")}\n`);
|
|
2252
|
-
return 0;
|
|
2253
|
-
}
|
|
2254
|
-
const q = (w) => t.paint("quiet", w);
|
|
2255
|
-
const rows = [[
|
|
2256
|
-
` ${q("TICKET")}`,
|
|
2257
|
-
q("STATE"),
|
|
2258
|
-
q("FROM"),
|
|
2259
|
-
q("TO"),
|
|
2260
|
-
q("WHEN"),
|
|
2261
|
-
q("QUESTION")
|
|
2262
|
-
], ...res.tickets.map((k) => [
|
|
2263
|
-
` ${t.bold(k.id)}`,
|
|
2264
|
-
k.status === "open" ? t.paint("entry", "open") : q(k.status),
|
|
2265
|
-
who(k.fromSession),
|
|
2266
|
-
who(k.toSession),
|
|
2267
|
-
q(stamp(k.createdAt, ctx.now())),
|
|
2268
|
-
`${k.kind === "permission" ? `${t.paint("warn", "permission")} ` : ""}${headline(k)}`
|
|
2269
|
-
])];
|
|
2270
|
-
ctx.out(`${columns(rows).join("\n")}\n\n`);
|
|
2271
|
-
const hint = res.openCount > 0 ? ` Answer with ${cmd(t, "conveno answer <ticket> <text>")}.` : "";
|
|
2272
|
-
ctx.out(`${plural(res.openCount, "open ticket")}.${hint}\n`);
|
|
2273
|
-
return 0;
|
|
2274
|
-
} finally {
|
|
2275
|
-
await client.close().catch(() => void 0);
|
|
1297
|
+
detection = await adapter.detect(env);
|
|
1298
|
+
} catch {
|
|
1299
|
+
detection = {
|
|
1300
|
+
installed: false,
|
|
1301
|
+
configPaths: []
|
|
1302
|
+
};
|
|
2276
1303
|
}
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
const
|
|
2284
|
-
if (hits.length === 1 && hits[0]) return hits[0];
|
|
2285
|
-
return hits.length === 0 ? `No ticket matches "${text}".` : `"${text}" matches ${hits.length} tickets.`;
|
|
2286
|
-
}
|
|
2287
|
-
async function runAnswer(ctx, argv) {
|
|
2288
|
-
const t = ctx.theme;
|
|
2289
|
-
const spec = COMMANDS.find((c) => c.name === "answer");
|
|
2290
|
-
if (!spec) return 2;
|
|
2291
|
-
const parsed = parseFlags(ctx, spec, argv);
|
|
2292
|
-
if (typeof parsed === "number") return parsed;
|
|
2293
|
-
const [id, ...words] = parsed.positionals;
|
|
2294
|
-
const response = words.join(" ").trim();
|
|
2295
|
-
if (!id || response === "") return fail(ctx, {
|
|
2296
|
-
what: "conveno answer needs a ticket and an answer",
|
|
2297
|
-
fix: `For example ${cmd(t, "conveno answer 01J8ABCD \"Use sqlite\"")}. ${cmd(t, "conveno tickets --open")} lists the open tickets.`,
|
|
2298
|
-
exit: 2,
|
|
2299
|
-
ref: "e_usage"
|
|
2300
|
-
});
|
|
2301
|
-
const client = await connectRunning(ctx, "Tickets live in the daemon, so there is nothing to answer.");
|
|
2302
|
-
if ("exit" in client) return client.exit;
|
|
1304
|
+
if (!detection.installed) return {
|
|
1305
|
+
adapter,
|
|
1306
|
+
detection,
|
|
1307
|
+
mcp: null,
|
|
1308
|
+
hooks: null
|
|
1309
|
+
};
|
|
1310
|
+
const hasHooks = adapter.deliveryTier !== "inbox" || hasAny(adapter.delivery?.(detection));
|
|
2303
1311
|
try {
|
|
2304
|
-
const
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
});
|
|
2312
|
-
const res = await client["ticket.answer"]({
|
|
2313
|
-
ticketId: picked.id,
|
|
2314
|
-
response
|
|
2315
|
-
});
|
|
2316
|
-
const who = res.ticket.kind === "permission" ? "The worker's CLI" : "The asker";
|
|
2317
|
-
ctx.out(`${t.status("ok")} ${t.bold("Answered")} ${res.ticket.id} ${t.paint("quiet", `(${res.ticket.answeredBy === "human" ? "by you" : "recorded"}). ${who} gets it now.`)}\n`);
|
|
2318
|
-
return 0;
|
|
1312
|
+
const changes = await adapter.plan(env);
|
|
1313
|
+
return {
|
|
1314
|
+
adapter,
|
|
1315
|
+
detection,
|
|
1316
|
+
mcp: partState(changes, "mcp"),
|
|
1317
|
+
hooks: hasHooks ? partState(changes, "hooks") : null
|
|
1318
|
+
};
|
|
2319
1319
|
} catch (e) {
|
|
2320
|
-
return
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
}
|
|
2327
|
-
} finally {
|
|
2328
|
-
await client.close().catch(() => void 0);
|
|
1320
|
+
return {
|
|
1321
|
+
adapter,
|
|
1322
|
+
detection,
|
|
1323
|
+
mcp: "missing",
|
|
1324
|
+
hooks: hasHooks ? "missing" : null,
|
|
1325
|
+
planError: plainError(e)
|
|
1326
|
+
};
|
|
2329
1327
|
}
|
|
2330
1328
|
}
|
|
2331
|
-
// src/permissions.ts
|
|
2332
|
-
const RELAY_WARNING = "EXPERIMENTAL: while the relay is on, the orchestrator can allow or deny this session's tool calls. Calls outside its repo, network and credential access always stay with you. See SECURITY.md.";
|
|
2333
1329
|
/**
|
|
2334
|
-
*
|
|
2335
|
-
*
|
|
2336
|
-
*
|
|
1330
|
+
* A note for a CLI outside the tested range. Older than the minimum is a problem. Past the tested
|
|
1331
|
+
* major or minor version is a warning. A patch release ahead gets only the short table note: CLIs
|
|
1332
|
+
* like Claude Code ship patches almost daily, and they rarely change config or hook formats.
|
|
2337
1333
|
*/
|
|
2338
|
-
|
|
2339
|
-
const
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
exit: 1,
|
|
2347
|
-
ref: "e_relay"
|
|
2348
|
-
});
|
|
2349
|
-
for (const cli of new Set(targets.map((s) => s.cli))) {
|
|
2350
|
-
const adapter = ctx.adapters.find((a) => a.cli === cli);
|
|
2351
|
-
if (!adapter?.permissionHookInstalled) return fail(ctx, {
|
|
2352
|
-
what: `The permission relay does not support ${cli}`,
|
|
2353
|
-
detail: ["It needs a hook that runs only when the CLI is about to ask for a permission. Claude Code and Codex have one; see SECURITY.md for the others."],
|
|
2354
|
-
fix: `Use the relay with a Claude Code or Codex worker.`,
|
|
1334
|
+
function versionBlock(t, adapter, version, status) {
|
|
1335
|
+
const name = adapter.displayName;
|
|
1336
|
+
if (status.kind === "older") return {
|
|
1337
|
+
problem: true,
|
|
1338
|
+
text: errorBlock(t, {
|
|
1339
|
+
what: `${name} ${version} is older than Conveno supports`,
|
|
1340
|
+
detail: [`Conveno needs ${name} ${status.minimum} or newer.`],
|
|
1341
|
+
fix: `Upgrade ${name}, then run ${cmd(t, "conveno doctor")} again.`,
|
|
2355
1342
|
exit: 1,
|
|
2356
|
-
ref: "
|
|
2357
|
-
})
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
installed: true,
|
|
2364
|
-
change
|
|
2365
|
-
});
|
|
2366
|
-
} catch (e) {
|
|
2367
|
-
return fail(ctx, {
|
|
2368
|
-
what: `Could not plan the ${adapter.displayName} permission hook`,
|
|
2369
|
-
detail: [plainError(e)],
|
|
2370
|
-
fix: "Fix the problem above, then run the command again.",
|
|
2371
|
-
exit: 1,
|
|
2372
|
-
ref: "e_plan"
|
|
2373
|
-
});
|
|
2374
|
-
}
|
|
2375
|
-
}
|
|
2376
|
-
if (items.length === 0) return void 0;
|
|
2377
|
-
ctx.out(`${t.status("info")} The relay needs a ${[...new Set(items.map((i) => i.cli))].join(" and ")} PermissionRequest hook. It is not installed yet.\n\n`);
|
|
2378
|
-
const result = await confirmAndApply(ctx, items, {
|
|
2379
|
-
yes,
|
|
2380
|
-
verb: "Apply",
|
|
2381
|
-
rerun: `conveno permissions relay on${named ? ` ${named}` : ""}`
|
|
2382
|
-
});
|
|
2383
|
-
if ("exit" in result) return result.exit === 0 ? 0 : result.exit;
|
|
2384
|
-
ctx.out(`${t.status("ok")} Hook added. Restart the open ${[...new Set(items.map((i) => i.cli))].join(" and ")} sessions so they load it${items.some((i) => i.cli === "codex") ? ", and trust it in Codex with /hooks" : ""}.\n`);
|
|
1343
|
+
ref: "e_cli_old"
|
|
1344
|
+
})
|
|
1345
|
+
};
|
|
1346
|
+
if (status.kind === "newer" && status.minor) return {
|
|
1347
|
+
problem: false,
|
|
1348
|
+
text: warnBlock(t, `${name} ${version} is newer than the ${status.verified} Conveno was tested with.`, "Nothing to do unless messages stop arriving. Please report it at https://github.com/0xPixelNinja/conveno/issues if something breaks.", "CLI vendors change config and hook formats often. A nightly check tests the newest releases and raises the tested version when they pass.")
|
|
1349
|
+
};
|
|
2385
1350
|
}
|
|
2386
|
-
async function
|
|
1351
|
+
async function runDoctor(ctx, argv = []) {
|
|
2387
1352
|
const t = ctx.theme;
|
|
2388
|
-
const spec = COMMANDS.find((c) => c.name === "
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
ref: "e_usage"
|
|
2399
|
-
});
|
|
2400
|
-
const client = await connectRunning(ctx, "The permission relay lives in the daemon.");
|
|
2401
|
-
if ("exit" in client) return client.exit;
|
|
2402
|
-
try {
|
|
2403
|
-
const sessions = (await client["session.list"]({ includeOffline: true })).sessions;
|
|
2404
|
-
const nameOf = (id) => sessions.find((s) => s.id === id)?.name ?? id.slice(-6);
|
|
2405
|
-
if (sub === void 0) {
|
|
2406
|
-
const { relays } = await client["permission.relay"]({});
|
|
2407
|
-
ctx.out(`${t.status("warn")} ${t.paint("quiet", "Permission relay is EXPERIMENTAL and off unless listed.")}\n`);
|
|
2408
|
-
if (relays.length === 0) ctx.out(`${t.status("info")} The relay is off for every session.\n`);
|
|
2409
|
-
else {
|
|
2410
|
-
const rows = relays.map((r) => `${nameOf(r.session)} (approved by ${nameOf(r.approver)})`);
|
|
2411
|
-
ctx.out(`${t.bold("Relay on for:")} ${rows.join(", ")}\n`);
|
|
2412
|
-
}
|
|
2413
|
-
ctx.out(` ${t.paint("quiet", `Turn it on with ${cmd(t, "conveno permissions relay on <session>")}. SECURITY.md has the threat model.`)}\n`);
|
|
2414
|
-
return 0;
|
|
2415
|
-
}
|
|
2416
|
-
const enable = state === "on";
|
|
2417
|
-
let targets;
|
|
2418
|
-
if (name !== void 0) {
|
|
2419
|
-
const found = sessions.find((s) => s.name === name && s.status !== "offline");
|
|
2420
|
-
if (!found) return fail(ctx, {
|
|
2421
|
-
what: `No online session named "${name}"`,
|
|
2422
|
-
fix: `Run ${cmd(t, "conveno status")} to see the names.`,
|
|
2423
|
-
exit: 1,
|
|
2424
|
-
ref: "e_no_session"
|
|
2425
|
-
});
|
|
2426
|
-
targets = [found];
|
|
2427
|
-
} else if (enable) {
|
|
2428
|
-
targets = sessions.filter((s) => s.spawned && s.status !== "offline");
|
|
2429
|
-
if (targets.length !== 1) return fail(ctx, {
|
|
2430
|
-
what: targets.length === 0 ? "No session started by Conveno is online" : "More than one spawned session is online",
|
|
2431
|
-
detail: ["The relay is only for sessions started with conveno spawn or spawn_session, never for one you drive yourself."],
|
|
2432
|
-
fix: `Name the session: ${cmd(t, "conveno permissions relay on <session>")}.`,
|
|
2433
|
-
exit: 2,
|
|
2434
|
-
ref: "e_usage"
|
|
2435
|
-
});
|
|
2436
|
-
} else {
|
|
2437
|
-
const { relays } = await client["permission.relay"]({});
|
|
2438
|
-
targets = sessions.filter((s) => relays.some((r) => r.session === s.id));
|
|
2439
|
-
if (targets.length === 0) {
|
|
2440
|
-
ctx.out(`${t.status("info")} The relay was already off for every session.\n`);
|
|
2441
|
-
return 0;
|
|
2442
|
-
}
|
|
2443
|
-
}
|
|
2444
|
-
if (enable) {
|
|
2445
|
-
const code = await ensureHooks(ctx, targets, name, parsed.values.yes === true);
|
|
2446
|
-
if (code !== void 0) return code;
|
|
2447
|
-
}
|
|
2448
|
-
for (const target of targets) {
|
|
2449
|
-
let approver;
|
|
2450
|
-
try {
|
|
2451
|
-
approver = (await client["permission.relay"]({
|
|
2452
|
-
target: target.id,
|
|
2453
|
-
enabled: enable
|
|
2454
|
-
})).relays.find((r) => r.session === target.id)?.approver;
|
|
2455
|
-
} catch (e) {
|
|
2456
|
-
return fail(ctx, {
|
|
2457
|
-
what: `The relay could not be turned ${state} for ${target.name}`,
|
|
2458
|
-
detail: [e instanceof Error ? e.message : String(e)],
|
|
2459
|
-
fix: usage,
|
|
2460
|
-
exit: 1,
|
|
2461
|
-
ref: "e_relay"
|
|
2462
|
-
});
|
|
2463
|
-
}
|
|
2464
|
-
ctx.out(`${t.status(enable ? "warn" : "ok")} Permission relay ${state} for ${t.bold(target.name)}.${approver ? ` ${nameOf(approver)} approves its prompts, and no one who takes the role later.` : ""}\n`);
|
|
2465
|
-
}
|
|
2466
|
-
if (enable) ctx.out(` ${RELAY_WARNING}\n`);
|
|
2467
|
-
return 0;
|
|
2468
|
-
} finally {
|
|
2469
|
-
await client.close().catch(() => void 0);
|
|
2470
|
-
}
|
|
2471
|
-
}
|
|
2472
|
-
// src/spawn.ts
|
|
2473
|
-
/** Read the task from `--task-file`. Returns the text or the failure's exit code. */
|
|
2474
|
-
function readTaskFile(ctx, path) {
|
|
2475
|
-
try {
|
|
2476
|
-
return readFileSync(resolve(ctx.cwd, path), "utf8");
|
|
2477
|
-
} catch (e) {
|
|
2478
|
-
const code = e.code;
|
|
2479
|
-
return fail(ctx, {
|
|
2480
|
-
what: `Cannot read the task file ${path}`,
|
|
2481
|
-
detail: [code === "ENOENT" ? "The file does not exist." : `The system said ${code ?? "no"}.`],
|
|
2482
|
-
fix: "Check the path, or pass the task with --task.",
|
|
1353
|
+
const spec = COMMANDS.find((c) => c.name === "doctor");
|
|
1354
|
+
let adapters = ctx.adapters;
|
|
1355
|
+
if (spec) {
|
|
1356
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
1357
|
+
if (typeof parsed === "number") return parsed;
|
|
1358
|
+
const chosen = parseCliList(typeof parsed.values.cli === "string" ? parsed.values.cli : void 0, ctx);
|
|
1359
|
+
if (!Array.isArray(chosen)) return fail(ctx, {
|
|
1360
|
+
what: chosen.message,
|
|
1361
|
+
fix: `Pass ${cmd(t, "--cli claude,codex,opencode")} or leave it out.`,
|
|
1362
|
+
...chosen.suggestion ? { didYouMean: chosen.suggestion } : {},
|
|
2483
1363
|
exit: 2,
|
|
2484
1364
|
ref: "e_usage"
|
|
2485
1365
|
});
|
|
1366
|
+
adapters = chosen;
|
|
2486
1367
|
}
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
async function runSpawn(ctx, argv) {
|
|
2493
|
-
const t = ctx.theme;
|
|
2494
|
-
const spec = COMMANDS.find((c) => c.name === "spawn");
|
|
2495
|
-
if (!spec) return 2;
|
|
2496
|
-
const parsed = parseFlags(ctx, spec, argv);
|
|
2497
|
-
if (typeof parsed === "number") return parsed;
|
|
2498
|
-
const help = `Run ${cmd(t, "conveno spawn --help")} to see the options.`;
|
|
2499
|
-
const [cli, ...extra] = parsed.positionals;
|
|
2500
|
-
if (!cli || extra.length > 0) return fail(ctx, {
|
|
2501
|
-
what: "conveno spawn needs exactly one CLI name",
|
|
2502
|
-
detail: [`Known: ${SPAWN_CLIS.join(", ")}.`],
|
|
2503
|
-
fix: `Run ${cmd(t, "conveno spawn claude --task 'review the open PR'")}.`,
|
|
2504
|
-
exit: 2,
|
|
2505
|
-
ref: "e_usage"
|
|
2506
|
-
});
|
|
2507
|
-
if (!Object.hasOwn(SPAWN_TABLE, cli)) return fail(ctx, {
|
|
2508
|
-
what: `"${cli}" is not a CLI Conveno can start`,
|
|
2509
|
-
detail: [`Known: ${SPAWN_CLIS.join(", ")}.`],
|
|
2510
|
-
fix: help,
|
|
2511
|
-
exit: 2,
|
|
2512
|
-
ref: "e_usage"
|
|
2513
|
-
});
|
|
2514
|
-
const str = (k) => typeof parsed.values[k] === "string" ? parsed.values[k] : void 0;
|
|
2515
|
-
if (str("task") !== void 0 && str("task-file") !== void 0) return fail(ctx, {
|
|
2516
|
-
what: "Use --task or --task-file, not both",
|
|
2517
|
-
fix: help,
|
|
2518
|
-
exit: 2,
|
|
2519
|
-
ref: "e_usage"
|
|
2520
|
-
});
|
|
2521
|
-
let task = str("task");
|
|
2522
|
-
const taskFile = str("task-file");
|
|
2523
|
-
if (taskFile !== void 0) {
|
|
2524
|
-
const text = readTaskFile(ctx, taskFile);
|
|
2525
|
-
if (typeof text === "number") return text;
|
|
2526
|
-
task = text;
|
|
2527
|
-
}
|
|
2528
|
-
const acpFlag = parsed.values.acp === true;
|
|
2529
|
-
const oneShot = parsed.values["one-shot"] === true;
|
|
2530
|
-
if (acpFlag && oneShot) return fail(ctx, {
|
|
2531
|
-
what: "Use --acp or --one-shot, not both",
|
|
2532
|
-
fix: help,
|
|
2533
|
-
exit: 2,
|
|
2534
|
-
ref: "e_usage"
|
|
2535
|
-
});
|
|
2536
|
-
const headless = parsed.values.headless === true || acpFlag || oneShot;
|
|
2537
|
-
const acp = acpFlag ? "require" : headless && !oneShot ? "prefer" : void 0;
|
|
2538
|
-
const allowFlag = str("allow");
|
|
2539
|
-
const allow = allowFlag === void 0 ? void 0 : [allowFlag];
|
|
2540
|
-
const yes = parsed.values.yes === true;
|
|
2541
|
-
const adapter = ctx.adapters.find((a) => a.cli === cli);
|
|
2542
|
-
if (adapter && !(await adapter.detect(adapterEnv(ctx))).installed) return fail(ctx, {
|
|
2543
|
-
what: `${adapter.displayName} is not installed`,
|
|
2544
|
-
detail: [`conveno could not run ${cli} --version.`],
|
|
2545
|
-
fix: "Install it, or check that its folder is on PATH.",
|
|
2546
|
-
exit: 1,
|
|
2547
|
-
ref: "e_spawn"
|
|
2548
|
-
});
|
|
2549
|
-
if (!yes) {
|
|
2550
|
-
if (!ctx.interactive) return fail(ctx, {
|
|
2551
|
-
what: "Needs a terminal to confirm",
|
|
2552
|
-
detail: ["Nothing was started."],
|
|
2553
|
-
fix: `Run the same command with ${cmd(t, "--yes")} to start the session without asking.`,
|
|
2554
|
-
exit: 2,
|
|
2555
|
-
ref: "e_no_tty"
|
|
2556
|
-
});
|
|
2557
|
-
const question = `Start ${cli} in ${tilde(resolve(ctx.cwd, str("cwd") ?? "."), ctx.home)}${headless ? " in the background" : ""}${task ? " with a first task" : ""}?`;
|
|
2558
|
-
if (!await ctx.confirm(question, true)) {
|
|
2559
|
-
ctx.out(`${t.status("info")} Nothing was started.\n`);
|
|
2560
|
-
return 0;
|
|
2561
|
-
}
|
|
2562
|
-
}
|
|
2563
|
-
let client;
|
|
1368
|
+
let ok = 0;
|
|
1369
|
+
let warnings = 0;
|
|
1370
|
+
let problems = 0;
|
|
1371
|
+
const notes = [];
|
|
1372
|
+
let daemonLine;
|
|
2564
1373
|
try {
|
|
2565
|
-
client = await ctx.connect(connectOpts(ctx,
|
|
1374
|
+
const client = await ctx.connect(connectOpts(ctx, false));
|
|
1375
|
+
try {
|
|
1376
|
+
const { sessions } = await client["session.list"]({ includeOffline: true });
|
|
1377
|
+
daemonLine = [` ${t.status("ok")} daemon`, `running, ${plural(sessions.length, "session")}`];
|
|
1378
|
+
ok++;
|
|
1379
|
+
} finally {
|
|
1380
|
+
await client.close().catch(() => void 0);
|
|
1381
|
+
}
|
|
2566
1382
|
} catch (e) {
|
|
2567
1383
|
const problem = daemonProblem(t, e);
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
env: ctx.env,
|
|
2583
|
-
home: ctx.home,
|
|
2584
|
-
dataDir: ctx.dataDir,
|
|
2585
|
-
client,
|
|
2586
|
-
runner
|
|
2587
|
-
});
|
|
2588
|
-
const res = await spawnSession(deps, {
|
|
2589
|
-
cli,
|
|
2590
|
-
callerCwd: ctx.cwd,
|
|
2591
|
-
cwd: str("cwd"),
|
|
2592
|
-
name: str("name"),
|
|
2593
|
-
task,
|
|
2594
|
-
headless,
|
|
2595
|
-
acp,
|
|
2596
|
-
allow,
|
|
2597
|
-
requester,
|
|
2598
|
-
confineToHome: false,
|
|
2599
|
-
onProgress: (line) => ctx.err(`${t.paint("quiet", line)}\n`)
|
|
2600
|
-
});
|
|
2601
|
-
const how = res.mode === "acp" ? "over ACP, background" : res.mode === "headless" ? "background" : res.terminal ?? "terminal";
|
|
2602
|
-
ctx.out(`${t.status("ok")} ${t.bold(`Started ${res.name}`)} ${t.paint("quiet", `(${res.cli}, ${how}) in ${tilde(res.cwd, ctx.home)}`)}\n`);
|
|
2603
|
-
if (res.task === "message") ctx.out(` The first task was sent to it as a Conveno message.\n`);
|
|
2604
|
-
if (res.mode === "acp") {
|
|
2605
|
-
ctx.out(` Follow it with ${cmd(t, `conveno attach ${res.name}`)}; end it with ${cmd(t, `conveno stop ${res.name}`)}.\n`);
|
|
2606
|
-
if (res.adapter) ctx.out(` ${t.paint("quiet", `Adapter: ${res.adapter}`)}\n`);
|
|
1384
|
+
if (problem.notRunning) {
|
|
1385
|
+
daemonLine = [` ${t.status("warn")} daemon`, "not running"];
|
|
1386
|
+
warnings++;
|
|
1387
|
+
notes.push(warnBlock(t, "The Conveno daemon is not running.", problem.fix, problem.why));
|
|
1388
|
+
} else {
|
|
1389
|
+
daemonLine = [` ${t.status("error")} daemon`, "cannot be reached"];
|
|
1390
|
+
problems++;
|
|
1391
|
+
notes.push(errorBlock(t, {
|
|
1392
|
+
what: "The Conveno daemon cannot be reached",
|
|
1393
|
+
detail: [problem.why],
|
|
1394
|
+
fix: problem.fix,
|
|
1395
|
+
exit: 1,
|
|
1396
|
+
ref: "e_daemon"
|
|
1397
|
+
}));
|
|
2607
1398
|
}
|
|
2608
|
-
if (res.logPath) ctx.out(` Output: ${tilde(res.logPath, ctx.home)}\n`);
|
|
2609
|
-
ctx.out(` ${t.paint("quiet", `${cmd(t, "conveno status")} lists it. Message it with send to: ${res.name}.`)}\n`);
|
|
2610
|
-
return 0;
|
|
2611
|
-
} catch (e) {
|
|
2612
|
-
if (e instanceof SpawnError) return fail(ctx, {
|
|
2613
|
-
what: "Could not start the session",
|
|
2614
|
-
detail: [e.message],
|
|
2615
|
-
...e.fix ? { fix: e.fix } : {},
|
|
2616
|
-
exit: 1,
|
|
2617
|
-
ref: "e_spawn"
|
|
2618
|
-
});
|
|
2619
|
-
throw e;
|
|
2620
|
-
} finally {
|
|
2621
|
-
await client.close().catch(() => void 0);
|
|
2622
1399
|
}
|
|
2623
|
-
}
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
if (!file) return fail(ctx, {
|
|
2628
|
-
what: "conveno spawn-run needs a launch file",
|
|
2629
|
-
detail: ["It is started by conveno spawn inside the new terminal."],
|
|
2630
|
-
fix: `Run ${cmd(ctx.theme, "conveno spawn <cli>")} instead.`,
|
|
2631
|
-
exit: 2,
|
|
2632
|
-
ref: "e_usage"
|
|
2633
|
-
});
|
|
2634
|
-
try {
|
|
2635
|
-
return await runLaunchFile(file);
|
|
2636
|
-
} catch (e) {
|
|
2637
|
-
return fail(ctx, {
|
|
2638
|
-
what: "Could not read the launch file",
|
|
2639
|
-
detail: [e instanceof Error ? e.message : String(e)],
|
|
2640
|
-
fix: `Run ${cmd(ctx.theme, "conveno spawn <cli>")} again.`,
|
|
2641
|
-
exit: 1,
|
|
2642
|
-
ref: "e_spawn"
|
|
2643
|
-
});
|
|
2644
|
-
}
|
|
2645
|
-
}
|
|
2646
|
-
// src/uninstall.ts
|
|
2647
|
-
const NOTE = {
|
|
2648
|
-
restore: "restored byte for byte",
|
|
2649
|
-
remove: "removed, it did not exist before",
|
|
2650
|
-
edit: "edited since init, so only Conveno's entries are removed",
|
|
2651
|
-
gone: "already gone, left as it is"
|
|
2652
|
-
};
|
|
2653
|
-
/**
|
|
2654
|
-
* The files as init found them, from the backups: their text, or null when they did not exist. A
|
|
2655
|
-
* backup that cannot be read leaves its file out, and the adapter then treats what it finds as
|
|
2656
|
-
* Conveno's own.
|
|
2657
|
-
*/
|
|
2658
|
-
async function baselineOf(dir, entries) {
|
|
2659
|
-
const out = /* @__PURE__ */ new Map();
|
|
2660
|
-
for (const e of entries) if (e.backup === null) out.set(e.path, null);
|
|
2661
|
-
else try {
|
|
2662
|
-
out.set(e.path, await readFile(join(dir, e.backup), "utf8"));
|
|
2663
|
-
} catch {}
|
|
2664
|
-
return out;
|
|
2665
|
-
}
|
|
2666
|
-
/** Remove Conveno's own entries from files that changed since init, through each adapter. */
|
|
2667
|
-
async function removeOwnEntries(ctx, dir, entries) {
|
|
2668
|
-
if (entries.length === 0) return {
|
|
2669
|
-
edited: [],
|
|
2670
|
-
failures: []
|
|
2671
|
-
};
|
|
2672
|
-
const clis = new Set(entries.map((e) => e.cli));
|
|
2673
|
-
const { items, failures } = await collectPlans(ctx, (await detectAll(ctx)).filter((f) => clis.has(f.adapter.cli)), "uninstallPlan", await baselineOf(dir, entries));
|
|
2674
|
-
const wanted = new Set(entries.map((e) => e.path));
|
|
2675
|
-
const mine = items.filter((i) => wanted.has(i.change.path));
|
|
2676
|
-
if (mine.length > 0) await applyChanges(ctx, mine, { markRestored: true });
|
|
2677
|
-
return {
|
|
2678
|
-
edited: mine.map((i) => i.change.path),
|
|
2679
|
-
failures
|
|
2680
|
-
};
|
|
2681
|
-
}
|
|
2682
|
-
async function restoreAll(ctx, manifests) {
|
|
2683
|
-
const restored = [];
|
|
2684
|
-
const edited = [];
|
|
2685
|
-
const untouched = [];
|
|
2686
|
-
for (const found of manifests) {
|
|
2687
|
-
const needEdit = [];
|
|
2688
|
-
for (const entry of found.manifest.entries) {
|
|
2689
|
-
const action = await restoreEntry(found.dir, entry);
|
|
2690
|
-
if (action === "edit") needEdit.push(entry);
|
|
2691
|
-
else if (action === "gone") untouched.push(entry.path);
|
|
2692
|
-
else restored.push(entry.path);
|
|
2693
|
-
}
|
|
2694
|
-
const r = await removeOwnEntries(ctx, found.dir, needEdit);
|
|
2695
|
-
if (r.failures.length > 0) {
|
|
2696
|
-
reportFailures(ctx, r.failures, "conveno uninstall");
|
|
2697
|
-
throw new Error("A config file could not be read, so it was left as it is.");
|
|
2698
|
-
}
|
|
2699
|
-
edited.push(...r.edited);
|
|
2700
|
-
for (const e of needEdit) if (!r.edited.includes(e.path)) untouched.push(e.path);
|
|
2701
|
-
await markRestored(ctx, found);
|
|
1400
|
+
ctx.out(`${columns([daemonLine]).join("\n")}\n\n`);
|
|
1401
|
+
if (!(await ctx.ancestry(ANCESTRY_TIMEOUT_MS)).complete) {
|
|
1402
|
+
warnings++;
|
|
1403
|
+
notes.push(warnBlock(t, "Process ancestry is unavailable.", `Run ${cmd(t, "conveno doctor")} from a normal desktop session, or allow this user to read the process list. Messages still reach the inbox tool either way.`, ctx.platform === "win32" ? "Windows refused the process list (WMI denies it to non-admin remote logons such as SSH). A hook can then only match a session whose CLI is its direct parent, so next-turn delivery can miss sessions started through a launcher such as conveno.cmd." : "The process list could not be read. A hook can then only match a session whose CLI is its direct parent, so next-turn delivery can miss sessions started through a launcher or a shell."));
|
|
2702
1404
|
}
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
const
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
exit: 2,
|
|
2729
|
-
ref: "e_no_tty"
|
|
2730
|
-
});
|
|
2731
|
-
if (!await ctx.confirm("Undo these changes?", false)) {
|
|
2732
|
-
ctx.out(`${t.status("info")} Nothing was changed.\n`);
|
|
2733
|
-
return 0;
|
|
2734
|
-
}
|
|
1405
|
+
const rows = await Promise.all(adapters.map((a) => inspect(ctx, a)));
|
|
1406
|
+
const q = (w) => t.paint("quiet", w);
|
|
1407
|
+
const table = [[
|
|
1408
|
+
` ${q("CLI")}`,
|
|
1409
|
+
q("NAME"),
|
|
1410
|
+
q("VERSION"),
|
|
1411
|
+
q("MCP"),
|
|
1412
|
+
q("HOOKS"),
|
|
1413
|
+
q("DELIVERY"),
|
|
1414
|
+
q("NOTE")
|
|
1415
|
+
]];
|
|
1416
|
+
const yesNo = (v) => v === null ? q("n/a") : v === "ok" ? "yes" : t.paint("warn", v === "missing" ? "not configured" : "needs update");
|
|
1417
|
+
for (const r of rows) {
|
|
1418
|
+
const { adapter, detection } = r;
|
|
1419
|
+
if (!detection.installed) {
|
|
1420
|
+
table.push([
|
|
1421
|
+
` ${t.glyph("offline")} ${adapter.cli}`,
|
|
1422
|
+
adapter.displayName,
|
|
1423
|
+
"",
|
|
1424
|
+
"",
|
|
1425
|
+
"",
|
|
1426
|
+
"",
|
|
1427
|
+
q("not found on PATH")
|
|
1428
|
+
]);
|
|
1429
|
+
continue;
|
|
2735
1430
|
}
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
1431
|
+
const good = r.mcp === "ok" && (r.hooks === null || r.hooks === "ok") && !r.planError;
|
|
1432
|
+
const compat = compatStatus(adapter.cli, detection.version, ctx.compat);
|
|
1433
|
+
const tiers = activeTiers(r);
|
|
1434
|
+
let note = tiers.includes("idle wake") ? "auto mode wakes idle sessions" : tiers.includes("end of turn") ? "auto mode: at the end of a turn, no idle wake" : tiers.includes("next turn") ? "delivered at the next prompt" : "read through the inbox tool";
|
|
1435
|
+
if (!good) note = r.planError ? "config could not be read" : r.mcp === "outdated" || r.hooks === "outdated" ? "needs an update" : "not fully configured";
|
|
1436
|
+
if (compat.kind === "older") note = `older than the minimum ${compat.minimum}`;
|
|
1437
|
+
else if (compat.kind === "newer" && good) note = `newer than tested (${compat.verified})`;
|
|
1438
|
+
const glyph = compat.kind === "older" ? t.status("error") : good && !(compat.kind === "newer" && compat.minor) ? t.status("ok") : t.status("warn");
|
|
1439
|
+
table.push([
|
|
1440
|
+
` ${glyph} ${adapter.cli}`,
|
|
1441
|
+
adapter.displayName,
|
|
1442
|
+
detection.version ?? "",
|
|
1443
|
+
yesNo(r.mcp),
|
|
1444
|
+
yesNo(r.hooks),
|
|
1445
|
+
tiers.join(", "),
|
|
1446
|
+
q(note)
|
|
1447
|
+
]);
|
|
1448
|
+
if (r.planError) {
|
|
1449
|
+
problems++;
|
|
1450
|
+
notes.push(errorBlock(t, {
|
|
1451
|
+
what: `${adapter.displayName} config could not be read`,
|
|
1452
|
+
detail: [r.planError],
|
|
1453
|
+
fix: "Repair the file named above, then run conveno doctor again.",
|
|
2745
1454
|
exit: 1,
|
|
2746
|
-
ref: "
|
|
2747
|
-
});
|
|
1455
|
+
ref: "e_config"
|
|
1456
|
+
}));
|
|
1457
|
+
} else if (good) {
|
|
1458
|
+
if (compat.kind !== "older" && !(compat.kind === "newer" && compat.minor)) ok++;
|
|
1459
|
+
} else {
|
|
1460
|
+
warnings++;
|
|
1461
|
+
const named = [["the MCP server", r.mcp], ["the hooks", r.hooks]];
|
|
1462
|
+
const list = (state) => named.filter(([, s]) => s === state).map(([n]) => n).join(" and ");
|
|
1463
|
+
const missing = list("missing");
|
|
1464
|
+
const outdated = list("outdated");
|
|
1465
|
+
const fix = `Run ${cmd(t, "conveno init")}, then restart open ${adapter.displayName} sessions.`;
|
|
1466
|
+
notes.push(missing && outdated ? warnBlock(t, `${adapter.displayName} is missing ${missing} and needs an update to ${outdated}.`, fix) : missing ? warnBlock(t, `${adapter.displayName} is missing ${missing}.`, fix) : warnBlock(t, `${adapter.displayName} needs an update.`, fix, `Conveno's setup for ${outdated} is from an older version. ${cmd(t, "conveno init")} shows exactly which lines change.`));
|
|
2748
1467
|
}
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
}
|
|
2755
|
-
const { items, failures } = await collectPlans(ctx, await detectAll(ctx), "uninstallPlan");
|
|
2756
|
-
if (failures.length > 0) {
|
|
2757
|
-
reportFailures(ctx, failures, "conveno uninstall");
|
|
2758
|
-
return 1;
|
|
2759
|
-
}
|
|
2760
|
-
if (items.length === 0) {
|
|
2761
|
-
ctx.out(`${t.status("ok")} Nothing to remove. No Conveno entries were found in any supported CLI.\n`);
|
|
2762
|
-
return 0;
|
|
2763
|
-
}
|
|
2764
|
-
ctx.out(`${t.status("info")} No install backup found, so Conveno will remove only its own entries.\n\n`);
|
|
2765
|
-
const result = await confirmAndApply(ctx, items, {
|
|
2766
|
-
yes,
|
|
2767
|
-
verb: "Remove",
|
|
2768
|
-
rerun: "conveno uninstall",
|
|
2769
|
-
markRestored: true
|
|
2770
|
-
});
|
|
2771
|
-
if ("exit" in result) return result.exit;
|
|
2772
|
-
ctx.out(`${t.status("ok")} ${t.bold("Done.")} ${seconds(started, ctx.now())}\n`);
|
|
2773
|
-
ctx.out(" Removed the Conveno entries. Restart open sessions to drop Conveno.\n");
|
|
2774
|
-
return 0;
|
|
2775
|
-
}
|
|
2776
|
-
// src/main.ts
|
|
2777
|
-
const DESCRIPTION = "Conveno lets AI coding sessions on one machine find each other and exchange messages.";
|
|
2778
|
-
function helpText(ctx) {
|
|
2779
|
-
const t = ctx.theme;
|
|
2780
|
-
const rows = COMMANDS.map((c) => [c.usage.replace(/^conveno /, ""), c.summary]);
|
|
2781
|
-
const width = Math.max(...rows.map(([u]) => u.length), 9) + 2;
|
|
2782
|
-
const row = (c, d) => ` ${t.bold(c.padEnd(width))}${d}`;
|
|
2783
|
-
return [
|
|
2784
|
-
DESCRIPTION,
|
|
2785
|
-
"",
|
|
2786
|
-
"Usage: conveno <command> [options]",
|
|
2787
|
-
"",
|
|
2788
|
-
...rows.map(([u, d]) => row(u, d)),
|
|
2789
|
-
row("--version", "Print the version"),
|
|
2790
|
-
"",
|
|
2791
|
-
`Run ${cmd(t, "conveno <command> --help")} for the options of one command.`,
|
|
2792
|
-
`conveno ${t.paint("info", VERSION)}`,
|
|
2793
|
-
""
|
|
2794
|
-
].join("\n");
|
|
2795
|
-
}
|
|
2796
|
-
async function runMcp(ctx, argv) {
|
|
2797
|
-
const t = ctx.theme;
|
|
2798
|
-
const spec = COMMANDS.find((c) => c.name === "mcp");
|
|
2799
|
-
if (!spec) return 2;
|
|
2800
|
-
const parsed = parseFlags(ctx, spec, argv);
|
|
2801
|
-
if (typeof parsed === "number") return parsed;
|
|
2802
|
-
const cli = typeof parsed.values.cli === "string" ? parsed.values.cli : void 0;
|
|
2803
|
-
if (!cli || !CLI_KINDS.includes(cli)) return fail(ctx, {
|
|
2804
|
-
what: "conveno mcp needs a CLI name",
|
|
2805
|
-
detail: [`Got ${cli ? `"${cli}"` : "none"}. Known: ${CLI_KINDS.join(", ")}.`],
|
|
2806
|
-
fix: `Run ${cmd(t, "conveno mcp --cli claude")}, or let ${cmd(t, "conveno init")} write the config.`,
|
|
2807
|
-
exit: 2,
|
|
2808
|
-
ref: "e_usage"
|
|
2809
|
-
});
|
|
2810
|
-
try {
|
|
2811
|
-
await ctx.runMcp({
|
|
2812
|
-
cli,
|
|
2813
|
-
...ctx.daemonEntry ? { daemonEntry: ctx.daemonEntry } : {}
|
|
2814
|
-
});
|
|
2815
|
-
return 0;
|
|
2816
|
-
} catch (e) {
|
|
2817
|
-
const problem = daemonProblem(t, e);
|
|
2818
|
-
return fail(ctx, {
|
|
2819
|
-
what: "The Conveno MCP server stopped",
|
|
2820
|
-
detail: [problem.why],
|
|
2821
|
-
fix: problem.notRunning ? `Run ${cmd(t, "conveno doctor")} to check the daemon.` : problem.fix,
|
|
2822
|
-
exit: 1,
|
|
2823
|
-
ref: "e_mcp"
|
|
2824
|
-
});
|
|
2825
|
-
}
|
|
2826
|
-
}
|
|
2827
|
-
async function dispatch(command, rest, ctx) {
|
|
2828
|
-
const spec = COMMANDS.find((c) => c.name === command);
|
|
2829
|
-
if (spec && (rest.includes("--help") || rest.includes("-h")) && command !== "hook") {
|
|
2830
|
-
ctx.out(commandHelp(ctx, spec));
|
|
2831
|
-
return 0;
|
|
2832
|
-
}
|
|
2833
|
-
switch (command) {
|
|
2834
|
-
case "init": return runInit(ctx, rest);
|
|
2835
|
-
case "uninstall": return runUninstall(ctx, rest);
|
|
2836
|
-
case "status": return runStatus(ctx, rest);
|
|
2837
|
-
case "tickets": return runTickets(ctx, rest);
|
|
2838
|
-
case "answer": return runAnswer(ctx, rest);
|
|
2839
|
-
case "permissions": return runPermissions(ctx, rest);
|
|
2840
|
-
case "forget": return runForget(ctx, rest);
|
|
2841
|
-
case "spawn": return runSpawn(ctx, rest);
|
|
2842
|
-
case "acp-host": return (await import("./acp-BlKK0v-B.js")).runAcpHostCmd(ctx, rest);
|
|
2843
|
-
case "stop": return (await import("./acp-BlKK0v-B.js")).runStop(ctx, rest);
|
|
2844
|
-
case "attach": return (await import("./acp-BlKK0v-B.js")).runAttach(ctx, rest);
|
|
2845
|
-
case "spawn-run": return runSpawnRun(ctx, rest);
|
|
2846
|
-
case "auto": return runAuto(ctx, rest);
|
|
2847
|
-
case "peek": return runPeek(ctx, rest);
|
|
2848
|
-
case "devices": return runDevices(ctx, rest);
|
|
2849
|
-
case "relay": return runRelay(ctx, rest);
|
|
2850
|
-
case "doctor": return runDoctor(ctx, rest);
|
|
2851
|
-
case "login": return runLogin(ctx, rest);
|
|
2852
|
-
case "logout": return runLogout(ctx, rest);
|
|
2853
|
-
case "account": return runAccount(ctx, rest);
|
|
2854
|
-
case "daemon": return runDaemon(ctx, rest);
|
|
2855
|
-
case "mcp": return runMcp(ctx, rest);
|
|
2856
|
-
case "hook": return runHook(ctx, rest);
|
|
2857
|
-
default: {
|
|
2858
|
-
const suggestion = closest(command, COMMAND_NAMES);
|
|
2859
|
-
return fail(ctx, {
|
|
2860
|
-
what: `Unknown command "${command}"`,
|
|
2861
|
-
detail: [`conveno ${VERSION} has: ${COMMAND_NAMES.join(", ")}.`],
|
|
2862
|
-
fix: `Run ${cmd(ctx.theme, "conveno --help")} to see usage.`,
|
|
2863
|
-
...suggestion ? { didYouMean: `Did you mean ${suggestion}?` } : {},
|
|
2864
|
-
exit: 2,
|
|
2865
|
-
ref: "e_usage"
|
|
2866
|
-
});
|
|
1468
|
+
const versionNote = versionBlock(t, adapter, detection.version, compat);
|
|
1469
|
+
if (versionNote) {
|
|
1470
|
+
notes.push(versionNote.text);
|
|
1471
|
+
if (versionNote.problem) problems++;
|
|
1472
|
+
else warnings++;
|
|
2867
1473
|
}
|
|
2868
1474
|
}
|
|
2869
|
-
}
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
ctx.out(helpText(ctx));
|
|
2879
|
-
return 0;
|
|
2880
|
-
case "--version":
|
|
2881
|
-
case "-v":
|
|
2882
|
-
case "version":
|
|
2883
|
-
ctx.out(`${VERSION}\n`);
|
|
2884
|
-
return 0;
|
|
1475
|
+
ctx.out(`${columns(table).join("\n")}\n`);
|
|
1476
|
+
if (rows.some((r) => r.detection.installed && activeTiers(r).some((t) => t !== "next turn" && t !== "inbox"))) ctx.out(`${q("End of turn and idle wake apply to sessions in auto mode; see conveno auto.")}\n`);
|
|
1477
|
+
const acpLines = acpDoctorLines(ctx, rows.filter((r) => r.detection.installed).map((r) => r.adapter.cli));
|
|
1478
|
+
if (acpLines.length > 0) ctx.out(`${acpLines.join("\n")}\n`);
|
|
1479
|
+
const relayRows = [];
|
|
1480
|
+
for (const r of rows) {
|
|
1481
|
+
if (!r.detection.installed || !r.adapter.permissionHookInstalled || r.planError) continue;
|
|
1482
|
+
const installed = await r.adapter.permissionHookInstalled(adapterEnv(ctx)).catch(() => false);
|
|
1483
|
+
relayRows.push([` ${r.adapter.cli}`, q(installed ? "permission relay: hook installed (off until turned on per session)" : "permission relay: not installed (optional)")]);
|
|
2885
1484
|
}
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
return fail(ctx, {
|
|
2891
|
-
what: "conveno stopped before it could finish",
|
|
2892
|
-
detail: [rawMessage(e), ...log ? [`The full error is in ${tilde(log, ctx.home)}.`] : []],
|
|
2893
|
-
fix: `Run ${cmd(ctx.theme, "conveno doctor")} to check the install, then try again.`,
|
|
2894
|
-
exit: 1,
|
|
2895
|
-
ref: "e_internal"
|
|
2896
|
-
});
|
|
1485
|
+
if (relayRows.length > 0) ctx.out(`\n${columns(relayRows).join("\n")}\n`);
|
|
1486
|
+
if (!rows.some((r) => r.detection.installed)) {
|
|
1487
|
+
notes.push(warnBlock(t, "No supported AI coding CLI was found on PATH.", "Install Claude Code, Codex CLI or OpenCode, then run conveno init."));
|
|
1488
|
+
warnings++;
|
|
2897
1489
|
}
|
|
1490
|
+
for (const n of notes) ctx.err(`\n${n.trimEnd()}\n`);
|
|
1491
|
+
ctx.out(`\n${ok} ok, ${plural(warnings, "warning")}, ${plural(problems, "problem")}\n`);
|
|
1492
|
+
return problems > 0 ? 1 : 0;
|
|
2898
1493
|
}
|
|
2899
|
-
export {
|
|
1494
|
+
export { runLogout as C, runLogin as S, runDevices as _, detectAll as a, openInBrowser 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, runAccount as x, daemonProblem as y };
|