@conveno/cli 0.2.0-rc.1 → 0.2.0-rc.10
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 +28 -29
- package/dist/acp-TSjX4JP9.js +82 -0
- package/dist/agy-relay-D-OWo85B.js +137 -0
- package/dist/args-B3Cj2Ie4.js +361 -0
- package/dist/bin.js +4 -4
- package/dist/ctx-tYftvhz_.js +17 -0
- package/dist/daemon.js +490 -1151
- package/dist/daemonError-C05GqdhQ.js +66 -0
- package/dist/{acp-BlKK0v-B.js → dist-BLfduOoT.js} +39 -286
- package/dist/dist-BRjg9CLd.js +731 -0
- package/dist/{dist-CWvQqhPj.js → dist-CVdpCNJo.js} +1 -1
- package/dist/{dist-DsRTUePN.js → dist-D_O_JLLq.js} +6 -14
- package/dist/dist-DaIpdMke.js +667 -0
- package/dist/dist-MK-cK1JY.js +969 -0
- package/dist/{dist-_qrCNXUP.js → dist-STNJjbNH.js} +840 -1253
- package/dist/dist-VOS92iqO.js +645 -0
- package/dist/fmt-C2SsP5Y0.js +96 -0
- package/dist/{hook-bfp9_AVT.js → hook-CDF1A8AY.js} +31 -22
- package/dist/hook-entry-C0bPssOy.js +1 -0
- package/dist/hook-entry-CQQU-e_t.js +2500 -0
- package/dist/main-BhKTG0AI.js +650 -0
- package/dist/pick-DLp6w_-z.js +9 -0
- package/dist/run-eCXO1SyO.js +5609 -0
- package/dist/runtime-BGPlr8CI.js +772 -0
- package/dist/{dist-D8gPpZKN.js → toml-patch-DGzVRdd1.js} +20 -1889
- package/dist/{main-sIWDc4jt.js → uninstall-DQlzpv5R.js} +629 -1494
- package/dist/watch-D0KIPowJ.js +185 -0
- package/package.json +23 -16
- package/dist/args-DHkLY6_f.js +0 -513
- package/dist/dist-DcmKjrmu.js +0 -271
- package/dist/hook-entry-Daxws9EC.js +0 -1
- package/dist/hook-entry-RlH2cG3S.js +0 -1289
- package/dist/runtime-5nEur1P5.js +0 -1505
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { t as ClientError } from "./dist-D_O_JLLq.js";
|
|
2
|
+
import { n as cmd, s as plainError } from "./fmt-C2SsP5Y0.js";
|
|
3
|
+
// src/daemonError.ts
|
|
4
|
+
/**
|
|
5
|
+
* Explain a failed connection to the daemon, with a fix that fits the cause. `start` is the command
|
|
6
|
+
* that fixes a daemon that is merely not running.
|
|
7
|
+
*/
|
|
8
|
+
function daemonProblem(t, e) {
|
|
9
|
+
const why = plainError(e);
|
|
10
|
+
const kind = e instanceof ClientError ? e.kind : void 0;
|
|
11
|
+
const start = cmd(t, "conveno daemon start");
|
|
12
|
+
const status = cmd(t, "conveno daemon status");
|
|
13
|
+
switch (kind) {
|
|
14
|
+
case "socket_path_too_long": return {
|
|
15
|
+
why,
|
|
16
|
+
fix: `Set ${cmd(t, "XDG_RUNTIME_DIR")} to a shorter directory, then run ${start}. Use the same value everywhere you run Conveno and your AI CLIs.`,
|
|
17
|
+
notRunning: false
|
|
18
|
+
};
|
|
19
|
+
case "permission": return {
|
|
20
|
+
why,
|
|
21
|
+
fix: `Check who owns the socket named above. If it is not yours, remove it, then run ${start}.`,
|
|
22
|
+
notRunning: false
|
|
23
|
+
};
|
|
24
|
+
case "not_daemon": return {
|
|
25
|
+
why,
|
|
26
|
+
fix: `Stop the process that owns the socket, or remove the socket, then run ${start}.`,
|
|
27
|
+
notRunning: false
|
|
28
|
+
};
|
|
29
|
+
case "token_empty": return {
|
|
30
|
+
why,
|
|
31
|
+
fix: `Run ${cmd(t, "conveno daemon stop")}, then ${start}.`,
|
|
32
|
+
notRunning: false
|
|
33
|
+
};
|
|
34
|
+
case "daemon_missing": return {
|
|
35
|
+
why,
|
|
36
|
+
fix: `Reinstall Conveno (${cmd(t, "npm install -g @conveno/cli")}), then run ${start}.`,
|
|
37
|
+
notRunning: false
|
|
38
|
+
};
|
|
39
|
+
case "start_timeout": return {
|
|
40
|
+
why,
|
|
41
|
+
fix: `Run ${status} to see whether it came up, or ${cmd(t, "conveno doctor")} to check the install.`,
|
|
42
|
+
notRunning: false
|
|
43
|
+
};
|
|
44
|
+
case "start_exited": return {
|
|
45
|
+
why,
|
|
46
|
+
fix: `Fix what its output above shows, then run ${start}. If it is unclear, report it with that output.`,
|
|
47
|
+
notRunning: false
|
|
48
|
+
};
|
|
49
|
+
case "connection": return {
|
|
50
|
+
why,
|
|
51
|
+
fix: `Run ${status}, then try again.`,
|
|
52
|
+
notRunning: false
|
|
53
|
+
};
|
|
54
|
+
case "no_daemon": return {
|
|
55
|
+
why,
|
|
56
|
+
fix: `Run ${start}. It also starts when a CLI opens the Conveno MCP server.`,
|
|
57
|
+
notRunning: true
|
|
58
|
+
};
|
|
59
|
+
default: return {
|
|
60
|
+
why,
|
|
61
|
+
fix: `Run ${cmd(t, "conveno doctor")} to check the install, then try again.`,
|
|
62
|
+
notRunning: false
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export { daemonProblem as t };
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { $ as isAllowed, Ut as spawnRecordPath, Yt as takeAcpLaunchFile, ft as parseAllowPatterns, jt as readSpawnRecord, m as acpTurnsPath, q as formatContinuation, r as ConvenoError, sn as CliKind, tn as updateSpawnRecord, xn as SessionId, yn as RpcErrorCode } from "./dist-_qrCNXUP.js";
|
|
1
|
+
import { n as connect } from "./dist-D_O_JLLq.js";
|
|
2
|
+
import { Jt as takeAcpLaunchFile, Q as isAllowed, en as updateSpawnRecord, ft as parseAllowPatterns, gn as RpcErrorCode, i as DEFAULT_ALLOW_RULES, on as CliKind, q as formatContinuation, r as ConvenoError, yn as SessionId } from "./dist-STNJjbNH.js";
|
|
4
3
|
import { randomBytes } from "node:crypto";
|
|
4
|
+
import { existsSync, rmSync } from "node:fs";
|
|
5
5
|
import { Readable, Writable } from "node:stream";
|
|
6
6
|
import { PROTOCOL_VERSION, client, methods, ndJsonStream } from "@agentclientprotocol/sdk";
|
|
7
|
-
import { appendFile } from "node:fs/promises";
|
|
8
|
-
import { t as redact } from "./dist-DcmKjrmu.js";
|
|
9
7
|
import { spawn, spawnSync } from "node:child_process";
|
|
10
|
-
import { i as parseFlags, l as fail, o as cmd, t as COMMANDS, u as localStamp } from "./args-DHkLY6_f.js";
|
|
11
8
|
// ../acp/dist/index.js
|
|
12
9
|
/**
|
|
13
10
|
* Pick the option to answer with. Allowing uses `allow_once` only: `allow_always` would change the
|
|
@@ -37,144 +34,44 @@ var AllowListPolicy = class {
|
|
|
37
34
|
if (outcome.outcome === "selected") return {
|
|
38
35
|
allowed: true,
|
|
39
36
|
outcome,
|
|
40
|
-
reason: `allowed ${what} by
|
|
37
|
+
reason: `allowed ${what} by the allow list`
|
|
41
38
|
};
|
|
42
39
|
return {
|
|
43
40
|
allowed: false,
|
|
44
41
|
outcome: answer(ask, false),
|
|
45
|
-
reason: `denied ${what}: allowed by
|
|
42
|
+
reason: `denied ${what}: allowed by the allow list, but the agent offered no allow-once option`
|
|
46
43
|
};
|
|
47
44
|
}
|
|
48
45
|
return {
|
|
49
46
|
allowed: false,
|
|
50
47
|
outcome: answer(ask, false),
|
|
51
|
-
reason: `denied ${what}:
|
|
48
|
+
reason: `denied ${what}: the allow list does not cover it`
|
|
52
49
|
};
|
|
53
50
|
}
|
|
54
51
|
};
|
|
55
|
-
/**
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
path;
|
|
60
|
-
now;
|
|
61
|
-
entries = [];
|
|
62
|
-
seq = 0;
|
|
63
|
-
pending = "";
|
|
64
|
-
timer;
|
|
65
|
-
size = 0;
|
|
66
|
-
writes = Promise.resolve();
|
|
67
|
-
/** Tool calls seen in this session: their latest title and kind, for permission requests. */
|
|
52
|
+
/** Calls remembered at most; the oldest are dropped. */
|
|
53
|
+
const TOOLS_MAX = 1e3;
|
|
54
|
+
var ToolTracker = class {
|
|
55
|
+
/** Tool calls seen in this session: their latest title and kind. */
|
|
68
56
|
tools = /* @__PURE__ */ new Map();
|
|
69
|
-
|
|
70
|
-
this.path = path;
|
|
71
|
-
this.now = now;
|
|
72
|
-
if (path) {
|
|
73
|
-
writeFileSync(path, "", { mode: 384 });
|
|
74
|
-
try {
|
|
75
|
-
chmodSync(path, 384);
|
|
76
|
-
} catch {}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/** The entries in memory, oldest first. */
|
|
80
|
-
recent(n = 200) {
|
|
81
|
-
return this.entries.slice(-n);
|
|
82
|
-
}
|
|
83
|
-
add(role, text) {
|
|
84
|
-
if (role !== "assistant") this.flush();
|
|
85
|
-
if (text === "") return;
|
|
86
|
-
const entry = {
|
|
87
|
-
seq: ++this.seq,
|
|
88
|
-
role,
|
|
89
|
-
text: clip(redact(text)),
|
|
90
|
-
at: this.now().toISOString()
|
|
91
|
-
};
|
|
92
|
-
this.entries.push(entry);
|
|
93
|
-
if (this.entries.length > 200) this.entries.splice(0, this.entries.length - 200);
|
|
94
|
-
this.write(entry);
|
|
95
|
-
}
|
|
96
|
-
/** Feed one `session/update`. Returns a status line when the update says what the agent is doing. */
|
|
57
|
+
/** Feed one `session/update`. Returns a status line when the agent starts a tool call. */
|
|
97
58
|
update(u) {
|
|
98
|
-
if (u.sessionUpdate
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const next = {
|
|
110
|
-
...this.tools.get(t.toolCallId) ?? {},
|
|
111
|
-
...t.title ? { title: t.title } : {},
|
|
112
|
-
...t.kind ? { kind: t.kind } : {}
|
|
113
|
-
};
|
|
114
|
-
this.tools.set(t.toolCallId, next);
|
|
115
|
-
if (this.tools.size > 1e3) {
|
|
116
|
-
const first = this.tools.keys().next().value;
|
|
117
|
-
if (first !== void 0) this.tools.delete(first);
|
|
118
|
-
}
|
|
119
|
-
const title = next.title ?? next.kind ?? "tool";
|
|
120
|
-
if (u.sessionUpdate === "tool_call") {
|
|
121
|
-
this.add("tool", `${title}${next.kind ? ` (${next.kind})` : ""}`);
|
|
122
|
-
return title;
|
|
123
|
-
}
|
|
124
|
-
if (t.status === "completed" || t.status === "failed") this.add("tool", `${title}: ${t.status}`);
|
|
125
|
-
return;
|
|
59
|
+
if (u.sessionUpdate !== "tool_call" && u.sessionUpdate !== "tool_call_update") return;
|
|
60
|
+
const t = u;
|
|
61
|
+
const next = {
|
|
62
|
+
...this.tools.get(t.toolCallId) ?? {},
|
|
63
|
+
...t.title ? { title: t.title } : {},
|
|
64
|
+
...t.kind ? { kind: t.kind } : {}
|
|
65
|
+
};
|
|
66
|
+
this.tools.set(t.toolCallId, next);
|
|
67
|
+
if (this.tools.size > TOOLS_MAX) {
|
|
68
|
+
const first = this.tools.keys().next().value;
|
|
69
|
+
if (first !== void 0) this.tools.delete(first);
|
|
126
70
|
}
|
|
127
|
-
|
|
128
|
-
/** Write out the agent message streamed so far. */
|
|
129
|
-
flush() {
|
|
130
|
-
if (this.timer) clearTimeout(this.timer);
|
|
131
|
-
this.timer = void 0;
|
|
132
|
-
const text = this.pending;
|
|
133
|
-
this.pending = "";
|
|
134
|
-
if (text.trim() !== "") this.add("assistant", text);
|
|
135
|
-
}
|
|
136
|
-
/** Resolves once every entry so far is on disk. */
|
|
137
|
-
async settle() {
|
|
138
|
-
this.flush();
|
|
139
|
-
await this.writes;
|
|
140
|
-
}
|
|
141
|
-
write(entry) {
|
|
142
|
-
const path = this.path;
|
|
143
|
-
if (!path) return;
|
|
144
|
-
const line = `${JSON.stringify(entry)}\n`;
|
|
145
|
-
this.writes = this.writes.then(async () => {
|
|
146
|
-
try {
|
|
147
|
-
if (this.size + line.length > 1e6) {
|
|
148
|
-
const text = this.entries.map((e) => `${JSON.stringify(e)}\n`).join("");
|
|
149
|
-
writeFileSync(`${path}.tmp`, text, { mode: 384 });
|
|
150
|
-
renameSync(`${path}.tmp`, path);
|
|
151
|
-
this.size = text.length;
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
await appendFile(path, line, { mode: 384 });
|
|
155
|
-
this.size += line.length;
|
|
156
|
-
} catch {}
|
|
157
|
-
});
|
|
71
|
+
return u.sessionUpdate === "tool_call" ? next.title ?? next.kind ?? "tool" : void 0;
|
|
158
72
|
}
|
|
159
73
|
};
|
|
160
|
-
|
|
161
|
-
function parseTurns(text) {
|
|
162
|
-
const out = [];
|
|
163
|
-
for (const line of text.split("\n")) {
|
|
164
|
-
if (line.trim() === "") continue;
|
|
165
|
-
try {
|
|
166
|
-
const v = JSON.parse(line);
|
|
167
|
-
if (typeof v.seq === "number" && typeof v.text === "string" && typeof v.at === "string" && (v.role === "user" || v.role === "assistant" || v.role === "tool" || v.role === "system")) out.push({
|
|
168
|
-
seq: v.seq,
|
|
169
|
-
role: v.role,
|
|
170
|
-
text: v.text,
|
|
171
|
-
at: v.at
|
|
172
|
-
});
|
|
173
|
-
} catch {}
|
|
174
|
-
}
|
|
175
|
-
return out;
|
|
176
|
-
}
|
|
177
|
-
const HOST_VERSION = "0.2.0-rc.1";
|
|
74
|
+
const HOST_VERSION = "0.2.0-rc.10";
|
|
178
75
|
/** A stop request file: `conveno stop` writes it next to the spawn record. */
|
|
179
76
|
const stopRequestPath = (recordPath) => recordPath.replace(/\.json$/, ".stop");
|
|
180
77
|
function withTimeout(p, ms, what) {
|
|
@@ -216,7 +113,7 @@ var AcpHost = class {
|
|
|
216
113
|
client;
|
|
217
114
|
log;
|
|
218
115
|
policy;
|
|
219
|
-
|
|
116
|
+
tools = new ToolTracker();
|
|
220
117
|
sessionId;
|
|
221
118
|
acpSessionId;
|
|
222
119
|
conn;
|
|
@@ -237,8 +134,8 @@ var AcpHost = class {
|
|
|
237
134
|
this.client = deps.client;
|
|
238
135
|
this.log = deps.log ?? ((line) => process.stderr.write(`[conveno acp-host] ${line}\n`));
|
|
239
136
|
const rules = parseAllowPatterns(spec.allow);
|
|
240
|
-
|
|
241
|
-
this.
|
|
137
|
+
const narrowed = rules.ok && rules.rules.length > 0 ? rules.rules : DEFAULT_ALLOW_RULES;
|
|
138
|
+
this.policy = deps.policy ?? new AllowListPolicy(narrowed);
|
|
242
139
|
}
|
|
243
140
|
/** Ask the host to stop. The first reason wins. */
|
|
244
141
|
stop(reason) {
|
|
@@ -330,6 +227,11 @@ var AcpHost = class {
|
|
|
330
227
|
}), timeout, "session/new"));
|
|
331
228
|
this.acpSessionId = created.sessionId;
|
|
332
229
|
this.log(`session/new: ${created.sessionId}`);
|
|
230
|
+
const mode = spec.fullAccessMode;
|
|
231
|
+
if (mode && created.modes?.availableModes.some((m) => m.id === mode)) await this.untilStopped(withTimeout(conn.agent.request(methods.agent.session.setMode, {
|
|
232
|
+
sessionId: created.sessionId,
|
|
233
|
+
modeId: mode
|
|
234
|
+
}), timeout, "session/set_mode")).then(() => this.log(`mode: ${mode}`), (e) => this.log(`could not set mode ${mode}: ${errText(e)}`));
|
|
333
235
|
const spawnedBy = SessionId.safeParse(spec.spawnedBy);
|
|
334
236
|
const { session } = await this.client["session.register"]({
|
|
335
237
|
name: spec.name,
|
|
@@ -349,11 +251,6 @@ var AcpHost = class {
|
|
|
349
251
|
agentPid: agent.pid
|
|
350
252
|
});
|
|
351
253
|
this.log(`registered as ${session.name} (${session.id})`);
|
|
352
|
-
await this.client["session.setCliInfo"]({
|
|
353
|
-
pid: process.pid,
|
|
354
|
-
cliSessionId: created.sessionId.slice(0, 200),
|
|
355
|
-
transcriptPath: spec.turnsPath
|
|
356
|
-
}).catch((e) => this.log(`could not report the turn log: ${errText(e)}`));
|
|
357
254
|
this.every(this.deps.heartbeatMs ?? 15e3, () => this.heartbeat());
|
|
358
255
|
}
|
|
359
256
|
async loop() {
|
|
@@ -397,7 +294,6 @@ var AcpHost = class {
|
|
|
397
294
|
this.turnCtl = new AbortController();
|
|
398
295
|
this.failedText = void 0;
|
|
399
296
|
this.denials = [];
|
|
400
|
-
this.turns.add("user", text);
|
|
401
297
|
await this.status("busy", null);
|
|
402
298
|
const turn = conn.agent.request(methods.agent.session.prompt, {
|
|
403
299
|
sessionId: sid,
|
|
@@ -407,21 +303,17 @@ var AcpHost = class {
|
|
|
407
303
|
}]
|
|
408
304
|
});
|
|
409
305
|
try {
|
|
410
|
-
|
|
411
|
-
this.turns.flush();
|
|
412
|
-
if (res.stopReason !== "end_turn") this.turns.add("system", `Turn ended: ${res.stopReason}.`);
|
|
306
|
+
await this.untilStopped(turn);
|
|
413
307
|
} catch (e) {
|
|
414
|
-
this.turns.flush();
|
|
415
308
|
if (!this.stopping) {
|
|
416
309
|
const reason = requestReason(e);
|
|
417
|
-
this.turns.add("system", `The prompt failed: ${reason}`);
|
|
418
310
|
this.log(`session/prompt failed: ${reason}`);
|
|
419
311
|
await this.promptFailed(reason);
|
|
420
312
|
return;
|
|
421
313
|
}
|
|
422
314
|
await conn.agent.notify(methods.agent.session.cancel, { sessionId: sid }).catch(() => void 0);
|
|
423
315
|
const grace = this.deps.stopGraceMs ?? 5e3;
|
|
424
|
-
await Promise.race([turn.then((
|
|
316
|
+
await Promise.race([turn.then(() => void 0, () => void 0), new Promise((r) => setTimeout(r, grace).unref())]);
|
|
425
317
|
}
|
|
426
318
|
}
|
|
427
319
|
/**
|
|
@@ -489,7 +381,7 @@ var AcpHost = class {
|
|
|
489
381
|
}
|
|
490
382
|
onUpdate(n) {
|
|
491
383
|
if (n.sessionId !== this.acpSessionId) return;
|
|
492
|
-
const doing = this.
|
|
384
|
+
const doing = this.tools.update(n.update);
|
|
493
385
|
if (doing !== void 0 && doing !== this.lastStatus) {
|
|
494
386
|
this.lastStatus = doing;
|
|
495
387
|
this.status(void 0, doing);
|
|
@@ -497,7 +389,7 @@ var AcpHost = class {
|
|
|
497
389
|
}
|
|
498
390
|
async onPermission(p) {
|
|
499
391
|
if (this.turnCtl.signal.aborted) return { outcome: { outcome: "cancelled" } };
|
|
500
|
-
const known = this.
|
|
392
|
+
const known = this.tools.tools.get(p.toolCall.toolCallId) ?? {};
|
|
501
393
|
const title = p.toolCall.title ?? known.title;
|
|
502
394
|
const kind = p.toolCall.kind ?? known.kind;
|
|
503
395
|
const ask = {
|
|
@@ -510,7 +402,6 @@ var AcpHost = class {
|
|
|
510
402
|
const decision = await Promise.race([this.policy.decide(ask, signal), new Promise((r) => signal.addEventListener("abort", () => r(null), { once: true }))]);
|
|
511
403
|
if (decision === null) return { outcome: { outcome: "cancelled" } };
|
|
512
404
|
this.log(`permission: ${decision.reason}`);
|
|
513
|
-
this.turns.add("system", `Permission ${decision.allowed ? "granted" : "denied"}: ${title ?? kind ?? "tool call"}.`);
|
|
514
405
|
if (!decision.allowed) this.denials.push(`${title ?? "a tool call"} (${kind ?? "other"})`);
|
|
515
406
|
return { outcome: decision.outcome };
|
|
516
407
|
}
|
|
@@ -567,9 +458,9 @@ var AcpHost = class {
|
|
|
567
458
|
if (this.denials.length > 5) list.push(`- and ${this.denials.length - 5} more`);
|
|
568
459
|
this.denials = [];
|
|
569
460
|
await this.tell([
|
|
570
|
-
`[conveno] Worker ${this.spec.name} (${this.spec.cli}, over ACP) was denied these tool calls in its last turn, because
|
|
461
|
+
`[conveno] Worker ${this.spec.name} (${this.spec.cli}, over ACP) was denied these tool calls in its last turn, because its spawn limited it to an allow list:`,
|
|
571
462
|
...list,
|
|
572
|
-
"The
|
|
463
|
+
"The allow list it was spawned with does not cover them. Spawn it again with a wider allow list, or none for full access."
|
|
573
464
|
].join("\n"));
|
|
574
465
|
}
|
|
575
466
|
/** Send a text message from this session to its spawner. Never throws. */
|
|
@@ -612,7 +503,6 @@ var AcpHost = class {
|
|
|
612
503
|
kind: "failed",
|
|
613
504
|
detail: "unknown"
|
|
614
505
|
};
|
|
615
|
-
await this.turns.settle();
|
|
616
506
|
const agent = this.agent;
|
|
617
507
|
if (agent) {
|
|
618
508
|
this.conn?.close();
|
|
@@ -731,141 +621,4 @@ async function runAcpHostFromFile(path, opts = {}) {
|
|
|
731
621
|
await client.close().catch(() => void 0);
|
|
732
622
|
}
|
|
733
623
|
}
|
|
734
|
-
|
|
735
|
-
/** How long `conveno stop` waits for a worker to end by itself before it ends the process tree. */
|
|
736
|
-
const STOP_WAIT_MS = 1e4;
|
|
737
|
-
/** `conveno acp-host <launch file>`: what `conveno spawn --acp` runs in the background. Not for people. */
|
|
738
|
-
async function runAcpHostCmd(ctx, argv) {
|
|
739
|
-
const [file] = argv;
|
|
740
|
-
if (!file) return fail(ctx, {
|
|
741
|
-
what: "conveno acp-host needs a launch file",
|
|
742
|
-
detail: ["It is started by conveno spawn --acp."],
|
|
743
|
-
fix: `Run ${cmd(ctx.theme, "conveno spawn <cli> --acp")} instead.`,
|
|
744
|
-
exit: 2,
|
|
745
|
-
ref: "e_usage"
|
|
746
|
-
});
|
|
747
|
-
try {
|
|
748
|
-
return await runAcpHostFromFile(file, {
|
|
749
|
-
dataDir: ctx.dataDir,
|
|
750
|
-
...ctx.socketPath ? { socketPath: ctx.socketPath } : {},
|
|
751
|
-
...ctx.daemonEntry ? { daemonEntry: ctx.daemonEntry } : {}
|
|
752
|
-
});
|
|
753
|
-
} catch (e) {
|
|
754
|
-
return fail(ctx, {
|
|
755
|
-
what: "The ACP host could not start",
|
|
756
|
-
detail: [e instanceof Error ? e.message : String(e)],
|
|
757
|
-
fix: `Run ${cmd(ctx.theme, "conveno spawn <cli> --acp")} again.`,
|
|
758
|
-
exit: 1,
|
|
759
|
-
ref: "e_spawn"
|
|
760
|
-
});
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
function findWorker(ctx, name, command) {
|
|
764
|
-
if (!name) return fail(ctx, {
|
|
765
|
-
what: `conveno ${command} needs a worker name`,
|
|
766
|
-
fix: `Run ${cmd(ctx.theme, "conveno status")} to see the names.`,
|
|
767
|
-
exit: 2,
|
|
768
|
-
ref: "e_usage"
|
|
769
|
-
});
|
|
770
|
-
const rec = /^[a-z0-9][a-z0-9._@-]{0,63}$/.test(name) ? readSpawnRecord(spawnRecordPath(ctx.dataDir, name)) : void 0;
|
|
771
|
-
if (!rec) return fail(ctx, {
|
|
772
|
-
what: `No running worker named "${name}"`,
|
|
773
|
-
detail: ["Only sessions started by conveno spawn or spawn_session on this machine are workers."],
|
|
774
|
-
fix: `Run ${cmd(ctx.theme, "conveno status")} to see the names.`,
|
|
775
|
-
exit: 1,
|
|
776
|
-
ref: "e_not_found"
|
|
777
|
-
});
|
|
778
|
-
return rec;
|
|
779
|
-
}
|
|
780
|
-
/**
|
|
781
|
-
* `conveno stop <worker>`. An ACP worker gets a stop request: its host sends `session/cancel` for
|
|
782
|
-
* a running turn, ends the agent, reports to the spawner and takes the session offline. A headless
|
|
783
|
-
* one-shot run is ended. A worker in a terminal is the user's to close.
|
|
784
|
-
*/
|
|
785
|
-
async function runStop(ctx, argv) {
|
|
786
|
-
const spec = COMMANDS.find((c) => c.name === "stop");
|
|
787
|
-
if (!spec) return 2;
|
|
788
|
-
const parsed = parseFlags(ctx, spec, argv);
|
|
789
|
-
if (typeof parsed === "number") return parsed;
|
|
790
|
-
const [name] = parsed.positionals;
|
|
791
|
-
const rec = findWorker(ctx, name, "stop");
|
|
792
|
-
if (typeof rec === "number") return rec;
|
|
793
|
-
const t = ctx.theme;
|
|
794
|
-
if (!rec.headless) return fail(ctx, {
|
|
795
|
-
what: `${rec.name} runs in a terminal`,
|
|
796
|
-
detail: ["Conveno does not close a terminal you can see."],
|
|
797
|
-
fix: "Exit the CLI in that terminal.",
|
|
798
|
-
exit: 1,
|
|
799
|
-
ref: "e_spawn"
|
|
800
|
-
});
|
|
801
|
-
const alive = () => rec.pid !== void 0 && ctx.isAlive(rec.pid);
|
|
802
|
-
if (rec.acp) {
|
|
803
|
-
writeFileSync(stopRequestPath(spawnRecordPath(ctx.dataDir, rec.name)), "", { mode: 384 });
|
|
804
|
-
const end = Date.now() + STOP_WAIT_MS;
|
|
805
|
-
while (alive() && Date.now() < end) await new Promise((r) => setTimeout(r, 100));
|
|
806
|
-
}
|
|
807
|
-
if (alive() && rec.pid !== void 0) killProcessTree(rec.pid, ctx.platform);
|
|
808
|
-
if (rec.agentPid !== void 0 && ctx.isAlive(rec.agentPid)) killProcessTree(rec.agentPid, ctx.platform);
|
|
809
|
-
ctx.out(`${t.status("ok")} ${t.bold(`Stopped ${rec.name}`)}\n`);
|
|
810
|
-
return 0;
|
|
811
|
-
}
|
|
812
|
-
const ROLE_LABEL = {
|
|
813
|
-
user: "prompt",
|
|
814
|
-
assistant: "agent",
|
|
815
|
-
tool: "tool",
|
|
816
|
-
system: "conveno"
|
|
817
|
-
};
|
|
818
|
-
/**
|
|
819
|
-
* `conveno attach <worker>`: print the recent turns of an ACP worker and follow new ones until it
|
|
820
|
-
* stops or Ctrl+C. Read-only: nothing typed here reaches the worker; message it with send instead.
|
|
821
|
-
*/
|
|
822
|
-
async function runAttach(ctx, argv) {
|
|
823
|
-
const spec = COMMANDS.find((c) => c.name === "attach");
|
|
824
|
-
if (!spec) return 2;
|
|
825
|
-
const parsed = parseFlags(ctx, spec, argv);
|
|
826
|
-
if (typeof parsed === "number") return parsed;
|
|
827
|
-
const t = ctx.theme;
|
|
828
|
-
const [name] = parsed.positionals;
|
|
829
|
-
const rec = findWorker(ctx, name, "attach");
|
|
830
|
-
if (typeof rec === "number") return rec;
|
|
831
|
-
if (!rec.acp) return fail(ctx, {
|
|
832
|
-
what: `${rec.name} is not driven over ACP`,
|
|
833
|
-
detail: ["attach follows workers started with conveno spawn --acp."],
|
|
834
|
-
fix: "Watch it in its terminal, or read its log in the data folder.",
|
|
835
|
-
exit: 1,
|
|
836
|
-
ref: "e_spawn"
|
|
837
|
-
});
|
|
838
|
-
const linesFlag = parsed.values.lines;
|
|
839
|
-
const lines = typeof linesFlag === "string" ? Number(linesFlag) : 20;
|
|
840
|
-
if (!Number.isInteger(lines) || lines < 0) return fail(ctx, {
|
|
841
|
-
what: "--lines takes a whole number",
|
|
842
|
-
fix: `Run ${cmd(t, "conveno attach <worker> --lines 50")}.`,
|
|
843
|
-
exit: 2,
|
|
844
|
-
ref: "e_usage"
|
|
845
|
-
});
|
|
846
|
-
const path = acpTurnsPath(ctx.dataDir, rec.name);
|
|
847
|
-
const read = () => existsSync(path) ? parseTurns(readFileSync(path, "utf8")) : [];
|
|
848
|
-
const show = (e) => {
|
|
849
|
-
const head = t.paint("quiet", `${localStamp(e.at)} ${ROLE_LABEL[e.role]}`);
|
|
850
|
-
ctx.out(`${head}\n${e.text}\n\n`);
|
|
851
|
-
};
|
|
852
|
-
let last = 0;
|
|
853
|
-
const first = read();
|
|
854
|
-
for (const e of first.slice(-lines)) show(e);
|
|
855
|
-
last = first.at(-1)?.seq ?? 0;
|
|
856
|
-
if (parsed.values["no-follow"] === true) return 0;
|
|
857
|
-
ctx.err(t.paint("quiet", `Following ${rec.name}. Read-only; Ctrl+C to leave.\n`));
|
|
858
|
-
const record = spawnRecordPath(ctx.dataDir, rec.name);
|
|
859
|
-
for (;;) {
|
|
860
|
-
await new Promise((r) => setTimeout(r, 300));
|
|
861
|
-
for (const e of read()) if (e.seq > last) {
|
|
862
|
-
show(e);
|
|
863
|
-
last = e.seq;
|
|
864
|
-
}
|
|
865
|
-
if (!existsSync(record)) {
|
|
866
|
-
ctx.err(t.paint("quiet", `${rec.name} stopped.\n`));
|
|
867
|
-
return 0;
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
export { runAcpHostCmd, runAttach, runStop };
|
|
624
|
+
export { runAcpHostFromFile as n, stopRequestPath as r, killProcessTree as t };
|