@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,658 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
// ../core/src/view/commands.ts
|
|
5
|
+
const BOTH = ["cli", "page"];
|
|
6
|
+
const ref = (about = "the element, by its ref") => ({
|
|
7
|
+
name: "ref",
|
|
8
|
+
kind: "ref",
|
|
9
|
+
required: true,
|
|
10
|
+
cli: "<ref>",
|
|
11
|
+
about
|
|
12
|
+
});
|
|
13
|
+
/** What narrows a page as it's printed: snapshot's, and open's for the page it loads. */
|
|
14
|
+
const NARROW = [
|
|
15
|
+
{
|
|
16
|
+
name: "depth",
|
|
17
|
+
kind: "number",
|
|
18
|
+
cli: "[--depth <n>]",
|
|
19
|
+
about: "how many levels below the top, or the part"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "interactive",
|
|
23
|
+
kind: "flag",
|
|
24
|
+
cli: "[-i]",
|
|
25
|
+
about: "only what can be acted on"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "match",
|
|
29
|
+
kind: "texts",
|
|
30
|
+
cli: "[--match <word,word>]",
|
|
31
|
+
about: "only lines with any of the words"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "limit",
|
|
35
|
+
kind: "number",
|
|
36
|
+
cli: "[--limit <n>]",
|
|
37
|
+
about: "how many alike items before the rest are cut; 0: none cut"
|
|
38
|
+
}
|
|
39
|
+
];
|
|
40
|
+
const COMMANDS = [
|
|
41
|
+
{
|
|
42
|
+
name: "open",
|
|
43
|
+
group: "read",
|
|
44
|
+
where: BOTH,
|
|
45
|
+
about: "load a page by its address (or its path on this site); prints the page, narrowed as snapshot narrows it",
|
|
46
|
+
args: [{
|
|
47
|
+
name: "address",
|
|
48
|
+
kind: "text",
|
|
49
|
+
required: true,
|
|
50
|
+
cli: "<address or path>",
|
|
51
|
+
about: "the address, or a path on this site"
|
|
52
|
+
}, ...NARROW]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "snapshot",
|
|
56
|
+
group: "read",
|
|
57
|
+
where: BOTH,
|
|
58
|
+
about: "the page as one tree, a ref on what can be acted on",
|
|
59
|
+
args: [{
|
|
60
|
+
name: "ref",
|
|
61
|
+
kind: "ref",
|
|
62
|
+
cli: "[<ref>]",
|
|
63
|
+
about: "only that part of the page"
|
|
64
|
+
}, ...NARROW]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "changes",
|
|
68
|
+
group: "read",
|
|
69
|
+
where: BOTH,
|
|
70
|
+
about: "what changed since the page was last read",
|
|
71
|
+
args: []
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "inspect",
|
|
75
|
+
group: "read",
|
|
76
|
+
where: BOTH,
|
|
77
|
+
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
|
+
args: [ref(), {
|
|
79
|
+
name: "parent",
|
|
80
|
+
kind: "number",
|
|
81
|
+
cli: "[--parent <n>]",
|
|
82
|
+
about: "what holds it instead, n levels out"
|
|
83
|
+
}]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "url",
|
|
87
|
+
group: "read",
|
|
88
|
+
where: ["cli"],
|
|
89
|
+
about: "the page's address",
|
|
90
|
+
args: []
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "tabs",
|
|
94
|
+
group: "read",
|
|
95
|
+
where: ["cli"],
|
|
96
|
+
about: "this session's tabs: the first, and those its pages opened (a popup, a link to a new tab)",
|
|
97
|
+
args: []
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "console",
|
|
101
|
+
group: "read",
|
|
102
|
+
where: ["cli"],
|
|
103
|
+
about: "what the page logged in its console since you last asked (its errors too)",
|
|
104
|
+
args: [{
|
|
105
|
+
name: "errors",
|
|
106
|
+
kind: "flag",
|
|
107
|
+
cli: "[--errors]",
|
|
108
|
+
about: "only errors and warnings"
|
|
109
|
+
}]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "network",
|
|
113
|
+
group: "read",
|
|
114
|
+
where: ["cli"],
|
|
115
|
+
about: "the requests the page made since you last asked: method, status, address (without its query), kind",
|
|
116
|
+
args: [{
|
|
117
|
+
name: "failed",
|
|
118
|
+
kind: "flag",
|
|
119
|
+
cli: "[--failed]",
|
|
120
|
+
about: "only those that failed or answered an error"
|
|
121
|
+
}]
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "switch-tab",
|
|
125
|
+
group: "act",
|
|
126
|
+
where: ["cli"],
|
|
127
|
+
about: "work in another of these tabs; prints its page",
|
|
128
|
+
args: [{
|
|
129
|
+
name: "tab",
|
|
130
|
+
kind: "number",
|
|
131
|
+
required: true,
|
|
132
|
+
cli: "<n>",
|
|
133
|
+
about: "the tab, by its number in tabs"
|
|
134
|
+
}]
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: "click",
|
|
138
|
+
group: "act",
|
|
139
|
+
where: BOTH,
|
|
140
|
+
locates: true,
|
|
141
|
+
about: "click it",
|
|
142
|
+
args: [ref()]
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: "dblclick",
|
|
146
|
+
group: "act",
|
|
147
|
+
where: ["cli"],
|
|
148
|
+
locates: true,
|
|
149
|
+
about: "double-click it",
|
|
150
|
+
args: [ref()]
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: "hover",
|
|
154
|
+
group: "act",
|
|
155
|
+
where: BOTH,
|
|
156
|
+
locates: true,
|
|
157
|
+
about: "move the pointer onto it, to show what shows only on hover",
|
|
158
|
+
args: [ref()]
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
name: "fill",
|
|
162
|
+
group: "act",
|
|
163
|
+
where: BOTH,
|
|
164
|
+
locates: true,
|
|
165
|
+
about: "replace what a field holds (a text field, or one edited in place)",
|
|
166
|
+
args: [ref("the field, by its ref"), {
|
|
167
|
+
name: "value",
|
|
168
|
+
kind: "text",
|
|
169
|
+
required: true,
|
|
170
|
+
cli: "<text>",
|
|
171
|
+
about: "what it should hold"
|
|
172
|
+
}]
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: "type",
|
|
176
|
+
group: "act",
|
|
177
|
+
where: BOTH,
|
|
178
|
+
locates: true,
|
|
179
|
+
about: "type into it, after what it holds",
|
|
180
|
+
args: [ref("the field, by its ref"), {
|
|
181
|
+
name: "value",
|
|
182
|
+
kind: "text",
|
|
183
|
+
required: true,
|
|
184
|
+
cli: "<text>",
|
|
185
|
+
about: "what to type"
|
|
186
|
+
}]
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: "select",
|
|
190
|
+
group: "act",
|
|
191
|
+
where: BOTH,
|
|
192
|
+
locates: true,
|
|
193
|
+
about: "choose in a drop-down, by what the choice says",
|
|
194
|
+
args: [ref("the drop-down, by its ref"), {
|
|
195
|
+
name: "choices",
|
|
196
|
+
kind: "texts",
|
|
197
|
+
required: true,
|
|
198
|
+
cli: "<choice…>",
|
|
199
|
+
about: "what the choices say (several for a list that takes several)"
|
|
200
|
+
}]
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: "check",
|
|
204
|
+
group: "act",
|
|
205
|
+
where: BOTH,
|
|
206
|
+
locates: true,
|
|
207
|
+
about: "tick a box or turn a switch on (nothing if it is already)",
|
|
208
|
+
args: [ref()]
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
name: "uncheck",
|
|
212
|
+
group: "act",
|
|
213
|
+
where: BOTH,
|
|
214
|
+
locates: true,
|
|
215
|
+
about: "untick a box or turn a switch off (nothing if it is already)",
|
|
216
|
+
args: [ref()]
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
name: "press",
|
|
220
|
+
group: "act",
|
|
221
|
+
where: BOTH,
|
|
222
|
+
about: "press a key, on an element or wherever the focus is",
|
|
223
|
+
args: [{
|
|
224
|
+
name: "ref",
|
|
225
|
+
kind: "ref",
|
|
226
|
+
cli: "[<ref>]",
|
|
227
|
+
about: "the element to press it on"
|
|
228
|
+
}, {
|
|
229
|
+
name: "key",
|
|
230
|
+
kind: "key",
|
|
231
|
+
required: true,
|
|
232
|
+
cli: "<key>",
|
|
233
|
+
about: "Enter, Escape, Tab, ArrowDown, Control+A…"
|
|
234
|
+
}]
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: "scroll",
|
|
238
|
+
group: "act",
|
|
239
|
+
where: BOTH,
|
|
240
|
+
about: "scroll the page; or bring an element into view; with a direction, scroll inside it",
|
|
241
|
+
args: [
|
|
242
|
+
{
|
|
243
|
+
name: "ref",
|
|
244
|
+
kind: "ref",
|
|
245
|
+
cli: "[<ref>]",
|
|
246
|
+
about: "the element to bring into view, or to scroll inside"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: "direction",
|
|
250
|
+
kind: "text",
|
|
251
|
+
cli: "[--up|--down]",
|
|
252
|
+
values: ["up", "down"],
|
|
253
|
+
about: "which way"
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: "by",
|
|
257
|
+
kind: "number",
|
|
258
|
+
cli: "[--by <px>]",
|
|
259
|
+
about: "how far, in pixels"
|
|
260
|
+
}
|
|
261
|
+
]
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: "upload",
|
|
265
|
+
group: "act",
|
|
266
|
+
where: ["cli"],
|
|
267
|
+
about: "give a file field files",
|
|
268
|
+
args: [ref("the file field, by its ref"), {
|
|
269
|
+
name: "files",
|
|
270
|
+
kind: "texts",
|
|
271
|
+
required: true,
|
|
272
|
+
cli: "<file…>",
|
|
273
|
+
about: "the files"
|
|
274
|
+
}]
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
name: "fill-secret",
|
|
278
|
+
group: "act",
|
|
279
|
+
where: BOTH,
|
|
280
|
+
about: "fill a field that takes a secret (a password, a key) with what the user gives, never shown",
|
|
281
|
+
args: [ref("the field, by its ref"), {
|
|
282
|
+
name: "variable",
|
|
283
|
+
kind: "text",
|
|
284
|
+
required: true,
|
|
285
|
+
cli: "<VARIABLE>",
|
|
286
|
+
where: ["cli"],
|
|
287
|
+
about: "the environment variable the user set, tied to its site with <VARIABLE>_ORIGIN"
|
|
288
|
+
}]
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
name: "handoff",
|
|
292
|
+
group: "act",
|
|
293
|
+
where: ["page"],
|
|
294
|
+
about: "hand a step to the user that only they should take (a code sent to them, a passkey, a captcha, a payment, signing in), and wait until they say it is done; the page is read again after",
|
|
295
|
+
args: [{
|
|
296
|
+
name: "what",
|
|
297
|
+
kind: "text",
|
|
298
|
+
required: true,
|
|
299
|
+
cli: "<what>",
|
|
300
|
+
about: "what the user should do, in one sentence"
|
|
301
|
+
}]
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
name: "back",
|
|
305
|
+
group: "act",
|
|
306
|
+
where: BOTH,
|
|
307
|
+
about: "go back a page",
|
|
308
|
+
args: []
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
name: "reload",
|
|
312
|
+
group: "act",
|
|
313
|
+
where: ["cli"],
|
|
314
|
+
about: "load the page again",
|
|
315
|
+
args: []
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
name: "wait",
|
|
319
|
+
group: "act",
|
|
320
|
+
where: BOTH,
|
|
321
|
+
about: "wait a while, or until some text shows",
|
|
322
|
+
args: [{
|
|
323
|
+
name: "ms",
|
|
324
|
+
kind: "number",
|
|
325
|
+
cli: "[<ms>]",
|
|
326
|
+
about: "how long, in milliseconds"
|
|
327
|
+
}, {
|
|
328
|
+
name: "text",
|
|
329
|
+
kind: "text",
|
|
330
|
+
cli: "[--text <text>]",
|
|
331
|
+
about: "until this text shows"
|
|
332
|
+
}]
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
name: "screenshot",
|
|
336
|
+
group: "act",
|
|
337
|
+
where: ["cli"],
|
|
338
|
+
optIn: true,
|
|
339
|
+
about: "save a picture of the page, what the page keeps out covered (off by default: start with --allow-screenshot)",
|
|
340
|
+
args: [{
|
|
341
|
+
name: "file",
|
|
342
|
+
kind: "text",
|
|
343
|
+
required: true,
|
|
344
|
+
cli: "<file.png>",
|
|
345
|
+
about: "where"
|
|
346
|
+
}, {
|
|
347
|
+
name: "full",
|
|
348
|
+
kind: "flag",
|
|
349
|
+
cli: "[--full]",
|
|
350
|
+
about: "the whole page, not only what shows"
|
|
351
|
+
}]
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
name: "script",
|
|
355
|
+
group: "act",
|
|
356
|
+
where: ["cli"],
|
|
357
|
+
about: "run JavaScript that drives this tool, to loop and filter in one call where each step would take one of its own: om.<command>(…) runs a command here and gives what it prints (om.click('e12'), om.open(url), om.snapshot({ match: 'Env' }); switch-tab as om.switchTab); om.find({ role, name, match, within }) gives the page's nodes as data (ref, role, name, value, description (the line's desc=), states, href, line), om.table(ref) a table's columns and rows, om.read() the whole page ({ url, title, root }); om.eval, where it is on, gives what the code returned as a value; print(…) says what to tell you; the last expression is said too. It runs in a sandbox of its own, never in the page; what it declares stays for the next script; a command that fails stops it (try/catch to go on); it stops after 100 s, so print as it goes, not only at its end. Not fill-secret: run that on its own",
|
|
358
|
+
args: [{
|
|
359
|
+
name: "script",
|
|
360
|
+
kind: "text",
|
|
361
|
+
cli: "[<script>]",
|
|
362
|
+
about: "the script; without it, read from stdin (a heredoc: agent-om script <<'JS' … JS)"
|
|
363
|
+
}]
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
name: "eval",
|
|
367
|
+
group: "act",
|
|
368
|
+
where: BOTH,
|
|
369
|
+
optIn: true,
|
|
370
|
+
about: "run JavaScript in the page and print what it returns: for what the view doesn't hold (figures the page only draws, a state only its markup keeps, a control with no ref), on an element the view found (ref) or the whole page, before guessing or saying it can't be done. Act with the commands, not page code, except on a control no command reaches and never on anything risky or confirm. The user's choice: here only where they have it on. It can read and change anything the page's own scripts can; what it returns has the page's secrets taken out",
|
|
371
|
+
args: [{
|
|
372
|
+
name: "script",
|
|
373
|
+
kind: "text",
|
|
374
|
+
required: true,
|
|
375
|
+
cli: "<script>",
|
|
376
|
+
about: "a function's body, run in the page: return what to print (return document.title)"
|
|
377
|
+
}, {
|
|
378
|
+
name: "ref",
|
|
379
|
+
kind: "ref",
|
|
380
|
+
cli: "[--ref <ref>]",
|
|
381
|
+
about: "an element the view found, which the script gets as el (return el.dataset)"
|
|
382
|
+
}]
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
name: "answer",
|
|
386
|
+
group: "act",
|
|
387
|
+
where: ["page"],
|
|
388
|
+
about: "end the task with the user's answer: what was found or done, or why it couldn't be",
|
|
389
|
+
args: [{
|
|
390
|
+
name: "text",
|
|
391
|
+
kind: "text",
|
|
392
|
+
required: true,
|
|
393
|
+
cli: "<text>",
|
|
394
|
+
about: "the answer"
|
|
395
|
+
}]
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
name: "start",
|
|
399
|
+
group: "session",
|
|
400
|
+
where: ["cli"],
|
|
401
|
+
about: "start a browser (any command starts one if none is running)",
|
|
402
|
+
args: [
|
|
403
|
+
{
|
|
404
|
+
name: "headed",
|
|
405
|
+
kind: "flag",
|
|
406
|
+
cli: "[--headed]",
|
|
407
|
+
about: "with a window"
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
name: "viewport",
|
|
411
|
+
kind: "text",
|
|
412
|
+
cli: "[--viewport <width>x<height>]",
|
|
413
|
+
about: "its size"
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
name: "state",
|
|
417
|
+
kind: "text",
|
|
418
|
+
cli: "[--state <file.json>]",
|
|
419
|
+
about: "cookies and storage saved by save-state (a signed-in user)"
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
name: "profile",
|
|
423
|
+
kind: "text",
|
|
424
|
+
cli: "[--profile <folder>]",
|
|
425
|
+
about: "a browser profile kept in this folder between sessions: what is signed in stays signed in"
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
name: "executable",
|
|
429
|
+
kind: "text",
|
|
430
|
+
cli: "[--executable <path>]",
|
|
431
|
+
about: "the browser to run"
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
name: "allow-origin",
|
|
435
|
+
kind: "texts",
|
|
436
|
+
cli: "[--allow-origin <origin,origin>]",
|
|
437
|
+
about: "the only sites the agent's tabs may go to (https://example.com): a page load anywhere else is stopped and said"
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
name: "cdp",
|
|
441
|
+
kind: "text",
|
|
442
|
+
cli: "[--cdp <port or address>]",
|
|
443
|
+
about: "attach to a browser that is running, by its debugging port or address, instead of starting one"
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
name: "auto-connect",
|
|
447
|
+
kind: "flag",
|
|
448
|
+
cli: "[--auto-connect]",
|
|
449
|
+
about: "attach to the user's running Chrome (remote debugging on at chrome://inspect/#remote-debugging; Chrome asks the user to allow it each time a session starts)"
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
name: "tabs",
|
|
453
|
+
kind: "text",
|
|
454
|
+
cli: "[--tabs own|active|all]",
|
|
455
|
+
values: [
|
|
456
|
+
"own",
|
|
457
|
+
"active",
|
|
458
|
+
"all"
|
|
459
|
+
],
|
|
460
|
+
about: "in a browser attached to: only the tabs the agent opens (own, the default), also the tab in front (active), or every tab (all); the user's choice, set at start, never widened"
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
name: "allow-screenshot",
|
|
464
|
+
kind: "flag",
|
|
465
|
+
cli: "[--allow-screenshot]",
|
|
466
|
+
about: "allow screenshots in this session (off by default; prompts for confirmation)"
|
|
467
|
+
}
|
|
468
|
+
]
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
name: "save-state",
|
|
472
|
+
group: "session",
|
|
473
|
+
where: ["cli"],
|
|
474
|
+
about: "save the session's cookies and storage (what is signed in) to a file only you can read, for start --state; it holds sign-ins: never print it",
|
|
475
|
+
args: [{
|
|
476
|
+
name: "file",
|
|
477
|
+
kind: "text",
|
|
478
|
+
required: true,
|
|
479
|
+
cli: "<file.json>",
|
|
480
|
+
about: "where"
|
|
481
|
+
}]
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
name: "stop",
|
|
485
|
+
group: "session",
|
|
486
|
+
where: ["cli"],
|
|
487
|
+
about: "close the browser",
|
|
488
|
+
args: []
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
name: "install",
|
|
492
|
+
group: "session",
|
|
493
|
+
where: ["cli"],
|
|
494
|
+
about: "download the browser this version is tested with (Playwright’s Chromium), once",
|
|
495
|
+
args: [{
|
|
496
|
+
name: "dry-run",
|
|
497
|
+
kind: "flag",
|
|
498
|
+
cli: "[--dry-run]",
|
|
499
|
+
about: "say what it would download, and download nothing"
|
|
500
|
+
}]
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
name: "doctor",
|
|
504
|
+
group: "session",
|
|
505
|
+
where: ["cli"],
|
|
506
|
+
about: "check what the tool needs, and say what to do about anything missing",
|
|
507
|
+
args: []
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
name: "status",
|
|
511
|
+
group: "session",
|
|
512
|
+
where: ["cli"],
|
|
513
|
+
about: "whether a browser is running, and its page",
|
|
514
|
+
args: []
|
|
515
|
+
}
|
|
516
|
+
];
|
|
517
|
+
/** What an action locates its element by when it has no ref: what it shows. */
|
|
518
|
+
const LOCATOR_ARGS = [
|
|
519
|
+
{
|
|
520
|
+
name: "text",
|
|
521
|
+
kind: "text",
|
|
522
|
+
cli: "--text \"<what it shows>\"",
|
|
523
|
+
about: "what it shows, for something with no ref (instead of the ref)"
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
name: "exact",
|
|
527
|
+
kind: "flag",
|
|
528
|
+
cli: "[--exact]",
|
|
529
|
+
about: "the whole text, not a part of it"
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
name: "nth",
|
|
533
|
+
kind: "number",
|
|
534
|
+
cli: "[--nth <n>]",
|
|
535
|
+
about: "which one, counting from 1, when several show it"
|
|
536
|
+
}
|
|
537
|
+
];
|
|
538
|
+
/** The commands a place offers, with the arguments it takes; opt-in commands (eval, screenshot) only when `on` names them. */
|
|
539
|
+
function commandsFor(where, on = []) {
|
|
540
|
+
return COMMANDS.filter((c) => c.where.includes(where) && (!c.optIn || on.includes(c.name))).map((c) => ({
|
|
541
|
+
...c,
|
|
542
|
+
args: c.args.filter((a) => !a.where || a.where.includes(where))
|
|
543
|
+
}));
|
|
544
|
+
}
|
|
545
|
+
// src/attach.ts
|
|
546
|
+
/** How long attaching waits: for the browser to let the session in, and for the user to allow it when Chrome asks (each time a session attaches). */
|
|
547
|
+
const ATTACH_MS = 6e4;
|
|
548
|
+
const TAB_LEVELS = [
|
|
549
|
+
"own",
|
|
550
|
+
"active",
|
|
551
|
+
"all"
|
|
552
|
+
];
|
|
553
|
+
/** A debugging address as the user gives it: a port on this computer, or the whole address (http:// or ws://). */
|
|
554
|
+
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;
|
|
557
|
+
throw new Error(`--cdp takes a port (9222) or a debugging address (http://127.0.0.1:9222, ws://…): '${cdp}'`);
|
|
558
|
+
}
|
|
559
|
+
/** Where each Chromium-family browser keeps its user data on this system: the default profile of each. */
|
|
560
|
+
function userDataDirs(platform = process.platform, home = homedir(), env = process.env) {
|
|
561
|
+
if (platform === "darwin") {
|
|
562
|
+
const base = join(home, "Library", "Application Support");
|
|
563
|
+
return [
|
|
564
|
+
"Google/Chrome",
|
|
565
|
+
"Google/Chrome Beta",
|
|
566
|
+
"Google/Chrome Canary",
|
|
567
|
+
"Chromium",
|
|
568
|
+
"BraveSoftware/Brave-Browser",
|
|
569
|
+
"Microsoft Edge"
|
|
570
|
+
].map((d) => join(base, d));
|
|
571
|
+
}
|
|
572
|
+
if (platform === "win32") {
|
|
573
|
+
const base = env.LOCALAPPDATA ?? join(home, "AppData", "Local");
|
|
574
|
+
return [
|
|
575
|
+
"Google/Chrome/User Data",
|
|
576
|
+
"Google/Chrome Beta/User Data",
|
|
577
|
+
"Google/Chrome SxS/User Data",
|
|
578
|
+
"Chromium/User Data",
|
|
579
|
+
"BraveSoftware/Brave-Browser/User Data",
|
|
580
|
+
"Microsoft/Edge/User Data"
|
|
581
|
+
].map((d) => join(base, d));
|
|
582
|
+
}
|
|
583
|
+
const base = env.XDG_CONFIG_HOME ?? join(home, ".config");
|
|
584
|
+
return [
|
|
585
|
+
"google-chrome",
|
|
586
|
+
"google-chrome-beta",
|
|
587
|
+
"google-chrome-unstable",
|
|
588
|
+
"chromium",
|
|
589
|
+
"BraveSoftware/Brave-Browser",
|
|
590
|
+
"microsoft-edge"
|
|
591
|
+
].map((d) => join(base, d));
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* The running browsers with remote debugging on, from the DevToolsActivePort
|
|
595
|
+
* file each writes in its user data (its port, then its browser's address):
|
|
596
|
+
* the exact address, so Chrome asks the user once for each session, not for each try. Stale files (a browser
|
|
597
|
+
* that has quit) are tried and fail like any other.
|
|
598
|
+
*/
|
|
599
|
+
function discover(dirs = userDataDirs()) {
|
|
600
|
+
const found = [];
|
|
601
|
+
for (const dir of dirs) {
|
|
602
|
+
const file = join(dir, "DevToolsActivePort");
|
|
603
|
+
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}`);
|
|
606
|
+
}
|
|
607
|
+
return found;
|
|
608
|
+
}
|
|
609
|
+
const NO_BROWSER = "no running browser with remote debugging found: in Chrome (144 or later), turn it on at chrome://inspect/#remote-debugging and allow the connection when Chrome asks (each time a session starts); or start a browser with --remote-debugging-port=9222 and attach with --cdp 9222";
|
|
610
|
+
// src/shared.ts
|
|
611
|
+
/** A command refused or failed in a way the model can act on. Its message may quote the page (an element's name), so it is said between the page-content markers. */
|
|
612
|
+
var UsageError = class extends Error {};
|
|
613
|
+
/**
|
|
614
|
+
* One in the tool's own words, which quote nothing the page wrote: said plain, outside the markers, so what it says to
|
|
615
|
+
* do reaches the model as the tool's. `quoting`: what of the page it's about (an element's name), said after it,
|
|
616
|
+
* between the markers.
|
|
617
|
+
*/
|
|
618
|
+
var ToolError = class extends UsageError {
|
|
619
|
+
quoting;
|
|
620
|
+
constructor(message, quoting) {
|
|
621
|
+
super(message);
|
|
622
|
+
if (quoting !== void 0) this.quoting = quoting;
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
/** The environment variable that turns eval off for a session (`0`) or on in the user's own browser (`1`), where the session starts: the user's choice, never a command's. */
|
|
626
|
+
const ALLOW_EVAL = "AGENT_OM_ALLOW_EVAL";
|
|
627
|
+
/**
|
|
628
|
+
* Whether eval is on for a session started in an environment. In a browser of the tool's own it is, unless the user
|
|
629
|
+
* turned it off. In the user's own browser (`attached`) a page's script reads what they are signed in to (cookies,
|
|
630
|
+
* stored tokens, which no scrubbing takes out), so there it is on only where the user turned it on.
|
|
631
|
+
*/
|
|
632
|
+
const evalOn = (env, attached = false) => attached ? env[ALLOW_EVAL] === "1" : env[ALLOW_EVAL] !== "0";
|
|
633
|
+
/** The environment variable that turns screenshots on for a session (`1`), where the session starts: off by default. */
|
|
634
|
+
const ALLOW_SCREENSHOT = "AGENT_OM_ALLOW_SCREENSHOT";
|
|
635
|
+
/** Whether screenshots are on for a session started in an environment: off by default unless explicitly opted in. */
|
|
636
|
+
const screenshotOn = (env) => env[ALLOW_SCREENSHOT] === "1";
|
|
637
|
+
/** Warning shown before enabling screenshots in the CLI. */
|
|
638
|
+
const SCREENSHOT_WARNING = [
|
|
639
|
+
"WARNING: Screenshots are off by default in Agent OM.",
|
|
640
|
+
"Agent OM's core design is screenshot-free text projection — reading pages as a compact semantic tree without sending images.",
|
|
641
|
+
"Enabling screenshots:",
|
|
642
|
+
" - Captures visual pixels of the page (even with redacted/ignored regions masked).",
|
|
643
|
+
" - Adds latency and token cost when images are inspected, and fails on text-only models.",
|
|
644
|
+
" - Is rarely needed: prefer snapshot, inspect, script, or eval first."
|
|
645
|
+
].join("\n");
|
|
646
|
+
// src/session.ts
|
|
647
|
+
/** The folder that holds the tool's sessions. */
|
|
648
|
+
const sessionsHome = () => join(process.env.AGENT_OM_HOME || join(homedir(), ".agent-om"), "cli");
|
|
649
|
+
const sessionDir = (name) => join(sessionsHome(), name);
|
|
650
|
+
const sessionFile = (name) => join(sessionDir(name), "session.json");
|
|
651
|
+
function readSession(name) {
|
|
652
|
+
try {
|
|
653
|
+
return JSON.parse(readFileSync(sessionFile(name), "utf8"));
|
|
654
|
+
} catch {
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
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 };
|