agental 0.42.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 +410 -93
- 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"],
|
|
@@ -9668,6 +9669,16 @@ var COMMANDS = [
|
|
|
9668
9669
|
{ name: "data-retention", summary: "Say how long your sandboxes' history is kept." },
|
|
9669
9670
|
{ name: "ci", summary: "Run GitHub Actions jobs on sandboxes: each repository's pool." },
|
|
9670
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
|
+
},
|
|
9671
9682
|
{ name: "webhooks", summary: "List the addresses your account's events are sent to." },
|
|
9672
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"] },
|
|
9673
9684
|
{ name: "keys", summary: "List your account's API keys." },
|
|
@@ -9784,7 +9795,7 @@ var MAP = [
|
|
|
9784
9795
|
["metrics", "CPU, memory and disk over time"],
|
|
9785
9796
|
["email", "an email address of its own"],
|
|
9786
9797
|
["desktop, browser", "a screen and a Chrome in the sandbox"],
|
|
9787
|
-
["files
|
|
9798
|
+
["files, snapshot", "its files, and its disk kept to roll back to"],
|
|
9788
9799
|
["scp, ssh-config", "files, and SSH from any tool"],
|
|
9789
9800
|
["bulk, region", "work on many at once, and where they run"]
|
|
9790
9801
|
]
|
|
@@ -10089,6 +10100,7 @@ function flagsOf(usages) {
|
|
|
10089
10100
|
var SANDBOX = /^<sandbox-id>/;
|
|
10090
10101
|
var SANDBOX_VERBS2 = /* @__PURE__ */ new Set(["list", "create", "start", "stop", "delete", "recover", "exec", "shell", "summary"]);
|
|
10091
10102
|
var TEMPLATE = /^<template>/;
|
|
10103
|
+
var SNAPSHOT = /^<snapshot/;
|
|
10092
10104
|
var JOB = /^<job>/;
|
|
10093
10105
|
var KEPT_SHELL = /^<shell>/;
|
|
10094
10106
|
var COMMAND_ID = /^<command-id>/;
|
|
@@ -10137,6 +10149,9 @@ async function complete(typed, reference, operator, fetchJson) {
|
|
|
10137
10149
|
if (SANDBOX.test(valueOf)) {
|
|
10138
10150
|
return starting(await sandboxes(fetchJson));
|
|
10139
10151
|
}
|
|
10152
|
+
if (SNAPSHOT.test(valueOf)) {
|
|
10153
|
+
return starting(await snapshots(fetchJson));
|
|
10154
|
+
}
|
|
10140
10155
|
if (KEPT_SHELL.test(valueOf)) {
|
|
10141
10156
|
const sandbox2 = before.slice(1).find((word) => /^sbx_[A-Za-z0-9]+$/.test(word));
|
|
10142
10157
|
return sandbox2 ? starting(await keptShells(fetchJson, sandbox2)) : [];
|
|
@@ -10160,6 +10175,7 @@ async function complete(typed, reference, operator, fetchJson) {
|
|
|
10160
10175
|
let wantsSandbox = false;
|
|
10161
10176
|
let wantsTemplate = false;
|
|
10162
10177
|
let wantsJob = false;
|
|
10178
|
+
let wantsSnapshot = false;
|
|
10163
10179
|
let wantsCommand = false;
|
|
10164
10180
|
for (const usage of usages) {
|
|
10165
10181
|
const parts = partsOf(usage).slice(1);
|
|
@@ -10182,6 +10198,7 @@ async function complete(typed, reference, operator, fetchJson) {
|
|
|
10182
10198
|
wantsSandbox ||= SANDBOX.test(inner);
|
|
10183
10199
|
wantsTemplate ||= TEMPLATE.test(inner);
|
|
10184
10200
|
wantsJob ||= JOB.test(inner);
|
|
10201
|
+
wantsSnapshot ||= SNAPSHOT.test(inner);
|
|
10185
10202
|
wantsCommand ||= COMMAND_ID.test(inner);
|
|
10186
10203
|
}
|
|
10187
10204
|
if (positionals.length === 0) {
|
|
@@ -10197,6 +10214,7 @@ async function complete(typed, reference, operator, fetchJson) {
|
|
|
10197
10214
|
...wantsSandbox ? await sandboxes(fetchJson) : [],
|
|
10198
10215
|
...wantsTemplate ? await templates(fetchJson) : [],
|
|
10199
10216
|
...wantsJob ? await jobs(fetchJson) : [],
|
|
10217
|
+
...wantsSnapshot ? await snapshots(fetchJson) : [],
|
|
10200
10218
|
...wantsCommand && sandbox !== void 0 ? await commandsIn(fetchJson, sandbox) : []
|
|
10201
10219
|
];
|
|
10202
10220
|
return starting([...candidates.values(), ...asked2]);
|
|
@@ -10231,6 +10249,11 @@ async function commandsIn(api2, sandbox) {
|
|
|
10231
10249
|
return about ? { value: each["id"], about } : { value: each["id"] };
|
|
10232
10250
|
});
|
|
10233
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
|
+
}
|
|
10234
10257
|
async function templates(api2) {
|
|
10235
10258
|
const body = await cached("templates", api2.as, () => api2.get("/v1/templates"));
|
|
10236
10259
|
const listed = Array.isArray(body) ? body : body?.templates ?? [];
|
|
@@ -10246,7 +10269,7 @@ async function jobs(api2) {
|
|
|
10246
10269
|
});
|
|
10247
10270
|
}
|
|
10248
10271
|
var KEPT_MS = 3e4;
|
|
10249
|
-
async function cached(what, as,
|
|
10272
|
+
async function cached(what, as, ask12) {
|
|
10250
10273
|
const folder = path5.join(process.env["XDG_CACHE_HOME"] || path5.join(os6.homedir(), ".cache"), "agental");
|
|
10251
10274
|
const file = path5.join(folder, `complete-${what}-${createHash2("sha256").update(as).digest("hex").slice(0, 16)}.json`);
|
|
10252
10275
|
try {
|
|
@@ -10258,7 +10281,7 @@ async function cached(what, as, ask11) {
|
|
|
10258
10281
|
}
|
|
10259
10282
|
let body = null;
|
|
10260
10283
|
try {
|
|
10261
|
-
body = await
|
|
10284
|
+
body = await ask12();
|
|
10262
10285
|
} catch {
|
|
10263
10286
|
return null;
|
|
10264
10287
|
}
|
|
@@ -12539,8 +12562,338 @@ function needId(id, what) {
|
|
|
12539
12562
|
return id;
|
|
12540
12563
|
}
|
|
12541
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
|
+
|
|
12542
12895
|
// ../src/cli-sites.ts
|
|
12543
|
-
var
|
|
12896
|
+
var USAGE8 = "site takes a sandbox, or list, add, rm, stats or analytics, then the sandbox. agental site --help shows each.";
|
|
12544
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.";
|
|
12545
12898
|
var REPORT_ROWS = 5;
|
|
12546
12899
|
async function bodyOf2(response) {
|
|
@@ -12550,7 +12903,7 @@ async function bodyOf2(response) {
|
|
|
12550
12903
|
return null;
|
|
12551
12904
|
}
|
|
12552
12905
|
}
|
|
12553
|
-
async function
|
|
12906
|
+
async function ask10(client, method, pathname, body) {
|
|
12554
12907
|
const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
|
|
12555
12908
|
const answered = await bodyOf2(response);
|
|
12556
12909
|
if (!response.ok) {
|
|
@@ -12566,7 +12919,7 @@ function routeOf(body) {
|
|
|
12566
12919
|
}
|
|
12567
12920
|
var isSite = (route) => route.public && !route.hidden;
|
|
12568
12921
|
async function sitesOf(client, sandbox) {
|
|
12569
|
-
const body = await
|
|
12922
|
+
const body = await ask10(client, "GET", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`);
|
|
12570
12923
|
return (Array.isArray(body?.routes) ? body.routes : []).map(routeOf).filter(isSite);
|
|
12571
12924
|
}
|
|
12572
12925
|
function stateOf3(route) {
|
|
@@ -12651,7 +13004,7 @@ async function siteSwitch(client, turn, words2, options) {
|
|
|
12651
13004
|
process.exitCode = 1;
|
|
12652
13005
|
return;
|
|
12653
13006
|
}
|
|
12654
|
-
const report = await
|
|
13007
|
+
const report = await ask10(client, "PUT", `/v1/host-routes/${encodeURIComponent(target)}/analytics`, { enabled: turn === "on" });
|
|
12655
13008
|
if (options.json) {
|
|
12656
13009
|
process.stdout.write(`${reportJson(report)}
|
|
12657
13010
|
`);
|
|
@@ -12677,7 +13030,7 @@ async function organizationSwitch(client, words2, options) {
|
|
|
12677
13030
|
}
|
|
12678
13031
|
let setting;
|
|
12679
13032
|
if (turn === void 0) {
|
|
12680
|
-
setting = await
|
|
13033
|
+
setting = await ask10(client, "GET", "/v1/site-analytics");
|
|
12681
13034
|
} else {
|
|
12682
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.")) {
|
|
12683
13036
|
process.stderr.write("Nothing was changed. --yes goes on without asking.\n");
|
|
@@ -12729,13 +13082,13 @@ async function site(client, positionals, options) {
|
|
|
12729
13082
|
const verb = positionals[0] === "list" || positionals[0] === "add" || positionals[0] === "rm" || positionals[0] === "stats" ? positionals[0] : null;
|
|
12730
13083
|
const [sandbox, target, ...rest] = verb === null ? positionals : positionals.slice(1);
|
|
12731
13084
|
if (sandbox === void 0) {
|
|
12732
|
-
throw new Error(
|
|
13085
|
+
throw new Error(USAGE8);
|
|
12733
13086
|
}
|
|
12734
13087
|
switch (verb) {
|
|
12735
13088
|
case null:
|
|
12736
13089
|
case "list": {
|
|
12737
13090
|
if (target !== void 0) {
|
|
12738
|
-
throw new Error(
|
|
13091
|
+
throw new Error(USAGE8);
|
|
12739
13092
|
}
|
|
12740
13093
|
const sites = await sitesOf(client, sandbox);
|
|
12741
13094
|
if (options.json) {
|
|
@@ -12755,10 +13108,10 @@ async function site(client, positionals, options) {
|
|
|
12755
13108
|
}
|
|
12756
13109
|
case "add": {
|
|
12757
13110
|
if (rest.length > 0) {
|
|
12758
|
-
throw new Error(
|
|
13111
|
+
throw new Error(USAGE8);
|
|
12759
13112
|
}
|
|
12760
13113
|
const port = portFrom(target);
|
|
12761
|
-
const made = routeOf(await
|
|
13114
|
+
const made = routeOf(await ask10(client, "POST", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`, { port, title: `port-${port}`, public: true }));
|
|
12762
13115
|
if (options.json) {
|
|
12763
13116
|
process.stdout.write(`${JSON.stringify(made, null, 2)}
|
|
12764
13117
|
`);
|
|
@@ -12783,7 +13136,7 @@ async function site(client, positionals, options) {
|
|
|
12783
13136
|
throw new Error(`site rm needs the sandbox and the site's id, as agental site ${sandbox} lists them.`);
|
|
12784
13137
|
}
|
|
12785
13138
|
const found = await siteOn(client, sandbox, target);
|
|
12786
|
-
await
|
|
13139
|
+
await ask10(client, "POST", `/v1/host-routes/${encodeURIComponent(target)}/hide`);
|
|
12787
13140
|
process.stdout.write(`Removed. ${found.url ?? `Port ${found.port}`} stops working now; adding port ${found.port} again gives a new link.
|
|
12788
13141
|
`);
|
|
12789
13142
|
return;
|
|
@@ -12797,7 +13150,7 @@ async function site(client, positionals, options) {
|
|
|
12797
13150
|
throw new Error(`--range is 24h or 7d. It was given ${range}.`);
|
|
12798
13151
|
}
|
|
12799
13152
|
await siteOn(client, sandbox, target);
|
|
12800
|
-
const report = await
|
|
13153
|
+
const report = await ask10(client, "GET", `/v1/host-routes/${encodeURIComponent(target)}/analytics?range=${range}`);
|
|
12801
13154
|
process.stdout.write(options.json ? `${reportJson(report)}
|
|
12802
13155
|
` : reportIn(report, sandbox, target));
|
|
12803
13156
|
return;
|
|
@@ -12806,10 +13159,10 @@ async function site(client, positionals, options) {
|
|
|
12806
13159
|
}
|
|
12807
13160
|
|
|
12808
13161
|
// ../src/cli-claude.ts
|
|
12809
|
-
var
|
|
13162
|
+
var USAGE9 = "claude takes connect, show, update or disconnect. agental claude --help shows each.";
|
|
12810
13163
|
var KEY_VARIABLE = "ANTHROPIC_ENVIRONMENT_KEY";
|
|
12811
13164
|
var SECRET_VARIABLE = "ANTHROPIC_WEBHOOK_SIGNING_KEY";
|
|
12812
|
-
async function
|
|
13165
|
+
async function ask11(client, method, pathname, body) {
|
|
12813
13166
|
const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
|
|
12814
13167
|
let answered = null;
|
|
12815
13168
|
if (response.status !== 204) {
|
|
@@ -12831,7 +13184,7 @@ function connectionOf(body) {
|
|
|
12831
13184
|
}
|
|
12832
13185
|
return connection;
|
|
12833
13186
|
}
|
|
12834
|
-
function
|
|
13187
|
+
function describe5(connection) {
|
|
12835
13188
|
return [
|
|
12836
13189
|
`id: ${connection.id}`,
|
|
12837
13190
|
`environment: ${connection.environmentId}`,
|
|
@@ -12899,7 +13252,7 @@ async function hidden(question) {
|
|
|
12899
13252
|
});
|
|
12900
13253
|
}
|
|
12901
13254
|
async function listClaude(client, asJson) {
|
|
12902
|
-
const body = await
|
|
13255
|
+
const body = await ask11(client, "GET", "/v1/claude/connections");
|
|
12903
13256
|
if (asJson) {
|
|
12904
13257
|
process.stdout.write(`${JSON.stringify(body, null, 2)}
|
|
12905
13258
|
`);
|
|
@@ -12921,7 +13274,7 @@ async function listClaude(client, asJson) {
|
|
|
12921
13274
|
async function claude(client, positionals, options) {
|
|
12922
13275
|
const [what, target, ...rest] = positionals;
|
|
12923
13276
|
if (rest.length > 0) {
|
|
12924
|
-
throw new Error(
|
|
13277
|
+
throw new Error(USAGE9);
|
|
12925
13278
|
}
|
|
12926
13279
|
switch (what) {
|
|
12927
13280
|
case "connect": {
|
|
@@ -12933,7 +13286,7 @@ async function claude(client, positionals, options) {
|
|
|
12933
13286
|
const environmentKey = await secretFrom(KEY_VARIABLE, "environment key", true);
|
|
12934
13287
|
const webhookSecret = await secretFrom(SECRET_VARIABLE, "webhook signing secret", false);
|
|
12935
13288
|
const made = connectionOf(
|
|
12936
|
-
await
|
|
13289
|
+
await ask11(client, "POST", "/v1/claude/connections", {
|
|
12937
13290
|
environmentId: target,
|
|
12938
13291
|
environmentKey,
|
|
12939
13292
|
...webhookSecret !== void 0 ? { webhookSecret } : {},
|
|
@@ -12946,7 +13299,7 @@ async function claude(client, positionals, options) {
|
|
|
12946
13299
|
`);
|
|
12947
13300
|
return;
|
|
12948
13301
|
}
|
|
12949
|
-
process.stdout.write(
|
|
13302
|
+
process.stdout.write(describe5(made));
|
|
12950
13303
|
process.stderr.write(
|
|
12951
13304
|
made.hasWebhookSecret ? `In the Claude Console, set ${made.webhookUrl} as a webhook for session.status_run_started.
|
|
12952
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
|
|
@@ -12955,9 +13308,9 @@ async function claude(client, positionals, options) {
|
|
|
12955
13308
|
return;
|
|
12956
13309
|
}
|
|
12957
13310
|
case "show": {
|
|
12958
|
-
const found = connectionOf(await
|
|
13311
|
+
const found = connectionOf(await ask11(client, "GET", `/v1/claude/connections/${encodeURIComponent(needId2(target, "show"))}`));
|
|
12959
13312
|
process.stdout.write(options.json ? `${JSON.stringify(found, null, 2)}
|
|
12960
|
-
` :
|
|
13313
|
+
` : describe5(found));
|
|
12961
13314
|
return;
|
|
12962
13315
|
}
|
|
12963
13316
|
case "update": {
|
|
@@ -12978,18 +13331,18 @@ async function claude(client, positionals, options) {
|
|
|
12978
13331
|
if (Object.keys(patch).length === 0) {
|
|
12979
13332
|
throw new Error("claude update changes --template, --keep-days, --new-key, --webhook-secret or --no-webhook-secret, and was given none of them.");
|
|
12980
13333
|
}
|
|
12981
|
-
const updated = connectionOf(await
|
|
13334
|
+
const updated = connectionOf(await ask11(client, "PATCH", `/v1/claude/connections/${encodeURIComponent(id)}`, patch));
|
|
12982
13335
|
process.stdout.write(options.json ? `${JSON.stringify(updated, null, 2)}
|
|
12983
|
-
` :
|
|
13336
|
+
` : describe5(updated));
|
|
12984
13337
|
return;
|
|
12985
13338
|
}
|
|
12986
13339
|
case "disconnect": {
|
|
12987
|
-
await
|
|
13340
|
+
await ask11(client, "DELETE", `/v1/claude/connections/${encodeURIComponent(needId2(target, "disconnect"))}`);
|
|
12988
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");
|
|
12989
13342
|
return;
|
|
12990
13343
|
}
|
|
12991
13344
|
default:
|
|
12992
|
-
throw new Error(
|
|
13345
|
+
throw new Error(USAGE9);
|
|
12993
13346
|
}
|
|
12994
13347
|
}
|
|
12995
13348
|
function needId2(id, what) {
|
|
@@ -13146,16 +13499,16 @@ async function shell(client, id, options = {}, streams = process) {
|
|
|
13146
13499
|
const verifier = randomBytes4(32).toString("base64url");
|
|
13147
13500
|
const challenge = createHash3("sha256").update(verifier).digest("base64url");
|
|
13148
13501
|
const interactive = stdin.isTTY === true && typeof stdin.setRawMode === "function";
|
|
13149
|
-
const
|
|
13502
|
+
const ask12 = async (keep) => await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminal`, {
|
|
13150
13503
|
method: "POST",
|
|
13151
13504
|
body: JSON.stringify({ ...size2, challenge, ...again ? { terminal: again.id } : keep ? { keep: true } : {} })
|
|
13152
13505
|
});
|
|
13153
|
-
let response = await
|
|
13506
|
+
let response = await ask12(interactive);
|
|
13154
13507
|
let body = await response.json().catch(() => null);
|
|
13155
13508
|
if (!again && interactive && response.status === 409 && body?.error?.code === "terminal_unavailable" && /keeps \d+ terminals/.test(String(body.error.message ?? ""))) {
|
|
13156
13509
|
stderr.write(`${String(body.error.message)} This one is not kept.
|
|
13157
13510
|
`);
|
|
13158
|
-
response = await
|
|
13511
|
+
response = await ask12(false);
|
|
13159
13512
|
body = await response.json().catch(() => null);
|
|
13160
13513
|
}
|
|
13161
13514
|
if (!response.ok || typeof body?.ticket !== "string") {
|
|
@@ -13326,63 +13679,6 @@ ${whyClosed(event.code, event.reason, error)}${maybe}
|
|
|
13326
13679
|
// left-out:cli-dev-key
|
|
13327
13680
|
var DEV_KEY = null;
|
|
13328
13681
|
|
|
13329
|
-
// ../src/domain.ts
|
|
13330
|
-
var MACHINE_SIZES = {
|
|
13331
|
-
tiny: { vcpu: 1, memoryMb: 2048, diskGb: 20 },
|
|
13332
|
-
small: { vcpu: 2, memoryMb: 4096, diskGb: 40 },
|
|
13333
|
-
medium: { vcpu: 4, memoryMb: 8192, diskGb: 80 },
|
|
13334
|
-
large: { vcpu: 8, memoryMb: 16384, diskGb: 160 }
|
|
13335
|
-
};
|
|
13336
|
-
var MACHINE_SIZE_NAMES = ["tiny", "small", "medium", "large"];
|
|
13337
|
-
var LIST_PRICE_MICROS_PER_HOUR = {
|
|
13338
|
-
tiny: 13500,
|
|
13339
|
-
small: 27e3,
|
|
13340
|
-
medium: 54e3,
|
|
13341
|
-
large: 108e3
|
|
13342
|
-
};
|
|
13343
|
-
var SPOT_PRICE_MICROS_PER_HOUR = {
|
|
13344
|
-
tiny: LIST_PRICE_MICROS_PER_HOUR.tiny / 2,
|
|
13345
|
-
small: LIST_PRICE_MICROS_PER_HOUR.small / 2,
|
|
13346
|
-
medium: LIST_PRICE_MICROS_PER_HOUR.medium / 2,
|
|
13347
|
-
large: LIST_PRICE_MICROS_PER_HOUR.large / 2
|
|
13348
|
-
};
|
|
13349
|
-
var SPOT_ON_RECLAIM = ["delete", "stop"];
|
|
13350
|
-
var SPOT_ON_RECLAIM_READ = [...SPOT_ON_RECLAIM, "upgrade"];
|
|
13351
|
-
var SPOT_RUN_LIMIT_SECONDS = 24 * 60 * 60;
|
|
13352
|
-
var HOURS_PER_MONTH = 730;
|
|
13353
|
-
var STOPPED_MICROS_PER_GB_MONTH = 5e4;
|
|
13354
|
-
var BYTES_PER_GB = 1e9;
|
|
13355
|
-
var NEVER_PAID_MAX_STORED_BYTES = 20 * BYTES_PER_GB;
|
|
13356
|
-
var STOPPED_DELETION_NOTICE_MS = 3 * 864e5;
|
|
13357
|
-
function stoppedMicrosPerHour(storedBytes) {
|
|
13358
|
-
if (storedBytes <= 0) {
|
|
13359
|
-
return 0;
|
|
13360
|
-
}
|
|
13361
|
-
return Math.max(1, Math.round(storedBytes * STOPPED_MICROS_PER_GB_MONTH / (BYTES_PER_GB * HOURS_PER_MONTH)));
|
|
13362
|
-
}
|
|
13363
|
-
function wholeStoredBytes(size2, withMemory) {
|
|
13364
|
-
const resources = MACHINE_SIZES[size2];
|
|
13365
|
-
return resources.diskGb * 2 ** 30 + (withMemory ? resources.memoryMb * 2 ** 20 : 0);
|
|
13366
|
-
}
|
|
13367
|
-
var STOPPED_MAX_MICROS_PER_HOUR = {
|
|
13368
|
-
tiny: stoppedMicrosPerHour(wholeStoredBytes("tiny", false)),
|
|
13369
|
-
small: stoppedMicrosPerHour(wholeStoredBytes("small", false)),
|
|
13370
|
-
medium: stoppedMicrosPerHour(wholeStoredBytes("medium", false)),
|
|
13371
|
-
large: stoppedMicrosPerHour(wholeStoredBytes("large", false))
|
|
13372
|
-
};
|
|
13373
|
-
var STOPPED_WITH_MEMORY_MAX_MICROS_PER_HOUR = {
|
|
13374
|
-
tiny: stoppedMicrosPerHour(wholeStoredBytes("tiny", true)),
|
|
13375
|
-
small: stoppedMicrosPerHour(wholeStoredBytes("small", true)),
|
|
13376
|
-
medium: stoppedMicrosPerHour(wholeStoredBytes("medium", true)),
|
|
13377
|
-
large: stoppedMicrosPerHour(wholeStoredBytes("large", true))
|
|
13378
|
-
};
|
|
13379
|
-
var SANDBOX_STATUSES = ["creating", "running", "stopped", "error", "deleted"];
|
|
13380
|
-
var SHOWN_STATUSES = [...SANDBOX_STATUSES, "restoring", "migrating"];
|
|
13381
|
-
var OUTBOUND_MODES = ["open", "blocked", "allowlist"];
|
|
13382
|
-
function isMachineSize(value) {
|
|
13383
|
-
return Object.hasOwn(MACHINE_SIZES, value);
|
|
13384
|
-
}
|
|
13385
|
-
|
|
13386
13682
|
// ../src/desktop-tree-text.ts
|
|
13387
13683
|
function treeText(tree) {
|
|
13388
13684
|
if (tree.windows.length === 0) {
|
|
@@ -14033,6 +14329,9 @@ async function main() {
|
|
|
14033
14329
|
case "webhooks":
|
|
14034
14330
|
await listWebhooks({ request, fail }, values.json);
|
|
14035
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;
|
|
14036
14335
|
case "webhook":
|
|
14037
14336
|
await webhook({ request, fail }, positionals.slice(1), values);
|
|
14038
14337
|
return;
|
|
@@ -14123,7 +14422,7 @@ async function create(values) {
|
|
|
14123
14422
|
const sshKeys2 = values["ssh-key"] === void 0 ? void 0 : publicKeysFrom(values["ssh-key"]);
|
|
14124
14423
|
const box = boxNamed(values.box);
|
|
14125
14424
|
const templateId = values.template === void 0 ? void 0 : (await templateNamed(values.template)).id;
|
|
14126
|
-
const idempotencyKey = values["idempotency-key"] ?? `cli-${
|
|
14425
|
+
const idempotencyKey = values["idempotency-key"] ?? `cli-${randomUUID3()}`;
|
|
14127
14426
|
const response = await request("/v1/sandboxes", {
|
|
14128
14427
|
method: "POST",
|
|
14129
14428
|
headers: { "Idempotency-Key": idempotencyKey, ...box ? { "X-Agental-Box": box } : {}, ...burstHeaders },
|
|
@@ -14131,6 +14430,7 @@ async function create(values) {
|
|
|
14131
14430
|
...values.name ? { name: values.name } : {},
|
|
14132
14431
|
...values.size ? { size: values.size } : {},
|
|
14133
14432
|
...templateId ? { templateId } : {},
|
|
14433
|
+
...values.snapshot ? { snapshotId: values.snapshot } : {},
|
|
14134
14434
|
...regionsOption(values.region),
|
|
14135
14435
|
...allow ? { network: { allow } } : {},
|
|
14136
14436
|
...egressAsked ? { egress: egressAsked } : {},
|
|
@@ -16775,7 +17075,7 @@ Setting up
|
|
|
16775
17075
|
agental completion zsh|bash|fish
|
|
16776
17076
|
|
|
16777
17077
|
Usage
|
|
16778
|
-
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>]
|
|
16779
17079
|
[--spot [--on-reclaim delete|stop] [--warn-at <chance>]]
|
|
16780
17080
|
${operator ? "[--box <name-or-id>] " : ""}[--allow <address>[,<address>...]] [--egress box | residential:<country>[:sticky|rotating]] [--max-burst-fee <dollars>]
|
|
16781
17081
|
[--ssh-key <public-key-or-file>]... [--tag <tag>[,<tag>...]]... [--meta <key>=<value>]...
|
|
@@ -16867,6 +17167,11 @@ Usage
|
|
|
16867
17167
|
agental job trigger rotate <job> <trigger-id> [--json] a new secret; the old one stops at once
|
|
16868
17168
|
agental job trigger delete <job> <trigger-id>
|
|
16869
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]
|
|
16870
17175
|
agental webhooks [--json]
|
|
16871
17176
|
agental webhook add <url> (--events <kind>[,<kind>...] | --all) [--description <text>] [--json]
|
|
16872
17177
|
agental webhook show <webhook-id> [--json]
|
|
@@ -16991,6 +17296,18 @@ lets out only them, and an allowlist lets out its addresses and them. That holds
|
|
|
16991
17296
|
sandbox is not restarted, and what is sent to it, commands, files and SSH, is not affected.
|
|
16992
17297
|
create --allow gives a new sandbox its own from its first boot. These work where GET
|
|
16993
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.
|
|
16994
17311
|
A template is what a sandbox is made as and held to: its start (a size, and a snapshot or a new
|
|
16995
17312
|
machine), its variables and files, and its outbound rule. Every account has one named default,
|
|
16996
17313
|
which a sandbox is on when create names none. <template> is a template's id or its name. A
|
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",
|