@conveno/cli 0.2.0-rc.1 → 0.2.0-rc.10
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 +28 -29
- package/dist/acp-TSjX4JP9.js +82 -0
- package/dist/agy-relay-D-OWo85B.js +137 -0
- package/dist/args-B3Cj2Ie4.js +361 -0
- package/dist/bin.js +4 -4
- package/dist/ctx-tYftvhz_.js +17 -0
- package/dist/daemon.js +490 -1151
- package/dist/daemonError-C05GqdhQ.js +66 -0
- package/dist/{acp-BlKK0v-B.js → dist-BLfduOoT.js} +39 -286
- package/dist/dist-BRjg9CLd.js +731 -0
- package/dist/{dist-CWvQqhPj.js → dist-CVdpCNJo.js} +1 -1
- package/dist/{dist-DsRTUePN.js → dist-D_O_JLLq.js} +6 -14
- package/dist/dist-DaIpdMke.js +667 -0
- package/dist/dist-MK-cK1JY.js +969 -0
- package/dist/{dist-_qrCNXUP.js → dist-STNJjbNH.js} +840 -1253
- package/dist/dist-VOS92iqO.js +645 -0
- package/dist/fmt-C2SsP5Y0.js +96 -0
- package/dist/{hook-bfp9_AVT.js → hook-CDF1A8AY.js} +31 -22
- package/dist/hook-entry-C0bPssOy.js +1 -0
- package/dist/hook-entry-CQQU-e_t.js +2500 -0
- package/dist/main-BhKTG0AI.js +650 -0
- package/dist/pick-DLp6w_-z.js +9 -0
- package/dist/run-eCXO1SyO.js +5609 -0
- package/dist/runtime-BGPlr8CI.js +772 -0
- package/dist/{dist-D8gPpZKN.js → toml-patch-DGzVRdd1.js} +20 -1889
- package/dist/{main-sIWDc4jt.js → uninstall-DQlzpv5R.js} +629 -1494
- package/dist/watch-D0KIPowJ.js +185 -0
- package/package.json +23 -16
- package/dist/args-DHkLY6_f.js +0 -513
- package/dist/dist-DcmKjrmu.js +0 -271
- package/dist/hook-entry-Daxws9EC.js +0 -1
- package/dist/hook-entry-RlH2cG3S.js +0 -1289
- package/dist/runtime-5nEur1P5.js +0 -1505
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @conveno/cli
|
|
2
2
|
|
|
3
|
-
Conveno connects
|
|
3
|
+
Conveno connects your AI coding CLI sessions. Open your CLIs, make one the lead, and it hands out work. The other sessions wake up and start working. With Pro it works across your computers and servers. You keep using each CLI the way you do today. This package is the `conveno` command and everything it needs, including the local daemon.
|
|
4
4
|
|
|
5
5
|
- Website: https://conveno.dev
|
|
6
6
|
- Source and issues: https://github.com/0xPixelNinja/conveno
|
|
7
|
-
- Status: pre-alpha. The local mesh works, with spawn
|
|
7
|
+
- Status: pre-alpha. The local mesh works, with spawn and handoff. Pro, the end-to-end encrypted relay between your machines, is in preview.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -23,7 +23,9 @@ conveno init
|
|
|
23
23
|
|
|
24
24
|
`conveno init` finds the supported CLIs on your machine and shows a diff of every config file it would change. It asks before it writes, and it backs each file up first. Add `--dry-run` to print the plan and write nothing.
|
|
25
25
|
|
|
26
|
-
Then open two CLI sessions, for example Claude Code and Codex.
|
|
26
|
+
Then open two CLI sessions, for example Claude Code and Codex. Make one the lead (in the app, with `conveno lead <session>`, or by asking it to coordinate) and ask it to hand out work. The other session wakes up and starts. `conveno status` lists the sessions.
|
|
27
|
+
|
|
28
|
+
Or run `conveno` with no arguments. It opens a full-screen app (Sessions, New, Devices, Setup) for the keyboard and mouse: `/` searches, `?` shows the keys. Turn the mouse off in Setup or with `CONVENO_MOUSE=0`.
|
|
27
29
|
|
|
28
30
|
`conveno uninstall` reverts what `init` did. A file that has not changed since `init` is restored byte for byte. If a CLI has rewritten it since, only Conveno's entries are removed.
|
|
29
31
|
|
|
@@ -31,39 +33,36 @@ Then open two CLI sessions, for example Claude Code and Codex. In one, ask it to
|
|
|
31
33
|
|
|
32
34
|
| Command | What it does |
|
|
33
35
|
|---|---|
|
|
34
|
-
| `conveno init
|
|
36
|
+
| `conveno init` | Add the Conveno MCP server and hooks to each detected CLI. |
|
|
35
37
|
| `conveno uninstall` | Undo every install that has not been undone. |
|
|
36
|
-
| `conveno status` | Online sessions grouped by repo, with the
|
|
37
|
-
| `conveno
|
|
38
|
-
| `conveno
|
|
39
|
-
| `conveno
|
|
40
|
-
| `conveno
|
|
41
|
-
| `conveno
|
|
42
|
-
| `conveno
|
|
43
|
-
| `conveno
|
|
44
|
-
| `conveno
|
|
45
|
-
| `conveno auto [on\|off\|resume] [<session>]`, `conveno auto limit <n\|default> [<session>]` | Auto mode for a session: waiting messages become its next prompt when its turn ends, and an idle Claude Code or OpenCode session is woken. Without a name it changes the session it is typed in; without arguments it lists the sessions. `resume` lifts a pause by the limit: 20 automatic turns per rolling hour, and a chain of sessions answering each other stops after 20 automatic turns with no person in between (`limit` changes both for one session). The orchestrator may resume a session once per hour; the owner any time. See `packages/protocol/PROTOCOL.md`, section 6.7. |
|
|
46
|
-
| `conveno peek <session> [-n 10] [--raw-json]` | Read the last turns (prompts, replies, tool calls) of another session on this machine, with secrets redacted on a best-effort basis. `-n` is 1 to 50. Works for Claude Code, Codex, OpenCode, Copilot and Grok, and for any worker started with `--acp`; Cursor and Antigravity sessions otherwise answer that peek is not supported yet. `--raw-json` prints the daemon's answer. |
|
|
47
|
-
| `conveno peek on\|off [session]` | Allow or stop other sessions reading yours. With no session it covers every session online now. The daemon log records each peek (who, whom, how many turns), never the text. |
|
|
48
|
-
| `conveno doctor` | Check each CLI and the daemon, and say which delivery works for each: next turn, end of turn, idle wake, or inbox only. |
|
|
38
|
+
| `conveno status` | Online sessions grouped by repo, with the lead marked. |
|
|
39
|
+
| `conveno send <to> <text...> [--urgent]` | Send a message as you to a session name or id, `lead`, or `device:name`. `-` reads the text from standard input. |
|
|
40
|
+
| `conveno rename <session> <new-name>` | Rename an online session. |
|
|
41
|
+
| `conveno lead <session>` | Make a session the lead. `conveno lead --clear` leaves no lead. |
|
|
42
|
+
| `conveno spawn <cli> [--cwd <dir>] [--name <name>] [--task <text> \| --task-file <path>] [--window] [--allow <kinds>] [--yes]` | Start a worker session of `claude`, `codex`, `opencode`, `cursor`, `copilot`, `antigravity` or `grok`, and print its name once it registers. The CLI must be installed. By default the worker runs in the background through the CLI's Agent Client Protocol server, with `conveno acp-host` driving it. It keeps running: each message sent to it becomes its next prompt at once when it is idle, or when its current turn ends. `--window` opens the real CLI in a new terminal instead, so you can watch it and take over: Windows Terminal (`wt -w 0 new-tab`, else a new console window) on Windows, Terminal.app (iTerm2 when it is your terminal) on macOS, and on Linux a new tmux window when you are inside tmux, else the first of `x-terminal-emulator`, `gnome-terminal`, `konsole`, `kitty`, `wezterm`, `alacritty` and `xterm`. The ACP commands are `claude-agent-acp` (install `@agentclientprotocol/claude-agent-acp`), `codex-acp` (install `@agentclientprotocol/codex-acp`), `opencode acp`, `agent acp` (Cursor), `copilot --acp --stdio`, `agy acp` and `grok agent stdio`; a missing one is an error that says what to install. For Claude Code and Codex, `conveno init` can allow running the adapter with `npx -y <package>@<pinned version>`, and `CONVENO_ACP_CODEX_CMD` / `CONVENO_ACP_CLAUDE_CMD` replace the command. In the background a tool call that needs approval is denied unless `--allow` covers it: comma-separated ACP tool kinds (`read`, `edit`, `delete`, `move`, `search`, `execute`, `think`, `fetch`, `switch_mode`, `other`, or `*`), each optionally with `:` and a title glob (`execute:npm test*`). Allowed calls are answered "allow once", never "always". The first task is optional. `--name` sets the session name (a taken or reserved one is refused); otherwise the usual `<cli>@<repo>-<n>` name is used. `--cwd` defaults to the current folder, which must be inside your home folder; an explicit `--cwd` can be anywhere. It asks first and `--yes` skips the question; without a terminal it exits 2 unless `--yes` is given. At most 8 spawned sessions run at once (`CONVENO_SPAWN_MAX` changes that), and a spawned session cannot spawn more than 3 levels deep. A task is at most 16000 characters. See `packages/protocol/PROTOCOL.md`. |
|
|
43
|
+
| `conveno stop <worker>` | Stop a background worker. It cancels a running turn, ends its CLI and the processes it started, tells the spawning session why, and goes offline. A worker in a window is yours to close. |
|
|
44
|
+
| `conveno doctor [--cli <list>]` | Check each CLI and the daemon, and say how to fix what is wrong. `--cli claude,codex` checks only those CLIs, so problems in the others do not count. |
|
|
45
|
+
| `conveno devices [pair\|join\|revoke\|rename\|accept\|reset]` | Pro. List your devices, or pair a new machine: `pair` on one device and `join` on the new one at the same time, then type the 8-digit code each screen shows. `revoke` removes a device for good. Needs a Pro login on both. |
|
|
46
|
+
| `conveno relay status` | Show the relay connection. |
|
|
49
47
|
| `conveno login [--no-browser]` | Sign in to your Conveno account for Pro. Shows a code and a link, opens the browser, and waits for you to approve the code. The tokens go to `account.json` in the data dir, readable by you only. The local mesh does not need an account. |
|
|
50
48
|
| `conveno logout` | Sign out on the server and delete the saved tokens. |
|
|
51
49
|
| `conveno account` | Show your plan and trial. |
|
|
52
|
-
| `conveno daemon start\|stop\|status` | Control the local daemon. It also starts when a CLI opens the Conveno MCP server, and exits when no session has been online for a while. |
|
|
53
50
|
|
|
54
|
-
`conveno --help` lists the rest, and `conveno <command> --help` shows the options of one. The `mcp`, `hook`, `spawn-run` and `acp-host` commands are what the CLIs
|
|
51
|
+
`conveno --help` lists the rest, and `conveno <command> --help` shows the options of one. The `daemon`, `mcp`, `hook`, `spawn-run` and `acp-host` commands are hidden or are what the CLIs and spawned workers call; you do not run them yourself.
|
|
55
52
|
|
|
56
53
|
## Supported CLIs
|
|
57
54
|
|
|
58
|
-
| CLI |
|
|
59
|
-
|
|
60
|
-
| Claude Code |
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
-
| Cursor CLI | After the next tool call (hook), or
|
|
64
|
-
| GitHub Copilot CLI |
|
|
65
|
-
| Antigravity | Before each model call (hook)
|
|
66
|
-
| Grok |
|
|
55
|
+
| CLI | Messages arrive | Wakes when idle |
|
|
56
|
+
|---|---|---|
|
|
57
|
+
| Claude Code | Next turn (hook), or `inbox` | Yes |
|
|
58
|
+
| OpenCode | `inbox`, plus the plugin at the end of a turn | Yes (plugin) |
|
|
59
|
+
| Codex | Next turn (hook), or `inbox` | Coming in the next release |
|
|
60
|
+
| Cursor CLI | After the next tool call (hook), or `inbox` | Coming in the next release |
|
|
61
|
+
| GitHub Copilot CLI | Next turn (hook), or `inbox` | Coming in the next release |
|
|
62
|
+
| Antigravity | Before each model call (hook), or `inbox` | Coming in the next release |
|
|
63
|
+
| Grok | `inbox`, plus a hook at the end of a turn | Coming in the next release |
|
|
64
|
+
|
|
65
|
+
A worker started with `conveno spawn` wakes on every message, whatever the CLI.
|
|
67
66
|
|
|
68
67
|
## Compatibility
|
|
69
68
|
|
|
@@ -71,7 +70,7 @@ Vendors change config and hook formats without notice. `conveno doctor` compares
|
|
|
71
70
|
|
|
72
71
|
## How it works
|
|
73
72
|
|
|
74
|
-
Each CLI session starts its own MCP server through `conveno mcp`. The servers talk to one small daemon on your machine, which keeps the session list, the mailboxes and the routing. The daemon listens on a local socket and nothing leaves your machine. Messages from other sessions reach an agent labelled as data from a peer, not as instructions from you.
|
|
73
|
+
Each CLI session starts its own MCP server through `conveno mcp`. The servers talk to one small daemon on your machine, which keeps the session list, the mailboxes and the routing. The daemon listens on a local socket and, without Pro, nothing leaves your machine. With Pro, end-to-end encrypted envelopes go through `relay.conveno.dev` to your other machines. The relay sees device names, public keys, routing metadata and sizes, never message content. Conveno sends no telemetry. Messages from other sessions reach an agent labelled as data from a peer, not as instructions from you.
|
|
75
74
|
|
|
76
75
|
Conveno never reads, stores or forwards a provider login token or credential file. It works with the official CLIs only, under your own login or API key.
|
|
77
76
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { n as runAcpHostFromFile, r as stopRequestPath, t as killProcessTree } from "./dist-BLfduOoT.js";
|
|
3
|
+
import { At as readSpawnRecord, Wt as spawnRecordPath } from "./dist-STNJjbNH.js";
|
|
4
|
+
import { a as parseFlags, n as COMMANDS } from "./args-B3Cj2Ie4.js";
|
|
5
|
+
import { a as fail, n as cmd } from "./fmt-C2SsP5Y0.js";
|
|
6
|
+
// src/acp.ts
|
|
7
|
+
/** How long `conveno stop` waits for a worker to end by itself before it ends the process tree. */
|
|
8
|
+
const STOP_WAIT_MS = 1e4;
|
|
9
|
+
/** `conveno acp-host <launch file>`: what `conveno spawn` runs in the background. Not for people. */
|
|
10
|
+
async function runAcpHostCmd(ctx, argv) {
|
|
11
|
+
const [file] = argv;
|
|
12
|
+
if (!file) return fail(ctx, {
|
|
13
|
+
what: "conveno acp-host needs a launch file",
|
|
14
|
+
detail: ["It is started by conveno spawn."],
|
|
15
|
+
fix: `Run ${cmd(ctx.theme, "conveno spawn <cli>")} instead.`,
|
|
16
|
+
exit: 2,
|
|
17
|
+
ref: "e_usage"
|
|
18
|
+
});
|
|
19
|
+
try {
|
|
20
|
+
return await runAcpHostFromFile(file, {
|
|
21
|
+
dataDir: ctx.dataDir,
|
|
22
|
+
...ctx.socketPath ? { socketPath: ctx.socketPath } : {},
|
|
23
|
+
...ctx.daemonEntry ? { daemonEntry: ctx.daemonEntry } : {}
|
|
24
|
+
});
|
|
25
|
+
} catch (e) {
|
|
26
|
+
return fail(ctx, {
|
|
27
|
+
what: "The ACP host could not start",
|
|
28
|
+
detail: [e instanceof Error ? e.message : String(e)],
|
|
29
|
+
fix: `Run ${cmd(ctx.theme, "conveno spawn <cli>")} again.`,
|
|
30
|
+
exit: 1,
|
|
31
|
+
ref: "e_spawn"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function findWorker(ctx, name, command) {
|
|
36
|
+
if (!name) return fail(ctx, {
|
|
37
|
+
what: `conveno ${command} needs a worker name`,
|
|
38
|
+
fix: `Run ${cmd(ctx.theme, "conveno status")} to see the names.`,
|
|
39
|
+
exit: 2,
|
|
40
|
+
ref: "e_usage"
|
|
41
|
+
});
|
|
42
|
+
const rec = /^[a-z0-9][a-z0-9._@-]{0,63}$/.test(name) ? readSpawnRecord(spawnRecordPath(ctx.dataDir, name)) : void 0;
|
|
43
|
+
if (!rec) return fail(ctx, {
|
|
44
|
+
what: `No running worker named "${name}"`,
|
|
45
|
+
detail: ["Only sessions started by conveno spawn or spawn_session on this machine are workers."],
|
|
46
|
+
fix: `Run ${cmd(ctx.theme, "conveno status")} to see the names.`,
|
|
47
|
+
exit: 1,
|
|
48
|
+
ref: "e_not_found"
|
|
49
|
+
});
|
|
50
|
+
return rec;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* `conveno stop <worker>`. An ACP worker gets a stop request: its host sends `session/cancel` for
|
|
54
|
+
* a running turn, ends the agent, reports to the spawner and takes the session offline. A worker in a
|
|
55
|
+
* terminal window is the user's to close.
|
|
56
|
+
*/
|
|
57
|
+
async function runStop(ctx, argv) {
|
|
58
|
+
const spec = COMMANDS.find((c) => c.name === "stop");
|
|
59
|
+
if (!spec) return 2;
|
|
60
|
+
const parsed = parseFlags(ctx, spec, argv);
|
|
61
|
+
if (typeof parsed === "number") return parsed;
|
|
62
|
+
const [name] = parsed.positionals;
|
|
63
|
+
const rec = findWorker(ctx, name, "stop");
|
|
64
|
+
if (typeof rec === "number") return rec;
|
|
65
|
+
const t = ctx.theme;
|
|
66
|
+
if (!rec.acp) return fail(ctx, {
|
|
67
|
+
what: `${rec.name} runs in a terminal`,
|
|
68
|
+
detail: ["Conveno does not close a terminal you can see."],
|
|
69
|
+
fix: "Exit the CLI in that terminal.",
|
|
70
|
+
exit: 1,
|
|
71
|
+
ref: "e_spawn"
|
|
72
|
+
});
|
|
73
|
+
const alive = () => rec.pid !== void 0 && ctx.isAlive(rec.pid);
|
|
74
|
+
writeFileSync(stopRequestPath(spawnRecordPath(ctx.dataDir, rec.name)), "", { mode: 384 });
|
|
75
|
+
const end = Date.now() + STOP_WAIT_MS;
|
|
76
|
+
while (alive() && Date.now() < end) await new Promise((r) => setTimeout(r, 100));
|
|
77
|
+
if (alive() && rec.pid !== void 0) killProcessTree(rec.pid, ctx.platform);
|
|
78
|
+
if (rec.agentPid !== void 0 && ctx.isAlive(rec.agentPid)) killProcessTree(rec.agentPid, ctx.platform);
|
|
79
|
+
ctx.out(`${t.status("ok")} ${t.bold(`Stopped ${rec.name}`)}\n`);
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
export { runAcpHostCmd, runStop };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { t as RELAY_SUBCOMMAND } from "./dist-VOS92iqO.js";
|
|
3
|
+
import { Vt as runWaker } from "./dist-STNJjbNH.js";
|
|
4
|
+
import { n as connectOpts } from "./ctx-tYftvhz_.js";
|
|
5
|
+
// src/agy-relay.ts
|
|
6
|
+
/**
|
|
7
|
+
* Time limit of one `agentapi send-message`. It normally answers within about a second; the limit
|
|
8
|
+
* only stops a hung run. It is long so a slow send that succeeds is not taken for a failure.
|
|
9
|
+
*/
|
|
10
|
+
const SEND_TIMEOUT_MS = 12e4;
|
|
11
|
+
/** Runs the file directly, never through a shell, so every argument stays one argument. */
|
|
12
|
+
const runSend = (file, args, timeoutMs) => new Promise((resolve) => {
|
|
13
|
+
execFile(file, args, {
|
|
14
|
+
timeout: timeoutMs,
|
|
15
|
+
windowsHide: true,
|
|
16
|
+
encoding: "utf8"
|
|
17
|
+
}, (err) => {
|
|
18
|
+
if (!err) return resolve("sent");
|
|
19
|
+
resolve(err.killed ? "unknown" : "failed");
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
const UUID = /^[0-9a-fA-F-]{8,64}$/;
|
|
23
|
+
function relayText(text, count) {
|
|
24
|
+
if (text.length <= 16e3) return text;
|
|
25
|
+
return `[conveno] ${count} message${count === 1 ? "" : "s"} arrived through Conveno, too long to show here. Conveno started this turn; the user did not type it. Read them with the inbox tool (unread_only false).`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Run `<agy> agentapi send-message <conversation> <text>`. The executable is run directly, never
|
|
29
|
+
* through a shell, so the text stays one argument; on Windows only a real `.exe` is run, because a
|
|
30
|
+
* `.cmd` or `.bat` shim would have cmd.exe parse the text. False only when no turn started: a send
|
|
31
|
+
* killed at the time limit counts as sent, so the waker does not requeue messages agy may already
|
|
32
|
+
* have taken and send them twice (they stay readable with the inbox tool).
|
|
33
|
+
*/
|
|
34
|
+
async function sendToConversation(io, exe, conversationId, text) {
|
|
35
|
+
if (io.platform === "win32" && !/\.exe$/i.test(exe)) return false;
|
|
36
|
+
try {
|
|
37
|
+
return await (io.run ?? runSend)(exe, [
|
|
38
|
+
"agentapi",
|
|
39
|
+
"send-message",
|
|
40
|
+
conversationId,
|
|
41
|
+
text
|
|
42
|
+
], SEND_TIMEOUT_MS) !== "failed";
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const END = {
|
|
48
|
+
superseded: "another relay for this conversation took over. Do not start it again.",
|
|
49
|
+
no_session: "no Conveno session belongs to this conversation (is the conveno MCP server on?). Do not start it again.",
|
|
50
|
+
one_shot: "this agy run is one-shot (agy -p), so nothing can wake it. Do not start it again."
|
|
51
|
+
};
|
|
52
|
+
/** agy's one-shot flags: `-p` and its aliases `--print` and `--prompt` (agy docs cli/headless). */
|
|
53
|
+
const ONE_SHOT = /^(?:-p|--print|--prompt)(?:=|$)/;
|
|
54
|
+
/** True when an ancestor of this process is a one-shot `agy -p` run. */
|
|
55
|
+
async function underOneShotAgy(ctx) {
|
|
56
|
+
return ((await ctx.ancestry(2e3).catch(() => void 0))?.entries ?? []).some((e) => {
|
|
57
|
+
const words = Array.from((e.command ?? "").matchAll(/"([^"]*)"|(\S+)/g)).map((m) => m[1] ?? m[2] ?? "");
|
|
58
|
+
const exe = (words[0] ?? "").split(/[\\/]/).pop()?.toLowerCase();
|
|
59
|
+
return (exe === "agy" || exe === "agy.exe") && words.slice(1).some((w) => ONE_SHOT.test(w));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async function runAgyRelay(ctx, argv, deps = {}) {
|
|
63
|
+
const end = (why, code = 0) => {
|
|
64
|
+
ctx.out(`[conveno] ${RELAY_SUBCOMMAND} ended: ${why}\n`);
|
|
65
|
+
return code;
|
|
66
|
+
};
|
|
67
|
+
if (argv.length > 0) return end("it takes no arguments.", 2);
|
|
68
|
+
const conversationId = ctx.env.ANTIGRAVITY_CONVERSATION_ID;
|
|
69
|
+
const exe = ctx.env.ANTIGRAVITY_AGENTAPI_EXE;
|
|
70
|
+
if (!conversationId || !UUID.test(conversationId) || !exe) return end("it only runs inside an Antigravity agent's command. Nothing to do.");
|
|
71
|
+
if (ctx.platform === "win32" && !/\.exe$/i.test(exe)) return end("ANTIGRAVITY_AGENTAPI_EXE is not an .exe. Do not start it again.");
|
|
72
|
+
if (await underOneShotAgy(ctx)) return end(END.one_shot);
|
|
73
|
+
const controller = new AbortController();
|
|
74
|
+
const signal = controller.signal;
|
|
75
|
+
const stop = () => controller.abort();
|
|
76
|
+
deps.signal?.addEventListener("abort", stop, { once: true });
|
|
77
|
+
if (deps.signal?.aborted) stop();
|
|
78
|
+
const signals = deps.signal ? [] : ["SIGINT", "SIGTERM"];
|
|
79
|
+
for (const s of signals) process.once(s, stop);
|
|
80
|
+
const runWaker$1 = deps.runWaker ?? runWaker;
|
|
81
|
+
const pollMs = deps.pollMs ?? 3e3;
|
|
82
|
+
const findMs = deps.findMs ?? 6e5;
|
|
83
|
+
const retryBase = deps.retryMs ?? 2e3;
|
|
84
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
85
|
+
const t = setTimeout(resolve, ms);
|
|
86
|
+
signal.addEventListener("abort", () => {
|
|
87
|
+
clearTimeout(t);
|
|
88
|
+
resolve();
|
|
89
|
+
}, { once: true });
|
|
90
|
+
});
|
|
91
|
+
let client;
|
|
92
|
+
let retry = retryBase;
|
|
93
|
+
let looking = Date.now();
|
|
94
|
+
try {
|
|
95
|
+
while (!signal.aborted) {
|
|
96
|
+
let session;
|
|
97
|
+
let c;
|
|
98
|
+
try {
|
|
99
|
+
c = client ??= await ctx.connect(connectOpts(ctx, false));
|
|
100
|
+
const { sessions } = await c["session.list"]({ cli: "antigravity" });
|
|
101
|
+
session = sessions.find((s) => s.nativeId === conversationId && s.status !== "offline");
|
|
102
|
+
retry = retryBase;
|
|
103
|
+
} catch {
|
|
104
|
+
await client?.close().catch(() => void 0);
|
|
105
|
+
client = void 0;
|
|
106
|
+
await sleep(retry);
|
|
107
|
+
retry = Math.min(retry * 2, 6e4);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (!session) {
|
|
111
|
+
if (Date.now() - looking > findMs) return end(END.no_session);
|
|
112
|
+
await sleep(pollMs);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const hostPid = session.hostPid;
|
|
116
|
+
const reason = await runWaker$1({
|
|
117
|
+
client: c,
|
|
118
|
+
sessionId: session.id,
|
|
119
|
+
signal,
|
|
120
|
+
...hostPid ? { isHostAlive: () => ctx.isAlive(hostPid) } : {},
|
|
121
|
+
inject: (text, messages) => sendToConversation({
|
|
122
|
+
platform: ctx.platform,
|
|
123
|
+
...deps.run ? { run: deps.run } : {}
|
|
124
|
+
}, exe, conversationId, relayText(text, messages.length))
|
|
125
|
+
});
|
|
126
|
+
if (reason === "aborted" || reason === "host_exited") return 0;
|
|
127
|
+
if (reason === "superseded") return end(END.superseded);
|
|
128
|
+
looking = Date.now();
|
|
129
|
+
}
|
|
130
|
+
return 0;
|
|
131
|
+
} finally {
|
|
132
|
+
deps.signal?.removeEventListener("abort", stop);
|
|
133
|
+
for (const s of signals) process.off(s, stop);
|
|
134
|
+
await client?.close().catch(() => void 0);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
export { runAgyRelay };
|