@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.
package/README.md CHANGED
@@ -10,11 +10,31 @@ on by ref. It works on any site, built for agents or not.
10
10
 
11
11
  ```sh
12
12
  npm install -g @agent-om/cli
13
- agent-om install # once: the browser it drives
13
+ agent-om install # once: downloads Playwright's Chromium
14
14
  ```
15
15
 
16
16
  Node 22 or later.
17
17
 
18
+ ### Using your own Chrome (no browser download needed)
19
+
20
+ You can skip `agent-om install` and launch your installed Chrome, or attach to a
21
+ Chrome you already have open (with your sign-ins):
22
+
23
+ ```sh
24
+ # Launch an installed Chrome / Chromium binary directly
25
+ agent-om start --executable "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
26
+
27
+ # Attach to your running Chrome (enable remote debugging at chrome://inspect/#remote-debugging;
28
+ # Chrome asks you to click Allow each time a session attaches)
29
+ agent-om start --auto-connect # agent's own tabs only (--tabs own, the default)
30
+ agent-om start --auto-connect --tabs active # also the tab currently in front
31
+ agent-om start --cdp 9222 # or attach by explicit CDP port / WebSocket URL
32
+ ```
33
+
34
+ Run `agent-om help session` for more on profiles (`--profile`), saved auth state
35
+ (`--state`), tab scopes (`--tabs own|active|all`), and site restrictions
36
+ (`--allow-origin`).
37
+
18
38
  ## Use
19
39
 
20
40
  ```console
@@ -66,18 +86,27 @@ acting (`click`, `fill`, `type`, `select`, `check`, `press`, `scroll`,
66
86
  session attached to your own browser (`--cdp`, `--auto-connect`), where a
67
87
  script would read everything you are signed in to, `eval` is off unless the
68
88
  session starts with `AGENT_OM_ALLOW_EVAL=1`.
89
+ - **`screenshot`, opt-in.** Screenshots are off by default (the text view is
90
+ usually enough and avoids sending pixels). Enable with
91
+ `agent-om start --allow-screenshot` or `AGENT_OM_ALLOW_SCREENSHOT=1`; secrets
92
+ and `data-agentom-ignore` regions are masked before capture.
69
93
 
70
94
  ## For an agent
71
95
 
72
96
  The package ships a skill text that teaches any model the workflow (skill
73
- name `agent-om`); `agent-om skill` prints the one for the installed version.
74
- For Claude Code:
97
+ name `agent-om`). Install it in one command:
75
98
 
76
99
  ```sh
