agental 0.9.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.
- package/dist/cli.js +485 -59
- 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.
|
|
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,
|
|
177
|
+
async function state(client, method, sandboxId, command2, options) {
|
|
178
178
|
if (!sandboxId) {
|
|
179
|
-
throw new Error(`${
|
|
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(([
|
|
1528
|
+
const width = Math.max(...rows.map(([command2]) => command2.length));
|
|
1529
1529
|
term.say(`
|
|
1530
1530
|
${bold("Next")}`);
|
|
1531
|
-
for (const [
|
|
1532
|
-
term.say(` ${
|
|
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, ...
|
|
2001
|
-
if (
|
|
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), ...
|
|
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 [
|
|
2895
|
-
const onboarding =
|
|
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 =
|
|
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(`${
|
|
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:
|
|
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 (
|
|
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
|
|
3056
|
-
if (
|
|
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 (
|
|
3373
|
+
switch (command2) {
|
|
3061
3374
|
case "create":
|
|
3062
3375
|
await create({ ...values, template: once(values.template, "--template") });
|
|
3063
3376
|
return;
|
|
@@ -3220,7 +3533,7 @@ async function main() {
|
|
|
3220
3533
|
await key({ request, fail }, positionals.slice(1), values);
|
|
3221
3534
|
return;
|
|
3222
3535
|
case "billing":
|
|
3223
|
-
await billing(positionals.slice(1), values.json);
|
|
3536
|
+
await billing(positionals.slice(1), values.json, values.limit);
|
|
3224
3537
|
return;
|
|
3225
3538
|
case "headroom":
|
|
3226
3539
|
await headroom(positionals.slice(1), { json: values.json, from: values.from, to: values.to, step: values.step });
|
|
@@ -3232,10 +3545,10 @@ async function main() {
|
|
|
3232
3545
|
case "unsuspend":
|
|
3233
3546
|
case "suspensions": {
|
|
3234
3547
|
if (PUBLISHED) {
|
|
3235
|
-
throw new Error(`${
|
|
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 },
|
|
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(
|
|
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
|
|
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
|
|
3642
|
-
if (!id ||
|
|
3643
|
-
throw new Error("exec
|
|
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
|
|
4085
|
-
const usage = what === "tags" ? `${
|
|
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(`${
|
|
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(`${
|
|
4408
|
+
throw new Error(`${command2} ${action} requires <tag>...`);
|
|
4098
4409
|
}
|
|
4099
|
-
const
|
|
4100
|
-
if (
|
|
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(
|
|
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(`${
|
|
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(`${
|
|
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);
|
|
@@ -4899,18 +5210,27 @@ async function telemetry(positionals, given, asJson) {
|
|
|
4899
5210
|
throw new Error(usage);
|
|
4900
5211
|
}
|
|
4901
5212
|
}
|
|
4902
|
-
async function billing(positionals, asJson) {
|
|
5213
|
+
async function billing(positionals, asJson, limit) {
|
|
4903
5214
|
const [what, amount, ...rest] = positionals;
|
|
4904
|
-
const
|
|
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
|
}
|
|
5221
|
+
if (limit !== void 0 && what !== "invoices") {
|
|
5222
|
+
throw new Error("--limit is taken by billing invoices alone.");
|
|
5223
|
+
}
|
|
4908
5224
|
const print4 = (body, text) => process.stdout.write(asJson ? `${JSON.stringify(body, null, 2)}
|
|
4909
5225
|
` : text());
|
|
4910
5226
|
switch (what) {
|
|
4911
5227
|
case void 0: {
|
|
4912
|
-
const body = await asked("/v1/billing", { method: "GET" });
|
|
4913
|
-
print4(body, () => describeBilling(body));
|
|
5228
|
+
const [body, card] = await Promise.all([asked("/v1/billing", { method: "GET" }), cardOnFile()]);
|
|
5229
|
+
print4({ ...body, card }, () => describeBilling(body, card));
|
|
5230
|
+
return;
|
|
5231
|
+
}
|
|
5232
|
+
case "invoices": {
|
|
5233
|
+
await invoices(asJson, limit);
|
|
4914
5234
|
return;
|
|
4915
5235
|
}
|
|
4916
5236
|
case "prices": {
|
|
@@ -4974,14 +5294,17 @@ function wholeMoney(micros) {
|
|
|
4974
5294
|
function dayOf(iso) {
|
|
4975
5295
|
return iso ? new Date(iso).toLocaleDateString("en-GB", { day: "numeric", month: "long", timeZone: "UTC" }) : "";
|
|
4976
5296
|
}
|
|
4977
|
-
function describeBilling(body) {
|
|
5297
|
+
function describeBilling(body, card = null) {
|
|
4978
5298
|
const lines = [];
|
|
4979
5299
|
const free = body.free ?? null;
|
|
4980
5300
|
if (free && body.plan) {
|
|
4981
5301
|
lines.push(["Plan", "free: nothing a month. What runs is paid from your credits, at list price."]);
|
|
4982
5302
|
if (!free.cardSaved) {
|
|
4983
5303
|
lines.push(["Card", "none saved. Save one, charged nothing, to run sandboxes and be given the free plan's credit: agental billing card."]);
|
|
4984
|
-
} else if (
|
|
5304
|
+
} else if (card) {
|
|
5305
|
+
lines.push(["Card", describeCard(card)]);
|
|
5306
|
+
}
|
|
5307
|
+
if (free.cardSaved && !free.paid) {
|
|
4985
5308
|
lines.push(["At once", `${free.unpaidUnits} small sandboxes until you buy a top-up, then ${(body.plan.runningUnits ?? 20).toLocaleString("en-US")}. A tiny counts half.`]);
|
|
4986
5309
|
}
|
|
4987
5310
|
lines.push(["Used", `${money(body.usedMicros)} this month at list price${usedParts(body)}`]);
|
|
@@ -5006,6 +5329,9 @@ function describeBilling(body) {
|
|
|
5006
5329
|
const charged = body.usedMicros - (body.discount?.micros ?? 0) + (body.carriedMicros ?? 0);
|
|
5007
5330
|
lines.push(["Included", `${money(body.includedMicros)}, ${money(Math.max(0, body.includedMicros - charged))} left. It does not carry over.`]);
|
|
5008
5331
|
lines.push(["Top-ups left", `${money(body.topUpMicros)}, used after the plan's credits. They do not expire.`]);
|
|
5332
|
+
if (card) {
|
|
5333
|
+
lines.push(["Card", describeCard(card)]);
|
|
5334
|
+
}
|
|
5009
5335
|
if (body.autoReload) {
|
|
5010
5336
|
lines.push(["Auto-reload", describeAutoReload(body.autoReload)]);
|
|
5011
5337
|
} else if (body.canAutoReload) {
|
|
@@ -5032,6 +5358,97 @@ function describeBilling(body) {
|
|
|
5032
5358
|
return lines.map(([label, value]) => `${label.padEnd(14)}${value}
|
|
5033
5359
|
`).join("");
|
|
5034
5360
|
}
|
|
5361
|
+
async function cardOnFile() {
|
|
5362
|
+
try {
|
|
5363
|
+
const response = await request("/v1/billing/card", { method: "GET" });
|
|
5364
|
+
if (!response.ok) {
|
|
5365
|
+
return null;
|
|
5366
|
+
}
|
|
5367
|
+
const body = await readBody(response);
|
|
5368
|
+
return body?.card ?? null;
|
|
5369
|
+
} catch {
|
|
5370
|
+
return null;
|
|
5371
|
+
}
|
|
5372
|
+
}
|
|
5373
|
+
var CARD_BRANDS = {
|
|
5374
|
+
amex: "American Express",
|
|
5375
|
+
diners: "Diners Club",
|
|
5376
|
+
discover: "Discover",
|
|
5377
|
+
eftpos_au: "eftpos",
|
|
5378
|
+
jcb: "JCB",
|
|
5379
|
+
link: "Link",
|
|
5380
|
+
mastercard: "Mastercard",
|
|
5381
|
+
unionpay: "UnionPay",
|
|
5382
|
+
visa: "Visa"
|
|
5383
|
+
};
|
|
5384
|
+
var WALLETS = { apple_pay: "Apple Pay", google_pay: "Google Pay", link: "Link", samsung_pay: "Samsung Pay" };
|
|
5385
|
+
function describeCard(card) {
|
|
5386
|
+
const brand = (card.brand ? CARD_BRANDS[card.brand] : void 0) ?? (card.brand ? card.brand.charAt(0).toUpperCase() + card.brand.slice(1) : "Card");
|
|
5387
|
+
const ending = card.last4 ? ` ending ${card.last4}` : "";
|
|
5388
|
+
const expires = card.expMonth !== null && card.expYear !== null ? `, expires ${String(card.expMonth).padStart(2, "0")}/${String(card.expYear % 100).padStart(2, "0")}` : "";
|
|
5389
|
+
const wallet = card.wallet ? `, through ${WALLETS[card.wallet] ?? card.wallet}` : "";
|
|
5390
|
+
return `${brand}${ending}${expires}${wallet}. It is changed in the console, under Billing.`;
|
|
5391
|
+
}
|
|
5392
|
+
async function invoices(asJson, limit) {
|
|
5393
|
+
if (limit !== void 0 && (!/^\d+$/.test(limit) || Number(limit) < 1 || Number(limit) > 100)) {
|
|
5394
|
+
throw new Error("billing invoices --limit takes how many of the newest invoices to list, a whole number from 1 to 100.");
|
|
5395
|
+
}
|
|
5396
|
+
const wanted = limit === void 0 ? Infinity : Number(limit);
|
|
5397
|
+
const listed = [];
|
|
5398
|
+
let after = null;
|
|
5399
|
+
do {
|
|
5400
|
+
const query = new URLSearchParams({ limit: String(Math.min(100, wanted - listed.length)) });
|
|
5401
|
+
if (after !== null) {
|
|
5402
|
+
query.set("startingAfter", after);
|
|
5403
|
+
}
|
|
5404
|
+
const body = await asked(`/v1/billing/invoices?${query}`, { method: "GET" });
|
|
5405
|
+
listed.push(...body.invoices);
|
|
5406
|
+
after = body.next === after ? null : body.next;
|
|
5407
|
+
} while (after !== null && listed.length < wanted);
|
|
5408
|
+
listed.splice(wanted);
|
|
5409
|
+
if (after !== null) {
|
|
5410
|
+
process.stderr.write("There are older invoices. Drop --limit to list them all.\n");
|
|
5411
|
+
}
|
|
5412
|
+
if (asJson) {
|
|
5413
|
+
process.stdout.write(`${JSON.stringify(listed, null, 2)}
|
|
5414
|
+
`);
|
|
5415
|
+
return;
|
|
5416
|
+
}
|
|
5417
|
+
if (listed.length === 0) {
|
|
5418
|
+
process.stdout.write("No invoices yet. A plan's month, a top-up or an auto-reload makes one once it is charged.\n");
|
|
5419
|
+
return;
|
|
5420
|
+
}
|
|
5421
|
+
const rows = listed.map((invoice) => [
|
|
5422
|
+
shortDayOf(invoice.createdAt),
|
|
5423
|
+
invoice.number ?? "-",
|
|
5424
|
+
INVOICE_STATES[invoice.status] ?? invoice.status,
|
|
5425
|
+
amountOf(invoice.totalMicros, invoice.currency),
|
|
5426
|
+
invoice.description ?? ""
|
|
5427
|
+
]);
|
|
5428
|
+
const widths = [0, 1, 2, 3].map((column) => Math.max(...rows.map((row) => row[column]?.length ?? 0)));
|
|
5429
|
+
for (const row of rows) {
|
|
5430
|
+
const [day, number, state2, total, what] = row;
|
|
5431
|
+
process.stdout.write(`${day.padEnd(widths[0] ?? 0)} ${number.padEnd(widths[1] ?? 0)} ${state2.padEnd(widths[2] ?? 0)} ${total.padStart(widths[3] ?? 0)} ${what}`.trimEnd() + "\n");
|
|
5432
|
+
}
|
|
5433
|
+
for (const invoice of listed.filter((each) => each.status === "open" && each.pageUrl)) {
|
|
5434
|
+
process.stdout.write(`${invoice.number ?? invoice.id} is not paid yet. Pay it at:
|
|
5435
|
+
${invoice.pageUrl}
|
|
5436
|
+
`);
|
|
5437
|
+
}
|
|
5438
|
+
if (listed.some((each) => each.pdfUrl)) {
|
|
5439
|
+
process.stdout.write("--json gives each one's page and PDF.\n");
|
|
5440
|
+
}
|
|
5441
|
+
}
|
|
5442
|
+
var INVOICE_STATES = { open: "not paid", paid: "paid", void: "void", uncollectible: "written off" };
|
|
5443
|
+
function amountOf(micros, currency) {
|
|
5444
|
+
if (currency.toLowerCase() === "usd") {
|
|
5445
|
+
return money(micros);
|
|
5446
|
+
}
|
|
5447
|
+
return `${(micros / 1e6).toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })} ${currency.toUpperCase()}`;
|
|
5448
|
+
}
|
|
5449
|
+
function shortDayOf(iso) {
|
|
5450
|
+
return new Date(iso).toLocaleDateString("en-GB", { day: "numeric", month: "short", year: "numeric", timeZone: "UTC" });
|
|
5451
|
+
}
|
|
5035
5452
|
function usedParts(body) {
|
|
5036
5453
|
const parts = [
|
|
5037
5454
|
...(body.mailMicros ?? 0) > 0 ? [`${money(body.mailMicros ?? 0)} by email`] : [],
|
|
@@ -5472,6 +5889,7 @@ Usage
|
|
|
5472
5889
|
agental key allow-from <key> (<address-or-range>... | --anywhere) [--json]
|
|
5473
5890
|
agental key delete <key>
|
|
5474
5891
|
agental billing [prices | card | top-up <dollars> | auto-reload <dollars | off>] [--json]
|
|
5892
|
+
agental billing invoices [--limit <n>] [--json]
|
|
5475
5893
|
agental headroom [--from <day or date-time>] [--to <day or date-time>] [--step 10m|hour|day] [--json]
|
|
5476
5894
|
agental headroom budget <dollars> | budget default [--json]
|
|
5477
5895
|
agental egress [budget <dollars> | budget default] [--json]
|
|
@@ -5660,8 +6078,11 @@ from its next request, and the sandboxes it made stay. Limit a key used inside a
|
|
|
5660
6078
|
server it is on, which changes when it moves. On a network with IPv6 the API sees your IPv6
|
|
5661
6079
|
address, so a key limited to IPv4 addresses alone is refused there.
|
|
5662
6080
|
billing says where your account stands: its plan, what it has used this month at list price,
|
|
5663
|
-
what is left of the month's credits,
|
|
5664
|
-
after it and do not expire
|
|
6081
|
+
what is left of the month's credits, what is left of the top-ups, which are used
|
|
6082
|
+
after it and do not expire, and the card it pays with. invoices lists the account's invoices,
|
|
6083
|
+
newest first, each with its day, number, state, total and what it was for, and where to pay
|
|
6084
|
+
one that is not paid yet; --limit lists that many of the newest, and --json gives each one's
|
|
6085
|
+
page and PDF to the account's owner. The free plan costs nothing a month and pays for what runs from
|
|
5665
6086
|
credits alone; it makes tiny and small sandboxes. prices lists the plans with the sizes each
|
|
5666
6087
|
makes, the top-ups with their bonus and the hourly price of each size. card prints the address
|
|
5667
6088
|
of a page to save a card for the free plan: nothing is charged, and once it is saved the account
|
|
@@ -5746,6 +6167,11 @@ main().catch((error) => {
|
|
|
5746
6167
|
const message = error instanceof Error ? error.message : "Command failed";
|
|
5747
6168
|
process.stderr.write(`${message}
|
|
5748
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
|
+
}
|
|
5749
6175
|
process.exit(1);
|
|
5750
6176
|
});
|
|
5751
6177
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agental",
|
|
3
|
-
"version": "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",
|