agental 0.45.0 → 0.47.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 +589 -170
  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.45.0" : "dev";
7414
+ var CLI_VERSION = true ? "0.47.0" : "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}`;
@@ -7971,8 +7971,8 @@ function keyOf(body) {
7971
7971
  return { ...key2, actions: list4(key2.actions), sandboxIds: list4(key2.sandboxIds), templateIds: list4(key2.templateIds), allowFrom: list4(key2.allowFrom) };
7972
7972
  }
7973
7973
  function keysOf(body) {
7974
- const listed = body?.apiKeys;
7975
- return (Array.isArray(listed) ? listed : []).map(keyOf);
7974
+ const listed2 = body?.apiKeys;
7975
+ return (Array.isArray(listed2) ? listed2 : []).map(keyOf);
7976
7976
  }
7977
7977
  function at(moment2) {
7978
7978
  return new Date(moment2).toISOString().replace(/\.\d+Z$/, "Z");
@@ -7983,8 +7983,8 @@ function listIn(given) {
7983
7983
  function canDoOf(key2, full) {
7984
7984
  const everything = key2.actions.includes(ALL_ACTIONS);
7985
7985
  if (!full) {
7986
- const listed = key2.actions.join(",");
7987
- return key2.preset ?? (everything ? "everything" : listed.length <= 30 ? listed : `${key2.actions.length} actions`);
7986
+ const listed2 = key2.actions.join(",");
7987
+ return key2.preset ?? (everything ? "everything" : listed2.length <= 30 ? listed2 : `${key2.actions.length} actions`);
7988
7988
  }
7989
7989
  const named = key2.preset ? `${key2.preset}: ` : "";
7990
7990
  return everything ? `${named}everything, and any action added later` : `${named}${key2.actions.join(", ")}`;
@@ -8017,8 +8017,8 @@ function addressesOf(allowFrom, full) {
8017
8017
  if (allowFrom.length === 0) {
8018
8018
  return "anywhere";
8019
8019
  }
8020
- const listed = allowFrom.join(full ? ", " : ",");
8021
- return full || listed.length <= 32 ? listed : `${allowFrom.length} addresses`;
8020
+ const listed2 = allowFrom.join(full ? ", " : ",");
8021
+ return full || listed2.length <= 32 ? listed2 : `${allowFrom.length} addresses`;
8022
8022
  }
8023
8023
  function lastUsedOf(key2) {
8024
8024
  if (key2.lastUsedAt === null) {
@@ -8286,10 +8286,10 @@ async function whoIs(base, key2) {
8286
8286
  throw error;
8287
8287
  }
8288
8288
  }
8289
- async function pushRequest(base, ask12) {
8289
+ async function pushRequest(base, ask13) {
8290
8290
  let made;
8291
8291
  try {
8292
- made = await call(base, "POST", "/v1/cli-sign-ins", ask12);
8292
+ made = await call(base, "POST", "/v1/cli-sign-ins", ask13);
8293
8293
  } catch (error) {
8294
8294
  if (error instanceof Refused && (error.status === 401 || error.status === 404)) {
8295
8295
  throw new Error(`${base} does not sign the command in through the browser. Make a key in its console, under API keys, and run agental login --key.`);
@@ -8305,7 +8305,7 @@ async function listen() {
8305
8305
  };
8306
8306
  const next = new Promise((resolve) => arrived = resolve);
8307
8307
  let taken = false;
8308
- const server = createServer((request2, response) => {
8308
+ const server2 = createServer((request2, response) => {
8309
8309
  const url = new URL(request2.url ?? "/", "http://127.0.0.1");
8310
8310
  if (url.pathname !== "/callback") {
8311
8311
  response.writeHead(404).end();
@@ -8320,11 +8320,11 @@ async function listen() {
8320
8320
  arrived(url);
8321
8321
  });
8322
8322
  await new Promise((resolve, reject) => {
8323
- server.once("error", reject);
8324
- server.listen(0, "127.0.0.1", resolve);
8323
+ server2.once("error", reject);
8324
+ server2.listen(0, "127.0.0.1", resolve);
8325
8325
  });
8326
- const { port } = server.address();
8327
- return { server, redirectUri: `http://127.0.0.1:${port}/callback`, next, answer: (to) => answer3(to) };
8326
+ const { port } = server2.address();
8327
+ return { server: server2, redirectUri: `http://127.0.0.1:${port}/callback`, next, answer: (to) => answer3(to) };
8328
8328
  }
8329
8329
  async function browserSignIn(base, term, organizationId) {
8330
8330
  const verifier = randomBytes2(32).toString("base64url");
@@ -8420,8 +8420,8 @@ async function login(base, args) {
8420
8420
  if (!who) {
8421
8421
  throw new Error(`${base} did not take that key. Make one in the console, under API keys.`);
8422
8422
  }
8423
- const listed = await call(base, "GET", "/v1/api-keys", void 0, key2).catch(() => ({}));
8424
- const mine = Array.isArray(listed["apiKeys"]) ? listed["apiKeys"].find((one) => one["prefix"] === key2.slice(0, 12)) : void 0;
8423
+ const listed2 = await call(base, "GET", "/v1/api-keys", void 0, key2).catch(() => ({}));
8424
+ const mine = Array.isArray(listed2["apiKeys"]) ? listed2["apiKeys"].find((one) => one["prefix"] === key2.slice(0, 12)) : void 0;
8425
8425
  const file = saveCredentials({
8426
8426
  apiUrl: base,
8427
8427
  apiKey: key2,
@@ -8599,14 +8599,14 @@ function addToJson(agent, places, url) {
8599
8599
  return { agent: agent.agent, did: "left", why: `${file} is not plain JSON, so it was left as it is: add ${lines}` };
8600
8600
  }
8601
8601
  }
8602
- const servers = settings[agent.key] ?? {};
8603
- if (typeof servers !== "object" || servers === null || Array.isArray(servers)) {
8602
+ const servers2 = settings[agent.key] ?? {};
8603
+ if (typeof servers2 !== "object" || servers2 === null || Array.isArray(servers2)) {
8604
8604
  return { agent: agent.agent, did: "left", why: `${agent.key} in ${file} is not a list of servers, so it was left as it is: add ${lines}` };
8605
8605
  }
8606
- if (CONNECTOR_NAME in servers) {
8606
+ if (CONNECTOR_NAME in servers2) {
8607
8607
  return { agent: agent.agent, did: "already" };
8608
8608
  }
8609
- settings[agent.key] = { ...servers, [CONNECTOR_NAME]: agent.entry(url) };
8609
+ settings[agent.key] = { ...servers2, [CONNECTOR_NAME]: agent.entry(url) };
8610
8610
  replaceFile(file, `${bom}${JSON.stringify(settings, null, 2)}
8611
8611
  `);
8612
8612
  return { agent: agent.agent, did: "added" };
@@ -9150,8 +9150,8 @@ async function yes(question) {
9150
9150
  }
9151
9151
  }
9152
9152
  async function atTheLimit(base, key2, term, message) {
9153
- const listed = await api(base, key2, "GET", "/v1/sandboxes");
9154
- const sandboxes2 = ordered(Array.isArray(listed.body["sandboxes"]) ? listed.body["sandboxes"] : []);
9153
+ const listed2 = await api(base, key2, "GET", "/v1/sandboxes");
9154
+ const sandboxes2 = ordered(Array.isArray(listed2.body["sandboxes"]) ? listed2.body["sandboxes"] : []);
9155
9155
  term.say(`
9156
9156
  ${bold("No new sandbox:")} ${message}`);
9157
9157
  const running = sandboxes2.find((sandbox) => sandbox["status"] === "running");
@@ -9684,6 +9684,19 @@ var COMMANDS = [
9684
9684
  },
9685
9685
  { name: "webhooks", summary: "List the addresses your account's events are sent to." },
9686
9686
  { name: "webhook", summary: "Add, change, turn off and remove the addresses your account's events are sent to.", examples: ["agental webhook add https://example.com/agental --all"] },
9687
+ { name: "servers", summary: "List your organization's own servers, and say whether new sandboxes go to agental's when they are full.", examples: ["agental servers", "agental servers offload on --over 80"] },
9688
+ {
9689
+ name: "server",
9690
+ summary: "Add, read, drain and remove a server of your organization's own, on the Enterprise plan.",
9691
+ examples: ["agental server add rack-2-server-01", "agental server readings rack-2-server-01", "agental server drain rack-2-server-01"],
9692
+ flags: [
9693
+ ["--every 1|5|15|60", "readings: the minutes a line covers (default 60)"],
9694
+ ["--since, --until <date-time>", "readings: from when to when (default the last 24 hours)"],
9695
+ ["--reason <text>", "gone: why it is gone, kept to be read back"],
9696
+ ["--yes", "gone: go on without asking"],
9697
+ ["--json", "print the API's answer as JSON"]
9698
+ ]
9699
+ },
9687
9700
  { name: "keys", summary: "List your account's API keys." },
9688
9701
  {
9689
9702
  name: "key",
@@ -9810,7 +9823,7 @@ var MAP = [
9810
9823
  ["billing", "plan, credits, invoices and card"],
9811
9824
  ["limits", "how close you run to your plan's limits"],
9812
9825
  ["key", "API keys"],
9813
- ["org, member", "teams"],
9826
+ ["org, member, server", "teams, and servers of your own"],
9814
9827
  ["webhook", "events sent to an address of yours"],
9815
9828
  ["telemetry", "metrics and events sent to your collector"],
9816
9829
  ["ci, claude", "GitHub Actions and Claude agents on sandboxes"],
@@ -9961,7 +9974,7 @@ function noSuchCommand(word, operator) {
9961
9974
  ${faint("agental help lists every command.", stream)}
9962
9975
  `;
9963
9976
  }
9964
- var LISTED = { template: "templates", key: "keys", webhook: "webhooks", job: "jobs" };
9977
+ var LISTED = { template: "templates", key: "keys", webhook: "webhooks", job: "jobs", server: "servers" };
9965
9978
  var SANDBOX_VERBS = /* @__PURE__ */ new Set(["list", "create", "start", "stop", "delete", "recover", "exec", "shell", "summary"]);
9966
9979
  var SECRET_VERBS = /* @__PURE__ */ new Set(["list", "get", "set", "unset", "hosts", "get-file", "put-file", "rm-file"]);
9967
9980
  var OPERATOR_VERBS = /* @__PURE__ */ new Set(["suspend", "unsuspend", "suspensions", "smoke"]);
@@ -10047,6 +10060,7 @@ var SUBCOMMANDS = {
10047
10060
  template: ["list"],
10048
10061
  key: ["list"],
10049
10062
  webhook: ["list"],
10063
+ server: ["list"],
10050
10064
  job: ["list"],
10051
10065
  limits: ["budget"],
10052
10066
  egress: ["budget", "use-case"],
@@ -10104,6 +10118,7 @@ var SANDBOX = /^<sandbox-id>/;
10104
10118
  var SANDBOX_VERBS2 = /* @__PURE__ */ new Set(["list", "create", "start", "stop", "delete", "recover", "exec", "shell", "summary"]);
10105
10119
  var TEMPLATE = /^<template>/;
10106
10120
  var SNAPSHOT = /^<snapshot/;
10121
+ var SERVER = /^<server>/;
10107
10122
  var JOB = /^<job>/;
10108
10123
  var KEPT_SHELL = /^<shell>/;
10109
10124
  var COMMAND_ID = /^<command-id>/;
@@ -10180,6 +10195,7 @@ async function complete(typed, reference, operator, fetchJson) {
10180
10195
  let wantsJob = false;
10181
10196
  let wantsSnapshot = false;
10182
10197
  let wantsCommand = false;
10198
+ let wantsServer = false;
10183
10199
  for (const usage of usages) {
10184
10200
  const parts = partsOf(usage).slice(1);
10185
10201
  const fits = positionals.every((word, index) => {
@@ -10203,6 +10219,7 @@ async function complete(typed, reference, operator, fetchJson) {
10203
10219
  wantsJob ||= JOB.test(inner);
10204
10220
  wantsSnapshot ||= SNAPSHOT.test(inner);
10205
10221
  wantsCommand ||= COMMAND_ID.test(inner);
10222
+ wantsServer ||= SERVER.test(inner);
10206
10223
  }
10207
10224
  if (positionals.length === 0) {
10208
10225
  for (const word of SUBCOMMANDS[name] ?? []) {
@@ -10218,7 +10235,8 @@ async function complete(typed, reference, operator, fetchJson) {
10218
10235
  ...wantsTemplate ? await templates(fetchJson) : [],
10219
10236
  ...wantsJob ? await jobs(fetchJson) : [],
10220
10237
  ...wantsSnapshot ? await snapshots(fetchJson) : [],
10221
- ...wantsCommand && sandbox !== void 0 ? await commandsIn(fetchJson, sandbox) : []
10238
+ ...wantsCommand && sandbox !== void 0 ? await commandsIn(fetchJson, sandbox) : [],
10239
+ ...wantsServer ? await ownServers(fetchJson) : []
10222
10240
  ];
10223
10241
  return starting([...candidates.values(), ...asked2]);
10224
10242
  }
@@ -10227,52 +10245,57 @@ async function sandboxes(api2) {
10227
10245
  return (body?.sandboxes ?? []).filter((each) => typeof each["id"] === "string").sort((a, b) => Number(b["status"] === "running") - Number(a["status"] === "running")).map((each) => ({ value: each["id"], about: [each["name"], each["status"]].filter((word) => typeof word === "string" && word).join(", ") }));
10228
10246
  }
10229
10247
  async function keptShells(api2, sandbox) {
10230
- let listed;
10248
+ let listed2;
10231
10249
  try {
10232
10250
  const body = await api2.get(`/v1/sandboxes/${encodeURIComponent(sandbox)}/terminals`);
10233
- listed = Array.isArray(body?.terminals) ? body.terminals : [];
10251
+ listed2 = Array.isArray(body?.terminals) ? body.terminals : [];
10234
10252
  } catch {
10235
10253
  return [];
10236
10254
  }
10237
- return listed.filter((each) => Number.isInteger(each["n"])).map((each) => {
10255
+ return listed2.filter((each) => Number.isInteger(each["n"])).map((each) => {
10238
10256
  const about = [typeof each["running"] === "string" ? each["running"] : each["exit"] ? "ended" : "", typeof each["cwd"] === "string" ? each["cwd"] : ""].filter(Boolean).join(", ");
10239
10257
  return about ? { value: String(each["n"]), about } : { value: String(each["n"]) };
10240
10258
  });
10241
10259
  }
10242
10260
  async function commandsIn(api2, sandbox) {
10243
- let listed;
10261
+ let listed2;
10244
10262
  try {
10245
10263
  const body = await api2.get(`/v1/sandboxes/${encodeURIComponent(sandbox)}/commands?limit=50`);
10246
- listed = Array.isArray(body?.commands) ? body.commands : [];
10264
+ listed2 = Array.isArray(body?.commands) ? body.commands : [];
10247
10265
  } catch {
10248
10266
  return [];
10249
10267
  }
10250
- return listed.filter((each) => typeof each["id"] === "string").map((each) => {
10268
+ return listed2.filter((each) => typeof each["id"] === "string").map((each) => {
10251
10269
  const about = each["status"] === "running" ? "running" : typeof each["exitCode"] === "number" ? `exited ${each["exitCode"]}` : typeof each["endReason"] === "string" ? each["endReason"].replace(/_/g, " ") : typeof each["status"] === "string" ? each["status"] : "";
10252
10270
  return about ? { value: each["id"], about } : { value: each["id"] };
10253
10271
  });
10254
10272
  }
10255
10273
  async function snapshots(api2) {
10256
10274
  const body = await cached("snapshots", api2.as, () => api2.get("/v1/snapshots"));
10257
- const listed = Array.isArray(body?.snapshots) ? body.snapshots : [];
10258
- return listed.filter((each) => typeof each["id"] === "string").reverse().map((each) => ({ value: each["id"], about: [each["name"], each["sandboxName"]].filter((word) => typeof word === "string" && word).join(", ") }));
10275
+ const listed2 = Array.isArray(body?.snapshots) ? body.snapshots : [];
10276
+ return listed2.filter((each) => typeof each["id"] === "string").reverse().map((each) => ({ value: each["id"], about: [each["name"], each["sandboxName"]].filter((word) => typeof word === "string" && word).join(", ") }));
10277
+ }
10278
+ async function ownServers(api2) {
10279
+ const body = await cached("servers", api2.as, () => api2.get("/v1/servers"));
10280
+ const listed2 = Array.isArray(body?.servers) ? body.servers : [];
10281
+ return listed2.filter((each) => typeof each["id"] === "string").map((each) => typeof each["label"] === "string" ? { value: each["id"], about: each["label"] } : { value: each["id"] });
10259
10282
  }
10260
10283
  async function templates(api2) {
10261
10284
  const body = await cached("templates", api2.as, () => api2.get("/v1/templates"));
10262
- const listed = Array.isArray(body) ? body : body?.templates ?? [];
10263
- return listed.filter((each) => typeof each["name"] === "string").map((each) => ({ value: each["name"], about: each["default"] === true ? "the default" : void 0 }));
10285
+ const listed2 = Array.isArray(body) ? body : body?.templates ?? [];
10286
+ return listed2.filter((each) => typeof each["name"] === "string").map((each) => ({ value: each["name"], about: each["default"] === true ? "the default" : void 0 }));
10264
10287
  }
10265
10288
  async function jobs(api2) {
10266
10289
  const body = await cached("jobs", api2.as, () => api2.get("/v1/jobs"));
10267
- const listed = Array.isArray(body?.jobs) ? body.jobs : [];
10268
- return listed.filter((each) => typeof each["name"] === "string").map((each) => {
10290
+ const listed2 = Array.isArray(body?.jobs) ? body.jobs : [];
10291
+ return listed2.filter((each) => typeof each["name"] === "string").map((each) => {
10269
10292
  const target = each["target"];
10270
10293
  const about = typeof target?.["sandboxName"] === "string" ? target["sandboxName"] : typeof target?.["sandbox"] === "string" ? target["sandbox"] : typeof target?.["templateName"] === "string" ? `fresh from ${target["templateName"]}` : typeof target?.["template"] === "string" ? `fresh from ${target["template"]}` : void 0;
10271
10294
  return about ? { value: each["name"], about } : { value: each["name"] };
10272
10295
  });
10273
10296
  }
10274
10297
  var KEPT_MS = 3e4;
10275
- async function cached(what, as, ask12) {
10298
+ async function cached(what, as, ask13) {
10276
10299
  const folder = path5.join(process.env["XDG_CACHE_HOME"] || path5.join(os6.homedir(), ".cache"), "agental");
10277
10300
  const file = path5.join(folder, `complete-${what}-${createHash2("sha256").update(as).digest("hex").slice(0, 16)}.json`);
10278
10301
  try {
@@ -10284,7 +10307,7 @@ async function cached(what, as, ask12) {
10284
10307
  }
10285
10308
  let body = null;
10286
10309
  try {
10287
- body = await ask12();
10310
+ body = await ask13();
10288
10311
  } catch {
10289
10312
  return null;
10290
10313
  }
@@ -10444,9 +10467,9 @@ function print2(json3, body, words2) {
10444
10467
  ` : words2);
10445
10468
  }
10446
10469
  async function organizations(client) {
10447
- const listed = (await ask5(client, "GET", "/v1/organizations"))["organizations"];
10470
+ const listed2 = (await ask5(client, "GET", "/v1/organizations"))["organizations"];
10448
10471
  const me = await ask5(client, "GET", "/v1/me");
10449
- return { organizations: Array.isArray(listed) ? listed : [], acting: String(me["activeOrganizationId"] ?? "") };
10472
+ return { organizations: Array.isArray(listed2) ? listed2 : [], acting: String(me["activeOrganizationId"] ?? "") };
10450
10473
  }
10451
10474
  function organizationNamed(list4, given) {
10452
10475
  const byId = list4.find((organization) => organization.id === given);
@@ -10534,12 +10557,12 @@ function memberNamed(list4, given) {
10534
10557
  async function members(client, positionals, options) {
10535
10558
  const [verb = "list", target] = positionals;
10536
10559
  const team = await actingTeam(client);
10537
- const listed = await ask5(client, "GET", `/v1/organizations/${encodeURIComponent(team.id)}/members`);
10538
- const list4 = Array.isArray(listed["members"]) ? listed["members"] : [];
10560
+ const listed2 = await ask5(client, "GET", `/v1/organizations/${encodeURIComponent(team.id)}/members`);
10561
+ const list4 = Array.isArray(listed2["members"]) ? listed2["members"] : [];
10539
10562
  switch (verb) {
10540
10563
  case "list": {
10541
10564
  if (options.json) {
10542
- print2(true, listed, "");
10565
+ print2(true, listed2, "");
10543
10566
  return;
10544
10567
  }
10545
10568
  process.stdout.write(`${team.name} (${team.id})
@@ -11516,11 +11539,11 @@ function fileJobsOf(file) {
11516
11539
  } catch (error) {
11517
11540
  throw new Error(`${file} is not YAML or JSON: ${error instanceof Error ? error.message : String(error)}`);
11518
11541
  }
11519
- const listed = parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed["jobs"] : void 0;
11520
- if (!Array.isArray(listed)) {
11542
+ const listed2 = parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed["jobs"] : void 0;
11543
+ if (!Array.isArray(listed2)) {
11521
11544
  throw new Error(`${file} has no jobs: list. It is a map whose jobs: lists each job, with its name, command, and sandbox or template.`);
11522
11545
  }
11523
- const jobs2 = listed.map((item, index) => fileJobOf(item, index));
11546
+ const jobs2 = listed2.map((item, index) => fileJobOf(item, index));
11524
11547
  const names2 = jobs2.map((each) => each.name);
11525
11548
  const twice = names2.filter((each, index) => names2.indexOf(each) !== index);
11526
11549
  if (twice.length > 0) {
@@ -11848,23 +11871,23 @@ function tookOf2(command3) {
11848
11871
  }
11849
11872
  async function list2(client, sandbox, commands, options) {
11850
11873
  const body = await ask7(client, "GET", `${commands}${options.limit === void 0 ? "" : `?limit=${encodeURIComponent(options.limit)}`}`);
11851
- const listed = body?.commands ?? [];
11874
+ const listed2 = body?.commands ?? [];
11852
11875
  if (options.json) {
11853
- json2(listed);
11876
+ json2(listed2);
11854
11877
  return;
11855
11878
  }
11856
- if (listed.length === 0) {
11879
+ if (listed2.length === 0) {
11857
11880
  process.stdout.write(`No commands in ${sandbox}. agental command start ${sandbox} -- <command> starts one.
11858
11881
  `);
11859
11882
  return;
11860
11883
  }
11861
11884
  const terminal2 = isTerminal(process.stdout);
11862
- const sized = listed.some((each) => typeof each.stdoutBytes === "number");
11885
+ const sized = listed2.some((each) => typeof each.stdoutBytes === "number");
11863
11886
  const written = (count) => typeof count === "number" ? bytes2(count) : "-";
11864
- const named = listed.some((each) => each.name != null);
11887
+ const named = listed2.some((each) => each.name != null);
11865
11888
  const rows = [
11866
11889
  ["ID", ...named ? ["NAME"] : [], "STATE", "STARTED", "TOOK", ...sized ? ["STDOUT", "STDERR"] : []],
11867
- ...listed.map((each) => [each.id, ...named ? [each.name ?? "-"] : [], stateOf(each), moment(each.startedAt), tookOf2(each), ...sized ? [written(each.stdoutBytes), written(each.stderrBytes)] : []])
11890
+ ...listed2.map((each) => [each.id, ...named ? [each.name ?? "-"] : [], stateOf(each), moment(each.startedAt), tookOf2(each), ...sized ? [written(each.stdoutBytes), written(each.stderrBytes)] : []])
11868
11891
  ];
11869
11892
  process.stdout.write(fitted(rows, { ...terminal2 ? { give: 1 } : { width: Number.MAX_SAFE_INTEGER }, paint: (cell, row) => row === 0 ? faint(cell) : cell }));
11870
11893
  }
@@ -12233,6 +12256,347 @@ async function writeStdin(client, sandbox, id, one) {
12233
12256
  }
12234
12257
  }
12235
12258
 
12259
+ // ../src/cli-servers.ts
12260
+ var SERVER_USAGE = "server takes list, add, show, readings, token, drain, gone or remove. agental server --help shows each.";
12261
+ var SERVERS_USAGE = "servers takes nothing to list them, offload [on|off] [--over <percent>], or core-days [--month <yyyy-mm>].";
12262
+ var READING_MINUTES = ["1", "5", "15", "60"];
12263
+ async function ask8(client, method, pathname, body) {
12264
+ const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
12265
+ let answered = null;
12266
+ try {
12267
+ answered = await response.json();
12268
+ } catch {
12269
+ answered = null;
12270
+ }
12271
+ if (!response.ok) {
12272
+ client.fail(response.status, answered);
12273
+ }
12274
+ return answered;
12275
+ }
12276
+ function printJson2(body) {
12277
+ process.stdout.write(`${JSON.stringify(body, null, 2)}
12278
+ `);
12279
+ }
12280
+ async function listed(client) {
12281
+ const body = await ask8(client, "GET", "/v1/servers");
12282
+ return Array.isArray(body?.servers) ? body.servers : [];
12283
+ }
12284
+ async function serverNamed(client, word, verb) {
12285
+ if (word === void 0) {
12286
+ throw new Error(`server ${verb} needs the server, by its id or its label, as agental servers lists them.`);
12287
+ }
12288
+ const servers2 = await listed(client);
12289
+ const found = servers2.find((server2) => server2.id === word) ?? servers2.find((server2) => server2.label === word);
12290
+ if (!found) {
12291
+ throw new Error(`No server of this organization is called ${word}. agental servers lists them.`);
12292
+ }
12293
+ return found;
12294
+ }
12295
+ var utc = (iso) => new Date(iso).toISOString().replace(/\.\d+Z$/, "Z");
12296
+ function agentOf(server2) {
12297
+ if (server2.agent.state === "waiting") {
12298
+ return "not joined yet";
12299
+ }
12300
+ const seen = server2.agent.lastSeenAt === null ? "" : `, last heard ${ago(server2.agent.lastSeenAt) ?? utc(server2.agent.lastSeenAt)}`;
12301
+ return `${server2.agent.state}${seen}`;
12302
+ }
12303
+ function stateOf2(server2) {
12304
+ switch (server2.state) {
12305
+ case "open":
12306
+ return "open: takes new sandboxes";
12307
+ case "held":
12308
+ return "held: takes no new sandbox";
12309
+ case "draining":
12310
+ return "draining: takes no new sandbox";
12311
+ case "evacuating":
12312
+ return "evacuating: its sandboxes are being moved off";
12313
+ }
12314
+ }
12315
+ function holdsOf(server2) {
12316
+ const { creating, running, stopped, failed, withSnapshots } = server2.holds;
12317
+ const parts = [`${running} running`, `${stopped} stopped`];
12318
+ if (creating > 0) {
12319
+ parts.push(`${creating} being made`);
12320
+ }
12321
+ if (failed > 0) {
12322
+ parts.push(`${failed} failed`);
12323
+ }
12324
+ if (withSnapshots > 0) {
12325
+ parts.push(`${withSnapshots} kept for snapshots`);
12326
+ }
12327
+ return parts.join(", ");
12328
+ }
12329
+ function describe3(server2) {
12330
+ const rows = [
12331
+ ["id", server2.id],
12332
+ ["label", server2.label],
12333
+ ["state", stateOf2(server2)],
12334
+ ["agent", `${agentOf(server2)}${server2.agent.version ? ` (version ${server2.agent.version})` : ""}`],
12335
+ ["address", server2.publicAddress ?? "none yet"],
12336
+ // Null for a joined server too, whose cores could not be told: it is not counted until a count is agreed with agental.
12337
+ ["cores", server2.cores !== null ? String(server2.cores) : server2.agent.state === "waiting" ? "counted once it joins" : "not known: not counted until a count is agreed with us"],
12338
+ ["holds", holdsOf(server2)],
12339
+ ["added", utc(server2.addedAt)]
12340
+ ];
12341
+ if (server2.agent.state === "waiting" && server2.agent.joinTokenExpiresAt !== null) {
12342
+ rows.push(["token", `works once, until ${utc(server2.agent.joinTokenExpiresAt)}`]);
12343
+ }
12344
+ return rows.map(([name, value]) => `${`${name}:`.padEnd(12)}${value}
12345
+ `).join("");
12346
+ }
12347
+ function sayJoin(joined) {
12348
+ process.stdout.write(describe3({ ...joined.server, agent: { ...joined.server.agent, joinTokenExpiresAt: null } }));
12349
+ process.stdout.write(`
12350
+ Run this as root on the server, with the disk for sandboxes in place of /dev/DISK:
12351
+
12352
+ ${joined.join.installCommand}
12353
+
12354
+ `);
12355
+ process.stdout.write(`token: ${joined.join.token}
12356
+ works once, until ${utc(joined.join.expiresAt)}
12357
+ `);
12358
+ process.stderr.write("The install line and its token are shown this once. agental server token gives a new one, while it has not joined.\n");
12359
+ }
12360
+ function sayOffload(offload2) {
12361
+ if (offload2.enabled) {
12362
+ process.stdout.write(
12363
+ `Offload is on, over ${offload2.overPercent}%.
12364
+ A new sandbox that names no region starts on agental's servers when none of yours has room under ${offload2.overPercent}% of its memory, CPU and disk. It is then a hosted sandbox, billed as one, from your credits. A sandbox made with --region own is never sent there.
12365
+ `
12366
+ );
12367
+ return;
12368
+ }
12369
+ process.stdout.write(
12370
+ `Offload is off (over ${offload2.overPercent}% when it is on).
12371
+ A new sandbox that names no region starts on your own servers only, and is refused with capacity_exceeded when none of them has room. agental servers offload on turns it on.
12372
+ `
12373
+ );
12374
+ }
12375
+ function percentOf(value) {
12376
+ return value === null ? "-" : `${Math.round(value)}%`;
12377
+ }
12378
+ async function servers(client, positionals, options) {
12379
+ const [what, ...rest] = positionals;
12380
+ if (what === void 0) {
12381
+ await listServers(client, options.json);
12382
+ return;
12383
+ }
12384
+ if (what === "offload") {
12385
+ await offload(client, rest, options);
12386
+ return;
12387
+ }
12388
+ if (what === "core-days" && rest.length === 0) {
12389
+ await coreDays(client, options);
12390
+ return;
12391
+ }
12392
+ throw new Error(SERVERS_USAGE);
12393
+ }
12394
+ async function listServers(client, asJson) {
12395
+ if (asJson) {
12396
+ printJson2(await ask8(client, "GET", "/v1/servers"));
12397
+ return;
12398
+ }
12399
+ const found = await listed(client);
12400
+ if (found.length === 0) {
12401
+ process.stdout.write("No servers of your own. agental server add <label> adds one; it comes with an Enterprise contract.\n");
12402
+ return;
12403
+ }
12404
+ const rows = [["ID", "LABEL", "STATE", "AGENT", "CORES", "SANDBOXES"]];
12405
+ for (const server2 of found) {
12406
+ rows.push([server2.id, server2.label, server2.state, agentOf(server2), server2.cores === null ? "-" : String(server2.cores), `${server2.holds.running} running, ${server2.holds.stopped} stopped`]);
12407
+ }
12408
+ process.stdout.write(fitted(rows, { give: 1 }));
12409
+ }
12410
+ async function offload(client, words2, options) {
12411
+ const [turn, ...extra] = words2;
12412
+ if (extra.length > 0 || turn !== void 0 && turn !== "on" && turn !== "off") {
12413
+ throw new Error("servers offload takes on or off, and --over <percent>: as agental servers offload on --over 80.");
12414
+ }
12415
+ let overPercent;
12416
+ if (options.over !== void 0) {
12417
+ if (!/^\d+%?$/.test(options.over)) {
12418
+ throw new Error("--over is a whole percent from 1 to 99, as 80.");
12419
+ }
12420
+ overPercent = Number.parseInt(options.over, 10);
12421
+ }
12422
+ if (turn === void 0 && overPercent === void 0) {
12423
+ const now = await ask8(client, "GET", "/v1/offload");
12424
+ if (options.json) {
12425
+ printJson2(now);
12426
+ } else {
12427
+ sayOffload(now);
12428
+ }
12429
+ return;
12430
+ }
12431
+ const enabled = turn === void 0 ? (await ask8(client, "GET", "/v1/offload")).enabled : turn === "on";
12432
+ const set = await ask8(client, "PUT", "/v1/offload", { enabled, ...overPercent === void 0 ? {} : { overPercent } });
12433
+ if (options.json) {
12434
+ printJson2(set);
12435
+ } else {
12436
+ sayOffload(set);
12437
+ }
12438
+ }
12439
+ async function coreDays(client, options) {
12440
+ const query = options.month === void 0 ? "" : `?month=${encodeURIComponent(options.month)}`;
12441
+ const body = await ask8(client, "GET", `/v1/core-days${query}`);
12442
+ if (options.json) {
12443
+ printJson2(body);
12444
+ return;
12445
+ }
12446
+ process.stdout.write(`Cores from ${body.fromDay} to ${body.throughDay}${body.of === "subscription" ? ", the cores subscription's month" : ""}:
12447
+ `);
12448
+ if (body.days.length === 0) {
12449
+ process.stdout.write("No core-days counted in it.\n");
12450
+ return;
12451
+ }
12452
+ const rows = [["DAY", "CORES", "COMMITTED", "PAST IT", "SERVERS"]];
12453
+ for (const day of body.days) {
12454
+ rows.push([day.day, String(day.cores), String(day.committedCores), String(day.extraCores), day.servers.map((server2) => `${server2.label} (${server2.cores})`).join(", ")]);
12455
+ }
12456
+ process.stdout.write(fitted(rows, { give: 4 }));
12457
+ process.stdout.write(`${body.coreDays} core-days in all, ${body.extraCoreDays} of them past the commitment.
12458
+ `);
12459
+ }
12460
+ async function server(client, positionals, options) {
12461
+ const [what, target, ...rest] = positionals;
12462
+ if (rest.length > 0) {
12463
+ throw new Error(`${SERVER_USAGE} A label with spaces is quoted, as "rack-2 server-01".`);
12464
+ }
12465
+ switch (what) {
12466
+ case "add": {
12467
+ if (target === void 0) {
12468
+ throw new Error("server add needs your own name for the server, as agental server add rack-2-server-01.");
12469
+ }
12470
+ const joined = await ask8(client, "POST", "/v1/servers", { label: target });
12471
+ if (options.json) {
12472
+ printJson2(joined);
12473
+ process.stderr.write("join.token and join.installCommand are shown this once.\n");
12474
+ return;
12475
+ }
12476
+ sayJoin(joined);
12477
+ return;
12478
+ }
12479
+ case "show": {
12480
+ const found = await serverNamed(client, target, "show");
12481
+ if (options.json) {
12482
+ printJson2(found);
12483
+ return;
12484
+ }
12485
+ process.stdout.write(describe3(found));
12486
+ return;
12487
+ }
12488
+ case "readings": {
12489
+ await readings(client, await serverNamed(client, target, "readings"), options);
12490
+ return;
12491
+ }
12492
+ case "token": {
12493
+ const found = await serverNamed(client, target, "token");
12494
+ const joined = await ask8(client, "POST", `/v1/servers/${encodeURIComponent(found.id)}/join-token`, {});
12495
+ if (options.json) {
12496
+ printJson2(joined);
12497
+ process.stderr.write("join.token and join.installCommand are shown this once. The token it had stopped working just now.\n");
12498
+ return;
12499
+ }
12500
+ sayJoin(joined);
12501
+ process.stderr.write("The token it had stopped working just now.\n");
12502
+ return;
12503
+ }
12504
+ case "drain": {
12505
+ const found = await serverNamed(client, target, "drain");
12506
+ const drained = await ask8(client, "POST", `/v1/servers/${encodeURIComponent(found.id)}/drain`);
12507
+ if (options.json) {
12508
+ printJson2(drained);
12509
+ return;
12510
+ }
12511
+ process.stdout.write(describe3(drained));
12512
+ process.stderr.write("It takes no new sandbox. Nothing on it was stopped or moved.\n");
12513
+ return;
12514
+ }
12515
+ case "gone": {
12516
+ const found = await serverNamed(client, target, "gone");
12517
+ if (options.reason === void 0 || options.reason.trim().length < 3) {
12518
+ throw new Error("server gone needs --reason, why it is gone, as it should be read back later: --reason 'The motherboard failed.'");
12519
+ }
12520
+ process.stderr.write(
12521
+ `This says ${found.label} (${found.id}) is gone for good, and cannot be undone. Its ${found.holds.running + found.holds.stopped + found.holds.creating + found.holds.failed} sandboxes are said lost and made again nowhere; its agent's key stops working; what is on its disks stays there.
12522
+ `
12523
+ );
12524
+ if (!options.yes && !await client.confirmed("Say it is gone?")) {
12525
+ process.stderr.write("Nothing was done. --yes goes on without asking.\n");
12526
+ process.exitCode = 1;
12527
+ return;
12528
+ }
12529
+ const gone = await ask8(client, "POST", `/v1/servers/${encodeURIComponent(found.id)}/declare-gone`, { label: found.label, reason: options.reason.trim() });
12530
+ if (options.json) {
12531
+ printJson2(gone);
12532
+ return;
12533
+ }
12534
+ process.stdout.write(`${found.label} is gone.${gone.sandboxesWaiting > 0 ? ` ${gone.sandboxesWaiting} of its sandboxes are still being seen to, within a few minutes.` : ""}
12535
+ `);
12536
+ return;
12537
+ }
12538
+ case "remove": {
12539
+ const found = await serverNamed(client, target, "remove");
12540
+ const removed = await ask8(client, "DELETE", `/v1/servers/${encodeURIComponent(found.id)}`, {});
12541
+ if (options.json) {
12542
+ printJson2(removed);
12543
+ return;
12544
+ }
12545
+ process.stdout.write(`Removed ${found.label}. Run this on it to take the agent off; your disks are left as they are:
12546
+
12547
+ ${removed.uninstallCommand}
12548
+ `);
12549
+ return;
12550
+ }
12551
+ default:
12552
+ throw new Error(SERVER_USAGE);
12553
+ }
12554
+ }
12555
+ async function readings(client, found, options) {
12556
+ const every = options.every ?? "60";
12557
+ if (!READING_MINUTES.includes(every)) {
12558
+ throw new Error(`--every is the minutes a line covers: ${READING_MINUTES.join(", ")}.`);
12559
+ }
12560
+ const query = new URLSearchParams({ everyMinutes: every });
12561
+ for (const [name, given] of [["since", options.since], ["until", options.until]]) {
12562
+ if (given === void 0) {
12563
+ continue;
12564
+ }
12565
+ const moment2 = new Date(given);
12566
+ if (Number.isNaN(moment2.getTime())) {
12567
+ throw new Error(`--${name} is a date and time, as 2026-11-30T10:00:00Z.`);
12568
+ }
12569
+ query.set(name, moment2.toISOString());
12570
+ }
12571
+ const body = await ask8(client, "GET", `/v1/servers/${encodeURIComponent(found.id)}/readings?${query}`);
12572
+ if (options.json) {
12573
+ printJson2(body);
12574
+ return;
12575
+ }
12576
+ process.stdout.write(`${found.label}, from ${utc(body.since)} to ${utc(body.until)}, a line every ${body.everyMinutes} ${body.everyMinutes === 1 ? "minute" : "minutes"}:
12577
+ `);
12578
+ if (body.readings.length === 0) {
12579
+ process.stdout.write("No readings: it had not joined, or they are older than the 15 days they are kept.\n");
12580
+ return;
12581
+ }
12582
+ const rows = [["FROM", "MEMORY", "CPU", "DISK", ""]];
12583
+ let away2 = 0;
12584
+ const since = Date.parse(body.since);
12585
+ const until2 = Date.parse(body.until);
12586
+ for (const reading of body.readings) {
12587
+ const from = Date.parse(reading.from);
12588
+ const inside = Math.round((Math.min(from + body.everyMinutes * 6e4, until2) - Math.max(from, since)) / 6e4);
12589
+ const note = reading.minutesRead === 0 ? "did not answer" : reading.minutesRead < inside - 1 ? `answered ${reading.minutesRead} of ${inside} minutes` : "";
12590
+ away2 += reading.minutesRead === 0 ? 1 : 0;
12591
+ rows.push([utc(reading.from), percentOf(reading.memoryUsedPercent), percentOf(reading.cpuBusyPercent), percentOf(reading.diskUsedPercent), note]);
12592
+ }
12593
+ process.stdout.write(fitted(rows));
12594
+ if (away2 > 0) {
12595
+ process.stdout.write(`It did not answer in ${away2} of ${body.readings.length} ${body.readings.length === 1 ? "line" : "lines"}.
12596
+ `);
12597
+ }
12598
+ }
12599
+
12236
12600
  // ../src/event-kinds.ts
12237
12601
  var LIFECYCLE_EVENTS = [
12238
12602
  "sandbox.created",
@@ -12303,7 +12667,7 @@ var WEBHOOK_OFF_AFTER_MS = 3 * 864e5;
12303
12667
  var USAGE6 = "webhook takes add, show, update, on, off, rotate or delete. agental webhook --help shows each.";
12304
12668
  var EVERY = "*";
12305
12669
  var TRIES2 = WEBHOOK_RETRY_AFTER_MS.length + 1;
12306
- async function ask8(client, method, pathname, body) {
12670
+ async function ask9(client, method, pathname, body) {
12307
12671
  const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
12308
12672
  let answered = null;
12309
12673
  if (response.status !== 204) {
@@ -12386,7 +12750,7 @@ function standingOf(events) {
12386
12750
  }
12387
12751
  return `given up (${answerOf(latest.tries[latest.tries.length - 1])}) ${at3(latest.lastAt)}`;
12388
12752
  }
12389
- function stateOf2(webhook2) {
12753
+ function stateOf3(webhook2) {
12390
12754
  if (webhook2.enabled !== false) {
12391
12755
  return "on";
12392
12756
  }
@@ -12415,14 +12779,14 @@ function eventsFrom(options, needed) {
12415
12779
  }
12416
12780
  return kinds;
12417
12781
  }
12418
- function describe3(webhook2) {
12782
+ function describe4(webhook2) {
12419
12783
  return [
12420
12784
  `id: ${webhook2.id}`,
12421
12785
  `name: ${nameOf(webhook2)}`,
12422
12786
  `url: ${webhook2.url}`,
12423
12787
  `sent: ${sentOf(webhook2.events)}`,
12424
12788
  `added: ${at3(webhook2.createdAt)}`,
12425
- `state: ${stateOf2(webhook2)}`,
12789
+ `state: ${stateOf3(webhook2)}`,
12426
12790
  `last post: ${standingOf(eventsOf2(webhook2.deliveries))}`,
12427
12791
  ""
12428
12792
  ].join("\n");
@@ -12435,7 +12799,7 @@ function saySecret(secret) {
12435
12799
  }
12436
12800
  }
12437
12801
  async function listWebhooks(client, asJson) {
12438
- const body = await ask8(client, "GET", "/v1/webhooks");
12802
+ const body = await ask9(client, "GET", "/v1/webhooks");
12439
12803
  if (asJson) {
12440
12804
  process.stdout.write(`${JSON.stringify(body, null, 2)}
12441
12805
  `);
@@ -12450,9 +12814,9 @@ async function listWebhooks(client, asJson) {
12450
12814
  process.stdout.write(`${[pad3("ID", 22), pad3("NAME", 18), pad3("SENT", 34), "LAST POST"].join(" ")}
12451
12815
  `);
12452
12816
  for (const webhook2 of webhooks) {
12453
- const listed = webhook2.events.join(",");
12454
- const sent = webhook2.events.includes(EVERY) ? "every event" : listed.length <= 33 ? listed : `${webhook2.events.length} kinds`;
12455
- const standing = webhook2.enabled === false ? stateOf2(webhook2) : standingOf(eventsOf2(webhook2.deliveries));
12817
+ const listed2 = webhook2.events.join(",");
12818
+ const sent = webhook2.events.includes(EVERY) ? "every event" : listed2.length <= 33 ? listed2 : `${webhook2.events.length} kinds`;
12819
+ const standing = webhook2.enabled === false ? stateOf3(webhook2) : standingOf(eventsOf2(webhook2.deliveries));
12456
12820
  process.stdout.write(`${[pad3(webhook2.id, 22), pad3(nameOf(webhook2), 18), pad3(sent, 34), standing].join(" ")}
12457
12821
  `);
12458
12822
  }
@@ -12472,7 +12836,7 @@ async function webhook(client, positionals, options) {
12472
12836
  }
12473
12837
  const events = eventsFrom(options, true);
12474
12838
  const made = webhookOf(
12475
- await ask8(client, "POST", "/v1/webhooks", { url: target, events, ...options.description !== void 0 ? { description: options.description } : {} })
12839
+ await ask9(client, "POST", "/v1/webhooks", { url: target, events, ...options.description !== void 0 ? { description: options.description } : {} })
12476
12840
  );
12477
12841
  if (options.json) {
12478
12842
  process.stdout.write(`${JSON.stringify(made, null, 2)}
@@ -12480,18 +12844,18 @@ async function webhook(client, positionals, options) {
12480
12844
  process.stderr.write("signingSecret is shown this once. Keep it where your receiver checks the X-Agental-Signature of each post.\n");
12481
12845
  return;
12482
12846
  }
12483
- process.stdout.write(describe3(made));
12847
+ process.stdout.write(describe4(made));
12484
12848
  saySecret(made.signingSecret);
12485
12849
  return;
12486
12850
  }
12487
12851
  case "show": {
12488
- const found = webhookOf(await ask8(client, "GET", `/v1/webhooks/${encodeURIComponent(needId(target, "show"))}`));
12852
+ const found = webhookOf(await ask9(client, "GET", `/v1/webhooks/${encodeURIComponent(needId(target, "show"))}`));
12489
12853
  if (options.json) {
12490
12854
  process.stdout.write(`${JSON.stringify(found, null, 2)}
12491
12855
  `);
12492
12856
  return;
12493
12857
  }
12494
- process.stdout.write(describe3(found));
12858
+ process.stdout.write(describe4(found));
12495
12859
  const slow = eventsOf2(found.deliveries).filter((one) => one.tries.length > 1 || one.outcome !== "taken");
12496
12860
  if (slow.length > 0) {
12497
12861
  process.stdout.write("\nEvents not taken at the first try, newest first:\n");
@@ -12519,27 +12883,27 @@ async function webhook(client, positionals, options) {
12519
12883
  if (Object.keys(patch).length === 0) {
12520
12884
  throw new Error("webhook update changes --url, --events (or --all) and --description, and was given none of them.");
12521
12885
  }
12522
- const updated = webhookOf(await ask8(client, "PATCH", `/v1/webhooks/${encodeURIComponent(id)}`, patch));
12886
+ const updated = webhookOf(await ask9(client, "PATCH", `/v1/webhooks/${encodeURIComponent(id)}`, patch));
12523
12887
  process.stdout.write(options.json ? `${JSON.stringify(updated, null, 2)}
12524
- ` : describe3(updated));
12888
+ ` : describe4(updated));
12525
12889
  return;
12526
12890
  }
12527
12891
  case "on":
12528
12892
  case "off": {
12529
- const turned = webhookOf(await ask8(client, "PATCH", `/v1/webhooks/${encodeURIComponent(needId(target, what))}`, { enabled: what === "on" }));
12893
+ const turned = webhookOf(await ask9(client, "PATCH", `/v1/webhooks/${encodeURIComponent(needId(target, what))}`, { enabled: what === "on" }));
12530
12894
  if (options.json) {
12531
12895
  process.stdout.write(`${JSON.stringify(turned, null, 2)}
12532
12896
  `);
12533
12897
  return;
12534
12898
  }
12535
- process.stdout.write(describe3(turned));
12899
+ process.stdout.write(describe4(turned));
12536
12900
  process.stderr.write(
12537
12901
  what === "on" ? "On. It is posted the events made from now on; none given up while it was off is sent.\n" : "Off. Nothing is posted to it, and the events still owed to it are given up. agental webhook on turns it on again.\n"
12538
12902
  );
12539
12903
  return;
12540
12904
  }
12541
12905
  case "rotate": {
12542
- const rotated = webhookOf(await ask8(client, "POST", `/v1/webhooks/${encodeURIComponent(needId(target, "rotate"))}/rotate`));
12906
+ const rotated = webhookOf(await ask9(client, "POST", `/v1/webhooks/${encodeURIComponent(needId(target, "rotate"))}/rotate`));
12543
12907
  if (options.json) {
12544
12908
  process.stdout.write(`${JSON.stringify(rotated, null, 2)}
12545
12909
  `);
@@ -12550,7 +12914,7 @@ async function webhook(client, positionals, options) {
12550
12914
  return;
12551
12915
  }
12552
12916
  case "delete": {
12553
- await ask8(client, "DELETE", `/v1/webhooks/${encodeURIComponent(needId(target, "delete"))}`);
12917
+ await ask9(client, "DELETE", `/v1/webhooks/${encodeURIComponent(needId(target, "delete"))}`);
12554
12918
  process.stdout.write("Deleted. Nothing more is posted to it, and its tries are gone.\n");
12555
12919
  return;
12556
12920
  }
@@ -12634,7 +12998,7 @@ var KEPT_WORDS = {
12634
12998
  var USAGE7 = "snapshot takes list, show, create, restore or delete. agental snapshot --help shows each.";
12635
12999
  var STORAGE_ONLY = "storage";
12636
13000
  var NONE = "\u2014";
12637
- async function ask9(client, method, pathname, init = {}) {
13001
+ async function ask10(client, method, pathname, init = {}) {
12638
13002
  const response = await client.request(pathname, {
12639
13003
  method,
12640
13004
  ...init.headers ? { headers: init.headers } : {},
@@ -12660,11 +13024,11 @@ function snapshotOf(body) {
12660
13024
  return body;
12661
13025
  }
12662
13026
  function snapshotsOf(body) {
12663
- const listed = body?.snapshots;
12664
- if (!Array.isArray(listed)) {
13027
+ const listed2 = body?.snapshots;
13028
+ if (!Array.isArray(listed2)) {
12665
13029
  throw new Error("The answer was missing snapshots.");
12666
13030
  }
12667
- return listed.map(snapshotOf);
13031
+ return listed2.map(snapshotOf);
12668
13032
  }
12669
13033
  function keptOf(snapshot2) {
12670
13034
  if (typeof snapshot2.kept !== "string") {
@@ -12678,7 +13042,7 @@ function sandboxOf2(snapshot2) {
12678
13042
  function takenOf(snapshot2, sandbox) {
12679
13043
  return snapshot2.sandboxId === sandbox || snapshot2.sandboxName === sandbox;
12680
13044
  }
12681
- function utc(iso) {
13045
+ function utc2(iso) {
12682
13046
  const moment2 = Date.parse(iso);
12683
13047
  return Number.isFinite(moment2) ? `${new Date(moment2).toISOString().slice(0, 16).replace("T", " ")} UTC` : iso;
12684
13048
  }
@@ -12696,9 +13060,9 @@ async function sandboxIdOrNone(client, word) {
12696
13060
  if (word.startsWith("sbx_")) {
12697
13061
  return word;
12698
13062
  }
12699
- const body = await ask9(client, "GET", `/v1/sandboxes?${new URLSearchParams({ q: word })}`);
12700
- const listed = Array.isArray(body?.sandboxes) ? body.sandboxes : [];
12701
- const named = listed.filter((one) => one.name === word && typeof one.id === "string");
13063
+ const body = await ask10(client, "GET", `/v1/sandboxes?${new URLSearchParams({ q: word })}`);
13064
+ const listed2 = Array.isArray(body?.sandboxes) ? body.sandboxes : [];
13065
+ const named = listed2.filter((one) => one.name === word && typeof one.id === "string");
12702
13066
  if (named.length > 1) {
12703
13067
  throw new Error(`${named.length} sandboxes are named ${word}. Give the id of the one you mean: ${named.map((one) => String(one.id)).join(", ")}.`);
12704
13068
  }
@@ -12709,32 +13073,32 @@ async function snapshotNamed(client, word, sandbox, what) {
12709
13073
  throw new Error(`snapshot ${what} needs the snapshot's id or its name, as agental snapshot list lists them.`);
12710
13074
  }
12711
13075
  if (word.startsWith("snap_")) {
12712
- const found = snapshotOf(await ask9(client, "GET", `/v1/snapshots/${encodeURIComponent(word)}`));
13076
+ const found = snapshotOf(await ask10(client, "GET", `/v1/snapshots/${encodeURIComponent(word)}`));
12713
13077
  if (sandbox !== void 0 && !takenOf(found, sandbox)) {
12714
13078
  throw new Error(`${word} is a snapshot of ${sandboxOf2(found)}, not of ${sandbox}.`);
12715
13079
  }
12716
13080
  return found;
12717
13081
  }
12718
- const among = snapshotsOf(await ask9(client, "GET", "/v1/snapshots")).filter((one) => sandbox === void 0 || takenOf(one, sandbox));
13082
+ const among = snapshotsOf(await ask10(client, "GET", "/v1/snapshots")).filter((one) => sandbox === void 0 || takenOf(one, sandbox));
12719
13083
  const named = among.filter((one) => one.name === word);
12720
13084
  const where = sandbox === void 0 ? "" : ` of ${sandbox}`;
12721
13085
  if (named.length === 0) {
12722
13086
  throw new Error(`There is no snapshot named ${word}${where}. agental snapshot list${sandbox === void 0 ? "" : ` --sandbox ${sandbox}`} lists them.`);
12723
13087
  }
12724
13088
  if (named.length > 1) {
12725
- const each = named.map((one) => `${one.id} (of ${sandboxOf2(one)}, taken ${ago(one.createdAt) ?? utc(one.createdAt)})`);
13089
+ const each = named.map((one) => `${one.id} (of ${sandboxOf2(one)}, taken ${ago(one.createdAt) ?? utc2(one.createdAt)})`);
12726
13090
  throw new Error(`${named.length} snapshots${where} are named ${word}. Give the id of the one you mean: ${each.join(", ")}.`);
12727
13091
  }
12728
- return snapshotOf(await ask9(client, "GET", `/v1/snapshots/${encodeURIComponent(named[0].id)}`));
13092
+ return snapshotOf(await ask10(client, "GET", `/v1/snapshots/${encodeURIComponent(named[0].id)}`));
12729
13093
  }
12730
- function describe4(snapshot2) {
13094
+ function describe5(snapshot2) {
12731
13095
  const status = snapshot2.sandboxStatus ?? (snapshot2.sandboxDeleted ? "deleted" : void 0);
12732
13096
  const disk = snapshot2.size !== null && isMachineSize(snapshot2.size) ? `, ${MACHINE_SIZES[snapshot2.size].diskGb} GB disk` : "";
12733
- const copied = typeof snapshot2.copiedAt === "string" ? `, copied ${ago(snapshot2.copiedAt) ?? utc(snapshot2.copiedAt)}` : "";
13097
+ const copied = typeof snapshot2.copiedAt === "string" ? `, copied ${ago(snapshot2.copiedAt) ?? utc2(snapshot2.copiedAt)}` : "";
12734
13098
  const facts = [
12735
13099
  ["Sandbox", `${sandboxOf2(snapshot2)}${status ? ` (${status})` : ""}`],
12736
13100
  ["Size", snapshot2.size === null ? NONE : `${snapshot2.size}${disk}`],
12737
- ["Taken", `${utc(snapshot2.createdAt)}${ago(snapshot2.createdAt) ? `, ${ago(snapshot2.createdAt)}` : ""}`],
13101
+ ["Taken", `${utc2(snapshot2.createdAt)}${ago(snapshot2.createdAt) ? `, ${ago(snapshot2.createdAt)}` : ""}`],
12738
13102
  ["Kept", `${keptOf(snapshot2)}${copied}`],
12739
13103
  ["State", snapshot2.state]
12740
13104
  ];
@@ -12772,14 +13136,14 @@ async function snapshotsOfSandbox(client, word) {
12772
13136
  return answered;
12773
13137
  }
12774
13138
  }
12775
- const kept2 = snapshotsOf(await ask9(client, "GET", "/v1/snapshots")).filter((one) => takenOf(one, word));
13139
+ const kept2 = snapshotsOf(await ask10(client, "GET", "/v1/snapshots")).filter((one) => takenOf(one, word));
12776
13140
  if (kept2.length === 0 && id === null) {
12777
13141
  throw new Error(`There is no sandbox named ${word}. agental list lists them.`);
12778
13142
  }
12779
13143
  return { snapshots: kept2 };
12780
13144
  }
12781
13145
  async function listSnapshots(client, options) {
12782
- const body = options.sandbox === void 0 ? await ask9(client, "GET", "/v1/snapshots") : await snapshotsOfSandbox(client, options.sandbox);
13146
+ const body = options.sandbox === void 0 ? await ask10(client, "GET", "/v1/snapshots") : await snapshotsOfSandbox(client, options.sandbox);
12783
13147
  if (options.json) {
12784
13148
  process.stdout.write(`${JSON.stringify(body, null, 2)}
12785
13149
  `);
@@ -12799,7 +13163,7 @@ async function listSnapshots(client, options) {
12799
13163
  one.id,
12800
13164
  ...all ? [`${sandboxOf2(one)}${one.sandboxDeleted ? " (deleted)" : ""}`] : [],
12801
13165
  one.size ?? NONE,
12802
- ago(one.createdAt) ?? utc(one.createdAt),
13166
+ ago(one.createdAt) ?? utc2(one.createdAt),
12803
13167
  keptOf(one)
12804
13168
  ])
12805
13169
  ];
@@ -12826,7 +13190,7 @@ async function snapshot(client, positionals, options) {
12826
13190
  case "show": {
12827
13191
  const found = await snapshotNamed(client, first, options.sandbox, "show");
12828
13192
  process.stdout.write(options.json ? `${JSON.stringify(found, null, 2)}
12829
- ` : describe4(found));
13193
+ ` : describe5(found));
12830
13194
  return;
12831
13195
  }
12832
13196
  case "create": {
@@ -12836,9 +13200,9 @@ async function snapshot(client, positionals, options) {
12836
13200
  if (options.sandbox !== void 0) {
12837
13201
  throw new Error("snapshot create takes the sandbox as its first word, not --sandbox.");
12838
13202
  }
12839
- const made = await ask9(client, "POST", `/v1/sandboxes/${encodeURIComponent(await sandboxIdOf(client, first))}/snapshots`, { body: { name: second } });
13203
+ const made = await ask10(client, "POST", `/v1/sandboxes/${encodeURIComponent(await sandboxIdOf(client, first))}/snapshots`, { body: { name: second } });
12840
13204
  process.stdout.write(options.json ? `${JSON.stringify(made, null, 2)}
12841
- ` : describe4(snapshotOf(made)));
13205
+ ` : describe5(snapshotOf(made)));
12842
13206
  return;
12843
13207
  }
12844
13208
  case "restore": {
@@ -12847,7 +13211,7 @@ async function snapshot(client, positionals, options) {
12847
13211
  if (found.sandboxDeleted) {
12848
13212
  throw new Error(`${sandbox} is deleted: there is nothing to roll back. agental sandbox create --snapshot ${found.id} starts a new sandbox from it.`);
12849
13213
  }
12850
- const question = `Roll ${sandbox} back to ${found.name}, taken ${ago(found.createdAt) ?? utc(found.createdAt)}? What runs in it ends, its snapshots taken after this one are deleted, and its address and SSH port may change. It cannot be undone.`;
13214
+ const question = `Roll ${sandbox} back to ${found.name}, taken ${ago(found.createdAt) ?? utc2(found.createdAt)}? What runs in it ends, its snapshots taken after this one are deleted, and its address and SSH port may change. It cannot be undone.`;
12851
13215
  if (!options.yes && !await client.confirmed(question)) {
12852
13216
  process.stderr.write("Nothing was rolled back. --yes goes on without asking.\n");
12853
13217
  process.exitCode = 1;
@@ -12856,7 +13220,7 @@ async function snapshot(client, positionals, options) {
12856
13220
  if (found.kept === STORAGE_ONLY) {
12857
13221
  process.stderr.write("Its server no longer holds it: it is fetched from storage first, which takes a few minutes.\n");
12858
13222
  }
12859
- const answer3 = await ask9(client, "POST", `/v1/sandboxes/${encodeURIComponent(found.sandboxId)}/restore`, {
13223
+ const answer3 = await ask10(client, "POST", `/v1/sandboxes/${encodeURIComponent(found.sandboxId)}/restore`, {
12860
13224
  headers: { "Idempotency-Key": options.idempotencyKey ?? `cli-${randomUUID2()}` },
12861
13225
  body: { snapshotId: found.id }
12862
13226
  });
@@ -12878,13 +13242,13 @@ async function snapshot(client, positionals, options) {
12878
13242
  }
12879
13243
  case "delete": {
12880
13244
  const found = await snapshotNamed(client, first, options.sandbox, "delete");
12881
- const question = `Delete ${found.name} (${found.id}), of ${sandboxOf2(found)}, taken ${ago(found.createdAt) ?? utc(found.createdAt)}? It cannot be undone.`;
13245
+ const question = `Delete ${found.name} (${found.id}), of ${sandboxOf2(found)}, taken ${ago(found.createdAt) ?? utc2(found.createdAt)}? It cannot be undone.`;
12882
13246
  if (!options.yes && !await client.confirmed(question)) {
12883
13247
  process.stderr.write("Nothing was deleted. --yes goes on without asking.\n");
12884
13248
  process.exitCode = 1;
12885
13249
  return;
12886
13250
  }
12887
- await ask9(client, "DELETE", `/v1/snapshots/${encodeURIComponent(found.id)}`);
13251
+ await ask10(client, "DELETE", `/v1/snapshots/${encodeURIComponent(found.id)}`);
12888
13252
  process.stdout.write(`Deleted ${found.name} (${found.id}). Sandboxes made from it are not affected.
12889
13253
  `);
12890
13254
  return;
@@ -12905,7 +13269,7 @@ async function bodyOf2(response) {
12905
13269
  return null;
12906
13270
  }
12907
13271
  }
12908
- async function ask10(client, method, pathname, body) {
13272
+ async function ask11(client, method, pathname, body) {
12909
13273
  const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
12910
13274
  const answered = await bodyOf2(response);
12911
13275
  if (!response.ok) {
@@ -12921,10 +13285,10 @@ function routeOf(body) {
12921
13285
  }
12922
13286
  var isSite = (route) => route.public && !route.hidden;
12923
13287
  async function sitesOf(client, sandbox) {
12924
- const body = await ask10(client, "GET", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`);
13288
+ const body = await ask11(client, "GET", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`);
12925
13289
  return (Array.isArray(body?.routes) ? body.routes : []).map(routeOf).filter(isSite);
12926
13290
  }
12927
- function stateOf3(route) {
13291
+ function stateOf4(route) {
12928
13292
  if (route.proxy !== "available") {
12929
13293
  return "not reachable: is the sandbox running?";
12930
13294
  }
@@ -13006,7 +13370,7 @@ async function siteSwitch(client, turn, words2, options) {
13006
13370
  process.exitCode = 1;
13007
13371
  return;
13008
13372
  }
13009
- const report = await ask10(client, "PUT", `/v1/host-routes/${encodeURIComponent(target)}/analytics`, { enabled: turn === "on" });
13373
+ const report = await ask11(client, "PUT", `/v1/host-routes/${encodeURIComponent(target)}/analytics`, { enabled: turn === "on" });
13010
13374
  if (options.json) {
13011
13375
  process.stdout.write(`${reportJson(report)}
13012
13376
  `);
@@ -13032,7 +13396,7 @@ async function organizationSwitch(client, words2, options) {
13032
13396
  }
13033
13397
  let setting;
13034
13398
  if (turn === void 0) {
13035
- setting = await ask10(client, "GET", "/v1/site-analytics");
13399
+ setting = await ask11(client, "GET", "/v1/site-analytics");
13036
13400
  } else {
13037
13401
  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.")) {
13038
13402
  process.stderr.write("Nothing was changed. --yes goes on without asking.\n");
@@ -13103,7 +13467,7 @@ async function site(client, positionals, options) {
13103
13467
  `);
13104
13468
  return;
13105
13469
  }
13106
- const rows = [["ID", "ADDRESS", "PORT", "STATE"], ...sites.map((route) => [route.id, route.url ?? "no public address here", String(route.port), stateOf3(route)])];
13470
+ const rows = [["ID", "ADDRESS", "PORT", "STATE"], ...sites.map((route) => [route.id, route.url ?? "no public address here", String(route.port), stateOf4(route)])];
13107
13471
  const terminal2 = isTerminal(process.stdout);
13108
13472
  process.stdout.write(fitted(rows, { ...terminal2 ? { give: 1 } : { width: Number.MAX_SAFE_INTEGER }, paint: (cell, row) => row === 0 ? faint(cell) : cell }));
13109
13473
  return;
@@ -13113,7 +13477,7 @@ async function site(client, positionals, options) {
13113
13477
  throw new Error(USAGE8);
13114
13478
  }
13115
13479
  const port = portFrom(target);
13116
- const made = routeOf(await ask10(client, "POST", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`, { port, title: `port-${port}`, public: true }));
13480
+ const made = routeOf(await ask11(client, "POST", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`, { port, title: `port-${port}`, public: true }));
13117
13481
  if (options.json) {
13118
13482
  process.stdout.write(`${JSON.stringify(made, null, 2)}
13119
13483
  `);
@@ -13138,7 +13502,7 @@ async function site(client, positionals, options) {
13138
13502
  throw new Error(`site rm needs the sandbox and the site's id, as agental site ${sandbox} lists them.`);
13139
13503
  }
13140
13504
  const found = await siteOn(client, sandbox, target);
13141
- await ask10(client, "POST", `/v1/host-routes/${encodeURIComponent(target)}/hide`);
13505
+ await ask11(client, "POST", `/v1/host-routes/${encodeURIComponent(target)}/hide`);
13142
13506
  process.stdout.write(`Removed. ${found.url ?? `Port ${found.port}`} stops working now; adding port ${found.port} again gives a new link.
13143
13507
  `);
13144
13508
  return;
@@ -13152,7 +13516,7 @@ async function site(client, positionals, options) {
13152
13516
  throw new Error(`--range is 24h or 7d. It was given ${range}.`);
13153
13517
  }
13154
13518
  await siteOn(client, sandbox, target);
13155
- const report = await ask10(client, "GET", `/v1/host-routes/${encodeURIComponent(target)}/analytics?range=${range}`);
13519
+ const report = await ask11(client, "GET", `/v1/host-routes/${encodeURIComponent(target)}/analytics?range=${range}`);
13156
13520
  process.stdout.write(options.json ? `${reportJson(report)}
13157
13521
  ` : reportIn(report, sandbox, target));
13158
13522
  return;
@@ -13164,7 +13528,7 @@ async function site(client, positionals, options) {
13164
13528
  var USAGE9 = "claude takes connect, show, update or disconnect. agental claude --help shows each.";
13165
13529
  var KEY_VARIABLE = "ANTHROPIC_ENVIRONMENT_KEY";
13166
13530
  var SECRET_VARIABLE = "ANTHROPIC_WEBHOOK_SIGNING_KEY";
13167
- async function ask11(client, method, pathname, body) {
13531
+ async function ask12(client, method, pathname, body) {
13168
13532
  const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
13169
13533
  let answered = null;
13170
13534
  if (response.status !== 204) {
@@ -13186,7 +13550,7 @@ function connectionOf(body) {
13186
13550
  }
13187
13551
  return connection;
13188
13552
  }
13189
- function describe5(connection) {
13553
+ function describe6(connection) {
13190
13554
  return [
13191
13555
  `id: ${connection.id}`,
13192
13556
  `environment: ${connection.environmentId}`,
@@ -13254,7 +13618,7 @@ async function hidden(question) {
13254
13618
  });
13255
13619
  }
13256
13620
  async function listClaude(client, asJson) {
13257
- const body = await ask11(client, "GET", "/v1/claude/connections");
13621
+ const body = await ask12(client, "GET", "/v1/claude/connections");
13258
13622
  if (asJson) {
13259
13623
  process.stdout.write(`${JSON.stringify(body, null, 2)}
13260
13624
  `);
@@ -13288,7 +13652,7 @@ async function claude(client, positionals, options) {
13288
13652
  const environmentKey = await secretFrom(KEY_VARIABLE, "environment key", true);
13289
13653
  const webhookSecret = await secretFrom(SECRET_VARIABLE, "webhook signing secret", false);
13290
13654
  const made = connectionOf(
13291
- await ask11(client, "POST", "/v1/claude/connections", {
13655
+ await ask12(client, "POST", "/v1/claude/connections", {
13292
13656
  environmentId: target,
13293
13657
  environmentKey,
13294
13658
  ...webhookSecret !== void 0 ? { webhookSecret } : {},
@@ -13301,7 +13665,7 @@ async function claude(client, positionals, options) {
13301
13665
  `);
13302
13666
  return;
13303
13667
  }
13304
- process.stdout.write(describe5(made));
13668
+ process.stdout.write(describe6(made));
13305
13669
  process.stderr.write(
13306
13670
  made.hasWebhookSecret ? `In the Claude Console, set ${made.webhookUrl} as a webhook for session.status_run_started.
13307
13671
  ` : `For a turn to start at once, add ${made.webhookUrl} as a webhook for session.status_run_started in the Claude Console, then: ${SECRET_VARIABLE}=whsec_... agental claude update ${made.id} --webhook-secret
@@ -13310,9 +13674,9 @@ async function claude(client, positionals, options) {
13310
13674
  return;
13311
13675
  }
13312
13676
  case "show": {
13313
- const found = connectionOf(await ask11(client, "GET", `/v1/claude/connections/${encodeURIComponent(needId2(target, "show"))}`));
13677
+ const found = connectionOf(await ask12(client, "GET", `/v1/claude/connections/${encodeURIComponent(needId2(target, "show"))}`));
13314
13678
  process.stdout.write(options.json ? `${JSON.stringify(found, null, 2)}
13315
- ` : describe5(found));
13679
+ ` : describe6(found));
13316
13680
  return;
13317
13681
  }
13318
13682
  case "update": {
@@ -13333,13 +13697,13 @@ async function claude(client, positionals, options) {
13333
13697
  if (Object.keys(patch).length === 0) {
13334
13698
  throw new Error("claude update changes --template, --keep-days, --new-key, --webhook-secret or --no-webhook-secret, and was given none of them.");
13335
13699
  }
13336
- const updated = connectionOf(await ask11(client, "PATCH", `/v1/claude/connections/${encodeURIComponent(id)}`, patch));
13700
+ const updated = connectionOf(await ask12(client, "PATCH", `/v1/claude/connections/${encodeURIComponent(id)}`, patch));
13337
13701
  process.stdout.write(options.json ? `${JSON.stringify(updated, null, 2)}
13338
- ` : describe5(updated));
13702
+ ` : describe6(updated));
13339
13703
  return;
13340
13704
  }
13341
13705
  case "disconnect": {
13342
- await ask11(client, "DELETE", `/v1/claude/connections/${encodeURIComponent(needId2(target, "disconnect"))}`);
13706
+ await ask12(client, "DELETE", `/v1/claude/connections/${encodeURIComponent(needId2(target, "disconnect"))}`);
13343
13707
  process.stdout.write("Disconnected: its key and signing secret are forgotten, and no more of its work is claimed. Its sessions' sandboxes are left as they are.\n");
13344
13708
  return;
13345
13709
  }
@@ -13416,11 +13780,11 @@ async function shellNamed(client, id, given, flag) {
13416
13780
  throw new Error(`${flag} takes a kept shell's number or its id, as ${flag} 2 or ${flag} pty_0123456789abcdef: agental shell ${id} --list lists them.`);
13417
13781
  }
13418
13782
  if (byId) {
13419
- const listed2 = await keptShells2(client, id).catch(() => []);
13420
- return { id: given, n: listed2.find((each) => each.id === given)?.n ?? null };
13783
+ const listed3 = await keptShells2(client, id).catch(() => []);
13784
+ return { id: given, n: listed3.find((each) => each.id === given)?.n ?? null };
13421
13785
  }
13422
- const listed = await keptShells2(client, id);
13423
- const found = listed.find((each) => each.n === Number(given));
13786
+ const listed2 = await keptShells2(client, id);
13787
+ const found = listed2.find((each) => each.n === Number(given));
13424
13788
  if (found) {
13425
13789
  if (typeof found.id !== "string" || !PTY_ID.test(found.id)) {
13426
13790
  throw new Error(`The list of kept shells named shell ${given} with an id that is not one.`);
@@ -13430,29 +13794,29 @@ async function shellNamed(client, id, given, flag) {
13430
13794
  if (byId) {
13431
13795
  return { id: given, n: null };
13432
13796
  }
13433
- throw new Error(`Sandbox ${id} keeps no shell ${given}${listed.length > 0 ? `; it keeps ${listed.map((each) => each.n).join(", ")}` : ""}. agental shell ${id} --list lists them.`);
13797
+ throw new Error(`Sandbox ${id} keeps no shell ${given}${listed2.length > 0 ? `; it keeps ${listed2.map((each) => each.n).join(", ")}` : ""}. agental shell ${id} --list lists them.`);
13434
13798
  }
13435
- function stateOf4(each) {
13799
+ function stateOf5(each) {
13436
13800
  if (each.exit) {
13437
13801
  return each.exit.signal > 0 ? `ended by signal ${each.exit.signal}` : `exited ${each.exit.code}`;
13438
13802
  }
13439
13803
  return each.running ?? "";
13440
13804
  }
13441
13805
  async function listShells(client, id, json3, stdout) {
13442
- const listed = await keptShells2(client, id);
13806
+ const listed2 = await keptShells2(client, id);
13443
13807
  if (json3) {
13444
- stdout.write(`${JSON.stringify(listed, null, 2)}
13808
+ stdout.write(`${JSON.stringify(listed2, null, 2)}
13445
13809
  `);
13446
13810
  return;
13447
13811
  }
13448
- if (listed.length === 0) {
13812
+ if (listed2.length === 0) {
13449
13813
  stdout.write(`No kept shells. agental shell ${id} opens one.
13450
13814
  `);
13451
13815
  return;
13452
13816
  }
13453
13817
  const rows = [
13454
13818
  ["N", "ID", "RUNNING", "CWD", "ATTACHED", "STARTED"],
13455
- ...listed.map((each) => [String(each.n), each.id, stateOf4(each), each.cwd ?? "", each.attached ? "yes" : "no", ago(each.startedAt) ?? each.startedAt])
13819
+ ...listed2.map((each) => [String(each.n), each.id, stateOf5(each), each.cwd ?? "", each.attached ? "yes" : "no", ago(each.startedAt) ?? each.startedAt])
13456
13820
  ];
13457
13821
  stdout.write(fitted(rows, { give: 2, paint: (cell, row) => row === 0 ? faint(cell, stdout) : cell }));
13458
13822
  }
@@ -13501,16 +13865,16 @@ async function shell(client, id, options = {}, streams = process) {
13501
13865
  const verifier = randomBytes4(32).toString("base64url");
13502
13866
  const challenge = createHash3("sha256").update(verifier).digest("base64url");
13503
13867
  const interactive = stdin.isTTY === true && typeof stdin.setRawMode === "function";
13504
- const ask12 = async (keep) => await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminal`, {
13868
+ const ask13 = async (keep) => await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminal`, {
13505
13869
  method: "POST",
13506
13870
  body: JSON.stringify({ ...size2, challenge, ...again ? { terminal: again.id } : keep ? { keep: true } : {} })
13507
13871
  });
13508
- let response = await ask12(interactive);
13872
+ let response = await ask13(interactive);
13509
13873
  let body = await response.json().catch(() => null);
13510
13874
  if (!again && interactive && response.status === 409 && body?.error?.code === "terminal_unavailable" && /keeps \d+ terminals/.test(String(body.error.message ?? ""))) {
13511
13875
  stderr.write(`${String(body.error.message)} This one is not kept.
13512
13876
  `);
13513
- response = await ask12(false);
13877
+ response = await ask13(false);
13514
13878
  body = await response.json().catch(() => null);
13515
13879
  }
13516
13880
  if (!response.ok || typeof body?.ticket !== "string") {
@@ -14086,6 +14450,8 @@ async function main() {
14086
14450
  "on-timeout": { type: "string" },
14087
14451
  // agental create and agental spot: a spot sandbox, what is done when its room is taken back, and the chance it is warned at.
14088
14452
  spot: { type: "boolean", default: false },
14453
+ // agental create and template start: a standard sandbox, whatever the template's start says of spot.
14454
+ standard: { type: "boolean", default: false },
14089
14455
  "on-reclaim": { type: "string" },
14090
14456
  "warn-at": { type: "string" },
14091
14457
  "max-burst-fee": { type: "string" },
@@ -14133,6 +14499,9 @@ async function main() {
14133
14499
  facets: { type: "string" },
14134
14500
  yes: { type: "boolean", default: false },
14135
14501
  confirm: { type: "string" },
14502
+ // agental servers offload: how used a server of the organization's own may be and still take a new sandbox. servers core-days: which month.
14503
+ over: { type: "string" },
14504
+ month: { type: "string" },
14136
14505
  // agental site stats: 24h or 7d.
14137
14506
  range: { type: "string" },
14138
14507
  // agental site analytics org on: the person has read what is kept.
@@ -14337,6 +14706,12 @@ async function main() {
14337
14706
  case "webhook":
14338
14707
  await webhook({ request, fail }, positionals.slice(1), values);
14339
14708
  return;
14709
+ case "servers":
14710
+ await servers({ request, fail, confirmed }, positionals.slice(1), values);
14711
+ return;
14712
+ case "server":
14713
+ await server({ request, fail, confirmed }, positionals.slice(1), values);
14714
+ return;
14340
14715
  case "claude": {
14341
14716
  const client = { request, fail, templateId: async (word) => (await templateNamed(word)).id };
14342
14717
  if (positionals.length === 1) {
@@ -14413,7 +14788,10 @@ async function create(values) {
14413
14788
  if (!values.spot && (values["on-reclaim"] !== void 0 || values["warn-at"] !== void 0)) {
14414
14789
  throw new Error("--on-reclaim and --warn-at are for a spot sandbox: add --spot.");
14415
14790
  }
14416
- const spotAsked = values.spot ? spotSettingsFrom(values) : void 0;
14791
+ if (values.spot && values.standard) {
14792
+ throw new Error("--spot and --standard say two things: give one.");
14793
+ }
14794
+ const spotAsked = values.spot ? spotSettingsFrom(values) : values.standard ? null : void 0;
14417
14795
  if (values.outbound !== void 0) {
14418
14796
  throw new Error(
14419
14797
  "--outbound is gone: a sandbox's rule comes from its template. Set it with agental template network <template> open|blocked|allowlist <address>..., and make the sandbox with --template <template>. --allow gives it addresses of its own on top."
@@ -14551,15 +14929,15 @@ async function regions(asJson) {
14551
14929
  if (!response.ok) {
14552
14930
  fail(response.status, body);
14553
14931
  }
14554
- const listed = Array.isArray(body["regions"]) ? body["regions"] : [];
14932
+ const listed2 = Array.isArray(body["regions"]) ? body["regions"] : [];
14555
14933
  if (asJson) {
14556
- process.stdout.write(`${JSON.stringify(listed, null, 2)}
14934
+ process.stdout.write(`${JSON.stringify(listed2, null, 2)}
14557
14935
  `);
14558
14936
  return;
14559
14937
  }
14560
14938
  process.stdout.write(`${[pad2("REGION"), pad2("NAME"), "ROOM FOR"].join(" ")}
14561
14939
  `);
14562
- for (const region of listed) {
14940
+ for (const region of listed2) {
14563
14941
  const room = Array.isArray(region["sizesWithRoom"]) ? region["sizesWithRoom"].map(String) : [];
14564
14942
  const name = `${String(region["name"] ?? "")}${region["default"] === true ? " *" : ""}`;
14565
14943
  process.stdout.write(`${[pad2(name), pad2(String(region["label"] ?? "")), room.length > 0 ? room.join(", ") : "nothing now"].join(" ")}
@@ -14779,15 +15157,15 @@ async function bulkActionsCommand(positionals, asJson) {
14779
15157
  `);
14780
15158
  return;
14781
15159
  }
14782
- const listed = verb === void 0 || verb === "list" ? body.actions ?? [] : [body];
14783
- if (listed.length === 0) {
15160
+ const listed2 = verb === void 0 || verb === "list" ? body.actions ?? [] : [body];
15161
+ if (listed2.length === 0) {
14784
15162
  process.stdout.write("No bulk actions.\n");
14785
15163
  return;
14786
15164
  }
14787
- for (const job2 of listed) {
15165
+ for (const job2 of listed2) {
14788
15166
  process.stdout.write(`${job2.id} ${pad2(job2.action)} ${pad2(job2.state)} ${job2.counts["done"] ?? 0}/${job2.total} done, ${job2.counts["failed"] ?? 0} failed, ${job2.counts["skipped"] ?? 0} skipped ${job2.createdAt}
14789
15167
  `);
14790
- if (listed.length === 1) {
15168
+ if (listed2.length === 1) {
14791
15169
  for (const problem of job2.problems) {
14792
15170
  process.stdout.write(` ${problem.sandboxId} ${problem.state}${problem.reason ? `: ${problem.reason}` : ""}
14793
15171
  `);
@@ -15121,8 +15499,8 @@ async function screenshot(id, file, options) {
15121
15499
  query.set("height", String(region[3]));
15122
15500
  }
15123
15501
  if (options.scale !== void 0) {
15124
- if (!/^(0(\.\d+)?|1(\.0+)?)$/.test(options.scale) || Number(options.scale) < 0.1) {
15125
- throw new Error("--scale is how much smaller the picture is made, from 0.1 to 1: 0.5 is half as wide and half as high");
15502
+ if (!/^(0(\.\d+)?|1(\.0+)?|2(\.0+)?)$/.test(options.scale) || Number(options.scale) < 0.1) {
15503
+ throw new Error("--scale is how large the picture is made, from 0.1 to 1, or 2 for every pixel of a desktop drawn at 2x: 0.5 is half as wide and half as high");
15126
15504
  }
15127
15505
  query.set("scale", options.scale);
15128
15506
  }
@@ -15379,8 +15757,8 @@ async function labels(what, holder, positionals, asJson) {
15379
15757
  ` : labelsInWords(body));
15380
15758
  }
15381
15759
  function ruleInWords(rule) {
15382
- const listed = Array.isArray(rule?.allow) ? rule.allow.map(String) : [];
15383
- return listed.length > 0 ? `${String(rule?.outbound ?? "")}: ${listed.join(", ")}` : String(rule?.outbound ?? "");
15760
+ const listed2 = Array.isArray(rule?.allow) ? rule.allow.map(String) : [];
15761
+ return listed2.length > 0 ? `${String(rule?.outbound ?? "")}: ${listed2.join(", ")}` : String(rule?.outbound ?? "");
15384
15762
  }
15385
15763
  function ownAddressesWarning(id, removedAll, heldTo, template2) {
15386
15764
  const blockIt = `agental template network ${template2} blocked, then agental template apply ${template2} ${id}`;
@@ -15574,8 +15952,8 @@ async function templateNames() {
15574
15952
  }
15575
15953
  }
15576
15954
  async function templateNamed(word) {
15577
- const listed = await templatesListed();
15578
- const found = listed.find((each) => each.id === word) ?? listed.find((each) => each.name === word);
15955
+ const listed2 = await templatesListed();
15956
+ const found = listed2.find((each) => each.id === word) ?? listed2.find((each) => each.name === word);
15579
15957
  if (!found) {
15580
15958
  throw new Error(`There is no template ${word}. agental templates lists them.`);
15581
15959
  }
@@ -15583,19 +15961,21 @@ async function templateNamed(word) {
15583
15961
  }
15584
15962
  function startInWords(start2) {
15585
15963
  const runs = typeof start2?.ttlSeconds === "number" ? `, runs ${timeInWords(start2.ttlSeconds)} after each start` : "";
15586
- return `${start2?.size ?? ""}, ${start2?.snapshotId ? `from snapshot ${start2.snapshotId}` : "a new machine"}${runs}`;
15964
+ const region = start2?.region ? `, in region ${start2.region}` : "";
15965
+ const spot2 = start2?.spot ? `, spot (${start2.spot.onReclaim === "delete" ? "deleted" : "stopped"} when its room is taken back)` : "";
15966
+ return `${start2?.size ?? ""}, ${start2?.snapshotId ? `from snapshot ${start2.snapshotId}` : "a new machine"}${runs}${region}${spot2}`;
15587
15967
  }
15588
15968
  async function listTemplates(asJson) {
15589
- const listed = await templatesListed();
15969
+ const listed2 = await templatesListed();
15590
15970
  if (asJson) {
15591
- process.stdout.write(`${JSON.stringify(listed, null, 2)}
15971
+ process.stdout.write(`${JSON.stringify(listed2, null, 2)}
15592
15972
  `);
15593
15973
  return;
15594
15974
  }
15595
15975
  if (isTerminal(process.stdout)) {
15596
15976
  const rows = [
15597
15977
  ["ID", "NAME", "START", "SANDBOXES"],
15598
- ...listed.map((each) => [each.id, each.default ? `${each.name} (default)` : each.name, `${each.start?.size ?? ""}${each.start?.snapshotId ? ` from ${each.start.snapshotId}` : ""}`, String(each.sandboxes ?? 0)])
15978
+ ...listed2.map((each) => [each.id, each.default ? `${each.name} (default)` : each.name, `${each.start?.size ?? ""}${each.start?.snapshotId ? ` from ${each.start.snapshotId}` : ""}`, String(each.sandboxes ?? 0)])
15599
15979
  ];
15600
15980
  process.stdout.write(fitted(rows, { give: 1, paint: (cell, row) => row === 0 ? faint(cell) : cell }));
15601
15981
  process.stdout.write(`
@@ -15605,7 +15985,7 @@ ${faint("The default is used when a sandbox is made without naming one. agental
15605
15985
  }
15606
15986
  process.stdout.write(`${[pad2("ID"), pad2("NAME"), pad2("START"), "SANDBOXES"].join(" ")}
15607
15987
  `);
15608
- for (const each of listed) {
15988
+ for (const each of listed2) {
15609
15989
  const start2 = `${each.start?.size ?? ""}${each.start?.snapshotId ? ` from ${each.start.snapshotId}` : ""}`;
15610
15990
  process.stdout.write(`${[pad2(each.id), pad2(each.default ? `${each.name} *` : each.name), pad2(start2), String(each.sandboxes ?? 0)].join(" ")}
15611
15991
  `);
@@ -15700,14 +16080,28 @@ async function template(positionals, values) {
15700
16080
  throw new Error("--size must be tiny, small, medium or large");
15701
16081
  }
15702
16082
  const ttlSeconds = ttlOption(values.ttl);
16083
+ if (values.spot && values.standard) {
16084
+ throw new Error("--spot and --standard say two things: give one.");
16085
+ }
16086
+ if (!values.spot && (values["on-reclaim"] !== void 0 || values["warn-at"] !== void 0)) {
16087
+ throw new Error("--on-reclaim and --warn-at are for spot sandboxes: add --spot.");
16088
+ }
16089
+ if (values.region !== void 0 && values.region.includes(",")) {
16090
+ throw new Error("--region on a template is one region, or default for the account's default region.");
16091
+ }
16092
+ const region = values.region === void 0 ? void 0 : values.region === "default" ? null : values.region;
16093
+ const spot2 = values.spot ? spotSettingsFrom(values) : values.standard ? null : void 0;
15703
16094
  let start2;
15704
- if (values.size === void 0 && values.snapshot === void 0 && !values["new-machine"] && ttlSeconds === void 0) {
16095
+ if (values.size === void 0 && values.snapshot === void 0 && !values["new-machine"] && ttlSeconds === void 0 && region === void 0 && spot2 === void 0) {
15705
16096
  start2 = await call2(path6, { method: "GET" });
15706
16097
  } else {
15707
16098
  const current = await call2(path6, { method: "GET" });
15708
16099
  const snapshotId = values["new-machine"] ? null : values.snapshot ?? current?.snapshotId ?? null;
15709
16100
  const ttl = ttlSeconds === void 0 ? current?.ttlSeconds ?? null : ttlSeconds;
15710
- start2 = await call2(path6, { method: "PUT", body: JSON.stringify({ size: values.size ?? current?.size, snapshotId, ttlSeconds: ttl }) });
16101
+ start2 = await call2(path6, {
16102
+ method: "PUT",
16103
+ body: JSON.stringify({ size: values.size ?? current?.size, snapshotId, ttlSeconds: ttl, ...region === void 0 ? {} : { region }, ...spot2 === void 0 ? {} : { spot: spot2 } })
16104
+ });
15711
16105
  }
15712
16106
  print4(start2, `start: ${startInWords(start2)}
15713
16107
  `);
@@ -15724,14 +16118,14 @@ async function template(positionals, values) {
15724
16118
  if (!OUTBOUND_MODES.some((known) => known === mode)) {
15725
16119
  throw new Error("template network requires <template>, and then nothing, open, blocked, or allowlist <address>...");
15726
16120
  }
15727
- const listed = listedIn(addresses);
16121
+ const listed2 = listedIn(addresses);
15728
16122
  if (mode !== "allowlist" && addresses.length > 0) {
15729
16123
  throw new Error(`Addresses and names are for allowlist. With ${mode}, leave them out.`);
15730
16124
  }
15731
- if (mode === "allowlist" && listed.length === 0) {
16125
+ if (mode === "allowlist" && listed2.length === 0) {
15732
16126
  throw new Error(`allowlist needs at least one address or name, as agental template network ${first ?? ""} allowlist github.com 203.0.113.7`);
15733
16127
  }
15734
- rule = await call2(path6, { method: "PUT", body: JSON.stringify(mode === "allowlist" ? { outbound: mode, allow: listed } : { outbound: mode }) });
16128
+ rule = await call2(path6, { method: "PUT", body: JSON.stringify(mode === "allowlist" ? { outbound: mode, allow: listed2 } : { outbound: mode }) });
15735
16129
  }
15736
16130
  print4(
15737
16131
  rule,
@@ -15868,9 +16262,9 @@ async function secrets(positionals, values) {
15868
16262
  };
15869
16263
  switch (action) {
15870
16264
  case void 0: {
15871
- const listed = await call2(`${base}/variables`, { method: "GET" });
15872
- const names2 = listed.names;
15873
- const hidden2 = listed.hidden ?? [];
16265
+ const listed2 = await call2(`${base}/variables`, { method: "GET" });
16266
+ const names2 = listed2.names;
16267
+ const hidden2 = listed2.hidden ?? [];
15874
16268
  const paths = (await call2(`${base}/files`, { method: "GET" })).paths;
15875
16269
  if (values.json) {
15876
16270
  process.stdout.write(`${JSON.stringify({ variables: names2, hidden: hidden2, files: paths }, null, 2)}
@@ -16572,31 +16966,31 @@ async function invoices(asJson, limit) {
16572
16966
  throw new Error("billing invoices --limit takes how many of the newest invoices to list, a whole number from 1 to 100.");
16573
16967
  }
16574
16968
  const wanted = limit === void 0 ? Infinity : Number(limit);
16575
- const listed = [];
16969
+ const listed2 = [];
16576
16970
  let after = null;
16577
16971
  do {
16578
- const query = new URLSearchParams({ limit: String(Math.min(100, wanted - listed.length)) });
16972
+ const query = new URLSearchParams({ limit: String(Math.min(100, wanted - listed2.length)) });
16579
16973
  if (after !== null) {
16580
16974
  query.set("startingAfter", after);
16581
16975
  }
16582
16976
  const body = await asked(`/v1/billing/invoices?${query}`, { method: "GET" });
16583
- listed.push(...body.invoices);
16977
+ listed2.push(...body.invoices);
16584
16978
  after = body.next === after ? null : body.next;
16585
- } while (after !== null && listed.length < wanted);
16586
- listed.splice(wanted);
16979
+ } while (after !== null && listed2.length < wanted);
16980
+ listed2.splice(wanted);
16587
16981
  if (after !== null) {
16588
16982
  process.stderr.write("There are older invoices. Drop --limit to list them all.\n");
16589
16983
  }
16590
16984
  if (asJson) {
16591
- process.stdout.write(`${JSON.stringify(listed, null, 2)}
16985
+ process.stdout.write(`${JSON.stringify(listed2, null, 2)}
16592
16986
  `);
16593
16987
  return;
16594
16988
  }
16595
- if (listed.length === 0) {
16989
+ if (listed2.length === 0) {
16596
16990
  process.stdout.write("No invoices yet. A plan's month, a top-up or an auto-reload makes one once it is charged.\n");
16597
16991
  return;
16598
16992
  }
16599
- const rows = listed.map((invoice) => [
16993
+ const rows = listed2.map((invoice) => [
16600
16994
  shortDayOf(invoice.createdAt),
16601
16995
  invoice.number ?? "-",
16602
16996
  INVOICE_STATES[invoice.status] ?? invoice.status,
@@ -16608,12 +17002,12 @@ async function invoices(asJson, limit) {
16608
17002
  const [day, number, state2, total, what] = row;
16609
17003
  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");
16610
17004
  }
16611
- for (const invoice of listed.filter((each) => each.status === "open" && each.pageUrl)) {
17005
+ for (const invoice of listed2.filter((each) => each.status === "open" && each.pageUrl)) {
16612
17006
  process.stdout.write(`${invoice.number ?? invoice.id} is not paid yet. Pay it at:
16613
17007
  ${invoice.pageUrl}
16614
17008
  `);
16615
17009
  }
16616
- if (listed.some((each) => each.pdfUrl)) {
17010
+ if (listed2.some((each) => each.pdfUrl)) {
16617
17011
  process.stdout.write("--json gives each one's page and PDF.\n");
16618
17012
  }
16619
17013
  }
@@ -17142,7 +17536,7 @@ Setting up
17142
17536
 
17143
17537
  Usage
17144
17538
  agental create [--name <name>] [--template <template>] [--snapshot <snapshot-id>] [--size tiny|small|medium|large] [--region <region>[,<region>...]] [--ttl <time> | --ttl default] [--on-timeout delete|stop|stop-with-memory] [--idempotency-key <key>]
17145
- [--spot [--on-reclaim delete|stop] [--warn-at <chance>]]
17539
+ [--spot [--on-reclaim delete|stop] [--warn-at <chance>] | --standard]
17146
17540
  ${operator ? "[--box <name-or-id>] " : ""}[--allow <address>[,<address>...]] [--egress box | residential:<country>[:sticky|rotating]] [--max-burst-fee <dollars>]
17147
17541
  [--ssh-key <public-key-or-file>]... [--tag <tag>[,<tag>...]]... [--meta <key>=<value>]...
17148
17542
  agental summary [--where '<words>'] [--tag <tag>[,<tag>...]]... [--meta <key>=<value>]... [--facets <field>[,<field>...]] [--json]
@@ -17182,7 +17576,7 @@ Usage
17182
17576
  agental template show <template> [--json]
17183
17577
  agental template rename <template> <new-name>
17184
17578
  agental template delete <template> [--pause-jobs]
17185
- agental template start <template> [--size tiny|small|medium|large] [--snapshot <snapshot-id> | --new-machine] [--ttl <time> | --ttl default]
17579
+ agental template start <template> [--size tiny|small|medium|large] [--snapshot <snapshot-id> | --new-machine] [--ttl <time> | --ttl default] [--region <region> | --region default] [--spot [--on-reclaim delete|stop] [--warn-at <chance>] | --standard]
17186
17580
  agental template network <template> [open | blocked | allowlist <address-or-name>...] [--json]
17187
17581
  agental template egress <template> [box | residential <country> [sticky | rotating]] [--json]
17188
17582
  agental template ssh <template> [on | off] [--json]
@@ -17245,6 +17639,16 @@ Usage
17245
17639
  agental webhook on|off <webhook-id> [--json]
17246
17640
  agental webhook rotate <webhook-id> [--json]
17247
17641
  agental webhook delete <webhook-id>
17642
+ agental servers [--json]
17643
+ agental servers offload [on|off] [--over <percent>] [--json]
17644
+ agental servers core-days [--month <yyyy-mm>] [--json]
17645
+ agental server add <label> [--json] its install line and join token, shown once
17646
+ agental server show <server> [--json]
17647
+ agental server readings <server> [--since <date-time>] [--until <date-time>] [--every 1|5|15|60] [--json]
17648
+ agental server token <server> [--json] a new join token; the old one stops at once
17649
+ agental server drain <server> [--json]
17650
+ agental server gone <server> --reason <text> [--yes] [--json] cannot be undone
17651
+ agental server remove <server> [--json]
17248
17652
  agental claude [--json]
17249
17653
  agental claude connect <environment-id> [--template <template>|default] [--keep-days <n>] [--json]
17250
17654
  agental claude show <connection-id> [--json]
@@ -17292,7 +17696,7 @@ ${FILES_USAGE.map((line) => ` ${line}`).join("\n")}
17292
17696
  [--reply-to <message-id>] [--idempotency-key <key>]
17293
17697
  agental email account [--json]
17294
17698
  agental desktop <sandbox-id> [--screen <width>x<height>] [--off] [--status]
17295
- agental desktop <sandbox-id> --screenshot <file> [--crop <x,y,width,height>] [--scale <0.1-1>]
17699
+ agental desktop <sandbox-id> --screenshot <file> [--crop <x,y,width,height>] [--scale <0.1-2>]
17296
17700
  [--quality <1-100>] [--no-cursor]
17297
17701
  agental desktop <sandbox-id> --click <x,y> | --move <x,y> | --drag <x,y,x,y>
17298
17702
  | --scroll <x,y,notches> | --type <text> | --key <keys>
@@ -17513,6 +17917,20 @@ command line, and the webhook's signing secret likewise from ANTHROPIC_WEBHOOK_S
17513
17917
  prints the address to give the Claude Console as the webhook for session.status_run_started. update
17514
17918
  --new-key and --webhook-secret read a new one the same way; --no-webhook-secret forgets it.
17515
17919
  disconnect forgets the key and claims no more of its work.
17920
+ servers lists your organization's own servers, on the Enterprise plan: each one's state, whether
17921
+ its agent is heard from, its cores and the sandboxes on it. Only an owner or an admin manages them.
17922
+ server add <label> adds one by your own name for it, and prints the line to run as root on it and
17923
+ the one-time token in that line, shown this once; it needs an Enterprise contract in force. token
17924
+ gives a server that has not joined a new token, and the old one stops working. A <server> is its id
17925
+ or its label. show says how it stands; readings is its memory, CPU and disk over the last day, a
17926
+ line an hour unless --every says otherwise, noting the times it did not answer. drain takes it out
17927
+ of placement and stops or moves nothing. remove removes one that holds nothing and prints the line
17928
+ that takes its agent off. gone says a server is gone for good, once it is drained and its agent has
17929
+ been away 24 hours: its sandboxes are said lost, and it cannot be undone, so it asks first unless
17930
+ --yes, and --reason says why. servers offload says whether a new sandbox that names no region
17931
+ starts on agental's servers when none of yours has room under --over percent of its memory, CPU
17932
+ and disk (80 to begin with); on and off turn it on and off. Such a sandbox is a hosted one, billed as
17933
+ one, from your credits. servers core-days is the month's cores as they are counted for billing, day by day.
17516
17934
  org lists the organizations you are in, your own and your teams, and marks the one this command
17517
17935
  acts in. A key acts in the organization it was made in, for good, so org use signs in again in
17518
17936
  the browser for a key made in the one given, by its id or name, and deletes the key the command
@@ -17652,8 +18070,9 @@ it off, after which the url leads nowhere, and --status only reads it. On a desk
17652
18070
  --type and --key use its pointer and keyboard, one for each run: --click 640,400,right,2 is a
17653
18071
  double click of the right button, --scroll 640,400,-3 turns the wheel up three notches, and
17654
18072
  --key ctrl+l presses keys named as xdotool names them. The picture is a JPEG when the file is
17655
- named .jpg, of a part of the screen with --crop, smaller with --scale, and without the pointer
17656
- with --no-cursor: each makes it cheaper for a model to read. --clipboard prints the text on the
18073
+ named .jpg, of a part of the screen with --crop, smaller with --scale (2 is every pixel of a
18074
+ desktop drawn at 2x), and without the pointer with --no-cursor: each makes it cheaper for a
18075
+ model to read. --clipboard prints the text on the
17657
18076
  desktop's clipboard, and --set-clipboard puts text there, read from standard input with -, for
17658
18077
  --key ctrl+v to paste at once what --type would type a key at a time. --tree prints what is on
17659
18078
  the screen as its programs tell it: each window, then its buttons, fields and menus, each with