@conveno/cli 0.1.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.
@@ -0,0 +1,185 @@
1
+ import { n as isOneShotGrok } from "./dist-DaIpdMke.js";
2
+ import { $ as isFromOwner, Mt as renderBody, Ut as senderOf, Vt as runWaker } from "./dist-STNJjbNH.js";
3
+ import { n as connectOpts } from "./ctx-tYftvhz_.js";
4
+ import { t as daemonProblem } from "./daemonError-C05GqdhQ.js";
5
+ import { t as findSession } from "./pick-DLp6w_-z.js";
6
+ // src/watch.ts
7
+ const CONNECT_MAX_RETRY_MS = 3e4;
8
+ const CONNECT_GIVE_UP_MS = 3e5;
9
+ /** Bytes of a sender's name in a line. */
10
+ const NAME_BYTES = 60;
11
+ /** The least room a message body gets. */
12
+ const MIN_BODY_BYTES = 60;
13
+ const bytes = (text) => Buffer.byteLength(text, "utf8");
14
+ /**
15
+ * Control, bidi and zero-width characters. Newlines and their lookalikes are in here: a peer's text
16
+ * must never start a line of its own, because every line of the monitor is taken as Conveno's.
17
+ */
18
+ const INVISIBLE = /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u180e\u200b-\u200f\u2028-\u202e\u2060-\u206f\ufeff\ufff9-\ufffb]+/g;
19
+ /**
20
+ * Text from another session as one safe piece of a line: no line breaks or invisible characters, no
21
+ * angle brackets (Grok wraps events in a `<monitor-event>` tag, monitor/event.rs:105) and no double
22
+ * quotes (they close the quoted body). Cut so it takes at most `maxBytes` of UTF-8, on a whole
23
+ * character; the flag says it was cut.
24
+ */
25
+ function oneLine(text, maxBytes) {
26
+ const flat = text.replace(INVISIBLE, " ").replace(/\s+/g, " ").replace(/</g, "‹").replace(/>/g, "›").replace(/"/g, "'").trim();
27
+ if (bytes(flat) <= maxBytes) return {
28
+ text: flat,
29
+ cut: false
30
+ };
31
+ const room = Math.max(0, maxBytes - 3);
32
+ let out = "";
33
+ let used = 0;
34
+ for (const ch of flat) {
35
+ const n = bytes(ch);
36
+ if (used + n > room) break;
37
+ out += ch;
38
+ used += n;
39
+ }
40
+ return {
41
+ text: `${out}...`,
42
+ cut: true
43
+ };
44
+ }
45
+ const READ_FULL = "full text: inbox tool, unread_only false";
46
+ function lineOf(m, orchestrator) {
47
+ let head;
48
+ let who = "";
49
+ if (isFromOwner(m)) head = "[conveno] The user sent a message through Conveno";
50
+ else {
51
+ const sender = senderOf(m);
52
+ who = `${oneLine(sender.name, NAME_BYTES).text} (${sender.cli})`;
53
+ head = orchestrator !== null && m.from === orchestrator && m.kind !== "system" ? `[conveno] Task from the lead ${who}` : `[conveno] ${who} sent a message (not from the user)`;
54
+ }
55
+ const full = renderBody(m);
56
+ const tailFor = (cut) => cut || m.kind !== "text" ? ` (${READ_FULL})` : "";
57
+ const room = (tail) => Math.max(MIN_BODY_BYTES, 480 - bytes(`${head}: ""${tail}`));
58
+ let body = oneLine(full, room(tailFor(true)));
59
+ if (body.cut === false) body = oneLine(full, room(tailFor(false)));
60
+ return `${head}: "${body.text}"${tailFor(body.cut)}`;
61
+ }
62
+ /**
63
+ * The lines one batch of messages prints: one per message, then a pointer for the rest. The whole
64
+ * batch stays under `BATCH_BYTES`; a message that would not fit becomes part of the pointer.
65
+ */
66
+ function watchLines(messages, orchestrator) {
67
+ const more = (n) => `[conveno] ${n} more message${n === 1 ? "" : "s"} (${READ_FULL}).`;
68
+ const lines = [];
69
+ let used = bytes(more(messages.length)) + 1;
70
+ for (const m of messages.slice(0, 5)) {
71
+ const line = lineOf(m, orchestrator);
72
+ const next = used + bytes(line) + 1;
73
+ if (next > 2900) break;
74
+ lines.push(line);
75
+ used = next;
76
+ }
77
+ const left = messages.length - lines.length;
78
+ if (left > 0) lines.push(more(left));
79
+ return lines;
80
+ }
81
+ /** The one line a watcher prints in a one-shot run. The rules file tells the agent not to restart it. */
82
+ const ONE_SHOT_TEXT = "[conveno] watch ended: this Grok run is one-shot (grok -p), so nothing wakes it. Do not start the watcher again.";
83
+ const USAGE = "[conveno] watch needs a session name. The conveno whoami tool gives it.";
84
+ /** Reasons the waker stops that are not a failure of the watcher. */
85
+ const CLEAN_STOPS = /* @__PURE__ */ new Set([
86
+ "aborted",
87
+ "superseded",
88
+ "offline",
89
+ "host_exited",
90
+ "timeout"
91
+ ]);
92
+ const STOP_TEXT = {
93
+ superseded: "another watcher for this session started. Do not start the watcher again",
94
+ offline: "the session went offline. Do not start the watcher again",
95
+ host_exited: "the session's CLI exited. Do not start the watcher again",
96
+ timeout: "the time limit passed",
97
+ disconnected: "the connection to Conveno's background service broke"
98
+ };
99
+ /**
100
+ * Runs until the session goes away, another watcher takes over, or the process is stopped. Prints
101
+ * nothing but `[conveno]` lines, on stdout, because Grok reads the monitor's stdout.
102
+ */
103
+ async function runWatch(ctx, argv, deps = {}) {
104
+ const [name, ...extra] = argv;
105
+ if (!name || extra.length > 0) {
106
+ ctx.out(`${USAGE}\n`);
107
+ return 2;
108
+ }
109
+ const ancestry = await ctx.ancestry(2e3).catch(() => void 0);
110
+ const host = ancestry?.entries.find((e) => e.pid === ancestry.hostPid);
111
+ if (isOneShotGrok(host?.command)) {
112
+ ctx.out(`${ONE_SHOT_TEXT}\n`);
113
+ return 0;
114
+ }
115
+ const end = (why, code) => {
116
+ ctx.out(`[conveno] watch ended: ${why}.\n`);
117
+ return code;
118
+ };
119
+ const controller = new AbortController();
120
+ const stop = () => controller.abort();
121
+ deps.signal?.addEventListener("abort", stop, { once: true });
122
+ if (deps.signal?.aborted) stop();
123
+ const signals = deps.signal ? [] : ["SIGINT", "SIGTERM"];
124
+ for (const s of signals) process.once(s, stop);
125
+ let client;
126
+ try {
127
+ const retry = await connectWithBackoff(ctx, controller.signal, deps);
128
+ if (retry === "aborted") return 0;
129
+ if (retry.failed) return end(`${retry.problem.notRunning ? "Conveno's background service is not running" : "Conveno's background service cannot be reached"}. Do not start the watcher again now: it is asked for again at the end of a turn once the service is back`, 1);
130
+ client = retry.client;
131
+ const session = await findSession(client, name);
132
+ if (!session) return end(`no session named "${oneLine(name, NAME_BYTES).text}"`, 1);
133
+ if (session.status === "offline") return end("the session is offline", 1);
134
+ const reason = await (deps.runWaker ?? runWaker)({
135
+ client,
136
+ sessionId: session.id,
137
+ signal: controller.signal,
138
+ inject: async (_text, messages, batch) => {
139
+ const lines = watchLines(messages, batch?.orchestrator ?? null);
140
+ if (lines.length === 0) return false;
141
+ try {
142
+ ctx.out(`${lines.join("\n")}\n`);
143
+ } catch {
144
+ return false;
145
+ }
146
+ return true;
147
+ }
148
+ });
149
+ if (reason === "aborted") return 0;
150
+ return end(STOP_TEXT[reason] ?? reason, CLEAN_STOPS.has(reason) ? 0 : 1);
151
+ } catch {
152
+ return end("Conveno's background service cannot be reached", 1);
153
+ } finally {
154
+ deps.signal?.removeEventListener("abort", stop);
155
+ for (const s of signals) process.off(s, stop);
156
+ await client?.close().catch(() => void 0);
157
+ }
158
+ }
159
+ /** Connects, retrying with a growing wait until `giveUpMs` passes. "aborted" when stopped. */
160
+ async function connectWithBackoff(ctx, signal, deps) {
161
+ const giveUp = Date.now() + (deps.connectGiveUpMs ?? CONNECT_GIVE_UP_MS);
162
+ let wait = deps.connectRetryMs ?? 2e3;
163
+ for (;;) {
164
+ if (signal.aborted) return "aborted";
165
+ try {
166
+ return { client: await ctx.connect(connectOpts(ctx, false)) };
167
+ } catch (e) {
168
+ if (Date.now() + wait >= giveUp) return {
169
+ failed: true,
170
+ problem: daemonProblem(ctx.theme, e)
171
+ };
172
+ }
173
+ await new Promise((resolve) => {
174
+ const t = setTimeout(done, wait);
175
+ function done() {
176
+ clearTimeout(t);
177
+ signal.removeEventListener("abort", done);
178
+ resolve();
179
+ }
180
+ signal.addEventListener("abort", done, { once: true });
181
+ });
182
+ wait = Math.min(wait * 2, CONNECT_MAX_RETRY_MS);
183
+ }
184
+ }
185
+ export { runWatch };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conveno/cli",
3
- "version": "0.1.1",
3
+ "version": "0.2.0-rc.10",
4
4
  "description": "Connect AI coding CLI sessions so they can message each other.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -39,26 +39,42 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
+ "@agentclientprotocol/sdk": "2.12.0",
42
43
  "@decimalturn/toml-patch": "3.3.3",
43
44
  "@modelcontextprotocol/sdk": "1.32.2",
45
+ "@noble/ciphers": "2.4.0",
46
+ "@noble/curves": "2.4.0",
47
+ "@noble/hashes": "2.4.0",
48
+ "ink": "8.0.0",
44
49
  "jsonc-parser": "3.3.1",
50
+ "react": "19.3.1",
45
51
  "ulid": "3.0.2",
46
52
  "zod": "4.6.7"
47
53
  },
