@conveno/cli 0.2.0-rc.1 → 0.2.0-rc.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export { i as runHookEntry } from "./hook-entry-BYvXWDJv.js";
@@ -0,0 +1,650 @@
1
+ import { F as dataPaths, Wt as spawnSession, d as SPAWN_TABLE, f as SpawnError, in as CLI_KINDS, jt as realSpawnDeps, u as SPAWN_CLIS, zt as runLaunchFile } from "./dist-qONHJRJk.js";
2
+ import { E as runLogout, T as runLogin, b as runRelay, i as runDoctor, m as runSetup, p as runInit, t as runUninstall, w as runAccount, x as runDaemon, y as runDevices } from "./uninstall-Blt-KHI5.js";
3
+ import { a as parseFlags, i as commandHelp, n as COMMANDS, r as COMMAND_NAMES, t as ALL_COMMAND_NAMES } from "./args-C1eX8Ixk.js";
4
+ import { t as daemonProblem } from "./daemonError-DraepwsB.js";
5
+ import { chmod, mkdir, writeFile } from "node:fs/promises";
6
+ import { join, resolve } from "node:path";
7
+ import { a as fail, c as plural, d as warnBlock, n as cmd, r as columns, s as plainError, t as closest, u as tilde } from "./fmt-C2SsP5Y0.js";
8
+ import { t as runHook } from "./hook-CDF1A8AY.js";
9
+ import { n as connectOpts, t as adapterEnv } from "./ctx-tYftvhz_.js";
10
+ import { t as findSession } from "./pick-B-axJvgf.js";
11
+ import { readFileSync } from "node:fs";
12
+ // src/version.ts
13
+ const VERSION = "0.2.0-rc.11";
14
+ // src/errorLog.ts
15
+ /** The message of an unexpected error, as it is. Not the softened text `plainError` gives. */
16
+ function rawMessage(e) {
17
+ if (e instanceof Error) return `${e.name}: ${e.message}`;
18
+ return String(e);
19
+ }
20
+ /**
21
+ * Write the full stack of an unexpected error to `<data dir>/logs/<timestamp>-error.log`, readable
22
+ * by the user only. Returns the path, or undefined when the log could not be written (the error is
23
+ * still reported, just without a log).
24
+ */
25
+ async function writeErrorLog(ctx, argv, e) {
26
+ try {
27
+ const dir = dataPaths(ctx.platform, ctx.dataDir).logs;
28
+ await mkdir(dir, {
29
+ recursive: true,
30
+ mode: 448
31
+ });
32
+ const stamp = ctx.now().toISOString().replace(/[:.]/g, "-");
33
+ const file = join(dir, `${stamp}-error.log`);
34
+ const command = argv.slice(0, 2).join(" ");
35
+ const text = [
36
+ `conveno ${VERSION} ${command}`,
37
+ "ref e_internal",
38
+ `time ${ctx.now().toISOString()}`,
39
+ `platform ${ctx.platform}, node ${process.version}`,
40
+ "",
41
+ e instanceof Error ? e.stack ?? rawMessage(e) : rawMessage(e),
42
+ e instanceof Error && e.cause !== void 0 ? `\nCaused by: ${e.cause instanceof Error ? e.cause.stack ?? rawMessage(e.cause) : String(e.cause)}` : "",
43
+ ""
44
+ ].join("\n");
45
+ await writeFile(file, text, { mode: 384 });
46
+ await chmod(file, 384).catch(() => void 0);
47
+ return file;
48
+ } catch {
49
+ return;
50
+ }
51
+ }
52
+ // src/lead.ts
53
+ /** `conveno lead <session>`: make that session the lead. `--clear` leaves no lead. */
54
+ async function runLead(ctx, argv) {
55
+ const t = ctx.theme;
56
+ const spec = COMMANDS.find((c) => c.name === "lead");
57
+ if (!spec) return 2;
58
+ const parsed = parseFlags(ctx, spec, argv);
59
+ if (typeof parsed === "number") return parsed;
60
+ const [session, ...extra] = parsed.positionals;
61
+ const clear = parsed.values.clear === true;
62
+ if (clear ? session !== void 0 : !session || extra.length > 0) return fail(ctx, {
63
+ what: clear ? "conveno lead --clear takes no session" : "conveno lead needs one session, or --clear",
64
+ fix: `For example ${cmd(t, "conveno lead planner")}, or ${cmd(t, "conveno lead --clear")}. ${cmd(t, "conveno status")} lists the names.`,
65
+ exit: 2,
66
+ ref: "e_usage"
67
+ });
68
+ let client;
69
+ try {
70
+ client = await ctx.connect(connectOpts(ctx, false));
71
+ } catch (e) {
72
+ const problem = daemonProblem(t, e);
73
+ return fail(ctx, {
74
+ what: problem.notRunning ? "Conveno's background service is not running" : "Conveno's background service cannot be reached",
75
+ detail: [problem.notRunning ? "There are no sessions to pick from." : problem.why],
76
+ fix: problem.notRunning ? `Run ${cmd(t, "conveno daemon start")}.` : problem.fix,
77
+ exit: 1,
78
+ ref: "e_daemon"
79
+ });
80
+ }
81
+ try {
82
+ if (clear) {
83
+ const res = await client["orchestrator.clear"]({});
84
+ ctx.out(res.previous ? `${t.status("ok")} No session is the lead now.\n` : `${t.status("info")} No session was the lead.\n`);
85
+ return 0;
86
+ }
87
+ const found = await findSession(client, session);
88
+ if (!found) return fail(ctx, {
89
+ what: `No session "${session}"`,
90
+ fix: `Run ${cmd(t, "conveno status")} to see the names.`,
91
+ exit: 1,
92
+ ref: "e_session"
93
+ });
94
+ if (found.status === "offline") return fail(ctx, {
95
+ what: `${found.name} is offline`,
96
+ detail: ["Only a session that is online can be the lead."],
97
+ fix: `Run ${cmd(t, "conveno status")} to see who is online.`,
98
+ exit: 1,
99
+ ref: "e_session"
100
+ });
101
+ await client["orchestrator.claim"]({ sessionId: found.id });
102
+ ctx.out(`${t.status("ok")} ${t.bold(found.name)} is the lead now.\n`);
103
+ return 0;
104
+ } catch (e) {
105
+ return fail(ctx, {
106
+ what: "The lead was not changed",
107
+ detail: [plainError(e)],
108
+ fix: `Run ${cmd(t, "conveno status")} to see the sessions.`,
109
+ exit: 1,
110
+ ref: "e_lead"
111
+ });
112
+ } finally {
113
+ await client.close().catch(() => void 0);
114
+ }
115
+ }
116
+ // src/rename.ts
117
+ /** `conveno rename <session> <new-name>`. */
118
+ async function runRename(ctx, argv) {
119
+ const t = ctx.theme;
120
+ const spec = COMMANDS.find((c) => c.name === "rename");
121
+ if (!spec) return 2;
122
+ const parsed = parseFlags(ctx, spec, argv);
123
+ if (typeof parsed === "number") return parsed;
124
+ const [session, name, ...extra] = parsed.positionals;
125
+ if (!session || !name || extra.length > 0) return fail(ctx, {
126
+ what: "conveno rename needs a session and a new name",
127
+ fix: `For example ${cmd(t, "conveno rename claude@app-1 planner")}.`,
128
+ exit: 2,
129
+ ref: "e_usage"
130
+ });
131
+ let client;
132
+ try {
133
+ client = await ctx.connect(connectOpts(ctx, false));
134
+ } catch (e) {
135
+ const problem = daemonProblem(t, e);
136
+ return fail(ctx, {
137
+ what: problem.notRunning ? "Conveno's background service is not running" : "Conveno's background service cannot be reached",
138
+ detail: [problem.notRunning ? "There are no sessions to rename." : problem.why],
139
+ fix: problem.notRunning ? `Run ${cmd(t, "conveno daemon start")}.` : problem.fix,
140
+ exit: 1,
141
+ ref: "e_daemon"
142
+ });
143
+ }
144
+ try {
145
+ const found = await findSession(client, session);
146
+ if (!found) return fail(ctx, {
147
+ what: `No session "${session}"`,
148
+ fix: `Run ${cmd(t, "conveno status")} to see the names.`,
149
+ exit: 1,
150
+ ref: "e_session"
151
+ });
152
+ if (found.status === "offline") return fail(ctx, {
153
+ what: `${found.name} is offline`,
154
+ detail: ["Only a session that is online can be renamed."],
155
+ fix: `Run ${cmd(t, "conveno status")} to see who is online.`,
156
+ exit: 1,
157
+ ref: "e_session"
158
+ });
159
+ const res = await client["session.rename"]({
160
+ sessionId: found.id,
161
+ name
162
+ });
163
+ ctx.out(`${t.status("ok")} ${t.bold(found.name)} is now ${t.bold(res.session.name)}.\n`);
164
+ return 0;
165
+ } catch (e) {
166
+ return fail(ctx, {
167
+ what: "The session was not renamed",
168
+ detail: [plainError(e)],
169
+ fix: `Pick another name, or run ${cmd(t, "conveno status")} to see the names in use.`,
170
+ exit: 1,
171
+ ref: "e_rename"
172
+ });
173
+ } finally {
174
+ await client.close().catch(() => void 0);
175
+ }
176
+ }
177
+ // src/send.ts
178
+ /** `conveno send <to> <text...>`: send a message as you, the owner. */
179
+ async function runSend(ctx, argv) {
180
+ const t = ctx.theme;
181
+ const spec = COMMANDS.find((c) => c.name === "send");
182
+ if (!spec) return 2;
183
+ const parsed = parseFlags(ctx, spec, argv);
184
+ if (typeof parsed === "number") return parsed;
185
+ const [to, ...words] = parsed.positionals;
186
+ let text = words.join(" ");
187
+ if (words.length === 1 && words[0] === "-") text = (await ctx.readStdin()).replace(/\s+$/, "");
188
+ if (!to || text.trim() === "") return fail(ctx, {
189
+ what: "conveno send needs a recipient and a text",
190
+ fix: `For example ${cmd(t, "conveno send lead \"Please start with the tests\"")}, or ${cmd(t, "conveno send worker -")} to read the text from standard input.`,
191
+ exit: 2,
192
+ ref: "e_usage"
193
+ });
194
+ let client;
195
+ try {
196
+ client = await ctx.connect(connectOpts(ctx, false));
197
+ } catch (e) {
198
+ const problem = daemonProblem(t, e);
199
+ return fail(ctx, {
200
+ what: problem.notRunning ? "Conveno's background service is not running" : "Conveno's background service cannot be reached",
201
+ detail: [problem.notRunning ? "Nobody can get the message." : problem.why],
202
+ fix: problem.notRunning ? `Run ${cmd(t, "conveno daemon start")}.` : problem.fix,
203
+ exit: 1,
204
+ ref: "e_daemon"
205
+ });
206
+ }
207
+ try {
208
+ const res = await client["owner.send"]({
209
+ to,
210
+ text,
211
+ urgent: parsed.values.urgent === true
212
+ });
213
+ ctx.out(`${t.status("ok")} Sent to ${t.bold(res.deliveredTo.name)}.\n`);
214
+ return 0;
215
+ } catch (e) {
216
+ return fail(ctx, {
217
+ what: "The message was not sent",
218
+ detail: [plainError(e)],
219
+ fix: `Run ${cmd(t, "conveno status")} to see the session names.`,
220
+ exit: 1,
221
+ ref: "e_send"
222
+ });
223
+ } finally {
224
+ await client.close().catch(() => void 0);
225
+ }
226
+ }
227
+ // src/spawn.ts
228
+ /** Read the task from `--task-file`. Returns the text or the failure's exit code. */
229
+ function readTaskFile(ctx, path) {
230
+ try {
231
+ return readFileSync(resolve(ctx.cwd, path), "utf8");
232
+ } catch (e) {
233
+ const code = e.code;
234
+ return fail(ctx, {
235
+ what: `Cannot read the task file ${path}`,
236
+ detail: [code === "ENOENT" ? "The file does not exist." : `The system said ${code ?? "no"}.`],
237
+ fix: "Check the path, or pass the task with --task.",
238
+ exit: 2,
239
+ ref: "e_usage"
240
+ });
241
+ }
242
+ }
243
+ /**
244
+ * `conveno spawn <cli> ...`: start a worker session of any CLI with a first task, and print the
245
+ * name it registers under.
246
+ */
247
+ async function runSpawn(ctx, argv) {
248
+ const t = ctx.theme;
249
+ const spec = COMMANDS.find((c) => c.name === "spawn");
250
+ if (!spec) return 2;
251
+ const parsed = parseFlags(ctx, spec, argv);
252
+ if (typeof parsed === "number") return parsed;
253
+ const help = `Run ${cmd(t, "conveno spawn --help")} to see the options.`;
254
+ const [cli, ...extra] = parsed.positionals;
255
+ if (!cli || extra.length > 0) return fail(ctx, {
256
+ what: "conveno spawn needs exactly one CLI name",
257
+ detail: [`Known: ${SPAWN_CLIS.join(", ")}.`],
258
+ fix: `Run ${cmd(t, "conveno spawn claude --task 'review the open PR'")}.`,
259
+ exit: 2,
260
+ ref: "e_usage"
261
+ });
262
+ if (!Object.hasOwn(SPAWN_TABLE, cli)) return fail(ctx, {
263
+ what: `"${cli}" is not a CLI Conveno can start`,
264
+ detail: [`Known: ${SPAWN_CLIS.join(", ")}.`],
265
+ fix: help,
266
+ exit: 2,
267
+ ref: "e_usage"
268
+ });
269
+ const str = (k) => typeof parsed.values[k] === "string" ? parsed.values[k] : void 0;
270
+ if (str("task") !== void 0 && str("task-file") !== void 0) return fail(ctx, {
271
+ what: "Use --task or --task-file, not both",
272
+ fix: help,
273
+ exit: 2,
274
+ ref: "e_usage"
275
+ });
276
+ let task = str("task");
277
+ const taskFile = str("task-file");
278
+ if (taskFile !== void 0) {
279
+ const text = readTaskFile(ctx, taskFile);
280
+ if (typeof text === "number") return text;
281
+ task = text;
282
+ }
283
+ const window = parsed.values.window === true;
284
+ const allowFlag = str("allow");
285
+ const allow = allowFlag === void 0 ? void 0 : [allowFlag];
286
+ const yes = parsed.values.yes === true;
287
+ const adapter = ctx.adapters.find((a) => a.cli === cli);
288
+ if (adapter && !(await adapter.detect(adapterEnv(ctx))).installed) return fail(ctx, {
289
+ what: `${adapter.displayName} is not installed`,
290
+ detail: [`conveno could not run ${cli} --version.`],
291
+ fix: "Install it, or check that its folder is on PATH.",
292
+ exit: 1,
293
+ ref: "e_spawn"
294
+ });
295
+ if (!yes) {
296
+ if (!ctx.interactive) return fail(ctx, {
297
+ what: "Needs a terminal to confirm",
298
+ detail: ["Nothing was started."],
299
+ fix: `Run the same command with ${cmd(t, "--yes")} to start the session without asking.`,
300
+ exit: 2,
301
+ ref: "e_no_tty"
302
+ });
303
+ const question = `Start ${cli} in ${tilde(resolve(ctx.cwd, str("cwd") ?? "."), ctx.home)}${window ? "" : " in the background"}${task ? " with a first task" : ""}?`;
304
+ if (!await ctx.confirm(question, true)) {
305
+ ctx.out(`${t.status("info")} Nothing was started.\n`);
306
+ return 0;
307
+ }
308
+ }
309
+ let client;
310
+ try {
311
+ client = await ctx.connect(connectOpts(ctx, true));
312
+ } catch (e) {
313
+ const problem = daemonProblem(t, e);
314
+ return fail(ctx, {
315
+ what: "Conveno's background service cannot be reached",
316
+ detail: [problem.why],
317
+ fix: problem.fix,
318
+ exit: 1,
319
+ ref: "e_daemon"
320
+ });
321
+ }
322
+ try {
323
+ const { hostPid } = await ctx.ancestry(2e3);
324
+ const requester = hostPid === void 0 ? void 0 : (await client["session.byHost"]({ pid: hostPid }).catch(() => void 0))?.session ?? void 0;
325
+ const runner = ctx.spawnRunner ?? [process.execPath, process.argv[1] ?? "conveno"];
326
+ const deps = realSpawnDeps({
327
+ platform: ctx.platform,
328
+ env: ctx.env,
329
+ home: ctx.home,
330
+ dataDir: ctx.dataDir,
331
+ client,
332
+ runner
333
+ });
334
+ const res = await spawnSession(deps, {
335
+ cli,
336
+ callerCwd: ctx.cwd,
337
+ cwd: str("cwd"),
338
+ name: str("name"),
339
+ task,
340
+ window,
341
+ allow,
342
+ requester,
343
+ confineToHome: false,
344
+ onProgress: (line) => ctx.err(`${t.paint("quiet", line)}\n`)
345
+ });
346
+ const how = res.window ? res.terminal ?? "terminal" : "background";
347
+ ctx.out(`${t.status("ok")} ${t.bold(`Started ${res.name}`)} ${t.paint("quiet", `(${res.cli}, ${how}) in ${tilde(res.cwd, ctx.home)}`)}\n`);
348
+ if (res.task === "message") ctx.out(` The first task was sent to it as a Conveno message.\n`);
349
+ if (!res.window) {
350
+ ctx.out(` End it with ${cmd(t, `conveno stop ${res.name}`)}.\n`);
351
+ if (res.adapter) ctx.out(` ${t.paint("quiet", `Adapter: ${res.adapter}`)}\n`);
352
+ }
353
+ if (res.logPath) ctx.out(` Output: ${tilde(res.logPath, ctx.home)}\n`);
354
+ ctx.out(` ${t.paint("quiet", `${cmd(t, "conveno status")} lists it. Message it with send to: ${res.name}.`)}\n`);
355
+ return 0;
356
+ } catch (e) {
357
+ if (e instanceof SpawnError) return fail(ctx, {
358
+ what: "Could not start the session",
359
+ detail: [e.message],
360
+ ...e.fix ? { fix: e.fix } : {},
361
+ exit: 1,
362
+ ref: "e_spawn"
363
+ });
364
+ throw e;
365
+ } finally {
366
+ await client.close().catch(() => void 0);
367
+ }
368
+ }
369
+ /** `conveno spawn-run <launch file>`: what a spawned terminal runs. Not for people. */
370
+ async function runSpawnRun(ctx, argv) {
371
+ const [file] = argv;
372
+ if (!file) return fail(ctx, {
373
+ what: "conveno spawn-run needs a launch file",
374
+ detail: ["It is started by conveno spawn inside the new terminal."],
375
+ fix: `Run ${cmd(ctx.theme, "conveno spawn <cli>")} instead.`,
376
+ exit: 2,
377
+ ref: "e_usage"
378
+ });
379
+ try {
380
+ return await runLaunchFile(file);
381
+ } catch (e) {
382
+ return fail(ctx, {
383
+ what: "Could not read the launch file",
384
+ detail: [e instanceof Error ? e.message : String(e)],
385
+ fix: `Run ${cmd(ctx.theme, "conveno spawn <cli>")} again.`,
386
+ exit: 1,
387
+ ref: "e_spawn"
388
+ });
389
+ }
390
+ }
391
+ // src/status.ts
392
+ function stateCell(theme, s) {
393
+ if (s.isOrchestrator) return {
394
+ glyph: theme.status("orchestrator"),
395
+ word: s.status === "busy" ? "working" : "idle"
396
+ };
397
+ if (s.status === "busy") return {
398
+ glyph: theme.glyph("busy"),
399
+ word: "working"
400
+ };
401
+ return {
402
+ glyph: theme.status("idle"),
403
+ word: "idle"
404
+ };
405
+ }
406
+ /** Sessions grouped by project folder, the way brand/components/terminal.md lays them out. */
407
+ function renderSessions(ctx, sessions) {
408
+ const t = ctx.theme;
409
+ const q = (w) => t.paint("quiet", w);
410
+ const toolName = (cli) => ctx.adapters.find((a) => a.cli === cli)?.displayName ?? cli;
411
+ const waiting = sessions.some((s) => (s.unreadCount ?? 0) > 0);
412
+ const doing = sessions.some((s) => s.statusText);
413
+ const groups = /* @__PURE__ */ new Map();
414
+ const keyOf = (s) => s.remote ? `${s.repo?.root ?? s.cwd}\u0000${s.deviceName ?? ""}` : s.repo?.root ?? s.cwd;
415
+ for (const s of sessions) {
416
+ const key = keyOf(s);
417
+ groups.set(key, [...groups.get(key) ?? [], s]);
418
+ }
419
+ const blocks = [];
420
+ for (const key of [...groups.keys()].sort()) {
421
+ const list = (groups.get(key) ?? []).sort((a, b) => a.name.localeCompare(b.name));
422
+ const head = [
423
+ ` ${q("SESSION")}`,
424
+ q("AI TOOL"),
425
+ q("STATE"),
426
+ ...waiting ? [q("WAITING")] : [],
427
+ ...doing ? [q("WORKING ON")] : []
428
+ ];
429
+ const rows = list.map((s) => {
430
+ const st = stateCell(t, s);
431
+ const tags = [...s.isOrchestrator ? [t.paint("entry", "lead")] : [], ...s.spawned || s.spawnedBy ? [q("spawned")] : []];
432
+ return [
433
+ `${st.glyph} ${t.bold(s.name)}${tags.length > 0 ? ` ${tags.join(" ")}` : ""}`,
434
+ toolName(s.cli),
435
+ st.word,
436
+ ...waiting ? [s.unreadCount ? String(s.unreadCount) : q("none")] : [],
437
+ ...doing ? [s.statusText ?? ""] : []
438
+ ];
439
+ });
440
+ const [headLine, ...rowLines] = columns([head, ...rows]);
441
+ const [path, device] = key.split("\0");
442
+ const title = device === void 0 ? t.bold(tilde(key, ctx.home)) : `${t.bold(path ?? "")} ${q(`on ${device || "another device"}`)}`;
443
+ blocks.push([
444
+ ` ${title}`,
445
+ ` ${headLine}`,
446
+ ...rowLines.map((l) => ` ${l}`)
447
+ ].join("\n"));
448
+ }
449
+ return blocks.join("\n\n");
450
+ }
451
+ /** The relay part of the status header line. */
452
+ function relaySummary(r) {
453
+ if (!r) return "off";
454
+ switch (r.state) {
455
+ case "connected": {
456
+ const online = r.peers.filter((p) => p.online).length;
457
+ return `connected, ${plural(online, "other device")} online`;
458
+ }
459
+ case "connecting": return "connecting";
460
+ case "disconnected": return "not connected, trying again";
461
+ case "revoked": return "off, this device was removed";
462
+ case "unpaired": return "off, no paired devices";
463
+ default: return "off";
464
+ }
465
+ }
466
+ async function runStatus(ctx, argv = []) {
467
+ const t = ctx.theme;
468
+ const spec = COMMANDS.find((c) => c.name === "status");
469
+ if (spec) {
470
+ const parsed = parseFlags(ctx, spec, argv);
471
+ if (typeof parsed === "number") return parsed;
472
+ }
473
+ let client;
474
+ try {
475
+ client = await ctx.connect(connectOpts(ctx, false));
476
+ } catch (e) {
477
+ const problem = daemonProblem(t, e);
478
+ ctx.err(problem.notRunning ? warnBlock(t, "Conveno is not running right now.", `Open one of your AI tools and it starts by itself. If you have not connected your AI tools yet, run ${cmd(t, "conveno setup")}.`, "Sessions are listed by Conveno's background service, and it is not running.") : warnBlock(t, "Conveno's background service cannot be reached.", problem.fix, problem.why));
479
+ return 0;
480
+ }
481
+ try {
482
+ const sessions = (await client["session.list"]({})).sessions;
483
+ const projects = new Set(sessions.map((s) => s.repo?.root ?? s.cwd)).size;
484
+ const relay = await (async () => client["relay.status"]({}))().catch(() => void 0);
485
+ ctx.out(`${t.status("ok")} Conveno is running. ${plural(sessions.length, "session")} online.\n`);
486
+ if (relay && [
487
+ "connected",
488
+ "connecting",
489
+ "disconnected"
490
+ ].includes(relay.state)) ctx.out(` Your other devices: ${relaySummary(relay)}\n`);
491
+ if (sessions.length === 0) {
492
+ ctx.out(`\nNo sessions yet. Open an AI tool you have connected with ${cmd(t, "conveno setup")} and it appears here.\n`);
493
+ return 0;
494
+ }
495
+ ctx.out(`\n${renderSessions(ctx, sessions)}\n\n`);
496
+ ctx.out(`${plural(sessions.length, "session")} in ${plural(projects, "project")}\n`);
497
+ return 0;
498
+ } finally {
499
+ await client.close().catch(() => void 0);
500
+ }
501
+ }
502
+ // src/main.ts
503
+ const DESCRIPTION = "Conveno lets AI coding sessions on one machine find each other and exchange messages.";
504
+ function helpText(ctx) {
505
+ const t = ctx.theme;
506
+ const label = (usage) => usage.replace(/^conveno /, "").split(/\s+[[|]/)[0]?.trim() ?? usage;
507
+ const rows = [
508
+ ["conveno", "Open the Conveno app"],
509
+ ...COMMANDS.filter((c) => !c.hidden).map((c) => [label(c.usage), c.summary]),
510
+ ["--help", "Show this help"],
511
+ ["--version", "Show the version"]
512
+ ];
513
+ const width = Math.max(...rows.map(([u]) => u.length)) + 2;
514
+ const row = (c, d) => ` ${t.bold(c.padEnd(width))}${d}`;
515
+ return [
516
+ DESCRIPTION,
517
+ "",
518
+ "Usage: conveno [command]",
519
+ "",
520
+ ...rows.map(([u, d]) => row(u, d)),
521
+ "",
522
+ `New here? Run ${cmd(t, "conveno setup")} to connect your AI tools.`,
523
+ `Run ${cmd(t, "conveno <command> --help")} for more about one command.`,
524
+ `conveno ${t.paint("info", VERSION)}`,
525
+ ""
526
+ ].join("\n");
527
+ }
528
+ async function runMcp(ctx, argv) {
529
+ const t = ctx.theme;
530
+ const spec = COMMANDS.find((c) => c.name === "mcp");
531
+ if (!spec) return 2;
532
+ const parsed = parseFlags(ctx, spec, argv);
533
+ if (typeof parsed === "number") return parsed;
534
+ const cli = typeof parsed.values.cli === "string" ? parsed.values.cli : void 0;
535
+ if (!cli || !CLI_KINDS.includes(cli)) return fail(ctx, {
536
+ what: "conveno mcp needs a CLI name",
537
+ detail: [`Got ${cli ? `"${cli}"` : "none"}. Known: ${CLI_KINDS.join(", ")}.`],
538
+ fix: `Run ${cmd(t, "conveno mcp --cli claude")}, or let ${cmd(t, "conveno setup")} write the config.`,
539
+ exit: 2,
540
+ ref: "e_usage"
541
+ });
542
+ try {
543
+ await ctx.runMcp({
544
+ cli,
545
+ ...ctx.daemonEntry ? { daemonEntry: ctx.daemonEntry } : {}
546
+ });
547
+ return 0;
548
+ } catch (e) {
549
+ const problem = daemonProblem(t, e);
550
+ return fail(ctx, {
551
+ what: "The Conveno MCP server stopped",
552
+ detail: [problem.why],
553
+ fix: problem.notRunning ? `Run ${cmd(t, "conveno doctor")} to check the daemon.` : problem.fix,
554
+ exit: 1,
555
+ ref: "e_mcp"
556
+ });
557
+ }
558
+ }
559
+ async function dispatch(name, rest, ctx) {
560
+ const command = name;
561
+ const spec = COMMANDS.find((c) => c.name === command);
562
+ if (spec && (rest.includes("--help") || rest.includes("-h")) && command !== "hook") {
563
+ ctx.out(commandHelp(ctx, spec));
564
+ return 0;
565
+ }
566
+ switch (command) {
567
+ case "setup": return runSetup(ctx, rest);
568
+ case "init": return runInit(ctx, rest);
569
+ case "uninstall": return runUninstall(ctx, rest);
570
+ case "status": return runStatus(ctx, rest);
571
+ case "send": return runSend(ctx, rest);
572
+ case "rename": return runRename(ctx, rest);
573
+ case "lead": return runLead(ctx, rest);
574
+ case "spawn": return runSpawn(ctx, rest);
575
+ case "acp-host": return (await import("./acp-BOSDOzU7.js")).runAcpHostCmd(ctx, rest);
576
+ case "stop": return (await import("./acp-BOSDOzU7.js")).runStop(ctx, rest);
577
+ case "spawn-run": return runSpawnRun(ctx, rest);
578
+ case "agy-relay": return (await import("./agy-relay-BUo9uRng.js")).runAgyRelay(ctx, rest);
579
+ case "watch": return (await import("./watch-CuZ7jPVd.js")).runWatch(ctx, rest);
580
+ case "devices": return runDevices(ctx, rest);
581
+ case "relay": return runRelay(ctx, rest);
582
+ case "doctor": return runDoctor(ctx, rest);
583
+ case "login": return runLogin(ctx, rest);
584
+ case "logout": return runLogout(ctx, rest);
585
+ case "account": return runAccount(ctx, rest);
586
+ case "daemon": return runDaemon(ctx, rest);
587
+ case "mcp": return runMcp(ctx, rest);
588
+ case "hook": return runHook(ctx, rest);
589
+ default: {
590
+ const suggestion = closest(command, ALL_COMMAND_NAMES);
591
+ return fail(ctx, {
592
+ what: `Unknown command "${command}"`,
593
+ detail: [`conveno ${VERSION} has: ${COMMAND_NAMES.join(", ")}.`],
594
+ fix: `Run ${cmd(ctx.theme, "conveno --help")} to see usage.`,
595
+ ...suggestion ? { didYouMean: `Did you mean ${suggestion}?` } : {},
596
+ exit: 2,
597
+ ref: "e_usage"
598
+ });
599
+ }
600
+ }
601
+ }
602
+ /**
603
+ * `conveno` alone opens the app, but only in a real terminal: not piped, not CI, not TERM=dumb.
604
+ * Everything else prints the help, as before.
605
+ */
606
+ function opensApp(env, tty = {
607
+ stdin: Boolean(process.stdin.isTTY),
608
+ stdout: Boolean(process.stdout.isTTY)
609
+ }) {
610
+ if (!tty.stdin || !tty.stdout) return false;
611
+ if (env.CI && env.CI !== "0" && env.CI.toLowerCase() !== "false") return false;
612
+ return env.TERM !== "dumb";
613
+ }
614
+ /** Run one command line. Returns the exit code. Never throws. */
615
+ async function main(argv, ctx) {
616
+ const [command, ...rest] = argv;
617
+ if (command === void 0 && opensApp(ctx.env)) try {
618
+ return await (await import("./run-CtGfzzwB.js")).runTui(ctx);
619
+ } catch (e) {
620
+ ctx.err(`The app could not start (${rawMessage(e)}). Showing the help instead.\n`);
621
+ ctx.out(helpText(ctx));
622
+ return 0;
623
+ }
624
+ switch (command) {
625
+ case void 0:
626
+ case "--help":
627
+ case "-h":
628
+ case "help":
629
+ ctx.out(helpText(ctx));
630
+ return 0;
631
+ case "--version":
632
+ case "-v":
633
+ case "version":
634
+ ctx.out(`${VERSION}\n`);
635
+ return 0;
636
+ }
637
+ try {
638
+ return await dispatch(command, rest, ctx);
639
+ } catch (e) {
640
+ const log = await writeErrorLog(ctx, argv, e);
641
+ return fail(ctx, {
642
+ what: "conveno stopped before it could finish",
643
+ detail: [rawMessage(e), ...log ? [`The full error is in ${tilde(log, ctx.home)}.`] : []],
644
+ fix: `Run ${cmd(ctx.theme, "conveno doctor")} to check the install, then try again.`,
645
+ exit: 1,
646
+ ref: "e_internal"
647
+ });
648
+ }
649
+ }
650
+ export { DESCRIPTION, helpText, main, opensApp };
@@ -0,0 +1,9 @@
1
+ import { vn as SessionId } from "./dist-qONHJRJk.js";
2
+ // src/pick.ts
3
+ /** The online session a name or id means, or undefined when nothing matches. */
4
+ async function findSession(client, text) {
5
+ const { sessions } = await client["session.list"]({});
6
+ if (SessionId.safeParse(text).success) return sessions.find((s) => s.id === text);
7
+ return sessions.filter((s) => s.name === text)[0];
8
+ }
9
+ export { findSession as t };