@agent-om/cli 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
- import { join } from "node:path";
3
2
  import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
4
  // ../core/src/view/commands.ts
5
5
  const BOTH = ["cli", "page"];
6
6
  const ref = (about = "the element, by its ref") => ({
@@ -74,6 +74,7 @@ const COMMANDS = [
74
74
  name: "inspect",
75
75
  group: "read",
76
76
  where: BOTH,
77
+ locates: true,
77
78
  about: "the element's markup and a few levels inside it (classes, ids, data- and aria- attributes, text), for what the page says only in its markup: a box ticked by a class. Never a field's value or anything the page keeps out",
78
79
  args: [ref(), {
79
80
  name: "parent",
@@ -219,6 +220,7 @@ const COMMANDS = [
219
220
  name: "press",
220
221
  group: "act",
221
222
  where: BOTH,
223
+ locates: true,
222
224
  about: "press a key, on an element or wherever the focus is",
223
225
  args: [{
224
226
  name: "ref",
@@ -237,6 +239,7 @@ const COMMANDS = [
237
239
  name: "scroll",
238
240
  group: "act",
239
241
  where: BOTH,
242
+ locates: true,
240
243
  about: "scroll the page; or bring an element into view; with a direction, scroll inside it",
241
244
  args: [
242
245
  {
@@ -264,6 +267,7 @@ const COMMANDS = [
264
267
  name: "upload",
265
268
  group: "act",
266
269
  where: ["cli"],
270
+ locates: true,
267
271
  about: "give a file field files",
268
272
  args: [ref("the file field, by its ref"), {
269
273
  name: "files",
@@ -277,6 +281,7 @@ const COMMANDS = [
277
281
  name: "fill-secret",
278
282
  group: "act",
279
283
  where: BOTH,
284
+ locates: true,
280
285
  about: "fill a field that takes a secret (a password, a key) with what the user gives, never shown",
281
286
  args: [ref("the field, by its ref"), {
282
287
  name: "variable",
@@ -552,8 +557,14 @@ const TAB_LEVELS = [
552
557
  ];
553
558
  /** A debugging address as the user gives it: a port on this computer, or the whole address (http:// or ws://). */
554
559
  function endpointOf(cdp) {
555
- if (/^\d{2,5}$/.test(cdp)) return `http://127.0.0.1:${cdp}`;
556
- if (/^(https?|wss?):\/\//.test(cdp)) return cdp;
560
+ if (/^\d{1,5}$/.test(cdp)) {
561
+ const port = Number(cdp);
562
+ if (port >= 1 && port <= 65535) return `http://127.0.0.1:${port}`;
563
+ }
564
+ if (/^(https?|wss?):\/\//.test(cdp)) try {
565
+ new URL(cdp);
566
+ return cdp;
567
+ } catch {}
557
568
  throw new Error(`--cdp takes a port (9222) or a debugging address (http://127.0.0.1:9222, ws://…): '${cdp}'`);
558
569
  }
559
570
  /** Where each Chromium-family browser keeps its user data on this system: the default profile of each. */
@@ -601,8 +612,17 @@ function discover(dirs = userDataDirs()) {
601
612
  for (const dir of dirs) {
602
613
  const file = join(dir, "DevToolsActivePort");
603
614
  if (!existsSync(file)) continue;
604
- const [port, path] = readFileSync(file, "utf8").split(/\r?\n/);
605
- if (/^\d+$/.test(port ?? "") && path?.startsWith("/")) found.push(`ws://127.0.0.1:${port}${path}`);
615
+ let text;
616
+ try {
617
+ text = readFileSync(file, "utf8");
618
+ } catch {
619
+ continue;
620
+ }
621
+ const [portStr, path] = text.split(/\r?\n/);
622
+ if (/^\d{1,5}$/.test(portStr ?? "") && path?.startsWith("/")) {
623
+ const port = Number(portStr);
624
+ if (port >= 1 && port <= 65535) found.push(`ws://127.0.0.1:${port}${path}`);
625
+ }
606
626
  }
607
627
  return found;
608
628
  }
@@ -644,9 +664,15 @@ const SCREENSHOT_WARNING = [
644
664
  " - Is rarely needed: prefer snapshot, inspect, script, or eval first."
645
665
  ].join("\n");
646
666
  // src/session.ts
667
+ const SESSION_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
668
+ /** Validate a session name to prevent path traversal or invalid filesystem names. */
669
+ function validateSessionName(name) {
670
+ if (!SESSION_NAME.test(name) || name === "." || name === "..") throw new UsageError(`invalid session name ${JSON.stringify(name)}: use 1–64 letters, digits, '.', '_' or '-', starting with a letter or digit`);
671
+ return name;
672
+ }
647
673
  /** The folder that holds the tool's sessions. */
648
674
  const sessionsHome = () => join(process.env.AGENT_OM_HOME || join(homedir(), ".agent-om"), "cli");
649
- const sessionDir = (name) => join(sessionsHome(), name);
675
+ const sessionDir = (name) => join(sessionsHome(), validateSessionName(name));
650
676
  const sessionFile = (name) => join(sessionDir(name), "session.json");
651
677
  function readSession(name) {
652
678
  try {
@@ -655,4 +681,4 @@ function readSession(name) {
655
681
  return;
656
682
  }
657
683
  }
658
- export { LOCATOR_ARGS as _, ALLOW_EVAL as a, ToolError as c, screenshotOn as d, ATTACH_MS as f, endpointOf as g, discover as h, sessionsHome as i, UsageError as l, TAB_LEVELS as m, sessionDir as n, ALLOW_SCREENSHOT as o, NO_BROWSER as p, sessionFile as r, SCREENSHOT_WARNING as s, readSession as t, evalOn as u, commandsFor as v };
684
+ export { endpointOf as _, validateSessionName as a, SCREENSHOT_WARNING as c, evalOn as d, screenshotOn as f, discover as g, TAB_LEVELS as h, sessionsHome as i, ToolError as l, NO_BROWSER as m, sessionDir as n, ALLOW_EVAL as o, ATTACH_MS as p, sessionFile as r, ALLOW_SCREENSHOT as s, readSession as t, UsageError as u, LOCATOR_ARGS as v, commandsFor as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-om/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "agent-om: a command-line tool any agent drives from a shell, on any model: a browser kept open between calls, the page read as the Agent Object Model's view (Chrome's accessibility tree and the DOM, merged, secrets removed), and acted on by ref.",
5
5
  "keywords": [
6
6
  "agents",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "@agent-om/cdp-reader": "0.0.0",
44
- "@agent-om/core": "0.1.0",
44
+ "@agent-om/core": "0.1.1",
45
45
  "@types/node": "^24.13.3",
46
46
  "tsdown": "0.23.1",
47
47
  "tsx": "^4.23.15"
package/skill/SKILL.md CHANGED
@@ -42,7 +42,7 @@ Use a heredoc (`agent-om script <<'JS' … JS`) to batch multi-item loops or agg
42
42
 
43
43
  - `om.find({ role, name, match, within })` returns nodes (`ref`, `role`, `name`, `text`, `value`, `description`, `href`, `states`, `line`). `name` tests the node's name; `match` tests anywhere in the line as the view writes it. `within` takes a ref or node.
44
44
  - `om.table(ref)` returns `{ columns, rows: [{ ref, cells, controls }] }`. `om.read()` gives the whole page `{ url, title, root }` uncut.
45
- - `om.<command>(…)` runs any CLI command (except `fill-secret`; `switch-tab` is `om.switchTab`). Back-to-back reads share one page snapshot for up to 500 ms until an action runs.
45
+ - `om.<command>(…)` runs any page CLI command (excluding `fill-secret`, `script`, session commands, and opt-in commands that are off; `switch-tab` is `om.switchTab`). Back-to-back reads share one page snapshot for up to 500 ms until an action runs.
46
46
  - `om.eval(code, node)` (when `eval` is on) runs page JS with `el` and gives what the code returned as a value (secrets scrubbed).
47
47
  - Print only needed facts via `print(…)`. Variables persist across scripts. A script stops after 100 seconds (resetting its sandbox).
48
48