@agent-om/cli 0.1.1 → 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
@@ -86,6 +86,10 @@ acting (`click`, `fill`, `type`, `select`, `check`, `press`, `scroll`,
86
86
  session attached to your own browser (`--cdp`, `--auto-connect`), where a
87
87
  script would read everything you are signed in to, `eval` is off unless the
88
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.
89
93
 
90
94
  ## For an agent
91
95
 
package/dist/agent-om.mjs CHANGED
@@ -1,8 +1,8 @@
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-Dx2d3ujt.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, writeFileSync } from "node:fs";
5
+ import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
6
6
  import { homedir } from "node:os";
7
7
  import { dirname, join, resolve } from "node:path";
8
8
  import { createInterface } from "node:readline/promises";
@@ -118,8 +118,26 @@ function usage() {
118
118
  ""
119
119
  ].join("\n");
120
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");
121
127
  /** The options of `start`, which a first command may carry for the session it starts. */
122
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
+ ]);
123
141
  /**
124
142
  * The options the table of commands names (opt-in commands too: one turned off is refused by name, not as an
125
143
  * unknown option), each taking a value (`--ref <ref>`, `--text "<what it shows>"`, `--tabs own|active|all`) or a
@@ -132,12 +150,14 @@ const BOOLEAN = /* @__PURE__ */ new Set([
132
150
  "confirm",
133
151
  "accept",
134
152
  "help",
153
+ "version",
135
154
  "global",
136
155
  ...OPTIONS.filter(([, , value]) => !value).map(([, name]) => name)
137
156
  ]);
138
157
  const VALUE = /* @__PURE__ */ new Set([
139
158
  "session",
140
159
  "dir",
160
+ "scope",
141
161
  ...OPTIONS.filter(([, , value]) => value).map(([, name]) => name)
142
162
  ]);
143
163
  /** A command line's command, arguments and options. An option the tool hasn't got, or one missing its value, is refused. */
@@ -165,6 +185,14 @@ function parse(argv) {
165
185
  args.flags.global = true;
166
186
  continue;
167
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
+ }
168
196
  if (!a.startsWith("--")) {
169
197
  word(a);
170
198
  continue;
@@ -182,13 +210,13 @@ function parse(argv) {
182
210
  args
183
211
  };
184
212
  }
185
- /** All of stdin, as text. */
186
- async function stdin() {
213
+ /** All of stdin (or an injected input stream), as text. */
214
+ async function stdin(input = process.stdin) {
187
215
  const chunks = [];
188
- 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);
189
217
  return Buffer.concat(chunks).toString("utf8");
190
218
  }
191
- 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");
192
220
  async function send(name, cmd, args, env) {
193
221
  const s = readSession(name);
194
222
  if (!s) return {
@@ -237,11 +265,15 @@ async function confirmScreenshots(input = process.stdin, output = process.stderr
237
265
  }
238
266
  }
239
267
  async function start(name, args, input = process.stdin, promptOut = process.stderr) {
240
- const running = await send(name, "status", args);
268
+ const running = await send(name, "status", {
269
+ _: [],
270
+ flags: {}
271
+ });
241
272
  if (running.ok) {
242
- 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 {
243
275
  ok: false,
244
- 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(", ")}`
245
277
  };
246
278
  return {
247
279
  ok: true,
@@ -271,11 +303,18 @@ async function start(name, args, input = process.stdin, promptOut = process.stde
271
303
  ok: false,
272
304
  error: `--tabs own, active or all: '${String(tabs)}'`
273
305
  };
274
- if (args.flags["allow-origin"] !== void 0) {
275
- const bad = String(args.flags["allow-origin"]).split(",").find((o) => !/^https?:\/\/[^/\s]+$/.test(o.trim().replace(/\/$/, "")));
276
- 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 {
277
316
  ok: false,
278
- 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}'`
279
318
  };
280
319
  }
281
320
  if (args.flags["allow-screenshot"] === true) {
@@ -289,33 +328,38 @@ async function start(name, args, input = process.stdin, promptOut = process.stde
289
328
  });
290
329
  const logFile = join(dir, "server.log");
291
330
  const from = existsSync(logFile) ? statSync(logFile).size : 0;
292
- const log = openSync(logFile, "a");
293
331
  const bin = process.argv[1] ?? fileURLToPath(new URL("../bin/agent-om.mjs", import.meta.url));
294
332
  const pass = (flag, path = false) => typeof args.flags[flag] === "string" ? [`--${flag}`, path ? resolve(args.flags[flag]) : args.flags[flag]] : [];
295
- const child = spawn(process.execPath, [
296
- bin,
297
- "__serve",
298
- "--session",
299
- name,
300
- "--viewport",
301
- viewport,
302
- ...args.flags.headed ? ["--headed"] : [],
303
- ...pass("state", true),
304
- ...pass("profile", true),
305
- ...pass("executable"),
306
- ...pass("cdp"),
307
- ...pass("tabs"),
308
- ...pass("allow-origin"),
309
- ...args.flags["auto-connect"] ? ["--auto-connect"] : [],
310
- ...args.flags["allow-screenshot"] ? ["--allow-screenshot"] : []
311
- ], {
312
- detached: true,
313
- stdio: [
314
- "ignore",
315
- log,
316
- log
317
- ]
318
- });
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
+ }
319
363
  child.unref();
