@conveno/cli 0.2.0-rc.8 → 0.2.0
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 +3 -5
- package/dist/{acp-YHhVx0Ya.js → acp-BUddItzP.js} +39 -7
- package/dist/{agy-relay-BS2NeFlh.js → agy-relay-BZ3d_-FS.js} +4 -2
- package/dist/{args-CGL-AmNd.js → args-CtyKPZuN.js} +29 -8
- package/dist/bin.js +16 -2
- package/dist/daemon.js +4 -3139
- package/dist/{daemonError-DJ-P55nH.js → daemonError-CDgEtvy7.js} +1 -1
- package/dist/dist-BNhTPp5p.js +4509 -0
- package/dist/{dist-BRjg9CLd.js → dist-BOwFdixw.js} +23 -50
- package/dist/{dist-CcoTmwrf.js → dist-CFsDqevs.js} +94 -56
- package/dist/dist-CNdqmI3E.js +1065 -0
- package/dist/{dist-BBdba94T.js → dist-CSSvrcKr.js} +1752 -708
- package/dist/{dist-B6Sm0MRT.js → dist-D6Xoip5W.js} +203 -62
- package/dist/{dist-WTkKRM39.js → dist-DAVtixeC.js} +19 -5
- package/dist/dist-DTMnNySx.js +989 -0
- package/dist/hook-BA-tI6Oc.js +208 -0
- package/dist/hook-entry-BwzBtAnd.js +1346 -0
- package/dist/hook-entry-Cgt5ZH1s.js +1 -0
- package/dist/{main-DrzHsV5y.js → main-kKnLA7Hj.js} +58 -21
- package/dist/{pick-Bi1yJDh6.js → pick-BsMvXuDo.js} +1 -1
- package/dist/run-PQBzaHv1.js +8193 -0
- package/dist/{runtime-Db_YT5Xg.js → runtime-0FMqklYn.js} +233 -122
- package/dist/{uninstall-D9rW_j7H.js → uninstall-DcxkIDpk.js} +556 -82
- package/dist/{watch-BrTWYf3Y.js → watch-BIepRTXJ.js} +29 -7
- package/package.json +14 -15
- package/dist/dist-B1EVHdIM.js +0 -504
- package/dist/dist-BlWWt5gx.js +0 -624
- package/dist/dist-C6cMQ00I.js +0 -793
- package/dist/hook-DxjJDCjz.js +0 -94
- package/dist/hook-entry-CrpZz5QW.js +0 -1
- package/dist/hook-entry-pHJioNgN.js +0 -2494
- package/dist/run-C32oP2c_.js +0 -5550
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as compatStatus, Et as logoutAccount, Fn as workerUnansweredOf, Gt as planSpawn, Ht as pinnedAdapter, K as dataPaths, Kt as pollDeviceCode, Nn as workerAccessOf, Pn as workerAskTimeoutOf, Rn as writeSettings, S as adapterNpxCommand, Tt as loginAccountApi, V as completeLogin, Yt as readAccountTokens, _n as signedInAccountApi, b as acpOverrideVar, h as WORKER_ACCESS, it as findOnPath, ln as resolveAcpProgram, nt as fetchAccountStatus, on as requestDeviceCode, p as SPAWN_TABLE, t as AccountError, tn as readSettings, x as adapterInstallCommand, zn as CLI_KINDS } from "./dist-CSSvrcKr.js";
|
|
2
2
|
import { a as fail, c as plural, d as warnBlock, i as errorBlock, l as seconds, n as cmd, o as localStamp, r as columns, s as plainError, t as closest, u as tilde } from "./fmt-C2SsP5Y0.js";
|
|
3
|
-
import { a as parseFlags, n as COMMANDS } from "./args-
|
|
3
|
+
import { a as parseFlags, n as COMMANDS } from "./args-CtyKPZuN.js";
|
|
4
4
|
import { n as connectOpts, t as adapterEnv } from "./ctx-tYftvhz_.js";
|
|
5
|
-
import { t as daemonProblem } from "./daemonError-
|
|
6
|
-
import { basename, dirname, join } from "node:path";
|
|
7
|
-
import { spawn } from "node:child_process";
|
|
5
|
+
import { t as daemonProblem } from "./daemonError-CDgEtvy7.js";
|
|
6
|
+
import { basename, dirname, isAbsolute, join } from "node:path";
|
|
7
|
+
import { execFile, spawn } from "node:child_process";
|
|
8
8
|
import { access, chmod, mkdir, open, readFile, readdir, realpath, rename as rename$1, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
9
9
|
import { createHash, randomBytes } from "node:crypto";
|
|
10
10
|
// src/account.ts
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
const tokenFile = (ctx) => dataPaths(ctx.platform, ctx.dataDir).account;
|
|
12
|
+
/** The account server of the saved login, the one its tokens may be sent to. */
|
|
13
|
+
const accountServer = (ctx) => signedInAccountApi(tokenFile(ctx), ctx.env);
|
|
14
|
+
const accountIo = (ctx, io, apiBase = accountServer(ctx)) => ({
|
|
15
|
+
apiBase,
|
|
13
16
|
now: () => ctx.now().getTime(),
|
|
14
17
|
...io.fetch ? { fetch: io.fetch } : {}
|
|
15
18
|
});
|
|
16
|
-
const tokenFile = (ctx) => dataPaths(ctx.platform, ctx.dataDir).account;
|
|
17
19
|
/** Show the code as ABCD-1234, the way the page asks for it. */
|
|
18
20
|
const showCode = (code) => /^[A-Za-z0-9]{8}$/.test(code) ? `${code.slice(0, 4)}-${code.slice(4)}` : code;
|
|
19
21
|
/** Open a page with the system's own opener. No shell is involved, so the URL is one argument. */
|
|
@@ -65,7 +67,7 @@ async function runLogin(ctx, argv, io = {}) {
|
|
|
65
67
|
const parsed = parseFlags(ctx, spec, argv);
|
|
66
68
|
if (typeof parsed === "number") return parsed;
|
|
67
69
|
const t = ctx.theme;
|
|
68
|
-
const aio = accountIo(ctx, io);
|
|
70
|
+
const aio = accountIo(ctx, io, loginAccountApi(ctx.env));
|
|
69
71
|
try {
|
|
70
72
|
const code = await requestDeviceCode(aio);
|
|
71
73
|
ctx.err([
|
|
@@ -98,13 +100,14 @@ async function runLogout(ctx, argv, io = {}) {
|
|
|
98
100
|
if (!spec) return 2;
|
|
99
101
|
const parsed = parseFlags(ctx, spec, argv);
|
|
100
102
|
if (typeof parsed === "number") return parsed;
|
|
101
|
-
const
|
|
103
|
+
const server = accountServer(ctx);
|
|
104
|
+
const r = await logoutAccount(tokenFile(ctx), accountIo(ctx, io, server));
|
|
102
105
|
if (!r.hadLogin) {
|
|
103
106
|
ctx.out("You were not signed in.\n");
|
|
104
107
|
return 0;
|
|
105
108
|
}
|
|
106
109
|
ctx.out(`${ctx.theme.status("ok")} Signed out.\n`);
|
|
107
|
-
if (!r.revoked) ctx.err(`${ctx.theme.status("warn")} The account server could not be reached, so the login was only removed from this machine. Sign out everywhere at
|
|
110
|
+
if (!r.revoked) ctx.err(`${ctx.theme.status("warn")} The account server could not be reached, so the login was only removed from this machine. Sign out everywhere at ${server}/account.\n`);
|
|
108
111
|
return 0;
|
|
109
112
|
}
|
|
110
113
|
/** `conveno account`: plan and trial. */
|
|
@@ -123,7 +126,8 @@ async function runAccount(ctx, argv, io = {}) {
|
|
|
123
126
|
ref: "e_account_not_logged_in"
|
|
124
127
|
});
|
|
125
128
|
try {
|
|
126
|
-
const
|
|
129
|
+
const server = accountServer(ctx);
|
|
130
|
+
const s = await fetchAccountStatus(tokens.refreshToken, accountIo(ctx, io, server));
|
|
127
131
|
const rows = [["Account", s.user.name], ["Plan", planLine(ctx, s)]];
|
|
128
132
|
if (s.status === "trialing" && s.trialEnd !== null) {
|
|
129
133
|
const left = s.trialDaysLeft ?? 0;
|
|
@@ -132,14 +136,16 @@ async function runAccount(ctx, argv, io = {}) {
|
|
|
132
136
|
if (s.paymentFailed) rows.push(["Billing", t.paint("warn", "last payment failed")]);
|
|
133
137
|
const width = Math.max(...rows.map(([k]) => k.length)) + 2;
|
|
134
138
|
const lines = rows.map(([k, v]) => `${t.paint("quiet", k.padEnd(width))}${v}`);
|
|
135
|
-
if (s.plan === "free") lines.push("", `Upgrade or start the 14-day trial at ${t.bold(
|
|
136
|
-
else if (s.status === "trialing") lines.push("",
|
|
139
|
+
if (s.plan === "free") lines.push("", `Upgrade or start the 14-day trial at ${t.bold(`${server}/account`)}.`);
|
|
140
|
+
else if (s.status === "trialing") lines.push("", `No card is on file. Add one at ${server}/account to keep Pro.`);
|
|
137
141
|
ctx.out(`${lines.join("\n")}\n`);
|
|
138
142
|
return 0;
|
|
139
143
|
} catch (e) {
|
|
140
144
|
return accountFailure(ctx, e, "Could not read your account");
|
|
141
145
|
}
|
|
142
146
|
}
|
|
147
|
+
// src/version.ts
|
|
148
|
+
const VERSION = "0.2.0";
|
|
143
149
|
// src/daemon.ts
|
|
144
150
|
async function lockPid(ctx) {
|
|
145
151
|
try {
|
|
@@ -276,6 +282,29 @@ async function stopDaemonIfRunning(ctx) {
|
|
|
276
282
|
}
|
|
277
283
|
return stopDaemon(ctx, true);
|
|
278
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* For the commands a person runs (`conveno`, `conveno setup`): when a daemon is running from a
|
|
287
|
+
* different version than this CLI (an upgrade left the old one up), stop it so the next connect
|
|
288
|
+
* starts this version's. Says nothing itself; the returned line is for the setup details. Never
|
|
289
|
+
* starts a daemon, and never throws. MCP servers and hooks must not call this: an old MCP would
|
|
290
|
+
* take the daemon back to its own version.
|
|
291
|
+
*/
|
|
292
|
+
async function replaceStaleDaemon(ctx) {
|
|
293
|
+
let running;
|
|
294
|
+
try {
|
|
295
|
+
const c = await ctx.connect(connectOpts(ctx, false));
|
|
296
|
+
running = c.daemonVersion;
|
|
297
|
+
await c.close().catch(() => void 0);
|
|
298
|
+
} catch {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
if (running === void 0 || running === VERSION) return null;
|
|
302
|
+
return await stopDaemon({
|
|
303
|
+
...ctx,
|
|
304
|
+
out: () => void 0,
|
|
305
|
+
err: () => void 0
|
|
306
|
+
}, true).catch(() => 1) === 0 ? `Restarted the background service: it was ${running}, now ${VERSION}.` : `The background service is still ${running} (this is ${VERSION}). Run conveno daemon stop.`;
|
|
307
|
+
}
|
|
279
308
|
const SUBCOMMANDS = [
|
|
280
309
|
"start",
|
|
281
310
|
"stop",
|
|
@@ -370,6 +399,7 @@ function listLine(ctx, list) {
|
|
|
370
399
|
function conflictBlock(ctx, c) {
|
|
371
400
|
if (!c) return "";
|
|
372
401
|
const t = ctx.theme;
|
|
402
|
+
const account = signedInAccountApi(dataPaths(ctx.platform, ctx.dataDir).account, ctx.env);
|
|
373
403
|
const head = (l) => l ? `${l.head.slice(0, 16)} ${t.paint("quiet", `(${plural(l.length, "entry", "entries")})`)}` : "none";
|
|
374
404
|
const why = c.kind === "split_view" ? [` ${c.peer?.name ?? "Another device"} signed a message with a device list this device does not hold.`, " The relay may be showing your devices different lists, for example to hide a revocation."] : [" The relay holds a device list that this device's list is not part of.", " Someone changed the list in a way this device cannot follow, or the relay is lying."];
|
|
375
405
|
return `${[
|
|
@@ -386,7 +416,7 @@ function conflictBlock(ctx, c) {
|
|
|
386
416
|
" If it lists only devices you recognize, type the head it shows (the full 64 characters) here:",
|
|
387
417
|
` ${cmd(t, "conveno devices accept <head>")}. Then revoke any device you do not recognize.`,
|
|
388
418
|
" If no device you trust is left, or you did not reset the devices yourself, reset them at",
|
|
389
|
-
`
|
|
419
|
+
` ${account}/account. After a reset, run ${cmd(t, "conveno devices reset")} here and pair again.`,
|
|
390
420
|
""
|
|
391
421
|
].join("\n")}\n`;
|
|
392
422
|
}
|
|
@@ -613,7 +643,8 @@ const STATE_TEXT = {
|
|
|
613
643
|
connecting: "connecting",
|
|
614
644
|
connected: "connected",
|
|
615
645
|
disconnected: "disconnected, retrying",
|
|
616
|
-
revoked: "off, this device was revoked"
|
|
646
|
+
revoked: "off, this device was revoked",
|
|
647
|
+
upgrade_required: "off, Conveno needs an update"
|
|
617
648
|
};
|
|
618
649
|
async function runRelay(ctx, argv) {
|
|
619
650
|
const t = ctx.theme;
|
|
@@ -762,6 +793,93 @@ ${missing.map((m) => ` ${pinnedAdapter(m.pkg) ?? m.pkg}\n`).join("")}`);
|
|
|
762
793
|
printManual(ctx, missing);
|
|
763
794
|
}
|
|
764
795
|
}
|
|
796
|
+
// src/acp-warm.ts
|
|
797
|
+
/** Longest a download may take. */
|
|
798
|
+
const WARM_TIMEOUT_MS = 3e5;
|
|
799
|
+
function realWarmRunner(ctx) {
|
|
800
|
+
return { run: (file, args, timeoutMs) => {
|
|
801
|
+
const plan = planSpawn(file, args);
|
|
802
|
+
return new Promise((resolve) => {
|
|
803
|
+
execFile(plan.file, plan.args, {
|
|
804
|
+
timeout: timeoutMs,
|
|
805
|
+
windowsHide: true,
|
|
806
|
+
env: {
|
|
807
|
+
...ctx.env,
|
|
808
|
+
npm_config_update_notifier: "false"
|
|
809
|
+
},
|
|
810
|
+
maxBuffer: 16777216,
|
|
811
|
+
...plan.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
|
|
812
|
+
}, (err) => {
|
|
813
|
+
if (!err) return resolve(0);
|
|
814
|
+
const code = err.code;
|
|
815
|
+
resolve(typeof code === "number" ? code : null);
|
|
816
|
+
});
|
|
817
|
+
});
|
|
818
|
+
} };
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* The pinned `<pkg>@<version>` of every adapter these tools need that is not on PATH (nor
|
|
822
|
+
* overridden), when the person allowed on-demand adapters. Empty otherwise.
|
|
823
|
+
*/
|
|
824
|
+
function adaptersToWarm(ctx, clis) {
|
|
825
|
+
if (!(readSettings(dataPaths(ctx.platform, ctx.dataDir).settings).acpAdapterNpx === true)) return [];
|
|
826
|
+
const out = [];
|
|
827
|
+
for (const cli of clis) {
|
|
828
|
+
const acp = SPAWN_TABLE[cli]?.acp;
|
|
829
|
+
if (!acp?.adapterPackage) continue;
|
|
830
|
+
const found = resolveAcpProgram(cli, acp, {
|
|
831
|
+
env: ctx.env,
|
|
832
|
+
which: (n) => findOnPath(n, ctx.env, ctx.platform),
|
|
833
|
+
npxConsent: false
|
|
834
|
+
});
|
|
835
|
+
const pinned = pinnedAdapter(acp.adapterPackage);
|
|
836
|
+
if (!found.ok && pinned && !out.includes(pinned)) out.push(pinned);
|
|
837
|
+
}
|
|
838
|
+
return out;
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Download the adapters now. `onStart` is called once, before the first download, and only when
|
|
842
|
+
* there is something to download. Never throws.
|
|
843
|
+
*/
|
|
844
|
+
async function warmAcpAdapters(ctx, clis, opts = {}) {
|
|
845
|
+
const packages = adaptersToWarm(ctx, clis);
|
|
846
|
+
if (packages.length === 0) return { status: "none" };
|
|
847
|
+
opts.onStart?.();
|
|
848
|
+
const runner = opts.runner ?? ctx.warmRunner ?? realWarmRunner(ctx);
|
|
849
|
+
const failed = [];
|
|
850
|
+
for (const pkg of packages) {
|
|
851
|
+
const args = [
|
|
852
|
+
"exec",
|
|
853
|
+
"--yes",
|
|
854
|
+
`--package=${pkg}`,
|
|
855
|
+
"--",
|
|
856
|
+
"node",
|
|
857
|
+
"-e",
|
|
858
|
+
"0"
|
|
859
|
+
];
|
|
860
|
+
opts.onLine?.(`$ npm ${args.join(" ")}`);
|
|
861
|
+
let code = null;
|
|
862
|
+
try {
|
|
863
|
+
code = await runner.run("npm", args, opts.timeoutMs ?? WARM_TIMEOUT_MS);
|
|
864
|
+
} catch {
|
|
865
|
+
code = null;
|
|
866
|
+
}
|
|
867
|
+
if (code !== 0) {
|
|
868
|
+
failed.push(pkg);
|
|
869
|
+
opts.onLine?.(`Could not fetch ${pkg} now (${code === null ? "no answer" : `exit ${code}`}).`);
|
|
870
|
+
} else opts.onLine?.(`${pkg} is ready.`);
|
|
871
|
+
}
|
|
872
|
+
if (failed.length === 0) return {
|
|
873
|
+
status: "ready",
|
|
874
|
+
packages
|
|
875
|
+
};
|
|
876
|
+
return {
|
|
877
|
+
status: "failed",
|
|
878
|
+
packages,
|
|
879
|
+
failed,
|
|
880
|
+
reason: "It will download the first time a worker starts."
|
|
881
|
+
};
|
|
882
|
+
}
|
|
765
883
|
// src/diff.ts
|
|
766
884
|
const splitLines = (s) => {
|
|
767
885
|
if (s === "") return [];
|
|
@@ -964,14 +1082,14 @@ const realIo = {
|
|
|
964
1082
|
* compare it with the plan just before writing, and `applyChanges` restores every file from its
|
|
965
1083
|
* backup if any write fails. No temp file exists on this path, so none can be left behind.
|
|
966
1084
|
*/
|
|
967
|
-
async function writeAtomic(path, data, io = realIo) {
|
|
1085
|
+
async function writeAtomic(path, data, io = realIo, wantMode) {
|
|
968
1086
|
const target = await io.realpath(path).catch(() => path);
|
|
969
1087
|
await io.mkdir(dirname(target));
|
|
970
1088
|
if (io.platform === "win32") {
|
|
971
1089
|
await io.overwrite(target, data);
|
|
972
1090
|
return;
|
|
973
1091
|
}
|
|
974
|
-
const mode = await io.mode(target);
|
|
1092
|
+
const mode = wantMode ?? await io.mode(target);
|
|
975
1093
|
const tmp = join(dirname(target), `.${basename(target)}.conveno-${randomBytes(6).toString("hex")}.tmp`);
|
|
976
1094
|
try {
|
|
977
1095
|
await io.writeFile(tmp, data, mode ?? 420);
|
|
@@ -1035,7 +1153,8 @@ async function applyChanges(ctx, items, opts = {}) {
|
|
|
1035
1153
|
path: change.path,
|
|
1036
1154
|
backup,
|
|
1037
1155
|
description: change.description,
|
|
1038
|
-
...change.deleteFile ? {} : { afterSha256: sha256(change.after) }
|
|
1156
|
+
...change.deleteFile ? {} : { afterSha256: sha256(change.after) },
|
|
1157
|
+
...change.pruneEmptyDir === void 0 ? {} : { pruneEmptyDir: change.pruneEmptyDir }
|
|
1039
1158
|
});
|
|
1040
1159
|
}
|
|
1041
1160
|
const manifest = {
|
|
@@ -1068,12 +1187,8 @@ async function applyChanges(ctx, items, opts = {}) {
|
|
|
1068
1187
|
await currentIfUnchanged(change);
|
|
1069
1188
|
if (change.deleteFile) {
|
|
1070
1189
|
await io.rm(change.path);
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
if (!await rmdir(dir).then(() => true, () => false)) break;
|
|
1074
|
-
dir = dirname(dir);
|
|
1075
|
-
}
|
|
1076
|
-
} else await writeAtomic(change.path, change.after, io);
|
|
1190
|
+
if (change.pruneEmptyDir !== void 0) await pruneEmptyDirs(change.path, change.pruneEmptyDir);
|
|
1191
|
+
} else await writeAtomic(change.path, change.after, io, change.mode);
|
|
1077
1192
|
}
|
|
1078
1193
|
how.push({
|
|
1079
1194
|
cli,
|
|
@@ -1166,12 +1281,22 @@ async function previewRestore(manifests) {
|
|
|
1166
1281
|
}
|
|
1167
1282
|
return rows;
|
|
1168
1283
|
}
|
|
1284
|
+
/** Remove up to `levels` empty folders above `file`, stopping at the first one with anything in it. */
|
|
1285
|
+
async function pruneEmptyDirs(file, levels) {
|
|
1286
|
+
let dir = dirname(file);
|
|
1287
|
+
for (let n = levels === true ? 1 : levels; n > 0; n--) {
|
|
1288
|
+
if (!await rmdir(dir).then(() => true, () => false)) break;
|
|
1289
|
+
dir = dirname(dir);
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1169
1292
|
/** Restore one file as init found it, when it still matches. Returns the action taken. */
|
|
1170
1293
|
async function restoreEntry(dir, entry) {
|
|
1171
1294
|
const bytes = await readBytes(entry.path);
|
|
1172
1295
|
const action = actionFor(entry, bytes === null ? null : sha256(bytes));
|
|
1173
|
-
if (action === "remove")
|
|
1174
|
-
|
|
1296
|
+
if (action === "remove") {
|
|
1297
|
+
await rm(entry.path, { force: true });
|
|
1298
|
+
if (entry.pruneEmptyDir !== void 0) await pruneEmptyDirs(entry.path, entry.pruneEmptyDir);
|
|
1299
|
+
} else if (action === "restore" && entry.backup !== null) await writeAtomic(entry.path, await readFile(join(dir, entry.backup)));
|
|
1175
1300
|
return action;
|
|
1176
1301
|
}
|
|
1177
1302
|
async function markRestored(ctx, found) {
|
|
@@ -1181,9 +1306,111 @@ async function markRestored(ctx, found) {
|
|
|
1181
1306
|
};
|
|
1182
1307
|
await writeFile(join(found.dir, MANIFEST_NAME), `${JSON.stringify(done, null, 2)}\n`, { mode: 384 });
|
|
1183
1308
|
}
|
|
1309
|
+
// src/tools.ts
|
|
1310
|
+
/**
|
|
1311
|
+
* The settings file, or undefined when its path is not a real path on this machine. A test that
|
|
1312
|
+
* fakes another platform builds paths with that platform's separators; writing there would land
|
|
1313
|
+
* in the working directory, so nothing is read or written.
|
|
1314
|
+
*/
|
|
1315
|
+
function settingsFile(ctx) {
|
|
1316
|
+
const path = dataPaths(ctx.platform, ctx.dataDir).settings;
|
|
1317
|
+
return isAbsolute(path) ? path : void 0;
|
|
1318
|
+
}
|
|
1319
|
+
/** The tools that already have Conveno's setup, whether or not their program is on PATH now. */
|
|
1320
|
+
async function connectedTools(ctx) {
|
|
1321
|
+
const env = adapterEnv(ctx);
|
|
1322
|
+
const out = [];
|
|
1323
|
+
for (const adapter of ctx.adapters) try {
|
|
1324
|
+
if (!(await adapter.plan(env)).some((c) => c.component === "mcp" && c.kind === "add")) out.push(adapter.cli);
|
|
1325
|
+
} catch {}
|
|
1326
|
+
return out;
|
|
1327
|
+
}
|
|
1328
|
+
/**
|
|
1329
|
+
* The saved choice. Installs from before the choice was saved have none: it is then taken, once,
|
|
1330
|
+
* from the tools that already have Conveno's setup and saved. Nothing saved and nothing set up
|
|
1331
|
+
* gives an empty list (the first setup has not happened).
|
|
1332
|
+
*/
|
|
1333
|
+
async function chosenTools(ctx) {
|
|
1334
|
+
const path = settingsFile(ctx);
|
|
1335
|
+
const known = new Set(ctx.adapters.map((a) => a.cli));
|
|
1336
|
+
const saved = path ? readSettings(path).tools : void 0;
|
|
1337
|
+
if (saved) return saved.filter((c) => known.has(c));
|
|
1338
|
+
const derived = await connectedTools(ctx);
|
|
1339
|
+
if (path && derived.length > 0) try {
|
|
1340
|
+
writeSettings(path, { tools: derived });
|
|
1341
|
+
} catch {}
|
|
1342
|
+
return derived;
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Save the choice, after the setup worked. The lead must be one of the chosen tools: a new one is
|
|
1346
|
+
* kept, the earlier one stays while it is still chosen, and a lead that was dropped is cleared.
|
|
1347
|
+
*/
|
|
1348
|
+
function saveChoice(ctx, tools, lead) {
|
|
1349
|
+
const path = settingsFile(ctx);
|
|
1350
|
+
if (!path) return;
|
|
1351
|
+
const next = lead ?? readSettings(path).leadCli;
|
|
1352
|
+
writeSettings(path, {
|
|
1353
|
+
tools: [...new Set(tools)],
|
|
1354
|
+
leadCli: next && tools.includes(next) ? next : null
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
// src/worker-access.ts
|
|
1358
|
+
/** "1 min", "2 min", "5 min". */
|
|
1359
|
+
const waitText = (sec) => `${Math.round(sec / 60)} min`;
|
|
1360
|
+
/** Plain words for each level. */
|
|
1361
|
+
const ACCESS_TEXT = {
|
|
1362
|
+
read: {
|
|
1363
|
+
label: "Read only",
|
|
1364
|
+
hint: "read and search files, list folders"
|
|
1365
|
+
},
|
|
1366
|
+
edit: {
|
|
1367
|
+
label: "Read and edit",
|
|
1368
|
+
hint: "also edit files; commands are asked"
|
|
1369
|
+
},
|
|
1370
|
+
full: {
|
|
1371
|
+
label: "Everything",
|
|
1372
|
+
hint: "anything, no questions"
|
|
1373
|
+
}
|
|
1374
|
+
};
|
|
1375
|
+
const UNANSWERED_TEXT = {
|
|
1376
|
+
deny: {
|
|
1377
|
+
label: "Deny it",
|
|
1378
|
+
hint: "the worker is told no"
|
|
1379
|
+
},
|
|
1380
|
+
allow: {
|
|
1381
|
+
label: "Allow it",
|
|
1382
|
+
hint: "the worker goes ahead"
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
const isWorkerAccess = (v) => WORKER_ACCESS.includes(v);
|
|
1386
|
+
/** The saved choices, or the defaults. */
|
|
1387
|
+
function readWorkerAccess(ctx) {
|
|
1388
|
+
const path = settingsFile(ctx);
|
|
1389
|
+
const s = path ? readSettings(path) : {};
|
|
1390
|
+
return {
|
|
1391
|
+
access: workerAccessOf(s),
|
|
1392
|
+
unanswered: workerUnansweredOf(s),
|
|
1393
|
+
waitSec: workerAskTimeoutOf(s)
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
/** Save some or all. Does nothing when the settings path is not a real path (faked platform). */
|
|
1397
|
+
function saveWorkerAccess(ctx, patch) {
|
|
1398
|
+
const path = settingsFile(ctx);
|
|
1399
|
+
if (!path) return;
|
|
1400
|
+
writeSettings(path, {
|
|
1401
|
+
...patch.access ? { workerAccess: patch.access } : {},
|
|
1402
|
+
...patch.unanswered ? { workerUnanswered: patch.unanswered } : {},
|
|
1403
|
+
...patch.waitSec ? { workerAskTimeoutSec: patch.waitSec } : {}
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
/** One quiet line for `conveno status` and `conveno doctor`. */
|
|
1407
|
+
function workerAccessLine(ctx) {
|
|
1408
|
+
const { access, unanswered, waitSec } = readWorkerAccess(ctx);
|
|
1409
|
+
if (access === "full") return "Workers: full · no questions";
|
|
1410
|
+
return `Workers: ${access} · asks wait ${waitText(waitSec)}, then ${unanswered}`;
|
|
1411
|
+
}
|
|
1184
1412
|
// src/init.ts
|
|
1185
1413
|
const CODEX_NOTE = "Codex asks you to approve Conveno once: run /hooks inside Codex.";
|
|
1186
|
-
const CURSOR_NOTE = "Cursor can ask you to approve Conveno when you start it in your home folder. Approve it once there with: cursor-agent mcp enable conveno";
|
|
1187
1414
|
/** Detect every adapter. A detection that throws counts as not installed. */
|
|
1188
1415
|
async function detectAll(ctx, adapters = ctx.adapters) {
|
|
1189
1416
|
const env = adapterEnv(ctx);
|
|
@@ -1224,6 +1451,24 @@ function parseCliList(raw, ctx) {
|
|
|
1224
1451
|
}
|
|
1225
1452
|
return out;
|
|
1226
1453
|
}
|
|
1454
|
+
/**
|
|
1455
|
+
* The tools to set up: `--cli` when given (it becomes the saved choice), else the saved choice.
|
|
1456
|
+
* With neither there is nothing to go on, so the caller must ask for `--cli`.
|
|
1457
|
+
*/
|
|
1458
|
+
async function toolsToSet(ctx, raw) {
|
|
1459
|
+
if (raw !== void 0) {
|
|
1460
|
+
const list = parseCliList(raw, ctx);
|
|
1461
|
+
return Array.isArray(list) ? {
|
|
1462
|
+
adapters: list,
|
|
1463
|
+
explicit: true
|
|
1464
|
+
} : list;
|
|
1465
|
+
}
|
|
1466
|
+
const saved = await chosenTools(ctx);
|
|
1467
|
+
return {
|
|
1468
|
+
adapters: ctx.adapters.filter((a) => saved.includes(a.cli)),
|
|
1469
|
+
explicit: false
|
|
1470
|
+
};
|
|
1471
|
+
}
|
|
1227
1472
|
function printDetections(ctx, found) {
|
|
1228
1473
|
const t = ctx.theme;
|
|
1229
1474
|
ctx.out(`${t.bold("Looking for AI tools on this machine")}\n`);
|
|
@@ -1241,11 +1486,14 @@ async function collectPlans(ctx, found, which, baseline, accept = []) {
|
|
|
1241
1486
|
const items = [];
|
|
1242
1487
|
const failures = [];
|
|
1243
1488
|
for (const { adapter, detection } of found) try {
|
|
1244
|
-
for (const change of await (which === "plan" ? adapter.plan(env, { accept }) : adapter.uninstallPlan(env, baseline)))
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1489
|
+
for (const change of await (which === "plan" ? adapter.plan(env, { accept }) : adapter.uninstallPlan(env, baseline))) {
|
|
1490
|
+
if (items.some((i) => i.change.path === change.path && i.change.after === change.after)) continue;
|
|
1491
|
+
items.push({
|
|
1492
|
+
cli: adapter.cli,
|
|
1493
|
+
installed: detection.installed,
|
|
1494
|
+
change
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1249
1497
|
} catch (e) {
|
|
1250
1498
|
failures.push({
|
|
1251
1499
|
cli: adapter.cli,
|
|
@@ -1277,8 +1525,10 @@ const staleFailure = (ctx, e, rerun) => fail(ctx, {
|
|
|
1277
1525
|
async function confirmAndApply(ctx, items, opts) {
|
|
1278
1526
|
const t = ctx.theme;
|
|
1279
1527
|
const files = new Set(items.map((i) => i.change.path)).size;
|
|
1280
|
-
|
|
1528
|
+
const notes = opts.notes ?? [];
|
|
1529
|
+
ctx.out(`${t.bold(`Conveno will change ${plural(files, "file")}.`)}${notes.length > 0 ? "" : " Nothing else is touched."}\n\n`);
|
|
1281
1530
|
presentChanges(ctx, items);
|
|
1531
|
+
for (const n of notes) ctx.out(` ${n}\n\n`);
|
|
1282
1532
|
const paths = dataPaths(ctx.platform, ctx.dataDir);
|
|
1283
1533
|
ctx.out(` ${t.paint("quiet", `Backups go to ${tilde(paths.backups, ctx.home)}/<timestamp>/`)}\n`);
|
|
1284
1534
|
ctx.out(` ${t.paint("quiet", "Undo any time with:")} ${cmd(t, "conveno uninstall")}\n\n`);
|
|
@@ -1300,7 +1550,7 @@ async function confirmAndApply(ctx, items, opts) {
|
|
|
1300
1550
|
if (code !== 0) return { exit: code };
|
|
1301
1551
|
}
|
|
1302
1552
|
try {
|
|
1303
|
-
return { applied: await applyChanges(ctx, items, opts.markRestored ? { markRestored: true } : {}) };
|
|
1553
|
+
return { applied: await applyChanges(ctx, [...items, ...opts.backups ?? []], opts.markRestored ? { markRestored: true } : {}) };
|
|
1304
1554
|
} catch (e) {
|
|
1305
1555
|
if (e instanceof StaleError) return { exit: staleFailure(ctx, e, opts.rerun) };
|
|
1306
1556
|
if (e instanceof ApplyError && !e.rolledBack) return { exit: fail(ctx, {
|
|
@@ -1319,20 +1569,135 @@ async function confirmAndApply(ctx, items, opts) {
|
|
|
1319
1569
|
}) };
|
|
1320
1570
|
}
|
|
1321
1571
|
}
|
|
1322
|
-
/**
|
|
1572
|
+
/**
|
|
1573
|
+
* Every optional question for these CLIs that is not yet turned on. `enabled` throwing counts as
|
|
1574
|
+
* on: nothing to offer. So does an option the tool cannot take (`available` false).
|
|
1575
|
+
*/
|
|
1323
1576
|
async function pendingOptions(ctx, adapters) {
|
|
1324
1577
|
const env = adapterEnv(ctx);
|
|
1325
1578
|
const out = [];
|
|
1326
1579
|
for (const a of adapters) for (const o of a.optional ?? []) {
|
|
1580
|
+
if (o.available && !await o.available(env).catch(() => false)) continue;
|
|
1327
1581
|
if (await o.enabled(env).catch(() => true)) continue;
|
|
1328
1582
|
out.push({
|
|
1329
1583
|
cli: a.cli,
|
|
1330
1584
|
id: o.id,
|
|
1331
|
-
question: o.question
|
|
1585
|
+
question: o.question,
|
|
1586
|
+
defaultYes: o.defaultYes === true
|
|
1332
1587
|
});
|
|
1333
1588
|
}
|
|
1334
1589
|
return out;
|
|
1335
1590
|
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Run the follow-up step of the options answered yes, for options that are not file edits (they
|
|
1593
|
+
* have `apply`). Each failure comes back as one friendly line and never stops the setup.
|
|
1594
|
+
*/
|
|
1595
|
+
async function applyOptions(ctx, adapters, accepted) {
|
|
1596
|
+
const env = adapterEnv(ctx);
|
|
1597
|
+
const yes = new Set(accepted);
|
|
1598
|
+
const done = [];
|
|
1599
|
+
const problems = [];
|
|
1600
|
+
for (const a of adapters) for (const o of a.optional ?? []) {
|
|
1601
|
+
if (!yes.has(o.id) || !o.apply) continue;
|
|
1602
|
+
try {
|
|
1603
|
+
const r = await o.apply(env);
|
|
1604
|
+
if (r.ok) done.push({
|
|
1605
|
+
cli: a.cli,
|
|
1606
|
+
id: o.id
|
|
1607
|
+
});
|
|
1608
|
+
else problems.push(r.message);
|
|
1609
|
+
} catch {
|
|
1610
|
+
problems.push(`Couldn't finish setting up ${a.displayName}.`);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
return {
|
|
1614
|
+
done,
|
|
1615
|
+
problems
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* Whether setup has taken care of a tool's first-run approvals: true when every approval option it
|
|
1620
|
+
* has is in place. Undefined when the tool has none, so its note is unchanged.
|
|
1621
|
+
*/
|
|
1622
|
+
async function approvedBySetup(ctx, adapter) {
|
|
1623
|
+
const env = adapterEnv(ctx);
|
|
1624
|
+
const approvals = (adapter.optional ?? []).filter((o) => o.approval === true);
|
|
1625
|
+
if (approvals.length === 0) return void 0;
|
|
1626
|
+
for (const o of approvals) if (!await o.enabled(env).catch(() => false)) return false;
|
|
1627
|
+
return true;
|
|
1628
|
+
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Approval options that are already on for a tool this run changes. Codex calls a hook it has
|
|
1631
|
+
* trusted "modified" once its command changes (a moved `conveno`), so the approval is given again.
|
|
1632
|
+
*/
|
|
1633
|
+
async function renewedApprovals(ctx, adapters, items) {
|
|
1634
|
+
const env = adapterEnv(ctx);
|
|
1635
|
+
const ids = [];
|
|
1636
|
+
for (const a of adapters) {
|
|
1637
|
+
if (!items.some((i) => i.cli === a.cli)) continue;
|
|
1638
|
+
for (const o of a.optional ?? []) {
|
|
1639
|
+
if (o.approval !== true || !o.apply) continue;
|
|
1640
|
+
if (o.available && !await o.available(env).catch(() => false)) continue;
|
|
1641
|
+
if (await o.enabled(env).catch(() => false)) ids.push(o.id);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
return ids;
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* What the options answered yes write outside the plan: a line for each, and the files as
|
|
1648
|
+
* no-change entries so they are backed up with the rest (a file the plan already changes is not
|
|
1649
|
+
* listed twice, and a file that does not exist has nothing to back up).
|
|
1650
|
+
*/
|
|
1651
|
+
async function approvalWrites(ctx, adapters, ids, items) {
|
|
1652
|
+
const env = adapterEnv(ctx);
|
|
1653
|
+
const notes = [];
|
|
1654
|
+
const backups = [];
|
|
1655
|
+
for (const a of adapters) for (const o of a.optional ?? []) {
|
|
1656
|
+
if (!ids.has(o.id) || !o.applyWrites) continue;
|
|
1657
|
+
const w = o.applyWrites(env);
|
|
1658
|
+
notes.push(w.note);
|
|
1659
|
+
for (const path of w.paths) {
|
|
1660
|
+
if ([...items, ...backups].some((i) => i.change.path === path)) continue;
|
|
1661
|
+
const text = await readFile(path, "utf8").catch(() => null);
|
|
1662
|
+
if (text === null) continue;
|
|
1663
|
+
backups.push({
|
|
1664
|
+
cli: a.cli,
|
|
1665
|
+
installed: true,
|
|
1666
|
+
change: {
|
|
1667
|
+
component: "hooks",
|
|
1668
|
+
kind: "update",
|
|
1669
|
+
path,
|
|
1670
|
+
before: text,
|
|
1671
|
+
after: text,
|
|
1672
|
+
description: `${a.displayName} approval of Conveno's hooks, written by ${a.displayName}.`
|
|
1673
|
+
}
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
return {
|
|
1678
|
+
notes,
|
|
1679
|
+
backups
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* After a tool wrote its own approval into a backed-up file, record the file as it is now, so
|
|
1684
|
+
* `conveno uninstall` still sees it as the one setup left and can restore the backup.
|
|
1685
|
+
*/
|
|
1686
|
+
async function refreshManifest(backupDir, paths) {
|
|
1687
|
+
const file = join(backupDir, "manifest.json");
|
|
1688
|
+
try {
|
|
1689
|
+
const manifest = JSON.parse(await readFile(file, "utf8"));
|
|
1690
|
+
let changed = false;
|
|
1691
|
+
for (const e of manifest.entries) {
|
|
1692
|
+
if (!paths.includes(e.path)) continue;
|
|
1693
|
+
const now = await readFile(e.path).catch(() => null);
|
|
1694
|
+
if (now === null) continue;
|
|
1695
|
+
e.afterSha256 = sha256(now);
|
|
1696
|
+
changed = true;
|
|
1697
|
+
}
|
|
1698
|
+
if (changed) await writeFile(file, `${JSON.stringify(manifest, null, 2)}\n`, { mode: 384 });
|
|
1699
|
+
} catch {}
|
|
1700
|
+
}
|
|
1336
1701
|
/** The changes `with` has that `base` does not: a different file, or the same file with other text. */
|
|
1337
1702
|
function extraChanges(base, withOpt) {
|
|
1338
1703
|
const had = new Set(base.map((i) => `${i.change.path}\0${i.change.after}\0${i.change.kind}`));
|
|
@@ -1355,9 +1720,29 @@ async function runInit(ctx, argv, name = "init") {
|
|
|
1355
1720
|
ref: "e_usage"
|
|
1356
1721
|
});
|
|
1357
1722
|
}
|
|
1723
|
+
if (typeof lead === "string") {
|
|
1724
|
+
const rawCli = early?.values.cli;
|
|
1725
|
+
const picked = await toolsToSet(ctx, typeof rawCli === "string" ? rawCli : void 0);
|
|
1726
|
+
if ("adapters" in picked && !picked.adapters.some((a) => a.cli === lead)) return fail(ctx, {
|
|
1727
|
+
what: `${lead} is not one of the chosen AI tools, so it can't lead`,
|
|
1728
|
+
detail: [`Chosen: ${picked.adapters.map((a) => a.cli).join(", ") || "none"}.`],
|
|
1729
|
+
fix: `Pass ${cmd(ctx.theme, `--cli ${lead}`)} too, or pick a lead from the list above.`,
|
|
1730
|
+
exit: 2,
|
|
1731
|
+
ref: "e_usage"
|
|
1732
|
+
});
|
|
1733
|
+
}
|
|
1734
|
+
if (early?.values["dry-run"] !== true) {
|
|
1735
|
+
const restarted = await replaceStaleDaemon(ctx);
|
|
1736
|
+
if (restarted) ctx.out(`${ctx.theme.status("info")} ${restarted}\n`);
|
|
1737
|
+
}
|
|
1358
1738
|
const outcome = {};
|
|
1359
1739
|
const code = await initSetup(ctx, argv, outcome, name);
|
|
1360
1740
|
if (code !== 0) return code;
|
|
1741
|
+
const access = early?.values["worker-access"];
|
|
1742
|
+
if (isWorkerAccess(access) && early?.values["dry-run"] !== true) {
|
|
1743
|
+
saveWorkerAccess(ctx, { access });
|
|
1744
|
+
ctx.out(`${ctx.theme.status("ok")} Workers get ${access} access.\n`);
|
|
1745
|
+
}
|
|
1361
1746
|
if (typeof lead === "string" && early?.values["dry-run"] !== true) {
|
|
1362
1747
|
writeSettings(dataPaths(ctx.platform, ctx.dataDir).settings, { leadCli: lead });
|
|
1363
1748
|
const shown = ctx.adapters.find((a) => a.cli === lead)?.displayName ?? lead;
|
|
@@ -1372,6 +1757,10 @@ async function runInit(ctx, argv, name = "init") {
|
|
|
1372
1757
|
flag: values["acp-adapters"] === true ? true : values["no-acp-adapters"] === true ? false : void 0,
|
|
1373
1758
|
yes: values.yes === true
|
|
1374
1759
|
});
|
|
1760
|
+
const t = ctx.theme;
|
|
1761
|
+
const warmed = await warmAcpAdapters(ctx, outcome.offer.map((a) => a.cli), { onStart: () => ctx.out(`${t.status("info")} Getting workers ready (the first download can take a minute).\n`) }).catch(() => void 0);
|
|
1762
|
+
if (warmed?.status === "ready") ctx.out(`${t.status("ok")} Workers are ready.\n`);
|
|
1763
|
+
else if (warmed?.status === "failed") ctx.out(`${t.status("info")} Couldn't get workers ready now. They download the first time one starts.\n`);
|
|
1375
1764
|
return 0;
|
|
1376
1765
|
}
|
|
1377
1766
|
async function initSetup(ctx, argv, outcome, name) {
|
|
@@ -1388,11 +1777,19 @@ async function initSetup(ctx, argv, outcome, name) {
|
|
|
1388
1777
|
exit: 2,
|
|
1389
1778
|
ref: "e_usage"
|
|
1390
1779
|
});
|
|
1391
|
-
const
|
|
1392
|
-
if (!
|
|
1393
|
-
what:
|
|
1780
|
+
const picked = await toolsToSet(ctx, typeof values.cli === "string" ? values.cli : void 0);
|
|
1781
|
+
if (!("adapters" in picked)) return fail(ctx, {
|
|
1782
|
+
what: picked.message,
|
|
1394
1783
|
fix: `Pass ${cmd(t, cliListExample(ctx))} or leave it out.`,
|
|
1395
|
-
...
|
|
1784
|
+
...picked.suggestion ? { didYouMean: picked.suggestion } : {},
|
|
1785
|
+
exit: 2,
|
|
1786
|
+
ref: "e_usage"
|
|
1787
|
+
});
|
|
1788
|
+
const chosen = picked.adapters;
|
|
1789
|
+
if (chosen.length === 0) return fail(ctx, {
|
|
1790
|
+
what: "No AI tools are chosen yet",
|
|
1791
|
+
detail: [`Choices: ${ctx.adapters.map((a) => a.cli).join(", ")}.`],
|
|
1792
|
+
fix: `Pass ${cmd(t, cliListExample(ctx))}, or run ${cmd(t, "conveno setup")} in a terminal to pick.`,
|
|
1396
1793
|
exit: 2,
|
|
1397
1794
|
ref: "e_usage"
|
|
1398
1795
|
});
|
|
@@ -1425,14 +1822,19 @@ async function initSetup(ctx, argv, outcome, name) {
|
|
|
1425
1822
|
const dryRun = Boolean(values["dry-run"]);
|
|
1426
1823
|
for (const o of pending) {
|
|
1427
1824
|
if (accepted.has(o.id)) continue;
|
|
1428
|
-
if (dryRun || values.yes === true || !ctx.interactive)
|
|
1429
|
-
|
|
1825
|
+
if (dryRun || values.yes === true || !ctx.interactive) {
|
|
1826
|
+
if (acceptRaw === void 0 && o.defaultYes) accepted.add(o.id);
|
|
1827
|
+
continue;
|
|
1828
|
+
}
|
|
1829
|
+
if (await ctx.confirm(o.question, o.defaultYes)) accepted.add(o.id);
|
|
1430
1830
|
}
|
|
1431
1831
|
const { items, failures } = await collectPlans(ctx, installed, "plan", void 0, [...accepted]);
|
|
1432
1832
|
if (failures.length > 0) {
|
|
1433
1833
|
reportFailures(ctx, failures, `conveno ${name} --cli <others>`);
|
|
1434
1834
|
return 1;
|
|
1435
1835
|
}
|
|
1836
|
+
const adapters = installed.map((f) => f.adapter);
|
|
1837
|
+
const applying = /* @__PURE__ */ new Set([...accepted, ...dryRun ? [] : await renewedApprovals(ctx, adapters, items)]);
|
|
1436
1838
|
const extras = [];
|
|
1437
1839
|
if (dryRun) for (const o of pending) {
|
|
1438
1840
|
if (accepted.has(o.id)) continue;
|
|
@@ -1444,13 +1846,19 @@ async function initSetup(ctx, argv, outcome, name) {
|
|
|
1444
1846
|
}
|
|
1445
1847
|
if (items.length === 0 && extras.length === 0) {
|
|
1446
1848
|
ctx.out(`${t.status("ok")} Conveno is already set up for ${installed.map((f) => f.adapter.cli).join(", ")}. Nothing to change.\n`);
|
|
1849
|
+
if (!dryRun) {
|
|
1850
|
+
await approveTools(ctx, installed, accepted, /* @__PURE__ */ new Set());
|
|
1851
|
+
if (picked.explicit) saveChoice(ctx, installed.map((f) => f.adapter.cli));
|
|
1852
|
+
}
|
|
1447
1853
|
outcome.offer = installed.map((f) => f.adapter);
|
|
1448
1854
|
return 0;
|
|
1449
1855
|
}
|
|
1450
1856
|
if (dryRun) {
|
|
1451
1857
|
const files = new Set(items.map((i) => i.change.path)).size;
|
|
1452
|
-
|
|
1858
|
+
const { notes } = await approvalWrites(ctx, installed.map((f) => f.adapter), applying, items);
|
|
1859
|
+
ctx.out(`${t.bold(`Conveno would change ${plural(files, "file")}.`)}${notes.length > 0 ? "" : " Nothing else is touched."}\n\n`);
|
|
1453
1860
|
presentChanges(ctx, items);
|
|
1861
|
+
for (const n of notes) ctx.out(` ${n}\n\n`);
|
|
1454
1862
|
for (const x of extras) {
|
|
1455
1863
|
ctx.out(`${t.bold(x.option.question)}\n ${t.paint("quiet", `Not turned on. With --accept ${x.option.id} Conveno would also change:`)}\n\n`);
|
|
1456
1864
|
presentChanges(ctx, x.items);
|
|
@@ -1458,10 +1866,13 @@ async function initSetup(ctx, argv, outcome, name) {
|
|
|
1458
1866
|
ctx.out(`${t.status("info")} Dry run: nothing was written. Run ${cmd(t, `conveno ${name}`)} to apply.\n`);
|
|
1459
1867
|
return 0;
|
|
1460
1868
|
}
|
|
1869
|
+
const writes = await approvalWrites(ctx, adapters, applying, items);
|
|
1461
1870
|
const result = await confirmAndApply(ctx, items, {
|
|
1462
1871
|
yes: values.yes === true,
|
|
1463
1872
|
verb: "Apply",
|
|
1464
|
-
rerun: `conveno ${name}
|
|
1873
|
+
rerun: `conveno ${name}`,
|
|
1874
|
+
notes: writes.notes,
|
|
1875
|
+
backups: writes.backups
|
|
1465
1876
|
});
|
|
1466
1877
|
if ("exit" in result) return result.exit;
|
|
1467
1878
|
const byCli = /* @__PURE__ */ new Map();
|
|
@@ -1471,13 +1882,39 @@ async function initSetup(ctx, argv, outcome, name) {
|
|
|
1471
1882
|
ctx.out(`${t.status("ok")} ${t.bold("Done.")} ${seconds(started, ctx.now())}\n`);
|
|
1472
1883
|
ctx.out(` Backups are in ${tilde(result.applied.backupDir, ctx.home)}.\n`);
|
|
1473
1884
|
ctx.out(" Restart open sessions so they pick up Conveno.\n");
|
|
1474
|
-
|
|
1475
|
-
if (byCli.has("
|
|
1885
|
+
const approved = await approveTools(ctx, installed, applying, new Set(byCli.keys()), result.applied.backupDir);
|
|
1886
|
+
if (byCli.has("codex") && !approved.has("codex")) ctx.out(`${t.status("info")} ${CODEX_NOTE}\n`);
|
|
1887
|
+
if (picked.explicit) saveChoice(ctx, installed.map((f) => f.adapter.cli));
|
|
1476
1888
|
ctx.out(` Next: ${cmd(t, "conveno status")} lists your sessions.\n`);
|
|
1477
1889
|
outcome.offer = installed.map((f) => f.adapter);
|
|
1478
1890
|
return 0;
|
|
1479
1891
|
}
|
|
1480
1892
|
/**
|
|
1893
|
+
* Runs the follow-up of the options answered yes and says what it did. Returns the tools whose
|
|
1894
|
+
* first-run approvals are now in place among `touched`, so their note is left out.
|
|
1895
|
+
*/
|
|
1896
|
+
async function approveTools(ctx, installed, accepted, touched, backupDir) {
|
|
1897
|
+
const t = ctx.theme;
|
|
1898
|
+
const adapters = installed.map((f) => f.adapter);
|
|
1899
|
+
const { done, problems } = await applyOptions(ctx, adapters, accepted);
|
|
1900
|
+
if (backupDir && done.length > 0) {
|
|
1901
|
+
const env = adapterEnv(ctx);
|
|
1902
|
+
const ids = new Set(done.map((d) => d.id));
|
|
1903
|
+
await refreshManifest(backupDir, adapters.flatMap((a) => (a.optional ?? []).flatMap((o) => ids.has(o.id) && o.applyWrites ? o.applyWrites(env).paths : [])));
|
|
1904
|
+
}
|
|
1905
|
+
for (const d of done) {
|
|
1906
|
+
const name = adapters.find((a) => a.cli === d.cli)?.displayName ?? d.cli;
|
|
1907
|
+
ctx.out(`${t.status("ok")} Approved Conveno in ${name}.\n`);
|
|
1908
|
+
}
|
|
1909
|
+
for (const p of problems) ctx.out(`${t.status("info")} ${p}\n`);
|
|
1910
|
+
const approved = /* @__PURE__ */ new Set();
|
|
1911
|
+
for (const a of adapters) {
|
|
1912
|
+
if (!touched.has(a.cli)) continue;
|
|
1913
|
+
if (await approvedBySetup(ctx, a) === true) approved.add(a.cli);
|
|
1914
|
+
}
|
|
1915
|
+
return approved;
|
|
1916
|
+
}
|
|
1917
|
+
/**
|
|
1481
1918
|
* `conveno setup`. In a terminal with no --yes it opens the onboarding in the app. Anywhere else
|
|
1482
1919
|
* it does what `conveno init` does, and also saves --lead.
|
|
1483
1920
|
*/
|
|
@@ -1487,7 +1924,18 @@ async function runSetup(ctx, argv) {
|
|
|
1487
1924
|
const parsed = parseFlags(ctx, spec, argv);
|
|
1488
1925
|
if (typeof parsed === "number") return parsed;
|
|
1489
1926
|
const v = parsed.values;
|
|
1490
|
-
|
|
1927
|
+
const access = v["worker-access"];
|
|
1928
|
+
if (access !== void 0 && !isWorkerAccess(access)) return fail(ctx, {
|
|
1929
|
+
what: `Unknown worker access "${String(access)}"`,
|
|
1930
|
+
detail: ["Choose read, edit or full."],
|
|
1931
|
+
fix: `Pass ${cmd(ctx.theme, "--worker-access edit")} or leave it out.`,
|
|
1932
|
+
exit: 2,
|
|
1933
|
+
ref: "e_usage"
|
|
1934
|
+
});
|
|
1935
|
+
if (ctx.interactive && v.yes !== true && v["dry-run"] !== true) {
|
|
1936
|
+
if (isWorkerAccess(access)) saveWorkerAccess(ctx, { access });
|
|
1937
|
+
return (await import("./run-PQBzaHv1.js")).runTui(ctx, { start: "setup" });
|
|
1938
|
+
}
|
|
1491
1939
|
return runInit(ctx, argv, "setup");
|
|
1492
1940
|
}
|
|
1493
1941
|
// src/doctor.ts
|
|
@@ -1538,9 +1986,10 @@ async function inspect(ctx, adapter) {
|
|
|
1538
1986
|
};
|
|
1539
1987
|
const hasHooks = adapter.deliveryTier !== "inbox" || hasAny(adapter.delivery?.(detection));
|
|
1540
1988
|
let idleWake;
|
|
1541
|
-
|
|
1989
|
+
const wakeOptions = (adapter.optional ?? []).filter((o) => o.approval !== true);
|
|
1990
|
+
if (wakeOptions.length > 0) {
|
|
1542
1991
|
idleWake = true;
|
|
1543
|
-
for (const o of
|
|
1992
|
+
for (const o of wakeOptions) if (!await o.enabled(env).catch(() => false)) idleWake = false;
|
|
1544
1993
|
}
|
|
1545
1994
|
const adapterNotes = await adapter.doctorNotes?.(env).catch(() => []);
|
|
1546
1995
|
try {
|
|
@@ -1567,44 +2016,35 @@ async function inspect(ctx, adapter) {
|
|
|
1567
2016
|
}
|
|
1568
2017
|
}
|
|
1569
2018
|
/**
|
|
1570
|
-
* A
|
|
1571
|
-
*
|
|
1572
|
-
*
|
|
2019
|
+
* A warning for a CLI older than a known-broken floor: a version that lacks something Conveno
|
|
2020
|
+
* needs. Nothing else is flagged: a newer or untested version gets no warning, and doctor never
|
|
2021
|
+
* exits 1 for a version.
|
|
1573
2022
|
*/
|
|
1574
2023
|
function versionBlock(t, adapter, version, status) {
|
|
2024
|
+
if (status.kind !== "older") return void 0;
|
|
1575
2025
|
const name = adapter.displayName;
|
|
1576
|
-
|
|
1577
|
-
problem: true,
|
|
1578
|
-
text: errorBlock(t, {
|
|
1579
|
-
what: `${name} ${version} is older than Conveno supports`,
|
|
1580
|
-
detail: [`Conveno needs ${name} ${status.minimum} or newer.`],
|
|
1581
|
-
fix: `Upgrade ${name}, then run ${cmd(t, "conveno doctor")} again.`,
|
|
1582
|
-
exit: 1,
|
|
1583
|
-
ref: "e_cli_old"
|
|
1584
|
-
})
|
|
1585
|
-
};
|
|
1586
|
-
if (status.kind === "newer" && status.minor) return {
|
|
1587
|
-
problem: false,
|
|
1588
|
-
text: warnBlock(t, `${name} ${version} is newer than the ${status.verified} Conveno was tested with.`, "Nothing to do unless messages stop arriving. Please report it at https://github.com/0xPixelNinja/conveno/issues if something breaks.", "CLI vendors change config and hook formats often. A nightly check tests the newest releases and raises the tested version when they pass.")
|
|
1589
|
-
};
|
|
2026
|
+
return warnBlock(t, `${name} ${version} is older than ${status.minimum}, which Conveno needs.`, `Upgrade ${name}, then run ${cmd(t, "conveno doctor")} again.`, `Some features need ${name} ${status.minimum} or newer. Conveno still works with what this version supports.`);
|
|
1590
2027
|
}
|
|
1591
2028
|
async function runDoctor(ctx, argv = []) {
|
|
1592
2029
|
const t = ctx.theme;
|
|
1593
2030
|
const spec = COMMANDS.find((c) => c.name === "doctor");
|
|
1594
2031
|
let adapters = ctx.adapters;
|
|
2032
|
+
let chosen;
|
|
1595
2033
|
if (spec) {
|
|
1596
2034
|
const parsed = parseFlags(ctx, spec, argv);
|
|
1597
2035
|
if (typeof parsed === "number") return parsed;
|
|
1598
|
-
const
|
|
1599
|
-
if (!Array.isArray(
|
|
1600
|
-
what:
|
|
2036
|
+
const picked = parseCliList(typeof parsed.values.cli === "string" ? parsed.values.cli : void 0, ctx);
|
|
2037
|
+
if (!Array.isArray(picked)) return fail(ctx, {
|
|
2038
|
+
what: picked.message,
|
|
1601
2039
|
fix: `Pass ${cmd(t, cliListExample(ctx))} or leave it out.`,
|
|
1602
|
-
...
|
|
2040
|
+
...picked.suggestion ? { didYouMean: picked.suggestion } : {},
|
|
1603
2041
|
exit: 2,
|
|
1604
2042
|
ref: "e_usage"
|
|
1605
2043
|
});
|
|
1606
|
-
adapters =
|
|
2044
|
+
adapters = picked;
|
|
2045
|
+
if (typeof parsed.values.cli === "string") chosen = new Set(picked.map((a) => a.cli));
|
|
1607
2046
|
}
|
|
2047
|
+
chosen ??= new Set(await chosenTools(ctx));
|
|
1608
2048
|
let ok = 0;
|
|
1609
2049
|
let warnings = 0;
|
|
1610
2050
|
let problems = 0;
|
|
@@ -1614,8 +2054,20 @@ async function runDoctor(ctx, argv = []) {
|
|
|
1614
2054
|
const client = await ctx.connect(connectOpts(ctx, false));
|
|
1615
2055
|
try {
|
|
1616
2056
|
const { sessions } = await client["session.list"]({});
|
|
1617
|
-
|
|
1618
|
-
|
|
2057
|
+
const relay = await (async () => client["relay.status"]({}))().catch(() => void 0);
|
|
2058
|
+
if (relay?.state === "upgrade_required") {
|
|
2059
|
+
warnings++;
|
|
2060
|
+
notes.push(warnBlock(t, "The relay no longer accepts this version of Conveno.", relay.detail ?? "Update Conveno to keep using your other computers.", "Your other computers cannot be reached until Conveno is updated."));
|
|
2061
|
+
}
|
|
2062
|
+
const running = client.daemonVersion;
|
|
2063
|
+
if (running !== void 0 && running !== VERSION) {
|
|
2064
|
+
daemonLine = [` ${t.status("warn")} daemon`, `running ${running}, this is ${VERSION}`];
|
|
2065
|
+
warnings++;
|
|
2066
|
+
notes.push(warnBlock(t, "Conveno's background service is from an older version.", `Run ${cmd(t, "conveno")} to restart it, or ${cmd(t, "conveno daemon stop")} and open your AI tools again.`, `The service running now is ${running}; this install is ${VERSION}. ${cmd(t, "conveno")} and ${cmd(t, "conveno setup")} restart it for you.`));
|
|
2067
|
+
} else {
|
|
2068
|
+
daemonLine = [` ${t.status("ok")} daemon`, `running, ${plural(sessions.length, "session")}`];
|
|
2069
|
+
ok++;
|
|
2070
|
+
}
|
|
1619
2071
|
} finally {
|
|
1620
2072
|
await client.close().catch(() => void 0);
|
|
1621
2073
|
}
|
|
@@ -1668,14 +2120,25 @@ async function runDoctor(ctx, argv = []) {
|
|
|
1668
2120
|
]);
|
|
1669
2121
|
continue;
|
|
1670
2122
|
}
|
|
2123
|
+
if (!chosen.has(adapter.cli) && !(r.mcp === "ok" && (r.hooks === null || r.hooks === "ok"))) {
|
|
2124
|
+
table.push([
|
|
2125
|
+
` ${t.glyph("offline")} ${adapter.cli}`,
|
|
2126
|
+
adapter.displayName,
|
|
2127
|
+
detection.version ?? "",
|
|
2128
|
+
"",
|
|
2129
|
+
"",
|
|
2130
|
+
"",
|
|
2131
|
+
q("not set up (not chosen)")
|
|
2132
|
+
]);
|
|
2133
|
+
continue;
|
|
2134
|
+
}
|
|
1671
2135
|
const good = r.mcp === "ok" && (r.hooks === null || r.hooks === "ok") && !r.planError;
|
|
1672
2136
|
const compat = compatStatus(adapter.cli, detection.version, ctx.compat);
|
|
1673
2137
|
const tiers = activeTiers(r);
|
|
1674
2138
|
let note = tiers.includes("idle wake") ? "wakes idle sessions" : tiers.includes("end of turn") ? "wakes at the end of a turn, no idle wake" : tiers.includes("next turn") ? "delivered at the next prompt" : "read through the inbox tool";
|
|
1675
2139
|
if (!good) note = r.planError ? "config could not be read" : r.mcp === "outdated" || r.hooks === "outdated" ? "needs an update" : "not fully configured";
|
|
1676
|
-
if (compat.kind === "older") note = `older than
|
|
1677
|
-
|
|
1678
|
-
const glyph = compat.kind === "older" ? t.status("error") : good && !(compat.kind === "newer" && compat.minor) ? t.status("ok") : t.status("warn");
|
|
2140
|
+
if (compat.kind === "older") note = `older than ${compat.minimum}, which Conveno needs`;
|
|
2141
|
+
const glyph = good && compat.kind !== "older" ? t.status("ok") : t.status("warn");
|
|
1679
2142
|
table.push([
|
|
1680
2143
|
` ${glyph} ${adapter.cli}`,
|
|
1681
2144
|
adapter.displayName,
|
|
@@ -1696,7 +2159,7 @@ async function runDoctor(ctx, argv = []) {
|
|
|
1696
2159
|
ref: "e_config"
|
|
1697
2160
|
}));
|
|
1698
2161
|
} else if (good) {
|
|
1699
|
-
if (compat.kind !== "older"
|
|
2162
|
+
if (compat.kind !== "older") ok++;
|
|
1700
2163
|
} else {
|
|
1701
2164
|
warnings++;
|
|
1702
2165
|
const named = [["the MCP server", r.mcp], ["the hooks", r.hooks]];
|
|
@@ -1708,14 +2171,14 @@ async function runDoctor(ctx, argv = []) {
|
|
|
1708
2171
|
}
|
|
1709
2172
|
const versionNote = versionBlock(t, adapter, detection.version, compat);
|
|
1710
2173
|
if (versionNote) {
|
|
1711
|
-
notes.push(versionNote
|
|
1712
|
-
|
|
1713
|
-
else warnings++;
|
|
2174
|
+
notes.push(versionNote);
|
|
2175
|
+
warnings++;
|
|
1714
2176
|
}
|
|
1715
2177
|
}
|
|
1716
2178
|
ctx.out(`${columns(table).join("\n")}\n`);
|
|
1717
2179
|
const acpLines = acpDoctorLines(ctx, rows.filter((r) => r.detection.installed).map((r) => r.adapter.cli));
|
|
1718
2180
|
if (acpLines.length > 0) ctx.out(`${acpLines.join("\n")}\n`);
|
|
2181
|
+
ctx.out(`${t.paint("quiet", workerAccessLine(ctx))}\n`);
|
|
1719
2182
|
if (!rows.some((r) => r.detection.installed)) {
|
|
1720
2183
|
notes.push(warnBlock(t, "No supported AI coding CLI was found on PATH.", "Install Claude Code, Codex CLI or OpenCode, then run conveno init."));
|
|
1721
2184
|
warnings++;
|
|
@@ -1731,6 +2194,13 @@ const NOTE = {
|
|
|
1731
2194
|
edit: "edited since setup, so only Conveno's entries are removed",
|
|
1732
2195
|
gone: "already gone, left as it is"
|
|
1733
2196
|
};
|
|
2197
|
+
/** The "asked once" markers the Grok and Antigravity Stop hooks keep in the data folder. */
|
|
2198
|
+
async function removeAskedMarkers(ctx) {
|
|
2199
|
+
for (const folder of ["grok-watch-asked", "agy-relay-asked"]) await rm(join(ctx.dataDir, folder), {
|
|
2200
|
+
recursive: true,
|
|
2201
|
+
force: true
|
|
2202
|
+
}).catch(() => void 0);
|
|
2203
|
+
}
|
|
1734
2204
|
/**
|
|
1735
2205
|
* The files as init found them, from the backups: their text, or null when they did not exist. A
|
|
1736
2206
|
* backup that cannot be read leaves its file out, and the adapter then treats what it finds as
|
|
@@ -1829,6 +2299,7 @@ async function runUninstall(ctx, argv) {
|
|
|
1829
2299
|
ref: "e_restore"
|
|
1830
2300
|
});
|
|
1831
2301
|
}
|
|
2302
|
+
await removeAskedMarkers(ctx);
|
|
1832
2303
|
ctx.out(`${t.status("ok")} ${t.bold("Done.")} ${seconds(started, ctx.now())}\n`);
|
|
1833
2304
|
ctx.out(` Restored ${plural(result.restored.length, "file")} to how they were before setup.\n`);
|
|
1834
2305
|
if (result.edited.length > 0) ctx.out(` Edited, not restored, because they changed since setup: ${result.edited.map((p) => tilde(p, ctx.home)).join(", ")}. Only Conveno's entries were removed.\n`);
|
|
@@ -1841,6 +2312,8 @@ async function runUninstall(ctx, argv) {
|
|
|
1841
2312
|
return 1;
|
|
1842
2313
|
}
|
|
1843
2314
|
if (items.length === 0) {
|
|
2315
|
+
const stopped = await stopDaemonIfRunning(ctx);
|
|
2316
|
+
if (stopped !== 0) return stopped;
|
|
1844
2317
|
ctx.out(`${t.status("ok")} Nothing to remove. No Conveno entries were found in any supported CLI.\n`);
|
|
1845
2318
|
return 0;
|
|
1846
2319
|
}
|
|
@@ -1853,8 +2326,9 @@ async function runUninstall(ctx, argv) {
|
|
|
1853
2326
|
beforeApply: () => stopDaemonIfRunning(ctx)
|
|
1854
2327
|
});
|
|
1855
2328
|
if ("exit" in result) return result.exit;
|
|
2329
|
+
await removeAskedMarkers(ctx);
|
|
1856
2330
|
ctx.out(`${t.status("ok")} ${t.bold("Done.")} ${seconds(started, ctx.now())}\n`);
|
|
1857
2331
|
ctx.out(" Removed the Conveno entries. Restart open sessions to drop Conveno.\n");
|
|
1858
2332
|
return 0;
|
|
1859
2333
|
}
|
|
1860
|
-
export {
|
|
2334
|
+
export { runRelay as A, saveChoice as C, warmAcpAdapters as D, unifiedDiff as E, openInBrowser as F, runAccount as I, runLogin as L, runDaemon as M, stopDaemonIfRunning as N, PAIR_TIMEOUT_MS as O, VERSION as P, runLogout as R, connectedTools as S, applyChanges as T, readWorkerAccess as _, applyOptions as a, workerAccessLine as b, collectPlans as c, refreshManifest as d, renewedApprovals as f, UNANSWERED_TEXT as g, ACCESS_TEXT as h, runDoctor as i, replaceStaleDaemon as j, runDevices as k, detectAll as l, runSetup as m, inspect as n, approvalWrites as o, runInit as p, partState as r, approvedBySetup as s, runUninstall as t, pendingOptions as u, saveWorkerAccess as v, StaleError as w, chosenTools as x, waitText as y, showCode as z };
|