agental 0.16.2 → 0.17.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 +96 -29
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -46,7 +46,7 @@ import { parseArgs } from "node:util";
46
46
 
47
47
  // ../src/cli-build.ts
48
48
  var PUBLISHED = true;
49
- var CLI_VERSION = true ? "0.16.2" : "dev";
49
+ var CLI_VERSION = true ? "0.17.0" : "dev";
50
50
  var DEFAULT_API_URL = true ? "https://agental.io" : "http://127.0.0.1:8741";
51
51
  var PACKAGE_NAME = "agental";
52
52
  var USER_AGENT = `agental-cli/${CLI_VERSION}`;
@@ -1879,7 +1879,7 @@ var COMMANDS = [
1879
1879
  summary: "Start a stopped sandbox, or every one --where finds.",
1880
1880
  examples: ["agental start sbx_2a9a47e50daec64a"],
1881
1881
  flags: [
1882
- ["--where '<words>'", "every sandbox the words find, as one job"],
1882
+ ["--where '<words>'", "every sandbox the words find, as one bulk action"],
1883
1883
  ["--yes", "with --where: start them without asking"],
1884
1884
  ["--max-burst-fee <dollars>", "the most this start may pay in burst fees"]
1885
1885
  ]
@@ -1890,7 +1890,7 @@ var COMMANDS = [
1890
1890
  examples: ["agental stop sbx_2a9a47e50daec64a", "agental stop sbx_2a9a47e50daec64a --keep-memory", "agental stop --where 'bench'"],
1891
1891
  flags: [
1892
1892
  ["--keep-memory", "keep what runs in memory too, so it carries on from where it was"],
1893
- ["--where '<words>'", "every sandbox the words find, as one job"],
1893
+ ["--where '<words>'", "every sandbox the words find, as one bulk action"],
1894
1894
  ["--yes", "with --where: stop them without asking"]
1895
1895
  ]
1896
1896
  },
@@ -1899,7 +1899,7 @@ var COMMANDS = [
1899
1899
  summary: "Delete a sandbox, or every one --where finds. It cannot be undone.",
1900
1900
  examples: ["agental delete sbx_2a9a47e50daec64a"],
1901
1901
  flags: [
1902
- ["--where '<words>'", "every sandbox the words find, as one job"],
1902
+ ["--where '<words>'", "every sandbox the words find, as one bulk action"],
1903
1903
  ["--confirm <count>", "with --where: how many it finds, typed so that none are deleted by mistake"]
1904
1904
  ]
1905
1905
  },
@@ -1916,7 +1916,7 @@ var COMMANDS = [
1916
1916
  ]
1917
1917
  },
1918
1918
  { name: "auto-stop", summary: "Say when a running sandbox stops by itself, or that it never does.", examples: ["agental auto-stop sbx_2a9a47e50daec64a --in 2h", "agental auto-stop sbx_2a9a47e50daec64a --never"] },
1919
- { name: "jobs", summary: "Follow or cancel the work started on many sandboxes at once." },
1919
+ { name: "bulk-actions", summary: "Follow or cancel the work started on many sandboxes at once." },
1920
1920
  { name: "tags", summary: "Read, add or remove a sandbox's tags.", examples: ["agental tags sbx_2a9a47e50daec64a add ci"] },
1921
1921
  {
1922
1922
  name: "meta",
@@ -2059,7 +2059,7 @@ var COMMANDS = [
2059
2059
  ["--json", "print as JSON"]
2060
2060
  ]
2061
2061
  },
2062
- { name: "job", summary: "Follow or cancel the work started on many sandboxes at once.", usage: ["agental job list [--json]", "agental job show <job-id> [--json]", "agental job cancel <job-id>"], also: "jobs" },
2062
+ { name: "bulk", summary: "Follow or cancel the work started on many sandboxes at once.", usage: ["agental bulk list [--json]", "agental bulk show <id> [--json]", "agental bulk cancel <id>"], also: "bulk-actions" },
2063
2063
  {
2064
2064
  name: "member",
2065
2065
  summary: "The members of a team: list them, remove one, invite someone.",
@@ -2099,7 +2099,7 @@ var MAP = [
2099
2099
  ["desktop, browser", "a screen and a Chrome in the sandbox"],
2100
2100
  ["files", "list, send, fetch, move and delete its files"],
2101
2101
  ["scp, ssh-config", "files, and SSH from any tool"],
2102
- ["job, region", "work on many at once, and where they run"]
2102
+ ["bulk, region", "work on many at once, and where they run"]
2103
2103
  ]
2104
2104
  ],
