agental 0.41.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +433 -102
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -7403,7 +7403,7 @@ var init_cli_operator = __esm({
|
|
|
7403
7403
|
});
|
|
7404
7404
|
|
|
7405
7405
|
// ../src/cli.ts
|
|
7406
|
-
import { randomUUID as
|
|
7406
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
7407
7407
|
import { readFileSync as readFileSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
7408
7408
|
import os7 from "node:os";
|
|
7409
7409
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
@@ -7411,7 +7411,7 @@ import { parseArgs } from "node:util";
|
|
|
7411
7411
|
|
|
7412
7412
|
// ../src/cli-build.ts
|
|
7413
7413
|
var PUBLISHED = true;
|
|
7414
|
-
var CLI_VERSION = true ? "0.
|
|
7414
|
+
var CLI_VERSION = true ? "0.43.0" : "dev";
|
|
7415
7415
|
var DEFAULT_API_URL = true ? "https://agental.io" : "http://127.0.0.1:8741";
|
|
7416
7416
|
var PACKAGE_NAME = "agental";
|
|
7417
7417
|
var USER_AGENT = `agental-cli/${CLI_VERSION}`;
|
|
@@ -8283,10 +8283,10 @@ async function whoIs(base, key2) {
|
|
|
8283
8283
|
throw error;
|
|
8284
8284
|
}
|
|
8285
8285
|
}
|
|
8286
|
-
async function pushRequest(base,
|
|
8286
|
+
async function pushRequest(base, ask12) {
|
|
8287
8287
|
let made;
|
|
8288
8288
|
try {
|
|
8289
|
-
made = await call(base, "POST", "/v1/cli-sign-ins",
|
|
8289
|
+
made = await call(base, "POST", "/v1/cli-sign-ins", ask12);
|
|
8290
8290
|
} catch (error) {
|
|
8291
8291
|
if (error instanceof Refused && (error.status === 401 || error.status === 404)) {
|
|
8292
8292
|
throw new Error(`${base} does not sign the command in through the browser. Make a key in its console, under API keys, and run agental login --key.`);
|
|
@@ -9408,6 +9408,7 @@ var COMMANDS = [
|
|
|
9408
9408
|
flags: [
|
|
9409
9409
|
["-n, --name <name>", "what to call it; left out, it is made up as sbx-\u2026"],
|
|
9410
9410
|
["-t, --template <template>", "what it starts from (default: your default template)"],
|
|
9411
|
+
[" --snapshot <snapshot-id>", "start it from this snapshot's disk"],
|
|
9411
9412
|
["-s, --size <size>", "tiny, small, medium or large (default: the template's)"],
|
|
9412
9413
|
[" --region <region>", "where it runs; agental regions lists them"],
|
|
9413
9414
|
[" --ttl <time>", "stop it after this long, as 30m or 2h"],
|
|
@@ -9450,7 +9451,7 @@ var COMMANDS = [
|
|
|
9450
9451
|
name: "command",
|
|
9451
9452
|
summary: "Start a command in a sandbox that runs on by itself, follow its output, write its stdin and signal it.",
|
|
9452
9453
|
examples: [
|
|
9453
|
-
"agental command start sbx_2a9a47e50daec64a --no-timeout -- npm run build",
|
|
9454
|
+
"agental command start sbx_2a9a47e50daec64a --name build --no-timeout -- npm run build",
|
|
9454
9455
|
"agental command logs sbx_2a9a47e50daec64a cmd_0123456789abcdef --follow",
|
|
9455
9456
|
"agental command start sbx_2a9a47e50daec64a --stdin -- sh -c 'wc -l'",
|
|
9456
9457
|
"agental command stdin sbx_2a9a47e50daec64a cmd_0123456789abcdef < big.csv",
|
|
@@ -9458,6 +9459,7 @@ var COMMANDS = [
|
|
|
9458
9459
|
],
|
|
9459
9460
|
flags: [
|
|
9460
9461
|
["-- <command> [args...]", "start: what to run, with no shell; everything after -- is the command's own"],
|
|
9462
|
+
["--name <name>", 'start: what it is for, as lists and the console show it, such as "dev server"; never a secret'],
|
|
9461
9463
|
["--cwd <dir>", "start: the absolute folder it runs in (default: the sandbox's work folder)"],
|
|
9462
9464
|
["--env <NAME>=<value>", "start: a variable for it alone, or NAME for the value it has here (may be given again); never printed"],
|
|
9463
9465
|
["--timeout <seconds>", "start: end it after this long, as 90 or 10m, up to 10m (default 60s)"],
|
|
@@ -9521,8 +9523,9 @@ var COMMANDS = [
|
|
|
9521
9523
|
{
|
|
9522
9524
|
name: "start",
|
|
9523
9525
|
summary: "Start a stopped sandbox, or every one --where finds.",
|
|
9524
|
-
examples: ["agental start sbx_2a9a47e50daec64a"],
|
|
9526
|
+
examples: ["agental start sbx_2a9a47e50daec64a", "agental start sbx_2a9a47e50daec64a --without-memory"],
|
|
9525
9527
|
flags: [
|
|
9528
|
+
["--without-memory", "start from its disk and let its kept memory go for good: files kept, running programs lost"],
|
|
9526
9529
|
["--where '<words>'", "every sandbox the words find, as one bulk action"],
|
|
9527
9530
|
["--yes", "with --where: start them without asking"],
|
|
9528
9531
|
["--max-burst-fee <dollars>", "the most this start may pay in burst fees"]
|
|
@@ -9666,6 +9669,16 @@ var COMMANDS = [
|
|
|
9666
9669
|
{ name: "data-retention", summary: "Say how long your sandboxes' history is kept." },
|
|
9667
9670
|
{ name: "ci", summary: "Run GitHub Actions jobs on sandboxes: each repository's pool." },
|
|
9668
9671
|
{ name: "claude", summary: "Connect Claude Managed Agents environments, whose sessions run on sandboxes." },
|
|
9672
|
+
{
|
|
9673
|
+
name: "snapshot",
|
|
9674
|
+
summary: "Take, list, read, roll back to and delete snapshots: a sandbox's disk as it was at a moment.",
|
|
9675
|
+
examples: ["agental snapshot create review-41 before-migration", "agental snapshot list --sandbox review-41", "agental snapshot show before-migration", "agental snapshot restore snap_5c1d0a9e8b7f6e42"],
|
|
9676
|
+
flags: [
|
|
9677
|
+
["--sandbox <sandbox>", "list: one sandbox's; show, restore, delete: look the name up among its snapshots"],
|
|
9678
|
+
["--yes", "restore, delete: go on without asking"],
|
|
9679
|
+
["--json", "print the API's answer as JSON"]
|
|
9680
|
+
]
|
|
9681
|
+
},
|
|
9669
9682
|
{ name: "webhooks", summary: "List the addresses your account's events are sent to." },
|
|
9670
9683
|
{ name: "webhook", summary: "Add, change, turn off and remove the addresses your account's events are sent to.", examples: ["agental webhook add https://example.com/agental --all"] },
|
|
9671
9684
|
{ name: "keys", summary: "List your account's API keys." },
|
|
@@ -9782,7 +9795,7 @@ var MAP = [
|
|
|
9782
9795
|
["metrics", "CPU, memory and disk over time"],
|
|
9783
9796
|
["email", "an email address of its own"],
|
|
9784
9797
|
["desktop, browser", "a screen and a Chrome in the sandbox"],
|
|
9785
|
-
["files
|
|
9798
|
+
["files, snapshot", "its files, and its disk kept to roll back to"],
|
|
9786
9799
|
["scp, ssh-config", "files, and SSH from any tool"],
|
|
9787
9800
|
["bulk, region", "work on many at once, and where they run"]
|
|
9788
9801
|
]
|
|
@@ -10087,6 +10100,7 @@ function flagsOf(usages) {
|
|
|
10087
10100
|
var SANDBOX = /^<sandbox-id>/;
|
|
10088
10101
|
var SANDBOX_VERBS2 = /* @__PURE__ */ new Set(["list", "create", "start", "stop", "delete", "recover", "exec", "shell", "summary"]);
|
|
10089
10102
|
var TEMPLATE = /^<template>/;
|
|
10103
|
+
var SNAPSHOT = /^<snapshot/;
|
|
10090
10104
|
var JOB = /^<job>/;
|
|
10091
10105
|
var KEPT_SHELL = /^<shell>/;
|
|
10092
10106
|
var COMMAND_ID = /^<command-id>/;
|
|
@@ -10135,6 +10149,9 @@ async function complete(typed, reference, operator, fetchJson) {
|
|
|
10135
10149
|
if (SANDBOX.test(valueOf)) {
|
|
10136
10150
|
return starting(await sandboxes(fetchJson));
|
|
10137
10151
|
}
|
|
10152
|
+
if (SNAPSHOT.test(valueOf)) {
|
|
10153
|
+
return starting(await snapshots(fetchJson));
|
|
10154
|
+
}
|
|
10138
10155
|
if (KEPT_SHELL.test(valueOf)) {
|
|
10139
10156
|
const sandbox2 = before.slice(1).find((word) => /^sbx_[A-Za-z0-9]+$/.test(word));
|
|
10140
10157
|
return sandbox2 ? starting(await keptShells(fetchJson, sandbox2)) : [];
|
|
@@ -10158,6 +10175,7 @@ async function complete(typed, reference, operator, fetchJson) {
|
|
|
10158
10175
|
let wantsSandbox = false;
|
|
10159
10176
|
let wantsTemplate = false;
|
|
10160
10177
|
let wantsJob = false;
|
|
10178
|
+
let wantsSnapshot = false;
|
|
10161
10179
|
let wantsCommand = false;
|
|
10162
10180
|
for (const usage of usages) {
|
|
10163
10181
|
const parts = partsOf(usage).slice(1);
|
|
@@ -10180,6 +10198,7 @@ async function complete(typed, reference, operator, fetchJson) {
|
|
|
10180
10198
|
wantsSandbox ||= SANDBOX.test(inner);
|
|
10181
10199
|
wantsTemplate ||= TEMPLATE.test(inner);
|
|
10182
10200
|
wantsJob ||= JOB.test(inner);
|
|
10201
|
+
wantsSnapshot ||= SNAPSHOT.test(inner);
|
|
10183
10202
|
wantsCommand ||= COMMAND_ID.test(inner);
|
|
10184
10203
|
}
|
|
10185
10204
|
if (positionals.length === 0) {
|
|
@@ -10195,6 +10214,7 @@ async function complete(typed, reference, operator, fetchJson) {
|
|
|
10195
10214
|
...wantsSandbox ? await sandboxes(fetchJson) : [],
|
|
10196
10215
|
...wantsTemplate ? await templates(fetchJson) : [],
|
|
10197
10216
|
...wantsJob ? await jobs(fetchJson) : [],
|
|
10217
|
+
...wantsSnapshot ? await snapshots(fetchJson) : [],
|
|
10198
10218
|
...wantsCommand && sandbox !== void 0 ? await commandsIn(fetchJson, sandbox) : []
|
|
10199
10219
|
];
|
|
10200
10220
|
return starting([...candidates.values(), ...asked2]);
|
|
@@ -10229,6 +10249,11 @@ async function commandsIn(api2, sandbox) {
|
|
|
10229
10249
|
return about ? { value: each["id"], about } : { value: each["id"] };
|
|
10230
10250
|
});
|
|
10231
10251
|
}
|
|
10252
|
+
async function snapshots(api2) {
|
|
10253
|
+
const body = await cached("snapshots", api2.as, () => api2.get("/v1/snapshots"));
|
|
10254
|
+
const listed = Array.isArray(body?.snapshots) ? body.snapshots : [];
|
|
10255
|
+
return listed.filter((each) => typeof each["id"] === "string").reverse().map((each) => ({ value: each["id"], about: [each["name"], each["sandboxName"]].filter((word) => typeof word === "string" && word).join(", ") }));
|
|
10256
|
+
}
|
|
10232
10257
|
async function templates(api2) {
|
|
10233
10258
|
const body = await cached("templates", api2.as, () => api2.get("/v1/templates"));
|
|
10234
10259
|
const listed = Array.isArray(body) ? body : body?.templates ?? [];
|
|
@@ -10244,7 +10269,7 @@ async function jobs(api2) {
|
|
|
10244
10269
|
});
|
|
10245
10270
|
}
|
|
10246
10271
|
var KEPT_MS = 3e4;
|
|
10247
|
-
async function cached(what, as,
|
|
10272
|
+
async function cached(what, as, ask12) {
|
|
10248
10273
|
const folder = path5.join(process.env["XDG_CACHE_HOME"] || path5.join(os6.homedir(), ".cache"), "agental");
|
|
10249
10274
|
const file = path5.join(folder, `complete-${what}-${createHash2("sha256").update(as).digest("hex").slice(0, 16)}.json`);
|
|
10250
10275
|
try {
|
|
@@ -10256,7 +10281,7 @@ async function cached(what, as, ask11) {
|
|
|
10256
10281
|
}
|
|
10257
10282
|
let body = null;
|
|
10258
10283
|
try {
|
|
10259
|
-
body = await
|
|
10284
|
+
body = await ask12();
|
|
10260
10285
|
} catch {
|
|
10261
10286
|
return null;
|
|
10262
10287
|
}
|
|
@@ -11729,7 +11754,8 @@ async function start(client, sandbox, commands, run3, extra, options) {
|
|
|
11729
11754
|
...options["no-timeout"] === true ? { timeoutMs: null } : options.timeout !== void 0 ? { timeoutMs: timeoutMsOf2(options.timeout) } : {},
|
|
11730
11755
|
...options.cwd !== void 0 ? { cwd: options.cwd } : {},
|
|
11731
11756
|
...options.env !== void 0 && options.env.length > 0 ? { env: envOf(options.env) } : {},
|
|
11732
|
-
...options.stdin === true ? { stdin: true } : {}
|
|
11757
|
+
...options.stdin === true ? { stdin: true } : {},
|
|
11758
|
+
...options.name !== void 0 ? { name: options.name } : {}
|
|
11733
11759
|
};
|
|
11734
11760
|
const started = await ask7(client, "POST", commands, body);
|
|
11735
11761
|
if (options.json) {
|
|
@@ -11832,9 +11858,10 @@ async function list2(client, sandbox, commands, options) {
|
|
|
11832
11858
|
const terminal2 = isTerminal(process.stdout);
|
|
11833
11859
|
const sized = listed.some((each) => typeof each.stdoutBytes === "number");
|
|
11834
11860
|
const written = (count) => typeof count === "number" ? bytes2(count) : "-";
|
|
11861
|
+
const named = listed.some((each) => each.name != null);
|
|
11835
11862
|
const rows = [
|
|
11836
|
-
["ID", "STATE", "STARTED", "TOOK", ...sized ? ["STDOUT", "STDERR"] : []],
|
|
11837
|
-
...listed.map((each) => [each.id, stateOf(each), moment(each.startedAt), tookOf2(each), ...sized ? [written(each.stdoutBytes), written(each.stderrBytes)] : []])
|
|
11863
|
+
["ID", ...named ? ["NAME"] : [], "STATE", "STARTED", "TOOK", ...sized ? ["STDOUT", "STDERR"] : []],
|
|
11864
|
+
...listed.map((each) => [each.id, ...named ? [each.name ?? "-"] : [], stateOf(each), moment(each.startedAt), tookOf2(each), ...sized ? [written(each.stdoutBytes), written(each.stderrBytes)] : []])
|
|
11838
11865
|
];
|
|
11839
11866
|
process.stdout.write(fitted(rows, { ...terminal2 ? { give: 1 } : { width: Number.MAX_SAFE_INTEGER }, paint: (cell, row) => row === 0 ? faint(cell) : cell }));
|
|
11840
11867
|
}
|
|
@@ -11853,6 +11880,7 @@ function show(command3, sandbox, asJson) {
|
|
|
11853
11880
|
};
|
|
11854
11881
|
const rows = [
|
|
11855
11882
|
["id", command3.id],
|
|
11883
|
+
...command3.name == null ? [] : [["name", command3.name]],
|
|
11856
11884
|
["sandbox", command3.sandboxId],
|
|
11857
11885
|
["state", stateOf(command3)],
|
|
11858
11886
|
...command3.pid === null ? [] : [["pid", String(command3.pid)]],
|
|
@@ -12534,8 +12562,338 @@ function needId(id, what) {
|
|
|
12534
12562
|
return id;
|
|
12535
12563
|
}
|
|
12536
12564
|
|
|
12565
|
+
// ../src/cli-snapshots.ts
|
|
12566
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
12567
|
+
|
|
12568
|
+
// ../src/domain.ts
|
|
12569
|
+
var MACHINE_SIZES = {
|
|
12570
|
+
tiny: { vcpu: 1, memoryMb: 2048, diskGb: 20 },
|
|
12571
|
+
small: { vcpu: 2, memoryMb: 4096, diskGb: 40 },
|
|
12572
|
+
medium: { vcpu: 4, memoryMb: 8192, diskGb: 80 },
|
|
12573
|
+
large: { vcpu: 8, memoryMb: 16384, diskGb: 160 }
|
|
12574
|
+
};
|
|
12575
|
+
var MACHINE_SIZE_NAMES = ["tiny", "small", "medium", "large"];
|
|
12576
|
+
var LIST_PRICE_MICROS_PER_HOUR = {
|
|
12577
|
+
tiny: 13500,
|
|
12578
|
+
small: 27e3,
|
|
12579
|
+
medium: 54e3,
|
|
12580
|
+
large: 108e3
|
|
12581
|
+
};
|
|
12582
|
+
var SPOT_PRICE_MICROS_PER_HOUR = {
|
|
12583
|
+
tiny: LIST_PRICE_MICROS_PER_HOUR.tiny / 2,
|
|
12584
|
+
small: LIST_PRICE_MICROS_PER_HOUR.small / 2,
|
|
12585
|
+
medium: LIST_PRICE_MICROS_PER_HOUR.medium / 2,
|
|
12586
|
+
large: LIST_PRICE_MICROS_PER_HOUR.large / 2
|
|
12587
|
+
};
|
|
12588
|
+
var SPOT_ON_RECLAIM = ["delete", "stop"];
|
|
12589
|
+
var SPOT_ON_RECLAIM_READ = [...SPOT_ON_RECLAIM, "upgrade"];
|
|
12590
|
+
var SPOT_RUN_LIMIT_SECONDS = 24 * 60 * 60;
|
|
12591
|
+
var HOURS_PER_MONTH = 730;
|
|
12592
|
+
var STOPPED_MICROS_PER_GB_MONTH = 5e4;
|
|
12593
|
+
var BYTES_PER_GB = 1e9;
|
|
12594
|
+
var NEVER_PAID_MAX_STORED_BYTES = 20 * BYTES_PER_GB;
|
|
12595
|
+
var STOPPED_DELETION_NOTICE_MS = 3 * 864e5;
|
|
12596
|
+
function stoppedMicrosPerHour(storedBytes) {
|
|
12597
|
+
if (storedBytes <= 0) {
|
|
12598
|
+
return 0;
|
|
12599
|
+
}
|
|
12600
|
+
return Math.max(1, Math.round(storedBytes * STOPPED_MICROS_PER_GB_MONTH / (BYTES_PER_GB * HOURS_PER_MONTH)));
|
|
12601
|
+
}
|
|
12602
|
+
function wholeStoredBytes(size2, withMemory) {
|
|
12603
|
+
const resources = MACHINE_SIZES[size2];
|
|
12604
|
+
return resources.diskGb * 2 ** 30 + (withMemory ? resources.memoryMb * 2 ** 20 : 0);
|
|
12605
|
+
}
|
|
12606
|
+
var STOPPED_MAX_MICROS_PER_HOUR = {
|
|
12607
|
+
tiny: stoppedMicrosPerHour(wholeStoredBytes("tiny", false)),
|
|
12608
|
+
small: stoppedMicrosPerHour(wholeStoredBytes("small", false)),
|
|
12609
|
+
medium: stoppedMicrosPerHour(wholeStoredBytes("medium", false)),
|
|
12610
|
+
large: stoppedMicrosPerHour(wholeStoredBytes("large", false))
|
|
12611
|
+
};
|
|
12612
|
+
var STOPPED_WITH_MEMORY_MAX_MICROS_PER_HOUR = {
|
|
12613
|
+
tiny: stoppedMicrosPerHour(wholeStoredBytes("tiny", true)),
|
|
12614
|
+
small: stoppedMicrosPerHour(wholeStoredBytes("small", true)),
|
|
12615
|
+
medium: stoppedMicrosPerHour(wholeStoredBytes("medium", true)),
|
|
12616
|
+
large: stoppedMicrosPerHour(wholeStoredBytes("large", true))
|
|
12617
|
+
};
|
|
12618
|
+
var SANDBOX_STATUSES = ["creating", "running", "stopped", "error", "deleted"];
|
|
12619
|
+
var SHOWN_STATUSES = [...SANDBOX_STATUSES, "restoring", "migrating"];
|
|
12620
|
+
var OUTBOUND_MODES = ["open", "blocked", "allowlist"];
|
|
12621
|
+
function isMachineSize(value) {
|
|
12622
|
+
return Object.hasOwn(MACHINE_SIZES, value);
|
|
12623
|
+
}
|
|
12624
|
+
|
|
12625
|
+
// ../src/cli-snapshots.ts
|
|
12626
|
+
var KEPT_WORDS = {
|
|
12627
|
+
server_and_storage: "server and storage",
|
|
12628
|
+
storage: "storage only",
|
|
12629
|
+
server: "server only",
|
|
12630
|
+
your_server: "your server"
|
|
12631
|
+
};
|
|
12632
|
+
var USAGE7 = "snapshot takes list, show, create, restore or delete. agental snapshot --help shows each.";
|
|
12633
|
+
var STORAGE_ONLY = "storage";
|
|
12634
|
+
var NONE = "\u2014";
|
|
12635
|
+
async function ask9(client, method, pathname, init = {}) {
|
|
12636
|
+
const response = await client.request(pathname, {
|
|
12637
|
+
method,
|
|
12638
|
+
...init.headers ? { headers: init.headers } : {},
|
|
12639
|
+
...init.body === void 0 ? {} : { body: JSON.stringify(init.body) }
|
|
12640
|
+
});
|
|
12641
|
+
let answered = null;
|
|
12642
|
+
if (response.status !== 204) {
|
|
12643
|
+
try {
|
|
12644
|
+
answered = await response.json();
|
|
12645
|
+
} catch {
|
|
12646
|
+
answered = null;
|
|
12647
|
+
}
|
|
12648
|
+
}
|
|
12649
|
+
if (!response.ok) {
|
|
12650
|
+
client.fail(response.status, answered);
|
|
12651
|
+
}
|
|
12652
|
+
return answered;
|
|
12653
|
+
}
|
|
12654
|
+
function snapshotOf(body) {
|
|
12655
|
+
if (!body || typeof body !== "object" || typeof body.id !== "string") {
|
|
12656
|
+
throw new Error("The answer was not a snapshot.");
|
|
12657
|
+
}
|
|
12658
|
+
return body;
|
|
12659
|
+
}
|
|
12660
|
+
function snapshotsOf(body) {
|
|
12661
|
+
const listed = body?.snapshots;
|
|
12662
|
+
if (!Array.isArray(listed)) {
|
|
12663
|
+
throw new Error("The answer was missing snapshots.");
|
|
12664
|
+
}
|
|
12665
|
+
return listed.map(snapshotOf);
|
|
12666
|
+
}
|
|
12667
|
+
function keptOf(snapshot2) {
|
|
12668
|
+
if (typeof snapshot2.kept !== "string") {
|
|
12669
|
+
return NONE;
|
|
12670
|
+
}
|
|
12671
|
+
return KEPT_WORDS[snapshot2.kept] ?? snapshot2.kept.replaceAll("_", " ");
|
|
12672
|
+
}
|
|
12673
|
+
function sandboxOf2(snapshot2) {
|
|
12674
|
+
return snapshot2.sandboxName ?? snapshot2.sandboxId;
|
|
12675
|
+
}
|
|
12676
|
+
function takenOf(snapshot2, sandbox) {
|
|
12677
|
+
return snapshot2.sandboxId === sandbox || snapshot2.sandboxName === sandbox;
|
|
12678
|
+
}
|
|
12679
|
+
function utc(iso) {
|
|
12680
|
+
const moment2 = Date.parse(iso);
|
|
12681
|
+
return Number.isFinite(moment2) ? `${new Date(moment2).toISOString().slice(0, 16).replace("T", " ")} UTC` : iso;
|
|
12682
|
+
}
|
|
12683
|
+
function plural(count, noun) {
|
|
12684
|
+
return `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
12685
|
+
}
|
|
12686
|
+
async function sandboxIdOf(client, word) {
|
|
12687
|
+
const id = await sandboxIdOrNone(client, word);
|
|
12688
|
+
if (id === null) {
|
|
12689
|
+
throw new Error(`There is no sandbox named ${word}. agental list lists them.`);
|
|
12690
|
+
}
|
|
12691
|
+
return id;
|
|
12692
|
+
}
|
|
12693
|
+
async function sandboxIdOrNone(client, word) {
|
|
12694
|
+
if (word.startsWith("sbx_")) {
|
|
12695
|
+
return word;
|
|
12696
|
+
}
|
|
12697
|
+
const body = await ask9(client, "GET", `/v1/sandboxes?${new URLSearchParams({ q: word })}`);
|
|
12698
|
+
const listed = Array.isArray(body?.sandboxes) ? body.sandboxes : [];
|
|
12699
|
+
const named = listed.filter((one) => one.name === word && typeof one.id === "string");
|
|
12700
|
+
if (named.length > 1) {
|
|
12701
|
+
throw new Error(`${named.length} sandboxes are named ${word}. Give the id of the one you mean: ${named.map((one) => String(one.id)).join(", ")}.`);
|
|
12702
|
+
}
|
|
12703
|
+
return named.length === 1 ? named[0].id : null;
|
|
12704
|
+
}
|
|
12705
|
+
async function snapshotNamed(client, word, sandbox, what) {
|
|
12706
|
+
if (word === void 0) {
|
|
12707
|
+
throw new Error(`snapshot ${what} needs the snapshot's id or its name, as agental snapshot list lists them.`);
|
|
12708
|
+
}
|
|
12709
|
+
if (word.startsWith("snap_")) {
|
|
12710
|
+
const found = snapshotOf(await ask9(client, "GET", `/v1/snapshots/${encodeURIComponent(word)}`));
|
|
12711
|
+
if (sandbox !== void 0 && !takenOf(found, sandbox)) {
|
|
12712
|
+
throw new Error(`${word} is a snapshot of ${sandboxOf2(found)}, not of ${sandbox}.`);
|
|
12713
|
+
}
|
|
12714
|
+
return found;
|
|
12715
|
+
}
|
|
12716
|
+
const among = snapshotsOf(await ask9(client, "GET", "/v1/snapshots")).filter((one) => sandbox === void 0 || takenOf(one, sandbox));
|
|
12717
|
+
const named = among.filter((one) => one.name === word);
|
|
12718
|
+
const where = sandbox === void 0 ? "" : ` of ${sandbox}`;
|
|
12719
|
+
if (named.length === 0) {
|
|
12720
|
+
throw new Error(`There is no snapshot named ${word}${where}. agental snapshot list${sandbox === void 0 ? "" : ` --sandbox ${sandbox}`} lists them.`);
|
|
12721
|
+
}
|
|
12722
|
+
if (named.length > 1) {
|
|
12723
|
+
const each = named.map((one) => `${one.id} (of ${sandboxOf2(one)}, taken ${ago(one.createdAt) ?? utc(one.createdAt)})`);
|
|
12724
|
+
throw new Error(`${named.length} snapshots${where} are named ${word}. Give the id of the one you mean: ${each.join(", ")}.`);
|
|
12725
|
+
}
|
|
12726
|
+
return snapshotOf(await ask9(client, "GET", `/v1/snapshots/${encodeURIComponent(named[0].id)}`));
|
|
12727
|
+
}
|
|
12728
|
+
function describe4(snapshot2) {
|
|
12729
|
+
const status = snapshot2.sandboxStatus ?? (snapshot2.sandboxDeleted ? "deleted" : void 0);
|
|
12730
|
+
const disk = snapshot2.size !== null && isMachineSize(snapshot2.size) ? `, ${MACHINE_SIZES[snapshot2.size].diskGb} GB disk` : "";
|
|
12731
|
+
const copied = typeof snapshot2.copiedAt === "string" ? `, copied ${ago(snapshot2.copiedAt) ?? utc(snapshot2.copiedAt)}` : "";
|
|
12732
|
+
const facts = [
|
|
12733
|
+
["Sandbox", `${sandboxOf2(snapshot2)}${status ? ` (${status})` : ""}`],
|
|
12734
|
+
["Size", snapshot2.size === null ? NONE : `${snapshot2.size}${disk}`],
|
|
12735
|
+
["Taken", `${utc(snapshot2.createdAt)}${ago(snapshot2.createdAt) ? `, ${ago(snapshot2.createdAt)}` : ""}`],
|
|
12736
|
+
["Kept", `${keptOf(snapshot2)}${copied}`],
|
|
12737
|
+
["State", snapshot2.state]
|
|
12738
|
+
];
|
|
12739
|
+
const out = [`${strong(snapshot2.name)} ${faint(snapshot2.id)}`, "", ...fitted(facts, { paint: (cell, _row, column) => column === 0 ? faint(cell) : cell }).trimEnd().split("\n")];
|
|
12740
|
+
if (snapshot2.kept === STORAGE_ONLY) {
|
|
12741
|
+
out.push("", "Its server no longer holds it. Rolling back to it, or starting a sandbox from it, fetches it first: a few minutes.");
|
|
12742
|
+
}
|
|
12743
|
+
if (snapshot2.state !== "ready") {
|
|
12744
|
+
return `${out.join("\n")}
|
|
12745
|
+
`;
|
|
12746
|
+
}
|
|
12747
|
+
const next = [
|
|
12748
|
+
...snapshot2.sandboxDeleted ? [] : [["Roll back", `agental snapshot restore ${snapshot2.id}`]],
|
|
12749
|
+
["Start from", `agental sandbox create --snapshot ${snapshot2.id}`],
|
|
12750
|
+
["Delete", `agental snapshot delete ${snapshot2.id}`]
|
|
12751
|
+
];
|
|
12752
|
+
out.push("", ...fitted(next, { paint: (cell, _row, column) => column === 0 ? faint(cell) : cell }).trimEnd().split("\n"));
|
|
12753
|
+
return `${out.join("\n")}
|
|
12754
|
+
`;
|
|
12755
|
+
}
|
|
12756
|
+
async function snapshotsOfSandbox(client, word) {
|
|
12757
|
+
const id = await sandboxIdOrNone(client, word);
|
|
12758
|
+
if (id !== null) {
|
|
12759
|
+
const response = await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/snapshots`, { method: "GET" });
|
|
12760
|
+
if (response.status !== 404) {
|
|
12761
|
+
let answered = null;
|
|
12762
|
+
try {
|
|
12763
|
+
answered = await response.json();
|
|
12764
|
+
} catch {
|
|
12765
|
+
answered = null;
|
|
12766
|
+
}
|
|
12767
|
+
if (!response.ok) {
|
|
12768
|
+
client.fail(response.status, answered);
|
|
12769
|
+
}
|
|
12770
|
+
return answered;
|
|
12771
|
+
}
|
|
12772
|
+
}
|
|
12773
|
+
const kept2 = snapshotsOf(await ask9(client, "GET", "/v1/snapshots")).filter((one) => takenOf(one, word));
|
|
12774
|
+
if (kept2.length === 0 && id === null) {
|
|
12775
|
+
throw new Error(`There is no sandbox named ${word}. agental list lists them.`);
|
|
12776
|
+
}
|
|
12777
|
+
return { snapshots: kept2 };
|
|
12778
|
+
}
|
|
12779
|
+
async function listSnapshots(client, options) {
|
|
12780
|
+
const body = options.sandbox === void 0 ? await ask9(client, "GET", "/v1/snapshots") : await snapshotsOfSandbox(client, options.sandbox);
|
|
12781
|
+
if (options.json) {
|
|
12782
|
+
process.stdout.write(`${JSON.stringify(body, null, 2)}
|
|
12783
|
+
`);
|
|
12784
|
+
return;
|
|
12785
|
+
}
|
|
12786
|
+
const snapshots2 = snapshotsOf(body);
|
|
12787
|
+
if (snapshots2.length === 0) {
|
|
12788
|
+
process.stdout.write(`${options.sandbox === void 0 ? "No snapshots." : `${options.sandbox} has no snapshots.`} agental snapshot create <sandbox> <name> takes one.
|
|
12789
|
+
`);
|
|
12790
|
+
return;
|
|
12791
|
+
}
|
|
12792
|
+
const all = options.sandbox === void 0;
|
|
12793
|
+
const rows = [
|
|
12794
|
+
["NAME", "ID", ...all ? ["SANDBOX"] : [], "SIZE", "TAKEN", "KEPT"],
|
|
12795
|
+
...snapshots2.map((one) => [
|
|
12796
|
+
one.name,
|
|
12797
|
+
one.id,
|
|
12798
|
+
...all ? [`${sandboxOf2(one)}${one.sandboxDeleted ? " (deleted)" : ""}`] : [],
|
|
12799
|
+
one.size ?? NONE,
|
|
12800
|
+
ago(one.createdAt) ?? utc(one.createdAt),
|
|
12801
|
+
keptOf(one)
|
|
12802
|
+
])
|
|
12803
|
+
];
|
|
12804
|
+
process.stdout.write(fitted(rows, { give: 0, paint: (cell, row) => row === 0 ? faint(cell) : cell }));
|
|
12805
|
+
if (snapshots2.some((one) => one.kept === STORAGE_ONLY)) {
|
|
12806
|
+
process.stdout.write(`
|
|
12807
|
+
${plural(snapshots2.length, "snapshot")}. A storage-only one takes a few minutes to roll back to or start from.
|
|
12808
|
+
`);
|
|
12809
|
+
}
|
|
12810
|
+
}
|
|
12811
|
+
async function snapshot(client, positionals, options) {
|
|
12812
|
+
const [what, first, second, ...rest] = positionals;
|
|
12813
|
+
if (rest.length > 0 || second !== void 0 && what !== "create") {
|
|
12814
|
+
throw new Error(what === "create" ? "snapshot create takes the sandbox and one name: put a name with spaces in quotes." : USAGE7);
|
|
12815
|
+
}
|
|
12816
|
+
switch (what) {
|
|
12817
|
+
case "list": {
|
|
12818
|
+
if (first !== void 0) {
|
|
12819
|
+
throw new Error(`snapshot list takes the sandbox as --sandbox: agental snapshot list --sandbox ${first}`);
|
|
12820
|
+
}
|
|
12821
|
+
await listSnapshots(client, options);
|
|
12822
|
+
return;
|
|
12823
|
+
}
|
|
12824
|
+
case "show": {
|
|
12825
|
+
const found = await snapshotNamed(client, first, options.sandbox, "show");
|
|
12826
|
+
process.stdout.write(options.json ? `${JSON.stringify(found, null, 2)}
|
|
12827
|
+
` : describe4(found));
|
|
12828
|
+
return;
|
|
12829
|
+
}
|
|
12830
|
+
case "create": {
|
|
12831
|
+
if (first === void 0 || second === void 0) {
|
|
12832
|
+
throw new Error("snapshot create needs the sandbox and a name for the snapshot, as agental snapshot create review-41 before-migration");
|
|
12833
|
+
}
|
|
12834
|
+
if (options.sandbox !== void 0) {
|
|
12835
|
+
throw new Error("snapshot create takes the sandbox as its first word, not --sandbox.");
|
|
12836
|
+
}
|
|
12837
|
+
const made = await ask9(client, "POST", `/v1/sandboxes/${encodeURIComponent(await sandboxIdOf(client, first))}/snapshots`, { body: { name: second } });
|
|
12838
|
+
process.stdout.write(options.json ? `${JSON.stringify(made, null, 2)}
|
|
12839
|
+
` : describe4(snapshotOf(made)));
|
|
12840
|
+
return;
|
|
12841
|
+
}
|
|
12842
|
+
case "restore": {
|
|
12843
|
+
const found = await snapshotNamed(client, first, options.sandbox, "restore");
|
|
12844
|
+
const sandbox = sandboxOf2(found);
|
|
12845
|
+
if (found.sandboxDeleted) {
|
|
12846
|
+
throw new Error(`${sandbox} is deleted: there is nothing to roll back. agental sandbox create --snapshot ${found.id} starts a new sandbox from it.`);
|
|
12847
|
+
}
|
|
12848
|
+
const question = `Roll ${sandbox} back to ${found.name}, taken ${ago(found.createdAt) ?? utc(found.createdAt)}? What runs in it ends, its snapshots taken after this one are deleted, and its address and SSH port may change. It cannot be undone.`;
|
|
12849
|
+
if (!options.yes && !await client.confirmed(question)) {
|
|
12850
|
+
process.stderr.write("Nothing was rolled back. --yes goes on without asking.\n");
|
|
12851
|
+
process.exitCode = 1;
|
|
12852
|
+
return;
|
|
12853
|
+
}
|
|
12854
|
+
if (found.kept === STORAGE_ONLY) {
|
|
12855
|
+
process.stderr.write("Its server no longer holds it: it is fetched from storage first, which takes a few minutes.\n");
|
|
12856
|
+
}
|
|
12857
|
+
const answer3 = await ask9(client, "POST", `/v1/sandboxes/${encodeURIComponent(found.sandboxId)}/restore`, {
|
|
12858
|
+
headers: { "Idempotency-Key": options.idempotencyKey ?? `cli-${randomUUID2()}` },
|
|
12859
|
+
body: { snapshotId: found.id }
|
|
12860
|
+
});
|
|
12861
|
+
if (options.json) {
|
|
12862
|
+
process.stdout.write(`${JSON.stringify(answer3, null, 2)}
|
|
12863
|
+
`);
|
|
12864
|
+
return;
|
|
12865
|
+
}
|
|
12866
|
+
const read2 = answer3;
|
|
12867
|
+
const discarded = Array.isArray(read2?.discarded) ? read2.discarded.map(String) : [];
|
|
12868
|
+
const status = typeof read2?.sandbox?.status === "string" ? `, and ${read2.sandbox.status}` : "";
|
|
12869
|
+
process.stdout.write(`${sandbox} is as it was at ${found.name}${status}.
|
|
12870
|
+
`);
|
|
12871
|
+
if (discarded.length > 0) {
|
|
12872
|
+
process.stdout.write(`${plural(discarded.length, "later snapshot")} deleted: ${discarded.join(", ")}.
|
|
12873
|
+
`);
|
|
12874
|
+
}
|
|
12875
|
+
return;
|
|
12876
|
+
}
|
|
12877
|
+
case "delete": {
|
|
12878
|
+
const found = await snapshotNamed(client, first, options.sandbox, "delete");
|
|
12879
|
+
const question = `Delete ${found.name} (${found.id}), of ${sandboxOf2(found)}, taken ${ago(found.createdAt) ?? utc(found.createdAt)}? It cannot be undone.`;
|
|
12880
|
+
if (!options.yes && !await client.confirmed(question)) {
|
|
12881
|
+
process.stderr.write("Nothing was deleted. --yes goes on without asking.\n");
|
|
12882
|
+
process.exitCode = 1;
|
|
12883
|
+
return;
|
|
12884
|
+
}
|
|
12885
|
+
await ask9(client, "DELETE", `/v1/snapshots/${encodeURIComponent(found.id)}`);
|
|
12886
|
+
process.stdout.write(`Deleted ${found.name} (${found.id}). Sandboxes made from it are not affected.
|
|
12887
|
+
`);
|
|
12888
|
+
return;
|
|
12889
|
+
}
|
|
12890
|
+
default:
|
|
12891
|
+
throw new Error(USAGE7);
|
|
12892
|
+
}
|
|
12893
|
+
}
|
|
12894
|
+
|
|
12537
12895
|
// ../src/cli-sites.ts
|
|
12538
|
-
var
|
|
12896
|
+
var USAGE8 = "site takes a sandbox, or list, add, rm, stats or analytics, then the sandbox. agental site --help shows each.";
|
|
12539
12897
|
var ANALYTICS_USAGE = "site analytics takes on or off, then the sandbox and the site's id, or org, with on or off to change it.";
|
|
12540
12898
|
var REPORT_ROWS = 5;
|
|
12541
12899
|
async function bodyOf2(response) {
|
|
@@ -12545,7 +12903,7 @@ async function bodyOf2(response) {
|
|
|
12545
12903
|
return null;
|
|
12546
12904
|
}
|
|
12547
12905
|
}
|
|
12548
|
-
async function
|
|
12906
|
+
async function ask10(client, method, pathname, body) {
|
|
12549
12907
|
const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
|
|
12550
12908
|
const answered = await bodyOf2(response);
|
|
12551
12909
|
if (!response.ok) {
|
|
@@ -12561,7 +12919,7 @@ function routeOf(body) {
|
|
|
12561
12919
|
}
|
|
12562
12920
|
var isSite = (route) => route.public && !route.hidden;
|
|
12563
12921
|
async function sitesOf(client, sandbox) {
|
|
12564
|
-
const body = await
|
|
12922
|
+
const body = await ask10(client, "GET", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`);
|
|
12565
12923
|
return (Array.isArray(body?.routes) ? body.routes : []).map(routeOf).filter(isSite);
|
|
12566
12924
|
}
|
|
12567
12925
|
function stateOf3(route) {
|
|
@@ -12646,7 +13004,7 @@ async function siteSwitch(client, turn, words2, options) {
|
|
|
12646
13004
|
process.exitCode = 1;
|
|
12647
13005
|
return;
|
|
12648
13006
|
}
|
|
12649
|
-
const report = await
|
|
13007
|
+
const report = await ask10(client, "PUT", `/v1/host-routes/${encodeURIComponent(target)}/analytics`, { enabled: turn === "on" });
|
|
12650
13008
|
if (options.json) {
|
|
12651
13009
|
process.stdout.write(`${reportJson(report)}
|
|
12652
13010
|
`);
|
|
@@ -12672,7 +13030,7 @@ async function organizationSwitch(client, words2, options) {
|
|
|
12672
13030
|
}
|
|
12673
13031
|
let setting;
|
|
12674
13032
|
if (turn === void 0) {
|
|
12675
|
-
setting = await
|
|
13033
|
+
setting = await ask10(client, "GET", "/v1/site-analytics");
|
|
12676
13034
|
} else {
|
|
12677
13035
|
if (turn === "off" && !options.yes && !await client.confirmed("Turn site analytics off for this organization? Every site's figures are deleted now and cannot be brought back.")) {
|
|
12678
13036
|
process.stderr.write("Nothing was changed. --yes goes on without asking.\n");
|
|
@@ -12724,13 +13082,13 @@ async function site(client, positionals, options) {
|
|
|
12724
13082
|
const verb = positionals[0] === "list" || positionals[0] === "add" || positionals[0] === "rm" || positionals[0] === "stats" ? positionals[0] : null;
|
|
12725
13083
|
const [sandbox, target, ...rest] = verb === null ? positionals : positionals.slice(1);
|
|
12726
13084
|
if (sandbox === void 0) {
|
|
12727
|
-
throw new Error(
|
|
13085
|
+
throw new Error(USAGE8);
|
|
12728
13086
|
}
|
|
12729
13087
|
switch (verb) {
|
|
12730
13088
|
case null:
|
|
12731
13089
|
case "list": {
|
|
12732
13090
|
if (target !== void 0) {
|
|
12733
|
-
throw new Error(
|
|
13091
|
+
throw new Error(USAGE8);
|
|
12734
13092
|
}
|
|
12735
13093
|
const sites = await sitesOf(client, sandbox);
|
|
12736
13094
|
if (options.json) {
|
|
@@ -12750,10 +13108,10 @@ async function site(client, positionals, options) {
|
|
|
12750
13108
|
}
|
|
12751
13109
|
case "add": {
|
|
12752
13110
|
if (rest.length > 0) {
|
|
12753
|
-
throw new Error(
|
|
13111
|
+
throw new Error(USAGE8);
|
|
12754
13112
|
}
|
|
12755
13113
|
const port = portFrom(target);
|
|
12756
|
-
const made = routeOf(await
|
|
13114
|
+
const made = routeOf(await ask10(client, "POST", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`, { port, title: `port-${port}`, public: true }));
|
|
12757
13115
|
if (options.json) {
|
|
12758
13116
|
process.stdout.write(`${JSON.stringify(made, null, 2)}
|
|
12759
13117
|
`);
|
|
@@ -12778,7 +13136,7 @@ async function site(client, positionals, options) {
|
|
|
12778
13136
|
throw new Error(`site rm needs the sandbox and the site's id, as agental site ${sandbox} lists them.`);
|
|
12779
13137
|
}
|
|
12780
13138
|
const found = await siteOn(client, sandbox, target);
|
|
12781
|
-
await
|
|
13139
|
+
await ask10(client, "POST", `/v1/host-routes/${encodeURIComponent(target)}/hide`);
|
|
12782
13140
|
process.stdout.write(`Removed. ${found.url ?? `Port ${found.port}`} stops working now; adding port ${found.port} again gives a new link.
|
|
12783
13141
|
`);
|
|
12784
13142
|
return;
|
|
@@ -12792,7 +13150,7 @@ async function site(client, positionals, options) {
|
|
|
12792
13150
|
throw new Error(`--range is 24h or 7d. It was given ${range}.`);
|
|
12793
13151
|
}
|
|
12794
13152
|
await siteOn(client, sandbox, target);
|
|
12795
|
-
const report = await
|
|
13153
|
+
const report = await ask10(client, "GET", `/v1/host-routes/${encodeURIComponent(target)}/analytics?range=${range}`);
|
|
12796
13154
|
process.stdout.write(options.json ? `${reportJson(report)}
|
|
12797
13155
|
` : reportIn(report, sandbox, target));
|
|
12798
13156
|
return;
|
|
@@ -12801,10 +13159,10 @@ async function site(client, positionals, options) {
|
|
|
12801
13159
|
}
|
|
12802
13160
|
|
|
12803
13161
|
// ../src/cli-claude.ts
|
|
12804
|
-
var
|
|
13162
|
+
var USAGE9 = "claude takes connect, show, update or disconnect. agental claude --help shows each.";
|
|
12805
13163
|
var KEY_VARIABLE = "ANTHROPIC_ENVIRONMENT_KEY";
|
|
12806
13164
|
var SECRET_VARIABLE = "ANTHROPIC_WEBHOOK_SIGNING_KEY";
|
|
12807
|
-
async function
|
|
13165
|
+
async function ask11(client, method, pathname, body) {
|
|
12808
13166
|
const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
|
|
12809
13167
|
let answered = null;
|
|
12810
13168
|
if (response.status !== 204) {
|
|
@@ -12826,7 +13184,7 @@ function connectionOf(body) {
|
|
|
12826
13184
|
}
|
|
12827
13185
|
return connection;
|
|
12828
13186
|
}
|
|
12829
|
-
function
|
|
13187
|
+
function describe5(connection) {
|
|
12830
13188
|
return [
|
|
12831
13189
|
`id: ${connection.id}`,
|
|
12832
13190
|
`environment: ${connection.environmentId}`,
|
|
@@ -12894,7 +13252,7 @@ async function hidden(question) {
|
|
|
12894
13252
|
});
|
|
12895
13253
|
}
|
|
12896
13254
|
async function listClaude(client, asJson) {
|
|
12897
|
-
const body = await
|
|
13255
|
+
const body = await ask11(client, "GET", "/v1/claude/connections");
|
|
12898
13256
|
if (asJson) {
|
|
12899
13257
|
process.stdout.write(`${JSON.stringify(body, null, 2)}
|
|
12900
13258
|
`);
|
|
@@ -12916,7 +13274,7 @@ async function listClaude(client, asJson) {
|
|
|
12916
13274
|
async function claude(client, positionals, options) {
|
|
12917
13275
|
const [what, target, ...rest] = positionals;
|
|
12918
13276
|
if (rest.length > 0) {
|
|
12919
|
-
throw new Error(
|
|
13277
|
+
throw new Error(USAGE9);
|
|
12920
13278
|
}
|
|
12921
13279
|
switch (what) {
|
|
12922
13280
|
case "connect": {
|
|
@@ -12928,7 +13286,7 @@ async function claude(client, positionals, options) {
|
|
|
12928
13286
|
const environmentKey = await secretFrom(KEY_VARIABLE, "environment key", true);
|
|
12929
13287
|
const webhookSecret = await secretFrom(SECRET_VARIABLE, "webhook signing secret", false);
|
|
12930
13288
|
const made = connectionOf(
|
|
12931
|
-
await
|
|
13289
|
+
await ask11(client, "POST", "/v1/claude/connections", {
|
|
12932
13290
|
environmentId: target,
|
|
12933
13291
|
environmentKey,
|
|
12934
13292
|
...webhookSecret !== void 0 ? { webhookSecret } : {},
|
|
@@ -12941,7 +13299,7 @@ async function claude(client, positionals, options) {
|
|
|
12941
13299
|
`);
|
|
12942
13300
|
return;
|
|
12943
13301
|
}
|
|
12944
|
-
process.stdout.write(
|
|
13302
|
+
process.stdout.write(describe5(made));
|
|
12945
13303
|
process.stderr.write(
|
|
12946
13304
|
made.hasWebhookSecret ? `In the Claude Console, set ${made.webhookUrl} as a webhook for session.status_run_started.
|
|
12947
13305
|
` : `For a turn to start at once, add ${made.webhookUrl} as a webhook for session.status_run_started in the Claude Console, then: ${SECRET_VARIABLE}=whsec_... agental claude update ${made.id} --webhook-secret
|
|
@@ -12950,9 +13308,9 @@ async function claude(client, positionals, options) {
|
|
|
12950
13308
|
return;
|
|
12951
13309
|
}
|
|
12952
13310
|
case "show": {
|
|
12953
|
-
const found = connectionOf(await
|
|
13311
|
+
const found = connectionOf(await ask11(client, "GET", `/v1/claude/connections/${encodeURIComponent(needId2(target, "show"))}`));
|
|
12954
13312
|
process.stdout.write(options.json ? `${JSON.stringify(found, null, 2)}
|
|
12955
|
-
` :
|
|
13313
|
+
` : describe5(found));
|
|
12956
13314
|
return;
|
|
12957
13315
|
}
|
|
12958
13316
|
case "update": {
|
|
@@ -12973,18 +13331,18 @@ async function claude(client, positionals, options) {
|
|
|
12973
13331
|
if (Object.keys(patch).length === 0) {
|
|
12974
13332
|
throw new Error("claude update changes --template, --keep-days, --new-key, --webhook-secret or --no-webhook-secret, and was given none of them.");
|
|
12975
13333
|
}
|
|
12976
|
-
const updated = connectionOf(await
|
|
13334
|
+
const updated = connectionOf(await ask11(client, "PATCH", `/v1/claude/connections/${encodeURIComponent(id)}`, patch));
|
|
12977
13335
|
process.stdout.write(options.json ? `${JSON.stringify(updated, null, 2)}
|
|
12978
|
-
` :
|
|
13336
|
+
` : describe5(updated));
|
|
12979
13337
|
return;
|
|
12980
13338
|
}
|
|
12981
13339
|
case "disconnect": {
|
|
12982
|
-
await
|
|
13340
|
+
await ask11(client, "DELETE", `/v1/claude/connections/${encodeURIComponent(needId2(target, "disconnect"))}`);
|
|
12983
13341
|
process.stdout.write("Disconnected: its key and signing secret are forgotten, and no more of its work is claimed. Its sessions' sandboxes are left as they are.\n");
|
|
12984
13342
|
return;
|
|
12985
13343
|
}
|
|
12986
13344
|
default:
|
|
12987
|
-
throw new Error(
|
|
13345
|
+
throw new Error(USAGE9);
|
|
12988
13346
|
}
|
|
12989
13347
|
}
|
|
12990
13348
|
function needId2(id, what) {
|
|
@@ -13141,16 +13499,16 @@ async function shell(client, id, options = {}, streams = process) {
|
|
|
13141
13499
|
const verifier = randomBytes4(32).toString("base64url");
|
|
13142
13500
|
const challenge = createHash3("sha256").update(verifier).digest("base64url");
|
|
13143
13501
|
const interactive = stdin.isTTY === true && typeof stdin.setRawMode === "function";
|
|
13144
|
-
const
|
|
13502
|
+
const ask12 = async (keep) => await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminal`, {
|
|
13145
13503
|
method: "POST",
|
|
13146
13504
|
body: JSON.stringify({ ...size2, challenge, ...again ? { terminal: again.id } : keep ? { keep: true } : {} })
|
|
13147
13505
|
});
|
|
13148
|
-
let response = await
|
|
13506
|
+
let response = await ask12(interactive);
|
|
13149
13507
|
let body = await response.json().catch(() => null);
|
|
13150
13508
|
if (!again && interactive && response.status === 409 && body?.error?.code === "terminal_unavailable" && /keeps \d+ terminals/.test(String(body.error.message ?? ""))) {
|
|
13151
13509
|
stderr.write(`${String(body.error.message)} This one is not kept.
|
|
13152
13510
|
`);
|
|
13153
|
-
response = await
|
|
13511
|
+
response = await ask12(false);
|
|
13154
13512
|
body = await response.json().catch(() => null);
|
|
13155
13513
|
}
|
|
13156
13514
|
if (!response.ok || typeof body?.ticket !== "string") {
|
|
@@ -13321,63 +13679,6 @@ ${whyClosed(event.code, event.reason, error)}${maybe}
|
|
|
13321
13679
|
// left-out:cli-dev-key
|
|
13322
13680
|
var DEV_KEY = null;
|
|
13323
13681
|
|
|
13324
|
-
// ../src/domain.ts
|
|
13325
|
-
var MACHINE_SIZES = {
|
|
13326
|
-
tiny: { vcpu: 1, memoryMb: 2048, diskGb: 20 },
|
|
13327
|
-
small: { vcpu: 2, memoryMb: 4096, diskGb: 40 },
|
|
13328
|
-
medium: { vcpu: 4, memoryMb: 8192, diskGb: 80 },
|
|
13329
|
-
large: { vcpu: 8, memoryMb: 16384, diskGb: 160 }
|
|
13330
|
-
};
|
|
13331
|
-
var MACHINE_SIZE_NAMES = ["tiny", "small", "medium", "large"];
|
|
13332
|
-
var LIST_PRICE_MICROS_PER_HOUR = {
|
|
13333
|
-
tiny: 13500,
|
|
13334
|
-
small: 27e3,
|
|
13335
|
-
medium: 54e3,
|
|
13336
|
-
large: 108e3
|
|
13337
|
-
};
|
|
13338
|
-
var SPOT_PRICE_MICROS_PER_HOUR = {
|
|
13339
|
-
tiny: LIST_PRICE_MICROS_PER_HOUR.tiny / 2,
|
|
13340
|
-
small: LIST_PRICE_MICROS_PER_HOUR.small / 2,
|
|
13341
|
-
medium: LIST_PRICE_MICROS_PER_HOUR.medium / 2,
|
|
13342
|
-
large: LIST_PRICE_MICROS_PER_HOUR.large / 2
|
|
13343
|
-
};
|
|
13344
|
-
var SPOT_ON_RECLAIM = ["delete", "stop"];
|
|
13345
|
-
var SPOT_ON_RECLAIM_READ = [...SPOT_ON_RECLAIM, "upgrade"];
|
|
13346
|
-
var SPOT_RUN_LIMIT_SECONDS = 24 * 60 * 60;
|
|
13347
|
-
var HOURS_PER_MONTH = 730;
|
|
13348
|
-
var STOPPED_MICROS_PER_GB_MONTH = 5e4;
|
|
13349
|
-
var BYTES_PER_GB = 1e9;
|
|
13350
|
-
var NEVER_PAID_MAX_STORED_BYTES = 20 * BYTES_PER_GB;
|
|
13351
|
-
var STOPPED_DELETION_NOTICE_MS = 3 * 864e5;
|
|
13352
|
-
function stoppedMicrosPerHour(storedBytes) {
|
|
13353
|
-
if (storedBytes <= 0) {
|
|
13354
|
-
return 0;
|
|
13355
|
-
}
|
|
13356
|
-
return Math.max(1, Math.round(storedBytes * STOPPED_MICROS_PER_GB_MONTH / (BYTES_PER_GB * HOURS_PER_MONTH)));
|
|
13357
|
-
}
|
|
13358
|
-
function wholeStoredBytes(size2, withMemory) {
|
|
13359
|
-
const resources = MACHINE_SIZES[size2];
|
|
13360
|
-
return resources.diskGb * 2 ** 30 + (withMemory ? resources.memoryMb * 2 ** 20 : 0);
|
|
13361
|
-
}
|
|
13362
|
-
var STOPPED_MAX_MICROS_PER_HOUR = {
|
|
13363
|
-
tiny: stoppedMicrosPerHour(wholeStoredBytes("tiny", false)),
|
|
13364
|
-
small: stoppedMicrosPerHour(wholeStoredBytes("small", false)),
|
|
13365
|
-
medium: stoppedMicrosPerHour(wholeStoredBytes("medium", false)),
|
|
13366
|
-
large: stoppedMicrosPerHour(wholeStoredBytes("large", false))
|
|
13367
|
-
};
|
|
13368
|
-
var STOPPED_WITH_MEMORY_MAX_MICROS_PER_HOUR = {
|
|
13369
|
-
tiny: stoppedMicrosPerHour(wholeStoredBytes("tiny", true)),
|
|
13370
|
-
small: stoppedMicrosPerHour(wholeStoredBytes("small", true)),
|
|
13371
|
-
medium: stoppedMicrosPerHour(wholeStoredBytes("medium", true)),
|
|
13372
|
-
large: stoppedMicrosPerHour(wholeStoredBytes("large", true))
|
|
13373
|
-
};
|
|
13374
|
-
var SANDBOX_STATUSES = ["creating", "running", "stopped", "error", "deleted"];
|
|
13375
|
-
var SHOWN_STATUSES = [...SANDBOX_STATUSES, "restoring", "migrating"];
|
|
13376
|
-
var OUTBOUND_MODES = ["open", "blocked", "allowlist"];
|
|
13377
|
-
function isMachineSize(value) {
|
|
13378
|
-
return Object.hasOwn(MACHINE_SIZES, value);
|
|
13379
|
-
}
|
|
13380
|
-
|
|
13381
13682
|
// ../src/desktop-tree-text.ts
|
|
13382
13683
|
function treeText(tree) {
|
|
13383
13684
|
if (tree.windows.length === 0) {
|
|
@@ -13737,6 +14038,7 @@ async function main() {
|
|
|
13737
14038
|
expires: { type: "string" },
|
|
13738
14039
|
"keep-streams": { type: "boolean" },
|
|
13739
14040
|
"keep-memory": { type: "boolean" },
|
|
14041
|
+
"without-memory": { type: "boolean" },
|
|
13740
14042
|
// agental delete and template delete: delete a sandbox that jobs run in, or a template they make their sandboxes from, and pause them.
|
|
13741
14043
|
"pause-jobs": { type: "boolean" },
|
|
13742
14044
|
// agental resize: the size now, with a restart, or a waiting size taken away.
|
|
@@ -13899,10 +14201,13 @@ async function main() {
|
|
|
13899
14201
|
return;
|
|
13900
14202
|
case "start":
|
|
13901
14203
|
if (values.where !== void 0) {
|
|
14204
|
+
if (values["without-memory"] === true) {
|
|
14205
|
+
throw new Error("--without-memory starts one sandbox at a time: name it, without --where.");
|
|
14206
|
+
}
|
|
13902
14207
|
await bulk("start", whereQuery(values.where, labelsFilter(values)), {}, values.yes === true, values.json);
|
|
13903
14208
|
return;
|
|
13904
14209
|
}
|
|
13905
|
-
await lifecycle("start", positionals[1], maxBurstFeeHeaders(values["max-burst-fee"]));
|
|
14210
|
+
await lifecycle("start", positionals[1], maxBurstFeeHeaders(values["max-burst-fee"]), values["without-memory"] === true ? { withoutMemory: true } : void 0);
|
|
13906
14211
|
return;
|
|
13907
14212
|
case "auto-stop":
|
|
13908
14213
|
await autoStop(positionals[1], values.in, values.at, values.never === true, values.json);
|
|
@@ -14024,6 +14329,9 @@ async function main() {
|
|
|
14024
14329
|
case "webhooks":
|
|
14025
14330
|
await listWebhooks({ request, fail }, values.json);
|
|
14026
14331
|
return;
|
|
14332
|
+
case "snapshot":
|
|
14333
|
+
await snapshot({ request, fail, confirmed }, positionals.slice(1), { json: values.json, sandbox: once(values.sandbox, "--sandbox"), yes: values.yes === true, ...values["idempotency-key"] === void 0 ? {} : { idempotencyKey: values["idempotency-key"] } });
|
|
14334
|
+
return;
|
|
14027
14335
|
case "webhook":
|
|
14028
14336
|
await webhook({ request, fail }, positionals.slice(1), values);
|
|
14029
14337
|
return;
|
|
@@ -14114,7 +14422,7 @@ async function create(values) {
|
|
|
14114
14422
|
const sshKeys2 = values["ssh-key"] === void 0 ? void 0 : publicKeysFrom(values["ssh-key"]);
|
|
14115
14423
|
const box = boxNamed(values.box);
|
|
14116
14424
|
const templateId = values.template === void 0 ? void 0 : (await templateNamed(values.template)).id;
|
|
14117
|
-
const idempotencyKey = values["idempotency-key"] ?? `cli-${
|
|
14425
|
+
const idempotencyKey = values["idempotency-key"] ?? `cli-${randomUUID3()}`;
|
|
14118
14426
|
const response = await request("/v1/sandboxes", {
|
|
14119
14427
|
method: "POST",
|
|
14120
14428
|
headers: { "Idempotency-Key": idempotencyKey, ...box ? { "X-Agental-Box": box } : {}, ...burstHeaders },
|
|
@@ -14122,6 +14430,7 @@ async function create(values) {
|
|
|
14122
14430
|
...values.name ? { name: values.name } : {},
|
|
14123
14431
|
...values.size ? { size: values.size } : {},
|
|
14124
14432
|
...templateId ? { templateId } : {},
|
|
14433
|
+
...values.snapshot ? { snapshotId: values.snapshot } : {},
|
|
14125
14434
|
...regionsOption(values.region),
|
|
14126
14435
|
...allow ? { network: { allow } } : {},
|
|
14127
14436
|
...egressAsked ? { egress: egressAsked } : {},
|
|
@@ -14542,6 +14851,10 @@ async function lifecycle(action, id, headers = {}, sent) {
|
|
|
14542
14851
|
if (!id) {
|
|
14543
14852
|
throw new Error(`${action} requires <sandbox-id>`);
|
|
14544
14853
|
}
|
|
14854
|
+
if (sent?.["withoutMemory"] === true) {
|
|
14855
|
+
process.stderr.write(`Starting ${id} from its disk. The memory it was stopped with is let go for good: its files are kept, and the programs that ran in it are not.
|
|
14856
|
+
`);
|
|
14857
|
+
}
|
|
14545
14858
|
if (sent?.["keepMemory"] === true) {
|
|
14546
14859
|
process.stderr.write(`Stopping ${id} with its memory kept. It ends once the memory is written, about a second for every 2 to 3 GiB.
|
|
14547
14860
|
`);
|
|
@@ -16762,7 +17075,7 @@ Setting up
|
|
|
16762
17075
|
agental completion zsh|bash|fish
|
|
16763
17076
|
|
|
16764
17077
|
Usage
|
|
16765
|
-
agental create [--name <name>] [--template <template>] [--size tiny|small|medium|large] [--region <region>[,<region>...]] [--ttl <time> | --ttl default] [--on-timeout delete|stop|stop-with-memory] [--idempotency-key <key>]
|
|
17078
|
+
agental create [--name <name>] [--template <template>] [--snapshot <snapshot-id>] [--size tiny|small|medium|large] [--region <region>[,<region>...]] [--ttl <time> | --ttl default] [--on-timeout delete|stop|stop-with-memory] [--idempotency-key <key>]
|
|
16766
17079
|
[--spot [--on-reclaim delete|stop] [--warn-at <chance>]]
|
|
16767
17080
|
${operator ? "[--box <name-or-id>] " : ""}[--allow <address>[,<address>...]] [--egress box | residential:<country>[:sticky|rotating]] [--max-burst-fee <dollars>]
|
|
16768
17081
|
[--ssh-key <public-key-or-file>]... [--tag <tag>[,<tag>...]]... [--meta <key>=<value>]...
|
|
@@ -16772,7 +17085,7 @@ Usage
|
|
|
16772
17085
|
agental meta <sandbox-id> [set <key>=<value>... | unset <key>...] [--json]
|
|
16773
17086
|
agental regions [--json]
|
|
16774
17087
|
agental exec <sandbox-id> -- <command> [args...]
|
|
16775
|
-
agental command start <sandbox-id> [--cwd <dir>] [--env <NAME>=<value>]... [--timeout <seconds> | --no-timeout] [--stdin] [--json] -- <command> [args...]
|
|
17088
|
+
agental command start <sandbox-id> [--name <name>] [--cwd <dir>] [--env <NAME>=<value>]... [--timeout <seconds> | --no-timeout] [--stdin] [--json] -- <command> [args...]
|
|
16776
17089
|
agental command list <sandbox-id> [--limit <n>] [--json]
|
|
16777
17090
|
agental command get <sandbox-id> <command-id> [--json]
|
|
16778
17091
|
agental command logs <sandbox-id> <command-id> [--follow]
|
|
@@ -16785,7 +17098,7 @@ Usage
|
|
|
16785
17098
|
agental shell <sandbox-id> --list [--json] the shells kept in it
|
|
16786
17099
|
agental shell <sandbox-id> --close <shell> end a kept shell
|
|
16787
17100
|
agental delete <sandbox-id>
|
|
16788
|
-
agental start <sandbox-id> [--max-burst-fee <dollars>]
|
|
17101
|
+
agental start <sandbox-id> [--max-burst-fee <dollars>] [--without-memory]
|
|
16789
17102
|
agental stop <sandbox-id> [--keep-memory]
|
|
16790
17103
|
agental stop --where '<words>' [--keep-memory] [--yes] every sandbox the words find, as one bulk action
|
|
16791
17104
|
agental start --where '<words>' [--yes]
|
|
@@ -16854,6 +17167,11 @@ Usage
|
|
|
16854
17167
|
agental job trigger rotate <job> <trigger-id> [--json] a new secret; the old one stops at once
|
|
16855
17168
|
agental job trigger delete <job> <trigger-id>
|
|
16856
17169
|
agental job calls <job> [--json] calls of its addresses refused in the last 7 days, with why
|
|
17170
|
+
agental snapshot list [--sandbox <sandbox-id>] [--json]
|
|
17171
|
+
agental snapshot show <snapshot> [--sandbox <sandbox-id>] [--json]
|
|
17172
|
+
agental snapshot create <sandbox-id> <name> [--json]
|
|
17173
|
+
agental snapshot restore <snapshot> [--sandbox <sandbox-id>] [--yes] [--idempotency-key <key>] [--json] roll its sandbox back to it
|
|
17174
|
+
agental snapshot delete <snapshot> [--sandbox <sandbox-id>] [--yes]
|
|
16857
17175
|
agental webhooks [--json]
|
|
16858
17176
|
agental webhook add <url> (--events <kind>[,<kind>...] | --all) [--description <text>] [--json]
|
|
16859
17177
|
agental webhook show <webhook-id> [--json]
|
|
@@ -16978,6 +17296,18 @@ lets out only them, and an allowlist lets out its addresses and them. That holds
|
|
|
16978
17296
|
sandbox is not restarted, and what is sent to it, commands, files and SSH, is not affected.
|
|
16979
17297
|
create --allow gives a new sandbox its own from its first boot. These work where GET
|
|
16980
17298
|
/v1/policy says networkPolicy.
|
|
17299
|
+
snapshot create takes a snapshot of a sandbox's disk as it is now, running or stopped, and leaves
|
|
17300
|
+
the sandbox as it was; it is kept until it is deleted, after its sandbox too. snapshot list lists
|
|
17301
|
+
yours, or one sandbox's with --sandbox, with where each is kept: on its server, in storage or both.
|
|
17302
|
+
One kept in storage only is fetched first, which takes a few minutes, to roll back to or start
|
|
17303
|
+
from. snapshot show says one in words, with what to type next. A snapshot is named by its id, or
|
|
17304
|
+
by its name among yours, or among one sandbox's with --sandbox; a name two of them have is
|
|
17305
|
+
refused, naming each. A sandbox is named by its id or its name. snapshot restore rolls its
|
|
17306
|
+
sandbox back to it: what runs in it ends, as on a stop and a start, and its snapshots taken after
|
|
17307
|
+
that one are deleted; its address and SSH port may change. Run again with the same
|
|
17308
|
+
--idempotency-key after a lost answer, it rolls back once. create --snapshot <snapshot-id> makes
|
|
17309
|
+
a new sandbox from one. restore and delete cannot be undone, and ask first in a terminal: --yes
|
|
17310
|
+
goes on without asking, and without a terminal nothing is done unless it is given.
|
|
16981
17311
|
A template is what a sandbox is made as and held to: its start (a size, and a snapshot or a new
|
|
16982
17312
|
machine), its variables and files, and its outbound rule. Every account has one named default,
|
|
16983
17313
|
which a sandbox is on when create names none. <template> is a template's id or its name. A
|
|
@@ -17175,7 +17505,8 @@ payments, usage, and what it has made. Secrets are named, never given. --out wri
|
|
|
17175
17505
|
only you can read. An account is closed from Settings in the console: a key cannot close one.
|
|
17176
17506
|
command start starts a command in a running sandbox and prints its id: what comes after -- is
|
|
17177
17507
|
its program and arguments, run as root with no shell (sh -c "..." for pipes), which runs on
|
|
17178
|
-
whether or not anything watches it.
|
|
17508
|
+
whether or not anything watches it. --name gives it a short name that lists and the console show,
|
|
17509
|
+
since agental keeps no command line. It runs in the sandbox's work folder unless --cwd names an
|
|
17179
17510
|
absolute one, with the sandbox's variables and those --env gives it, NAME=VALUE or NAME alone for
|
|
17180
17511
|
the value it has here; their values are never printed or kept in agental's records. It is ended
|
|
17181
17512
|
after 60 seconds unless --timeout says, up to 10m, or --no-timeout gives it no limit of its own:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agental",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"description": "The agental command: Linux sandboxes for your agents, from the terminal. npx agental@latest signs you in and installs the agent skills.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "VERTIXER LTD",
|