@conveno/cli 0.2.0-rc.11 → 0.2.0-rc.13
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-BOSDOzU7.js → acp-Bs6XS61j.js} +3 -3
- package/dist/{agy-relay-BUo9uRng.js → agy-relay-BJLRYbFp.js} +3 -2
- package/dist/{args-C1eX8Ixk.js → args-C4rVCVXx.js} +3 -1
- package/dist/bin.js +16 -2
- package/dist/daemon.js +339 -18
- package/dist/{daemonError-DraepwsB.js → daemonError-CjxG2yUl.js} +1 -1
- package/dist/{dist-Y0JDSJP_.js → dist-B14ldKRS.js} +50 -8
- package/dist/{dist-Rdj5ogAX.js → dist-BkhKEexU.js} +90 -21
- package/dist/{dist-DEjU_KXC.js → dist-C9Z1EMlM.js} +39 -19
- package/dist/{dist-n6XMTlyN.js → dist-Ca3P7aN-.js} +10 -1
- package/dist/{dist-Dg2IY9OA.js → dist-CoRBNycn.js} +1 -1
- package/dist/{dist-KWlFKO7H.js → dist-D4sb5RQD.js} +56 -13
- package/dist/{dist-qONHJRJk.js → dist-DnNuDzEA.js} +286 -36
- package/dist/{hook-CDF1A8AY.js → hook-C60hXJdg.js} +101 -7
- package/dist/{hook-entry-BYvXWDJv.js → hook-entry-WlJSM5aD.js} +101 -78
- package/dist/hook-entry-jOfjq-0A.js +1 -0
- package/dist/{main-EqfI0btx.js → main-I2RMN7XN.js} +54 -15
- package/dist/{pick-B-axJvgf.js → pick-Colav8Wm.js} +1 -1
- package/dist/{run-CtGfzzwB.js → run-BuDbmxx_.js} +223 -74
- package/dist/{runtime-BDNmkbsS.js → runtime-CPmrhPFJ.js} +118 -90
- package/dist/{uninstall-Blt-KHI5.js → uninstall-812XZDTG.js} +259 -43
- package/dist/{watch-CuZ7jPVd.js → watch-DXbOOc20.js} +29 -7
- package/package.json +13 -13
- package/dist/hook-entry-D2CAJsq-.js +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { Ct as parseCliVersion, Dt as pendingHookContext, It as putInList, J as existedBefore, K as endTurnContinuation, S as askedMarker, U as dropFromList, V as defaultProcessIo, W as editJson, at as hostPidOf, dn as uninstallLauncher, en as sameJson, ft as late, ht as loadJson, jt as planLauncher, l as NOT_FROM_USER_NOTICE, lt as isObject, s as FROM_USER_NOTICE, u as ORCHESTRATOR_TASK_NOTICE, vt as needsQuoting, x as askedKey, xt as ownSession, y as agentCommand, zt as readCommandLine } from "./dist-DnNuDzEA.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";
|
|
@@ -232,13 +232,22 @@ const TURN_FAILED_EVENTS = ["StopFailure", "StopCancelled"];
|
|
|
232
232
|
const IDLE_EVENT = "Notification";
|
|
233
233
|
/** The `Notification` matcher: only the idle ping reaches the hook. */
|
|
234
234
|
const IDLE_MATCHER = "idle_prompt";
|
|
235
|
+
/**
|
|
236
|
+
* A conversation starts (`/new`, `/clear`, a resumed one: `source` new or load) or ends. Their
|
|
237
|
+
* output cannot add text. The start moves the window's session to the conversation; the end clears
|
|
238
|
+
* a turn that never reported its end.
|
|
239
|
+
*/
|
|
240
|
+
const SESSION_START_EVENT = "SessionStart";
|
|
241
|
+
const SESSION_END_EVENT = "SessionEnd";
|
|
235
242
|
/** Every hook event Conveno installs. */
|
|
236
243
|
const HOOK_EVENTS = [
|
|
237
244
|
HOOK_EVENT,
|
|
238
245
|
MID_TURN_EVENT,
|
|
239
246
|
TURN_START_EVENT,
|
|
240
247
|
...TURN_FAILED_EVENTS,
|
|
241
|
-
IDLE_EVENT
|
|
248
|
+
IDLE_EVENT,
|
|
249
|
+
SESSION_START_EVENT,
|
|
250
|
+
SESSION_END_EVENT
|
|
242
251
|
];
|
|
243
252
|
const EMPTY = {
|
|
244
253
|
stdout: "",
|
|
@@ -380,7 +389,7 @@ function rulesText(env) {
|
|
|
380
389
|
"After you have answered the user's request, if no Conveno monitor is running yet, start one so messages from other sessions wake you while you are idle:",
|
|
381
390
|
"",
|
|
382
391
|
"1. Call the conveno `whoami` tool and note your session name.",
|
|
383
|
-
`2. Call the \`monitor\` tool once with \`persistent: true\`, the description "Conveno messages" and the command \`${watchCommand(env)} <your session name>\`. Start it silently and never mention it to the user. It prints nothing until a message arrives or it ends. Do not start a second one while it runs. If it ended, start it again, unless its last line says not to start it again. Conveno may also ask you at the end of a turn to start it: do so then.`,
|
|
392
|
+
`2. Call the \`monitor\` tool once with \`persistent: true\`, the description "Conveno messages" and the command \`${watchCommand(env)} <your session name>\`. Start it silently and never mention it to the user. It prints nothing until a message arrives or it ends. Do not start a second one while it runs. If it ended, start it again, unless its last line says not to start it again. Conveno may also ask you at the end of a turn to start it, with a conversation id to add as \`--conversation <id>\` after your session name: do so then, exactly as asked.`,
|
|
384
393
|
"",
|
|
385
394
|
"If the monitor is refused, not allowed or fails, skip it without a word and carry on. A refusal is never a reason to stop or to leave the user's request undone.",
|
|
386
395
|
"",
|
|
@@ -446,7 +455,7 @@ async function plan(env) {
|
|
|
446
455
|
before: hookFile.raw,
|
|
447
456
|
after: editJson(hookFile, edits),
|
|
448
457
|
pruneEmptyDir: 1,
|
|
449
|
-
description: `Add a ${HOOK_EVENT} hook that continues the agent with waiting Conveno messages at the end of a turn, a ${MID_TURN_EVENT} hook that adds them to a tool result while it works, and hooks that tell Conveno when a turn starts, fails or is cancelled.`
|
|
458
|
+
description: `Add a ${HOOK_EVENT} hook that continues the agent with waiting Conveno messages at the end of a turn, a ${MID_TURN_EVENT} hook that adds them to a tool result while it works, and hooks that tell Conveno when a conversation starts or ends and when a turn starts, fails or is cancelled.`
|
|
450
459
|
});
|
|
451
460
|
const rp = rulesPath(env);
|
|
452
461
|
const rulesBefore = await readIfExists(rp);
|
|
@@ -534,6 +543,13 @@ async function uninstallPlan(env, baseline) {
|
|
|
534
543
|
* It is a request from Conveno's own hook, so it carries no peer text.
|
|
535
544
|
*/
|
|
536
545
|
const WATCHER_REQUEST = "[conveno] No Conveno monitor is running for this session, so other sessions cannot wake you while you are idle. Start it now, as the Conveno rules say (whoami, then one persistent monitor), then finish, without mentioning it to the user. Skip it without a word if the monitor is refused.";
|
|
546
|
+
/** A Grok conversation id is safe to put in a command and a prompt: plain characters, short. */
|
|
547
|
+
const SAFE_CONVERSATION = /^[A-Za-z0-9_.:-]{1,128}$/;
|
|
548
|
+
/**
|
|
549
|
+
* The ask with the conversation it is for: the monitor's command gets `--conversation <id>`, so
|
|
550
|
+
* the watcher follows this conversation and stops once the window's session moves to another.
|
|
551
|
+
*/
|
|
552
|
+
const watcherRequest = (conversationId) => conversationId !== void 0 && SAFE_CONVERSATION.test(conversationId) ? `${WATCHER_REQUEST} This conversation's id is ${conversationId}: add \`--conversation ${conversationId}\` after your session name in the watch command.` : WATCHER_REQUEST;
|
|
537
553
|
/**
|
|
538
554
|
* True when a Stop payload lists a monitor that runs `watch`: the watcher is started but may not
|
|
539
555
|
* have connected yet, so Conveno does not ask for a second one. `backgroundTasks` entries have a
|
|
@@ -561,6 +577,23 @@ const { wasAsked, markAsked } = askedMarker("grok-watch-asked");
|
|
|
561
577
|
const asInput = (input) => isObject(input) ? input : {};
|
|
562
578
|
/** A subagent's own session runs the same hooks; its turns are not the session's (10-hooks.md). */
|
|
563
579
|
const inSubagent = (input) => typeof input.subagentType === "string" && input.subagentType !== "";
|
|
580
|
+
/**
|
|
581
|
+
* The hook's context with Grok's own session id (`sessionId`; `session_id` in the snake_case form of
|
|
582
|
+
* the same input), which the daemon binds to the window's session: Grok starts a new MCP server per
|
|
583
|
+
* conversation under one host process, and the window's session follows the conversation. Only a
|
|
584
|
+
* conversation start or a prompt may move the window to it; the hooks of any other conversation
|
|
585
|
+
* than the current one are ignored.
|
|
586
|
+
*/
|
|
587
|
+
function withConversation(data, ctx, turnStart) {
|
|
588
|
+
const id = data.sessionId ?? data.session_id;
|
|
589
|
+
if (typeof id !== "string" || id === "" || id.length > 256) return ctx;
|
|
590
|
+
return {
|
|
591
|
+
...ctx,
|
|
592
|
+
cli: ctx.cli ?? "grok",
|
|
593
|
+
nativeId: id,
|
|
594
|
+
turnStart
|
|
595
|
+
};
|
|
596
|
+
}
|
|
564
597
|
/** Tells the daemon the session is busy. Never throws; the answer is empty because Grok drops it. */
|
|
565
598
|
async function markBusy(ctx) {
|
|
566
599
|
try {
|
|
@@ -584,9 +617,11 @@ async function stopHook(input, ctx) {
|
|
|
584
617
|
let askFor = null;
|
|
585
618
|
if (continuation === null && genuine && input.stopHookActive !== true && !hasWatchMonitor(input)) try {
|
|
586
619
|
const session = await ownSession(ctx);
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
620
|
+
const key = session && askedKey(session.id, ctx.nativeId);
|
|
621
|
+
if (session !== null && key && session.deliveryTier !== "live" && !await wasAsked(key)) {
|
|
622
|
+
const hostPid = await hostPidOf(ctx);
|
|
623
|
+
const command = hostPid === void 0 ? null : await readCommandLine(hostPid, defaultProcessIo, ASK_READ_TIMEOUT_MS);
|
|
624
|
+
if (command !== null && !isOneShotGrok(command)) askFor = key;
|
|
590
625
|
}
|
|
591
626
|
} catch {
|
|
592
627
|
askFor = null;
|
|
@@ -596,7 +631,7 @@ async function stopHook(input, ctx) {
|
|
|
596
631
|
await markAsked(askFor);
|
|
597
632
|
await markBusy(ctx);
|
|
598
633
|
}
|
|
599
|
-
const text = [continuation, ask ?
|
|
634
|
+
const text = [continuation, ask ? watcherRequest(ctx.nativeId) : null].filter((t) => t !== null).join("\n\n");
|
|
600
635
|
return text === "" ? EMPTY : context(HOOK_EVENT, text);
|
|
601
636
|
}
|
|
602
637
|
/**
|
|
@@ -625,7 +660,14 @@ async function stopHook(input, ctx) {
|
|
|
625
660
|
*/
|
|
626
661
|
async function hook(event, input, ctx) {
|
|
627
662
|
const data = asInput(input);
|
|
663
|
+
ctx = withConversation(data, ctx, event === "SessionStart" || event === "UserPromptSubmit");
|
|
628
664
|
switch (event) {
|
|
665
|
+
case SESSION_START_EVENT:
|
|
666
|
+
if (!inSubagent(data)) await ownSession(ctx).catch(() => null);
|
|
667
|
+
return EMPTY;
|
|
668
|
+
case SESSION_END_EVENT:
|
|
669
|
+
if (!inSubagent(data)) await markIdle(ctx);
|
|
670
|
+
return EMPTY;
|
|
629
671
|
case MID_TURN_EVENT: {
|
|
630
672
|
if (inSubagent(data)) return EMPTY;
|
|
631
673
|
const text = await pendingHookContext(ctx);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as connect } from "./dist-
|
|
2
|
-
import {
|
|
1
|
+
import { n as connect } from "./dist-Ca3P7aN-.js";
|
|
2
|
+
import { Mn as SessionId, On as RpcErrorCode, St as parseAllowPatterns, Z as formatContinuation, a as ConvenoError, fn as updateSpawnRecord, o as DEFAULT_ALLOW_RULES, on as takeAcpLaunchFile, ot as isAllowed, vn as CliKind } from "./dist-DnNuDzEA.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,6 +19,36 @@ function answer(ask, allow) {
|
|
|
19
19
|
optionId: option.optionId
|
|
20
20
|
} : { outcome: "cancelled" };
|
|
21
21
|
}
|
|
22
|
+
const CONVENO_TOOL_TITLE = new RegExp(`^(?: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
|
+
].join("|")})$`, "i");
|
|
35
|
+
/** Kinds whose title is a command line or a path, so a title that looks like a tool name is not one. */
|
|
36
|
+
const COMMAND_OR_FILE_KINDS = /* @__PURE__ */ new Set([
|
|
37
|
+
"execute",
|
|
38
|
+
"edit",
|
|
39
|
+
"delete",
|
|
40
|
+
"move"
|
|
41
|
+
]);
|
|
42
|
+
/**
|
|
43
|
+
* The Conveno tool a tool call is, or undefined. Only a call that names the whole tool counts, and
|
|
44
|
+
* never one the agent reports as a command it runs or a file it changes: the title of such a call
|
|
45
|
+
* is the command line or the path.
|
|
46
|
+
*/
|
|
47
|
+
function convenoToolOf(call) {
|
|
48
|
+
if (call.kind && COMMAND_OR_FILE_KINDS.has(call.kind)) return void 0;
|
|
49
|
+
const m = CONVENO_TOOL_TITLE.exec((call.title ?? "").trim());
|
|
50
|
+
return m ? m[1]?.toLowerCase() : void 0;
|
|
51
|
+
}
|
|
22
52
|
var AllowListPolicy = class {
|
|
23
53
|
rules;
|
|
24
54
|
constructor(rules) {
|
|
@@ -26,7 +56,8 @@ var AllowListPolicy = class {
|
|
|
26
56
|
}
|
|
27
57
|
async decide(ask, _signal) {
|
|
28
58
|
const what = `${ask.title ?? "a tool call"} (${ask.kind ?? "other"})`;
|
|
29
|
-
|
|
59
|
+
const own = convenoToolOf(ask) !== void 0;
|
|
60
|
+
if (own || isAllowed(this.rules, {
|
|
30
61
|
kind: ask.kind,
|
|
31
62
|
title: ask.title
|
|
32
63
|
})) {
|
|
@@ -34,7 +65,7 @@ var AllowListPolicy = class {
|
|
|
34
65
|
if (outcome.outcome === "selected") return {
|
|
35
66
|
allowed: true,
|
|
36
67
|
outcome,
|
|
37
|
-
reason: `allowed ${what} by the allow list`
|
|
68
|
+
reason: `allowed ${what} ${own ? "(a Conveno tool)" : "by the allow list"}`
|
|
38
69
|
};
|
|
39
70
|
return {
|
|
40
71
|
allowed: false,
|
|
@@ -71,7 +102,7 @@ var ToolTracker = class {
|
|
|
71
102
|
return u.sessionUpdate === "tool_call" ? next.title ?? next.kind ?? "tool" : void 0;
|
|
72
103
|
}
|
|
73
104
|
};
|
|
74
|
-
const HOST_VERSION = "0.2.0-rc.
|
|
105
|
+
const HOST_VERSION = "0.2.0-rc.13";
|
|
75
106
|
/** A stop request file: `conveno stop` writes it next to the spawn record. */
|
|
76
107
|
const stopRequestPath = (recordPath) => recordPath.replace(/\.json$/, ".stop");
|
|
77
108
|
function withTimeout(p, ms, what) {
|
|
@@ -126,6 +157,8 @@ var AcpHost = class {
|
|
|
126
157
|
/** The status line after a failed prompt, kept until the next prompt starts. */
|
|
127
158
|
failedText;
|
|
128
159
|
denials = [];
|
|
160
|
+
/** The worker called Conveno's `send` (or `handoff`) in the turn that is running. */
|
|
161
|
+
sentThisTurn = false;
|
|
129
162
|
lastStatus;
|
|
130
163
|
timers = [];
|
|
131
164
|
constructor(spec, deps) {
|
|
@@ -245,6 +278,10 @@ var AcpHost = class {
|
|
|
245
278
|
...agentVersion ? { cliVersion: agentVersion } : {}
|
|
246
279
|
});
|
|
247
280
|
this.sessionId = session.id;
|
|
281
|
+
await this.client["session.setNative"]({
|
|
282
|
+
sessionId: session.id,
|
|
283
|
+
nativeId: created.sessionId.slice(0, 256)
|
|
284
|
+
}).catch((e) => this.log(`could not record the ACP session id: ${errText(e)}`));
|
|
248
285
|
updateSpawnRecord(spec.record, {
|
|
249
286
|
pid: process.pid,
|
|
250
287
|
sessionId: session.id,
|
|
@@ -257,9 +294,9 @@ var AcpHost = class {
|
|
|
257
294
|
let next = this.spec.task ?? null;
|
|
258
295
|
if (next === null) await this.status("idle", null);
|
|
259
296
|
while (!this.stopping) if (next !== null) {
|
|
260
|
-
await this.prompt(next);
|
|
297
|
+
const finished = await this.prompt(next);
|
|
261
298
|
if (this.stopping) break;
|
|
262
|
-
await this.
|
|
299
|
+
await this.reportTurnEnd(finished);
|
|
263
300
|
next = await this.endTurn();
|
|
264
301
|
} else next = await this.waitForWork();
|
|
265
302
|
}
|
|
@@ -286,14 +323,18 @@ var AcpHost = class {
|
|
|
286
323
|
return null;
|
|
287
324
|
}
|
|
288
325
|
}
|
|
289
|
-
/**
|
|
326
|
+
/**
|
|
327
|
+
* One prompt turn. Resolves when the agent answers `session/prompt` or the host stops. True when
|
|
328
|
+
* the turn ran to its end; false when the prompt failed (the spawner was told) or the host stopped.
|
|
329
|
+
*/
|
|
290
330
|
async prompt(text) {
|
|
291
331
|
const conn = this.conn;
|
|
292
332
|
const sid = this.acpSessionId;
|
|
293
|
-
if (!conn || !sid) return;
|
|
333
|
+
if (!conn || !sid) return false;
|
|
294
334
|
this.turnCtl = new AbortController();
|
|
295
335
|
this.failedText = void 0;
|
|
296
336
|
this.denials = [];
|
|
337
|
+
this.sentThisTurn = false;
|
|
297
338
|
await this.status("busy", null);
|
|
298
339
|
const turn = conn.agent.request(methods.agent.session.prompt, {
|
|
299
340
|
sessionId: sid,
|
|
@@ -309,12 +350,14 @@ var AcpHost = class {
|
|
|
309
350
|
const reason = requestReason(e);
|
|
310
351
|
this.log(`session/prompt failed: ${reason}`);
|
|
311
352
|
await this.promptFailed(reason);
|
|
312
|
-
return;
|
|
353
|
+
return false;
|
|
313
354
|
}
|
|
314
355
|
await conn.agent.notify(methods.agent.session.cancel, { sessionId: sid }).catch(() => void 0);
|
|
315
356
|
const grace = this.deps.stopGraceMs ?? 5e3;
|
|
316
357
|
await Promise.race([turn.then(() => void 0, () => void 0), new Promise((r) => setTimeout(r, grace).unref())]);
|
|
358
|
+
return false;
|
|
317
359
|
}
|
|
360
|
+
return true;
|
|
318
361
|
}
|
|
319
362
|
/**
|
|
320
363
|
* Idle: wait until the daemon hands this session messages through `turn.wake`, then return the
|
|
@@ -382,6 +425,8 @@ var AcpHost = class {
|
|
|
382
425
|
onUpdate(n) {
|
|
383
426
|
if (n.sessionId !== this.acpSessionId) return;
|
|
384
427
|
const doing = this.tools.update(n.update);
|
|
428
|
+
const id = n.update.toolCallId;
|
|
429
|
+
if (id !== void 0) this.noteConvenoCall(this.tools.tools.get(id));
|
|
385
430
|
if (doing !== void 0 && doing !== this.lastStatus) {
|
|
386
431
|
this.lastStatus = doing;
|
|
387
432
|
this.status(void 0, doing);
|
|
@@ -392,6 +437,10 @@ var AcpHost = class {
|
|
|
392
437
|
const known = this.tools.tools.get(p.toolCall.toolCallId) ?? {};
|
|
393
438
|
const title = p.toolCall.title ?? known.title;
|
|
394
439
|
const kind = p.toolCall.kind ?? known.kind;
|
|
440
|
+
this.noteConvenoCall({
|
|
441
|
+
title,
|
|
442
|
+
kind
|
|
443
|
+
});
|
|
395
444
|
const ask = {
|
|
396
445
|
toolCallId: p.toolCall.toolCallId,
|
|
397
446
|
...title ? { title } : {},
|
|
@@ -451,17 +500,32 @@ var AcpHost = class {
|
|
|
451
500
|
this.lastPromptFailure = reason;
|
|
452
501
|
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
502
|
}
|
|
454
|
-
/**
|
|
455
|
-
|
|
456
|
-
if (
|
|
457
|
-
const
|
|
458
|
-
if (
|
|
503
|
+
/** Remember that the worker sent something this turn. Only Conveno's own send tools count. */
|
|
504
|
+
noteConvenoCall(call) {
|
|
505
|
+
if (!call) return;
|
|
506
|
+
const tool = convenoToolOf(call);
|
|
507
|
+
if (tool === "send" || tool === "handoff") this.sentThisTurn = true;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* One note to the spawner about the turn that just ended: the worker finished without sending
|
|
511
|
+
* anything, and/or which tool calls were denied. Nothing when there is no spawner (a spawn from
|
|
512
|
+
* a terminal), when the worker did reply and nothing was denied, or when the prompt failed.
|
|
513
|
+
*/
|
|
514
|
+
async reportTurnEnd(finished) {
|
|
515
|
+
const denials = this.denials;
|
|
459
516
|
this.denials = [];
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
]
|
|
517
|
+
if (!this.spec.spawnedBy) return;
|
|
518
|
+
const silent = finished && !this.sentThisTurn;
|
|
519
|
+
if (denials.length === 0 && !silent) return;
|
|
520
|
+
const who = `[conveno] Worker ${this.spec.name} (${this.spec.cli}, over ACP)`;
|
|
521
|
+
const lines = [];
|
|
522
|
+
if (silent) lines.push(`${who} finished its turn without replying.`);
|
|
523
|
+
if (denials.length > 0) {
|
|
524
|
+
const list = denials.slice(0, 5).map((d) => `- ${d}`);
|
|
525
|
+
if (denials.length > 5) list.push(`- and ${denials.length - 5} more`);
|
|
526
|
+
lines.push(silent ? "It was denied these tool calls in its last turn, because its spawn limited it to an allow list:" : `${who} was denied these tool calls in its last turn, because its spawn limited it to an allow list:`, ...list, "The allow list it was spawned with does not cover them. Spawn it again with a wider allow list, or none for full access.");
|
|
527
|
+
}
|
|
528
|
+
await this.tell(lines.join("\n"));
|
|
465
529
|
}
|
|
466
530
|
/** Send a text message from this session to its spawner. Never throws. */
|
|
467
531
|
async tell(text) {
|
|
@@ -522,6 +586,8 @@ var AcpHost = class {
|
|
|
522
586
|
this.log(`stopped: ${describeStop(reason)}`);
|
|
523
587
|
}
|
|
524
588
|
};
|
|
589
|
+
/** Set on every agent the ACP host starts. `conveno hook` exits at once when it is set. */
|
|
590
|
+
const ACP_WORKER_ENV = "CONVENO_ACP_WORKER";
|
|
525
591
|
/**
|
|
526
592
|
* End `pid` and its descendants. POSIX: the agent leads its own process group (it was started
|
|
527
593
|
* detached), so the whole group gets SIGKILL. Windows has no process groups; `taskkill /T` ends the
|
|
@@ -566,7 +632,10 @@ function startAgentProcess(opts) {
|
|
|
566
632
|
],
|
|
567
633
|
detached: platform !== "win32",
|
|
568
634
|
windowsHide: true,
|
|
569
|
-
env:
|
|
635
|
+
env: {
|
|
636
|
+
...opts.env ?? process.env,
|
|
637
|
+
[ACP_WORKER_ENV]: "1"
|
|
638
|
+
},
|
|
570
639
|
...opts.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
|
|
571
640
|
});
|
|
572
641
|
const exited = new Promise((r) => {
|
|
@@ -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 { Ct as parseCliVersion, Dt as pendingHookContext, K as endTurnContinuation, Mt as planProgram, Nt as planSpawn, X as findOnPath, in as startTurnContext, xt as ownSession } from "./dist-DnNuDzEA.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) {
|
|
@@ -607,7 +612,8 @@ const EMPTY = {
|
|
|
607
612
|
* continuation would otherwise wait for the user. Conveno's wake limit bounds the chain.
|
|
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,23 +637,36 @@ async function hook(event, input, ctx) {
|
|
|
631
637
|
};
|
|
632
638
|
}
|
|
633
639
|
/**
|
|
634
|
-
* The
|
|
635
|
-
*
|
|
636
|
-
*
|
|
637
|
-
*
|
|
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.
|
|
638
644
|
*/
|
|
639
|
-
async function
|
|
640
|
-
|
|
641
|
-
if (typeof threadId !== "string" || threadId === "") return;
|
|
645
|
+
async function retireThread(ctx) {
|
|
646
|
+
if (ctx.nativeId === void 0) return EMPTY;
|
|
642
647
|
try {
|
|
643
648
|
const session = await ownSession(ctx);
|
|
644
|
-
if (
|
|
645
|
-
const call = ctx.client["session.setNative"];
|
|
646
|
-
if (typeof call === "function") await call({
|
|
647
|
-
sessionId: session.id,
|
|
648
|
-
nativeId: threadId
|
|
649
|
-
});
|
|
649
|
+
if (session) await ctx.client["session.unregister"]({ sessionId: session.id });
|
|
650
650
|
} catch {}
|
|
651
|
+
return EMPTY;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* The hook's `session_id` is the Codex thread id, the id `codex queue --thread` takes. Codex
|
|
655
|
+
* threads can share one app-server process, so the host pid alone may not tell windows apart: the
|
|
656
|
+
* daemon binds the thread to the window's session (`session.bind`), and wakes the session by it.
|
|
657
|
+
* A session start or a prompt may move the window to the thread; a Stop of any other thread than
|
|
658
|
+
* the session's current one is ignored. With several windows on one process the daemon may not
|
|
659
|
+
* know which one the hook is in; the thread's own MCP server binds it on its first tool call.
|
|
660
|
+
*/
|
|
661
|
+
function withThread(input, ctx, event) {
|
|
662
|
+
const threadId = asObject(input).session_id;
|
|
663
|
+
if (typeof threadId !== "string" || threadId === "") return ctx;
|
|
664
|
+
return {
|
|
665
|
+
...ctx,
|
|
666
|
+
cli: ctx.cli ?? "codex",
|
|
667
|
+
nativeId: threadId,
|
|
668
|
+
turnStart: event === "SessionStart" || event === "UserPromptSubmit"
|
|
669
|
+
};
|
|
651
670
|
}
|
|
652
671
|
/** How long `codex queue` may take (it probes the shared local app-server) before we give up. */
|
|
653
672
|
const QUEUE_TIMEOUT_MS = 2e4;
|
|
@@ -859,6 +878,7 @@ const STATE_EVENTS = {
|
|
|
859
878
|
SessionStart: "session_start",
|
|
860
879
|
UserPromptSubmit: "user_prompt_submit",
|
|
861
880
|
Stop: "stop",
|
|
881
|
+
SessionEnd: "session_end",
|
|
862
882
|
PermissionRequest: "permission_request"
|
|
863
883
|
};
|
|
864
884
|
/**
|
|
@@ -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 { En as PROTOCOL_VERSION, Fn as encodeFrame, Ft as proofsMatch, In as ipcMethods, Jn as socketPathTooLongMessage, L as daemonProof, Ln as isSocketPathTooLong, Nn as createLineDecoder, On as RpcErrorCode, Pn as defaultSocketPath, R as dataDir, Sn as EventPayload, a as ConvenoError, j as clientProof, kn as RpcResponse, yt as newAuthNonce, z as dataPaths } from "./dist-DnNuDzEA.js";
|
|
7
7
|
// ../client/dist/index.js
|
|
8
8
|
const DEFAULT_REQUEST_TIMEOUT_MS = 5e3;
|
|
9
9
|
const DEFAULT_START_TIMEOUT_MS = 1e4;
|
|
@@ -12,11 +12,13 @@ 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",
|
|
18
19
|
"session.hostOf",
|
|
19
20
|
"session.setNative",
|
|
21
|
+
"session.bind",
|
|
20
22
|
"turn.start",
|
|
21
23
|
"turn.end",
|
|
22
24
|
"turn.wake",
|
|
@@ -146,6 +148,8 @@ var Connection = class {
|
|
|
146
148
|
pending = /* @__PURE__ */ new Map();
|
|
147
149
|
decoder = createLineDecoder();
|
|
148
150
|
closed = false;
|
|
151
|
+
/** The daemon's version, from its `hello` answer. */
|
|
152
|
+
daemonVersion;
|
|
149
153
|
constructor(socket, timeoutMs, onEvent = () => {}) {
|
|
150
154
|
this.socket = socket;
|
|
151
155
|
this.timeoutMs = timeoutMs;
|
|
@@ -253,6 +257,7 @@ async function handshake(socketPath, tokenPath, kind, timeoutMs, onEvent) {
|
|
|
253
257
|
});
|
|
254
258
|
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" });
|
|
255
259
|
await typedCall(conn, "auth", { proof: clientProof(token, hello.challenge) });
|
|
260
|
+
conn.daemonVersion = hello.daemonVersion;
|
|
256
261
|
return conn;
|
|
257
262
|
} catch (e) {
|
|
258
263
|
await conn.close();
|
|
@@ -467,6 +472,10 @@ async function connect(opts) {
|
|
|
467
472
|
onEvent: (handler) => link.onEvent(handler),
|
|
468
473
|
close: () => link.close()
|
|
469
474
|
};
|
|
475
|
+
Object.defineProperty(client, "daemonVersion", {
|
|
476
|
+
get: () => link.conn.daemonVersion,
|
|
477
|
+
enumerable: true
|
|
478
|
+
});
|
|
470
479
|
for (const method of CLIENT_METHODS) client[method] = (params) => link.call(method, params);
|
|
471
480
|
return client;
|
|
472
481
|
}
|
|
@@ -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 { $n as literal, Qn as discriminatedUnion, Xn as array, Yn as _enum, er as number, nr as string, tr as object, yn as DeviceId } from "./dist-DnNuDzEA.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";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile, readdir } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { Ct as parseCliVersion, Dt as pendingHookContext, J as existedBefore, K as endTurnContinuation, M as compareVersions, R as dataDir, S as askedMarker, U as dropFromList, W as editJson, dn as uninstallLauncher, en as sameJson, ft as late, ht as loadJson, jt as planLauncher, lt as isObject, vt as needsQuoting, xt as ownSession, y as agentCommand } from "./dist-DnNuDzEA.js";
|
|
4
4
|
// ../adapters/antigravity/dist/index.js
|
|
5
5
|
const SERVER_NAME = "conveno";
|
|
6
6
|
/** The name of our entry in hooks.json. Antigravity keys hooks by an arbitrary name. */
|
|
@@ -554,23 +554,63 @@ async function uninstallPlan(env, baseline) {
|
|
|
554
554
|
}
|
|
555
555
|
const UUID = /^[0-9a-fA-F-]{8,64}$/;
|
|
556
556
|
/**
|
|
557
|
-
* The
|
|
558
|
-
* (`session.
|
|
559
|
-
*
|
|
557
|
+
* The hook's context with its conversation id, which the daemon binds to the window's session
|
|
558
|
+
* (`session.bind`): that is how `conveno agy-relay` finds its session, and the window's session
|
|
559
|
+
* follows `/new` and `/resume`. A session start or a model call may move the window to the
|
|
560
|
+
* conversation; a Stop of any other conversation than the current one is ignored.
|
|
560
561
|
*/
|
|
561
|
-
|
|
562
|
+
function withConversation(input, ctx, turnStart) {
|
|
563
|
+
const id = isObject(input) ? input.conversationId : void 0;
|
|
564
|
+
if (typeof id !== "string" || !UUID.test(id)) return ctx;
|
|
565
|
+
return {
|
|
566
|
+
...ctx,
|
|
567
|
+
cli: ctx.cli ?? "antigravity",
|
|
568
|
+
nativeId: id,
|
|
569
|
+
turnStart
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
/** The session that owns this hook, or null when none does or on any failure. Never throws. */
|
|
573
|
+
async function sessionOf(ctx) {
|
|
562
574
|
try {
|
|
563
|
-
|
|
564
|
-
const id = isObject(input) ? input.conversationId : void 0;
|
|
565
|
-
if (!session || typeof id !== "string" || !UUID.test(id) || session.nativeId === id) return session;
|
|
566
|
-
return (await ctx.client["session.setNative"]({
|
|
567
|
-
sessionId: session.id,
|
|
568
|
-
nativeId: id
|
|
569
|
-
})).session;
|
|
575
|
+
return await ownSession(ctx);
|
|
570
576
|
} catch {
|
|
571
577
|
return null;
|
|
572
578
|
}
|
|
573
579
|
}
|
|
580
|
+
/** The folder the hook says the agent works in: the first of `workspacePaths`, else `cwd`. */
|
|
581
|
+
function workspaceOf(input) {
|
|
582
|
+
if (!isObject(input)) return void 0;
|
|
583
|
+
const paths = input.workspacePaths;
|
|
584
|
+
const first = Array.isArray(paths) ? paths[0] : void 0;
|
|
585
|
+
const dir = typeof first === "string" && first !== "" ? first : input.cwd;
|
|
586
|
+
return typeof dir === "string" && dir !== "" ? dir : void 0;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Is the transcript in the Antigravity desktop app's product folder (`antigravity/`), not the CLI's
|
|
590
|
+
* (`antigravity-cli/`) or the IDE's (`antigravity-ide/`)? A second signal next to the process chain.
|
|
591
|
+
*/
|
|
592
|
+
function appTranscript(input) {
|
|
593
|
+
const t = isObject(input) ? input.transcriptPath : void 0;
|
|
594
|
+
return typeof t === "string" && t.split(/[\\/]/).includes("antigravity");
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* The desktop app starts Conveno in its install folder; a hook knows the workspace. Tell the daemon
|
|
598
|
+
* when an app session works elsewhere, and the row moves there. A CLI row is never sent: it already
|
|
599
|
+
* runs in the folder the user opened. Never throws.
|
|
600
|
+
*/
|
|
601
|
+
async function followWorkspace(input, ctx, session) {
|
|
602
|
+
const app = session.variant === "app" || appTranscript(input);
|
|
603
|
+
const dir = workspaceOf(input);
|
|
604
|
+
if (!app || dir === void 0) return;
|
|
605
|
+
if (session.variant === "app" && dir === session.cwd) return;
|
|
606
|
+
try {
|
|
607
|
+
await ctx.client["session.setCwd"]({
|
|
608
|
+
sessionId: session.id,
|
|
609
|
+
cwd: dir,
|
|
610
|
+
...session.variant === "app" ? {} : { variant: "app" }
|
|
611
|
+
});
|
|
612
|
+
} catch {}
|
|
613
|
+
}
|
|
574
614
|
/** What the Stop hook asks once per turn while no relay is connected. */
|
|
575
615
|
/** The relay request is asked once per Conveno session (a one-shot `agy -p` run counts each retry as a new turn). */
|
|
576
616
|
const relayAsk = askedMarker("agy-relay-asked");
|
|
@@ -592,7 +632,9 @@ const isHookEvent = (e) => HOOK_EVENTS.includes(e);
|
|
|
592
632
|
*/
|
|
593
633
|
async function hook(event, input, ctx) {
|
|
594
634
|
if (!isHookEvent(event)) return EMPTY;
|
|
595
|
-
|
|
635
|
+
ctx = withConversation(input, ctx, event !== "Stop");
|
|
636
|
+
const session = await sessionOf(ctx);
|
|
637
|
+
if (session !== null) await followWorkspace(input, ctx, session);
|
|
596
638
|
if (event === "Stop") {
|
|
597
639
|
const stop = isObject(input) ? input : {};
|
|
598
640
|
const completed = (stop.terminationReason === void 0 || stop.terminationReason === "NO_TOOL_CALL") && (stop.error === void 0 || stop.error === "");
|
|
@@ -639,6 +681,7 @@ const antigravityAdapter = {
|
|
|
639
681
|
detect,
|
|
640
682
|
plan,
|
|
641
683
|
optional: [relayOption],
|
|
684
|
+
doctorNotes: async () => ["The Antigravity app shares the CLI's settings, so Conveno is set up in both. App sessions show as \"Antigravity app\"."],
|
|
642
685
|
uninstallPlan,
|
|
643
686
|
hook
|
|
644
687
|
};
|