skydive-cli 0.5.0-beta.4 → 0.5.0-beta.41
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/CHANGELOG.md +8 -0
- package/README.md +35 -4
- package/dist/js/api-DQCaztBg.mjs +315 -0
- package/dist/js/{billing-blocked-Dgu5-oDy.mjs → billing-blocked-SE6tySLd.mjs} +1 -1
- package/dist/js/bin.mjs +655 -278
- package/dist/js/{boot-B_93T51X.mjs → boot-B1Y1D48W.mjs} +2980 -823
- package/dist/js/chunk-BbwQpWto.mjs +33 -0
- package/dist/js/{client-Cn2af31H.mjs → client-Btq6bMzX.mjs} +108 -2
- package/dist/js/client-DCwVlAal.mjs +5 -0
- package/dist/js/{client-Dd5sMXPv.mjs → client-DMYwKALl.mjs} +348 -141
- package/dist/js/daemon-By-I_HVM.mjs +7 -0
- package/dist/js/{daemon-BYlIJN6x.mjs → daemon-D8WoX21I.mjs} +43 -7
- package/dist/js/{daemon-client-DPjmvIDE.mjs → daemon-client-Bp5DMeIi.mjs} +12 -8
- package/dist/js/daemon-client-_SVAskeO.mjs +8 -0
- package/dist/js/dist-CRtjM7ba.mjs +1750 -0
- package/dist/js/forward-zwB55Bls.mjs +208 -0
- package/dist/js/{profiler-RmWjKIHD.mjs → install-BkMcGVYS.mjs} +529 -211
- package/dist/js/launcher.mjs +49 -0
- package/dist/js/localhost-cert-Bn-UBUmj.mjs +67 -0
- package/dist/js/{print-ba_0hiV9.mjs → print-BAmEefvX.mjs} +3 -3
- package/dist/js/{print-CbayCa87.mjs → print-CwbdwCeQ.mjs} +213 -37
- package/dist/js/{print-share-uwUG16Ov.mjs → print-share-azWHVxpt.mjs} +8 -2
- package/dist/js/raw-pty-Ci2qFR9F.mjs +5 -0
- package/dist/js/{raw-pty-B6mAroiI.mjs → raw-pty-D5PhKZSl.mjs} +1 -1
- package/dist/js/rest-B5DVQ1LM.mjs +6 -0
- package/dist/js/{rest-BY2nADw5.mjs → rest-Bbe-RhMy.mjs} +105 -25
- package/dist/js/tls-cert-CLgSQALB.mjs +4 -0
- package/dist/js/tls-cert-CV-pwxVN.mjs +67 -0
- package/package.json +11 -4
- package/dist/js/client-DZstLQ_1.mjs +0 -4
- package/dist/js/daemon-CBvFKDpy.mjs +0 -5
- package/dist/js/daemon-client-Z4Ce4zf-.mjs +0 -6
- package/dist/js/raw-pty-3EkG-jjH.mjs +0 -5
- package/dist/js/rest-DADJh0bi.mjs +0 -6
- /package/dist/js/{billing-blocked-2wju4gC_.mjs → billing-blocked-D3l5kJlX.mjs} +0 -0
- /package/dist/js/{http-error-DzyrsLAZ.mjs → http-error-UHH3mVBF.mjs} +0 -0
- /package/dist/js/{output-DYzzdXYV.mjs → output-wY0VQDea.mjs} +0 -0
package/dist/js/bin.mjs
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { A as
|
|
4
|
-
import { n as printError, r as printTable, t as output } from "./output-
|
|
5
|
-
import { t as HttpError } from "./http-error-
|
|
6
|
-
import { t as createRestClient } from "./rest-
|
|
7
|
-
import "./billing-blocked-
|
|
8
|
-
import {
|
|
9
|
-
import { i as queryDaemonStatus, l as PORTAL_DAEMON_FLAG, n as ensureDaemonRunning, s as stopDaemon, u as daemonPaths } from "./daemon-
|
|
10
|
-
import
|
|
2
|
+
import { A as installAgentAlias, B as resolveWorkspaceId, D as machineOsFromPlatform, E as buildImportSeedPrompt, F as detectShell, H as name, I as ensureActiveOrganization, L as getActiveWorkspaceId, M as takenAliasNames, N as SUPPORTED_SHELLS, O as aliasActivationHint, P as defaultInstallEnv, R as getSessionIdentity, U as version, V as setActiveWorkspace, c as getAutomaticLogsDir, j as slugifyAliasName, k as dedupeAliasName, l as maybeStartProfiling, o as brandHelpArt, t as installCrashHandler, u as profileDir, w as themes, z as listWorkspaces } from "./install-BkMcGVYS.mjs";
|
|
3
|
+
import { A as getShareMachineDefault, C as getConfigPath, D as getPromptHistoryPath, E as getPreference, F as resolveAppUrl, H as saveSession, I as resolveChatAuth, L as resolveConfig, M as getStoredApiKeyWorkspaceName, N as getUpdateCheckDisabled, R as resolveManagementAuth, S as deleteConfig, T as getLastSeenVersion, V as saveConfig, W as setLastSeenVersion, _ as API_KEY_FAMILY_PREFIX, g as API_KEYS_URL, i as resolveAgent$1, j as getStoredApiKeyId, v as API_KEY_PREFIX, w as getDefaultAgent, x as PREFERENCES, y as DEFAULT_API_URL, z as resolveSession$1 } from "./print-CwbdwCeQ.mjs";
|
|
4
|
+
import { n as printError, r as printTable, t as output } from "./output-wY0VQDea.mjs";
|
|
5
|
+
import { t as HttpError } from "./http-error-UHH3mVBF.mjs";
|
|
6
|
+
import { t as createRestClient } from "./rest-Bbe-RhMy.mjs";
|
|
7
|
+
import "./billing-blocked-D3l5kJlX.mjs";
|
|
8
|
+
import { r as resolveMachineIdentity } from "./client-DMYwKALl.mjs";
|
|
9
|
+
import { i as queryDaemonStatus, l as PORTAL_DAEMON_FLAG, n as ensureDaemonRunning, s as stopDaemon, u as daemonPaths } from "./daemon-D8WoX21I.mjs";
|
|
10
|
+
import "./tls-cert-CV-pwxVN.mjs";
|
|
11
|
+
import { i as grantPortalAccess, n as fetchPortalDevices, o as registerPortalDevice, r as findThisDevice, s as revokePortalAccess } from "./api-DQCaztBg.mjs";
|
|
12
|
+
import { a as encodeFsRequest, i as decodeFsResponse, n as SANDBOX_STREAM_PATH, r as streamSpecToQuery, t as SandboxStream } from "./client-Btq6bMzX.mjs";
|
|
11
13
|
import { hideBin } from "yargs/helpers";
|
|
12
14
|
import yargs from "yargs";
|
|
13
|
-
import
|
|
15
|
+
import { hostname, tmpdir } from "node:os";
|
|
14
16
|
import path, { join } from "node:path";
|
|
15
17
|
import { err, ok } from "neverthrow";
|
|
16
18
|
import { z } from "zod";
|
|
17
19
|
import open from "open";
|
|
18
20
|
import fs from "node:fs";
|
|
19
21
|
import { spawn, spawnSync } from "node:child_process";
|
|
20
|
-
import { createHash
|
|
22
|
+
import { createHash } from "node:crypto";
|
|
21
23
|
import zlib from "node:zlib";
|
|
22
24
|
import fsp, { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
23
|
-
import {
|
|
25
|
+
import { WebSocket } from "ws";
|
|
24
26
|
import semver from "semver";
|
|
25
27
|
import { createInterface } from "node:readline";
|
|
28
|
+
import { createInterface as createInterface$1 } from "node:readline/promises";
|
|
26
29
|
|
|
27
30
|
//#region src/types.ts
|
|
28
31
|
const NON_INTERACTIVE_ENV_VARS = [
|
|
@@ -69,10 +72,12 @@ var SkydiveApiClient = class {
|
|
|
69
72
|
baseUrl;
|
|
70
73
|
token;
|
|
71
74
|
authKind;
|
|
75
|
+
workspaceId;
|
|
72
76
|
constructor(config) {
|
|
73
77
|
this.baseUrl = `${config.apiUrl.replace(/\/$/, "")}/v1`;
|
|
74
78
|
this.token = config.token;
|
|
75
79
|
this.authKind = config.kind;
|
|
80
|
+
this.workspaceId = config.workspaceId;
|
|
76
81
|
}
|
|
77
82
|
/**
|
|
78
83
|
* List one page of agents in the caller's workspace. The server caps a
|
|
@@ -158,6 +163,7 @@ var SkydiveApiClient = class {
|
|
|
158
163
|
authorization: `Bearer ${this.token}`,
|
|
159
164
|
"user-agent": USER_AGENT
|
|
160
165
|
};
|
|
166
|
+
if (this.workspaceId) headers["x-workspace-id"] = this.workspaceId;
|
|
161
167
|
if (params.body) headers["content-type"] = "application/json";
|
|
162
168
|
let response;
|
|
163
169
|
try {
|
|
@@ -615,7 +621,7 @@ const logoutCommand = {
|
|
|
615
621
|
const keyId = getStoredApiKeyId();
|
|
616
622
|
let keyRevoked = false;
|
|
617
623
|
if (keyId) {
|
|
618
|
-
const session = resolveSession({ appUrl: argv["api-url"] });
|
|
624
|
+
const session = resolveSession$1({ appUrl: argv["api-url"] });
|
|
619
625
|
const config = resolveConfig({ apiUrl: argv["api-url"] });
|
|
620
626
|
const credential = session.isOk() ? {
|
|
621
627
|
appUrl: session.value.appUrl,
|
|
@@ -646,7 +652,7 @@ const statusCommand$1 = {
|
|
|
646
652
|
describe: "Show current authentication state",
|
|
647
653
|
handler: async (argv) => {
|
|
648
654
|
const apiKey = resolveConfig({ apiUrl: argv["api-url"] });
|
|
649
|
-
const session = resolveSession({});
|
|
655
|
+
const session = resolveSession$1({});
|
|
650
656
|
const management = resolveManagementAuth({ apiUrl: argv["api-url"] });
|
|
651
657
|
const identity = session.isOk() ? (await getSessionIdentity({
|
|
652
658
|
appUrl: session.value.appUrl,
|
|
@@ -717,11 +723,6 @@ const authCommand = {
|
|
|
717
723
|
* matches on it to keep notices off the user's prompt (see isCompletionProbe).
|
|
718
724
|
*/
|
|
719
725
|
const COMPLETION_PROBE_FLAG = "--get-yargs-completions";
|
|
720
|
-
const SUPPORTED_SHELLS = [
|
|
721
|
-
"bash",
|
|
722
|
-
"zsh",
|
|
723
|
-
"fish"
|
|
724
|
-
];
|
|
725
726
|
/**
|
|
726
727
|
* True when this invocation is a shell asking for completion candidates
|
|
727
728
|
* rather than a user running a command. Such a run must print candidates and
|
|
@@ -893,24 +894,6 @@ complete -c ${name} -f -k -a '(${fn})'
|
|
|
893
894
|
${blockEnd(name)}
|
|
894
895
|
`;
|
|
895
896
|
}
|
|
896
|
-
const defaultInstallEnv = () => ({
|
|
897
|
-
home: os.homedir(),
|
|
898
|
-
platform: process.platform,
|
|
899
|
-
env: process.env,
|
|
900
|
-
exists: fs.existsSync
|
|
901
|
-
});
|
|
902
|
-
/**
|
|
903
|
-
* The shell to install for when the user didn't name one. `$SHELL` is the
|
|
904
|
-
* only signal available: a completion install runs as a child process, so the
|
|
905
|
-
* invoking shell's own variables (`$ZSH_VERSION`, `$FISH_VERSION`) aren't
|
|
906
|
-
* visible here.
|
|
907
|
-
*/
|
|
908
|
-
function detectShell(env = process.env) {
|
|
909
|
-
const shell = env["SHELL"];
|
|
910
|
-
if (!shell) return null;
|
|
911
|
-
const name = path.basename(shell);
|
|
912
|
-
return SUPPORTED_SHELLS.find((candidate) => name === candidate) ?? null;
|
|
913
|
-
}
|
|
914
897
|
function completionTarget(shell, deps = defaultInstallEnv()) {
|
|
915
898
|
const { home, platform, env, exists } = deps;
|
|
916
899
|
if (shell === "fish") {
|
|
@@ -1019,7 +1002,7 @@ const completionCommand = {
|
|
|
1019
1002
|
* resolve-or-exit block isn't copy-pasted per command.
|
|
1020
1003
|
*/
|
|
1021
1004
|
function requireSession(argv) {
|
|
1022
|
-
const session = resolveSession({ appUrl: resolveAppUrl({ appUrl: argv["api-url"] }) });
|
|
1005
|
+
const session = resolveSession$1({ appUrl: resolveAppUrl({ appUrl: argv["api-url"] }) });
|
|
1023
1006
|
if (session.isErr()) {
|
|
1024
1007
|
printError(`${session.error.message} Run \`skydive auth login\` first, or set SKYDIVE_SESSION_TOKEN.`);
|
|
1025
1008
|
process.exit(1);
|
|
@@ -1031,7 +1014,7 @@ function requireSession(argv) {
|
|
|
1031
1014
|
* {@link resolveManagementAuth}) or exit with a friendly hint, then build the
|
|
1032
1015
|
* `/v1` client. Shared by `agents`, `keys` and `secrets`.
|
|
1033
1016
|
*/
|
|
1034
|
-
function requireManagementClient(argv) {
|
|
1017
|
+
function requireManagementClient(argv, opts = {}) {
|
|
1035
1018
|
const auth = resolveManagementAuth({ apiUrl: argv["api-url"] });
|
|
1036
1019
|
if (auth.isErr()) {
|
|
1037
1020
|
printError(auth.error.message);
|
|
@@ -1039,7 +1022,10 @@ function requireManagementClient(argv) {
|
|
|
1039
1022
|
}
|
|
1040
1023
|
if (auth.value.kind === "api-key" && auth.value.pinnedWorkspaceName) process.stderr.write(`Using this machine's API key, which always acts in the "${auth.value.pinnedWorkspaceName}" workspace (even after \`workspace switch\`). Run \`skydive auth login\` to change that.
|
|
1041
1024
|
`);
|
|
1042
|
-
return new SkydiveApiClient(
|
|
1025
|
+
return new SkydiveApiClient({
|
|
1026
|
+
...auth.value,
|
|
1027
|
+
...opts.workspaceId ? { workspaceId: opts.workspaceId } : {}
|
|
1028
|
+
});
|
|
1043
1029
|
}
|
|
1044
1030
|
/** Resolve the session (see {@link requireSession}) and build a REST client. */
|
|
1045
1031
|
function requireRestClient(argv) {
|
|
@@ -1056,7 +1042,32 @@ function requireRestClient(argv) {
|
|
|
1056
1042
|
|
|
1057
1043
|
//#endregion
|
|
1058
1044
|
//#region src/commands/agents.ts
|
|
1059
|
-
const
|
|
1045
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1046
|
+
/**
|
|
1047
|
+
* Resolve an agent from an id or a name. A uuid selector hits `GET
|
|
1048
|
+
* /agents/:id` directly; anything else is matched case-insensitively against
|
|
1049
|
+
* the roster's names. Ambiguity is an error rather than a silent pick, so an
|
|
1050
|
+
* alias never lands on the wrong agent.
|
|
1051
|
+
*/
|
|
1052
|
+
async function resolveAgent(client, selector) {
|
|
1053
|
+
if (UUID_RE.test(selector)) {
|
|
1054
|
+
const result = await client.getAgent(selector);
|
|
1055
|
+
if (result.isErr()) throw new Error(result.error.message);
|
|
1056
|
+
return result.value;
|
|
1057
|
+
}
|
|
1058
|
+
const list = await client.listAgents({
|
|
1059
|
+
scope: "org",
|
|
1060
|
+
limit: 100
|
|
1061
|
+
});
|
|
1062
|
+
if (list.isErr()) throw new Error(list.error.message);
|
|
1063
|
+
const needle = selector.trim().toLowerCase();
|
|
1064
|
+
const matches = list.value.agents.filter((a) => a.name.toLowerCase() === needle);
|
|
1065
|
+
const [first] = matches;
|
|
1066
|
+
if (matches.length === 1 && first) return first;
|
|
1067
|
+
if (matches.length === 0) throw new Error(`No agent named "${selector}". Pass an id, or run \`skydive agents list\`.`);
|
|
1068
|
+
throw new Error(`Multiple agents named "${selector}". Pass the id instead:\n${matches.map((a) => ` ${a.name} ${a.id}`).join("\n")}`);
|
|
1069
|
+
}
|
|
1070
|
+
const listCommand$6 = {
|
|
1060
1071
|
command: "list",
|
|
1061
1072
|
describe: "List agents in the active workspace",
|
|
1062
1073
|
builder: (y) => y.option("limit", {
|
|
@@ -1205,10 +1216,82 @@ const createCommand$1 = {
|
|
|
1205
1216
|
if (agent.url) console.log(` API: ${agent.url}`);
|
|
1206
1217
|
}
|
|
1207
1218
|
};
|
|
1219
|
+
/**
|
|
1220
|
+
* Resolve the `--workspace` selector (slug/name/id) to a workspace, using the
|
|
1221
|
+
* chat/session credential (workspace listing is a session endpoint). Exits
|
|
1222
|
+
* with a clear message on a bad selector or when listing isn't available
|
|
1223
|
+
* (e.g. a pinned API key). Returns null when the flag is absent.
|
|
1224
|
+
*/
|
|
1225
|
+
async function resolveAliasWorkspace(argv) {
|
|
1226
|
+
if (!argv.workspace) return null;
|
|
1227
|
+
const auth = resolveChatAuth({ appUrl: resolveAppUrl({ appUrl: argv["api-url"] }) });
|
|
1228
|
+
if (auth.isErr()) {
|
|
1229
|
+
printError(`${auth.error.message} Run \`skydive auth login\` to resolve a workspace by name.`);
|
|
1230
|
+
process.exit(1);
|
|
1231
|
+
}
|
|
1232
|
+
const resolved = await resolveWorkspaceId({
|
|
1233
|
+
appUrl: auth.value.appUrl,
|
|
1234
|
+
sessionToken: auth.value.token,
|
|
1235
|
+
selector: argv.workspace
|
|
1236
|
+
});
|
|
1237
|
+
if (resolved.isErr()) {
|
|
1238
|
+
printError(resolved.error.message);
|
|
1239
|
+
process.exit(1);
|
|
1240
|
+
}
|
|
1241
|
+
return resolved.value;
|
|
1242
|
+
}
|
|
1243
|
+
const aliasCommand = {
|
|
1244
|
+
command: "alias <agent> [name]",
|
|
1245
|
+
describe: "Add a shell alias that opens an agent's chat",
|
|
1246
|
+
builder: (y) => y.positional("agent", {
|
|
1247
|
+
type: "string",
|
|
1248
|
+
demandOption: true,
|
|
1249
|
+
describe: "Agent id or name to alias"
|
|
1250
|
+
}).positional("name", {
|
|
1251
|
+
type: "string",
|
|
1252
|
+
describe: "Alias to use (default: derived from the agent name)"
|
|
1253
|
+
}).option("shell", {
|
|
1254
|
+
type: "string",
|
|
1255
|
+
choices: SUPPORTED_SHELLS,
|
|
1256
|
+
describe: "Shell to install for (default: $SHELL)"
|
|
1257
|
+
}).option("workspace", {
|
|
1258
|
+
type: "string",
|
|
1259
|
+
describe: "Workspace the agent lives in (slug, name, or id). Scopes the lookup to it and pins it in the alias, so the alias opens the right agent even when it isn't your active workspace."
|
|
1260
|
+
}).example("skydive agents alias Ripple", "alias `ripple` -> that agent").example("skydive agents alias Ripple rip", "use a custom alias token").example("skydive agents alias Ripple --workspace acme", "pin the workspace in the alias"),
|
|
1261
|
+
handler: async (argv) => {
|
|
1262
|
+
const shell = argv.shell ? SUPPORTED_SHELLS.find((s) => s === argv.shell) : detectShell();
|
|
1263
|
+
if (!shell) throw new Error(argv.shell ? `Unsupported shell "${argv.shell}". Supported: ${SUPPORTED_SHELLS.join(", ")}.` : `Could not tell which shell to use from $SHELL. Name one with --shell (${SUPPORTED_SHELLS.join(", ")}).`);
|
|
1264
|
+
const workspace = await resolveAliasWorkspace(argv);
|
|
1265
|
+
const agent = await resolveAgent(requireManagementClient(argv, { workspaceId: workspace?.id }), argv.agent);
|
|
1266
|
+
const preferred = argv.name ? slugifyAliasName(argv.name) : slugifyAliasName(agent.name);
|
|
1267
|
+
const alias = dedupeAliasName(preferred, takenAliasNames(shell));
|
|
1268
|
+
const result = installAgentAlias({
|
|
1269
|
+
alias,
|
|
1270
|
+
agentId: agent.id,
|
|
1271
|
+
shell,
|
|
1272
|
+
...workspace ? { workspaceId: workspace.id } : {}
|
|
1273
|
+
}, void 0);
|
|
1274
|
+
if (argv.json) {
|
|
1275
|
+
output(argv, {
|
|
1276
|
+
...result,
|
|
1277
|
+
workspace: workspace ?? null
|
|
1278
|
+
});
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
if (argv.quiet) {
|
|
1282
|
+
console.log(result.alias);
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
const where = workspace ? ` (workspace ${workspace.name})` : "";
|
|
1286
|
+
console.log(`${result.updated ? "Updated" : "Added"} alias \`${result.alias}\` -> ${agent.name}${where} in ${result.path}`);
|
|
1287
|
+
if (alias !== preferred) console.log(`(\`${preferred}\` was taken, so used \`${alias}\`.)`);
|
|
1288
|
+
console.log(aliasActivationHint(result));
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1208
1291
|
const agentsCommand = {
|
|
1209
1292
|
command: "agents",
|
|
1210
1293
|
describe: "Manage agents",
|
|
1211
|
-
builder: (y) => y.command(listCommand$
|
|
1294
|
+
builder: (y) => y.command(listCommand$6).command(getCommand$2).command(createCommand$1).command(aliasCommand).demandCommand(1, "Specify a subcommand: list, get, create, alias"),
|
|
1212
1295
|
handler: () => {}
|
|
1213
1296
|
};
|
|
1214
1297
|
|
|
@@ -1462,19 +1545,6 @@ function ensureBunAndReexec(onProgress) {
|
|
|
1462
1545
|
|
|
1463
1546
|
//#endregion
|
|
1464
1547
|
//#region src/commands/import.ts
|
|
1465
|
-
/**
|
|
1466
|
-
* The first message of the import conversation, sent as the user. It hands
|
|
1467
|
-
* the real work to the agent's `import-config` skill; this text only needs
|
|
1468
|
-
* to establish intent, anchor the starting directory, and set the two
|
|
1469
|
-
* expectations the user cares about most (plan first, no credentials).
|
|
1470
|
-
*/
|
|
1471
|
-
function buildImportSeedPrompt(projectDir) {
|
|
1472
|
-
return [
|
|
1473
|
-
"I'm migrating from another coding agent. Import my setup from this machine.",
|
|
1474
|
-
"",
|
|
1475
|
-
`Use your import-config skill. I ran this from \`${projectDir}\`, so start there and in my home directory. Don't assume one tool — do the discovery sweep so you catch whatever I actually use (Claude Code, Cursor, Codex, Gemini CLI, Copilot, Windsurf, Cline, OpenCode, Aider, and any nested AGENTS.md). Show me the plan first: everything you found, what you'll bring over, where it lands in you, and anything you're leaving out (credentials especially). Then wait for my OK before committing anything.`
|
|
1476
|
-
].join("\n");
|
|
1477
|
-
}
|
|
1478
1548
|
const importCommand = {
|
|
1479
1549
|
command: "import",
|
|
1480
1550
|
describe: "Import your existing coding-agent setup (Claude Code, Cursor, Codex, Gemini, Copilot, and more) into an agent (opens a machine-shared chat)",
|
|
@@ -1503,30 +1573,33 @@ const importCommand = {
|
|
|
1503
1573
|
printError(`import needs the Bun runtime and it couldn't be set up automatically. Install Bun (https://bun.sh) and run \`bun ${process.argv[1] ?? "skydive"} import\`, point SKYDIVE_BUN_PATH at an existing bun binary, or use the non-interactive \`import -p\` (runs under Node).`);
|
|
1504
1574
|
process.exit(1);
|
|
1505
1575
|
}
|
|
1506
|
-
let session = resolveSession({ appUrl });
|
|
1576
|
+
let session = resolveSession$1({ appUrl });
|
|
1507
1577
|
if (session.isErr()) {
|
|
1508
1578
|
const login = await loginWithDevice({ appUrl });
|
|
1509
1579
|
if (login.isErr()) {
|
|
1510
1580
|
printError(login.error.message);
|
|
1511
1581
|
process.exit(1);
|
|
1512
1582
|
}
|
|
1513
|
-
session = resolveSession({ appUrl });
|
|
1583
|
+
session = resolveSession$1({ appUrl });
|
|
1514
1584
|
if (session.isErr()) {
|
|
1515
1585
|
printError("Signed in, but no session was stored.");
|
|
1516
1586
|
process.exit(1);
|
|
1517
1587
|
}
|
|
1518
1588
|
}
|
|
1519
|
-
const { runChat } = await import("./boot-
|
|
1589
|
+
const { runChat } = await import("./boot-B1Y1D48W.mjs");
|
|
1520
1590
|
await runChat({
|
|
1521
1591
|
appUrl,
|
|
1522
1592
|
sessionToken: session.value.sessionToken,
|
|
1593
|
+
workspaceId: void 0,
|
|
1523
1594
|
shareMachine: true,
|
|
1524
1595
|
promptHistoryPath: getPromptHistoryPath(),
|
|
1525
1596
|
notifications: true,
|
|
1526
1597
|
agentSelector: argv.agent ?? null,
|
|
1527
1598
|
conversationId: null,
|
|
1528
1599
|
newConversation: false,
|
|
1529
|
-
|
|
1600
|
+
defaultAgentSelector: getDefaultAgent(),
|
|
1601
|
+
forceOnboarding: false,
|
|
1602
|
+
seedPrompt: buildImportSeedPrompt(process.cwd(), machineOsFromPlatform(process.platform))
|
|
1530
1603
|
});
|
|
1531
1604
|
}
|
|
1532
1605
|
};
|
|
@@ -1538,20 +1611,20 @@ const importCommand = {
|
|
|
1538
1611
|
* (`chat -p "go ahead" --resume <id> --share-machine`) to apply it.
|
|
1539
1612
|
*/
|
|
1540
1613
|
async function runImportPrintMode({ argv, appUrl }) {
|
|
1541
|
-
const session = resolveSession({ appUrl });
|
|
1614
|
+
const session = resolveSession$1({ appUrl });
|
|
1542
1615
|
if (session.isErr()) {
|
|
1543
1616
|
printError(`${session.error.message} For non-interactive use, run \`skydive auth login --web\` first, or set SKYDIVE_SESSION_TOKEN.`);
|
|
1544
1617
|
process.exit(1);
|
|
1545
1618
|
}
|
|
1546
|
-
const { connectMachineShare } = await import("./print-share-
|
|
1619
|
+
const { connectMachineShare } = await import("./print-share-azWHVxpt.mjs");
|
|
1547
1620
|
const machineShare = await connectMachineShare({
|
|
1548
1621
|
appUrl,
|
|
1549
1622
|
sessionToken: session.value.sessionToken,
|
|
1550
1623
|
timeoutHint: "Check `skydive portal status`, then re-run."
|
|
1551
1624
|
});
|
|
1552
1625
|
const extra = (argv.print ?? "").trim();
|
|
1553
|
-
const prompt = buildImportSeedPrompt(process.cwd()) + (extra ? `\n\nAdditional instructions: ${extra}` : "");
|
|
1554
|
-
const { runPrint } = await import("./print-
|
|
1626
|
+
const prompt = buildImportSeedPrompt(process.cwd(), machineOsFromPlatform(process.platform)) + (extra ? `\n\nAdditional instructions: ${extra}` : "");
|
|
1627
|
+
const { runPrint } = await import("./print-BAmEefvX.mjs");
|
|
1555
1628
|
try {
|
|
1556
1629
|
const result = await runPrint({
|
|
1557
1630
|
appUrl,
|
|
@@ -1575,7 +1648,7 @@ async function runImportPrintMode({ argv, appUrl }) {
|
|
|
1575
1648
|
|
|
1576
1649
|
//#endregion
|
|
1577
1650
|
//#region src/commands/keys.ts
|
|
1578
|
-
const listCommand$
|
|
1651
|
+
const listCommand$5 = {
|
|
1579
1652
|
command: "list",
|
|
1580
1653
|
describe: "List API keys for an agent",
|
|
1581
1654
|
handler: async (argv) => {
|
|
@@ -1664,7 +1737,7 @@ const keysCommand = {
|
|
|
1664
1737
|
type: "string",
|
|
1665
1738
|
demandOption: true,
|
|
1666
1739
|
describe: "Agent ID"
|
|
1667
|
-
}).command(listCommand$
|
|
1740
|
+
}).command(listCommand$5).command(createCommand).command(revokeCommand$1).demandCommand(1, "Specify a subcommand: list, create, revoke"),
|
|
1668
1741
|
handler: () => {}
|
|
1669
1742
|
};
|
|
1670
1743
|
|
|
@@ -1676,7 +1749,7 @@ async function readStdin() {
|
|
|
1676
1749
|
for await (const chunk of process.stdin) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
1677
1750
|
return Buffer.concat(chunks).toString("utf8").replace(/\n$/, "");
|
|
1678
1751
|
}
|
|
1679
|
-
const listCommand$
|
|
1752
|
+
const listCommand$4 = {
|
|
1680
1753
|
command: "list",
|
|
1681
1754
|
describe: "List secret names for an agent (values are never shown)",
|
|
1682
1755
|
handler: async (argv) => {
|
|
@@ -1762,7 +1835,7 @@ const secretsCommand = {
|
|
|
1762
1835
|
type: "string",
|
|
1763
1836
|
demandOption: true,
|
|
1764
1837
|
describe: "Agent ID"
|
|
1765
|
-
}).command(listCommand$
|
|
1838
|
+
}).command(listCommand$4).command(setCommand$1).command(rmCommand).demandCommand(1, "Specify a subcommand: list, set, rm"),
|
|
1766
1839
|
handler: () => {}
|
|
1767
1840
|
};
|
|
1768
1841
|
|
|
@@ -1859,6 +1932,24 @@ async function resolveAgentWorkspace({ appUrl, sessionToken, agentSelector }) {
|
|
|
1859
1932
|
|
|
1860
1933
|
//#endregion
|
|
1861
1934
|
//#region src/commands/chat.ts
|
|
1935
|
+
/**
|
|
1936
|
+
* Resolve the `--workspace` selector to an id, or undefined when the flag is
|
|
1937
|
+
* absent. A bad selector is fatal — a chat scoped to the wrong (or a
|
|
1938
|
+
* nonexistent) workspace is worse than failing fast with how to list them.
|
|
1939
|
+
*/
|
|
1940
|
+
async function resolveWorkspaceFlag({ appUrl, sessionToken, selector }) {
|
|
1941
|
+
if (!selector) return void 0;
|
|
1942
|
+
const resolved = await resolveWorkspaceId({
|
|
1943
|
+
appUrl,
|
|
1944
|
+
sessionToken,
|
|
1945
|
+
selector
|
|
1946
|
+
});
|
|
1947
|
+
if (resolved.isErr()) {
|
|
1948
|
+
printError(resolved.error.message);
|
|
1949
|
+
process.exit(1);
|
|
1950
|
+
}
|
|
1951
|
+
return resolved.value.id;
|
|
1952
|
+
}
|
|
1862
1953
|
const chatCommand = {
|
|
1863
1954
|
command: "chat",
|
|
1864
1955
|
describe: "Open the interactive chat TUI, or -p for a one-shot",
|
|
@@ -1869,6 +1960,9 @@ const chatCommand = {
|
|
|
1869
1960
|
}).option("agent", {
|
|
1870
1961
|
type: "string",
|
|
1871
1962
|
describe: "Target agent, by id, slug, or name. With -p, the agent to send the one-shot prompt to. Without -p, pre-selects the agent and opens its conversation list, skipping the agent picker. Optional when the account has exactly one agent."
|
|
1963
|
+
}).option("workspace", {
|
|
1964
|
+
type: "string",
|
|
1965
|
+
describe: "Scope this chat to a workspace, by slug, name, or id. Every request for this invocation is scoped to it (no persistent switch of your active workspace), so a slug/name --agent resolves inside it and the roster is that workspace. Useful in an alias for an agent that lives in a workspace other than your active one."
|
|
1872
1966
|
}).option("conversation", {
|
|
1873
1967
|
alias: "resume",
|
|
1874
1968
|
type: "string",
|
|
@@ -1877,6 +1971,10 @@ const chatCommand = {
|
|
|
1877
1971
|
type: "boolean",
|
|
1878
1972
|
default: false,
|
|
1879
1973
|
describe: "Start a fresh conversation instead of opening the conversation list. With --agent, opens a new conversation with that agent directly. Without --agent, opens a new conversation once you pick an agent (auto-picked if the account has only one). Ignored with --resume, which always continues the named conversation."
|
|
1974
|
+
}).option("onboarding", {
|
|
1975
|
+
type: "boolean",
|
|
1976
|
+
default: false,
|
|
1977
|
+
describe: "Force the first-run onboarding flow (auto-create a first agent, then offer the machine import) even when the workspace already has agents. Also settable via SKYDIVE_FORCE_ONBOARDING=1. Handy for replaying the new-user experience; ignored with -p, --resume, or --agent."
|
|
1880
1978
|
}).option("share-machine", {
|
|
1881
1979
|
type: "boolean",
|
|
1882
1980
|
describe: "Share this machine with the agent over the portal so it can run commands here (default-deny; in the TUI you approve per agent, with -p the flag grants the target agent for the run). Defaults to `shareMachineDefault` in the CLI config file; --no-share-machine disables for this invocation."
|
|
@@ -1918,21 +2016,27 @@ const chatCommand = {
|
|
|
1918
2016
|
process.exit(1);
|
|
1919
2017
|
}
|
|
1920
2018
|
}
|
|
2019
|
+
const workspaceId = await resolveWorkspaceFlag({
|
|
2020
|
+
appUrl,
|
|
2021
|
+
sessionToken: auth.value.token,
|
|
2022
|
+
selector: argv.workspace
|
|
2023
|
+
});
|
|
1921
2024
|
const themeId = argv.theme ?? process.env["SKYDIVE_THEME"] ?? void 0;
|
|
1922
2025
|
if (themeId !== void 0 && !themes.some((t) => t.id === themeId)) {
|
|
1923
2026
|
printError(`Unknown theme "${themeId}". Valid themes: ${themes.map((t) => t.id).join(", ")}`);
|
|
1924
2027
|
process.exit(1);
|
|
1925
2028
|
}
|
|
1926
|
-
await ensureAgentWorkspace({
|
|
2029
|
+
if (!workspaceId) await ensureAgentWorkspace({
|
|
1927
2030
|
appUrl,
|
|
1928
2031
|
sessionToken: auth.value.token,
|
|
1929
2032
|
agentSelector: argv.agent ?? null
|
|
1930
2033
|
});
|
|
1931
|
-
const { runChat } = await import("./boot-
|
|
2034
|
+
const { runChat } = await import("./boot-B1Y1D48W.mjs");
|
|
1932
2035
|
await runChat({
|
|
1933
2036
|
appUrl: auth.value.appUrl,
|
|
1934
2037
|
sessionToken: auth.value.token,
|
|
1935
2038
|
authKind: auth.value.kind,
|
|
2039
|
+
workspaceId,
|
|
1936
2040
|
shareMachine: resolveShareMachine(argv),
|
|
1937
2041
|
promptHistoryPath: getPromptHistoryPath(),
|
|
1938
2042
|
theme: themeId,
|
|
@@ -1940,6 +2044,8 @@ const chatCommand = {
|
|
|
1940
2044
|
agentSelector: argv.agent ?? null,
|
|
1941
2045
|
conversationId: argv.conversation ?? null,
|
|
1942
2046
|
newConversation: resolveNewConversation(argv),
|
|
2047
|
+
forceOnboarding: resolveForceOnboarding(argv),
|
|
2048
|
+
defaultAgentSelector: getDefaultAgent(),
|
|
1943
2049
|
seedPrompt: null
|
|
1944
2050
|
});
|
|
1945
2051
|
}
|
|
@@ -1961,6 +2067,20 @@ function resolveNewConversation(argv) {
|
|
|
1961
2067
|
return argv.new === true && !argv.conversation;
|
|
1962
2068
|
}
|
|
1963
2069
|
/**
|
|
2070
|
+
* Whether to force the first-run onboarding flow: the `--onboarding` flag or
|
|
2071
|
+
* `SKYDIVE_FORCE_ONBOARDING` (any non-empty, non-"0"/"false" value). Lets the
|
|
2072
|
+
* new-user experience be replayed in a workspace that already has agents. The
|
|
2073
|
+
* TUI applies it only to a bare interactive launch — an explicit
|
|
2074
|
+
* `--agent`/`--resume`/`--new` still takes precedence.
|
|
2075
|
+
*/
|
|
2076
|
+
function resolveForceOnboarding(argv, env = process.env) {
|
|
2077
|
+
if (argv.onboarding === true) return true;
|
|
2078
|
+
const raw = env["SKYDIVE_FORCE_ONBOARDING"];
|
|
2079
|
+
if (raw === void 0) return false;
|
|
2080
|
+
const value = raw.trim().toLowerCase();
|
|
2081
|
+
return value !== "" && value !== "0" && value !== "false";
|
|
2082
|
+
}
|
|
2083
|
+
/**
|
|
1964
2084
|
* Cross-workspace `--agent <uuid>` handling shared by the TUI and -p paths:
|
|
1965
2085
|
* on a hit in another workspace, switch to it and say so on stderr (stdout
|
|
1966
2086
|
* may carry the -p reply/JSON envelope); when the id matches no workspace on
|
|
@@ -1995,8 +2115,13 @@ async function runPrintMode({ argv, appUrl }) {
|
|
|
1995
2115
|
printError(`${auth.error.message} For non-interactive use, run \`skydive auth login\` first, or set SKYDIVE_API_KEY / SKYDIVE_SESSION_TOKEN.`);
|
|
1996
2116
|
process.exit(1);
|
|
1997
2117
|
}
|
|
1998
|
-
const { runPrint, readStdin } = await import("./print-
|
|
1999
|
-
await
|
|
2118
|
+
const { runPrint, readStdin } = await import("./print-BAmEefvX.mjs");
|
|
2119
|
+
const workspaceId = await resolveWorkspaceFlag({
|
|
2120
|
+
appUrl,
|
|
2121
|
+
sessionToken: auth.value.token,
|
|
2122
|
+
selector: argv.workspace
|
|
2123
|
+
});
|
|
2124
|
+
if (!workspaceId) await ensureAgentWorkspace({
|
|
2000
2125
|
appUrl,
|
|
2001
2126
|
sessionToken: auth.value.token,
|
|
2002
2127
|
agentSelector: argv.agent ?? null
|
|
@@ -2020,7 +2145,7 @@ async function runPrintMode({ argv, appUrl }) {
|
|
|
2020
2145
|
process.exit(1);
|
|
2021
2146
|
}
|
|
2022
2147
|
} else {
|
|
2023
|
-
const { connectMachineShare } = await import("./print-share-
|
|
2148
|
+
const { connectMachineShare } = await import("./print-share-azWHVxpt.mjs");
|
|
2024
2149
|
machineShare = await connectMachineShare({
|
|
2025
2150
|
appUrl: auth.value.appUrl,
|
|
2026
2151
|
sessionToken: auth.value.token,
|
|
@@ -2031,6 +2156,7 @@ async function runPrintMode({ argv, appUrl }) {
|
|
|
2031
2156
|
const result = await runPrint({
|
|
2032
2157
|
appUrl: auth.value.appUrl,
|
|
2033
2158
|
sessionToken: auth.value.token,
|
|
2159
|
+
workspaceId,
|
|
2034
2160
|
prompt,
|
|
2035
2161
|
agentSelector: argv.agent ?? null,
|
|
2036
2162
|
conversationId: argv.conversation ?? null,
|
|
@@ -2040,7 +2166,7 @@ async function runPrintMode({ argv, appUrl }) {
|
|
|
2040
2166
|
});
|
|
2041
2167
|
if (argv.json) output(argv, result);
|
|
2042
2168
|
} catch (error) {
|
|
2043
|
-
const { BillingBlockedError, BILLING_BLOCKED_EXIT_CODE, billingBlockedJsonResult } = await import("./billing-blocked-
|
|
2169
|
+
const { BillingBlockedError, BILLING_BLOCKED_EXIT_CODE, billingBlockedJsonResult } = await import("./billing-blocked-SE6tySLd.mjs");
|
|
2044
2170
|
if (error instanceof BillingBlockedError) {
|
|
2045
2171
|
if (argv.json) output(argv, billingBlockedJsonResult(error, null));
|
|
2046
2172
|
printError(error.message);
|
|
@@ -2084,7 +2210,7 @@ const getCommand$1 = {
|
|
|
2084
2210
|
printError(`${auth.error.message} Run \`skydive auth login\` first, or set SKYDIVE_API_KEY / SKYDIVE_SESSION_TOKEN.`);
|
|
2085
2211
|
process.exit(1);
|
|
2086
2212
|
}
|
|
2087
|
-
const { messageGet } = await import("./print-
|
|
2213
|
+
const { messageGet } = await import("./print-BAmEefvX.mjs");
|
|
2088
2214
|
try {
|
|
2089
2215
|
const result = await messageGet({
|
|
2090
2216
|
appUrl: auth.value.appUrl,
|
|
@@ -2094,7 +2220,7 @@ const getCommand$1 = {
|
|
|
2094
2220
|
});
|
|
2095
2221
|
if (argv.json) output(argv, result);
|
|
2096
2222
|
} catch (error) {
|
|
2097
|
-
const { BillingBlockedError, BILLING_BLOCKED_EXIT_CODE, billingBlockedJsonResult } = await import("./billing-blocked-
|
|
2223
|
+
const { BillingBlockedError, BILLING_BLOCKED_EXIT_CODE, billingBlockedJsonResult } = await import("./billing-blocked-SE6tySLd.mjs");
|
|
2098
2224
|
if (error instanceof BillingBlockedError) {
|
|
2099
2225
|
if (argv.json) output(argv, billingBlockedJsonResult(error, argv["message-id"]));
|
|
2100
2226
|
printError(error.message);
|
|
@@ -2131,7 +2257,7 @@ function messageToText(message) {
|
|
|
2131
2257
|
}
|
|
2132
2258
|
return chunks.join("\n").trim();
|
|
2133
2259
|
}
|
|
2134
|
-
const listCommand$
|
|
2260
|
+
const listCommand$3 = {
|
|
2135
2261
|
command: "list",
|
|
2136
2262
|
describe: "List an agent's conversations",
|
|
2137
2263
|
builder: (y) => y.option("agent", {
|
|
@@ -2143,7 +2269,7 @@ const listCommand$2 = {
|
|
|
2143
2269
|
}),
|
|
2144
2270
|
handler: async (argv) => {
|
|
2145
2271
|
const client = requireRestClient(argv);
|
|
2146
|
-
const agent = resolveAgent(await client.listAgents({
|
|
2272
|
+
const agent = resolveAgent$1(await client.listAgents({
|
|
2147
2273
|
scope: "org",
|
|
2148
2274
|
onPage: null
|
|
2149
2275
|
}), argv.agent ?? null);
|
|
@@ -2200,7 +2326,7 @@ const showCommand = {
|
|
|
2200
2326
|
console.log(recap ?? "(no recap available)");
|
|
2201
2327
|
return;
|
|
2202
2328
|
}
|
|
2203
|
-
const messages = await client.listMessages({ conversationId });
|
|
2329
|
+
const { messages } = await client.listMessages({ conversationId });
|
|
2204
2330
|
if (argv.json) {
|
|
2205
2331
|
output(argv, messages);
|
|
2206
2332
|
return;
|
|
@@ -2221,7 +2347,7 @@ const conversationsCommand = {
|
|
|
2221
2347
|
command: "conversations",
|
|
2222
2348
|
aliases: ["conv"],
|
|
2223
2349
|
describe: "List and read agent conversations",
|
|
2224
|
-
builder: (y) => y.command(listCommand$
|
|
2350
|
+
builder: (y) => y.command(listCommand$3).command(showCommand).demandCommand(1, "Specify a subcommand: list, show"),
|
|
2225
2351
|
handler: () => {}
|
|
2226
2352
|
};
|
|
2227
2353
|
|
|
@@ -2263,7 +2389,7 @@ async function runList(argv, { hint }) {
|
|
|
2263
2389
|
]));
|
|
2264
2390
|
if (hint && !argv.quiet) console.log("\nRun `skydive workspace switch` to pick a workspace, or pass its slug directly.");
|
|
2265
2391
|
}
|
|
2266
|
-
const listCommand$
|
|
2392
|
+
const listCommand$2 = {
|
|
2267
2393
|
command: "list",
|
|
2268
2394
|
describe: "List workspaces on your account",
|
|
2269
2395
|
handler: (argv) => runList(argv, { hint: false })
|
|
@@ -2287,7 +2413,7 @@ const switchCommand = {
|
|
|
2287
2413
|
printError("The workspace picker needs the Bun runtime and it could not be set up automatically. Pass a workspace slug instead, or install Bun and retry.");
|
|
2288
2414
|
process.exit(1);
|
|
2289
2415
|
}
|
|
2290
|
-
const { runWorkspacePicker } = await import("./boot-
|
|
2416
|
+
const { runWorkspacePicker } = await import("./boot-B1Y1D48W.mjs");
|
|
2291
2417
|
await runWorkspacePicker(session);
|
|
2292
2418
|
return;
|
|
2293
2419
|
}
|
|
@@ -2320,7 +2446,7 @@ const switchCommand = {
|
|
|
2320
2446
|
const workspaceCommand = {
|
|
2321
2447
|
command: "workspace",
|
|
2322
2448
|
describe: "List or switch the workspace all `skydive` commands act on",
|
|
2323
|
-
builder: (y) => y.command(listCommand$
|
|
2449
|
+
builder: (y) => y.command(listCommand$2).command(switchCommand),
|
|
2324
2450
|
handler: (argv) => runList(argv, { hint: true })
|
|
2325
2451
|
};
|
|
2326
2452
|
|
|
@@ -2336,10 +2462,10 @@ const workspaceCommand = {
|
|
|
2336
2462
|
*/
|
|
2337
2463
|
async function resolveGrantTarget(argv) {
|
|
2338
2464
|
const session = requireSession(argv);
|
|
2339
|
-
const [{ devices, agents }, identity] = await Promise.all([fetchPortalDevices(session), resolveMachineIdentity()]);
|
|
2465
|
+
const [{ devices, agents }, identity] = await Promise.all([fetchPortalDevices(session), resolveMachineIdentity(null)]);
|
|
2340
2466
|
return {
|
|
2341
2467
|
session,
|
|
2342
|
-
agent: resolveAgent(agents, argv.agent),
|
|
2468
|
+
agent: resolveAgent$1(agents, argv.agent),
|
|
2343
2469
|
device: findThisDevice(devices, identity.machineName),
|
|
2344
2470
|
identity
|
|
2345
2471
|
};
|
|
@@ -2363,10 +2489,10 @@ const openCommand = {
|
|
|
2363
2489
|
}),
|
|
2364
2490
|
handler: async (argv) => {
|
|
2365
2491
|
const session = requireSession(argv);
|
|
2366
|
-
const agent = argv.agent ? resolveAgent((await fetchPortalDevices(session)).agents, argv.agent) : null;
|
|
2492
|
+
const agent = argv.agent ? resolveAgent$1((await fetchPortalDevices(session)).agents, argv.agent) : null;
|
|
2367
2493
|
const cwd = argv.cwd ? path.resolve(argv.cwd) : process.cwd();
|
|
2368
|
-
const { machineName } = await resolveMachineIdentity();
|
|
2369
|
-
const { PortalDaemonClient } = await import("./daemon-client-
|
|
2494
|
+
const { machineName } = await resolveMachineIdentity(null);
|
|
2495
|
+
const { PortalDaemonClient } = await import("./daemon-client-_SVAskeO.mjs");
|
|
2370
2496
|
let lastLine = "";
|
|
2371
2497
|
let signalConnected;
|
|
2372
2498
|
const connected = new Promise((resolve) => {
|
|
@@ -2395,7 +2521,7 @@ const openCommand = {
|
|
|
2395
2521
|
client.enable();
|
|
2396
2522
|
await connected;
|
|
2397
2523
|
if (agent) {
|
|
2398
|
-
await client.grantAgent(agent.id);
|
|
2524
|
+
await client.grantAgent(agent.id, null);
|
|
2399
2525
|
console.log(`portal: granted ${agent.name} access to this machine (persists until revoked)`);
|
|
2400
2526
|
}
|
|
2401
2527
|
console.log(`portal: open. granted agents can run commands on ${machineName} as your user, cwd ${cwd}. ctrl+c to close.`);
|
|
@@ -2415,7 +2541,8 @@ const grantCommand = {
|
|
|
2415
2541
|
})).id;
|
|
2416
2542
|
await grantPortalAccess(session, {
|
|
2417
2543
|
deviceId,
|
|
2418
|
-
agentId: agent.id
|
|
2544
|
+
agentId: agent.id,
|
|
2545
|
+
conversationId: null
|
|
2419
2546
|
});
|
|
2420
2547
|
if (argv.json) {
|
|
2421
2548
|
output(argv, {
|
|
@@ -2424,7 +2551,7 @@ const grantCommand = {
|
|
|
2424
2551
|
});
|
|
2425
2552
|
return;
|
|
2426
2553
|
}
|
|
2427
|
-
console.log(`Granted ${agent.name} access to ${device?.friendlyName ?? friendlyName}. The agent can run commands here whenever its portal is open. Start with \`skydive portal open\`, or pass \`--share-machine\` on a \`chat -p\` run. Revoke with \`skydive portal revoke --agent ${agent.name}\`.`);
|
|
2554
|
+
console.log(`Granted ${agent.name} access to ${device?.friendlyName ?? friendlyName}. The agent can run commands here whenever its portal is open. Start with \`skydive portal open\`, or pass \`--share-machine\` on a \`chat -p\` run. Revoke with \`skydive portal revoke --agent "${agent.name}"\`.`);
|
|
2428
2555
|
}
|
|
2429
2556
|
};
|
|
2430
2557
|
const revokeCommand = {
|
|
@@ -2464,7 +2591,7 @@ const statusCommand = {
|
|
|
2464
2591
|
console.log("No machines registered. Run `skydive portal open` to register this one.");
|
|
2465
2592
|
return;
|
|
2466
2593
|
}
|
|
2467
|
-
const { headers, rows } = buildDeviceTable(devices, agents, (await resolveMachineIdentity()).machineName);
|
|
2594
|
+
const { headers, rows } = buildDeviceTable(devices, agents, (await resolveMachineIdentity(null)).machineName);
|
|
2468
2595
|
printTable(headers, rows);
|
|
2469
2596
|
}
|
|
2470
2597
|
};
|
|
@@ -2592,17 +2719,56 @@ const daemonCommand = {
|
|
|
2592
2719
|
builder: (y) => y.command(daemonStatusCommand).command(daemonStopCommand).command(daemonStartCommand).command(daemonRestartCommand).command(daemonLogsCommand).demandCommand(1, "Specify a subcommand: status, stop, start, restart, logs"),
|
|
2593
2720
|
handler: () => {}
|
|
2594
2721
|
};
|
|
2722
|
+
const forwardCommand = {
|
|
2723
|
+
command: "forward <port>",
|
|
2724
|
+
describe: "Forward localhost:<port> to the agent sandbox's port, so a dev server running in the sandbox is reachable at http://localhost:<port> (stays in the foreground; ctrl+c to stop)",
|
|
2725
|
+
builder: (y) => y.positional("port", {
|
|
2726
|
+
type: "number",
|
|
2727
|
+
demandOption: true,
|
|
2728
|
+
describe: "Sandbox port to forward to (e.g. 3000 for a dev server)"
|
|
2729
|
+
}).option("agent", {
|
|
2730
|
+
type: "string",
|
|
2731
|
+
describe: "Agent, by id or name (defaults when the account has one)"
|
|
2732
|
+
}).option("local-port", {
|
|
2733
|
+
type: "number",
|
|
2734
|
+
describe: "Local port to listen on (default: same as <port>)"
|
|
2735
|
+
}),
|
|
2736
|
+
handler: async (argv) => {
|
|
2737
|
+
const session = requireSession(argv);
|
|
2738
|
+
const agent = resolveAgent$1((await fetchPortalDevices(session)).agents, argv.agent ?? null);
|
|
2739
|
+
const targetPort = argv.port;
|
|
2740
|
+
const localPort = argv["local-port"] ?? targetPort;
|
|
2741
|
+
const { startForward } = await import("./forward-zwB55Bls.mjs");
|
|
2742
|
+
const { defaultTlsCertSource } = await import("./tls-cert-CLgSQALB.mjs");
|
|
2743
|
+
const log = (msg) => console.error(msg);
|
|
2744
|
+
const listener = await startForward({
|
|
2745
|
+
auth: session,
|
|
2746
|
+
agentId: agent.id,
|
|
2747
|
+
localPort,
|
|
2748
|
+
targetPort,
|
|
2749
|
+
tlsCertSource: defaultTlsCertSource(process.env, log),
|
|
2750
|
+
log
|
|
2751
|
+
});
|
|
2752
|
+
console.log(`Forwarding http://localhost:${listener.port} -> ${agent.name}'s sandbox port ${targetPort}. ctrl+c to stop.`);
|
|
2753
|
+
if (listener.tls) console.log(` https://${listener.tls.hostname}:${listener.tls.port} (TLS — browsers negotiate HTTP/2 here, which loads module-heavy dev servers much faster)`);
|
|
2754
|
+
await new Promise((resolve) => {
|
|
2755
|
+
process.once("SIGINT", () => resolve());
|
|
2756
|
+
process.once("SIGTERM", () => resolve());
|
|
2757
|
+
});
|
|
2758
|
+
await listener.close();
|
|
2759
|
+
}
|
|
2760
|
+
};
|
|
2595
2761
|
const portalCommand = {
|
|
2596
2762
|
command: "portal",
|
|
2597
2763
|
describe: "Open this machine's portal to agents and manage their access",
|
|
2598
|
-
builder: (y) => y.command(openCommand).command(grantCommand).command(revokeCommand).command(statusCommand).command(daemonCommand).demandCommand(1, "Specify a subcommand: open, grant, revoke, status, daemon"),
|
|
2764
|
+
builder: (y) => y.command(openCommand).command(grantCommand).command(revokeCommand).command(statusCommand).command(forwardCommand).command(daemonCommand).demandCommand(1, "Specify a subcommand: open, grant, revoke, status, forward, daemon"),
|
|
2599
2765
|
handler: () => {}
|
|
2600
2766
|
};
|
|
2601
2767
|
|
|
2602
2768
|
//#endregion
|
|
2603
2769
|
//#region src/commands/sandbox.ts
|
|
2604
2770
|
/** POSIX single-quote one word so the remote shell treats it as one token. */
|
|
2605
|
-
function shellQuote
|
|
2771
|
+
function shellQuote(word) {
|
|
2606
2772
|
if (/^[A-Za-z0-9_@%+=:,./-]+$/.test(word)) return word;
|
|
2607
2773
|
return `'${word.replace(/'/g, `'\\''`)}'`;
|
|
2608
2774
|
}
|
|
@@ -2617,7 +2783,7 @@ function shellQuote$1(word) {
|
|
|
2617
2783
|
* for too. yargs number-coerces bare numerals, so words are stringified.
|
|
2618
2784
|
*/
|
|
2619
2785
|
function joinCommandWords(words) {
|
|
2620
|
-
return words.map(String).map(shellQuote
|
|
2786
|
+
return words.map(String).map(shellQuote).join(" ").trim();
|
|
2621
2787
|
}
|
|
2622
2788
|
/**
|
|
2623
2789
|
* `skydive sandbox` — the standalone counterpart to the chat TUI's `/sandbox`
|
|
@@ -2640,8 +2806,8 @@ const sandboxCommand = {
|
|
|
2640
2806
|
}).example("skydive sandbox --agent grace", "Live terminal (Ctrl-] detaches)").example("skydive sandbox --agent grace -- tail -n 50 /tmp/harness.log", "One-shot command (use `--` so its flags reach the sandbox)").example("skydive sandbox --agent grace -- sh -c 'ls /tmp | wc -l'", "Shell features go through an explicit `sh -c`"),
|
|
2641
2807
|
handler: async (argv) => {
|
|
2642
2808
|
const session = requireSession(argv);
|
|
2643
|
-
const { createRestClient } = await import("./rest-
|
|
2644
|
-
const { resolveAgent } = await import("./print-
|
|
2809
|
+
const { createRestClient } = await import("./rest-B5DVQ1LM.mjs");
|
|
2810
|
+
const { resolveAgent } = await import("./print-BAmEefvX.mjs");
|
|
2645
2811
|
const client = createRestClient({
|
|
2646
2812
|
appUrl: session.appUrl,
|
|
2647
2813
|
sessionToken: session.sessionToken
|
|
@@ -2710,7 +2876,7 @@ async function runPty({ session, agentId, agentName }) {
|
|
|
2710
2876
|
return 1;
|
|
2711
2877
|
}
|
|
2712
2878
|
console.error(`Connecting to ${agentName}'s sandbox… (Ctrl-] detaches)`);
|
|
2713
|
-
const { runRawPtyPassthrough } = await import("./raw-pty-
|
|
2879
|
+
const { runRawPtyPassthrough } = await import("./raw-pty-Ci2qFR9F.mjs");
|
|
2714
2880
|
const result = await runRawPtyPassthrough({
|
|
2715
2881
|
stdin: process.stdin,
|
|
2716
2882
|
stdout: process.stdout,
|
|
@@ -2722,40 +2888,151 @@ async function runPty({ session, agentId, agentName }) {
|
|
|
2722
2888
|
return result.code;
|
|
2723
2889
|
}
|
|
2724
2890
|
|
|
2891
|
+
//#endregion
|
|
2892
|
+
//#region src/chat/sandbox/fs-client.ts
|
|
2893
|
+
function wsBase(appUrl) {
|
|
2894
|
+
const base = appUrl.replace(/\/+$/, "");
|
|
2895
|
+
if (base.startsWith("https://")) return `wss://${base.slice(8)}`;
|
|
2896
|
+
if (base.startsWith("http://")) return `ws://${base.slice(7)}`;
|
|
2897
|
+
return `wss://${base}`;
|
|
2898
|
+
}
|
|
2899
|
+
function toU8(data) {
|
|
2900
|
+
if (Buffer.isBuffer(data)) return new Uint8Array(data);
|
|
2901
|
+
if (Array.isArray(data)) return new Uint8Array(Buffer.concat(data));
|
|
2902
|
+
return new Uint8Array(Buffer.from(data));
|
|
2903
|
+
}
|
|
2904
|
+
var SandboxFsClient = class SandboxFsClient {
|
|
2905
|
+
ws;
|
|
2906
|
+
ready;
|
|
2907
|
+
nextReqId = 1;
|
|
2908
|
+
pending = /* @__PURE__ */ new Map();
|
|
2909
|
+
closedReason = null;
|
|
2910
|
+
constructor(opts) {
|
|
2911
|
+
const spec = {
|
|
2912
|
+
mode: "fs",
|
|
2913
|
+
agentId: opts.agentId
|
|
2914
|
+
};
|
|
2915
|
+
const url = new URL(`${wsBase(opts.appUrl)}${SANDBOX_STREAM_PATH}`);
|
|
2916
|
+
for (const [key, value] of Object.entries(streamSpecToQuery(spec))) url.searchParams.set(key, value);
|
|
2917
|
+
this.ws = new WebSocket(url.toString(), { headers: { authorization: `Bearer ${opts.sessionToken}` } });
|
|
2918
|
+
this.ws.binaryType = "nodebuffer";
|
|
2919
|
+
this.ready = new Promise((resolve, reject) => {
|
|
2920
|
+
this.ws.once("open", () => resolve());
|
|
2921
|
+
this.ws.once("error", (err) => reject(err));
|
|
2922
|
+
});
|
|
2923
|
+
this.ws.on("message", (data, isBinary) => {
|
|
2924
|
+
if (!isBinary) return;
|
|
2925
|
+
const res = decodeFsResponse(toU8(data));
|
|
2926
|
+
if (!res) return;
|
|
2927
|
+
const p = this.pending.get(res.reqId);
|
|
2928
|
+
if (!p) return;
|
|
2929
|
+
this.pending.delete(res.reqId);
|
|
2930
|
+
if (res.status === "error") p.reject(new Error(res.message));
|
|
2931
|
+
else p.resolve({
|
|
2932
|
+
result: res.result,
|
|
2933
|
+
blob: res.blob
|
|
2934
|
+
});
|
|
2935
|
+
});
|
|
2936
|
+
const failAll = (reason) => {
|
|
2937
|
+
this.closedReason = reason;
|
|
2938
|
+
for (const [, p] of this.pending) p.reject(new Error(reason));
|
|
2939
|
+
this.pending.clear();
|
|
2940
|
+
};
|
|
2941
|
+
this.ws.on("error", (err) => failAll(err.message));
|
|
2942
|
+
this.ws.on("close", () => failAll(this.closedReason ?? "the sandbox filesystem connection closed"));
|
|
2943
|
+
}
|
|
2944
|
+
/** Open and wait for the channel to be ready to accept requests. */
|
|
2945
|
+
static async connect(opts) {
|
|
2946
|
+
const client = new SandboxFsClient(opts);
|
|
2947
|
+
await client.ready;
|
|
2948
|
+
return client;
|
|
2949
|
+
}
|
|
2950
|
+
request(req, blob) {
|
|
2951
|
+
if (this.closedReason) return Promise.reject(new Error(this.closedReason));
|
|
2952
|
+
const reqId = this.nextReqId++;
|
|
2953
|
+
return new Promise((resolve, reject) => {
|
|
2954
|
+
this.pending.set(reqId, {
|
|
2955
|
+
resolve,
|
|
2956
|
+
reject
|
|
2957
|
+
});
|
|
2958
|
+
try {
|
|
2959
|
+
this.ws.send(encodeFsRequest(reqId, req, blob));
|
|
2960
|
+
} catch (error) {
|
|
2961
|
+
this.pending.delete(reqId);
|
|
2962
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2963
|
+
}
|
|
2964
|
+
});
|
|
2965
|
+
}
|
|
2966
|
+
async list(path) {
|
|
2967
|
+
const { result } = await this.request({
|
|
2968
|
+
op: "list",
|
|
2969
|
+
path
|
|
2970
|
+
}, null);
|
|
2971
|
+
const entries = result["entries"];
|
|
2972
|
+
if (!Array.isArray(entries)) return [];
|
|
2973
|
+
return entries;
|
|
2974
|
+
}
|
|
2975
|
+
async stat(path) {
|
|
2976
|
+
const { result } = await this.request({
|
|
2977
|
+
op: "stat",
|
|
2978
|
+
path
|
|
2979
|
+
}, null);
|
|
2980
|
+
return result["stat"];
|
|
2981
|
+
}
|
|
2982
|
+
async read(path, range) {
|
|
2983
|
+
const req = range ? {
|
|
2984
|
+
op: "read",
|
|
2985
|
+
path,
|
|
2986
|
+
offset: range.offset,
|
|
2987
|
+
length: range.length
|
|
2988
|
+
} : {
|
|
2989
|
+
op: "read",
|
|
2990
|
+
path
|
|
2991
|
+
};
|
|
2992
|
+
const { blob } = await this.request(req, null);
|
|
2993
|
+
return blob;
|
|
2994
|
+
}
|
|
2995
|
+
async write(path, data) {
|
|
2996
|
+
await this.request({
|
|
2997
|
+
op: "write",
|
|
2998
|
+
path
|
|
2999
|
+
}, data);
|
|
3000
|
+
}
|
|
3001
|
+
async mkdir(path) {
|
|
3002
|
+
await this.request({
|
|
3003
|
+
op: "mkdir",
|
|
3004
|
+
path
|
|
3005
|
+
}, null);
|
|
3006
|
+
}
|
|
3007
|
+
async rename(oldPath, newPath) {
|
|
3008
|
+
await this.request({
|
|
3009
|
+
op: "rename",
|
|
3010
|
+
oldPath,
|
|
3011
|
+
newPath
|
|
3012
|
+
}, null);
|
|
3013
|
+
}
|
|
3014
|
+
async remove(path) {
|
|
3015
|
+
await this.request({
|
|
3016
|
+
op: "remove",
|
|
3017
|
+
path
|
|
3018
|
+
}, null);
|
|
3019
|
+
}
|
|
3020
|
+
async exists(path) {
|
|
3021
|
+
const { result } = await this.request({
|
|
3022
|
+
op: "exists",
|
|
3023
|
+
path
|
|
3024
|
+
}, null);
|
|
3025
|
+
return result["exists"] === true;
|
|
3026
|
+
}
|
|
3027
|
+
close() {
|
|
3028
|
+
this.closedReason ??= "closed by caller";
|
|
3029
|
+
this.ws.close();
|
|
3030
|
+
}
|
|
3031
|
+
};
|
|
3032
|
+
|
|
2725
3033
|
//#endregion
|
|
2726
3034
|
//#region src/commands/fs.ts
|
|
2727
3035
|
/**
|
|
2728
|
-
* POSIX-quote one word so the remote shell treats it as a single token. Wraps
|
|
2729
|
-
* `shell-quote`'s `quote` (already a repo dependency, used elsewhere in the
|
|
2730
|
-
* CLI) rather than hand-rolling the escaping — it is the well-tested source of
|
|
2731
|
-
* truth for making a path/arg with spaces, quotes, `$`, `;`, globs, etc. inert
|
|
2732
|
-
* when interpolated into an `sh -c` line.
|
|
2733
|
-
*/
|
|
2734
|
-
function shellQuote(word) {
|
|
2735
|
-
return quote([word]);
|
|
2736
|
-
}
|
|
2737
|
-
const MISSING_FILE_EXIT = 44;
|
|
2738
|
-
/**
|
|
2739
|
-
* Build the remote shell command that base64-encodes a file to stdout. Exits
|
|
2740
|
-
* {@link MISSING_FILE_EXIT} when the path doesn't exist, 1 when it's a
|
|
2741
|
-
* directory, so the caller can tell "create new" from a genuine error.
|
|
2742
|
-
*/
|
|
2743
|
-
function buildReadCommand(path) {
|
|
2744
|
-
const q = shellQuote(path);
|
|
2745
|
-
return `sh -c ${shellQuote(`if [ ! -e ${q} ]; then exit ${MISSING_FILE_EXIT}; fi; if [ -d ${q} ]; then echo 'path is a directory' >&2; exit 1; fi; base64 < ${q}`)}`;
|
|
2746
|
-
}
|
|
2747
|
-
/**
|
|
2748
|
-
* Build the remote shell command that decodes `b64` and writes it to `path`
|
|
2749
|
-
* atomically (temp file + `mv`) so a dropped connection can't truncate the
|
|
2750
|
-
* original in place. `token` is a caller-supplied unique suffix for the temp
|
|
2751
|
-
* file — generated in JS (not the shell's `$$`, which shell-quote would escape
|
|
2752
|
-
* to a literal, so every write would collide on the same temp name).
|
|
2753
|
-
*/
|
|
2754
|
-
function buildWriteCommand(path, b64, token) {
|
|
2755
|
-
const tmp = `${path}.skydive-edit.${token}`;
|
|
2756
|
-
return `sh -c ${shellQuote(`printf %s ${shellQuote(b64)} | base64 -d > ${shellQuote(tmp)} && mv -f ${shellQuote(tmp)} ${shellQuote(path)}`)}`;
|
|
2757
|
-
}
|
|
2758
|
-
/**
|
|
2759
3036
|
* Resolve the editor command from an explicit override, then $VISUAL, $EDITOR,
|
|
2760
3037
|
* then `vi`. Split so `EDITOR="code --wait"` (command + flags) is honored.
|
|
2761
3038
|
*/
|
|
@@ -2769,17 +3046,17 @@ function resolveEditor(override, env) {
|
|
|
2769
3046
|
/**
|
|
2770
3047
|
* `skydive fs edit <path>` — edit a file that lives on the agent's computer
|
|
2771
3048
|
* (its sandbox) with your LOCAL editor. It reads the remote file down over the
|
|
2772
|
-
*
|
|
2773
|
-
* changes back when you save and close — so you edit a remote file as if
|
|
2774
|
-
* were local, without opening the chat TUI.
|
|
3049
|
+
* multiplexed `fs` sandbox-stream channel, opens it in `$EDITOR`, and writes
|
|
3050
|
+
* your changes back when you save and close — so you edit a remote file as if
|
|
3051
|
+
* it were local, without opening the chat TUI.
|
|
2775
3052
|
*
|
|
2776
|
-
*
|
|
2777
|
-
*
|
|
2778
|
-
*
|
|
2779
|
-
* embedded
|
|
2780
|
-
*
|
|
2781
|
-
*
|
|
2782
|
-
*
|
|
3053
|
+
* It rides the first-class `fs` relay channel ({@link SandboxFsClient}): file
|
|
3054
|
+
* bytes move as the frame's trailing binary blob in BOTH directions, so binary
|
|
3055
|
+
* content, trailing newlines, and CRLF are preserved and — unlike the old
|
|
3056
|
+
* exec-mode path that embedded a base64 payload in the upgrade URL — a large
|
|
3057
|
+
* file no longer blows past the WebSocket URL / request-header length limit.
|
|
3058
|
+
* Access gating (EDIT on the agent + the `sandbox-fs-enabled` kill switch) is
|
|
3059
|
+
* enforced by the relay, exactly as for `skydive sandbox`.
|
|
2783
3060
|
*/
|
|
2784
3061
|
const fsEditCommand = {
|
|
2785
3062
|
command: "edit <path>",
|
|
@@ -2798,8 +3075,8 @@ const fsEditCommand = {
|
|
|
2798
3075
|
handler: async (argv) => {
|
|
2799
3076
|
const session = requireSession(argv);
|
|
2800
3077
|
const remotePath = argv.path;
|
|
2801
|
-
const { createRestClient } = await import("./rest-
|
|
2802
|
-
const { resolveAgent } = await import("./print-
|
|
3078
|
+
const { createRestClient } = await import("./rest-B5DVQ1LM.mjs");
|
|
3079
|
+
const { resolveAgent } = await import("./print-BAmEefvX.mjs");
|
|
2803
3080
|
const client = createRestClient({
|
|
2804
3081
|
appUrl: session.appUrl,
|
|
2805
3082
|
sessionToken: session.sessionToken
|
|
@@ -2814,148 +3091,63 @@ const fsEditCommand = {
|
|
|
2814
3091
|
printError(error instanceof Error ? error.message : String(error));
|
|
2815
3092
|
process.exit(1);
|
|
2816
3093
|
}
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
if (read.kind === "error") {
|
|
2827
|
-
printError(read.message);
|
|
3094
|
+
let fs;
|
|
3095
|
+
try {
|
|
3096
|
+
fs = await SandboxFsClient.connect({
|
|
3097
|
+
appUrl: session.appUrl,
|
|
3098
|
+
sessionToken: session.sessionToken,
|
|
3099
|
+
agentId: agent.id
|
|
3100
|
+
});
|
|
3101
|
+
} catch (error) {
|
|
3102
|
+
printError(`Could not open the sandbox filesystem channel: ${error instanceof Error ? error.message : String(error)}`);
|
|
2828
3103
|
process.exit(1);
|
|
2829
3104
|
}
|
|
2830
|
-
const
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
3105
|
+
const cleanup = async (dir) => {
|
|
3106
|
+
await rm(dir, {
|
|
3107
|
+
recursive: true,
|
|
3108
|
+
force: true
|
|
3109
|
+
}).catch((error) => {
|
|
3110
|
+
console.error(`Note: could not remove temp dir ${dir}: ${error instanceof Error ? error.message : String(error)}`);
|
|
3111
|
+
});
|
|
3112
|
+
};
|
|
3113
|
+
let local = null;
|
|
3114
|
+
let dir = null;
|
|
2834
3115
|
try {
|
|
3116
|
+
console.error(`Reading ${remotePath} from ${agent.name}'s sandbox…`);
|
|
3117
|
+
const isNew = !await fs.exists(remotePath);
|
|
3118
|
+
const original = isNew ? Buffer.alloc(0) : Buffer.from(await fs.read(remotePath, null));
|
|
3119
|
+
if (isNew) console.error(`${remotePath} does not exist yet — it will be created when you save.`);
|
|
3120
|
+
dir = await mkdtemp(join(tmpdir(), "skydive-edit-"));
|
|
3121
|
+
const base = remotePath.split("/").pop() || "file";
|
|
3122
|
+
local = join(dir, base);
|
|
2835
3123
|
await writeFile(local, original);
|
|
2836
3124
|
if (!await openEditor(argv.editor, local)) {
|
|
2837
3125
|
printError("Editor exited non-zero; not saving any changes.");
|
|
3126
|
+
fs.close();
|
|
3127
|
+
await cleanup(dir);
|
|
2838
3128
|
process.exit(1);
|
|
2839
3129
|
}
|
|
2840
3130
|
const edited = await readFile(local);
|
|
2841
3131
|
if (edited.equals(original)) {
|
|
2842
3132
|
console.error("No changes — nothing written.");
|
|
3133
|
+
fs.close();
|
|
3134
|
+
await cleanup(dir);
|
|
2843
3135
|
process.exit(0);
|
|
2844
3136
|
}
|
|
2845
3137
|
console.error(`Writing changes back to ${remotePath}…`);
|
|
2846
|
-
|
|
2847
|
-
...opts,
|
|
2848
|
-
path: remotePath,
|
|
2849
|
-
content: edited
|
|
2850
|
-
});
|
|
2851
|
-
if (wrote.kind === "error") {
|
|
2852
|
-
printError(`${wrote.message}\nYour edited copy is kept at ${local} so you don't lose it.`);
|
|
2853
|
-
process.exit(1);
|
|
2854
|
-
}
|
|
3138
|
+
await fs.write(remotePath, new Uint8Array(edited));
|
|
2855
3139
|
console.error("Saved.");
|
|
3140
|
+
fs.close();
|
|
3141
|
+
await cleanup(dir);
|
|
2856
3142
|
process.exit(0);
|
|
2857
|
-
}
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
}).catch((error) => {
|
|
2862
|
-
console.error(`Note: could not remove temp dir ${dir}: ${error instanceof Error ? error.message : String(error)}`);
|
|
2863
|
-
});
|
|
3143
|
+
} catch (error) {
|
|
3144
|
+
fs.close();
|
|
3145
|
+
printError(`${error instanceof Error ? error.message : String(error)}${local ? `\nYour edited copy is kept at ${local} so you don't lose it.` : ""}`);
|
|
3146
|
+
process.exit(1);
|
|
2864
3147
|
}
|
|
2865
3148
|
}
|
|
2866
3149
|
};
|
|
2867
3150
|
/**
|
|
2868
|
-
* Read a remote file as bytes. Runs `base64` on the file in the sandbox and
|
|
2869
|
-
* decodes the streamed stdout locally. Distinguishes "file is missing" (exit
|
|
2870
|
-
* code 44, so `edit` can create it) from a real read failure.
|
|
2871
|
-
*/
|
|
2872
|
-
function readRemote({ session, agentId, path }) {
|
|
2873
|
-
const command = buildReadCommand(path);
|
|
2874
|
-
const chunks = [];
|
|
2875
|
-
const stderr = [];
|
|
2876
|
-
return new Promise((resolve) => {
|
|
2877
|
-
SandboxStream.open({
|
|
2878
|
-
mode: "exec",
|
|
2879
|
-
appUrl: session.appUrl,
|
|
2880
|
-
sessionToken: session.sessionToken,
|
|
2881
|
-
agentId,
|
|
2882
|
-
command,
|
|
2883
|
-
onEvent: (e) => {
|
|
2884
|
-
switch (e.type) {
|
|
2885
|
-
case "data":
|
|
2886
|
-
chunks.push(Buffer.from(e.bytes));
|
|
2887
|
-
break;
|
|
2888
|
-
case "exit":
|
|
2889
|
-
if (e.code === MISSING_FILE_EXIT) resolve({
|
|
2890
|
-
kind: "missing",
|
|
2891
|
-
content: Buffer.alloc(0)
|
|
2892
|
-
});
|
|
2893
|
-
else if (e.code === 0) resolve({
|
|
2894
|
-
kind: "ok",
|
|
2895
|
-
content: Buffer.from(Buffer.concat(chunks).toString("utf8").replace(/\s+/g, ""), "base64")
|
|
2896
|
-
});
|
|
2897
|
-
else resolve({
|
|
2898
|
-
kind: "error",
|
|
2899
|
-
message: stderr.join("").trim() || `Could not read the file (exit ${e.code}).`
|
|
2900
|
-
});
|
|
2901
|
-
break;
|
|
2902
|
-
case "error":
|
|
2903
|
-
stderr.push(e.message);
|
|
2904
|
-
break;
|
|
2905
|
-
case "close":
|
|
2906
|
-
resolve({
|
|
2907
|
-
kind: "error",
|
|
2908
|
-
message: e.failure || "The connection to the sandbox closed before the file could be read."
|
|
2909
|
-
});
|
|
2910
|
-
break;
|
|
2911
|
-
}
|
|
2912
|
-
}
|
|
2913
|
-
});
|
|
2914
|
-
});
|
|
2915
|
-
}
|
|
2916
|
-
/**
|
|
2917
|
-
* Write bytes to a remote file. Exec has no stdin, so the base64 payload is
|
|
2918
|
-
* embedded in the command and decoded on the far side. Writes atomically via a
|
|
2919
|
-
* temp file + `mv` so a dropped connection mid-write can't leave a truncated
|
|
2920
|
-
* file in place of the original.
|
|
2921
|
-
*/
|
|
2922
|
-
function writeRemote({ session, agentId, path, content }) {
|
|
2923
|
-
const token = randomBytes(6).toString("hex");
|
|
2924
|
-
const command = buildWriteCommand(path, content.toString("base64"), token);
|
|
2925
|
-
const stderr = [];
|
|
2926
|
-
return new Promise((resolve) => {
|
|
2927
|
-
SandboxStream.open({
|
|
2928
|
-
mode: "exec",
|
|
2929
|
-
appUrl: session.appUrl,
|
|
2930
|
-
sessionToken: session.sessionToken,
|
|
2931
|
-
agentId,
|
|
2932
|
-
command,
|
|
2933
|
-
onEvent: (e) => {
|
|
2934
|
-
switch (e.type) {
|
|
2935
|
-
case "data":
|
|
2936
|
-
stderr.push(Buffer.from(e.bytes).toString("utf8"));
|
|
2937
|
-
break;
|
|
2938
|
-
case "exit":
|
|
2939
|
-
resolve(e.code === 0 ? { kind: "ok" } : {
|
|
2940
|
-
kind: "error",
|
|
2941
|
-
message: stderr.join("").trim() || `Could not write the file (exit ${e.code}).`
|
|
2942
|
-
});
|
|
2943
|
-
break;
|
|
2944
|
-
case "error":
|
|
2945
|
-
stderr.push(e.message);
|
|
2946
|
-
break;
|
|
2947
|
-
case "close":
|
|
2948
|
-
resolve({
|
|
2949
|
-
kind: "error",
|
|
2950
|
-
message: e.failure || "The connection to the sandbox closed before the file was written."
|
|
2951
|
-
});
|
|
2952
|
-
break;
|
|
2953
|
-
}
|
|
2954
|
-
}
|
|
2955
|
-
});
|
|
2956
|
-
});
|
|
2957
|
-
}
|
|
2958
|
-
/**
|
|
2959
3151
|
* Open `file` in the caller's editor and resolve to whether it exited cleanly.
|
|
2960
3152
|
* Precedence: explicit `--editor`, then $VISUAL, $EDITOR, then `vi`. The editor
|
|
2961
3153
|
* inherits the real TTY so full-screen editors (vim/nano) work.
|
|
@@ -2978,7 +3170,7 @@ function openEditor(override, file) {
|
|
|
2978
3170
|
*
|
|
2979
3171
|
* - `fs edit <path>` edit one remote file with your local editor (shipped).
|
|
2980
3172
|
* - `fs mount <dir>` mount the whole sandbox filesystem locally (coming in a
|
|
2981
|
-
* later PR, on
|
|
3173
|
+
* later PR, on the same first-class `fs` relay channel).
|
|
2982
3174
|
*
|
|
2983
3175
|
* Grouping these under one command keeps the file surface discoverable and
|
|
2984
3176
|
* leaves room to grow (`fs ls`, `fs cat`, `fs pull`) without adding more
|
|
@@ -3266,7 +3458,27 @@ function resolveSelfPath(execPath = process.execPath) {
|
|
|
3266
3458
|
|
|
3267
3459
|
//#endregion
|
|
3268
3460
|
//#region src/update-check/sources.ts
|
|
3461
|
+
/**
|
|
3462
|
+
* How this CLI was installed, which decides whether `skydive update` (and the
|
|
3463
|
+
* background update check) self-updates the binary from the release CDN or
|
|
3464
|
+
* hands off to the package manager.
|
|
3465
|
+
*
|
|
3466
|
+
* Two signals, runtime env first:
|
|
3467
|
+
* - `SKYDIVE_CLI_INSTALL_SOURCE` env var — set by the npm launcher
|
|
3468
|
+
* (src/launcher.ts) to `package-manager` before it execs the compiled
|
|
3469
|
+
* binary. The binary itself is `--define`'d to `binary`, but when it was
|
|
3470
|
+
* launched via the npm-installed launcher, npm owns its bytes and must not
|
|
3471
|
+
* be self-mutated — so the env override wins.
|
|
3472
|
+
* - The `SKYDIVE_CLI_INSTALL_SOURCE` compile-time constant — stamped
|
|
3473
|
+
* `binary` into the standalone binary, undefined in the npm JS bundle.
|
|
3474
|
+
*
|
|
3475
|
+
* Any value other than exactly `binary` (including unset) means
|
|
3476
|
+
* package-manager, the safe default: we never self-update something we can't
|
|
3477
|
+
* prove is a standalone binary.
|
|
3478
|
+
*/
|
|
3269
3479
|
function resolveInstallSource() {
|
|
3480
|
+
const runtime = typeof process !== "undefined" ? process.env?.["SKYDIVE_CLI_INSTALL_SOURCE"] : void 0;
|
|
3481
|
+
if (runtime !== void 0) return runtime === "binary" ? "binary" : "package-manager";
|
|
3270
3482
|
return typeof SKYDIVE_CLI_INSTALL_SOURCE === "string" && SKYDIVE_CLI_INSTALL_SOURCE === "binary" ? "binary" : "package-manager";
|
|
3271
3483
|
}
|
|
3272
3484
|
const NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
@@ -3680,6 +3892,11 @@ function resolvePreference(key) {
|
|
|
3680
3892
|
}
|
|
3681
3893
|
return pref;
|
|
3682
3894
|
}
|
|
3895
|
+
/** Human rendering of a preference value; unset string preferences (null)
|
|
3896
|
+
* print as empty rather than the string "null". */
|
|
3897
|
+
function formatValue(value) {
|
|
3898
|
+
return value === null ? "" : String(value);
|
|
3899
|
+
}
|
|
3683
3900
|
/** One row's worth of state for a preference, used by `list` and `get`. */
|
|
3684
3901
|
function snapshot(pref) {
|
|
3685
3902
|
return {
|
|
@@ -3689,7 +3906,7 @@ function snapshot(pref) {
|
|
|
3689
3906
|
describe: pref.describe
|
|
3690
3907
|
};
|
|
3691
3908
|
}
|
|
3692
|
-
const listCommand = {
|
|
3909
|
+
const listCommand$1 = {
|
|
3693
3910
|
command: "list",
|
|
3694
3911
|
aliases: ["ls"],
|
|
3695
3912
|
describe: "Show every editable preference, its value, and its source",
|
|
@@ -3706,7 +3923,7 @@ const listCommand = {
|
|
|
3706
3923
|
"Description"
|
|
3707
3924
|
], rows.map((r) => [
|
|
3708
3925
|
r.key,
|
|
3709
|
-
|
|
3926
|
+
formatValue(r.value),
|
|
3710
3927
|
r.source,
|
|
3711
3928
|
r.describe
|
|
3712
3929
|
]));
|
|
@@ -3727,7 +3944,7 @@ const getCommand = {
|
|
|
3727
3944
|
output(argv, snapshot(pref));
|
|
3728
3945
|
return;
|
|
3729
3946
|
}
|
|
3730
|
-
console.log(
|
|
3947
|
+
console.log(formatValue(pref.read()));
|
|
3731
3948
|
}
|
|
3732
3949
|
};
|
|
3733
3950
|
const setCommand = {
|
|
@@ -3745,17 +3962,16 @@ const setCommand = {
|
|
|
3745
3962
|
}),
|
|
3746
3963
|
handler: (argv) => {
|
|
3747
3964
|
const pref = resolvePreference(argv.key);
|
|
3748
|
-
const
|
|
3749
|
-
if (
|
|
3750
|
-
printError(`${pref.key}: ${
|
|
3965
|
+
const result = pref.set(argv.value ?? "");
|
|
3966
|
+
if (result.isErr()) {
|
|
3967
|
+
printError(`${pref.key}: ${result.error}`);
|
|
3751
3968
|
process.exit(1);
|
|
3752
3969
|
}
|
|
3753
|
-
pref.write(parsed.value);
|
|
3754
3970
|
if (argv.json) {
|
|
3755
3971
|
output(argv, snapshot(pref));
|
|
3756
3972
|
return;
|
|
3757
3973
|
}
|
|
3758
|
-
if (!argv.quiet) console.log(`Set ${pref.key} = ${
|
|
3974
|
+
if (!argv.quiet) console.log(`Set ${pref.key} = ${formatValue(pref.read())}`);
|
|
3759
3975
|
}
|
|
3760
3976
|
};
|
|
3761
3977
|
const unsetCommand = {
|
|
@@ -3775,10 +3991,13 @@ const unsetCommand = {
|
|
|
3775
3991
|
output(argv, snapshot(pref));
|
|
3776
3992
|
return;
|
|
3777
3993
|
}
|
|
3778
|
-
if (!argv.quiet)
|
|
3994
|
+
if (!argv.quiet) {
|
|
3995
|
+
const fallback = pref.read();
|
|
3996
|
+
console.log(fallback === null ? `Unset ${pref.key}` : `Unset ${pref.key} (now ${formatValue(fallback)} by default)`);
|
|
3997
|
+
}
|
|
3779
3998
|
}
|
|
3780
3999
|
};
|
|
3781
|
-
const pathCommand = {
|
|
4000
|
+
const pathCommand$1 = {
|
|
3782
4001
|
command: "path",
|
|
3783
4002
|
describe: "Print the on-disk config file path",
|
|
3784
4003
|
handler: (argv) => {
|
|
@@ -3792,14 +4011,172 @@ const pathCommand = {
|
|
|
3792
4011
|
const configCommand = {
|
|
3793
4012
|
command: "config",
|
|
3794
4013
|
describe: "View and set CLI preferences (safe, hand-editable keys only)",
|
|
3795
|
-
builder: (y) => y.command(listCommand).command(getCommand).command(setCommand).command(unsetCommand).command(pathCommand),
|
|
4014
|
+
builder: (y) => y.command(listCommand$1).command(getCommand).command(setCommand).command(unsetCommand).command(pathCommand$1),
|
|
4015
|
+
handler: (argv) => listCommand$1.handler(argv)
|
|
4016
|
+
};
|
|
4017
|
+
|
|
4018
|
+
//#endregion
|
|
4019
|
+
//#region src/commands/logs.ts
|
|
4020
|
+
const ISSUE_REPOSITORY_URL = "https://github.com/Create-Inc/skydive-cli";
|
|
4021
|
+
function issueUrl(archivePath) {
|
|
4022
|
+
const url = new URL(`${ISSUE_REPOSITORY_URL}/issues/new`);
|
|
4023
|
+
url.searchParams.set("title", "CLI issue: ");
|
|
4024
|
+
url.searchParams.set("body", [
|
|
4025
|
+
"## What happened?",
|
|
4026
|
+
"",
|
|
4027
|
+
"<!-- Tell us what you were doing and what went wrong. -->",
|
|
4028
|
+
"",
|
|
4029
|
+
"## Diagnostics",
|
|
4030
|
+
"",
|
|
4031
|
+
`Please attach \`${path.basename(archivePath)}\` to this issue.`
|
|
4032
|
+
].join("\n"));
|
|
4033
|
+
return url.toString();
|
|
4034
|
+
}
|
|
4035
|
+
async function listLogSessions(activeSessionPath = profileDir()) {
|
|
4036
|
+
const root = getAutomaticLogsDir();
|
|
4037
|
+
try {
|
|
4038
|
+
const entries = await fs.promises.readdir(root, { withFileTypes: true });
|
|
4039
|
+
return (await Promise.all(entries.filter((entry) => entry.isDirectory() && path.join(root, entry.name) !== activeSessionPath).map(async (entry) => {
|
|
4040
|
+
const sessionPath = path.join(root, entry.name);
|
|
4041
|
+
return {
|
|
4042
|
+
name: entry.name,
|
|
4043
|
+
path: sessionPath,
|
|
4044
|
+
modifiedAt: (await fs.promises.stat(sessionPath)).mtime.toISOString()
|
|
4045
|
+
};
|
|
4046
|
+
}))).sort((a, b) => b.name.localeCompare(a.name));
|
|
4047
|
+
} catch (_error) {
|
|
4048
|
+
return [];
|
|
4049
|
+
}
|
|
4050
|
+
}
|
|
4051
|
+
async function resolveSession(name) {
|
|
4052
|
+
const sessions = await listLogSessions();
|
|
4053
|
+
const session = name ? sessions.find((candidate) => candidate.name === name) : sessions[0];
|
|
4054
|
+
if (session) return session;
|
|
4055
|
+
printError(name ? `Log session "${name}" was not found. Run \`skydive logs list\`.` : "No diagnostic logs found yet.");
|
|
4056
|
+
process.exit(1);
|
|
4057
|
+
}
|
|
4058
|
+
async function offerIssueReport(archivePath) {
|
|
4059
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
4060
|
+
console.log(`Report an issue: ${ISSUE_REPOSITORY_URL}`);
|
|
4061
|
+
return;
|
|
4062
|
+
}
|
|
4063
|
+
const prompt = createInterface$1({
|
|
4064
|
+
input: process.stdin,
|
|
4065
|
+
output: process.stdout
|
|
4066
|
+
});
|
|
4067
|
+
try {
|
|
4068
|
+
if ((await prompt.question("Open a prefilled GitHub issue in your browser? [Y/n] ")).trim().toLowerCase() === "n") {
|
|
4069
|
+
console.log(`File an issue: ${ISSUE_REPOSITORY_URL}`);
|
|
4070
|
+
return;
|
|
4071
|
+
}
|
|
4072
|
+
await open(issueUrl(archivePath));
|
|
4073
|
+
console.log(`Attach the diagnostics archive: ${archivePath}`);
|
|
4074
|
+
} finally {
|
|
4075
|
+
prompt.close();
|
|
4076
|
+
}
|
|
4077
|
+
}
|
|
4078
|
+
async function createArchive(source, destination) {
|
|
4079
|
+
await new Promise((resolve, reject) => {
|
|
4080
|
+
const child = spawn("tar", [
|
|
4081
|
+
"-czf",
|
|
4082
|
+
destination,
|
|
4083
|
+
"-C",
|
|
4084
|
+
path.dirname(source),
|
|
4085
|
+
path.basename(source)
|
|
4086
|
+
], { stdio: [
|
|
4087
|
+
"ignore",
|
|
4088
|
+
"ignore",
|
|
4089
|
+
"pipe"
|
|
4090
|
+
] });
|
|
4091
|
+
const stderr = [];
|
|
4092
|
+
child.stderr.on("data", (chunk) => stderr.push(chunk));
|
|
4093
|
+
child.once("error", reject);
|
|
4094
|
+
child.once("close", (code) => {
|
|
4095
|
+
if (code === 0) {
|
|
4096
|
+
resolve();
|
|
4097
|
+
return;
|
|
4098
|
+
}
|
|
4099
|
+
reject(new Error(Buffer.concat(stderr).toString("utf8").trim() || "Could not archive logs."));
|
|
4100
|
+
});
|
|
4101
|
+
});
|
|
4102
|
+
}
|
|
4103
|
+
const listCommand = {
|
|
4104
|
+
command: "list",
|
|
4105
|
+
aliases: ["ls"],
|
|
4106
|
+
describe: "List recent diagnostic sessions",
|
|
4107
|
+
handler: async (argv) => {
|
|
4108
|
+
const sessions = await listLogSessions();
|
|
4109
|
+
if (argv.json) {
|
|
4110
|
+
output(argv, sessions);
|
|
4111
|
+
return;
|
|
4112
|
+
}
|
|
4113
|
+
if (sessions.length === 0) {
|
|
4114
|
+
console.log("No diagnostic logs found yet.");
|
|
4115
|
+
return;
|
|
4116
|
+
}
|
|
4117
|
+
printTable(["Session", "Modified"], sessions.map((session) => [session.name, session.modifiedAt]));
|
|
4118
|
+
}
|
|
4119
|
+
};
|
|
4120
|
+
const pathCommand = {
|
|
4121
|
+
command: "path [session]",
|
|
4122
|
+
describe: "Print a diagnostic session directory (latest by default)",
|
|
4123
|
+
builder: (y) => y.positional("session", {
|
|
4124
|
+
type: "string",
|
|
4125
|
+
describe: "Session name from `skydive logs list`"
|
|
4126
|
+
}),
|
|
4127
|
+
handler: async (argv) => {
|
|
4128
|
+
const session = await resolveSession(argv.session);
|
|
4129
|
+
if (argv.json) {
|
|
4130
|
+
output(argv, session);
|
|
4131
|
+
return;
|
|
4132
|
+
}
|
|
4133
|
+
console.log(session.path);
|
|
4134
|
+
}
|
|
4135
|
+
};
|
|
4136
|
+
const exportCommand = {
|
|
4137
|
+
command: "export [session]",
|
|
4138
|
+
describe: "Archive a diagnostic session for sharing (latest by default)",
|
|
4139
|
+
builder: (y) => y.positional("session", {
|
|
4140
|
+
type: "string",
|
|
4141
|
+
describe: "Session name from `skydive logs list`"
|
|
4142
|
+
}).option("output", {
|
|
4143
|
+
alias: "o",
|
|
4144
|
+
type: "string",
|
|
4145
|
+
describe: "Archive path (defaults to the current directory)"
|
|
4146
|
+
}),
|
|
4147
|
+
handler: async (argv) => {
|
|
4148
|
+
const session = await resolveSession(argv.session);
|
|
4149
|
+
const destination = path.resolve(argv.output ?? `skydive-logs-${session.name}.tar.gz`);
|
|
4150
|
+
try {
|
|
4151
|
+
await createArchive(session.path, destination);
|
|
4152
|
+
} catch (error) {
|
|
4153
|
+
printError(error instanceof Error ? error.message : String(error));
|
|
4154
|
+
process.exit(1);
|
|
4155
|
+
}
|
|
4156
|
+
if (argv.json) {
|
|
4157
|
+
output(argv, {
|
|
4158
|
+
path: destination,
|
|
4159
|
+
session: session.name,
|
|
4160
|
+
issueUrl: issueUrl(destination),
|
|
4161
|
+
repositoryUrl: ISSUE_REPOSITORY_URL
|
|
4162
|
+
});
|
|
4163
|
+
return;
|
|
4164
|
+
}
|
|
4165
|
+
console.log(destination);
|
|
4166
|
+
await offerIssueReport(destination);
|
|
4167
|
+
}
|
|
4168
|
+
};
|
|
4169
|
+
const logsCommand = {
|
|
4170
|
+
command: "logs",
|
|
4171
|
+
describe: "Find and export recent local diagnostic logs",
|
|
4172
|
+
builder: (y) => y.command(listCommand).command(pathCommand).command(exportCommand),
|
|
3796
4173
|
handler: (argv) => listCommand.handler(argv)
|
|
3797
4174
|
};
|
|
3798
4175
|
|
|
3799
4176
|
//#endregion
|
|
3800
4177
|
//#region src/cli.ts
|
|
3801
4178
|
function createCli(argv) {
|
|
3802
|
-
return yargs(argv).scriptName("skydive").usage("$0 <command> [options]").parserConfiguration({ "populate--": true }).example("skydive auth login", "Store your API key").example("skydive chat", "Open the interactive chat TUI (prod)").example("skydive chat --api-url http://localhost:4500", "Chat against a local dev API").example("skydive agents list", "List your agents").example("skydive completion install", "Set up TAB completion for your shell").example("skydive keys create \"my-key\"", "Create an API key").example("skydive secrets set OPENAI_API_KEY --agent-id <id>", "Set a secret (value from stdin)").example("skydive workspace list", "List workspaces on your account").example("skydive config set updateCheck false", "Disable the daily update check").example("skydive workspace switch acme-team", "Switch the workspace all `skydive` commands act on").example("skydive portal open --agent grace", "Open the portal to this machine for an agent, headless (no TUI)").example("skydive fs edit --agent grace /tmp/notes.md", "Edit a file on the agent's computer with your local editor").option("json", {
|
|
4179
|
+
return yargs(argv).scriptName("skydive").usage("$0 <command> [options]").parserConfiguration({ "populate--": true }).example("skydive auth login", "Store your API key").example("skydive chat", "Open the interactive chat TUI (prod)").example("skydive chat --api-url http://localhost:4500", "Chat against a local dev API").example("skydive agents list", "List your agents").example("skydive completion install", "Set up TAB completion for your shell").example("skydive keys create \"my-key\"", "Create an API key").example("skydive secrets set OPENAI_API_KEY --agent-id <id>", "Set a secret (value from stdin)").example("skydive workspace list", "List workspaces on your account").example("skydive config set updateCheck false", "Disable the daily update check").example("skydive logs export", "Archive the latest local diagnostics for sharing").example("skydive workspace switch acme-team", "Switch the workspace all `skydive` commands act on").example("skydive portal open --agent grace", "Open the portal to this machine for an agent, headless (no TUI)").example("skydive fs edit --agent grace /tmp/notes.md", "Edit a file on the agent's computer with your local editor").option("json", {
|
|
3803
4180
|
type: "boolean",
|
|
3804
4181
|
default: false,
|
|
3805
4182
|
global: true,
|
|
@@ -3813,7 +4190,7 @@ function createCli(argv) {
|
|
|
3813
4190
|
type: "string",
|
|
3814
4191
|
global: true,
|
|
3815
4192
|
describe: "Override API base URL"
|
|
3816
|
-
}).command(authCommand).command(chatCommand).command(messagesCommand).command(conversationsCommand).command(agentsCommand).command(importCommand).command(keysCommand).command(secretsCommand).command(workspaceCommand).command(portalCommand).command(sandboxCommand).command(fsCommand).command(updateCommand).command(configCommand).command(completionCommand).demandCommand(1, "Specify a command. Run --help for usage.").strict().wrap(null).version(version).alias("v", "version").alias("h", "help").help().fail((msg, err) => {
|
|
4193
|
+
}).command(authCommand).command(chatCommand).command(messagesCommand).command(conversationsCommand).command(agentsCommand).command(importCommand).command(keysCommand).command(secretsCommand).command(workspaceCommand).command(portalCommand).command(sandboxCommand).command(fsCommand).command(updateCommand).command(configCommand).command(logsCommand).command(completionCommand).demandCommand(1, "Specify a command. Run --help for usage.").strict().wrap(null).version(version).alias("v", "version").alias("h", "help").help().fail((msg, err) => {
|
|
3817
4194
|
printError(err ? err instanceof Error ? err.message : String(err) : msg ?? "Unknown error");
|
|
3818
4195
|
process.exit(1);
|
|
3819
4196
|
});
|
|
@@ -4026,7 +4403,7 @@ function setupUpdateCheck(argv) {
|
|
|
4026
4403
|
|
|
4027
4404
|
//#endregion
|
|
4028
4405
|
//#region src/changelog.generated.ts
|
|
4029
|
-
const CHANGELOG_MD = "# Changelog\n\nAll notable changes to the Skydive CLI are documented here.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n## [Unreleased]\n\n### Added\n\n- `skydive fs` — a namespace for working with the files on an agent's computer (its sandbox) from your own machine. Its first subcommand, `skydive fs edit <path>`, reads a remote file down over the same relay `skydive sandbox` uses, opens it in your local editor (`$VISUAL`/`$EDITOR`, override with `--editor`, defaults to `vi`), and writes your changes back atomically when you save and close — so you can edit a remote file as if it were local without opening the chat TUI. A path that doesn't exist yet is created on save; no changes means nothing is written. Access is gated on EDIT permission for the agent, exactly like `skydive sandbox`. (A first-class `fs` relay channel and `skydive fs mount` land in follow-ups.)\n\n## [0.4.0] - 2026-08-07\n\n### Added\n\n- `skydive chat` works with API key auth: an API key alone now opens the chat TUI (and headless `chat -p`) without a browser login, using the key's pinned workspace.\n- `skydive config` command to view and set the safe, hand-editable CLI preferences (`shareMachineDefault`, `updateCheck`) without opening `config.json`. `config`/`config list` shows each key, its effective value, and whether it comes from the file or the built-in default; `config get`/`set`/`unset` read and change one key; `config path` prints the config file location. It only ever touches those preference keys, never credentials or flow-managed state.\n- Billing-blocked sends and runs now surface the server-authored recovery\n guidance from the typed billing outcome. The chat TUI renders it as a\n warning-toned system-notice row — live when a send is refused or a run is\n stopped at the billing boundary, and again when reopening a conversation\n that holds a persisted billing notice — instead of a generic error.\n Headless `chat -p` and `messages get` print the guidance (state, recovery\n step, and manage-billing URL) on stderr, keep any partial output already\n streamed on stdout, and exit with code `5` (distinct from the generic `1`)\n so scripted callers can tell a billing pause from a failure.\n- Syntax highlighting for 14 more languages in the chat transcript and file/review panes (python, bash, go, rust, c, cpp, java, ruby, css, html, json, yaml, and more) — previously only JavaScript/TypeScript rendered colored.\n\n### Changed\n\n- `skydive agent list` lists the full agent roster by default instead of a truncated page.\n\n### Fixed\n\n- Long multi-line bash tool-call commands (e.g. heredocs) are clamped with a `+N more · click to expand` tail instead of dumping their whole body into the scrollback.\n- Tool error output is clipped the same way as ok output, so a failing command no longer floods the transcript.\n- The TUI toast overlay has an opaque background instead of letting the transcript bleed through.\n\n## [0.3.0] - 2026-08-04\n\n### Added\n\n**Chat TUI**\n\n- `/fork` slash command to fork a conversation at any point and continue in a new thread.\n- `/conversation` switches threads from inside a live session.\n- `/compact` triggers manual conversation compaction.\n- `/portal` and `/copy` slash commands.\n- Archive the current conversation from the chat TUI.\n- `--new` flag on `skydive chat` to start a fresh conversation.\n- Debounced server-side conversation search in the picker, with title matches ranked first.\n- File review pane orientation toggle, and review comments in the file pane.\n- Pinned plan card controls and a jump-to-latest hint.\n- Terminal title (OSC) follows the live conversation title on every screen; inside cmux the workspace is renamed too, and linked PRs are pushed to the cmux sidebar.\n- Every participating agent shows in the conversation list; connect cards each have their own identity, and ctrl+r asks which connect card to act on.\n- Colored Skydive splash art in `skydive --help` and the TUI pickers.\n- New-agent name prefilled from the server's suggestion.\n\n**CLI & platform**\n\n- `skydive update` self-updater, with an update notice when a new version is available.\n- Shell completions for bash, zsh, and fish via `completion install`.\n- Portal daemon: one connection per host with per-conversation working directories.\n- Agent-led coding-agent import (`skydive import`).\n- Per-workspace scoping on the REST client, and cross-org `--agent <uuid>` auto-switches workspace.\n- `skydive-beta` wrapper for the canary channel.\n\n### Fixed\n\n- `skydive update` no longer claims an update is available on every npm install.\n- Chat memory is bounded (payload clamps + windowed rows) with a memory watchdog and OOM diagnostic report; transcript rows are memoized so streaming stops re-rendering the whole chat.\n- Chat-send failures map to real error messages.\n- Notification and sidebar previews use the last text block of the reply and strip inline markdown.\n- Picker rows no longer overlap when a conversation title contains a newline, tab, or control character.\n- Sending to non-web channel conversations is blocked in the TUI.\n- GitHub bot connect opens on the web front door, not api.skydive.com.\n- TUI activity counter times from the run, not the screen.\n\n## [0.2.0] - 2026-07-29\n\n### Added\n\n**Sandbox & machine access**\n\n- Standalone `skydive sandbox` command for direct access to an agent's sandbox.\n- `/sandbox` in the chat TUI — live PTY session and one-shot command execution.\n- Headless machine sharing via `skydive portal`, with self-registering portal grants.\n- `shareMachineDefault` config key for always-on portal sharing.\n\n**Chat TUI**\n\n- File pane (`ctrl+g`) with Changes and Files tabs: a shared file tree plus source viewer and a workspace browser, mouse-resizable and responsive to terminal size.\n- Agent todo list rendered in the chat TUI, above the composer, mirroring the web chat's todo card.\n- Fuzzy finder in the conversation and agent pickers.\n- Slash-command autocomplete menu.\n- Paste or drag-and-drop any file into the composer; paste clipboard images with Cmd+V.\n- Run local shell commands with `!` in the composer.\n- Conversation recaps, streamed live title updates, and per-agent attribution on assistant turns.\n- Working timer rolls up into minutes and hours.\n- Conversation picker paginates past 50 conversations and shows only your own conversations.\n- Esc leaves a live run; typing `exit` quits the chat.\n- Cursor Dark theme.\n- Picker rows no longer overlap when a conversation title contains a newline, tab, or control character.\n\n**Headless & scripting**\n\n- Resume a conversation by id.\n- `conversations list` and `conversations show` for transcript reads.\n- `messages get`, with run recovery keyed on message id.\n- Connect cards surface in headless `-p` mode so a driving agent never gets stuck.\n\n**Authentication**\n\n- `skydive auth login` via the browser now auto-mints an API key, so one login yields both a chat session and a usable management credential. Management commands announce the key's pinned workspace when it drives them, so a workspace mismatch is visible at use time.\n- Workspace picker on the device authorization page.\n- Account and workspace identity shown in `auth status`.\n\n**Platform**\n\n- Standalone binary builds compiling the CLI into a per-target executable.\n- Interactive workspace switcher; management commands follow the active workspace.\n- Terminal host integrations and agent notifications.\n\n### Fixed\n\n- Transcript errors collapse to one line, click to expand (REST and portal errors keep their full body).\n- Dragged/pasted image file paths attach the file instead of inserting path text, including macOS paths with literal parentheses.\n- Bare URLs in chat markdown are hyperlinked so they survive text wrap.\n- Composer draft is preserved across TUI overlays.\n- Relative connect links resolve before opening the browser.\n- Numbered markdown headings render colored in the TUI.\n- Chat transcript pages by 75% of a screen; picker rows stay on one line.\n- Run starts push to the TUI over the conversation stream.\n- Security: remediated high-severity dependency findings and cleared tar/shell-quote CVEs.\n\n## [0.1.0] - 2026-07-21\n\nInitial public release: `skydive chat` TUI, agent and conversation management,\ndevice authorization, and headless `-p` mode.\n";
|
|
4406
|
+
const CHANGELOG_MD = "# Changelog\n\nAll notable changes to the Skydive CLI are documented here.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n## [Unreleased]\n\n### Changed\n\n- `npm i -g skydive-cli` (and yarn/pnpm/bun) now installs a tiny launcher plus one prebuilt, os/cpu-matched binary that carries its own runtime — so on the common platforms `skydive chat` and `skydive import` start instantly and **do not download a Bun runtime on first use**. On any platform without a prebuilt binary (or if the optional dependency is skipped), the CLI automatically falls back to the existing behavior: it runs under your Node and provisions Bun on first `chat`, exactly as before. Nothing about the commands, flags, config, or `SKYDIVE_*` environment variables changes, and `skydive update` still upgrades npm installs via your package manager and standalone-binary installs in place.\n\n### Added\n\n- `/search` (alias `/find`) in the chat TUI — opens the conversation picker with its search field focused, so \"find a conversation\" has a discoverable command instead of being a feature you had to know the bare picker already had. Pass a query inline (`/search billing deep dive`) and the picker opens already narrowed to the matches; bare `/search` opens it ready for you to type. The search runs server-side across conversation titles, message bodies, and participant names, the same search the picker exposes.\n- First run in a workspace with no agents now sets you up automatically: instead of dropping you on an empty agent picker, `skydive` creates your first agent for you (with a suggested name and avatar, mirroring the web onboarding flow) and then offers to have it learn how you already work — reading the other coding agents set up on your machine (Claude Code, Cursor, Codex, and more), the same import that `skydive import` runs, with a plan shown first and credentials never copied. Decline and you go straight into the new agent's chat. You can replay this flow anytime with `skydive --onboarding` (or `SKYDIVE_FORCE_ONBOARDING=1`), even in a workspace that already has agents.\n- `/computer` in the chat TUI — a snapshot of the agent's sandbox drawn as colored bar graphs: CPU, memory, and disk usage. Bars turn amber past 75%% and red past 90%% so a glance tells you whether the box is under pressure. The numbers come from the Skydive API (the same live resource sample the web computer view reads), not by connecting to the sandbox — so the card shows instantly, never waking or hanging on a box that isn't running: when the agent has no live sandbox it simply reads \"no sandbox running\". The card keeps itself current quietly (a slow background refresh, no flicker or \"updating\" chrome); only the most recent card refreshes, and it silently stops while you're scrolled up (no wasted polls on a card you're not looking at) and resumes at the bottom.\n- `/computer restart` in the chat TUI — reboot the agent's sandbox from chat. It asks a `y`/`n` confirm first (the restart stops whatever run is going and brings up a fresh box), then enqueues the same restart the web \"Restart\" control does. Available to anyone with edit access to the agent; view-only members are told they can't.\n- `skydive fs` — a namespace for working with the files on an agent's computer (its sandbox) from your own machine. Its first subcommand, `skydive fs edit <path>`, reads a remote file down over the same relay `skydive sandbox` uses, opens it in your local editor (`$VISUAL`/`$EDITOR`, override with `--editor`, defaults to `vi`), and writes your changes back atomically when you save and close — so you can edit a remote file as if it were local without opening the chat TUI. A path that doesn't exist yet is created on save; no changes means nothing is written. Access is gated on EDIT permission for the agent, exactly like `skydive sandbox`. (A first-class `fs` relay channel and `skydive fs mount` land in follow-ups.)\n\n## [0.4.0] - 2026-08-07\n\n### Added\n\n- `skydive chat` works with API key auth: an API key alone now opens the chat TUI (and headless `chat -p`) without a browser login, using the key's pinned workspace.\n- `skydive config` command to view and set the safe, hand-editable CLI preferences (`shareMachineDefault`, `updateCheck`) without opening `config.json`. `config`/`config list` shows each key, its effective value, and whether it comes from the file or the built-in default; `config get`/`set`/`unset` read and change one key; `config path` prints the config file location. It only ever touches those preference keys, never credentials or flow-managed state.\n- Billing-blocked sends and runs now surface the server-authored recovery\n guidance from the typed billing outcome. The chat TUI renders it as a\n warning-toned system-notice row — live when a send is refused or a run is\n stopped at the billing boundary, and again when reopening a conversation\n that holds a persisted billing notice — instead of a generic error.\n Headless `chat -p` and `messages get` print the guidance (state, recovery\n step, and manage-billing URL) on stderr, keep any partial output already\n streamed on stdout, and exit with code `5` (distinct from the generic `1`)\n so scripted callers can tell a billing pause from a failure.\n- Syntax highlighting for 14 more languages in the chat transcript and file/review panes (python, bash, go, rust, c, cpp, java, ruby, css, html, json, yaml, and more) — previously only JavaScript/TypeScript rendered colored.\n\n### Changed\n\n- `skydive agent list` lists the full agent roster by default instead of a truncated page.\n\n### Fixed\n\n- Long multi-line bash tool-call commands (e.g. heredocs) are clamped with a `+N more · click to expand` tail instead of dumping their whole body into the scrollback.\n- Tool error output is clipped the same way as ok output, so a failing command no longer floods the transcript.\n- The TUI toast overlay has an opaque background instead of letting the transcript bleed through.\n\n## [0.3.0] - 2026-08-04\n\n### Added\n\n**Chat TUI**\n\n- `/fork` slash command to fork a conversation at any point and continue in a new thread.\n- `/conversation` switches threads from inside a live session.\n- `/compact` triggers manual conversation compaction.\n- `/portal` and `/copy` slash commands.\n- Archive the current conversation from the chat TUI.\n- `--new` flag on `skydive chat` to start a fresh conversation.\n- Debounced server-side conversation search in the picker, with title matches ranked first.\n- File review pane orientation toggle, and review comments in the file pane.\n- Pinned plan card controls and a jump-to-latest hint.\n- Terminal title (OSC) follows the live conversation title on every screen; inside cmux the workspace is renamed too, and linked PRs are pushed to the cmux sidebar.\n- Every participating agent shows in the conversation list; connect cards each have their own identity, and ctrl+r asks which connect card to act on.\n- Colored Skydive splash art in `skydive --help` and the TUI pickers.\n- New-agent name prefilled from the server's suggestion.\n\n**CLI & platform**\n\n- `skydive update` self-updater, with an update notice when a new version is available.\n- Shell completions for bash, zsh, and fish via `completion install`.\n- Portal daemon: one connection per host with per-conversation working directories.\n- Agent-led coding-agent import (`skydive import`).\n- Per-workspace scoping on the REST client, and cross-org `--agent <uuid>` auto-switches workspace.\n- `skydive-beta` wrapper for the canary channel.\n\n### Fixed\n\n- `skydive update` no longer claims an update is available on every npm install.\n- Chat memory is bounded (payload clamps + windowed rows) with a memory watchdog and OOM diagnostic report; transcript rows are memoized so streaming stops re-rendering the whole chat.\n- Chat-send failures map to real error messages.\n- Notification and sidebar previews use the last text block of the reply and strip inline markdown.\n- Picker rows no longer overlap when a conversation title contains a newline, tab, or control character.\n- Sending to non-web channel conversations is blocked in the TUI.\n- GitHub bot connect opens on the web front door, not api.skydive.com.\n- TUI activity counter times from the run, not the screen.\n\n## [0.2.0] - 2026-07-29\n\n### Added\n\n**Sandbox & machine access**\n\n- Standalone `skydive sandbox` command for direct access to an agent's sandbox.\n- `/sandbox` in the chat TUI — live PTY session and one-shot command execution.\n- Headless machine sharing via `skydive portal`, with self-registering portal grants.\n- `shareMachineDefault` config key for always-on portal sharing.\n\n**Chat TUI**\n\n- File pane (`ctrl+g`) with Changes and Files tabs: a shared file tree plus source viewer and a workspace browser, mouse-resizable and responsive to terminal size.\n- Agent todo list rendered in the chat TUI, above the composer, mirroring the web chat's todo card.\n- Fuzzy finder in the conversation and agent pickers.\n- Slash-command autocomplete menu.\n- Paste or drag-and-drop any file into the composer; paste clipboard images with Cmd+V.\n- Run local shell commands with `!` in the composer.\n- Conversation recaps, streamed live title updates, and per-agent attribution on assistant turns.\n- Working timer rolls up into minutes and hours.\n- Conversation picker paginates past 50 conversations and shows only your own conversations.\n- Esc leaves a live run; typing `exit` quits the chat.\n- Cursor Dark theme.\n- Picker rows no longer overlap when a conversation title contains a newline, tab, or control character.\n\n**Headless & scripting**\n\n- Resume a conversation by id.\n- `conversations list` and `conversations show` for transcript reads.\n- `messages get`, with run recovery keyed on message id.\n- Connect cards surface in headless `-p` mode so a driving agent never gets stuck.\n\n**Authentication**\n\n- `skydive auth login` via the browser now auto-mints an API key, so one login yields both a chat session and a usable management credential. Management commands announce the key's pinned workspace when it drives them, so a workspace mismatch is visible at use time.\n- Workspace picker on the device authorization page.\n- Account and workspace identity shown in `auth status`.\n\n**Platform**\n\n- Standalone binary builds compiling the CLI into a per-target executable.\n- Interactive workspace switcher; management commands follow the active workspace.\n- Terminal host integrations and agent notifications.\n\n### Fixed\n\n- Transcript errors collapse to one line, click to expand (REST and portal errors keep their full body).\n- Dragged/pasted image file paths attach the file instead of inserting path text, including macOS paths with literal parentheses.\n- Bare URLs in chat markdown are hyperlinked so they survive text wrap.\n- Composer draft is preserved across TUI overlays.\n- Relative connect links resolve before opening the browser.\n- Numbered markdown headings render colored in the TUI.\n- Chat transcript pages by 75% of a screen; picker rows stay on one line.\n- Run starts push to the TUI over the conversation stream.\n- Security: remediated high-severity dependency findings and cleared tar/shell-quote CVEs.\n\n## [0.1.0] - 2026-07-21\n\nInitial public release: `skydive chat` TUI, agent and conversation management,\ndevice authorization, and headless `-p` mode.\n";
|
|
4030
4407
|
|
|
4031
4408
|
//#endregion
|
|
4032
4409
|
//#region src/whats-new.ts
|
|
@@ -4169,7 +4546,7 @@ if (process.argv.includes(UPDATE_WORKER_FLAG)) {
|
|
|
4169
4546
|
process.exit(0);
|
|
4170
4547
|
}
|
|
4171
4548
|
if (process.argv.includes(PORTAL_DAEMON_FLAG)) {
|
|
4172
|
-
const { runPortalDaemon } = await import("./daemon-
|
|
4549
|
+
const { runPortalDaemon } = await import("./daemon-By-I_HVM.mjs");
|
|
4173
4550
|
runPortalDaemon(process.argv);
|
|
4174
4551
|
} else runCli();
|
|
4175
4552
|
function runCli() {
|