agental 0.11.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 +395 -37
  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.11.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}`;
@@ -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);
@@ -1696,7 +1696,13 @@ var COMMANDS = [
1696
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
1697
  { name: "jobs", summary: "Follow or cancel the work started on many sandboxes at once." },
1698
1698
  { name: "tags", summary: "Read, add or remove a sandbox's tags.", examples: ["agental tags sbx_2a9a47e50daec64a add ci"] },
1699
- { name: "meta", summary: "Read, set or unset a sandbox's metadata.", examples: ["agental meta sbx_2a9a47e50daec64a set owner=ian"] },
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
+ },
1700
1706
  { name: "regions", summary: "List where sandboxes run, and how much room each has now." },
1701
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"] },
1702
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"] },
@@ -1727,6 +1733,52 @@ var COMMANDS = [
1727
1733
  { name: "logout", summary: "Delete this computer's key from your account and from here." },
1728
1734
  { name: "whoami", summary: "Who the command is signed in as, and with which key." },
1729
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 },
1730
1782
  { name: "suspend", summary: "Suspend an account.", operator: true },
1731
1783
  { name: "unsuspend", summary: "Lift an account's suspension.", operator: true },
1732
1784
  { name: "suspensions", summary: "List suspended accounts.", operator: true },
@@ -1749,25 +1801,25 @@ var MAP = [
1749
1801
  ["start, stop, delete", "one sandbox, or every one --where finds"],
1750
1802
  ["recover, auto-stop", "get a stuck one going, say when one stops"],
1751
1803
  ["schedule", "run a command on a timer"],
1752
- ["secrets", "values and files kept out of the sandbox"],
1804
+ ["secret", "values and files kept out of the sandbox"],
1753
1805
  ["network, egress", "what it may reach, and the address it leaves from"],
1754
- ["tags, meta, summary", "label sandboxes and find them again"],
1806
+ ["tag, meta, summary", "label sandboxes and find them again"],
1755
1807
  ["metrics", "CPU, memory and disk over time"],
1756
1808
  ["email", "an email address of its own"],
1757
1809
  ["desktop, browser", "a screen and a Chrome in the sandbox"],
1758
1810
  ["scp, ssh-config", "files, and SSH from any tool"],
1759
- ["jobs, regions", "work on many at once, and where they run"]
1811
+ ["job, region", "work on many at once, and where they run"]
1760
1812
  ]
1761
1813
  ],
1762
1814
  [
1763
1815
  "Account",
1764
1816
  [
1765
- ["templates, template", "what new sandboxes start from"],
1817
+ ["template", "what new sandboxes start from"],
1766
1818
  ["billing", "plan, credits, invoices and card"],
1767
1819
  ["headroom", "how close you run to your plan's limits"],
1768
- ["keys, key", "API keys"],
1769
- ["org, members, invite", "teams"],
1770
- ["webhooks, webhook", "events sent to an address of yours"],
1820
+ ["key", "API keys"],
1821
+ ["org, member", "teams"],
1822
+ ["webhook", "events sent to an address of yours"],
1771
1823
  ["telemetry", "metrics and events sent to your collector"],
1772
1824
  ["ci, claude", "GitHub Actions and Claude agents on sandboxes"],
1773
1825
  ["data-retention", "how long your sandboxes' history is kept"],
@@ -1787,6 +1839,7 @@ function shortHelp() {
1787
1839
  lines.push(` ${painted}${" ".repeat(width - names.length)}${what}`);
1788
1840
  }
1789
1841
  }
1842
+ lines.push("", faint("Each thing takes list, show, add or create, update and delete, as agental key list."));
1790
1843
  lines.push("", faint(`agental <command> --help its flags and examples`), faint(`agental help --all everything, as one page`), faint(DOCS), "");
1791
1844
  return lines.join("\n");
1792
1845
  }
@@ -1850,7 +1903,7 @@ function commandHelp(name, reference, operator) {
1850
1903
  return null;
1851
1904
  }
1852
1905
  const width = Math.min(Math.max(process.stdout.columns ?? 100, 60), 110);
1853
- const usages = usageOf(reference).get(name) ?? [];
1906
+ const usages = [...LISTED[name] ? [`agental ${name} list [--json]`] : [], ...found.usage ?? usageOf(reference).get(name) ?? []];
1854
1907
  const lines = [found.summary, ""];
1855
1908
  if (usages.length > 0) {
1856
1909
  lines.push(strong("Usage"));
@@ -1866,13 +1919,16 @@ function commandHelp(name, reference, operator) {
1866
1919
  const pad3 = Math.max(...found.flags.map(([flag]) => flag.length)) + 2;
1867
1920
  lines.push(strong("Flags"), ...found.flags.map(([flag, what]) => ` ${flag.padEnd(pad3)}${what}`), "");
1868
1921
  }
1922
+ if (found.also) {
1923
+ lines.push(faint(`Also typed as agental ${found.also}.`), "");
1924
+ }
1869
1925
  lines.push(faint(`More: agental help --all, or ${DOCS}`), "");
1870
1926
  return lines.join("\n");
1871
1927
  }
1872
1928
  function nearest(word, words2) {
1873
1929
  let best = null;
1874
1930
  let bestDistance = Infinity;
1875
- for (const candidate of words2) {
1931
+ for (const candidate of words2.filter((each) => each !== word)) {
1876
1932
  const distance = editDistance(word.toLowerCase(), candidate);
1877
1933
  if (distance < bestDistance) {
1878
1934
  best = candidate;
@@ -1906,6 +1962,153 @@ function noSuchCommand(word, operator) {
1906
1962
  ${faint("agental help lists every command.", stream)}
1907
1963
  `;
