agent-browser 0.13.0 → 0.15.0
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 +50 -1
- package/bin/agent-browser-darwin-arm64 +0 -0
- package/bin/agent-browser-darwin-x64 +0 -0
- package/bin/agent-browser-linux-arm64 +0 -0
- package/bin/agent-browser-linux-x64 +0 -0
- package/bin/agent-browser-win32-x64.exe +0 -0
- package/dist/action-policy.d.ts +14 -0
- package/dist/action-policy.d.ts.map +1 -0
- package/dist/action-policy.js +253 -0
- package/dist/action-policy.js.map +1 -0
- package/dist/actions.d.ts +1 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +495 -305
- package/dist/actions.js.map +1 -1
- package/dist/auth-cli.d.ts +2 -0
- package/dist/auth-cli.d.ts.map +1 -0
- package/dist/auth-cli.js +97 -0
- package/dist/auth-cli.js.map +1 -0
- package/dist/auth-vault.d.ts +36 -0
- package/dist/auth-vault.d.ts.map +1 -0
- package/dist/auth-vault.js +125 -0
- package/dist/auth-vault.js.map +1 -0
- package/dist/browser.d.ts +33 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +173 -17
- package/dist/browser.js.map +1 -1
- package/dist/confirmation.d.ts +8 -0
- package/dist/confirmation.d.ts.map +1 -0
- package/dist/confirmation.js +30 -0
- package/dist/confirmation.js.map +1 -0
- package/dist/daemon.d.ts +7 -0
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +107 -29
- package/dist/daemon.js.map +1 -1
- package/dist/domain-filter.d.ts +28 -0
- package/dist/domain-filter.d.ts.map +1 -0
- package/dist/domain-filter.js +149 -0
- package/dist/domain-filter.js.map +1 -0
- package/dist/encryption.d.ts +25 -2
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +96 -10
- package/dist/encryption.js.map +1 -1
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +64 -1
- package/dist/protocol.js.map +1 -1
- package/dist/types.d.ts +70 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -1
- package/skills/agent-browser/SKILL.md +88 -1
- package/skills/agent-browser/templates/authenticated-session.sh +5 -0
- package/skills/dogfood/SKILL.md +216 -0
- package/skills/dogfood/references/issue-taxonomy.md +109 -0
- package/skills/dogfood/templates/dogfood-report-template.md +53 -0
package/README.md
CHANGED
|
@@ -101,13 +101,15 @@ agent-browser focus <sel> # Focus element
|
|
|
101
101
|
agent-browser type <sel> <text> # Type into element
|
|
102
102
|
agent-browser fill <sel> <text> # Clear and fill
|
|
103
103
|
agent-browser press <key> # Press key (Enter, Tab, Control+a) (alias: key)
|
|
104
|
+
agent-browser keyboard type <text> # Type with real keystrokes (no selector, current focus)
|
|
105
|
+
agent-browser keyboard inserttext <text> # Insert text without key events (no selector)
|
|
104
106
|
agent-browser keydown <key> # Hold key down
|
|
105
107
|
agent-browser keyup <key> # Release key
|
|
106
108
|
agent-browser hover <sel> # Hover element
|
|
107
109
|
agent-browser select <sel> <val> # Select dropdown option
|
|
108
110
|
agent-browser check <sel> # Check checkbox
|
|
109
111
|
agent-browser uncheck <sel> # Uncheck checkbox
|
|
110
|
-
agent-browser scroll <dir> [px] # Scroll (up/down/left/right)
|
|
112
|
+
agent-browser scroll <dir> [px] # Scroll (up/down/left/right, --selector <sel>)
|
|
111
113
|
agent-browser scrollintoview <sel> # Scroll element into view (alias: scrollinto)
|
|
112
114
|
agent-browser drag <src> <tgt> # Drag and drop
|
|
113
115
|
agent-browser upload <sel> <files> # Upload files
|
|
@@ -393,6 +395,28 @@ agent-browser --session-name secure open example.com
|
|
|
393
395
|
| `AGENT_BROWSER_ENCRYPTION_KEY` | 64-char hex key for AES-256-GCM encryption |
|
|
394
396
|
| `AGENT_BROWSER_STATE_EXPIRE_DAYS` | Auto-delete states older than N days (default: 30) |
|
|
395
397
|
|
|
398
|
+
## Security
|
|
399
|
+
|
|
400
|
+
agent-browser includes security features for safe AI agent deployments. All features are opt-in -- existing workflows are unaffected until you explicitly enable a feature:
|
|
401
|
+
|
|
402
|
+
- **Authentication Vault** -- Store credentials locally (always encrypted), reference by name. The LLM never sees passwords. A key is auto-generated at `~/.agent-browser/.encryption-key` if `AGENT_BROWSER_ENCRYPTION_KEY` is not set: `echo "pass" | agent-browser auth save github --url https://github.com/login --username user --password-stdin` then `agent-browser auth login github`
|
|
403
|
+
- **Content Boundary Markers** -- Wrap page output in delimiters so LLMs can distinguish tool output from untrusted content: `--content-boundaries`
|
|
404
|
+
- **Domain Allowlist** -- Restrict navigation to trusted domains (wildcards like `*.example.com` also match the bare domain): `--allowed-domains "example.com,*.example.com"`. Sub-resource requests (scripts, images, fetch) and WebSocket/EventSource connections to non-allowed domains are also blocked. Include any CDN domains your target pages depend on (e.g., `*.cdn.example.com`).
|
|
405
|
+
- **Action Policy** -- Gate destructive actions with a static policy file: `--action-policy ./policy.json`
|
|
406
|
+
- **Action Confirmation** -- Require explicit approval for sensitive action categories: `--confirm-actions eval,download`
|
|
407
|
+
- **Output Length Limits** -- Prevent context flooding: `--max-output 50000`
|
|
408
|
+
|
|
409
|
+
| Variable | Description |
|
|
410
|
+
|----------|-------------|
|
|
411
|
+
| `AGENT_BROWSER_CONTENT_BOUNDARIES` | Wrap page output in boundary markers |
|
|
412
|
+
| `AGENT_BROWSER_MAX_OUTPUT` | Max characters for page output |
|
|
413
|
+
| `AGENT_BROWSER_ALLOWED_DOMAINS` | Comma-separated allowed domain patterns |
|
|
414
|
+
| `AGENT_BROWSER_ACTION_POLICY` | Path to action policy JSON file |
|
|
415
|
+
| `AGENT_BROWSER_CONFIRM_ACTIONS` | Action categories requiring confirmation |
|
|
416
|
+
| `AGENT_BROWSER_CONFIRM_INTERACTIVE` | Enable interactive confirmation prompts |
|
|
417
|
+
|
|
418
|
+
See [Security documentation](https://agent-browser.vercel.app/security) for details.
|
|
419
|
+
|
|
396
420
|
## Snapshot Options
|
|
397
421
|
|
|
398
422
|
The `snapshot` command supports filtering to reduce output size:
|
|
@@ -463,6 +487,14 @@ This is useful for multimodal AI models that can reason about visual layout, unl
|
|
|
463
487
|
| `--headed` | Show browser window (not headless) |
|
|
464
488
|
| `--cdp <port\|url>` | Connect via Chrome DevTools Protocol (port or WebSocket URL) |
|
|
465
489
|
| `--auto-connect` | Auto-discover and connect to running Chrome (or `AGENT_BROWSER_AUTO_CONNECT` env) |
|
|
490
|
+
| `--color-scheme <scheme>` | Color scheme: `dark`, `light`, `no-preference` (or `AGENT_BROWSER_COLOR_SCHEME` env) |
|
|
491
|
+
| `--download-path <path>` | Default download directory (or `AGENT_BROWSER_DOWNLOAD_PATH` env) |
|
|
492
|
+
| `--content-boundaries` | Wrap page output in boundary markers for LLM safety (or `AGENT_BROWSER_CONTENT_BOUNDARIES` env) |
|
|
493
|
+
| `--max-output <chars>` | Truncate page output to N characters (or `AGENT_BROWSER_MAX_OUTPUT` env) |
|
|
494
|
+
| `--allowed-domains <list>` | Comma-separated allowed domain patterns (or `AGENT_BROWSER_ALLOWED_DOMAINS` env) |
|
|
495
|
+
| `--action-policy <path>` | Path to action policy JSON file (or `AGENT_BROWSER_ACTION_POLICY` env) |
|
|
496
|
+
| `--confirm-actions <list>` | Action categories requiring confirmation (or `AGENT_BROWSER_CONFIRM_ACTIONS` env) |
|
|
497
|
+
| `--confirm-interactive` | Interactive confirmation prompts; auto-denies if stdin is not a TTY (or `AGENT_BROWSER_CONFIRM_INTERACTIVE` env) |
|
|
466
498
|
| `--config <path>` | Use a custom config file (or `AGENT_BROWSER_CONFIG` env) |
|
|
467
499
|
| `--debug` | Debug output |
|
|
468
500
|
|
|
@@ -504,6 +536,23 @@ Auto-discovered config files that are missing are silently ignored. If `--config
|
|
|
504
536
|
|
|
505
537
|
> **Tip:** If your project-level `agent-browser.json` contains environment-specific values (paths, proxies), consider adding it to `.gitignore`.
|
|
506
538
|
|
|
539
|
+
## Default Timeout
|
|
540
|
+
|
|
541
|
+
The default Playwright timeout for standard operations (clicks, waits, fills, etc.) is 25 seconds. This is intentionally below the CLI's 30-second IPC read timeout so that Playwright returns a proper error instead of the CLI timing out with EAGAIN.
|
|
542
|
+
|
|
543
|
+
Override the default timeout via environment variable:
|
|
544
|
+
|
|
545
|
+
```bash
|
|
546
|
+
# Set a longer timeout for slow pages (in milliseconds)
|
|
547
|
+
export AGENT_BROWSER_DEFAULT_TIMEOUT=45000
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
> **Note:** Setting this above 30000 (30s) may cause EAGAIN errors on slow operations because the CLI's read timeout will expire before Playwright responds. The CLI retries transient errors automatically, but response times will increase.
|
|
551
|
+
|
|
552
|
+
| Variable | Description |
|
|
553
|
+
|----------|-------------|
|
|
554
|
+
| `AGENT_BROWSER_DEFAULT_TIMEOUT` | Default Playwright timeout in ms (default: 25000) |
|
|
555
|
+
|
|
507
556
|
## Selectors
|
|
508
557
|
|
|
509
558
|
### Refs (Recommended for AI)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ActionPolicy {
|
|
2
|
+
default: 'allow' | 'deny';
|
|
3
|
+
allow?: string[];
|
|
4
|
+
deny?: string[];
|
|
5
|
+
}
|
|
6
|
+
export type PolicyDecision = 'allow' | 'deny' | 'confirm';
|
|
7
|
+
export declare const KNOWN_CATEGORIES: Set<string>;
|
|
8
|
+
export declare function getActionCategory(action: string): string;
|
|
9
|
+
export declare function loadPolicyFile(policyPath: string): ActionPolicy;
|
|
10
|
+
export declare function initPolicyReloader(policyPath: string, policy: ActionPolicy): void;
|
|
11
|
+
export declare function reloadPolicyIfChanged(): ActionPolicy | null;
|
|
12
|
+
export declare function checkPolicy(action: string, policy: ActionPolicy | null, confirmCategories: Set<string>): PolicyDecision;
|
|
13
|
+
export declare function describeAction(action: string, command: Record<string, unknown>): string;
|
|
14
|
+
//# sourceMappingURL=action-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-policy.d.ts","sourceRoot":"","sources":["../src/action-policy.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AA4K1D,eAAO,MAAM,gBAAgB,aAE5B,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,YAAY,CAwB/D;AAQD,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAIjF;AAED,wBAAgB,qBAAqB,IAAI,YAAY,GAAG,IAAI,CAkB3D;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,GAAG,IAAI,EAC3B,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,GAC7B,cAAc,CAkBhB;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAyBvF"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
const ACTION_CATEGORIES = {
|
|
4
|
+
navigate: 'navigate',
|
|
5
|
+
back: 'navigate',
|
|
6
|
+
forward: 'navigate',
|
|
7
|
+
reload: 'navigate',
|
|
8
|
+
tab_new: 'navigate',
|
|
9
|
+
click: 'click',
|
|
10
|
+
dblclick: 'click',
|
|
11
|
+
tap: 'click',
|
|
12
|
+
fill: 'fill',
|
|
13
|
+
type: 'fill',
|
|
14
|
+
// The `keyboard` action is a compound command that dispatches to sub-actions
|
|
15
|
+
// (type, inserttext, press, down, up). Its primary use is text input, so it
|
|
16
|
+
// maps to 'fill'. The interact-like sub-actions (press, down, up) are less
|
|
17
|
+
// common and don't have separate top-level action names in the protocol.
|
|
18
|
+
keyboard: 'fill',
|
|
19
|
+
inserttext: 'fill',
|
|
20
|
+
select: 'fill',
|
|
21
|
+
multiselect: 'fill',
|
|
22
|
+
check: 'fill',
|
|
23
|
+
uncheck: 'fill',
|
|
24
|
+
clear: 'fill',
|
|
25
|
+
selectall: 'fill',
|
|
26
|
+
setvalue: 'fill',
|
|
27
|
+
download: 'download',
|
|
28
|
+
waitfordownload: 'download',
|
|
29
|
+
upload: 'upload',
|
|
30
|
+
evaluate: 'eval',
|
|
31
|
+
evalhandle: 'eval',
|
|
32
|
+
addscript: 'eval',
|
|
33
|
+
addinitscript: 'eval',
|
|
34
|
+
snapshot: 'snapshot',
|
|
35
|
+
screenshot: 'snapshot',
|
|
36
|
+
pdf: 'snapshot',
|
|
37
|
+
diff_snapshot: 'snapshot',
|
|
38
|
+
diff_screenshot: 'snapshot',
|
|
39
|
+
diff_url: 'snapshot',
|
|
40
|
+
scroll: 'scroll',
|
|
41
|
+
scrollintoview: 'scroll',
|
|
42
|
+
wait: 'wait',
|
|
43
|
+
waitforurl: 'wait',
|
|
44
|
+
waitforloadstate: 'wait',
|
|
45
|
+
waitforfunction: 'wait',
|
|
46
|
+
gettext: 'get',
|
|
47
|
+
content: 'get',
|
|
48
|
+
innerhtml: 'get',
|
|
49
|
+
innertext: 'get',
|
|
50
|
+
inputvalue: 'get',
|
|
51
|
+
url: 'get',
|
|
52
|
+
title: 'get',
|
|
53
|
+
getattribute: 'get',
|
|
54
|
+
count: 'get',
|
|
55
|
+
boundingbox: 'get',
|
|
56
|
+
styles: 'get',
|
|
57
|
+
isvisible: 'get',
|
|
58
|
+
isenabled: 'get',
|
|
59
|
+
ischecked: 'get',
|
|
60
|
+
responsebody: 'get',
|
|
61
|
+
route: 'network',
|
|
62
|
+
unroute: 'network',
|
|
63
|
+
requests: 'network',
|
|
64
|
+
state_save: 'state',
|
|
65
|
+
state_load: 'state',
|
|
66
|
+
cookies_set: 'state',
|
|
67
|
+
storage_set: 'state',
|
|
68
|
+
credentials: 'state',
|
|
69
|
+
hover: 'interact',
|
|
70
|
+
focus: 'interact',
|
|
71
|
+
drag: 'interact',
|
|
72
|
+
press: 'interact',
|
|
73
|
+
keydown: 'interact',
|
|
74
|
+
keyup: 'interact',
|
|
75
|
+
mousemove: 'interact',
|
|
76
|
+
mousedown: 'interact',
|
|
77
|
+
mouseup: 'interact',
|
|
78
|
+
wheel: 'interact',
|
|
79
|
+
dispatch: 'interact',
|
|
80
|
+
// These are always allowed (internal/meta operations)
|
|
81
|
+
launch: '_internal',
|
|
82
|
+
close: '_internal',
|
|
83
|
+
tab_list: '_internal',
|
|
84
|
+
tab_switch: '_internal',
|
|
85
|
+
tab_close: '_internal',
|
|
86
|
+
window_new: '_internal',
|
|
87
|
+
frame: '_internal',
|
|
88
|
+
mainframe: '_internal',
|
|
89
|
+
dialog: '_internal',
|
|
90
|
+
session: '_internal',
|
|
91
|
+
console: '_internal',
|
|
92
|
+
errors: '_internal',
|
|
93
|
+
cookies_get: '_internal',
|
|
94
|
+
cookies_clear: '_internal',
|
|
95
|
+
storage_get: '_internal',
|
|
96
|
+
storage_clear: '_internal',
|
|
97
|
+
state_list: '_internal',
|
|
98
|
+
state_show: '_internal',
|
|
99
|
+
state_clear: '_internal',
|
|
100
|
+
state_clean: '_internal',
|
|
101
|
+
state_rename: '_internal',
|
|
102
|
+
highlight: '_internal',
|
|
103
|
+
bringtofront: '_internal',
|
|
104
|
+
trace_start: '_internal',
|
|
105
|
+
trace_stop: '_internal',
|
|
106
|
+
har_start: '_internal',
|
|
107
|
+
har_stop: '_internal',
|
|
108
|
+
video_start: '_internal',
|
|
109
|
+
video_stop: '_internal',
|
|
110
|
+
recording_start: '_internal',
|
|
111
|
+
recording_stop: '_internal',
|
|
112
|
+
recording_restart: '_internal',
|
|
113
|
+
profiler_start: '_internal',
|
|
114
|
+
profiler_stop: '_internal',
|
|
115
|
+
clipboard: '_internal',
|
|
116
|
+
viewport: '_internal',
|
|
117
|
+
useragent: '_internal',
|
|
118
|
+
device: '_internal',
|
|
119
|
+
geolocation: '_internal',
|
|
120
|
+
permissions: '_internal',
|
|
121
|
+
emulatemedia: '_internal',
|
|
122
|
+
offline: '_internal',
|
|
123
|
+
headers: '_internal',
|
|
124
|
+
addstyle: 'eval',
|
|
125
|
+
expose: 'eval',
|
|
126
|
+
timezone: '_internal',
|
|
127
|
+
locale: '_internal',
|
|
128
|
+
pause: '_internal',
|
|
129
|
+
setcontent: 'eval',
|
|
130
|
+
screencast_start: '_internal',
|
|
131
|
+
screencast_stop: '_internal',
|
|
132
|
+
input_mouse: '_internal',
|
|
133
|
+
input_keyboard: '_internal',
|
|
134
|
+
input_touch: '_internal',
|
|
135
|
+
auth_save: '_internal',
|
|
136
|
+
auth_login: '_internal',
|
|
137
|
+
auth_list: '_internal',
|
|
138
|
+
auth_delete: '_internal',
|
|
139
|
+
auth_show: '_internal',
|
|
140
|
+
confirm: '_internal',
|
|
141
|
+
deny: '_internal',
|
|
142
|
+
// Find/semantic locator actions (read-only element resolution)
|
|
143
|
+
getbyrole: 'get',
|
|
144
|
+
getbytext: 'get',
|
|
145
|
+
getbylabel: 'get',
|
|
146
|
+
getbyplaceholder: 'get',
|
|
147
|
+
getbyalttext: 'get',
|
|
148
|
+
getbytitle: 'get',
|
|
149
|
+
getbytestid: 'get',
|
|
150
|
+
nth: 'get',
|
|
151
|
+
};
|
|
152
|
+
// User-facing categories used in policy files. '_internal' is excluded because
|
|
153
|
+
// internal actions always bypass policy. 'unknown' is intentionally not a value
|
|
154
|
+
// in ACTION_CATEGORIES -- it is only the fallback return of getActionCategory()
|
|
155
|
+
// for unrecognized actions. If a user puts "unknown" in a policy file,
|
|
156
|
+
// loadPolicyFile will warn about it as unrecognized, which is correct.
|
|
157
|
+
export const KNOWN_CATEGORIES = new Set(Object.values(ACTION_CATEGORIES).filter((c) => c !== '_internal'));
|
|
158
|
+
export function getActionCategory(action) {
|
|
159
|
+
return ACTION_CATEGORIES[action] ?? 'unknown';
|
|
160
|
+
}
|
|
161
|
+
export function loadPolicyFile(policyPath) {
|
|
162
|
+
const resolved = resolve(policyPath);
|
|
163
|
+
const content = readFileSync(resolved, 'utf-8');
|
|
164
|
+
const policy = JSON.parse(content);
|
|
165
|
+
if (policy.default !== 'allow' && policy.default !== 'deny') {
|
|
166
|
+
throw new Error(`Invalid action policy: "default" must be "allow" or "deny", got "${policy.default}"`);
|
|
167
|
+
}
|
|
168
|
+
for (const list of [policy.allow, policy.deny]) {
|
|
169
|
+
if (!list)
|
|
170
|
+
continue;
|
|
171
|
+
for (const category of list) {
|
|
172
|
+
if (!KNOWN_CATEGORIES.has(category)) {
|
|
173
|
+
console.warn(`[agent-browser] Warning: unrecognized action category "${category}" in policy file. ` +
|
|
174
|
+
`Known categories: ${[...KNOWN_CATEGORIES].sort().join(', ')}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return policy;
|
|
179
|
+
}
|
|
180
|
+
let cachedPolicyPath = null;
|
|
181
|
+
let cachedPolicyMtimeMs = 0;
|
|
182
|
+
let cachedPolicy = null;
|
|
183
|
+
const RELOAD_CHECK_INTERVAL_MS = 5_000;
|
|
184
|
+
let lastCheckMs = 0;
|
|
185
|
+
export function initPolicyReloader(policyPath, policy) {
|
|
186
|
+
cachedPolicyPath = resolve(policyPath);
|
|
187
|
+
cachedPolicyMtimeMs = statSync(cachedPolicyPath).mtimeMs;
|
|
188
|
+
cachedPolicy = policy;
|
|
189
|
+
}
|
|
190
|
+
export function reloadPolicyIfChanged() {
|
|
191
|
+
if (!cachedPolicyPath)
|
|
192
|
+
return cachedPolicy;
|
|
193
|
+
const now = Date.now();
|
|
194
|
+
if (now - lastCheckMs < RELOAD_CHECK_INTERVAL_MS)
|
|
195
|
+
return cachedPolicy;
|
|
196
|
+
lastCheckMs = now;
|
|
197
|
+
try {
|
|
198
|
+
const currentMtime = statSync(cachedPolicyPath).mtimeMs;
|
|
199
|
+
if (currentMtime !== cachedPolicyMtimeMs) {
|
|
200
|
+
cachedPolicy = loadPolicyFile(cachedPolicyPath);
|
|
201
|
+
cachedPolicyMtimeMs = currentMtime;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
// File may have been removed; keep using cached policy
|
|
206
|
+
}
|
|
207
|
+
return cachedPolicy;
|
|
208
|
+
}
|
|
209
|
+
export function checkPolicy(action, policy, confirmCategories) {
|
|
210
|
+
const category = getActionCategory(action);
|
|
211
|
+
// Internal actions are always allowed
|
|
212
|
+
if (category === '_internal')
|
|
213
|
+
return 'allow';
|
|
214
|
+
// Explicit deny takes precedence over confirmation
|
|
215
|
+
if (policy?.deny?.includes(category))
|
|
216
|
+
return 'deny';
|
|
217
|
+
// Check if this category requires confirmation
|
|
218
|
+
if (confirmCategories.has(category))
|
|
219
|
+
return 'confirm';
|
|
220
|
+
if (!policy)
|
|
221
|
+
return 'allow';
|
|
222
|
+
// Explicit allow list
|
|
223
|
+
if (policy.allow?.includes(category))
|
|
224
|
+
return 'allow';
|
|
225
|
+
return policy.default;
|
|
226
|
+
}
|
|
227
|
+
export function describeAction(action, command) {
|
|
228
|
+
const category = getActionCategory(action);
|
|
229
|
+
switch (action) {
|
|
230
|
+
case 'navigate':
|
|
231
|
+
return `Navigate to ${command.url}`;
|
|
232
|
+
case 'evaluate':
|
|
233
|
+
case 'evalhandle':
|
|
234
|
+
return `Evaluate JavaScript: ${String(command.script ?? '').slice(0, 80)}`;
|
|
235
|
+
case 'fill':
|
|
236
|
+
return `Fill ${command.selector}`;
|
|
237
|
+
case 'type':
|
|
238
|
+
return `Type into ${command.selector}`;
|
|
239
|
+
case 'click':
|
|
240
|
+
return `Click ${command.selector}`;
|
|
241
|
+
case 'dblclick':
|
|
242
|
+
return `Double-click ${command.selector}`;
|
|
243
|
+
case 'tap':
|
|
244
|
+
return `Tap ${command.selector}`;
|
|
245
|
+
case 'download':
|
|
246
|
+
return `Download via ${command.selector} to ${command.path}`;
|
|
247
|
+
case 'upload':
|
|
248
|
+
return `Upload files to ${command.selector}`;
|
|
249
|
+
default:
|
|
250
|
+
return `${category}: ${action}`;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=action-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-policy.js","sourceRoot":"","sources":["../src/action-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC,MAAM,iBAAiB,GAA2B;IAChD,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,UAAU;IACnB,MAAM,EAAE,UAAU;IAClB,OAAO,EAAE,UAAU;IAEnB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,OAAO;IACjB,GAAG,EAAE,OAAO;IAEZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,6EAA6E;IAC7E,4EAA4E;IAC5E,2EAA2E;IAC3E,yEAAyE;IACzE,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,MAAM;IAClB,MAAM,EAAE,MAAM;IACd,WAAW,EAAE,MAAM;IACnB,KAAK,EAAE,MAAM;IACb,OAAO,EAAE,MAAM;IACf,KAAK,EAAE,MAAM;IACb,SAAS,EAAE,MAAM;IACjB,QAAQ,EAAE,MAAM;IAEhB,QAAQ,EAAE,UAAU;IACpB,eAAe,EAAE,UAAU;IAE3B,MAAM,EAAE,QAAQ;IAEhB,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,MAAM;IAClB,SAAS,EAAE,MAAM;IACjB,aAAa,EAAE,MAAM;IAErB,QAAQ,EAAE,UAAU;IACpB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AAE,CAAC;QACrC,KAAK,UAAU;YACb,OAAO,gBAAgB,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC5C,KAAK,KAAK;YACR,OAAO,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;QACnC,KAAK,UAAU;YACb,OAAO,gBAAgB,OAAO,CAAC,QAAQ,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;QAC/D,KAAK,QAAQ;YACX,OAAO,mBAAmB,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC/C;YACE,OAAO,GAAG,QAAQ,KAAK,MAAM,EAAE,CAAC;IACpC,CAAC;AACH,CAAC"}
|
package/dist/actions.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare function setScreencastFrameCallback(callback: ((frame: Screencast
|
|
|
10
10
|
* @internal Exported for testing
|
|
11
11
|
*/
|
|
12
12
|
export declare function toAIFriendlyError(error: unknown, selector: string): Error;
|
|
13
|
+
export declare function initActionPolicy(): void;
|
|
13
14
|
/**
|
|
14
15
|
* Execute a command and return a response
|
|
15
16
|
*/
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAqBpE,OAAO,KAAK,EACV,OAAO,EACP,QAAQ,EAsIT,MAAM,YAAY,CAAC;AAQpB;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC,GAAG,IAAI,GAClD,IAAI,CAEN;AAQD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,CAqDzE;AAKD,wBAAgB,gBAAgB,IAAI,IAAI,CAuBvC;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6CjG"}
|