77
- mkdir -p .claude/skills/agent-om
78
- agent-om skill > .claude/skills/agent-om/SKILL.md
100
+ # Install globally for OpenCode, Claude Code, Codex, and Cursor:
101
+ agent-om skill install --global
102
+
103
+ # Or install into the current project (.agents/skills/ and .claude/skills/):
104
+ agent-om skill install
79
105
  ```
80
106
 
107
+ `agent-om skill` prints the raw `SKILL.md` to stdout if you want to place it
108
+ somewhere else manually.
109
+
81
110
  ## Documentation
82
111
 
83
112
  - [How it works](https://github.com/TheAsyncLooop/agent-om/blob/master/docs/semantic-projection.md)
package/dist/agent-om.mjs CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { _ as LOCATOR_ARGS, a as ALLOW_EVAL, d as screenshotOn, f as ATTACH_MS, h as discover, i as sessionsHome, l as UsageError, m as TAB_LEVELS, n as sessionDir, o as ALLOW_SCREENSHOT, s as SCREENSHOT_WARNING, t as readSession, u as evalOn, v as commandsFor } from "./session-CeDFN-1x.mjs";
2
+ import { a as validateSessionName, c as SCREENSHOT_WARNING, d as evalOn, f as screenshotOn, g as discover, h as TAB_LEVELS, i as sessionsHome, n as sessionDir, o as ALLOW_EVAL, p as ATTACH_MS, s as ALLOW_SCREENSHOT, t as readSession, u as UsageError, v as LOCATOR_ARGS, y as commandsFor } from "./session-lYFPsBGa.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { spawn, spawnSync } from "node:child_process";
5
- import { existsSync, mkdirSync, openSync, readFileSync, readdirSync, statSync } from "node:fs";
5
+ import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
6
+ import { homedir } from "node:os";
6
7
  import { dirname, join, resolve } from "node:path";
7
8
  import { createInterface } from "node:readline/promises";
8
9
  import { fileURLToPath } from "node:url";
@@ -110,13 +111,33 @@ function usage() {
110
111
  "Help",
111
112
  " help this text",
112
113
  ...Object.entries(TOPICS).map(([name, t]) => ` ${`help ${name}`.padEnd(37)}${t.about}`),
113
- " skill the skill an agent reads to use this tool, for this version (save it as",
114
- " .claude/skills/agent-om/SKILL.md, or wherever the agent reads skills)",
114
+ " skill print the skill an agent reads to use this tool, for this version",
115
+ " skill install [--global] [--dir <folder>]",
116
+ " install the skill into .agents/skills/ and .claude/skills/ (or with --global,",
117
+ " also ~/.config/opencode/skills/ under your home directory)",
115
118
  ""
116
119
  ].join("\n");
117
120
  }
121
+ const SKILL_HELP = [
122
+ "agent-om skill print the skill for this version",
123
+ "agent-om skill install [--dir <folder>] install into .agents/skills/agent-om/ and .claude/skills/agent-om/",
124
+ "agent-om skill install --global (-g) install globally for OpenCode, Claude Code, Codex, and Cursor",
125
+ ""
126
+ ].join("\n");
118
127
  /** The options of `start`, which a first command may carry for the session it starts. */
119
128
  const START_OPTIONS = commandsFor("cli").find((c) => c.name === "start").args.flatMap((a) => [...a.cli.matchAll(/--([a-z-]+)/g)].map(([, name]) => name));
129
+ /** Session/security flags that cannot be applied to an already running session. */
130
+ const RUNNING_SESSION_FLAGS = /* @__PURE__ */ new Set([
131
+ ...START_OPTIONS,
132
+ "allow-origin",
133
+ "tabs",
134
+ "state",
135
+ "profile",
136
+ "cdp",
137
+ "auto-connect",
138
+ "allow-screenshot",
139
+ "no-eval"
140
+ ]);
120
141
  /**
121
142
  * The options the table of commands names (opt-in commands too: one turned off is refused by name, not as an
122
143
  * unknown option), each taking a value (`--ref <ref>`, `--text "<what it shows>"`, `--tabs own|active|all`) or a
@@ -129,9 +150,16 @@ const BOOLEAN = /* @__PURE__ */ new Set([
129
150
  "confirm",
130
151
  "accept",
131
152
  "help",
153
+ "version",
154
+ "global",
132
155
  ...OPTIONS.filter(([, , value]) => !value).map(([, name]) => name)
133
156
  ]);
134
- const VALUE = /* @__PURE__ */ new Set(["session", ...OPTIONS.filter(([, , value]) => value).map(([, name]) => name)]);
157
+ const VALUE = /* @__PURE__ */ new Set([
158
+ "session",
159
+ "dir",
160
+ "scope",
161
+ ...OPTIONS.filter(([, , value]) => value).map(([, name]) => name)
162
+ ]);
135
163
  /** A command line's command, arguments and options. An option the tool hasn't got, or one missing its value, is refused. */
136
164
  function parse(argv) {
137
165
  const args = {
@@ -153,6 +181,18 @@ function parse(argv) {
153
181
  args.flags.interactive = true;
154
182
  continue;
155
183
  }
184
+ if (a === "-g") {
185
+ args.flags.global = true;
186
+ continue;
187
+ }
188
+ if (a === "-h") {
189
+ args.flags.help = true;
190
+ continue;
191
+ }
192
+ if (a === "-v") {
193
+ args.flags.version = true;
194
+ continue;
195
+ }
156
196
  if (!a.startsWith("--")) {
157
197
  word(a);
158
198
  continue;
@@ -170,13 +210,13 @@ function parse(argv) {
170
210
  args
171
211
  };
172
212
  }
173
- /** All of stdin, as text. */
174
- async function stdin() {
213
+ /** All of stdin (or an injected input stream), as text. */
214
+ async function stdin(input = process.stdin) {
175
215
  const chunks = [];
176
- for await (const c of process.stdin) chunks.push(c);
216
+ for await (const c of input) chunks.push(typeof c === "string" ? Buffer.from(c, "utf8") : c);
177
217
  return Buffer.concat(chunks).toString("utf8");
178
218
  }
179
- const nameOf = (args) => typeof args.flags.session === "string" && args.flags.session || process.env.AGENT_OM_SESSION || "default";
219
+ const nameOf = (args) => validateSessionName(typeof args.flags.session === "string" && args.flags.session || process.env.AGENT_OM_SESSION || "default");
180
220
  async function send(name, cmd, args, env) {
181
221
  const s = readSession(name);
182
222
  if (!s) return {
@@ -225,11 +265,15 @@ async function confirmScreenshots(input = process.stdin, output = process.stderr
225
265
  }
226
266
  }
227
267
  async function start(name, args, input = process.stdin, promptOut = process.stderr) {
228
- const running = await send(name, "status", args);
268
+ const running = await send(name, "status", {
269
+ _: [],
270
+ flags: {}
271
+ });
229
272
  if (running.ok) {
230
- if (args.flags["allow-screenshot"] === true) return {
273
+ const given = Object.keys(args.flags).filter((f) => RUNNING_SESSION_FLAGS.has(f));
274
+ if (given.length) return {
231
275
  ok: false,
232
- error: "a session is already running: run agent-om stop first, then start with --allow-screenshot"
276
+ error: `a session is already running: run agent-om stop first, then start with ${given.map((f) => `--${f}`).join(", ")}`
233
277
  };
234
278
  return {
235
279
  ok: true,
@@ -259,11 +303,18 @@ async function start(name, args, input = process.stdin, promptOut = process.stde
259
303
  ok: false,
260
304
  error: `--tabs own, active or all: '${String(tabs)}'`
261
305
  };
262
- if (args.flags["allow-origin"] !== void 0) {
263
- const bad = String(args.flags["allow-origin"]).split(",").find((o) => !/^https?:\/\/[^/\s]+$/.test(o.trim().replace(/\/$/, "")));
264
- if (bad !== void 0) return {
306
+ if (args.flags["allow-origin"] !== void 0) for (const raw of String(args.flags["allow-origin"]).split(",")) {
307
+ const trimmed = raw.trim().replace(/\/$/, "");
308
+ let valid = false;
309
+ try {
310
+ const u = new URL(trimmed);
311
+ valid = (u.protocol === "http:" || u.protocol === "https:") && u.pathname === "/" && !u.search && !u.hash && !u.username && !u.password && !!u.hostname;
312
+ } catch {
313
+ valid = false;
314
+ }
315
+ if (!valid) return {
265
316
  ok: false,
266
- error: `--allow-origin takes sites as https://example.com, separated by commas: '${bad}'`
317
+ error: `--allow-origin takes sites as https://example.com, separated by commas: '${raw}'`
267
318
  };
