@conveno/cli 0.2.0-rc.12 → 0.2.0-rc.14
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 +1 -1
- package/dist/{acp-CIzgcCp9.js → acp-OHqthTVC.js} +3 -3
- package/dist/{agy-relay-Y9o-Pw9U.js → agy-relay-DLP2H1Rj.js} +2 -2
- package/dist/{args-C1eX8Ixk.js → args-DmUsbNu9.js} +13 -5
- package/dist/bin.js +16 -2
- package/dist/daemon.js +235 -12
- package/dist/{daemonError-0KnkgIRo.js → daemonError-CUE_dVn-.js} +1 -1
- package/dist/{dist-CRj_cuHc.js → dist-1k5b8UGF.js} +295 -88
- package/dist/{dist-B3YYLzKS.js → dist-BYkDv29h.js} +17 -5
- package/dist/{dist-4iJnF07i.js → dist-BiV6HopA.js} +223 -31
- package/dist/{dist-DeN0jR3I.js → dist-C4Ey9THP.js} +1 -1
- package/dist/{dist-BjATai4T.js → dist-Cv5et1iE.js} +26 -5
- package/dist/{dist-DF0nL8wE.js → dist-D-PhGsuL.js} +3 -2
- package/dist/{dist-Du1hwaux.js → dist-vefQHFb-.js} +37 -1
- package/dist/{hook-entry-DWa1oppt.js → hook-entry-Cxh3yIdT.js} +9 -9
- package/dist/hook-entry-De06GWme.js +1 -0
- package/dist/{hook-ByduyOom.js → hook-mvifUk0K.js} +46 -12
- package/dist/{main-WIfawg60.js → main-BY7Kcf9S.js} +36 -20
- package/dist/{pick-BmZuv9yQ.js → pick-ClIK4l8K.js} +1 -1
- package/dist/{run-Df6vFm9n.js → run-BYmOjvDF.js} +435 -41
- package/dist/{runtime-BKPod_ZQ.js → runtime-PeEPWwix.js} +65 -17
- package/dist/{uninstall-MaS5t1CK.js → uninstall-CQoGVhp3.js} +204 -8
- package/dist/{watch-CPkilo9L.js → watch-CaC2G2cT.js} +4 -4
- package/package.json +13 -13
- package/dist/hook-entry-ajdMBSpY.js +0 -1
|
@@ -3,7 +3,7 @@ import { mkdir, open, readFile, rm, stat } from "node:fs/promises";
|
|
|
3
3
|
import { createConnection } from "node:net";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
|
-
import {
|
|
6
|
+
import { B as dataDir, Bn as defaultSocketPath, Fn as RpcResponse, Hn as ipcMethods, Mn as PROTOCOL_VERSION, N as clientProof, On as EventPayload, Pn as RpcErrorCode, Rt as proofsMatch, St as newAuthNonce, Un as isSocketPathTooLong, V as dataPaths, Vn as encodeFrame, er as socketPathTooLongMessage, i as ConvenoError, z as daemonProof, zn as createLineDecoder } from "./dist-1k5b8UGF.js";
|
|
7
7
|
// ../client/dist/index.js
|
|
8
8
|
const DEFAULT_REQUEST_TIMEOUT_MS = 5e3;
|
|
9
9
|
const DEFAULT_START_TIMEOUT_MS = 1e4;
|
|
@@ -12,6 +12,7 @@ const CLIENT_METHODS = [
|
|
|
12
12
|
"session.register",
|
|
13
13
|
"session.heartbeat",
|
|
14
14
|
"session.unregister",
|
|
15
|
+
"session.remove",
|
|
15
16
|
"session.rename",
|
|
16
17
|
"session.setStatus",
|
|
17
18
|
"session.byHost",
|
|
@@ -25,6 +26,8 @@ const CLIENT_METHODS = [
|
|
|
25
26
|
"session.list",
|
|
26
27
|
"orchestrator.claim",
|
|
27
28
|
"orchestrator.clear",
|
|
29
|
+
"permission.ask",
|
|
30
|
+
"permission.answer",
|
|
28
31
|
"message.send",
|
|
29
32
|
"message.inbox",
|
|
30
33
|
"message.deliver",
|
|
@@ -53,6 +56,7 @@ const NOT_REPLAYABLE = /* @__PURE__ */ new Set([
|
|
|
53
56
|
"daemon.shutdown",
|
|
54
57
|
"turn.end",
|
|
55
58
|
"turn.wake",
|
|
59
|
+
"permission.ask",
|
|
56
60
|
"devices.pair",
|
|
57
61
|
"devices.pairConfirm",
|
|
58
62
|
"devices.revoke",
|
|
@@ -147,6 +151,8 @@ var Connection = class {
|
|
|
147
151
|
pending = /* @__PURE__ */ new Map();
|
|
148
152
|
decoder = createLineDecoder();
|
|
149
153
|
closed = false;
|
|
154
|
+
/** The daemon's version, from its `hello` answer. */
|
|
155
|
+
daemonVersion;
|
|
150
156
|
constructor(socket, timeoutMs, onEvent = () => {}) {
|
|
151
157
|
this.socket = socket;
|
|
152
158
|
this.timeoutMs = timeoutMs;
|
|
@@ -183,14 +189,14 @@ var Connection = class {
|
|
|
183
189
|
p.reject(e);
|
|
184
190
|
}
|
|
185
191
|
}
|
|
186
|
-
call(method, params) {
|
|
192
|
+
call(method, params, timeoutMs = this.timeoutMs) {
|
|
187
193
|
if (this.closed) return Promise.reject(new ConnectionLost("Connection to the Conveno daemon is closed.", false));
|
|
188
194
|
const id = this.nextId++;
|
|
189
195
|
return new Promise((resolve, reject) => {
|
|
190
196
|
const timer = setTimeout(() => {
|
|
191
197
|
this.pending.delete(id);
|
|
192
|
-
reject(new ClientError(`Request ${method} timed out after ${
|
|
193
|
-
},
|
|
198
|
+
reject(new ClientError(`Request ${method} timed out after ${timeoutMs} ms. Check that the daemon is running with "conveno daemon status".`, { kind: "connection" }));
|
|
199
|
+
}, timeoutMs);
|
|
194
200
|
this.pending.set(id, {
|
|
195
201
|
resolve,
|
|
196
202
|
reject,
|
|
@@ -254,6 +260,7 @@ async function handshake(socketPath, tokenPath, kind, timeoutMs, onEvent) {
|
|
|
254
260
|
});
|
|
255
261
|
if (!proofsMatch(hello.proof, daemonProof(token, nonce))) throw new ClientError(`The process on ${socketPath} is not the Conveno daemon. Stop it, or remove the socket, and try again.`, { kind: "not_daemon" });
|
|
256
262
|
await typedCall(conn, "auth", { proof: clientProof(token, hello.challenge) });
|
|
263
|
+
conn.daemonVersion = hello.daemonVersion;
|
|
257
264
|
return conn;
|
|
258
265
|
} catch (e) {
|
|
259
266
|
await conn.close();
|
|
@@ -393,8 +400,9 @@ var Link = class {
|
|
|
393
400
|
if (this.closed) throw new ClientError("The Conveno client is closed.");
|
|
394
401
|
const used = this.conn;
|
|
395
402
|
let result;
|
|
403
|
+
const wait = method === "permission.ask" ? wire.timeoutMs + 1e4 : void 0;
|
|
396
404
|
try {
|
|
397
|
-
result = await used.call(method, wire);
|
|
405
|
+
result = await used.call(method, wire, wait);
|
|
398
406
|
} catch (e) {
|
|
399
407
|
if (!(e instanceof ConnectionLost) || this.closed) throw plainError(e, this.socketPath);
|
|
400
408
|
if (e.sent && NOT_REPLAYABLE.has(method)) {
|
|
@@ -468,6 +476,10 @@ async function connect(opts) {
|
|
|
468
476
|
onEvent: (handler) => link.onEvent(handler),
|
|
469
477
|
close: () => link.close()
|
|
470
478
|
};
|
|
479
|
+
Object.defineProperty(client, "daemonVersion", {
|
|
480
|
+
get: () => link.conn.daemonVersion,
|
|
481
|
+
enumerable: true
|
|
482
|
+
});
|
|
471
483
|
for (const method of CLIENT_METHODS) client[method] = (params) => link.call(method, params);
|
|
472
484
|
return client;
|
|
473
485
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as connect } from "./dist-
|
|
2
|
-
import {
|
|
1
|
+
import { n as connect } from "./dist-BYkDv29h.js";
|
|
2
|
+
import { $ as formatContinuation, Pn as RpcErrorCode, Rn as SessionId, g as accessAllows, hn as updateSpawnRecord, i as ConvenoError, ln as takeAcpLaunchFile, wn as CliKind } from "./dist-1k5b8UGF.js";
|
|
3
3
|
import { randomBytes } from "node:crypto";
|
|
4
4
|
import { existsSync, rmSync } from "node:fs";
|
|
5
5
|
import { Readable, Writable } from "node:stream";
|
|
@@ -19,14 +19,46 @@ function answer(ask, allow) {
|
|
|
19
19
|
optionId: option.optionId
|
|
20
20
|
} : { outcome: "cancelled" };
|
|
21
21
|
}
|
|
22
|
+
const CONVENO_TOOL_TITLE = new RegExp(`^(?:(?:running|run|calling|call|using|use|execute|invoke)\\s+)?(?:tool\\s*[:\\-]\\s*)?(?:mcp[_\\-.:/ ]{1,3})?conveno[_\\-.:/ ]{1,3}(${[
|
|
23
|
+
"whoami",
|
|
24
|
+
"list_sessions",
|
|
25
|
+
"send",
|
|
26
|
+
"inbox",
|
|
27
|
+
"ack",
|
|
28
|
+
"rename",
|
|
29
|
+
"set_status",
|
|
30
|
+
"become_lead",
|
|
31
|
+
"orchestrate",
|
|
32
|
+
"handoff",
|
|
33
|
+
"spawn_session",
|
|
34
|
+
"answer_permission"
|
|
35
|
+
].join("|")})$`, "i");
|
|
36
|
+
/** Kinds whose title is a command line or a path, so a title that looks like a tool name is not one. */
|
|
37
|
+
const COMMAND_OR_FILE_KINDS = /* @__PURE__ */ new Set([
|
|
38
|
+
"execute",
|
|
39
|
+
"edit",
|
|
40
|
+
"delete",
|
|
41
|
+
"move"
|
|
42
|
+
]);
|
|
43
|
+
/**
|
|
44
|
+
* The Conveno tool a tool call is, or undefined. Only a call that names the whole tool counts, and
|
|
45
|
+
* never one the agent reports as a command it runs or a file it changes: the title of such a call
|
|
46
|
+
* is the command line or the path.
|
|
47
|
+
*/
|
|
48
|
+
function convenoToolOf(call) {
|
|
49
|
+
if (call.kind && COMMAND_OR_FILE_KINDS.has(call.kind)) return void 0;
|
|
50
|
+
const m = CONVENO_TOOL_TITLE.exec((call.title ?? "").trim());
|
|
51
|
+
return m ? m[1]?.toLowerCase() : void 0;
|
|
52
|
+
}
|
|
22
53
|
var AllowListPolicy = class {
|
|
23
|
-
|
|
24
|
-
constructor(
|
|
25
|
-
this.
|
|
54
|
+
allows;
|
|
55
|
+
constructor(allows) {
|
|
56
|
+
this.allows = allows;
|
|
26
57
|
}
|
|
27
58
|
async decide(ask, _signal) {
|
|
28
59
|
const what = `${ask.title ?? "a tool call"} (${ask.kind ?? "other"})`;
|
|
29
|
-
|
|
60
|
+
const own = convenoToolOf(ask) !== void 0;
|
|
61
|
+
if (own || this.allows({
|
|
30
62
|
kind: ask.kind,
|
|
31
63
|
title: ask.title
|
|
32
64
|
})) {
|
|
@@ -34,7 +66,7 @@ var AllowListPolicy = class {
|
|
|
34
66
|
if (outcome.outcome === "selected") return {
|
|
35
67
|
allowed: true,
|
|
36
68
|
outcome,
|
|
37
|
-
reason: `allowed ${what} by the allow list`
|
|
69
|
+
reason: `allowed ${what} ${own ? "(a Conveno tool)" : "by the allow list"}`
|
|
38
70
|
};
|
|
39
71
|
return {
|
|
40
72
|
allowed: false,
|
|
@@ -49,6 +81,83 @@ var AllowListPolicy = class {
|
|
|
49
81
|
};
|
|
50
82
|
}
|
|
51
83
|
};
|
|
84
|
+
/** "45 s", "2 min". */
|
|
85
|
+
const waitText = (ms) => ms >= 6e4 && ms % 6e4 === 0 ? `${ms / 6e4} min` : `${Math.round(ms / 1e3)} s`;
|
|
86
|
+
/**
|
|
87
|
+
* What the inner policy denies is put to the spawner. Its answer decides; with no answer, or no
|
|
88
|
+
* spawner, `unanswered` does. "Always" is remembered for this policy's lifetime, per kind and exact
|
|
89
|
+
* title. The agent only ever gets allow-once or reject-once (see `answer`).
|
|
90
|
+
*/
|
|
91
|
+
var AskSpawnerPolicy = class {
|
|
92
|
+
inner;
|
|
93
|
+
deps;
|
|
94
|
+
always = /* @__PURE__ */ new Set();
|
|
95
|
+
constructor(inner, deps) {
|
|
96
|
+
this.inner = inner;
|
|
97
|
+
this.deps = deps;
|
|
98
|
+
}
|
|
99
|
+
async decide(ask, signal) {
|
|
100
|
+
const first = await this.inner.decide(ask, signal);
|
|
101
|
+
if (first.allowed) return first;
|
|
102
|
+
const what = `${ask.title ?? "a tool call"} (${ask.kind ?? "other"})`;
|
|
103
|
+
const key = ask.title === void 0 ? void 0 : `${ask.kind ?? ""}\0${ask.title}`;
|
|
104
|
+
if (key !== void 0 && this.always.has(key)) return this.allow(ask, what, `allowed ${what}: always allowed earlier`);
|
|
105
|
+
const { deps } = this;
|
|
106
|
+
const timeoutMs = deps.timeoutMs ?? 12e4;
|
|
107
|
+
await deps.waiting?.(ask.title ?? what);
|
|
108
|
+
let reply;
|
|
109
|
+
try {
|
|
110
|
+
reply = await Promise.race([deps.ask({
|
|
111
|
+
...ask.title !== void 0 ? { title: ask.title.slice(0, 500) } : {},
|
|
112
|
+
...ask.kind !== void 0 ? { kind: ask.kind.slice(0, 100) } : {},
|
|
113
|
+
timeoutMs,
|
|
114
|
+
unanswered: deps.unanswered
|
|
115
|
+
}).catch((e) => {
|
|
116
|
+
deps.log?.(`could not ask the spawner: ${e instanceof Error ? e.message : String(e)}`);
|
|
117
|
+
return { answer: "no_spawner" };
|
|
118
|
+
}), new Promise((r) => {
|
|
119
|
+
if (signal.aborted) r(null);
|
|
120
|
+
else signal.addEventListener("abort", () => r(null), { once: true });
|
|
121
|
+
})]);
|
|
122
|
+
} finally {
|
|
123
|
+
await deps.waiting?.(null);
|
|
124
|
+
}
|
|
125
|
+
if (reply === null) return {
|
|
126
|
+
allowed: false,
|
|
127
|
+
outcome: { outcome: "cancelled" },
|
|
128
|
+
reason: `cancelled ${what}`
|
|
129
|
+
};
|
|
130
|
+
switch (reply.answer) {
|
|
131
|
+
case "allow_once": return this.allow(ask, what, `allowed ${what}: ${deps.spawnerName} said yes`);
|
|
132
|
+
case "allow_always":
|
|
133
|
+
if (key !== void 0) this.always.add(key);
|
|
134
|
+
return this.allow(ask, what, `allowed ${what}: ${deps.spawnerName} said always`);
|
|
135
|
+
case "deny": return this.deny(ask, what, `denied by ${deps.spawnerName}`);
|
|
136
|
+
case "unanswered":
|
|
137
|
+
case "no_spawner": {
|
|
138
|
+
const why = reply.answer === "unanswered" ? `no answer in ${waitText(timeoutMs)}` : "no spawner to ask";
|
|
139
|
+
return deps.unanswered === "allow" ? this.allow(ask, what, `allowed ${what}: ${why}`) : this.deny(ask, what, why);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
allow(ask, what, reason) {
|
|
144
|
+
const outcome = answer(ask, true);
|
|
145
|
+
if (outcome.outcome === "selected") return {
|
|
146
|
+
allowed: true,
|
|
147
|
+
outcome,
|
|
148
|
+
reason
|
|
149
|
+
};
|
|
150
|
+
return this.deny(ask, what, "the agent offered no allow-once option");
|
|
151
|
+
}
|
|
152
|
+
deny(ask, what, why) {
|
|
153
|
+
return {
|
|
154
|
+
allowed: false,
|
|
155
|
+
outcome: answer(ask, false),
|
|
156
|
+
reason: `denied ${what}: ${why}`,
|
|
157
|
+
why
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
};
|
|
52
161
|
/** Calls remembered at most; the oldest are dropped. */
|
|
53
162
|
const TOOLS_MAX = 1e3;
|
|
54
163
|
var ToolTracker = class {
|
|
@@ -71,7 +180,7 @@ var ToolTracker = class {
|
|
|
71
180
|
return u.sessionUpdate === "tool_call" ? next.title ?? next.kind ?? "tool" : void 0;
|
|
72
181
|
}
|
|
73
182
|
};
|
|
74
|
-
const HOST_VERSION = "0.2.0-rc.
|
|
183
|
+
const HOST_VERSION = "0.2.0-rc.14";
|
|
75
184
|
/** A stop request file: `conveno stop` writes it next to the spawn record. */
|
|
76
185
|
const stopRequestPath = (recordPath) => recordPath.replace(/\.json$/, ".stop");
|
|
77
186
|
function withTimeout(p, ms, what) {
|
|
@@ -126,6 +235,10 @@ var AcpHost = class {
|
|
|
126
235
|
/** The status line after a failed prompt, kept until the next prompt starts. */
|
|
127
236
|
failedText;
|
|
128
237
|
denials = [];
|
|
238
|
+
/** A denied call of a worker nobody spawned, shown until the next turn starts. */
|
|
239
|
+
deniedText;
|
|
240
|
+
/** The worker called Conveno's `send` (or `handoff`) in the turn that is running. */
|
|
241
|
+
sentThisTurn = false;
|
|
129
242
|
lastStatus;
|
|
130
243
|
timers = [];
|
|
131
244
|
constructor(spec, deps) {
|
|
@@ -133,9 +246,17 @@ var AcpHost = class {
|
|
|
133
246
|
this.deps = deps;
|
|
134
247
|
this.client = deps.client;
|
|
135
248
|
this.log = deps.log ?? ((line) => process.stderr.write(`[conveno acp-host] ${line}\n`));
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
249
|
+
this.policy = deps.policy ?? new AskSpawnerPolicy(new AllowListPolicy((call) => accessAllows(spec.access, call)), {
|
|
250
|
+
spawnerName: spec.from,
|
|
251
|
+
unanswered: spec.unanswered ?? "deny",
|
|
252
|
+
timeoutMs: deps.askTimeoutMs ?? spec.askTimeoutMs ?? 12e4,
|
|
253
|
+
ask: (p) => this.client["permission.ask"]({
|
|
254
|
+
sessionId: this.me,
|
|
255
|
+
...p
|
|
256
|
+
}),
|
|
257
|
+
waiting: (title) => this.waitingFor(title),
|
|
258
|
+
log: this.log
|
|
259
|
+
});
|
|
139
260
|
}
|
|
140
261
|
/** Ask the host to stop. The first reason wins. */
|
|
141
262
|
stop(reason) {
|
|
@@ -227,11 +348,19 @@ var AcpHost = class {
|
|
|
227
348
|
}), timeout, "session/new"));
|
|
228
349
|
this.acpSessionId = created.sessionId;
|
|
229
350
|
this.log(`session/new: ${created.sessionId}`);
|
|
230
|
-
const mode = spec.
|
|
351
|
+
const mode = spec.mode;
|
|
231
352
|
if (mode && created.modes?.availableModes.some((m) => m.id === mode)) await this.untilStopped(withTimeout(conn.agent.request(methods.agent.session.setMode, {
|
|
232
353
|
sessionId: created.sessionId,
|
|
233
354
|
modeId: mode
|
|
234
355
|
}), timeout, "session/set_mode")).then(() => this.log(`mode: ${mode}`), (e) => this.log(`could not set mode ${mode}: ${errText(e)}`));
|
|
356
|
+
else if (mode) {
|
|
357
|
+
const configId = modeConfigId(created.configOptions, mode);
|
|
358
|
+
if (configId) await this.untilStopped(withTimeout(conn.agent.request(methods.agent.session.setConfigOption, {
|
|
359
|
+
sessionId: created.sessionId,
|
|
360
|
+
configId,
|
|
361
|
+
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)}`));
|
|
363
|
+
}
|
|
235
364
|
const spawnedBy = SessionId.safeParse(spec.spawnedBy);
|
|
236
365
|
const { session } = await this.client["session.register"]({
|
|
237
366
|
name: spec.name,
|
|
@@ -245,6 +374,10 @@ var AcpHost = class {
|
|
|
245
374
|
...agentVersion ? { cliVersion: agentVersion } : {}
|
|
246
375
|
});
|
|
247
376
|
this.sessionId = session.id;
|
|
377
|
+
await this.client["session.setNative"]({
|
|
378
|
+
sessionId: session.id,
|
|
379
|
+
nativeId: created.sessionId.slice(0, 256)
|
|
380
|
+
}).catch((e) => this.log(`could not record the ACP session id: ${errText(e)}`));
|
|
248
381
|
updateSpawnRecord(spec.record, {
|
|
249
382
|
pid: process.pid,
|
|
250
383
|
sessionId: session.id,
|
|
@@ -257,9 +390,9 @@ var AcpHost = class {
|
|
|
257
390
|
let next = this.spec.task ?? null;
|
|
258
391
|
if (next === null) await this.status("idle", null);
|
|
259
392
|
while (!this.stopping) if (next !== null) {
|
|
260
|
-
await this.prompt(next);
|
|
393
|
+
const finished = await this.prompt(next);
|
|
261
394
|
if (this.stopping) break;
|
|
262
|
-
await this.
|
|
395
|
+
await this.reportTurnEnd(finished);
|
|
263
396
|
next = await this.endTurn();
|
|
264
397
|
} else next = await this.waitForWork();
|
|
265
398
|
}
|
|
@@ -271,7 +404,7 @@ var AcpHost = class {
|
|
|
271
404
|
allowContinue: true
|
|
272
405
|
});
|
|
273
406
|
const next = formatContinuation(r.messages, r.orchestrator, r.remaining) || null;
|
|
274
|
-
if (next === null) await this.status(void 0, this.failedText ?? null);
|
|
407
|
+
if (next === null) await this.status(void 0, this.failedText ?? this.deniedText ?? null);
|
|
275
408
|
return next;
|
|
276
409
|
} catch (e) {
|
|
277
410
|
if (e instanceof ConvenoError && e.code === RpcErrorCode.NotFound) {
|
|
@@ -286,14 +419,19 @@ var AcpHost = class {
|
|
|
286
419
|
return null;
|
|
287
420
|
}
|
|
288
421
|
}
|
|
289
|
-
/**
|
|
422
|
+
/**
|
|
423
|
+
* One prompt turn. Resolves when the agent answers `session/prompt` or the host stops. True when
|
|
424
|
+
* the turn ran to its end; false when the prompt failed (the spawner was told) or the host stopped.
|
|
425
|
+
*/
|
|
290
426
|
async prompt(text) {
|
|
291
427
|
const conn = this.conn;
|
|
292
428
|
const sid = this.acpSessionId;
|
|
293
|
-
if (!conn || !sid) return;
|
|
429
|
+
if (!conn || !sid) return false;
|
|
294
430
|
this.turnCtl = new AbortController();
|
|
295
431
|
this.failedText = void 0;
|
|
296
432
|
this.denials = [];
|
|
433
|
+
this.deniedText = void 0;
|
|
434
|
+
this.sentThisTurn = false;
|
|
297
435
|
await this.status("busy", null);
|
|
298
436
|
const turn = conn.agent.request(methods.agent.session.prompt, {
|
|
299
437
|
sessionId: sid,
|
|
@@ -309,12 +447,14 @@ var AcpHost = class {
|
|
|
309
447
|
const reason = requestReason(e);
|
|
310
448
|
this.log(`session/prompt failed: ${reason}`);
|
|
311
449
|
await this.promptFailed(reason);
|
|
312
|
-
return;
|
|
450
|
+
return false;
|
|
313
451
|
}
|
|
314
452
|
await conn.agent.notify(methods.agent.session.cancel, { sessionId: sid }).catch(() => void 0);
|
|
315
453
|
const grace = this.deps.stopGraceMs ?? 5e3;
|
|
316
454
|
await Promise.race([turn.then(() => void 0, () => void 0), new Promise((r) => setTimeout(r, grace).unref())]);
|
|
455
|
+
return false;
|
|
317
456
|
}
|
|
457
|
+
return true;
|
|
318
458
|
}
|
|
319
459
|
/**
|
|
320
460
|
* Idle: wait until the daemon hands this session messages through `turn.wake`, then return the
|
|
@@ -382,6 +522,8 @@ var AcpHost = class {
|
|
|
382
522
|
onUpdate(n) {
|
|
383
523
|
if (n.sessionId !== this.acpSessionId) return;
|
|
384
524
|
const doing = this.tools.update(n.update);
|
|
525
|
+
const id = n.update.toolCallId;
|
|
526
|
+
if (id !== void 0) this.noteConvenoCall(this.tools.tools.get(id));
|
|
385
527
|
if (doing !== void 0 && doing !== this.lastStatus) {
|
|
386
528
|
this.lastStatus = doing;
|
|
387
529
|
this.status(void 0, doing);
|
|
@@ -392,6 +534,10 @@ var AcpHost = class {
|
|
|
392
534
|
const known = this.tools.tools.get(p.toolCall.toolCallId) ?? {};
|
|
393
535
|
const title = p.toolCall.title ?? known.title;
|
|
394
536
|
const kind = p.toolCall.kind ?? known.kind;
|
|
537
|
+
this.noteConvenoCall({
|
|
538
|
+
title,
|
|
539
|
+
kind
|
|
540
|
+
});
|
|
395
541
|
const ask = {
|
|
396
542
|
toolCallId: p.toolCall.toolCallId,
|
|
397
543
|
...title ? { title } : {},
|
|
@@ -400,9 +546,16 @@ var AcpHost = class {
|
|
|
400
546
|
};
|
|
401
547
|
const signal = this.turnCtl.signal;
|
|
402
548
|
const decision = await Promise.race([this.policy.decide(ask, signal), new Promise((r) => signal.addEventListener("abort", () => r(null), { once: true }))]);
|
|
403
|
-
if (decision === null) return { outcome: { outcome: "cancelled" } };
|
|
549
|
+
if (decision === null || signal.aborted) return { outcome: { outcome: "cancelled" } };
|
|
404
550
|
this.log(`permission: ${decision.reason}`);
|
|
405
|
-
if (!decision.allowed)
|
|
551
|
+
if (!decision.allowed) {
|
|
552
|
+
const what = `${title ?? "a tool call"} (${kind ?? "other"})`;
|
|
553
|
+
this.denials.push(`${what}: ${decision.why ?? "it was not allowed"}`);
|
|
554
|
+
if (!this.spec.spawnedBy) {
|
|
555
|
+
this.deniedText = `denied: ${title ?? what}`;
|
|
556
|
+
this.status(void 0, this.deniedText);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
406
559
|
return { outcome: decision.outcome };
|
|
407
560
|
}
|
|
408
561
|
get me() {
|
|
@@ -419,6 +572,10 @@ var AcpHost = class {
|
|
|
419
572
|
...text !== void 0 ? { statusText: text } : {}
|
|
420
573
|
}).catch(() => void 0);
|
|
421
574
|
}
|
|
575
|
+
/** Show that the worker waits for its spawner's answer; null puts the usual status back. */
|
|
576
|
+
async waitingFor(title) {
|
|
577
|
+
await this.status(void 0, title === null ? this.deniedText ?? this.lastStatus ?? null : `waiting for permission: ${title}`);
|
|
578
|
+
}
|
|
422
579
|
async heartbeat() {
|
|
423
580
|
if (!this.sessionId) return;
|
|
424
581
|
try {
|
|
@@ -451,17 +608,32 @@ var AcpHost = class {
|
|
|
451
608
|
this.lastPromptFailure = reason;
|
|
452
609
|
await this.tell(`[conveno] Worker ${this.spec.name} (${this.spec.cli}, over ACP) could not run a prompt: ${reason}. It keeps running and takes the next message.`);
|
|
453
610
|
}
|
|
454
|
-
/**
|
|
455
|
-
|
|
456
|
-
if (
|
|
457
|
-
const
|
|
458
|
-
if (
|
|
611
|
+
/** Remember that the worker sent something this turn. Only Conveno's own send tools count. */
|
|
612
|
+
noteConvenoCall(call) {
|
|
613
|
+
if (!call) return;
|
|
614
|
+
const tool = convenoToolOf(call);
|
|
615
|
+
if (tool === "send" || tool === "handoff") this.sentThisTurn = true;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* One note to the spawner about the turn that just ended: the worker finished without sending
|
|
619
|
+
* anything, and/or which tool calls were denied. Nothing when there is no spawner (a spawn from
|
|
620
|
+
* a terminal), when the worker did reply and nothing was denied, or when the prompt failed.
|
|
621
|
+
*/
|
|
622
|
+
async reportTurnEnd(finished) {
|
|
623
|
+
const denials = this.denials;
|
|
459
624
|
this.denials = [];
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
]
|
|
625
|
+
if (!this.spec.spawnedBy) return;
|
|
626
|
+
const silent = finished && !this.sentThisTurn;
|
|
627
|
+
if (denials.length === 0 && !silent) return;
|
|
628
|
+
const who = `[conveno] Worker ${this.spec.name} (${this.spec.cli}, over ACP)`;
|
|
629
|
+
const lines = [];
|
|
630
|
+
if (silent) lines.push(`${who} finished its turn without replying.`);
|
|
631
|
+
if (denials.length > 0) {
|
|
632
|
+
const list = denials.slice(0, 5).map((d) => `- ${d}`);
|
|
633
|
+
if (denials.length > 5) list.push(`- and ${denials.length - 5} more`);
|
|
634
|
+
lines.push(silent ? "These tool calls were not allowed in its last turn:" : `${who} had tool calls that were not allowed in its last turn:`, ...list);
|
|
635
|
+
}
|
|
636
|
+
await this.tell(lines.join("\n"));
|
|
465
637
|
}
|
|
466
638
|
/** Send a text message from this session to its spawner. Never throws. */
|
|
467
639
|
async tell(text) {
|
|
@@ -523,6 +695,23 @@ var AcpHost = class {
|
|
|
523
695
|
}
|
|
524
696
|
};
|
|
525
697
|
/**
|
|
698
|
+
* The id of a session config option in the `mode` category (or with id `mode`) that offers `value`,
|
|
699
|
+
* from `session/new`'s `configOptions`. Undefined when there is none.
|
|
700
|
+
*/
|
|
701
|
+
function modeConfigId(options, value) {
|
|
702
|
+
if (!Array.isArray(options)) return void 0;
|
|
703
|
+
for (const o of options) {
|
|
704
|
+
if (o?.category !== "mode" && o?.id !== "mode") continue;
|
|
705
|
+
const values = (Array.isArray(o.options) ? o.options : []).flatMap((x) => {
|
|
706
|
+
const item = x;
|
|
707
|
+
return Array.isArray(item?.options) ? item.options : [item];
|
|
708
|
+
});
|
|
709
|
+
if (typeof o.id === "string" && values.some((v) => v?.value === value)) return o.id;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
/** Set on every agent the ACP host starts. `conveno hook` exits at once when it is set. */
|
|
713
|
+
const ACP_WORKER_ENV = "CONVENO_ACP_WORKER";
|
|
714
|
+
/**
|
|
526
715
|
* End `pid` and its descendants. POSIX: the agent leads its own process group (it was started
|
|
527
716
|
* detached), so the whole group gets SIGKILL. Windows has no process groups; `taskkill /T` ends the
|
|
528
717
|
* tree by parent pid. Never throws: the process may be gone already.
|
|
@@ -566,7 +755,10 @@ function startAgentProcess(opts) {
|
|
|
566
755
|
],
|
|
567
756
|
detached: platform !== "win32",
|
|
568
757
|
windowsHide: true,
|
|
569
|
-
env:
|
|
758
|
+
env: {
|
|
759
|
+
...opts.env ?? process.env,
|
|
760
|
+
[ACP_WORKER_ENV]: "1"
|
|
761
|
+
},
|
|
570
762
|
...opts.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
|
|
571
763
|
});
|
|
572
764
|
const exited = new Promise((r) => {
|
|
@@ -2,7 +2,7 @@ import { randomBytes as randomBytes$1 } from "@noble/ciphers/utils.js";
|
|
|
2
2
|
import { equalBytes } from "@noble/curves/utils.js";
|
|
3
3
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
4
4
|
import { bytesToHex, concatBytes, utf8ToBytes } from "@noble/hashes/utils.js";
|
|
5
|
-
import {
|
|
5
|
+
import { Tn as DeviceId, ar as literal, cr as string, ir as discriminatedUnion, nr as array, or as number, sr as object, tr as _enum } from "./dist-1k5b8UGF.js";
|
|
6
6
|
import { ed25519, x25519 } from "@noble/curves/ed25519.js";
|
|
7
7
|
import { chacha20poly1305 } from "@noble/ciphers/chacha.js";
|
|
8
8
|
import { expand, extract } from "@noble/hashes/hkdf.js";
|
|
@@ -2,7 +2,7 @@ import { execFile, spawn } from "node:child_process";
|
|
|
2
2
|
import { readFileSync, statSync } from "node:fs";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
import {
|
|
5
|
+
import { At as pendingHookContext, Ft as planProgram, It as planSpawn, J as endTurnContinuation, Q as findOnPath, Tt as parseCliVersion, sn as startTurnContext, wt as ownSession } from "./dist-1k5b8UGF.js";
|
|
6
6
|
import { n as cs, t as Za } from "./toml-patch-DGzVRdd1.js";
|
|
7
7
|
// ../adapters/codex/dist/index.js
|
|
8
8
|
const SERVER_NAME = "conveno";
|
|
@@ -95,6 +95,7 @@ const EVENT_NAME = {
|
|
|
95
95
|
session_start: "SessionStart",
|
|
96
96
|
user_prompt_submit: "UserPromptSubmit",
|
|
97
97
|
stop: "Stop",
|
|
98
|
+
session_end: "SessionEnd",
|
|
98
99
|
permission_request: "PermissionRequest"
|
|
99
100
|
};
|
|
100
101
|
/** A hook key is `<file>:<event>:<group>:<handler>`; null for any other shape. */
|
|
@@ -354,12 +355,16 @@ function renameHooks(toml, rename) {
|
|
|
354
355
|
const HOOK_EVENTS = [
|
|
355
356
|
"SessionStart",
|
|
356
357
|
"UserPromptSubmit",
|
|
357
|
-
"Stop"
|
|
358
|
+
"Stop",
|
|
359
|
+
"SessionEnd"
|
|
358
360
|
];
|
|
359
361
|
/** Older versions also installed a PermissionRequest hook; uninstall still removes it. */
|
|
360
362
|
const LEGACY_HOOK_EVENTS = ["PermissionRequest"];
|
|
361
363
|
/** Seconds. The hook gives up after 2 s on its own; this leaves room for Node startup. Same as Claude. */
|
|
362
364
|
const HOOK_TIMEOUT_SECONDS = 5;
|
|
365
|
+
/** Codex runs SessionEnd while a thread unloads and caps it at 3 s (default 1 s). */
|
|
366
|
+
const SESSION_END_TIMEOUT_SECONDS = 3;
|
|
367
|
+
const timeoutFor = (event) => event === "SessionEnd" ? SESSION_END_TIMEOUT_SECONDS : HOOK_TIMEOUT_SECONDS;
|
|
363
368
|
const codexDir = (env) => env.env.CODEX_HOME || join(env.home, ".codex");
|
|
364
369
|
const configPath = (env) => join(codexDir(env), "config.toml");
|
|
365
370
|
const hooksPath = (env) => join(codexDir(env), "hooks.json");
|
|
@@ -471,7 +476,7 @@ async function planHooks(env) {
|
|
|
471
476
|
next[event] = withOursReplaced(groups, event, { hooks: [{
|
|
472
477
|
type: "command",
|
|
473
478
|
command,
|
|
474
|
-
timeout:
|
|
479
|
+
timeout: timeoutFor(event)
|
|
475
480
|
}] });
|
|
476
481
|
}
|
|
477
482
|
if (!changed) return [];
|
|
@@ -491,7 +496,7 @@ async function planHooks(env) {
|
|
|
491
496
|
...doc,
|
|
492
497
|
hooks: next
|
|
493
498
|
}),
|
|
494
|
-
description: `Add SessionStart, UserPromptSubmit and
|
|
499
|
+
description: `Add SessionStart, UserPromptSubmit, Stop and SessionEnd hooks that deliver Conveno messages on the next turn and at the end of a turn, and take a closed window offline. Codex asks you to trust new hooks: review them with /hooks.`
|
|
495
500
|
}];
|
|
496
501
|
}
|
|
497
502
|
async function uninstallHooks(env) {
|
|
@@ -522,7 +527,7 @@ async function uninstallHooks(env) {
|
|
|
522
527
|
path,
|
|
523
528
|
before,
|
|
524
529
|
after: json(after),
|
|
525
|
-
description: "Remove the Conveno SessionStart, UserPromptSubmit, and
|
|
530
|
+
description: "Remove the Conveno SessionStart, UserPromptSubmit, Stop, and SessionEnd hooks."
|
|
526
531
|
}];
|
|
527
532
|
}
|
|
528
533
|
function serverSpec(env, existing) {
|
|
@@ -608,6 +613,7 @@ const EMPTY = {
|
|
|
608
613
|
*/
|
|
609
614
|
async function hook(event, input, ctx) {
|
|
610
615
|
ctx = withThread(input, ctx, event);
|
|
616
|
+
if (event === "SessionEnd") return retireThread(ctx);
|
|
611
617
|
if (event === "Stop") {
|
|
612
618
|
const reason = await endTurnContinuation(ctx);
|
|
613
619
|
if (reason === null) return EMPTY;
|
|
@@ -631,6 +637,20 @@ async function hook(event, input, ctx) {
|
|
|
631
637
|
};
|
|
632
638
|
}
|
|
633
639
|
/**
|
|
640
|
+
* The thread unloaded (its window closed, or the TUI left it 60 s ago). If it is the session's
|
|
641
|
+
* current conversation, the session departs: the thread's MCP may outlive it (Windows, when Codex
|
|
642
|
+
* cannot kill the process tree) and would keep the row online. A thread the window already left
|
|
643
|
+
* binds to nothing (`turnStart` is false), so the window's session stays. No delivery.
|
|
644
|
+
*/
|
|
645
|
+
async function retireThread(ctx) {
|
|
646
|
+
if (ctx.nativeId === void 0) return EMPTY;
|
|
647
|
+
try {
|
|
648
|
+
const session = await ownSession(ctx);
|
|
649
|
+
if (session) await ctx.client["session.unregister"]({ sessionId: session.id });
|
|
650
|
+
} catch {}
|
|
651
|
+
return EMPTY;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
634
654
|
* The hook's `session_id` is the Codex thread id, the id `codex queue --thread` takes. Codex
|
|
635
655
|
* threads can share one app-server process, so the host pid alone may not tell windows apart: the
|
|
636
656
|
* daemon binds the thread to the window's session (`session.bind`), and wakes the session by it.
|
|
@@ -858,6 +878,7 @@ const STATE_EVENTS = {
|
|
|
858
878
|
SessionStart: "session_start",
|
|
859
879
|
UserPromptSubmit: "user_prompt_submit",
|
|
860
880
|
Stop: "stop",
|
|
881
|
+
SessionEnd: "session_end",
|
|
861
882
|
PermissionRequest: "permission_request"
|
|
862
883
|
};
|
|
863
884
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { At as pendingHookContext, C as askedKey, G as dropFromList, Ht as readCommandLine, J as endTurnContinuation, K as editJson, Pt as planLauncher, Tt as parseCliVersion, U as defaultProcessIo, X as existedBefore, a as FROM_USER_NOTICE, c as ORCHESTRATOR_TASK_NOTICE, mn as uninstallLauncher, pt as late, rn as sameJson, s as NOT_FROM_USER_NOTICE, st as hostPidOf, ut as isObject, vt as loadJson, w as askedMarker, wt as ownSession, x as agentCommand, xt as needsQuoting, zt as putInList } from "./dist-1k5b8UGF.js";
|
|
4
4
|
import { n as cs, t as Za } from "./toml-patch-DGzVRdd1.js";
|
|
5
5
|
// ../adapters/grok/dist/index.js
|
|
6
6
|
const SERVER_NAME = "conveno";
|
|
@@ -619,7 +619,8 @@ async function stopHook(input, ctx) {
|
|
|
619
619
|
const session = await ownSession(ctx);
|
|
620
620
|
const key = session && askedKey(session.id, ctx.nativeId);
|
|
621
621
|
if (session !== null && key && session.deliveryTier !== "live" && !await wasAsked(key)) {
|
|
622
|
-
const
|
|
622
|
+
const hostPid = await hostPidOf(ctx);
|
|
623
|
+
const command = hostPid === void 0 ? null : await readCommandLine(hostPid, defaultProcessIo, ASK_READ_TIMEOUT_MS);
|
|
623
624
|
if (command !== null && !isOneShotGrok(command)) askFor = key;
|
|
624
625
|
}
|
|
625
626
|
} catch {
|