@conveno/cli 0.2.0-rc.6 → 0.2.0-rc.7

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.
@@ -0,0 +1,547 @@
1
+ import { readFile, readdir } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { I as dropFromList, L as editJson, Pt as sameJson, V as existedBefore, Z as isObject, et as loadJson, it as ownSession, j as dataDir, ot as parseCliVersion, ut as pendingHookContext, z as endTurnContinuation } from "./dist-D2hMvcZu.js";
4
+ // ../adapters/antigravity/dist/index.js
5
+ const SERVER_NAME = "conveno";
6
+ /** The name of our entry in hooks.json. Antigravity keys hooks by an arbitrary name. */
7
+ const HOOK_NAME = "conveno";
8
+ /**
9
+ * SessionStart fires when a conversation starts; PreInvocation before every model call; Stop when
10
+ * the agent loop is about to stop, where a waiting message continues it.
11
+ */
12
+ const HOOK_EVENTS = [
13
+ "SessionStart",
14
+ "PreInvocation",
15
+ "Stop"
16
+ ];
17
+ /**
18
+ * Conveno's Antigravity plugin, `~/.gemini/config/plugins/conveno/`. A plugin in that folder is
19
+ * found and enabled without `agy plugin install`, and its `rules/*.md` files load like global rules
20
+ * (agy 1.5.21 built-in skill `migrate-agent-settings`, "Step 3: Write the plugin": `plugin.json`
21
+ * plus `rules/<name>.md` starting with `trigger: always_on`). Ours holds one rule: the one that
22
+ * tells the agent to start the relay.
23
+ */
24
+ const PLUGIN_NAME = "conveno";
25
+ /** The plugin's own version. Antigravity's marketplace lists no plugin without one. */
26
+ const PLUGIN_VERSION = "1.0.0";
27
+ /** 0.2.0-rc.6 and the sidecar build used this id; only uninstall and clean-up still name it. */
28
+ const SIDECAR_ID = "conveno";
29
+ /**
30
+ * The hidden command that wakes an idle conversation (packages/cli/src/agy-relay.ts). The agent
31
+ * starts it as a background `run_command`, so it inherits what Antigravity gives the agent's own
32
+ * shell: `ANTIGRAVITY_CONVERSATION_ID` and `ANTIGRAVITY_AGENTAPI_EXE` (agy.strings: "The calling
33
+ * conversation's own ID is in `ANTIGRAVITY_CONVERSATION_ID`"), plus the language server's address
34
+ * and CSRF token that `agentapi send-message` needs.
35
+ */
36
+ const RELAY_SUBCOMMAND = "agy-relay";
37
+ /** The permission rule that lets the agent call our tools without asking. */
38
+ const PERMISSION_RULE = `mcp(${SERVER_NAME}/*)`;
39
+ const EMPTY = {
40
+ stdout: "",
41
+ exitCode: 0
42
+ };
43
+ /** Everything Antigravity CLI keeps for the user lives under `~/.gemini`. */
44
+ function paths(env) {
45
+ const root = join(env.home, ".gemini");
46
+ const plugin = join(root, "config", "plugins", PLUGIN_NAME);
47
+ return {
48
+ plugin: join(plugin, "plugin.json"),
49
+ rules: join(plugin, "rules", "conveno.md"),
50
+ sidecar: join(plugin, "sidecars", SIDECAR_ID, "sidecar.json"),
51
+ legacySidecar: join(root, "config", "sidecars", SIDECAR_ID, "sidecar.json"),
52
+ config: join(root, "config", "config.json"),
53
+ mcp: join(root, "config", "mcp_config.json"),
54
+ settings: join(root, "antigravity-cli", "settings.json"),
55
+ hooks: join(root, "config", "hooks.json")
56
+ };
57
+ }
58
+ /**
59
+ * Quote one word of a hook command. Antigravity's docs do not say which shell runs a hook, so the
60
+ * word is written to mean the same in bash, cmd.exe and POSIX sh: double quotes only when the word
61
+ * needs them, and on Windows forward slashes, which every Windows API Node uses accepts, so no
62
+ * backslash has to be escaped.
63
+ */
64
+ function quoteHookWord(arg, platform) {
65
+ const word = platform === "win32" ? arg.replace(/\\/g, "/") : arg;
66
+ return /^[A-Za-z0-9_@%+=:,./\\-]+$/.test(word) ? word : `"${word.replace(/(["\\$`])/g, "\\$1")}"`;
67
+ }
68
+ const commandLine = (env, words) => [...env.conveno.command, ...words].map((w) => quoteHookWord(w, env.platform)).join(" ");
69
+ const hookCommand = (env, event) => commandLine(env, [
70
+ "hook",
71
+ "antigravity",
72
+ event
73
+ ]);
74
+ /**
75
+ * The command line the agent runs to start the relay, exactly as the rule and the permission name
76
+ * it. agy runs the agent's commands on Windows in PowerShell (seen live, agy 1.5.21: a command
77
+ * starting with a quoted path failed with "Unexpected token"), so there a quoted program gets
78
+ * PowerShell's `&`, and a `conveno` shim is not used: a `.ps1` shim can be blocked by the execution
79
+ * policy. It runs as `node <bin.js>` instead.
80
+ */
81
+ const relayCommand = (env) => {
82
+ if (env.platform !== "win32") return commandLine(env, [RELAY_SUBCOMMAND]);
83
+ const { command, bin } = env.conveno;
84
+ const words = [...command.length > 1 || !bin ? command : ["node", bin], RELAY_SUBCOMMAND].map((w) => quoteHookWord(w, env.platform));
85
+ return `${words[0]?.startsWith("\"") ? "& " : ""}${words.join(" ")}`;
86
+ };
87
+ /**
88
+ * Conveno no longer writes an allow rule for the relay: the user approves its start once. A
89
+ * `command(...)` rule is not an exact match on every agy: a POSIX command line is split into
90
+ * statements and each one checked against the rules by prefix, and on Windows an exact match is
91
+ * only required since agy 1.5.8 (agy.strings changelog 1.5.8: before it, `git status '&& del
92
+ * secret.txt'` could pass a rule meant for `git status`). An install removes the rule earlier
93
+ * versions wrote.
94
+ */
95
+ /** Recognizes the relay rule earlier versions wrote, whatever the conveno path was. */
96
+ const isOurRelayRule = (r) => typeof r === "string" && r.startsWith("command(") && r.endsWith(` agy-relay)`);
97
+ const mcpArgs = (env) => [
98
+ ...env.conveno.command,
99
+ "mcp",
100
+ "--cli",
101
+ "antigravity"
102
+ ];
103
+ const desiredPlugin = {
104
+ name: PLUGIN_NAME,
105
+ version: PLUGIN_VERSION,
106
+ displayName: "Conveno",
107
+ description: "Tells the agent to start Conveno's relay, which wakes it when a message arrives."
108
+ };
109
+ /** What the agent is told, as an always-on rule. */
110
+ const relayRuleText = (env) => `---
111
+ trigger: always_on
112
+ ---
113
+
114
+ # Conveno relay
115
+
116
+ Conveno connects this conversation to the user's other AI coding sessions. Messages from them can
117
+ wake you while you are idle only while Conveno's relay runs in this conversation.
118
+
119
+ - Once per conversation, after you have replied to the user, start it: run \`${relayCommand(env)}\`
120
+ with run_command as a background command (WaitMsBeforeAsync 500). Do not wait for it, poll it or
121
+ read its output, and do not mention it to the user.
122
+ - It prints nothing while it works. If it ends, start it again only if its last line asks you to.
123
+ - Antigravity may ask the user to approve it. If the command is refused or fails, that is fine:
124
+ carry on without it and do not ask again.
125
+ - Never let it delay or block the user's task.
126
+ `;
127
+ /** The `sidecars` or `plugins` object of config.json, or an empty one. */
128
+ function sectionOf(config, key, path) {
129
+ const s = config[key];
130
+ if (s === void 0) return {};
131
+ if (!isObject(s)) throw new Error(`"${key}" in ${path} must be an object. Fix the file, then run the install again. Nothing was changed.`);
132
+ return s;
133
+ }
134
+ /** A file's text, or null when it does not exist. */
135
+ async function readText(path) {
136
+ try {
137
+ return await readFile(path, "utf8");
138
+ } catch (e) {
139
+ if (e.code === "ENOENT") return null;
140
+ throw e;
141
+ }
142
+ }
143
+ const OLD_CONVERSATION_FILE = /^[A-Za-z0-9]{1,64}\.json(?:\.\d+\.tmp)?$/;
144
+ /** Deletes the per-session files 0.2.0-rc.6 left, and their folders once empty. */
145
+ async function oldConversationFiles(env) {
146
+ const dir = join(dataDir(env.platform, env.env, env.home), "antigravity", "conversations");
147
+ let names;
148
+ try {
149
+ names = await readdir(dir);
150
+ } catch {
151
+ return [];
152
+ }
153
+ const changes = [];
154
+ for (const name of names.filter((n) => OLD_CONVERSATION_FILE.test(n)).sort()) {
155
+ const c = await deleteOwned(join(dir, name), 2, "Remove an old Conveno conversation record.");
156
+ if (c) changes.push(c);
157
+ }
158
+ return changes;
159
+ }
160
+ /** Deletes a file Conveno owns, and the folders it leaves empty up to `levels`. */
161
+ async function deleteOwned(path, levels, description) {
162
+ const raw = await readText(path);
163
+ if (raw === null) return void 0;
164
+ return {
165
+ component: "hooks",
166
+ kind: "remove",
167
+ path,
168
+ before: raw,
169
+ after: "",
170
+ deleteFile: true,
171
+ pruneEmptyDir: levels,
172
+ description
173
+ };
174
+ }
175
+ /**
176
+ * Takes Conveno's entry out of a section of config.json: rc.6's `sidecars.conveno`, or the
177
+ * `plugins.conveno` that `agy plugin enable/disable` writes. The section goes with it when ours
178
+ * was its only entry and it was not there before Conveno.
179
+ */
180
+ async function dropConfigEntry(p, baseline) {
181
+ const cfgFile = await loadJson(p.config);
182
+ const edits = [];
183
+ for (const key of ["sidecars", "plugins"]) {
184
+ const section = sectionOf(cfgFile.value, key, p.config);
185
+ if (!(SIDECAR_ID in section)) continue;
186
+ const onlyOurs = Object.keys(section).length === 1 && !existedBefore(baseline?.get(p.config), [key]);
187
+ edits.push({
188
+ path: onlyOurs ? [key] : [key, SIDECAR_ID],
189
+ value: void 0
190
+ });
191
+ }
192
+ if (edits.length === 0) return void 0;
193
+ return {
194
+ component: "hooks",
195
+ kind: "remove",
196
+ path: p.config,
197
+ before: cfgFile.raw,
198
+ after: editJson(cfgFile, edits),
199
+ description: "Remove Conveno's entries from Antigravity's config.json."
200
+ };
201
+ }
202
+ const desiredServer = (env) => {
203
+ const [command = "conveno", ...args] = mcpArgs(env);
204
+ return {
205
+ command,
206
+ args
207
+ };
208
+ };
209
+ const desiredHandlers = (env, event) => [{
210
+ type: "command",
211
+ command: hookCommand(env, event),
212
+ timeout: 5
213
+ }];
214
+ /** Recognizes our hook command even if the conveno path changed since install. */
215
+ const isOurHookCommand = (cmd) => typeof cmd === "string" && /(^|\s)hook antigravity (SessionStart|PreInvocation|Stop)$/.test(cmd.trim());
216
+ const listOf = (names) => `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`;
217
+ const handlersOf = (entry, event) => {
218
+ const h = entry[event];
219
+ return Array.isArray(h) ? h : [];
220
+ };
221
+ const hasOurHandler = (entry) => HOOK_EVENTS.some((e) => handlersOf(entry, e).some((h) => isObject(h) && isOurHookCommand(h.command)));
222
+ function mcpServers(config, path) {
223
+ const s = config.mcpServers;
224
+ if (s === void 0) return {};
225
+ if (!isObject(s)) throw new Error(`"mcpServers" in ${path} must be an object. Fix the file, then run the install again. Nothing was changed.`);
226
+ return s;
227
+ }
228
+ /** The `permissions.allow` list, or undefined when there is none. */
229
+ function allowList(settings, path) {
230
+ const p = settings.permissions;
231
+ if (p === void 0) return void 0;
232
+ if (!isObject(p)) throw new Error(`"permissions" in ${path} must be an object. Fix the file, then run the install again. Nothing was changed.`);
233
+ const a = p.allow;
234
+ if (a === void 0) return void 0;
235
+ if (!Array.isArray(a)) throw new Error(`"permissions.allow" in ${path} must be a list. Fix the file, then run the install again. Nothing was changed.`);
236
+ return a;
237
+ }
238
+ /** Our entry in hooks.json, or undefined. A hook of that name that is not ours is the user's: refuse. */
239
+ function ourHookEntry(hooksFile, path) {
240
+ const e = hooksFile[HOOK_NAME];
241
+ if (e === void 0) return void 0;
242
+ if (!isObject(e) || !hasOurHandler(e)) throw new Error(`${path} already has a hook named "${HOOK_NAME}" that is not Conveno's. Rename it, then run the install again. Nothing was changed.`);
243
+ return e;
244
+ }
245
+ async function detect(env) {
246
+ const p = paths(env);
247
+ const configPaths = [
248
+ p.mcp,
249
+ p.settings,
250
+ p.hooks
251
+ ];
252
+ try {
253
+ const r = await env.exec("agy", ["--version"]);
254
+ if (r.code !== 0) return {
255
+ installed: false,
256
+ configPaths
257
+ };
258
+ const version = parseCliVersion(r.stdout);
259
+ return {
260
+ installed: true,
261
+ binary: "agy",
262
+ ...version ? { version } : {},
263
+ configPaths
264
+ };
265
+ } catch {
266
+ return {
267
+ installed: false,
268
+ configPaths
269
+ };
270
+ }
271
+ }
272
+ async function plan(env) {
273
+ const p = paths(env);
274
+ const changes = [];
275
+ const mcpFile = await loadJson(p.mcp);
276
+ const servers = mcpServers(mcpFile.value, p.mcp);
277
+ const wantServer = desiredServer(env);
278
+ if (!sameJson(servers["conveno"], wantServer)) changes.push({
279
+ component: "mcp",
280
+ kind: servers["conveno"] === void 0 ? "add" : "update",
281
+ parts: [{
282
+ name: "MCP server",
283
+ kind: servers["conveno"] === void 0 ? "add" : "update"
284
+ }],
285
+ path: p.mcp,
286
+ before: mcpFile.raw,
287
+ after: editJson(mcpFile, [{
288
+ path: ["mcpServers", SERVER_NAME],
289
+ value: wantServer
290
+ }]),
291
+ description: `Register the "${SERVER_NAME}" MCP server (conveno mcp --cli antigravity).`
292
+ });
293
+ const setFile = await loadJson(p.settings);
294
+ const allow = allowList(setFile.value, p.settings);
295
+ const hasRule = allow?.includes("mcp(conveno/*)") ?? false;
296
+ const stale = dropFromList(allow, ["permissions", "allow"], isOurRelayRule, { keepEmpty: true });
297
+ if (!hasRule || stale.length > 0) {
298
+ const ruleEdits = [];
299
+ if (setFile.value.permissions === void 0) ruleEdits.push({
300
+ path: ["permissions"],
301
+ value: { allow: [PERMISSION_RULE] }
302
+ });
303
+ else if (allow === void 0) ruleEdits.push({
304
+ path: ["permissions", "allow"],
305
+ value: [PERMISSION_RULE]
306
+ });
307
+ else {
308
+ const first = stale[0];
309
+ if (!hasRule && first) ruleEdits.push({
310
+ path: first.path,
311
+ value: PERMISSION_RULE
312
+ }, ...stale.slice(1));
313
+ else {
314
+ ruleEdits.push(...stale);
315
+ if (!hasRule) ruleEdits.push({
316
+ path: [
317
+ "permissions",
318
+ "allow",
319
+ allow.length
320
+ ],
321
+ value: PERMISSION_RULE,
322
+ insert: true
323
+ });
324
+ }
325
+ }
326
+ const added = allow === void 0 || !hasRule && stale.length === 0;
327
+ changes.push({
328
+ component: "mcp",
329
+ kind: added ? "add" : "update",
330
+ parts: [{
331
+ name: "permissions",
332
+ kind: added ? "add" : "update"
333
+ }],
334
+ path: p.settings,
335
+ before: setFile.raw,
336
+ after: editJson(setFile, ruleEdits),
337
+ description: stale.length > 0 ? `Allow the agent to call Conveno's tools (${PERMISSION_RULE}) without asking, and remove the old rule that started Conveno's relay without asking: Antigravity now asks you once.` : `Allow the agent to call Conveno's tools (${PERMISSION_RULE}) without asking. They only exchange messages between your own sessions.`
338
+ });
339
+ }
340
+ const hooksFile = await loadJson(p.hooks);
341
+ const entry = ourHookEntry(hooksFile.value, p.hooks);
342
+ const edits = [];
343
+ const parts = [];
344
+ for (const e of HOOK_EVENTS) {
345
+ const want = desiredHandlers(env, e);
346
+ const have = entry ? handlersOf(entry, e) : void 0;
347
+ if (!sameJson(have, want)) {
348
+ edits.push({
349
+ path: [HOOK_NAME, e],
350
+ value: want
351
+ });
352
+ parts.push({
353
+ name: `${e} hook`,
354
+ kind: have === void 0 ? "add" : "update"
355
+ });
356
+ }
357
+ }
358
+ if (edits.length > 0) changes.push({
359
+ component: "hooks",
360
+ kind: entry ? "update" : "add",
361
+ parts,
362
+ path: p.hooks,
363
+ before: hooksFile.raw,
364
+ after: editJson(hooksFile, edits),
365
+ description: `Add ${listOf(HOOK_EVENTS)} hooks that deliver Conveno messages to Antigravity on the next prompt and at the end of a turn.`
366
+ });
367
+ const pluginFile = await loadJson(p.plugin);
368
+ if (!sameJson(pluginFile.value, desiredPlugin)) {
369
+ const had = pluginFile.raw !== null;
370
+ changes.push({
371
+ component: "hooks",
372
+ kind: had ? "update" : "add",
373
+ parts: [{
374
+ name: "Antigravity plugin",
375
+ kind: had ? "update" : "add"
376
+ }],
377
+ path: p.plugin,
378
+ before: pluginFile.raw,
379
+ after: `${JSON.stringify(desiredPlugin, null, 2)}\n`,
380
+ description: "Add the Conveno plugin to Antigravity, which holds the relay rule."
381
+ });
382
+ }
383
+ const rulesRaw = await readText(p.rules);
384
+ const wantRulesText = relayRuleText(env);
385
+ if (rulesRaw !== wantRulesText) {
386
+ const had = rulesRaw !== null;
387
+ changes.push({
388
+ component: "hooks",
389
+ kind: had ? "update" : "add",
390
+ parts: [{
391
+ name: "relay rule",
392
+ kind: had ? "update" : "add"
393
+ }],
394
+ path: p.rules,
395
+ before: rulesRaw,
396
+ after: wantRulesText,
397
+ description: `Add a rule that tells the agent to start Conveno's relay (${relayCommand(env)}) in the background, so a message can wake an idle conversation.`
398
+ });
399
+ }
400
+ const sidecar = await deleteOwned(p.sidecar, 2, "Remove the old Conveno wake sidecar.");
401
+ if (sidecar) changes.push(sidecar);
402
+ const legacy = await deleteOwned(p.legacySidecar, 2, "Remove the old Conveno sidecar location.");
403
+ if (legacy) changes.push(legacy);
404
+ const cfgFile = await loadJson(p.config);
405
+ const sidecars = sectionOf(cfgFile.value, "sidecars", p.config);
406
+ if (SIDECAR_ID in sidecars) changes.push({
407
+ component: "hooks",
408
+ kind: "remove",
409
+ path: p.config,
410
+ before: cfgFile.raw,
411
+ after: editJson(cfgFile, [{
412
+ path: Object.keys(sidecars).length === 1 ? ["sidecars"] : ["sidecars", SIDECAR_ID],
413
+ value: void 0
414
+ }]),
415
+ description: "Remove the old Conveno sidecar entry from Antigravity's config.json."
416
+ });
417
+ changes.push(...await oldConversationFiles(env));
418
+ return changes;
419
+ }
420
+ async function uninstallPlan(env, baseline) {
421
+ const p = paths(env);
422
+ const changes = [];
423
+ const mcpFile = await loadJson(p.mcp);
424
+ if ("conveno" in mcpServers(mcpFile.value, p.mcp)) changes.push({
425
+ component: "mcp",
426
+ kind: "remove",
427
+ path: p.mcp,
428
+ before: mcpFile.raw,
429
+ after: editJson(mcpFile, [{
430
+ path: ["mcpServers", SERVER_NAME],
431
+ value: void 0
432
+ }]),
433
+ description: `Remove the "${SERVER_NAME}" MCP server.`
434
+ });
435
+ const setFile = await loadJson(p.settings);
436
+ const drops = dropFromList(allowList(setFile.value, p.settings), ["permissions", "allow"], (r) => r === "mcp(conveno/*)" || isOurRelayRule(r), { keepEmpty: existedBefore(baseline?.get(p.settings), ["permissions", "allow"]) });
437
+ if (drops.length > 0) {
438
+ const alone = drops.length === 1 && drops[0]?.path.length === 2;
439
+ const only = Object.keys(setFile.value.permissions).length === 1 && !existedBefore(baseline?.get(p.settings), ["permissions"]);
440
+ changes.push({
441
+ component: "mcp",
442
+ kind: "remove",
443
+ path: p.settings,
444
+ before: setFile.raw,
445
+ after: editJson(setFile, alone && only ? [{
446
+ path: ["permissions"],
447
+ value: void 0
448
+ }] : drops),
449
+ description: `Remove the ${PERMISSION_RULE} and relay permissions.`
450
+ });
451
+ }
452
+ const hooksFile = await loadJson(p.hooks);
453
+ if (ourHookEntry(hooksFile.value, p.hooks)) changes.push({
454
+ component: "hooks",
455
+ kind: "remove",
456
+ path: p.hooks,
457
+ before: hooksFile.raw,
458
+ after: editJson(hooksFile, [{
459
+ path: [HOOK_NAME],
460
+ value: void 0
461
+ }]),
462
+ description: `Remove the Conveno ${listOf(HOOK_EVENTS)} hooks.`
463
+ });
464
+ for (const c of [
465
+ await deleteOwned(p.rules, 1, "Remove the Conveno relay rule."),
466
+ await deleteOwned(p.sidecar, 2, "Remove the old Conveno wake sidecar."),
467
+ await deleteOwned(p.plugin, 1, "Remove the Conveno plugin from Antigravity."),
468
+ await deleteOwned(p.legacySidecar, 2, "Remove the old Conveno sidecar location."),
469
+ await dropConfigEntry(p, baseline)
470
+ ]) if (c) changes.push(c);
471
+ changes.push(...await oldConversationFiles(env));
472
+ return changes;
473
+ }
474
+ const UUID = /^[0-9a-fA-F-]{8,64}$/;
475
+ /**
476
+ * The session that owns this hook, after recording its conversation id as the session's native id
477
+ * (`session.setNative`), which is how `conveno agy-relay` finds its session. Null when no session
478
+ * owns the hook or on any failure. Never throws.
479
+ */
480
+ async function sessionOf(input, ctx) {
481
+ try {
482
+ const session = await ownSession(ctx);
483
+ const id = isObject(input) ? input.conversationId : void 0;
484
+ if (!session || typeof id !== "string" || !UUID.test(id) || session.nativeId === id) return session;
485
+ return (await ctx.client["session.setNative"]({
486
+ sessionId: session.id,
487
+ nativeId: id
488
+ })).session;
489
+ } catch {
490
+ return null;
491
+ }
492
+ }
493
+ /** What the Stop hook asks once per turn while no relay is connected. */
494
+ const START_RELAY_TEXT = `[conveno] Conveno's relay is not running in this conversation, so messages from the user's other sessions cannot wake it while it is idle. Start it now: run the exact command the Conveno relay rule names (it ends in \`${RELAY_SUBCOMMAND}\`) with run_command as a background command (WaitMsBeforeAsync 500), do not wait for it, and end your turn without mentioning it. If it is refused, skip it.`;
495
+ const isHookEvent = (e) => HOOK_EVENTS.includes(e);
496
+ /**
497
+ * - SessionStart, PreInvocation: both accept `injectSteps`. An injected system message stays in the
498
+ * conversation, so a step is added only when a message is waiting.
499
+ * - Stop: records the turn end. After a turn that ended on its own (`terminationReason`
500
+ * `NO_TOOL_CALL`, "Normal turn completion" in agy 1.5.21's built-in hooks guide, and no `error`),
501
+ * `{"decision":"continue","reason":"<text>"}` re-enters the loop and `reason` becomes a system
502
+ * message: the waiting messages, or, when none wait and no relay is connected (the session's
503
+ * tier is not `live`), the request to start the relay. `continuationActive` (true while the agent
504
+ * does work a Stop hook asked for) limits that request to once per turn; Conveno's auto-mode limit
505
+ * bounds a chain of messages. `fullyIdle` is not checked: the relay is a background task that
506
+ * never ends, so with it running `fullyIdle` stays false.
507
+ * Never throws and never writes to stderr: any failure means "deliver nothing this time".
508
+ */
509
+ async function hook(event, input, ctx) {
510
+ if (!isHookEvent(event)) return EMPTY;
511
+ const session = await sessionOf(input, ctx);
512
+ if (event === "Stop") {
513
+ const stop = isObject(input) ? input : {};
514
+ const completed = (stop.terminationReason === void 0 || stop.terminationReason === "NO_TOOL_CALL") && (stop.error === void 0 || stop.error === "");
515
+ let reason = await endTurnContinuation(ctx, { allowContinue: completed });
516
+ if (reason === null && completed && stop.continuationActive !== true && session !== null && session.deliveryTier === "next_turn") reason = START_RELAY_TEXT;
517
+ if (reason === null) return EMPTY;
518
+ return {
519
+ stdout: JSON.stringify({
520
+ decision: "continue",
521
+ reason
522
+ }),
523
+ exitCode: 0
524
+ };
525
+ }
526
+ const text = await pendingHookContext(ctx);
527
+ if (text === null) return EMPTY;
528
+ return {
529
+ stdout: JSON.stringify({ injectSteps: [{ systemMessage: { systemMessage: text } }] }),
530
+ exitCode: 0
531
+ };
532
+ }
533
+ const antigravityAdapter = {
534
+ cli: "antigravity",
535
+ displayName: "Antigravity CLI",
536
+ deliveryTier: "next_turn",
537
+ delivery: () => ({
538
+ nextTurn: true,
539
+ endOfTurn: true,
540
+ idleWake: true
541
+ }),
542
+ detect,
543
+ plan,
544
+ uninstallPlan,
545
+ hook
546
+ };
547
+ export { antigravityAdapter as n, RELAY_SUBCOMMAND as t };