@conveno/cli 0.2.0-rc.1 → 0.2.0-rc.11
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 +26 -29
- package/dist/acp-BOSDOzU7.js +82 -0
- package/dist/agy-relay-BUo9uRng.js +137 -0
- package/dist/args-C1eX8Ixk.js +361 -0
- package/dist/bin.js +4 -4
- package/dist/ctx-tYftvhz_.js +17 -0
- package/dist/daemon.js +490 -1153
- package/dist/daemonError-DraepwsB.js +66 -0
- package/dist/dist-BRjg9CLd.js +731 -0
- package/dist/dist-DEjU_KXC.js +969 -0
- package/dist/{dist-CWvQqhPj.js → dist-Dg2IY9OA.js} +1 -1
- package/dist/dist-KWlFKO7H.js +645 -0
- package/dist/{acp-BlKK0v-B.js → dist-Rdj5ogAX.js} +41 -288
- package/dist/dist-Y0JDSJP_.js +667 -0
- package/dist/{dist-DsRTUePN.js → dist-n6XMTlyN.js} +6 -14
- package/dist/{dist-_qrCNXUP.js → dist-qONHJRJk.js} +817 -1289
- package/dist/fmt-C2SsP5Y0.js +96 -0
- package/dist/{hook-bfp9_AVT.js → hook-CDF1A8AY.js} +31 -22
- package/dist/hook-entry-BYvXWDJv.js +1320 -0
- package/dist/hook-entry-D2CAJsq-.js +1 -0
- package/dist/main-EqfI0btx.js +650 -0
- package/dist/pick-B-axJvgf.js +9 -0
- package/dist/run-CtGfzzwB.js +5568 -0
- package/dist/runtime-BDNmkbsS.js +770 -0
- package/dist/{dist-D8gPpZKN.js → toml-patch-DGzVRdd1.js} +20 -1889
- package/dist/{main-sIWDc4jt.js → uninstall-Blt-KHI5.js} +628 -1495
- package/dist/watch-CuZ7jPVd.js +185 -0
- package/package.json +21 -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
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// src/fmt.ts
|
|
2
|
+
/** Shorten the home directory to `~`. */
|
|
3
|
+
function tilde(path, home) {
|
|
4
|
+
if (path === home) return "~";
|
|
5
|
+
for (const sep of ["/", "\\"]) if (path.startsWith(home + sep)) return `~${sep}${path.slice(home.length + 1)}`;
|
|
6
|
+
return path;
|
|
7
|
+
}
|
|
8
|
+
/** Length of a string without ANSI escapes. */
|
|
9
|
+
const visibleLength = (s) => s.replace(/\u001b\[[0-9;]*m/g, "").length;
|
|
10
|
+
const padEnd = (s, width) => s + " ".repeat(Math.max(0, width - visibleLength(s)));
|
|
11
|
+
/** Pad every column to its widest cell. The last column is left unpadded. */
|
|
12
|
+
function columns(rows, gap = 2) {
|
|
13
|
+
const widths = [];
|
|
14
|
+
for (const row of rows) row.forEach((cell, i) => {
|
|
15
|
+
widths[i] = Math.max(widths[i] ?? 0, visibleLength(cell));
|
|
16
|
+
});
|
|
17
|
+
return rows.map((row) => row.map((cell, i) => i === row.length - 1 ? cell : padEnd(cell, (widths[i] ?? 0) + gap)).join("").trimEnd());
|
|
18
|
+
}
|
|
19
|
+
const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
20
|
+
const pad2 = (n) => String(n).padStart(2, "0");
|
|
21
|
+
/** `2026-11-27 14:02:11` in the machine's local time. */
|
|
22
|
+
function localStamp(iso) {
|
|
23
|
+
const d = new Date(iso);
|
|
24
|
+
if (Number.isNaN(d.getTime())) return iso;
|
|
25
|
+
return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())} ${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`;
|
|
26
|
+
}
|
|
27
|
+
/** `1.2s` between two times. */
|
|
28
|
+
const seconds = (from, to) => `${(Math.max(0, to.getTime() - from.getTime()) / 1e3).toFixed(1)}s`;
|
|
29
|
+
function levenshtein(a, b) {
|
|
30
|
+
let prev = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
31
|
+
for (let i = 1; i <= a.length; i++) {
|
|
32
|
+
const row = [i];
|
|
33
|
+
for (let j = 1; j <= b.length; j++) row[j] = Math.min(row[j - 1] + 1, prev[j] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
34
|
+
prev = row;
|
|
35
|
+
}
|
|
36
|
+
return prev[b.length];
|
|
37
|
+
}
|
|
38
|
+
/** The closest candidate within two edits, or undefined. */
|
|
39
|
+
function closest(word, candidates) {
|
|
40
|
+
let best;
|
|
41
|
+
let bestDistance = 3;
|
|
42
|
+
for (const c of candidates) {
|
|
43
|
+
const d = levenshtein(word.toLowerCase(), c.toLowerCase());
|
|
44
|
+
if (d < bestDistance) {
|
|
45
|
+
best = c;
|
|
46
|
+
bestDistance = d;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return best;
|
|
50
|
+
}
|
|
51
|
+
/** Error block: what happened, detail, fix, then `exit N · ref e_code`. Goes to stderr. */
|
|
52
|
+
function errorBlock(theme, f) {
|
|
53
|
+
const lines = [`${theme.status("error")} ${f.what}`];
|
|
54
|
+
for (const d of f.detail ?? []) lines.push(` ${d}`);
|
|
55
|
+
if (f.fix) lines.push(` ${theme.paint("quiet", "fix")} ${f.fix}`);
|
|
56
|
+
if (f.didYouMean) lines.push(` ${f.didYouMean}`);
|
|
57
|
+
lines.push("", theme.paint("quiet", `exit ${f.exit} ${theme.glyph("bullet")} ref ${f.ref}`));
|
|
58
|
+
return `${lines.join("\n")}\n`;
|
|
59
|
+
}
|
|
60
|
+
/** Print an error block on stderr and return its exit code. */
|
|
61
|
+
function fail(ctx, f) {
|
|
62
|
+
ctx.err(errorBlock(ctx.theme, f));
|
|
63
|
+
return f.exit;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A message safe to show a user. Errors raised by Node get a plain sentence; errors we wrote
|
|
67
|
+
* pass through. Never a stack trace or a bare `EACCES: ...`.
|
|
68
|
+
*/
|
|
69
|
+
function plainError(e) {
|
|
70
|
+
if (!(e instanceof Error)) return "Something unexpected stopped the command.";
|
|
71
|
+
const code = e.code;
|
|
72
|
+
const path = e.path;
|
|
73
|
+
const named = path ?? "a file it needs";
|
|
74
|
+
switch (code) {
|
|
75
|
+
case "EACCES":
|
|
76
|
+
case "EPERM": return `Conveno has no permission to use ${named}.`;
|
|
77
|
+
case "ENOENT": return `${path ?? "A file or folder"} does not exist.`;
|
|
78
|
+
case "ENOSPC": return "The disk is full.";
|
|
79
|
+
case "EROFS": return `${path ?? "The location"} is read-only.`;
|
|
80
|
+
case "EISDIR":
|
|
81
|
+
case "ENOTDIR": return `${path ?? "A path"} is not the kind of entry Conveno expected.`;
|
|
82
|
+
case "EMFILE": return "Too many files are open.";
|
|
83
|
+
}
|
|
84
|
+
if (typeof code === "string" && /^E[A-Z0-9]+$/.test(code)) return `The system refused an operation (${code}).`;
|
|
85
|
+
if (e instanceof TypeError || e instanceof RangeError || e instanceof ReferenceError) return "Conveno hit an internal error.";
|
|
86
|
+
return e.message.replace(/,? or enable autoStart\.?/i, ".").replace(/No session holds the orchestrator role/, "No session is the lead yet").replace(/Run orchestrate in the session you want to use/, "Run conveno lead <session>").replace(/ Run list_sessions to see who is available\./, "").replace(/^No Conveno daemon is listening at /, "Conveno's background service is not listening at ").replace(/\.\.$/, ".");
|
|
87
|
+
}
|
|
88
|
+
function warnBlock(theme, what, fix, why) {
|
|
89
|
+
const lines = [`${theme.status("warn")} ${what}`];
|
|
90
|
+
if (why) lines.push(` ${theme.paint("quiet", "why")} ${why}`);
|
|
91
|
+
lines.push(` ${theme.paint("quiet", "fix")} ${fix}`);
|
|
92
|
+
return `${lines.join("\n")}\n`;
|
|
93
|
+
}
|
|
94
|
+
/** A command to run, in bold ink. */
|
|
95
|
+
const cmd = (theme, text) => theme.bold(text);
|
|
96
|
+
export { fail as a, plural as c, warnBlock as d, errorBlock as i, seconds as l, cmd as n, localStamp as o, columns as r, plainError as s, closest as t, tilde as u };
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const adapterEnv = (ctx, opts = {}) => ({
|
|
4
|
-
home: ctx.home,
|
|
5
|
-
platform: ctx.platform,
|
|
6
|
-
cwd: ctx.cwd,
|
|
7
|
-
exec: ctx.exec,
|
|
8
|
-
conveno: ctx.conveno,
|
|
9
|
-
env: ctx.env,
|
|
10
|
-
...opts.permissionRelay ? { permissionRelay: true } : {}
|
|
11
|
-
});
|
|
12
|
-
const connectOpts = (ctx, autoStart) => ({
|
|
13
|
-
kind: "cli",
|
|
14
|
-
dataDir: ctx.dataDir,
|
|
15
|
-
autoStart,
|
|
16
|
-
...ctx.socketPath ? { socketPath: ctx.socketPath } : {},
|
|
17
|
-
...ctx.daemonEntry ? { daemonEntry: ctx.daemonEntry } : {}
|
|
18
|
-
});
|
|
1
|
+
import { appendFileSync } from "node:fs";
|
|
2
|
+
import { n as connectOpts } from "./ctx-tYftvhz_.js";
|
|
19
3
|
// src/hook.ts
|
|
20
4
|
/**
|
|
21
5
|
* Time allowed for the hook's own process-table query. Only the fallback runs it: the usual way to
|
|
@@ -48,6 +32,18 @@ async function findHostPid(ctx, client, cli, local) {
|
|
|
48
32
|
return (await local()).hostPid;
|
|
49
33
|
}
|
|
50
34
|
/**
|
|
35
|
+
* One line of the timing log: `<iso time> cli=<cli> event=<event> ms=<n> proc_ms=<n> timeout=<yes|no>`.
|
|
36
|
+
* `ms` is the time inside `runHook`; `proc_ms` also counts process start-up (what the CLI's own
|
|
37
|
+
* hook limit sees). `timeout=yes` means the hook ran past its limit and was cut off.
|
|
38
|
+
*/
|
|
39
|
+
function timingLine(cli, event, ms, procMs, timedOut) {
|
|
40
|
+
return `${(/* @__PURE__ */ new Date()).toISOString()} cli=${cli} event=${event} ms=${ms}${procMs === void 0 ? "" : ` proc_ms=${procMs}`} timeout=${timedOut ? "yes" : "no"}\n`;
|
|
41
|
+
}
|
|
42
|
+
/** After a timeout, the hook gets this many more timeouts' worth of time to finish recording. */
|
|
43
|
+
const FINISH_GRACE_FACTOR = 2;
|
|
44
|
+
/** How long before the hook's timeout its messages count as too late to print. */
|
|
45
|
+
const DEADLINE_MARGIN_MS = 300;
|
|
46
|
+
/**
|
|
51
47
|
* `conveno hook <cli> <event>`: reads the CLI's hook JSON on stdin and prints what the adapter
|
|
52
48
|
* returns. Never starts a daemon. A hook that fails or stalls must not hold the CLI up, so an
|
|
53
49
|
* ordinary hook gives up after the context's timeout (2 s), never writes to stderr and exits 0.
|
|
@@ -62,6 +58,9 @@ async function runHook(ctx, argv) {
|
|
|
62
58
|
const adapter = ctx.adapters.find((a) => a.cli === cli);
|
|
63
59
|
if (!adapter || !event) return 0;
|
|
64
60
|
const listener = adapter.listenEvents?.includes(event) === true;
|
|
61
|
+
const deadline = listener ? void 0 : Date.now() + ctx.hookTimeoutMs - DEADLINE_MARGIN_MS;
|
|
62
|
+
const t0 = ctx.timingLog && !listener ? Date.now() : void 0;
|
|
63
|
+
let timedOut = false;
|
|
65
64
|
let client;
|
|
66
65
|
let timer;
|
|
67
66
|
const early = ctx.hostLookup ? void 0 : ctx.ancestry(HOOK_ANCESTRY_TIMEOUT_MS);
|
|
@@ -82,24 +81,34 @@ async function runHook(ctx, argv) {
|
|
|
82
81
|
client,
|
|
83
82
|
hostPid,
|
|
84
83
|
cli: adapter.cli,
|
|
85
|
-
isAlive: ctx.isAlive
|
|
84
|
+
isAlive: ctx.isAlive,
|
|
85
|
+
...deadline === void 0 ? {} : { deadline }
|
|
86
86
|
});
|
|
87
87
|
})();
|
|
88
|
-
const budget = isPermissionHook(cli, event) ? ctx.permissionHookTimeoutMs ?? 9e4 : ctx.hookTimeoutMs;
|
|
89
88
|
const timeout = listener ? new Promise(() => void 0) : new Promise((resolve) => {
|
|
90
|
-
timer = setTimeout(() =>
|
|
89
|
+
timer = setTimeout(() => {
|
|
90
|
+
timedOut = true;
|
|
91
|
+
resolve(NOTHING);
|
|
92
|
+
}, ctx.hookTimeoutMs);
|
|
91
93
|
});
|
|
92
94
|
let code = 0;
|
|
93
95
|
try {
|
|
94
96
|
const out = await Promise.race([work, timeout]);
|
|
97
|
+
if (out === NOTHING && !listener) await Promise.race([work.catch(() => void 0), new Promise((r) => setTimeout(r, ctx.hookTimeoutMs * FINISH_GRACE_FACTOR))]);
|
|
95
98
|
if (out.stdout) ctx.out(out.stdout.endsWith("\n") ? out.stdout : `${out.stdout}\n`);
|
|
96
99
|
if (listener && out.stderr) ctx.err(out.stderr.endsWith("\n") ? out.stderr : `${out.stderr}\n`);
|
|
97
100
|
if (listener) code = out.exitCode;
|
|
98
101
|
} catch {} finally {
|
|
102
|
+
if (t0 !== void 0 && ctx.timingLog) {
|
|
103
|
+
const up = ctx.uptimeMs?.();
|
|
104
|
+
try {
|
|
105
|
+
appendFileSync(ctx.timingLog, timingLine(adapter.cli, event, Date.now() - t0, up === void 0 ? void 0 : Math.round(up), timedOut));
|
|
106
|
+
} catch {}
|
|
107
|
+
}
|
|
99
108
|
if (timer) clearTimeout(timer);
|
|
100
109
|
work.catch(() => void 0);
|
|
101
110
|
await Promise.race([client?.close().catch(() => void 0), new Promise((r) => setTimeout(r, 100))]);
|
|
102
111
|
}
|
|
103
112
|
return code;
|
|
104
113
|
}
|
|
105
|
-
export {
|
|
114
|
+
export { runHook as t };
|