320
364
  let exited = false;
321
365
  child.once("exit", () => void (exited = true));
@@ -420,41 +464,14 @@ async function main(argv, input = process.stdin) {
420
464
  return;
421
465
  }
422
466
  const { cmd, args } = parsed;
423
- const name = nameOf(args);
424
- if (cmd === "__serve") {
425
- const { serve } = await import("./server-CNRN0if0.mjs");
426
- const [width, height] = String(args.flags.viewport ?? "1280x900").split("x").map(Number);
427
- try {
428
- await serve({
429
- name,
430
- headed: args.flags.headed === true,
431
- viewport: {
432
- width,
433
- height
434
- },
435
- ...typeof args.flags.state === "string" ? { state: args.flags.state } : {},
436
- ...typeof args.flags.profile === "string" ? { profile: args.flags.profile } : {},
437
- ...typeof args.flags.cdp === "string" ? { cdp: args.flags.cdp } : {},
438
- ...args.flags["auto-connect"] === true ? { autoConnect: true } : {},
439
- ...typeof args.flags.tabs === "string" ? { tabs: args.flags.tabs } : {},
440
- ...typeof args.flags["allow-origin"] === "string" ? { allowedOrigins: args.flags["allow-origin"].split(",").map((o) => new URL(o.trim()).origin) } : {},
441
- ...typeof args.flags.executable === "string" ? { executable: args.flags.executable } : {},
442
- ...args.flags["allow-screenshot"] === true ? { allowScreenshot: true } : {}
443
- });
444
- } catch (e) {
445
- process.stderr.write(`${e instanceof Error ? e.message : String(e)}\n`);
446
- process.exit(1);
447
- }
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`);
448
470
  return;
449
471
  }
450
472
  if (cmd === "skill") {
451
473
  if (args.flags.help) {
452
- process.stdout.write([
453
- "agent-om skill print the skill for this version",
454
- "agent-om skill install [--dir <folder>] install into .agents/skills/agent-om/ and .claude/skills/agent-om/",
455
- "agent-om skill install --global (-g) install globally for OpenCode, Claude Code, Codex, and Cursor",
456
- ""
457
- ].join("\n"));
474
+ process.stdout.write(SKILL_HELP);
458
475
  return;
459
476
  }
460
477
  const text = readFileSync(new URL("../skill/SKILL.md", import.meta.url), "utf8");
@@ -489,6 +506,10 @@ async function main(argv, input = process.stdin) {
489
506
  return;
490
507
  }
491
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
+ }
492
513
  const ownHelp = own && commandHelp(own);
493
514
  if (ownHelp) {
494
515
  process.stdout.write(ownHelp);
@@ -507,6 +528,40 @@ async function main(argv, input = process.stdin) {
507
528
  process.stdout.write(usage());
508
529
  return;
509
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
+ }
539
+ if (cmd === "__serve") {
540
+ const { serve } = await import("./server-h-sKRRpx.mjs");
541
+ const [width, height] = String(args.flags.viewport ?? "1280x900").split("x").map(Number);
542
+ try {
543
+ await serve({
544
+ name,
545
+ headed: args.flags.headed === true,
546
+ viewport: {
547
+ width,
548
+ height
549
+ },
550
+ ...typeof args.flags.state === "string" ? { state: args.flags.state } : {},
551
+ ...typeof args.flags.profile === "string" ? { profile: args.flags.profile } : {},
552
+ ...typeof args.flags.cdp === "string" ? { cdp: args.flags.cdp } : {},
553
+ ...args.flags["auto-connect"] === true ? { autoConnect: true } : {},
554
+ ...typeof args.flags.tabs === "string" ? { tabs: args.flags.tabs } : {},
555
+ ...typeof args.flags["allow-origin"] === "string" ? { allowedOrigins: args.flags["allow-origin"].split(",").map((o) => new URL(o.trim()).origin) } : {},
556
+ ...typeof args.flags.executable === "string" ? { executable: args.flags.executable } : {},
557
+ ...args.flags["allow-screenshot"] === true ? { allowScreenshot: true } : {}
558
+ });
559
+ } catch (e) {
560
+ process.stderr.write(`${e instanceof Error ? e.message : String(e)}\n`);
561
+ process.exit(1);
562
+ }
563
+ return;
564
+ }
510
565
  let reply;
511
566
  if (cmd === "install") reply = install(args.flags["dry-run"] === true);
512
567
  else if (cmd === "doctor") reply = await doctor();
@@ -524,8 +579,12 @@ async function main(argv, input = process.stdin) {
524
579
  ...process.env[variable] !== void 0 ? { [variable]: process.env[variable] } : {},
525
580
  ...site !== void 0 ? { [`${variable}_ORIGIN`]: site } : {}
526
581
  } : void 0;
527
- if (cmd === "save-state" && args._[0]) args._[0] = resolve(args._[0]);
528
- 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));
529
588
  reply = await send(name, cmd, args, env);
530
589
  if (!reply.ok && reply.error === "no session") {
531
590
  const started = await start(name, args, input);