agental 0.37.0 → 0.40.2

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 +279 -50
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -7411,7 +7411,7 @@ import { parseArgs } from "node:util";
7411
7411
 
7412
7412
  // ../src/cli-build.ts
7413
7413
  var PUBLISHED = true;
7414
- var CLI_VERSION = true ? "0.37.0" : "dev";
7414
+ var CLI_VERSION = true ? "0.40.2" : "dev";
7415
7415
  var DEFAULT_API_URL = true ? "https://agental.io" : "http://127.0.0.1:8741";
7416
7416
  var PACKAGE_NAME = "agental";
7417
7417
  var USER_AGENT = `agental-cli/${CLI_VERSION}`;
@@ -8736,6 +8736,7 @@ var REMOTE = /^(?:([^@:/]+)@)?(sbx_[A-Za-z0-9]+):(.*)$/s;
8736
8736
  var ON_ITS_WAY = /* @__PURE__ */ new Set(["sandbox_migrating", "sandbox_moved", "invalid_state", "ssh_unavailable", "uncertain_operation"]);
8737
8737
  var LOOK_AGAIN_FOR_MS = 12e4;
8738
8738
  var LOOK_AGAIN_EVERY_MS = 2e3;
8739
+ var RESTORING_WAIT_MS = 10 * 6e4;
8739
8740
  var SSH_LOST = 255;
8740
8741
  var SOON_MS = 1e4;
8741
8742
  var TRIES_IN_A_ROW = 3;
@@ -8785,6 +8786,8 @@ function accessIn(record) {
8785
8786
  }
