@conveno/cli 0.2.0-rc.5 → 0.2.0-rc.6
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 +22 -30
- package/dist/acp-3xehqLdo.js +82 -0
- package/dist/args-D9T-6TDw.js +315 -0
- package/dist/bin.js +2 -2
- package/dist/{ctx-CDLE-2f2.js → ctx-tYftvhz_.js} +2 -3
- package/dist/daemon.js +362 -1420
- package/dist/daemonError-CdLataBW.js +66 -0
- package/dist/{dist-BPPOKmbH.js → dist-BAlMjYqQ.js} +39 -148
- package/dist/{dist-TrWRppjR.js → dist-BTLBO1Rp.js} +363 -1139
- package/dist/{dist-CEJ2-wxh.js → dist-BYVibI3a.js} +4 -17
- package/dist/{dist-C8JRuLiZ.js → dist-CNyzLyZh.js} +161 -1554
- package/dist/{dist-E3XvoT1Q.js → dist-DIAtMDWW.js} +1 -1
- package/dist/dist-LkcRvVjE.js +449 -0
- package/dist/{doctor-CzIGTeNT.js → doctor-DjwXJvKw.js} +26 -94
- package/dist/fmt-C2SsP5Y0.js +96 -0
- package/dist/{hook-CLB_muZS.js → hook-BGJc4PHG.js} +2 -4
- package/dist/hook-entry-BWWJS7n3.js +2622 -0
- package/dist/hook-entry-rDISaMgP.js +1 -0
- package/dist/main-CRw-fISR.js +971 -0
- package/dist/pick-B-18E4Mx.js +9 -0
- package/dist/{run-CYH0CRbp.js → run-Yi48fiJN.js} +286 -1699
- package/dist/{runtime-B1Pb9Qqg.js → runtime-DyknkzAS.js} +109 -209
- package/dist/sidecar-CTKxOMie.js +98 -0
- package/dist/watch-CfYanJvt.js +109 -0
- package/package.json +15 -15
- package/dist/acp-BD7Oaerg.js +0 -142
- package/dist/args-BRB8QEQM.js +0 -554
- package/dist/dist-DcmKjrmu.js +0 -271
- package/dist/hook-entry-BlvSoNMm.js +0 -1289
- package/dist/hook-entry-CRDh36pe.js +0 -1
- package/dist/main-CsCsyq2G.js +0 -1645
|
@@ -0,0 +1,971 @@
|
|
|
1
|
+
import { At as runLaunchFile, Ft as spawnSession, M as dataPaths, St as realSpawnDeps, d as SPAWN_TABLE, f as SpawnError, qt as CLI_KINDS, u as SPAWN_CLIS } from "./dist-BTLBO1Rp.js";
|
|
2
|
+
import { S as runLogout, _ as runDevices, a as detectAll, b as runAccount, c as staleFailure, d as listManifests, f as markRestored, i as confirmAndApply, l as StaleError, m as restoreEntry, n as runDoctor, o as reportFailures, p as previewRestore, r as collectPlans, s as runInit, u as applyChanges, v as runRelay, x as runLogin } from "./doctor-DjwXJvKw.js";
|
|
3
|
+
import { i as parseFlags, n as COMMAND_NAMES, r as commandHelp, t as COMMANDS } from "./args-D9T-6TDw.js";
|
|
4
|
+
import { access, chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import { n as connectOpts, t as adapterEnv } from "./ctx-tYftvhz_.js";
|
|
6
|
+
import { t as daemonProblem } from "./daemonError-CdLataBW.js";
|
|
7
|
+
import { a as fail, c as plural, d as warnBlock, l as seconds, n as cmd, o as localStamp, r as columns, s as plainError, t as closest, u as tilde } from "./fmt-C2SsP5Y0.js";
|
|
8
|
+
import { join, resolve } from "node:path";
|
|
9
|
+
import { t as runHook } from "./hook-BGJc4PHG.js";
|
|
10
|
+
import { t as findSession } from "./pick-B-18E4Mx.js";
|
|
11
|
+
import { readFileSync } from "node:fs";
|
|
12
|
+
// src/daemon.ts
|
|
13
|
+
async function lockPid(ctx) {
|
|
14
|
+
try {
|
|
15
|
+
const raw = await readFile(dataPaths(ctx.platform, ctx.dataDir).lock, "utf8");
|
|
16
|
+
const pid = JSON.parse(raw).pid;
|
|
17
|
+
return typeof pid === "number" && Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
23
|
+
/** Does something on the socket answer the Conveno handshake? */
|
|
24
|
+
async function reachable(ctx) {
|
|
25
|
+
try {
|
|
26
|
+
await (await ctx.connect(connectOpts(ctx, false))).close().catch(() => void 0);
|
|
27
|
+
return true;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const lockExists = (ctx) => access(dataPaths(ctx.platform, ctx.dataDir).lock).then(() => true, () => false);
|
|
33
|
+
/** Poll until `done()` holds or `ms` pass. Returns whether it held. */
|
|
34
|
+
async function waitFor(done, ms) {
|
|
35
|
+
const deadline = Date.now() + ms;
|
|
36
|
+
for (;;) {
|
|
37
|
+
if (await done()) return true;
|
|
38
|
+
if (Date.now() >= deadline) return false;
|
|
39
|
+
await sleep(50);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const norm = (text) => text.replaceAll("\\", "/").toLowerCase();
|
|
43
|
+
/**
|
|
44
|
+
* Does this command line belong to the Conveno daemon? It must run the daemon's entry script: the
|
|
45
|
+
* one this install resolved, any installed `@conveno/cli`'s `daemon.js`, or the `bin.js` of the
|
|
46
|
+
* `@conveno/daemon` package that releases before 0.1.1 started.
|
|
47
|
+
*/
|
|
48
|
+
function isConvenoDaemonCommand(commandLine, daemonEntry) {
|
|
49
|
+
const line = norm(commandLine);
|
|
50
|
+
if (daemonEntry !== void 0 && line.includes(norm(daemonEntry))) return true;
|
|
51
|
+
return /@conveno\/cli\/(?:[^ ]+\/)?daemon\.js|@conveno\/daemon\/(?:[^ ]+\/)?bin\.js/.test(line);
|
|
52
|
+
}
|
|
53
|
+
const STOP_FIX = (t) => `then run ${cmd(t, "conveno daemon status")}`;
|
|
54
|
+
/**
|
|
55
|
+
* `conveno daemon stop`. The normal path asks the daemon to shut itself down over the control
|
|
56
|
+
* channel (`daemon.shutdown`), the way Docker and pm2 do. That needs no signal and no external
|
|
57
|
+
* tool, so it works for a normal user in a Windows SSH session. Only when the daemon does not answer,
|
|
58
|
+
* and its lock pid is verified to be the daemon, is the process ended directly.
|
|
59
|
+
*/
|
|
60
|
+
async function stopDaemon(ctx) {
|
|
61
|
+
const t = ctx.theme;
|
|
62
|
+
const lock = dataPaths(ctx.platform, ctx.dataDir).lock;
|
|
63
|
+
const pid = await lockPid(ctx);
|
|
64
|
+
const named = pid === null ? "" : ` (pid ${pid})`;
|
|
65
|
+
let client;
|
|
66
|
+
try {
|
|
67
|
+
client = await ctx.connect(connectOpts(ctx, false));
|
|
68
|
+
} catch {
|
|
69
|
+
client = void 0;
|
|
70
|
+
}
|
|
71
|
+
if (client) {
|
|
72
|
+
try {
|
|
73
|
+
await client["daemon.shutdown"]({});
|
|
74
|
+
} catch (e) {
|
|
75
|
+
await client.close().catch(() => void 0);
|
|
76
|
+
return fail(ctx, {
|
|
77
|
+
what: `The background service${named} did not accept the stop request`,
|
|
78
|
+
detail: [plainError(e)],
|
|
79
|
+
fix: `${pid === null ? "Stop the process that owns the daemon socket yourself" : `Stop pid ${pid} yourself`}, ${STOP_FIX(t)}.`,
|
|
80
|
+
exit: 1,
|
|
81
|
+
ref: "e_daemon_stop"
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
await client.close().catch(() => void 0);
|
|
85
|
+
if (!await waitFor(async () => !await reachable(ctx) && !await lockExists(ctx) && (pid === null || !ctx.isAlive(pid)), ctx.stopTimeoutMs)) return fail(ctx, {
|
|
86
|
+
what: `The background service${named} is still running after ${Math.round(ctx.stopTimeoutMs / 1e3)}s`,
|
|
87
|
+
detail: ["It accepted the stop request, but its process, socket or lock file is still there."],
|
|
88
|
+
fix: `${pid === null ? "Stop the process that owns the daemon socket yourself" : `Stop pid ${pid} yourself`}, ${STOP_FIX(t)}.`,
|
|
89
|
+
exit: 1,
|
|
90
|
+
ref: "e_daemon_stop"
|
|
91
|
+
});
|
|
92
|
+
ctx.out(`${t.status("ok")} Stopped the daemon${named}.\n`);
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
if (pid === null) {
|
|
96
|
+
ctx.out(`${t.status("info")} Conveno's background service is not running. Nothing to stop.\n`);
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
const stale = async () => {
|
|
100
|
+
await rm(lock, { force: true }).catch(() => void 0);
|
|
101
|
+
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`);
|
|
102
|
+
return 0;
|
|
103
|
+
};
|
|
104
|
+
if (!ctx.isAlive(pid)) return stale();
|
|
105
|
+
const commandLine = await ctx.commandLineOf(pid);
|
|
106
|
+
if (commandLine === null) return fail(ctx, {
|
|
107
|
+
what: `The background service did not answer, and pid ${pid} could not be checked`,
|
|
108
|
+
detail: ["Conveno could not read that process's command line, so it cannot tell whether it is the daemon. It stopped nothing."],
|
|
109
|
+
fix: `If pid ${pid} is the Conveno daemon, end it yourself (Task Manager on Windows, \`kill ${pid}\` elsewhere), ${STOP_FIX(t)}.`,
|
|
110
|
+
exit: 1,
|
|
111
|
+
ref: "e_daemon_lock"
|
|
112
|
+
});
|
|
113
|
+
if (!isConvenoDaemonCommand(commandLine, ctx.daemonEntry)) return stale();
|
|
114
|
+
try {
|
|
115
|
+
ctx.kill(pid);
|
|
116
|
+
} catch (e) {
|
|
117
|
+
return fail(ctx, {
|
|
118
|
+
what: `Could not stop the daemon (pid ${pid})`,
|
|
119
|
+
detail: [plainError(e)],
|
|
120
|
+
fix: `Stop that process yourself, ${STOP_FIX(t)}.`,
|
|
121
|
+
exit: 1,
|
|
122
|
+
ref: "e_daemon_stop"
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (!await waitFor(() => !ctx.isAlive(pid), ctx.stopTimeoutMs)) return fail(ctx, {
|
|
126
|
+
what: `The background service (pid ${pid}) is still running after ${Math.round(ctx.stopTimeoutMs / 1e3)}s`,
|
|
127
|
+
detail: ["It did not answer, was ended, and has not exited."],
|
|
128
|
+
fix: `Stop that process yourself, ${STOP_FIX(t)}.`,
|
|
129
|
+
exit: 1,
|
|
130
|
+
ref: "e_daemon_stop"
|
|
131
|
+
});
|
|
132
|
+
await rm(lock, { force: true }).catch(() => void 0);
|
|
133
|
+
ctx.out(`${t.status("ok")} Stopped the daemon (pid ${pid}). It was not answering, so it was ended directly.\n`);
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
const SUBCOMMANDS = [
|
|
137
|
+
"start",
|
|
138
|
+
"stop",
|
|
139
|
+
"status"
|
|
140
|
+
];
|
|
141
|
+
async function runDaemon(ctx, argv) {
|
|
142
|
+
const t = ctx.theme;
|
|
143
|
+
const sub = argv[0];
|
|
144
|
+
if (sub === "start") {
|
|
145
|
+
try {
|
|
146
|
+
await (await ctx.connect(connectOpts(ctx, true))).close().catch(() => void 0);
|
|
147
|
+
} catch (e) {
|
|
148
|
+
const problem = daemonProblem(t, e);
|
|
149
|
+
return fail(ctx, {
|
|
150
|
+
what: "The Conveno daemon did not start",
|
|
151
|
+
detail: [problem.why],
|
|
152
|
+
fix: problem.notRunning ? `Run ${cmd(t, "conveno doctor")} to check the install, then try again.` : problem.fix,
|
|
153
|
+
exit: 1,
|
|
154
|
+
ref: "e_daemon_start"
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
const pid = await lockPid(ctx);
|
|
158
|
+
ctx.out(`${t.status("ok")} Daemon running${pid ? `, pid ${pid}` : ""}.\n`);
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
161
|
+
if (sub === "status") {
|
|
162
|
+
const pid = await lockPid(ctx);
|
|
163
|
+
try {
|
|
164
|
+
await (await ctx.connect(connectOpts(ctx, false))).close().catch(() => void 0);
|
|
165
|
+
ctx.out(`${t.status("ok")} daemon running${pid ? `, pid ${pid}` : ""}\n`);
|
|
166
|
+
return 0;
|
|
167
|
+
} catch (e) {
|
|
168
|
+
const problem = daemonProblem(t, e);
|
|
169
|
+
if (problem.notRunning) ctx.out(`${t.glyph("offline")} daemon not running\n`);
|
|
170
|
+
else {
|
|
171
|
+
ctx.out(`${t.status("error")} daemon cannot be reached\n`);
|
|
172
|
+
ctx.err(warnBlock(t, "Conveno's background service cannot be reached.", problem.fix, problem.why));
|
|
173
|
+
}
|
|
174
|
+
return 1;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (sub === "stop") return stopDaemon(ctx);
|
|
178
|
+
const suggestion = sub ? closest(sub, SUBCOMMANDS) : void 0;
|
|
179
|
+
return fail(ctx, {
|
|
180
|
+
what: sub ? `Unknown daemon command "${sub}"` : "conveno daemon needs a command",
|
|
181
|
+
fix: `Run ${cmd(t, "conveno daemon start")}, ${cmd(t, "conveno daemon stop")} or ${cmd(t, "conveno daemon status")}.`,
|
|
182
|
+
...suggestion ? { didYouMean: `Did you mean ${suggestion}?` } : {},
|
|
183
|
+
exit: 2,
|
|
184
|
+
ref: "e_usage"
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
// src/version.ts
|
|
188
|
+
const VERSION = "0.2.0-rc.6";
|
|
189
|
+
// src/errorLog.ts
|
|
190
|
+
/** The message of an unexpected error, as it is. Not the softened text `plainError` gives. */
|
|
191
|
+
function rawMessage(e) {
|
|
192
|
+
if (e instanceof Error) return `${e.name}: ${e.message}`;
|
|
193
|
+
return String(e);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Write the full stack of an unexpected error to `<data dir>/logs/<timestamp>-error.log`, readable
|
|
197
|
+
* by the user only. Returns the path, or undefined when the log could not be written (the error is
|
|
198
|
+
* still reported, just without a log).
|
|
199
|
+
*/
|
|
200
|
+
async function writeErrorLog(ctx, argv, e) {
|
|
201
|
+
try {
|
|
202
|
+
const dir = dataPaths(ctx.platform, ctx.dataDir).logs;
|
|
203
|
+
await mkdir(dir, {
|
|
204
|
+
recursive: true,
|
|
205
|
+
mode: 448
|
|
206
|
+
});
|
|
207
|
+
const stamp = ctx.now().toISOString().replace(/[:.]/g, "-");
|
|
208
|
+
const file = join(dir, `${stamp}-error.log`);
|
|
209
|
+
const command = argv.slice(0, 2).join(" ");
|
|
210
|
+
const text = [
|
|
211
|
+
`conveno ${VERSION} ${command}`,
|
|
212
|
+
"ref e_internal",
|
|
213
|
+
`time ${ctx.now().toISOString()}`,
|
|
214
|
+
`platform ${ctx.platform}, node ${process.version}`,
|
|
215
|
+
"",
|
|
216
|
+
e instanceof Error ? e.stack ?? rawMessage(e) : rawMessage(e),
|
|
217
|
+
e instanceof Error && e.cause !== void 0 ? `\nCaused by: ${e.cause instanceof Error ? e.cause.stack ?? rawMessage(e.cause) : String(e.cause)}` : "",
|
|
218
|
+
""
|
|
219
|
+
].join("\n");
|
|
220
|
+
await writeFile(file, text, { mode: 384 });
|
|
221
|
+
await chmod(file, 384).catch(() => void 0);
|
|
222
|
+
return file;
|
|
223
|
+
} catch {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// src/lead.ts
|
|
228
|
+
/** `conveno lead <session>`: make that session the lead. `--clear` leaves no lead. */
|
|
229
|
+
async function runLead(ctx, argv) {
|
|
230
|
+
const t = ctx.theme;
|
|
231
|
+
const spec = COMMANDS.find((c) => c.name === "lead");
|
|
232
|
+
if (!spec) return 2;
|
|
233
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
234
|
+
if (typeof parsed === "number") return parsed;
|
|
235
|
+
const [session, ...extra] = parsed.positionals;
|
|
236
|
+
const clear = parsed.values.clear === true;
|
|
237
|
+
if (clear ? session !== void 0 : !session || extra.length > 0) return fail(ctx, {
|
|
238
|
+
what: clear ? "conveno lead --clear takes no session" : "conveno lead needs one session, or --clear",
|
|
239
|
+
fix: `For example ${cmd(t, "conveno lead planner")}, or ${cmd(t, "conveno lead --clear")}. ${cmd(t, "conveno status")} lists the names.`,
|
|
240
|
+
exit: 2,
|
|
241
|
+
ref: "e_usage"
|
|
242
|
+
});
|
|
243
|
+
let client;
|
|
244
|
+
try {
|
|
245
|
+
client = await ctx.connect(connectOpts(ctx, false));
|
|
246
|
+
} catch (e) {
|
|
247
|
+
const problem = daemonProblem(t, e);
|
|
248
|
+
return fail(ctx, {
|
|
249
|
+
what: problem.notRunning ? "Conveno's background service is not running" : "Conveno's background service cannot be reached",
|
|
250
|
+
detail: [problem.notRunning ? "There are no sessions to pick from." : problem.why],
|
|
251
|
+
fix: problem.notRunning ? `Run ${cmd(t, "conveno daemon start")}.` : problem.fix,
|
|
252
|
+
exit: 1,
|
|
253
|
+
ref: "e_daemon"
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
if (clear) {
|
|
258
|
+
const res = await client["orchestrator.clear"]({});
|
|
259
|
+
ctx.out(res.previous ? `${t.status("ok")} No session is the lead now.\n` : `${t.status("info")} No session was the lead.\n`);
|
|
260
|
+
return 0;
|
|
261
|
+
}
|
|
262
|
+
const found = await findSession(client, session);
|
|
263
|
+
if (!found) return fail(ctx, {
|
|
264
|
+
what: `No session "${session}"`,
|
|
265
|
+
fix: `Run ${cmd(t, "conveno status")} to see the names.`,
|
|
266
|
+
exit: 1,
|
|
267
|
+
ref: "e_session"
|
|
268
|
+
});
|
|
269
|
+
if (found.status === "offline") return fail(ctx, {
|
|
270
|
+
what: `${found.name} is offline`,
|
|
271
|
+
detail: ["Only a session that is online can be the lead."],
|
|
272
|
+
fix: `Run ${cmd(t, "conveno status")} to see who is online.`,
|
|
273
|
+
exit: 1,
|
|
274
|
+
ref: "e_session"
|
|
275
|
+
});
|
|
276
|
+
await client["orchestrator.claim"]({ sessionId: found.id });
|
|
277
|
+
ctx.out(`${t.status("ok")} ${t.bold(found.name)} is the lead now.\n`);
|
|
278
|
+
return 0;
|
|
279
|
+
} catch (e) {
|
|
280
|
+
return fail(ctx, {
|
|
281
|
+
what: "The lead was not changed",
|
|
282
|
+
detail: [plainError(e)],
|
|
283
|
+
fix: `Run ${cmd(t, "conveno status")} to see the sessions.`,
|
|
284
|
+
exit: 1,
|
|
285
|
+
ref: "e_lead"
|
|
286
|
+
});
|
|
287
|
+
} finally {
|
|
288
|
+
await client.close().catch(() => void 0);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// src/rename.ts
|
|
292
|
+
/** `conveno rename <session> <new-name>`. */
|
|
293
|
+
async function runRename(ctx, argv) {
|
|
294
|
+
const t = ctx.theme;
|
|
295
|
+
const spec = COMMANDS.find((c) => c.name === "rename");
|
|
296
|
+
if (!spec) return 2;
|
|
297
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
298
|
+
if (typeof parsed === "number") return parsed;
|
|
299
|
+
const [session, name, ...extra] = parsed.positionals;
|
|
300
|
+
if (!session || !name || extra.length > 0) return fail(ctx, {
|
|
301
|
+
what: "conveno rename needs a session and a new name",
|
|
302
|
+
fix: `For example ${cmd(t, "conveno rename claude@app-1 planner")}.`,
|
|
303
|
+
exit: 2,
|
|
304
|
+
ref: "e_usage"
|
|
305
|
+
});
|
|
306
|
+
let client;
|
|
307
|
+
try {
|
|
308
|
+
client = await ctx.connect(connectOpts(ctx, false));
|
|
309
|
+
} catch (e) {
|
|
310
|
+
const problem = daemonProblem(t, e);
|
|
311
|
+
return fail(ctx, {
|
|
312
|
+
what: problem.notRunning ? "Conveno's background service is not running" : "Conveno's background service cannot be reached",
|
|
313
|
+
detail: [problem.notRunning ? "There are no sessions to rename." : problem.why],
|
|
314
|
+
fix: problem.notRunning ? `Run ${cmd(t, "conveno daemon start")}.` : problem.fix,
|
|
315
|
+
exit: 1,
|
|
316
|
+
ref: "e_daemon"
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
const found = await findSession(client, session);
|
|
321
|
+
if (!found) return fail(ctx, {
|
|
322
|
+
what: `No session "${session}"`,
|
|
323
|
+
fix: `Run ${cmd(t, "conveno status")} to see the names.`,
|
|
324
|
+
exit: 1,
|
|
325
|
+
ref: "e_session"
|
|
326
|
+
});
|
|
327
|
+
if (found.status === "offline") return fail(ctx, {
|
|
328
|
+
what: `${found.name} is offline`,
|
|
329
|
+
detail: ["Only a session that is online can be renamed."],
|
|
330
|
+
fix: `Run ${cmd(t, "conveno status")} to see who is online.`,
|
|
331
|
+
exit: 1,
|
|
332
|
+
ref: "e_session"
|
|
333
|
+
});
|
|
334
|
+
const res = await client["session.rename"]({
|
|
335
|
+
sessionId: found.id,
|
|
336
|
+
name
|
|
337
|
+
});
|
|
338
|
+
ctx.out(`${t.status("ok")} ${t.bold(found.name)} is now ${t.bold(res.session.name)}.\n`);
|
|
339
|
+
return 0;
|
|
340
|
+
} catch (e) {
|
|
341
|
+
return fail(ctx, {
|
|
342
|
+
what: "The session was not renamed",
|
|
343
|
+
detail: [plainError(e)],
|
|
344
|
+
fix: `Pick another name, or run ${cmd(t, "conveno status")} to see the names in use.`,
|
|
345
|
+
exit: 1,
|
|
346
|
+
ref: "e_rename"
|
|
347
|
+
});
|
|
348
|
+
} finally {
|
|
349
|
+
await client.close().catch(() => void 0);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// src/send.ts
|
|
353
|
+
/** `conveno send <to> <text...>`: send a message as you, the owner. */
|
|
354
|
+
async function runSend(ctx, argv) {
|
|
355
|
+
const t = ctx.theme;
|
|
356
|
+
const spec = COMMANDS.find((c) => c.name === "send");
|
|
357
|
+
if (!spec) return 2;
|
|
358
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
359
|
+
if (typeof parsed === "number") return parsed;
|
|
360
|
+
const [to, ...words] = parsed.positionals;
|
|
361
|
+
let text = words.join(" ");
|
|
362
|
+
if (words.length === 1 && words[0] === "-") text = (await ctx.readStdin()).replace(/\s+$/, "");
|
|
363
|
+
if (!to || text.trim() === "") return fail(ctx, {
|
|
364
|
+
what: "conveno send needs a recipient and a text",
|
|
365
|
+
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.`,
|
|
366
|
+
exit: 2,
|
|
367
|
+
ref: "e_usage"
|
|
368
|
+
});
|
|
369
|
+
let client;
|
|
370
|
+
try {
|
|
371
|
+
client = await ctx.connect(connectOpts(ctx, false));
|
|
372
|
+
} catch (e) {
|
|
373
|
+
const problem = daemonProblem(t, e);
|
|
374
|
+
return fail(ctx, {
|
|
375
|
+
what: problem.notRunning ? "Conveno's background service is not running" : "Conveno's background service cannot be reached",
|
|
376
|
+
detail: [problem.notRunning ? "Nobody can get the message." : problem.why],
|
|
377
|
+
fix: problem.notRunning ? `Run ${cmd(t, "conveno daemon start")}.` : problem.fix,
|
|
378
|
+
exit: 1,
|
|
379
|
+
ref: "e_daemon"
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
try {
|
|
383
|
+
const res = await client["owner.send"]({
|
|
384
|
+
to,
|
|
385
|
+
text,
|
|
386
|
+
urgent: parsed.values.urgent === true
|
|
387
|
+
});
|
|
388
|
+
ctx.out(`${t.status("ok")} Sent to ${t.bold(res.deliveredTo.name)}.\n`);
|
|
389
|
+
return 0;
|
|
390
|
+
} catch (e) {
|
|
391
|
+
return fail(ctx, {
|
|
392
|
+
what: "The message was not sent",
|
|
393
|
+
detail: [plainError(e)],
|
|
394
|
+
fix: `Run ${cmd(t, "conveno status")} to see the session names.`,
|
|
395
|
+
exit: 1,
|
|
396
|
+
ref: "e_send"
|
|
397
|
+
});
|
|
398
|
+
} finally {
|
|
399
|
+
await client.close().catch(() => void 0);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
// src/spawn.ts
|
|
403
|
+
/** Read the task from `--task-file`. Returns the text or the failure's exit code. */
|
|
404
|
+
function readTaskFile(ctx, path) {
|
|
405
|
+
try {
|
|
406
|
+
return readFileSync(resolve(ctx.cwd, path), "utf8");
|
|
407
|
+
} catch (e) {
|
|
408
|
+
const code = e.code;
|
|
409
|
+
return fail(ctx, {
|
|
410
|
+
what: `Cannot read the task file ${path}`,
|
|
411
|
+
detail: [code === "ENOENT" ? "The file does not exist." : `The system said ${code ?? "no"}.`],
|
|
412
|
+
fix: "Check the path, or pass the task with --task.",
|
|
413
|
+
exit: 2,
|
|
414
|
+
ref: "e_usage"
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* `conveno spawn <cli> ...`: start a worker session of any CLI with a first task, and print the
|
|
420
|
+
* name it registers under.
|
|
421
|
+
*/
|
|
422
|
+
async function runSpawn(ctx, argv) {
|
|
423
|
+
const t = ctx.theme;
|
|
424
|
+
const spec = COMMANDS.find((c) => c.name === "spawn");
|
|
425
|
+
if (!spec) return 2;
|
|
426
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
427
|
+
if (typeof parsed === "number") return parsed;
|
|
428
|
+
const help = `Run ${cmd(t, "conveno spawn --help")} to see the options.`;
|
|
429
|
+
const [cli, ...extra] = parsed.positionals;
|
|
430
|
+
if (!cli || extra.length > 0) return fail(ctx, {
|
|
431
|
+
what: "conveno spawn needs exactly one CLI name",
|
|
432
|
+
detail: [`Known: ${SPAWN_CLIS.join(", ")}.`],
|
|
433
|
+
fix: `Run ${cmd(t, "conveno spawn claude --task 'review the open PR'")}.`,
|
|
434
|
+
exit: 2,
|
|
435
|
+
ref: "e_usage"
|
|
436
|
+
});
|
|
437
|
+
if (!Object.hasOwn(SPAWN_TABLE, cli)) return fail(ctx, {
|
|
438
|
+
what: `"${cli}" is not a CLI Conveno can start`,
|
|
439
|
+
detail: [`Known: ${SPAWN_CLIS.join(", ")}.`],
|
|
440
|
+
fix: help,
|
|
441
|
+
exit: 2,
|
|
442
|
+
ref: "e_usage"
|
|
443
|
+
});
|
|
444
|
+
const str = (k) => typeof parsed.values[k] === "string" ? parsed.values[k] : void 0;
|
|
445
|
+
if (str("task") !== void 0 && str("task-file") !== void 0) return fail(ctx, {
|
|
446
|
+
what: "Use --task or --task-file, not both",
|
|
447
|
+
fix: help,
|
|
448
|
+
exit: 2,
|
|
449
|
+
ref: "e_usage"
|
|
450
|
+
});
|
|
451
|
+
let task = str("task");
|
|
452
|
+
const taskFile = str("task-file");
|
|
453
|
+
if (taskFile !== void 0) {
|
|
454
|
+
const text = readTaskFile(ctx, taskFile);
|
|
455
|
+
if (typeof text === "number") return text;
|
|
456
|
+
task = text;
|
|
457
|
+
}
|
|
458
|
+
const window = parsed.values.window === true;
|
|
459
|
+
const allowFlag = str("allow");
|
|
460
|
+
const allow = allowFlag === void 0 ? void 0 : [allowFlag];
|
|
461
|
+
const yes = parsed.values.yes === true;
|
|
462
|
+
const adapter = ctx.adapters.find((a) => a.cli === cli);
|
|
463
|
+
if (adapter && !(await adapter.detect(adapterEnv(ctx))).installed) return fail(ctx, {
|
|
464
|
+
what: `${adapter.displayName} is not installed`,
|
|
465
|
+
detail: [`conveno could not run ${cli} --version.`],
|
|
466
|
+
fix: "Install it, or check that its folder is on PATH.",
|
|
467
|
+
exit: 1,
|
|
468
|
+
ref: "e_spawn"
|
|
469
|
+
});
|
|
470
|
+
if (!yes) {
|
|
471
|
+
if (!ctx.interactive) return fail(ctx, {
|
|
472
|
+
what: "Needs a terminal to confirm",
|
|
473
|
+
detail: ["Nothing was started."],
|
|
474
|
+
fix: `Run the same command with ${cmd(t, "--yes")} to start the session without asking.`,
|
|
475
|
+
exit: 2,
|
|
476
|
+
ref: "e_no_tty"
|
|
477
|
+
});
|
|
478
|
+
const question = `Start ${cli} in ${tilde(resolve(ctx.cwd, str("cwd") ?? "."), ctx.home)}${window ? "" : " in the background"}${task ? " with a first task" : ""}?`;
|
|
479
|
+
if (!await ctx.confirm(question, true)) {
|
|
480
|
+
ctx.out(`${t.status("info")} Nothing was started.\n`);
|
|
481
|
+
return 0;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
let client;
|
|
485
|
+
try {
|
|
486
|
+
client = await ctx.connect(connectOpts(ctx, true));
|
|
487
|
+
} catch (e) {
|
|
488
|
+
const problem = daemonProblem(t, e);
|
|
489
|
+
return fail(ctx, {
|
|
490
|
+
what: "Conveno's background service cannot be reached",
|
|
491
|
+
detail: [problem.why],
|
|
492
|
+
fix: problem.fix,
|
|
493
|
+
exit: 1,
|
|
494
|
+
ref: "e_daemon"
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
try {
|
|
498
|
+
const { hostPid } = await ctx.ancestry(2e3);
|
|
499
|
+
const requester = hostPid === void 0 ? void 0 : (await client["session.byHost"]({ pid: hostPid }).catch(() => void 0))?.session ?? void 0;
|
|
500
|
+
const runner = ctx.spawnRunner ?? [process.execPath, process.argv[1] ?? "conveno"];
|
|
501
|
+
const deps = realSpawnDeps({
|
|
502
|
+
platform: ctx.platform,
|
|
503
|
+
env: ctx.env,
|
|
504
|
+
home: ctx.home,
|
|
505
|
+
dataDir: ctx.dataDir,
|
|
506
|
+
client,
|
|
507
|
+
runner
|
|
508
|
+
});
|
|
509
|
+
const res = await spawnSession(deps, {
|
|
510
|
+
cli,
|
|
511
|
+
callerCwd: ctx.cwd,
|
|
512
|
+
cwd: str("cwd"),
|
|
513
|
+
name: str("name"),
|
|
514
|
+
task,
|
|
515
|
+
window,
|
|
516
|
+
allow,
|
|
517
|
+
requester,
|
|
518
|
+
confineToHome: false,
|
|
519
|
+
onProgress: (line) => ctx.err(`${t.paint("quiet", line)}\n`)
|
|
520
|
+
});
|
|
521
|
+
const how = res.window ? res.terminal ?? "terminal" : "background";
|
|
522
|
+
ctx.out(`${t.status("ok")} ${t.bold(`Started ${res.name}`)} ${t.paint("quiet", `(${res.cli}, ${how}) in ${tilde(res.cwd, ctx.home)}`)}\n`);
|
|
523
|
+
if (res.task === "message") ctx.out(` The first task was sent to it as a Conveno message.\n`);
|
|
524
|
+
if (!res.window) {
|
|
525
|
+
ctx.out(` End it with ${cmd(t, `conveno stop ${res.name}`)}.\n`);
|
|
526
|
+
if (res.adapter) ctx.out(` ${t.paint("quiet", `Adapter: ${res.adapter}`)}\n`);
|
|
527
|
+
}
|
|
528
|
+
if (res.logPath) ctx.out(` Output: ${tilde(res.logPath, ctx.home)}\n`);
|
|
529
|
+
ctx.out(` ${t.paint("quiet", `${cmd(t, "conveno status")} lists it. Message it with send to: ${res.name}.`)}\n`);
|
|
530
|
+
return 0;
|
|
531
|
+
} catch (e) {
|
|
532
|
+
if (e instanceof SpawnError) return fail(ctx, {
|
|
533
|
+
what: "Could not start the session",
|
|
534
|
+
detail: [e.message],
|
|
535
|
+
...e.fix ? { fix: e.fix } : {},
|
|
536
|
+
exit: 1,
|
|
537
|
+
ref: "e_spawn"
|
|
538
|
+
});
|
|
539
|
+
throw e;
|
|
540
|
+
} finally {
|
|
541
|
+
await client.close().catch(() => void 0);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
/** `conveno spawn-run <launch file>`: what a spawned terminal runs. Not for people. */
|
|
545
|
+
async function runSpawnRun(ctx, argv) {
|
|
546
|
+
const [file] = argv;
|
|
547
|
+
if (!file) return fail(ctx, {
|
|
548
|
+
what: "conveno spawn-run needs a launch file",
|
|
549
|
+
detail: ["It is started by conveno spawn inside the new terminal."],
|
|
550
|
+
fix: `Run ${cmd(ctx.theme, "conveno spawn <cli>")} instead.`,
|
|
551
|
+
exit: 2,
|
|
552
|
+
ref: "e_usage"
|
|
553
|
+
});
|
|
554
|
+
try {
|
|
555
|
+
return await runLaunchFile(file);
|
|
556
|
+
} catch (e) {
|
|
557
|
+
return fail(ctx, {
|
|
558
|
+
what: "Could not read the launch file",
|
|
559
|
+
detail: [e instanceof Error ? e.message : String(e)],
|
|
560
|
+
fix: `Run ${cmd(ctx.theme, "conveno spawn <cli>")} again.`,
|
|
561
|
+
exit: 1,
|
|
562
|
+
ref: "e_spawn"
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
// src/status.ts
|
|
567
|
+
const CLI_SHORT = {
|
|
568
|
+
claude: "cl",
|
|
569
|
+
codex: "cx",
|
|
570
|
+
opencode: "oc",
|
|
571
|
+
antigravity: "ag",
|
|
572
|
+
cursor: "cu",
|
|
573
|
+
copilot: "cp",
|
|
574
|
+
grok: "gk"
|
|
575
|
+
};
|
|
576
|
+
const pad2 = (n) => String(n).padStart(2, "0");
|
|
577
|
+
/** Local `HH:MM:SS`, with the date in front when it is not today. */
|
|
578
|
+
function stamp(iso, now) {
|
|
579
|
+
const d = new Date(iso);
|
|
580
|
+
const time = `${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`;
|
|
581
|
+
const day = `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`;
|
|
582
|
+
return day === `${now.getFullYear()}-${pad2(now.getMonth() + 1)}-${pad2(now.getDate())}` ? time : `${day} ${time}`;
|
|
583
|
+
}
|
|
584
|
+
function tierText(theme, tier) {
|
|
585
|
+
switch (tier) {
|
|
586
|
+
case "live": return theme.paint("entry", "live");
|
|
587
|
+
case "next_turn": return "next turn";
|
|
588
|
+
case "acp": return "ACP";
|
|
589
|
+
case "inbox": return theme.paint("quiet", "inbox");
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
function stateCell(theme, s) {
|
|
593
|
+
if (s.isOrchestrator) return {
|
|
594
|
+
glyph: theme.status("orchestrator"),
|
|
595
|
+
word: s.status
|
|
596
|
+
};
|
|
597
|
+
if (s.status === "busy") return {
|
|
598
|
+
glyph: theme.glyph("busy"),
|
|
599
|
+
word: "busy"
|
|
600
|
+
};
|
|
601
|
+
return {
|
|
602
|
+
glyph: theme.status("idle"),
|
|
603
|
+
word: "idle"
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
/** Sessions grouped by repository, the way brand/components/terminal.md lays them out. */
|
|
607
|
+
function renderSessions(ctx, sessions) {
|
|
608
|
+
const t = ctx.theme;
|
|
609
|
+
const now = ctx.now();
|
|
610
|
+
const groups = /* @__PURE__ */ new Map();
|
|
611
|
+
const keyOf = (s) => s.remote ? `${s.repo?.root ?? s.cwd}\u0000${s.deviceName ?? ""}` : s.repo?.root ?? s.cwd;
|
|
612
|
+
for (const s of sessions) {
|
|
613
|
+
const key = keyOf(s);
|
|
614
|
+
groups.set(key, [...groups.get(key) ?? [], s]);
|
|
615
|
+
}
|
|
616
|
+
const blocks = [];
|
|
617
|
+
for (const key of [...groups.keys()].sort()) {
|
|
618
|
+
const list = (groups.get(key) ?? []).sort((a, b) => a.name.localeCompare(b.name));
|
|
619
|
+
const q = (w) => t.paint("quiet", w);
|
|
620
|
+
const head = [
|
|
621
|
+
` ${q("SESSION")}`,
|
|
622
|
+
q("CLI"),
|
|
623
|
+
q("TIER"),
|
|
624
|
+
q("STATE"),
|
|
625
|
+
q("UNREAD"),
|
|
626
|
+
q("LAST SEEN")
|
|
627
|
+
];
|
|
628
|
+
const rows = list.map((s) => {
|
|
629
|
+
const st = stateCell(t, s);
|
|
630
|
+
return [
|
|
631
|
+
`${st.glyph} ${t.bold(s.name)}`,
|
|
632
|
+
CLI_SHORT[s.cli] ?? s.cli,
|
|
633
|
+
tierText(t, s.deliveryTier),
|
|
634
|
+
st.word,
|
|
635
|
+
s.unreadCount ? String(s.unreadCount) : q("0"),
|
|
636
|
+
t.paint("quiet", stamp(s.lastSeenAt, now)),
|
|
637
|
+
...s.isOrchestrator ? [t.paint("entry", "lead")] : [],
|
|
638
|
+
...s.spawned || s.spawnedBy ? [t.paint("quiet", "spawned")] : []
|
|
639
|
+
];
|
|
640
|
+
});
|
|
641
|
+
const [headLine, ...rowLines] = columns([head, ...rows]);
|
|
642
|
+
const [path, device] = key.split("\0");
|
|
643
|
+
const title = device === void 0 ? t.bold(tilde(key, ctx.home)) : `${t.bold(path ?? "")} ${t.paint("quiet", `on ${device || "another device"}`)}`;
|
|
644
|
+
blocks.push([
|
|
645
|
+
` ${title}`,
|
|
646
|
+
` ${headLine}`,
|
|
647
|
+
...rowLines.map((l) => ` ${l}`)
|
|
648
|
+
].join("\n"));
|
|
649
|
+
}
|
|
650
|
+
return blocks.join("\n\n");
|
|
651
|
+
}
|
|
652
|
+
/** The relay part of the status header line. */
|
|
653
|
+
function relaySummary(r) {
|
|
654
|
+
if (!r) return "off (local only)";
|
|
655
|
+
switch (r.state) {
|
|
656
|
+
case "connected": {
|
|
657
|
+
const online = r.peers.filter((p) => p.online).length;
|
|
658
|
+
return `connected (${plural(online, "other device")} online)`;
|
|
659
|
+
}
|
|
660
|
+
case "connecting": return "connecting";
|
|
661
|
+
case "disconnected": return "disconnected, retrying";
|
|
662
|
+
case "revoked": return "off (this device was revoked)";
|
|
663
|
+
case "unpaired": return "off (no paired devices)";
|
|
664
|
+
default: return "off (local only)";
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
async function runStatus(ctx, argv = []) {
|
|
668
|
+
const t = ctx.theme;
|
|
669
|
+
const spec = COMMANDS.find((c) => c.name === "status");
|
|
670
|
+
if (spec) {
|
|
671
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
672
|
+
if (typeof parsed === "number") return parsed;
|
|
673
|
+
}
|
|
674
|
+
let client;
|
|
675
|
+
try {
|
|
676
|
+
client = await ctx.connect(connectOpts(ctx, false));
|
|
677
|
+
} catch (e) {
|
|
678
|
+
const problem = daemonProblem(t, e);
|
|
679
|
+
ctx.err(problem.notRunning ? warnBlock(t, "Conveno's background service 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, "Conveno's background service cannot be reached.", problem.fix, problem.why));
|
|
680
|
+
return 0;
|
|
681
|
+
}
|
|
682
|
+
try {
|
|
683
|
+
const sessions = (await client["session.list"]({})).sessions;
|
|
684
|
+
const repos = new Set(sessions.map((s) => s.repo?.root ?? s.cwd)).size;
|
|
685
|
+
const relay = await (async () => client["relay.status"]({}))().catch(() => void 0);
|
|
686
|
+
ctx.out(`daemon up ${t.status("bullet")} relay: ${relaySummary(relay)} ${t.status("bullet")} ${plural(sessions.length, "session")}\n`);
|
|
687
|
+
if (sessions.length === 0) {
|
|
688
|
+
ctx.out(`\nNo sessions yet. Open a supported CLI after ${cmd(t, "conveno init")} and it appears here.\n`);
|
|
689
|
+
return 0;
|
|
690
|
+
}
|
|
691
|
+
ctx.out(`\n${renderSessions(ctx, sessions)}\n\n`);
|
|
692
|
+
ctx.out(`${plural(sessions.length, "session")} in ${plural(repos, "repo")}\n`);
|
|
693
|
+
return 0;
|
|
694
|
+
} finally {
|
|
695
|
+
await client.close().catch(() => void 0);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
// src/uninstall.ts
|
|
699
|
+
const NOTE = {
|
|
700
|
+
restore: "restored byte for byte",
|
|
701
|
+
remove: "removed, it did not exist before",
|
|
702
|
+
edit: "edited since init, so only Conveno's entries are removed",
|
|
703
|
+
gone: "already gone, left as it is"
|
|
704
|
+
};
|
|
705
|
+
/**
|
|
706
|
+
* The files as init found them, from the backups: their text, or null when they did not exist. A
|
|
707
|
+
* backup that cannot be read leaves its file out, and the adapter then treats what it finds as
|
|
708
|
+
* Conveno's own.
|
|
709
|
+
*/
|
|
710
|
+
async function baselineOf(dir, entries) {
|
|
711
|
+
const out = /* @__PURE__ */ new Map();
|
|
712
|
+
for (const e of entries) if (e.backup === null) out.set(e.path, null);
|
|
713
|
+
else try {
|
|
714
|
+
out.set(e.path, await readFile(join(dir, e.backup), "utf8"));
|
|
715
|
+
} catch {}
|
|
716
|
+
return out;
|
|
717
|
+
}
|
|
718
|
+
/** Remove Conveno's own entries from files that changed since init, through each adapter. */
|
|
719
|
+
async function removeOwnEntries(ctx, dir, entries) {
|
|
720
|
+
if (entries.length === 0) return {
|
|
721
|
+
edited: [],
|
|
722
|
+
failures: []
|
|
723
|
+
};
|
|
724
|
+
const clis = new Set(entries.map((e) => e.cli));
|
|
725
|
+
const found = (await detectAll(ctx)).filter((f) => clis.has(f.adapter.cli));
|
|
726
|
+
const { items, failures } = await collectPlans(ctx, found, "uninstallPlan", await baselineOf(dir, entries));
|
|
727
|
+
const wanted = new Set(entries.map((e) => e.path));
|
|
728
|
+
const mine = items.filter((i) => wanted.has(i.change.path));
|
|
729
|
+
if (mine.length > 0) await applyChanges(ctx, mine, { markRestored: true });
|
|
730
|
+
return {
|
|
731
|
+
edited: mine.map((i) => i.change.path),
|
|
732
|
+
failures
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
async function restoreAll(ctx, manifests) {
|
|
736
|
+
const restored = [];
|
|
737
|
+
const edited = [];
|
|
738
|
+
const untouched = [];
|
|
739
|
+
for (const found of manifests) {
|
|
740
|
+
const needEdit = [];
|
|
741
|
+
for (const entry of found.manifest.entries) {
|
|
742
|
+
const action = await restoreEntry(found.dir, entry);
|
|
743
|
+
if (action === "edit") needEdit.push(entry);
|
|
744
|
+
else if (action === "gone") untouched.push(entry.path);
|
|
745
|
+
else restored.push(entry.path);
|
|
746
|
+
}
|
|
747
|
+
const r = await removeOwnEntries(ctx, found.dir, needEdit);
|
|
748
|
+
if (r.failures.length > 0) {
|
|
749
|
+
reportFailures(ctx, r.failures, "conveno uninstall");
|
|
750
|
+
throw new Error("A config file could not be read, so it was left as it is.");
|
|
751
|
+
}
|
|
752
|
+
edited.push(...r.edited);
|
|
753
|
+
for (const e of needEdit) if (!r.edited.includes(e.path)) untouched.push(e.path);
|
|
754
|
+
await markRestored(ctx, found);
|
|
755
|
+
}
|
|
756
|
+
return {
|
|
757
|
+
restored,
|
|
758
|
+
edited,
|
|
759
|
+
untouched
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
async function runUninstall(ctx, argv) {
|
|
763
|
+
const t = ctx.theme;
|
|
764
|
+
const started = ctx.now();
|
|
765
|
+
const spec = COMMANDS.find((c) => c.name === "uninstall");
|
|
766
|
+
if (!spec) return 2;
|
|
767
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
768
|
+
if (typeof parsed === "number") return parsed;
|
|
769
|
+
const yes = parsed.values.yes === true;
|
|
770
|
+
const manifests = await listManifests(ctx).catch(() => []);
|
|
771
|
+
if (manifests.length > 0) {
|
|
772
|
+
const rows = await previewRestore(manifests);
|
|
773
|
+
const made = manifests.map((m) => localStamp(m.manifest.createdAt));
|
|
774
|
+
ctx.out(`${t.bold(`Conveno will undo ${plural(manifests.length, "install")}`)}, made ${made.join(", ")} (local time).\n\n`);
|
|
775
|
+
ctx.out(`${columns(rows.map((r) => [` ${tilde(r.entry.path, ctx.home)}`, t.paint("quiet", NOTE[r.action])])).join("\n")}\n\n`);
|
|
776
|
+
if (!yes) {
|
|
777
|
+
if (!ctx.interactive) return fail(ctx, {
|
|
778
|
+
what: "Needs a terminal to confirm",
|
|
779
|
+
detail: ["No files were changed."],
|
|
780
|
+
fix: `Run ${cmd(t, "conveno uninstall --yes")} to undo the changes listed above.`,
|
|
781
|
+
exit: 2,
|
|
782
|
+
ref: "e_no_tty"
|
|
783
|
+
});
|
|
784
|
+
if (!await ctx.confirm("Undo these changes?", false)) {
|
|
785
|
+
ctx.out(`${t.status("info")} Nothing was changed.\n`);
|
|
786
|
+
return 0;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
let result;
|
|
790
|
+
try {
|
|
791
|
+
result = await restoreAll(ctx, manifests);
|
|
792
|
+
} catch (e) {
|
|
793
|
+
if (e instanceof StaleError) return staleFailure(ctx, e, "conveno uninstall");
|
|
794
|
+
return fail(ctx, {
|
|
795
|
+
what: "Could not restore a file",
|
|
796
|
+
detail: [plainError(e), `The backups are still in ${tilde(manifests[0]?.dir ?? ctx.dataDir, ctx.home)} and the other backup folders next to it.`],
|
|
797
|
+
fix: "Fix the problem above, then run conveno uninstall again.",
|
|
798
|
+
exit: 1,
|
|
799
|
+
ref: "e_restore"
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
ctx.out(`${t.status("ok")} ${t.bold("Done.")} ${seconds(started, ctx.now())}\n`);
|
|
803
|
+
ctx.out(` Restored ${plural(result.restored.length, "file")} to how init found them.\n`);
|
|
804
|
+
if (result.edited.length > 0) ctx.out(` Edited, not restored, because they changed since init: ${result.edited.map((p) => tilde(p, ctx.home)).join(", ")}. Only Conveno's entries were removed.\n`);
|
|
805
|
+
ctx.out(" Restart open sessions to drop Conveno.\n");
|
|
806
|
+
return 0;
|
|
807
|
+
}
|
|
808
|
+
const found = await detectAll(ctx);
|
|
809
|
+
const { items, failures } = await collectPlans(ctx, found, "uninstallPlan");
|
|
810
|
+
if (failures.length > 0) {
|
|
811
|
+
reportFailures(ctx, failures, "conveno uninstall");
|
|
812
|
+
return 1;
|
|
813
|
+
}
|
|
814
|
+
if (items.length === 0) {
|
|
815
|
+
ctx.out(`${t.status("ok")} Nothing to remove. No Conveno entries were found in any supported CLI.\n`);
|
|
816
|
+
return 0;
|
|
817
|
+
}
|
|
818
|
+
ctx.out(`${t.status("info")} No install backup found, so Conveno will remove only its own entries.\n\n`);
|
|
819
|
+
const result = await confirmAndApply(ctx, items, {
|
|
820
|
+
yes,
|
|
821
|
+
verb: "Remove",
|
|
822
|
+
rerun: "conveno uninstall",
|
|
823
|
+
markRestored: true
|
|
824
|
+
});
|
|
825
|
+
if ("exit" in result) return result.exit;
|
|
826
|
+
ctx.out(`${t.status("ok")} ${t.bold("Done.")} ${seconds(started, ctx.now())}\n`);
|
|
827
|
+
ctx.out(" Removed the Conveno entries. Restart open sessions to drop Conveno.\n");
|
|
828
|
+
return 0;
|
|
829
|
+
}
|
|
830
|
+
// src/main.ts
|
|
831
|
+
const DESCRIPTION = "Conveno lets AI coding sessions on one machine find each other and exchange messages.";
|
|
832
|
+
function helpText(ctx) {
|
|
833
|
+
const t = ctx.theme;
|
|
834
|
+
const rows = COMMANDS.filter((c) => !c.hidden).map((c) => [c.usage.replace(/^conveno /, ""), c.summary]);
|
|
835
|
+
const width = Math.max(...rows.map(([u]) => u.length), 9) + 2;
|
|
836
|
+
const row = (c, d) => ` ${t.bold(c.padEnd(width))}${d}`;
|
|
837
|
+
return [
|
|
838
|
+
DESCRIPTION,
|
|
839
|
+
"",
|
|
840
|
+
"Usage: conveno <command> [options]",
|
|
841
|
+
"",
|
|
842
|
+
...rows.map(([u, d]) => row(u, d)),
|
|
843
|
+
row("--version", "Print the version"),
|
|
844
|
+
"",
|
|
845
|
+
`Run ${cmd(t, "conveno <command> --help")} for the options of one command.`,
|
|
846
|
+
`conveno ${t.paint("info", VERSION)}`,
|
|
847
|
+
""
|
|
848
|
+
].join("\n");
|
|
849
|
+
}
|
|
850
|
+
async function runMcp(ctx, argv) {
|
|
851
|
+
const t = ctx.theme;
|
|
852
|
+
const spec = COMMANDS.find((c) => c.name === "mcp");
|
|
853
|
+
if (!spec) return 2;
|
|
854
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
855
|
+
if (typeof parsed === "number") return parsed;
|
|
856
|
+
const cli = typeof parsed.values.cli === "string" ? parsed.values.cli : void 0;
|
|
857
|
+
if (!cli || !CLI_KINDS.includes(cli)) return fail(ctx, {
|
|
858
|
+
what: "conveno mcp needs a CLI name",
|
|
859
|
+
detail: [`Got ${cli ? `"${cli}"` : "none"}. Known: ${CLI_KINDS.join(", ")}.`],
|
|
860
|
+
fix: `Run ${cmd(t, "conveno mcp --cli claude")}, or let ${cmd(t, "conveno init")} write the config.`,
|
|
861
|
+
exit: 2,
|
|
862
|
+
ref: "e_usage"
|
|
863
|
+
});
|
|
864
|
+
try {
|
|
865
|
+
await ctx.runMcp({
|
|
866
|
+
cli,
|
|
867
|
+
...ctx.daemonEntry ? { daemonEntry: ctx.daemonEntry } : {}
|
|
868
|
+
});
|
|
869
|
+
return 0;
|
|
870
|
+
} catch (e) {
|
|
871
|
+
const problem = daemonProblem(t, e);
|
|
872
|
+
return fail(ctx, {
|
|
873
|
+
what: "The Conveno MCP server stopped",
|
|
874
|
+
detail: [problem.why],
|
|
875
|
+
fix: problem.notRunning ? `Run ${cmd(t, "conveno doctor")} to check the daemon.` : problem.fix,
|
|
876
|
+
exit: 1,
|
|
877
|
+
ref: "e_mcp"
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
async function dispatch(name, rest, ctx) {
|
|
882
|
+
const command = name;
|
|
883
|
+
const spec = COMMANDS.find((c) => c.name === command);
|
|
884
|
+
if (spec && (rest.includes("--help") || rest.includes("-h")) && command !== "hook") {
|
|
885
|
+
ctx.out(commandHelp(ctx, spec));
|
|
886
|
+
return 0;
|
|
887
|
+
}
|
|
888
|
+
switch (command) {
|
|
889
|
+
case "init": return runInit(ctx, rest);
|
|
890
|
+
case "uninstall": return runUninstall(ctx, rest);
|
|
891
|
+
case "status": return runStatus(ctx, rest);
|
|
892
|
+
case "send": return runSend(ctx, rest);
|
|
893
|
+
case "rename": return runRename(ctx, rest);
|
|
894
|
+
case "lead": return runLead(ctx, rest);
|
|
895
|
+
case "spawn": return runSpawn(ctx, rest);
|
|
896
|
+
case "acp-host": return (await import("./acp-3xehqLdo.js")).runAcpHostCmd(ctx, rest);
|
|
897
|
+
case "stop": return (await import("./acp-3xehqLdo.js")).runStop(ctx, rest);
|
|
898
|
+
case "spawn-run": return runSpawnRun(ctx, rest);
|
|
899
|
+
case "sidecar": return (await import("./sidecar-CTKxOMie.js")).runSidecar(ctx, rest);
|
|
900
|
+
case "watch": return (await import("./watch-CfYanJvt.js")).runWatch(ctx, rest);
|
|
901
|
+
case "devices": return runDevices(ctx, rest);
|
|
902
|
+
case "relay": return runRelay(ctx, rest);
|
|
903
|
+
case "doctor": return runDoctor(ctx, rest);
|
|
904
|
+
case "login": return runLogin(ctx, rest);
|
|
905
|
+
case "logout": return runLogout(ctx, rest);
|
|
906
|
+
case "account": return runAccount(ctx, rest);
|
|
907
|
+
case "daemon": return runDaemon(ctx, rest);
|
|
908
|
+
case "mcp": return runMcp(ctx, rest);
|
|
909
|
+
case "hook": return runHook(ctx, rest);
|
|
910
|
+
default: {
|
|
911
|
+
const suggestion = closest(command, COMMAND_NAMES);
|
|
912
|
+
return fail(ctx, {
|
|
913
|
+
what: `Unknown command "${command}"`,
|
|
914
|
+
detail: [`conveno ${VERSION} has: ${COMMAND_NAMES.join(", ")}.`],
|
|
915
|
+
fix: `Run ${cmd(ctx.theme, "conveno --help")} to see usage.`,
|
|
916
|
+
...suggestion ? { didYouMean: `Did you mean ${suggestion}?` } : {},
|
|
917
|
+
exit: 2,
|
|
918
|
+
ref: "e_usage"
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
/**
|
|
924
|
+
* `conveno` alone opens the app, but only in a real terminal: not piped, not CI, not TERM=dumb.
|
|
925
|
+
* Everything else prints the help, as before.
|
|
926
|
+
*/
|
|
927
|
+
function opensApp(env, tty = {
|
|
928
|
+
stdin: Boolean(process.stdin.isTTY),
|
|
929
|
+
stdout: Boolean(process.stdout.isTTY)
|
|
930
|
+
}) {
|
|
931
|
+
if (!tty.stdin || !tty.stdout) return false;
|
|
932
|
+
if (env.CI && env.CI !== "0" && env.CI.toLowerCase() !== "false") return false;
|
|
933
|
+
return env.TERM !== "dumb";
|
|
934
|
+
}
|
|
935
|
+
/** Run one command line. Returns the exit code. Never throws. */
|
|
936
|
+
async function main(argv, ctx) {
|
|
937
|
+
const [command, ...rest] = argv;
|
|
938
|
+
if (command === void 0 && opensApp(ctx.env)) try {
|
|
939
|
+
return await (await import("./run-Yi48fiJN.js")).runTui(ctx);
|
|
940
|
+
} catch (e) {
|
|
941
|
+
ctx.err(`The app could not start (${rawMessage(e)}). Showing the help instead.\n`);
|
|
942
|
+
ctx.out(helpText(ctx));
|
|
943
|
+
return 0;
|
|
944
|
+
}
|
|
945
|
+
switch (command) {
|
|
946
|
+
case void 0:
|
|
947
|
+
case "--help":
|
|
948
|
+
case "-h":
|
|
949
|
+
case "help":
|
|
950
|
+
ctx.out(helpText(ctx));
|
|
951
|
+
return 0;
|
|
952
|
+
case "--version":
|
|
953
|
+
case "-v":
|
|
954
|
+
case "version":
|
|
955
|
+
ctx.out(`${VERSION}\n`);
|
|
956
|
+
return 0;
|
|
957
|
+
}
|
|
958
|
+
try {
|
|
959
|
+
return await dispatch(command, rest, ctx);
|
|
960
|
+
} catch (e) {
|
|
961
|
+
const log = await writeErrorLog(ctx, argv, e);
|
|
962
|
+
return fail(ctx, {
|
|
963
|
+
what: "conveno stopped before it could finish",
|
|
964
|
+
detail: [rawMessage(e), ...log ? [`The full error is in ${tilde(log, ctx.home)}.`] : []],
|
|
965
|
+
fix: `Run ${cmd(ctx.theme, "conveno doctor")} to check the install, then try again.`,
|
|
966
|
+
exit: 1,
|
|
967
|
+
ref: "e_internal"
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
export { DESCRIPTION, helpText, main, opensApp };
|