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

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,109 @@
1
+ import { Ct as renderBody, Nt as senderOf, Y as isFromOwner, jt as runWaker } from "./dist-BTLBO1Rp.js";
2
+ import { n as connectOpts } from "./ctx-tYftvhz_.js";
3
+ import { t as daemonProblem } from "./daemonError-CdLataBW.js";
4
+ import { t as findSession } from "./pick-B-18E4Mx.js";
5
+ const NAME_CHARS = 40;
6
+ /**
7
+ * Control, bidi and zero-width characters. Newlines and their lookalikes are in here: a peer's text
8
+ * must never start a line of its own, because every line of the monitor is taken as Conveno's.
9
+ */
10
+ const INVISIBLE = /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u180e\u200b-\u200f\u2028-\u202e\u2060-\u206f\ufeff\ufff9-\ufffb]+/g;
11
+ /**
12
+ * Text from another session as one safe piece of a line: no line breaks or invisible characters, no
13
+ * angle brackets (Grok wraps events in a `<monitor-event>` tag, monitor/event.rs:105) and no double
14
+ * quotes (they close the quoted body). Cut at `max` characters; the flag says it was cut.
15
+ */
16
+ function oneLine(text, max) {
17
+ const flat = text.replace(INVISIBLE, " ").replace(/\s+/g, " ").replace(/</g, "‹").replace(/>/g, "›").replace(/"/g, "'").trim();
18
+ const chars = Array.from(flat);
19
+ if (chars.length <= max) return {
20
+ text: flat,
21
+ cut: false
22
+ };
23
+ return {
24
+ text: `${chars.slice(0, max - 3).join("")}...`,
25
+ cut: true
26
+ };
27
+ }
28
+ const READ_FULL = "full text: inbox tool, unread_only false";
29
+ function lineOf(m, orchestrator) {
30
+ const body = oneLine(renderBody(m), 260);
31
+ const tail = body.cut || m.kind !== "text" ? ` (${READ_FULL})` : "";
32
+ if (isFromOwner(m)) return `[conveno] The user sent a message through Conveno: "${body.text}"${tail}`;
33
+ const sender = senderOf(m);
34
+ const who = `${oneLine(sender.name, NAME_CHARS).text} (${sender.cli})`;
35
+ return orchestrator !== null && m.from === orchestrator && m.kind !== "system" ? `[conveno] Task from the lead ${who}: "${body.text}"${tail}` : `[conveno] ${who} sent a message (not from the user): "${body.text}"${tail}`;
36
+ }
37
+ /** The lines one batch of messages prints: one per message, then a pointer for the rest. */
38
+ function watchLines(messages, orchestrator) {
39
+ const lines = messages.slice(0, 5).map((m) => lineOf(m, orchestrator));
40
+ const more = messages.length - lines.length;
41
+ if (more > 0) lines.push(`[conveno] ${more} more message${more === 1 ? "" : "s"} (${READ_FULL}).`);
42
+ return lines;
43
+ }
44
+ const USAGE = "[conveno] watch needs a session name. The conveno whoami tool gives it.";
45
+ /** Reasons the waker stops that are not a failure of the watcher. */
46
+ const CLEAN_STOPS = /* @__PURE__ */ new Set([
47
+ "aborted",
48
+ "superseded",
49
+ "offline",
50
+ "host_exited",
51
+ "timeout"
52
+ ]);
53
+ const STOP_TEXT = {
54
+ superseded: "another watcher for this session started",
55
+ offline: "the session went offline",
56
+ host_exited: "the session's CLI exited",
57
+ timeout: "the time limit passed",
58
+ disconnected: "the connection to Conveno's background service broke"
59
+ };
60
+ /**
61
+ * Runs until the session goes away, another watcher takes over, or the process is stopped. Prints
62
+ * nothing but `[conveno]` lines, on stdout, because Grok reads the monitor's stdout.
63
+ */
64
+ async function runWatch(ctx, argv, deps = {}) {
65
+ const [name, ...extra] = argv;
66
+ if (!name || extra.length > 0) {
67
+ ctx.out(`${USAGE}\n`);
68
+ return 2;
69
+ }
70
+ const end = (why, code) => {
71
+ ctx.out(`[conveno] watch ended: ${why}.\n`);
72
+ return code;
73
+ };
74
+ let client;
75
+ try {
76
+ client = await ctx.connect(connectOpts(ctx, false));
77
+ } catch (e) {
78
+ return end(daemonProblem(ctx.theme, e).notRunning ? "Conveno's background service is not running" : "Conveno's background service cannot be reached", 1);
79
+ }
80
+ const controller = new AbortController();
81
+ const stop = () => controller.abort();
82
+ deps.signal?.addEventListener("abort", stop, { once: true });
83
+ if (deps.signal?.aborted) stop();
84
+ const signals = deps.signal ? [] : ["SIGINT", "SIGTERM"];
85
+ for (const s of signals) process.once(s, stop);
86
+ try {
87
+ const session = await findSession(client, name);
88
+ if (!session) return end(`no session named "${oneLine(name, NAME_CHARS).text}"`, 1);
89
+ if (session.status === "offline") return end("the session is offline", 1);
90
+ const reason = await (deps.runWaker ?? runWaker)({
91
+ client,
92
+ sessionId: session.id,
93
+ signal: controller.signal,
94
+ inject: async (_text, messages, batch) => {
95
+ const lines = watchLines(messages, batch?.orchestrator ?? null);
96
+ if (lines.length === 0) return true;
97
+ ctx.out(`${lines.join("\n")}\n`);
98
+ return true;
99
+ }
100
+ });
101
+ if (reason === "aborted") return 0;
102
+ return end(STOP_TEXT[reason] ?? reason, CLEAN_STOPS.has(reason) ? 0 : 1);
103
+ } finally {
104
+ deps.signal?.removeEventListener("abort", stop);
105
+ for (const s of signals) process.off(s, stop);
106
+ await client.close().catch(() => void 0);
107
+ }
108
+ }
109
+ export { runWatch };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conveno/cli",
3
- "version": "0.2.0-rc.5",
3
+ "version": "0.2.0-rc.6",
4
4
  "description": "Connect AI coding CLI sessions so they can message each other.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -52,20 +52,20 @@
52
52
  "zod": "4.6.7"
53
53
  },