2105
2105
  [
@@ -2273,8 +2273,8 @@ function spelledOut(args, operator = false) {
2273
2273
  return verb !== void 0 && SANDBOX_VERBS.has(verb) ? [verb, ...rest] : wrong("list, create, start, stop, delete, recover, exec, shell or summary");
2274
2274
  case "region":
2275
2275
  return verb === "list" ? ["regions", ...rest] : wrong("list");
2276
- case "job":
2277
- return verb === "list" || verb === "show" || verb === "cancel" ? ["jobs", verb, ...rest] : wrong("list, show or cancel");
2276
+ case "bulk":
2277
+ return verb === "list" || verb === "show" || verb === "cancel" ? ["bulk-actions", verb, ...rest] : wrong("list, show or cancel");
2278
2278
  case "member":
2279
2279
  if (verb === "invite") {
2280
2280
  return ["invite", ...rest];
@@ -2354,7 +2354,7 @@ var SUBCOMMANDS = {
2354
2354
  ci: ["set", "reset"],
2355
2355
  org: ["list", "use", "create"],
2356
2356
  members: ["list", "remove"],
2357
- jobs: ["list", "show", "cancel"],
2357
+ "bulk-actions": ["list", "show", "cancel"],
2358
2358
  account: ["export"],
2359
2359
  help: []
2360
2360
  };
@@ -3959,6 +3959,33 @@ function isMachineSize(value) {
3959
3959
  return Object.hasOwn(MACHINE_SIZES, value);
3960
3960
  }
3961
3961
 
3962
+ // ../src/desktop-tree-text.ts
3963
+ function treeText(tree) {
3964
+ if (tree.windows.length === 0) {
3965
+ return "Nothing on the screen tells what it holds: no window of a program that does is shown. Take a screenshot.";
3966
+ }
3967
+ const quoted2 = (value) => JSON.stringify(value.length > 120 ? `${value.slice(0, 119)}\u2026` : value);
3968
+ const lines = [];
3969
+ for (const window of tree.windows) {
3970
+ const box = window.bounds;
3971
+ lines.push(`window ${window.index}: ${window.program}${window.title ? ` ${quoted2(window.title)}` : ""}${window.active ? " (active)" : ""} at ${box.x},${box.y} ${box.width}x${box.height}`);
3972
+ for (const element of tree.elements.filter((each) => each.window === window.index)) {
3973
+ const b = element.bounds;
3974
+ const middle = `${b.x + Math.floor(b.width / 2)},${b.y + Math.floor(b.height / 2)}`;
3975
+ const states = element.states && element.states.length > 0 ? ` [${element.states.join(", ")}]` : "";
3976
+ const value = element.value !== void 0 ? ` value=${quoted2(element.value)}` : "";
3977
+ lines.push(` ${element.role}${element.name ? ` ${quoted2(element.name)}` : ""}${states}${value} click ${middle}`);
3978
+ }
3979
+ }
3980
+ if (tree.elements.length === 0) {
3981
+ lines.push("No element matched.");
3982
+ }
3983
+ if (tree.truncated) {
3984
+ lines.push("There is more than this: narrow it with window or query.");
3985
+ }
3986
+ return lines.join("\n");
3987
+ }
3988
+
3962
3989
  // ../src/ssh-keys.ts
3963
3990
  var KEY_TYPE = /^(ssh-(ed25519|rsa|dss)|ecdsa-sha2-nistp(256|384|521)|sk-ssh-ed25519(@openssh\.com)?|sk-ecdsa-sha2-nistp256(@openssh\.com)?)$/;
3964
3991
  var SSH_PUBLIC_KEY = new RegExp(`^${KEY_TYPE.source.slice(1, -1)} [A-Za-z0-9+/]+={0,3}(?: .*)?$`);
@@ -4283,6 +4310,9 @@ async function main() {
4283
4310
  "no-cursor": { type: "boolean" },
4284
4311
  clipboard: { type: "boolean" },
4285
4312
  "set-clipboard": { type: "string" },
4313
+ tree: { type: "boolean" },
4314
+ window: { type: "string" },
4315
+ query: { type: "string" },
4286
4316
  link: { type: "string" },
4287
4317
  links: { type: "boolean" },
4288
4318
  unlink: { type: "string" },
@@ -4368,8 +4398,8 @@ async function main() {
4368
4398
  case "list":
4369
4399
  await list2(values.json, whereQuery(values.where ?? "", labelsFilter(values)), values.sort, values.limit, values.wide);
4370
4400
  return;
4371
- case "jobs":
4372
- await jobs(positionals.slice(1), values.json);
4401
+ case "bulk-actions":
4402
+ await bulkActionsCommand(positionals.slice(1), values.json);
4373
4403
  return;
4374
4404
  case "summary":
4375
4405
  await summary(values.json, whereQuery(values.where ?? "", labelsFilter(values)), values.facets);
@@ -4449,14 +4479,20 @@ async function main() {
4449
4479
  const use = DESKTOP_USES.filter((name) => values[name] !== void 0);
4450
4480
  const shotOptions = { crop: values.crop, scale: values.scale, quality: values.quality, cursor: values["no-cursor"] === true ? false : void 0 };
4451
4481
  const linkOptions = { expires: values.expires, keepStreams: values["keep-streams"] === true };
4482
+ const treeOptions = { window: values.window, query: values.query, limit: values.limit };
4452
4483
  const shaping = Object.values(shotOptions).some((value) => value !== void 0);
4453
4484
  const linking = linkOptions.expires !== void 0 || linkOptions.keepStreams;
4454
- if (use.length === 0 && !shaping && !linking) {
4485
+ const narrowing = Object.values(treeOptions).some((value) => value !== void 0);
4486
+ if (use.length === 0 && !shaping && !linking && !narrowing) {
4455
4487
  await desktop(positionals[1], values.screen, values.off, values.status);
4456
4488
  } else if (use.length !== 1 || values.screen !== void 0 || values.off || values.status) {
4457
- throw new Error(use.length === 0 ? "desktop takes --crop, --scale, --quality and --no-cursor with --screenshot, and --expires and --keep-streams with --link" : `desktop does one thing at a time: --${use[0]} goes with no other of its options`);
4458
- } else if (shaping && use[0] !== "screenshot" || linking && use[0] !== "link") {
4459
- throw new Error(shaping ? "--crop, --scale, --quality and --no-cursor go with --screenshot" : "--expires and --keep-streams go with --link");
4489
+ throw new Error(
4490
+ use.length === 0 ? "desktop takes --crop, --scale, --quality and --no-cursor with --screenshot, --window, --query and --limit with --tree, and --expires and --keep-streams with --link" : `desktop does one thing at a time: --${use[0]} goes with no other of its options`
4491
+ );
4492
+ } else if (shaping && use[0] !== "screenshot" || linking && use[0] !== "link" || narrowing && use[0] !== "tree") {
4493
+ throw new Error(shaping ? "--crop, --scale, --quality and --no-cursor go with --screenshot" : linking ? "--expires and --keep-streams go with --link" : "--window, --query and --limit go with --tree");
4494
+ } else if (use[0] === "tree") {
4495
+ await desktopTree(positionals[1], treeOptions, values.json);
4460
4496
  } else if (use[0] === "screenshot") {
4461
4497
  await screenshot(positionals[1], values.screenshot, shotOptions);
4462
4498
  } else if (use[0] === "clipboard" || use[0] === "set-clipboard") {
@@ -4871,7 +4907,7 @@ async function confirmed(question) {
4871
4907
  }
4872
4908
  }
4873
4909
  async function bulk(action, filter, options, yes2, asJson, confirm) {
4874
- const previewed = await request("/v1/sandbox-jobs/preview", { method: "POST", body: JSON.stringify({ action, options, select: { filter: filterOf(filter) } }) });
4910
+ const previewed = await request("/v1/bulk-actions/preview", { method: "POST", body: JSON.stringify({ action, options, select: { filter: filterOf(filter) } }) });
4875
4911
  const preview = await readBody(previewed);
4876
4912
  if (!previewed.ok) {
4877
4913
  fail(previewed.status, preview);
@@ -4895,7 +4931,7 @@ async function bulk(action, filter, options, yes2, asJson, confirm) {
4895
4931
  process.stderr.write("Nothing was done. --yes goes on without asking.\n");
4896
4932
  return;
4897
4933
  }
4898
- const made = await request("/v1/sandbox-jobs", { method: "POST", headers: { "Idempotency-Key": `cli-${read2.id}` }, body: JSON.stringify({ previewId: read2.id, ...count === null ? {} : { confirm: count } }) });
4934
+ const made = await request("/v1/bulk-actions", { method: "POST", headers: { "Idempotency-Key": `cli-${read2.id}` }, body: JSON.stringify({ previewId: read2.id, ...count === null ? {} : { confirm: count } }) });
4899
4935
  let job = await readBody(made);
4900
4936
  if (!made.ok) {
4901
4937
  fail(made.status, job);
@@ -4903,7 +4939,7 @@ async function bulk(action, filter, options, yes2, asJson, confirm) {
4903
4939
  while (job.state === "running") {
4904
4940
  process.stderr.write(`\r${job.id}: ${job.counts["done"] ?? 0} done, ${job.counts["skipped"] ?? 0} skipped, ${job.counts["failed"] ?? 0} failed of ${job.total}`);
4905
4941
  await new Promise((resolve) => setTimeout(resolve, 1e3));
4906
- const read3 = await request(`/v1/sandbox-jobs/${job.id}`, { method: "GET" });
4942
+ const read3 = await request(`/v1/bulk-actions/${job.id}`, { method: "GET" });
4907
4943
  job = await readBody(read3);
4908
4944
  if (!read3.ok) {
4909
4945
  fail(read3.status, job);
@@ -4922,11 +4958,11 @@ async function bulk(action, filter, options, yes2, asJson, confirm) {
4922
4958
  `);
4923
4959
  }
4924
4960
  }
4925
- async function jobs(positionals, asJson) {
4961
+ async function bulkActionsCommand(positionals, asJson) {
4926
4962
  const [verb, id] = positionals;
4927
- const path5 = verb === void 0 || verb === "list" ? "/v1/sandbox-jobs" : verb === "show" && id ? `/v1/sandbox-jobs/${encodeURIComponent(id)}` : verb === "cancel" && id ? `/v1/sandbox-jobs/${encodeURIComponent(id)}/cancel` : null;
4963
+ const path5 = verb === void 0 || verb === "list" ? "/v1/bulk-actions" : verb === "show" && id ? `/v1/bulk-actions/${encodeURIComponent(id)}` : verb === "cancel" && id ? `/v1/bulk-actions/${encodeURIComponent(id)}/cancel` : null;
4928
4964
  if (path5 === null) {
4929
- throw new Error("jobs takes list, show <job-id> or cancel <job-id>");
4965
+ throw new Error("bulk-actions takes list, show <id> or cancel <id>");
4930
4966
  }
4931
4967
  const response = await request(path5, { method: verb === "cancel" ? "POST" : "GET" });
4932
4968
  const body = await readBody(response);
@@ -4938,9 +4974,9 @@ async function jobs(positionals, asJson) {
4938
4974
  `);
4939
4975
  return;
4940
4976
  }
4941
- const listed = verb === void 0 || verb === "list" ? body.jobs ?? [] : [body];
4977
+ const listed = verb === void 0 || verb === "list" ? body.actions ?? [] : [body];
4942
4978
  if (listed.length === 0) {
4943
- process.stdout.write("No jobs.\n");
4979
+ process.stdout.write("No bulk actions.\n");
4944
4980
  return;
4945
4981
  }
4946
4982
  for (const job of listed) {
@@ -5001,7 +5037,7 @@ async function lifecycle(action, id, headers = {}, sent) {
5001
5037
  throw new Error(`${action} requires <sandbox-id>`);
5002
5038
  }
5003
5039
  if (sent?.["keepMemory"] === true) {
5004
- process.stderr.write(`Stopping ${id} with its memory kept. It ends once the memory is written, up to two minutes for a large sandbox.
5040
+ process.stderr.write(`Stopping ${id} with its memory kept. It ends once the memory is written, about a second for every 2 to 3 GiB.
5005
5041
  `);
5006
5042
  }
5007
5043
  const response = await request(`/v1/sandboxes/${encodeURIComponent(id)}/${action}`, { method: "POST", headers, ...sent === void 0 ? {} : { body: JSON.stringify(sent) } });
@@ -5180,7 +5216,7 @@ async function browser(id, headless, headed, off, status) {
5180
5216
  );
5181
5217
  }
5182
5218
  }
5183
- var DESKTOP_USES = ["screenshot", "click", "move", "drag", "scroll", "type", "key", "clipboard", "set-clipboard", "link", "links", "unlink"];
5219
+ var DESKTOP_USES = ["screenshot", "click", "move", "drag", "scroll", "type", "key", "clipboard", "set-clipboard", "tree", "link", "links", "unlink"];
5184
5220
  function seconds(text) {
5185
5221
  const given = /^(\d+)([smhd]?)$/.exec(text);
5186
5222
  return given ? Number(given[1]) * { "": 1, s: 1, m: 60, h: 3600, d: 86400 }[given[2] ?? ""] : null;
@@ -5322,6 +5358,32 @@ async function clipboard(id, text) {
5322
5358
  process.stderr.write(`The text is on the clipboard of ${id}. It is pasted where the keyboard's focus is by agental desktop ${id} --key ctrl+v.
5323
5359
  `);
5324
5360
  }
5361
+ async function desktopTree(id, options, json) {
5362
+ if (!id) {
5363
+ throw new Error("desktop requires <sandbox-id>");
5364
+ }
5365
+ const query = new URLSearchParams();
5366
+ if (options.window !== void 0) {
5367
+ query.set("window", options.window);
5368
+ }
5369
+ if (options.query !== void 0) {
5370
+ query.set("query", options.query);
5371
+ }
5372
+ if (options.limit !== void 0) {
5373
+ if (!/^\d+$/.test(options.limit)) {
5374
+ throw new Error("--limit is a number of elements, from 1 to 2000");
5375
+ }
5376
+ query.set("limit", options.limit);
5377
+ }
5378
+ const response = await request(`/v1/sandboxes/${encodeURIComponent(id)}/desktop/tree${query.size > 0 ? `?${query}` : ""}`, { method: "GET" });
5379
+ const body = await readBody(response);
5380
+ if (!response.ok) {
5381
+ fail(response.status, body);
5382
+ }
5383
+ process.stdout.write(json ? `${JSON.stringify(body, null, 2)}
5384
+ ` : `${treeText(body)}
5385
+ `);
5386
+ }
5325
5387
  async function desktopLinks(id, use, given, options) {
5326
5388
  if (!id) {
5327
5389
  throw new Error("desktop requires <sandbox-id>");
@@ -7058,10 +7120,10 @@ Usage
7058
7120
  agental delete <sandbox-id>
7059
7121
  agental start <sandbox-id> [--max-burst-fee <dollars>]
7060
7122
  agental stop <sandbox-id> [--keep-memory]
7061
- agental stop --where '<words>' [--keep-memory] [--yes] every sandbox the words find, as one job
7123
+ agental stop --where '<words>' [--keep-memory] [--yes] every sandbox the words find, as one bulk action
7062
7124
  agental start --where '<words>' [--yes]
7063
7125
  agental delete --where '<words>' [--confirm <count>] asks for the count to be typed
7064
- agental jobs [list | show <job-id> | cancel <job-id>] [--json]
7126
+ agental bulk-actions [list | show <id> | cancel <id>] [--json]
7065
7127
  agental recover <sandbox-id> [--max-burst-fee <dollars>]
7066
7128
  agental resize <sandbox-id> tiny|small|medium|large [--now] [--max-burst-fee <dollars>] [--json]
7067
7129
  agental resize <sandbox-id> --cancel [--json] a size that waits for its next start, taken away
@@ -7154,6 +7216,7 @@ ${FILES_USAGE.map((line) => ` ${line}`).join("\n")}
7154
7216
  agental desktop <sandbox-id> --click <x,y> | --move <x,y> | --drag <x,y,x,y>
7155
7217
  | --scroll <x,y,notches> | --type <text> | --key <keys>
7156
7218
  agental desktop <sandbox-id> --clipboard | --set-clipboard <text|->
7219
+ agental desktop <sandbox-id> --tree [--window <title>] [--query <word>] [--limit <n>] [--json]
7157
7220
  agental desktop <sandbox-id> --link view|control [--expires <10m>] [--keep-streams] | --links
7158
7221
  | --unlink <link-id>
7159
7222
  agental browser <sandbox-id> [--headless | --headed] [--off] [--status]
@@ -7401,7 +7464,11 @@ double click of the right button, --scroll 640,400,-3 turns the wheel up three n
7401
7464
  named .jpg, of a part of the screen with --crop, smaller with --scale, and without the pointer
7402
7465
  with --no-cursor: each makes it cheaper for a model to read. --clipboard prints the text on the
7403
7466
  desktop's clipboard, and --set-clipboard puts text there, read from standard input with -, for
7404
- --key ctrl+v to paste at once what --type would type a key at a time. --link view makes a link
7467
+ --key ctrl+v to paste at once what --type would type a key at a time. --tree prints what is on
7468
+ the screen as its programs tell it: each window, then its buttons, fields and menus, each with
7469
+ the point --click is sent to. --window keeps the windows whose title or program holds a word,
7470
+ --query the elements whose name or role does, and --limit says how many at most, 300 unless it
7471
+ is given. A page in the browser is not in it. --link view makes a link
7405
7472
  to watch the screen without using it, and --link control one to use it as well, at an address of
7406
7473
  its own that leads nowhere after ten minutes, or after --expires: 30m, 1h, up to a day. What was
7407
7474
  opened through it is closed then, unless --keep-streams. --links lists them, and --unlink takes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agental",
3
- "version": "0.16.2",
3
+ "version": "0.17.0",
4
4
  "description": "The agental command: Linux sandboxes for your agents, from the terminal. npx agental@latest signs you in and installs the agent skills.",
5
5
  "license": "MIT",
6
6
  "author": "VERTIXER LTD",