@agent-om/cli 0.0.0-stage → 0.1.1
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/LICENSE +64 -0
- package/README.md +112 -2
- package/dist/agent-om.mjs +547 -0
- package/dist/server-CNRN0if0.mjs +4751 -0
- package/dist/session-Dx2d3ujt.mjs +658 -0
- package/package.json +54 -3
- package/skill/SKILL.md +64 -0
|
@@ -0,0 +1,547 @@
|
|
|
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";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
5
|
+
import { existsSync, mkdirSync, openSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { dirname, join, resolve } from "node:path";
|
|
8
|
+
import { createInterface } from "node:readline/promises";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
// src/topics.ts
|
|
11
|
+
const TOPICS = {
|
|
12
|
+
session: {
|
|
13
|
+
about: "staying signed in, the user's own browser, tabs, downloads, the sites a session may open",
|
|
14
|
+
text: `agent-om help session
|
|
15
|
+
|
|
16
|
+
Staying signed in. A session's sign-in ends with it. To keep one,
|
|
17
|
+
agent-om save-state <file.json> saves what is signed in to a file only the user can read
|
|
18
|
+
agent-om start --state <file.json> starts signed in the same
|
|
19
|
+
agent-om start --profile <folder> keeps a browser profile in that folder from one session to the next
|
|
20
|
+
The file and the folder hold the user's sign-ins: never print them or send them anywhere. In the user's own browser
|
|
21
|
+
(a session started with --cdp or --auto-connect) there is nothing to save: it keeps its own sign-ins, and save-state
|
|
22
|
+
refuses.
|
|
23
|
+
|
|
24
|
+
The user's own browser. agent-om start --auto-connect (or --cdp <port>) works in a browser the user already has open,
|
|
25
|
+
with their sign-ins, when the user asks for that. Chrome asks the user to allow it each time a session starts: tell
|
|
26
|
+
them to expect that, and to click Allow. How much of it you may touch is the user's to say, with --tabs: own (the
|
|
27
|
+
default) is only the tabs you open and those they open; active also the tab in front; all every tab. Use only the
|
|
28
|
+
level the user gave: never start again with a wider one yourself. stop closes your tabs and leaves their browser open.
|
|
29
|
+
|
|
30
|
+
Tabs. agent-om tabs lists the tabs this session's pages opened; agent-om switch-tab <n> works in another. When an
|
|
31
|
+
action opens a tab (a sign-in window, a link to a new tab), you are in it after that action, and read it whole. When
|
|
32
|
+
it closes itself (a sign-in window does, once you've signed in), you are back in the tab that opened it, and read
|
|
33
|
+
what changed there.
|
|
34
|
+
|
|
35
|
+
Downloads. A file the page downloads (an export, a report) is saved in the session's folder, and the action says its
|
|
36
|
+
name, size and path: read it from there.
|
|
37
|
+
|
|
38
|
+
Sites. When the user started the session with --allow-origin, a page load to any other site is stopped, and the
|
|
39
|
+
action says so: stay on those sites.
|
|
40
|
+
`
|
|
41
|
+
},
|
|
42
|
+
trouble: {
|
|
43
|
+
about: "the tool doesn't start, a page stops answering, something fails without saying why",
|
|
44
|
+
text: `agent-om help trouble
|
|
45
|
+
|
|
46
|
+
The tool doesn't start. agent-om doctor checks what the tool needs and says what to do about anything missing;
|
|
47
|
+
agent-om install downloads its browser.
|
|
48
|
+
|
|
49
|
+
A page stops answering (a script on it never ends). It is given up after a while: its tab is closed, a new one takes
|
|
50
|
+
its place, and the answer says how to load the page again.
|
|
51
|
+
|
|
52
|
+
Something didn't happen, and the page doesn't say why. agent-om console shows what the page logged since you last
|
|
53
|
+
asked (its errors too; --errors for only those and warnings), and agent-om network the requests it made (--failed
|
|
54
|
+
for those that failed or answered an error), each address without its query. Use them to find out why something
|
|
55
|
+
didn't happen, not instead of reading the page.
|
|
56
|
+
`
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
// src/main.ts
|
|
60
|
+
/** The opt-in commands currently on in this environment: eval (unless AGENT_OM_ALLOW_EVAL=0) and screenshot (only when AGENT_OM_ALLOW_SCREENSHOT=1). */
|
|
61
|
+
const turnedOn = () => [...evalOn(process.env) ? ["eval"] : [], ...screenshotOn(process.env) ? ["screenshot"] : []];
|
|
62
|
+
const wrap = (text, indent, width = 120) => {
|
|
63
|
+
const lines = [];
|
|
64
|
+
let line = "";
|
|
65
|
+
for (const word of text.split(" ")) if (line && indent + line.length + 1 + word.length > width) {
|
|
66
|
+
lines.push(line);
|
|
67
|
+
line = word;
|
|
68
|
+
} else line = line ? `${line} ${word}` : word;
|
|
69
|
+
if (line) lines.push(line);
|
|
70
|
+
return lines.join("\n" + " ".repeat(indent));
|
|
71
|
+
};
|
|
72
|
+
const COL = 39;
|
|
73
|
+
/** One command's help: how it's written, what it does, and its options. */
|
|
74
|
+
const entry = (c) => {
|
|
75
|
+
const head = ` ${[c.name, ...c.args.map((a) => a.cli)].join(" ")}`;
|
|
76
|
+
const options = c.args.filter((a) => a.cli.includes("-") || a.cli.startsWith("[")).filter((a) => a.about);
|
|
77
|
+
const about = [c.about, ...options.map((a) => `${a.cli.replace(/[[\]]/g, "").split(" ")[0]}: ${a.about}`)].join("; ");
|
|
78
|
+
return head.length + 2 <= COL ? head.padEnd(COL) + wrap(about, COL) : `${head}\n${" ".repeat(COL)}${wrap(about, COL)}`;
|
|
79
|
+
};
|
|
80
|
+
/** A command's own help (help <command>, <command> --help); an opt-in command that is off says so. */
|
|
81
|
+
function commandHelp(name) {
|
|
82
|
+
const c = commandsFor("cli", ["eval", "screenshot"]).find((x) => x.name === name);
|
|
83
|
+
if (!c) return void 0;
|
|
84
|
+
if (c.optIn && !turnedOn().includes(name)) {
|
|
85
|
+
if (name === "screenshot") return `screenshot is off by default: Agent OM works from text projection without screenshots. Start a session with --allow-screenshot (and confirm the warning) or set ${ALLOW_SCREENSHOT}=1 to enable it.\n`;
|
|
86
|
+
return `${name} is off in this session: the user turned it off (${ALLOW_EVAL}=0 where the session starts)\n`;
|
|
87
|
+
}
|
|
88
|
+
return `${entry(c)}\n`;
|
|
89
|
+
}
|
|
90
|
+
usage();
|
|
91
|
+
function usage() {
|
|
92
|
+
const on = turnedOn();
|
|
93
|
+
const commands = commandsFor("cli", on);
|
|
94
|
+
const section = (group) => commands.filter((c) => c.group === group).map(entry).join("\n");
|
|
95
|
+
return [
|
|
96
|
+
"agent-om <command> [arguments] [--session <name>]",
|
|
97
|
+
"",
|
|
98
|
+
"Reading",
|
|
99
|
+
section("read"),
|
|
100
|
+
"",
|
|
101
|
+
`Acting (a ref from the page, or ${LOCATOR_ARGS.map((a) => a.cli).join(" ")} for something with no ref);`,
|
|
102
|
+
"each prints what it did and what changed on the page",
|
|
103
|
+
section("act"),
|
|
104
|
+
"",
|
|
105
|
+
" --confirm take an action the page says must be confirmed (only when the user's request asks for it)",
|
|
106
|
+
" --accept accept the browser's own confirm dialog if the action opens one",
|
|
107
|
+
"",
|
|
108
|
+
"Session",
|
|
109
|
+
section("session"),
|
|
110
|
+
"",
|
|
111
|
+
"Help",
|
|
112
|
+
" help this text",
|
|
113
|
+
...Object.entries(TOPICS).map(([name, t]) => ` ${`help ${name}`.padEnd(37)}${t.about}`),
|
|
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)",
|
|
118
|
+
""
|
|
119
|
+
].join("\n");
|
|
120
|
+
}
|
|
121
|
+
/** The options of `start`, which a first command may carry for the session it starts. */
|
|
122
|
+
const START_OPTIONS = commandsFor("cli").find((c) => c.name === "start").args.flatMap((a) => [...a.cli.matchAll(/--([a-z-]+)/g)].map(([, name]) => name));
|
|
123
|
+
/**
|
|
124
|
+
* The options the table of commands names (opt-in commands too: one turned off is refused by name, not as an
|
|
125
|
+
* unknown option), each taking a value (`--ref <ref>`, `--text "<what it shows>"`, `--tabs own|active|all`) or a
|
|
126
|
+
* switch (`--exact`, `--up|--down`); with those every command takes (`--session`, `--help`) and a few more.
|
|
127
|
+
*/
|
|
128
|
+
const OPTIONS = [...commandsFor("cli", ["eval", "screenshot"]).flatMap((c) => c.args), ...LOCATOR_ARGS].flatMap((a) => [...a.cli.matchAll(/--([a-z-]+)(?:[ =]([<"][^>"]*[>"]|[a-z]+(?:\|[a-z]+)+))?/g)]);
|
|
129
|
+
const BOOLEAN = /* @__PURE__ */ new Set([
|
|
130
|
+
"interactive",
|
|
131
|
+
"i",
|
|
132
|
+
"confirm",
|
|
133
|
+
"accept",
|
|
134
|
+
"help",
|
|
135
|
+
"global",
|
|
136
|
+
...OPTIONS.filter(([, , value]) => !value).map(([, name]) => name)
|
|
137
|
+
]);
|
|
138
|
+
const VALUE = /* @__PURE__ */ new Set([
|
|
139
|
+
"session",
|
|
140
|
+
"dir",
|
|
141
|
+
...OPTIONS.filter(([, , value]) => value).map(([, name]) => name)
|
|
142
|
+
]);
|
|
143
|
+
/** A command line's command, arguments and options. An option the tool hasn't got, or one missing its value, is refused. */
|
|
144
|
+
function parse(argv) {
|
|
145
|
+
const args = {
|
|
146
|
+
_: [],
|
|
147
|
+
flags: {}
|
|
148
|
+
};
|
|
149
|
+
let cmd;
|
|
150
|
+
const word = (a) => {
|
|
151
|
+
if (cmd === void 0) cmd = a;
|
|
152
|
+
else args._.push(a);
|
|
153
|
+
};
|
|
154
|
+
for (let i = 0; i < argv.length; i++) {
|
|
155
|
+
const a = argv[i];
|
|
156
|
+
if (a === "--") {
|
|
157
|
+
argv.slice(i + 1).forEach(word);
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
if (a === "-i") {
|
|
161
|
+
args.flags.interactive = true;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (a === "-g") {
|
|
165
|
+
args.flags.global = true;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (!a.startsWith("--")) {
|
|
169
|
+
word(a);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const name = a.slice(2);
|
|
173
|
+
if (BOOLEAN.has(name)) args.flags[name] = true;
|
|
174
|
+
else if (VALUE.has(name)) {
|
|
175
|
+
const value = argv[++i];
|
|
176
|
+
if (value === void 0) throw new UsageError(`${a} needs a value (agent-om help)`);
|
|
177
|
+
args.flags[name] = value;
|
|
178
|
+
} else throw new UsageError(`no option ${a} (agent-om help); text that starts with -- goes after a -- of its own`);
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
cmd,
|
|
182
|
+
args
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/** All of stdin, as text. */
|
|
186
|
+
async function stdin() {
|
|
187
|
+
const chunks = [];
|
|
188
|
+
for await (const c of process.stdin) chunks.push(c);
|
|
189
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
190
|
+
}
|
|
191
|
+
const nameOf = (args) => typeof args.flags.session === "string" && args.flags.session || process.env.AGENT_OM_SESSION || "default";
|
|
192
|
+
async function send(name, cmd, args, env) {
|
|
193
|
+
const s = readSession(name);
|
|
194
|
+
if (!s) return {
|
|
195
|
+
ok: false,
|
|
196
|
+
error: "no session"
|
|
197
|
+
};
|
|
198
|
+
const body = {
|
|
199
|
+
token: s.token,
|
|
200
|
+
cmd,
|
|
201
|
+
args,
|
|
202
|
+
...env ? { env } : {}
|
|
203
|
+
};
|
|
204
|
+
try {
|
|
205
|
+
return await (await fetch(`http://127.0.0.1:${s.port}/`, {
|
|
206
|
+
method: "POST",
|
|
207
|
+
body: JSON.stringify(body)
|
|
208
|
+
})).json();
|
|
209
|
+
} catch {
|
|
210
|
+
return {
|
|
211
|
+
ok: false,
|
|
212
|
+
error: "no session"
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/** Ask the user to confirm enabling screenshots after showing the warning. */
|
|
217
|
+
async function confirmScreenshots(input = process.stdin, output = process.stderr) {
|
|
218
|
+
if (input === process.stdin && !process.stdin.isTTY) return {
|
|
219
|
+
ok: false,
|
|
220
|
+
error: `${SCREENSHOT_WARNING}\n\nCannot prompt for confirmation in a non-interactive terminal. Re-run interactively to confirm, or set ${ALLOW_SCREENSHOT}=1 to explicitly enable screenshots.`
|
|
221
|
+
};
|
|
222
|
+
output.write(`${SCREENSHOT_WARNING}\n\n`);
|
|
223
|
+
const rl = createInterface({
|
|
224
|
+
input,
|
|
225
|
+
output,
|
|
226
|
+
terminal: false
|
|
227
|
+
});
|
|
228
|
+
try {
|
|
229
|
+
const answer = (await rl.question("Enable screenshots for this session? [y/N]: ").catch(() => "")).trim().toLowerCase();
|
|
230
|
+
if (answer === "y" || answer === "yes") return { ok: true };
|
|
231
|
+
return {
|
|
232
|
+
ok: false,
|
|
233
|
+
error: "Cancelled: screenshots remain off."
|
|
234
|
+
};
|
|
235
|
+
} finally {
|
|
236
|
+
rl.close();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async function start(name, args, input = process.stdin, promptOut = process.stderr) {
|
|
240
|
+
const running = await send(name, "status", args);
|
|
241
|
+
if (running.ok) {
|
|
242
|
+
if (args.flags["allow-screenshot"] === true) return {
|
|
243
|
+
ok: false,
|
|
244
|
+
error: "a session is already running: run agent-om stop first, then start with --allow-screenshot"
|
|
245
|
+
};
|
|
246
|
+
return {
|
|
247
|
+
ok: true,
|
|
248
|
+
out: `already running: ${running.out}`
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
const viewport = typeof args.flags.viewport === "string" ? args.flags.viewport : "1280x900";
|
|
252
|
+
if (!/^\d{2,5}x\d{2,5}$/.test(viewport)) return {
|
|
253
|
+
ok: false,
|
|
254
|
+
error: `--viewport <width>x<height>, in pixels (1280x900): '${viewport}'`
|
|
255
|
+
};
|
|
256
|
+
if (typeof args.flags.state === "string" && typeof args.flags.profile === "string") return {
|
|
257
|
+
ok: false,
|
|
258
|
+
error: "--state or --profile, not both: a profile keeps its own sign-ins"
|
|
259
|
+
};
|
|
260
|
+
const attach = typeof args.flags.cdp === "string" || args.flags["auto-connect"] === true;
|
|
261
|
+
if (attach && (args.flags.state !== void 0 || args.flags.profile !== void 0 || args.flags.executable !== void 0 || args.flags.headed !== void 0)) return {
|
|
262
|
+
ok: false,
|
|
263
|
+
error: "--cdp and --auto-connect attach to a browser that is running, with its own sign-ins and window: not with --state, --profile, --executable or --headed"
|
|
264
|
+
};
|
|
265
|
+
const tabs = args.flags.tabs;
|
|
266
|
+
if (tabs !== void 0 && !attach) return {
|
|
267
|
+
ok: false,
|
|
268
|
+
error: "--tabs is for a browser attached to (--cdp or --auto-connect): a browser of its own is all the agent's"
|
|
269
|
+
};
|
|
270
|
+
if (tabs !== void 0 && !TAB_LEVELS.includes(tabs)) return {
|
|
271
|
+
ok: false,
|
|
272
|
+
error: `--tabs own, active or all: '${String(tabs)}'`
|
|
273
|
+
};
|
|
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 {
|
|
277
|
+
ok: false,
|
|
278
|
+
error: `--allow-origin takes sites as https://example.com, separated by commas: '${bad}'`
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
if (args.flags["allow-screenshot"] === true) {
|
|
282
|
+
const confirmed = await confirmScreenshots(input, promptOut);
|
|
283
|
+
if (!confirmed.ok) return confirmed;
|
|
284
|
+
}
|
|
285
|
+
const dir = sessionDir(name);
|
|
286
|
+
mkdirSync(dir, {
|
|
287
|
+
recursive: true,
|
|
288
|
+
mode: 448
|
|
289
|
+
});
|
|
290
|
+
const logFile = join(dir, "server.log");
|
|
291
|
+
const from = existsSync(logFile) ? statSync(logFile).size : 0;
|
|
292
|
+
const log = openSync(logFile, "a");
|
|
293
|
+
const bin = process.argv[1] ?? fileURLToPath(new URL("../bin/agent-om.mjs", import.meta.url));
|
|
294
|
+
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
|
+
});
|
|
319
|
+
child.unref();
|
|
320
|
+
let exited = false;
|
|
321
|
+
child.once("exit", () => void (exited = true));
|
|
322
|
+
const deadline = Date.now() + (attach ? ATTACH_MS + 5e3 : 3e4);
|
|
323
|
+
while (Date.now() < deadline && !exited) {
|
|
324
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
325
|
+
const s = readSession(name);
|
|
326
|
+
if (s && s.pid === child.pid) {
|
|
327
|
+
const status = await send(name, "status", args);
|
|
328
|
+
if (status.ok) return {
|
|
329
|
+
ok: true,
|
|
330
|
+
out: `started: ${status.out}`
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const other = await send(name, "status", args);
|
|
335
|
+
if (other.ok) return {
|
|
336
|
+
ok: true,
|
|
337
|
+
out: `already running: ${other.out}`
|
|
338
|
+
};
|
|
339
|
+
const said = existsSync(logFile) ? readFileSync(logFile).subarray(from).toString("utf8").trim() : "";
|
|
340
|
+
return {
|
|
341
|
+
ok: false,
|
|
342
|
+
error: `the session didn't start${said ? `:\n${said}` : ""}\n(its log: ${logFile})`
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
const require = createRequire(import.meta.url);
|
|
346
|
+
/** Playwright's own command, from the version this one is tested with. */
|
|
347
|
+
const playwrightCli = () => join(dirname(require.resolve("playwright/package.json")), "cli.js");
|
|
348
|
+
/** Download the browser this version is tested with: Playwright's Chromium, for its version. */
|
|
349
|
+
function install(dryRun) {
|
|
350
|
+
const r = spawnSync(process.execPath, [
|
|
351
|
+
playwrightCli(),
|
|
352
|
+
"install",
|
|
353
|
+
"chromium",
|
|
354
|
+
...dryRun ? ["--dry-run"] : []
|
|
355
|
+
], { stdio: "inherit" });
|
|
356
|
+
if (dryRun) return r.status === 0 ? {
|
|
357
|
+
ok: true,
|
|
358
|
+
out: "nothing was downloaded (--dry-run)"
|
|
359
|
+
} : {
|
|
360
|
+
ok: false,
|
|
361
|
+
error: "Playwright's installer failed (it said why, above)"
|
|
362
|
+
};
|
|
363
|
+
return r.status === 0 ? {
|
|
364
|
+
ok: true,
|
|
365
|
+
out: "the browser is installed: agent-om open <address> starts it"
|
|
366
|
+
} : {
|
|
367
|
+
ok: false,
|
|
368
|
+
error: `the browser didn't install (Playwright's installer said why, above)`
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
/** What the tool needs, checked one by one: each line says it's there, or what to do. */
|
|
372
|
+
async function doctor() {
|
|
373
|
+
const lines = [];
|
|
374
|
+
let bad = false;
|
|
375
|
+
const ok = (line) => lines.push(`ok ${line}`);
|
|
376
|
+
const no = (line) => {
|
|
377
|
+
bad = true;
|
|
378
|
+
lines.push(`no ${line}`);
|
|
379
|
+
};
|
|
380
|
+
const [major] = process.versions.node.split(".").map(Number);
|
|
381
|
+
if (major >= 22) ok(`Node ${process.versions.node}`);
|
|
382
|
+
else no(`Node ${process.versions.node}: this tool needs Node 22 or later`);
|
|
383
|
+
const { chromium } = await import("playwright");
|
|
384
|
+
const version = require("playwright/package.json").version;
|
|
385
|
+
const browser = chromium.executablePath();
|
|
386
|
+
if (existsSync(browser)) {
|
|
387
|
+
ok(`Playwright ${version}, with its Chromium at ${browser}`);
|
|
388
|
+
const started = await chromium.launch().then(async (b) => (await b.close(), void 0), (e) => e.message.split("\n")[0]);
|
|
389
|
+
if (started) no(`the browser doesn't start: ${started}`);
|
|
390
|
+
else ok("the browser starts");
|
|
391
|
+
} else no(`Playwright ${version}'s Chromium isn't installed: agent-om install`);
|
|
392
|
+
const home = sessionsHome();
|
|
393
|
+
const running = [];
|
|
394
|
+
for (const name of existsSync(home) ? readdirSync(home) : []) if (readSession(name) && (await send(name, "status", {
|
|
395
|
+
_: [],
|
|
396
|
+
flags: {}
|
|
397
|
+
})).ok) running.push(name);
|
|
398
|
+
ok(running.length ? `sessions running: ${running.join(", ")} (in ${home})` : `no session running (they are kept in ${home})`);
|
|
399
|
+
const found = discover();
|
|
400
|
+
lines.push(found.length ? `ok a browser with remote debugging on, for --auto-connect: ${found.length === 1 ? "one" : found.length}` : "-- no running browser with remote debugging on (only --auto-connect needs one: Chrome 144 or later, at chrome://inspect/#remote-debugging)");
|
|
401
|
+
return bad ? {
|
|
402
|
+
ok: false,
|
|
403
|
+
error: lines.join("\n")
|
|
404
|
+
} : {
|
|
405
|
+
ok: true,
|
|
406
|
+
out: lines.join("\n")
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
async function main(argv, input = process.stdin) {
|
|
410
|
+
process.stdout.on("error", (e) => {
|
|
411
|
+
if (e.code === "EPIPE") process.exit(0);
|
|
412
|
+
throw e;
|
|
413
|
+
});
|
|
414
|
+
let parsed;
|
|
415
|
+
try {
|
|
416
|
+
parsed = parse(argv);
|
|
417
|
+
} catch (e) {
|
|
418
|
+
process.stderr.write(`${e.message}\n`);
|
|
419
|
+
process.exitCode = 1;
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
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
|
+
}
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (cmd === "skill") {
|
|
451
|
+
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"));
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
const text = readFileSync(new URL("../skill/SKILL.md", import.meta.url), "utf8");
|
|
461
|
+
const sub = args._[0];
|
|
462
|
+
if (!sub) {
|
|
463
|
+
process.stdout.write(text);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
if (sub !== "install") {
|
|
467
|
+
process.stderr.write(`unknown skill subcommand '${sub}': use 'agent-om skill' to print or 'agent-om skill install [--global] [--dir <folder>]'\n`);
|
|
468
|
+
process.exitCode = 1;
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
const isGlobal = args.flags.global === true;
|
|
472
|
+
const dirFlag = typeof args.flags.dir === "string" ? args.flags.dir : void 0;
|
|
473
|
+
if (isGlobal && dirFlag) {
|
|
474
|
+
process.stderr.write("use either --global or --dir, not both\n");
|
|
475
|
+
process.exitCode = 1;
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
const base = isGlobal ? homedir() : resolve(dirFlag ?? process.cwd());
|
|
479
|
+
const targets = isGlobal ? [
|
|
480
|
+
join(base, ".agents", "skills", "agent-om", "SKILL.md"),
|
|
481
|
+
join(base, ".claude", "skills", "agent-om", "SKILL.md"),
|
|
482
|
+
join(base, ".config", "opencode", "skills", "agent-om", "SKILL.md")
|
|
483
|
+
] : [join(base, ".agents", "skills", "agent-om", "SKILL.md"), join(base, ".claude", "skills", "agent-om", "SKILL.md")];
|
|
484
|
+
for (const target of targets) {
|
|
485
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
486
|
+
writeFileSync(target, text);
|
|
487
|
+
}
|
|
488
|
+
process.stdout.write(`${targets.map((t) => `installed ${t}`).join("\n")}\n`);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
const own = cmd === "help" ? args._[0] : args.flags.help ? cmd : void 0;
|
|
492
|
+
const ownHelp = own && commandHelp(own);
|
|
493
|
+
if (ownHelp) {
|
|
494
|
+
process.stdout.write(ownHelp);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (cmd === "help" && args._[0] && args._[0] !== "help") {
|
|
498
|
+
if (!Object.hasOwn(TOPICS, args._[0])) {
|
|
499
|
+
process.stderr.write(`no help on '${args._[0]}': agent-om help, agent-om help <command>, or agent-om help ${Object.keys(TOPICS).join(" | ")}\n`);
|
|
500
|
+
process.exitCode = 1;
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
process.stdout.write(TOPICS[args._[0]].text);
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
if (!cmd || cmd === "help" || args.flags.help) {
|
|
507
|
+
process.stdout.write(usage());
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
let reply;
|
|
511
|
+
if (cmd === "install") reply = install(args.flags["dry-run"] === true);
|
|
512
|
+
else if (cmd === "doctor") reply = await doctor();
|
|
513
|
+
else if (cmd === "start") reply = await start(name, args, input);
|
|
514
|
+
else if (cmd === "stop" || cmd === "status") {
|
|
515
|
+
reply = await send(name, cmd, args);
|
|
516
|
+
if (!reply.ok && reply.error === "no session") reply = {
|
|
517
|
+
ok: true,
|
|
518
|
+
out: "no session running"
|
|
519
|
+
};
|
|
520
|
+
} else {
|
|
521
|
+
const variable = cmd === "fill-secret" ? typeof args.flags.text === "string" ? args._[0] : args._[1] : void 0;
|
|
522
|
+
const site = variable ? process.env[`${variable}_ORIGIN`] : void 0;
|
|
523
|
+
const env = variable ? {
|
|
524
|
+
...process.env[variable] !== void 0 ? { [variable]: process.env[variable] } : {},
|
|
525
|
+
...site !== void 0 ? { [`${variable}_ORIGIN`]: site } : {}
|
|
526
|
+
} : 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());
|
|
529
|
+
reply = await send(name, cmd, args, env);
|
|
530
|
+
if (!reply.ok && reply.error === "no session") {
|
|
531
|
+
const started = await start(name, args, input);
|
|
532
|
+
if (!started.ok) reply = started;
|
|
533
|
+
else {
|
|
534
|
+
for (const option of START_OPTIONS) delete args.flags[option];
|
|
535
|
+
reply = await send(name, cmd, args, env);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
if (reply.ok) process.stdout.write(`${reply.out}\n`);
|
|
540
|
+
else {
|
|
541
|
+
process.stderr.write(`${reply.error}\n`);
|
|
542
|
+
process.exitCode = 1;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
// src/bin.ts
|
|
546
|
+
await main(process.argv.slice(2));
|
|
547
|
+
export {};
|