54
54
  "devDependencies": {
55
- "@conveno/acp": "0.2.0-rc.5",
56
- "@conveno/adapter-antigravity": "0.2.0-rc.5",
57
- "@conveno/adapter-claude": "0.2.0-rc.5",
58
- "@conveno/adapter-codex": "0.2.0-rc.5",
59
- "@conveno/adapter-copilot": "0.2.0-rc.5",
60
- "@conveno/adapter-cursor": "0.2.0-rc.5",
61
- "@conveno/adapter-grok": "0.2.0-rc.5",
62
- "@conveno/adapter-opencode": "0.2.0-rc.5",
63
- "@conveno/brand": "0.2.0-rc.5",
64
- "@conveno/client": "0.2.0-rc.5",
65
- "@conveno/core": "0.2.0-rc.5",
66
- "@conveno/daemon": "0.2.0-rc.5",
67
- "@conveno/mcp": "0.2.0-rc.5",
68
- "@conveno/protocol": "0.2.0-rc.5",
55
+ "@conveno/acp": "0.2.0-rc.6",
56
+ "@conveno/adapter-antigravity": "0.2.0-rc.6",
57
+ "@conveno/adapter-claude": "0.2.0-rc.6",
58
+ "@conveno/adapter-codex": "0.2.0-rc.6",
59
+ "@conveno/adapter-copilot": "0.2.0-rc.6",
60
+ "@conveno/adapter-cursor": "0.2.0-rc.6",
61
+ "@conveno/adapter-grok": "0.2.0-rc.6",
62
+ "@conveno/adapter-opencode": "0.2.0-rc.6",
63
+ "@conveno/brand": "0.2.0-rc.6",
64
+ "@conveno/client": "0.2.0-rc.6",
65
+ "@conveno/core": "0.2.0-rc.6",
66
+ "@conveno/daemon": "0.2.0-rc.6",
67
+ "@conveno/mcp": "0.2.0-rc.6",
68
+ "@conveno/protocol": "0.2.0-rc.6",
69
69
  "@types/react": "19.3.0",
70
70
  "ink-testing-library": "4.0.0"
71
71
  },