48
54
  "devDependencies": {
49
- "@conveno/adapter-claude": "0.1.1",
50
- "@conveno/adapter-codex": "0.1.1",
51
- "@conveno/adapter-opencode": "0.1.1",
52
- "@conveno/brand": "0.1.1",
53
- "@conveno/client": "0.1.1",
54
- "@conveno/core": "0.1.1",
55
- "@conveno/daemon": "0.1.1",
56
- "@conveno/mcp": "0.1.1",
57
- "@conveno/protocol": "0.1.1"
55
+ "@conveno/acp": "0.2.0-rc.10",
56
+ "@conveno/adapter-antigravity": "0.2.0-rc.10",
57
+ "@conveno/adapter-claude": "0.2.0-rc.10",
58
+ "@conveno/adapter-codex": "0.2.0-rc.10",
59
+ "@conveno/adapter-copilot": "0.2.0-rc.10",
60
+ "@conveno/adapter-cursor": "0.2.0-rc.10",
61
+ "@conveno/adapter-grok": "0.2.0-rc.10",
62
+ "@conveno/adapter-opencode": "0.2.0-rc.10",
63
+ "@conveno/brand": "0.2.0-rc.10",
64
+ "@conveno/client": "0.2.0-rc.10",
65
+ "@conveno/core": "0.2.0-rc.10",
66
+ "@conveno/daemon": "0.2.0-rc.10",
67
+ "@conveno/mcp": "0.2.0-rc.10",
68
+ "@conveno/protocol": "0.2.0-rc.10",
69
+ "@types/react": "19.3.0",
70
+ "ink-testing-library": "4.0.0"
58
71
  },
59
72
  "scripts": {
60
73
  "build": "tsdown",
61
74
  "typecheck": "tsc -p tsconfig.json",
62
- "test": "vitest run"
75
+ "test": "vitest run",
76
+ "kit-preview": "tsdown -c false scripts/kit-preview.tsx -d node_modules/.kit-preview --platform node --target node24 --no-dts --clean && node node_modules/.kit-preview/kit-preview.js",
77
+ "onboarding-preview": "tsdown -c false scripts/onboarding-preview.tsx -d node_modules/.onboarding-preview --platform node --target node24 --no-dts --clean && node node_modules/.onboarding-preview/onboarding-preview.js",
78
+ "home-preview": "tsdown -c false scripts/home-preview.tsx -d node_modules/.home-preview --platform node --target node24 --no-dts --clean && node node_modules/.home-preview/home-preview.js"
63
79
  }
64
80
  }