agental 0.10.0 → 0.13.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.
Files changed (2) hide show
  1. package/dist/cli.js +753 -77
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -46,7 +46,7 @@ import { parseArgs } from "node:util";
46
46
 
47
47
  // ../src/cli-build.ts
48
48
  var PUBLISHED = true;
49
- var CLI_VERSION = true ? "0.10.0" : "dev";
49
+ var CLI_VERSION = true ? "0.13.0" : "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}`;
@@ -118,7 +118,7 @@ function resolveApi(fallbackUrl, fallbackKey, env = process.env) {
118
118
  }
119
119
 
120
120
  // ../src/cli-email.ts
121
- var USAGE = "email requires <sandbox-id>, or one of on, off, list, read, delete, send and account. agental help shows each.";
121
+ var USAGE = "email requires <sandbox-id>, or one of on, off, list, read, delete, send and account. agental email --help shows each.";
122
122
  async function readObject(response) {
123
123
  try {
124
124
  const body = await response.json();
@@ -174,9 +174,9 @@ function printState(state2, asJson) {
174
174
  `domain: ${typeof state2["domain"] === "string" ? state2["domain"] : "none. No mail is offered here: GET /v1/policy says so as email."}`
175
175
  ]);
176
176
  }
177
- async function state(client, method, sandboxId, command, options) {
177
+ async function state(client, method, sandboxId, command2, options) {
178
178
  if (!sandboxId) {
179
- throw new Error(`${command} requires <sandbox-id>`);
179
+ throw new Error(`${command2} requires <sandbox-id>`);
180
180
  }
181
181
  printState((await ask(client, method, mailOf(sandboxId))).body, options.json);
182
182
  }
@@ -325,7 +325,7 @@ async function email(client, positionals, options) {
325
325
  }
326
326
  const takes = (count) => {
327
327
  if (positionals.length > count) {
328
- throw new Error(`email ${first} was given more than it takes: ${positionals.slice(count).join(" ")}. agental help shows what it takes.`);
328
+ throw new Error(`email ${first} was given more than it takes: ${positionals.slice(count).join(" ")}. agental email --help shows what it takes.`);
329
329
  }
330
330
  };
331
331
  switch (first) {
@@ -424,7 +424,7 @@ var PRESETS = {
424
424
  var PRESET_NAMES = Object.keys(PRESETS);
425
425
 
426
426
  // ../src/cli-keys.ts
427
- var USAGE2 = "key takes add, show, allow-from or delete. agental help shows each.";
427
+ var USAGE2 = "key takes add, show, allow-from or delete. agental key --help shows each.";
428
428
  var HOUR_MS = 36e5;
429
429
  var SHOWN_ONCE = "is shown this once: only its hash is kept. Use it as AGENTAL_API_KEY, or as the Bearer token of each request.";
430
430
  async function ask2(client, method, pathname, body) {
@@ -550,9 +550,9 @@ function grantFrom(options) {
550
550
  }
551
551
  function expiryFrom(given, now = Date.now()) {
552
552
  const text = given.trim();
553
- const span = /^(\d+)([dh])$/.exec(text);
554
- if (span && Number(span[1]) > 0) {
555
- return at(now + Number(span[1]) * (span[2] === "d" ? 24 : 1) * HOUR_MS);
553
+ const span2 = /^(\d+)([dh])$/.exec(text);
554
+ if (span2 && Number(span2[1]) > 0) {
555
+ return at(now + Number(span2[1]) * (span2[2] === "d" ? 24 : 1) * HOUR_MS);
556
556
  }
557
557
  const moment = /^\d{4}-\d{2}-\d{2}/.test(text) ? Date.parse(text) : Number.NaN;
558
558
  if (Number.isNaN(moment)) {
@@ -1072,7 +1072,7 @@ function accessIn(record) {
1072
1072
  return typeof user === "string" && typeof hostKey === "string" && typeof host === "string" && typeof port === "number" ? { user, hostKey, host, port } : null;
1073
1073
  }
1074
1074
  async function reach(client, sandboxId, waitMs = 0) {
1075
- const until = Date.now() + waitMs;
1075
+ const until2 = Date.now() + waitMs;
1076
1076
  for (; ; ) {
1077
1077
  try {
1078
1078
  const access = accessIn(await ask3(client, "GET", sandboxId, "")) ?? accessIn(await ask3(client, "PUT", sandboxId, ""));
@@ -1082,7 +1082,7 @@ async function reach(client, sandboxId, waitMs = 0) {
1082
1082
  }
1083
1083
  throw new Refused2("ssh_unavailable", "SSH was turned on, and the API gave no address to connect to.");
1084
1084
  } catch (error) {
1085
- if (!(error instanceof Refused2) || !ON_ITS_WAY.has(error.code) || Date.now() + LOOK_AGAIN_EVERY_MS > until) {
1085
+ if (!(error instanceof Refused2) || !ON_ITS_WAY.has(error.code) || Date.now() + LOOK_AGAIN_EVERY_MS > until2) {
1086
1086
  throw error;
1087
1087
  }
1088
1088
  await new Promise((resolve) => setTimeout(resolve, LOOK_AGAIN_EVERY_MS));
@@ -1454,8 +1454,8 @@ async function saveCard(base, key2, term, message) {
1454
1454
  openBrowser(page);
1455
1455
  term.say(` ${dim("If it did not open:")} ${page}`);
1456
1456
  term.say(` ${dim("waiting for your card to be saved\u2026 (Ctrl-C to stop)")}`);
1457
- const until = Date.now() + CARD_MS;
1458
- while (Date.now() < until) {
1457
+ const until2 = Date.now() + CARD_MS;
1458
+ while (Date.now() < until2) {
1459
1459
  await sleep(CARD_LOOK_MS);
1460
1460
  const billing2 = await api(base, key2, "GET", "/v1/billing").catch(() => null);
1461
1461
  if (billing2?.status === 200 && billing2.body["needsPlan"] === false) {
@@ -1470,11 +1470,11 @@ async function saveCard(base, key2, term, message) {
1470
1470
  async function newSandbox(base, key2, term) {
1471
1471
  const name = `sh-${randomBytes3(3).toString("hex")}`;
1472
1472
  const idempotencyKey = `cli-sh-${randomUUID()}`;
1473
- const until = Date.now() + READY_MS;
1473
+ const until2 = Date.now() + READY_MS;
1474
1474
  let made;
1475
1475
  for (; ; ) {
1476
1476
  made = await api(base, key2, "POST", "/v1/sandboxes", { name }, { "Idempotency-Key": idempotencyKey });
1477
- if (made.status !== 202 || Date.now() > until) {
1477
+ if (made.status !== 202 || Date.now() > until2) {
1478
1478
  break;
1479
1479
  }
1480
1480
  await sleep(2e3);
@@ -1508,7 +1508,7 @@ async function newSandbox(base, key2, term) {
1508
1508
  const id = String(made.body["id"]);
1509
1509
  let status = String(made.body["status"]);
1510
1510
  while (status !== "running") {
1511
- if (status === "error" || Date.now() > until) {
1511
+ if (status === "error" || Date.now() > until2) {
1512
1512
  throw new Error(`${id} is ${status}, not running. agental list shows it, and agental delete ${id} removes it.`);
1513
1513
  }
1514
1514
  await sleep(2e3);
@@ -1525,11 +1525,11 @@ async function hourly(base, key2, size) {
1525
1525
  }
1526
1526
  var perHour = (micros) => `$${(micros / 1e6).toFixed(micros < 1e5 ? 4 : 3)} an hour`;
1527
1527
  function nextSteps(term, rows) {
1528
- const width = Math.max(...rows.map(([command]) => command.length));
1528
+ const width = Math.max(...rows.map(([command2]) => command2.length));
1529
1529
  term.say(`
1530
1530
  ${bold("Next")}`);
1531
- for (const [command, what] of rows) {
1532
- term.say(` ${command.padEnd(width)} ${dim(what)}`);
1531
+ for (const [command2, what] of rows) {
1532
+ term.say(` ${command2.padEnd(width)} ${dim(what)}`);
1533
1533
  }
1534
1534
  term.say("");
1535
1535
  }
@@ -1632,9 +1632,487 @@ async function onboard(base, options) {
1632
1632
  nextSteps(term, [[`agental ssh ${sandbox.id}`, "back in"], stopLine]);
1633
1633
  }
1634
1634
 
1635
+ // ../src/cli-help.ts
1636
+ function isTerminal(stream) {
1637
+ return stream.isTTY === true || process.env["AGENTAL_TERMINAL"] === "1";
1638
+ }
1639
+ function colours(stream) {
1640
+ return isTerminal(stream) && !process.env["NO_COLOR"] && process.env["TERM"] !== "dumb";
1641
+ }
1642
+ var paint = (code) => (text, stream = process.stdout) => colours(stream) ? `\x1B[${code}m${text}\x1B[0m` : text;
1643
+ var strong = paint("1");
1644
+ var faint = paint("2");
1645
+ var command = paint("36");
1646
+ var good = paint("32");
1647
+ var bad = paint("1;31");
1648
+ var COMMANDS = [
1649
+ { name: "sh", summary: "Sign in if need be, make a sandbox on your default template and open a shell in it.", examples: ["agental sh"] },
1650
+ {
1651
+ name: "create",
1652
+ summary: "Make a sandbox: a Linux machine of its own, started from a template.",
1653
+ examples: ["agental create --name review-pr-218", "agental create --name build --size medium --template ci", "agental create --name scraper --egress residential:de --ttl 2h"],
1654
+ flags: [
1655
+ ["-n, --name <name>", "what to call it (required)"],
1656
+ ["-t, --template <template>", "what it starts from (default: your default template)"],
1657
+ ["-s, --size <size>", "tiny, small, medium or large (default: the template's)"],
1658
+ [" --region <region>", "where it runs; agental regions lists them"],
1659
+ [" --ttl <time>", "stop it after this long, as 30m or 2h"],
1660
+ [" --allow <addresses>", "reach only these addresses, comma-separated"],
1661
+ [" --egress <egress>", "box, or residential:<country>[:sticky|rotating]"],
1662
+ [" --ssh-key <key or file>", "let this key in over SSH (may be given again)"],
1663
+ [" --tag <tag>", "label it (may be given again)"],
1664
+ [" --meta <key>=<value>", "attach data to it (may be given again)"],
1665
+ [" --max-burst-fee <dollars>", "the most this start may pay in burst fees"],
1666
+ [" --idempotency-key <key>", "safe to retry: the same key makes one sandbox"],
1667
+ [" --json", "print the sandbox as JSON"]
1668
+ ]
1669
+ },
1670
+ {
1671
+ name: "list",
1672
+ summary: "List your sandboxes.",
1673
+ examples: ["agental list", "agental list --tag ci", "agental list --where 'bench' --json"],
1674
+ flags: [
1675
+ ["--where '<words>'", "only the sandboxes the words find"],
1676
+ ["--tag <tag>", "only those with this tag (may be given again)"],
1677
+ ["--meta <key>=<value>", "only those with this data (may be given again)"],
1678
+ ["--sort=<sort>", "the order to list them in"],
1679
+ ["--limit <n>", "at most this many"],
1680
+ ["--json", "print them as JSON"]
1681
+ ]
1682
+ },
1683
+ { name: "summary", summary: "Count your sandboxes by status, size, template, tag or any field.", examples: ["agental summary", "agental summary --facets size,status"] },
1684
+ { name: "exec", summary: "Run a command in a sandbox and print what it prints.", examples: ["agental exec sbx_2a9a47e50daec64a -- ls -la", "agental exec sbx_2a9a47e50daec64a -- npm test"] },
1685
+ { 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
+ { name: "ssh", summary: "Open a shell in a sandbox, or run a command there, over SSH.", examples: ["agental ssh sbx_2a9a47e50daec64a", "agental ssh sbx_2a9a47e50daec64a --tmux"] },
1687
+ { name: "scp", summary: "Copy files to or from a sandbox over SSH.", examples: ["agental scp ./build.tar.gz sbx_2a9a47e50daec64a:/tmp/"] },
1688
+ { 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
+ { name: "ssh-connect", summary: "Reach a sandbox for ssh: what the Host block ssh-config prints runs. It is not typed by hand." },
1690
+ { name: "ssh-keys", summary: "List or remove the SSH keys a sandbox lets in." },
1691
+ { name: "ssh-off", summary: "Turn SSH off for a sandbox and close its port." },
1692
+ { name: "start", summary: "Start a stopped sandbox, or every one --where finds.", examples: ["agental start sbx_2a9a47e50daec64a"] },
1693
+ { name: "stop", summary: "Stop a sandbox, or every one --where finds. Its disk is kept.", examples: ["agental stop sbx_2a9a47e50daec64a", "agental stop sbx_2a9a47e50daec64a --keep-memory", "agental stop --where 'bench'"] },
1694
+ { name: "delete", summary: "Delete a sandbox, or every one --where finds. It cannot be undone.", examples: ["agental delete sbx_2a9a47e50daec64a"] },
1695
+ { name: "recover", summary: "Get a stuck sandbox going again: what runs in it is killed, its disk is kept." },
1696
+ { 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
+ { name: "jobs", summary: "Follow or cancel the work started on many sandboxes at once." },
1698
+ { name: "tags", summary: "Read, add or remove a sandbox's tags.", examples: ["agental tags sbx_2a9a47e50daec64a add ci"] },
1699
+ {
1700
+ name: "meta",
1701
+ summary: "Read, set or unset a sandbox's metadata.",
1702
+ usage: ["agental meta show <sandbox-id> [--json]", "agental meta set <sandbox-id> <key>=<value>... [--json]", "agental meta unset <sandbox-id> <key>... [--json]"],
1703
+ examples: ["agental meta set sbx_2a9a47e50daec64a owner=ian"],
1704
+ also: "meta <sandbox-id> [set <key>=<value>... | unset <key>...]"
1705
+ },
1706
+ { name: "regions", summary: "List where sandboxes run, and how much room each has now." },
1707
+ { 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
+ { 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
+ { name: "templates", summary: "List your templates: what new sandboxes start from." },
1710
+ { name: "template", summary: "Make, read, change and start templates.", examples: ["agental template create my-env", "agental template start my-env --size medium", "agental template put my-env sbx_2a9a47e50daec64a"] },
1711
+ { name: "secrets", summary: "Keep values and files out of a sandbox, or out of every sandbox of a template.", examples: ["agental secrets --template default set GITHUB_TOKEN=ghp_\u2026 --host github.com,api.github.com", "agental secrets sbx_2a9a47e50daec64a"] },
1712
+ { name: "schedules", summary: "List a sandbox's schedules." },
1713
+ { name: "schedule", summary: "Run a command in a sandbox on a timer, or once at a time.", examples: ["agental schedule add sbx_2a9a47e50daec64a --every 1h -- npm test", "agental schedule runs sbx_2a9a47e50daec64a nightly"] },
1714
+ { 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
+ { name: "email", summary: "Give a sandbox an email address of its own, and read and send its mail." },
1716
+ { name: "desktop", summary: "Turn on a screen in a sandbox, watch it, and drive it." },
1717
+ { name: "browser", summary: "Turn on a Chrome in a sandbox to drive from outside it." },
1718
+ { name: "telemetry", summary: "Send your sandboxes' metrics and events to your OpenTelemetry collector." },
1719
+ { name: "data-retention", summary: "Say how long your sandboxes' history is kept." },
1720
+ { name: "ci", summary: "Run GitHub Actions jobs on sandboxes: each repository's pool." },
1721
+ { name: "claude", summary: "Connect Claude Managed Agents environments, whose sessions run on sandboxes." },
1722
+ { name: "webhooks", summary: "List the addresses your account's events are sent to." },
1723
+ { 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
+ { name: "keys", summary: "List your account's API keys." },
1725
+ { name: "key", summary: "Make, read, limit and delete API keys.", examples: ["agental key add ci --preset ci", "agental key add reader --preset read-only --expires 30d"] },
1726
+ { name: "org", summary: "List, switch and make the accounts you belong to." },
1727
+ { name: "members", summary: "List or remove the members of a team." },
1728
+ { name: "invite", summary: "Invite someone to your team by email." },
1729
+ { name: "billing", summary: "Your plan, credits, invoices and card, and buying credits.", examples: ["agental billing", "agental billing invoices", "agental billing top-up 500"] },
1730
+ { name: "headroom", summary: "How close you run to your plan's limits, and your burst budget." },
1731
+ { name: "account", summary: "Export everything agental keeps about your account and you." },
1732
+ { name: "login", summary: "Sign in through the browser, or with a key from standard input." },
1733
+ { name: "logout", summary: "Delete this computer's key from your account and from here." },
1734
+ { name: "whoami", summary: "Who the command is signed in as, and with which key." },
1735
+ { name: "version", summary: "Print the version of agental." },
1736
+ {
1737
+ name: "sandbox",
1738
+ summary: "Your sandboxes, as agental sandbox <verb>: each is the same as the command without sandbox in front.",
1739
+ usage: [
1740
+ "agental sandbox list [flags]",
1741
+ "agental sandbox create --name <name> [flags]",
1742
+ "agental sandbox start|stop|delete|recover <sandbox-id> [flags]",
1743
+ "agental sandbox exec <sandbox-id> -- <command> [args...]",
1744
+ "agental sandbox shell <sandbox-id>",
1745
+ "agental sandbox summary [flags]"
1746
+ ],
1747
+ examples: ["agental sandbox list", "agental sandbox stop sbx_2a9a47e50daec64a"],
1748
+ also: "list, create, start, stop, delete, recover, exec, shell and summary: agental create --help says create's flags"
1749
+ },
1750
+ { name: "region", summary: "Where sandboxes run, and how much room each has now.", usage: ["agental region list [--json]"], also: "regions" },
1751
+ {
1752
+ name: "tag",
1753
+ summary: "Read, add or remove a sandbox's tags.",
1754
+ usage: ["agental tag list <sandbox-id> [--json]", "agental tag add <sandbox-id> <tag>... [--json]", "agental tag rm <sandbox-id> <tag>... [--json]"],
1755
+ examples: ["agental tag add sbx_2a9a47e50daec64a ci"],
1756
+ also: "tags <sandbox-id> [add|rm <tag>...]"
1757
+ },
1758
+ {
1759
+ name: "secret",
1760
+ summary: "Keep values and files out of a sandbox, or out of every sandbox of a template.",
1761
+ usage: [
1762
+ "agental secret list (<sandbox-id> | --template <template>) [--json]",
1763
+ "agental secret set (<sandbox-id> | --template <template>) <NAME>=<value>... [--host <host>[,<host>...] | --plain]",
1764
+ "agental secret get (<sandbox-id> | --template <template>) <NAME> [--json]",
1765
+ "agental secret unset (<sandbox-id> | --template <template>) <NAME>...",
1766
+ "agental secret hosts (<sandbox-id> | --template <template>) <NAME> --host <host>[,<host>...] [--json]",
1767
+ "agental secret put-file (<sandbox-id> | --template <template>) <path> (<local-file> | --text <text>)",
1768
+ "agental secret get-file|rm-file (<sandbox-id> | --template <template>) <path>"
1769
+ ],
1770
+ 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>"
1772
+ },
1773
+ { 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
+ {
1775
+ name: "member",
1776
+ summary: "The members of a team: list them, remove one, invite someone.",
1777
+ usage: ["agental member list [--json]", "agental member remove <member> [--revoke-keys] [--json]", "agental member invite <email> [--role member|admin] [--json]"],
1778
+ examples: ["agental member invite ana@example.com --role admin"],
1779
+ also: "members and invite"
1780
+ },
1781
+ { name: "operator", summary: "What only whoever runs the service may run: suspend, unsuspend, suspensions and smoke.", usage: ["agental operator suspend|unsuspend|suspensions|smoke ..."], operator: true },
1782
+ { name: "suspend", summary: "Suspend an account.", operator: true },
1783
+ { name: "unsuspend", summary: "Lift an account's suspension.", operator: true },
1784
+ { name: "suspensions", summary: "List suspended accounts.", operator: true },
1785
+ { name: "smoke", summary: "Make a sandbox, try what it does, and delete it.", operator: true }
1786
+ ];
1787
+ var MAP = [
1788
+ [
1789
+ "Start here",
1790
+ [
1791
+ ["sh", "make a sandbox and open a shell in it"],
1792
+ ["create", "make a sandbox"],
1793
+ ["list", "your sandboxes"],
1794
+ ["exec", "run a command in a sandbox"],
1795
+ ["shell, ssh", "open a shell in a sandbox, here or over SSH"]
1796
+ ]
1797
+ ],
1798
+ [
1799
+ "Sandboxes",
1800
+ [
1801
+ ["start, stop, delete", "one sandbox, or every one --where finds"],
1802
+ ["recover, auto-stop", "get a stuck one going, say when one stops"],
1803
+ ["schedule", "run a command on a timer"],
1804
+ ["secret", "values and files kept out of the sandbox"],
1805
+ ["network, egress", "what it may reach, and the address it leaves from"],
1806
+ ["tag, meta, summary", "label sandboxes and find them again"],
1807
+ ["metrics", "CPU, memory and disk over time"],
1808
+ ["email", "an email address of its own"],
1809
+ ["desktop, browser", "a screen and a Chrome in the sandbox"],
1810
+ ["scp, ssh-config", "files, and SSH from any tool"],
1811
+ ["job, region", "work on many at once, and where they run"]
1812
+ ]
1813
+ ],
1814
+ [
1815
+ "Account",
1816
+ [
1817
+ ["template", "what new sandboxes start from"],
1818
+ ["billing", "plan, credits, invoices and card"],
1819
+ ["headroom", "how close you run to your plan's limits"],
1820
+ ["key", "API keys"],
1821
+ ["org, member", "teams"],
1822
+ ["webhook", "events sent to an address of yours"],
1823
+ ["telemetry", "metrics and events sent to your collector"],
1824
+ ["ci, claude", "GitHub Actions and Claude agents on sandboxes"],
1825
+ ["data-retention", "how long your sandboxes' history is kept"],
1826
+ ["account", "everything agental keeps about you"]
1827
+ ]
1828
+ ],
1829
+ ["You", [["login, logout, whoami", "who the command is signed in as"]]]
1830
+ ];
1831
+ var DOCS = "https://agental.io/docs/cli";
1832
+ function shortHelp() {
1833
+ const width = Math.max(...MAP.flatMap(([, rows]) => rows.map(([names]) => names.length))) + 3;
1834
+ const lines = [`${strong("agental")} \xB7 Linux sandboxes for your agents`, "", `${strong("Usage")} agental <command> [flags]`];
1835
+ for (const [group, rows] of MAP) {
1836
+ lines.push("", strong(group));
1837
+ for (const [names, what] of rows) {
1838
+ const painted = names.split(", ").map((name) => command(name)).join(", ");
1839
+ lines.push(` ${painted}${" ".repeat(width - names.length)}${what}`);
1840
+ }
1841
+ }
1842
+ lines.push("", faint("Each thing takes list, show, add or create, update and delete, as agental key list."));
1843
+ lines.push("", faint(`agental <command> --help its flags and examples`), faint(`agental help --all everything, as one page`), faint(DOCS), "");
1844
+ return lines.join("\n");
1845
+ }
1846
+ function usageOf(reference) {
1847
+ const found = /* @__PURE__ */ new Map();
1848
+ let open = null;
1849
+ for (const line of reference.split("\n")) {
1850
+ const start = /^ {2}agental ([a-z][a-z-]*)\b/.exec(line);
1851
+ if (start) {
1852
+ const name = start[1];
1853
+ open = found.get(name) ?? [];
1854
+ open.push(line.trim());
1855
+ found.set(name, open);
1856
+ } else if (open !== null && /^ {3,}\S/.test(line)) {
1857
+ open[open.length - 1] = `${open[open.length - 1]} ${line.trim()}`;
1858
+ } else {
1859
+ open = null;
1860
+ }
1861
+ }
1862
+ return found;
1863
+ }
1864
+ function foldUsage(usage, width) {
1865
+ const said = /^(.*?\S) {3,}(\S.*)$/.exec(usage);
1866
+ const line = said ? said[1] : usage;
1867
+ const note = said ? said[2] : null;
1868
+ const head = /^agental [a-z-]+ /.exec(line)?.[0] ?? "agental ";
1869
+ const indent = " ".repeat(Math.min(head.length, 24) + 2);
1870
+ const parts = [];
1871
+ let depth = 0;
1872
+ let part = "";
1873
+ for (const char of line.slice(head.length)) {
1874
+ depth += char === "[" || char === "(" ? 1 : char === "]" || char === ")" ? -1 : 0;
1875
+ if (char === " " && depth === 0) {
1876
+ parts.push(part);
1877
+ part = "";
1878
+ } else {
1879
+ part += char;
1880
+ }
1881
+ }
1882
+ parts.push(part);
1883
+ parts.splice(0, parts.length, ...parts.filter((each) => each !== ""));
1884
+ const lines = [];
1885
+ let current = ` ${head.trimEnd()}`;
1886
+ for (const part2 of parts) {
1887
+ if (current.length + 1 + part2.length > width && current.trim().length > head.trim().length) {
1888
+ lines.push(current);
1889
+ current = `${indent}${part2}`;
1890
+ } else {
1891
+ current = `${current} ${part2}`;
1892
+ }
1893
+ }
1894
+ lines.push(current);
1895
+ if (note) {
1896
+ lines.push(`${indent}${faint(note)}`);
1897
+ }
1898
+ return lines;
1899
+ }
1900
+ function commandHelp(name, reference, operator) {
1901
+ const found = COMMANDS.find((each) => each.name === name && (operator || !each.operator));
1902
+ if (!found) {
1903
+ return null;
1904
+ }
1905
+ const width = Math.min(Math.max(process.stdout.columns ?? 100, 60), 110);
1906
+ const usages = [...LISTED[name] ? [`agental ${name} list [--json]`] : [], ...found.usage ?? usageOf(reference).get(name) ?? []];
1907
+ const lines = [found.summary, ""];
1908
+ if (usages.length > 0) {
1909
+ lines.push(strong("Usage"));
1910
+ for (const usage of usages) {
1911
+ lines.push(...foldUsage(usage, width));
1912
+ }
1913
+ lines.push("");
1914
+ }
1915
+ if (found.examples) {
1916
+ lines.push(strong("Examples"), ...found.examples.map((example) => ` ${command(example)}`), "");
1917
+ }
1918
+ if (found.flags) {
1919
+ const pad3 = Math.max(...found.flags.map(([flag]) => flag.length)) + 2;
1920
+ lines.push(strong("Flags"), ...found.flags.map(([flag, what]) => ` ${flag.padEnd(pad3)}${what}`), "");
1921
+ }
1922
+ if (found.also) {
1923
+ lines.push(faint(`Also typed as agental ${found.also}.`), "");
1924
+ }
1925
+ lines.push(faint(`More: agental help --all, or ${DOCS}`), "");
1926
+ return lines.join("\n");
1927
+ }
1928
+ function nearest(word, words2) {
1929
+ let best = null;
1930
+ let bestDistance = Infinity;
1931
+ for (const candidate of words2.filter((each) => each !== word)) {
1932
+ const distance = editDistance(word.toLowerCase(), candidate);
1933
+ if (distance < bestDistance) {
1934
+ best = candidate;
1935
+ bestDistance = distance;
1936
+ }
1937
+ }
1938
+ return best !== null && bestDistance <= Math.max(1, Math.min(2, Math.floor(word.length / 3))) ? best : null;
1939
+ }
1940
+ function editDistance(a, b) {
1941
+ const rows = Array.from({ length: a.length + 1 }, (_, i) => Array.from({ length: b.length + 1 }, (_2, j) => i === 0 ? j : j === 0 ? i : 0));
1942
+ for (let i = 1; i <= a.length; i++) {
1943
+ for (let j = 1; j <= b.length; j++) {
1944
+ const row = rows[i];
1945
+ const above = rows[i - 1];
1946
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
1947
+ row[j] = Math.min(above[j] + 1, row[j - 1] + 1, above[j - 1] + cost);
1948
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
1949
+ row[j] = Math.min(row[j], rows[i - 2][j - 2] + 1);
1950
+ }
1951
+ }
1952
+ }
1953
+ return rows[a.length][b.length];
1954
+ }
1955
+ function noSuchCommand(word, operator) {
1956
+ const near = nearest(
1957
+ word,
1958
+ COMMANDS.filter((each) => operator || !each.operator).map((each) => each.name)
1959
+ );
1960
+ const stream = process.stderr;
1961
+ return `${bad("agental:", stream)} there is no command ${word}.${near ? ` Did you mean ${command(near, stream)}?` : ""}
1962
+ ${faint("agental help lists every command.", stream)}
1963
+ `;
1964
+ }
1965
+ var LISTED = { template: "templates", key: "keys", webhook: "webhooks" };
1966
+ var SANDBOX_VERBS = /* @__PURE__ */ new Set(["list", "create", "start", "stop", "delete", "recover", "exec", "shell", "summary"]);
1967
+ var SECRET_VERBS = /* @__PURE__ */ new Set(["list", "get", "set", "unset", "hosts", "get-file", "put-file", "rm-file"]);
1968
+ var OPERATOR_VERBS = /* @__PURE__ */ new Set(["suspend", "unsuspend", "suspensions", "smoke"]);
1969
+ function spelledOut(args, operator = false) {
1970
+ const [thing, verb, ...rest] = args;
1971
+ const wrong = (verbs) => {
1972
+ throw new Error(`${thing} takes ${verbs}. agental ${thing} --help shows each.`);
1973
+ };
1974
+ switch (thing) {
1975
+ case "sandbox":
1976
+ return verb !== void 0 && SANDBOX_VERBS.has(verb) ? [verb, ...rest] : wrong("list, create, start, stop, delete, recover, exec, shell or summary");
1977
+ case "region":
1978
+ return verb === "list" ? ["regions", ...rest] : wrong("list");
1979
+ case "job":
1980
+ return verb === "list" || verb === "show" || verb === "cancel" ? ["jobs", verb, ...rest] : wrong("list, show or cancel");
1981
+ case "member":
1982
+ if (verb === "invite") {
1983
+ return ["invite", ...rest];
1984
+ }
1985
+ return verb === "list" || verb === "remove" ? ["members", verb, ...rest] : wrong("list, remove or invite");
1986
+ case "tag": {
1987
+ const { sandbox, others } = sandboxIn(rest);
1988
+ if (sandbox === void 0 || verb !== "list" && verb !== "add" && verb !== "rm") {
1989
+ return wrong("list, add or rm, then the sandbox");
1990
+ }
1991
+ return ["tags", sandbox, ...verb === "list" ? [] : [verb], ...others];
1992
+ }
1993
+ case "meta": {
1994
+ if (verb !== "show" && verb !== "list" && verb !== "set" && verb !== "unset") {
1995
+ return args;
1996
+ }
1997
+ const { sandbox, others } = sandboxIn(rest);
1998
+ if (sandbox === void 0) {
1999
+ return wrong("show, set or unset, then the sandbox");
2000
+ }
2001
+ return ["meta", sandbox, ...verb === "set" || verb === "unset" ? [verb] : [], ...others];
2002
+ }
2003
+ case "secret": {
2004
+ if (verb === void 0 || !SECRET_VERBS.has(verb)) {
2005
+ return wrong("list, get, set, unset, hosts, get-file, put-file or rm-file, then the sandbox or --template <template>");
2006
+ }
2007
+ const at4 = rest.findIndex((word) => word === "--template" || word === "-t" || word.startsWith("--template="));
2008
+ if (at4 >= 0) {
2009
+ const given = rest[at4];
2010
+ const pair = given.startsWith("--template=") ? [given] : rest.slice(at4, at4 + 2);
2011
+ return ["secrets", ...pair, ...verb === "list" ? [] : [verb], ...rest.filter((_, index) => index < at4 || index >= at4 + pair.length)];
2012
+ }
2013
+ const { sandbox, others } = sandboxIn(rest, ["--host", "--text"]);
2014
+ if (sandbox === void 0) {
2015
+ return wrong("list, get, set, unset, hosts, get-file, put-file or rm-file, then the sandbox or --template <template>");
2016
+ }
2017
+ return ["secrets", sandbox, ...verb === "list" ? [] : [verb], ...others];
2018
+ }
2019
+ case "schedule":
2020
+ return verb === "list" ? ["schedules", ...rest] : args;
2021
+ case "operator":
2022
+ if (verb !== void 0 && OPERATOR_VERBS.has(verb)) {
2023
+ return [verb, ...rest];
2024
+ }
2025
+ return operator ? wrong("suspend, unsuspend, suspensions or smoke") : args;
2026
+ default:
2027
+ return thing !== void 0 && Object.hasOwn(LISTED, thing) && verb === "list" ? [LISTED[thing], ...rest] : args;
2028
+ }
2029
+ }
2030
+ function sandboxIn(words2, valued = []) {
2031
+ for (let index = 0; index < words2.length; index++) {
2032
+ const word = words2[index];
2033
+ if (word === "--") {
2034
+ break;
2035
+ }
2036
+ if (word.startsWith("-")) {
2037
+ index += valued.includes(word) ? 1 : 0;
2038
+ continue;
2039
+ }
2040
+ return { sandbox: word, others: words2.filter((_, at4) => at4 !== index) };
2041
+ }
2042
+ return { sandbox: void 0, others: words2 };
2043
+ }
2044
+
2045
+ // ../src/cli-table.ts
2046
+ var plain2 = (text) => text.replace(/\x1b\[[0-9;]*m/g, "");
2047
+ function windowWidth() {
2048
+ const columns = process.stdout.columns;
2049
+ return typeof columns === "number" && columns >= 40 ? columns : 120;
2050
+ }
2051
+ function cutMiddle(text, room) {
2052
+ if (text.length <= room || room < 5) {
2053
+ return text;
2054
+ }
2055
+ const keep = room - 1;
2056
+ const head = Math.ceil(keep / 2);
2057
+ return `${text.slice(0, head)}\u2026${text.slice(text.length - (keep - head))}`;
2058
+ }
2059
+ function fitted(rows, options = {}) {
2060
+ const width = options.width ?? windowWidth();
2061
+ const columns = Math.max(0, ...rows.map((row) => row.length));
2062
+ const widths = Array.from({ length: columns }, (_, column) => Math.max(0, ...rows.map((row) => plain2(row[column] ?? "").length)));
2063
+ const total = widths.reduce((sum, each) => sum + each, 0) + 2 * (columns - 1);
2064
+ const cut = options.give !== void 0 && total > width ? options.give : -1;
2065
+ if (cut >= 0) {
2066
+ widths[cut] = Math.min(widths[cut] ?? 0, Math.max(12, (widths[cut] ?? 0) - (total - width)));
2067
+ }
2068
+ return rows.map(
2069
+ (row, index) => row.map((cell, column) => {
2070
+ const fit = column === cut ? cutMiddle(cell, widths[column] ?? 0) : cell;
2071
+ const padded = column === row.length - 1 ? fit : fit + " ".repeat(Math.max(0, (widths[column] ?? 0) - plain2(fit).length));
2072
+ return options.paint ? options.paint(padded, index, column) : padded;
2073
+ }).join(" ").trimEnd()
2074
+ ).map((line) => `${line}
2075
+ `).join("");
2076
+ }
2077
+ function ago(iso, now = Date.now()) {
2078
+ const ms = now - Date.parse(iso);
2079
+ if (!Number.isFinite(ms)) {
2080
+ return null;
2081
+ }
2082
+ const said = span(ms);
2083
+ return said === "moments" ? "just now" : `${said} ago`;
2084
+ }
2085
+ function until(iso, now = Date.now()) {
2086
+ const ms = Date.parse(iso) - now;
2087
+ if (!Number.isFinite(ms)) {
2088
+ return null;
2089
+ }
2090
+ const said = span(ms);
2091
+ return said === "moments" ? "any moment now" : `in ${said}`;
2092
+ }
2093
+ function span(ms) {
2094
+ const minutes = Math.max(0, Math.round(ms / 6e4));
2095
+ const say = (count, unit) => `${count} ${unit}${count === 1 ? "" : "s"}`;
2096
+ if (minutes < 1) {
2097
+ return "moments";
2098
+ }
2099
+ if (minutes < 60) {
2100
+ return say(minutes, "minute");
2101
+ }
2102
+ const hours = Math.round(minutes / 60);
2103
+ if (hours < 36) {
2104
+ return say(hours, "hour");
2105
+ }
2106
+ const days = Math.round(hours / 24);
2107
+ if (days < 60) {
2108
+ return say(days, "day");
2109
+ }
2110
+ return say(Math.round(days / 30), "month");
2111
+ }
2112
+
1635
2113
  // ../src/cli-teams.ts
1636
- var ORG_USAGE = "org takes list, use <organization> or create <name>. agental help shows each.";
1637
- var MEMBERS_USAGE = "members takes list, or remove <member> [--revoke-keys]. agental help shows each.";
2114
+ var ORG_USAGE = "org takes list, use <organization> or create <name>. agental org --help shows each.";
2115
+ var MEMBERS_USAGE = "members takes list, or remove <member> [--revoke-keys]. agental members --help shows each.";
1638
2116
  var ROLES = ["member", "admin"];
1639
2117
  async function ask4(client, method, pathname, body) {
1640
2118
  const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
@@ -1811,7 +2289,7 @@ async function invite(client, positionals, options) {
1811
2289
  }
1812
2290
 
1813
2291
  // ../src/cli-schedules.ts
1814
- var USAGE3 = "schedule takes add, show, runs, run, pause, resume, update or delete. agental help shows each.";
2292
+ var USAGE3 = "schedule takes add, show, runs, run, pause, resume, update or delete. agental schedule --help shows each.";
1815
2293
  var OVERLAPS = ["skip", "replace", "parallel"];
1816
2294
  async function ask5(client, method, pathname, body) {
1817
2295
  const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
@@ -1997,8 +2475,8 @@ async function schedule(client, positionals, options) {
1997
2475
  case "resume":
1998
2476
  case "delete":
1999
2477
  case "update": {
2000
- const [target, ...command] = rest;
2001
- if (command.length > 0 && what !== "update") {
2478
+ const [target, ...command2] = rest;
2479
+ if (command2.length > 0 && what !== "update") {
2002
2480
  throw new Error(USAGE3);
2003
2481
  }
2004
2482
  const id = await idOf2(client, sandboxId, target, what);
@@ -2045,7 +2523,7 @@ async function schedule(client, positionals, options) {
2045
2523
  process.stdout.write(`Deleted ${id}, with its runs.
2046
2524
  `);
2047
2525
  } else {
2048
- const changes = { ...fieldsOf(options), ...command.length > 0 ? { command: commandLine(command) } : {} };
2526
+ const changes = { ...fieldsOf(options), ...command2.length > 0 ? { command: commandLine(command2) } : {} };
2049
2527
  if (Object.keys(changes).length === 0) {
2050
2528
  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 --.");
2051
2529
  }
@@ -2090,7 +2568,7 @@ var WEBHOOK_GROUPS = [...new Set(WEBHOOK_KINDS.map((kind) => kind.slice(0, kind.
2090
2568
  var WEBHOOK_RETRY_AFTER_MS = [6e4, 5 * 6e4, 15 * 6e4, 60 * 6e4, 3 * 36e5, 6 * 36e5, 12 * 36e5];
2091
2569
 
2092
2570
  // ../src/cli-webhooks.ts
2093
- var USAGE4 = "webhook takes add, show, update, rotate or delete. agental help shows each.";
2571
+ var USAGE4 = "webhook takes add, show, update, rotate or delete. agental webhook --help shows each.";
2094
2572
  var EVERY = "*";
2095
2573
  var TRIES = WEBHOOK_RETRY_AFTER_MS.length + 1;
2096
2574
  async function ask6(client, method, pathname, body) {
@@ -2333,7 +2811,7 @@ function needId(id, what) {
2333
2811
  }
2334
2812
 
2335
2813
  // ../src/cli-claude.ts
2336
- var USAGE5 = "claude takes connect, show, update or disconnect. agental help shows each.";
2814
+ var USAGE5 = "claude takes connect, show, update or disconnect. agental claude --help shows each.";
2337
2815
  var KEY_VARIABLE = "ANTHROPIC_ENVIRONMENT_KEY";
2338
2816
  var SECRET_VARIABLE = "ANTHROPIC_WEBHOOK_SIGNING_KEY";
2339
2817
  async function ask7(client, method, pathname, body) {
@@ -2767,6 +3245,7 @@ var FREE = {
2767
3245
  /** Small sandboxes an account on the free plan runs and starts at once before it has paid for anything. */
2768
3246
  unpaidUnits: 2
2769
3247
  };
3248
+ var PLAN_NAMES = { free: "Free", plan100: "Fleet", plan500: "Platform", plan2000: "Scale" };
2770
3249
  var TOP_UP_DOLLARS = { min: 15, max: 1e5 };
2771
3250
  var TOP_UP_BONUS = { fromDollars: 200, fromPercent: 2, toDollars: 1e4, toPercent: 25 };
2772
3251
  function topUpBonusPercent(dollars) {
@@ -2798,7 +3277,7 @@ function words(text) {
2798
3277
  return found;
2799
3278
  }
2800
3279
  function whereQuery(text, query = new URLSearchParams()) {
2801
- const plain2 = [];
3280
+ const plain3 = [];
2802
3281
  for (const word of words(text)) {
2803
3282
  const time = /^(made|stopped)([<>])(.+)$/.exec(word);
2804
3283
  if (time) {
@@ -2814,7 +3293,7 @@ function whereQuery(text, query = new URLSearchParams()) {
2814
3293
  }
2815
3294
  const pair = /^(-?)([a-z0-9][a-z0-9_.-]*):(.*)$/.exec(word);
2816
3295
  if (!pair) {
2817
- plain2.push(word);
3296
+ plain3.push(word);
2818
3297
  continue;
2819
3298
  }
2820
3299
  const [, not, key2, value] = pair;
@@ -2876,8 +3355,8 @@ function whereQuery(text, query = new URLSearchParams()) {
2876
3355
  query.append(key2, value);
2877
3356
  }
2878
3357
  }
2879
- if (plain2.length > 0) {
2880
- query.set("q", plain2.join(" "));
3358
+ if (plain3.length > 0) {
3359
+ query.set("q", plain3.join(" "));
2881
3360
  }
2882
3361
  return query;
2883
3362
  }
@@ -2891,23 +3370,23 @@ var SSH_COMMANDS = {
2891
3370
  "ssh-connect": sshConnect
2892
3371
  };
2893
3372
  async function setUp(args) {
2894
- const [command, ...rest] = args;
2895
- const onboarding = command === void 0 || command === "sh" || command === "--no-skills" || command === "--no-install" || command === "--json";
3373
+ const [command2, ...rest] = args;
3374
+ const onboarding = command2 === void 0 || command2 === "sh" || command2 === "--no-skills" || command2 === "--no-install" || command2 === "--json";
2896
3375
  if (onboarding) {
2897
- const flags2 = command === "sh" ? rest : args;
3376
+ const flags2 = command2 === "sh" ? rest : args;
2898
3377
  const unknown = flags2.filter((flag) => !["--json", "--no-skills", "--no-install"].includes(flag));
2899
3378
  if (unknown.length > 0) {
2900
- throw new Error(`${command === "sh" ? "sh" : "agental"} takes --json, --no-skills and --no-install, not ${unknown.join(" ")}`);
3379
+ throw new Error(`${command2 === "sh" ? "sh" : "agental"} takes --json, --no-skills and --no-install, not ${unknown.join(" ")}`);
2901
3380
  }
2902
3381
  await onboard(apiBase(), {
2903
- sandbox: command === "sh",
3382
+ sandbox: command2 === "sh",
2904
3383
  json: flags2.includes("--json"),
2905
3384
  installCommand: !flags2.includes("--no-install"),
2906
3385
  installSkills: !flags2.includes("--no-skills")
2907
3386
  });
2908
3387
  return true;
2909
3388
  }
2910
- switch (command) {
3389
+ switch (command2) {
2911
3390
  case "--version":
2912
3391
  case "-v":
2913
3392
  case "version":
@@ -2930,11 +3409,50 @@ async function setUp(args) {
2930
3409
  return false;
2931
3410
  }
2932
3411
  }
3412
+ async function helpAsked(args) {
3413
+ const own = args.indexOf("--");
3414
+ const ours = own < 0 ? args : args.slice(0, own);
3415
+ const [first, second] = ours;
3416
+ const asked2 = (word) => word === "--help" || word === "-h";
3417
+ const operator = !PUBLISHED;
3418
+ let topic;
3419
+ if ((first === "help" || asked2(first)) && ours.includes("--all")) {
3420
+ process.stdout.write(await helpText());
3421
+ return true;
3422
+ }
3423
+ if (first === "help") {
3424
+ topic = second === "help" ? void 0 : second;
3425
+ } else if (asked2(first)) {
3426
+ topic = void 0;
3427
+ } else if (first !== void 0 && first.startsWith("-") && ours.some(asked2)) {
3428
+ topic = void 0;
3429
+ } else if (first !== void 0 && (Object.hasOwn(SSH_COMMANDS, first) ? asked2(second) : ours.some(asked2))) {
3430
+ topic = first;
3431
+ } else {
3432
+ return false;
3433
+ }
3434
+ if (topic === void 0) {
3435
+ process.stdout.write(isTerminal(process.stdout) ? shortHelp() : await helpText());
3436
+ return true;
3437
+ }
3438
+ const one = commandHelp(topic, await helpText(), operator);
3439
+ if (one === null) {
3440
+ process.stderr.write(noSuchCommand(topic, operator));
3441
+ process.exitCode = 1;
3442
+ return true;
3443
+ }
3444
+ process.stdout.write(one);
3445
+ return true;
3446
+ }
2933
3447
  async function main() {
3448
+ if (await helpAsked(process.argv.slice(2))) {
3449
+ return;
3450
+ }
3451
+ process.argv.splice(2, process.argv.length - 2, ...spelledOut(process.argv.slice(2), !PUBLISHED));
2934
3452
  if (await setUp(process.argv.slice(2))) {
2935
3453
  return;
2936
3454
  }
2937
- const overSsh = SSH_COMMANDS[process.argv[2] ?? ""];
3455
+ const overSsh = Object.hasOwn(SSH_COMMANDS, process.argv[2] ?? "") ? SSH_COMMANDS[process.argv[2] ?? ""] : void 0;
2938
3456
  if (overSsh) {
2939
3457
  await overSsh({ request }, process.argv.slice(3));
2940
3458
  return;
@@ -2943,11 +3461,11 @@ async function main() {
2943
3461
  args: process.argv.slice(2),
2944
3462
  allowPositionals: true,
2945
3463
  options: {
2946
- name: { type: "string" },
3464
+ name: { type: "string", short: "n" },
2947
3465
  // Left out, a new sandbox is the size its template starts sandboxes as.
2948
- size: { type: "string" },
3466
+ size: { type: "string", short: "s" },
2949
3467
  // Given more than once only to key add, as a key may be limited to several.
2950
- template: { type: "string", multiple: true },
3468
+ template: { type: "string", multiple: true, short: "t" },
2951
3469
  snapshot: { type: "string" },
2952
3470
  "new-machine": { type: "boolean", default: false },
2953
3471
  remove: { type: "boolean", default: false },
@@ -3049,20 +3567,22 @@ async function main() {
3049
3567
  sort: { type: "string" },
3050
3568
  role: { type: "string" },
3051
3569
  "revoke-keys": { type: "boolean", default: false },
3570
+ // agental list in a terminal: every column, as piped.
3571
+ wide: { type: "boolean", default: false },
3052
3572
  help: { type: "boolean", short: "h", default: false }
3053
3573
  }
3054
3574
  });
3055
- const command = positionals[0];
3056
- if (values.help || !command || command === "help") {
3057
- process.stdout.write(await helpText());
3575
+ const command2 = positionals[0];
3576
+ if (!command2) {
3577
+ process.stdout.write(isTerminal(process.stdout) ? shortHelp() : await helpText());
3058
3578
  return;
3059
3579
  }
3060
- switch (command) {
3580
+ switch (command2) {
3061
3581
  case "create":
3062
3582
  await create({ ...values, template: once(values.template, "--template") });
3063
3583
  return;
3064
3584
  case "list":
3065
- await list2(values.json, whereQuery(values.where ?? "", labelsFilter(values)), values.sort, values.limit);
3585
+ await list2(values.json, whereQuery(values.where ?? "", labelsFilter(values)), values.sort, values.limit, values.wide);
3066
3586
  return;
3067
3587
  case "jobs":
3068
3588
  await jobs(positionals.slice(1), values.json);
@@ -3232,10 +3752,10 @@ async function main() {
3232
3752
  case "unsuspend":
3233
3753
  case "suspensions": {
3234
3754
  if (PUBLISHED) {
3235
- throw new Error(`${command} is for whoever runs agental, from its repository.`);
3755
+ throw new Error(`${command2} is for whoever runs agental, from its repository.`);
3236
3756
  }
3237
3757
  const { suspensions: suspensions2 } = await Promise.resolve().then(() => (init_cli_operator(), cli_operator_exports));
3238
- await suspensions2({ request, fail }, command, positionals[1], values.reason, values.json);
3758
+ await suspensions2({ request, fail }, command2, positionals[1], values.reason, values.json);
3239
3759
  return;
3240
3760
  }
3241
3761
  case "smoke": {
@@ -3247,9 +3767,7 @@ async function main() {
3247
3767
  return;
3248
3768
  }
3249
3769
  default:
3250
- process.stderr.write(`Unknown command ${command}
3251
-
3252
- ${await helpText()}`);
3770
+ process.stderr.write(noSuchCommand(command2, !PUBLISHED));
3253
3771
  process.exitCode = 1;
3254
3772
  }
3255
3773
  }
@@ -3261,7 +3779,7 @@ function once(given, name) {
3261
3779
  }
3262
3780
  async function create(values) {
3263
3781
  if (!values.name) {
3264
- throw new Error("create requires --name");
3782
+ throw new Error("create needs --name: what to call the sandbox, as agental create --name review-pr-218.");
3265
3783
  }
3266
3784
  const given = labelsGiven(values);
3267
3785
  const burstHeaders = maxBurstFeeHeaders(values["max-burst-fee"]);
@@ -3419,7 +3937,7 @@ async function regions(asJson) {
3419
3937
  }
3420
3938
  process.stdout.write("* where a sandbox is made when no region is named\n");
3421
3939
  }
3422
- async function list2(asJson, filter, sort, limit) {
3940
+ async function list2(asJson, filter, sort, limit, wide = false) {
3423
3941
  const sandboxes = [];
3424
3942
  let cursor = null;
3425
3943
  do {
@@ -3455,6 +3973,10 @@ async function list2(asJson, filter, sort, limit) {
3455
3973
  return;
3456
3974
  }
3457
3975
  const names = sandboxes.some((sandbox) => typeof sandbox["templateId"] === "string") ? await templateNames() : /* @__PURE__ */ new Map();
3976
+ if (isTerminal(process.stdout) && !wide) {
3977
+ process.stdout.write(sandboxesForPeople(sandboxes, names, sort !== void 0));
3978
+ return;
3979
+ }
3458
3980
  const tagged = sandboxes.some((sandbox) => Array.isArray(sandbox["tags"]));
3459
3981
  const header = [...["ID", "NAME", "SIZE", "STATUS"].map(pad2), "VM ", pad2("TEMPLATE"), tagged ? pad2("OUTBOUND") : "OUTBOUND", ...tagged ? ["TAGS"] : []].join(" ");
3460
3982
  process.stdout.write(`${header}
@@ -3638,13 +4160,13 @@ async function jobs(positionals, asJson) {
3638
4160
  }
3639
4161
  async function exec(positionals) {
3640
4162
  const id = positionals[0];
3641
- const command = positionals.slice(1);
3642
- if (!id || command.length === 0) {
3643
- throw new Error("exec requires <sandbox-id> -- <command> [args...]");
4163
+ const command2 = positionals.slice(1);
4164
+ if (!id || command2.length === 0) {
4165
+ throw new Error("exec needs the sandbox and what to run in it, after --: agental exec <sandbox-id> -- ls -la. agental list shows your sandboxes' ids.");
3644
4166
  }
3645
4167
  const response = await request(`/v1/sandboxes/${encodeURIComponent(id)}/exec`, {
3646
4168
  method: "POST",
3647
- body: JSON.stringify({ command })
4169
+ body: JSON.stringify({ command: command2 })
3648
4170
  });
3649
4171
  const body = await readBody(response);
3650
4172
  if (!response.ok) {
@@ -4081,10 +4603,10 @@ function labelsInWords(body) {
4081
4603
  }
4082
4604
  async function labels(what, holder, positionals, asJson) {
4083
4605
  const [named, action, ...words2] = positionals;
4084
- const command = `${holder === "template" ? "template " : ""}${what}`;
4085
- const usage = what === "tags" ? `${command} <${holder}> [add|rm <tag>...]` : `${command} <${holder}> [set <key>=<value>... | unset <key>...]`;
4606
+ const command2 = `${holder === "template" ? "template " : ""}${what}`;
4607
+ const usage = what === "tags" ? `${command2} <${holder}> [add|rm <tag>...]` : `${command2} <${holder}> [set <key>=<value>... | unset <key>...]`;
4086
4608
  if (!named) {
4087
- throw new Error(`${command} requires <${holder}>: ${usage}`);
4609
+ throw new Error(`${command2} requires <${holder}>: ${usage}`);
4088
4610
  }
4089
4611
  const id = holder === "template" ? (await templateNamed(named)).id : named;
4090
4612
  const path4 = `/v1/${holder === "template" ? "templates" : "sandboxes"}/${encodeURIComponent(id)}`;
@@ -4094,23 +4616,23 @@ async function labels(what, holder, positionals, asJson) {
4094
4616
  } else if (what === "tags" && (action === "add" || action === "rm")) {
4095
4617
  const tags = listedIn(words2).map((tag) => tag.toLowerCase());
4096
4618
  if (tags.length === 0) {
4097
- throw new Error(`${command} ${action} requires <tag>...`);
4619
+ throw new Error(`${command2} ${action} requires <tag>...`);
4098
4620
  }
4099
- const bad = tags.find((tag) => !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(tag));
4100
- if (bad !== void 0) {
4101
- 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(bad)}.`);
4621
+ const bad2 = tags.find((tag) => !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(tag));
4622
+ if (bad2 !== void 0) {
4623
+ 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)}.`);
4102
4624
  }
4103
4625
  for (const tag of tags) {
4104
4626
  body = await call2(`${path4}/tags/${encodeURIComponent(tag)}`, { method: action === "add" ? "PUT" : "DELETE" });
4105
4627
  }
4106
4628
  } else if (what === "meta" && (action === "set" || action === "unset")) {
4107
4629
  if (words2.length === 0) {
4108
- throw new Error(`${command} ${action} requires ${action === "set" ? "<key>=<value>" : "<key>"}...`);
4630
+ throw new Error(`${command2} ${action} requires ${action === "set" ? "<key>=<value>" : "<key>"}...`);
4109
4631
  }
4110
4632
  const metadata = action === "set" ? metadataGiven(words2) : Object.fromEntries(words2.map((key2) => [key2, null]));
4111
4633
  body = await call2(path4, { method: "PATCH", body: JSON.stringify({ metadata }) });
4112
4634
  } else {
4113
- throw new Error(`${command} takes ${usage}`);
4635
+ throw new Error(`${command2} takes ${usage}`);
4114
4636
  }
4115
4637
  process.stdout.write(asJson ? `${JSON.stringify(body, null, 2)}
4116
4638
  ` : labelsInWords(body));
@@ -4198,7 +4720,7 @@ async function egress(positionals, values) {
4198
4720
  const missing = Array.isArray(account3["missing"]) ? account3["missing"].map(String) : [];
4199
4721
  const needs = {
4200
4722
  plan: "a plan of Fleet ($100 a month) or larger: agental billing",
4201
- card: "a card saved: agental billing card",
4723
+ card: "a card saved: agental billing card save",
4202
4724
  use_case: 'what your sandboxes will use it for: agental egress use-case "<what for>"'
4203
4725
  };
4204
4726
  const refused = account3["refused"];
@@ -4266,6 +4788,17 @@ async function listTemplates(asJson) {
4266
4788
  const listed = await templatesListed();
4267
4789
  if (asJson) {
4268
4790
  process.stdout.write(`${JSON.stringify(listed, null, 2)}
4791
+ `);
4792
+ return;
4793
+ }
4794
+ if (isTerminal(process.stdout)) {
4795
+ const rows = [
4796
+ ["ID", "NAME", "START", "SANDBOXES"],
4797
+ ...listed.map((each) => [each.id, each.default ? `${each.name} (default)` : each.name, `${each.start?.size ?? ""}${each.start?.snapshotId ? ` from ${each.start.snapshotId}` : ""}`, String(each.sandboxes ?? 0)])
4798
+ ];
4799
+ process.stdout.write(fitted(rows, { give: 1, paint: (cell, row) => row === 0 ? faint(cell) : cell }));
4800
+ process.stdout.write(`
4801
+ ${faint("The default is used when a sandbox is made without naming one. agental template show <name> says more.")}
4269
4802
  `);
4270
4803
  return;
4271
4804
  }
@@ -4300,7 +4833,7 @@ function showTemplate(each) {
4300
4833
  }
4301
4834
  async function template(positionals, values) {
4302
4835
  const [action, first, ...rest] = positionals;
4303
- const usage = "template takes create, show, rename, delete, start, network, egress, ssh, ssh-keys, tags, meta, sandboxes, apply, of or put. agental help says how.";
4836
+ const usage = "template takes create, show, rename, delete, start, network, egress, ssh, ssh-keys, tags, meta, sandboxes, apply, of or put. agental template --help says how.";
4304
4837
  const print4 = (body, words2) => {
4305
4838
  process.stdout.write(values.json ? `${JSON.stringify(body, null, 2)}
4306
4839
  ` : words2);
@@ -4901,8 +5434,10 @@ async function telemetry(positionals, given, asJson) {
4901
5434
  }
4902
5435
  async function billing(positionals, asJson, limit) {
4903
5436
  const [what, amount, ...rest] = positionals;
4904
- const usage = "billing takes nothing, prices, invoices, card, top-up <dollars>, or auto-reload <dollars | off>";
4905
- if (rest.length > 0 || what !== "top-up" && what !== "auto-reload" && amount !== void 0) {
5437
+ const kinds = ["prices", "invoices", "card", "top-up", "auto-reload"];
5438
+ const near = what !== void 0 && !kinds.includes(what) ? nearest(what, kinds) : null;
5439
+ const usage = `${near ? `billing has no ${what}: did you mean billing ${near}? ` : ""}billing takes nothing, prices, invoices, card, card save, top-up <dollars>, or auto-reload <dollars | off>`;
5440
+ if (rest.length > 0 || what !== "top-up" && what !== "auto-reload" && !(what === "card" && amount === "save") && amount !== void 0) {
4906
5441
  throw new Error(usage);
4907
5442
  }
4908
5443
  if (limit !== void 0 && what !== "invoices") {
@@ -4912,8 +5447,8 @@ async function billing(positionals, asJson, limit) {
4912
5447
  ` : text());
4913
5448
  switch (what) {
4914
5449
  case void 0: {
4915
- const [body, card] = await Promise.all([asked("/v1/billing", { method: "GET" }), asJson ? null : cardOnFile()]);
4916
- print4(body, () => describeBilling(body, card));
5450
+ const [body, card] = await Promise.all([asked("/v1/billing", { method: "GET" }), cardOnFile()]);
5451
+ print4({ ...body, card }, () => describeBilling(body, card));
4917
5452
  return;
4918
5453
  }
4919
5454
  case "invoices": {
@@ -4922,10 +5457,16 @@ async function billing(positionals, asJson, limit) {
4922
5457
  }
4923
5458
  case "prices": {
4924
5459
  const body = await asked("/v1/billing/plans", { method: "GET" });
4925
- print4(body, () => describePrices(body));
5460
+ print4(body, () => isTerminal(process.stdout) ? pricesForPeople(body) : describePrices(body));
4926
5461
  return;
4927
5462
  }
4928
5463
  case "card": {
5464
+ if (amount === void 0) {
5465
+ const body2 = await asked("/v1/billing/card", { method: "GET" });
5466
+ print4(body2, () => body2.card ? `${describeCard(body2.card)}
5467
+ ` : "No card saved. agental billing card save prints the page to save one on, charged nothing.\n");
5468
+ return;
5469
+ }
4929
5470
  const body = await asked("/v1/billing/checkout", { method: "POST", body: JSON.stringify({ card: true }) });
4930
5471
  print4(
4931
5472
  body,
@@ -4987,7 +5528,7 @@ function describeBilling(body, card = null) {
4987
5528
  if (free && body.plan) {
4988
5529
  lines.push(["Plan", "free: nothing a month. What runs is paid from your credits, at list price."]);
4989
5530
  if (!free.cardSaved) {
4990
- lines.push(["Card", "none saved. Save one, charged nothing, to run sandboxes and be given the free plan's credit: agental billing card."]);
5531
+ lines.push(["Card", "none saved. Save one, charged nothing, to run sandboxes and be given the free plan's credit: agental billing card save."]);
4991
5532
  } else if (card) {
4992
5533
  lines.push(["Card", describeCard(card)]);
4993
5534
  }
@@ -5030,13 +5571,13 @@ function describeBilling(body, card = null) {
5030
5571
  if (!body.canRun && body.reason) {
5031
5572
  lines.push([
5032
5573
  "Running",
5033
- body.reason === "out_of_credit" ? `no: ${free ? "your credits are" : "the plan's credits and the top-ups are"} used. agental billing top-up <dollars> buys more.` : body.reason === "billing_required" ? "no: save a card first, charged nothing, with agental billing card." : `no: ${body.reason}`
5574
+ body.reason === "out_of_credit" ? `no: ${free ? "your credits are" : "the plan's credits and the top-ups are"} used. agental billing top-up <dollars> buys more.` : body.reason === "billing_required" ? "no: save a card first, charged nothing, with agental billing card save." : `no: ${body.reason}`
5034
5575
  ]);
5035
5576
  }
5036
5577
  if (body.lapse) {
5037
5578
  lines.push([
5038
5579
  "Deleted on",
5039
- body.lapse.reason === "unpaid" ? `${dayOf(body.lapse.deletesAt)}: your sandboxes and snapshots, as the account owes for what it used past its plan. agental billing top-up <dollars> buys enough to pay it and keep them.` : body.lapse.reason === "out_of_credit" ? `${dayOf(body.lapse.deletesAt)}: your sandboxes and snapshots, as your credits are used. agental billing top-up <dollars> keeps them.` : `${dayOf(body.lapse.deletesAt)}: your sandboxes and snapshots, as the account has no card saved. agental billing card saves one, charged nothing, to keep them.`
5580
+ body.lapse.reason === "unpaid" ? `${dayOf(body.lapse.deletesAt)}: your sandboxes and snapshots, as the account owes for what it used past its plan. agental billing top-up <dollars> buys enough to pay it and keep them.` : body.lapse.reason === "out_of_credit" ? `${dayOf(body.lapse.deletesAt)}: your sandboxes and snapshots, as your credits are used. agental billing top-up <dollars> keeps them.` : `${dayOf(body.lapse.deletesAt)}: your sandboxes and snapshots, as the account has no card saved. agental billing card save saves one, charged nothing, to keep them.`
5040
5581
  ]);
5041
5582
  }
5042
5583
  if (body.testMode) {
@@ -5152,6 +5693,78 @@ function describeAutoReload(autoReload) {
5152
5693
  const adds = topUp && topUp.bonusMicros > 0 ? ` for ${wholeMoney(topUp.micros)} of credits, a bonus of ${topUp.bonusPercent}%,` : "";
5153
5694
  return `${wholeMoney(autoReload.dollars * 1e6)}${adds} charged to your saved card when your credits run out, before anything is stopped. At most 3 times a day.`;
5154
5695
  }
5696
+ function pricesForPeople(body) {
5697
+ const out = [];
5698
+ const count = (value) => value === void 0 || value === null ? "" : value.toLocaleString("en-US");
5699
+ const section = (title, rows, notes) => {
5700
+ const table4 = fitted(rows, { paint: (cell, row) => row === 0 ? faint(cell) : cell }).trimEnd().split("\n");
5701
+ out.push(strong(title), ...table4.map((line) => ` ${line}`), ...notes.map((note) => ` ${faint(note)}`), "");
5702
+ };
5703
+ if (body.tiers?.length) {
5704
+ section(
5705
+ "Plans",
5706
+ [
5707
+ ["", "A MONTH", "CREDITS BACK", "RUN AT ONCE", "START FREE", "SIZES"],
5708
+ ...body.tiers.map((tier) => [
5709
+ (tier.id ? PLAN_NAMES[tier.id] : void 0) ?? (tier.dollarsPerMonth === 0 ? "Free" : `$${tier.dollarsPerMonth.toLocaleString("en-US")}`),
5710
+ wholeMoney(tier.dollarsPerMonth * 1e6),
5711
+ tier.dollarsPerMonth === 0 ? body.free ? `${wholeMoney(body.free.creditMicros)}, once` : "none" : wholeMoney(tier.includedMicros),
5712
+ count(tier.runningUnits ?? tier.sandboxesAtOnce),
5713
+ count(tier.freeBurstUnits),
5714
+ tier.sizes === void 0 ? "" : tier.sizes.length === body.plans.length ? "every size" : tier.sizes.join(", ")
5715
+ ])
5716
+ ],
5717
+ [
5718
+ ...body.free ? [`Free needs a card saved, charged nothing; it runs ${body.free.unpaidUnits} at once until your first top-up.`] : [],
5719
+ ...body.tiers.some((tier) => tier.runningUnits !== void 0) ? ["Counted in small sandboxes: a medium is 2, a large 4, a tiny half."] : []
5720
+ ]
5721
+ );
5722
+ }
5723
+ section(
5724
+ "Sizes",
5725
+ [
5726
+ ["", "VCPU", "MEMORY", "AN HOUR", ...body.storage ? ["STOPPED, AN HOUR"] : []],
5727
+ ...body.plans.map((size) => [
5728
+ size.size,
5729
+ String(size.vcpu),
5730
+ `${size.memoryMb / 1024} GiB`,
5731
+ `$${size.listPriceMicrosPerHour / 1e6}`,
5732
+ ...body.storage ? [size.stoppedMicrosPerHour === void 0 ? "" : `$${size.stoppedMicrosPerHour / 1e6}`] : []
5733
+ ])
5734
+ ],
5735
+ [`Charged by the second.${body.storage ? ` Stopped, a sandbox costs ${body.storage.stoppedPercent}% while its disk is kept.` : ""}`]
5736
+ );
5737
+ if (body.topUps?.length) {
5738
+ const range = body.topUpRange;
5739
+ section(
5740
+ "Top-ups",
5741
+ [
5742
+ ["PAY", "GET", ""],
5743
+ ...body.topUps.map((topUp) => [
5744
+ wholeMoney(topUp.dollars * 1e6),
5745
+ wholeMoney(topUp.micros ?? topUp.dollars * 1e6),
5746
+ topUp.bonusPercent ? good(`+${topUp.bonusPercent}%`) : ""
5747
+ ])
5748
+ ],
5749
+ [
5750
+ `${range ? `Any whole amount from ${wholeMoney(range.minDollars * 1e6)} to ${wholeMoney(range.maxDollars * 1e6)}. ` : ""}${body.topUpBonus ? `A bonus from ${wholeMoney(body.topUpBonus.fromDollars * 1e6)}. ` : ""}They never expire.`
5751
+ ]
5752
+ );
5753
+ }
5754
+ const also = [];
5755
+ if (body.burstFee) {
5756
+ also.push(["Bursts", `$0.027 a small started past your free starts, at most ${wholeMoney(body.burstFee.defaultBudgetMicros)} a month unless you set a budget`]);
5757
+ }
5758
+ if (body.storage) {
5759
+ also.push(["Snapshots", `the ${body.storage.freeSnapshots} oldest free, then $${(body.storage.snapshotMicrosPerHour * 730 / 1e6).toFixed(2)} a month each`]);
5760
+ }
5761
+ if (also.length > 0) {
5762
+ out.push(strong("Also"), ...fitted(also).trimEnd().split("\n").map((line) => ` ${line}`), "");
5763
+ }
5764
+ out.push(faint("agental billing top-up <dollars> \xB7 agental headroom budget <dollars> \xB7 https://agental.io/pricing"));
5765
+ return `${out.join("\n")}
5766
+ `;
5767
+ }
5155
5768
  function describePrices(body) {
5156
5769
  const out = [];
5157
5770
  if (body.tiers?.length) {
@@ -5387,6 +6000,64 @@ function table3(rows) {
5387
6000
  return rows.map((row) => `${row.map((cell, column) => cell.padEnd(widths[column] ?? 0, " ")).join(" ").trimEnd()}
5388
6001
  `).join("");
5389
6002
  }
6003
+ var ACTIVE = /* @__PURE__ */ new Set(["running", "starting", "stopping", "restoring", "creating"]);
6004
+ function sandboxesForPeople(sandboxes, names, sorted) {
6005
+ const text = (value) => typeof value === "string" ? value : "";
6006
+ const changed = (sandbox) => Date.parse(text(sandbox["stoppedAt"]) || text(sandbox["updatedAt"]) || text(sandbox["createdAt"])) || 0;
6007
+ const shown = sorted ? sandboxes : [...sandboxes].sort((a, b) => Number(ACTIVE.has(text(b["status"]))) - Number(ACTIVE.has(text(a["status"]))) || changed(b) - changed(a));
6008
+ const outbound = (sandbox) => {
6009
+ const rule = sandbox["network"];
6010
+ return rule && typeof rule === "object" ? text(rule["outbound"]) : "";
6011
+ };
6012
+ const differs = (read2) => new Set(shown.map(read2)).size > 1;
6013
+ const showVm = differs((sandbox) => String(sandbox["vmIsolation"] === true));
6014
+ const showOutbound = differs(outbound);
6015
+ const showTags = shown.some((sandbox) => Array.isArray(sandbox["tags"]) && sandbox["tags"].length > 0);
6016
+ const status = (sandbox) => {
6017
+ const word = text(sandbox["status"]) || "unknown";
6018
+ const stops = word === "running" ? until(text(sandbox["autoStopAt"])) : null;
6019
+ const stopped = word === "stopped" ? ago(text(sandbox["stoppedAt"])) : null;
6020
+ return stops ? `running, stops ${stops}` : stopped ? `stopped ${stopped}` : word;
6021
+ };
6022
+ const rows = [
6023
+ ["", "ID", "NAME", "SIZE", "TEMPLATE", "STATUS", ...showVm ? ["VM"] : [], ...showOutbound ? ["OUTBOUND"] : [], ...showTags ? ["TAGS"] : []],
6024
+ ...shown.map((sandbox) => {
6025
+ const templateId = text(sandbox["templateId"]);
6026
+ return [
6027
+ ACTIVE.has(text(sandbox["status"])) ? "\u25CF" : "\u25CB",
6028
+ text(sandbox["id"]),
6029
+ text(sandbox["name"]),
6030
+ text(sandbox["size"]),
6031
+ templateId ? names.get(templateId) ?? templateId : "-",
6032
+ status(sandbox),
6033
+ ...showVm ? [sandbox["vmIsolation"] === true ? "yes" : "no"] : [],
6034
+ ...showOutbound ? [outbound(sandbox)] : [],
6035
+ ...showTags ? [Array.isArray(sandbox["tags"]) ? sandbox["tags"].join(",") : ""] : []
6036
+ ];
6037
+ })
6038
+ ];
6039
+ const body = fitted(rows, {
6040
+ give: 2,
6041
+ paint: (cell, row, column) => {
6042
+ if (row === 0) {
6043
+ return faint(cell);
6044
+ }
6045
+ const active = ACTIVE.has(text(shown[row - 1]?.["status"]));
6046
+ if (column === 0 || column === 5) {
6047
+ return active ? good(cell) : faint(cell);
6048
+ }
6049
+ return column === 2 && active ? strong(cell) : cell;
6050
+ }
6051
+ });
6052
+ const byStatus = /* @__PURE__ */ new Map();
6053
+ for (const sandbox of shown) {
6054
+ byStatus.set(text(sandbox["status"]) || "unknown", (byStatus.get(text(sandbox["status"]) || "unknown") ?? 0) + 1);
6055
+ }
6056
+ const counts = `${[...byStatus].sort(([a], [b]) => Number(ACTIVE.has(b)) - Number(ACTIVE.has(a))).map(([word, count]) => `${count} ${word}`).join(", ")}.`;
6057
+ return `${body}
6058
+ ${counts} ${faint("--wide for every column, --json for scripts")}
6059
+ `;
6060
+ }
5390
6061
  function boxNamed(value) {
5391
6062
  if (value !== void 0 && value.trim() === "") {
5392
6063
  throw new Error("--box takes the id or the name of a box");
@@ -5575,7 +6246,7 @@ Usage
5575
6246
  agental key show <key> [--json]
5576
6247
  agental key allow-from <key> (<address-or-range>... | --anywhere) [--json]
5577
6248
  agental key delete <key>
5578
- agental billing [prices | card | top-up <dollars> | auto-reload <dollars | off>] [--json]
6249
+ agental billing [prices | card [save] | top-up <dollars> | auto-reload <dollars | off>] [--json]
5579
6250
  agental billing invoices [--limit <n>] [--json]
5580
6251
  agental headroom [--from <day or date-time>] [--to <day or date-time>] [--step 10m|hour|day] [--json]
5581
6252
  agental headroom budget <dollars> | budget default [--json]
@@ -5854,6 +6525,11 @@ main().catch((error) => {
5854
6525
  const message = error instanceof Error ? error.message : "Command failed";
5855
6526
  process.stderr.write(`${message}
5856
6527
  `);
6528
+ const word = process.argv[2];
6529
+ if (error instanceof Error && isTerminal(process.stderr) && COMMANDS.some((each) => each.name === word && (!each.operator || !PUBLISHED))) {
6530
+ process.stderr.write(`${faint(`agental ${word} --help shows what it takes.`, process.stderr)}
6531
+ `);
6532
+ }
5857
6533
  process.exit(1);
5858
6534
  });
5859
6535
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agental",
3
- "version": "0.10.0",
3
+ "version": "0.13.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",