@conveno/cli 0.2.0-rc.2 → 0.2.0-rc.4
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/dist/acp-Bs2yS0Qg.js +142 -0
- package/dist/bin.js +4 -4
- package/dist/ctx-CDLE-2f2.js +18 -0
- package/dist/daemon.js +191 -68
- package/dist/dist-BRjg9CLd.js +731 -0
- package/dist/{dist-hYvLf29C.js → dist-BmpWfYuM.js} +1 -1
- package/dist/{dist-BVE5ihb8.js → dist-CfwMkSGH.js} +1 -1
- package/dist/{dist-BEZPNGU5.js → dist-CiE50AoI.js} +6 -1
- package/dist/{acp-B772ag5j.js → dist-CuStS_nO.js} +5 -143
- package/dist/{dist-_sq6DmrE.js → dist-DUqXHTRg.js} +83 -25
- package/dist/{main-DyHE7TAz.js → doctor-Bckon1ju.js} +16 -1431
- package/dist/{hook-DlTGn8Do.js → hook-DUMp43Xn.js} +3 -19
- package/dist/{hook-entry-BWfePrqh.js → hook-entry-C-HTnddc.js} +4 -4
- package/dist/hook-entry-DP6eq6qr.js +1 -0
- package/dist/main-ByyF0srt.js +1448 -0
- package/dist/run-BEhIahUS.js +5846 -0
- package/dist/{runtime-DPrz7M0s.js → runtime-BS-SUGVR.js} +13 -741
- package/package.json +19 -15
- package/dist/hook-entry-jDI9wAt-.js +0 -1
|
@@ -0,0 +1,1448 @@
|
|
|
1
|
+
import { Bt as runLaunchFile, Cn as SessionName, N as dataPaths, Nt as realSpawnDeps, On as TicketId, Sn as SessionId, Tn as SessionNamePattern, Wn as sanitizeLine, Wt as spawnSession, an as AUTO_LIMIT_MAX, bn as RpcErrorCode, c as SPAWN_CLIS, gt as pauseLabel, l as SPAWN_TABLE, on as CLI_KINDS, r as ConvenoError, u as SpawnError, wn as SessionNameInput } from "./dist-DUqXHTRg.js";
|
|
2
|
+
import { C as runLogout, S as runLogin, _ as runDevices, a as detectAll, 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 runAccount, y as daemonProblem } from "./doctor-Bckon1ju.js";
|
|
3
|
+
import { a as closest, d as plainError, f as plural, h as warnBlock, i as parseFlags, l as fail, m as tilde, n as COMMAND_NAMES, o as cmd, p as seconds, r as commandHelp, 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 { access, chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
6
|
+
import { join, resolve } from "node:path";
|
|
7
|
+
import { t as runHook } from "./hook-DUMp43Xn.js";
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
// src/status.ts
|
|
10
|
+
const CLI_SHORT = {
|
|
11
|
+
claude: "cl",
|
|
12
|
+
codex: "cx",
|
|
13
|
+
opencode: "oc",
|
|
14
|
+
antigravity: "ag",
|
|
15
|
+
cursor: "cu",
|
|
16
|
+
copilot: "cp",
|
|
17
|
+
grok: "gk"
|
|
18
|
+
};
|
|
19
|
+
const pad2 = (n) => String(n).padStart(2, "0");
|
|
20
|
+
/** Local `HH:MM:SS`, with the date in front when it is not today. */
|
|
21
|
+
function stamp(iso, now) {
|
|
22
|
+
const d = new Date(iso);
|
|
23
|
+
const time = `${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`;
|
|
24
|
+
const day = `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`;
|
|
25
|
+
return day === `${now.getFullYear()}-${pad2(now.getMonth() + 1)}-${pad2(now.getDate())}` ? time : `${day} ${time}`;
|
|
26
|
+
}
|
|
27
|
+
function tierText(theme, tier) {
|
|
28
|
+
switch (tier) {
|
|
29
|
+
case "live": return theme.paint("entry", "live");
|
|
30
|
+
case "next_turn": return "next turn";
|
|
31
|
+
case "acp": return "ACP";
|
|
32
|
+
case "inbox": return theme.paint("quiet", "inbox");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function stateCell(theme, s) {
|
|
36
|
+
if (s.status === "offline") return {
|
|
37
|
+
glyph: theme.status("offline"),
|
|
38
|
+
word: "offline"
|
|
39
|
+
};
|
|
40
|
+
if (s.status === "waiting_on_question") return {
|
|
41
|
+
glyph: theme.status("waiting"),
|
|
42
|
+
word: "waiting"
|
|
43
|
+
};
|
|
44
|
+
if (s.isOrchestrator) return {
|
|
45
|
+
glyph: theme.status("orchestrator"),
|
|
46
|
+
word: s.status
|
|
47
|
+
};
|
|
48
|
+
if (s.status === "busy") return {
|
|
49
|
+
glyph: theme.glyph("busy"),
|
|
50
|
+
word: "busy"
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
glyph: theme.status("idle"),
|
|
54
|
+
word: "idle"
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** `on`, `off` or `paused by limit`. */
|
|
58
|
+
function autoText(theme, s) {
|
|
59
|
+
if (s.auto === true && s.autoPausedBy !== void 0) return theme.paint("warn", pauseLabel(s.autoPausedBy));
|
|
60
|
+
return s.auto === true ? "on" : theme.paint("quiet", "off");
|
|
61
|
+
}
|
|
62
|
+
/** Sessions grouped by repository, the way brand/components/terminal.md lays them out. */
|
|
63
|
+
function renderSessions(ctx, sessions) {
|
|
64
|
+
const t = ctx.theme;
|
|
65
|
+
const now = ctx.now();
|
|
66
|
+
const groups = /* @__PURE__ */ new Map();
|
|
67
|
+
const keyOf = (s) => s.remote ? `${s.repo?.root ?? s.cwd}\u0000${s.deviceName ?? ""}` : s.repo?.root ?? s.cwd;
|
|
68
|
+
for (const s of sessions) {
|
|
69
|
+
const key = keyOf(s);
|
|
70
|
+
groups.set(key, [...groups.get(key) ?? [], s]);
|
|
71
|
+
}
|
|
72
|
+
const blocks = [];
|
|
73
|
+
for (const key of [...groups.keys()].sort()) {
|
|
74
|
+
const list = (groups.get(key) ?? []).sort((a, b) => a.name.localeCompare(b.name));
|
|
75
|
+
const q = (w) => t.paint("quiet", w);
|
|
76
|
+
const head = [
|
|
77
|
+
` ${q("SESSION")}`,
|
|
78
|
+
q("CLI"),
|
|
79
|
+
q("TIER"),
|
|
80
|
+
q("STATE"),
|
|
81
|
+
q("AUTO"),
|
|
82
|
+
q("UNREAD"),
|
|
83
|
+
q("LAST SEEN")
|
|
84
|
+
];
|
|
85
|
+
const rows = list.map((s) => {
|
|
86
|
+
const st = stateCell(t, s);
|
|
87
|
+
return [
|
|
88
|
+
`${st.glyph} ${t.bold(s.name)}`,
|
|
89
|
+
CLI_SHORT[s.cli] ?? s.cli,
|
|
90
|
+
tierText(t, s.deliveryTier),
|
|
91
|
+
st.word,
|
|
92
|
+
autoText(t, s),
|
|
93
|
+
s.unreadCount ? String(s.unreadCount) : q("0"),
|
|
94
|
+
t.paint("quiet", stamp(s.lastSeenAt, now)),
|
|
95
|
+
...s.isOrchestrator ? [t.paint("entry", "orchestrator")] : [],
|
|
96
|
+
...s.spawned || s.spawnedBy ? [t.paint("quiet", "spawned")] : []
|
|
97
|
+
];
|
|
98
|
+
});
|
|
99
|
+
const [headLine, ...rowLines] = columns([head, ...rows]);
|
|
100
|
+
const [path, device] = key.split("\0");
|
|
101
|
+
const title = device === void 0 ? t.bold(tilde(key, ctx.home)) : `${t.bold(path ?? "")} ${t.paint("quiet", `on ${device || "another device"}`)}`;
|
|
102
|
+
blocks.push([
|
|
103
|
+
` ${title}`,
|
|
104
|
+
` ${headLine}`,
|
|
105
|
+
...rowLines.map((l) => ` ${l}`)
|
|
106
|
+
].join("\n"));
|
|
107
|
+
}
|
|
108
|
+
return blocks.join("\n\n");
|
|
109
|
+
}
|
|
110
|
+
/** The relay part of the status header line. */
|
|
111
|
+
function relaySummary(r) {
|
|
112
|
+
if (!r) return "off (local only)";
|
|
113
|
+
switch (r.state) {
|
|
114
|
+
case "connected": {
|
|
115
|
+
const online = r.peers.filter((p) => p.online).length;
|
|
116
|
+
return `connected (${plural(online, "other device")} online)`;
|
|
117
|
+
}
|
|
118
|
+
case "connecting": return "connecting";
|
|
119
|
+
case "disconnected": return "disconnected, retrying";
|
|
120
|
+
case "revoked": return "off (this device was revoked)";
|
|
121
|
+
case "unpaired": return "off (no paired devices)";
|
|
122
|
+
default: return "off (local only)";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async function runStatus(ctx, argv = []) {
|
|
126
|
+
const t = ctx.theme;
|
|
127
|
+
const spec = COMMANDS.find((c) => c.name === "status");
|
|
128
|
+
let all = false;
|
|
129
|
+
if (spec) {
|
|
130
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
131
|
+
if (typeof parsed === "number") return parsed;
|
|
132
|
+
all = parsed.values.all === true;
|
|
133
|
+
}
|
|
134
|
+
let client;
|
|
135
|
+
try {
|
|
136
|
+
client = await ctx.connect(connectOpts(ctx, false));
|
|
137
|
+
} catch (e) {
|
|
138
|
+
const problem = daemonProblem(t, e);
|
|
139
|
+
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));
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
const everyone = (await client["session.list"]({ includeOffline: true })).sessions;
|
|
144
|
+
const sessions = all ? everyone : everyone.filter((s) => s.status !== "offline");
|
|
145
|
+
const hidden = everyone.length - sessions.length;
|
|
146
|
+
const repos = new Set(sessions.map((s) => s.repo?.root ?? s.cwd)).size;
|
|
147
|
+
const hint = hidden > 0 ? `${hidden} offline hidden, ${cmd(t, "conveno status --all")} shows them` : "";
|
|
148
|
+
const relay = await (async () => client["relay.status"]({}))().catch(() => void 0);
|
|
149
|
+
ctx.out(`daemon up ${t.status("bullet")} relay: ${relaySummary(relay)} ${t.status("bullet")} ${plural(sessions.length, "session")}\n`);
|
|
150
|
+
if (sessions.length === 0) {
|
|
151
|
+
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`);
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
ctx.out(`\n${renderSessions(ctx, sessions)}\n\n`);
|
|
155
|
+
ctx.out(`${plural(sessions.length, "session")} in ${plural(repos, "repo")}${hint ? ` ${t.status("bullet")} ${hint}` : ""}\n`);
|
|
156
|
+
const paused = sessions.filter((s) => s.auto === true && s.autoPausedBy !== void 0);
|
|
157
|
+
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."));
|
|
158
|
+
const open = await client["ticket.list"]({
|
|
159
|
+
status: "open",
|
|
160
|
+
limit: 1
|
|
161
|
+
}).catch(() => void 0);
|
|
162
|
+
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`);
|
|
163
|
+
return 0;
|
|
164
|
+
} finally {
|
|
165
|
+
await client.close().catch(() => void 0);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// src/auto.ts
|
|
169
|
+
/** Time allowed for the process-table query that finds the session this command runs in. */
|
|
170
|
+
const ANCESTRY_TIMEOUT_MS = 5e3;
|
|
171
|
+
/**
|
|
172
|
+
* The session this command runs inside, when it is typed in a CLI's own shell (for example
|
|
173
|
+
* `! conveno auto on` in Claude Code): the nearest ancestor that hosts exactly one session. A
|
|
174
|
+
* command the user types may look past its first ancestor, because the user asked for it and is
|
|
175
|
+
* told which session changed; hooks never do this.
|
|
176
|
+
*/
|
|
177
|
+
async function enclosingSession(ctx, client) {
|
|
178
|
+
const { pids } = await ctx.ancestry(ANCESTRY_TIMEOUT_MS);
|
|
179
|
+
for (const pid of pids) {
|
|
180
|
+
const { session } = await client["session.byHost"]({ pid });
|
|
181
|
+
if (session) return session;
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const isTarget = (s) => SessionName.safeParse(s).success || SessionId.safeParse(s).success;
|
|
186
|
+
/** `conveno auto [on|off|resume|limit <n|default>] [<session>]`. */
|
|
187
|
+
async function runAuto(ctx, argv) {
|
|
188
|
+
const t = ctx.theme;
|
|
189
|
+
const spec = COMMANDS.find((c) => c.name === "auto");
|
|
190
|
+
if (!spec) return 2;
|
|
191
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
192
|
+
if (typeof parsed === "number") return parsed;
|
|
193
|
+
const [mode, ...rest] = parsed.positionals;
|
|
194
|
+
const usage = `Run ${cmd(t, "conveno auto --help")} to see the usage.`;
|
|
195
|
+
const usageError = (what) => fail(ctx, {
|
|
196
|
+
what,
|
|
197
|
+
fix: usage,
|
|
198
|
+
exit: 2,
|
|
199
|
+
ref: "e_usage"
|
|
200
|
+
});
|
|
201
|
+
let change;
|
|
202
|
+
let args = rest;
|
|
203
|
+
switch (mode) {
|
|
204
|
+
case void 0: break;
|
|
205
|
+
case "on":
|
|
206
|
+
case "off":
|
|
207
|
+
change = { auto: mode === "on" };
|
|
208
|
+
break;
|
|
209
|
+
case "resume":
|
|
210
|
+
change = { resume: true };
|
|
211
|
+
break;
|
|
212
|
+
case "limit": {
|
|
213
|
+
const [value, ...after] = rest;
|
|
214
|
+
if (value === void 0) return usageError("conveno auto limit needs a number or default");
|
|
215
|
+
if (value === "default") change = { limit: null };
|
|
216
|
+
else if (/^\d+$/.test(value) && Number(value) >= 1 && Number(value) <= 1e3) change = { limit: Number(value) };
|
|
217
|
+
else return usageError(`"${value}" is not a limit from 1 to ${AUTO_LIMIT_MAX}, or default`);
|
|
218
|
+
args = after;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
default: return usageError(`Unexpected argument "${mode}" for conveno auto`);
|
|
222
|
+
}
|
|
223
|
+
const [target, ...extra] = args;
|
|
224
|
+
if (extra.length > 0) return usageError(`Unexpected argument "${extra[0]}" for conveno auto`);
|
|
225
|
+
if (target !== void 0 && !isTarget(target)) return fail(ctx, {
|
|
226
|
+
what: `"${target}" is not a session name or id`,
|
|
227
|
+
fix: `Run ${cmd(t, "conveno status")} to see the names.`,
|
|
228
|
+
exit: 2,
|
|
229
|
+
ref: "e_usage"
|
|
230
|
+
});
|
|
231
|
+
let client;
|
|
232
|
+
try {
|
|
233
|
+
client = await ctx.connect(connectOpts(ctx, false));
|
|
234
|
+
} catch (e) {
|
|
235
|
+
const problem = daemonProblem(t, e);
|
|
236
|
+
return fail(ctx, {
|
|
237
|
+
what: "The Conveno daemon cannot be reached",
|
|
238
|
+
detail: [problem.why],
|
|
239
|
+
fix: problem.fix,
|
|
240
|
+
exit: 1,
|
|
241
|
+
ref: "e_daemon"
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
try {
|
|
245
|
+
if (change === void 0) {
|
|
246
|
+
const { sessions } = await client["session.list"]({});
|
|
247
|
+
ctx.out(sessions.length === 0 ? "No sessions online.\n" : `${renderSessions(ctx, sessions)}\n`);
|
|
248
|
+
return 0;
|
|
249
|
+
}
|
|
250
|
+
const session = target ?? (await enclosingSession(ctx, client))?.id;
|
|
251
|
+
if (session === void 0) return fail(ctx, {
|
|
252
|
+
what: "conveno auto needs a session",
|
|
253
|
+
detail: ["This command does not run inside a session Conveno knows."],
|
|
254
|
+
fix: `Name one, such as ${cmd(t, "conveno auto on api-worker")}. ${cmd(t, "conveno status")} lists the names.`,
|
|
255
|
+
exit: 2,
|
|
256
|
+
ref: "e_usage"
|
|
257
|
+
});
|
|
258
|
+
const s = (await client["session.setAuto"]({
|
|
259
|
+
session,
|
|
260
|
+
...change
|
|
261
|
+
})).session;
|
|
262
|
+
ctx.out(`Auto mode for ${t.bold(s.name)} is ${autoText(t, s)}.\n`);
|
|
263
|
+
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");
|
|
264
|
+
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");
|
|
265
|
+
else ctx.out("Messages still reach it at the next prompt and through the inbox tool.\n");
|
|
266
|
+
return 0;
|
|
267
|
+
} catch (e) {
|
|
268
|
+
const problem = daemonProblem(t, e);
|
|
269
|
+
return fail(ctx, {
|
|
270
|
+
what: "Auto mode was not changed",
|
|
271
|
+
detail: [problem.why],
|
|
272
|
+
fix: `Run ${cmd(t, "conveno status")} to see the sessions.`,
|
|
273
|
+
exit: 1,
|
|
274
|
+
ref: "e_auto"
|
|
275
|
+
});
|
|
276
|
+
} finally {
|
|
277
|
+
await client.close().catch(() => void 0);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// src/daemon.ts
|
|
281
|
+
async function lockPid(ctx) {
|
|
282
|
+
try {
|
|
283
|
+
const raw = await readFile(dataPaths(ctx.platform, ctx.dataDir).lock, "utf8");
|
|
284
|
+
const pid = JSON.parse(raw).pid;
|
|
285
|
+
return typeof pid === "number" && Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
286
|
+
} catch {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
291
|
+
/** Does something on the socket answer the Conveno handshake? */
|
|
292
|
+
async function reachable(ctx) {
|
|
293
|
+
try {
|
|
294
|
+
await (await ctx.connect(connectOpts(ctx, false))).close().catch(() => void 0);
|
|
295
|
+
return true;
|
|
296
|
+
} catch {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const lockExists = (ctx) => access(dataPaths(ctx.platform, ctx.dataDir).lock).then(() => true, () => false);
|
|
301
|
+
/** Poll until `done()` holds or `ms` pass. Returns whether it held. */
|
|
302
|
+
async function waitFor(done, ms) {
|
|
303
|
+
const deadline = Date.now() + ms;
|
|
304
|
+
for (;;) {
|
|
305
|
+
if (await done()) return true;
|
|
306
|
+
if (Date.now() >= deadline) return false;
|
|
307
|
+
await sleep(50);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const norm = (text) => text.replaceAll("\\", "/").toLowerCase();
|
|
311
|
+
/**
|
|
312
|
+
* Does this command line belong to the Conveno daemon? It must run the daemon's entry script: the
|
|
313
|
+
* one this install resolved, any installed `@conveno/cli`'s `daemon.js`, or the `bin.js` of the
|
|
314
|
+
* `@conveno/daemon` package that releases before 0.1.1 started.
|
|
315
|
+
*/
|
|
316
|
+
function isConvenoDaemonCommand(commandLine, daemonEntry) {
|
|
317
|
+
const line = norm(commandLine);
|
|
318
|
+
if (daemonEntry !== void 0 && line.includes(norm(daemonEntry))) return true;
|
|
319
|
+
return /@conveno\/cli\/(?:[^ ]+\/)?daemon\.js|@conveno\/daemon\/(?:[^ ]+\/)?bin\.js/.test(line);
|
|
320
|
+
}
|
|
321
|
+
const STOP_FIX = (t) => `then run ${cmd(t, "conveno daemon status")}`;
|
|
322
|
+
/**
|
|
323
|
+
* `conveno daemon stop`. The normal path asks the daemon to shut itself down over the control
|
|
324
|
+
* channel (`daemon.shutdown`), the way Docker and pm2 do. That needs no signal and no external
|
|
325
|
+
* tool, so it works for a normal user in a Windows SSH session. Only when the daemon does not answer,
|
|
326
|
+
* and its lock pid is verified to be the daemon, is the process ended directly.
|
|
327
|
+
*/
|
|
328
|
+
async function stopDaemon(ctx) {
|
|
329
|
+
const t = ctx.theme;
|
|
330
|
+
const lock = dataPaths(ctx.platform, ctx.dataDir).lock;
|
|
331
|
+
const pid = await lockPid(ctx);
|
|
332
|
+
const named = pid === null ? "" : ` (pid ${pid})`;
|
|
333
|
+
let client;
|
|
334
|
+
try {
|
|
335
|
+
client = await ctx.connect(connectOpts(ctx, false));
|
|
336
|
+
} catch {
|
|
337
|
+
client = void 0;
|
|
338
|
+
}
|
|
339
|
+
if (client) {
|
|
340
|
+
try {
|
|
341
|
+
await client["daemon.shutdown"]({});
|
|
342
|
+
} catch (e) {
|
|
343
|
+
await client.close().catch(() => void 0);
|
|
344
|
+
return fail(ctx, {
|
|
345
|
+
what: `The daemon${named} did not accept the stop request`,
|
|
346
|
+
detail: [plainError(e)],
|
|
347
|
+
fix: `${pid === null ? "Stop the process that owns the daemon socket yourself" : `Stop pid ${pid} yourself`}, ${STOP_FIX(t)}.`,
|
|
348
|
+
exit: 1,
|
|
349
|
+
ref: "e_daemon_stop"
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
await client.close().catch(() => void 0);
|
|
353
|
+
if (!await waitFor(async () => !await reachable(ctx) && !await lockExists(ctx) && (pid === null || !ctx.isAlive(pid)), ctx.stopTimeoutMs)) return fail(ctx, {
|
|
354
|
+
what: `The daemon${named} is still running after ${Math.round(ctx.stopTimeoutMs / 1e3)}s`,
|
|
355
|
+
detail: ["It accepted the stop request, but its process, socket or lock file is still there."],
|
|
356
|
+
fix: `${pid === null ? "Stop the process that owns the daemon socket yourself" : `Stop pid ${pid} yourself`}, ${STOP_FIX(t)}.`,
|
|
357
|
+
exit: 1,
|
|
358
|
+
ref: "e_daemon_stop"
|
|
359
|
+
});
|
|
360
|
+
ctx.out(`${t.status("ok")} Stopped the daemon${named}.\n`);
|
|
361
|
+
return 0;
|
|
362
|
+
}
|
|
363
|
+
if (pid === null) {
|
|
364
|
+
ctx.out(`${t.status("info")} The daemon is not running. Nothing to stop.\n`);
|
|
365
|
+
return 0;
|
|
366
|
+
}
|
|
367
|
+
const stale = async () => {
|
|
368
|
+
await rm(lock, { force: true }).catch(() => void 0);
|
|
369
|
+
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`);
|
|
370
|
+
return 0;
|
|
371
|
+
};
|
|
372
|
+
if (!ctx.isAlive(pid)) return stale();
|
|
373
|
+
const commandLine = await ctx.commandLineOf(pid);
|
|
374
|
+
if (commandLine === null) return fail(ctx, {
|
|
375
|
+
what: `The daemon did not answer, and pid ${pid} could not be checked`,
|
|
376
|
+
detail: ["Conveno could not read that process's command line, so it cannot tell whether it is the daemon. It stopped nothing."],
|
|
377
|
+
fix: `If pid ${pid} is the Conveno daemon, end it yourself (Task Manager on Windows, \`kill ${pid}\` elsewhere), ${STOP_FIX(t)}.`,
|
|
378
|
+
exit: 1,
|
|
379
|
+
ref: "e_daemon_lock"
|
|
380
|
+
});
|
|
381
|
+
if (!isConvenoDaemonCommand(commandLine, ctx.daemonEntry)) return stale();
|
|
382
|
+
try {
|
|
383
|
+
ctx.kill(pid);
|
|
384
|
+
} catch (e) {
|
|
385
|
+
return fail(ctx, {
|
|
386
|
+
what: `Could not stop the daemon (pid ${pid})`,
|
|
387
|
+
detail: [plainError(e)],
|
|
388
|
+
fix: `Stop that process yourself, ${STOP_FIX(t)}.`,
|
|
389
|
+
exit: 1,
|
|
390
|
+
ref: "e_daemon_stop"
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
if (!await waitFor(() => !ctx.isAlive(pid), ctx.stopTimeoutMs)) return fail(ctx, {
|
|
394
|
+
what: `The daemon (pid ${pid}) is still running after ${Math.round(ctx.stopTimeoutMs / 1e3)}s`,
|
|
395
|
+
detail: ["It did not answer, was ended, and has not exited."],
|
|
396
|
+
fix: `Stop that process yourself, ${STOP_FIX(t)}.`,
|
|
397
|
+
exit: 1,
|
|
398
|
+
ref: "e_daemon_stop"
|
|
399
|
+
});
|
|
400
|
+
await rm(lock, { force: true }).catch(() => void 0);
|
|
401
|
+
ctx.out(`${t.status("ok")} Stopped the daemon (pid ${pid}). It was not answering, so it was ended directly.\n`);
|
|
402
|
+
return 0;
|
|
403
|
+
}
|
|
404
|
+
const SUBCOMMANDS = [
|
|
405
|
+
"start",
|
|
406
|
+
"stop",
|
|
407
|
+
"status"
|
|
408
|
+
];
|
|
409
|
+
async function runDaemon(ctx, argv) {
|
|
410
|
+
const t = ctx.theme;
|
|
411
|
+
const sub = argv[0];
|
|
412
|
+
if (sub === "start") {
|
|
413
|
+
try {
|
|
414
|
+
await (await ctx.connect(connectOpts(ctx, true))).close().catch(() => void 0);
|
|
415
|
+
} catch (e) {
|
|
416
|
+
const problem = daemonProblem(t, e);
|
|
417
|
+
return fail(ctx, {
|
|
418
|
+
what: "The Conveno daemon did not start",
|
|
419
|
+
detail: [problem.why],
|
|
420
|
+
fix: problem.notRunning ? `Run ${cmd(t, "conveno doctor")} to check the install, then try again.` : problem.fix,
|
|
421
|
+
exit: 1,
|
|
422
|
+
ref: "e_daemon_start"
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
const pid = await lockPid(ctx);
|
|
426
|
+
ctx.out(`${t.status("ok")} Daemon running${pid ? `, pid ${pid}` : ""}.\n`);
|
|
427
|
+
return 0;
|
|
428
|
+
}
|
|
429
|
+
if (sub === "status") {
|
|
430
|
+
const pid = await lockPid(ctx);
|
|
431
|
+
try {
|
|
432
|
+
await (await ctx.connect(connectOpts(ctx, false))).close().catch(() => void 0);
|
|
433
|
+
ctx.out(`${t.status("ok")} daemon running${pid ? `, pid ${pid}` : ""}\n`);
|
|
434
|
+
return 0;
|
|
435
|
+
} catch (e) {
|
|
436
|
+
const problem = daemonProblem(t, e);
|
|
437
|
+
if (problem.notRunning) ctx.out(`${t.glyph("offline")} daemon not running\n`);
|
|
438
|
+
else {
|
|
439
|
+
ctx.out(`${t.status("error")} daemon cannot be reached\n`);
|
|
440
|
+
ctx.err(warnBlock(t, "The Conveno daemon cannot be reached.", problem.fix, problem.why));
|
|
441
|
+
}
|
|
442
|
+
return 1;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (sub === "stop") return stopDaemon(ctx);
|
|
446
|
+
const suggestion = sub ? closest(sub, SUBCOMMANDS) : void 0;
|
|
447
|
+
return fail(ctx, {
|
|
448
|
+
what: sub ? `Unknown daemon command "${sub}"` : "conveno daemon needs a command",
|
|
449
|
+
fix: `Run ${cmd(t, "conveno daemon start")}, ${cmd(t, "conveno daemon stop")} or ${cmd(t, "conveno daemon status")}.`,
|
|
450
|
+
...suggestion ? { didYouMean: `Did you mean ${suggestion}?` } : {},
|
|
451
|
+
exit: 2,
|
|
452
|
+
ref: "e_usage"
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
// src/version.ts
|
|
456
|
+
const VERSION = "0.2.0-rc.4";
|
|
457
|
+
// src/errorLog.ts
|
|
458
|
+
/** The message of an unexpected error, as it is. Not the softened text `plainError` gives. */
|
|
459
|
+
function rawMessage(e) {
|
|
460
|
+
if (e instanceof Error) return `${e.name}: ${e.message}`;
|
|
461
|
+
return String(e);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Write the full stack of an unexpected error to `<data dir>/logs/<timestamp>-error.log`, readable
|
|
465
|
+
* by the user only. Returns the path, or undefined when the log could not be written (the error is
|
|
466
|
+
* still reported, just without a log).
|
|
467
|
+
*/
|
|
468
|
+
async function writeErrorLog(ctx, argv, e) {
|
|
469
|
+
try {
|
|
470
|
+
const dir = dataPaths(ctx.platform, ctx.dataDir).logs;
|
|
471
|
+
await mkdir(dir, {
|
|
472
|
+
recursive: true,
|
|
473
|
+
mode: 448
|
|
474
|
+
});
|
|
475
|
+
const stamp = ctx.now().toISOString().replace(/[:.]/g, "-");
|
|
476
|
+
const file = join(dir, `${stamp}-error.log`);
|
|
477
|
+
const command = argv.slice(0, 2).join(" ");
|
|
478
|
+
const text = [
|
|
479
|
+
`conveno ${VERSION} ${command}`,
|
|
480
|
+
"ref e_internal",
|
|
481
|
+
`time ${ctx.now().toISOString()}`,
|
|
482
|
+
`platform ${ctx.platform}, node ${process.version}`,
|
|
483
|
+
"",
|
|
484
|
+
e instanceof Error ? e.stack ?? rawMessage(e) : rawMessage(e),
|
|
485
|
+
e instanceof Error && e.cause !== void 0 ? `\nCaused by: ${e.cause instanceof Error ? e.cause.stack ?? rawMessage(e.cause) : String(e.cause)}` : "",
|
|
486
|
+
""
|
|
487
|
+
].join("\n");
|
|
488
|
+
await writeFile(file, text, { mode: 384 });
|
|
489
|
+
await chmod(file, 384).catch(() => void 0);
|
|
490
|
+
return file;
|
|
491
|
+
} catch {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
// src/forget.ts
|
|
496
|
+
const UNIT_MS = {
|
|
497
|
+
m: 6e4,
|
|
498
|
+
h: 36e5,
|
|
499
|
+
d: 864e5
|
|
500
|
+
};
|
|
501
|
+
/** `30m`, `24h` or `7d` as milliseconds, or undefined when the text is anything else. */
|
|
502
|
+
function parseDuration(text) {
|
|
503
|
+
const m = /^(\d{1,6})([mhd])$/.exec(text);
|
|
504
|
+
if (!m) return void 0;
|
|
505
|
+
const ms = Number(m[1]) * UNIT_MS[m[2]];
|
|
506
|
+
return ms > 0 ? ms : void 0;
|
|
507
|
+
}
|
|
508
|
+
/** Rebuild the command line the user typed, for the "run it again with --yes" hint. */
|
|
509
|
+
function rerunLine(names, flags) {
|
|
510
|
+
return [
|
|
511
|
+
"conveno forget",
|
|
512
|
+
...names.map((n) => n.includes("*") ? `'${n}'` : n),
|
|
513
|
+
...flags.offline ? ["--offline"] : [],
|
|
514
|
+
...flags.olderThan ? ["--older-than", flags.olderThan] : []
|
|
515
|
+
].join(" ");
|
|
516
|
+
}
|
|
517
|
+
async function runForget(ctx, argv) {
|
|
518
|
+
const t = ctx.theme;
|
|
519
|
+
const spec = COMMANDS.find((c) => c.name === "forget");
|
|
520
|
+
if (!spec) return 2;
|
|
521
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
522
|
+
if (typeof parsed === "number") return parsed;
|
|
523
|
+
const names = parsed.positionals;
|
|
524
|
+
const offline = parsed.values.offline === true;
|
|
525
|
+
const olderThan = typeof parsed.values["older-than"] === "string" ? parsed.values["older-than"] : void 0;
|
|
526
|
+
const dryRun = parsed.values["dry-run"] === true;
|
|
527
|
+
const yes = parsed.values.yes === true;
|
|
528
|
+
const help = `Run ${cmd(t, "conveno forget --help")} to see the options.`;
|
|
529
|
+
for (const n of names) if (!SessionNamePattern.safeParse(n).success) return fail(ctx, {
|
|
530
|
+
what: `"${n}" is not a session name or pattern`,
|
|
531
|
+
detail: ["Names use lowercase letters, digits and \".\", \"_\", \"@\" or \"-\". A \"*\" matches any run of characters."],
|
|
532
|
+
fix: `Run ${cmd(t, "conveno status --all")} to see the names.`,
|
|
533
|
+
exit: 2,
|
|
534
|
+
ref: "e_usage"
|
|
535
|
+
});
|
|
536
|
+
let olderThanMs;
|
|
537
|
+
if (olderThan !== void 0) {
|
|
538
|
+
olderThanMs = parseDuration(olderThan);
|
|
539
|
+
if (olderThanMs === void 0) return fail(ctx, {
|
|
540
|
+
what: `"${olderThan}" is not a duration`,
|
|
541
|
+
detail: ["Use a whole number and a unit: 30m for minutes, 24h for hours, 7d for days."],
|
|
542
|
+
fix: help,
|
|
543
|
+
exit: 2,
|
|
544
|
+
ref: "e_usage"
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
if (names.length === 0 && !offline && olderThanMs === void 0) return fail(ctx, {
|
|
548
|
+
what: "conveno forget needs to know which sessions to forget",
|
|
549
|
+
detail: ["Name them, or pass --offline for every offline session."],
|
|
550
|
+
fix: `For example ${cmd(t, "conveno forget 'conveno-real-*'")} or ${cmd(t, "conveno forget --offline --older-than 7d")}.`,
|
|
551
|
+
exit: 2,
|
|
552
|
+
ref: "e_usage"
|
|
553
|
+
});
|
|
554
|
+
let client;
|
|
555
|
+
try {
|
|
556
|
+
client = await ctx.connect(connectOpts(ctx, false));
|
|
557
|
+
} catch (e) {
|
|
558
|
+
const problem = daemonProblem(t, e);
|
|
559
|
+
return fail(ctx, {
|
|
560
|
+
what: problem.notRunning ? "The Conveno daemon is not running" : "The Conveno daemon cannot be reached",
|
|
561
|
+
detail: [problem.notRunning ? "Sessions live in the daemon, so there is nothing to forget until it runs." : problem.why],
|
|
562
|
+
fix: problem.notRunning ? `Run ${cmd(t, "conveno daemon start")}.` : problem.fix,
|
|
563
|
+
exit: 1,
|
|
564
|
+
ref: "e_daemon"
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
try {
|
|
568
|
+
const selector = {
|
|
569
|
+
...names.length > 0 ? { names } : {},
|
|
570
|
+
...names.length === 0 || olderThanMs !== void 0 ? { olderThanMs: olderThanMs ?? 0 } : {}
|
|
571
|
+
};
|
|
572
|
+
const preview = await client["session.forget"]({
|
|
573
|
+
...selector,
|
|
574
|
+
dryRun: true
|
|
575
|
+
});
|
|
576
|
+
const ids = new Set(preview.forgotten.map((s) => s.id));
|
|
577
|
+
const picked = (await client["session.list"]({ includeOffline: true })).sessions.filter((s) => ids.has(s.id));
|
|
578
|
+
if (preview.skippedOnline.length > 0) {
|
|
579
|
+
ctx.out(`${t.status("warn")} ${t.bold(`Skipped ${plural(preview.skippedOnline.length, "online session")}`)}\n`);
|
|
580
|
+
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`);
|
|
581
|
+
}
|
|
582
|
+
if (picked.length === 0) {
|
|
583
|
+
ctx.out(`${t.status("info")} Nothing to forget. ${t.paint("quiet", `${cmd(t, "conveno status --all")} lists the offline sessions.`)}\n`);
|
|
584
|
+
return 0;
|
|
585
|
+
}
|
|
586
|
+
ctx.out(`${t.bold(dryRun ? `Would forget ${plural(picked.length, "session")}` : `Will forget ${plural(picked.length, "session")}`)}\n\n`);
|
|
587
|
+
ctx.out(`${renderSessions(ctx, picked)}\n\n`);
|
|
588
|
+
ctx.out(` ${t.paint("quiet", "Their queued messages are deleted too. Messages they sent stay with the receivers.")}\n\n`);
|
|
589
|
+
if (dryRun) {
|
|
590
|
+
ctx.out(`${t.status("info")} Dry run. Nothing was changed.\n`);
|
|
591
|
+
return 0;
|
|
592
|
+
}
|
|
593
|
+
if (!yes) {
|
|
594
|
+
if (!ctx.interactive) return fail(ctx, {
|
|
595
|
+
what: "Needs a terminal to confirm",
|
|
596
|
+
detail: ["No sessions were forgotten."],
|
|
597
|
+
fix: `Run ${cmd(t, `${rerunLine(names, {
|
|
598
|
+
offline,
|
|
599
|
+
...olderThan ? { olderThan } : {}
|
|
600
|
+
})} --yes`)} to forget the sessions listed above.`,
|
|
601
|
+
exit: 2,
|
|
602
|
+
ref: "e_no_tty"
|
|
603
|
+
});
|
|
604
|
+
if (!await ctx.confirm(`Forget ${plural(picked.length, "session")}?`, false)) {
|
|
605
|
+
ctx.out(`${t.status("info")} Nothing was changed.\n`);
|
|
606
|
+
return 0;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
const done = await client["session.forget"]({ ids: [...ids] });
|
|
610
|
+
ctx.out(`${t.status("ok")} ${t.bold("Done.")} Forgot ${plural(done.forgotten.length, "session")}.\n`);
|
|
611
|
+
return 0;
|
|
612
|
+
} finally {
|
|
613
|
+
await client.close().catch(() => void 0);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
// src/peek.ts
|
|
617
|
+
async function connectOrFail(ctx) {
|
|
618
|
+
const t = ctx.theme;
|
|
619
|
+
try {
|
|
620
|
+
return await ctx.connect(connectOpts(ctx, false));
|
|
621
|
+
} catch (e) {
|
|
622
|
+
const problem = daemonProblem(t, e);
|
|
623
|
+
return fail(ctx, {
|
|
624
|
+
what: problem.notRunning ? "The Conveno daemon is not running" : "The Conveno daemon cannot be reached",
|
|
625
|
+
detail: [problem.notRunning ? "Sessions live in the daemon, so there is nothing to peek at until it runs." : problem.why],
|
|
626
|
+
fix: problem.notRunning ? `Run ${cmd(t, "conveno daemon start")}.` : problem.fix,
|
|
627
|
+
exit: 1,
|
|
628
|
+
ref: "e_daemon"
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
const isSessionRef = (s) => SessionId.safeParse(s).success || SessionNameInput.safeParse(s).success;
|
|
633
|
+
function badSession(ctx, name) {
|
|
634
|
+
return fail(ctx, {
|
|
635
|
+
what: `"${name}" is not a session name`,
|
|
636
|
+
detail: ["Names use lowercase letters, digits and \".\", \"_\", \"@\" or \"-\"."],
|
|
637
|
+
fix: `Run ${cmd(ctx.theme, "conveno status")} to see the names.`,
|
|
638
|
+
exit: 2,
|
|
639
|
+
ref: "e_usage"
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
/** `conveno peek on|off [session]`: the owner's switch. */
|
|
643
|
+
async function runSwitch(ctx, peekable, session) {
|
|
644
|
+
const t = ctx.theme;
|
|
645
|
+
if (session !== void 0 && !isSessionRef(session)) return badSession(ctx, session);
|
|
646
|
+
const client = await connectOrFail(ctx);
|
|
647
|
+
if (typeof client === "number") return client;
|
|
648
|
+
try {
|
|
649
|
+
const res = await client["session.setPeekable"]({
|
|
650
|
+
peekable,
|
|
651
|
+
...session !== void 0 ? { session } : {}
|
|
652
|
+
});
|
|
653
|
+
if (res.sessions.length === 0) {
|
|
654
|
+
ctx.out(`${t.status("info")} No online sessions, so nothing changed.\n`);
|
|
655
|
+
return 0;
|
|
656
|
+
}
|
|
657
|
+
const names = res.sessions.map((s) => s.name).join(", ");
|
|
658
|
+
ctx.out(`${t.status("ok")} Peek is ${t.bold(peekable ? "on" : "off")} for ${plural(res.sessions.length, "session")}: ${names}\n`);
|
|
659
|
+
if (session === void 0) ctx.out(` ${t.paint("quiet", "Sessions that start later are peekable by default. Run it again after they start.")}\n`);
|
|
660
|
+
return 0;
|
|
661
|
+
} catch (e) {
|
|
662
|
+
return daemonFailure(ctx, e);
|
|
663
|
+
} finally {
|
|
664
|
+
await client.close().catch(() => void 0);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
function daemonFailure(ctx, e) {
|
|
668
|
+
const t = ctx.theme;
|
|
669
|
+
if (e instanceof ConvenoError) {
|
|
670
|
+
const permission = e.code === RpcErrorCode.PermissionRequired;
|
|
671
|
+
return fail(ctx, {
|
|
672
|
+
what: permission ? "Peek is turned off for that session" : e.message,
|
|
673
|
+
...permission ? { detail: [e.message] } : {},
|
|
674
|
+
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.`,
|
|
675
|
+
exit: 1,
|
|
676
|
+
ref: permission ? "e_peek_off" : "e_peek"
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
const problem = daemonProblem(t, e);
|
|
680
|
+
return fail(ctx, {
|
|
681
|
+
what: "The Conveno daemon could not answer",
|
|
682
|
+
detail: [problem.why],
|
|
683
|
+
fix: problem.fix,
|
|
684
|
+
exit: 1,
|
|
685
|
+
ref: "e_daemon"
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
/** `conveno peek <session> [-n N] [--raw-json]`: what another session did lately, secrets redacted. */
|
|
689
|
+
async function runPeek(ctx, argv) {
|
|
690
|
+
const t = ctx.theme;
|
|
691
|
+
const spec = COMMANDS.find((c) => c.name === "peek");
|
|
692
|
+
if (!spec) return 2;
|
|
693
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
694
|
+
if (typeof parsed === "number") return parsed;
|
|
695
|
+
const [first, second] = parsed.positionals;
|
|
696
|
+
if (first === void 0) return fail(ctx, {
|
|
697
|
+
what: "conveno peek needs a session",
|
|
698
|
+
detail: ["Name the session to read, or use on or off to switch peek for your sessions."],
|
|
699
|
+
fix: `For example ${cmd(t, "conveno peek claude@api-1")} or ${cmd(t, "conveno peek off")}.`,
|
|
700
|
+
exit: 2,
|
|
701
|
+
ref: "e_usage"
|
|
702
|
+
});
|
|
703
|
+
if (first === "on" || first === "off") return runSwitch(ctx, first === "on", second);
|
|
704
|
+
if (!isSessionRef(first)) return badSession(ctx, first);
|
|
705
|
+
const nText = typeof parsed.values.n === "string" ? parsed.values.n : void 0;
|
|
706
|
+
const n = nText === void 0 ? 10 : Number(nText);
|
|
707
|
+
if (!Number.isInteger(n) || n < 1 || n > 50) return fail(ctx, {
|
|
708
|
+
what: `"${nText}" is not a number of turns`,
|
|
709
|
+
detail: [`Use a whole number from 1 to 50.`],
|
|
710
|
+
fix: `For example ${cmd(t, `conveno peek ${first} -n 20`)}.`,
|
|
711
|
+
exit: 2,
|
|
712
|
+
ref: "e_usage"
|
|
713
|
+
});
|
|
714
|
+
const client = await connectOrFail(ctx);
|
|
715
|
+
if (typeof client === "number") return client;
|
|
716
|
+
try {
|
|
717
|
+
const res = await client["session.peek"]({
|
|
718
|
+
target: first,
|
|
719
|
+
lastTurns: n
|
|
720
|
+
});
|
|
721
|
+
if (parsed.values["raw-json"] === true) {
|
|
722
|
+
ctx.out(`${JSON.stringify(res, null, 2)}\n`);
|
|
723
|
+
return 0;
|
|
724
|
+
}
|
|
725
|
+
ctx.out(`${t.bold(res.session.name)} ${t.paint("quiet", `${res.session.cli}, last ${plural(res.turns.length, "turn")}, secrets redacted (best effort)`)}\n`);
|
|
726
|
+
if (res.turns.length === 0) ctx.out(`\n${t.paint("quiet", "The transcript has no turns yet.")}\n`);
|
|
727
|
+
for (const turn of res.turns) {
|
|
728
|
+
const stamp = turn.at ? ` ${t.paint("quiet", localStamp(turn.at))}` : "";
|
|
729
|
+
ctx.out(`\n${t.bold(turn.role)}${stamp}\n${turn.text.replace(/\n/g, "\n ").replace(/^/, " ")}\n`);
|
|
730
|
+
}
|
|
731
|
+
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`);
|
|
732
|
+
return 0;
|
|
733
|
+
} catch (e) {
|
|
734
|
+
return daemonFailure(ctx, e);
|
|
735
|
+
} finally {
|
|
736
|
+
await client.close().catch(() => void 0);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
// src/tickets.ts
|
|
740
|
+
/** Connect to a running daemon, or print why not. */
|
|
741
|
+
async function connectRunning(ctx, why) {
|
|
742
|
+
const t = ctx.theme;
|
|
743
|
+
try {
|
|
744
|
+
return await ctx.connect(connectOpts(ctx, false));
|
|
745
|
+
} catch (e) {
|
|
746
|
+
const problem = daemonProblem(t, e);
|
|
747
|
+
return { exit: fail(ctx, {
|
|
748
|
+
what: problem.notRunning ? "The Conveno daemon is not running" : "The Conveno daemon cannot be reached",
|
|
749
|
+
detail: [problem.notRunning ? why : problem.why],
|
|
750
|
+
fix: problem.notRunning ? `Run ${cmd(t, "conveno daemon start")}.` : problem.fix,
|
|
751
|
+
exit: 1,
|
|
752
|
+
ref: "e_daemon"
|
|
753
|
+
}) };
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
const oneLine = (text, max) => {
|
|
757
|
+
const flat = sanitizeLine(text);
|
|
758
|
+
return flat.length > max ? `${flat.slice(0, max - 3)}...` : flat;
|
|
759
|
+
};
|
|
760
|
+
/** The first line of a ticket, which for a permission request is its title line. */
|
|
761
|
+
const headline = (t) => oneLine(t.question.split("\n")[0] ?? "", 70);
|
|
762
|
+
async function runTickets(ctx, argv) {
|
|
763
|
+
const t = ctx.theme;
|
|
764
|
+
const spec = COMMANDS.find((c) => c.name === "tickets");
|
|
765
|
+
if (!spec) return 2;
|
|
766
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
767
|
+
if (typeof parsed === "number") return parsed;
|
|
768
|
+
const openOnly = parsed.values.open === true;
|
|
769
|
+
const client = await connectRunning(ctx, "Tickets live in the daemon, so there are none to list.");
|
|
770
|
+
if ("exit" in client) return client.exit;
|
|
771
|
+
try {
|
|
772
|
+
const res = await client["ticket.list"]({
|
|
773
|
+
...openOnly ? { status: "open" } : {},
|
|
774
|
+
limit: 200
|
|
775
|
+
});
|
|
776
|
+
const names = new Map((await client["session.list"]({ includeOffline: true })).sessions.map((s) => [s.id, s.name]));
|
|
777
|
+
const who = (id) => names.get(id) ?? id.slice(-6);
|
|
778
|
+
if (res.tickets.length === 0) {
|
|
779
|
+
ctx.out(`${t.status("info")} ${openOnly ? "No open tickets." : "No tickets yet."} ${t.paint("quiet", "Workers raise them with the ask tool.")}\n`);
|
|
780
|
+
return 0;
|
|
781
|
+
}
|
|
782
|
+
const q = (w) => t.paint("quiet", w);
|
|
783
|
+
const rows = [[
|
|
784
|
+
` ${q("TICKET")}`,
|
|
785
|
+
q("STATE"),
|
|
786
|
+
q("FROM"),
|
|
787
|
+
q("TO"),
|
|
788
|
+
q("WHEN"),
|
|
789
|
+
q("QUESTION")
|
|
790
|
+
], ...res.tickets.map((k) => [
|
|
791
|
+
` ${t.bold(k.id)}`,
|
|
792
|
+
k.status === "open" ? t.paint("entry", "open") : q(k.status),
|
|
793
|
+
who(k.fromSession),
|
|
794
|
+
who(k.toSession),
|
|
795
|
+
q(stamp(k.createdAt, ctx.now())),
|
|
796
|
+
`${k.kind === "permission" ? `${t.paint("warn", "permission")} ` : ""}${headline(k)}`
|
|
797
|
+
])];
|
|
798
|
+
ctx.out(`${columns(rows).join("\n")}\n\n`);
|
|
799
|
+
const hint = res.openCount > 0 ? ` Answer with ${cmd(t, "conveno answer <ticket> <text>")}.` : "";
|
|
800
|
+
ctx.out(`${plural(res.openCount, "open ticket")}.${hint}\n`);
|
|
801
|
+
return 0;
|
|
802
|
+
} finally {
|
|
803
|
+
await client.close().catch(() => void 0);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
/** A full ticket id, or the one open ticket that ends or starts with `text` (at least 6 characters). */
|
|
807
|
+
function pickTicket(tickets, text) {
|
|
808
|
+
if (TicketId.safeParse(text).success) return tickets.find((k) => k.id === text) ?? `No ticket ${text}.`;
|
|
809
|
+
if (text.length < 6) return `"${text}" is too short to name a ticket. Use at least 6 characters.`;
|
|
810
|
+
const wanted = text.toUpperCase();
|
|
811
|
+
const hits = tickets.filter((k) => k.id.startsWith(wanted) || k.id.endsWith(wanted));
|
|
812
|
+
if (hits.length === 1 && hits[0]) return hits[0];
|
|
813
|
+
return hits.length === 0 ? `No ticket matches "${text}".` : `"${text}" matches ${hits.length} tickets.`;
|
|
814
|
+
}
|
|
815
|
+
async function runAnswer(ctx, argv) {
|
|
816
|
+
const t = ctx.theme;
|
|
817
|
+
const spec = COMMANDS.find((c) => c.name === "answer");
|
|
818
|
+
if (!spec) return 2;
|
|
819
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
820
|
+
if (typeof parsed === "number") return parsed;
|
|
821
|
+
const [id, ...words] = parsed.positionals;
|
|
822
|
+
const response = words.join(" ").trim();
|
|
823
|
+
if (!id || response === "") return fail(ctx, {
|
|
824
|
+
what: "conveno answer needs a ticket and an answer",
|
|
825
|
+
fix: `For example ${cmd(t, "conveno answer 01J8ABCD \"Use sqlite\"")}. ${cmd(t, "conveno tickets --open")} lists the open tickets.`,
|
|
826
|
+
exit: 2,
|
|
827
|
+
ref: "e_usage"
|
|
828
|
+
});
|
|
829
|
+
const client = await connectRunning(ctx, "Tickets live in the daemon, so there is nothing to answer.");
|
|
830
|
+
if ("exit" in client) return client.exit;
|
|
831
|
+
try {
|
|
832
|
+
const { tickets } = await client["ticket.list"]({ limit: 200 });
|
|
833
|
+
const picked = pickTicket(tickets, id);
|
|
834
|
+
if (typeof picked === "string") return fail(ctx, {
|
|
835
|
+
what: picked,
|
|
836
|
+
fix: `Run ${cmd(t, "conveno tickets --open")} to see the open tickets.`,
|
|
837
|
+
exit: 1,
|
|
838
|
+
ref: "e_ticket"
|
|
839
|
+
});
|
|
840
|
+
const res = await client["ticket.answer"]({
|
|
841
|
+
ticketId: picked.id,
|
|
842
|
+
response
|
|
843
|
+
});
|
|
844
|
+
const who = res.ticket.kind === "permission" ? "The worker's CLI" : "The asker";
|
|
845
|
+
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`);
|
|
846
|
+
return 0;
|
|
847
|
+
} catch (e) {
|
|
848
|
+
return fail(ctx, {
|
|
849
|
+
what: "The ticket could not be answered",
|
|
850
|
+
detail: [e instanceof Error ? e.message : String(e)],
|
|
851
|
+
fix: `Run ${cmd(t, "conveno tickets")} to see its state.`,
|
|
852
|
+
exit: 1,
|
|
853
|
+
ref: "e_ticket"
|
|
854
|
+
});
|
|
855
|
+
} finally {
|
|
856
|
+
await client.close().catch(() => void 0);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
// src/permissions.ts
|
|
860
|
+
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.";
|
|
861
|
+
/**
|
|
862
|
+
* The relay needs the CLI's PermissionRequest hook. Add it the first time, with the same diff,
|
|
863
|
+
* backup and manifest as `conveno init` (so `conveno uninstall` removes it). Returns an exit code
|
|
864
|
+
* to stop with, or undefined to go on.
|
|
865
|
+
*/
|
|
866
|
+
async function ensureHooks(ctx, targets, named, yes) {
|
|
867
|
+
const t = ctx.theme;
|
|
868
|
+
const items = [];
|
|
869
|
+
const driven = targets.find((s) => !s.spawned);
|
|
870
|
+
if (driven) return fail(ctx, {
|
|
871
|
+
what: `The relay could not be turned on for ${driven.name}`,
|
|
872
|
+
detail: [`${driven.name} was not started by Conveno, so a person is driving it. The relay is only for sessions started with conveno spawn or spawn_session.`],
|
|
873
|
+
fix: `Start a worker with ${cmd(t, "conveno spawn <cli>")}.`,
|
|
874
|
+
exit: 1,
|
|
875
|
+
ref: "e_relay"
|
|
876
|
+
});
|
|
877
|
+
for (const cli of new Set(targets.map((s) => s.cli))) {
|
|
878
|
+
const adapter = ctx.adapters.find((a) => a.cli === cli);
|
|
879
|
+
if (!adapter?.permissionHookInstalled) return fail(ctx, {
|
|
880
|
+
what: `The permission relay does not support ${cli}`,
|
|
881
|
+
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."],
|
|
882
|
+
fix: `Use the relay with a Claude Code or Codex worker.`,
|
|
883
|
+
exit: 1,
|
|
884
|
+
ref: "e_relay_cli"
|
|
885
|
+
});
|
|
886
|
+
try {
|
|
887
|
+
if (await adapter.permissionHookInstalled(adapterEnv(ctx))) continue;
|
|
888
|
+
const changes = await adapter.plan(adapterEnv(ctx, { permissionRelay: true }));
|
|
889
|
+
for (const change of changes.filter((c) => c.component === "hooks")) items.push({
|
|
890
|
+
cli: adapter.cli,
|
|
891
|
+
installed: true,
|
|
892
|
+
change
|
|
893
|
+
});
|
|
894
|
+
} catch (e) {
|
|
895
|
+
return fail(ctx, {
|
|
896
|
+
what: `Could not plan the ${adapter.displayName} permission hook`,
|
|
897
|
+
detail: [plainError(e)],
|
|
898
|
+
fix: "Fix the problem above, then run the command again.",
|
|
899
|
+
exit: 1,
|
|
900
|
+
ref: "e_plan"
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
if (items.length === 0) return void 0;
|
|
905
|
+
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`);
|
|
906
|
+
const result = await confirmAndApply(ctx, items, {
|
|
907
|
+
yes,
|
|
908
|
+
verb: "Apply",
|
|
909
|
+
rerun: `conveno permissions relay on${named ? ` ${named}` : ""}`
|
|
910
|
+
});
|
|
911
|
+
if ("exit" in result) return result.exit === 0 ? 0 : result.exit;
|
|
912
|
+
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`);
|
|
913
|
+
}
|
|
914
|
+
async function runPermissions(ctx, argv) {
|
|
915
|
+
const t = ctx.theme;
|
|
916
|
+
const spec = COMMANDS.find((c) => c.name === "permissions");
|
|
917
|
+
if (!spec) return 2;
|
|
918
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
919
|
+
if (typeof parsed === "number") return parsed;
|
|
920
|
+
const [sub, state, name, ...extra] = parsed.positionals;
|
|
921
|
+
const usage = `Run ${cmd(t, "conveno permissions relay on <session>")} or ${cmd(t, "conveno permissions relay off [session]")}.`;
|
|
922
|
+
if (sub !== void 0 && (sub !== "relay" || state !== "on" && state !== "off" || extra.length > 0)) return fail(ctx, {
|
|
923
|
+
what: `"${parsed.positionals.join(" ")}" is not a permissions command`,
|
|
924
|
+
fix: usage,
|
|
925
|
+
exit: 2,
|
|
926
|
+
ref: "e_usage"
|
|
927
|
+
});
|
|
928
|
+
const client = await connectRunning(ctx, "The permission relay lives in the daemon.");
|
|
929
|
+
if ("exit" in client) return client.exit;
|
|
930
|
+
try {
|
|
931
|
+
const sessions = (await client["session.list"]({ includeOffline: true })).sessions;
|
|
932
|
+
const nameOf = (id) => sessions.find((s) => s.id === id)?.name ?? id.slice(-6);
|
|
933
|
+
if (sub === void 0) {
|
|
934
|
+
const { relays } = await client["permission.relay"]({});
|
|
935
|
+
ctx.out(`${t.status("warn")} ${t.paint("quiet", "Permission relay is EXPERIMENTAL and off unless listed.")}\n`);
|
|
936
|
+
if (relays.length === 0) ctx.out(`${t.status("info")} The relay is off for every session.\n`);
|
|
937
|
+
else {
|
|
938
|
+
const rows = relays.map((r) => `${nameOf(r.session)} (approved by ${nameOf(r.approver)})`);
|
|
939
|
+
ctx.out(`${t.bold("Relay on for:")} ${rows.join(", ")}\n`);
|
|
940
|
+
}
|
|
941
|
+
ctx.out(` ${t.paint("quiet", `Turn it on with ${cmd(t, "conveno permissions relay on <session>")}. SECURITY.md has the threat model.`)}\n`);
|
|
942
|
+
return 0;
|
|
943
|
+
}
|
|
944
|
+
const enable = state === "on";
|
|
945
|
+
let targets;
|
|
946
|
+
if (name !== void 0) {
|
|
947
|
+
const found = sessions.find((s) => s.name === name && s.status !== "offline");
|
|
948
|
+
if (!found) return fail(ctx, {
|
|
949
|
+
what: `No online session named "${name}"`,
|
|
950
|
+
fix: `Run ${cmd(t, "conveno status")} to see the names.`,
|
|
951
|
+
exit: 1,
|
|
952
|
+
ref: "e_no_session"
|
|
953
|
+
});
|
|
954
|
+
targets = [found];
|
|
955
|
+
} else if (enable) {
|
|
956
|
+
targets = sessions.filter((s) => s.spawned && s.status !== "offline");
|
|
957
|
+
if (targets.length !== 1) return fail(ctx, {
|
|
958
|
+
what: targets.length === 0 ? "No session started by Conveno is online" : "More than one spawned session is online",
|
|
959
|
+
detail: ["The relay is only for sessions started with conveno spawn or spawn_session, never for one you drive yourself."],
|
|
960
|
+
fix: `Name the session: ${cmd(t, "conveno permissions relay on <session>")}.`,
|
|
961
|
+
exit: 2,
|
|
962
|
+
ref: "e_usage"
|
|
963
|
+
});
|
|
964
|
+
} else {
|
|
965
|
+
const { relays } = await client["permission.relay"]({});
|
|
966
|
+
targets = sessions.filter((s) => relays.some((r) => r.session === s.id));
|
|
967
|
+
if (targets.length === 0) {
|
|
968
|
+
ctx.out(`${t.status("info")} The relay was already off for every session.\n`);
|
|
969
|
+
return 0;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
if (enable) {
|
|
973
|
+
const code = await ensureHooks(ctx, targets, name, parsed.values.yes === true);
|
|
974
|
+
if (code !== void 0) return code;
|
|
975
|
+
}
|
|
976
|
+
for (const target of targets) {
|
|
977
|
+
let approver;
|
|
978
|
+
try {
|
|
979
|
+
approver = (await client["permission.relay"]({
|
|
980
|
+
target: target.id,
|
|
981
|
+
enabled: enable
|
|
982
|
+
})).relays.find((r) => r.session === target.id)?.approver;
|
|
983
|
+
} catch (e) {
|
|
984
|
+
return fail(ctx, {
|
|
985
|
+
what: `The relay could not be turned ${state} for ${target.name}`,
|
|
986
|
+
detail: [e instanceof Error ? e.message : String(e)],
|
|
987
|
+
fix: usage,
|
|
988
|
+
exit: 1,
|
|
989
|
+
ref: "e_relay"
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
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`);
|
|
993
|
+
}
|
|
994
|
+
if (enable) ctx.out(` ${RELAY_WARNING}\n`);
|
|
995
|
+
return 0;
|
|
996
|
+
} finally {
|
|
997
|
+
await client.close().catch(() => void 0);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
// src/spawn.ts
|
|
1001
|
+
/** Read the task from `--task-file`. Returns the text or the failure's exit code. */
|
|
1002
|
+
function readTaskFile(ctx, path) {
|
|
1003
|
+
try {
|
|
1004
|
+
return readFileSync(resolve(ctx.cwd, path), "utf8");
|
|
1005
|
+
} catch (e) {
|
|
1006
|
+
const code = e.code;
|
|
1007
|
+
return fail(ctx, {
|
|
1008
|
+
what: `Cannot read the task file ${path}`,
|
|
1009
|
+
detail: [code === "ENOENT" ? "The file does not exist." : `The system said ${code ?? "no"}.`],
|
|
1010
|
+
fix: "Check the path, or pass the task with --task.",
|
|
1011
|
+
exit: 2,
|
|
1012
|
+
ref: "e_usage"
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* `conveno spawn <cli> ...`: start a worker session of any CLI with a first task, and print the
|
|
1018
|
+
* name it registers under.
|
|
1019
|
+
*/
|
|
1020
|
+
async function runSpawn(ctx, argv) {
|
|
1021
|
+
const t = ctx.theme;
|
|
1022
|
+
const spec = COMMANDS.find((c) => c.name === "spawn");
|
|
1023
|
+
if (!spec) return 2;
|
|
1024
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
1025
|
+
if (typeof parsed === "number") return parsed;
|
|
1026
|
+
const help = `Run ${cmd(t, "conveno spawn --help")} to see the options.`;
|
|
1027
|
+
const [cli, ...extra] = parsed.positionals;
|
|
1028
|
+
if (!cli || extra.length > 0) return fail(ctx, {
|
|
1029
|
+
what: "conveno spawn needs exactly one CLI name",
|
|
1030
|
+
detail: [`Known: ${SPAWN_CLIS.join(", ")}.`],
|
|
1031
|
+
fix: `Run ${cmd(t, "conveno spawn claude --task 'review the open PR'")}.`,
|
|
1032
|
+
exit: 2,
|
|
1033
|
+
ref: "e_usage"
|
|
1034
|
+
});
|
|
1035
|
+
if (!Object.hasOwn(SPAWN_TABLE, cli)) return fail(ctx, {
|
|
1036
|
+
what: `"${cli}" is not a CLI Conveno can start`,
|
|
1037
|
+
detail: [`Known: ${SPAWN_CLIS.join(", ")}.`],
|
|
1038
|
+
fix: help,
|
|
1039
|
+
exit: 2,
|
|
1040
|
+
ref: "e_usage"
|
|
1041
|
+
});
|
|
1042
|
+
const str = (k) => typeof parsed.values[k] === "string" ? parsed.values[k] : void 0;
|
|
1043
|
+
if (str("task") !== void 0 && str("task-file") !== void 0) return fail(ctx, {
|
|
1044
|
+
what: "Use --task or --task-file, not both",
|
|
1045
|
+
fix: help,
|
|
1046
|
+
exit: 2,
|
|
1047
|
+
ref: "e_usage"
|
|
1048
|
+
});
|
|
1049
|
+
let task = str("task");
|
|
1050
|
+
const taskFile = str("task-file");
|
|
1051
|
+
if (taskFile !== void 0) {
|
|
1052
|
+
const text = readTaskFile(ctx, taskFile);
|
|
1053
|
+
if (typeof text === "number") return text;
|
|
1054
|
+
task = text;
|
|
1055
|
+
}
|
|
1056
|
+
const acpFlag = parsed.values.acp === true;
|
|
1057
|
+
const oneShot = parsed.values["one-shot"] === true;
|
|
1058
|
+
if (acpFlag && oneShot) return fail(ctx, {
|
|
1059
|
+
what: "Use --acp or --one-shot, not both",
|
|
1060
|
+
fix: help,
|
|
1061
|
+
exit: 2,
|
|
1062
|
+
ref: "e_usage"
|
|
1063
|
+
});
|
|
1064
|
+
const headless = parsed.values.headless === true || acpFlag || oneShot;
|
|
1065
|
+
const acp = acpFlag ? "require" : headless && !oneShot ? "prefer" : void 0;
|
|
1066
|
+
const allowFlag = str("allow");
|
|
1067
|
+
const allow = allowFlag === void 0 ? void 0 : [allowFlag];
|
|
1068
|
+
const yes = parsed.values.yes === true;
|
|
1069
|
+
const adapter = ctx.adapters.find((a) => a.cli === cli);
|
|
1070
|
+
if (adapter && !(await adapter.detect(adapterEnv(ctx))).installed) return fail(ctx, {
|
|
1071
|
+
what: `${adapter.displayName} is not installed`,
|
|
1072
|
+
detail: [`conveno could not run ${cli} --version.`],
|
|
1073
|
+
fix: "Install it, or check that its folder is on PATH.",
|
|
1074
|
+
exit: 1,
|
|
1075
|
+
ref: "e_spawn"
|
|
1076
|
+
});
|
|
1077
|
+
if (!yes) {
|
|
1078
|
+
if (!ctx.interactive) return fail(ctx, {
|
|
1079
|
+
what: "Needs a terminal to confirm",
|
|
1080
|
+
detail: ["Nothing was started."],
|
|
1081
|
+
fix: `Run the same command with ${cmd(t, "--yes")} to start the session without asking.`,
|
|
1082
|
+
exit: 2,
|
|
1083
|
+
ref: "e_no_tty"
|
|
1084
|
+
});
|
|
1085
|
+
const question = `Start ${cli} in ${tilde(resolve(ctx.cwd, str("cwd") ?? "."), ctx.home)}${headless ? " in the background" : ""}${task ? " with a first task" : ""}?`;
|
|
1086
|
+
if (!await ctx.confirm(question, true)) {
|
|
1087
|
+
ctx.out(`${t.status("info")} Nothing was started.\n`);
|
|
1088
|
+
return 0;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
let client;
|
|
1092
|
+
try {
|
|
1093
|
+
client = await ctx.connect(connectOpts(ctx, true));
|
|
1094
|
+
} catch (e) {
|
|
1095
|
+
const problem = daemonProblem(t, e);
|
|
1096
|
+
return fail(ctx, {
|
|
1097
|
+
what: "The Conveno daemon cannot be reached",
|
|
1098
|
+
detail: [problem.why],
|
|
1099
|
+
fix: problem.fix,
|
|
1100
|
+
exit: 1,
|
|
1101
|
+
ref: "e_daemon"
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
try {
|
|
1105
|
+
const { hostPid } = await ctx.ancestry(2e3);
|
|
1106
|
+
const requester = hostPid === void 0 ? void 0 : (await client["session.byHost"]({ pid: hostPid }).catch(() => void 0))?.session ?? void 0;
|
|
1107
|
+
const runner = ctx.spawnRunner ?? [process.execPath, process.argv[1] ?? "conveno"];
|
|
1108
|
+
const deps = realSpawnDeps({
|
|
1109
|
+
platform: ctx.platform,
|
|
1110
|
+
env: ctx.env,
|
|
1111
|
+
home: ctx.home,
|
|
1112
|
+
dataDir: ctx.dataDir,
|
|
1113
|
+
client,
|
|
1114
|
+
runner
|
|
1115
|
+
});
|
|
1116
|
+
const res = await spawnSession(deps, {
|
|
1117
|
+
cli,
|
|
1118
|
+
callerCwd: ctx.cwd,
|
|
1119
|
+
cwd: str("cwd"),
|
|
1120
|
+
name: str("name"),
|
|
1121
|
+
task,
|
|
1122
|
+
headless,
|
|
1123
|
+
acp,
|
|
1124
|
+
allow,
|
|
1125
|
+
requester,
|
|
1126
|
+
confineToHome: false,
|
|
1127
|
+
onProgress: (line) => ctx.err(`${t.paint("quiet", line)}\n`)
|
|
1128
|
+
});
|
|
1129
|
+
const how = res.mode === "acp" ? "over ACP, background" : res.mode === "headless" ? "background" : res.terminal ?? "terminal";
|
|
1130
|
+
ctx.out(`${t.status("ok")} ${t.bold(`Started ${res.name}`)} ${t.paint("quiet", `(${res.cli}, ${how}) in ${tilde(res.cwd, ctx.home)}`)}\n`);
|
|
1131
|
+
if (res.task === "message") ctx.out(` The first task was sent to it as a Conveno message.\n`);
|
|
1132
|
+
if (res.mode === "acp") {
|
|
1133
|
+
ctx.out(` Follow it with ${cmd(t, `conveno attach ${res.name}`)}; end it with ${cmd(t, `conveno stop ${res.name}`)}.\n`);
|
|
1134
|
+
if (res.adapter) ctx.out(` ${t.paint("quiet", `Adapter: ${res.adapter}`)}\n`);
|
|
1135
|
+
}
|
|
1136
|
+
if (res.logPath) ctx.out(` Output: ${tilde(res.logPath, ctx.home)}\n`);
|
|
1137
|
+
ctx.out(` ${t.paint("quiet", `${cmd(t, "conveno status")} lists it. Message it with send to: ${res.name}.`)}\n`);
|
|
1138
|
+
return 0;
|
|
1139
|
+
} catch (e) {
|
|
1140
|
+
if (e instanceof SpawnError) return fail(ctx, {
|
|
1141
|
+
what: "Could not start the session",
|
|
1142
|
+
detail: [e.message],
|
|
1143
|
+
...e.fix ? { fix: e.fix } : {},
|
|
1144
|
+
exit: 1,
|
|
1145
|
+
ref: "e_spawn"
|
|
1146
|
+
});
|
|
1147
|
+
throw e;
|
|
1148
|
+
} finally {
|
|
1149
|
+
await client.close().catch(() => void 0);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
/** `conveno spawn-run <launch file>`: what a spawned terminal runs. Not for people. */
|
|
1153
|
+
async function runSpawnRun(ctx, argv) {
|
|
1154
|
+
const [file] = argv;
|
|
1155
|
+
if (!file) return fail(ctx, {
|
|
1156
|
+
what: "conveno spawn-run needs a launch file",
|
|
1157
|
+
detail: ["It is started by conveno spawn inside the new terminal."],
|
|
1158
|
+
fix: `Run ${cmd(ctx.theme, "conveno spawn <cli>")} instead.`,
|
|
1159
|
+
exit: 2,
|
|
1160
|
+
ref: "e_usage"
|
|
1161
|
+
});
|
|
1162
|
+
try {
|
|
1163
|
+
return await runLaunchFile(file);
|
|
1164
|
+
} catch (e) {
|
|
1165
|
+
return fail(ctx, {
|
|
1166
|
+
what: "Could not read the launch file",
|
|
1167
|
+
detail: [e instanceof Error ? e.message : String(e)],
|
|
1168
|
+
fix: `Run ${cmd(ctx.theme, "conveno spawn <cli>")} again.`,
|
|
1169
|
+
exit: 1,
|
|
1170
|
+
ref: "e_spawn"
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
// src/uninstall.ts
|
|
1175
|
+
const NOTE = {
|
|
1176
|
+
restore: "restored byte for byte",
|
|
1177
|
+
remove: "removed, it did not exist before",
|
|
1178
|
+
edit: "edited since init, so only Conveno's entries are removed",
|
|
1179
|
+
gone: "already gone, left as it is"
|
|
1180
|
+
};
|
|
1181
|
+
/**
|
|
1182
|
+
* The files as init found them, from the backups: their text, or null when they did not exist. A
|
|
1183
|
+
* backup that cannot be read leaves its file out, and the adapter then treats what it finds as
|
|
1184
|
+
* Conveno's own.
|
|
1185
|
+
*/
|
|
1186
|
+
async function baselineOf(dir, entries) {
|
|
1187
|
+
const out = /* @__PURE__ */ new Map();
|
|
1188
|
+
for (const e of entries) if (e.backup === null) out.set(e.path, null);
|
|
1189
|
+
else try {
|
|
1190
|
+
out.set(e.path, await readFile(join(dir, e.backup), "utf8"));
|
|
1191
|
+
} catch {}
|
|
1192
|
+
return out;
|
|
1193
|
+
}
|
|
1194
|
+
/** Remove Conveno's own entries from files that changed since init, through each adapter. */
|
|
1195
|
+
async function removeOwnEntries(ctx, dir, entries) {
|
|
1196
|
+
if (entries.length === 0) return {
|
|
1197
|
+
edited: [],
|
|
1198
|
+
failures: []
|
|
1199
|
+
};
|
|
1200
|
+
const clis = new Set(entries.map((e) => e.cli));
|
|
1201
|
+
const found = (await detectAll(ctx)).filter((f) => clis.has(f.adapter.cli));
|
|
1202
|
+
const { items, failures } = await collectPlans(ctx, found, "uninstallPlan", await baselineOf(dir, entries));
|
|
1203
|
+
const wanted = new Set(entries.map((e) => e.path));
|
|
1204
|
+
const mine = items.filter((i) => wanted.has(i.change.path));
|
|
1205
|
+
if (mine.length > 0) await applyChanges(ctx, mine, { markRestored: true });
|
|
1206
|
+
return {
|
|
1207
|
+
edited: mine.map((i) => i.change.path),
|
|
1208
|
+
failures
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
async function restoreAll(ctx, manifests) {
|
|
1212
|
+
const restored = [];
|
|
1213
|
+
const edited = [];
|
|
1214
|
+
const untouched = [];
|
|
1215
|
+
for (const found of manifests) {
|
|
1216
|
+
const needEdit = [];
|
|
1217
|
+
for (const entry of found.manifest.entries) {
|
|
1218
|
+
const action = await restoreEntry(found.dir, entry);
|
|
1219
|
+
if (action === "edit") needEdit.push(entry);
|
|
1220
|
+
else if (action === "gone") untouched.push(entry.path);
|
|
1221
|
+
else restored.push(entry.path);
|
|
1222
|
+
}
|
|
1223
|
+
const r = await removeOwnEntries(ctx, found.dir, needEdit);
|
|
1224
|
+
if (r.failures.length > 0) {
|
|
1225
|
+
reportFailures(ctx, r.failures, "conveno uninstall");
|
|
1226
|
+
throw new Error("A config file could not be read, so it was left as it is.");
|
|
1227
|
+
}
|
|
1228
|
+
edited.push(...r.edited);
|
|
1229
|
+
for (const e of needEdit) if (!r.edited.includes(e.path)) untouched.push(e.path);
|
|
1230
|
+
await markRestored(ctx, found);
|
|
1231
|
+
}
|
|
1232
|
+
return {
|
|
1233
|
+
restored,
|
|
1234
|
+
edited,
|
|
1235
|
+
untouched
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
async function runUninstall(ctx, argv) {
|
|
1239
|
+
const t = ctx.theme;
|
|
1240
|
+
const started = ctx.now();
|
|
1241
|
+
const spec = COMMANDS.find((c) => c.name === "uninstall");
|
|
1242
|
+
if (!spec) return 2;
|
|
1243
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
1244
|
+
if (typeof parsed === "number") return parsed;
|
|
1245
|
+
const yes = parsed.values.yes === true;
|
|
1246
|
+
const manifests = await listManifests(ctx).catch(() => []);
|
|
1247
|
+
if (manifests.length > 0) {
|
|
1248
|
+
const rows = await previewRestore(manifests);
|
|
1249
|
+
const made = manifests.map((m) => localStamp(m.manifest.createdAt));
|
|
1250
|
+
ctx.out(`${t.bold(`Conveno will undo ${plural(manifests.length, "install")}`)}, made ${made.join(", ")} (local time).\n\n`);
|
|
1251
|
+
ctx.out(`${columns(rows.map((r) => [` ${tilde(r.entry.path, ctx.home)}`, t.paint("quiet", NOTE[r.action])])).join("\n")}\n\n`);
|
|
1252
|
+
if (!yes) {
|
|
1253
|
+
if (!ctx.interactive) return fail(ctx, {
|
|
1254
|
+
what: "Needs a terminal to confirm",
|
|
1255
|
+
detail: ["No files were changed."],
|
|
1256
|
+
fix: `Run ${cmd(t, "conveno uninstall --yes")} to undo the changes listed above.`,
|
|
1257
|
+
exit: 2,
|
|
1258
|
+
ref: "e_no_tty"
|
|
1259
|
+
});
|
|
1260
|
+
if (!await ctx.confirm("Undo these changes?", false)) {
|
|
1261
|
+
ctx.out(`${t.status("info")} Nothing was changed.\n`);
|
|
1262
|
+
return 0;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
let result;
|
|
1266
|
+
try {
|
|
1267
|
+
result = await restoreAll(ctx, manifests);
|
|
1268
|
+
} catch (e) {
|
|
1269
|
+
if (e instanceof StaleError) return staleFailure(ctx, e, "conveno uninstall");
|
|
1270
|
+
return fail(ctx, {
|
|
1271
|
+
what: "Could not restore a file",
|
|
1272
|
+
detail: [plainError(e), `The backups are still in ${tilde(manifests[0]?.dir ?? ctx.dataDir, ctx.home)} and the other backup folders next to it.`],
|
|
1273
|
+
fix: "Fix the problem above, then run conveno uninstall again.",
|
|
1274
|
+
exit: 1,
|
|
1275
|
+
ref: "e_restore"
|
|
1276
|
+
});
|
|
1277
|
+
}
|
|
1278
|
+
ctx.out(`${t.status("ok")} ${t.bold("Done.")} ${seconds(started, ctx.now())}\n`);
|
|
1279
|
+
ctx.out(` Restored ${plural(result.restored.length, "file")} to how init found them.\n`);
|
|
1280
|
+
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`);
|
|
1281
|
+
ctx.out(" Restart open sessions to drop Conveno.\n");
|
|
1282
|
+
return 0;
|
|
1283
|
+
}
|
|
1284
|
+
const found = await detectAll(ctx);
|
|
1285
|
+
const { items, failures } = await collectPlans(ctx, found, "uninstallPlan");
|
|
1286
|
+
if (failures.length > 0) {
|
|
1287
|
+
reportFailures(ctx, failures, "conveno uninstall");
|
|
1288
|
+
return 1;
|
|
1289
|
+
}
|
|
1290
|
+
if (items.length === 0) {
|
|
1291
|
+
ctx.out(`${t.status("ok")} Nothing to remove. No Conveno entries were found in any supported CLI.\n`);
|
|
1292
|
+
return 0;
|
|
1293
|
+
}
|
|
1294
|
+
ctx.out(`${t.status("info")} No install backup found, so Conveno will remove only its own entries.\n\n`);
|
|
1295
|
+
const result = await confirmAndApply(ctx, items, {
|
|
1296
|
+
yes,
|
|
1297
|
+
verb: "Remove",
|
|
1298
|
+
rerun: "conveno uninstall",
|
|
1299
|
+
markRestored: true
|
|
1300
|
+
});
|
|
1301
|
+
if ("exit" in result) return result.exit;
|
|
1302
|
+
ctx.out(`${t.status("ok")} ${t.bold("Done.")} ${seconds(started, ctx.now())}\n`);
|
|
1303
|
+
ctx.out(" Removed the Conveno entries. Restart open sessions to drop Conveno.\n");
|
|
1304
|
+
return 0;
|
|
1305
|
+
}
|
|
1306
|
+
// src/main.ts
|
|
1307
|
+
const DESCRIPTION = "Conveno lets AI coding sessions on one machine find each other and exchange messages.";
|
|
1308
|
+
function helpText(ctx) {
|
|
1309
|
+
const t = ctx.theme;
|
|
1310
|
+
const rows = COMMANDS.map((c) => [c.usage.replace(/^conveno /, ""), c.summary]);
|
|
1311
|
+
const width = Math.max(...rows.map(([u]) => u.length), 9) + 2;
|
|
1312
|
+
const row = (c, d) => ` ${t.bold(c.padEnd(width))}${d}`;
|
|
1313
|
+
return [
|
|
1314
|
+
DESCRIPTION,
|
|
1315
|
+
"",
|
|
1316
|
+
"Usage: conveno <command> [options]",
|
|
1317
|
+
"",
|
|
1318
|
+
...rows.map(([u, d]) => row(u, d)),
|
|
1319
|
+
row("--version", "Print the version"),
|
|
1320
|
+
"",
|
|
1321
|
+
`Run ${cmd(t, "conveno <command> --help")} for the options of one command.`,
|
|
1322
|
+
`conveno ${t.paint("info", VERSION)}`,
|
|
1323
|
+
""
|
|
1324
|
+
].join("\n");
|
|
1325
|
+
}
|
|
1326
|
+
async function runMcp(ctx, argv) {
|
|
1327
|
+
const t = ctx.theme;
|
|
1328
|
+
const spec = COMMANDS.find((c) => c.name === "mcp");
|
|
1329
|
+
if (!spec) return 2;
|
|
1330
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
1331
|
+
if (typeof parsed === "number") return parsed;
|
|
1332
|
+
const cli = typeof parsed.values.cli === "string" ? parsed.values.cli : void 0;
|
|
1333
|
+
if (!cli || !CLI_KINDS.includes(cli)) return fail(ctx, {
|
|
1334
|
+
what: "conveno mcp needs a CLI name",
|
|
1335
|
+
detail: [`Got ${cli ? `"${cli}"` : "none"}. Known: ${CLI_KINDS.join(", ")}.`],
|
|
1336
|
+
fix: `Run ${cmd(t, "conveno mcp --cli claude")}, or let ${cmd(t, "conveno init")} write the config.`,
|
|
1337
|
+
exit: 2,
|
|
1338
|
+
ref: "e_usage"
|
|
1339
|
+
});
|
|
1340
|
+
try {
|
|
1341
|
+
await ctx.runMcp({
|
|
1342
|
+
cli,
|
|
1343
|
+
...ctx.daemonEntry ? { daemonEntry: ctx.daemonEntry } : {}
|
|
1344
|
+
});
|
|
1345
|
+
return 0;
|
|
1346
|
+
} catch (e) {
|
|
1347
|
+
const problem = daemonProblem(t, e);
|
|
1348
|
+
return fail(ctx, {
|
|
1349
|
+
what: "The Conveno MCP server stopped",
|
|
1350
|
+
detail: [problem.why],
|
|
1351
|
+
fix: problem.notRunning ? `Run ${cmd(t, "conveno doctor")} to check the daemon.` : problem.fix,
|
|
1352
|
+
exit: 1,
|
|
1353
|
+
ref: "e_mcp"
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
async function dispatch(command, rest, ctx) {
|
|
1358
|
+
const spec = COMMANDS.find((c) => c.name === command);
|
|
1359
|
+
if (spec && (rest.includes("--help") || rest.includes("-h")) && command !== "hook") {
|
|
1360
|
+
ctx.out(commandHelp(ctx, spec));
|
|
1361
|
+
return 0;
|
|
1362
|
+
}
|
|
1363
|
+
switch (command) {
|
|
1364
|
+
case "init": return runInit(ctx, rest);
|
|
1365
|
+
case "uninstall": return runUninstall(ctx, rest);
|
|
1366
|
+
case "status": return runStatus(ctx, rest);
|
|
1367
|
+
case "tickets": return runTickets(ctx, rest);
|
|
1368
|
+
case "answer": return runAnswer(ctx, rest);
|
|
1369
|
+
case "permissions": return runPermissions(ctx, rest);
|
|
1370
|
+
case "forget": return runForget(ctx, rest);
|
|
1371
|
+
case "spawn": return runSpawn(ctx, rest);
|
|
1372
|
+
case "acp-host": return (await import("./acp-Bs2yS0Qg.js")).runAcpHostCmd(ctx, rest);
|
|
1373
|
+
case "stop": return (await import("./acp-Bs2yS0Qg.js")).runStop(ctx, rest);
|
|
1374
|
+
case "attach": return (await import("./acp-Bs2yS0Qg.js")).runAttach(ctx, rest);
|
|
1375
|
+
case "spawn-run": return runSpawnRun(ctx, rest);
|
|
1376
|
+
case "auto": return runAuto(ctx, rest);
|
|
1377
|
+
case "peek": return runPeek(ctx, rest);
|
|
1378
|
+
case "devices": return runDevices(ctx, rest);
|
|
1379
|
+
case "relay": return runRelay(ctx, rest);
|
|
1380
|
+
case "doctor": return runDoctor(ctx, rest);
|
|
1381
|
+
case "login": return runLogin(ctx, rest);
|
|
1382
|
+
case "logout": return runLogout(ctx, rest);
|
|
1383
|
+
case "account": return runAccount(ctx, rest);
|
|
1384
|
+
case "daemon": return runDaemon(ctx, rest);
|
|
1385
|
+
case "mcp": return runMcp(ctx, rest);
|
|
1386
|
+
case "hook": return runHook(ctx, rest);
|
|
1387
|
+
default: {
|
|
1388
|
+
const suggestion = closest(command, COMMAND_NAMES);
|
|
1389
|
+
return fail(ctx, {
|
|
1390
|
+
what: `Unknown command "${command}"`,
|
|
1391
|
+
detail: [`conveno ${VERSION} has: ${COMMAND_NAMES.join(", ")}.`],
|
|
1392
|
+
fix: `Run ${cmd(ctx.theme, "conveno --help")} to see usage.`,
|
|
1393
|
+
...suggestion ? { didYouMean: `Did you mean ${suggestion}?` } : {},
|
|
1394
|
+
exit: 2,
|
|
1395
|
+
ref: "e_usage"
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* `conveno` alone opens the app, but only in a real terminal: not piped, not CI, not TERM=dumb.
|
|
1402
|
+
* Everything else prints the help, as before.
|
|
1403
|
+
*/
|
|
1404
|
+
function opensApp(env, tty = {
|
|
1405
|
+
stdin: Boolean(process.stdin.isTTY),
|
|
1406
|
+
stdout: Boolean(process.stdout.isTTY)
|
|
1407
|
+
}) {
|
|
1408
|
+
if (!tty.stdin || !tty.stdout) return false;
|
|
1409
|
+
if (env.CI && env.CI !== "0" && env.CI.toLowerCase() !== "false") return false;
|
|
1410
|
+
return env.TERM !== "dumb";
|
|
1411
|
+
}
|
|
1412
|
+
/** Run one command line. Returns the exit code. Never throws. */
|
|
1413
|
+
async function main(argv, ctx) {
|
|
1414
|
+
const [command, ...rest] = argv;
|
|
1415
|
+
if (command === void 0 && opensApp(ctx.env)) try {
|
|
1416
|
+
return await (await import("./run-BEhIahUS.js")).runTui(ctx);
|
|
1417
|
+
} catch (e) {
|
|
1418
|
+
ctx.err(`The app could not start (${rawMessage(e)}). Showing the help instead.\n`);
|
|
1419
|
+
ctx.out(helpText(ctx));
|
|
1420
|
+
return 0;
|
|
1421
|
+
}
|
|
1422
|
+
switch (command) {
|
|
1423
|
+
case void 0:
|
|
1424
|
+
case "--help":
|
|
1425
|
+
case "-h":
|
|
1426
|
+
case "help":
|
|
1427
|
+
ctx.out(helpText(ctx));
|
|
1428
|
+
return 0;
|
|
1429
|
+
case "--version":
|
|
1430
|
+
case "-v":
|
|
1431
|
+
case "version":
|
|
1432
|
+
ctx.out(`${VERSION}\n`);
|
|
1433
|
+
return 0;
|
|
1434
|
+
}
|
|
1435
|
+
try {
|
|
1436
|
+
return await dispatch(command, rest, ctx);
|
|
1437
|
+
} catch (e) {
|
|
1438
|
+
const log = await writeErrorLog(ctx, argv, e);
|
|
1439
|
+
return fail(ctx, {
|
|
1440
|
+
what: "conveno stopped before it could finish",
|
|
1441
|
+
detail: [rawMessage(e), ...log ? [`The full error is in ${tilde(log, ctx.home)}.`] : []],
|
|
1442
|
+
fix: `Run ${cmd(ctx.theme, "conveno doctor")} to check the install, then try again.`,
|
|
1443
|
+
exit: 1,
|
|
1444
|
+
ref: "e_internal"
|
|
1445
|
+
});
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
export { DESCRIPTION, helpText, main, opensApp };
|