@conveno/cli 0.2.0-rc.4 → 0.2.0-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,66 @@
1
+ import { t as ClientError } from "./dist-BYVibI3a.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,11 +1,9 @@
1
- import { n as connect } from "./dist-CiE50AoI.js";
2
- import { $ as isAllowed, Sn as SessionId, Yt as takeAcpLaunchFile, bn as RpcErrorCode, ft as parseAllowPatterns, q as formatContinuation, r as ConvenoError, sn as CliKind, tn as updateSpawnRecord } from "./dist-DUqXHTRg.js";
1
+ import { n as connect } from "./dist-BYVibI3a.js";
2
+ import { Ht as updateSpawnRecord, J as isAllowed, Jt as CliKind, Rt as takeAcpLaunchFile, W as formatContinuation, i as DEFAULT_ALLOW_RULES, in as RpcErrorCode, it as parseAllowPatterns, on as SessionId, r as ConvenoError } from "./dist-BTLBO1Rp.js";
3
3
  import { randomBytes } from "node:crypto";
4
- import { chmodSync, existsSync, renameSync, rmSync, writeFileSync } from "node:fs";
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 --allow`
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 --allow, but the agent offered no allow-once option`
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}: nobody watches this worker, and --allow does not cover it`
48
+ reason: `denied ${what}: the allow list does not cover it`
51
49
  };
52
50
  }
53
51
  };
54
- /** An agent message being streamed is written out at least this often. */
55
- const FLUSH_MS = 500;
56
- const clip = (s) => s.length <= 8e3 ? s : `${s.slice(0, 7990)}\n[clipped]`;
57
- var TurnLog = class {
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
- constructor(path, now = () => /* @__PURE__ */ new Date()) {
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 === "agent_message_chunk") {
98
- const c = u.content;
99
- if (c.type === "text" && c.text) {
100
- this.pending += c.text;
101
- if (this.pending.length >= 8e3) this.flush();
102
- else this.timer ??= setTimeout(() => this.flush(), FLUSH_MS);
103
- }
104
- return;
105
- }
106
- if (u.sessionUpdate === "tool_call" || u.sessionUpdate === "tool_call_update") {
107
- const t = u;
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
- /** Parse a turns file. Lines that are not entries are skipped. */
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.4";
74
+ const HOST_VERSION = "0.2.0-rc.6";
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
- turns;
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
- this.policy = deps.policy ?? new AllowListPolicy(rules.ok ? rules.rules : []);
240
- this.turns = new TurnLog(spec.turnsPath, deps.now);
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
- const res = await this.untilStopped(turn);
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((r) => this.turns.add("system", `Turn ended: ${r.stopReason}.`), () => void 0), new Promise((r) => setTimeout(r, grace).unref())]);
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.turns.update(n.update);
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.turns.tools.get(p.toolCall.toolCallId) ?? {};
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 nobody watches it and its spawn did not allow them:`,
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 owner can allow kinds of tool calls with: conveno spawn --acp --allow <kinds>. You may allow read, search and think with spawn_session's allow."
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 { stopRequestPath as i, parseTurns as n, runAcpHostFromFile as r, killProcessTree as t };
624
+ export { runAcpHostFromFile as n, stopRequestPath as r, killProcessTree as t };