agental 0.10.0 → 0.11.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 +371 -53
  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.11.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) {
@@ -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,284 @@ 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
+ { name: "meta", summary: "Read, set or unset a sandbox's metadata.", examples: ["agental meta sbx_2a9a47e50daec64a set owner=ian"] },
1700
+ { name: "regions", summary: "List where sandboxes run, and how much room each has now." },
1701
+ { 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
+ { name: "egress", summary: "Say where a sandbox's web traffic leaves from, or read your residential egress.", examples: ["agental egress sbx_2a9a47e50daec64a residential de"] },
1703
+ { name: "templates", summary: "List your templates: what new sandboxes start from." },
1704
+ { 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"] },
1705
+ { 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"] },
1706
+ { name: "schedules", summary: "List a sandbox's schedules." },
1707
+ { 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"] },
1708
+ { 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"] },
1709
+ { name: "email", summary: "Give a sandbox an email address of its own, and read and send its mail." },
1710
+ { name: "desktop", summary: "Turn on a screen in a sandbox, watch it, and drive it." },
1711
+ { name: "browser", summary: "Turn on a Chrome in a sandbox to drive from outside it." },
1712
+ { name: "telemetry", summary: "Send your sandboxes' metrics and events to your OpenTelemetry collector." },
1713
+ { name: "data-retention", summary: "Say how long your sandboxes' history is kept." },
1714
+ { name: "ci", summary: "Run GitHub Actions jobs on sandboxes: each repository's pool." },
1715
+ { name: "claude", summary: "Connect Claude Managed Agents environments, whose sessions run on sandboxes." },
1716
+ { name: "webhooks", summary: "List the addresses your account's events are sent to." },
1717
+ { 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"] },
1718
+ { name: "keys", summary: "List your account's API keys." },
1719
+ { 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"] },
1720
+ { name: "org", summary: "List, switch and make the accounts you belong to." },
1721
+ { name: "members", summary: "List or remove the members of a team." },
1722
+ { name: "invite", summary: "Invite someone to your team by email." },
1723
+ { name: "billing", summary: "Your plan, credits, invoices and card, and buying credits.", examples: ["agental billing", "agental billing invoices", "agental billing top-up 500"] },
1724
+ { name: "headroom", summary: "How close you run to your plan's limits, and your burst budget." },
1725
+ { name: "account", summary: "Export everything agental keeps about your account and you." },
1726
+ { name: "login", summary: "Sign in through the browser, or with a key from standard input." },
1727
+ { name: "logout", summary: "Delete this computer's key from your account and from here." },
1728
+ { name: "whoami", summary: "Who the command is signed in as, and with which key." },
1729
+ { name: "version", summary: "Print the version of agental." },
1730
+ { name: "suspend", summary: "Suspend an account.", operator: true },
1731
+ { name: "unsuspend", summary: "Lift an account's suspension.", operator: true },
1732
+ { name: "suspensions", summary: "List suspended accounts.", operator: true },
1733
+ { name: "smoke", summary: "Make a sandbox, try what it does, and delete it.", operator: true }
1734
+ ];
1735
+ var MAP = [
1736
+ [
1737
+ "Start here",
1738
+ [
1739
+ ["sh", "make a sandbox and open a shell in it"],
1740
+ ["create", "make a sandbox"],
1741
+ ["list", "your sandboxes"],
1742
+ ["exec", "run a command in a sandbox"],
1743
+ ["shell, ssh", "open a shell in a sandbox, here or over SSH"]
1744
+ ]
1745
+ ],
1746
+ [
1747
+ "Sandboxes",
1748
+ [
1749
+ ["start, stop, delete", "one sandbox, or every one --where finds"],
1750
+ ["recover, auto-stop", "get a stuck one going, say when one stops"],
1751
+ ["schedule", "run a command on a timer"],
1752
+ ["secrets", "values and files kept out of the sandbox"],
1753
+ ["network, egress", "what it may reach, and the address it leaves from"],
1754
+ ["tags, meta, summary", "label sandboxes and find them again"],
1755
+ ["metrics", "CPU, memory and disk over time"],
1756
+ ["email", "an email address of its own"],
1757
+ ["desktop, browser", "a screen and a Chrome in the sandbox"],
1758
+ ["scp, ssh-config", "files, and SSH from any tool"],
1759
+ ["jobs, regions", "work on many at once, and where they run"]
1760
+ ]
1761
+ ],
1762
+ [
1763
+ "Account",
1764
+ [
1765
+ ["templates, template", "what new sandboxes start from"],
1766
+ ["billing", "plan, credits, invoices and card"],
1767
+ ["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"],
1771
+ ["telemetry", "metrics and events sent to your collector"],
1772
+ ["ci, claude", "GitHub Actions and Claude agents on sandboxes"],
1773
+ ["data-retention", "how long your sandboxes' history is kept"],
1774
+ ["account", "everything agental keeps about you"]
1775
+ ]
1776
+ ],
1777
+ ["You", [["login, logout, whoami", "who the command is signed in as"]]]
1778
+ ];
1779
+ var DOCS = "https://agental.io/docs/cli";
1780
+ function shortHelp() {
1781
+ const width = Math.max(...MAP.flatMap(([, rows]) => rows.map(([names]) => names.length))) + 3;
1782
+ const lines = [`${strong("agental")} \xB7 Linux sandboxes for your agents`, "", `${strong("Usage")} agental <command> [flags]`];
1783
+ for (const [group, rows] of MAP) {
1784
+ lines.push("", strong(group));
1785
+ for (const [names, what] of rows) {
1786
+ const painted = names.split(", ").map((name) => command(name)).join(", ");
1787
+ lines.push(` ${painted}${" ".repeat(width - names.length)}${what}`);
1788
+ }
1789
+ }
1790
+ lines.push("", faint(`agental <command> --help its flags and examples`), faint(`agental help --all everything, as one page`), faint(DOCS), "");
1791
+ return lines.join("\n");
1792
+ }
1793
+ function usageOf(reference) {
1794
+ const found = /* @__PURE__ */ new Map();
1795
+ let open = null;
1796
+ for (const line of reference.split("\n")) {
1797
+ const start = /^ {2}agental ([a-z][a-z-]*)\b/.exec(line);
1798
+ if (start) {
1799
+ const name = start[1];
1800
+ open = found.get(name) ?? [];
1801
+ open.push(line.trim());
1802
+ found.set(name, open);
1803
+ } else if (open !== null && /^ {3,}\S/.test(line)) {
1804
+ open[open.length - 1] = `${open[open.length - 1]} ${line.trim()}`;
1805
+ } else {
1806
+ open = null;
1807
+ }
1808
+ }
1809
+ return found;
1810
+ }
1811
+ function foldUsage(usage, width) {
1812
+ const said = /^(.*?\S) {3,}(\S.*)$/.exec(usage);
1813
+ const line = said ? said[1] : usage;
1814
+ const note = said ? said[2] : null;
1815
+ const head = /^agental [a-z-]+ /.exec(line)?.[0] ?? "agental ";
1816
+ const indent = " ".repeat(Math.min(head.length, 24) + 2);
1817
+ const parts = [];
1818
+ let depth = 0;
1819
+ let part = "";
1820
+ for (const char of line.slice(head.length)) {
1821
+ depth += char === "[" || char === "(" ? 1 : char === "]" || char === ")" ? -1 : 0;
1822
+ if (char === " " && depth === 0) {
1823
+ parts.push(part);
1824
+ part = "";
1825
+ } else {
1826
+ part += char;
1827
+ }
1828
+ }
1829
+ parts.push(part);
1830
+ parts.splice(0, parts.length, ...parts.filter((each) => each !== ""));
1831
+ const lines = [];
1832
+ let current = ` ${head.trimEnd()}`;
1833
+ for (const part2 of parts) {
1834
+ if (current.length + 1 + part2.length > width && current.trim().length > head.trim().length) {
1835
+ lines.push(current);
1836
+ current = `${indent}${part2}`;
1837
+ } else {
1838
+ current = `${current} ${part2}`;
1839
+ }
1840
+ }
1841
+ lines.push(current);
1842
+ if (note) {
1843
+ lines.push(`${indent}${faint(note)}`);
1844
+ }
1845
+ return lines;
1846
+ }
1847
+ function commandHelp(name, reference, operator) {
1848
+ const found = COMMANDS.find((each) => each.name === name && (operator || !each.operator));
1849
+ if (!found) {
1850
+ return null;
1851
+ }
1852
+ const width = Math.min(Math.max(process.stdout.columns ?? 100, 60), 110);
1853
+ const usages = usageOf(reference).get(name) ?? [];
1854
+ const lines = [found.summary, ""];
1855
+ if (usages.length > 0) {
1856
+ lines.push(strong("Usage"));
1857
+ for (const usage of usages) {
1858
+ lines.push(...foldUsage(usage, width));
1859
+ }
1860
+ lines.push("");
1861
+ }
1862
+ if (found.examples) {
1863
+ lines.push(strong("Examples"), ...found.examples.map((example) => ` ${command(example)}`), "");
1864
+ }
1865
+ if (found.flags) {
1866
+ const pad3 = Math.max(...found.flags.map(([flag]) => flag.length)) + 2;
1867
+ lines.push(strong("Flags"), ...found.flags.map(([flag, what]) => ` ${flag.padEnd(pad3)}${what}`), "");
1868
+ }
1869
+ lines.push(faint(`More: agental help --all, or ${DOCS}`), "");
1870
+ return lines.join("\n");
1871
+ }
1872
+ function nearest(word, words2) {
1873
+ let best = null;
1874
+ let bestDistance = Infinity;
1875
+ for (const candidate of words2) {
1876
+ const distance = editDistance(word.toLowerCase(), candidate);
1877
+ if (distance < bestDistance) {
1878
+ best = candidate;
1879
+ bestDistance = distance;
1880
+ }
1881
+ }
1882
+ return best !== null && bestDistance <= Math.max(1, Math.min(2, Math.floor(word.length / 3))) ? best : null;
1883
+ }
1884
+ function editDistance(a, b) {
1885
+ const rows = Array.from({ length: a.length + 1 }, (_, i) => Array.from({ length: b.length + 1 }, (_2, j) => i === 0 ? j : j === 0 ? i : 0));
1886
+ for (let i = 1; i <= a.length; i++) {
1887
+ for (let j = 1; j <= b.length; j++) {
1888
+ const row = rows[i];
1889
+ const above = rows[i - 1];
1890
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
1891
+ row[j] = Math.min(above[j] + 1, row[j - 1] + 1, above[j - 1] + cost);
1892
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
1893
+ row[j] = Math.min(row[j], rows[i - 2][j - 2] + 1);
1894
+ }
1895
+ }
1896
+ }
1897
+ return rows[a.length][b.length];
1898
+ }
1899
+ function noSuchCommand(word, operator) {
1900
+ const near = nearest(
1901
+ word,
1902
+ COMMANDS.filter((each) => operator || !each.operator).map((each) => each.name)
1903
+ );
1904
+ const stream = process.stderr;
1905
+ return `${bad("agental:", stream)} there is no command ${word}.${near ? ` Did you mean ${command(near, stream)}?` : ""}
1906
+ ${faint("agental help lists every command.", stream)}
1907
+ `;
1908
+ }
1909
+
1635
1910
  // ../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.";
1911
+ var ORG_USAGE = "org takes list, use <organization> or create <name>. agental org --help shows each.";
1912
+ var MEMBERS_USAGE = "members takes list, or remove <member> [--revoke-keys]. agental members --help shows each.";
1638
1913
  var ROLES = ["member", "admin"];
1639
1914
  async function ask4(client, method, pathname, body) {
1640
1915
  const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
@@ -1811,7 +2086,7 @@ async function invite(client, positionals, options) {
1811
2086
  }
1812
2087
 
1813
2088
  // ../src/cli-schedules.ts
1814
- var USAGE3 = "schedule takes add, show, runs, run, pause, resume, update or delete. agental help shows each.";
2089
+ var USAGE3 = "schedule takes add, show, runs, run, pause, resume, update or delete. agental schedule --help shows each.";
1815
2090
  var OVERLAPS = ["skip", "replace", "parallel"];
1816
2091
  async function ask5(client, method, pathname, body) {
1817
2092
  const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
@@ -1997,8 +2272,8 @@ async function schedule(client, positionals, options) {
1997
2272
  case "resume":
1998
2273
  case "delete":
1999
2274
  case "update": {
2000
- const [target, ...command] = rest;
2001
- if (command.length > 0 && what !== "update") {
2275
+ const [target, ...command2] = rest;
2276
+ if (command2.length > 0 && what !== "update") {
2002
2277
  throw new Error(USAGE3);
2003
2278
  }
2004
2279
  const id = await idOf2(client, sandboxId, target, what);
@@ -2045,7 +2320,7 @@ async function schedule(client, positionals, options) {
2045
2320
  process.stdout.write(`Deleted ${id}, with its runs.
2046
2321
  `);
2047
2322
  } else {
2048
- const changes = { ...fieldsOf(options), ...command.length > 0 ? { command: commandLine(command) } : {} };
2323
+ const changes = { ...fieldsOf(options), ...command2.length > 0 ? { command: commandLine(command2) } : {} };
2049
2324
  if (Object.keys(changes).length === 0) {
2050
2325
  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
2326
  }
@@ -2090,7 +2365,7 @@ var WEBHOOK_GROUPS = [...new Set(WEBHOOK_KINDS.map((kind) => kind.slice(0, kind.
2090
2365
  var WEBHOOK_RETRY_AFTER_MS = [6e4, 5 * 6e4, 15 * 6e4, 60 * 6e4, 3 * 36e5, 6 * 36e5, 12 * 36e5];
2091
2366
 
2092
2367
  // ../src/cli-webhooks.ts
2093
- var USAGE4 = "webhook takes add, show, update, rotate or delete. agental help shows each.";
2368
+ var USAGE4 = "webhook takes add, show, update, rotate or delete. agental webhook --help shows each.";
2094
2369
  var EVERY = "*";
2095
2370
  var TRIES = WEBHOOK_RETRY_AFTER_MS.length + 1;
2096
2371
  async function ask6(client, method, pathname, body) {
@@ -2333,7 +2608,7 @@ function needId(id, what) {
2333
2608
  }
2334
2609
 
2335
2610
  // ../src/cli-claude.ts
2336
- var USAGE5 = "claude takes connect, show, update or disconnect. agental help shows each.";
2611
+ var USAGE5 = "claude takes connect, show, update or disconnect. agental claude --help shows each.";
2337
2612
  var KEY_VARIABLE = "ANTHROPIC_ENVIRONMENT_KEY";
2338
2613
  var SECRET_VARIABLE = "ANTHROPIC_WEBHOOK_SIGNING_KEY";
2339
2614
  async function ask7(client, method, pathname, body) {
@@ -2891,23 +3166,23 @@ var SSH_COMMANDS = {
2891
3166
  "ssh-connect": sshConnect
2892
3167
  };
2893
3168
  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";
3169
+ const [command2, ...rest] = args;
3170
+ const onboarding = command2 === void 0 || command2 === "sh" || command2 === "--no-skills" || command2 === "--no-install" || command2 === "--json";
2896
3171
  if (onboarding) {
2897
- const flags2 = command === "sh" ? rest : args;
3172
+ const flags2 = command2 === "sh" ? rest : args;
2898
3173
  const unknown = flags2.filter((flag) => !["--json", "--no-skills", "--no-install"].includes(flag));
2899
3174
  if (unknown.length > 0) {
2900
- throw new Error(`${command === "sh" ? "sh" : "agental"} takes --json, --no-skills and --no-install, not ${unknown.join(" ")}`);
3175
+ throw new Error(`${command2 === "sh" ? "sh" : "agental"} takes --json, --no-skills and --no-install, not ${unknown.join(" ")}`);
2901
3176
  }
2902
3177
  await onboard(apiBase(), {
2903
- sandbox: command === "sh",
3178
+ sandbox: command2 === "sh",
2904
3179
  json: flags2.includes("--json"),
2905
3180
  installCommand: !flags2.includes("--no-install"),
2906
3181
  installSkills: !flags2.includes("--no-skills")
2907
3182
  });
2908
3183
  return true;
2909
3184
  }
2910
- switch (command) {
3185
+ switch (command2) {
2911
3186
  case "--version":
2912
3187
  case "-v":
2913
3188
  case "version":
@@ -2930,7 +3205,45 @@ async function setUp(args) {
2930
3205
  return false;
2931
3206
  }
2932
3207
  }
3208
+ async function helpAsked(args) {
3209
+ const own = args.indexOf("--");
3210
+ const ours = own < 0 ? args : args.slice(0, own);
3211
+ const [first, second] = ours;
3212
+ const asked2 = (word) => word === "--help" || word === "-h";
3213
+ const operator = !PUBLISHED;
3214
+ let topic;
3215
+ if ((first === "help" || asked2(first)) && ours.includes("--all")) {
3216
+ process.stdout.write(await helpText());
3217
+ return true;
3218
+ }
3219
+ if (first === "help") {
3220
+ topic = second === "help" ? void 0 : second;
3221
+ } else if (asked2(first)) {
3222
+ topic = void 0;
3223
+ } else if (first !== void 0 && first.startsWith("-") && ours.some(asked2)) {
3224
+ topic = void 0;
3225
+ } else if (first !== void 0 && (SSH_COMMANDS[first] ? asked2(second) : ours.some(asked2))) {
3226
+ topic = first;
3227
+ } else {
3228
+ return false;
3229
+ }
3230
+ if (topic === void 0) {
3231
+ process.stdout.write(isTerminal(process.stdout) ? shortHelp() : await helpText());
3232
+ return true;
3233
+ }
3234
+ const one = commandHelp(topic, await helpText(), operator);
3235
+ if (one === null) {
3236
+ process.stderr.write(noSuchCommand(topic, operator));
3237
+ process.exitCode = 1;
3238
+ return true;
3239
+ }
3240
+ process.stdout.write(one);
3241
+ return true;
3242
+ }
2933
3243
  async function main() {
3244
+ if (await helpAsked(process.argv.slice(2))) {
3245
+ return;
3246
+ }
2934
3247
  if (await setUp(process.argv.slice(2))) {
2935
3248
  return;
2936
3249
  }
@@ -2943,11 +3256,11 @@ async function main() {
2943
3256
  args: process.argv.slice(2),
2944
3257
  allowPositionals: true,
2945
3258
  options: {
2946
- name: { type: "string" },
3259
+ name: { type: "string", short: "n" },
2947
3260
  // Left out, a new sandbox is the size its template starts sandboxes as.
2948
- size: { type: "string" },
3261
+ size: { type: "string", short: "s" },
2949
3262
  // Given more than once only to key add, as a key may be limited to several.
2950
- template: { type: "string", multiple: true },
3263
+ template: { type: "string", multiple: true, short: "t" },
2951
3264
  snapshot: { type: "string" },
2952
3265
  "new-machine": { type: "boolean", default: false },
2953
3266
  remove: { type: "boolean", default: false },
@@ -3052,12 +3365,12 @@ async function main() {
3052
3365
  help: { type: "boolean", short: "h", default: false }
3053
3366
  }
3054
3367
  });
3055
- const command = positionals[0];
3056
- if (values.help || !command || command === "help") {
3057
- process.stdout.write(await helpText());
3368
+ const command2 = positionals[0];
3369
+ if (!command2) {
3370
+ process.stdout.write(isTerminal(process.stdout) ? shortHelp() : await helpText());
3058
3371
  return;
3059
3372
  }
3060
- switch (command) {
3373
+ switch (command2) {
3061
3374
  case "create":
3062
3375
  await create({ ...values, template: once(values.template, "--template") });
3063
3376
  return;
@@ -3232,10 +3545,10 @@ async function main() {
3232
3545
  case "unsuspend":
3233
3546
  case "suspensions": {
3234
3547
  if (PUBLISHED) {
3235
- throw new Error(`${command} is for whoever runs agental, from its repository.`);
3548
+ throw new Error(`${command2} is for whoever runs agental, from its repository.`);
3236
3549
  }
3237
3550
  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);
3551
+ await suspensions2({ request, fail }, command2, positionals[1], values.reason, values.json);
3239
3552
  return;
3240
3553
  }
3241
3554
  case "smoke": {
@@ -3247,9 +3560,7 @@ async function main() {
3247
3560
  return;
3248
3561
  }
3249
3562
  default:
3250
- process.stderr.write(`Unknown command ${command}
3251
-
3252
- ${await helpText()}`);
3563
+ process.stderr.write(noSuchCommand(command2, !PUBLISHED));
3253
3564
  process.exitCode = 1;
3254
3565
  }
3255
3566
  }
@@ -3261,7 +3572,7 @@ function once(given, name) {
3261
3572
  }
3262
3573
  async function create(values) {
3263
3574
  if (!values.name) {
3264
- throw new Error("create requires --name");
3575
+ throw new Error("create needs --name: what to call the sandbox, as agental create --name review-pr-218.");
3265
3576
  }
3266
3577
  const given = labelsGiven(values);
3267
3578
  const burstHeaders = maxBurstFeeHeaders(values["max-burst-fee"]);
@@ -3638,13 +3949,13 @@ async function jobs(positionals, asJson) {
3638
3949
  }
3639
3950
  async function exec(positionals) {
3640
3951
  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...]");
3952
+ const command2 = positionals.slice(1);
3953
+ if (!id || command2.length === 0) {
3954
+ 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
3955
  }
3645
3956
  const response = await request(`/v1/sandboxes/${encodeURIComponent(id)}/exec`, {
3646
3957
  method: "POST",
3647
- body: JSON.stringify({ command })
3958
+ body: JSON.stringify({ command: command2 })
3648
3959
  });
3649
3960
  const body = await readBody(response);
3650
3961
  if (!response.ok) {
@@ -4081,10 +4392,10 @@ function labelsInWords(body) {
4081
4392
  }
4082
4393
  async function labels(what, holder, positionals, asJson) {
4083
4394
  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>...]`;
4395
+ const command2 = `${holder === "template" ? "template " : ""}${what}`;
4396
+ const usage = what === "tags" ? `${command2} <${holder}> [add|rm <tag>...]` : `${command2} <${holder}> [set <key>=<value>... | unset <key>...]`;
4086
4397
  if (!named) {
4087
- throw new Error(`${command} requires <${holder}>: ${usage}`);
4398
+ throw new Error(`${command2} requires <${holder}>: ${usage}`);
4088
4399
  }
4089
4400
  const id = holder === "template" ? (await templateNamed(named)).id : named;
4090
4401
  const path4 = `/v1/${holder === "template" ? "templates" : "sandboxes"}/${encodeURIComponent(id)}`;
@@ -4094,23 +4405,23 @@ async function labels(what, holder, positionals, asJson) {
4094
4405
  } else if (what === "tags" && (action === "add" || action === "rm")) {
4095
4406
  const tags = listedIn(words2).map((tag) => tag.toLowerCase());
4096
4407
  if (tags.length === 0) {
4097
- throw new Error(`${command} ${action} requires <tag>...`);
4408
+ throw new Error(`${command2} ${action} requires <tag>...`);
4098
4409
  }
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)}.`);
4410
+ const bad2 = tags.find((tag) => !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(tag));
4411
+ if (bad2 !== void 0) {
4412
+ 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
4413
  }
4103
4414
  for (const tag of tags) {
4104
4415
  body = await call2(`${path4}/tags/${encodeURIComponent(tag)}`, { method: action === "add" ? "PUT" : "DELETE" });
4105
4416
  }
4106
4417
  } else if (what === "meta" && (action === "set" || action === "unset")) {
4107
4418
  if (words2.length === 0) {
4108
- throw new Error(`${command} ${action} requires ${action === "set" ? "<key>=<value>" : "<key>"}...`);
4419
+ throw new Error(`${command2} ${action} requires ${action === "set" ? "<key>=<value>" : "<key>"}...`);
4109
4420
  }
4110
4421
  const metadata = action === "set" ? metadataGiven(words2) : Object.fromEntries(words2.map((key2) => [key2, null]));
4111
4422
  body = await call2(path4, { method: "PATCH", body: JSON.stringify({ metadata }) });
4112
4423
  } else {
4113
- throw new Error(`${command} takes ${usage}`);
4424
+ throw new Error(`${command2} takes ${usage}`);
4114
4425
  }
4115
4426
  process.stdout.write(asJson ? `${JSON.stringify(body, null, 2)}
4116
4427
  ` : labelsInWords(body));
@@ -4300,7 +4611,7 @@ function showTemplate(each) {
4300
4611
  }
4301
4612
  async function template(positionals, values) {
4302
4613
  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.";
4614
+ 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
4615
  const print4 = (body, words2) => {
4305
4616
  process.stdout.write(values.json ? `${JSON.stringify(body, null, 2)}
4306
4617
  ` : words2);
@@ -4901,7 +5212,9 @@ async function telemetry(positionals, given, asJson) {
4901
5212
  }
4902
5213
  async function billing(positionals, asJson, limit) {
4903
5214
  const [what, amount, ...rest] = positionals;
4904
- const usage = "billing takes nothing, prices, invoices, card, top-up <dollars>, or auto-reload <dollars | off>";
5215
+ const kinds = ["prices", "invoices", "card", "top-up", "auto-reload"];
5216
+ 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>`;
4905
5218
  if (rest.length > 0 || what !== "top-up" && what !== "auto-reload" && amount !== void 0) {
4906
5219
  throw new Error(usage);
4907
5220
  }
@@ -4912,8 +5225,8 @@ async function billing(positionals, asJson, limit) {
4912
5225
  ` : text());
4913
5226
  switch (what) {
4914
5227
  case void 0: {
4915
- const [body, card] = await Promise.all([asked("/v1/billing", { method: "GET" }), asJson ? null : cardOnFile()]);
4916
- print4(body, () => describeBilling(body, card));
5228
+ const [body, card] = await Promise.all([asked("/v1/billing", { method: "GET" }), cardOnFile()]);
5229
+ print4({ ...body, card }, () => describeBilling(body, card));
4917
5230
  return;
4918
5231
  }
4919
5232
  case "invoices": {
@@ -5854,6 +6167,11 @@ main().catch((error) => {
5854
6167
  const message = error instanceof Error ? error.message : "Command failed";
5855
6168
  process.stderr.write(`${message}
5856
6169
  `);
6170
+ const word = process.argv[2];
6171
+ if (error instanceof Error && isTerminal(process.stderr) && COMMANDS.some((each) => each.name === word && (!each.operator || !PUBLISHED))) {
6172
+ process.stderr.write(`${faint(`agental ${word} --help shows what it takes.`, process.stderr)}
6173
+ `);
6174
+ }
5857
6175
  process.exit(1);
5858
6176
  });
5859
6177
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agental",
3
- "version": "0.10.0",
3
+ "version": "0.11.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",