agental 0.13.0 → 0.14.1
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 +515 -109
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -39,14 +39,14 @@ var init_cli_operator = __esm({
|
|
|
39
39
|
|
|
40
40
|
// ../src/cli.ts
|
|
41
41
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
42
|
-
import { readFileSync as
|
|
43
|
-
import
|
|
42
|
+
import { readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
43
|
+
import os6 from "node:os";
|
|
44
44
|
import { readFile } from "node:fs/promises";
|
|
45
45
|
import { parseArgs } from "node:util";
|
|
46
46
|
|
|
47
47
|
// ../src/cli-build.ts
|
|
48
48
|
var PUBLISHED = true;
|
|
49
|
-
var CLI_VERSION = true ? "0.
|
|
49
|
+
var CLI_VERSION = true ? "0.14.1" : "dev";
|
|
50
50
|
var DEFAULT_API_URL = true ? "https://agental.io" : "http://127.0.0.1:8741";
|
|
51
51
|
var PACKAGE_NAME = "agental";
|
|
52
52
|
var USER_AGENT = `agental-cli/${CLI_VERSION}`;
|
|
@@ -473,15 +473,15 @@ function reachOf(key2, full) {
|
|
|
473
473
|
if (key2.sandboxIds.length === 0 && key2.templateIds.length === 0) {
|
|
474
474
|
return key2.seesAll ? "every account" : "all of the account";
|
|
475
475
|
}
|
|
476
|
-
const
|
|
477
|
-
const
|
|
476
|
+
const sandboxes2 = key2.sandboxIds;
|
|
477
|
+
const templates2 = key2.templateIds;
|
|
478
478
|
if (!full) {
|
|
479
479
|
const one = (ids, noun) => ids.length === 1 ? `${noun} ${ids[0]}` : `${ids.length} ${noun}s`;
|
|
480
|
-
return [...
|
|
480
|
+
return [...sandboxes2.length > 0 ? [one(sandboxes2, "sandbox")] : [], ...templates2.length > 0 ? [one(templates2, "template")] : []].join(", ");
|
|
481
481
|
}
|
|
482
482
|
return [
|
|
483
|
-
...
|
|
484
|
-
...
|
|
483
|
+
...sandboxes2.length > 0 ? [`${sandboxes2.length === 1 ? "sandbox" : "sandboxes"} ${sandboxes2.join(", ")}`] : [],
|
|
484
|
+
...templates2.length > 0 ? [`${templates2.length === 1 ? "template" : "templates"} ${templates2.join(", ")} and the sandboxes on ${templates2.length === 1 ? "it" : "them"}`] : []
|
|
485
485
|
].join("; ");
|
|
486
486
|
}
|
|
487
487
|
function expiryOf(key2) {
|
|
@@ -565,12 +565,12 @@ async function templateIdsOf(client, words2) {
|
|
|
565
565
|
return words2;
|
|
566
566
|
}
|
|
567
567
|
const body = await ask2(client, "GET", "/v1/templates");
|
|
568
|
-
const
|
|
568
|
+
const templates2 = Array.isArray(body?.templates) ? body.templates : [];
|
|
569
569
|
return words2.map((word) => {
|
|
570
570
|
if (word.startsWith("tpl_")) {
|
|
571
571
|
return word;
|
|
572
572
|
}
|
|
573
|
-
const found =
|
|
573
|
+
const found = templates2.find((one) => one.name === word);
|
|
574
574
|
if (!found || typeof found.id !== "string") {
|
|
575
575
|
throw new Error(`There is no template ${word}. agental templates lists them.`);
|
|
576
576
|
}
|
|
@@ -1403,8 +1403,8 @@ async function ensureSkills(options, site) {
|
|
|
1403
1403
|
}
|
|
1404
1404
|
return done(`agent skills installed for the coding agents on this computer ${dim(`\xB7 again with npx skills add ${site} -g`)}`);
|
|
1405
1405
|
}
|
|
1406
|
-
function ordered(
|
|
1407
|
-
return
|
|
1406
|
+
function ordered(sandboxes2) {
|
|
1407
|
+
return sandboxes2.filter((sandbox) => sandbox["status"] !== "deleted").sort((a, b) => Number(b["status"] === "running") - Number(a["status"] === "running") || String(b["createdAt"]).localeCompare(String(a["createdAt"])));
|
|
1408
1408
|
}
|
|
1409
1409
|
async function yes(question) {
|
|
1410
1410
|
const lines = createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -1417,16 +1417,16 @@ async function yes(question) {
|
|
|
1417
1417
|
}
|
|
1418
1418
|
async function atTheLimit(base, key2, term, message) {
|
|
1419
1419
|
const listed = await api(base, key2, "GET", "/v1/sandboxes");
|
|
1420
|
-
const
|
|
1420
|
+
const sandboxes2 = ordered(Array.isArray(listed.body["sandboxes"]) ? listed.body["sandboxes"] : []);
|
|
1421
1421
|
term.say(`
|
|
1422
1422
|
${bold("No new sandbox:")} ${message}`);
|
|
1423
|
-
const running =
|
|
1423
|
+
const running = sandboxes2.find((sandbox) => sandbox["status"] === "running");
|
|
1424
1424
|
if (term.interactive && running && await yes(` Open ${bold(String(running["name"]))} (${String(running["id"])}) instead? [Y/n] `)) {
|
|
1425
1425
|
return { id: String(running["id"]), name: String(running["name"]), size: String(running["size"]), existing: true };
|
|
1426
1426
|
}
|
|
1427
|
-
if (
|
|
1428
|
-
const width = Math.max(...
|
|
1429
|
-
for (const sandbox of
|
|
1427
|
+
if (sandboxes2.length > 0) {
|
|
1428
|
+
const width = Math.max(...sandboxes2.map((sandbox) => String(sandbox["name"]).length));
|
|
1429
|
+
for (const sandbox of sandboxes2) {
|
|
1430
1430
|
term.say(` ${String(sandbox["id"])} ${String(sandbox["name"]).padEnd(width)} ${String(sandbox["status"])}`);
|
|
1431
1431
|
}
|
|
1432
1432
|
}
|
|
@@ -1632,6 +1632,12 @@ async function onboard(base, options) {
|
|
|
1632
1632
|
nextSteps(term, [[`agental ssh ${sandbox.id}`, "back in"], stopLine]);
|
|
1633
1633
|
}
|
|
1634
1634
|
|
|
1635
|
+
// ../src/cli-completion.ts
|
|
1636
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
1637
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
1638
|
+
import os5 from "node:os";
|
|
1639
|
+
import path4 from "node:path";
|
|
1640
|
+
|
|
1635
1641
|
// ../src/cli-help.ts
|
|
1636
1642
|
function isTerminal(stream) {
|
|
1637
1643
|
return stream.isTTY === true || process.env["AGENTAL_TERMINAL"] === "1";
|
|
@@ -1681,17 +1687,58 @@ var COMMANDS = [
|
|
|
1681
1687
|
]
|
|
1682
1688
|
},
|
|
1683
1689
|
{ name: "summary", summary: "Count your sandboxes by status, size, template, tag or any field.", examples: ["agental summary", "agental summary --facets size,status"] },
|
|
1684
|
-
{
|
|
1690
|
+
{
|
|
1691
|
+
name: "exec",
|
|
1692
|
+
summary: "Run a command in a sandbox and print what it prints.",
|
|
1693
|
+
examples: ["agental exec sbx_2a9a47e50daec64a -- ls -la", "agental exec sbx_2a9a47e50daec64a -- npm test"],
|
|
1694
|
+
flags: [
|
|
1695
|
+
["-- <command> [args...]", "what to run; everything after -- is the command's own"]
|
|
1696
|
+
]
|
|
1697
|
+
},
|
|
1685
1698
|
{ name: "shell", summary: "Open a login shell in a sandbox, in this terminal, with no SSH key or port.", examples: ["agental shell sbx_2a9a47e50daec64a"] },
|
|
1686
|
-
{
|
|
1699
|
+
{
|
|
1700
|
+
name: "ssh",
|
|
1701
|
+
summary: "Open a shell in a sandbox, or run a command there, over SSH.",
|
|
1702
|
+
examples: ["agental ssh sbx_2a9a47e50daec64a", "agental ssh sbx_2a9a47e50daec64a --tmux"],
|
|
1703
|
+
flags: [
|
|
1704
|
+
["--tmux", "keep the shell in a tmux session, to come back to after a lost connection"],
|
|
1705
|
+
["[ssh options]", "anything ssh itself takes, as -L 8080:localhost:8080"]
|
|
1706
|
+
]
|
|
1707
|
+
},
|
|
1687
1708
|
{ name: "scp", summary: "Copy files to or from a sandbox over SSH.", examples: ["agental scp ./build.tar.gz sbx_2a9a47e50daec64a:/tmp/"] },
|
|
1688
1709
|
{ name: "ssh-config", summary: "Print a Host block for ~/.ssh/config, so anything that speaks SSH reaches a sandbox by its id.", examples: ["agental ssh-config sbx_2a9a47e50daec64a >> ~/.ssh/config"] },
|
|
1689
1710
|
{ name: "ssh-connect", summary: "Reach a sandbox for ssh: what the Host block ssh-config prints runs. It is not typed by hand." },
|
|
1690
1711
|
{ name: "ssh-keys", summary: "List or remove the SSH keys a sandbox lets in." },
|
|
1691
1712
|
{ name: "ssh-off", summary: "Turn SSH off for a sandbox and close its port." },
|
|
1692
|
-
{
|
|
1693
|
-
|
|
1694
|
-
|
|
1713
|
+
{
|
|
1714
|
+
name: "start",
|
|
1715
|
+
summary: "Start a stopped sandbox, or every one --where finds.",
|
|
1716
|
+
examples: ["agental start sbx_2a9a47e50daec64a"],
|
|
1717
|
+
flags: [
|
|
1718
|
+
["--where '<words>'", "every sandbox the words find, as one job"],
|
|
1719
|
+
["--yes", "with --where: start them without asking"],
|
|
1720
|
+
["--max-burst-fee <dollars>", "the most this start may pay in burst fees"]
|
|
1721
|
+
]
|
|
1722
|
+
},
|
|
1723
|
+
{
|
|
1724
|
+
name: "stop",
|
|
1725
|
+
summary: "Stop a sandbox, or every one --where finds. Its disk is kept.",
|
|
1726
|
+
examples: ["agental stop sbx_2a9a47e50daec64a", "agental stop sbx_2a9a47e50daec64a --keep-memory", "agental stop --where 'bench'"],
|
|
1727
|
+
flags: [
|
|
1728
|
+
["--keep-memory", "keep what runs in memory too, so it carries on from where it was"],
|
|
1729
|
+
["--where '<words>'", "every sandbox the words find, as one job"],
|
|
1730
|
+
["--yes", "with --where: stop them without asking"]
|
|
1731
|
+
]
|
|
1732
|
+
},
|
|
1733
|
+
{
|
|
1734
|
+
name: "delete",
|
|
1735
|
+
summary: "Delete a sandbox, or every one --where finds. It cannot be undone.",
|
|
1736
|
+
examples: ["agental delete sbx_2a9a47e50daec64a"],
|
|
1737
|
+
flags: [
|
|
1738
|
+
["--where '<words>'", "every sandbox the words find, as one job"],
|
|
1739
|
+
["--confirm <count>", "with --where: how many it finds, typed so that none are deleted by mistake"]
|
|
1740
|
+
]
|
|
1741
|
+
},
|
|
1695
1742
|
{ name: "recover", summary: "Get a stuck sandbox going again: what runs in it is killed, its disk is kept." },
|
|
1696
1743
|
{ name: "auto-stop", summary: "Say when a running sandbox stops by itself, or that it never does.", examples: ["agental auto-stop sbx_2a9a47e50daec64a --in 2h", "agental auto-stop sbx_2a9a47e50daec64a --never"] },
|
|
1697
1744
|
{ name: "jobs", summary: "Follow or cancel the work started on many sandboxes at once." },
|
|
@@ -1707,10 +1754,51 @@ var COMMANDS = [
|
|
|
1707
1754
|
{ name: "network", summary: "Say what a sandbox may reach outside itself.", examples: ["agental network sbx_2a9a47e50daec64a --allow github.com,registry.npmjs.org", "agental network sbx_2a9a47e50daec64a --none"] },
|
|
1708
1755
|
{ name: "egress", summary: "Say where a sandbox's web traffic leaves from, or read your residential egress.", examples: ["agental egress sbx_2a9a47e50daec64a residential de"] },
|
|
1709
1756
|
{ name: "templates", summary: "List your templates: what new sandboxes start from." },
|
|
1710
|
-
{
|
|
1711
|
-
|
|
1757
|
+
{
|
|
1758
|
+
name: "template",
|
|
1759
|
+
summary: "Make, read, change and start templates.",
|
|
1760
|
+
examples: ["agental template create my-env", "agental template start my-env --size medium", "agental template put my-env sbx_2a9a47e50daec64a"],
|
|
1761
|
+
flags: [
|
|
1762
|
+
["--size <size>", "start: the size its sandboxes start as"],
|
|
1763
|
+
["--snapshot <snapshot-id>", "start: start them from this snapshot"],
|
|
1764
|
+
["--new-machine", "start: start them as a new machine, from no snapshot"],
|
|
1765
|
+
["--ttl <time> | default", "start: stop them after this long, as 2h"],
|
|
1766
|
+
["--tag <tag>, --meta <key>=<value>", "create: label it (may be given again)"],
|
|
1767
|
+
["--json", "print as JSON"]
|
|
1768
|
+
]
|
|
1769
|
+
},
|
|
1770
|
+
{
|
|
1771
|
+
name: "secrets",
|
|
1772
|
+
summary: "Keep values and files out of a sandbox, or out of every sandbox of a template.",
|
|
1773
|
+
examples: ["agental secrets --template default set GITHUB_TOKEN=ghp_\u2026 --host github.com,api.github.com", "agental secrets sbx_2a9a47e50daec64a"],
|
|
1774
|
+
flags: [
|
|
1775
|
+
["--template <template>", "the template's secrets, for every sandbox made from it"],
|
|
1776
|
+
["--host <host>[,<host>...]", "set, hosts: keep the value out of the sandbox, sent only to these hosts"],
|
|
1777
|
+
["--plain", "set: a variable the sandbox sees, where its template keeps one out"],
|
|
1778
|
+
["--text <text>", "put-file: the file's content, in place of a local file"],
|
|
1779
|
+
["--json", "print as JSON"]
|
|
1780
|
+
]
|
|
1781
|
+
},
|
|
1712
1782
|
{ name: "schedules", summary: "List a sandbox's schedules." },
|
|
1713
|
-
{
|
|
1783
|
+
{
|
|
1784
|
+
name: "schedule",
|
|
1785
|
+
summary: "Run a command in a sandbox on a timer, or once at a time.",
|
|
1786
|
+
examples: ["agental schedule add sbx_2a9a47e50daec64a --every 1h -- npm test", "agental schedule runs sbx_2a9a47e50daec64a nightly"],
|
|
1787
|
+
flags: [
|
|
1788
|
+
["--every 5m|15m|1h|1d", "add, update: how often, counted from now"],
|
|
1789
|
+
['--cron "<m h dom mon dow>"', "add, update: when, as cron says it, in UTC unless --tz says"],
|
|
1790
|
+
["--tz <zone>", "the time zone --cron is read in, as Europe/Sofia"],
|
|
1791
|
+
["--at <date-time>", "add, update: once, at that moment"],
|
|
1792
|
+
["--name <name>", "what to call it, for show, run and the rest"],
|
|
1793
|
+
["--timeout <time>", "how long a run may take (default 10m, at most 6h)"],
|
|
1794
|
+
["--if-stopped start|skip", "start a stopped sandbox for the run and stop it after (start), or skip"],
|
|
1795
|
+
["--keep-memory", "when the run stops the sandbox again, keep its memory too"],
|
|
1796
|
+
["--overlap skip|replace|parallel", "when the last run still goes: skip this one, stop that one, or run both"],
|
|
1797
|
+
["--delete-after", "with --at: delete the sandbox after a run that exits 0"],
|
|
1798
|
+
["--limit <n>", "runs: how many to list"],
|
|
1799
|
+
["--json", "print as JSON"]
|
|
1800
|
+
]
|
|
1801
|
+
},
|
|
1714
1802
|
{ name: "metrics", summary: "Read CPU, memory and disk, of each sandbox now or of one over time.", examples: ["agental metrics", "agental metrics sbx_2a9a47e50daec64a --since 2h"] },
|
|
1715
1803
|
{ name: "email", summary: "Give a sandbox an email address of its own, and read and send its mail." },
|
|
1716
1804
|
{ name: "desktop", summary: "Turn on a screen in a sandbox, watch it, and drive it." },
|
|
@@ -1722,7 +1810,21 @@ var COMMANDS = [
|
|
|
1722
1810
|
{ name: "webhooks", summary: "List the addresses your account's events are sent to." },
|
|
1723
1811
|
{ name: "webhook", summary: "Add, change and remove the addresses your account's events are sent to.", examples: ["agental webhook add https://example.com/agental --all"] },
|
|
1724
1812
|
{ name: "keys", summary: "List your account's API keys." },
|
|
1725
|
-
{
|
|
1813
|
+
{
|
|
1814
|
+
name: "key",
|
|
1815
|
+
summary: "Make, read, limit and delete API keys.",
|
|
1816
|
+
examples: ["agental key add ci --preset ci", "agental key add reader --preset read-only --expires 30d"],
|
|
1817
|
+
flags: [
|
|
1818
|
+
["--preset <preset>", "add: read-only, full-sandbox, ci or admin"],
|
|
1819
|
+
["--actions <action>[,...]", "add: exactly these actions, in place of a preset"],
|
|
1820
|
+
["--sandbox <sandbox-id>", "add: reach only these sandboxes (may be given again)"],
|
|
1821
|
+
["--template <template>", "add: reach only these templates and their sandboxes (may be given again)"],
|
|
1822
|
+
["--expires <date> | <n>d | <n>h", "add: stop working then, as 2026-12-31 or 30d"],
|
|
1823
|
+
["--allow-from <address-or-range>", "add, allow-from: be used only from these addresses (may be given again)"],
|
|
1824
|
+
["--anywhere", "allow-from: lift the limit"],
|
|
1825
|
+
["--json", "print as JSON"]
|
|
1826
|
+
]
|
|
1827
|
+
},
|
|
1726
1828
|
{ name: "org", summary: "List, switch and make the accounts you belong to." },
|
|
1727
1829
|
{ name: "members", summary: "List or remove the members of a team." },
|
|
1728
1830
|
{ name: "invite", summary: "Invite someone to your team by email." },
|
|
@@ -1733,6 +1835,11 @@ var COMMANDS = [
|
|
|
1733
1835
|
{ name: "logout", summary: "Delete this computer's key from your account and from here." },
|
|
1734
1836
|
{ name: "whoami", summary: "Who the command is signed in as, and with which key." },
|
|
1735
1837
|
{ name: "version", summary: "Print the version of agental." },
|
|
1838
|
+
{
|
|
1839
|
+
name: "completion",
|
|
1840
|
+
summary: "Print the script that completes agental's commands, flags, sandboxes and templates when Tab is pressed.",
|
|
1841
|
+
examples: ["source <(agental completion zsh) # in ~/.zshrc, after compinit", "source <(agental completion bash) # in ~/.bashrc", "agental completion fish | source # in ~/.config/fish/config.fish"]
|
|
1842
|
+
},
|
|
1736
1843
|
{
|
|
1737
1844
|
name: "sandbox",
|
|
1738
1845
|
summary: "Your sandboxes, as agental sandbox <verb>: each is the same as the command without sandbox in front.",
|
|
@@ -1768,7 +1875,14 @@ var COMMANDS = [
|
|
|
1768
1875
|
"agental secret get-file|rm-file (<sandbox-id> | --template <template>) <path>"
|
|
1769
1876
|
],
|
|
1770
1877
|
examples: ["agental secret set --template default GITHUB_TOKEN=ghp_\u2026 --host github.com,api.github.com", "agental secret list sbx_2a9a47e50daec64a"],
|
|
1771
|
-
also: "secrets <sandbox-id> <verb>"
|
|
1878
|
+
also: "secrets <sandbox-id> <verb>",
|
|
1879
|
+
flags: [
|
|
1880
|
+
["--template <template>", "the template's secrets, for every sandbox made from it"],
|
|
1881
|
+
["--host <host>[,<host>...]", "set, hosts: keep the value out of the sandbox, sent only to these hosts"],
|
|
1882
|
+
["--plain", "set: a variable the sandbox sees, where its template keeps one out"],
|
|
1883
|
+
["--text <text>", "put-file: the file's content, in place of a local file"],
|
|
1884
|
+
["--json", "print as JSON"]
|
|
1885
|
+
]
|
|
1772
1886
|
},
|
|
1773
1887
|
{ name: "job", summary: "Follow or cancel the work started on many sandboxes at once.", usage: ["agental job list [--json]", "agental job show <job-id> [--json]", "agental job cancel <job-id>"], also: "jobs" },
|
|
1774
1888
|
{
|
|
@@ -1826,7 +1940,13 @@ var MAP = [
|
|
|
1826
1940
|
["account", "everything agental keeps about you"]
|
|
1827
1941
|
]
|
|
1828
1942
|
],
|
|
1829
|
-
[
|
|
1943
|
+
[
|
|
1944
|
+
"You",
|
|
1945
|
+
[
|
|
1946
|
+
["login, logout, whoami", "who the command is signed in as"],
|
|
1947
|
+
["completion", "Tab completion for zsh, bash and fish"]
|
|
1948
|
+
]
|
|
1949
|
+
]
|
|
1830
1950
|
];
|
|
1831
1951
|
var DOCS = "https://agental.io/docs/cli";
|
|
1832
1952
|
function shortHelp() {
|
|
@@ -2042,6 +2162,252 @@ function sandboxIn(words2, valued = []) {
|
|
|
2042
2162
|
return { sandbox: void 0, others: words2 };
|
|
2043
2163
|
}
|
|
2044
2164
|
|
|
2165
|
+
// ../src/cli-completion.ts
|
|
2166
|
+
var SHELLS = ["zsh", "bash", "fish"];
|
|
2167
|
+
var SUBCOMMANDS = {
|
|
2168
|
+
billing: ["prices", "invoices", "card", "top-up", "auto-reload"],
|
|
2169
|
+
// Each thing that lists as its plural lists as itself too.
|
|
2170
|
+
template: ["list"],
|
|
2171
|
+
key: ["list"],
|
|
2172
|
+
webhook: ["list"],
|
|
2173
|
+
schedule: ["list"],
|
|
2174
|
+
headroom: ["budget"],
|
|
2175
|
+
egress: ["budget", "use-case"],
|
|
2176
|
+
telemetry: ["set", "test", "unset"],
|
|
2177
|
+
ci: ["set", "reset"],
|
|
2178
|
+
org: ["list", "use", "create"],
|
|
2179
|
+
members: ["list", "remove"],
|
|
2180
|
+
jobs: ["list", "show", "cancel"],
|
|
2181
|
+
account: ["export"],
|
|
2182
|
+
help: []
|
|
2183
|
+
};
|
|
2184
|
+
function partsOf(usage) {
|
|
2185
|
+
const line = usage.replace(/ {3,}\S.*$/, "").replace(/^agental /, "");
|
|
2186
|
+
const parts = [];
|
|
2187
|
+
let depth = 0;
|
|
2188
|
+
let part = "";
|
|
2189
|
+
for (const char of line) {
|
|
2190
|
+
depth += char === "[" || char === "(" ? 1 : char === "]" || char === ")" ? -1 : 0;
|
|
2191
|
+
if (char === " " && depth === 0) {
|
|
2192
|
+
if (part) {
|
|
2193
|
+
parts.push(part);
|
|
2194
|
+
}
|
|
2195
|
+
part = "";
|
|
2196
|
+
} else {
|
|
2197
|
+
part += char;
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
if (part) {
|
|
2201
|
+
parts.push(part);
|
|
2202
|
+
}
|
|
2203
|
+
return parts;
|
|
2204
|
+
}
|
|
2205
|
+
function wordsOf(part) {
|
|
2206
|
+
const inner = part.replace(/^[[(]/, "").replace(/[\])]\.*$/, "");
|
|
2207
|
+
const first = inner.split(" ")[0] ?? "";
|
|
2208
|
+
if (first.startsWith("-") || first.startsWith("<") || first === "") {
|
|
2209
|
+
return [];
|
|
2210
|
+
}
|
|
2211
|
+
return first.split("|").filter((word) => /^[a-z][a-z-]*$/.test(word));
|
|
2212
|
+
}
|
|
2213
|
+
function flagsOf(usages) {
|
|
2214
|
+
const flags2 = /* @__PURE__ */ new Map();
|
|
2215
|
+
for (const usage of usages) {
|
|
2216
|
+
for (const found of usage.matchAll(/(--[a-z][a-z-]*)(?:[ =]([^\s\]|)]+(?:\|[^\s\]|)]+)*))?/g)) {
|
|
2217
|
+
const flag = found[1];
|
|
2218
|
+
const value = found[2] && !found[2].startsWith("-") ? found[2] : null;
|
|
2219
|
+
if (!flags2.has(flag) || flags2.get(flag) === null && value !== null) {
|
|
2220
|
+
flags2.set(flag, value);
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
return flags2;
|
|
2225
|
+
}
|
|
2226
|
+
var SANDBOX = /^<sandbox-id>/;
|
|
2227
|
+
var SANDBOX_VERBS2 = /* @__PURE__ */ new Set(["list", "create", "start", "stop", "delete", "recover", "exec", "shell", "summary"]);
|
|
2228
|
+
var TEMPLATE = /^<template>/;
|
|
2229
|
+
async function complete(typed, reference, operator, fetchJson) {
|
|
2230
|
+
if (typed[0] === "sandbox" && typed.length > 2 && SANDBOX_VERBS2.has(typed[1])) {
|
|
2231
|
+
return complete(typed.slice(1), reference, operator, fetchJson);
|
|
2232
|
+
}
|
|
2233
|
+
const words2 = typed.length === 0 ? [""] : [...typed];
|
|
2234
|
+
const equals = words2.lastIndexOf("=");
|
|
2235
|
+
if (equals > 0 && equals >= words2.length - 2 && words2[equals - 1]?.startsWith("--")) {
|
|
2236
|
+
words2.splice(equals, 1);
|
|
2237
|
+
if (equals === words2.length) {
|
|
2238
|
+
words2.push("");
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
const whole = /^(--[a-z][a-z-]*)=(.*)$/.exec(words2[words2.length - 1]);
|
|
2242
|
+
if (whole) {
|
|
2243
|
+
words2.splice(words2.length - 1, 1, whole[1], whole[2]);
|
|
2244
|
+
}
|
|
2245
|
+
const current = words2[words2.length - 1];
|
|
2246
|
+
const before = words2.slice(0, -1);
|
|
2247
|
+
const commands = COMMANDS.filter((each) => operator || !each.operator);
|
|
2248
|
+
const starting = (candidates2) => candidates2.filter((each) => each.value.startsWith(current)).map((each) => whole ? { ...each, value: `${whole[1]}=${each.value}` } : each);
|
|
2249
|
+
if (before.includes("--")) {
|
|
2250
|
+
return [];
|
|
2251
|
+
}
|
|
2252
|
+
if (before.length === 0) {
|
|
2253
|
+
return starting([...commands.map((each) => ({ value: each.name, about: each.summary })), { value: "help", about: "the map of the commands, or one command's help" }]);
|
|
2254
|
+
}
|
|
2255
|
+
const name = before[0];
|
|
2256
|
+
const found = commands.find((each) => each.name === name);
|
|
2257
|
+
if (!found && name !== "help") {
|
|
2258
|
+
return [];
|
|
2259
|
+
}
|
|
2260
|
+
if (name === "help") {
|
|
2261
|
+
return before.length === 1 ? starting([...commands.map((each) => ({ value: each.name, about: each.summary })), { value: "--all", about: "everything, as one page" }]) : [];
|
|
2262
|
+
}
|
|
2263
|
+
const usages = [...found?.usage ?? [], ...usageOf(reference).get(name) ?? []];
|
|
2264
|
+
const flags2 = flagsOf(usages);
|
|
2265
|
+
const last = before[before.length - 1];
|
|
2266
|
+
const valueOf = flags2.get(last) ?? (last === "-t" ? "<template>" : last === "-s" ? "tiny|small|medium|large" : void 0);
|
|
2267
|
+
if (valueOf !== void 0 && valueOf !== null) {
|
|
2268
|
+
if (TEMPLATE.test(valueOf)) {
|
|
2269
|
+
return starting(await templates(fetchJson));
|
|
2270
|
+
}
|
|
2271
|
+
if (SANDBOX.test(valueOf)) {
|
|
2272
|
+
return starting(await sandboxes(fetchJson));
|
|
2273
|
+
}
|
|
2274
|
+
const choices = valueOf.split("|").filter((word) => /^[a-z0-9][a-z0-9.-]*$/i.test(word));
|
|
2275
|
+
return starting(choices.map((value) => ({ value })));
|
|
2276
|
+
}
|
|
2277
|
+
if (current.startsWith("-")) {
|
|
2278
|
+
return starting([...[...flags2.keys()].sort().map((value) => ({ value })), { value: "--help", about: "this command's help" }]);
|
|
2279
|
+
}
|
|
2280
|
+
const positionals = [];
|
|
2281
|
+
for (let index = 1; index < before.length; index++) {
|
|
2282
|
+
const word = before[index];
|
|
2283
|
+
if (word.startsWith("-")) {
|
|
2284
|
+
index += flags2.get(word) || word === "-t" || word === "-s" || word === "-n" ? 1 : 0;
|
|
2285
|
+
continue;
|
|
2286
|
+
}
|
|
2287
|
+
positionals.push(word);
|
|
2288
|
+
}
|
|
2289
|
+
const candidates = /* @__PURE__ */ new Map();
|
|
2290
|
+
let wantsSandbox = false;
|
|
2291
|
+
let wantsTemplate = false;
|
|
2292
|
+
for (const usage of usages) {
|
|
2293
|
+
const parts = partsOf(usage).slice(1);
|
|
2294
|
+
const fits = positionals.every((word, index) => {
|
|
2295
|
+
const part2 = parts[index];
|
|
2296
|
+
if (part2 === void 0) {
|
|
2297
|
+
return false;
|
|
2298
|
+
}
|
|
2299
|
+
const choices = wordsOf(part2);
|
|
2300
|
+
return choices.length === 0 || choices.includes(word);
|
|
2301
|
+
});
|
|
2302
|
+
const part = parts[positionals.length];
|
|
2303
|
+
if (!fits || part === void 0) {
|
|
2304
|
+
continue;
|
|
2305
|
+
}
|
|
2306
|
+
for (const word of wordsOf(part)) {
|
|
2307
|
+
candidates.set(word, { value: word });
|
|
2308
|
+
}
|
|
2309
|
+
const inner = part.replace(/^[[(]/, "");
|
|
2310
|
+
wantsSandbox ||= SANDBOX.test(inner);
|
|
2311
|
+
wantsTemplate ||= TEMPLATE.test(inner);
|
|
2312
|
+
}
|
|
2313
|
+
if (positionals.length === 0) {
|
|
2314
|
+
for (const word of SUBCOMMANDS[name] ?? []) {
|
|
2315
|
+
candidates.set(word, { value: word });
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
if (name === "billing" && positionals[0] === "card" && positionals.length === 1) {
|
|
2319
|
+
candidates.set("save", { value: "save", about: "save a card, charged nothing" });
|
|
2320
|
+
}
|
|
2321
|
+
const asked2 = [...wantsSandbox ? await sandboxes(fetchJson) : [], ...wantsTemplate ? await templates(fetchJson) : []];
|
|
2322
|
+
return starting([...candidates.values(), ...asked2]);
|
|
2323
|
+
}
|
|
2324
|
+
async function sandboxes(api2) {
|
|
2325
|
+
const body = await cached("sandboxes", api2.as, () => api2.get("/v1/sandboxes?limit=200"));
|
|
2326
|
+
return (body?.sandboxes ?? []).filter((each) => typeof each["id"] === "string").sort((a, b) => Number(b["status"] === "running") - Number(a["status"] === "running")).map((each) => ({ value: each["id"], about: [each["name"], each["status"]].filter((word) => typeof word === "string" && word).join(", ") }));
|
|
2327
|
+
}
|
|
2328
|
+
async function templates(api2) {
|
|
2329
|
+
const body = await cached("templates", api2.as, () => api2.get("/v1/templates"));
|
|
2330
|
+
const listed = Array.isArray(body) ? body : body?.templates ?? [];
|
|
2331
|
+
return listed.filter((each) => typeof each["name"] === "string").map((each) => ({ value: each["name"], about: each["default"] === true ? "the default" : void 0 }));
|
|
2332
|
+
}
|
|
2333
|
+
var KEPT_MS = 3e4;
|
|
2334
|
+
async function cached(what, as, ask8) {
|
|
2335
|
+
const folder = path4.join(process.env["XDG_CACHE_HOME"] || path4.join(os5.homedir(), ".cache"), "agental");
|
|
2336
|
+
const file = path4.join(folder, `complete-${what}-${createHash2("sha256").update(as).digest("hex").slice(0, 16)}.json`);
|
|
2337
|
+
try {
|
|
2338
|
+
const kept2 = JSON.parse(readFileSync3(file, "utf8"));
|
|
2339
|
+
if (Date.now() - kept2.at < KEPT_MS) {
|
|
2340
|
+
return kept2.body;
|
|
2341
|
+
}
|
|
2342
|
+
} catch {
|
|
2343
|
+
}
|
|
2344
|
+
let body = null;
|
|
2345
|
+
try {
|
|
2346
|
+
body = await ask8();
|
|
2347
|
+
} catch {
|
|
2348
|
+
return null;
|
|
2349
|
+
}
|
|
2350
|
+
try {
|
|
2351
|
+
mkdirSync3(folder, { recursive: true, mode: 448 });
|
|
2352
|
+
writeFileSync3(file, JSON.stringify({ at: Date.now(), body }), { mode: 384 });
|
|
2353
|
+
} catch {
|
|
2354
|
+
}
|
|
2355
|
+
return body;
|
|
2356
|
+
}
|
|
2357
|
+
var SAFE_VALUE = /^[A-Za-z0-9._:@\/+,=%-]+$/;
|
|
2358
|
+
function linesOf(candidates) {
|
|
2359
|
+
const shown = candidates.filter((each) => SAFE_VALUE.test(each.value));
|
|
2360
|
+
const plain3 = (text) => text.replace(/[\u0000-\u001f\u007f-\u009f]/g, " ");
|
|
2361
|
+
return shown.map((each) => each.about ? `${each.value} ${plain3(each.about)}` : each.value).join("\n") + (shown.length > 0 ? "\n" : "");
|
|
2362
|
+
}
|
|
2363
|
+
function scriptFor(shell2) {
|
|
2364
|
+
switch (shell2) {
|
|
2365
|
+
case "zsh":
|
|
2366
|
+
return `#compdef agental
|
|
2367
|
+
# agental's tab completion for zsh. Add to ~/.zshrc, after compinit:
|
|
2368
|
+
# source <(agental completion zsh)
|
|
2369
|
+
_agental() {
|
|
2370
|
+
local -a lines described
|
|
2371
|
+
local line
|
|
2372
|
+
lines=("\${(@f)$(agental __complete -- "\${(@)words[2,CURRENT]}" 2>/dev/null)}")
|
|
2373
|
+
for line in "\${lines[@]}"; do
|
|
2374
|
+
[[ -z "$line" ]] && continue
|
|
2375
|
+
if [[ "$line" == *$'\\t'* ]]; then
|
|
2376
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
2377
|
+
else
|
|
2378
|
+
described+=("\${line//:/\\\\:}")
|
|
2379
|
+
fi
|
|
2380
|
+
done
|
|
2381
|
+
if (( \${#described} )); then
|
|
2382
|
+
_describe -t agental 'agental' described
|
|
2383
|
+
else
|
|
2384
|
+
_default
|
|
2385
|
+
fi
|
|
2386
|
+
}
|
|
2387
|
+
if (( $+functions[compdef] )); then
|
|
2388
|
+
compdef _agental agental
|
|
2389
|
+
fi
|
|
2390
|
+
`;
|
|
2391
|
+
case "bash":
|
|
2392
|
+
return `# agental's tab completion for bash. Add to ~/.bashrc:
|
|
2393
|
+
# source <(agental completion bash)
|
|
2394
|
+
_agental() {
|
|
2395
|
+
local line
|
|
2396
|
+
COMPREPLY=()
|
|
2397
|
+
while IFS= read -r line; do
|
|
2398
|
+
COMPREPLY+=("\${line%%$'\\t'*}")
|
|
2399
|
+
done < <(agental __complete -- "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null)
|
|
2400
|
+
}
|
|
2401
|
+
complete -o default -F _agental agental
|
|
2402
|
+
`;
|
|
2403
|
+
case "fish":
|
|
2404
|
+
return `# agental's tab completion for fish. Add to ~/.config/fish/config.fish:
|
|
2405
|
+
# agental completion fish | source
|
|
2406
|
+
complete -c agental -f -a '(agental __complete -- (commandline -opc)[2..-1] (commandline -ct) 2>/dev/null)'
|
|
2407
|
+
`;
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2045
2411
|
// ../src/cli-table.ts
|
|
2046
2412
|
var plain2 = (text) => text.replace(/\x1b\[[0-9;]*m/g, "");
|
|
2047
2413
|
function windowWidth() {
|
|
@@ -2480,12 +2846,12 @@ async function schedule(client, positionals, options) {
|
|
|
2480
2846
|
throw new Error(USAGE3);
|
|
2481
2847
|
}
|
|
2482
2848
|
const id = await idOf2(client, sandboxId, target, what);
|
|
2483
|
-
const
|
|
2849
|
+
const path5 = `${base}/${encodeURIComponent(id)}`;
|
|
2484
2850
|
if (what === "show") {
|
|
2485
|
-
print3(await ask5(client, "GET",
|
|
2851
|
+
print3(await ask5(client, "GET", path5), options.json);
|
|
2486
2852
|
} else if (what === "runs") {
|
|
2487
2853
|
const limit = options.limit === void 0 ? "" : `?limit=${encodeURIComponent(options.limit)}`;
|
|
2488
|
-
const runs = (await ask5(client, "GET", `${
|
|
2854
|
+
const runs = (await ask5(client, "GET", `${path5}/runs${limit}`))?.runs ?? [];
|
|
2489
2855
|
if (options.json) {
|
|
2490
2856
|
process.stdout.write(`${JSON.stringify(runs, null, 2)}
|
|
2491
2857
|
`);
|
|
@@ -2507,7 +2873,7 @@ async function schedule(client, positionals, options) {
|
|
|
2507
2873
|
);
|
|
2508
2874
|
}
|
|
2509
2875
|
} else if (what === "run") {
|
|
2510
|
-
const run2 = await ask5(client, "POST", `${
|
|
2876
|
+
const run2 = await ask5(client, "POST", `${path5}/run`);
|
|
2511
2877
|
if (options.json) {
|
|
2512
2878
|
process.stdout.write(`${JSON.stringify(run2, null, 2)}
|
|
2513
2879
|
`);
|
|
@@ -2517,9 +2883,9 @@ async function schedule(client, positionals, options) {
|
|
|
2517
2883
|
`);
|
|
2518
2884
|
}
|
|
2519
2885
|
} else if (what === "pause" || what === "resume") {
|
|
2520
|
-
print3(await ask5(client, "PATCH",
|
|
2886
|
+
print3(await ask5(client, "PATCH", path5, { enabled: what === "resume" }), options.json);
|
|
2521
2887
|
} else if (what === "delete") {
|
|
2522
|
-
await ask5(client, "DELETE",
|
|
2888
|
+
await ask5(client, "DELETE", path5);
|
|
2523
2889
|
process.stdout.write(`Deleted ${id}, with its runs.
|
|
2524
2890
|
`);
|
|
2525
2891
|
} else {
|
|
@@ -2527,7 +2893,7 @@ async function schedule(client, positionals, options) {
|
|
|
2527
2893
|
if (Object.keys(changes).length === 0) {
|
|
2528
2894
|
throw new Error("schedule update needs something to change: --every, --cron, --at, --tz, --name, --timeout, --overlap, --if-stopped, --keep-memory or --disk-only, --delete-after or --keep-sandbox, or a new command after --.");
|
|
2529
2895
|
}
|
|
2530
|
-
print3(await ask5(client, "PATCH",
|
|
2896
|
+
print3(await ask5(client, "PATCH", path5, changes), options.json);
|
|
2531
2897
|
}
|
|
2532
2898
|
return;
|
|
2533
2899
|
}
|
|
@@ -3005,7 +3371,7 @@ function needId2(id, what) {
|
|
|
3005
3371
|
}
|
|
3006
3372
|
|
|
3007
3373
|
// ../src/cli-shell.ts
|
|
3008
|
-
import { createHash as
|
|
3374
|
+
import { createHash as createHash3, randomBytes as randomBytes4 } from "node:crypto";
|
|
3009
3375
|
var TERMINAL_PROTOCOL = "agental.terminal.v1";
|
|
3010
3376
|
var TICKET_PROTOCOL_PREFIX = "ticket.";
|
|
3011
3377
|
var VERIFIER_PROTOCOL_PREFIX = "verifier.";
|
|
@@ -3017,15 +3383,15 @@ function clamp(value, fallback) {
|
|
|
3017
3383
|
function sizeOf(stdout) {
|
|
3018
3384
|
return stdout.isTTY ? { cols: clamp(stdout.columns, 80), rows: clamp(stdout.rows, 24) } : { cols: 80, rows: 24 };
|
|
3019
3385
|
}
|
|
3020
|
-
function webSocketUrl(base,
|
|
3021
|
-
if (typeof
|
|
3386
|
+
function webSocketUrl(base, path5) {
|
|
3387
|
+
if (typeof path5 !== "string" || !path5.startsWith("/") || path5.startsWith("//") || /[\\\s]/.test(path5)) {
|
|
3022
3388
|
throw new Error("The API gave the terminal a path that is not one on its own address.");
|
|
3023
3389
|
}
|
|
3024
3390
|
const url = new URL(base);
|
|
3025
3391
|
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
3026
3392
|
throw new Error(`A terminal is opened on an http: or https: API, not ${url.protocol}`);
|
|
3027
3393
|
}
|
|
3028
|
-
return `${url.protocol === "https:" ? "wss:" : "ws:"}//${url.host}${url.pathname.replace(/\/+$/, "")}${
|
|
3394
|
+
return `${url.protocol === "https:" ? "wss:" : "ws:"}//${url.host}${url.pathname.replace(/\/+$/, "")}${path5}`;
|
|
3029
3395
|
}
|
|
3030
3396
|
function whyClosed(code, reason, error) {
|
|
3031
3397
|
const said = error?.message || reason;
|
|
@@ -3053,7 +3419,7 @@ async function shell(client, id, streams = process) {
|
|
|
3053
3419
|
const { stdin, stdout, stderr } = streams;
|
|
3054
3420
|
const size = sizeOf(stdout);
|
|
3055
3421
|
const verifier = randomBytes4(32).toString("base64url");
|
|
3056
|
-
const challenge =
|
|
3422
|
+
const challenge = createHash3("sha256").update(verifier).digest("base64url");
|
|
3057
3423
|
const response = await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminal`, { method: "POST", body: JSON.stringify({ ...size, challenge }) });
|
|
3058
3424
|
const body = await response.json().catch(() => null);
|
|
3059
3425
|
if (!response.ok || typeof body?.ticket !== "string") {
|
|
@@ -3444,7 +3810,43 @@ async function helpAsked(args) {
|
|
|
3444
3810
|
process.stdout.write(one);
|
|
3445
3811
|
return true;
|
|
3446
3812
|
}
|
|
3813
|
+
async function completionAsked(args) {
|
|
3814
|
+
const [first, second, ...rest] = args;
|
|
3815
|
+
if (first === "__complete") {
|
|
3816
|
+
const typed = second === "--" ? rest : args.slice(1);
|
|
3817
|
+
try {
|
|
3818
|
+
const api2 = {
|
|
3819
|
+
as: `${apiBase()} ${maybeApiKey() ?? ""}`,
|
|
3820
|
+
get: async (pathname) => {
|
|
3821
|
+
if (!maybeApiKey()) {
|
|
3822
|
+
throw new Error("not signed in");
|
|
3823
|
+
}
|
|
3824
|
+
const response = await request(pathname, { method: "GET", signal: AbortSignal.timeout(800) });
|
|
3825
|
+
if (!response.ok) {
|
|
3826
|
+
throw new Error(String(response.status));
|
|
3827
|
+
}
|
|
3828
|
+
return await readBody(response);
|
|
3829
|
+
}
|
|
3830
|
+
};
|
|
3831
|
+
const lines = linesOf(await complete(typed, await helpText(), !PUBLISHED, api2));
|
|
3832
|
+
await new Promise((resolve) => process.stdout.write(lines, () => resolve()));
|
|
3833
|
+
} catch {
|
|
3834
|
+
}
|
|
3835
|
+
process.exit(0);
|
|
3836
|
+
}
|
|
3837
|
+
if (first === "completion" && !args.includes("--help") && !args.includes("-h")) {
|
|
3838
|
+
if (!SHELLS.includes(second) || rest.length > 0) {
|
|
3839
|
+
throw new Error(`completion takes the shell to complete in, ${SHELLS.join(", ")}: as source <(agental completion zsh) in ~/.zshrc.`);
|
|
3840
|
+
}
|
|
3841
|
+
process.stdout.write(scriptFor(second));
|
|
3842
|
+
return true;
|
|
3843
|
+
}
|
|
3844
|
+
return false;
|
|
3845
|
+
}
|
|
3447
3846
|
async function main() {
|
|
3847
|
+
if (await completionAsked(process.argv.slice(2))) {
|
|
3848
|
+
return;
|
|
3849
|
+
}
|
|
3448
3850
|
if (await helpAsked(process.argv.slice(2))) {
|
|
3449
3851
|
return;
|
|
3450
3852
|
}
|
|
@@ -3859,17 +4261,17 @@ async function sshKeys(id, keyId, remove3, json) {
|
|
|
3859
4261
|
if (!id) {
|
|
3860
4262
|
throw new Error("ssh-keys requires <sandbox-id>");
|
|
3861
4263
|
}
|
|
3862
|
-
const
|
|
4264
|
+
const path5 = `/v1/sandboxes/${encodeURIComponent(id)}/ssh/keys`;
|
|
3863
4265
|
if (remove3) {
|
|
3864
4266
|
if (!keyId) {
|
|
3865
4267
|
throw new Error("ssh-keys --remove requires <key-id>, as ssh-keys lists it");
|
|
3866
4268
|
}
|
|
3867
|
-
await call2(`${
|
|
4269
|
+
await call2(`${path5}/${encodeURIComponent(keyId)}`, { method: "DELETE" });
|
|
3868
4270
|
process.stdout.write(`${keyId} may log in to ${id} no longer.
|
|
3869
4271
|
`);
|
|
3870
4272
|
return;
|
|
3871
4273
|
}
|
|
3872
|
-
const body = await call2(
|
|
4274
|
+
const body = await call2(path5, { method: "GET" });
|
|
3873
4275
|
const keys = body?.keys ?? [];
|
|
3874
4276
|
if (json) {
|
|
3875
4277
|
process.stdout.write(`${JSON.stringify(keys, null, 2)}
|
|
@@ -3883,10 +4285,10 @@ function publicKeysFrom(given) {
|
|
|
3883
4285
|
if (SSH_PUBLIC_KEY.test(each.trim())) {
|
|
3884
4286
|
return [each.trim()];
|
|
3885
4287
|
}
|
|
3886
|
-
const file = each.startsWith("~/") ? `${
|
|
4288
|
+
const file = each.startsWith("~/") ? `${os6.homedir()}${each.slice(1)}` : each;
|
|
3887
4289
|
let text;
|
|
3888
4290
|
try {
|
|
3889
|
-
text =
|
|
4291
|
+
text = readFileSync4(file, "utf8");
|
|
3890
4292
|
} catch {
|
|
3891
4293
|
throw new Error(`${each} is neither a public key nor a file that can be read. Give a key line, as ssh-ed25519 AAAA... you@laptop, or its file, as ~/.ssh/id_ed25519.pub.`);
|
|
3892
4294
|
}
|
|
@@ -3938,7 +4340,7 @@ async function regions(asJson) {
|
|
|
3938
4340
|
process.stdout.write("* where a sandbox is made when no region is named\n");
|
|
3939
4341
|
}
|
|
3940
4342
|
async function list2(asJson, filter, sort, limit, wide = false) {
|
|
3941
|
-
const
|
|
4343
|
+
const sandboxes2 = [];
|
|
3942
4344
|
let cursor = null;
|
|
3943
4345
|
do {
|
|
3944
4346
|
const query = new URLSearchParams(filter);
|
|
@@ -3954,7 +4356,7 @@ async function list2(asJson, filter, sort, limit, wide = false) {
|
|
|
3954
4356
|
if (!response.ok) {
|
|
3955
4357
|
fail(response.status, body);
|
|
3956
4358
|
}
|
|
3957
|
-
|
|
4359
|
+
sandboxes2.push(...readSandboxes(body));
|
|
3958
4360
|
const next = body && typeof body === "object" ? body["nextCursor"] : null;
|
|
3959
4361
|
cursor = typeof next === "string" ? next : null;
|
|
3960
4362
|
if (limit !== void 0 && cursor !== null) {
|
|
@@ -3964,24 +4366,24 @@ async function list2(asJson, filter, sort, limit, wide = false) {
|
|
|
3964
4366
|
}
|
|
3965
4367
|
} while (cursor !== null);
|
|
3966
4368
|
if (asJson) {
|
|
3967
|
-
process.stdout.write(`${JSON.stringify(
|
|
4369
|
+
process.stdout.write(`${JSON.stringify(sandboxes2, null, 2)}
|
|
3968
4370
|
`);
|
|
3969
4371
|
return;
|
|
3970
4372
|
}
|
|
3971
|
-
if (
|
|
4373
|
+
if (sandboxes2.length === 0) {
|
|
3972
4374
|
process.stdout.write(filter.size > 0 ? "No sandboxes match.\n" : "No sandboxes.\n");
|
|
3973
4375
|
return;
|
|
3974
4376
|
}
|
|
3975
|
-
const names =
|
|
4377
|
+
const names = sandboxes2.some((sandbox) => typeof sandbox["templateId"] === "string") ? await templateNames() : /* @__PURE__ */ new Map();
|
|
3976
4378
|
if (isTerminal(process.stdout) && !wide) {
|
|
3977
|
-
process.stdout.write(sandboxesForPeople(
|
|
4379
|
+
process.stdout.write(sandboxesForPeople(sandboxes2, names, sort !== void 0));
|
|
3978
4380
|
return;
|
|
3979
4381
|
}
|
|
3980
|
-
const tagged =
|
|
4382
|
+
const tagged = sandboxes2.some((sandbox) => Array.isArray(sandbox["tags"]));
|
|
3981
4383
|
const header = [...["ID", "NAME", "SIZE", "STATUS"].map(pad2), "VM ", pad2("TEMPLATE"), tagged ? pad2("OUTBOUND") : "OUTBOUND", ...tagged ? ["TAGS"] : []].join(" ");
|
|
3982
4384
|
process.stdout.write(`${header}
|
|
3983
4385
|
`);
|
|
3984
|
-
for (const sandbox of
|
|
4386
|
+
for (const sandbox of sandboxes2) {
|
|
3985
4387
|
const rule = sandbox["network"];
|
|
3986
4388
|
const templateId = typeof sandbox["templateId"] === "string" ? sandbox["templateId"] : null;
|
|
3987
4389
|
const row = [
|
|
@@ -4128,11 +4530,11 @@ async function bulk(action, filter, options, yes2, asJson, confirm) {
|
|
|
4128
4530
|
}
|
|
4129
4531
|
async function jobs(positionals, asJson) {
|
|
4130
4532
|
const [verb, id] = positionals;
|
|
4131
|
-
const
|
|
4132
|
-
if (
|
|
4533
|
+
const path5 = verb === void 0 || verb === "list" ? "/v1/sandbox-jobs" : verb === "show" && id ? `/v1/sandbox-jobs/${encodeURIComponent(id)}` : verb === "cancel" && id ? `/v1/sandbox-jobs/${encodeURIComponent(id)}/cancel` : null;
|
|
4534
|
+
if (path5 === null) {
|
|
4133
4535
|
throw new Error("jobs takes list, show <job-id> or cancel <job-id>");
|
|
4134
4536
|
}
|
|
4135
|
-
const response = await request(
|
|
4537
|
+
const response = await request(path5, { method: verb === "cancel" ? "POST" : "GET" });
|
|
4136
4538
|
const body = await readBody(response);
|
|
4137
4539
|
if (!response.ok) {
|
|
4138
4540
|
fail(response.status, body);
|
|
@@ -4359,18 +4761,18 @@ async function autoStop(id, inText, at4, never, asJson) {
|
|
|
4359
4761
|
if ([inText !== void 0, at4 !== void 0, never].filter(Boolean).length > 1) {
|
|
4360
4762
|
throw new Error("--in, --at and --never say different things: give one.");
|
|
4361
4763
|
}
|
|
4362
|
-
const
|
|
4764
|
+
const path5 = `/v1/sandboxes/${encodeURIComponent(id)}/auto-stop`;
|
|
4363
4765
|
let body;
|
|
4364
4766
|
if (never) {
|
|
4365
|
-
body = await call2(
|
|
4767
|
+
body = await call2(path5, { method: "DELETE" });
|
|
4366
4768
|
} else if (inText === void 0 && at4 === void 0) {
|
|
4367
|
-
body = await call2(
|
|
4769
|
+
body = await call2(path5, { method: "GET" });
|
|
4368
4770
|
} else {
|
|
4369
4771
|
const inSeconds = inText === void 0 ? void 0 : seconds(inText);
|
|
4370
4772
|
if (inSeconds === null) {
|
|
4371
4773
|
throw new Error("--in is a time from now, such as 30m, 2h or 1d");
|
|
4372
4774
|
}
|
|
4373
|
-
body = await call2(
|
|
4775
|
+
body = await call2(path5, { method: "PUT", body: JSON.stringify(inSeconds === void 0 ? { at: at4 } : { inSeconds }) });
|
|
4374
4776
|
}
|
|
4375
4777
|
if (asJson) {
|
|
4376
4778
|
process.stdout.write(`${JSON.stringify(body, null, 2)}
|
|
@@ -4426,7 +4828,7 @@ async function screenshot(id, file, options) {
|
|
|
4426
4828
|
fail(response.status, await readBody(response));
|
|
4427
4829
|
}
|
|
4428
4830
|
const picture = Buffer.from(await response.arrayBuffer());
|
|
4429
|
-
|
|
4831
|
+
writeFileSync4(file, picture);
|
|
4430
4832
|
const size = pictureSize(picture);
|
|
4431
4833
|
process.stderr.write(`A picture of the screen of ${id} is in ${file}: ${size ? `${size.width} by ${size.height}, ` : ""}${picture.length} bytes.
|
|
4432
4834
|
`);
|
|
@@ -4461,7 +4863,7 @@ async function clipboard(id, text) {
|
|
|
4461
4863
|
process.stdout.write(String(body.text ?? ""));
|
|
4462
4864
|
return;
|
|
4463
4865
|
}
|
|
4464
|
-
const given = text === "-" ?
|
|
4866
|
+
const given = text === "-" ? readFileSync4(0, "utf8") : text;
|
|
4465
4867
|
const response = await request(at4, { method: "PUT", body: JSON.stringify({ text: given }) });
|
|
4466
4868
|
if (!response.ok) {
|
|
4467
4869
|
fail(response.status, await readBody(response));
|
|
@@ -4609,10 +5011,10 @@ async function labels(what, holder, positionals, asJson) {
|
|
|
4609
5011
|
throw new Error(`${command2} requires <${holder}>: ${usage}`);
|
|
4610
5012
|
}
|
|
4611
5013
|
const id = holder === "template" ? (await templateNamed(named)).id : named;
|
|
4612
|
-
const
|
|
5014
|
+
const path5 = `/v1/${holder === "template" ? "templates" : "sandboxes"}/${encodeURIComponent(id)}`;
|
|
4613
5015
|
let body;
|
|
4614
5016
|
if (action === void 0) {
|
|
4615
|
-
body = await call2(
|
|
5017
|
+
body = await call2(path5, { method: "GET" });
|
|
4616
5018
|
} else if (what === "tags" && (action === "add" || action === "rm")) {
|
|
4617
5019
|
const tags = listedIn(words2).map((tag) => tag.toLowerCase());
|
|
4618
5020
|
if (tags.length === 0) {
|
|
@@ -4623,14 +5025,14 @@ async function labels(what, holder, positionals, asJson) {
|
|
|
4623
5025
|
throw new Error(`A tag is lowercase letters, digits and hyphens, 1 to 63 characters, not starting or ending with a hyphen, not ${JSON.stringify(bad2)}.`);
|
|
4624
5026
|
}
|
|
4625
5027
|
for (const tag of tags) {
|
|
4626
|
-
body = await call2(`${
|
|
5028
|
+
body = await call2(`${path5}/tags/${encodeURIComponent(tag)}`, { method: action === "add" ? "PUT" : "DELETE" });
|
|
4627
5029
|
}
|
|
4628
5030
|
} else if (what === "meta" && (action === "set" || action === "unset")) {
|
|
4629
5031
|
if (words2.length === 0) {
|
|
4630
5032
|
throw new Error(`${command2} ${action} requires ${action === "set" ? "<key>=<value>" : "<key>"}...`);
|
|
4631
5033
|
}
|
|
4632
5034
|
const metadata = action === "set" ? metadataGiven(words2) : Object.fromEntries(words2.map((key2) => [key2, null]));
|
|
4633
|
-
body = await call2(
|
|
5035
|
+
body = await call2(path5, { method: "PATCH", body: JSON.stringify({ metadata }) });
|
|
4634
5036
|
} else {
|
|
4635
5037
|
throw new Error(`${command2} takes ${usage}`);
|
|
4636
5038
|
}
|
|
@@ -4657,9 +5059,9 @@ async function network(positionals, values) {
|
|
|
4657
5059
|
if (values.allow !== void 0 && values.none) {
|
|
4658
5060
|
throw new Error("--allow and --none say two things: give one.");
|
|
4659
5061
|
}
|
|
4660
|
-
const
|
|
5062
|
+
const path5 = `/v1/sandboxes/${encodeURIComponent(id)}/network`;
|
|
4661
5063
|
const allow = values.none ? [] : values.allow === void 0 ? void 0 : listedIn(values.allow);
|
|
4662
|
-
const body = await call2(
|
|
5064
|
+
const body = await call2(path5, allow === void 0 ? { method: "GET" } : { method: "PUT", body: JSON.stringify({ allow }) });
|
|
4663
5065
|
if (values.json) {
|
|
4664
5066
|
process.stdout.write(`${JSON.stringify(body, null, 2)}
|
|
4665
5067
|
`);
|
|
@@ -4735,9 +5137,9 @@ async function egress(positionals, values) {
|
|
|
4735
5137
|
`);
|
|
4736
5138
|
return;
|
|
4737
5139
|
}
|
|
4738
|
-
const
|
|
5140
|
+
const path5 = `/v1/sandboxes/${encodeURIComponent(first)}/egress`;
|
|
4739
5141
|
const how = `egress takes <sandbox-id>, and then nothing, box, or residential <country> [sticky|rotating], as agental egress ${first} residential de.`;
|
|
4740
|
-
const body = await call2(
|
|
5142
|
+
const body = await call2(path5, rest.length === 0 ? { method: "GET" } : { method: "PUT", body: JSON.stringify(egressFrom(rest, how)) });
|
|
4741
5143
|
print4(body, `${first}: ${egressInWords(body)}
|
|
4742
5144
|
`);
|
|
4743
5145
|
}
|
|
@@ -4875,7 +5277,7 @@ async function template(positionals, values) {
|
|
|
4875
5277
|
}
|
|
4876
5278
|
case "start": {
|
|
4877
5279
|
const found = await templateNamed(need(first, "<template>"));
|
|
4878
|
-
const
|
|
5280
|
+
const path5 = `/v1/templates/${encodeURIComponent(found.id)}/start`;
|
|
4879
5281
|
if (values.snapshot !== void 0 && values["new-machine"]) {
|
|
4880
5282
|
throw new Error("--snapshot and --new-machine say two things: give one.");
|
|
4881
5283
|
}
|
|
@@ -4885,12 +5287,12 @@ async function template(positionals, values) {
|
|
|
4885
5287
|
const ttlSeconds = ttlOption(values.ttl);
|
|
4886
5288
|
let start;
|
|
4887
5289
|
if (values.size === void 0 && values.snapshot === void 0 && !values["new-machine"] && ttlSeconds === void 0) {
|
|
4888
|
-
start = await call2(
|
|
5290
|
+
start = await call2(path5, { method: "GET" });
|
|
4889
5291
|
} else {
|
|
4890
|
-
const current = await call2(
|
|
5292
|
+
const current = await call2(path5, { method: "GET" });
|
|
4891
5293
|
const snapshotId = values["new-machine"] ? null : values.snapshot ?? current?.snapshotId ?? null;
|
|
4892
5294
|
const ttl = ttlSeconds === void 0 ? current?.ttlSeconds ?? null : ttlSeconds;
|
|
4893
|
-
start = await call2(
|
|
5295
|
+
start = await call2(path5, { method: "PUT", body: JSON.stringify({ size: values.size ?? current?.size, snapshotId, ttlSeconds: ttl }) });
|
|
4894
5296
|
}
|
|
4895
5297
|
print4(start, `start: ${startInWords(start)}
|
|
4896
5298
|
`);
|
|
@@ -4898,11 +5300,11 @@ async function template(positionals, values) {
|
|
|
4898
5300
|
}
|
|
4899
5301
|
case "network": {
|
|
4900
5302
|
const found = await templateNamed(need(first, "<template>"));
|
|
4901
|
-
const
|
|
5303
|
+
const path5 = `/v1/templates/${encodeURIComponent(found.id)}/network`;
|
|
4902
5304
|
const [mode, ...addresses] = rest;
|
|
4903
5305
|
let rule;
|
|
4904
5306
|
if (mode === void 0) {
|
|
4905
|
-
rule = await call2(
|
|
5307
|
+
rule = await call2(path5, { method: "GET" });
|
|
4906
5308
|
} else {
|
|
4907
5309
|
if (!OUTBOUND_MODES.some((known) => known === mode)) {
|
|
4908
5310
|
throw new Error("template network requires <template>, and then nothing, open, blocked, or allowlist <address>...");
|
|
@@ -4914,7 +5316,7 @@ async function template(positionals, values) {
|
|
|
4914
5316
|
if (mode === "allowlist" && listed.length === 0) {
|
|
4915
5317
|
throw new Error(`allowlist needs at least one address, as agental template network ${first ?? ""} allowlist 203.0.113.7 198.51.100.0/24`);
|
|
4916
5318
|
}
|
|
4917
|
-
rule = await call2(
|
|
5319
|
+
rule = await call2(path5, { method: "PUT", body: JSON.stringify(mode === "allowlist" ? { outbound: mode, allow: listed } : { outbound: mode }) });
|
|
4918
5320
|
}
|
|
4919
5321
|
print4(
|
|
4920
5322
|
rule,
|
|
@@ -4925,37 +5327,37 @@ ${mode === void 0 ? "" : "A sandbox on it takes this when it next starts, or now
|
|
|
4925
5327
|
}
|
|
4926
5328
|
case "egress": {
|
|
4927
5329
|
const found = await templateNamed(need(first, "<template>"));
|
|
4928
|
-
const
|
|
5330
|
+
const path5 = `/v1/templates/${encodeURIComponent(found.id)}/egress`;
|
|
4929
5331
|
const how = `template egress takes <template>, and then nothing, box, or residential <country> [sticky|rotating], as agental template egress ${first ?? ""} residential de.`;
|
|
4930
|
-
const set = await call2(
|
|
5332
|
+
const set = await call2(path5, rest.length === 0 ? { method: "GET" } : { method: "PUT", body: JSON.stringify(egressFrom(rest, how)) });
|
|
4931
5333
|
print4(set, `${found.name}: ${egressInWords(set)}${rest.length === 0 ? "" : ", for sandboxes made from it from now on"}
|
|
4932
5334
|
`);
|
|
4933
5335
|
return;
|
|
4934
5336
|
}
|
|
4935
5337
|
case "ssh": {
|
|
4936
5338
|
const found = await templateNamed(need(first, "<template>"));
|
|
4937
|
-
const
|
|
5339
|
+
const path5 = `/v1/templates/${encodeURIComponent(found.id)}/ssh`;
|
|
4938
5340
|
const [turn] = rest;
|
|
4939
5341
|
if (turn !== void 0 && turn !== "on" && turn !== "off") {
|
|
4940
5342
|
throw new Error("template ssh requires <template>, and then nothing, on or off");
|
|
4941
5343
|
}
|
|
4942
|
-
const ssh2 = await call2(
|
|
5344
|
+
const ssh2 = await call2(path5, { method: turn === "on" ? "PUT" : turn === "off" ? "DELETE" : "GET" });
|
|
4943
5345
|
print4(ssh2, `${found.name}: SSH ${templateSshInWords(ssh2)}
|
|
4944
5346
|
`);
|
|
4945
5347
|
return;
|
|
4946
5348
|
}
|
|
4947
5349
|
case "ssh-keys": {
|
|
4948
5350
|
const found = await templateNamed(need(first, "<template>"));
|
|
4949
|
-
const
|
|
5351
|
+
const path5 = `/v1/templates/${encodeURIComponent(found.id)}/ssh/keys`;
|
|
4950
5352
|
if (values.remove) {
|
|
4951
5353
|
const keyId = need(rest[0], "<template> --remove <key-id>");
|
|
4952
|
-
await call2(`${
|
|
5354
|
+
await call2(`${path5}/${encodeURIComponent(keyId)}`, { method: "DELETE" });
|
|
4953
5355
|
process.stdout.write(`${keyId} is let in to no sandbox made from ${found.name} from now on. The sandboxes made already keep it.
|
|
4954
5356
|
`);
|
|
4955
5357
|
return;
|
|
4956
5358
|
}
|
|
4957
5359
|
for (const publicKey2 of publicKeysFrom(rest)) {
|
|
4958
|
-
await call2(
|
|
5360
|
+
await call2(path5, { method: "POST", body: JSON.stringify({ publicKey: publicKey2 }) });
|
|
4959
5361
|
}
|
|
4960
5362
|
const ssh2 = await call2(`/v1/templates/${encodeURIComponent(found.id)}/ssh`, { method: "GET" });
|
|
4961
5363
|
if (values.json) {
|
|
@@ -5017,8 +5419,8 @@ up to date: ${body["upToDate"] === true ? "yes" : "no: it takes the template whe
|
|
|
5017
5419
|
function keptOutInWords(variable) {
|
|
5018
5420
|
return [`${variable.name} is kept out of the sandbox, and its value is never given back.`, `stand-in: ${variable.standIn}`, `hosts: ${variable.hosts.join(", ")}`, ""].join("\n");
|
|
5019
5421
|
}
|
|
5020
|
-
async function keptOutNow(
|
|
5021
|
-
const response = await request(
|
|
5422
|
+
async function keptOutNow(path5) {
|
|
5423
|
+
const response = await request(path5, { method: "GET" });
|
|
5022
5424
|
const body = await readBody(response);
|
|
5023
5425
|
if (response.status === 404) {
|
|
5024
5426
|
return false;
|
|
@@ -5043,11 +5445,11 @@ async function secrets(positionals, values) {
|
|
|
5043
5445
|
base = `/v1/sandboxes/${encodeURIComponent(sandboxId)}/secrets`;
|
|
5044
5446
|
}
|
|
5045
5447
|
const [action, ...args] = words2;
|
|
5046
|
-
const fileQuery = (
|
|
5047
|
-
if (!
|
|
5448
|
+
const fileQuery = (path5) => {
|
|
5449
|
+
if (!path5) {
|
|
5048
5450
|
throw new Error(`secrets ${action ?? ""} requires <path>`);
|
|
5049
5451
|
}
|
|
5050
|
-
return `${base}/files?path=${encodeURIComponent(
|
|
5452
|
+
return `${base}/files?path=${encodeURIComponent(path5)}`;
|
|
5051
5453
|
};
|
|
5052
5454
|
switch (action) {
|
|
5053
5455
|
case void 0: {
|
|
@@ -5066,7 +5468,7 @@ async function secrets(positionals, values) {
|
|
|
5066
5468
|
}
|
|
5067
5469
|
process.stdout.write(
|
|
5068
5470
|
[...names.map((name) => `variable ${name}${hidden2.includes(name) ? " kept out of the sandbox" : ""}
|
|
5069
|
-
`), ...paths.map((
|
|
5471
|
+
`), ...paths.map((path5) => `file ${path5}
|
|
5070
5472
|
`)].join("")
|
|
5071
5473
|
);
|
|
5072
5474
|
return;
|
|
@@ -5104,11 +5506,11 @@ async function secrets(positionals, values) {
|
|
|
5104
5506
|
}
|
|
5105
5507
|
return [arg.slice(0, at4), arg.slice(at4 + 1)];
|
|
5106
5508
|
});
|
|
5107
|
-
const
|
|
5509
|
+
const path5 = (name) => `${base}/variables/${encodeURIComponent(name)}`;
|
|
5108
5510
|
if (hosts === void 0 && !values.plain) {
|
|
5109
5511
|
const byTemplate = sandboxId === void 0 ? [] : (await call2(`/v1/sandboxes/${encodeURIComponent(sandboxId)}/template`, { method: "GET" }))?.hidden ?? [];
|
|
5110
5512
|
for (const [name] of pairs) {
|
|
5111
|
-
if (await keptOutNow(
|
|
5513
|
+
if (await keptOutNow(path5(name))) {
|
|
5112
5514
|
throw new Error(
|
|
5113
5515
|
`${name} is kept out of the sandbox. Set without --host it would be plain, and its commands would read its value. Give its hosts again with --host to keep it out, or --plain for its commands to read it. Nothing was set.`
|
|
5114
5516
|
);
|
|
@@ -5121,7 +5523,7 @@ async function secrets(positionals, values) {
|
|
|
5121
5523
|
}
|
|
5122
5524
|
}
|
|
5123
5525
|
for (const [name, value] of pairs) {
|
|
5124
|
-
const body = await call2(
|
|
5526
|
+
const body = await call2(path5(name), { method: "PUT", body: JSON.stringify(hosts === void 0 ? { value } : { value, hosts }) });
|
|
5125
5527
|
process.stdout.write(
|
|
5126
5528
|
body.hidden === true ? `set ${name}, kept out of the sandbox: its commands see ${body.standIn}, and its value is sent only to ${body.hosts.join(", ")}
|
|
5127
5529
|
` : `set ${name}
|
|
@@ -5163,12 +5565,12 @@ async function secrets(positionals, values) {
|
|
|
5163
5565
|
return;
|
|
5164
5566
|
}
|
|
5165
5567
|
case "put-file": {
|
|
5166
|
-
const [
|
|
5167
|
-
if (!
|
|
5568
|
+
const [path5, local] = args;
|
|
5569
|
+
if (!path5 || local === void 0 === (values.text === void 0)) {
|
|
5168
5570
|
throw new Error("secrets put-file requires <path>, and then a local file to read it from or --text with what it holds");
|
|
5169
5571
|
}
|
|
5170
5572
|
const text = values.text ?? await readFile(local ?? "", "utf8");
|
|
5171
|
-
const body = await call2(`${base}/files`, { method: "PUT", body: JSON.stringify({ path:
|
|
5573
|
+
const body = await call2(`${base}/files`, { method: "PUT", body: JSON.stringify({ path: path5, text }) });
|
|
5172
5574
|
process.stdout.write(`put ${body.path}
|
|
5173
5575
|
`);
|
|
5174
5576
|
return;
|
|
@@ -5203,9 +5605,9 @@ async function metrics(id, asked2) {
|
|
|
5203
5605
|
query.set(name, value);
|
|
5204
5606
|
}
|
|
5205
5607
|
}
|
|
5206
|
-
const
|
|
5608
|
+
const path5 = asked2.running ? "/v1/metrics/running" : id === void 0 ? "/v1/metrics" : `/v1/sandboxes/${encodeURIComponent(id)}/metrics`;
|
|
5207
5609
|
const search = query.toString();
|
|
5208
|
-
const response = await request(search === "" ?
|
|
5610
|
+
const response = await request(search === "" ? path5 : `${path5}?${search}`, { method: "GET" });
|
|
5209
5611
|
const body = await readBody(response);
|
|
5210
5612
|
if (!response.ok) {
|
|
5211
5613
|
fail(response.status, body);
|
|
@@ -5228,11 +5630,11 @@ async function metrics(id, asked2) {
|
|
|
5228
5630
|
` : table3([["AT", ...FIGURE_HEADINGS], ...points.map((point) => [String(point["at"] ?? ""), ...figuresOf(point)])])
|
|
5229
5631
|
);
|
|
5230
5632
|
} else {
|
|
5231
|
-
const
|
|
5633
|
+
const sandboxes2 = readList(body, "sandboxes");
|
|
5232
5634
|
process.stdout.write(
|
|
5233
|
-
|
|
5635
|
+
sandboxes2.length === 0 ? "No sandboxes.\n" : table3([
|
|
5234
5636
|
["ID", "NAME", "SIZE", ...FIGURE_HEADINGS],
|
|
5235
|
-
...
|
|
5637
|
+
...sandboxes2.map((sandbox) => [String(sandbox["sandboxId"] ?? ""), String(sandbox["name"] ?? ""), String(sandbox["size"] ?? ""), ...figuresOf(sandbox["reading"])])
|
|
5236
5638
|
])
|
|
5237
5639
|
);
|
|
5238
5640
|
}
|
|
@@ -5254,7 +5656,7 @@ async function account2(positionals, out) {
|
|
|
5254
5656
|
process.stdout.write(text);
|
|
5255
5657
|
return;
|
|
5256
5658
|
}
|
|
5257
|
-
|
|
5659
|
+
writeFileSync4(out, text, { mode: 384 });
|
|
5258
5660
|
process.stdout.write(`Written to ${out}.
|
|
5259
5661
|
`);
|
|
5260
5662
|
}
|
|
@@ -5333,9 +5735,9 @@ async function ci(positionals, options) {
|
|
|
5333
5735
|
if (repo === void 0 || !/^[^/\s]+\/[^/\s]+$/.test(repo)) {
|
|
5334
5736
|
throw new Error(`ci ${what} needs the repository, as agental ci ${what} acme/app`);
|
|
5335
5737
|
}
|
|
5336
|
-
const
|
|
5738
|
+
const path5 = `/v1/runs-on/repositories/${repo.split("/").map(encodeURIComponent).join("/")}`;
|
|
5337
5739
|
if (what === "reset") {
|
|
5338
|
-
const response = await request(
|
|
5740
|
+
const response = await request(path5, { method: "DELETE" });
|
|
5339
5741
|
if (!response.ok) {
|
|
5340
5742
|
fail(response.status, await readBody(response));
|
|
5341
5743
|
}
|
|
@@ -5357,7 +5759,7 @@ async function ci(positionals, options) {
|
|
|
5357
5759
|
if (options.template !== void 0) {
|
|
5358
5760
|
templateId = options.template === "default" ? null : (await templateNamed(options.template)).id;
|
|
5359
5761
|
}
|
|
5360
|
-
const saved = await asked(
|
|
5762
|
+
const saved = await asked(path5, { method: "PUT", body: JSON.stringify({ poolMax, templateId }) });
|
|
5361
5763
|
if (options.json) {
|
|
5362
5764
|
process.stdout.write(`${JSON.stringify(saved, null, 2)}
|
|
5363
5765
|
`);
|
|
@@ -5921,8 +6323,8 @@ function duration(ms) {
|
|
|
5921
6323
|
const minutes = Math.round(ms / 6e4);
|
|
5922
6324
|
return minutes < 60 ? `${minutes} min` : `${Math.floor(minutes / 60)} h${minutes % 60 === 0 ? "" : ` ${minutes % 60} min`}`;
|
|
5923
6325
|
}
|
|
5924
|
-
async function asked(
|
|
5925
|
-
const response = await request(
|
|
6326
|
+
async function asked(path5, init) {
|
|
6327
|
+
const response = await request(path5, init);
|
|
5926
6328
|
const body = await readBody(response);
|
|
5927
6329
|
if (!response.ok) {
|
|
5928
6330
|
fail(response.status, body);
|
|
@@ -6001,10 +6403,10 @@ function table3(rows) {
|
|
|
6001
6403
|
`).join("");
|
|
6002
6404
|
}
|
|
6003
6405
|
var ACTIVE = /* @__PURE__ */ new Set(["running", "starting", "stopping", "restoring", "creating"]);
|
|
6004
|
-
function sandboxesForPeople(
|
|
6406
|
+
function sandboxesForPeople(sandboxes2, names, sorted) {
|
|
6005
6407
|
const text = (value) => typeof value === "string" ? value : "";
|
|
6006
6408
|
const changed = (sandbox) => Date.parse(text(sandbox["stoppedAt"]) || text(sandbox["updatedAt"]) || text(sandbox["createdAt"])) || 0;
|
|
6007
|
-
const shown = sorted ?
|
|
6409
|
+
const shown = sorted ? sandboxes2 : [...sandboxes2].sort((a, b) => Number(ACTIVE.has(text(b["status"]))) - Number(ACTIVE.has(text(a["status"]))) || changed(b) - changed(a));
|
|
6008
6410
|
const outbound = (sandbox) => {
|
|
6009
6411
|
const rule = sandbox["network"];
|
|
6010
6412
|
return rule && typeof rule === "object" ? text(rule["outbound"]) : "";
|
|
@@ -6164,6 +6566,7 @@ Setting up
|
|
|
6164
6566
|
agental logout
|
|
6165
6567
|
agental whoami [--json]
|
|
6166
6568
|
agental --version
|
|
6569
|
+
agental completion zsh|bash|fish
|
|
6167
6570
|
|
|
6168
6571
|
Usage
|
|
6169
6572
|
agental create --name <name> [--template <template>] [--size tiny|small|medium|large] [--region <region>[,<region>...]] [--ttl <time> | --ttl default] [--idempotency-key <key>]
|
|
@@ -6286,6 +6689,9 @@ in a terminal it offers to open your newest running sandbox instead, and otherwi
|
|
|
6286
6689
|
login signs in through the browser: the page asks you to allow this computer, and the command is
|
|
6287
6690
|
given an API key of its own, named CLI on <this computer>, which is in the console under API keys.
|
|
6288
6691
|
--key reads a key from standard input instead, for a computer with no browser.
|
|
6692
|
+
completion prints a script that completes agental's commands, flags, sandboxes and templates
|
|
6693
|
+
when Tab is pressed: source <(agental completion zsh) in ~/.zshrc, source <(agental completion
|
|
6694
|
+
bash) in ~/.bashrc, or agental completion fish | source in ~/.config/fish/config.fish.
|
|
6289
6695
|
The key is kept in ~/.config/agental/credentials.json, readable by you alone. logout deletes the
|
|
6290
6696
|
key from your account and that file. whoami says who the command is signed in as, and with which
|
|
6291
6697
|
key. AGENTAL_API_KEY, when it is set, is used in place of what is kept.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agental",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
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",
|