1908
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
+ }
1909
2112
 
1910
2113
  // ../src/cli-teams.ts
1911
2114
  var ORG_USAGE = "org takes list, use <organization> or create <name>. agental org --help shows each.";
@@ -3042,6 +3245,7 @@ var FREE = {
3042
3245
  /** Small sandboxes an account on the free plan runs and starts at once before it has paid for anything. */
3043
3246
  unpaidUnits: 2
3044
3247
  };
3248
+ var PLAN_NAMES = { free: "Free", plan100: "Fleet", plan500: "Platform", plan2000: "Scale" };
3045
3249
  var TOP_UP_DOLLARS = { min: 15, max: 1e5 };
3046
3250
  var TOP_UP_BONUS = { fromDollars: 200, fromPercent: 2, toDollars: 1e4, toPercent: 25 };
3047
3251
  function topUpBonusPercent(dollars) {
@@ -3073,7 +3277,7 @@ function words(text) {
3073
3277
  return found;
3074
3278
  }
3075
3279
  function whereQuery(text, query = new URLSearchParams()) {
3076
- const plain2 = [];
3280
+ const plain3 = [];
3077
3281
  for (const word of words(text)) {
3078
3282
  const time = /^(made|stopped)([<>])(.+)$/.exec(word);
3079
3283
  if (time) {
@@ -3089,7 +3293,7 @@ function whereQuery(text, query = new URLSearchParams()) {
3089
3293
  }
3090
3294
  const pair = /^(-?)([a-z0-9][a-z0-9_.-]*):(.*)$/.exec(word);
3091
3295
  if (!pair) {
3092
- plain2.push(word);
3296
+ plain3.push(word);
3093
3297
  continue;
3094
3298
  }
3095
3299
  const [, not, key2, value] = pair;
@@ -3151,8 +3355,8 @@ function whereQuery(text, query = new URLSearchParams()) {
3151
3355
  query.append(key2, value);
3152
3356
  }
3153
3357
  }
3154
- if (plain2.length > 0) {
3155
- query.set("q", plain2.join(" "));
3358
+ if (plain3.length > 0) {
3359
+ query.set("q", plain3.join(" "));
3156
3360
  }
3157
3361
  return query;
3158
3362
  }
@@ -3222,7 +3426,7 @@ async function helpAsked(args) {
3222
3426
  topic = void 0;
3223
3427
  } else if (first !== void 0 && first.startsWith("-") && ours.some(asked2)) {
3224
3428
  topic = void 0;
3225
- } else if (first !== void 0 && (SSH_COMMANDS[first] ? asked2(second) : ours.some(asked2))) {
3429
+ } else if (first !== void 0 && (Object.hasOwn(SSH_COMMANDS, first) ? asked2(second) : ours.some(asked2))) {
3226
3430
  topic = first;
3227
3431
  } else {
3228
3432
  return false;
@@ -3244,10 +3448,11 @@ async function main() {
3244
3448
  if (await helpAsked(process.argv.slice(2))) {
3245
3449
  return;
3246
3450
  }
3451
+ process.argv.splice(2, process.argv.length - 2, ...spelledOut(process.argv.slice(2), !PUBLISHED));
3247
3452
  if (await setUp(process.argv.slice(2))) {
3248
3453
  return;
3249
3454
  }
3250
- const overSsh = SSH_COMMANDS[process.argv[2] ?? ""];
3455
+ const overSsh = Object.hasOwn(SSH_COMMANDS, process.argv[2] ?? "") ? SSH_COMMANDS[process.argv[2] ?? ""] : void 0;
3251
3456
  if (overSsh) {
3252
3457
  await overSsh({ request }, process.argv.slice(3));
3253
3458
  return;
@@ -3362,6 +3567,8 @@ async function main() {
3362
3567
  sort: { type: "string" },
3363
3568
  role: { type: "string" },
3364
3569
  "revoke-keys": { type: "boolean", default: false },
3570
+ // agental list in a terminal: every column, as piped.
3571
+ wide: { type: "boolean", default: false },
3365
3572
  help: { type: "boolean", short: "h", default: false }
3366
3573
  }
3367
3574
  });
@@ -3375,7 +3582,7 @@ async function main() {
3375
3582
  await create({ ...values, template: once(values.template, "--template") });
3376
3583
  return;
3377
3584
  case "list":
3378
- 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);
3379
3586
  return;
3380
3587
  case "jobs":
3381
3588
  await jobs(positionals.slice(1), values.json);
@@ -3730,7 +3937,7 @@ async function regions(asJson) {
3730
3937
  }
3731
3938
  process.stdout.write("* where a sandbox is made when no region is named\n");
3732
3939
  }
3733
- async function list2(asJson, filter, sort, limit) {
3940
+ async function list2(asJson, filter, sort, limit, wide = false) {
3734
3941
  const sandboxes = [];
3735
3942
  let cursor = null;
3736
3943
  do {
@@ -3766,6 +3973,10 @@ async function list2(asJson, filter, sort, limit) {
3766
3973
  return;
3767
3974
  }
3768
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
+ }
3769
3980
  const tagged = sandboxes.some((sandbox) => Array.isArray(sandbox["tags"]));
3770
3981
  const header = [...["ID", "NAME", "SIZE", "STATUS"].map(pad2), "VM ", pad2("TEMPLATE"), tagged ? pad2("OUTBOUND") : "OUTBOUND", ...tagged ? ["TAGS"] : []].join(" ");
3771
3982
  process.stdout.write(`${header}
@@ -4509,7 +4720,7 @@ async function egress(positionals, values) {
4509
4720
  const missing = Array.isArray(account3["missing"]) ? account3["missing"].map(String) : [];
4510
4721
  const needs = {
4511
4722
  plan: "a plan of Fleet ($100 a month) or larger: agental billing",
4512
- card: "a card saved: agental billing card",
4723
+ card: "a card saved: agental billing card save",
4513
4724
  use_case: 'what your sandboxes will use it for: agental egress use-case "<what for>"'
4514
4725
  };
4515
4726
  const refused = account3["refused"];
@@ -4577,6 +4788,17 @@ async function listTemplates(asJson) {
4577
4788
  const listed = await templatesListed();
4578
4789
  if (asJson) {
4579
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.")}
4580
4802
  `);
4581
4803
  return;
4582
4804
  }
@@ -5214,8 +5436,8 @@ async function billing(positionals, asJson, limit) {
5214
5436
  const [what, amount, ...rest] = positionals;
5215
5437
  const kinds = ["prices", "invoices", "card", "top-up", "auto-reload"];
5216
5438
  const near = what !== void 0 && !kinds.includes(what) ? nearest(what, kinds) : null;
5217
- const usage = `${near ? `billing has no ${what}: did you mean billing ${near}? ` : ""}billing takes nothing, prices, invoices, card, top-up <dollars>, or auto-reload <dollars | off>`;
5218
- if (rest.length > 0 || what !== "top-up" && what !== "auto-reload" && amount !== void 0) {
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) {
5219
5441
  throw new Error(usage);
5220
5442
  }
5221
5443
  if (limit !== void 0 && what !== "invoices") {
@@ -5235,10 +5457,16 @@ async function billing(positionals, asJson, limit) {
5235
5457
  }
5236
5458
  case "prices": {
5237
5459
  const body = await asked("/v1/billing/plans", { method: "GET" });
5238
- print4(body, () => describePrices(body));
5460
+ print4(body, () => isTerminal(process.stdout) ? pricesForPeople(body) : describePrices(body));
5239
5461
  return;
5240
5462
  }
5241
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
+ }
5242
5470
  const body = await asked("/v1/billing/checkout", { method: "POST", body: JSON.stringify({ card: true }) });
5243
5471
  print4(
5244
5472
  body,
@@ -5300,7 +5528,7 @@ function describeBilling(body, card = null) {
5300
5528
  if (free && body.plan) {
5301
5529
  lines.push(["Plan", "free: nothing a month. What runs is paid from your credits, at list price."]);
5302
5530
  if (!free.cardSaved) {
5303
- 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."]);
5304
5532
  } else if (card) {
5305
5533
  lines.push(["Card", describeCard(card)]);
5306
5534
  }
@@ -5343,13 +5571,13 @@ function describeBilling(body, card = null) {
5343
5571
  if (!body.canRun && body.reason) {
5344
5572
  lines.push([
5345
5573
  "Running",
5346
- 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}`
5347
5575
  ]);
5348
5576
  }
5349
5577
  if (body.lapse) {
5350
5578
  lines.push([
5351
5579
  "Deleted on",
5352
- 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.`
5353
5581
  ]);
5354
5582
  }
5355
5583
  if (body.testMode) {
@@ -5465,6 +5693,78 @@ function describeAutoReload(autoReload) {
5465
5693
  const adds = topUp && topUp.bonusMicros > 0 ? ` for ${wholeMoney(topUp.micros)} of credits, a bonus of ${topUp.bonusPercent}%,` : "";
5466
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.`;
5467
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
+ }
5468
5768
  function describePrices(body) {
5469
5769
  const out = [];
5470
5770
  if (body.tiers?.length) {
@@ -5700,6 +6000,64 @@ function table3(rows) {
5700
6000
  return rows.map((row) => `${row.map((cell, column) => cell.padEnd(widths[column] ?? 0, " ")).join(" ").trimEnd()}
5701
6001
  `).join("");
5702
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
+ }
5703
6061
  function boxNamed(value) {
5704
6062
  if (value !== void 0 && value.trim() === "") {
5705
6063
  throw new Error("--box takes the id or the name of a box");
@@ -5888,7 +6246,7 @@ Usage
5888
6246
  agental key show <key> [--json]
5889
6247
  agental key allow-from <key> (<address-or-range>... | --anywhere) [--json]
5890
6248
  agental key delete <key>
5891
- 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]
5892
6250
  agental billing invoices [--limit <n>] [--json]
5893
6251
  agental headroom [--from <day or date-time>] [--to <day or date-time>] [--step 10m|hour|day] [--json]
5894
6252
  agental headroom budget <dollars> | budget default [--json]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agental",
3
- "version": "0.11.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",