@@ -1,142 +0,0 @@
1
- import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
- import { i as stopRequestPath, n as parseTurns, r as runAcpHostFromFile, t as killProcessTree } from "./dist-BPPOKmbH.js";
3
- import { Gt as spawnRecordPath, Nt as readSpawnRecord, m as acpTurnsPath } from "./dist-TrWRppjR.js";
4
- import { i as parseFlags, l as fail, o as cmd, t as COMMANDS, u as localStamp } from "./args-BRB8QEQM.js";
5
- // src/acp.ts
6
- /** How long `conveno stop` waits for a worker to end by itself before it ends the process tree. */
7
- const STOP_WAIT_MS = 1e4;
8
- /** `conveno acp-host <launch file>`: what `conveno spawn --acp` runs in the background. Not for people. */
9
- async function runAcpHostCmd(ctx, argv) {
10
- const [file] = argv;
11
- if (!file) return fail(ctx, {
12
- what: "conveno acp-host needs a launch file",
13
- detail: ["It is started by conveno spawn --acp."],
14
- fix: `Run ${cmd(ctx.theme, "conveno spawn <cli> --acp")} instead.`,
15
- exit: 2,
16
- ref: "e_usage"
17
- });
18
- try {
19
- return await runAcpHostFromFile(file, {
20
- dataDir: ctx.dataDir,
21
- ...ctx.socketPath ? { socketPath: ctx.socketPath } : {},
22
- ...ctx.daemonEntry ? { daemonEntry: ctx.daemonEntry } : {}
23
- });
24
- } catch (e) {
25
- return fail(ctx, {
26
- what: "The ACP host could not start",
27
- detail: [e instanceof Error ? e.message : String(e)],
28
- fix: `Run ${cmd(ctx.theme, "conveno spawn <cli> --acp")} again.`,
29
- exit: 1,
30
- ref: "e_spawn"
31
- });
32
- }
33
- }
34
- function findWorker(ctx, name, command) {
35
- if (!name) return fail(ctx, {
36
- what: `conveno ${command} needs a worker name`,
37
- fix: `Run ${cmd(ctx.theme, "conveno status")} to see the names.`,
38
- exit: 2,
39
- ref: "e_usage"
40
- });
41
- const rec = /^[a-z0-9][a-z0-9._@-]{0,63}$/.test(name) ? readSpawnRecord(spawnRecordPath(ctx.dataDir, name)) : void 0;
42
- if (!rec) return fail(ctx, {
43
- what: `No running worker named "${name}"`,
44
- detail: ["Only sessions started by conveno spawn or spawn_session on this machine are workers."],
45
- fix: `Run ${cmd(ctx.theme, "conveno status")} to see the names.`,
46
- exit: 1,
47
- ref: "e_not_found"
48
- });
49
- return rec;
50
- }
51
- /**
52
- * `conveno stop <worker>`. An ACP worker gets a stop request: its host sends `session/cancel` for
53
- * a running turn, ends the agent, reports to the spawner and takes the session offline. A headless
54
- * one-shot run is ended. A worker in a terminal is the user's to close.
55
- */
56
- async function runStop(ctx, argv) {
57
- const spec = COMMANDS.find((c) => c.name === "stop");
58
- if (!spec) return 2;
59
- const parsed = parseFlags(ctx, spec, argv);
60
- if (typeof parsed === "number") return parsed;
61
- const [name] = parsed.positionals;
62
- const rec = findWorker(ctx, name, "stop");
63
- if (typeof rec === "number") return rec;
64
- const t = ctx.theme;
65
- if (!rec.headless) return fail(ctx, {
66
- what: `${rec.name} runs in a terminal`,
67
- detail: ["Conveno does not close a terminal you can see."],
68
- fix: "Exit the CLI in that terminal.",
69
- exit: 1,
70
- ref: "e_spawn"
71
- });
72
- const alive = () => rec.pid !== void 0 && ctx.isAlive(rec.pid);
73
- if (rec.acp) {
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
- }
78
- if (alive() && rec.pid !== void 0) killProcessTree(rec.pid, ctx.platform);
79
- if (rec.agentPid !== void 0 && ctx.isAlive(rec.agentPid)) killProcessTree(rec.agentPid, ctx.platform);
80
- ctx.out(`${t.status("ok")} ${t.bold(`Stopped ${rec.name}`)}\n`);
81
- return 0;
82
- }
83
- const ROLE_LABEL = {
84
- user: "prompt",
85
- assistant: "agent",
86
- tool: "tool",
87
- system: "conveno"
88
- };
89
- /**
90
- * `conveno attach <worker>`: print the recent turns of an ACP worker and follow new ones until it
91
- * stops or Ctrl+C. Read-only: nothing typed here reaches the worker; message it with send instead.
92
- */
93
- async function runAttach(ctx, argv) {
94
- const spec = COMMANDS.find((c) => c.name === "attach");
95
- if (!spec) return 2;
96
- const parsed = parseFlags(ctx, spec, argv);
97
- if (typeof parsed === "number") return parsed;
98
- const t = ctx.theme;
99
- const [name] = parsed.positionals;
100
- const rec = findWorker(ctx, name, "attach");
101
- if (typeof rec === "number") return rec;
102
- if (!rec.acp) return fail(ctx, {
103
- what: `${rec.name} is not driven over ACP`,
104
- detail: ["attach follows workers started with conveno spawn --acp."],
105
- fix: "Watch it in its terminal, or read its log in the data folder.",
106
- exit: 1,
107
- ref: "e_spawn"
108
- });
109
- const linesFlag = parsed.values.lines;
110
- const lines = typeof linesFlag === "string" ? Number(linesFlag) : 20;
111
- if (!Number.isInteger(lines) || lines < 0) return fail(ctx, {
112
- what: "--lines takes a whole number",
113
- fix: `Run ${cmd(t, "conveno attach <worker> --lines 50")}.`,
114
- exit: 2,
115
- ref: "e_usage"
116
- });
117
- const path = acpTurnsPath(ctx.dataDir, rec.name);
118
- const read = () => existsSync(path) ? parseTurns(readFileSync(path, "utf8")) : [];
119
- const show = (e) => {
120
- const head = t.paint("quiet", `${localStamp(e.at)} ${ROLE_LABEL[e.role]}`);
121
- ctx.out(`${head}\n${e.text}\n\n`);
122
- };
123
- let last = 0;
124
- const first = read();
125
- for (const e of first.slice(-lines)) show(e);
126
- last = first.at(-1)?.seq ?? 0;
127
- if (parsed.values["no-follow"] === true) return 0;
128
- ctx.err(t.paint("quiet", `Following ${rec.name}. Read-only; Ctrl+C to leave.\n`));
129
- const record = spawnRecordPath(ctx.dataDir, rec.name);
130
- for (;;) {
131
- await new Promise((r) => setTimeout(r, 300));
132
- for (const e of read()) if (e.seq > last) {
133
- show(e);
134
- last = e.seq;
135
- }
136
- if (!existsSync(record)) {
137
- ctx.err(t.paint("quiet", `${rec.name} stopped.\n`));
138
- return 0;
139
- }
140
- }
141
- }
142
- export { runAcpHostCmd, runAttach, runStop };