agental 0.54.0 → 0.56.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 +599 -186
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -6363,15 +6363,15 @@ var require_parser = __commonJS({
6363
6363
  var node_process = __require("process");
6364
6364
  var cst = require_cst();
6365
6365
  var lexer = require_lexer();
6366
- function includesToken(list5, type) {
6367
- for (let i = 0; i < list5.length; ++i)
6368
- if (list5[i].type === type)
6366
+ function includesToken(list6, type) {
6367
+ for (let i = 0; i < list6.length; ++i)
6368
+ if (list6[i].type === type)
6369
6369
  return true;
6370
6370
  return false;
6371
6371
  }
6372
- function findNonEmptyIndex(list5) {
6373
- for (let i = 0; i < list5.length; ++i) {
6374
- switch (list5[i].type) {
6372
+ function findNonEmptyIndex(list6) {
6373
+ for (let i = 0; i < list6.length; ++i) {
6374
+ switch (list6[i].type) {
6375
6375
  case "space":
6376
6376
  case "comment":
6377
6377
  case "newline":
@@ -7404,14 +7404,14 @@ var init_cli_operator = __esm({
7404
7404
 
7405
7405
  // ../src/cli.ts
7406
7406
  import { randomUUID as randomUUID3 } from "node:crypto";
7407
- import { readFileSync as readFileSync7, writeFileSync as writeFileSync5 } from "node:fs";
7407
+ import { readFileSync as readFileSync8, writeFileSync as writeFileSync5 } from "node:fs";
7408
7408
  import os7 from "node:os";
7409
7409
  import { readFile as readFile2 } from "node:fs/promises";
7410
7410
  import { parseArgs } from "node:util";
7411
7411
 
7412
7412
  // ../src/cli-build.ts
7413
7413
  var PUBLISHED = true;
7414
- var CLI_VERSION = true ? "0.54.0" : "dev";
7414
+ var CLI_VERSION = true ? "0.56.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}`;
@@ -7468,6 +7468,14 @@ function saveCredentials(credentials, env = process.env) {
7468
7468
  function removeCredentials(env = process.env) {
7469
7469
  rmSync(credentialsPath(env), { force: true });
7470
7470
  }
7471
+ function guildTokenHere(fallbackUrl, env = process.env) {
7472
+ const token = env["AGENTAL_SANDBOX_TOKEN"]?.trim();
7473
+ const named = env["AGENTAL_API_URL"]?.trim();
7474
+ if (!token || !named || resolveApi(fallbackUrl, null, env).key !== null) {
7475
+ return null;
7476
+ }
7477
+ return token;
7478
+ }
7471
7479
  function resolveApi(fallbackUrl, fallbackKey, env = process.env) {
7472
7480
  const trim = (value) => value.replace(/\/+$/, "");
7473
7481
  const namedUrl = env["AGENTAL_API_URL"]?.trim() || void 0;
@@ -7974,8 +7982,8 @@ function keyOf(body) {
7974
7982
  throw new Error("The answer was not an API key.");
7975
7983
  }
7976
7984
  const key2 = body;
7977
- const list5 = (value) => Array.isArray(value) ? value.map(String) : [];
7978
- return { ...key2, actions: list5(key2.actions), sandboxIds: list5(key2.sandboxIds), templateIds: list5(key2.templateIds), allowFrom: list5(key2.allowFrom) };
7985
+ const list6 = (value) => Array.isArray(value) ? value.map(String) : [];
7986
+ return { ...key2, actions: list6(key2.actions), sandboxIds: list6(key2.sandboxIds), templateIds: list6(key2.templateIds), allowFrom: list6(key2.allowFrom) };
7979
7987
  }
7980
7988
  function keysOf(body) {
7981
7989
  const listed2 = body?.apiKeys;
@@ -8293,10 +8301,10 @@ async function whoIs(base, key2) {
8293
8301
  throw error;
8294
8302
  }
8295
8303
  }
8296
- async function pushRequest(base, ask13) {
8304
+ async function pushRequest(base, ask14) {
8297
8305
  let made;
8298
8306
  try {
8299
- made = await call(base, "POST", "/v1/cli-sign-ins", ask13);
8307
+ made = await call(base, "POST", "/v1/cli-sign-ins", ask14);
8300
8308
  } catch (error) {
8301
8309
  if (error instanceof Refused && (error.status === 401 || error.status === 404)) {
8302
8310
  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.`);
@@ -8308,7 +8316,7 @@ async function pushRequest(base, ask13) {
8308
8316
  async function listen() {
8309
8317
  let arrived = () => {
8310
8318
  };
8311
- let answer5 = () => {
8319
+ let answer6 = () => {
8312
8320
  };
8313
8321
  const next = new Promise((resolve) => arrived = resolve);
8314
8322
  let taken = false;
@@ -8323,7 +8331,7 @@ async function listen() {
8323
8331
  return;
8324
8332
  }
8325
8333
  taken = true;
8326
- answer5 = (to) => response.writeHead(302, { location: to, "cache-control": "no-store" }).end();
8334
+ answer6 = (to) => response.writeHead(302, { location: to, "cache-control": "no-store" }).end();
8327
8335
  arrived(url);
8328
8336
  });
8329
8337
  await new Promise((resolve, reject) => {
@@ -8331,7 +8339,7 @@ async function listen() {
8331
8339
  server2.listen(0, "127.0.0.1", resolve);
8332
8340
  });
8333
8341
  const { port } = server2.address();
8334
- return { server: server2, redirectUri: `http://127.0.0.1:${port}/callback`, next, answer: (to) => answer5(to) };
8342
+ return { server: server2, redirectUri: `http://127.0.0.1:${port}/callback`, next, answer: (to) => answer6(to) };
8335
8343
  }
8336
8344
  async function browserSignIn(base, term, organizationId) {
8337
8345
  const verifier = randomBytes2(32).toString("base64url");
@@ -8696,8 +8704,8 @@ function claudeDesktopHere(places, platform = process.platform, env = process.en
8696
8704
  function addToClaudeLink(url) {
8697
8705
  return `https://claude.ai/customize/connectors?modal=add-custom-connector&connectorName=${CONNECTOR_NAME}&connectorUrl=${encodeURIComponent(url)}`;
8698
8706
  }
8699
- function names(list5) {
8700
- return list5.length < 2 ? list5[0] ?? "" : `${list5.slice(0, -1).join(", ")} and ${list5.at(-1)}`;
8707
+ function names(list6) {
8708
+ return list6.length < 2 ? list6[0] ?? "" : `${list6.slice(0, -1).join(", ")} and ${list6.at(-1)}`;
8701
8709
  }
8702
8710
  async function ensureConnector(site2, places = placesFrom()) {
8703
8711
  const url = `${site2}/v1/mcp`;
@@ -8999,9 +9007,9 @@ async function api(base, key2, method, pathname, body, headers = {}) {
8999
9007
  }
9000
9008
  return { status: response.status, body: parsed && typeof parsed === "object" ? parsed : {} };
9001
9009
  }
9002
- function errorOf(answer5) {
9003
- const error = answer5.body["error"] && typeof answer5.body["error"] === "object" ? answer5.body["error"] : {};
9004
- return { code: String(error["code"] ?? `http_${answer5.status}`), message: String(error["message"] ?? `HTTP ${answer5.status}`) };
9010
+ function errorOf(answer6) {
9011
+ const error = answer6.body["error"] && typeof answer6.body["error"] === "object" ? answer6.body["error"] : {};
9012
+ return { code: String(error["code"] ?? `http_${answer6.status}`), message: String(error["message"] ?? `HTTP ${answer6.status}`) };
9005
9013
  }
9006
9014
  var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
9007
9015
  function real(file) {
@@ -9597,6 +9605,49 @@ var COMMANDS = [
9597
9605
  ["--yes", "disconnect: without asking; every sandbox is taken off the tailnet"]
9598
9606
  ]
9599
9607
  },
9608
+ {
9609
+ name: "guild",
9610
+ summary: "Set up a guild, where agents work together under identities of its design, or join one as an agent.",
9611
+ usage: [
9612
+ "agental guild [list] | show <guild> | delete <guild> [--yes]",
9613
+ "agental guild create <guild> --roles <name[:seats],...> [--brief <text>] [--form <file.json>]",
9614
+ "agental guild attach <guild> <template> [--roles <role,...>] | detach <guild> <template>",
9615
+ "agental guild mine",
9616
+ "agental guild join <guild> --as <name> --role <role> [--answer <key=value>]...",
9617
+ "agental guild members <guild> | leave <guild> <identity> | handover <guild> <identity> <sandbox>"
9618
+ ],
9619
+ examples: [
9620
+ 'agental guild create marketing --roles "blog manager:1,reviewer:2" --brief "Reviewers answer pass or fail."',
9621
+ "agental guild attach marketing writers",
9622
+ "agental guild join marketing --as Atlas --role reviewer --answer model=claude"
9623
+ ],
9624
+ flags: [
9625
+ ["--roles <name[:seats],...>", "create: the roles, each with its seats; attach: the roles its sandboxes may take"],
9626
+ ["--brief <text>", "create: what the guild is for, read by every member"],
9627
+ ["--form <file.json>", "create: the fields an agent fills in to join, as the API takes them"],
9628
+ ["--as <name>", "join: the name you will be known by in the guild"],
9629
+ ["--role <role>", "join: one of the guild's roles with a free seat"],
9630
+ ["--answer <key=value>", "join: an answer to the guild's form (may be given again)"],
9631
+ ["--yes", "delete: without asking"]
9632
+ ]
9633
+ },
9634
+ {
9635
+ name: "subscriptions",
9636
+ summary: "Sign in to Claude, ChatGPT (Codex), GitHub Copilot or Grok Build on agental's servers, which keep it sealed; list or delete them.",
9637
+ usage: ["agental subscriptions [list] [--json]", "agental subscriptions sign-in claude|codex|copilot|grok", "agental subscriptions delete <agent> [--yes]"],
9638
+ examples: ["agental subscriptions sign-in codex", "agental subscriptions delete grok --yes"],
9639
+ flags: [["--yes", "delete: without asking; it is taken off every template and sandbox that uses it"]]
9640
+ },
9641
+ {
9642
+ name: "agents",
9643
+ summary: "Say or set how a template or a sandbox reaches each coding agent's vendor: off, the account's subscription, or its API key.",
9644
+ usage: ["agental agents --template <template> [<agent> off|subscription|api_key] [--json]", "agental agents --sandbox <sandbox-id> [<agent> off|subscription|api_key|template] [--json]"],
9645
+ examples: ["agental agents --template default claude subscription", "agental agents --sandbox sbx_2a9a47e50daec64a codex template"],
9646
+ flags: [
9647
+ ["--template <template>", "the template, by id or name"],
9648
+ ["--sandbox <sandbox-id>", "the sandbox: template follows its template again"]
9649
+ ]
9650
+ },
9600
9651
  {
9601
9652
  name: "tailnet",
9602
9653
  summary: "Join a sandbox to the account's tailnet as a node, change how, or take it off.",
@@ -10059,11 +10110,11 @@ function spelledOut(args, operator = false) {
10059
10110
  if (verb === void 0 || !SECRET_VERBS.has(verb)) {
10060
10111
  return wrong("list, get, set, unset, hosts, get-file, put-file or rm-file, then the sandbox or --template <template>");
10061
10112
  }
10062
- const at4 = rest.findIndex((word) => word === "--template" || word === "-t" || word.startsWith("--template="));
10063
- if (at4 >= 0) {
10064
- const given = rest[at4];
10065
- const pair = given.startsWith("--template=") ? [given] : rest.slice(at4, at4 + 2);
10066
- return ["secrets", ...pair, ...verb === "list" ? [] : [verb], ...rest.filter((_, index) => index < at4 || index >= at4 + pair.length)];
10113
+ const at5 = rest.findIndex((word) => word === "--template" || word === "-t" || word.startsWith("--template="));
10114
+ if (at5 >= 0) {
10115
+ const given = rest[at5];
10116
+ const pair = given.startsWith("--template=") ? [given] : rest.slice(at5, at5 + 2);
10117
+ return ["secrets", ...pair, ...verb === "list" ? [] : [verb], ...rest.filter((_, index) => index < at5 || index >= at5 + pair.length)];
10067
10118
  }
10068
10119
  const { sandbox, others } = sandboxIn(rest, ["--host", "--text"]);
10069
10120
  if (sandbox === void 0) {
@@ -10090,7 +10141,7 @@ function sandboxIn(words2, valued = []) {
10090
10141
  index += valued.includes(word) ? 1 : 0;
10091
10142
  continue;
10092
10143
  }
10093
- return { sandbox: word, others: words2.filter((_, at4) => at4 !== index) };
10144
+ return { sandbox: word, others: words2.filter((_, at5) => at5 !== index) };
10094
10145
  }
10095
10146
  return { sandbox: void 0, others: words2 };
10096
10147
  }
@@ -10108,6 +10159,8 @@ var SUBCOMMANDS = {
10108
10159
  limits: ["budget"],
10109
10160
  egress: ["budget", "use-case"],
10110
10161
  tailscale: ["status", "connect", "disconnect"],
10162
+ guild: ["list", "show", "create", "delete", "attach", "detach", "mine", "join", "members", "leave", "handover"],
10163
+ subscriptions: ["list", "sign-in", "delete"],
10111
10164
  telemetry: ["set", "test", "unset"],
10112
10165
  ci: ["jobs", "set", "reset"],
10113
10166
  org: ["list", "use", "create"],
@@ -10339,7 +10392,7 @@ async function jobs(api2) {
10339
10392
  });
10340
10393
  }
10341
10394
  var KEPT_MS = 3e4;
10342
- async function cached(what, as, ask13) {
10395
+ async function cached(what, as, ask14) {
10343
10396
  const folder = path5.join(process.env["XDG_CACHE_HOME"] || path5.join(os6.homedir(), ".cache"), "agental");
10344
10397
  const file = path5.join(folder, `complete-${what}-${createHash2("sha256").update(as).digest("hex").slice(0, 16)}.json`);
10345
10398
  try {
@@ -10351,7 +10404,7 @@ async function cached(what, as, ask13) {
10351
10404
  }
10352
10405
  let body = null;
10353
10406
  try {
10354
- body = await ask13();
10407
+ body = await ask14();
10355
10408
  } catch {
10356
10409
  return null;
10357
10410
  }
@@ -10515,12 +10568,12 @@ async function organizations(client) {
10515
10568
  const me = await ask5(client, "GET", "/v1/me");
10516
10569
  return { organizations: Array.isArray(listed2) ? listed2 : [], acting: String(me["activeOrganizationId"] ?? "") };
10517
10570
  }
10518
- function organizationNamed(list5, given) {
10519
- const byId = list5.find((organization) => organization.id === given);
10571
+ function organizationNamed(list6, given) {
10572
+ const byId = list6.find((organization) => organization.id === given);
10520
10573
  if (byId) {
10521
10574
  return byId;
10522
10575
  }
10523
- const byName = list5.filter((organization) => organization.name.toLowerCase() === given.toLowerCase());
10576
+ const byName = list6.filter((organization) => organization.name.toLowerCase() === given.toLowerCase());
10524
10577
  if (byName.length === 1 && byName[0]) {
10525
10578
  return byName[0];
10526
10579
  }
@@ -10533,14 +10586,14 @@ async function org(client, positionals, options, signInTo) {
10533
10586
  const [verb = "list", ...rest] = positionals;
10534
10587
  switch (verb) {
10535
10588
  case "list": {
10536
- const { organizations: list5, acting } = await organizations(client);
10589
+ const { organizations: list6, acting } = await organizations(client);
10537
10590
  if (options.json) {
10538
- print2(true, { organizations: list5.map((organization) => ({ ...organization, acting: organization.id === acting })) }, "");
10591
+ print2(true, { organizations: list6.map((organization) => ({ ...organization, acting: organization.id === acting })) }, "");
10539
10592
  return;
10540
10593
  }
10541
10594
  process.stdout.write(` ${[pad("ID", 22), pad("NAME", 24), "ROLE"].join(" ")}
10542
10595
  `);
10543
- for (const organization of list5) {
10596
+ for (const organization of list6) {
10544
10597
  const role = organization.personal ? "your own" : organization.role ?? "";
10545
10598
  process.stdout.write(`${organization.id === acting ? "*" : " "} ${[pad(organization.id, 22), pad(organization.name, 24), role].join(" ")}
10546
10599
  `);
@@ -10553,8 +10606,8 @@ async function org(client, positionals, options, signInTo) {
10553
10606
  if (!given) {
10554
10607
  throw new Error("org use takes the organization's id or name: agental org use Acme.");
10555
10608
  }
10556
- const { organizations: list5, acting } = await organizations(client);
10557
- const chosen = organizationNamed(list5, given);
10609
+ const { organizations: list6, acting } = await organizations(client);
10610
+ const chosen = organizationNamed(list6, given);
10558
10611
  if (chosen.id === acting) {
10559
10612
  process.stdout.write(`This command's key acts in ${chosen.name} already.
10560
10613
  `);
@@ -10584,15 +10637,15 @@ agental org use ${organization.id} signs this command in to it.
10584
10637
  }
10585
10638
  }
10586
10639
  async function actingTeam(client) {
10587
- const { organizations: list5, acting } = await organizations(client);
10588
- const team = list5.find((organization) => organization.id === acting);
10640
+ const { organizations: list6, acting } = await organizations(client);
10641
+ const team = list6.find((organization) => organization.id === acting);
10589
10642
  if (!team) {
10590
10643
  throw new Error("This command's key acts in no organization you are in. agental org use <organization> signs it in to one.");
10591
10644
  }
10592
10645
  return team;
10593
10646
  }
10594
- function memberNamed(list5, given) {
10595
- const found = list5.find((member) => member.userId === given || member.email?.toLowerCase() === given.toLowerCase());
10647
+ function memberNamed(list6, given) {
10648
+ const found = list6.find((member) => member.userId === given || member.email?.toLowerCase() === given.toLowerCase());
10596
10649
  if (!found) {
10597
10650
  throw new Error(`No member ${given} in this team. agental members lists them.`);
10598
10651
  }
@@ -10602,7 +10655,7 @@ async function members(client, positionals, options) {
10602
10655
  const [verb = "list", target] = positionals;
10603
10656
  const team = await actingTeam(client);
10604
10657
  const listed2 = await ask5(client, "GET", `/v1/organizations/${encodeURIComponent(team.id)}/members`);
10605
- const list5 = Array.isArray(listed2["members"]) ? listed2["members"] : [];
10658
+ const list6 = Array.isArray(listed2["members"]) ? listed2["members"] : [];
10606
10659
  switch (verb) {
10607
10660
  case "list": {
10608
10661
  if (options.json) {
@@ -10614,7 +10667,7 @@ async function members(client, positionals, options) {
10614
10667
  `);
10615
10668
  process.stdout.write(`${[pad("ID", 34), pad("EMAIL", 30), pad("ROLE", 8), "ADDED"].join(" ")}
10616
10669
  `);
10617
- for (const member of list5) {
10670
+ for (const member of list6) {
10618
10671
  process.stdout.write(`${[pad(member.userId, 34), pad(member.email ?? member.name ?? "", 30), pad(member.role, 8), member.addedAt.slice(0, 10)].join(" ")}
10619
10672
  `);
10620
10673
  }
@@ -10624,7 +10677,7 @@ async function members(client, positionals, options) {
10624
10677
  if (!target) {
10625
10678
  throw new Error("members remove takes the member's id or email: agental members remove cy@example.com.");
10626
10679
  }
10627
- const member = memberNamed(list5, target);
10680
+ const member = memberNamed(list6, target);
10628
10681
  const query = options.revokeKeys ? "?revokeKeys=true" : "";
10629
10682
  const removed = await ask5(client, "DELETE", `/v1/organizations/${encodeURIComponent(team.id)}/members/${encodeURIComponent(member.userId)}${query}`);
10630
10683
  const revoked = Number(removed["revokedKeys"] ?? 0);
@@ -11905,8 +11958,8 @@ function exitOf2(command3) {
11905
11958
  }
11906
11959
  }
11907
11960
  function moment(iso) {
11908
- const at4 = new Date(iso).toISOString().replace(/\.\d+Z$/, "Z");
11909
- return isTerminal(process.stdout) ? ago(iso) ?? at4 : at4;
11961
+ const at5 = new Date(iso).toISOString().replace(/\.\d+Z$/, "Z");
11962
+ return isTerminal(process.stdout) ? ago(iso) ?? at5 : at5;
11910
11963
  }
11911
11964
  function tookOf2(command3) {
11912
11965
  const began = Date.parse(command3.startedAt);
@@ -11970,7 +12023,7 @@ function show(command3, sandbox, asJson) {
11970
12023
  function put(stream, data) {
11971
12024
  return new Promise((resolve, reject) => stream.write(data, (error) => error ? reject(error) : resolve()));
11972
12025
  }
11973
- async function readOutput(client, path6, at4, follow2, wrote) {
12026
+ async function readOutput(client, path6, at5, follow2, wrote) {
11974
12027
  const controller = new AbortController();
11975
12028
  let silence = setTimeout(() => controller.abort(), SILENT_MS);
11976
12029
  const heard = () => {
@@ -11981,7 +12034,7 @@ async function readOutput(client, path6, at4, follow2, wrote) {
11981
12034
  try {
11982
12035
  let response;
11983
12036
  try {
11984
- response = await client.request(`${path6}?stdout=${at4.stdout}&stderr=${at4.stderr}${follow2 ? "&follow=1" : ""}`, { method: "GET", headers: { Accept: "text/event-stream" }, signal: controller.signal });
12037
+ response = await client.request(`${path6}?stdout=${at5.stdout}&stderr=${at5.stderr}${follow2 ? "&follow=1" : ""}`, { method: "GET", headers: { Accept: "text/event-stream" }, signal: controller.signal });
11985
12038
  } catch (error) {
11986
12039
  return { kind: "cut", why: errorText(error), progressed };
11987
12040
  }
@@ -12004,12 +12057,12 @@ async function readOutput(client, path6, at4, follow2, wrote) {
12004
12057
  case "output": {
12005
12058
  const piece = JSON.parse(data2);
12006
12059
  const raw = Buffer.from(piece.data, "base64");
12007
- const skip = Math.max(0, at4[piece.stream] - piece.offset);
12060
+ const skip = Math.max(0, at5[piece.stream] - piece.offset);
12008
12061
  if (skip < raw.length) {
12009
12062
  await put(piece.stream === "stdout" ? process.stdout : process.stderr, raw.subarray(skip));
12010
12063
  wrote();
12011
12064
  }
12012
- at4[piece.stream] = Math.max(at4[piece.stream], piece.offset + raw.length);
12065
+ at5[piece.stream] = Math.max(at5[piece.stream], piece.offset + raw.length);
12013
12066
  progressed = true;
12014
12067
  return null;
12015
12068
  }
@@ -12017,14 +12070,14 @@ async function readOutput(client, path6, at4, follow2, wrote) {
12017
12070
  const gap = JSON.parse(data2);
12018
12071
  await put(process.stderr, `[agental: bytes ${gap.from} to ${gap.to} of its ${gap.stream} were overwritten in the sandbox before they were read: each stream keeps its last 1 MiB]
12019
12072
  `);
12020
- at4[gap.stream] = Math.max(at4[gap.stream], gap.to);
12073
+ at5[gap.stream] = Math.max(at5[gap.stream], gap.to);
12021
12074
  progressed = true;
12022
12075
  return null;
12023
12076
  }
12024
12077
  case "continue": {
12025
12078
  const next = JSON.parse(data2);
12026
- at4.stdout = Math.max(at4.stdout, next.stdout);
12027
- at4.stderr = Math.max(at4.stderr, next.stderr);
12079
+ at5.stdout = Math.max(at5.stdout, next.stdout);
12080
+ at5.stderr = Math.max(at5.stderr, next.stderr);
12028
12081
  return { kind: "continue" };
12029
12082
  }
12030
12083
  case "end":
@@ -12083,13 +12136,13 @@ async function logs(client, sandbox, id, one, follow2) {
12083
12136
  process.exit(0);
12084
12137
  }
12085
12138
  });
12086
- const at4 = { stdout: 0, stderr: 0 };
12139
+ const at5 = { stdout: 0, stderr: 0 };
12087
12140
  let wrote = false;
12088
12141
  let failed = 0;
12089
12142
  let idle = 0;
12090
12143
  for (; ; ) {
12091
- const from = { ...at4 };
12092
- const read2 = await readOutput(client, `${one}/output`, at4, follow2, () => wrote = true);
12144
+ const from = { ...at5 };
12145
+ const read2 = await readOutput(client, `${one}/output`, at5, follow2, () => wrote = true);
12093
12146
  switch (read2.kind) {
12094
12147
  case "end":
12095
12148
  if (follow2) {
@@ -12102,7 +12155,7 @@ async function logs(client, sandbox, id, one, follow2) {
12102
12155
  `, process.stderr));
12103
12156
  return;
12104
12157
  }
12105
- if (at4.stdout === from.stdout && at4.stderr === from.stderr) {
12158
+ if (at5.stdout === from.stdout && at5.stderr === from.stderr) {
12106
12159
  idle += 1;
12107
12160
  await sleep2(waitBefore(idle));
12108
12161
  continue;
@@ -12802,7 +12855,7 @@ function stateOf3(webhook2) {
12802
12855
  const since = webhook2.disabledAt ? ` since ${at3(webhook2.disabledAt)}` : "";
12803
12856
  return `off${since}${webhook2.disabledReason ? `: ${webhook2.disabledReason}` : ""}`;
12804
12857
  }
12805
- function eventsFrom(options, needed) {
12858
+ function eventsFrom(options, needed2) {
12806
12859
  if (options.all && options.events !== void 0) {
12807
12860
  throw new Error("Give --events or --all, not both.");
12808
12861
  }
@@ -12810,7 +12863,7 @@ function eventsFrom(options, needed) {
12810
12863
  return [EVERY];
12811
12864
  }
12812
12865
  if (options.events === void 0) {
12813
- if (needed) {
12866
+ if (needed2) {
12814
12867
  throw new Error(`Say what to send: --events with kinds such as sandbox.stopped,sandbox.error, or --all. The kinds are ${WEBHOOK_KINDS.join(", ")}; a group of them is ${WEBHOOK_GROUPS.map((group) => `${group}.*`).join(", ")}, quoted for the shell.`);
12815
12868
  }
12816
12869
  return void 0;
@@ -13265,16 +13318,16 @@ async function snapshot(client, positionals, options) {
13265
13318
  if (found.kept === STORAGE_ONLY) {
13266
13319
  process.stderr.write("Its server no longer holds it: it is fetched from storage first, which takes a few minutes.\n");
13267
13320
  }
13268
- const answer5 = await ask10(client, "POST", `/v1/sandboxes/${encodeURIComponent(found.sandboxId)}/restore`, {
13321
+ const answer6 = await ask10(client, "POST", `/v1/sandboxes/${encodeURIComponent(found.sandboxId)}/restore`, {
13269
13322
  headers: { "Idempotency-Key": options.idempotencyKey ?? `cli-${randomUUID2()}` },
13270
13323
  body: { snapshotId: found.id }
13271
13324
  });
13272
13325
  if (options.json) {
13273
- process.stdout.write(`${JSON.stringify(answer5, null, 2)}
13326
+ process.stdout.write(`${JSON.stringify(answer6, null, 2)}
13274
13327
  `);
13275
13328
  return;
13276
13329
  }
13277
- const read2 = answer5;
13330
+ const read2 = answer6;
13278
13331
  const discarded = Array.isArray(read2?.discarded) ? read2.discarded.map(String) : [];
13279
13332
  const status = typeof read2?.sandbox?.status === "string" ? `, and ${read2.sandbox.status}` : "";
13280
13333
  process.stdout.write(`${sandbox} is as it was at ${found.name}${status}.
@@ -13314,7 +13367,7 @@ var AgentalError = class extends Error {
13314
13367
  // ../sdk/typescript/src/sealed.ts
13315
13368
  var SEALED_SUITE = "x25519-hkdf-sha256-aes256gcm";
13316
13369
  var ROOT_PUBLIC_KEYS = ["jNdFf3FKdbFQ5J-1e_NE7ZzuaNPRdci-mzlGj384Rmw"];
13317
- var SEALED_PURPOSES = ["variable", "tailscale-oauth"];
13370
+ var SEALED_PURPOSES = ["variable", "tailscale-oauth", "sign-in-code"];
13318
13371
  var KEM_ID = 32;
13319
13372
  var KDF_ID = 1;
13320
13373
  var AEAD_ID = 2;
@@ -13602,10 +13655,10 @@ async function toSeal(client, given, options, verb) {
13602
13655
  if (!given) {
13603
13656
  throw new Error(`secret ${verb} requires <NAME>, and --host: agental secret ${verb} GITHUB_TOKEN --host api.github.com`);
13604
13657
  }
13605
- const at4 = given.indexOf("=");
13606
- const name = nameOf2(at4 < 0 ? given : given.slice(0, at4), verb);
13658
+ const at5 = given.indexOf("=");
13659
+ const name = nameOf2(at5 < 0 ? given : given.slice(0, at5), verb);
13607
13660
  const hosts = hostsOf(options.host, verb);
13608
- const value = at4 < 0 ? await client.readValue(`${name}'s value (not shown): `) : given.slice(at4 + 1);
13661
+ const value = at5 < 0 ? await client.readValue(`${name}'s value (not shown): `) : given.slice(at5 + 1);
13609
13662
  if (value.length < SHORTEST_VALUE) {
13610
13663
  throw new Error(`${name}'s value is ${value.length} characters: a secret is at least ${SHORTEST_VALUE}, and the API cannot check a sealed one, so it is refused here.`);
13611
13664
  }
@@ -13826,8 +13879,332 @@ function createTailnet(given, flags2 = {}) {
13826
13879
  return joinBody({ ...flags2, json: false, yes: false, tag: [given] }, true);
13827
13880
  }
13828
13881
 
13882
+ // ../src/cli-guilds.ts
13883
+ import { readFileSync as readFileSync7 } from "node:fs";
13884
+ var USAGE9 = "guild takes list, show <guild>, create <guild> --roles <name[:seats],...>, delete <guild>, attach <guild> <template>, detach <guild> <template>, mine, join <guild> --as <name> --role <role>, members <guild>, leave <guild> <identity>, or handover <guild> <identity> <sandbox>. agental guild --help shows each.";
13885
+ async function ask11(client, method, pathname, body) {
13886
+ const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
13887
+ let answered = null;
13888
+ if (response.status !== 204) {
13889
+ try {
13890
+ answered = await response.json();
13891
+ } catch {
13892
+ answered = null;
13893
+ }
13894
+ }
13895
+ if (!response.ok) {
13896
+ client.fail(response.status, answered);
13897
+ }
13898
+ return answered !== null && typeof answered === "object" ? answered : {};
13899
+ }
13900
+ function print4(json3, body, words2) {
13901
+ process.stdout.write(json3 ? `${JSON.stringify(body, null, 2)}
13902
+ ` : words2);
13903
+ }
13904
+ function at4(name) {
13905
+ return `/v1/guilds/${encodeURIComponent(name)}`;
13906
+ }
13907
+ function needed(value, what) {
13908
+ if (value === void 0 || value === "") {
13909
+ throw new Error(`${what}. ${USAGE9}`);
13910
+ }
13911
+ return value;
13912
+ }
13913
+ function rolesOf(given) {
13914
+ return given.split(",").map((part) => part.trim()).filter((part) => part !== "").map((part) => {
13915
+ const colon = part.lastIndexOf(":");
13916
+ const after = colon === -1 ? "" : part.slice(colon + 1).trim();
13917
+ return /^[0-9]+$/.test(after) ? { name: part.slice(0, colon).trim(), seats: Number(after) } : { name: part };
13918
+ });
13919
+ }
13920
+ function answersOf(given = []) {
13921
+ const answers = {};
13922
+ for (const one of given) {
13923
+ const equals = one.indexOf("=");
13924
+ if (equals < 1) {
13925
+ throw new Error(`--answer takes key=value: ${JSON.stringify(one)} is not.`);
13926
+ }
13927
+ answers[one.slice(0, equals)] = one.slice(equals + 1);
13928
+ }
13929
+ return answers;
13930
+ }
13931
+ function formFrom(file) {
13932
+ let text;
13933
+ try {
13934
+ text = readFileSync7(file, "utf8");
13935
+ } catch (error) {
13936
+ throw new Error(`--form ${file} could not be read: ${error instanceof Error ? error.message : String(error)}`);
13937
+ }
13938
+ try {
13939
+ return JSON.parse(text);
13940
+ } catch {
13941
+ throw new Error(`--form ${file} is not JSON. It is an array of fields: [{"key": "model", "label": "Which model are you?", "kind": "choice", "choices": ["claude", "codex"], "required": true}].`);
13942
+ }
13943
+ }
13944
+ function roleLine(role) {
13945
+ return `${String(role["name"])} (${role["seats"] === null ? "any number" : `${String(role["seats"])} seat${role["seats"] === 1 ? "" : "s"}`}, ${String(role["onDelete"])} at a delete)`;
13946
+ }
13947
+ function memberLine(member) {
13948
+ const held = member.holder === null ? "vacant" : member.holder === "outside" ? "held outside agental" : member.sandboxId ? `held by ${member.sandboxId}` : "held by a sandbox";
13949
+ return `${member.id} ${member.name}, ${member.role}, ${held}
13950
+ `;
13951
+ }
13952
+ async function memberNamed2(client, guild2, given) {
13953
+ const members2 = (await ask11(client, "GET", `${at4(guild2)}/members`))["members"] ?? [];
13954
+ const found = members2.find((member) => member.id === given) ?? members2.find((member) => member.name.toLowerCase() === given.toLowerCase());
13955
+ if (!found) {
13956
+ throw new Error(`Guild ${guild2} has no identity ${JSON.stringify(given)}. agental guild members ${guild2} lists them.`);
13957
+ }
13958
+ return found;
13959
+ }
13960
+ async function guild(client, positionals, options) {
13961
+ const [verb = client.onToken ? "mine" : "list", name, third, fourth] = positionals;
13962
+ switch (verb) {
13963
+ case "list": {
13964
+ const listed2 = (await ask11(client, "GET", "/v1/guilds"))["guilds"] ?? [];
13965
+ print4(options.json, listed2, listed2.length === 0 ? "No guilds. agental guild create <name> --roles <role,...> makes one.\n" : listed2.map((one) => `${String(one["name"])} ${one["roles"].map((role) => String(role["name"])).join(", ")}
13966
+ `).join(""));
13967
+ return;
13968
+ }
13969
+ case "show": {
13970
+ const found = await ask11(client, "GET", at4(needed(name, "show takes a guild")));
13971
+ const members2 = (await ask11(client, "GET", `${at4(String(found["name"]))}/members`))["members"] ?? [];
13972
+ const words2 = [
13973
+ `${String(found["name"])}
13974
+ `,
13975
+ found["brief"] ? ` ${String(found["brief"])}
13976
+ ` : "",
13977
+ `roles
13978
+ ${found["roles"].map((role) => ` ${roleLine(role)}
13979
+ `).join("")}`,
13980
+ found["form"].length ? `form
13981
+ ${found["form"].map((field) => ` ${String(field["key"])}: ${String(field["label"])}${field["required"] ? " (required)" : ""}
13982
+ `).join("")}` : "",
13983
+ `templates
13984
+ ${found["templates"].map((one) => ` ${String(one["templateId"])}${one["roles"] ? ` as ${one["roles"].join(", ")}` : ", any role"}
13985
+ `).join("") || " none\n"}`,
13986
+ `identities
13987
+ ${members2.map((member) => ` ${memberLine(member)}`).join("") || " none\n"}`
13988
+ ].join("");
13989
+ print4(options.json, { ...found, members: members2 }, words2);
13990
+ return;
13991
+ }
13992
+ case "create": {
13993
+ const body = {
13994
+ name: needed(name, "create takes a guild's name"),
13995
+ roles: rolesOf(needed(options.roles, 'create takes --roles, such as "blog manager:1,reviewer:2"')),
13996
+ ...options.brief === void 0 ? {} : { brief: options.brief },
13997
+ ...options.form === void 0 ? {} : { form: formFrom(options.form) }
13998
+ };
13999
+ const made = await ask11(client, "POST", "/v1/guilds", body);
14000
+ print4(options.json, made, `Made guild ${String(made["name"])}. agental guild attach ${String(made["name"])} <template> lets that template's sandboxes join it.
14001
+ `);
14002
+ return;
14003
+ }
14004
+ case "delete": {
14005
+ const guildName = needed(name, "delete takes a guild");
14006
+ if (!options.yes && !await client.confirmed(`Delete guild ${guildName} and every identity in it, for good? [y/N] `)) {
14007
+ throw new Error(`Nothing was deleted. agental guild delete ${guildName} --yes deletes it without asking.`);
14008
+ }
14009
+ await ask11(client, "DELETE", at4(guildName));
14010
+ print4(options.json, { deleted: name }, `Deleted guild ${String(name)}, with its identities.
14011
+ `);
14012
+ return;
14013
+ }
14014
+ case "attach": {
14015
+ const template2 = await client.templateId(needed(third, "attach takes a guild and a template"));
14016
+ const roles = options.roles === void 0 ? {} : { roles: rolesOf(options.roles).map((role) => role.name) };
14017
+ const attached = await ask11(client, "PUT", `${at4(needed(name, "attach takes a guild"))}/templates/${encodeURIComponent(template2)}`, roles);
14018
+ print4(options.json, attached, `Sandboxes of ${template2} may join ${String(name)}${attached["roles"] ? ` as ${attached["roles"].join(" or ")}` : ", in any role"}.
14019
+ `);
14020
+ return;
14021
+ }
14022
+ case "detach": {
14023
+ const template2 = await client.templateId(needed(third, "detach takes a guild and a template"));
14024
+ await ask11(client, "DELETE", `${at4(needed(name, "detach takes a guild"))}/templates/${encodeURIComponent(template2)}`);
14025
+ print4(options.json, { detached: template2 }, `Sandboxes of ${template2} may no longer join ${String(name)}.
14026
+ `);
14027
+ return;
14028
+ }
14029
+ case "mine": {
14030
+ const mine = (await ask11(client, "GET", "/v1/guilds/mine"))["guilds"] ?? [];
14031
+ const words2 = mine.map((one) => {
14032
+ const found = one["guild"];
14033
+ const open = one["rolesOpen"] === null ? "any role" : one["rolesOpen"].join(", ") || "none";
14034
+ const held = one["held"].map((member) => ` you are ${member.name}, ${member.role} (${member.id})
14035
+ `).join("");
14036
+ return `${String(found["name"])} open to you: ${open}
14037
+ ${held}`;
14038
+ }).join("");
14039
+ print4(options.json, mine, words2 || "No guild: this sandbox's template is attached to none, and it holds no identity.\n");
14040
+ return;
14041
+ }
14042
+ case "join": {
14043
+ const joined = await ask11(client, "POST", `${at4(needed(name, "join takes a guild"))}/members`, {
14044
+ name: needed(options.as, "join takes --as <the name you will be known by>"),
14045
+ role: needed(options.role, "join takes --role <one of the guild's roles>"),
14046
+ ...options.answer === void 0 ? {} : { answers: answersOf(options.answer) }
14047
+ });
14048
+ print4(options.json, joined, `You are ${String(joined["name"])}, ${String(joined["role"])} of ${String(name)} (${String(joined["id"])}).
14049
+ `);
14050
+ return;
14051
+ }
14052
+ case "members": {
14053
+ const members2 = (await ask11(client, "GET", `${at4(needed(name, "members takes a guild"))}/members`))["members"] ?? [];
14054
+ print4(options.json, members2, members2.map(memberLine).join("") || "No identities yet.\n");
14055
+ return;
14056
+ }
14057
+ case "leave": {
14058
+ const guildName = needed(name, "leave takes a guild and an identity");
14059
+ const member = await memberNamed2(client, guildName, needed(third, "leave takes a guild and an identity"));
14060
+ await ask11(client, "DELETE", `${at4(guildName)}/members/${encodeURIComponent(member.id)}`);
14061
+ print4(options.json, { left: member.id }, `${member.name} has left ${guildName}; the name and its seat are free.
14062
+ `);
14063
+ return;
14064
+ }
14065
+ case "handover": {
14066
+ const guildName = needed(name, "handover takes a guild, an identity and a sandbox");
14067
+ const member = await memberNamed2(client, guildName, needed(third, "handover takes a guild, an identity and a sandbox"));
14068
+ const sandbox = await ask11(client, "GET", `/v1/sandboxes/${encodeURIComponent(needed(fourth, "handover takes a sandbox"))}`);
14069
+ const handed = await ask11(client, "POST", `${at4(guildName)}/members/${encodeURIComponent(member.id)}/handover`, { sandboxId: String(sandbox["id"]) });
14070
+ print4(options.json, handed, `${member.name} is held by ${String(sandbox["name"] ?? sandbox["id"])} now.
14071
+ `);
14072
+ return;
14073
+ }
14074
+ default:
14075
+ throw new Error(USAGE9);
14076
+ }
14077
+ }
14078
+
14079
+ // ../src/cli-subscriptions.ts
14080
+ var AGENTS = ["claude", "codex", "copilot", "grok"];
14081
+ var USES = ["off", "subscription", "api_key"];
14082
+ var CLAUDE_TOKEN_HOST = "platform.claude.com";
14083
+ var USAGE10 = "subscriptions takes list, sign-in <agent> or delete <agent>; agents takes --template or --sandbox, and <agent> <off|subscription|api_key>. agental subscriptions --help shows each.";
14084
+ async function subscriptions(client, positionals, options) {
14085
+ const [verb, agent] = positionals;
14086
+ switch (verb) {
14087
+ case void 0:
14088
+ case "list":
14089
+ return await list4(client, options);
14090
+ case "sign-in":
14091
+ return await signIn(client, agentOf2(agent), options);
14092
+ case "delete":
14093
+ return await remove3(client, agentOf2(agent), options);
14094
+ default:
14095
+ throw new Error(`agental subscriptions ${verb} is not a command. ${USAGE10}`);
14096
+ }
14097
+ }
14098
+ async function agents(client, positionals, options) {
14099
+ if (options.template === void 0 === (options.sandbox === void 0)) {
14100
+ throw new Error("agents takes --template <template> or --sandbox <sandbox-id>, one of them.");
14101
+ }
14102
+ const path6 = options.template !== void 0 ? `/v1/templates/${encodeURIComponent(await client.templateId(options.template))}` : `/v1/sandboxes/${encodeURIComponent(options.sandbox ?? "")}`;
14103
+ const [agent, use2] = positionals;
14104
+ let choices;
14105
+ if (agent === void 0) {
14106
+ choices = (await answer4(client, `${path6}/agents`, { method: "GET" })).agents;
14107
+ } else {
14108
+ const allowed = options.sandbox !== void 0 ? [...USES, "template"] : USES;
14109
+ if (use2 === void 0 || !allowed.includes(use2)) {
14110
+ throw new Error(`agents ${agent} takes one of ${allowed.join(", ")}.`);
14111
+ }
14112
+ choices = (await answer4(client, `${path6}/agents/${agentOf2(agent)}`, { method: "PUT", headers: { "content-type": "application/json" }, body: JSON.stringify({ use: use2 }) })).agents;
14113
+ }
14114
+ if (options.json) {
14115
+ process.stdout.write(`${JSON.stringify({ agents: choices }, null, 2)}
14116
+ `);
14117
+ return;
14118
+ }
14119
+ for (const c of choices) {
14120
+ const where = c.use === "api_key" && c.kept === "variable" ? ` (its own variable ${c.secret ?? ""})` : c.secret ? ` (${c.secret})` : "";
14121
+ const from = options.sandbox !== void 0 ? ` ${c.from === "sandbox" ? "set on the sandbox" : "from its template"}` : "";
14122
+ process.stdout.write(`${c.agent} ${c.use}${where}${c.signedOut ? " signed out: sign in again" : ""}${from}
14123
+ `);
14124
+ }
14125
+ }
14126
+ async function list4(client, options) {
14127
+ const { subscriptions: all } = await answer4(client, "/v1/subscriptions", { method: "GET" });
14128
+ if (options.json) {
14129
+ process.stdout.write(`${JSON.stringify({ subscriptions: all }, null, 2)}
14130
+ `);
14131
+ return;
14132
+ }
14133
+ for (const s of all) {
14134
+ process.stdout.write(`${s.agent} ${s.state.replace("_", " ")}${s.account?.plan ? ` ${s.account.plan}` : ""}${s.why ? ` ${s.why}` : ""}
14135
+ `);
14136
+ }
14137
+ }
14138
+ async function signIn(client, agent, options) {
14139
+ let now = await answer4(client, `/v1/subscriptions/${agent}/sign-in`, { method: "POST" });
14140
+ const shown = now.signIn;
14141
+ if (shown === null) {
14142
+ throw new Error("The sign-in was not begun: the API showed nothing to approve.");
14143
+ }
14144
+ if (shown.authorizeUrl !== null) {
14145
+ process.stderr.write(`Open this page, sign in to Claude, and copy the code it shows:
14146
+ ${shown.authorizeUrl}
14147
+ `);
14148
+ const code = (await client.readValue("Paste the code: ")).trim();
14149
+ if (!code.includes("#")) {
14150
+ throw new Error("Paste the whole code the page shows, with the part after its #. Nothing was sent.");
14151
+ }
14152
+ const { sealed } = await sealForAccount(client, now.secret, code, [CLAUDE_TOKEN_HOST], "sign-in-code");
14153
+ now = await answer4(client, `/v1/subscriptions/${agent}/code`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ sealed: sealed[0] }) });
14154
+ } else {
14155
+ process.stderr.write(`Open ${shown.verificationUrl ?? ""} and enter the code ${shown.userCode ?? ""} (good until ${shown.expiresAt}). Waiting for it\u2026
14156
+ `);
14157
+ const until2 = Date.parse(shown.expiresAt) + 6e4;
14158
+ while (now.state === "signing_in" && Date.now() < until2) {
14159
+ await new Promise((resolve) => setTimeout(resolve, options.intervalMs ?? 5e3));
14160
+ now = await answer4(client, `/v1/subscriptions/${agent}`, { method: "GET" });
14161
+ }
14162
+ }
14163
+ if (options.json) {
14164
+ process.stdout.write(`${JSON.stringify(now, null, 2)}
14165
+ `);
14166
+ } else if (now.state === "signed_in") {
14167
+ process.stdout.write(`Signed in to ${agent}${now.account?.plan ? ` (${now.account.plan})` : ""}. Kept sealed as ${now.secret}; a template uses it with: agental agents --template <template> ${agent} subscription
14168
+ `);
14169
+ } else {
14170
+ process.stdout.write(`Not signed in to ${agent}${now.why ? `: ${now.why}` : ""}.
14171
+ `);
14172
+ }
14173
+ if (now.state !== "signed_in") {
14174
+ process.exitCode = 1;
14175
+ }
14176
+ }
14177
+ async function remove3(client, agent, options) {
14178
+ if (!options.yes && !await client.confirmed(`Delete the ${agent} subscription, and take it off every template and sandbox that uses it?`)) {
14179
+ process.stdout.write("Nothing was deleted.\n");
14180
+ return;
14181
+ }
14182
+ const after = await answer4(client, `/v1/subscriptions/${agent}`, { method: "DELETE" });
14183
+ if (options.json) {
14184
+ process.stdout.write(`${JSON.stringify(after, null, 2)}
14185
+ `);
14186
+ return;
14187
+ }
14188
+ process.stdout.write(`Deleted here. To end it on ${agent}'s side too: ${after.revokeAt}
14189
+ `);
14190
+ }
14191
+ function agentOf2(given) {
14192
+ if (given === void 0 || !AGENTS.includes(given)) {
14193
+ throw new Error(`Name the agent: ${AGENTS.join(", ")}.`);
14194
+ }
14195
+ return given;
14196
+ }
14197
+ async function answer4(client, path6, init) {
14198
+ const res = await client.request(path6, init);
14199
+ const body = await res.json().catch(() => null);
14200
+ if (!res.ok) {
14201
+ client.fail(res.status, body);
14202
+ }
14203
+ return body;
14204
+ }
14205
+
13829
14206
  // ../src/cli-sites.ts
13830
- var USAGE9 = "site takes a sandbox, or list, add, rm, stats or analytics, then the sandbox. agental site --help shows each.";
14207
+ var USAGE11 = "site takes a sandbox, or list, add, rm, stats or analytics, then the sandbox. agental site --help shows each.";
13831
14208
  var ANALYTICS_USAGE = "site analytics takes on or off, then the sandbox and the site's id, or org, with on or off to change it.";
13832
14209
  var REPORT_ROWS = 5;
13833
14210
  async function bodyOf2(response) {
@@ -13837,7 +14214,7 @@ async function bodyOf2(response) {
13837
14214
  return null;
13838
14215
  }
13839
14216
  }
13840
- async function ask11(client, method, pathname, body) {
14217
+ async function ask12(client, method, pathname, body) {
13841
14218
  const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
13842
14219
  const answered = await bodyOf2(response);
13843
14220
  if (!response.ok) {
@@ -13853,7 +14230,7 @@ function routeOf(body) {
13853
14230
  }
13854
14231
  var isSite = (route) => route.public && !route.hidden;
13855
14232
  async function sitesOf(client, sandbox) {
13856
- const body = await ask11(client, "GET", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`);
14233
+ const body = await ask12(client, "GET", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`);
13857
14234
  return (Array.isArray(body?.routes) ? body.routes : []).map(routeOf).filter(isSite);
13858
14235
  }
13859
14236
  function stateOf4(route) {
@@ -13938,7 +14315,7 @@ async function siteSwitch(client, turn, words2, options) {
13938
14315
  process.exitCode = 1;
13939
14316
  return;
13940
14317
  }
13941
- const report = await ask11(client, "PUT", `/v1/host-routes/${encodeURIComponent(target)}/analytics`, { enabled: turn === "on" });
14318
+ const report = await ask12(client, "PUT", `/v1/host-routes/${encodeURIComponent(target)}/analytics`, { enabled: turn === "on" });
13942
14319
  if (options.json) {
13943
14320
  process.stdout.write(`${reportJson(report)}
13944
14321
  `);
@@ -13964,7 +14341,7 @@ async function organizationSwitch(client, words2, options) {
13964
14341
  }
13965
14342
  let setting;
13966
14343
  if (turn === void 0) {
13967
- setting = await ask11(client, "GET", "/v1/site-analytics");
14344
+ setting = await ask12(client, "GET", "/v1/site-analytics");
13968
14345
  } else {
13969
14346
  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.")) {
13970
14347
  process.stderr.write("Nothing was changed. --yes goes on without asking.\n");
@@ -14016,13 +14393,13 @@ async function site(client, positionals, options) {
14016
14393
  const verb = positionals[0] === "list" || positionals[0] === "add" || positionals[0] === "rm" || positionals[0] === "stats" ? positionals[0] : null;
14017
14394
  const [sandbox, target, ...rest] = verb === null ? positionals : positionals.slice(1);
14018
14395
  if (sandbox === void 0) {
14019
- throw new Error(USAGE9);
14396
+ throw new Error(USAGE11);
14020
14397
  }
14021
14398
  switch (verb) {
14022
14399
  case null:
14023
14400
  case "list": {
14024
14401
  if (target !== void 0) {
14025
- throw new Error(USAGE9);
14402
+ throw new Error(USAGE11);
14026
14403
  }
14027
14404
  const sites = await sitesOf(client, sandbox);
14028
14405
  if (options.json) {
@@ -14042,10 +14419,10 @@ async function site(client, positionals, options) {
14042
14419
  }
14043
14420
  case "add": {
14044
14421
  if (rest.length > 0) {
14045
- throw new Error(USAGE9);
14422
+ throw new Error(USAGE11);
14046
14423
  }
14047
14424
  const port = portFrom(target);
14048
- const made = routeOf(await ask11(client, "POST", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`, { port, title: `port-${port}`, public: true }));
14425
+ const made = routeOf(await ask12(client, "POST", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`, { port, title: `port-${port}`, public: true }));
14049
14426
  if (options.json) {
14050
14427
  process.stdout.write(`${JSON.stringify(made, null, 2)}
14051
14428
  `);
@@ -14070,7 +14447,7 @@ async function site(client, positionals, options) {
14070
14447
  throw new Error(`site rm needs the sandbox and the site's id, as agental site ${sandbox} lists them.`);
14071
14448
  }
14072
14449
  const found = await siteOn(client, sandbox, target);
14073
- await ask11(client, "POST", `/v1/host-routes/${encodeURIComponent(target)}/hide`);
14450
+ await ask12(client, "POST", `/v1/host-routes/${encodeURIComponent(target)}/hide`);
14074
14451
  process.stdout.write(`Removed. ${found.url ?? `Port ${found.port}`} stops working now; adding port ${found.port} again gives a new link.
14075
14452
  `);
14076
14453
  return;
@@ -14084,7 +14461,7 @@ async function site(client, positionals, options) {
14084
14461
  throw new Error(`--range is 24h or 7d. It was given ${range}.`);
14085
14462
  }
14086
14463
  await siteOn(client, sandbox, target);
14087
- const report = await ask11(client, "GET", `/v1/host-routes/${encodeURIComponent(target)}/analytics?range=${range}`);
14464
+ const report = await ask12(client, "GET", `/v1/host-routes/${encodeURIComponent(target)}/analytics?range=${range}`);
14088
14465
  process.stdout.write(options.json ? `${reportJson(report)}
14089
14466
  ` : reportIn(report, sandbox, target));
14090
14467
  return;
@@ -14093,10 +14470,10 @@ async function site(client, positionals, options) {
14093
14470
  }
14094
14471
 
14095
14472
  // ../src/cli-claude.ts
14096
- var USAGE10 = "claude takes connect, show, update or disconnect. agental claude --help shows each.";
14473
+ var USAGE12 = "claude takes connect, show, update or disconnect. agental claude --help shows each.";
14097
14474
  var KEY_VARIABLE = "ANTHROPIC_ENVIRONMENT_KEY";
14098
14475
  var SECRET_VARIABLE = "ANTHROPIC_WEBHOOK_SIGNING_KEY";
14099
- async function ask12(client, method, pathname, body) {
14476
+ async function ask13(client, method, pathname, body) {
14100
14477
  const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
14101
14478
  let answered = null;
14102
14479
  if (response.status !== 204) {
@@ -14178,15 +14555,15 @@ async function hidden(question) {
14178
14555
  const muted = lines;
14179
14556
  process.stderr.write(question);
14180
14557
  muted._writeToOutput = () => void 0;
14181
- lines.question("", (answer5) => {
14558
+ lines.question("", (answer6) => {
14182
14559
  lines.close();
14183
14560
  process.stderr.write("\n");
14184
- resolve(answer5.trim());
14561
+ resolve(answer6.trim());
14185
14562
  });
14186
14563
  });
14187
14564
  }
14188
14565
  async function listClaude(client, asJson) {
14189
- const body = await ask12(client, "GET", "/v1/claude/connections");
14566
+ const body = await ask13(client, "GET", "/v1/claude/connections");
14190
14567
  if (asJson) {
14191
14568
  process.stdout.write(`${JSON.stringify(body, null, 2)}
14192
14569
  `);
@@ -14208,7 +14585,7 @@ async function listClaude(client, asJson) {
14208
14585
  async function claude(client, positionals, options) {
14209
14586
  const [what, target, ...rest] = positionals;
14210
14587
  if (rest.length > 0) {
14211
- throw new Error(USAGE10);
14588
+ throw new Error(USAGE12);
14212
14589
  }
14213
14590
  switch (what) {
14214
14591
  case "connect": {
@@ -14220,7 +14597,7 @@ async function claude(client, positionals, options) {
14220
14597
  const environmentKey = await secretFrom(KEY_VARIABLE, "environment key", true);
14221
14598
  const webhookSecret = await secretFrom(SECRET_VARIABLE, "webhook signing secret", false);
14222
14599
  const made = connectionOf(
14223
- await ask12(client, "POST", "/v1/claude/connections", {
14600
+ await ask13(client, "POST", "/v1/claude/connections", {
14224
14601
  environmentId: target,
14225
14602
  environmentKey,
14226
14603
  ...webhookSecret !== void 0 ? { webhookSecret } : {},
@@ -14242,7 +14619,7 @@ async function claude(client, positionals, options) {
14242
14619
  return;
14243
14620
  }
14244
14621
  case "show": {
14245
- const found = connectionOf(await ask12(client, "GET", `/v1/claude/connections/${encodeURIComponent(needId2(target, "show"))}`));
14622
+ const found = connectionOf(await ask13(client, "GET", `/v1/claude/connections/${encodeURIComponent(needId2(target, "show"))}`));
14246
14623
  process.stdout.write(options.json ? `${JSON.stringify(found, null, 2)}
14247
14624
  ` : describe6(found));
14248
14625
  return;
@@ -14265,18 +14642,18 @@ async function claude(client, positionals, options) {
14265
14642
  if (Object.keys(patch).length === 0) {
14266
14643
  throw new Error("claude update changes --template, --keep-days, --new-key, --webhook-secret or --no-webhook-secret, and was given none of them.");
14267
14644
  }
14268
- const updated = connectionOf(await ask12(client, "PATCH", `/v1/claude/connections/${encodeURIComponent(id)}`, patch));
14645
+ const updated = connectionOf(await ask13(client, "PATCH", `/v1/claude/connections/${encodeURIComponent(id)}`, patch));
14269
14646
  process.stdout.write(options.json ? `${JSON.stringify(updated, null, 2)}
14270
14647
  ` : describe6(updated));
14271
14648
  return;
14272
14649
  }
14273
14650
  case "disconnect": {
14274
- await ask12(client, "DELETE", `/v1/claude/connections/${encodeURIComponent(needId2(target, "disconnect"))}`);
14651
+ await ask13(client, "DELETE", `/v1/claude/connections/${encodeURIComponent(needId2(target, "disconnect"))}`);
14275
14652
  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");
14276
14653
  return;
14277
14654
  }
14278
14655
  default:
14279
- throw new Error(USAGE10);
14656
+ throw new Error(USAGE12);
14280
14657
  }
14281
14658
  }
14282
14659
  function needId2(id, what) {
@@ -14327,7 +14704,7 @@ function whyClosed(code, reason2, error) {
14327
14704
  return `The terminal was closed (${code})${said ? `: ${said}` : ""}.`;
14328
14705
  }
14329
14706
  }
14330
- async function answer4(response) {
14707
+ async function answer5(response) {
14331
14708
  const body = await response.json().catch(() => null);
14332
14709
  if (!response.ok) {
14333
14710
  const error = body?.error;
@@ -14336,7 +14713,7 @@ async function answer4(response) {
14336
14713
  return body;
14337
14714
  }
14338
14715
  async function keptShells2(client, id) {
14339
- const body = await answer4(await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminals`, { method: "GET" }));
14716
+ const body = await answer5(await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminals`, { method: "GET" }));
14340
14717
  if (!body || !Array.isArray(body.terminals)) {
14341
14718
  throw new Error("The list of kept shells was missing terminals.");
14342
14719
  }
@@ -14390,7 +14767,7 @@ async function listShells(client, id, json3, stdout) {
14390
14767
  }
14391
14768
  async function closeShell(client, id, given, stdout) {
14392
14769
  const found = await shellNamed(client, id, given, "--close");
14393
- await answer4(await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminals/${encodeURIComponent(found.id)}`, { method: "DELETE" }));
14770
+ await answer5(await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminals/${encodeURIComponent(found.id)}`, { method: "DELETE" }));
14394
14771
  stdout.write(`Closed ${found.n === null ? "shell" : `shell ${found.n}`} (${found.id}).
14395
14772
  `);
14396
14773
  }
@@ -14433,16 +14810,16 @@ async function shell(client, id, options = {}, streams = process) {
14433
14810
  const verifier = randomBytes4(32).toString("base64url");
14434
14811
  const challenge = createHash3("sha256").update(verifier).digest("base64url");
14435
14812
  const interactive = stdin.isTTY === true && typeof stdin.setRawMode === "function";
14436
- const ask13 = async (keep) => await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminal`, {
14813
+ const ask14 = async (keep) => await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminal`, {
14437
14814
  method: "POST",
14438
14815
  body: JSON.stringify({ ...size2, challenge, ...again ? { terminal: again.id } : keep ? { keep: true } : {} })
14439
14816
  });
14440
- let response = await ask13(interactive);
14817
+ let response = await ask14(interactive);
14441
14818
  let body = await response.json().catch(() => null);
14442
14819
  if (!again && interactive && response.status === 409 && body?.error?.code === "terminal_unavailable" && /keeps \d+ terminals/.test(String(body.error.message ?? ""))) {
14443
14820
  stderr.write(`${String(body.error.message)} This one is not kept.
14444
14821
  `);
14445
- response = await ask13(false);
14822
+ response = await ask14(false);
14446
14823
  body = await response.json().catch(() => null);
14447
14824
  }
14448
14825
  if (!response.ok || typeof body?.ticket !== "string") {
@@ -14462,8 +14839,8 @@ async function shell(client, id, options = {}, streams = process) {
14462
14839
  if (socket.readyState !== WebSocket.OPEN || chunk.length === 0) {
14463
14840
  return;
14464
14841
  }
14465
- for (let at4 = 0; at4 < chunk.length; at4 += MAX_INPUT_BYTES) {
14466
- socket.send(chunk.subarray(at4, at4 + MAX_INPUT_BYTES));
14842
+ for (let at5 = 0; at5 < chunk.length; at5 += MAX_INPUT_BYTES) {
14843
+ socket.send(chunk.subarray(at5, at5 + MAX_INPUT_BYTES));
14467
14844
  }
14468
14845
  lastSent = chunk[chunk.length - 1];
14469
14846
  };
@@ -14697,11 +15074,11 @@ function whereQuery(text, query = new URLSearchParams()) {
14697
15074
  for (const word of words(text)) {
14698
15075
  const time = /^(made|stopped)([<>])(.+)$/.exec(word);
14699
15076
  if (time) {
14700
- const [, what, side, at4] = time;
15077
+ const [, what, side, at5] = time;
14701
15078
  if (what === "made") {
14702
- query.append(side === ">" ? "createdAfter" : "createdBefore", at4);
15079
+ query.append(side === ">" ? "createdAfter" : "createdBefore", at5);
14703
15080
  } else if (side === "<") {
14704
- query.append("stoppedBefore", at4);
15081
+ query.append("stoppedBefore", at5);
14705
15082
  } else {
14706
15083
  throw new Error(`${word}: stopped takes < only, for sandboxes stopped before a time.`);
14707
15084
  }
@@ -15083,6 +15460,12 @@ async function main() {
15083
15460
  informed: { type: "boolean", default: false },
15084
15461
  sort: { type: "string" },
15085
15462
  role: { type: "string" },
15463
+ // Guilds: the roles of a create or an attach, its brief and form, and who joins with what answers.
15464
+ roles: { type: "string" },
15465
+ brief: { type: "string" },
15466
+ form: { type: "string" },
15467
+ as: { type: "string" },
15468
+ answer: { type: "string", multiple: true },
15086
15469
  "revoke-keys": { type: "boolean", default: false },
15087
15470
  // agental list in a terminal: every column, as piped.
15088
15471
  wide: { type: "boolean", default: false },
@@ -15107,7 +15490,7 @@ async function main() {
15107
15490
  await create({ ...values, template: once(values.template, "--template") });
15108
15491
  return;
15109
15492
  case "list":
15110
- await list4(values.json, whereQuery(values.where ?? "", labelsFilter(values)), values.sort, values.limit, values.wide);
15493
+ await list5(values.json, whereQuery(values.where ?? "", labelsFilter(values)), values.sort, values.limit, values.wide);
15111
15494
  return;
15112
15495
  case "bulk-actions":
15113
15496
  await bulkActionsCommand(positionals.slice(1), values.json);
@@ -15143,7 +15526,7 @@ async function main() {
15143
15526
  await bulk("delete", whereQuery(values.where, labelsFilter(values)), {}, values.yes === true, values.json, values.confirm);
15144
15527
  return;
15145
15528
  }
15146
- await remove3(positionals[1], values["pause-jobs"] === true);
15529
+ await remove4(positionals[1], values["pause-jobs"] === true);
15147
15530
  return;
15148
15531
  case "start":
15149
15532
  if (values.where !== void 0) {
@@ -15233,6 +15616,34 @@ async function main() {
15233
15616
  case "tailscale":
15234
15617
  await tailscale(tailscaleClient(), positionals.slice(1), tailnetFlags(values));
15235
15618
  return;
15619
+ case "guild":
15620
+ case "guilds": {
15621
+ const token = guildTokenHere(DEFAULT_URL);
15622
+ if (token !== null) {
15623
+ process.env["AGENTAL_API_KEY"] = token;
15624
+ }
15625
+ await guild(
15626
+ { request, fail, confirmed, templateId: async (given) => (await templateNamed(given)).id, onToken: token !== null },
15627
+ positionals.slice(1),
15628
+ {
15629
+ json: values.json,
15630
+ yes: values.yes,
15631
+ ...values.roles === void 0 ? {} : { roles: values.roles },
15632
+ ...values.role === void 0 ? {} : { role: values.role },
15633
+ ...values.brief === void 0 ? {} : { brief: values.brief },
15634
+ ...values.form === void 0 ? {} : { form: values.form },
15635
+ ...values.as === void 0 ? {} : { as: values.as },
15636
+ ...values.answer === void 0 ? {} : { answer: values.answer }
15637
+ }
15638
+ );
15639
+ return;
15640
+ }
15641
+ case "subscriptions":
15642
+ await subscriptions(tailscaleClient(), positionals.slice(1), { json: values.json, yes: values.yes === true });
15643
+ return;
15644
+ case "agents":
15645
+ await agents(tailscaleClient(), positionals.slice(1), { json: values.json, yes: values.yes === true, ...once(values.template, "--template") === void 0 ? {} : { template: once(values.template, "--template") }, ...once(values.sandbox, "--sandbox") === void 0 ? {} : { sandbox: once(values.sandbox, "--sandbox") } });
15646
+ return;
15236
15647
  case "tailnet":
15237
15648
  await tailnet(tailscaleClient(), "sandbox", positionals.slice(1), tailnetFlags(values));
15238
15649
  return;
@@ -15461,12 +15872,12 @@ function regionsOption(given) {
15461
15872
  const named = listedIn([given]);
15462
15873
  return named.length === 1 ? { region: named[0] } : { regions: named };
15463
15874
  }
15464
- async function sshKeys(id, keyId, remove4, json3) {
15875
+ async function sshKeys(id, keyId, remove5, json3) {
15465
15876
  if (!id) {
15466
15877
  throw new Error("ssh-keys requires <sandbox-id>");
15467
15878
  }
15468
15879
  const path6 = `/v1/sandboxes/${encodeURIComponent(id)}/ssh/keys`;
15469
- if (remove4) {
15880
+ if (remove5) {
15470
15881
  if (!keyId) {
15471
15882
  throw new Error("ssh-keys --remove requires <key-id>, as ssh-keys lists it");
15472
15883
  }
@@ -15492,7 +15903,7 @@ function publicKeysFrom(given) {
15492
15903
  const file = each.startsWith("~/") ? `${os7.homedir()}${each.slice(1)}` : each;
15493
15904
  let text;
15494
15905
  try {
15495
- text = readFileSync7(file, "utf8");
15906
+ text = readFileSync8(file, "utf8");
15496
15907
  } catch {
15497
15908
  throw new Error(`${each} is neither a public key nor a file that can be read. Give a key line, as ssh-ed25519 AAAA... you@laptop, or its file, as ~/.ssh/id_ed25519.pub.`);
15498
15909
  }
@@ -15543,7 +15954,7 @@ async function regions(asJson) {
15543
15954
  }
15544
15955
  process.stdout.write("* where a sandbox is made when no region is named\n");
15545
15956
  }
15546
- async function list4(asJson, filter, sort, limit, wide = false) {
15957
+ async function list5(asJson, filter, sort, limit, wide = false) {
15547
15958
  const sandboxes2 = [];
15548
15959
  let cursor = null;
15549
15960
  do {
@@ -15858,7 +16269,7 @@ async function exec(positionals) {
15858
16269
  }
15859
16270
  process.exitCode = typeof record["exitCode"] === "number" ? record["exitCode"] : 1;
15860
16271
  }
15861
- async function remove3(id, pauseJobs) {
16272
+ async function remove4(id, pauseJobs) {
15862
16273
  if (!id) {
15863
16274
  throw new Error("delete requires <sandbox-id>");
15864
16275
  }
@@ -15940,11 +16351,11 @@ async function resize(id, size2, now, cancel, maxBurstFee, asJson) {
15940
16351
  const path6 = `/v1/sandboxes/${encodeURIComponent(id)}`;
15941
16352
  const before = await call2(path6, { method: "GET" });
15942
16353
  const name = before.name || id;
15943
- const print4 = (sandbox, line) => process.stdout.write(asJson ? `${JSON.stringify(sandbox, null, 2)}
16354
+ const print5 = (sandbox, line) => process.stdout.write(asJson ? `${JSON.stringify(sandbox, null, 2)}
15944
16355
  ` : `${line}
15945
16356
  `);
15946
16357
  if (cancel && !before.pendingSize) {
15947
- print4(before, `${name} has no size waiting: it stays a ${before.size}.`);
16358
+ print5(before, `${name} has no size waiting: it stays a ${before.size}.`);
15948
16359
  return;
15949
16360
  }
15950
16361
  const to = cancel ? before.size : size2;
@@ -15959,7 +16370,7 @@ async function resize(id, size2, now, cancel, maxBurstFee, asJson) {
15959
16370
  if (!response.ok) {
15960
16371
  if (cancel && response.status === 409 && isApiError(body) && body.error.code === "size_smaller") {
15961
16372
  const read2 = await call2(path6, { method: "GET" });
15962
- print4(read2, `${read2.name || id} is already a ${read2.size}; nothing was waiting.`);
16373
+ print5(read2, `${read2.name || id} is already a ${read2.size}; nothing was waiting.`);
15963
16374
  return;
15964
16375
  }
15965
16376
  fail(response.status, body);
@@ -15967,11 +16378,11 @@ async function resize(id, size2, now, cancel, maxBurstFee, asJson) {
15967
16378
  sayBurstFee(response);
15968
16379
  const after = body;
15969
16380
  if (restart && after.status !== "running") {
15970
- print4(after, `${name} is a ${after.size} now, but ${after.status ?? "not running"}, not running again${after.error ? `: ${after.error}` : ""}. agental start ${id} starts it.`);
16381
+ print5(after, `${name} is a ${after.size} now, but ${after.status ?? "not running"}, not running again${after.error ? `: ${after.error}` : ""}. agental start ${id} starts it.`);
15971
16382
  process.exitCode = 1;
15972
16383
  return;
15973
16384
  }
15974
- print4(
16385
+ print5(
15975
16386
  after,
15976
16387
  after.pendingSize ? `${name} becomes a ${after.pendingSize} at its next start; it runs as a ${after.size} until it is stopped.` : after.size === before.size ? `${name} stays a ${after.size}.` : restart ? `${name} is a ${after.size} now, running again.` : `${name} is a ${after.size} now; its next start boots it as one.`
15977
16388
  );
@@ -16104,25 +16515,25 @@ function timeInWords(total) {
16104
16515
  const parts = [days ? `${days}d` : "", hours ? `${hours}h` : "", minutes ? `${minutes}m` : ""].filter(Boolean);
16105
16516
  return parts.length > 0 ? parts.join(" ") : `${total}s`;
16106
16517
  }
16107
- async function autoStop(id, inText, at4, never, asJson) {
16518
+ async function autoStop(id, inText, at5, never, asJson) {
16108
16519
  if (!id) {
16109
16520
  throw new Error("auto-stop requires <sandbox-id>");
16110
16521
  }
16111
- if ([inText !== void 0, at4 !== void 0, never].filter(Boolean).length > 1) {
16522
+ if ([inText !== void 0, at5 !== void 0, never].filter(Boolean).length > 1) {
16112
16523
  throw new Error("--in, --at and --never say different things: give one.");
16113
16524
  }
16114
16525
  const path6 = `/v1/sandboxes/${encodeURIComponent(id)}/auto-stop`;
16115
16526
  let body;
16116
16527
  if (never) {
16117
16528
  body = await call2(path6, { method: "DELETE" });
16118
- } else if (inText === void 0 && at4 === void 0) {
16529
+ } else if (inText === void 0 && at5 === void 0) {
16119
16530
  body = await call2(path6, { method: "GET" });
16120
16531
  } else {
16121
16532
  const inSeconds = inText === void 0 ? void 0 : seconds(inText);
16122
16533
  if (inSeconds === null) {
16123
16534
  throw new Error("--in is a time from now, such as 30m, 2h or 1d");
16124
16535
  }
16125
- body = await call2(path6, { method: "PUT", body: JSON.stringify(inSeconds === void 0 ? { at: at4 } : { inSeconds }) });
16536
+ body = await call2(path6, { method: "PUT", body: JSON.stringify(inSeconds === void 0 ? { at: at5 } : { inSeconds }) });
16126
16537
  }
16127
16538
  if (asJson) {
16128
16539
  process.stdout.write(`${JSON.stringify(body, null, 2)}
@@ -16187,15 +16598,15 @@ function pictureSize(bytes4) {
16187
16598
  if (bytes4.length >= 24 && bytes4.toString("latin1", 1, 4) === "PNG") {
16188
16599
  return { width: bytes4.readUInt32BE(16), height: bytes4.readUInt32BE(20) };
16189
16600
  }
16190
- for (let at4 = 2; bytes4[0] === 255 && bytes4[1] === 216 && at4 + 9 <= bytes4.length; ) {
16191
- const marker = bytes4[at4 + 1];
16192
- if (bytes4[at4] !== 255) {
16601
+ for (let at5 = 2; bytes4[0] === 255 && bytes4[1] === 216 && at5 + 9 <= bytes4.length; ) {
16602
+ const marker = bytes4[at5 + 1];
16603
+ if (bytes4[at5] !== 255) {
16193
16604
  return null;
16194
16605
  }
16195
16606
  if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
16196
- return { width: bytes4.readUInt16BE(at4 + 7), height: bytes4.readUInt16BE(at4 + 5) };
16607
+ return { width: bytes4.readUInt16BE(at5 + 7), height: bytes4.readUInt16BE(at5 + 5) };
16197
16608
  }
16198
- at4 += 2 + bytes4.readUInt16BE(at4 + 2);
16609
+ at5 += 2 + bytes4.readUInt16BE(at5 + 2);
16199
16610
  }
16200
16611
  return null;
16201
16612
  }
@@ -16203,9 +16614,9 @@ async function clipboard(id, text) {
16203
16614
  if (!id) {
16204
16615
  throw new Error("desktop requires <sandbox-id>");
16205
16616
  }
16206
- const at4 = `/v1/sandboxes/${encodeURIComponent(id)}/desktop/clipboard`;
16617
+ const at5 = `/v1/sandboxes/${encodeURIComponent(id)}/desktop/clipboard`;
16207
16618
  if (text === void 0) {
16208
- const response2 = await request(at4, { method: "GET" });
16619
+ const response2 = await request(at5, { method: "GET" });
16209
16620
  const body = await readBody(response2);
16210
16621
  if (!response2.ok) {
16211
16622
  fail(response2.status, body);
@@ -16213,8 +16624,8 @@ async function clipboard(id, text) {
16213
16624
  process.stdout.write(String(body.text ?? ""));
16214
16625
  return;
16215
16626
  }
16216
- const given = text === "-" ? readFileSync7(0, "utf8") : text;
16217
- const response = await request(at4, { method: "PUT", body: JSON.stringify({ text: given }) });
16627
+ const given = text === "-" ? readFileSync8(0, "utf8") : text;
16628
+ const response = await request(at5, { method: "PUT", body: JSON.stringify({ text: given }) });
16218
16629
  if (!response.ok) {
16219
16630
  fail(response.status, await readBody(response));
16220
16631
  }
@@ -16251,9 +16662,9 @@ async function desktopLinks(id, use2, given, options) {
16251
16662
  if (!id) {
16252
16663
  throw new Error("desktop requires <sandbox-id>");
16253
16664
  }
16254
- const at4 = `/v1/sandboxes/${encodeURIComponent(id)}/desktop/links`;
16665
+ const at5 = `/v1/sandboxes/${encodeURIComponent(id)}/desktop/links`;
16255
16666
  if (use2 === "unlink") {
16256
- const response2 = await request(`${at4}/${encodeURIComponent(String(given))}`, { method: "DELETE" });
16667
+ const response2 = await request(`${at5}/${encodeURIComponent(String(given))}`, { method: "DELETE" });
16257
16668
  if (!response2.ok) {
16258
16669
  fail(response2.status, await readBody(response2));
16259
16670
  }
@@ -16262,7 +16673,7 @@ async function desktopLinks(id, use2, given, options) {
16262
16673
  return;
16263
16674
  }
16264
16675
  if (use2 === "links") {
16265
- const response2 = await request(at4, { method: "GET" });
16676
+ const response2 = await request(at5, { method: "GET" });
16266
16677
  const body2 = await readBody(response2);
16267
16678
  if (!response2.ok) {
16268
16679
  fail(response2.status, body2);
@@ -16278,7 +16689,7 @@ async function desktopLinks(id, use2, given, options) {
16278
16689
  if (expiresIn === null) {
16279
16690
  throw new Error("--expires is how long the link lasts: 600, 10m or 1h, from a minute to a day");
16280
16691
  }
16281
- const response = await request(at4, {
16692
+ const response = await request(at5, {
16282
16693
  method: "POST",
16283
16694
  body: JSON.stringify({ access: given, ...expiresIn === void 0 ? {} : { expiresIn }, ...options.keepStreams ? { cutOnExpiry: false } : {} })
16284
16695
  });
@@ -16303,7 +16714,7 @@ async function useDesktop(id, use2, given) {
16303
16714
  if (!id) {
16304
16715
  throw new Error("desktop requires <sandbox-id>");
16305
16716
  }
16306
- const at4 = `/v1/sandboxes/${encodeURIComponent(id)}/desktop/${use2}`;
16717
+ const at5 = `/v1/sandboxes/${encodeURIComponent(id)}/desktop/${use2}`;
16307
16718
  let body;
16308
16719
  if (use2 === "click") {
16309
16720
  const [x, y, button, count, ...more] = given.split(",");
@@ -16335,7 +16746,7 @@ async function useDesktop(id, use2, given) {
16335
16746
  } else {
16336
16747
  body = { keys: given };
16337
16748
  }
16338
- const response = await request(at4, { method: "POST", body: JSON.stringify(body) });
16749
+ const response = await request(at5, { method: "POST", body: JSON.stringify(body) });
16339
16750
  if (!response.ok) {
16340
16751
  fail(response.status, await readBody(response));
16341
16752
  }
@@ -16348,12 +16759,12 @@ function listedIn(given) {
16348
16759
  function metadataGiven(given) {
16349
16760
  const metadata = {};
16350
16761
  for (const each of given) {
16351
- const at4 = each.indexOf("=");
16352
- const key2 = at4 < 0 ? "" : each.slice(0, at4).trim();
16762
+ const at5 = each.indexOf("=");
16763
+ const key2 = at5 < 0 ? "" : each.slice(0, at5).trim();
16353
16764
  if (key2 === "") {
16354
16765
  throw new Error(`--meta is <key>=<value>, as --meta repo=acme/web, not ${each}`);
16355
16766
  }
16356
- metadata[key2] = each.slice(at4 + 1);
16767
+ metadata[key2] = each.slice(at5 + 1);
16357
16768
  }
16358
16769
  return metadata;
16359
16770
  }
@@ -16488,7 +16899,7 @@ function egressInWords(body) {
16488
16899
  }
16489
16900
  async function egress(positionals, values) {
16490
16901
  const [first, ...rest] = positionals;
16491
- const print4 = (body2, words2) => {
16902
+ const print5 = (body2, words2) => {
16492
16903
  process.stdout.write(values.json ? `${JSON.stringify(body2, null, 2)}
16493
16904
  ` : words2);
16494
16905
  };
@@ -16526,14 +16937,14 @@ async function egress(positionals, values) {
16526
16937
  `this month: ${money(number("spentMicros"))} of a ${money(number("budgetMicros"))} budget${account3["budgetSet"] ? "" : " (the default)"}`,
16527
16938
  ...account3["blocked"] && account3["blocked"] !== "refused" ? [`blocked now: ${String(account3["blocked"]).replaceAll("_", " ")}`] : []
16528
16939
  ];
16529
- print4(body2, `${lines.join("\n")}
16940
+ print5(body2, `${lines.join("\n")}
16530
16941
  `);
16531
16942
  return;
16532
16943
  }
16533
16944
  const path6 = `/v1/sandboxes/${encodeURIComponent(first)}/egress`;
16534
16945
  const how = `egress takes <sandbox-id>, and then nothing, box, or residential <country> [sticky|rotating], as agental egress ${first} residential de.`;
16535
16946
  const body = await call2(path6, rest.length === 0 ? { method: "GET" } : { method: "PUT", body: JSON.stringify(egressFrom(rest, how)) });
16536
- print4(body, `${first}: ${egressInWords(body)}
16947
+ print5(body, `${first}: ${egressInWords(body)}
16537
16948
  `);
16538
16949
  }
16539
16950
  function spotSettingsFrom(values) {
@@ -16652,15 +17063,15 @@ ${faint("The default is used when a sandbox is made without naming one. agental
16652
17063
  process.stdout.write("* used when a sandbox is made without naming one\n");
16653
17064
  }
16654
17065
  function showTemplate(each) {
16655
- const list5 = (items) => items && items.length > 0 ? items.join(", ") : "none";
17066
+ const list6 = (items) => items && items.length > 0 ? items.join(", ") : "none";
16656
17067
  return [
16657
17068
  `id: ${each.id}`,
16658
17069
  `name: ${each.name}${each.default ? " (default: used when a sandbox is made without naming one)" : ""}`,
16659
17070
  `start: ${startInWords(each.start)}`,
16660
- `variables: ${list5(each.variables)}`,
17071
+ `variables: ${list6(each.variables)}`,
16661
17072
  // Said only where some are. An API from before variables could be kept out of the sandbox says nothing of them.
16662
- ...each.hidden && each.hidden.length > 0 ? [`kept out: ${list5(each.hidden)}`] : [],
16663
- `files: ${list5(each.files)}`,
17073
+ ...each.hidden && each.hidden.length > 0 ? [`kept out: ${list6(each.hidden)}`] : [],
17074
+ `files: ${list6(each.files)}`,
16664
17075
  // An API from before templates held rules says nothing of one.
16665
17076
  ...each.network ? [`network: ${ruleInWords(each.network)}`] : [],
16666
17077
  // An API from before templates gave SSH says nothing of it.
@@ -16674,7 +17085,7 @@ function showTemplate(each) {
16674
17085
  async function template(positionals, values) {
16675
17086
  const [action, first, ...rest] = positionals;
16676
17087
  const usage = "template takes create, show, rename, delete, start, network, egress, tailnet, ssh, ssh-keys, tags, meta, sandboxes, apply, of or put. agental template --help says how.";
16677
- const print4 = (body, words2) => {
17088
+ const print5 = (body, words2) => {
16678
17089
  process.stdout.write(values.json ? `${JSON.stringify(body, null, 2)}
16679
17090
  ` : words2);
16680
17091
  };
@@ -16687,7 +17098,7 @@ async function template(positionals, values) {
16687
17098
  switch (action) {
16688
17099
  case "create": {
16689
17100
  const made = await call2("/v1/templates", { method: "POST", body: JSON.stringify({ name: need(first, "<name>"), ...labelsGiven(values) }) });
16690
- print4(made, showTemplate(made));
17101
+ print5(made, showTemplate(made));
16691
17102
  return;
16692
17103
  }
16693
17104
  case "tags":
@@ -16697,13 +17108,13 @@ async function template(positionals, values) {
16697
17108
  case "show": {
16698
17109
  const found = await templateNamed(need(first, "<template>"));
16699
17110
  const read2 = await call2(`/v1/templates/${encodeURIComponent(found.id)}`, { method: "GET" });
16700
- print4(read2, showTemplate(read2));
17111
+ print5(read2, showTemplate(read2));
16701
17112
  return;
16702
17113
  }
16703
17114
  case "rename": {
16704
17115
  const found = await templateNamed(need(first, "<template> <new-name>"));
16705
17116
  const renamed = await call2(`/v1/templates/${encodeURIComponent(found.id)}`, { method: "PATCH", body: JSON.stringify({ name: need(rest[0], "<template> <new-name>") }) });
16706
- print4(renamed, showTemplate(renamed));
17117
+ print5(renamed, showTemplate(renamed));
16707
17118
  return;
16708
17119
  }
16709
17120
  case "delete": {
@@ -16762,7 +17173,7 @@ async function template(positionals, values) {
16762
17173
  body: JSON.stringify({ size: values.size ?? current?.size, snapshotId, ttlSeconds: ttl, ...region === void 0 ? {} : { region }, ...spot2 === void 0 ? {} : { spot: spot2 } })
16763
17174
  });
16764
17175
  }
16765
- print4(start2, `start: ${startInWords(start2)}
17176
+ print5(start2, `start: ${startInWords(start2)}
16766
17177
  `);
16767
17178
  return;
16768
17179
  }
@@ -16786,7 +17197,7 @@ async function template(positionals, values) {
16786
17197
  }
16787
17198
  rule = await call2(path6, { method: "PUT", body: JSON.stringify(mode === "allowlist" ? { outbound: mode, allow: listed2 } : { outbound: mode }) });
16788
17199
  }
16789
- print4(
17200
+ print5(
16790
17201
  rule,
16791
17202
  `${found.name}: ${ruleInWords(rule)}
16792
17203
  ${mode === void 0 ? "" : "A sandbox on it takes this when it next starts, or now with agental template apply.\n"}`
@@ -16801,7 +17212,7 @@ ${mode === void 0 ? "" : "A sandbox on it takes this when it next starts, or now
16801
17212
  const path6 = `/v1/templates/${encodeURIComponent(found.id)}/egress`;
16802
17213
  const how = `template egress takes <template>, and then nothing, box, or residential <country> [sticky|rotating], as agental template egress ${first ?? ""} residential de.`;
16803
17214
  const set2 = await call2(path6, rest.length === 0 ? { method: "GET" } : { method: "PUT", body: JSON.stringify(egressFrom(rest, how)) });
16804
- print4(set2, `${found.name}: ${egressInWords(set2)}${rest.length === 0 ? "" : ", for sandboxes made from it from now on"}
17215
+ print5(set2, `${found.name}: ${egressInWords(set2)}${rest.length === 0 ? "" : ", for sandboxes made from it from now on"}
16805
17216
  `);
16806
17217
  return;
16807
17218
  }
@@ -16813,7 +17224,7 @@ ${mode === void 0 ? "" : "A sandbox on it takes this when it next starts, or now
16813
17224
  throw new Error("template ssh requires <template>, and then nothing, on or off");
16814
17225
  }
16815
17226
  const ssh2 = await call2(path6, { method: turn === "on" ? "PUT" : turn === "off" ? "DELETE" : "GET" });
16816
- print4(ssh2, `${found.name}: SSH ${templateSshInWords(ssh2)}
17227
+ print5(ssh2, `${found.name}: SSH ${templateSshInWords(ssh2)}
16817
17228
  `);
16818
17229
  return;
16819
17230
  }
@@ -16844,7 +17255,7 @@ ${mode === void 0 ? "" : "A sandbox on it takes this when it next starts, or now
16844
17255
  const body = await call2(`/v1/templates/${encodeURIComponent(found.id)}/sandboxes`, { method: "GET" });
16845
17256
  const rows = body.sandboxes.map((each) => `${[pad2(String(each["id"])), pad2(String(each["name"])), pad2(String(each["status"])), each["upToDate"] === true ? "yes" : "no"].join(" ")}
16846
17257
  `);
16847
- print4(body, `${[pad2("ID"), pad2("NAME"), pad2("STATUS"), "UP TO DATE"].join(" ")}
17258
+ print5(body, `${[pad2("ID"), pad2("NAME"), pad2("STATUS"), "UP TO DATE"].join(" ")}
16848
17259
  ${rows.join("")}`);
16849
17260
  return;
16850
17261
  }
@@ -16856,7 +17267,7 @@ ${rows.join("")}`);
16856
17267
  });
16857
17268
  const failed = (body.failed ?? []).map((each) => `Not brought up to date, and held to the rule it had: ${each.sandboxId}: ${each.error}
16858
17269
  `).join("");
16859
- print4(
17270
+ print5(
16860
17271
  body,
16861
17272
  `${body.applied.length === 0 && failed === "" ? `No sandbox on ${found.name} is running. Each takes it when it next starts.
16862
17273
  ` : body.applied.length === 0 ? "" : `Brought up to date with ${found.name}: ${body.applied.join(", ")}
@@ -16870,7 +17281,7 @@ ${rows.join("")}`);
16870
17281
  case "of": {
16871
17282
  const sandboxId = need(first, "<sandbox-id>");
16872
17283
  const body = await call2(`/v1/sandboxes/${encodeURIComponent(sandboxId)}/template`, { method: "GET" });
16873
- print4(body, `template: ${String(body["name"])} (${String(body["templateId"])})
17284
+ print5(body, `template: ${String(body["name"])} (${String(body["templateId"])})
16874
17285
  up to date: ${body["upToDate"] === true ? "yes" : "no: it takes the template when it next starts, or when apply names it"}
16875
17286
  `);
16876
17287
  return;
@@ -16879,7 +17290,7 @@ up to date: ${body["upToDate"] === true ? "yes" : "no: it takes the template whe
16879
17290
  const found = await templateNamed(need(first, "<template> <sandbox-id>"));
16880
17291
  const sandboxId = need(rest[0], "<template> <sandbox-id>");
16881
17292
  const body = await call2(`/v1/sandboxes/${encodeURIComponent(sandboxId)}/template`, { method: "PUT", body: JSON.stringify({ templateId: found.id }) });
16882
- print4(body, `${sandboxId} is on ${found.name}: it has its variables and files from its next command, and is held to its outbound rule now.
17293
+ print5(body, `${sandboxId} is on ${found.name}: it has its variables and files from its next command, and is held to its outbound rule now.
16883
17294
  `);
16884
17295
  return;
16885
17296
  }
@@ -16971,11 +17382,11 @@ async function secrets(positionals, values) {
16971
17382
  throw new Error("--host takes a host, as --host api.github.com");
16972
17383
  }
16973
17384
  const pairs = args.map((arg) => {
16974
- const at4 = arg.indexOf("=");
16975
- if (at4 <= 0) {
17385
+ const at5 = arg.indexOf("=");
17386
+ if (at5 <= 0) {
16976
17387
  throw new Error(`secrets set takes <NAME>=<value>, and ${arg} has no name before an =`);
16977
17388
  }
16978
- return [arg.slice(0, at4), arg.slice(at4 + 1)];
17389
+ return [arg.slice(0, at5), arg.slice(at5 + 1)];
16979
17390
  });
16980
17391
  const path6 = (name) => `${base}/variables/${encodeURIComponent(name)}`;
16981
17392
  if (hosts === void 0 && !values.plain) {
@@ -17083,8 +17494,8 @@ async function metrics(id, asked2) {
17083
17494
  if (!response.ok) {
17084
17495
  fail(response.status, body);
17085
17496
  }
17086
- const answer5 = body && typeof body === "object" ? body : {};
17087
- const fromTo = typeof answer5["since"] === "string" && typeof answer5["until"] === "string" ? ` from ${answer5["since"]} to ${answer5["until"]}` : "";
17497
+ const answer6 = body && typeof body === "object" ? body : {};
17498
+ const fromTo = typeof answer6["since"] === "string" && typeof answer6["until"] === "string" ? ` from ${answer6["since"]} to ${answer6["until"]}` : "";
17088
17499
  if (asked2.json) {
17089
17500
  process.stdout.write(`${JSON.stringify(body, null, 2)}
17090
17501
  `);
@@ -17109,7 +17520,7 @@ async function metrics(id, asked2) {
17109
17520
  ])
17110
17521
  );
17111
17522
  }
17112
- if (answer5["complete"] === false) {
17523
+ if (answer6["complete"] === false) {
17113
17524
  process.stderr.write(
17114
17525
  id === void 0 ? "A server did not answer, so a sandbox on it has no reading here though it may have been running. Ask again in a minute.\n" : `A server did not answer, so readings may be missing: those from any time ${id} was on that server. Ask again in a minute.
17115
17526
  `
@@ -17152,8 +17563,8 @@ async function dataRetention(positionals, asJson) {
17152
17563
  `);
17153
17564
  return;
17154
17565
  }
17155
- const answer5 = body ?? {};
17156
- const days = answer5.keepDays ?? null;
17566
+ const answer6 = body ?? {};
17567
+ const days = answer6.keepDays ?? null;
17157
17568
  const kept2 = days === null ? "until their sandbox is deleted" : days === 1 ? "1 day" : `${days} days`;
17158
17569
  process.stdout.write(`${period === void 0 ? "" : "Saved. "}Command output, agent conversations and events are kept ${kept2}.
17159
17570
  `);
@@ -17161,7 +17572,7 @@ async function dataRetention(positionals, asJson) {
17161
17572
  process.stdout.write(`What is older is deleted within the hour, and cannot be brought back.
17162
17573
  `);
17163
17574
  }
17164
- const last = answer5.lastCleared;
17575
+ const last = answer6.lastCleared;
17165
17576
  if (period === void 0) {
17166
17577
  process.stdout.write(
17167
17578
  last ? `Last clean-up ${last.at}: ${last.commands} commands' output, ${last.conversations} conversations and ${last.events} events deleted.
@@ -17385,12 +17796,12 @@ async function billing(positionals, asJson, limit) {
17385
17796
  if (limit !== void 0 && what !== "invoices") {
17386
17797
  throw new Error("--limit is taken by billing invoices alone.");
17387
17798
  }
17388
- const print4 = (body, text) => process.stdout.write(asJson ? `${JSON.stringify(body, null, 2)}
17799
+ const print5 = (body, text) => process.stdout.write(asJson ? `${JSON.stringify(body, null, 2)}
17389
17800
  ` : text());
17390
17801
  switch (what) {
17391
17802
  case void 0: {
17392
17803
  const [body, card] = await Promise.all([asked("/v1/billing", { method: "GET" }), cardOnFile()]);
17393
- print4({ ...body, card }, () => describeBilling(body, card));
17804
+ print5({ ...body, card }, () => describeBilling(body, card));
17394
17805
  return;
17395
17806
  }
17396
17807
  case "invoices": {
@@ -17399,28 +17810,28 @@ async function billing(positionals, asJson, limit) {
17399
17810
  }
17400
17811
  case "compare": {
17401
17812
  const body = await asked("/v1/burst/replay", { method: "GET" });
17402
- print4(body, () => describePlanReplay(body));
17813
+ print5(body, () => describePlanReplay(body));
17403
17814
  return;
17404
17815
  }
17405
17816
  case "details": {
17406
17817
  const body = await asked("/v1/billing/details", { method: "GET" });
17407
- print4(body, () => describeDetails(body.details));
17818
+ print5(body, () => describeDetails(body.details));
17408
17819
  return;
17409
17820
  }
17410
17821
  case "prices": {
17411
17822
  const body = await asked("/v1/billing/plans", { method: "GET" });
17412
- print4(body, () => isTerminal(process.stdout) ? pricesForPeople(body) : describePrices(body));
17823
+ print5(body, () => isTerminal(process.stdout) ? pricesForPeople(body) : describePrices(body));
17413
17824
  return;
17414
17825
  }
17415
17826
  case "card": {
17416
17827
  if (amount === void 0) {
17417
17828
  const body2 = await asked("/v1/billing/card", { method: "GET" });
17418
- print4(body2, () => body2.card ? `${describeCard(body2.card)}
17829
+ print5(body2, () => body2.card ? `${describeCard(body2.card)}
17419
17830
  ` : "No card saved. agental billing card save prints the page to save one on, charged nothing.\n");
17420
17831
  return;
17421
17832
  }
17422
17833
  const body = await asked("/v1/billing/checkout", { method: "POST", body: JSON.stringify({ card: true }) });
17423
- print4(
17834
+ print5(
17424
17835
  body,
17425
17836
  () => body.url ? `Save a card for the free plan at:
17426
17837
  ${body.url}
@@ -17439,7 +17850,7 @@ Nothing is charged. Once it is saved, the account has its monthly free allowance
17439
17850
  const body = await asked("/v1/billing/checkout", { method: "POST", body: JSON.stringify({ topUp: dollars }) });
17440
17851
  const topUp = topUpByDollars(dollars);
17441
17852
  const what2 = topUp && topUp.bonusMicros > 0 ? `Pay ${wholeMoney(dollars * 1e6)} for ${wholeMoney(topUp.micros)} of credits, a bonus of ${topUp.bonusPercent}%, at:` : `Pay for ${wholeMoney(dollars * 1e6)} of credits at:`;
17442
- print4(
17853
+ print5(
17443
17854
  body,
17444
17855
  () => body.url ? `${what2}
17445
17856
  ${body.url}
@@ -17457,13 +17868,13 @@ Nothing is charged until it is paid. agental billing shows it within a minute of
17457
17868
  );
17458
17869
  }
17459
17870
  const body = await asked("/v1/billing/auto-reload", { method: "PUT", body: JSON.stringify({ dollars: off ? null : dollars }) });
17460
- print4(body, () => `${describeAutoReload(body.autoReload)}
17871
+ print5(body, () => `${describeAutoReload(body.autoReload)}
17461
17872
  `);
17462
17873
  return;
17463
17874
  }
17464
17875
  case "email-copy": {
17465
17876
  const body = await asked("/v1/billing/email-copy", { method: "GET" });
17466
- print4(
17877
+ print5(
17467
17878
  body,
17468
17879
  () => body.address === null ? "Billing emails go to the owners alone. An owner can add an address for a copy of each under Billing in the console.\n" : body.confirmed === false ? `${body.address} gets no copies yet: it has to confirm by the link sent to it. An owner can send a new one under Billing in the console.
17469
17880
  ` : body.waiting === true ? `${body.address} gets no copies for now: whoever set it is no longer an owner. An owner keeps it or removes it under Billing in the console.
@@ -17862,10 +18273,10 @@ async function showLimits(positionals, options) {
17862
18273
  `);
17863
18274
  return;
17864
18275
  }
17865
- const answer5 = body2 && typeof body2 === "object" ? body2 : {};
17866
- const spent = typeof answer5["spentMicros"] === "number" ? answer5["spentMicros"] : 0;
17867
- const budget = typeof answer5["budgetMicros"] === "number" ? answer5["budgetMicros"] : 0;
17868
- process.stdout.write(`Budget for burst fees: ${money(budget)} a month${answer5["budgetSet"] === true ? "" : " (the default)"}; ${money(spent)} spent this month.
18276
+ const answer6 = body2 && typeof body2 === "object" ? body2 : {};
18277
+ const spent = typeof answer6["spentMicros"] === "number" ? answer6["spentMicros"] : 0;
18278
+ const budget = typeof answer6["budgetMicros"] === "number" ? answer6["budgetMicros"] : 0;
18279
+ process.stdout.write(`Budget for burst fees: ${money(budget)} a month${answer6["budgetSet"] === true ? "" : " (the default)"}; ${money(spent)} spent this month.
17869
18280
  `);
17870
18281
  return;
17871
18282
  }
@@ -17895,22 +18306,22 @@ async function showLimits(positionals, options) {
17895
18306
  process.stdout.write(describeLimits(body, options.from === void 0 && options.to === void 0, options.to === void 0));
17896
18307
  }
17897
18308
  function describeLimits(body, today, endsNow) {
17898
- const answer5 = body && typeof body === "object" ? body : {};
17899
- const now = answer5["now"] && typeof answer5["now"] === "object" ? answer5["now"] : {};
18309
+ const answer6 = body && typeof body === "object" ? body : {};
18310
+ const now = answer6["now"] && typeof answer6["now"] === "object" ? answer6["now"] : {};
17900
18311
  const number = (from, name) => typeof from[name] === "number" ? from[name] : 0;
17901
18312
  const units = (mb) => {
17902
18313
  const value = mb / 2048;
17903
18314
  return (Number.isInteger(value) ? value : Math.round(value * 10) / 10).toLocaleString("en-US");
17904
18315
  };
17905
18316
  const clock = (iso) => {
17906
- const at4 = new Date(iso).toISOString();
17907
- return at4.slice(0, 10) === (/* @__PURE__ */ new Date()).toISOString().slice(0, 10) ? `${at4.slice(11, 16)} UTC` : `${at4.slice(0, 10)} ${at4.slice(11, 16)} UTC`;
18317
+ const at5 = new Date(iso).toISOString();
18318
+ return at5.slice(0, 10) === (/* @__PURE__ */ new Date()).toISOString().slice(0, 10) ? `${at5.slice(11, 16)} UTC` : `${at5.slice(0, 10)} ${at5.slice(11, 16)} UTC`;
17908
18319
  };
17909
- const range = today ? "today (UTC)" : `from ${String(answer5["from"] ?? "")} to ${String(answer5["to"] ?? "")}`;
18320
+ const range = today ? "today (UTC)" : `from ${String(answer6["from"] ?? "")} to ${String(answer6["to"] ?? "")}`;
17910
18321
  const lines = [
17911
- `running: ${units(number(now, "runningMb"))} of ${number(now, "runningUnits").toLocaleString("en-US")} units (a tiny is 1, a small 2, a medium 4, a large 8); at the running count ${duration(number(answer5, "atRunningCountMs"))} ${range}`
18322
+ `running: ${units(number(now, "runningMb"))} of ${number(now, "runningUnits").toLocaleString("en-US")} units (a tiny is 1, a small 2, a medium 4, a large 8); at the running count ${duration(number(answer6, "atRunningCountMs"))} ${range}`
17912
18323
  ];
17913
- const bursts = Array.isArray(answer5["bursts"]) ? answer5["bursts"] : [];
18324
+ const bursts = Array.isArray(answer6["bursts"]) ? answer6["bursts"] : [];
17914
18325
  const open = endsNow ? bursts.find((one) => one["endedAt"] === null && typeof one["startedAt"] === "string") : void 0;
17915
18326
  const over = number(now, "overMb") > 0;
17916
18327
  const nextStart = Array.isArray(now["nextStart"]) ? now["nextStart"] : [];
@@ -17926,7 +18337,7 @@ function describeLimits(body, today, endsNow) {
17926
18337
  const budgetMonth = now["budgetMonth"] && typeof now["budgetMonth"] === "object" ? now["budgetMonth"] : null;
17927
18338
  const since = typeof budgetMonth?.start === "string" && budgetMonth.start.slice(8, 10) !== "01" ? ` (since ${shortDayOf(budgetMonth.start)})` : "";
17928
18339
  lines.push(`fees: ${money(number(now, "spentMicros"))} this month${since} of a ${money(number(now, "budgetMicros"))} budget`);
17929
- const refused2 = answer5["refused"] && typeof answer5["refused"] === "object" ? answer5["refused"] : {};
18340
+ const refused2 = answer6["refused"] && typeof answer6["refused"] === "object" ? answer6["refused"] : {};
17930
18341
  const total = number(refused2, "total");
17931
18342
  const byReason = Array.isArray(refused2["byReason"]) ? refused2["byReason"] : [];
17932
18343
  lines.push(
@@ -18135,7 +18546,7 @@ function adminKeyHere() {
18135
18546
  return given;
18136
18547
  }
18137
18548
  try {
18138
- const saved = JSON.parse(readFileSync7(`${os7.homedir()}/.config/agental/admin-key.json`, "utf8"));
18549
+ const saved = JSON.parse(readFileSync8(`${os7.homedir()}/.config/agental/admin-key.json`, "utf8"));
18139
18550
  const forHere = typeof saved.apiUrl === "string" && saved.apiUrl.replace(/\/$/, "") === apiBase().replace(/\/$/, "");
18140
18551
  if (forHere && typeof saved.key === "string" && !(typeof saved.expiresAt === "string" && Date.parse(saved.expiresAt) <= Date.now())) {
18141
18552
  return saved.key;
@@ -18176,11 +18587,11 @@ function readSandboxes(body) {
18176
18587
  return body.sandboxes.filter((item) => Boolean(item) && typeof item === "object");
18177
18588
  }
18178
18589
  function readList(body, name) {
18179
- const list5 = body && typeof body === "object" ? body[name] : void 0;
18180
- if (!Array.isArray(list5)) {
18590
+ const list6 = body && typeof body === "object" ? body[name] : void 0;
18591
+ if (!Array.isArray(list6)) {
18181
18592
  throw new Error(`Metrics response was missing ${name}`);
18182
18593
  }
18183
- return list5.filter((item) => Boolean(item) && typeof item === "object");
18594
+ return list6.filter((item) => Boolean(item) && typeof item === "object");
18184
18595
  }
18185
18596
  function teamOptions(values) {
18186
18597
  return { json: values.json, revokeKeys: values["revoke-keys"], ...values.role === void 0 ? {} : { role: values.role } };
@@ -18276,6 +18687,8 @@ Usage
18276
18687
  agental network <sandbox-id> [--allow <address-or-name>[,<address-or-name>...] | --none] [--json]
18277
18688
  agental egress <sandbox-id> [box | residential <country> [sticky | rotating]] [--json]
18278
18689
  agental tailscale [status | connect --client-id <id> | disconnect [--yes]] [--json]
18690
+ agental subscriptions [list | sign-in <agent> | delete <agent> [--yes]] [--json]
18691
+ agental agents (--template <template> | --sandbox <sandbox-id>) [<agent> off|subscription|api_key|template] [--json]
18279
18692
  agental tailnet <sandbox-id> [join --tag <tag>... [--accept <range>]... [--exit-node <ip>] [--keep-address] [--node-name <name>] | off] [--json]
18280
18693
  agental spot <sandbox-id> [off] [--on-reclaim delete|stop] [--warn-at <chance>] [--json]
18281
18694
  agental templates [--json]