@conveno/cli 0.2.0-rc.5 → 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.
- package/README.md +22 -30
- package/dist/acp-9pRRszwU.js +82 -0
- package/dist/agy-relay-C-nqvieJ.js +137 -0
- package/dist/args-C7Agak9f.js +321 -0
- package/dist/bin.js +2 -2
- package/dist/{ctx-CDLE-2f2.js → ctx-tYftvhz_.js} +2 -3
- package/dist/daemon.js +410 -1423
- package/dist/daemonError-DNAKEyRT.js +66 -0
- package/dist/{dist-TrWRppjR.js → dist-D2hMvcZu.js} +592 -1216
- package/dist/dist-D9Gu-mQm.js +547 -0
- package/dist/dist-DOGlDbRb.js +504 -0
- package/dist/{dist-BPPOKmbH.js → dist-DOKVrSIw.js} +39 -148
- package/dist/dist-Dd31Fg0h.js +671 -0
- package/dist/{dist-CEJ2-wxh.js → dist-ftx5RNCp.js} +4 -17
- package/dist/{dist-E3XvoT1Q.js → dist-iFaY42Bs.js} +1 -1
- package/dist/{doctor-CzIGTeNT.js → doctor-BYa-MApu.js} +109 -102
- package/dist/fmt-C2SsP5Y0.js +96 -0
- package/dist/{hook-CLB_muZS.js → hook-CQeSn-w4.js} +7 -5
- package/dist/hook-entry-BXmSN--S.js +2490 -0
- package/dist/hook-entry-CgiSN-Oj.js +1 -0
- package/dist/main-seh-HPZO.js +971 -0
- package/dist/pick-DoyocW55.js +9 -0
- package/dist/{run-CYH0CRbp.js → run-B-WfNtCX.js} +627 -1998
- package/dist/{runtime-B1Pb9Qqg.js → runtime-Bnjh9BQ8.js} +119 -210
- package/dist/{dist-C8JRuLiZ.js → toml-patch-DGzVRdd1.js} +20 -1890
- package/dist/watch-Dr2RdyGo.js +185 -0
- package/package.json +15 -15
- package/dist/acp-BD7Oaerg.js +0 -142
- package/dist/args-BRB8QEQM.js +0 -554
- package/dist/dist-DcmKjrmu.js +0 -271
- package/dist/hook-entry-BlvSoNMm.js +0 -1289
- package/dist/hook-entry-CRDh36pe.js +0 -1
- package/dist/main-CsCsyq2G.js +0 -1645
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { n as isOneShotGrok } from "./dist-Dd31Fg0h.js";
|
|
2
|
+
import { Ft as senderOf, Nt as runWaker, X as isFromOwner, wt as renderBody } from "./dist-D2hMvcZu.js";
|
|
3
|
+
import { n as connectOpts } from "./ctx-tYftvhz_.js";
|
|
4
|
+
import { t as daemonProblem } from "./daemonError-DNAKEyRT.js";
|
|
5
|
+
import { t as findSession } from "./pick-DoyocW55.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.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.7",
|
|
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.
|
|
56
|
-
"@conveno/adapter-antigravity": "0.2.0-rc.
|
|
57
|
-
"@conveno/adapter-claude": "0.2.0-rc.
|
|
58
|
-
"@conveno/adapter-codex": "0.2.0-rc.
|
|
59
|
-
"@conveno/adapter-copilot": "0.2.0-rc.
|
|
60
|
-
"@conveno/adapter-cursor": "0.2.0-rc.
|
|
61
|
-
"@conveno/adapter-grok": "0.2.0-rc.
|
|
62
|
-
"@conveno/adapter-opencode": "0.2.0-rc.
|
|
63
|
-
"@conveno/brand": "0.2.0-rc.
|
|
64
|
-
"@conveno/client": "0.2.0-rc.
|
|
65
|
-
"@conveno/core": "0.2.0-rc.
|
|
66
|
-
"@conveno/daemon": "0.2.0-rc.
|
|
67
|
-
"@conveno/mcp": "0.2.0-rc.
|
|
68
|
-
"@conveno/protocol": "0.2.0-rc.
|
|
55
|
+
"@conveno/acp": "0.2.0-rc.7",
|
|
56
|
+
"@conveno/adapter-antigravity": "0.2.0-rc.7",
|
|
57
|
+
"@conveno/adapter-claude": "0.2.0-rc.7",
|
|
58
|
+
"@conveno/adapter-codex": "0.2.0-rc.7",
|
|
59
|
+
"@conveno/adapter-copilot": "0.2.0-rc.7",
|
|
60
|
+
"@conveno/adapter-cursor": "0.2.0-rc.7",
|
|
61
|
+
"@conveno/adapter-grok": "0.2.0-rc.7",
|
|
62
|
+
"@conveno/adapter-opencode": "0.2.0-rc.7",
|
|
63
|
+
"@conveno/brand": "0.2.0-rc.7",
|
|
64
|
+
"@conveno/client": "0.2.0-rc.7",
|
|
65
|
+
"@conveno/core": "0.2.0-rc.7",
|
|
66
|
+
"@conveno/daemon": "0.2.0-rc.7",
|
|
67
|
+
"@conveno/mcp": "0.2.0-rc.7",
|
|
68
|
+
"@conveno/protocol": "0.2.0-rc.7",
|
|
69
69
|
"@types/react": "19.3.0",
|
|
70
70
|
"ink-testing-library": "4.0.0"
|
|
71
71
|
},
|
package/dist/acp-BD7Oaerg.js
DELETED
|
@@ -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 };
|