@conveno/cli 0.2.0-rc.10 → 0.2.0-rc.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -4
- package/dist/{acp-TSjX4JP9.js → acp-CIzgcCp9.js} +3 -3
- package/dist/{agy-relay-D-OWo85B.js → agy-relay-Y9o-Pw9U.js} +3 -2
- package/dist/{args-B3Cj2Ie4.js → args-C1eX8Ixk.js} +3 -3
- package/dist/bin.js +2 -2
- package/dist/daemon.js +213 -18
- package/dist/{daemonError-C05GqdhQ.js → daemonError-0KnkgIRo.js} +1 -1
- package/dist/{dist-BLfduOoT.js → dist-4iJnF07i.js} +5 -5
- package/dist/{dist-D_O_JLLq.js → dist-B3YYLzKS.js} +2 -1
- package/dist/{dist-MK-cK1JY.js → dist-BjATai4T.js} +15 -16
- package/dist/{dist-STNJjbNH.js → dist-CRj_cuHc.js} +188 -95
- package/dist/{dist-DaIpdMke.js → dist-DF0nL8wE.js} +48 -7
- package/dist/{dist-CVdpCNJo.js → dist-DeN0jR3I.js} +1 -1
- package/dist/{dist-VOS92iqO.js → dist-Du1hwaux.js} +20 -13
- package/dist/{hook-CDF1A8AY.js → hook-ByduyOom.js} +62 -2
- package/dist/hook-entry-DWa1oppt.js +1343 -0
- package/dist/hook-entry-ajdMBSpY.js +1 -0
- package/dist/{main-BhKTG0AI.js → main-WIfawg60.js} +12 -12
- package/dist/{pick-DLp6w_-z.js → pick-BmZuv9yQ.js} +1 -1
- package/dist/{run-eCXO1SyO.js → run-Df6vFm9n.js} +76 -104
- package/dist/{runtime-BGPlr8CI.js → runtime-BKPod_ZQ.js} +93 -90
- package/dist/{uninstall-DQlzpv5R.js → uninstall-MaS5t1CK.js} +132 -42
- package/dist/{watch-D0KIPowJ.js → watch-CPkilo9L.js} +29 -7
- package/package.json +13 -15
- package/dist/hook-entry-C0bPssOy.js +0 -1
- package/dist/hook-entry-CQQU-e_t.js +0 -2500
|
@@ -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 pendingHookContext, Et as planLauncher, G as endTurnContinuation, H as dropFromList, Jt as sameJson, L as dataDir, U as editJson, _t as ownSession, an as uninstallLauncher, at as isObject, ct as late, dt as loadJson, j as compareVersions, mt as needsQuoting, q as existedBefore, v as agentCommand, x as askedMarker, yt as parseCliVersion } from "./dist-CRj_cuHc.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,19 +554,25 @@ 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
|
}
|
|
@@ -592,7 +598,8 @@ const isHookEvent = (e) => HOOK_EVENTS.includes(e);
|
|
|
592
598
|
*/
|
|
593
599
|
async function hook(event, input, ctx) {
|
|
594
600
|
if (!isHookEvent(event)) return EMPTY;
|
|
595
|
-
|
|
601
|
+
ctx = withConversation(input, ctx, event !== "Stop");
|
|
602
|
+
const session = await sessionOf(ctx);
|
|
596
603
|
if (event === "Stop") {
|
|
597
604
|
const stop = isObject(input) ? input : {};
|
|
598
605
|
const completed = (stop.terminationReason === void 0 || stop.terminationReason === "NO_TOOL_CALL") && (stop.error === void 0 || stop.error === "");
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { appendFileSync } from "node:fs";
|
|
2
|
+
import { tt as hookLogLine, y as appendHookLog } from "./dist-CRj_cuHc.js";
|
|
2
3
|
import { n as connectOpts } from "./ctx-tYftvhz_.js";
|
|
3
4
|
// src/hook.ts
|
|
4
5
|
/**
|
|
@@ -39,6 +40,49 @@ 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;
|
|
44
88
|
/** How long before the hook's timeout its messages count as too late to print. */
|
|
@@ -60,6 +104,8 @@ async function runHook(ctx, argv) {
|
|
|
60
104
|
const listener = adapter.listenEvents?.includes(event) === true;
|
|
61
105
|
const deadline = listener ? void 0 : Date.now() + ctx.hookTimeoutMs - DEADLINE_MARGIN_MS;
|
|
62
106
|
const t0 = ctx.timingLog && !listener ? Date.now() : void 0;
|
|
107
|
+
const trace = { delivered: 0 };
|
|
108
|
+
let conversation;
|
|
63
109
|
let timedOut = false;
|
|
64
110
|
let client;
|
|
65
111
|
let timer;
|
|
@@ -74,9 +120,13 @@ async function runHook(ctx, argv) {
|
|
|
74
120
|
}
|
|
75
121
|
};
|
|
76
122
|
const [input, connected] = await Promise.all([readInput(), ctx.connect(connectOpts(ctx, false))]);
|
|
77
|
-
client = connected;
|
|
123
|
+
client = ctx.hookLog ? traced(connected, trace) : connected;
|
|
124
|
+
if (ctx.hookLog) conversation = conversationIn(input);
|
|
78
125
|
const hostPid = await findHostPid(ctx, connected, adapter.cli, () => early ?? ctx.ancestry(1200));
|
|
79
|
-
if (hostPid === void 0)
|
|
126
|
+
if (hostPid === void 0) {
|
|
127
|
+
await adapter.hookWithoutSession?.(event, input).catch(() => {});
|
|
128
|
+
return NOTHING;
|
|
129
|
+
}
|
|
80
130
|
return adapter.hook(event, input, {
|
|
81
131
|
client,
|
|
82
132
|
hostPid,
|
|
@@ -99,6 +149,16 @@ async function runHook(ctx, argv) {
|
|
|
99
149
|
if (listener && out.stderr) ctx.err(out.stderr.endsWith("\n") ? out.stderr : `${out.stderr}\n`);
|
|
100
150
|
if (listener) code = out.exitCode;
|
|
101
151
|
} catch {} finally {
|
|
152
|
+
if (ctx.hookLog) {
|
|
153
|
+
const result = timedOut ? "timeout" : trace.error ?? (trace.delivered > 0 ? `delivered ${trace.delivered}` : trace.turn ?? "nothing");
|
|
154
|
+
appendHookLog(ctx.hookLog, hookLogLine({
|
|
155
|
+
cli: adapter.cli,
|
|
156
|
+
event,
|
|
157
|
+
conversationId: conversation,
|
|
158
|
+
session: trace.session,
|
|
159
|
+
result
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
102
162
|
if (t0 !== void 0 && ctx.timingLog) {
|
|
103
163
|
const up = ctx.uptimeMs?.();
|
|
104
164
|
try {
|