@conveno/cli 0.2.0-rc.15 → 0.2.0-rc.17
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 +2 -2
- package/dist/{acp-DZf0zyNC.js → acp-C-o3rtAB.js} +39 -7
- package/dist/{agy-relay-DSRJtMz3.js → agy-relay-D17zTd_Z.js} +2 -2
- package/dist/{args-CpAvszNY.js → args-CtyKPZuN.js} +12 -0
- package/dist/bin.js +2 -2
- package/dist/daemon.js +134 -67
- package/dist/{daemonError-Bj22X-4V.js → daemonError-BwdtKOCy.js} +1 -1
- package/dist/{dist-Bx22a5AV.js → dist-B1pfP_d5.js} +1 -1
- package/dist/{dist-BRjg9CLd.js → dist-BOwFdixw.js} +23 -50
- package/dist/{dist-C4KljaIP.js → dist-Bb2opAjB.js} +3 -3
- package/dist/{dist-C59LTq60.js → dist-BgAfkqeX.js} +2 -1
- package/dist/{dist-Bv1bmmme.js → dist-CTw3arJP.js} +5 -5
- package/dist/{dist-DDzIkwf9.js → dist-CvKAege3.js} +1 -1
- package/dist/{dist-ZL7d4_97.js → dist-Dc50_P_f.js} +537 -163
- package/dist/{dist-fI_XSoCQ.js → dist-hyKfBSdF.js} +242 -38
- package/dist/{hook-BFZTvd7M.js → hook-BLSrNkFF.js} +2 -2
- package/dist/hook-entry-B1Yt2cwr.js +1 -0
- package/dist/{hook-entry-CvzyjOo4.js → hook-entry-DYXjVztc.js} +8 -8
- package/dist/{main-1QSm5UjR.js → main-CQx2xc_w.js} +36 -12
- package/dist/{pick-DaCRjuyz.js → pick-iuG24FX9.js} +1 -1
- package/dist/{run-CKiYjNqx.js → run-B01nDeos.js} +4079 -1815
- package/dist/{runtime-CeFKWoIL.js → runtime-hZwjrEPc.js} +37 -15
- package/dist/{uninstall-DK25hyWX.js → uninstall-B-deU_wY.js} +33 -19
- package/dist/{watch-De3wbdQL.js → watch-CPZ2X-yt.js} +4 -4
- package/package.json +14 -13
- package/dist/hook-entry-CmuvppGf.js +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { homedir, tmpdir } from "node:os";
|
|
1
|
+
import { homedir, tmpdir, userInfo } from "node:os";
|
|
2
2
|
import { dirname, join, posix, win32 } from "node:path";
|
|
3
|
-
import { execFile, spawn, spawnSync } from "node:child_process";
|
|
3
|
+
import { execFile, execFileSync, spawn, spawnSync } from "node:child_process";
|
|
4
4
|
import { accessSync, appendFileSync, chmodSync, closeSync, constants, existsSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
-
import {
|
|
5
|
+
import { mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
6
6
|
import crypto, { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
7
7
|
import { applyEdits, findNodeAtLocation, modify, parse as parse$1, parseTree, printParseErrorCode } from "jsonc-parser";
|
|
8
8
|
// ../../node_modules/.pnpm/ulid@3.0.2/node_modules/ulid/dist/node/index.js
|
|
@@ -5937,7 +5937,8 @@ const RelayState = _enum([
|
|
|
5937
5937
|
"connecting",
|
|
5938
5938
|
"connected",
|
|
5939
5939
|
"disconnected",
|
|
5940
|
-
"revoked"
|
|
5940
|
+
"revoked",
|
|
5941
|
+
"upgrade_required"
|
|
5941
5942
|
]);
|
|
5942
5943
|
const DeviceName = string().min(1).max(64);
|
|
5943
5944
|
const Fingerprint = string().min(1).max(64);
|
|
@@ -6169,6 +6170,8 @@ const Session = object({
|
|
|
6169
6170
|
name: union([SessionName, RemoteSessionName]),
|
|
6170
6171
|
cli: CliKind,
|
|
6171
6172
|
cliVersion: string().min(1).max(64).optional(),
|
|
6173
|
+
/** The model and effort a background worker runs on (`sonnet · high`), when known. Not stored. */
|
|
6174
|
+
model: string().min(1).max(200).optional(),
|
|
6172
6175
|
/** Set when the session is a desktop app of `cli` rather than the CLI. Screens say "Antigravity app". */
|
|
6173
6176
|
variant: SessionVariant.optional(),
|
|
6174
6177
|
deviceId: DeviceId,
|
|
@@ -6216,6 +6219,8 @@ const Session = object({
|
|
|
6216
6219
|
});
|
|
6217
6220
|
/** Wire protocol identifier. Bumped only on breaking changes. */
|
|
6218
6221
|
const PROTOCOL_VERSION = "conveno/1";
|
|
6222
|
+
/** What a device's daemon calls itself in a relay `hello` (`client.name`). */
|
|
6223
|
+
const RELAY_CLIENT_NAME = "conveno-cli";
|
|
6219
6224
|
const ClientKind = _enum([
|
|
6220
6225
|
"mcp",
|
|
6221
6226
|
"cli",
|
|
@@ -6248,6 +6253,8 @@ const RegisterParams = object({
|
|
|
6248
6253
|
name: SessionNameInput.optional(),
|
|
6249
6254
|
cli: CliKind,
|
|
6250
6255
|
cliVersion: string().min(1).max(64).optional(),
|
|
6256
|
+
/** The worker's model and effort as a short label (`sonnet · high`), shown on its card. */
|
|
6257
|
+
model: string().min(1).max(200).optional(),
|
|
6251
6258
|
/** The session runs in a desktop app of `cli`. See `Session.variant`. */
|
|
6252
6259
|
variant: SessionVariant.optional(),
|
|
6253
6260
|
cwd: string().min(1),
|
|
@@ -6263,7 +6270,7 @@ const RegisterParams = object({
|
|
|
6263
6270
|
spawned: boolean().default(false),
|
|
6264
6271
|
/**
|
|
6265
6272
|
* A `conveno acp-host` registers the session it drives over the Agent Client Protocol: the
|
|
6266
|
-
* session's delivery tier is `acp`, and its host prompts it with waiting messages (section
|
|
6273
|
+
* session's delivery tier is `acp`, and its host prompts it with waiting messages (section 5.8).
|
|
6267
6274
|
*/
|
|
6268
6275
|
acp: boolean().default(false)
|
|
6269
6276
|
});
|
|
@@ -6316,6 +6323,21 @@ const SendResult = object({
|
|
|
6316
6323
|
name: union([SessionName, literal("you")])
|
|
6317
6324
|
})
|
|
6318
6325
|
});
|
|
6326
|
+
/** One message between two sessions, as `message.recent` lists it for the app's activity list. */
|
|
6327
|
+
const RecentMessage = object({
|
|
6328
|
+
id: MessageId,
|
|
6329
|
+
from: SessionId,
|
|
6330
|
+
/** The sender's name when it sent the message (`<device>:<name>` for another machine's). */
|
|
6331
|
+
fromName: string().max(200).optional(),
|
|
6332
|
+
fromCli: CliKind.optional(),
|
|
6333
|
+
/** The session that got it. */
|
|
6334
|
+
to: SessionId,
|
|
6335
|
+
toName: string().max(200),
|
|
6336
|
+
toCli: CliKind.optional(),
|
|
6337
|
+
/** The first line of the text (or a handoff's goal), one plain line, cut. */
|
|
6338
|
+
text: string().max(200),
|
|
6339
|
+
createdAt: IsoTimestamp
|
|
6340
|
+
});
|
|
6319
6341
|
const EVENT_NAMES = [
|
|
6320
6342
|
"message.received",
|
|
6321
6343
|
"session.updated",
|
|
@@ -6379,7 +6401,8 @@ const ipcMethods = {
|
|
|
6379
6401
|
"session.heartbeat": {
|
|
6380
6402
|
params: object({
|
|
6381
6403
|
...sid,
|
|
6382
|
-
pid: number().int().positive().optional()
|
|
6404
|
+
pid: number().int().positive().optional(),
|
|
6405
|
+
model: string().min(1).max(200).optional()
|
|
6383
6406
|
}),
|
|
6384
6407
|
result: object({ lastSeenAt: IsoTimestamp })
|
|
6385
6408
|
},
|
|
@@ -6593,6 +6616,10 @@ const ipcMethods = {
|
|
|
6593
6616
|
}),
|
|
6594
6617
|
result: object({ acked: number().int().min(0) })
|
|
6595
6618
|
},
|
|
6619
|
+
"message.recent": {
|
|
6620
|
+
params: object({ limit: number().int().min(1).max(200).default(50) }),
|
|
6621
|
+
result: object({ messages: array(RecentMessage) })
|
|
6622
|
+
},
|
|
6596
6623
|
"owner.send": {
|
|
6597
6624
|
params: object({
|
|
6598
6625
|
to: Recipient,
|
|
@@ -6694,20 +6721,30 @@ const b64Bytes = (n) => {
|
|
|
6694
6721
|
const RelayKey32 = b64Bytes(32);
|
|
6695
6722
|
/** A 64-byte Ed25519 signature, base64. */
|
|
6696
6723
|
const RelaySig = b64Bytes(64);
|
|
6724
|
+
/** Relay to device, first frame: a fresh nonce the device signs in `hello`. */
|
|
6725
|
+
const RelayChallenge = object({
|
|
6726
|
+
t: literal("challenge"),
|
|
6727
|
+
v,
|
|
6728
|
+
nonce: b64Bytes(32)
|
|
6729
|
+
});
|
|
6730
|
+
/** What sent a `hello`: the program and its version. Not signed; the relay only reads it. */
|
|
6731
|
+
const RelayClientInfo = object({
|
|
6732
|
+
name: string().min(1).max(64),
|
|
6733
|
+
version: string().min(1).max(64)
|
|
6734
|
+
});
|
|
6697
6735
|
const RelayFrame = discriminatedUnion("t", [
|
|
6698
|
-
|
|
6699
|
-
t: literal("challenge"),
|
|
6700
|
-
v,
|
|
6701
|
-
nonce: b64Bytes(32)
|
|
6702
|
-
}),
|
|
6736
|
+
RelayChallenge,
|
|
6703
6737
|
object({
|
|
6704
6738
|
t: literal("hello"),
|
|
6705
6739
|
v,
|
|
6706
6740
|
deviceId: DeviceId,
|
|
6707
6741
|
/** Ed25519 public key, base64. */
|
|
6708
6742
|
signingKey: RelayKey32,
|
|
6709
|
-
/** Ed25519 signature over the canonical hello bytes (PROTOCOL.md section
|
|
6710
|
-
sig: RelaySig
|
|
6743
|
+
/** Ed25519 signature over the canonical hello bytes (PROTOCOL.md section 6.2). */
|
|
6744
|
+
sig: RelaySig,
|
|
6745
|
+
client: RelayClientInfo.optional(),
|
|
6746
|
+
/** Optional protocol features the device supports, for the relay to branch on later. */
|
|
6747
|
+
features: array(string().min(1).max(64)).max(32).optional()
|
|
6711
6748
|
}),
|
|
6712
6749
|
object({
|
|
6713
6750
|
t: literal("ready"),
|
|
@@ -6756,7 +6793,9 @@ const RelayFrame = discriminatedUnion("t", [
|
|
|
6756
6793
|
object({
|
|
6757
6794
|
t: literal("error"),
|
|
6758
6795
|
code: string().min(1).max(64),
|
|
6759
|
-
message: string().max(1e3)
|
|
6796
|
+
message: string().max(1e3),
|
|
6797
|
+
/** With `upgrade_required`: the oldest client version the relay accepts. */
|
|
6798
|
+
minVersion: string().min(1).max(64).optional()
|
|
6760
6799
|
})
|
|
6761
6800
|
]);
|
|
6762
6801
|
/** A session as published to the owner's other devices. Process ids stay on their machine. */
|
|
@@ -6840,15 +6879,245 @@ function socketPathTooLongMessage(path, platform) {
|
|
|
6840
6879
|
return `The Conveno socket path is too long for this system (${utf8ByteLength(path)} bytes, the limit is ${max}): ${path}. Set XDG_RUNTIME_DIR to a shorter directory and try again.`;
|
|
6841
6880
|
}
|
|
6842
6881
|
// ../core/dist/index.js
|
|
6882
|
+
const defaultIsFile = (path) => {
|
|
6883
|
+
try {
|
|
6884
|
+
return statSync(path).isFile();
|
|
6885
|
+
} catch {
|
|
6886
|
+
return false;
|
|
6887
|
+
}
|
|
6888
|
+
};
|
|
6889
|
+
/** Environment variable lookup that ignores case, as Windows does (`Path`, `PATH`, `PathExt`). */
|
|
6890
|
+
function envGet(env, name) {
|
|
6891
|
+
const want = name.toLowerCase();
|
|
6892
|
+
for (const [k, v] of Object.entries(env)) if (k.toLowerCase() === want && v !== void 0) return v;
|
|
6893
|
+
}
|
|
6894
|
+
const DEFAULT_PATHEXT = ".COM;.EXE;.BAT;.CMD";
|
|
6895
|
+
/** Only these can be started safely: other PATHEXT entries (.JS, .VBS) open Windows Script Host. */
|
|
6896
|
+
const LAUNCHABLE = /* @__PURE__ */ new Set([
|
|
6897
|
+
".com",
|
|
6898
|
+
".exe",
|
|
6899
|
+
".bat",
|
|
6900
|
+
".cmd"
|
|
6901
|
+
]);
|
|
6843
6902
|
/**
|
|
6844
|
-
*
|
|
6845
|
-
*
|
|
6846
|
-
*
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6903
|
+
* Find `command` the way cmd.exe does: each PATH directory in order, each PATHEXT extension in
|
|
6904
|
+
* order. A name that already ends in a launchable extension is tried as written first. Returns
|
|
6905
|
+
* undefined when nothing matches.
|
|
6906
|
+
*/
|
|
6907
|
+
function resolveWindowsCommand(command, env, isFile = defaultIsFile) {
|
|
6908
|
+
const exts = (envGet(env, "PATHEXT") ?? DEFAULT_PATHEXT).split(";").map((e) => e.trim()).filter((e) => LAUNCHABLE.has(e.toLowerCase()));
|
|
6909
|
+
const own = win32.extname(command).toLowerCase();
|
|
6910
|
+
const candidatesIn = (base) => [...LAUNCHABLE.has(own) ? [base] : [], ...exts.map((e) => base + e)];
|
|
6911
|
+
const dirs = /[\\/]/.test(command) || win32.isAbsolute(command) ? [""] : (envGet(env, "PATH") ?? "").split(";").map((d) => d.trim().replace(/^"(.*)"$/, "$1")).filter(Boolean);
|
|
6912
|
+
for (const dir of dirs) for (const candidate of candidatesIn(dir === "" ? command : win32.join(dir, command))) if (isFile(candidate)) return candidate;
|
|
6913
|
+
}
|
|
6914
|
+
/** Characters cmd.exe treats specially, plus the ones cross-spawn escapes defensively. */
|
|
6915
|
+
const CMD_META = /([()\][%!^"`<>&|;, *?])/g;
|
|
6916
|
+
/** The program name part of a cmd.exe command line: escape only, never wrap in quotes. */
|
|
6917
|
+
function escapeCmdCommand(command) {
|
|
6918
|
+
return command.replace(CMD_META, "^$1");
|
|
6919
|
+
}
|
|
6920
|
+
/**
|
|
6921
|
+
* Quote one argument for a `cmd.exe /d /s /c "..."` command line, the way cross-spawn does:
|
|
6922
|
+
* make it safe for the program's own parser (backslashes before a quote are doubled, the quote
|
|
6923
|
+
* is backslash-escaped, the whole thing is wrapped in quotes), then caret-escape every
|
|
6924
|
+
* character cmd.exe would act on, including the quotes themselves.
|
|
6925
|
+
*/
|
|
6926
|
+
function escapeCmdArg(arg) {
|
|
6927
|
+
let a = `${arg}`;
|
|
6928
|
+
a = a.replace(/(\\*)"/g, "$1$1\\\"");
|
|
6929
|
+
a = a.replace(/(\\*)$/, "$1$1");
|
|
6930
|
+
a = `"${a}"`;
|
|
6931
|
+
return a.replace(CMD_META, "^$1");
|
|
6932
|
+
}
|
|
6933
|
+
/** `cmd.exe /d /s /c "<command line>"` for a .cmd or .bat file. */
|
|
6934
|
+
function cmdShimPlan(file, args, env) {
|
|
6935
|
+
const line = [escapeCmdCommand(file), ...args.map(escapeCmdArg)].join(" ");
|
|
6936
|
+
return {
|
|
6937
|
+
file: envGet(env, "ComSpec") || "cmd.exe",
|
|
6938
|
+
args: [
|
|
6939
|
+
"/d",
|
|
6940
|
+
"/s",
|
|
6941
|
+
"/c",
|
|
6942
|
+
`"${line}"`
|
|
6943
|
+
],
|
|
6944
|
+
windowsVerbatimArguments: true
|
|
6945
|
+
};
|
|
6946
|
+
}
|
|
6947
|
+
/**
|
|
6948
|
+
* What to spawn for `command args...`. On Windows the command is resolved on PATH: .exe and .com
|
|
6949
|
+
* run directly, .cmd and .bat (npm shims) go through cmd.exe with one quoted command line. Never
|
|
6950
|
+
* uses a shell option with an args array. Elsewhere, and when nothing is found, the command is
|
|
6951
|
+
* returned unchanged so the caller sees the normal ENOENT.
|
|
6952
|
+
*/
|
|
6953
|
+
function planSpawn(command, args, opts = {}) {
|
|
6954
|
+
if ((opts.platform ?? process.platform) !== "win32") return {
|
|
6955
|
+
file: command,
|
|
6956
|
+
args
|
|
6957
|
+
};
|
|
6958
|
+
const env = opts.env ?? process.env;
|
|
6959
|
+
const found = resolveWindowsCommand(command, env, opts.isFile);
|
|
6960
|
+
if (!found) return {
|
|
6961
|
+
file: command,
|
|
6962
|
+
args
|
|
6963
|
+
};
|
|
6964
|
+
const ext = win32.extname(found).toLowerCase();
|
|
6965
|
+
if (ext === ".cmd" || ext === ".bat") return cmdShimPlan(found, args, env);
|
|
6966
|
+
return {
|
|
6967
|
+
file: found,
|
|
6968
|
+
args
|
|
6969
|
+
};
|
|
6970
|
+
}
|
|
6971
|
+
/**
|
|
6972
|
+
* Files only the current user may read: account tokens, device keys, the daemon token. POSIX
|
|
6973
|
+
* gets mode 0600; Windows ignores the mode, so there the file gets a user-only ACL from icacls.
|
|
6974
|
+
*/
|
|
6975
|
+
/**
|
|
6976
|
+
* The icacls command that leaves only the current user with access to `path`: inherited entries
|
|
6977
|
+
* removed (`/inheritance:r`), full control granted to the user, replacing any earlier grant
|
|
6978
|
+
* (`/grant:r`). For a directory, `inherit` makes the grant apply to files and folders created in
|
|
6979
|
+
* it (`(OI)(CI)`), so they are user-only from the moment they exist.
|
|
6980
|
+
* See https://learn.microsoft.com/windows-server/administration/windows-commands/icacls.
|
|
6981
|
+
* icacls is run from System32 by absolute path, never looked up on PATH.
|
|
6982
|
+
*/
|
|
6983
|
+
function userOnlyAclPlan(path, env, user, isFile, inherit = false) {
|
|
6984
|
+
const systemRoot = env.SystemRoot ?? env.SYSTEMROOT ?? "C:\\Windows";
|
|
6985
|
+
const icacls = win32.join(systemRoot, "System32", "icacls.exe");
|
|
6986
|
+
const domain = env.USERDOMAIN;
|
|
6987
|
+
return planSpawn(icacls, [
|
|
6988
|
+
path,
|
|
6989
|
+
"/inheritance:r",
|
|
6990
|
+
"/grant:r",
|
|
6991
|
+
`${domain ? `${domain}\\${user}` : user}:${inherit ? "(OI)(CI)" : ""}F`
|
|
6992
|
+
], {
|
|
6993
|
+
platform: "win32",
|
|
6994
|
+
env,
|
|
6995
|
+
...isFile ? { isFile } : {}
|
|
6996
|
+
});
|
|
6997
|
+
}
|
|
6998
|
+
const runPlan = (plan) => {
|
|
6999
|
+
execFileSync(plan.file, plan.args, {
|
|
7000
|
+
stdio: "ignore",
|
|
7001
|
+
windowsHide: true,
|
|
7002
|
+
...plan.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
|
|
7003
|
+
});
|
|
7004
|
+
};
|
|
7005
|
+
/**
|
|
7006
|
+
* Make a file readable by the current user only: mode 0600 on POSIX, a user-only ACL on Windows
|
|
7007
|
+
* (where the mode is ignored). A directory gets 0700, or an ACL its new entries inherit.
|
|
7008
|
+
*/
|
|
7009
|
+
function restrictToUser(path, platform = process.platform, directory = false, run = runPlan, sid = currentUserSid) {
|
|
7010
|
+
if (platform !== "win32") {
|
|
7011
|
+
chmodSync(path, directory ? 448 : 384);
|
|
7012
|
+
return;
|
|
7013
|
+
}
|
|
7014
|
+
const id = sid();
|
|
7015
|
+
const env = {
|
|
7016
|
+
...process.env,
|
|
7017
|
+
USERDOMAIN: void 0
|
|
7018
|
+
};
|
|
7019
|
+
const principals = id ? [`*${id}`, userInfo().username] : [userInfo().username];
|
|
7020
|
+
for (const principal of principals) try {
|
|
7021
|
+
run(userOnlyAclPlan(path, env, principal, void 0, directory));
|
|
7022
|
+
return;
|
|
7023
|
+
} catch {}
|
|
7024
|
+
}
|
|
7025
|
+
let sidCache = null;
|
|
7026
|
+
/** The current user's SID from `whoami /user`, or undefined. Read once per process. */
|
|
7027
|
+
function currentUserSid() {
|
|
7028
|
+
if (sidCache !== null) return sidCache;
|
|
7029
|
+
sidCache = void 0;
|
|
7030
|
+
try {
|
|
7031
|
+
const systemRoot = process.env.SystemRoot ?? process.env.SYSTEMROOT ?? "C:\\Windows";
|
|
7032
|
+
const out = execFileSync(win32.join(systemRoot, "System32", "whoami.exe"), [
|
|
7033
|
+
"/user",
|
|
7034
|
+
"/fo",
|
|
7035
|
+
"csv",
|
|
7036
|
+
"/nh"
|
|
7037
|
+
], {
|
|
7038
|
+
encoding: "utf8",
|
|
7039
|
+
windowsHide: true,
|
|
7040
|
+
stdio: [
|
|
7041
|
+
"ignore",
|
|
7042
|
+
"pipe",
|
|
7043
|
+
"ignore"
|
|
7044
|
+
]
|
|
7045
|
+
});
|
|
7046
|
+
sidCache = /"(S-1-[0-9-]+)"/.exec(out)?.[1];
|
|
7047
|
+
} catch {}
|
|
7048
|
+
return sidCache;
|
|
7049
|
+
}
|
|
7050
|
+
const tmpName = (path) => `${path}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
7051
|
+
const busy = (e) => {
|
|
7052
|
+
const code = e.code;
|
|
7053
|
+
return code === "EPERM" || code === "EACCES" || code === "EBUSY";
|
|
7054
|
+
};
|
|
7055
|
+
/**
|
|
7056
|
+
* Write `body` to `path`, readable by this user only. The file is written next to its final
|
|
7057
|
+
* place, restricted, then renamed over it, so a reader never sees a half-written file or one with
|
|
7058
|
+
* looser permissions (a rename on one volume keeps the ACL). On Windows the temporary file is
|
|
7059
|
+
* restricted while still empty, before the secret is written into it.
|
|
6850
7060
|
*/
|
|
6851
|
-
|
|
7061
|
+
async function writePrivateFile(path, body, o = {}) {
|
|
7062
|
+
const platform = o.platform ?? process.platform;
|
|
7063
|
+
const restrict = o.restrict ?? ((f) => restrictToUser(f, platform));
|
|
7064
|
+
await mkdir(dirname(path), { recursive: true });
|
|
7065
|
+
const tmp = tmpName(path);
|
|
7066
|
+
try {
|
|
7067
|
+
if (platform === "win32") {
|
|
7068
|
+
await writeFile(tmp, "", { flag: "wx" });
|
|
7069
|
+
restrict(tmp);
|
|
7070
|
+
await writeFile(tmp, body);
|
|
7071
|
+
} else {
|
|
7072
|
+
await writeFile(tmp, body, {
|
|
7073
|
+
mode: 384,
|
|
7074
|
+
flag: "wx"
|
|
7075
|
+
});
|
|
7076
|
+
restrict(tmp);
|
|
7077
|
+
}
|
|
7078
|
+
for (let attempt = 0;; attempt++) try {
|
|
7079
|
+
await rename(tmp, path);
|
|
7080
|
+
break;
|
|
7081
|
+
} catch (e) {
|
|
7082
|
+
if (platform !== "win32" || attempt >= 20 || !busy(e)) throw e;
|
|
7083
|
+
await new Promise((r) => setTimeout(r, Math.min(25 * (attempt + 1), 200)));
|
|
7084
|
+
}
|
|
7085
|
+
} catch (e) {
|
|
7086
|
+
await rm(tmp, { force: true });
|
|
7087
|
+
throw e;
|
|
7088
|
+
}
|
|
7089
|
+
}
|
|
7090
|
+
/** {@link writePrivateFile}, synchronously. */
|
|
7091
|
+
function writePrivateFileSync(path, body, o = {}) {
|
|
7092
|
+
const platform = o.platform ?? process.platform;
|
|
7093
|
+
const restrict = o.restrict ?? ((f) => restrictToUser(f, platform));
|
|
7094
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
7095
|
+
const tmp = tmpName(path);
|
|
7096
|
+
try {
|
|
7097
|
+
if (platform === "win32") {
|
|
7098
|
+
writeFileSync(tmp, "", { flag: "wx" });
|
|
7099
|
+
restrict(tmp);
|
|
7100
|
+
writeFileSync(tmp, body);
|
|
7101
|
+
} else {
|
|
7102
|
+
writeFileSync(tmp, body, {
|
|
7103
|
+
mode: 384,
|
|
7104
|
+
flag: "wx"
|
|
7105
|
+
});
|
|
7106
|
+
restrict(tmp);
|
|
7107
|
+
}
|
|
7108
|
+
const wait = new Int32Array(new SharedArrayBuffer(4));
|
|
7109
|
+
for (let attempt = 0;; attempt++) try {
|
|
7110
|
+
renameSync(tmp, path);
|
|
7111
|
+
break;
|
|
7112
|
+
} catch (e) {
|
|
7113
|
+
if (platform !== "win32" || attempt >= 20 || !busy(e)) throw e;
|
|
7114
|
+
Atomics.wait(wait, 0, 0, Math.min(25 * (attempt + 1), 200));
|
|
7115
|
+
}
|
|
7116
|
+
} catch (e) {
|
|
7117
|
+
rmSync(tmp, { force: true });
|
|
7118
|
+
throw e;
|
|
7119
|
+
}
|
|
7120
|
+
}
|
|
6852
7121
|
/** The `client_id` of the device authorization grant. The server accepts only this one. */
|
|
6853
7122
|
const DEVICE_CLIENT_ID = "conveno-cli";
|
|
6854
7123
|
/** Renew an access token this long before it expires, so a request never carries a dead one. */
|
|
@@ -6861,14 +7130,36 @@ var AccountError = class extends Error {
|
|
|
6861
7130
|
this.name = "AccountError";
|
|
6862
7131
|
}
|
|
6863
7132
|
};
|
|
6864
|
-
const
|
|
7133
|
+
const trimBase = (url) => url.replace(/\/+$/, "");
|
|
7134
|
+
const base = (io) => trimBase(io.apiBase ?? "https://api.conveno.dev");
|
|
7135
|
+
/** Where requests carrying these tokens go: the server that issued them, never another one. */
|
|
7136
|
+
const baseFor = (t, io) => t.apiBase ? trimBase(t.apiBase) : base(io);
|
|
6865
7137
|
const doFetch = (io) => io.fetch ?? fetch;
|
|
6866
7138
|
const clock = (io) => (io.now ?? Date.now)();
|
|
6867
7139
|
function isTokens(v) {
|
|
6868
7140
|
if (!v || typeof v !== "object") return false;
|
|
6869
7141
|
const t = v;
|
|
6870
|
-
return typeof t.accessToken === "string" && typeof t.refreshToken === "string" && t.refreshToken.length > 0 && typeof t.expiresAt === "number" && Number.isFinite(t.expiresAt);
|
|
7142
|
+
return typeof t.accessToken === "string" && typeof t.refreshToken === "string" && t.refreshToken.length > 0 && typeof t.expiresAt === "number" && Number.isFinite(t.expiresAt) && (t.apiBase === void 0 || typeof t.apiBase === "string" && t.apiBase.length > 0);
|
|
6871
7143
|
}
|
|
7144
|
+
/**
|
|
7145
|
+
* The account server for a new login: `CONVENO_API_URL`, else {@link ACCOUNT_API}. Every other
|
|
7146
|
+
* request uses {@link signedInAccountApi}.
|
|
7147
|
+
*/
|
|
7148
|
+
const loginAccountApi = (env = process.env) => trimBase(env.CONVENO_API_URL || "https://api.conveno.dev");
|
|
7149
|
+
/**
|
|
7150
|
+
* The account server of the saved login: the one saved in `account.json`, else
|
|
7151
|
+
* `CONVENO_API_URL`, else {@link ACCOUNT_API}. Also the server whose `/account` page the user
|
|
7152
|
+
* should visit.
|
|
7153
|
+
*/
|
|
7154
|
+
function signedInAccountApi(path, env = process.env) {
|
|
7155
|
+
try {
|
|
7156
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
7157
|
+
if (isTokens(parsed) && parsed.apiBase) return trimBase(parsed.apiBase);
|
|
7158
|
+
} catch {}
|
|
7159
|
+
return loginAccountApi(env);
|
|
7160
|
+
}
|
|
7161
|
+
/** The relay the daemon connects to: `CONVENO_RELAY_URL`, else {@link RELAY_URL}. */
|
|
7162
|
+
const relayUrl = (env = process.env) => env.CONVENO_RELAY_URL || "wss://relay.conveno.dev/v1/connect";
|
|
6872
7163
|
/** The saved tokens, or null when the user is not logged in or the file is unreadable. */
|
|
6873
7164
|
async function readAccountTokens(path) {
|
|
6874
7165
|
let text;
|
|
@@ -6884,27 +7175,14 @@ async function readAccountTokens(path) {
|
|
|
6884
7175
|
return null;
|
|
6885
7176
|
}
|
|
6886
7177
|
}
|
|
6887
|
-
/**
|
|
6888
|
-
* Save the tokens, readable by this user only. The file is written next to its final place with
|
|
6889
|
-
* the mode set at creation, then renamed over it, so a reader never sees a half-written file or
|
|
6890
|
-
* one with looser permissions.
|
|
6891
|
-
*/
|
|
7178
|
+
/** Save the tokens, readable by this user only. See {@link writePrivateFile}. */
|
|
6892
7179
|
async function writeAccountTokens(path, tokens) {
|
|
6893
|
-
await
|
|
6894
|
-
const tmp = `${path}.${process.pid}.tmp`;
|
|
6895
|
-
const body = `${JSON.stringify({
|
|
7180
|
+
await writePrivateFile(path, `${JSON.stringify({
|
|
6896
7181
|
accessToken: tokens.accessToken,
|
|
6897
7182
|
refreshToken: tokens.refreshToken,
|
|
6898
|
-
expiresAt: tokens.expiresAt
|
|
6899
|
-
|
|
6900
|
-
|
|
6901
|
-
await writeFile(tmp, body, { mode: 384 });
|
|
6902
|
-
await chmod(tmp, 384);
|
|
6903
|
-
await rename(tmp, path);
|
|
6904
|
-
} catch (e) {
|
|
6905
|
-
await rm(tmp, { force: true });
|
|
6906
|
-
throw e;
|
|
6907
|
-
}
|
|
7183
|
+
expiresAt: tokens.expiresAt,
|
|
7184
|
+
...tokens.apiBase ? { apiBase: tokens.apiBase } : {}
|
|
7185
|
+
}, null, 2)}\n`);
|
|
6908
7186
|
}
|
|
6909
7187
|
/** Delete the saved tokens. Returns whether there was a file. */
|
|
6910
7188
|
async function clearAccountTokens(path) {
|
|
@@ -6958,8 +7236,12 @@ async function refreshAccountTokens(path, io = {}) {
|
|
|
6958
7236
|
const current = await readAccountTokens(path);
|
|
6959
7237
|
if (!current) throw new AccountError("not_logged_in", "Not logged in. Run conveno login.");
|
|
6960
7238
|
const next = {
|
|
6961
|
-
...await requestAccessToken(current.refreshToken,
|
|
6962
|
-
|
|
7239
|
+
...await requestAccessToken(current.refreshToken, {
|
|
7240
|
+
...io,
|
|
7241
|
+
apiBase: baseFor(current, io)
|
|
7242
|
+
}),
|
|
7243
|
+
refreshToken: current.refreshToken,
|
|
7244
|
+
...current.apiBase ? { apiBase: current.apiBase } : {}
|
|
6963
7245
|
};
|
|
6964
7246
|
await writeAccountTokens(path, next);
|
|
6965
7247
|
return next;
|
|
@@ -6990,7 +7272,7 @@ async function devicePost(path, route, deviceId, io) {
|
|
|
6990
7272
|
const tokens = await readAccountTokens(path);
|
|
6991
7273
|
if (!tokens) throw new AccountError("not_logged_in", "Not logged in. Run conveno login.");
|
|
6992
7274
|
try {
|
|
6993
|
-
return await doFetch(io)(`${
|
|
7275
|
+
return await doFetch(io)(`${baseFor(tokens, io)}/api/device/${route}`, {
|
|
6994
7276
|
method: "POST",
|
|
6995
7277
|
headers: {
|
|
6996
7278
|
authorization: `Bearer ${tokens.refreshToken}`,
|
|
@@ -7097,11 +7379,15 @@ async function pollDeviceCode(code, o = {}) {
|
|
|
7097
7379
|
}
|
|
7098
7380
|
}
|
|
7099
7381
|
}
|
|
7100
|
-
/**
|
|
7382
|
+
/**
|
|
7383
|
+
* After approval: keep the session token as the refresh token and get a first access token. The
|
|
7384
|
+
* account server is saved with them, so later requests go back to it.
|
|
7385
|
+
*/
|
|
7101
7386
|
async function completeLogin(path, sessionToken, io = {}) {
|
|
7102
7387
|
const tokens = {
|
|
7103
7388
|
...await requestAccessToken(sessionToken, io),
|
|
7104
|
-
refreshToken: sessionToken
|
|
7389
|
+
refreshToken: sessionToken,
|
|
7390
|
+
apiBase: base(io)
|
|
7105
7391
|
};
|
|
7106
7392
|
await writeAccountTokens(path, tokens);
|
|
7107
7393
|
return tokens;
|
|
@@ -7113,18 +7399,21 @@ async function completeLogin(path, sessionToken, io = {}) {
|
|
|
7113
7399
|
async function logoutAccount(path, io = {}) {
|
|
7114
7400
|
const tokens = await readAccountTokens(path);
|
|
7115
7401
|
let revoked = false;
|
|
7116
|
-
if (tokens)
|
|
7117
|
-
const
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7122
|
-
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7402
|
+
if (tokens) {
|
|
7403
|
+
const server = baseFor(tokens, io);
|
|
7404
|
+
try {
|
|
7405
|
+
const res = await doFetch(io)(`${server}/api/auth/sign-out`, {
|
|
7406
|
+
...json({}),
|
|
7407
|
+
headers: {
|
|
7408
|
+
"content-type": "application/json",
|
|
7409
|
+
authorization: `Bearer ${tokens.refreshToken}`,
|
|
7410
|
+
origin: server
|
|
7411
|
+
}
|
|
7412
|
+
});
|
|
7413
|
+
revoked = res.ok || res.status === 401;
|
|
7414
|
+
} catch {
|
|
7415
|
+
revoked = false;
|
|
7416
|
+
}
|
|
7128
7417
|
}
|
|
7129
7418
|
const removed = await clearAccountTokens(path);
|
|
7130
7419
|
return {
|
|
@@ -7190,7 +7479,9 @@ function dataPaths(platform, dir) {
|
|
|
7190
7479
|
/** Conveno account tokens from `conveno login`, mode 0600. See account.ts. */
|
|
7191
7480
|
account: p.join(dir, "account.json"),
|
|
7192
7481
|
/** Choices the user made, such as whether ACP adapters may be fetched with npx. See settings.ts. */
|
|
7193
|
-
settings: p.join(dir, "settings.json")
|
|
7482
|
+
settings: p.join(dir, "settings.json"),
|
|
7483
|
+
/** The models and effort levels each CLI offered its last worker. See worker-models.ts. */
|
|
7484
|
+
workerModels: p.join(dir, "worker-models.json")
|
|
7194
7485
|
};
|
|
7195
7486
|
}
|
|
7196
7487
|
/** Best effort: deletes the markers in `dir` not touched for `ASKED_MAX_AGE_MS`. */
|
|
@@ -7566,20 +7857,20 @@ function parseCliVersion(output) {
|
|
|
7566
7857
|
}
|
|
7567
7858
|
var clis = {
|
|
7568
7859
|
"claude": {
|
|
7569
|
-
"verified": "2.1.
|
|
7860
|
+
"verified": "2.1.335",
|
|
7570
7861
|
"minimum": "2.1.139"
|
|
7571
7862
|
},
|
|
7572
|
-
"codex": { "verified": "0.
|
|
7573
|
-
"opencode": { "verified": "2.4.
|
|
7863
|
+
"codex": { "verified": "0.173.0" },
|
|
7864
|
+
"opencode": { "verified": "2.4.4" },
|
|
7574
7865
|
"antigravity": {
|
|
7575
|
-
"verified": "1.5.
|
|
7866
|
+
"verified": "1.5.22",
|
|
7576
7867
|
"minimum": "1.5.8"
|
|
7577
7868
|
},
|
|
7578
|
-
"grok": { "verified": "1.0.
|
|
7869
|
+
"grok": { "verified": "1.0.100" }
|
|
7579
7870
|
};
|
|
7580
7871
|
var acpAdapters = {
|
|
7581
|
-
"@agentclientprotocol/codex-acp": "2.
|
|
7582
|
-
"@agentclientprotocol/claude-agent-acp": "0.
|
|
7872
|
+
"@agentclientprotocol/codex-acp": "2.12.0",
|
|
7873
|
+
"@agentclientprotocol/claude-agent-acp": "0.112.0"
|
|
7583
7874
|
};
|
|
7584
7875
|
/**
|
|
7585
7876
|
* Versions per CLI, from `compat.json`. The nightly compat workflow raises `verified` when a newer
|
|
@@ -8463,7 +8754,7 @@ function statusAfterLiveness(current, verdict) {
|
|
|
8463
8754
|
return current;
|
|
8464
8755
|
}
|
|
8465
8756
|
const isOnline = (s) => s.status !== "offline";
|
|
8466
|
-
const MAX_NAME = 64;
|
|
8757
|
+
const MAX_NAME$1 = 64;
|
|
8467
8758
|
/** Make a directory name safe to embed in a session name: lowercase, `[a-z0-9._-]`, non-empty. */
|
|
8468
8759
|
function sanitizeNamePart(raw) {
|
|
8469
8760
|
const cleaned = raw.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[^a-z0-9]+/, "").replace(/-+$/, "");
|
|
@@ -8478,7 +8769,7 @@ function generateSessionName(cli, repoBasename, sessions) {
|
|
|
8478
8769
|
const prefix = `${cli}@`;
|
|
8479
8770
|
for (let n = 1;; n++) {
|
|
8480
8771
|
const suffix = `-${n}`;
|
|
8481
|
-
const room = MAX_NAME - prefix.length - suffix.length;
|
|
8772
|
+
const room = MAX_NAME$1 - prefix.length - suffix.length;
|
|
8482
8773
|
const name = `${prefix}${sanitizeNamePart(repoBasename).slice(0, room)}${suffix}`;
|
|
8483
8774
|
if (!taken.has(name)) return name;
|
|
8484
8775
|
}
|
|
@@ -8592,95 +8883,6 @@ function pendingTurn(dir, folder) {
|
|
|
8592
8883
|
}
|
|
8593
8884
|
};
|
|
8594
8885
|
}
|
|
8595
|
-
const defaultIsFile = (path) => {
|
|
8596
|
-
try {
|
|
8597
|
-
return statSync(path).isFile();
|
|
8598
|
-
} catch {
|
|
8599
|
-
return false;
|
|
8600
|
-
}
|
|
8601
|
-
};
|
|
8602
|
-
/** Environment variable lookup that ignores case, as Windows does (`Path`, `PATH`, `PathExt`). */
|
|
8603
|
-
function envGet(env, name) {
|
|
8604
|
-
const want = name.toLowerCase();
|
|
8605
|
-
for (const [k, v] of Object.entries(env)) if (k.toLowerCase() === want && v !== void 0) return v;
|
|
8606
|
-
}
|
|
8607
|
-
const DEFAULT_PATHEXT = ".COM;.EXE;.BAT;.CMD";
|
|
8608
|
-
/** Only these can be started safely: other PATHEXT entries (.JS, .VBS) open Windows Script Host. */
|
|
8609
|
-
const LAUNCHABLE = /* @__PURE__ */ new Set([
|
|
8610
|
-
".com",
|
|
8611
|
-
".exe",
|
|
8612
|
-
".bat",
|
|
8613
|
-
".cmd"
|
|
8614
|
-
]);
|
|
8615
|
-
/**
|
|
8616
|
-
* Find `command` the way cmd.exe does: each PATH directory in order, each PATHEXT extension in
|
|
8617
|
-
* order. A name that already ends in a launchable extension is tried as written first. Returns
|
|
8618
|
-
* undefined when nothing matches.
|
|
8619
|
-
*/
|
|
8620
|
-
function resolveWindowsCommand(command, env, isFile = defaultIsFile) {
|
|
8621
|
-
const exts = (envGet(env, "PATHEXT") ?? DEFAULT_PATHEXT).split(";").map((e) => e.trim()).filter((e) => LAUNCHABLE.has(e.toLowerCase()));
|
|
8622
|
-
const own = win32.extname(command).toLowerCase();
|
|
8623
|
-
const candidatesIn = (base) => [...LAUNCHABLE.has(own) ? [base] : [], ...exts.map((e) => base + e)];
|
|
8624
|
-
const dirs = /[\\/]/.test(command) || win32.isAbsolute(command) ? [""] : (envGet(env, "PATH") ?? "").split(";").map((d) => d.trim().replace(/^"(.*)"$/, "$1")).filter(Boolean);
|
|
8625
|
-
for (const dir of dirs) for (const candidate of candidatesIn(dir === "" ? command : win32.join(dir, command))) if (isFile(candidate)) return candidate;
|
|
8626
|
-
}
|
|
8627
|
-
/** Characters cmd.exe treats specially, plus the ones cross-spawn escapes defensively. */
|
|
8628
|
-
const CMD_META = /([()\][%!^"`<>&|;, *?])/g;
|
|
8629
|
-
/** The program name part of a cmd.exe command line: escape only, never wrap in quotes. */
|
|
8630
|
-
function escapeCmdCommand(command) {
|
|
8631
|
-
return command.replace(CMD_META, "^$1");
|
|
8632
|
-
}
|
|
8633
|
-
/**
|
|
8634
|
-
* Quote one argument for a `cmd.exe /d /s /c "..."` command line, the way cross-spawn does:
|
|
8635
|
-
* make it safe for the program's own parser (backslashes before a quote are doubled, the quote
|
|
8636
|
-
* is backslash-escaped, the whole thing is wrapped in quotes), then caret-escape every
|
|
8637
|
-
* character cmd.exe would act on, including the quotes themselves.
|
|
8638
|
-
*/
|
|
8639
|
-
function escapeCmdArg(arg) {
|
|
8640
|
-
let a = `${arg}`;
|
|
8641
|
-
a = a.replace(/(\\*)"/g, "$1$1\\\"");
|
|
8642
|
-
a = a.replace(/(\\*)$/, "$1$1");
|
|
8643
|
-
a = `"${a}"`;
|
|
8644
|
-
return a.replace(CMD_META, "^$1");
|
|
8645
|
-
}
|
|
8646
|
-
/** `cmd.exe /d /s /c "<command line>"` for a .cmd or .bat file. */
|
|
8647
|
-
function cmdShimPlan(file, args, env) {
|
|
8648
|
-
const line = [escapeCmdCommand(file), ...args.map(escapeCmdArg)].join(" ");
|
|
8649
|
-
return {
|
|
8650
|
-
file: envGet(env, "ComSpec") || "cmd.exe",
|
|
8651
|
-
args: [
|
|
8652
|
-
"/d",
|
|
8653
|
-
"/s",
|
|
8654
|
-
"/c",
|
|
8655
|
-
`"${line}"`
|
|
8656
|
-
],
|
|
8657
|
-
windowsVerbatimArguments: true
|
|
8658
|
-
};
|
|
8659
|
-
}
|
|
8660
|
-
/**
|
|
8661
|
-
* What to spawn for `command args...`. On Windows the command is resolved on PATH: .exe and .com
|
|
8662
|
-
* run directly, .cmd and .bat (npm shims) go through cmd.exe with one quoted command line. Never
|
|
8663
|
-
* uses a shell option with an args array. Elsewhere, and when nothing is found, the command is
|
|
8664
|
-
* returned unchanged so the caller sees the normal ENOENT.
|
|
8665
|
-
*/
|
|
8666
|
-
function planSpawn(command, args, opts = {}) {
|
|
8667
|
-
if ((opts.platform ?? process.platform) !== "win32") return {
|
|
8668
|
-
file: command,
|
|
8669
|
-
args
|
|
8670
|
-
};
|
|
8671
|
-
const env = opts.env ?? process.env;
|
|
8672
|
-
const found = resolveWindowsCommand(command, env, opts.isFile);
|
|
8673
|
-
if (!found) return {
|
|
8674
|
-
file: command,
|
|
8675
|
-
args
|
|
8676
|
-
};
|
|
8677
|
-
const ext = win32.extname(found).toLowerCase();
|
|
8678
|
-
if (ext === ".cmd" || ext === ".bat") return cmdShimPlan(found, args, env);
|
|
8679
|
-
return {
|
|
8680
|
-
file: found,
|
|
8681
|
-
args
|
|
8682
|
-
};
|
|
8683
|
-
}
|
|
8684
8886
|
function exec(file, args, timeoutMs) {
|
|
8685
8887
|
const plan = planSpawn(file, args);
|
|
8686
8888
|
return new Promise((resolve) => {
|
|
@@ -9225,6 +9427,153 @@ function accessAllows(access, call) {
|
|
|
9225
9427
|
if (access === "full") return true;
|
|
9226
9428
|
return isAllowed(accessRules(access), call) || call.kind === "execute" && isSafeReadCommand(call.title ?? "");
|
|
9227
9429
|
}
|
|
9430
|
+
const MAX_NAME = 200;
|
|
9431
|
+
const CONTROL = /\p{Cc}/u;
|
|
9432
|
+
/**
|
|
9433
|
+
* A model or effort name as given by a person or an agent: trimmed, non-empty, bounded, with no
|
|
9434
|
+
* control characters (it ends up on a command line and in a terminal).
|
|
9435
|
+
*/
|
|
9436
|
+
function cleanModelName(v) {
|
|
9437
|
+
if (typeof v !== "string") return void 0;
|
|
9438
|
+
const s = v.trim();
|
|
9439
|
+
return s.length > 0 && s.length <= MAX_NAME && !CONTROL.test(s) ? s : void 0;
|
|
9440
|
+
}
|
|
9441
|
+
/**
|
|
9442
|
+
* One item of a menu a CLI offered: a value with a control character is dropped, a name has them
|
|
9443
|
+
* taken out (and falls back to the value when nothing is left).
|
|
9444
|
+
*/
|
|
9445
|
+
function menuItem(value, name) {
|
|
9446
|
+
if (typeof value !== "string" || value === "" || CONTROL.test(value)) return void 0;
|
|
9447
|
+
const shown = typeof name === "string" ? name.replace(/\p{Cc}+/gu, " ").trim() : "";
|
|
9448
|
+
return {
|
|
9449
|
+
value,
|
|
9450
|
+
name: shown === "" ? value : shown
|
|
9451
|
+
};
|
|
9452
|
+
}
|
|
9453
|
+
/** Parse the `workerModels` settings value; anything malformed is dropped. */
|
|
9454
|
+
function parseWorkerModels(v) {
|
|
9455
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return {};
|
|
9456
|
+
const out = {};
|
|
9457
|
+
for (const cli of CLI_KINDS) {
|
|
9458
|
+
const c = v[cli];
|
|
9459
|
+
if (typeof c !== "object" || c === null) continue;
|
|
9460
|
+
const model = cleanModelName(c.model);
|
|
9461
|
+
const effort = cleanModelName(c.effort);
|
|
9462
|
+
if (model || effort) out[cli] = {
|
|
9463
|
+
...model ? { model } : {},
|
|
9464
|
+
...effort ? { effort } : {}
|
|
9465
|
+
};
|
|
9466
|
+
}
|
|
9467
|
+
return out;
|
|
9468
|
+
}
|
|
9469
|
+
/** The worker's model and effort: each field from the request, else the user's default. */
|
|
9470
|
+
function resolveWorkerModel(requested, defaults) {
|
|
9471
|
+
const model = cleanModelName(requested?.model) ?? cleanModelName(defaults?.model);
|
|
9472
|
+
const effort = cleanModelName(requested?.effort) ?? cleanModelName(defaults?.effort);
|
|
9473
|
+
return {
|
|
9474
|
+
...model ? { model } : {},
|
|
9475
|
+
...effort ? { effort } : {}
|
|
9476
|
+
};
|
|
9477
|
+
}
|
|
9478
|
+
const MODEL_IDS = ["model"];
|
|
9479
|
+
const EFFORT_IDS = [
|
|
9480
|
+
"effort",
|
|
9481
|
+
"reasoning_effort",
|
|
9482
|
+
"thought_level"
|
|
9483
|
+
];
|
|
9484
|
+
/** The ACP session config option for `kind`: by category, else by a known id. */
|
|
9485
|
+
function findModelOption(options, kind) {
|
|
9486
|
+
if (!Array.isArray(options)) return void 0;
|
|
9487
|
+
const list = options;
|
|
9488
|
+
const category = kind === "model" ? "model" : "thought_level";
|
|
9489
|
+
const ids = kind === "model" ? MODEL_IDS : EFFORT_IDS;
|
|
9490
|
+
const o = list.find((x) => x?.category === category) ?? list.find((x) => typeof x?.id === "string" && ids.includes(x.id));
|
|
9491
|
+
if (!o || typeof o.id !== "string") return void 0;
|
|
9492
|
+
const flat = (Array.isArray(o.options) ? o.options : []).flatMap((x) => {
|
|
9493
|
+
const item = x;
|
|
9494
|
+
return Array.isArray(item?.options) ? item.options : [x];
|
|
9495
|
+
});
|
|
9496
|
+
const values = [];
|
|
9497
|
+
for (const x of flat) {
|
|
9498
|
+
const item = menuItem(x?.value, x?.name);
|
|
9499
|
+
if (item) values.push(item);
|
|
9500
|
+
}
|
|
9501
|
+
return {
|
|
9502
|
+
id: o.id,
|
|
9503
|
+
...typeof o.currentValue === "string" && !CONTROL.test(o.currentValue) ? { current: o.currentValue } : {},
|
|
9504
|
+
values
|
|
9505
|
+
};
|
|
9506
|
+
}
|
|
9507
|
+
/** The menu a CLI offers, from its ACP session config options. */
|
|
9508
|
+
function menuFromConfigOptions(options, at) {
|
|
9509
|
+
const m = findModelOption(options, "model");
|
|
9510
|
+
const e = findModelOption(options, "effort");
|
|
9511
|
+
return {
|
|
9512
|
+
models: m?.values ?? [],
|
|
9513
|
+
efforts: e?.values ?? [],
|
|
9514
|
+
current: {
|
|
9515
|
+
...m?.current ? { model: m.current } : {},
|
|
9516
|
+
...e?.current ? { effort: e.current } : {}
|
|
9517
|
+
},
|
|
9518
|
+
at
|
|
9519
|
+
};
|
|
9520
|
+
}
|
|
9521
|
+
/** Short label for a card: `sonnet · high`, or undefined when nothing is known. */
|
|
9522
|
+
function modelLabel(c) {
|
|
9523
|
+
const parts = [c?.model, c?.effort].filter((x) => !!x);
|
|
9524
|
+
return parts.length > 0 ? parts.join(" · ") : void 0;
|
|
9525
|
+
}
|
|
9526
|
+
function parseItems(v) {
|
|
9527
|
+
if (!Array.isArray(v)) return [];
|
|
9528
|
+
return v.flatMap((x) => {
|
|
9529
|
+
if (typeof x !== "object" || x === null) return [];
|
|
9530
|
+
const item = menuItem(x.value, x.name);
|
|
9531
|
+
return item ? [item] : [];
|
|
9532
|
+
});
|
|
9533
|
+
}
|
|
9534
|
+
/** Read the remembered menus (`dataPaths(...).workerModels`). Missing or malformed: none. */
|
|
9535
|
+
function readModelMenus(path) {
|
|
9536
|
+
try {
|
|
9537
|
+
const v = JSON.parse(readFileSync(path, "utf8"));
|
|
9538
|
+
if (typeof v !== "object" || v === null) return {};
|
|
9539
|
+
const out = {};
|
|
9540
|
+
for (const cli of CLI_KINDS) {
|
|
9541
|
+
const m = v[cli];
|
|
9542
|
+
if (typeof m !== "object" || m === null) continue;
|
|
9543
|
+
const cur = m.current ?? {};
|
|
9544
|
+
const model = cleanModelName(cur.model);
|
|
9545
|
+
const effort = cleanModelName(cur.effort);
|
|
9546
|
+
out[cli] = {
|
|
9547
|
+
models: parseItems(m.models),
|
|
9548
|
+
efforts: parseItems(m.efforts),
|
|
9549
|
+
current: {
|
|
9550
|
+
...model ? { model } : {},
|
|
9551
|
+
...effort ? { effort } : {}
|
|
9552
|
+
},
|
|
9553
|
+
at: typeof m.at === "string" ? m.at : ""
|
|
9554
|
+
};
|
|
9555
|
+
}
|
|
9556
|
+
return out;
|
|
9557
|
+
} catch {
|
|
9558
|
+
return {};
|
|
9559
|
+
}
|
|
9560
|
+
}
|
|
9561
|
+
/** Remember the menu of one CLI. Written atomically; failures are ignored (it is a cache). */
|
|
9562
|
+
function writeModelMenu(path, cli, menu) {
|
|
9563
|
+
try {
|
|
9564
|
+
const all = {
|
|
9565
|
+
...readModelMenus(path),
|
|
9566
|
+
[cli]: menu
|
|
9567
|
+
};
|
|
9568
|
+
mkdirSync(dirname(path), {
|
|
9569
|
+
recursive: true,
|
|
9570
|
+
mode: 448
|
|
9571
|
+
});
|
|
9572
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
9573
|
+
writeFileSync(tmp, `${JSON.stringify(all, null, 2)}\n`, { mode: 384 });
|
|
9574
|
+
renameSync(tmp, path);
|
|
9575
|
+
} catch {}
|
|
9576
|
+
}
|
|
9228
9577
|
const WORKER_UNANSWERED = ["deny", "allow"];
|
|
9229
9578
|
/** What workers may do, with the default when it was never chosen. */
|
|
9230
9579
|
function workerAccessOf(s) {
|
|
@@ -9254,7 +9603,8 @@ function readSettings(path) {
|
|
|
9254
9603
|
...typeof o.wakeBeforeFirstPrompt === "boolean" ? { wakeBeforeFirstPrompt: o.wakeBeforeFirstPrompt } : {},
|
|
9255
9604
|
...typeof o.workerAccess === "string" && parseWorkerAccess(o.workerAccess) ? { workerAccess: parseWorkerAccess(o.workerAccess) } : {},
|
|
9256
9605
|
...WORKER_ASK_TIMEOUT_CHOICES.includes(o.workerAskTimeoutSec) ? { workerAskTimeoutSec: o.workerAskTimeoutSec } : {},
|
|
9257
|
-
...WORKER_UNANSWERED.includes(o.workerUnanswered) ? { workerUnanswered: o.workerUnanswered } : {}
|
|
9606
|
+
...WORKER_UNANSWERED.includes(o.workerUnanswered) ? { workerUnanswered: o.workerUnanswered } : {},
|
|
9607
|
+
...Object.keys(parseWorkerModels(o.workerModels)).length > 0 ? { workerModels: parseWorkerModels(o.workerModels) } : {}
|
|
9258
9608
|
};
|
|
9259
9609
|
} catch {
|
|
9260
9610
|
return {};
|
|
@@ -9411,6 +9761,13 @@ const recordFiles = (dataDir) => {
|
|
|
9411
9761
|
return [];
|
|
9412
9762
|
}
|
|
9413
9763
|
};
|
|
9764
|
+
/** The record of the worker whose host registered `sessionId`, whatever its file is named. */
|
|
9765
|
+
function spawnRecordOfSession(dataDir, sessionId) {
|
|
9766
|
+
for (const path of recordFiles(dataDir)) {
|
|
9767
|
+
const rec = readSpawnRecord(path);
|
|
9768
|
+
if (rec?.sessionId === sessionId) return rec;
|
|
9769
|
+
}
|
|
9770
|
+
}
|
|
9414
9771
|
/**
|
|
9415
9772
|
* Records of spawned sessions that are still running. Records of sessions that ended are deleted
|
|
9416
9773
|
* as they are found.
|
|
@@ -9490,7 +9847,10 @@ function decodeAcpLaunchSpec(text) {
|
|
|
9490
9847
|
} } : {},
|
|
9491
9848
|
askTimeoutMs: typeof o.askTimeoutMs === "number" && o.askTimeoutMs > 0 ? o.askTimeoutMs : 12e4,
|
|
9492
9849
|
...o.unanswered === "allow" || o.unanswered === "deny" ? { unanswered: o.unanswered } : {},
|
|
9493
|
-
...typeof o.setupTimeoutMs === "number" && o.setupTimeoutMs > 0 ? { setupTimeoutMs: o.setupTimeoutMs } : {}
|
|
9850
|
+
...typeof o.setupTimeoutMs === "number" && o.setupTimeoutMs > 0 ? { setupTimeoutMs: o.setupTimeoutMs } : {},
|
|
9851
|
+
...cleanModelName(o.model) ? { model: cleanModelName(o.model) } : {},
|
|
9852
|
+
...cleanModelName(o.effort) ? { effort: cleanModelName(o.effort) } : {},
|
|
9853
|
+
...typeof o.modelMenuPath === "string" && o.modelMenuPath !== "" ? { modelMenuPath: o.modelMenuPath } : {}
|
|
9494
9854
|
};
|
|
9495
9855
|
}
|
|
9496
9856
|
/** Write an ACP launch file readable by the owner only. */
|
|
@@ -9767,6 +10127,7 @@ function realSpawnDeps(opts) {
|
|
|
9767
10127
|
which: (name) => findOnPath(name, env, platform, platform === "win32" ? entryExists : void 0),
|
|
9768
10128
|
acpNpxConsent: () => readSettings(dataPaths(platform, opts.dataDir).settings).acpAdapterNpx === true,
|
|
9769
10129
|
workerAccess: () => readSettings(dataPaths(platform, opts.dataDir).settings).workerAccess,
|
|
10130
|
+
workerModels: () => readSettings(dataPaths(platform, opts.dataDir).settings).workerModels,
|
|
9770
10131
|
workerUnanswered: () => readSettings(dataPaths(platform, opts.dataDir).settings).workerUnanswered ?? "deny",
|
|
9771
10132
|
workerAskTimeoutSec: () => workerAskTimeoutOf(readSettings(dataPaths(platform, opts.dataDir).settings)),
|
|
9772
10133
|
repoExists: existsSync,
|
|
@@ -9849,6 +10210,7 @@ const SPAWN_TABLE = {
|
|
|
9849
10210
|
claude: {
|
|
9850
10211
|
binaries: ["claude"],
|
|
9851
10212
|
interactive: (task) => task === void 0 ? [] : [task],
|
|
10213
|
+
modelArgs: (c) => [...c.model ? ["--model", c.model] : [], ...c.effort ? ["--effort", c.effort] : []],
|
|
9852
10214
|
interactivePrompt: true,
|
|
9853
10215
|
docs: ["https://code.claude.com/docs/en/cli-reference (claude \"query\")"],
|
|
9854
10216
|
acp: {
|
|
@@ -9867,6 +10229,7 @@ const SPAWN_TABLE = {
|
|
|
9867
10229
|
codex: {
|
|
9868
10230
|
binaries: ["codex"],
|
|
9869
10231
|
interactive: (task) => task === void 0 ? [] : [task],
|
|
10232
|
+
modelArgs: (c) => [...c.model ? ["-m", c.model] : [], ...c.effort ? ["-c", `model_reasoning_effort=${c.effort}`] : []],
|
|
9870
10233
|
interactivePrompt: true,
|
|
9871
10234
|
docs: ["https://developers.openai.com/codex/cli/reference (codex [PROMPT])", "reference/src/codex/codex-rs/tui/src/cli.rs (the optional PROMPT argument)"],
|
|
9872
10235
|
acp: {
|
|
@@ -9889,6 +10252,7 @@ const SPAWN_TABLE = {
|
|
|
9889
10252
|
opencode: {
|
|
9890
10253
|
binaries: ["opencode"],
|
|
9891
10254
|
interactive: (task) => task === void 0 ? [] : ["--prompt", task],
|
|
10255
|
+
modelArgs: (c) => c.model ? ["-m", c.model] : [],
|
|
9892
10256
|
interactivePrompt: true,
|
|
9893
10257
|
docs: ["https://opencode.ai/docs/cli/ (the TUI --prompt flag)", "reference/src/opencode/packages/cli/src/commands/commands.ts at v2.4.3 (--prompt)"],
|
|
9894
10258
|
acp: {
|
|
@@ -9906,6 +10270,7 @@ const SPAWN_TABLE = {
|
|
|
9906
10270
|
antigravity: {
|
|
9907
10271
|
binaries: ["agy"],
|
|
9908
10272
|
interactive: () => [],
|
|
10273
|
+
modelArgs: (c) => [...c.model ? ["--model", c.model] : [], ...c.effort ? ["--effort", c.effort] : []],
|
|
9909
10274
|
interactivePrompt: false,
|
|
9910
10275
|
docs: ["https://antigravity.google/docs/cli/acp (agy)"],
|
|
9911
10276
|
acp: {
|
|
@@ -9923,6 +10288,7 @@ const SPAWN_TABLE = {
|
|
|
9923
10288
|
grok: {
|
|
9924
10289
|
binaries: ["grok"],
|
|
9925
10290
|
interactive: (task) => task === void 0 ? [] : [task],
|
|
10291
|
+
modelArgs: (c) => [...c.model ? ["-m", c.model] : [], ...c.effort ? ["--reasoning-effort", c.effort] : []],
|
|
9926
10292
|
interactivePrompt: true,
|
|
9927
10293
|
docs: ["reference/src/grok-build/crates/codegen/xai-grok-pager/src/app/cli.rs (prompt)"],
|
|
9928
10294
|
acp: {
|
|
@@ -9945,10 +10311,10 @@ function safePrompt(task) {
|
|
|
9945
10311
|
return task.startsWith("-") ? `Task: ${task}` : task;
|
|
9946
10312
|
}
|
|
9947
10313
|
/** Arguments (after the program) for a window spawn: the interactive CLI, with the first task. */
|
|
9948
|
-
function buildCliArgs(cli, task) {
|
|
10314
|
+
function buildCliArgs(cli, task, choice = {}) {
|
|
9949
10315
|
const spec = SPAWN_TABLE[cli];
|
|
9950
10316
|
if (!spec) throw new Error(`No spawn entry for "${cli}".`);
|
|
9951
|
-
return spec.interactive(spec.interactivePrompt && task !== void 0 ? safePrompt(task) : void 0);
|
|
10317
|
+
return [...spec.modelArgs?.(choice) ?? [], ...spec.interactive(spec.interactivePrompt && task !== void 0 ? safePrompt(task) : void 0)];
|
|
9952
10318
|
}
|
|
9953
10319
|
const NO_TERMINAL_FIX = "Run the session in the background (drop --window), or start the CLI yourself.";
|
|
9954
10320
|
/** Linux terminals, in the order tried. Each says how to run a program in a directory. */
|
|
@@ -10207,7 +10573,12 @@ async function spawnSession(deps, req) {
|
|
|
10207
10573
|
}))];
|
|
10208
10574
|
const repo = await detectRepo(cwd, { exists: deps.repoExists });
|
|
10209
10575
|
const name = req.name !== void 0 ? validateRename(newSessionId(), req.name, named) : generateSessionName(kind.data, repo.basename, named);
|
|
10210
|
-
const
|
|
10576
|
+
const chosen = resolveWorkerModel({
|
|
10577
|
+
model: req.model,
|
|
10578
|
+
effort: req.effort
|
|
10579
|
+
}, deps.workerModels?.()?.[cli]);
|
|
10580
|
+
if (window && [chosen.model, chosen.effort].some((v) => v?.startsWith("-"))) throw new SpawnError("A model or effort name cannot start with a dash in a window, the CLI would read it as a flag.");
|
|
10581
|
+
const plan = planProgram(program, window ? buildCliArgs(cli, task, chosen) : [...acpRun?.args ?? [], ...spec.acp?.args ?? []], {
|
|
10211
10582
|
platform: deps.platform,
|
|
10212
10583
|
env: deps.env
|
|
10213
10584
|
});
|
|
@@ -10257,6 +10628,9 @@ async function spawnSession(deps, req) {
|
|
|
10257
10628
|
},
|
|
10258
10629
|
unanswered: deps.workerUnanswered?.() === "allow" ? "allow" : "deny",
|
|
10259
10630
|
askTimeoutMs: (deps.workerAskTimeoutSec?.() ?? 120) * 1e3,
|
|
10631
|
+
...chosen.model ? { model: chosen.model } : {},
|
|
10632
|
+
...chosen.effort ? { effort: chosen.effort } : {},
|
|
10633
|
+
modelMenuPath: dataPaths(deps.platform, deps.dataDir).workerModels,
|
|
10260
10634
|
...acpRun?.source.startsWith("npx:") ? { setupTimeoutMs: NPX_SETUP_TIMEOUT_MS } : {}
|
|
10261
10635
|
});
|
|
10262
10636
|
run = await deps.launchBackground({
|
|
@@ -10384,4 +10758,4 @@ async function waitForRegistration(deps, w) {
|
|
|
10384
10758
|
await deps.sleep(250);
|
|
10385
10759
|
}
|
|
10386
10760
|
}
|
|
10387
|
-
export {
|
|
10761
|
+
export { findModelOption as $, defaultSocketPath as $n, realSpawnDeps as $t, claimOrchestrator as A, workerAskTimeoutOf as An, parseCliVersion as At, daemonProof as B, EventPayload as Bn, planProgram as Bt, askedKey as C, turnHops as Cn, markDelivered as Ct, autoLimitsFromEnv as D, waitForWork as Dn, newAuthNonce as Dt, autoCandidates as E, validateRename as En, needsQuoting as Et, compareVersions as F, CLI_KINDS as Fn, pendingHookContext as Ft, detectRepo as G, RELAY_CLIENT_NAME as Gn, readAccountTokens as Gt, dataPaths as H, MessageId as Hn, pollDeviceCode as Ht, compatStatus as I, CliKind as In, pendingTurn as It, effectiveHolder as J, RpcResponse as Jn, readInbox as Jt, dropFromList as K, RelayPayload as Kn, readAncestry as Kt, completeLogin as L, DeviceId as Ln, pidAlive as Lt, cleanModelName as M, writeModelMenu as Mn, parsePs1ShimTarget as Mt, clearOrchestrator as N, writePrivateFileSync as Nn, parseWorkerAccess as Nt, baseName as O, waitForWorkBatch as On, oneWindowPerHost as Ot, clientProof as P, writeSettings as Pn, pendingForInjection as Pt, fetchAccountStatus as Q, createLineDecoder as Qn, readSpawnRecord as Qt, createWmiWalker as R, EVENT_NAMES as Rn, pinnedAdapter as Rt, appendHookLog as S, tooManyUnreadMessage as Sn, logoutAccount as St, attachAcpSession as T, updateSpawnRecord as Tn, modelLabel as Tt, decideAutoContinue as U, OWNER_SESSION_ID as Un, proofsMatch as Ut, dataDir as V, Message as Vn, planSpawn as Vt, defaultProcessIo as W, PROTOCOL_VERSION as Wn, putInList as Wt, evaluateLiveness as X, SESSION_NAME_PATTERN as Xn, readProcessList as Xt, endTurnContinuation as Y, SESSION_ENDED_TEXT as Yn, readModelMenus as Yt, existedBefore as Z, SessionId as Zn, readSettings as Zt, ackEntries as _, startTurnContext as _n, discriminatedUnion as _r, launcherText as _t, HEARTBEAT_INTERVAL_MS as a, resolveAcpProgram as an, makeResult as ar, holderAfterDeparture as at, adapterNpxCommand as b, takeWithinBytes as bn, object as br, loadJson as bt, ORCHESTRATOR_TASK_NOTICE as c, restrictToUser as cn, newSessionId as cr, hostAlive as ct, SPAWN_TABLE as d, sameJson as dn, safeParse as dr, isFromOwner as dt, relayUrl as en, encodeFrame as er, findOnPath as et, SpawnError as f, senderOf as fn, sanitizeLine as fr, isObject as ft, accessAllows as g, spawnSession as gn, boolean as gr, launcherPath as gt, WORKER_UNANSWERED as h, spawnRecordPath as hn, array as hr, late as ht, FROM_USER_NOTICE as i, requeueMessages as in, makeEventNotification as ir, generateSessionName as it, claimSpawnRecord as j, workerUnansweredOf as jn, parseCmdShimTarget as jt, bindAccountDevice as k, workerAccessOf as kn, ownSession as kt, RESPONSE_BUDGET_BYTES as l, runLaunchFile as ln, parseIpcRequest as lr, hostPidOf as lt, WORKER_ASK_TIMEOUT_CHOICES as m, spawnRecordOfSession as mn, _enum as mr, jwtClaim as mt, CLAUDE_PENDING_TURN_FOLDER as n, requestDeviceCode as nn, isSocketPathTooLong as nr, formatHookContext as nt, NOT_FROM_USER_NOTICE as o, resolveRecipient as on, newDeviceId as or, hookLogLine as ot, WORKER_ACCESS as p, signedInAccountApi as pn, socketPathTooLongMessage as pr, isOnline as pt, editJson as q, RpcErrorCode as qn, readCommandLine as qt, ConvenoError as r, requeueEntries as rn, makeError as rr, formatInbox as rt, NPX_SETUP_TIMEOUT_MS as s, resolveWindowsCommand as sn, newMessageId as sr, hookLogPath as st, AccountError as t, renderBody as tn, ipcMethods as tr, formatContinuation as tt, SPAWN_CLIS as u, runWaker as un, parseRelayFrame as ur, isAntigravityApp as ut, acpOverrideVar as v, statusAfterLiveness as vn, literal as vr, leadLogLine as vt, askedMarker as w, uninstallLauncher as wn, menuFromConfigOptions as wt, agentCommand as x, takeWithinChars as xn, string as xr, loginAccountApi as xt, adapterInstallCommand as y, takeAcpLaunchFile as yn, number as yr, leadLogPath as yt, currentAccessToken as z, EVENT_NOTIFICATION_METHOD as zn, planLauncher as zt };
|