268
319
  }
269
320
  if (args.flags["allow-screenshot"] === true) {
@@ -277,33 +328,38 @@ async function start(name, args, input = process.stdin, promptOut = process.stde
277
328
  });
278
329
  const logFile = join(dir, "server.log");
279
330
  const from = existsSync(logFile) ? statSync(logFile).size : 0;
280
- const log = openSync(logFile, "a");
281
331
  const bin = process.argv[1] ?? fileURLToPath(new URL("../bin/agent-om.mjs", import.meta.url));
282
332
  const pass = (flag, path = false) => typeof args.flags[flag] === "string" ? [`--${flag}`, path ? resolve(args.flags[flag]) : args.flags[flag]] : [];
283
- const child = spawn(process.execPath, [
284
- bin,
285
- "__serve",
286
- "--session",
287
- name,
288
- "--viewport",
289
- viewport,
290
- ...args.flags.headed ? ["--headed"] : [],
291
- ...pass("state", true),
292
- ...pass("profile", true),
293
- ...pass("executable"),
294
- ...pass("cdp"),
295
- ...pass("tabs"),
296
- ...pass("allow-origin"),
297
- ...args.flags["auto-connect"] ? ["--auto-connect"] : [],
298
- ...args.flags["allow-screenshot"] ? ["--allow-screenshot"] : []
299
- ], {
300
- detached: true,
301
- stdio: [
302
- "ignore",
303
- log,
304
- log
305
- ]
306
- });
333
+ const log = openSync(logFile, "a", 384);
334
+ let child;
335
+ try {
336
+ child = spawn(process.execPath, [
337
+ bin,
338
+ "__serve",
339
+ "--session",
340
+ name,
341
+ "--viewport",
342
+ viewport,
343
+ ...args.flags.headed ? ["--headed"] : [],
344
+ ...pass("state", true),
345
+ ...pass("profile", true),
346
+ ...pass("executable"),
347
+ ...pass("cdp"),
348
+ ...pass("tabs"),
349
+ ...pass("allow-origin"),
350
+ ...args.flags["auto-connect"] ? ["--auto-connect"] : [],
351
+ ...args.flags["allow-screenshot"] ? ["--allow-screenshot"] : []
352
+ ], {
353
+ detached: true,
354
+ stdio: [
355
+ "ignore",
356
+ log,
357
+ log
358
+ ]
359
+ });
360
+ } finally {
361
+ closeSync(log);
362
+ }
307
363
  child.unref();