8786
8787
  async function reach(client, sandboxId, waitMs = 0) {
8787
8788
  const until2 = Date.now() + waitMs;
8789
+ const restoringUntil = Date.now() + RESTORING_WAIT_MS;
8790
+ let saidRestoring = false;
8788
8791
  for (; ; ) {
8789
8792
  try {
8790
8793
  const access = accessIn(await ask4(client, "GET", sandboxId, "")) ?? accessIn(await ask4(client, "PUT", sandboxId, ""));
@@ -8794,6 +8797,15 @@ async function reach(client, sandboxId, waitMs = 0) {
8794
8797
  }
8795
8798
  throw new Refused2("ssh_unavailable", "SSH was turned on, and the API gave no address to connect to.");
8796
8799
  } catch (error) {
8800
+ if (error instanceof Refused2 && (error.code === "sandbox_not_running" || error.code === "sandbox_archived") && Date.now() + LOOK_AGAIN_EVERY_MS <= restoringUntil && await isRestoring(client, sandboxId)) {
8801
+ if (!saidRestoring) {
8802
+ process.stderr.write(`${sandboxId} is being brought back. Waiting for it.
8803
+ `);
8804
+ saidRestoring = true;
8805
+ }
8806
+ await new Promise((resolve) => setTimeout(resolve, LOOK_AGAIN_EVERY_MS));
8807
+ continue;
8808
+ }
8797
8809
  if (!(error instanceof Refused2) || !ON_ITS_WAY.has(error.code) || Date.now() + LOOK_AGAIN_EVERY_MS > until2) {
8798
8810
  throw error;
8799
8811
  }
@@ -8801,6 +8813,13 @@ async function reach(client, sandboxId, waitMs = 0) {
8801
8813
  }
8802
8814
  }
8803
8815
  }
8816
+ async function isRestoring(client, sandboxId) {
8817
+ const response = await client.request(`/v1/sandboxes/${encodeURIComponent(sandboxId)}`, { method: "GET" });
8818
+ if (!response.ok) {
8819
+ return false;
8820
+ }
8821
+ return (await response.json()).status === "restoring";
8822
+ }
8804
8823
  async function letIn(client, sandboxId) {
8805
8824
  await ask4(client, "POST", sandboxId, "/keys", { publicKey: publicKey() });
8806
8825
  }
@@ -9460,9 +9479,21 @@ var COMMANDS = [
9460
9479
  { name: "ssh-off", summary: "Turn SSH off for a sandbox and close its port." },
9461
9480
  {
9462
9481
  name: "site",
9463
- summary: "List, add and remove a sandbox's sites: public links to its ports that anyone can open while it runs.",
9464
- examples: ["agental site sbx_2a9a47e50daec64a", "agental site add sbx_2a9a47e50daec64a 3000", "agental site rm sbx_2a9a47e50daec64a rte_0123456789abcdef"],
9465
- flags: [["--json", "list, add: print as JSON"]]
9482
+ summary: "List, add and remove a sandbox's sites, public links to its ports, and see their visits.",
9483
+ examples: [
9484
+ "agental site sbx_2a9a47e50daec64a",
9485
+ "agental site add sbx_2a9a47e50daec64a 3000",
9486
+ "agental site rm sbx_2a9a47e50daec64a rte_0123456789abcdef",
9487
+ "agental site stats sbx_2a9a47e50daec64a rte_0123456789abcdef --range 24h",
9488
+ "agental site analytics off sbx_2a9a47e50daec64a rte_0123456789abcdef",
9489
+ "agental site analytics org"
9490
+ ],
9491
+ flags: [
9492
+ ["--json", "list, add, stats, analytics: print as JSON"],
9493
+ ["--range <24h|7d>", "stats: the last 24 hours, or 7 days, the default"],
9494
+ ["--yes", "analytics off: delete the figures without asking"],
9495
+ ["--informed", "analytics org on: you have read what is kept, on Enterprise or with your own server"]
9496
+ ]
9466
9497
  },
9467
9498
  {
9468
9499
  name: "start",
@@ -9634,7 +9665,7 @@ var COMMANDS = [
9634
9665
  { name: "members", summary: "List or remove the members of a team." },
9635
9666
  { name: "invite", summary: "Invite someone to your team by email." },
9636
9667
  { name: "billing", summary: "Your plan, credits, invoices and card, and buying credits.", examples: ["agental billing", "agental billing compare", "agental billing invoices", "agental billing top-up 500"] },
9637
- { name: "headroom", summary: "How close you run to your plan's limits, and your burst budget." },
9668
+ { name: "limits", summary: "How close you run to your plan's limits, and your burst budget." },
9638
9669
  { name: "account", summary: "Export everything agental keeps about your account and you." },
9639
9670
  { name: "login", summary: "Sign in through the browser, or with a key from standard input." },
9640
9671
  { name: "logout", summary: "Delete this computer's key from your account and from here." },
@@ -9738,7 +9769,7 @@ var MAP = [
9738
9769
  [
9739
9770
  ["template", "what new sandboxes start from"],
9740
9771
  ["billing", "plan, credits, invoices and card"],
9741
- ["headroom", "how close you run to your plan's limits"],
9772
+ ["limits", "how close you run to your plan's limits"],
9742
9773
  ["key", "API keys"],
9743
9774
  ["org, member", "teams"],
9744
9775
  ["webhook", "events sent to an address of yours"],
@@ -9978,7 +10009,7 @@ var SUBCOMMANDS = {
9978
10009
  key: ["list"],
9979
10010
  webhook: ["list"],
9980
10011
  job: ["list"],
9981
- headroom: ["budget"],
10012
+ limits: ["budget"],
9982
10013
  egress: ["budget", "use-case"],
9983
10014
  telemetry: ["set", "test", "unset"],
9984
10015
  ci: ["set", "reset"],
@@ -11517,12 +11548,12 @@ var EMAIL_EVENTS = ["email.received", "email.delivered", "email.bounced"];
11517
11548
  var MEMBER_EVENTS = ["member.invited", "member.joined", "member.removed", "member.role_changed", "key.revoked"];
11518
11549
  var TEMPLATE_EVENTS = ["template.created", "template.updated", "template.secrets_changed", "template.labels_changed", "template.deleted"];
11519
11550
  var HEADROOM_EVENTS = [
11520
- "headroom.burst_started",
11521
- "headroom.burst_ended",
11522
- "headroom.refused",
11523
- "headroom.running_count_reached",
11524
- "headroom.budget_threshold",
11525
- "headroom.budget_reached"
11551
+ "limits.burst_started",
11552
+ "limits.burst_ended",
11553
+ "limits.refused",
11554
+ "limits.running_count_reached",
11555
+ "limits.budget_threshold",
11556
+ "limits.budget_reached"
11526
11557
  ];
11527
11558
  var JOB_EVENTS = ["job.created", "job.updated", "job.deleted", "job.run_started", "job.run_finished", "job.run_failed", "job.recovered", "job.paused"];
11528
11559
  var WEBHOOK_KINDS = [...WEBHOOK_EVENTS, ...EMAIL_EVENTS, ...MEMBER_EVENTS, ...TEMPLATE_EVENTS, ...HEADROOM_EVENTS, ...JOB_EVENTS];
@@ -11829,15 +11860,19 @@ function needId(id, what) {
11829
11860
  }
11830
11861
 
11831
11862
  // ../src/cli-sites.ts
11832
- var USAGE6 = "site takes a sandbox, or list, add or rm, then the sandbox. agental site --help shows each.";
11833
- async function ask8(client, method, pathname, body) {
11834
- const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
11835
- let answered = null;
11863
+ var USAGE6 = "site takes a sandbox, or list, add, rm, stats or analytics, then the sandbox. agental site --help shows each.";
11864
+ var ANALYTICS_USAGE = "site analytics takes on or off, then the sandbox and the site's id, or org, with on or off to change it.";
11865
+ var REPORT_ROWS = 5;
11866
+ async function bodyOf(response) {
11836
11867
  try {
11837
- answered = await response.json();
11868
+ return await response.json();
11838
11869
  } catch {
11839
- answered = null;
11870
+ return null;
11840
11871
  }
11872
+ }
11873
+ async function ask8(client, method, pathname, body) {
11874
+ const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
11875
+ const answered = await bodyOf(response);
11841
11876
  if (!response.ok) {
11842
11877
  client.fail(response.status, answered);
11843
11878
  }
@@ -11867,8 +11902,151 @@ function portFrom(given) {
11867
11902
  }
11868
11903
  return port;
11869
11904
  }
11905
+ async function siteOn(client, sandbox, target) {
11906
+ const found = (await sitesOf(client, sandbox)).find((route) => route.id === target);
11907
+ if (!found) {
11908
+ throw new Error(`${sandbox} has no site ${target}. agental site ${sandbox} lists its sites.`);
11909
+ }
11910
+ return found;
11911
+ }
11912
+ var printable = (name) => name.replace(new RegExp("\\p{C}", "gu"), "?");
11913
+ var reportJson = (report) => JSON.stringify(report, null, 2).replace(/[^\P{C}\n]/gu, (found) => [...Array(found.length).keys()].map((index) => `\\u${found.charCodeAt(index).toString(16).padStart(4, "0")}`).join(""));
11914
+ function countryName(code) {
11915
+ try {
11916
+ return new Intl.DisplayNames(["en"], { type: "region" }).of(code) ?? code;
11917
+ } catch {
11918
+ return code;
11919
+ }
11920
+ }
11921
+ function comparedIn(report) {
11922
+ const change = report.visitsChangePercent;
11923
+ if (change === null) return "There's nothing to compare it with yet.";
11924
+ const before = report.range === "24h" ? "the day before" : "the 3 before";
11925
+ const subject = report.range === "24h" ? "That's" : "The last 3 days had";
11926
+ if (change === 0) return `${subject} the same as ${before}.`;
11927
+ return `${subject} ${Math.abs(change)}% ${change > 0 ? "more" : "fewer"} than ${before}.`;
11928
+ }
11929
+ function listIn2(title, rows) {
11930
+ if (rows.length === 0) return "";
11931
+ const shown = rows.slice(0, REPORT_ROWS);
11932
+ const width = Math.max(...shown.map((row) => row.name.length));
11933
+ return `
11934
+ ${faint(title)}
11935
+ ${shown.map((row) => ` ${row.name.padEnd(width)} ${row.count}
11936
+ `).join("")}`;
11937
+ }
11938
+ function reportIn(report, sandbox, siteId) {
11939
+ if (!report.organizationEnabled) {
11940
+ return "Site analytics are off for this organization, so nothing is counted. agental site analytics org on turns them on.\n";
11941
+ }
11942
+ if (!report.enabled) {
11943
+ return `Analytics are off for this site, so nothing is counted. agental site analytics on ${sandbox} ${siteId} turns them on.
11944
+ `;
11945
+ }
11946
+ const span2 = report.range === "24h" ? "in the last 24 hours" : "in the last 7 days";
11947
+ const today = report.range === "24h" ? " today (UTC)" : "";
11948
+ const worked = report.requests > 0 ? ` ${Math.floor((report.requests - report.errors) * 1e3 / report.requests) / 10}% of requests worked${today}.` : "";
11949
+ return [
11950
+ `${report.visits} ${report.visits === 1 ? "visit" : "visits"} ${span2}.
11951
+ `,
11952
+ `${comparedIn(report)} They opened ${report.pageViews} ${report.pageViews === 1 ? "page" : "pages"}.${worked}
11953
+ `,
11954
+ listIn2(`Top pages${today}`, report.pages.map((row) => ({ ...row, name: printable(row.name) }))),
11955
+ listIn2(`Top sources${today}`, report.sources.map((row) => ({ ...row, name: printable(row.name) }))),
11956
+ listIn2(`Top countries${today}`, report.countries.map((row) => ({ ...row, name: printable(countryName(row.name)) })))
11957
+ ].join("");
11958
+ }
11959
+ async function siteSwitch(client, turn, words2, options) {
11960
+ const [sandbox, target, ...rest] = words2;
11961
+ if (sandbox === void 0 || target === void 0 || rest.length > 0) {
11962
+ throw new Error(ANALYTICS_USAGE);
11963
+ }
11964
+ if (options.informed) {
11965
+ throw new Error("--informed is for agental site analytics org on.");
11966
+ }
11967
+ const found = await siteOn(client, sandbox, target);
11968
+ const named = found.url ?? `port ${found.port}`;
11969
+ if (turn === "off" && !options.yes && !await client.confirmed(`Turn analytics off for ${named}? Its figures are deleted now and cannot be brought back.`)) {
11970
+ process.stderr.write("Nothing was changed. --yes goes on without asking.\n");
11971
+ process.exitCode = 1;
11972
+ return;
11973
+ }
11974
+ const report = await ask8(client, "PUT", `/v1/host-routes/${encodeURIComponent(target)}/analytics`, { enabled: turn === "on" });
11975
+ if (options.json) {
11976
+ process.stdout.write(`${reportJson(report)}
11977
+ `);
11978
+ return;
11979
+ }
11980
+ if (turn === "off") {
11981
+ process.stdout.write(`Analytics are off for ${named}, and its figures are deleted.
11982
+ `);
11983
+ return;
11984
+ }
11985
+ process.stdout.write(
11986
+ report.organizationEnabled ? `Analytics are on for ${named}.
11987
+ ` : "This site's switch is on, but the organization's is off, so nothing is counted until agental site analytics org on.\n"
11988
+ );
11989
+ }
11990
+ async function organizationSwitch(client, words2, options) {
11991
+ const [turn, ...rest] = words2;
11992
+ if (rest.length > 0 || turn !== void 0 && turn !== "on" && turn !== "off") {
11993
+ throw new Error(ANALYTICS_USAGE);
11994
+ }
11995
+ if (options.informed && turn !== "on") {
11996
+ throw new Error("--informed is for agental site analytics org on.");
11997
+ }
11998
+ let setting;
11999
+ if (turn === void 0) {
12000
+ setting = await ask8(client, "GET", "/v1/site-analytics");
12001
+ } else {
12002
+ if (turn === "off" && !options.yes && !await client.confirmed("Turn site analytics off for this organization? Every site's figures are deleted now and cannot be brought back.")) {
12003
+ process.stderr.write("Nothing was changed. --yes goes on without asking.\n");
12004
+ process.exitCode = 1;
12005
+ return;
12006
+ }
12007
+ const put = (body) => client.request("/v1/site-analytics", { method: "PUT", body: JSON.stringify(body) });
12008
+ let response = await put({ enabled: turn === "on" });
12009
+ let answered = await bodyOf(response);
12010
+ const refused = answered?.error;
12011
+ if (response.status === 409 && refused?.code === "notice_required") {
12012
+ process.stderr.write(`${refused.message ?? ""}
12013
+ `);
12014
+ if (!options.informed) {
12015
+ process.stderr.write("Nothing was changed. If your organization accepts this: agental site analytics org on --informed\n");
12016
+ process.exitCode = 1;
12017
+ return;
12018
+ }
12019
+ response = await put({ enabled: true, informed: true });
12020
+ answered = await bodyOf(response);
12021
+ }
12022
+ if (!response.ok) {
12023
+ client.fail(response.status, answered);
12024
+ }
12025
+ setting = answered;
12026
+ }
12027
+ if (options.json) {
12028
+ process.stdout.write(`${JSON.stringify(setting, null, 2)}
12029
+ `);
12030
+ return;
12031
+ }
12032
+ if (turn === "off") {
12033
+ process.stdout.write("Site analytics are off for this organization, and every site's figures are deleted.\n");
12034
+ return;
12035
+ }
12036
+ process.stdout.write(
12037
+ setting.enabled ? `Site analytics are on for this organization. Figures are kept for ${setting.keptDays} days at most.
12038
+ ` : `Site analytics are off for this organization.${setting.noticeRequired ? " Turning them on takes --informed, after reading what is kept." : ""}
12039
+ `
12040
+ );
12041
+ }
11870
12042
  async function site(client, positionals, options) {
11871
- const verb = positionals[0] === "list" || positionals[0] === "add" || positionals[0] === "rm" ? positionals[0] : null;
12043
+ if (positionals[0] === "analytics") {
12044
+ const [turn, ...words2] = positionals.slice(1);
12045
+ if (turn === "org") return organizationSwitch(client, words2, options);
12046
+ if (turn === "on" || turn === "off") return siteSwitch(client, turn, words2, options);
12047
+ throw new Error(ANALYTICS_USAGE);
12048
+ }
12049
+ const verb = positionals[0] === "list" || positionals[0] === "add" || positionals[0] === "rm" || positionals[0] === "stats" ? positionals[0] : null;
11872
12050
  const [sandbox, target, ...rest] = verb === null ? positionals : positionals.slice(1);
11873
12051
  if (sandbox === void 0) {
11874
12052
  throw new Error(USAGE6);
@@ -11924,15 +12102,26 @@ async function site(client, positionals, options) {
11924
12102
  if (target === void 0 || rest.length > 0) {
11925
12103
  throw new Error(`site rm needs the sandbox and the site's id, as agental site ${sandbox} lists them.`);
11926
12104
  }
11927
- const found = (await sitesOf(client, sandbox)).find((route) => route.id === target);
11928
- if (!found) {
11929
- throw new Error(`${sandbox} has no site ${target}. agental site ${sandbox} lists its sites.`);
11930
- }
12105
+ const found = await siteOn(client, sandbox, target);
11931
12106
  await ask8(client, "POST", `/v1/host-routes/${encodeURIComponent(target)}/hide`);
11932
12107
  process.stdout.write(`Removed. ${found.url ?? `Port ${found.port}`} stops working now; adding port ${found.port} again gives a new link.
11933
12108
  `);
11934
12109
  return;
11935
12110
  }
12111
+ case "stats": {
12112
+ if (target === void 0 || rest.length > 0) {
12113
+ throw new Error(`site stats needs the sandbox and the site's id, as agental site ${sandbox} lists them.`);
12114
+ }
12115
+ const range = options.range ?? "7d";
12116
+ if (range !== "24h" && range !== "7d") {
12117
+ throw new Error(`--range is 24h or 7d. It was given ${range}.`);
12118
+ }
12119
+ await siteOn(client, sandbox, target);
12120
+ const report = await ask8(client, "GET", `/v1/host-routes/${encodeURIComponent(target)}/analytics?range=${range}`);
12121
+ process.stdout.write(options.json ? `${reportJson(report)}
12122
+ ` : reportIn(report, sandbox, target));
12123
+ return;
12124
+ }
11936
12125
  }
11937
12126
  }
11938
12127
 
@@ -12841,7 +13030,7 @@ async function main() {
12841
13030
  raw: { type: "boolean", default: false },
12842
13031
  subject: { type: "string" },
12843
13032
  from: { type: "string" },
12844
- // agental headroom: where its range ends (--from is where it begins).
13033
+ // agental limits: where its range ends (--from is where it begins).
12845
13034
  to: { type: "string" },
12846
13035
  "from-name": { type: "string" },
12847
13036
  "reply-to": { type: "string" },
@@ -12965,6 +13154,10 @@ async function main() {
12965
13154
  facets: { type: "string" },
12966
13155
  yes: { type: "boolean", default: false },
12967
13156
  confirm: { type: "string" },
13157
+ // agental site stats: 24h or 7d.
13158
+ range: { type: "string" },
13159
+ // agental site analytics org on: the person has read what is kept.
13160
+ informed: { type: "boolean", default: false },
12968
13161
  sort: { type: "string" },
12969
13162
  role: { type: "string" },
12970
13163
  "revoke-keys": { type: "boolean", default: false },
@@ -13095,7 +13288,7 @@ async function main() {
13095
13288
  await browser(positionals[1], values.headless, values.headed, values.off, values.status);
13096
13289
  return;
13097
13290
  case "site":
13098
- await site({ request, fail }, positionals.slice(1), { json: values.json });
13291
+ await site({ request, fail, confirmed }, positionals.slice(1), { json: values.json, range: values.range, yes: values.yes === true, informed: values.informed === true });
13099
13292
  return;
13100
13293
  case "network":
13101
13294
  await network(positionals.slice(1), values);
@@ -13172,8 +13365,8 @@ async function main() {
13172
13365
  case "billing":
13173
13366
  await billing(positionals.slice(1), values.json, values.limit);
13174
13367
  return;
13175
- case "headroom":
13176
- await headroom(positionals.slice(1), { json: values.json, from: values.from, to: values.to, step: values.step });
13368
+ case "limits":
13369
+ await showLimits(positionals.slice(1), { json: values.json, from: values.from, to: values.to, step: values.step });
13177
13370
  return;
13178
13371
  case "account":
13179
13372
  await account2(positionals.slice(1), values.out);
@@ -13281,7 +13474,7 @@ function maxBurstFeeHeaders(given) {
13281
13474
  function sayBurstFee(response) {
13282
13475
  const micros = Number(response.headers.get("Agental-Burst-Fee") ?? "0");
13283
13476
  if (micros > 0) {
13284
- process.stderr.write(`This start cost a burst fee of ${money(micros)}: the account started more than its plan's free starts in the last 15 minutes. Starts are free again within 15 minutes; agental headroom says the minute.
13477
+ process.stderr.write(`This start cost a burst fee of ${money(micros)}: the account started more than its plan's free starts in the last 15 minutes. Starts are free again within 15 minutes; agental limits says the minute.
13285
13478
  `);
13286
13479
  }
13287
13480
  }
@@ -14185,6 +14378,16 @@ function ruleInWords(rule) {
14185
14378
  const listed = Array.isArray(rule?.allow) ? rule.allow.map(String) : [];
14186
14379
  return listed.length > 0 ? `${String(rule?.outbound ?? "")}: ${listed.join(", ")}` : String(rule?.outbound ?? "");
14187
14380
  }
14381
+ function ownAddressesWarning(id, removedAll, heldTo, template2) {
14382
+ const blockIt = `agental template network ${template2} blocked, then agental template apply ${template2} ${id}`;
14383
+ if (heldTo === "open") {
14384
+ return removedAll ? `--none removes this sandbox's own addresses. It blocks nothing: its template is open, so it still reaches everything. To block it: ${blockIt}` : `Its template is open, so this sandbox still reaches everything. These addresses count once the template is blocked or an allowlist. To block the rest: ${blockIt}`;
14385
+ }
14386
+ if (removedAll && heldTo === "allowlist") {
14387
+ return "--none removes this sandbox's own addresses. It can still reach the addresses on its template's list.";
14388
+ }
14389
+ return null;
14390
+ }
14188
14391
  async function network(positionals, values) {
14189
14392
  const [id, ...more] = positionals;
14190
14393
  if (!id) {
@@ -14218,6 +14421,13 @@ async function network(positionals, values) {
14218
14421
  ""
14219
14422
  ].join("\n")
14220
14423
  );
14424
+ if (allow !== void 0) {
14425
+ const warning = ownAddressesWarning(id, values.none, body?.outbound, String(body?.template?.name ?? "<template>"));
14426
+ if (warning) {
14427
+ process.stderr.write(`${warning}
14428
+ `);
14429
+ }
14430
+ }
14221
14431
  }
14222
14432
  function egressFrom(words2, how) {
14223
14433
  const [via, country, session, ...more] = words2.map((word) => word.trim());
@@ -14930,6 +15140,14 @@ async function ci(positionals, options) {
14930
15140
  `${item.repository} pool ${item.poolMax ?? `${body.defaultPoolMax} (default)`} template ${item.templateId ?? "runs-on (empty)"} agental is ${item.size} ${item.sandboxes.length} sandboxes, ${busy} busy
14931
15141
  `
14932
15142
  );
15143
+ for (const sandbox of item.sandboxes.filter((each) => each.heldUntil)) {
15144
+ process.stdout.write(` ${sandbox.name} is kept as a job failed on it, until ${sandbox.heldUntil}: agental start ${sandbox.sandboxId} && agental ssh ${sandbox.sandboxId}
15145
+ `);
15146
+ }
15147
+ for (const job2 of item.waiting ?? []) {
15148
+ process.stdout.write(` job ${job2.jobId} waiting since ${job2.since}: ${job2.message}
15149
+ `);
15150
+ }
14933
15151
  }
14934
15152
  return;
14935
15153
  }
@@ -15128,7 +15346,7 @@ Nothing is charged until it is paid. agental billing shows it within a minute of
15128
15346
  body,
15129
15347
  () => body.address === null ? "Billing emails go to the owners alone. An owner can add an address for a copy of each under Billing in the console.\n" : body.confirmed === false ? `${body.address} gets no copies yet: it has to confirm by the link sent to it. An owner can send a new one under Billing in the console.
15130
15348
  ` : body.waiting === true ? `${body.address} gets no copies for now: whoever set it is no longer an owner. An owner keeps it or removes it under Billing in the console.
15131
- ` : `Billing emails also go to ${body.address}: out of credit, reloads, a failed payment, the free allowance. An owner changes it under Billing in the console.
15349
+ ` : `Billing emails also go to ${body.address}: out of credit, reloads, a failed payment, the free allowance, the burst budget. An owner changes it under Billing in the console.
15132
15350
  `
15133
15351
  );
15134
15352
  return;
@@ -15440,7 +15658,7 @@ function pricesForPeople(body) {
15440
15658
  if (also.length > 0) {
15441
15659
  out.push(strong("Also"), ...fitted(also).trimEnd().split("\n").map((line) => ` ${line}`), "");
15442
15660
  }
15443
- out.push(faint("agental billing top-up <dollars> \xB7 agental headroom budget <dollars> \xB7 https://agental.io/pricing"));
15661
+ out.push(faint("agental billing top-up <dollars> \xB7 agental limits budget <dollars> \xB7 https://agental.io/pricing"));
15444
15662
  return `${out.join("\n")}
15445
15663
  `;
15446
15664
  }
@@ -15467,7 +15685,7 @@ function describePrices(body) {
15467
15685
  }
15468
15686
  if (body.burstFee) {
15469
15687
  out.push(
15470
- `A start past your free starts in any ${body.burstFee.windowMinutes} minutes costs one hour of its price: $${body.burstFee.feeMicrosPerUnit / 1e6} a unit, $0.027 a small, $0.108 a large. At most ${wholeMoney(body.burstFee.defaultBudgetMicros)} a month unless you set another budget: agental headroom budget <dollars>.`
15688
+ `A start past your free starts in any ${body.burstFee.windowMinutes} minutes costs one hour of its price: $${body.burstFee.feeMicrosPerUnit / 1e6} a unit, $0.027 a small, $0.108 a large. At most ${wholeMoney(body.burstFee.defaultBudgetMicros)} a month unless you set another budget: agental limits budget <dollars>.`
15471
15689
  );
15472
15690
  }
15473
15691
  if (body.topUps?.length) {
@@ -15506,17 +15724,17 @@ function stoppedWords(storage) {
15506
15724
  return `A stopped sandbox is free for ${storage.stoppedFreeDays} days after each stop, then $${storage.stoppedMicrosPerGbMonth / 1e6} a GB a month of what it stores, by the second.`;
15507
15725
  }
15508
15726
  var BURST_DOCS = "https://agental.io/docs/usage#bursts";
15509
- async function headroom(positionals, options) {
15727
+ async function showLimits(positionals, options) {
15510
15728
  if (positionals[0] === "budget") {
15511
15729
  const given = positionals[1];
15512
15730
  if (given === void 0 || positionals.length > 2) {
15513
- throw new Error("headroom budget takes the most to spend on burst fees in a month, in US dollars, as agental headroom budget 20, or default.");
15731
+ throw new Error("limits budget takes the most to spend on burst fees in a month, in US dollars, as agental limits budget 20, or default.");
15514
15732
  }
15515
15733
  const dollars = Number(given.replace(/^\$/, ""));
15516
15734
  if (given !== "default" && (!Number.isFinite(dollars) || dollars < 0)) {
15517
- throw new Error(`headroom budget takes US dollars, as 20 or 0, or default. It was given ${given}.`);
15735
+ throw new Error(`limits budget takes US dollars, as 20 or 0, or default. It was given ${given}.`);
15518
15736
  }
15519
- const body2 = await asked("/v1/headroom/budget", { method: "PUT", body: JSON.stringify({ budgetMicros: given === "default" ? null : Math.round(dollars * 1e6) }) });
15737
+ const body2 = await asked("/v1/limits/budget", { method: "PUT", body: JSON.stringify({ budgetMicros: given === "default" ? null : Math.round(dollars * 1e6) }) });
15520
15738
  if (options.json) {
15521
15739
  process.stdout.write(`${JSON.stringify(body2, null, 2)}
15522
15740
  `);
@@ -15530,7 +15748,7 @@ async function headroom(positionals, options) {
15530
15748
  return;
15531
15749
  }
15532
15750
  if (positionals.length > 0) {
15533
- throw new Error(`headroom takes nothing, or budget <dollars>: it is the account's. It was given ${positionals.join(" ")}.`);
15751
+ throw new Error(`limits takes nothing, or budget <dollars>: it is the account's. It was given ${positionals.join(" ")}.`);
15534
15752
  }
15535
15753
  if (options.step !== void 0 && !["10m", "hour", "day"].includes(options.step)) {
15536
15754
  throw new Error(`--step is 10m, hour or day. It was given ${options.step}.`);
@@ -15542,15 +15760,15 @@ async function headroom(positionals, options) {
15542
15760
  }
15543
15761
  }
15544
15762
  const asks = query.toString();
15545
- const body = await asked(`/v1/headroom${asks === "" ? "" : `?${asks}`}`, { method: "GET" });
15763
+ const body = await asked(`/v1/limits${asks === "" ? "" : `?${asks}`}`, { method: "GET" });
15546
15764
  if (options.json) {
15547
15765
  process.stdout.write(`${JSON.stringify(body, null, 2)}
15548
15766
  `);
15549
15767
  return;
15550
15768
  }
15551
- process.stdout.write(describeHeadroom(body, options.from === void 0 && options.to === void 0, options.to === void 0));
15769
+ process.stdout.write(describeLimits(body, options.from === void 0 && options.to === void 0, options.to === void 0));
15552
15770
  }
15553
- function describeHeadroom(body, today, endsNow) {
15771
+ function describeLimits(body, today, endsNow) {
15554
15772
  const answer3 = body && typeof body === "object" ? body : {};
15555
15773
  const now = answer3["now"] && typeof answer3["now"] === "object" ? answer3["now"] : {};
15556
15774
  const number = (from, name) => typeof from[name] === "number" ? from[name] : 0;
@@ -15810,12 +16028,12 @@ function refusedWords(body) {
15810
16028
  if (!isApiError(body)) {
15811
16029
  return "";
15812
16030
  }
15813
- const { refusedLastHour, headroomUrl } = body.error;
15814
- if (typeof refusedLastHour !== "number" || typeof headroomUrl !== "string") {
16031
+ const { refusedLastHour, limitsUrl } = body.error;
16032
+ if (typeof refusedLastHour !== "number" || typeof limitsUrl !== "string") {
15815
16033
  return "";
15816
16034
  }
15817
16035
  return `Refused this way in the last hour: ${refusedLastHour.toLocaleString("en-US")}.
15818
- ${headroomUrl}
16036
+ ${limitsUrl}
15819
16037
  `;
15820
16038
  }
15821
16039
  async function readBody(response) {
@@ -15966,8 +16184,8 @@ Usage
15966
16184
  agental key delete <key>
15967
16185
  agental billing [prices | compare | card [save] | details | top-up <dollars> | auto-reload <dollars | off> | email-copy] [--json]
15968
16186
  agental billing invoices [--limit <n>] [--json]
15969
- agental headroom [--from <day or date-time>] [--to <day or date-time>] [--step 10m|hour|day] [--json]
15970
- agental headroom budget <dollars> | budget default [--json]
16187
+ agental limits [--from <day or date-time>] [--to <day or date-time>] [--step 10m|hour|day] [--json]
16188
+ agental limits budget <dollars> | budget default [--json]
15971
16189
  agental egress [budget <dollars> | budget default] [--json]
15972
16190
  agental egress use-case "<what your sandboxes will use it for>" [--json]
15973
16191
  agental account export [--out <file>]
@@ -15981,6 +16199,9 @@ ${FILES_USAGE.map((line) => ` ${line}`).join("\n")}
15981
16199
  agental site list <sandbox-id> [--json]
15982
16200
  agental site add <sandbox-id> <port> [--json] a public link to a port, printed
15983
16201
  agental site rm <sandbox-id> <site-id> the link stops working, for good
16202
+ agental site stats <sandbox-id> <site-id> [--range 24h|7d] [--json] its visits, pages, sources, countries
16203
+ agental site analytics on|off <sandbox-id> <site-id> [--yes] [--json] off deletes its figures
16204
+ agental site analytics org [on|off] [--informed] [--yes] [--json] the organization's switch
15984
16205
  agental email <sandbox-id> [--json]
15985
16206
  agental email on|off <sandbox-id>
15986
16207
  agental email list <sandbox-id> [--limit <n>] [--json]
@@ -16053,8 +16274,9 @@ the place of the one it had, so an allowlist names every address each time. A sa
16053
16274
  template takes it when it next starts, or now when template apply names it, and one made from
16054
16275
  it is held to it from its first boot. network says what a sandbox is held to, its template's
16055
16276
  rule as it has it, and its own addresses. With --allow it gives the sandbox the addresses that
16056
- follow as its own, in place of the ones it had, and with --none takes them away: they add to
16057
- its template's rule and never take from it. Open lets everything out whatever they say, blocked
16277
+ follow as its own, in place of the ones it had, and with --none takes them away, which does not
16278
+ block the sandbox: they add to its template's rule and never take from it. To block a sandbox,
16279
+ set its template's rule. Open lets everything out whatever they say, blocked
16058
16280
  lets out only them, and an allowlist lets out its addresses and them. That holds at once, the
16059
16281
  sandbox is not restarted, and what is sent to it, commands, files and SSH, is not affected.
16060
16282
  create --allow gives a new sandbox its own from its first boot. These work where GET
@@ -16173,9 +16395,9 @@ webhooks lists the addresses your account's events are posted to, with what each
16173
16395
  how its last post went. webhook add makes one: it posts to <url>, which has to be on the public
16174
16396
  internet, the kinds --events names, such as sandbox.stopped,sandbox.error, or every kind with
16175
16397
  --all, those added later included. The kinds are ${WEBHOOK_KINDS.join(", ")}.
16176
- A group by its name and .*, as headroom.* or sandbox.*, is every kind of the group, and any
16177
- added to it later; quote it, as --events 'headroom.*,sandbox.error', so the shell leaves it be.
16178
- headroom.* are the organization's, about no sandbox: a burst begun and ended, starts refused,
16398
+ A group by its name and .*, as limits.* or sandbox.*, is every kind of the group, and any
16399
+ added to it later; quote it, as --events 'limits.*,sandbox.error', so the shell leaves it be.
16400
+ limits.* are the organization's, about no sandbox: a burst begun and ended, starts refused,
16179
16401
  the running count met, and the burst budget at 80% and reached.
16180
16402
  It prints the webhook's signing secret, the one time it is given: each post carries
16181
16403
  X-Agental-Signature, the HMAC-SHA256 of its body under that secret. show says what one is sent,
@@ -16286,6 +16508,13 @@ something listens there now. site add gives a port a link and prints it; the ser
16286
16508
  sandbox must listen on 0.0.0.0. site rm takes a site away for good: its link stops working at
16287
16509
  once, and adding the port again gives a new one. They are the API's host routes with public
16288
16510
  true, and site rm is POST /v1/host-routes/{id}/hide.
16511
+ site stats reports a site's visits: a visit is one address and browser on one site on one UTC day, and bots
16512
+ are left out. Figures are totals kept for 7 days at most, with no visitor's address, query
16513
+ or cookie. site analytics off deletes a site's figures at once, and asks first: --yes goes on
16514
+ without asking, and without a terminal nothing is changed unless it is given. site analytics org
16515
+ is the organization's switch, which each site's applies within. On Enterprise or with a server
16516
+ of your own, org on prints what is kept and changes nothing until it is run with --informed,
16517
+ which says that you have read it.
16289
16518
  email says whether mail is on for a sandbox, and the domain its addresses end in: any name
16290
16519
  before the @ of that domain reaches the sandbox. Mail is off until email on turns it on, for
16291
16520
  receiving and for sending both, and each message is charged to the account from then on. email
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agental",
3
- "version": "0.37.0",
3
+ "version": "0.40.2",
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",