@conveno/cli 0.2.0-rc.5 → 0.2.0-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -30
- package/dist/acp-9pRRszwU.js +82 -0
- package/dist/agy-relay-C-nqvieJ.js +137 -0
- package/dist/args-C7Agak9f.js +321 -0
- package/dist/bin.js +2 -2
- package/dist/{ctx-CDLE-2f2.js → ctx-tYftvhz_.js} +2 -3
- package/dist/daemon.js +410 -1423
- package/dist/daemonError-DNAKEyRT.js +66 -0
- package/dist/{dist-TrWRppjR.js → dist-D2hMvcZu.js} +592 -1216
- package/dist/dist-D9Gu-mQm.js +547 -0
- package/dist/dist-DOGlDbRb.js +504 -0
- package/dist/{dist-BPPOKmbH.js → dist-DOKVrSIw.js} +39 -148
- package/dist/dist-Dd31Fg0h.js +671 -0
- package/dist/{dist-CEJ2-wxh.js → dist-ftx5RNCp.js} +4 -17
- package/dist/{dist-E3XvoT1Q.js → dist-iFaY42Bs.js} +1 -1
- package/dist/{doctor-CzIGTeNT.js → doctor-BYa-MApu.js} +109 -102
- package/dist/fmt-C2SsP5Y0.js +96 -0
- package/dist/{hook-CLB_muZS.js → hook-CQeSn-w4.js} +7 -5
- package/dist/hook-entry-BXmSN--S.js +2490 -0
- package/dist/hook-entry-CgiSN-Oj.js +1 -0
- package/dist/main-seh-HPZO.js +971 -0
- package/dist/pick-DoyocW55.js +9 -0
- package/dist/{run-CYH0CRbp.js → run-B-WfNtCX.js} +627 -1998
- package/dist/{runtime-B1Pb9Qqg.js → runtime-Bnjh9BQ8.js} +119 -210
- package/dist/{dist-C8JRuLiZ.js → toml-patch-DGzVRdd1.js} +20 -1890
- package/dist/watch-Dr2RdyGo.js +185 -0
- package/package.json +15 -15
- package/dist/acp-BD7Oaerg.js +0 -142
- package/dist/args-BRB8QEQM.js +0 -554
- package/dist/dist-DcmKjrmu.js +0 -271
- package/dist/hook-entry-BlvSoNMm.js +0 -1289
- package/dist/hook-entry-CRDh36pe.js +0 -1
- package/dist/main-CsCsyq2G.js +0 -1645
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { n as connect } from "./dist-
|
|
2
|
-
import {
|
|
1
|
+
import { n as connect } from "./dist-ftx5RNCp.js";
|
|
2
|
+
import { Bt as takeAcpLaunchFile, Gt as updateSpawnRecord, W as formatContinuation, Y as isAllowed, Zt as CliKind, at as parseAllowPatterns, i as DEFAULT_ALLOW_RULES, ln as SessionId, r as ConvenoError, sn as RpcErrorCode } from "./dist-D2hMvcZu.js";
|
|
3
3
|
import { randomBytes } from "node:crypto";
|
|
4
|
-
import {
|
|
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
8
|
// ../acp/dist/index.js
|
|
11
9
|
/**
|
|
@@ -36,144 +34,44 @@ var AllowListPolicy = class {
|
|
|
36
34
|
if (outcome.outcome === "selected") return {
|
|
37
35
|
allowed: true,
|
|
38
36
|
outcome,
|
|
39
|
-
reason: `allowed ${what} by
|
|
37
|
+
reason: `allowed ${what} by the allow list`
|
|
40
38
|
};
|
|
41
39
|
return {
|
|
42
40
|
allowed: false,
|
|
43
41
|
outcome: answer(ask, false),
|
|
44
|
-
reason: `denied ${what}: allowed by
|
|
42
|
+
reason: `denied ${what}: allowed by the allow list, but the agent offered no allow-once option`
|
|
45
43
|
};
|
|
46
44
|
}
|
|
47
45
|
return {
|
|
48
46
|
allowed: false,
|
|
49
47
|
outcome: answer(ask, false),
|
|
50
|
-
reason: `denied ${what}:
|
|
48
|
+
reason: `denied ${what}: the allow list does not cover it`
|
|
51
49
|
};
|
|
52
50
|
}
|
|
53
51
|
};
|
|
54
|
-
/**
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
path;
|
|
59
|
-
now;
|
|
60
|
-
entries = [];
|
|
61
|
-
seq = 0;
|
|
62
|
-
pending = "";
|
|
63
|
-
timer;
|
|
64
|
-
size = 0;
|
|
65
|
-
writes = Promise.resolve();
|
|
66
|
-
/** 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. */
|
|
67
56
|
tools = /* @__PURE__ */ new Map();
|
|
68
|
-
|
|
69
|
-
this.path = path;
|
|
70
|
-
this.now = now;
|
|
71
|
-
if (path) {
|
|
72
|
-
writeFileSync(path, "", { mode: 384 });
|
|
73
|
-
try {
|
|
74
|
-
chmodSync(path, 384);
|
|
75
|
-
} catch {}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/** The entries in memory, oldest first. */
|
|
79
|
-
recent(n = 200) {
|
|
80
|
-
return this.entries.slice(-n);
|
|
81
|
-
}
|
|
82
|
-
add(role, text) {
|
|
83
|
-
if (role !== "assistant") this.flush();
|
|
84
|
-
if (text === "") return;
|
|
85
|
-
const entry = {
|
|
86
|
-
seq: ++this.seq,
|
|
87
|
-
role,
|
|
88
|
-
text: clip(redact(text)),
|
|
89
|
-
at: this.now().toISOString()
|
|
90
|
-
};
|
|
91
|
-
this.entries.push(entry);
|
|
92
|
-
if (this.entries.length > 200) this.entries.splice(0, this.entries.length - 200);
|
|
93
|
-
this.write(entry);
|
|
94
|
-
}
|
|
95
|
-
/** 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. */
|
|
96
58
|
update(u) {
|
|
97
|
-
if (u.sessionUpdate
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const next = {
|
|
109
|
-
...this.tools.get(t.toolCallId) ?? {},
|
|
110
|
-
...t.title ? { title: t.title } : {},
|
|
111
|
-
...t.kind ? { kind: t.kind } : {}
|
|
112
|
-
};
|
|
113
|
-
this.tools.set(t.toolCallId, next);
|
|
114
|
-
if (this.tools.size > 1e3) {
|
|
115
|
-
const first = this.tools.keys().next().value;
|
|
116
|
-
if (first !== void 0) this.tools.delete(first);
|
|
117
|
-
}
|
|
118
|
-
const title = next.title ?? next.kind ?? "tool";
|
|
119
|
-
if (u.sessionUpdate === "tool_call") {
|
|
120
|
-
this.add("tool", `${title}${next.kind ? ` (${next.kind})` : ""}`);
|
|
121
|
-
return title;
|
|
122
|
-
}
|
|
123
|
-
if (t.status === "completed" || t.status === "failed") this.add("tool", `${title}: ${t.status}`);
|
|
124
|
-
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);
|
|
125
70
|
}
|
|
126
|
-
|
|
127
|
-
/** Write out the agent message streamed so far. */
|
|
128
|
-
flush() {
|
|
129
|
-
if (this.timer) clearTimeout(this.timer);
|
|
130
|
-
this.timer = void 0;
|
|
131
|
-
const text = this.pending;
|
|
132
|
-
this.pending = "";
|
|
133
|
-
if (text.trim() !== "") this.add("assistant", text);
|
|
134
|
-
}
|
|
135
|
-
/** Resolves once every entry so far is on disk. */
|
|
136
|
-
async settle() {
|
|
137
|
-
this.flush();
|
|
138
|
-
await this.writes;
|
|
139
|
-
}
|
|
140
|
-
write(entry) {
|
|
141
|
-
const path = this.path;
|
|
142
|
-
if (!path) return;
|
|
143
|
-
const line = `${JSON.stringify(entry)}\n`;
|
|
144
|
-
this.writes = this.writes.then(async () => {
|
|
145
|
-
try {
|
|
146
|
-
if (this.size + line.length > 1e6) {
|
|
147
|
-
const text = this.entries.map((e) => `${JSON.stringify(e)}\n`).join("");
|
|
148
|
-
writeFileSync(`${path}.tmp`, text, { mode: 384 });
|
|
149
|
-
renameSync(`${path}.tmp`, path);
|
|
150
|
-
this.size = text.length;
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
await appendFile(path, line, { mode: 384 });
|
|
154
|
-
this.size += line.length;
|
|
155
|
-
} catch {}
|
|
156
|
-
});
|
|
71
|
+
return u.sessionUpdate === "tool_call" ? next.title ?? next.kind ?? "tool" : void 0;
|
|
157
72
|
}
|
|
158
73
|
};
|
|
159
|
-
|
|
160
|
-
function parseTurns(text) {
|
|
161
|
-
const out = [];
|
|
162
|
-
for (const line of text.split("\n")) {
|
|
163
|
-
if (line.trim() === "") continue;
|
|
164
|
-
try {
|
|
165
|
-
const v = JSON.parse(line);
|
|
166
|
-
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({
|
|
167
|
-
seq: v.seq,
|
|
168
|
-
role: v.role,
|
|
169
|
-
text: v.text,
|
|
170
|
-
at: v.at
|
|
171
|
-
});
|
|
172
|
-
} catch {}
|
|
173
|
-
}
|
|
174
|
-
return out;
|
|
175
|
-
}
|
|
176
|
-
const HOST_VERSION = "0.2.0-rc.5";
|
|
74
|
+
const HOST_VERSION = "0.2.0-rc.7";
|
|
177
75
|
/** A stop request file: `conveno stop` writes it next to the spawn record. */
|
|
178
76
|
const stopRequestPath = (recordPath) => recordPath.replace(/\.json$/, ".stop");
|
|
179
77
|
function withTimeout(p, ms, what) {
|
|
@@ -215,7 +113,7 @@ var AcpHost = class {
|
|
|
215
113
|
client;
|
|
216
114
|
log;
|
|
217
115
|
policy;
|
|
218
|
-
|
|
116
|
+
tools = new ToolTracker();
|
|
219
117
|
sessionId;
|
|
220
118
|
acpSessionId;
|
|
221
119
|
conn;
|
|
@@ -236,8 +134,8 @@ var AcpHost = class {
|
|
|
236
134
|
this.client = deps.client;
|
|
237
135
|
this.log = deps.log ?? ((line) => process.stderr.write(`[conveno acp-host] ${line}\n`));
|
|
238
136
|
const rules = parseAllowPatterns(spec.allow);
|
|
239
|
-
|
|
240
|
-
this.
|
|
137
|
+
const narrowed = rules.ok && rules.rules.length > 0 ? rules.rules : DEFAULT_ALLOW_RULES;
|
|
138
|
+
this.policy = deps.policy ?? new AllowListPolicy(narrowed);
|
|
241
139
|
}
|
|
242
140
|
/** Ask the host to stop. The first reason wins. */
|
|
243
141
|
stop(reason) {
|
|
@@ -329,6 +227,11 @@ var AcpHost = class {
|
|
|
329
227
|
}), timeout, "session/new"));
|
|
330
228
|
this.acpSessionId = created.sessionId;
|
|
331
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)}`));
|
|
332
235
|
const spawnedBy = SessionId.safeParse(spec.spawnedBy);
|
|
333
236
|
const { session } = await this.client["session.register"]({
|
|
334
237
|
name: spec.name,
|
|
@@ -348,11 +251,6 @@ var AcpHost = class {
|
|
|
348
251
|
agentPid: agent.pid
|
|
349
252
|
});
|
|
350
253
|
this.log(`registered as ${session.name} (${session.id})`);
|
|
351
|
-
await this.client["session.setCliInfo"]({
|
|
352
|
-
pid: process.pid,
|
|
353
|
-
cliSessionId: created.sessionId.slice(0, 200),
|
|
354
|
-
transcriptPath: spec.turnsPath
|
|
355
|
-
}).catch((e) => this.log(`could not report the turn log: ${errText(e)}`));
|
|
356
254
|
this.every(this.deps.heartbeatMs ?? 15e3, () => this.heartbeat());
|
|
357
255
|
}
|
|
358
256
|
async loop() {
|
|
@@ -396,7 +294,6 @@ var AcpHost = class {
|
|
|
396
294
|
this.turnCtl = new AbortController();
|
|
397
295
|
this.failedText = void 0;
|
|
398
296
|
this.denials = [];
|
|
399
|
-
this.turns.add("user", text);
|
|
400
297
|
await this.status("busy", null);
|
|
401
298
|
const turn = conn.agent.request(methods.agent.session.prompt, {
|
|
402
299
|
sessionId: sid,
|
|
@@ -406,21 +303,17 @@ var AcpHost = class {
|
|
|
406
303
|
}]
|
|
407
304
|
});
|
|
408
305
|
try {
|
|
409
|
-
|
|
410
|
-
this.turns.flush();
|
|
411
|
-
if (res.stopReason !== "end_turn") this.turns.add("system", `Turn ended: ${res.stopReason}.`);
|
|
306
|
+
await this.untilStopped(turn);
|
|
412
307
|
} catch (e) {
|
|
413
|
-
this.turns.flush();
|
|
414
308
|
if (!this.stopping) {
|
|
415
309
|
const reason = requestReason(e);
|
|
416
|
-
this.turns.add("system", `The prompt failed: ${reason}`);
|
|
417
310
|
this.log(`session/prompt failed: ${reason}`);
|
|
418
311
|
await this.promptFailed(reason);
|
|
419
312
|
return;
|
|
420
313
|
}
|
|
421
314
|
await conn.agent.notify(methods.agent.session.cancel, { sessionId: sid }).catch(() => void 0);
|
|
422
315
|
const grace = this.deps.stopGraceMs ?? 5e3;
|
|
423
|
-
await Promise.race([turn.then((
|
|
316
|
+
await Promise.race([turn.then(() => void 0, () => void 0), new Promise((r) => setTimeout(r, grace).unref())]);
|
|
424
317
|
}
|
|
425
318
|
}
|
|
426
319
|
/**
|
|
@@ -488,7 +381,7 @@ var AcpHost = class {
|
|
|
488
381
|
}
|
|
489
382
|
onUpdate(n) {
|
|
490
383
|
if (n.sessionId !== this.acpSessionId) return;
|
|
491
|
-
const doing = this.
|
|
384
|
+
const doing = this.tools.update(n.update);
|
|
492
385
|
if (doing !== void 0 && doing !== this.lastStatus) {
|
|
493
386
|
this.lastStatus = doing;
|
|
494
387
|
this.status(void 0, doing);
|
|
@@ -496,7 +389,7 @@ var AcpHost = class {
|
|
|
496
389
|
}
|
|
497
390
|
async onPermission(p) {
|
|
498
391
|
if (this.turnCtl.signal.aborted) return { outcome: { outcome: "cancelled" } };
|
|
499
|
-
const known = this.
|
|
392
|
+
const known = this.tools.tools.get(p.toolCall.toolCallId) ?? {};
|
|
500
393
|
const title = p.toolCall.title ?? known.title;
|
|
501
394
|
const kind = p.toolCall.kind ?? known.kind;
|
|
502
395
|
const ask = {
|
|
@@ -509,7 +402,6 @@ var AcpHost = class {
|
|
|
509
402
|
const decision = await Promise.race([this.policy.decide(ask, signal), new Promise((r) => signal.addEventListener("abort", () => r(null), { once: true }))]);
|
|
510
403
|
if (decision === null) return { outcome: { outcome: "cancelled" } };
|
|
511
404
|
this.log(`permission: ${decision.reason}`);
|
|
512
|
-
this.turns.add("system", `Permission ${decision.allowed ? "granted" : "denied"}: ${title ?? kind ?? "tool call"}.`);
|
|
513
405
|
if (!decision.allowed) this.denials.push(`${title ?? "a tool call"} (${kind ?? "other"})`);
|
|
514
406
|
return { outcome: decision.outcome };
|
|
515
407
|
}
|
|
@@ -566,9 +458,9 @@ var AcpHost = class {
|
|
|
566
458
|
if (this.denials.length > 5) list.push(`- and ${this.denials.length - 5} more`);
|
|
567
459
|
this.denials = [];
|
|
568
460
|
await this.tell([
|
|
569
|
-
`[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:`,
|
|
570
462
|
...list,
|
|
571
|
-
"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."
|
|
572
464
|
].join("\n"));
|
|
573
465
|
}
|
|
574
466
|
/** Send a text message from this session to its spawner. Never throws. */
|
|
@@ -611,7 +503,6 @@ var AcpHost = class {
|
|
|
611
503
|
kind: "failed",
|
|
612
504
|
detail: "unknown"
|
|
613
505
|
};
|
|
614
|
-
await this.turns.settle();
|
|
615
506
|
const agent = this.agent;
|
|
616
507
|
if (agent) {
|
|
617
508
|
this.conn?.close();
|
|
@@ -730,4 +621,4 @@ async function runAcpHostFromFile(path, opts = {}) {
|
|
|
730
621
|
await client.close().catch(() => void 0);
|
|
731
622
|
}
|
|
732
623
|
}
|
|
733
|
-
export {
|
|
624
|
+
export { runAcpHostFromFile as n, stopRequestPath as r, killProcessTree as t };
|