@conveno/cli 0.2.0-rc.14 → 0.2.0-rc.16
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 +2 -2
- package/dist/{acp-OHqthTVC.js → acp-BtwJHwcr.js} +39 -7
- package/dist/{agy-relay-DLP2H1Rj.js → agy-relay-KS1DbLqD.js} +3 -2
- package/dist/{args-DmUsbNu9.js → args-CtyKPZuN.js} +17 -4
- package/dist/bin.js +2 -2
- package/dist/daemon.js +79 -9
- package/dist/{daemonError-CUE_dVn-.js → daemonError-DUP5zkiR.js} +1 -1
- package/dist/{dist-D-PhGsuL.js → dist-BqfYxlVP.js} +1 -1
- package/dist/{dist-BYkDv29h.js → dist-Ch3ohbIk.js} +2 -1
- package/dist/{dist-BRjg9CLd.js → dist-CkqMgCGl.js} +15 -4
- package/dist/{dist-BiV6HopA.js → dist-DVLAWfDg.js} +284 -40
- package/dist/{dist-1k5b8UGF.js → dist-DnWOZkAu.js} +221 -20
- package/dist/{dist-Cv5et1iE.js → dist-X1bpJWck.js} +1 -1
- package/dist/{dist-vefQHFb-.js → dist-XoKXwG-y.js} +1 -1
- package/dist/{dist-C4Ey9THP.js → dist-fwpPA9AY.js} +1 -1
- package/dist/{hook-mvifUk0K.js → hook-DHMu72Vf.js} +1 -1
- package/dist/{hook-entry-Cxh3yIdT.js → hook-entry-CLAuy_HJ.js} +6 -6
- package/dist/hook-entry-DY-CMxKE.js +1 -0
- package/dist/{main-BY7Kcf9S.js → main-DVIyOy85.js} +32 -16
- package/dist/{pick-ClIK4l8K.js → pick-UDFASnAn.js} +1 -1
- package/dist/{run-BYmOjvDF.js → run-B-UMVEQs.js} +4010 -1789
- package/dist/{runtime-PeEPWwix.js → runtime-CU-5JQvj.js} +36 -12
- package/dist/{uninstall-CQoGVhp3.js → uninstall-jwneyeJm.js} +7 -7
- package/dist/{watch-CaC2G2cT.js → watch-Cpp4Uwsd.js} +4 -4
- package/package.json +14 -13
- package/dist/hook-entry-De06GWme.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as connect } from "./dist-
|
|
2
|
-
import {
|
|
1
|
+
import { n as connect } from "./dist-Ch3ohbIk.js";
|
|
2
|
+
import { Bt as planProgram, Hn as RpcErrorCode, Kn as SessionId, Mn as CliKind, Sn as updateSpawnRecord, Tt as modelLabel, _ as accessAllows, c as NPX_SETUP_TIMEOUT_MS, et as findModelOption, f as SPAWN_TABLE, gn as takeAcpLaunchFile, i as ConvenoError, in as resolveAcpProgram, kn as writeModelMenu, nt as formatContinuation, tt as findOnPath, wt as menuFromConfigOptions } from "./dist-DnWOZkAu.js";
|
|
3
3
|
import { randomBytes } from "node:crypto";
|
|
4
4
|
import { existsSync, rmSync } from "node:fs";
|
|
5
5
|
import { Readable, Writable } from "node:stream";
|
|
@@ -13,7 +13,11 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
13
13
|
*/
|
|
14
14
|
function answer(ask, allow) {
|
|
15
15
|
const want = allow ? "allow_once" : "reject_once";
|
|
16
|
-
const
|
|
16
|
+
const candidates = ask.options.filter((o) => o.kind === want);
|
|
17
|
+
const option = allow ? candidates[0] : candidates.find((o) => {
|
|
18
|
+
const text = `${o.optionId} ${o.name}`;
|
|
19
|
+
return /decline|continue/i.test(text) && !/cancel|abort|differently/i.test(text);
|
|
20
|
+
}) ?? candidates[0];
|
|
17
21
|
return option ? {
|
|
18
22
|
outcome: "selected",
|
|
19
23
|
optionId: option.optionId
|
|
@@ -33,6 +37,26 @@ const CONVENO_TOOL_TITLE = new RegExp(`^(?:(?:running|run|calling|call|using|use
|
|
|
33
37
|
"spawn_session",
|
|
34
38
|
"answer_permission"
|
|
35
39
|
].join("|")})$`, "i");
|
|
40
|
+
/** The hidden subcommand that starts Antigravity's idle-wake relay (`RELAY_SUBCOMMAND` of its adapter). */
|
|
41
|
+
const RELAY_SUBCOMMAND = "agy-relay";
|
|
42
|
+
/** One word of a command line: quoted (no quote, `$` or backtick inside), or bare without shell metacharacters. */
|
|
43
|
+
const WORD = String.raw`"[^"'\r\n$\`]+"|'[^"'\r\n$\`]+'|[^\s"'\r\n$\`&|;<>()^%!*?{}]+`;
|
|
44
|
+
const unquote = (w) => /^["']/.test(w) ? w.slice(1, -1) : w;
|
|
45
|
+
const baseName = (w) => unquote(w).split(/[\\/]/).pop() ?? "";
|
|
46
|
+
const RELAY_TITLE = new RegExp(`^(?:(?:running|run|calling|call|using|use|execute|invoke)\\s+)?(\`?)(?:&\\s+)?(${WORD})(?:\\s+(${WORD}))?\\s+${RELAY_SUBCOMMAND}\\1$`, "i");
|
|
47
|
+
/**
|
|
48
|
+
* Is this execute call exactly Conveno's relay command: `conveno agy-relay`, with a path, a
|
|
49
|
+
* `.cmd`, `.exe` or `.ps1` ending, or `node <path>/bin.js agy-relay`, and nothing chained after it.
|
|
50
|
+
*/
|
|
51
|
+
function isRelayCommand(call) {
|
|
52
|
+
if (call.kind !== "execute") return false;
|
|
53
|
+
const m = RELAY_TITLE.exec((call.title ?? "").trim());
|
|
54
|
+
if (!m) return false;
|
|
55
|
+
const first = m[2] ?? "";
|
|
56
|
+
const second = m[3];
|
|
57
|
+
if (second === void 0) return /^conveno(?:\.(?:cmd|exe|ps1))?$/i.test(baseName(first));
|
|
58
|
+
return /^node(?:\.exe)?$/i.test(baseName(first)) && /^bin\.js$/i.test(baseName(second));
|
|
59
|
+
}
|
|
36
60
|
/** Kinds whose title is a command line or a path, so a title that looks like a tool name is not one. */
|
|
37
61
|
const COMMAND_OR_FILE_KINDS = /* @__PURE__ */ new Set([
|
|
38
62
|
"execute",
|
|
@@ -57,7 +81,7 @@ var AllowListPolicy = class {
|
|
|
57
81
|
}
|
|
58
82
|
async decide(ask, _signal) {
|
|
59
83
|
const what = `${ask.title ?? "a tool call"} (${ask.kind ?? "other"})`;
|
|
60
|
-
const own = convenoToolOf(ask) !== void 0;
|
|
84
|
+
const own = convenoToolOf(ask) !== void 0 || isRelayCommand(ask);
|
|
61
85
|
if (own || this.allows({
|
|
62
86
|
kind: ask.kind,
|
|
63
87
|
title: ask.title
|
|
@@ -134,8 +158,9 @@ var AskSpawnerPolicy = class {
|
|
|
134
158
|
return this.allow(ask, what, `allowed ${what}: ${deps.spawnerName} said always`);
|
|
135
159
|
case "deny": return this.deny(ask, what, `denied by ${deps.spawnerName}`);
|
|
136
160
|
case "unanswered":
|
|
161
|
+
case "worker_offline":
|
|
137
162
|
case "no_spawner": {
|
|
138
|
-
const why = reply.answer === "unanswered" ? `no answer in ${waitText(timeoutMs)}` : "no spawner to ask";
|
|
163
|
+
const why = reply.answer === "unanswered" ? `no answer in ${waitText(timeoutMs)}` : reply.answer === "worker_offline" ? "the worker went offline while waiting" : "no spawner to ask";
|
|
139
164
|
return deps.unanswered === "allow" ? this.allow(ask, what, `allowed ${what}: ${why}`) : this.deny(ask, what, why);
|
|
140
165
|
}
|
|
141
166
|
}
|
|
@@ -180,10 +205,10 @@ var ToolTracker = class {
|
|
|
180
205
|
return u.sessionUpdate === "tool_call" ? next.title ?? next.kind ?? "tool" : void 0;
|
|
181
206
|
}
|
|
182
207
|
};
|
|
183
|
-
const HOST_VERSION = "0.2.0-rc.
|
|
208
|
+
const HOST_VERSION = "0.2.0-rc.16";
|
|
184
209
|
/** A stop request file: `conveno stop` writes it next to the spawn record. */
|
|
185
210
|
const stopRequestPath = (recordPath) => recordPath.replace(/\.json$/, ".stop");
|
|
186
|
-
function withTimeout(p, ms, what) {
|
|
211
|
+
function withTimeout$1(p, ms, what) {
|
|
187
212
|
return new Promise((resolve, reject) => {
|
|
188
213
|
const t = setTimeout(() => reject(/* @__PURE__ */ new Error(`${what} did not answer within ${Math.round(ms / 1e3)} s.`)), ms);
|
|
189
214
|
p.then((v) => {
|
|
@@ -195,11 +220,11 @@ function withTimeout(p, ms, what) {
|
|
|
195
220
|
});
|
|
196
221
|
});
|
|
197
222
|
}
|
|
198
|
-
const errText = (e) => e instanceof Error ? e.message : String(e);
|
|
223
|
+
const errText$1 = (e) => e instanceof Error ? e.message : String(e);
|
|
199
224
|
/** A JSON-RPC error's own words: an agent that throws gets "Internal error" with the text in `data.details`. */
|
|
200
225
|
const requestReason = (e) => {
|
|
201
226
|
const details = e?.data?.details;
|
|
202
|
-
return typeof details === "string" && details.trim() !== "" ? details.trim() : errText(e);
|
|
227
|
+
return typeof details === "string" && details.trim() !== "" ? details.trim() : errText$1(e);
|
|
203
228
|
};
|
|
204
229
|
const describeStop = (r) => {
|
|
205
230
|
switch (r.kind) {
|
|
@@ -224,6 +249,8 @@ var AcpHost = class {
|
|
|
224
249
|
policy;
|
|
225
250
|
tools = new ToolTracker();
|
|
226
251
|
sessionId;
|
|
252
|
+
/** The model label, sent again with each heartbeat so a restarted daemon still shows it. */
|
|
253
|
+
modelLabel;
|
|
227
254
|
acpSessionId;
|
|
228
255
|
conn;
|
|
229
256
|
agent;
|
|
@@ -235,10 +262,18 @@ var AcpHost = class {
|
|
|
235
262
|
/** The status line after a failed prompt, kept until the next prompt starts. */
|
|
236
263
|
failedText;
|
|
237
264
|
denials = [];
|
|
238
|
-
/**
|
|
265
|
+
/** The last denied call, shown on the row until the next turn starts. */
|
|
239
266
|
deniedText;
|
|
240
267
|
/** The worker called Conveno's `send` (or `handoff`) in the turn that is running. */
|
|
241
268
|
sentThisTurn = false;
|
|
269
|
+
/** The daemon's `lastSentAt` of this session when the turn began. */
|
|
270
|
+
sentAtTurnStart;
|
|
271
|
+
/** The messages the next turn's prompt hands over; undefined for the first task. */
|
|
272
|
+
answering;
|
|
273
|
+
/** When the newest message from a session that the running turn hands over was sent. */
|
|
274
|
+
askedAt;
|
|
275
|
+
/** Status updates go out one after another, so a late one cannot overwrite a newer one. */
|
|
276
|
+
statusChain = Promise.resolve();
|
|
242
277
|
lastStatus;
|
|
243
278
|
timers = [];
|
|
244
279
|
constructor(spec, deps) {
|
|
@@ -282,7 +317,7 @@ var AcpHost = class {
|
|
|
282
317
|
} catch (e) {
|
|
283
318
|
if (!this.stopping) this.stop({
|
|
284
319
|
kind: "failed",
|
|
285
|
-
detail: errText(e)
|
|
320
|
+
detail: errText$1(e)
|
|
286
321
|
});
|
|
287
322
|
} finally {
|
|
288
323
|
process.off("SIGTERM", onSignal);
|
|
@@ -321,7 +356,7 @@ var AcpHost = class {
|
|
|
321
356
|
const app = client({ name: "conveno" }).onNotification(methods.client.session.update, ({ params }) => this.onUpdate(params)).onRequest(methods.client.session.requestPermission, ({ params }) => this.onPermission(params));
|
|
322
357
|
this.conn = app.connect(ndJsonStream(Writable.toWeb(agent.stdin), Readable.toWeb(agent.stdout)));
|
|
323
358
|
const conn = this.conn;
|
|
324
|
-
const init = await this.untilStopped(withTimeout(conn.agent.request(methods.agent.initialize, {
|
|
359
|
+
const init = await this.untilStopped(withTimeout$1(conn.agent.request(methods.agent.initialize, {
|
|
325
360
|
protocolVersion: PROTOCOL_VERSION,
|
|
326
361
|
clientCapabilities: {
|
|
327
362
|
fs: {
|
|
@@ -337,7 +372,7 @@ var AcpHost = class {
|
|
|
337
372
|
}), timeout, "initialize"));
|
|
338
373
|
const agentVersion = init.agentInfo?.version?.trim().slice(0, 64);
|
|
339
374
|
this.log(`initialize: protocol ${init.protocolVersion}, agent ${init.agentInfo?.name ?? "unknown"} ${agentVersion ?? ""}`);
|
|
340
|
-
const created = await this.untilStopped(withTimeout(conn.agent.request(methods.agent.session.new, {
|
|
375
|
+
const created = await this.untilStopped(withTimeout$1(conn.agent.request(methods.agent.session.new, {
|
|
341
376
|
cwd: spec.cwd,
|
|
342
377
|
mcpServers: spec.mcp ? [{
|
|
343
378
|
name: "conveno",
|
|
@@ -349,18 +384,19 @@ var AcpHost = class {
|
|
|
349
384
|
this.acpSessionId = created.sessionId;
|
|
350
385
|
this.log(`session/new: ${created.sessionId}`);
|
|
351
386
|
const mode = spec.mode;
|
|
352
|
-
if (mode && created.modes?.availableModes.some((m) => m.id === mode)) await this.untilStopped(withTimeout(conn.agent.request(methods.agent.session.setMode, {
|
|
387
|
+
if (mode && created.modes?.availableModes.some((m) => m.id === mode)) await this.untilStopped(withTimeout$1(conn.agent.request(methods.agent.session.setMode, {
|
|
353
388
|
sessionId: created.sessionId,
|
|
354
389
|
modeId: mode
|
|
355
|
-
}), timeout, "session/set_mode")).then(() => this.log(`mode: ${mode}`), (e) => this.log(`could not set mode ${mode}: ${errText(e)}`));
|
|
390
|
+
}), timeout, "session/set_mode")).then(() => this.log(`mode: ${mode}`), (e) => this.log(`could not set mode ${mode}: ${errText$1(e)}`));
|
|
356
391
|
else if (mode) {
|
|
357
392
|
const configId = modeConfigId(created.configOptions, mode);
|
|
358
|
-
if (configId) await this.untilStopped(withTimeout(conn.agent.request(methods.agent.session.setConfigOption, {
|
|
393
|
+
if (configId) await this.untilStopped(withTimeout$1(conn.agent.request(methods.agent.session.setConfigOption, {
|
|
359
394
|
sessionId: created.sessionId,
|
|
360
395
|
configId,
|
|
361
396
|
value: mode
|
|
362
|
-
}), timeout, "session/set_config_option")).then(() => this.log(`mode: ${mode} (config option ${configId})`), (e) => this.log(`could not set mode ${mode}: ${errText(e)}`));
|
|
397
|
+
}), timeout, "session/set_config_option")).then(() => this.log(`mode: ${mode} (config option ${configId})`), (e) => this.log(`could not set mode ${mode}: ${errText$1(e)}`));
|
|
363
398
|
}
|
|
399
|
+
const modelState = await this.applyModel(conn, created.sessionId, created.configOptions, timeout);
|
|
364
400
|
const spawnedBy = SessionId.safeParse(spec.spawnedBy);
|
|
365
401
|
const { session } = await this.client["session.register"]({
|
|
366
402
|
name: spec.name,
|
|
@@ -371,21 +407,75 @@ var AcpHost = class {
|
|
|
371
407
|
spawned: true,
|
|
372
408
|
acp: true,
|
|
373
409
|
...spawnedBy.success ? { spawnedBy: spawnedBy.data } : {},
|
|
374
|
-
...agentVersion ? { cliVersion: agentVersion } : {}
|
|
410
|
+
...agentVersion ? { cliVersion: agentVersion } : {},
|
|
411
|
+
...modelState.label ? { model: modelState.label.slice(0, 200) } : {}
|
|
375
412
|
});
|
|
376
413
|
this.sessionId = session.id;
|
|
414
|
+
this.modelLabel = modelState.label?.slice(0, 200);
|
|
377
415
|
await this.client["session.setNative"]({
|
|
378
416
|
sessionId: session.id,
|
|
379
417
|
nativeId: created.sessionId.slice(0, 256)
|
|
380
|
-
}).catch((e) => this.log(`could not record the ACP session id: ${errText(e)}`));
|
|
418
|
+
}).catch((e) => this.log(`could not record the ACP session id: ${errText$1(e)}`));
|
|
381
419
|
updateSpawnRecord(spec.record, {
|
|
382
420
|
pid: process.pid,
|
|
383
421
|
sessionId: session.id,
|
|
384
422
|
agentPid: agent.pid
|
|
385
423
|
});
|
|
386
424
|
this.log(`registered as ${session.name} (${session.id})`);
|
|
425
|
+
for (const note of modelState.notes) await this.tell(`[conveno] Worker ${spec.name}: ${note}`);
|
|
387
426
|
this.every(this.deps.heartbeatMs ?? 15e3, () => this.heartbeat());
|
|
388
427
|
}
|
|
428
|
+
/**
|
|
429
|
+
* Set the worker's model, then its effort (the effort list can change with the model), through
|
|
430
|
+
* the CLI's session config options. Never fails the worker: a name the CLI does not offer or an
|
|
431
|
+
* error keeps the CLI's default and leaves a note for the spawner.
|
|
432
|
+
*/
|
|
433
|
+
async applyModel(conn, sessionId, initial, timeout) {
|
|
434
|
+
const { spec } = this;
|
|
435
|
+
let options = initial;
|
|
436
|
+
const notes = [];
|
|
437
|
+
const set = async (kind, want) => {
|
|
438
|
+
if (!want) return;
|
|
439
|
+
const opt = findModelOption(options, kind);
|
|
440
|
+
if (!opt) {
|
|
441
|
+
this.log(`${kind}: '${want}' not offered; ${spec.cli} has no ${kind} choice here`);
|
|
442
|
+
notes.push(`${kind} '${want}' is not offered by ${spec.cli}: it has no ${kind} choice here.`);
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (!opt.values.some((v) => v.value === want)) {
|
|
446
|
+
const names = opt.values.map((v) => v.value);
|
|
447
|
+
const offered = names.slice(0, 20).join(", ") + (names.length > 20 ? ` and ${names.length - 20} more` : "");
|
|
448
|
+
this.log(`${kind}: '${want}' not offered${opt.current ? `; using ${opt.current}` : ""}. Offered: ${offered}`);
|
|
449
|
+
notes.push(`${kind} '${want}' is not offered by ${spec.cli}${opt.current ? `; it uses ${opt.current}` : ""}. Offered: ${offered}.`);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
try {
|
|
453
|
+
const r = await this.untilStopped(withTimeout$1(conn.agent.request(methods.agent.session.setConfigOption, {
|
|
454
|
+
sessionId,
|
|
455
|
+
configId: opt.id,
|
|
456
|
+
value: want
|
|
457
|
+
}), timeout, "session/set_config_option"));
|
|
458
|
+
if (Array.isArray(r?.configOptions) && r.configOptions.length > 0) options = r.configOptions;
|
|
459
|
+
} catch (e) {
|
|
460
|
+
this.log(`could not set ${kind} ${want}: ${errText$1(e)}`);
|
|
461
|
+
notes.push(`${kind} '${want}' could not be set on ${spec.cli}; it keeps its default.`);
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
await set("model", spec.model);
|
|
465
|
+
await set("effort", spec.effort);
|
|
466
|
+
const m = findModelOption(options, "model");
|
|
467
|
+
const e = findModelOption(options, "effort");
|
|
468
|
+
const label = modelLabel({
|
|
469
|
+
...m?.current ? { model: m.current } : {},
|
|
470
|
+
...e?.current ? { effort: e.current } : {}
|
|
471
|
+
});
|
|
472
|
+
if (label) this.log(`model: ${label}`);
|
|
473
|
+
if (spec.modelMenuPath && m) writeModelMenu(spec.modelMenuPath, CliKind.parse(spec.cli), menuFromConfigOptions(options, (/* @__PURE__ */ new Date()).toISOString()));
|
|
474
|
+
return {
|
|
475
|
+
label,
|
|
476
|
+
notes
|
|
477
|
+
};
|
|
478
|
+
}
|
|
389
479
|
async loop() {
|
|
390
480
|
let next = this.spec.task ?? null;
|
|
391
481
|
if (next === null) await this.status("idle", null);
|
|
@@ -403,6 +493,7 @@ var AcpHost = class {
|
|
|
403
493
|
sessionId: this.me,
|
|
404
494
|
allowContinue: true
|
|
405
495
|
});
|
|
496
|
+
this.answering = r.messages;
|
|
406
497
|
const next = formatContinuation(r.messages, r.orchestrator, r.remaining) || null;
|
|
407
498
|
if (next === null) await this.status(void 0, this.failedText ?? this.deniedText ?? null);
|
|
408
499
|
return next;
|
|
@@ -410,12 +501,12 @@ var AcpHost = class {
|
|
|
410
501
|
if (e instanceof ConvenoError && e.code === RpcErrorCode.NotFound) {
|
|
411
502
|
this.stop({
|
|
412
503
|
kind: "session-gone",
|
|
413
|
-
detail: errText(e)
|
|
504
|
+
detail: errText$1(e)
|
|
414
505
|
});
|
|
415
506
|
return null;
|
|
416
507
|
}
|
|
417
|
-
this.log(`turn.end failed: ${errText(e)}`);
|
|
418
|
-
await this.status("idle", null);
|
|
508
|
+
this.log(`turn.end failed: ${errText$1(e)}`);
|
|
509
|
+
await this.status("idle", this.failedText ?? this.deniedText ?? null);
|
|
419
510
|
return null;
|
|
420
511
|
}
|
|
421
512
|
}
|
|
@@ -432,6 +523,9 @@ var AcpHost = class {
|
|
|
432
523
|
this.denials = [];
|
|
433
524
|
this.deniedText = void 0;
|
|
434
525
|
this.sentThisTurn = false;
|
|
526
|
+
this.askedAt = (this.answering ?? []).filter((m) => m.kind !== "system").map((m) => m.createdAt).sort().at(-1);
|
|
527
|
+
this.answering = void 0;
|
|
528
|
+
this.sentAtTurnStart = await this.lastSentAt();
|
|
435
529
|
await this.status("busy", null);
|
|
436
530
|
const turn = conn.agent.request(methods.agent.session.prompt, {
|
|
437
531
|
sessionId: sid,
|
|
@@ -484,7 +578,10 @@ var AcpHost = class {
|
|
|
484
578
|
sessionId: id,
|
|
485
579
|
listenerId
|
|
486
580
|
});
|
|
487
|
-
if (r.messages.length > 0)
|
|
581
|
+
if (r.messages.length > 0) {
|
|
582
|
+
this.answering = r.messages;
|
|
583
|
+
return formatContinuation(r.messages, r.orchestrator, r.remaining);
|
|
584
|
+
}
|
|
488
585
|
if (r.superseded) {
|
|
489
586
|
this.log("turn.wake: superseded; listening again");
|
|
490
587
|
return null;
|
|
@@ -508,11 +605,11 @@ var AcpHost = class {
|
|
|
508
605
|
if (e instanceof ConvenoError && e.code === RpcErrorCode.NotFound) {
|
|
509
606
|
this.stop({
|
|
510
607
|
kind: "session-gone",
|
|
511
|
-
detail: errText(e)
|
|
608
|
+
detail: errText$1(e)
|
|
512
609
|
});
|
|
513
610
|
return null;
|
|
514
611
|
}
|
|
515
|
-
this.log(`waiting for work failed: ${errText(e)}`);
|
|
612
|
+
this.log(`waiting for work failed: ${errText$1(e)}`);
|
|
516
613
|
await new Promise((r) => setTimeout(r, Math.min(pollMs, 5e3)).unref());
|
|
517
614
|
return null;
|
|
518
615
|
} finally {
|
|
@@ -526,7 +623,7 @@ var AcpHost = class {
|
|
|
526
623
|
if (id !== void 0) this.noteConvenoCall(this.tools.tools.get(id));
|
|
527
624
|
if (doing !== void 0 && doing !== this.lastStatus) {
|
|
528
625
|
this.lastStatus = doing;
|
|
529
|
-
this.status(void 0, doing);
|
|
626
|
+
this.status(void 0, this.deniedText ?? doing);
|
|
530
627
|
}
|
|
531
628
|
}
|
|
532
629
|
async onPermission(p) {
|
|
@@ -551,10 +648,8 @@ var AcpHost = class {
|
|
|
551
648
|
if (!decision.allowed) {
|
|
552
649
|
const what = `${title ?? "a tool call"} (${kind ?? "other"})`;
|
|
553
650
|
this.denials.push(`${what}: ${decision.why ?? "it was not allowed"}`);
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
this.status(void 0, this.deniedText);
|
|
557
|
-
}
|
|
651
|
+
this.deniedText = `denied: ${title ?? what}`;
|
|
652
|
+
this.status(void 0, this.deniedText);
|
|
558
653
|
}
|
|
559
654
|
return { outcome: decision.outcome };
|
|
560
655
|
}
|
|
@@ -566,11 +661,33 @@ var AcpHost = class {
|
|
|
566
661
|
if (!this.sessionId) return;
|
|
567
662
|
const text = typeof statusText === "string" ? statusText.slice(0, 200) : statusText;
|
|
568
663
|
if (status === void 0 && text === void 0) return;
|
|
569
|
-
|
|
570
|
-
|
|
664
|
+
const sessionId = this.sessionId;
|
|
665
|
+
const send = () => this.client["session.setStatus"]({
|
|
666
|
+
sessionId,
|
|
571
667
|
...status ? { status } : {},
|
|
572
668
|
...text !== void 0 ? { statusText: text } : {}
|
|
573
669
|
}).catch(() => void 0);
|
|
670
|
+
const done = this.statusChain.then(send, send);
|
|
671
|
+
this.statusChain = done;
|
|
672
|
+
await done;
|
|
673
|
+
}
|
|
674
|
+
/** This session as the daemon has it now; undefined when unknown. */
|
|
675
|
+
async self() {
|
|
676
|
+
if (!this.sessionId) return void 0;
|
|
677
|
+
try {
|
|
678
|
+
const { sessions } = await this.client["session.list"]({ includeOffline: true });
|
|
679
|
+
return sessions.find((x) => x.id === this.sessionId);
|
|
680
|
+
} catch {
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
/** When the daemon last saw this session send a message; undefined if never, or unknown. */
|
|
685
|
+
async lastSentAt() {
|
|
686
|
+
return (await this.self())?.lastSentAt;
|
|
687
|
+
}
|
|
688
|
+
/** How a notice names this worker: by its name now, which a rename may have changed. */
|
|
689
|
+
async who() {
|
|
690
|
+
return `[conveno] Worker ${(await this.self())?.name ?? this.spec.name} (${this.spec.cli}, over ACP)`;
|
|
574
691
|
}
|
|
575
692
|
/** Show that the worker waits for its spawner's answer; null puts the usual status back. */
|
|
576
693
|
async waitingFor(title) {
|
|
@@ -579,11 +696,14 @@ var AcpHost = class {
|
|
|
579
696
|
async heartbeat() {
|
|
580
697
|
if (!this.sessionId) return;
|
|
581
698
|
try {
|
|
582
|
-
await this.client["session.heartbeat"]({
|
|
699
|
+
await this.client["session.heartbeat"]({
|
|
700
|
+
sessionId: this.sessionId,
|
|
701
|
+
...this.modelLabel ? { model: this.modelLabel } : {}
|
|
702
|
+
});
|
|
583
703
|
} catch (e) {
|
|
584
704
|
if (e instanceof ConvenoError && e.code === RpcErrorCode.NotFound) this.stop({
|
|
585
705
|
kind: "session-gone",
|
|
586
|
-
detail: errText(e)
|
|
706
|
+
detail: errText$1(e)
|
|
587
707
|
});
|
|
588
708
|
}
|
|
589
709
|
}
|
|
@@ -606,7 +726,7 @@ var AcpHost = class {
|
|
|
606
726
|
await this.status("idle", this.failedText);
|
|
607
727
|
if (reason === this.lastPromptFailure) return;
|
|
608
728
|
this.lastPromptFailure = reason;
|
|
609
|
-
await this.tell(
|
|
729
|
+
await this.tell(`${await this.who()} could not run a prompt: ${reason}. It keeps running and takes the next message.`);
|
|
610
730
|
}
|
|
611
731
|
/** Remember that the worker sent something this turn. Only Conveno's own send tools count. */
|
|
612
732
|
noteConvenoCall(call) {
|
|
@@ -623,9 +743,15 @@ var AcpHost = class {
|
|
|
623
743
|
const denials = this.denials;
|
|
624
744
|
this.denials = [];
|
|
625
745
|
if (!this.spec.spawnedBy) return;
|
|
626
|
-
|
|
746
|
+
let silent = finished && !this.sentThisTurn;
|
|
747
|
+
if (silent) {
|
|
748
|
+
const sent = await this.lastSentAt();
|
|
749
|
+
const askedAt = this.askedAt;
|
|
750
|
+
if (sent !== this.sentAtTurnStart) silent = false;
|
|
751
|
+
else if (sent !== void 0 && askedAt !== void 0 && sent >= askedAt) silent = false;
|
|
752
|
+
}
|
|
627
753
|
if (denials.length === 0 && !silent) return;
|
|
628
|
-
const who =
|
|
754
|
+
const who = await this.who();
|
|
629
755
|
const lines = [];
|
|
630
756
|
if (silent) lines.push(`${who} finished its turn without replying.`);
|
|
631
757
|
if (denials.length > 0) {
|
|
@@ -645,7 +771,7 @@ var AcpHost = class {
|
|
|
645
771
|
kind: "text",
|
|
646
772
|
body: { text }
|
|
647
773
|
}).catch((e) => {
|
|
648
|
-
this.log(`could not message the spawner: ${errText(e)}`);
|
|
774
|
+
this.log(`could not message the spawner: ${errText$1(e)}`);
|
|
649
775
|
});
|
|
650
776
|
}
|
|
651
777
|
every(ms, fn) {
|
|
@@ -686,7 +812,7 @@ var AcpHost = class {
|
|
|
686
812
|
}
|
|
687
813
|
if (this.sessionId) {
|
|
688
814
|
const why = describeStop(reason);
|
|
689
|
-
if (reason.kind !== "session-gone") await this.tell(
|
|
815
|
+
if (reason.kind !== "session-gone") await this.tell(`${await this.who()} stopped: ${why}. Its session is now offline.`);
|
|
690
816
|
await this.client["session.unregister"]({ sessionId: this.sessionId }).catch(() => void 0);
|
|
691
817
|
}
|
|
692
818
|
rmSync(this.spec.record, { force: true });
|
|
@@ -786,6 +912,124 @@ function startAgentProcess(opts) {
|
|
|
786
912
|
});
|
|
787
913
|
});
|
|
788
914
|
}
|
|
915
|
+
/** An agent that throws gets "Internal error" from the SDK, with its own words in `data.details`. */
|
|
916
|
+
const errText = (e) => {
|
|
917
|
+
const details = e?.data?.details;
|
|
918
|
+
if (typeof details === "string" && details.trim() !== "") return details.trim();
|
|
919
|
+
return e instanceof Error ? e.message : String(e);
|
|
920
|
+
};
|
|
921
|
+
function withTimeout(p, ms, what) {
|
|
922
|
+
let timer;
|
|
923
|
+
const late = new Promise((_, reject) => {
|
|
924
|
+
timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`${what} timed out after ${ms / 1e3}s.`)), ms);
|
|
925
|
+
});
|
|
926
|
+
return Promise.race([p, late]).finally(() => clearTimeout(timer));
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* Start `cli`'s ACP server, read the models and efforts it offers, and stop it (with everything it
|
|
930
|
+
* started). Never throws: a failure comes back as a message fit to show.
|
|
931
|
+
*/
|
|
932
|
+
async function probeModelMenu(opts) {
|
|
933
|
+
const platform = opts.platform;
|
|
934
|
+
const spec = SPAWN_TABLE[opts.cli]?.acp;
|
|
935
|
+
let launch;
|
|
936
|
+
let timeout = opts.timeoutMs ?? 6e4;
|
|
937
|
+
if (opts.command) launch = {
|
|
938
|
+
file: opts.command.file,
|
|
939
|
+
args: opts.command.args
|
|
940
|
+
};
|
|
941
|
+
else {
|
|
942
|
+
if (!spec) return {
|
|
943
|
+
ok: false,
|
|
944
|
+
message: `${opts.cli} cannot run in the background.`
|
|
945
|
+
};
|
|
946
|
+
const res = resolveAcpProgram(opts.cli, spec, {
|
|
947
|
+
env: opts.env,
|
|
948
|
+
which: opts.which ?? ((name) => findOnPath(name, opts.env, platform)),
|
|
949
|
+
npxConsent: opts.npxConsent
|
|
950
|
+
});
|
|
951
|
+
if (!res.ok) return {
|
|
952
|
+
ok: false,
|
|
953
|
+
message: res.reason === "no-npx" ? `${opts.cli} needs npx to start, and npx was not found. Install Node.js.` : `${opts.cli} is not installed for background workers. Run conveno init to set it up.`
|
|
954
|
+
};
|
|
955
|
+
if (res.run.source.startsWith("npx:") && opts.timeoutMs === void 0) timeout = NPX_SETUP_TIMEOUT_MS;
|
|
956
|
+
launch = planProgram(res.run.program, [...res.run.args, ...spec.args], {
|
|
957
|
+
platform,
|
|
958
|
+
env: opts.env
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
const CANCELLED = "Cancelled.";
|
|
962
|
+
if (opts.signal?.aborted) return {
|
|
963
|
+
ok: false,
|
|
964
|
+
message: CANCELLED
|
|
965
|
+
};
|
|
966
|
+
let agent;
|
|
967
|
+
let onAbort;
|
|
968
|
+
const cancelled = new Promise((_, reject) => {
|
|
969
|
+
onAbort = () => {
|
|
970
|
+
agent?.killTree();
|
|
971
|
+
reject(/* @__PURE__ */ new Error(CANCELLED));
|
|
972
|
+
};
|
|
973
|
+
opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
974
|
+
});
|
|
975
|
+
cancelled.catch(() => void 0);
|
|
976
|
+
try {
|
|
977
|
+
agent = await startAgentProcess({
|
|
978
|
+
file: launch.file,
|
|
979
|
+
args: launch.args,
|
|
980
|
+
cwd: opts.home,
|
|
981
|
+
env: opts.env,
|
|
982
|
+
platform,
|
|
983
|
+
stderr: new Writable({ write: (_c, _e, done) => done() }),
|
|
984
|
+
...launch.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
|
|
985
|
+
});
|
|
986
|
+
if (opts.signal?.aborted) return {
|
|
987
|
+
ok: false,
|
|
988
|
+
message: CANCELLED
|
|
989
|
+
};
|
|
990
|
+
const gone = agent.exited.then(({ code, signal }) => {
|
|
991
|
+
throw new Error(`${opts.cli} stopped before it answered (${signal ?? `exit ${code}`}).`);
|
|
992
|
+
});
|
|
993
|
+
gone.catch(() => void 0);
|
|
994
|
+
const conn = client({ name: "conveno" }).connect(ndJsonStream(Writable.toWeb(agent.stdin), Readable.toWeb(agent.stdout)));
|
|
995
|
+
const step = (p, what) => Promise.race([
|
|
996
|
+
withTimeout(p, timeout, what),
|
|
997
|
+
gone,
|
|
998
|
+
cancelled
|
|
999
|
+
]);
|
|
1000
|
+
await step(conn.agent.request(methods.agent.initialize, {
|
|
1001
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
1002
|
+
clientCapabilities: {
|
|
1003
|
+
fs: {
|
|
1004
|
+
readTextFile: false,
|
|
1005
|
+
writeTextFile: false
|
|
1006
|
+
},
|
|
1007
|
+
terminal: false
|
|
1008
|
+
},
|
|
1009
|
+
clientInfo: {
|
|
1010
|
+
name: "conveno",
|
|
1011
|
+
version: "probe"
|
|
1012
|
+
}
|
|
1013
|
+
}), "initialize");
|
|
1014
|
+
const created = await step(conn.agent.request(methods.agent.session.new, {
|
|
1015
|
+
cwd: opts.home,
|
|
1016
|
+
mcpServers: []
|
|
1017
|
+
}), "session/new");
|
|
1018
|
+
const at = (opts.now?.() ?? /* @__PURE__ */ new Date()).toISOString();
|
|
1019
|
+
return {
|
|
1020
|
+
ok: true,
|
|
1021
|
+
menu: menuFromConfigOptions(created.configOptions, at)
|
|
1022
|
+
};
|
|
1023
|
+
} catch (e) {
|
|
1024
|
+
return {
|
|
1025
|
+
ok: false,
|
|
1026
|
+
message: opts.signal?.aborted ? CANCELLED : errText(e)
|
|
1027
|
+
};
|
|
1028
|
+
} finally {
|
|
1029
|
+
if (onAbort) opts.signal?.removeEventListener("abort", onAbort);
|
|
1030
|
+
agent?.killTree();
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
789
1033
|
/**
|
|
790
1034
|
* `conveno acp-host <launch file>`: read and delete the launch file, connect to the daemon and
|
|
791
1035
|
* drive the worker until it stops. Returns the exit code.
|
|
@@ -813,4 +1057,4 @@ async function runAcpHostFromFile(path, opts = {}) {
|
|
|
813
1057
|
await client.close().catch(() => void 0);
|
|
814
1058
|
}
|
|
815
1059
|
}
|
|
816
|
-
export {
|
|
1060
|
+
export { stopRequestPath as i, probeModelMenu as n, runAcpHostFromFile as r, killProcessTree as t };
|