308
364
  let exited = false;
309
365
  child.once("exit", () => void (exited = true));
@@ -408,9 +464,80 @@ async function main(argv, input = process.stdin) {
408
464
  return;
409
465
  }
410
466
  const { cmd, args } = parsed;
411
- const name = nameOf(args);
467
+ if (args.flags.version && !cmd) {
468
+ const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
469
+ process.stdout.write(`${pkg.version}\n`);
470
+ return;
471
+ }
472
+ if (cmd === "skill") {
473
+ if (args.flags.help) {
474
+ process.stdout.write(SKILL_HELP);
475
+ return;
476
+ }
477
+ const text = readFileSync(new URL("../skill/SKILL.md", import.meta.url), "utf8");
478
+ const sub = args._[0];
479
+ if (!sub) {
480
+ process.stdout.write(text);
481
+ return;
482
+ }
483
+ if (sub !== "install") {
484
+ process.stderr.write(`unknown skill subcommand '${sub}': use 'agent-om skill' to print or 'agent-om skill install [--global] [--dir <folder>]'\n`);
485
+ process.exitCode = 1;
486
+ return;
487
+ }
488
+ const isGlobal = args.flags.global === true;
489
+ const dirFlag = typeof args.flags.dir === "string" ? args.flags.dir : void 0;
490
+ if (isGlobal && dirFlag) {
491
+ process.stderr.write("use either --global or --dir, not both\n");
492
+ process.exitCode = 1;
493
+ return;
494
+ }
495
+ const base = isGlobal ? homedir() : resolve(dirFlag ?? process.cwd());
496
+ const targets = isGlobal ? [
497
+ join(base, ".agents", "skills", "agent-om", "SKILL.md"),
498
+ join(base, ".claude", "skills", "agent-om", "SKILL.md"),
499
+ join(base, ".config", "opencode", "skills", "agent-om", "SKILL.md")
500
+ ] : [join(base, ".agents", "skills", "agent-om", "SKILL.md"), join(base, ".claude", "skills", "agent-om", "SKILL.md")];
501
+ for (const target of targets) {
502
+ mkdirSync(dirname(target), { recursive: true });
503
+ writeFileSync(target, text);
504
+ }
505
+ process.stdout.write(`${targets.map((t) => `installed ${t}`).join("\n")}\n`);
506
+ return;
507
+ }
508
+ const own = cmd === "help" ? args._[0] : args.flags.help ? cmd : void 0;
509
+ if (own === "skill") {
510
+ process.stdout.write(SKILL_HELP);
511
+ return;
512
+ }
513
+ const ownHelp = own && commandHelp(own);
514
+ if (ownHelp) {
515
+ process.stdout.write(ownHelp);
516
+ return;
517
+ }
518
+ if (cmd === "help" && args._[0] && args._[0] !== "help") {
519
+ if (!Object.hasOwn(TOPICS, args._[0])) {
520
+ process.stderr.write(`no help on '${args._[0]}': agent-om help, agent-om help <command>, or agent-om help ${Object.keys(TOPICS).join(" | ")}\n`);
521
+ process.exitCode = 1;
522
+ return;
523
+ }
524
+ process.stdout.write(TOPICS[args._[0]].text);
525
+ return;
526
+ }
527
+ if (!cmd || cmd === "help" || args.flags.help) {
528
+ process.stdout.write(usage());
529
+ return;
530
+ }
531
+ let name;
532
+ try {
533
+ name = nameOf(args);
534
+ } catch (e) {
535
+ process.stderr.write(`${e.message}\n`);
536
+ process.exitCode = 1;
537
+ return;
538
+ }
412
539
  if (cmd === "__serve") {
413
- const { serve } = await import("./server-BydUJYxP.mjs");
540
+ const { serve } = await import("./server-h-sKRRpx.mjs");
414
541
  const [width, height] = String(args.flags.viewport ?? "1280x900").split("x").map(Number);
415
542
  try {
416
543
  await serve({
@@ -435,29 +562,6 @@ async function main(argv, input = process.stdin) {
435
562
  }
436
563
  return;
437
564
  }
438
- if (cmd === "skill") {
439
- process.stdout.write(readFileSync(new URL("../skill/SKILL.md", import.meta.url), "utf8"));
440
- return;
441
- }
442
- const own = cmd === "help" ? args._[0] : args.flags.help ? cmd : void 0;
443
- const ownHelp = own && commandHelp(own);
444
- if (ownHelp) {
445
- process.stdout.write(ownHelp);
446
- return;
447
- }
448
- if (cmd === "help" && args._[0] && args._[0] !== "help") {
449
- if (!Object.hasOwn(TOPICS, args._[0])) {
450
- process.stderr.write(`no help on '${args._[0]}': agent-om help, agent-om help <command>, or agent-om help ${Object.keys(TOPICS).join(" | ")}\n`);
451
- process.exitCode = 1;
452
- return;
453
- }
454
- process.stdout.write(TOPICS[args._[0]].text);
455
- return;
456
- }
457
- if (!cmd || cmd === "help" || args.flags.help) {
458
- process.stdout.write(usage());
459
- return;
460
- }
461
565
  let reply;
462
566
  if (cmd === "install") reply = install(args.flags["dry-run"] === true);
463
567
  else if (cmd === "doctor") reply = await doctor();
@@ -475,8 +579,12 @@ async function main(argv, input = process.stdin) {
475
579
  ...process.env[variable] !== void 0 ? { [variable]: process.env[variable] } : {},
476
580
  ...site !== void 0 ? { [`${variable}_ORIGIN`]: site } : {}
477
581
  } : void 0;
478
- if (cmd === "save-state" && args._[0]) args._[0] = resolve(args._[0]);
479
- if (cmd === "script" && !args._.length && !process.stdin.isTTY) args._.push(await stdin());
582
+ if ((cmd === "save-state" || cmd === "screenshot") && args._[0]) args._[0] = resolve(args._[0]);
583
+ if (cmd === "upload") {
584
+ const startIdx = typeof args.flags.text === "string" ? 0 : 1;
585
+ for (let i = startIdx; i < args._.length; i++) args._[i] = resolve(args._[i]);
586
+ }
587
+ if (cmd === "script" && !args._.length && (input !== process.stdin || !process.stdin.isTTY)) args._.push(await stdin(input));
480
588
  reply = await send(name, cmd, args, env);
481
589
  if (!reply.ok && reply.error === "no session") {
482
590
  const started = await start(name, args, input);