@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,4 +1,5 @@
|
|
|
1
1
|
import { appendFileSync } from "node:fs";
|
|
2
|
+
import { b as appendHookLog, nt as hookLogLine } from "./dist-DnNuDzEA.js";
|
|
2
3
|
import { n as connectOpts } from "./ctx-tYftvhz_.js";
|
|
3
4
|
// src/hook.ts
|
|
4
5
|
/**
|
|
@@ -39,8 +40,59 @@ async function findHostPid(ctx, client, cli, local) {
|
|
|
39
40
|
function timingLine(cli, event, ms, procMs, timedOut) {
|
|
40
41
|
return `${(/* @__PURE__ */ new Date()).toISOString()} cli=${cli} event=${event} ms=${ms}${procMs === void 0 ? "" : ` proc_ms=${procMs}`} timeout=${timedOut ? "yes" : "no"}\n`;
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The client with its answers noted in `trace`: the session a lookup resolved to, the messages
|
|
45
|
+
* handed over, the turn state recorded. The hook sees the same client.
|
|
46
|
+
*/
|
|
47
|
+
function traced(client, trace) {
|
|
48
|
+
return new Proxy(client, { get(target, prop, receiver) {
|
|
49
|
+
const value = Reflect.get(target, prop, receiver);
|
|
50
|
+
if (typeof prop !== "string" || !prop.includes(".") || typeof value !== "function") return value;
|
|
51
|
+
return async (...args) => {
|
|
52
|
+
let r;
|
|
53
|
+
try {
|
|
54
|
+
r = await value.apply(target, args);
|
|
55
|
+
} catch (e) {
|
|
56
|
+
const code = e?.code;
|
|
57
|
+
trace.error = `error ${typeof code === "number" || typeof code === "string" ? code : "unknown"}`;
|
|
58
|
+
throw e;
|
|
59
|
+
}
|
|
60
|
+
const out = r;
|
|
61
|
+
const count = Array.isArray(out?.messages) ? out.messages.length : 0;
|
|
62
|
+
if ((prop === "session.bind" || prop === "session.byHost") && out?.session?.name) trace.session = out.session.name;
|
|
63
|
+
else if (prop === "turn.start") trace.turn = "busy";
|
|
64
|
+
else if (prop === "turn.end") {
|
|
65
|
+
trace.delivered += count;
|
|
66
|
+
trace.turn = count > 0 ? "busy" : "idle";
|
|
67
|
+
} else if (prop === "message.deliver" || prop === "turn.wake") trace.delivered += count;
|
|
68
|
+
return r;
|
|
69
|
+
};
|
|
70
|
+
} });
|
|
71
|
+
}
|
|
72
|
+
/** The CLI's own conversation id in a hook's input, whichever way that CLI spells it. */
|
|
73
|
+
function conversationIn(input) {
|
|
74
|
+
if (typeof input !== "object" || input === null) return void 0;
|
|
75
|
+
const o = input;
|
|
76
|
+
for (const key of [
|
|
77
|
+
"session_id",
|
|
78
|
+
"sessionId",
|
|
79
|
+
"sessionID",
|
|
80
|
+
"conversationId"
|
|
81
|
+
]) {
|
|
82
|
+
const v = o[key];
|
|
83
|
+
if (typeof v === "string" && v !== "") return v;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
42
86
|
/** After a timeout, the hook gets this many more timeouts' worth of time to finish recording. */
|
|
43
87
|
const FINISH_GRACE_FACTOR = 2;
|
|
88
|
+
/**
|
|
89
|
+
* Every CLI kills a hook 5 s after it starts (`HOOK_TIMEOUT_SECONDS` in each adapter). The budget
|
|
90
|
+
* and the finish grace together stay under this, so the process ends by itself with its outcome
|
|
91
|
+
* logged instead of being killed mid-write. The rest is left for process start-up.
|
|
92
|
+
*/
|
|
93
|
+
const HOOK_TOTAL_MAX_MS = 4800;
|
|
94
|
+
/** How long a timed-out hook may keep running to record its turn: capped so budget + grace fits. */
|
|
95
|
+
const finishGraceMs = (timeoutMs) => Math.max(0, Math.min(timeoutMs * FINISH_GRACE_FACTOR, HOOK_TOTAL_MAX_MS - timeoutMs));
|
|
44
96
|
/** How long before the hook's timeout its messages count as too late to print. */
|
|
45
97
|
const DEADLINE_MARGIN_MS = 300;
|
|
46
98
|
/**
|
|
@@ -59,8 +111,15 @@ async function runHook(ctx, argv) {
|
|
|
59
111
|
if (!adapter || !event) return 0;
|
|
60
112
|
const listener = adapter.listenEvents?.includes(event) === true;
|
|
61
113
|
const deadline = listener ? void 0 : Date.now() + ctx.hookTimeoutMs - DEADLINE_MARGIN_MS;
|
|
62
|
-
const
|
|
114
|
+
const started = Date.now();
|
|
115
|
+
const t0 = ctx.timingLog && !listener ? started : void 0;
|
|
116
|
+
const trace = { delivered: 0 };
|
|
117
|
+
let conversation;
|
|
63
118
|
let timedOut = false;
|
|
119
|
+
let workDone = false;
|
|
120
|
+
let hostMs;
|
|
121
|
+
let hostResolved = false;
|
|
122
|
+
let hostMissing = false;
|
|
64
123
|
let client;
|
|
65
124
|
let timer;
|
|
66
125
|
const early = ctx.hostLookup ? void 0 : ctx.ancestry(HOOK_ANCESTRY_TIMEOUT_MS);
|
|
@@ -74,17 +133,39 @@ async function runHook(ctx, argv) {
|
|
|
74
133
|
}
|
|
75
134
|
};
|
|
76
135
|
const [input, connected] = await Promise.all([readInput(), ctx.connect(connectOpts(ctx, false))]);
|
|
77
|
-
client = connected;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
136
|
+
client = ctx.hookLog ? traced(connected, trace) : connected;
|
|
137
|
+
if (ctx.hookLog) conversation = conversationIn(input);
|
|
138
|
+
let hostPid;
|
|
139
|
+
const resolveHostPid = () => {
|
|
140
|
+
hostPid ??= (async () => {
|
|
141
|
+
const t = Date.now();
|
|
142
|
+
try {
|
|
143
|
+
const pid = await findHostPid(ctx, connected, adapter.cli, () => early ?? ctx.ancestry(1200));
|
|
144
|
+
if (pid === void 0) hostMissing = true;
|
|
145
|
+
return pid;
|
|
146
|
+
} finally {
|
|
147
|
+
hostMs = Date.now() - t;
|
|
148
|
+
hostResolved = true;
|
|
149
|
+
}
|
|
150
|
+
})();
|
|
151
|
+
return hostPid;
|
|
152
|
+
};
|
|
153
|
+
const out = await adapter.hook(event, input, {
|
|
81
154
|
client,
|
|
82
|
-
|
|
155
|
+
resolveHostPid,
|
|
156
|
+
...ctx.hostLookup ? { ppid: ctx.hostLookup.ppid } : {},
|
|
83
157
|
cli: adapter.cli,
|
|
84
158
|
isAlive: ctx.isAlive,
|
|
85
159
|
...deadline === void 0 ? {} : { deadline }
|
|
86
160
|
});
|
|
161
|
+
if (hostResolved && hostMissing) await adapter.hookWithoutSession?.(event, input).catch(() => {});
|
|
162
|
+
return out;
|
|
87
163
|
})();
|
|
164
|
+
work.then(() => {
|
|
165
|
+
workDone = true;
|
|
166
|
+
}, () => {
|
|
167
|
+
workDone = true;
|
|
168
|
+
});
|
|
88
169
|
const timeout = listener ? new Promise(() => void 0) : new Promise((resolve) => {
|
|
89
170
|
timer = setTimeout(() => {
|
|
90
171
|
timedOut = true;
|
|
@@ -94,11 +175,24 @@ async function runHook(ctx, argv) {
|
|
|
94
175
|
let code = 0;
|
|
95
176
|
try {
|
|
96
177
|
const out = await Promise.race([work, timeout]);
|
|
97
|
-
if (out === NOTHING && !listener) await Promise.race([work.catch(() => void 0), new Promise((r) => setTimeout(r, ctx.hookTimeoutMs
|
|
178
|
+
if (out === NOTHING && !listener) await Promise.race([work.catch(() => void 0), new Promise((r) => setTimeout(r, finishGraceMs(ctx.hookTimeoutMs)))]);
|
|
98
179
|
if (out.stdout) ctx.out(out.stdout.endsWith("\n") ? out.stdout : `${out.stdout}\n`);
|
|
99
180
|
if (listener && out.stderr) ctx.err(out.stderr.endsWith("\n") ? out.stderr : `${out.stderr}\n`);
|
|
100
181
|
if (listener) code = out.exitCode;
|
|
101
182
|
} catch {} finally {
|
|
183
|
+
if (ctx.hookLog) {
|
|
184
|
+
const done = trace.error ?? (trace.delivered > 0 ? `delivered ${trace.delivered}` : trace.turn ?? "nothing");
|
|
185
|
+
const result = timedOut ? workDone ? `${done} late` : "timeout" : done;
|
|
186
|
+
appendHookLog(ctx.hookLog, hookLogLine({
|
|
187
|
+
cli: adapter.cli,
|
|
188
|
+
event,
|
|
189
|
+
conversationId: conversation,
|
|
190
|
+
session: trace.session,
|
|
191
|
+
result,
|
|
192
|
+
hostMs,
|
|
193
|
+
ms: Date.now() - started
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
102
196
|
if (t0 !== void 0 && ctx.timingLog) {
|
|
103
197
|
const up = ctx.uptimeMs?.();
|
|
104
198
|
try {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
|
-
import { n as antigravityAdapter } from "./dist-
|
|
2
|
+
import { n as antigravityAdapter } from "./dist-D4sb5RQD.js";
|
|
3
3
|
import { isAbsolute, join } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { Ct as parseCliVersion, Dt as pendingHookContext, Ht as readSettings, Jt as requeueMessages, K as endTurnContinuation, Ot as pendingTurn, R as dataDir, Rt as readAncestry, hn as waitForWorkBatch, i as CLAUDE_PENDING_TURN_FOLDER, in as startTurnContext, it as hostAlive, mn as waitForWork, rt as hookLogPath, xt as ownSession, z as dataPaths } from "./dist-DnNuDzEA.js";
|
|
5
5
|
import { readFile } from "node:fs/promises";
|
|
6
6
|
import { applyEdits, modify, parse, printParseErrorCode } from "jsonc-parser";
|
|
7
|
-
import { t as codexAdapter } from "./dist-
|
|
8
|
-
import { t as grokAdapter } from "./dist-
|
|
9
|
-
import { n as connect } from "./dist-
|
|
10
|
-
import { t as runHook } from "./hook-
|
|
7
|
+
import { t as codexAdapter } from "./dist-C9Z1EMlM.js";
|
|
8
|
+
import { t as grokAdapter } from "./dist-B14ldKRS.js";
|
|
9
|
+
import { n as connect } from "./dist-Ca3P7aN-.js";
|
|
10
|
+
import { t as runHook } from "./hook-C60hXJdg.js";
|
|
11
11
|
// ../adapters/claude/dist/index.js
|
|
12
12
|
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
13
13
|
/** Read a JSON object file. Missing or blank files give `{}`; anything else that is not a JSON object throws. */
|
|
@@ -67,7 +67,8 @@ const HOOK_EVENTS = [
|
|
|
67
67
|
"SessionStart",
|
|
68
68
|
"UserPromptSubmit",
|
|
69
69
|
"PostToolUse",
|
|
70
|
-
"Stop"
|
|
70
|
+
"Stop",
|
|
71
|
+
"SessionEnd"
|
|
71
72
|
];
|
|
72
73
|
/** Older versions also installed a PermissionRequest hook; uninstall still removes it. */
|
|
73
74
|
const LEGACY_HOOK_EVENTS = ["PermissionRequest"];
|
|
@@ -129,7 +130,8 @@ const HANDLERS = {
|
|
|
129
130
|
SessionStart: ["SessionStart", LISTEN_EVENT],
|
|
130
131
|
UserPromptSubmit: ["UserPromptSubmit"],
|
|
131
132
|
PostToolUse: ["PostToolUse"],
|
|
132
|
-
Stop: ["Stop", LISTEN_EVENT]
|
|
133
|
+
Stop: ["Stop", LISTEN_EVENT],
|
|
134
|
+
SessionEnd: ["SessionEnd"]
|
|
133
135
|
};
|
|
134
136
|
const EMPTY$1 = {
|
|
135
137
|
stdout: "",
|
|
@@ -151,7 +153,7 @@ function paths(env) {
|
|
|
151
153
|
* The program and arguments of one hook, in exec form: Claude Code spawns `command` with `args` and
|
|
152
154
|
* no shell, so nothing is quoted and Git Bash, PowerShell and `sh` read it alike
|
|
153
155
|
* (https://code.claude.com/docs/en/hooks, "Exec form and shell form"; `args` since Claude Code
|
|
154
|
-
* 2.1.139,
|
|
156
|
+
* 2.1.139, the `minimum` in compat.json). On Windows `command` must be a real executable, not an
|
|
155
157
|
* npm `.cmd` shim, so a bare `conveno` there becomes `node <conveno's script>`, the pattern the
|
|
156
158
|
* docs give for npm tools.
|
|
157
159
|
*/
|
|
@@ -202,7 +204,7 @@ const desiredServer = (env) => {
|
|
|
202
204
|
env: {}
|
|
203
205
|
};
|
|
204
206
|
};
|
|
205
|
-
const OUR_EVENTS = /^(SessionStart|UserPromptSubmit|PostToolUse|Stop|Listen|PermissionRequest)$/;
|
|
207
|
+
const OUR_EVENTS = /^(SessionStart|UserPromptSubmit|PostToolUse|Stop|SessionEnd|Listen|PermissionRequest)$/;
|
|
206
208
|
/**
|
|
207
209
|
* Recognizes our hook handler even if the conveno path changed since install: exec form (`args`
|
|
208
210
|
* ending in `hook claude <event>`) or the shell form older versions wrote.
|
|
@@ -391,7 +393,7 @@ async function uninstallPlan$1(env) {
|
|
|
391
393
|
path: p.settings,
|
|
392
394
|
before: setFile.raw,
|
|
393
395
|
after: editJson(setFile, edits),
|
|
394
|
-
description: "Remove the Conveno SessionStart, UserPromptSubmit, PostToolUse and
|
|
396
|
+
description: "Remove the Conveno SessionStart, UserPromptSubmit, PostToolUse, Stop and SessionEnd hooks and the listener."
|
|
395
397
|
});
|
|
396
398
|
}
|
|
397
399
|
return changes;
|
|
@@ -417,38 +419,58 @@ function claudeSessionId(input) {
|
|
|
417
419
|
return isObject(input) && typeof input.session_id === "string" && input.session_id !== "" ? input.session_id : void 0;
|
|
418
420
|
}
|
|
419
421
|
/**
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
* (
|
|
424
|
-
*
|
|
425
|
-
* Never throws: on any failure the pid lookup of the helpers applies.
|
|
422
|
+
* The hook's context with Claude Code's own session id, which the daemon binds to the window's
|
|
423
|
+
* session (`session.bind`): `/clear`, `--resume` and `--continue` give a new id to the same window,
|
|
424
|
+
* and the window's session follows it. `turnStart` says whether this event may move the window to
|
|
425
|
+
* the id (a session start or a prompt); any other event of a session that is not the window's
|
|
426
|
+
* current one is ignored.
|
|
426
427
|
*/
|
|
427
|
-
|
|
428
|
+
function withSessionId(ctx, input, turnStart) {
|
|
428
429
|
const nativeId = claudeSessionId(input);
|
|
429
430
|
if (nativeId === void 0 || ctx.nativeId !== void 0) return ctx;
|
|
431
|
+
return {
|
|
432
|
+
...ctx,
|
|
433
|
+
cli: ctx.cli ?? "claude",
|
|
434
|
+
nativeId,
|
|
435
|
+
turnStart
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
/** `source` of a SessionStart input: startup, resume, clear, compact or fork. */
|
|
439
|
+
const startSource = (input) => isObject(input) && typeof input.source === "string" ? input.source : void 0;
|
|
440
|
+
/** The notes of turns that started before their session registered (`pendingTurn`). */
|
|
441
|
+
const pendingTurns = () => pendingTurn(dataDir(process.platform, process.env, homedir()), CLAUDE_PENDING_TURN_FOLDER);
|
|
442
|
+
/**
|
|
443
|
+
* No Claude Code session is online yet: a prompt that comes now (Claude Code started with one)
|
|
444
|
+
* leaves its note, so the MCP server starts the turn when it registers.
|
|
445
|
+
*/
|
|
446
|
+
async function hookWithoutSession(event, input) {
|
|
447
|
+
if (event !== "UserPromptSubmit") return;
|
|
448
|
+
const id = claudeSessionId(input);
|
|
449
|
+
if (id !== void 0) await pendingTurns().mark(id);
|
|
450
|
+
}
|
|
451
|
+
/** A turn that ended no longer waits for its session to register. */
|
|
452
|
+
async function clearPendingTurn(input) {
|
|
453
|
+
const id = claudeSessionId(input);
|
|
454
|
+
if (id !== void 0) await pendingTurns().clear(id);
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Whether a listener armed by this SessionStart may listen. A window that has just started is
|
|
458
|
+
* woken before its first prompt only when the user asked for it (`wakeBeforeFirstPrompt`) or the
|
|
459
|
+
* lead started it. Every other start (resume, clear, compact, fork) and every Stop listens.
|
|
460
|
+
*/
|
|
461
|
+
async function mayListen(ctx, input) {
|
|
462
|
+
if (!isObject(input) || input.hook_event_name !== "SessionStart") return true;
|
|
463
|
+
if (startSource(input) !== "startup") return true;
|
|
430
464
|
try {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
};
|
|
439
|
-
const byPid = await client["session.byHost"]({ pid });
|
|
440
|
-
if (byPid.session?.cli !== "claude") return ctx;
|
|
441
|
-
await client["session.setNative"]({
|
|
442
|
-
sessionId: byPid.session.id,
|
|
443
|
-
nativeId
|
|
444
|
-
});
|
|
445
|
-
return {
|
|
446
|
-
...ctx,
|
|
447
|
-
nativeId
|
|
448
|
-
};
|
|
449
|
-
} catch {
|
|
450
|
-
return ctx;
|
|
465
|
+
if (readSettings(dataPaths(process.platform, dataDir(process.platform, process.env, homedir())).settings).wakeBeforeFirstPrompt === true) return true;
|
|
466
|
+
} catch {}
|
|
467
|
+
for (let i = 0; i < 20; i++) {
|
|
468
|
+
const session = await ownSession(ctx).catch(() => null);
|
|
469
|
+
if (session) return session.spawned;
|
|
470
|
+
if (!await hostAlive(ctx)) return false;
|
|
471
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
451
472
|
}
|
|
473
|
+
return false;
|
|
452
474
|
}
|
|
453
475
|
/**
|
|
454
476
|
* Never throws: any failure means "deliver nothing this time". What a hook prints stays within
|
|
@@ -476,22 +498,38 @@ async function hook$1(event, input, ctx) {
|
|
|
476
498
|
deadline: Date.now() + DELIVER_DEADLINE_MS
|
|
477
499
|
};
|
|
478
500
|
switch (event) {
|
|
479
|
-
case "SessionStart": return contextOutput(event, await pendingHookContext(
|
|
480
|
-
case "UserPromptSubmit":
|
|
501
|
+
case "SessionStart": return contextOutput(event, await pendingHookContext(withSessionId(ctx, input, true), opts));
|
|
502
|
+
case "UserPromptSubmit": {
|
|
503
|
+
const own = withSessionId(ctx, input, true);
|
|
504
|
+
const id = own.nativeId;
|
|
505
|
+
const onNoSession = async () => {
|
|
506
|
+
if (id !== void 0) await pendingTurns().mark(id);
|
|
507
|
+
};
|
|
508
|
+
return contextOutput(event, await startTurnContext(own, {
|
|
509
|
+
...opts,
|
|
510
|
+
onNoSession
|
|
511
|
+
}));
|
|
512
|
+
}
|
|
481
513
|
case "PostToolUse":
|
|
482
514
|
if (inSubagent(input)) return EMPTY$1;
|
|
483
|
-
return contextOutput(event, await pendingHookContext(
|
|
515
|
+
return contextOutput(event, await pendingHookContext(withSessionId(ctx, input, false), opts));
|
|
484
516
|
case "Stop": {
|
|
485
|
-
|
|
517
|
+
await clearPendingTurn(input);
|
|
518
|
+
const reason = await endTurnContinuation(withSessionId(ctx, input, false), {
|
|
486
519
|
...opts,
|
|
487
520
|
allowContinue: !stopHookActive(input)
|
|
488
521
|
});
|
|
489
522
|
return contextOutput(event, reason);
|
|
490
523
|
}
|
|
524
|
+
case "SessionEnd":
|
|
525
|
+
await clearPendingTurn(input);
|
|
526
|
+
await endTurnContinuation(withSessionId(ctx, input, false), { allowContinue: false });
|
|
527
|
+
return EMPTY$1;
|
|
491
528
|
case LISTEN_EVENT: {
|
|
492
529
|
const entry = process.env.CLAUDE_CODE_ENTRYPOINT;
|
|
493
530
|
if (entry !== void 0 && NON_INTERACTIVE_ENTRYPOINTS.has(entry)) return EMPTY$1;
|
|
494
|
-
const own =
|
|
531
|
+
const own = withSessionId(ctx, input, isObject(input) && input.hook_event_name === "SessionStart");
|
|
532
|
+
if (!await mayListen(own, input)) return EMPTY$1;
|
|
495
533
|
const r = await waitForWorkBatch(own, {
|
|
496
534
|
maxMs: LISTEN_MAX_MS,
|
|
497
535
|
registerWaitMs: LISTEN_REGISTER_WAIT_MS,
|
|
@@ -499,7 +537,7 @@ async function hook$1(event, input, ctx) {
|
|
|
499
537
|
maxChars: WAKE_MAX_CHARS
|
|
500
538
|
});
|
|
501
539
|
if (r === null) return EMPTY$1;
|
|
502
|
-
if (
|
|
540
|
+
if (!await hostAlive(ctx)) {
|
|
503
541
|
await requeueMessages(ctx.client, r.sessionId, r.batch.messages);
|
|
504
542
|
return EMPTY$1;
|
|
505
543
|
}
|
|
@@ -525,6 +563,7 @@ const claudeAdapter = {
|
|
|
525
563
|
plan: plan$1,
|
|
526
564
|
uninstallPlan: uninstallPlan$1,
|
|
527
565
|
hook: hook$1,
|
|
566
|
+
hookWithoutSession,
|
|
528
567
|
listenEvents: [LISTEN_EVENT],
|
|
529
568
|
delivery: delivery$1
|
|
530
569
|
};
|
|
@@ -876,15 +915,6 @@ const V2_MIN = [
|
|
|
876
915
|
2,
|
|
877
916
|
0
|
|
878
917
|
];
|
|
879
|
-
/**
|
|
880
|
-
* The 2.x release Conveno is checked against (the 2.4.3 source). Older 2.x still gets the right
|
|
881
|
-
* config, but waking is only supported from here; doctor says so.
|
|
882
|
-
*/
|
|
883
|
-
const V2_SUPPORTED = [
|
|
884
|
-
2,
|
|
885
|
-
4,
|
|
886
|
-
0
|
|
887
|
-
];
|
|
888
918
|
/** `$XDG_CONFIG_HOME/opencode` when XDG_CONFIG_HOME is an absolute path, else `~/.config/opencode`. */
|
|
889
919
|
function configDir(env) {
|
|
890
920
|
const xdg = env.env.XDG_CONFIG_HOME;
|
|
@@ -968,12 +998,6 @@ function atLeast(v, min) {
|
|
|
968
998
|
function isV2OrLater(v) {
|
|
969
999
|
return atLeast(v, V2_MIN);
|
|
970
1000
|
}
|
|
971
|
-
/** One line for `conveno doctor` when this OpenCode is a 2.x release older than the supported one. */
|
|
972
|
-
async function opencodeDoctorNotes(env) {
|
|
973
|
-
const v = await installedVersion(env);
|
|
974
|
-
if (!v || !isV2OrLater(v) || atLeast(v, V2_SUPPORTED)) return [];
|
|
975
|
-
return [`OpenCode ${v.join(".")} is older than 2.4, the oldest 2.x Conveno supports. Update OpenCode so waking works.`];
|
|
976
|
-
}
|
|
977
1001
|
async function installedVersion(env) {
|
|
978
1002
|
try {
|
|
979
1003
|
const res = await env.exec("opencode", ["--version"]);
|
|
@@ -1155,7 +1179,8 @@ const EMPTY = {
|
|
|
1155
1179
|
* - Stopped: the turn failed or the user interrupted it. Records the end and never continues.
|
|
1156
1180
|
* - Listen: the background listener. Waits for work while the session is idle.
|
|
1157
1181
|
* - Requeue: the plugin could not send the prompt; puts the messages (`ids` in the input) back to queued.
|
|
1158
|
-
* - Deleted: the OpenCode session was deleted;
|
|
1182
|
+
* - Deleted: the OpenCode session was deleted; records that its turn is over. The window's Conveno
|
|
1183
|
+
* session stays: it follows whichever OpenCode session the user is in next.
|
|
1159
1184
|
* - Title: prints the session's Conveno name, which the plugin sets as the OpenCode session title.
|
|
1160
1185
|
*/
|
|
1161
1186
|
async function hook(event, input, ctx) {
|
|
@@ -1167,7 +1192,9 @@ async function hook(event, input, ctx) {
|
|
|
1167
1192
|
const native = typeof input === "object" && input !== null ? input.sessionID : void 0;
|
|
1168
1193
|
if (typeof native === "string" && native !== "") ctx = {
|
|
1169
1194
|
...ctx,
|
|
1170
|
-
|
|
1195
|
+
cli: ctx.cli ?? "opencode",
|
|
1196
|
+
nativeId: native,
|
|
1197
|
+
turnStart: event === "Idle" || event === "Stopped"
|
|
1171
1198
|
};
|
|
1172
1199
|
if (event === "Deleted") {
|
|
1173
1200
|
await release(ctx, input);
|
|
@@ -1205,15 +1232,14 @@ function recordIds(client, ids) {
|
|
|
1205
1232
|
};
|
|
1206
1233
|
} });
|
|
1207
1234
|
}
|
|
1208
|
-
/**
|
|
1235
|
+
/**
|
|
1236
|
+
* `Deleted`: the OpenCode session is gone. If it is the one the window's session follows, its turn
|
|
1237
|
+
* (if any) is over. The window itself lives on, so the Conveno session is not removed.
|
|
1238
|
+
*/
|
|
1209
1239
|
async function release(ctx, input) {
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
const session = await ownSession(ctx);
|
|
1214
|
-
if (!session) return;
|
|
1215
|
-
await ctx.client["session.unregister"]({ sessionId: session.id });
|
|
1216
|
-
} catch {}
|
|
1240
|
+
const id = input?.sessionID;
|
|
1241
|
+
if (typeof id !== "string" || id === "") return;
|
|
1242
|
+
await endTurnContinuation(ctx, { allowContinue: false });
|
|
1217
1243
|
}
|
|
1218
1244
|
/** `Requeue`: sending the prompt failed, so the messages go back to queued for the next turn. */
|
|
1219
1245
|
async function requeue(ctx, input) {
|
|
@@ -1236,13 +1262,9 @@ async function sessionName(ctx) {
|
|
|
1236
1262
|
return null;
|
|
1237
1263
|
}
|
|
1238
1264
|
}
|
|
1239
|
-
/**
|
|
1240
|
-
* Only the plugin delivers, on 1.x and 2.4+ alike; it adds nothing to a prompt the user types.
|
|
1241
|
-
* 2.0 to 2.3 are not supported (`opencodeDoctorNotes`), so doctor claims no waking for them.
|
|
1242
|
-
*/
|
|
1265
|
+
/** Only the plugin delivers, on 1.x and 2.x alike; it adds nothing to a prompt the user types. */
|
|
1243
1266
|
function delivery(detection) {
|
|
1244
|
-
const
|
|
1245
|
-
const supported = v !== void 0 && (!isV2OrLater(v) || atLeast(v, V2_SUPPORTED));
|
|
1267
|
+
const supported = detection.version !== void 0 && parseVersion(detection.version) !== void 0;
|
|
1246
1268
|
return {
|
|
1247
1269
|
nextTurn: false,
|
|
1248
1270
|
endOfTurn: supported,
|
|
@@ -1250,7 +1272,6 @@ function delivery(detection) {
|
|
|
1250
1272
|
};
|
|
1251
1273
|
}
|
|
1252
1274
|
const opencodeAdapter = {
|
|
1253
|
-
doctorNotes: opencodeDoctorNotes,
|
|
1254
1275
|
cli: "opencode",
|
|
1255
1276
|
displayName: "OpenCode",
|
|
1256
1277
|
deliveryTier: "inbox",
|
|
@@ -1285,8 +1306,10 @@ function isProcessAlive(pid) {
|
|
|
1285
1306
|
}
|
|
1286
1307
|
function createHookCtx() {
|
|
1287
1308
|
const launcherPaths = process.argv[1] ? [process.argv[1]] : [];
|
|
1309
|
+
const data = dataDir(process.platform, process.env, homedir());
|
|
1288
1310
|
return {
|
|
1289
|
-
dataDir:
|
|
1311
|
+
dataDir: data,
|
|
1312
|
+
...process.env.CONVENO_HOOK_LOG === "0" ? {} : { hookLog: hookLogPath(data) },
|
|
1290
1313
|
adapters: [
|
|
1291
1314
|
claudeAdapter,
|
|
1292
1315
|
codexAdapter,
|
|
@@ -1307,7 +1330,7 @@ function createHookCtx() {
|
|
|
1307
1330
|
launcherPaths
|
|
1308
1331
|
},
|
|
1309
1332
|
isAlive: isProcessAlive,
|
|
1310
|
-
hookTimeoutMs: 2e3,
|
|
1333
|
+
hookTimeoutMs: process.platform === "win32" ? 3500 : 2e3,
|
|
1311
1334
|
...process.env.CONVENO_HOOK_TIMING_LOG ? {
|
|
1312
1335
|
timingLog: process.env.CONVENO_HOOK_TIMING_LOG,
|
|
1313
1336
|
uptimeMs: () => process.uptime() * 1e3
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { i as runHookEntry } from "./hook-entry-WlJSM5aD.js";
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { E as
|
|
3
|
-
import { a as parseFlags, i as commandHelp, n as COMMANDS, r as COMMAND_NAMES, t as ALL_COMMAND_NAMES } from "./args-
|
|
4
|
-
import { t as daemonProblem } from "./daemonError-
|
|
1
|
+
import { Qt as runLaunchFile, Wt as realSpawnDeps, _n as CLI_KINDS, f as SPAWN_CLIS, m as SpawnError, n as ACP_TOOL_KINDS, p as SPAWN_TABLE, rn as spawnSession, z as dataPaths } from "./dist-DnNuDzEA.js";
|
|
2
|
+
import { A as runAccount, C as runDevices, E as runDaemon, M as runLogout, O as VERSION, i as runDoctor, j as runLogin, m as runSetup, p as runInit, t as runUninstall, w as runRelay } from "./uninstall-812XZDTG.js";
|
|
3
|
+
import { a as parseFlags, i as commandHelp, n as COMMANDS, r as COMMAND_NAMES, t as ALL_COMMAND_NAMES } from "./args-C4rVCVXx.js";
|
|
4
|
+
import { t as daemonProblem } from "./daemonError-CjxG2yUl.js";
|
|
5
5
|
import { chmod, mkdir, writeFile } from "node:fs/promises";
|
|
6
6
|
import { join, resolve } from "node:path";
|
|
7
7
|
import { a as fail, c as plural, d as warnBlock, n as cmd, r as columns, s as plainError, t as closest, u as tilde } from "./fmt-C2SsP5Y0.js";
|
|
8
|
-
import { t as runHook } from "./hook-
|
|
8
|
+
import { t as runHook } from "./hook-C60hXJdg.js";
|
|
9
9
|
import { n as connectOpts, t as adapterEnv } from "./ctx-tYftvhz_.js";
|
|
10
|
-
import { t as findSession } from "./pick-
|
|
10
|
+
import { t as findSession } from "./pick-Colav8Wm.js";
|
|
11
11
|
import { readFileSync } from "node:fs";
|
|
12
|
-
// src/version.ts
|
|
13
|
-
const VERSION = "0.2.0-rc.11";
|
|
14
12
|
// src/errorLog.ts
|
|
15
13
|
/** The message of an unexpected error, as it is. Not the softened text `plainError` gives. */
|
|
16
14
|
function rawMessage(e) {
|
|
@@ -240,6 +238,47 @@ function readTaskFile(ctx, path) {
|
|
|
240
238
|
});
|
|
241
239
|
}
|
|
242
240
|
}
|
|
241
|
+
/** Is this word the start of an allow pattern: a tool kind or `*`, then maybe `:<title glob>`? */
|
|
242
|
+
const isAllowItem = (word) => {
|
|
243
|
+
const kind = word.split(":")[0]?.trim() ?? "";
|
|
244
|
+
return kind === "*" || ACP_TOOL_KINDS.includes(kind);
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Fold every way of writing `--allow` into one `--allow=<a,b,c>`: comma separated, space separated
|
|
248
|
+
* (`--allow read search`, which is what PowerShell's shim turns `--allow read,search` into), and
|
|
249
|
+
* repeated. Words after `--allow` are taken as more patterns only while they look like one, so a
|
|
250
|
+
* CLI name or another flag ends the list. Nothing is changed when `--allow` is not used.
|
|
251
|
+
*/
|
|
252
|
+
function normalizeAllowArgs(argv) {
|
|
253
|
+
const rest = [];
|
|
254
|
+
const allow = [];
|
|
255
|
+
let used = false;
|
|
256
|
+
for (let i = 0; i < argv.length; i++) {
|
|
257
|
+
const a = argv[i];
|
|
258
|
+
if (a === "--") {
|
|
259
|
+
rest.push(...argv.slice(i));
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
if (a.startsWith("--allow=")) {
|
|
263
|
+
used = true;
|
|
264
|
+
allow.push(a.slice(8));
|
|
265
|
+
} else if (a === "--allow") {
|
|
266
|
+
used = true;
|
|
267
|
+
const value = argv[i + 1];
|
|
268
|
+
if (value === void 0) {
|
|
269
|
+
rest.push(a);
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
allow.push(value);
|
|
273
|
+
i++;
|
|
274
|
+
while (i + 1 < argv.length && isAllowItem(argv[i + 1]) && !argv[i + 1]?.startsWith("-")) {
|
|
275
|
+
allow.push(argv[i + 1]);
|
|
276
|
+
i++;
|
|
277
|
+
}
|
|
278
|
+
} else rest.push(a);
|
|
279
|
+
}
|
|
280
|
+
return used ? [...rest, `--allow=${allow.join(",")}`] : argv;
|
|
281
|
+
}
|
|
243
282
|
/**
|
|
244
283
|
* `conveno spawn <cli> ...`: start a worker session of any CLI with a first task, and print the
|
|
245
284
|
* name it registers under.
|
|
@@ -248,7 +287,7 @@ async function runSpawn(ctx, argv) {
|
|
|
248
287
|
const t = ctx.theme;
|
|
249
288
|
const spec = COMMANDS.find((c) => c.name === "spawn");
|
|
250
289
|
if (!spec) return 2;
|
|
251
|
-
const parsed = parseFlags(ctx, spec, argv);
|
|
290
|
+
const parsed = parseFlags(ctx, spec, normalizeAllowArgs(argv));
|
|
252
291
|
if (typeof parsed === "number") return parsed;
|
|
253
292
|
const help = `Run ${cmd(t, "conveno spawn --help")} to see the options.`;
|
|
254
293
|
const [cli, ...extra] = parsed.positionals;
|
|
@@ -431,7 +470,7 @@ function renderSessions(ctx, sessions) {
|
|
|
431
470
|
const tags = [...s.isOrchestrator ? [t.paint("entry", "lead")] : [], ...s.spawned || s.spawnedBy ? [q("spawned")] : []];
|
|
432
471
|
return [
|
|
433
472
|
`${st.glyph} ${t.bold(s.name)}${tags.length > 0 ? ` ${tags.join(" ")}` : ""}`,
|
|
434
|
-
toolName(s.cli),
|
|
473
|
+
s.variant === "app" ? "Antigravity app" : toolName(s.cli),
|
|
435
474
|
st.word,
|
|
436
475
|
...waiting ? [s.unreadCount ? String(s.unreadCount) : q("none")] : [],
|
|
437
476
|
...doing ? [s.statusText ?? ""] : []
|
|
@@ -572,11 +611,11 @@ async function dispatch(name, rest, ctx) {
|
|
|
572
611
|
case "rename": return runRename(ctx, rest);
|
|
573
612
|
case "lead": return runLead(ctx, rest);
|
|
574
613
|
case "spawn": return runSpawn(ctx, rest);
|
|
575
|
-
case "acp-host": return (await import("./acp-
|
|
576
|
-
case "stop": return (await import("./acp-
|
|
614
|
+
case "acp-host": return (await import("./acp-Bs6XS61j.js")).runAcpHostCmd(ctx, rest);
|
|
615
|
+
case "stop": return (await import("./acp-Bs6XS61j.js")).runStop(ctx, rest);
|
|
577
616
|
case "spawn-run": return runSpawnRun(ctx, rest);
|
|
578
|
-
case "agy-relay": return (await import("./agy-relay-
|
|
579
|
-
case "watch": return (await import("./watch-
|
|
617
|
+
case "agy-relay": return (await import("./agy-relay-BJLRYbFp.js")).runAgyRelay(ctx, rest);
|
|
618
|
+
case "watch": return (await import("./watch-DXbOOc20.js")).runWatch(ctx, rest);
|
|
580
619
|
case "devices": return runDevices(ctx, rest);
|
|
581
620
|
case "relay": return runRelay(ctx, rest);
|
|
582
621
|
case "doctor": return runDoctor(ctx, rest);
|
|
@@ -615,7 +654,7 @@ function opensApp(env, tty = {
|
|
|
615
654
|
async function main(argv, ctx) {
|
|
616
655
|
const [command, ...rest] = argv;
|
|
617
656
|
if (command === void 0 && opensApp(ctx.env)) try {
|
|
618
|
-
return await (await import("./run-
|
|
657
|
+
return await (await import("./run-BuDbmxx_.js")).runTui(ctx);
|
|
619
658
|
} catch (e) {
|
|
620
659
|
ctx.err(`The app could not start (${rawMessage(e)}). Showing the help instead.\n`);
|
|
621
660
|
ctx.out(helpText(ctx));
|