leapfrog-mcp 0.6.1 → 0.6.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 +29 -16
- package/dist/index.js +8 -5
- package/dist/session-manager.js +19 -4
- package/dist/tile-manager.d.ts +2 -2
- package/dist/tile-manager.js +3 -27
- package/package.json +1 -1
- package/dist/adaptive-wait.d.ts +0 -72
- package/dist/adaptive-wait.js +0 -695
- package/dist/api-intelligence.d.ts +0 -82
- package/dist/api-intelligence.js +0 -575
- package/dist/captcha-solver.d.ts +0 -26
- package/dist/captcha-solver.js +0 -547
- package/dist/cdp-connector.d.ts +0 -33
- package/dist/cdp-connector.js +0 -176
- package/dist/consent-dismiss.d.ts +0 -33
- package/dist/consent-dismiss.js +0 -358
- package/dist/crash-recovery.d.ts +0 -74
- package/dist/crash-recovery.js +0 -242
- package/dist/domain-knowledge.d.ts +0 -149
- package/dist/domain-knowledge.js +0 -449
- package/dist/harness-intelligence.d.ts +0 -65
- package/dist/harness-intelligence.js +0 -432
- package/dist/humanize-fingerprint.d.ts +0 -42
- package/dist/humanize-fingerprint.js +0 -161
- package/dist/humanize-mouse.d.ts +0 -95
- package/dist/humanize-mouse.js +0 -275
- package/dist/humanize-pause.d.ts +0 -48
- package/dist/humanize-pause.js +0 -111
- package/dist/humanize-scroll.d.ts +0 -67
- package/dist/humanize-scroll.js +0 -185
- package/dist/humanize-typing.d.ts +0 -60
- package/dist/humanize-typing.js +0 -258
- package/dist/humanize-utils.d.ts +0 -62
- package/dist/humanize-utils.js +0 -100
- package/dist/interaction-tracker.d.ts +0 -44
- package/dist/interaction-tracker.js +0 -148
- package/dist/intervention.d.ts +0 -65
- package/dist/intervention.js +0 -591
- package/dist/logger.d.ts +0 -13
- package/dist/logger.js +0 -47
- package/dist/network-intelligence.d.ts +0 -70
- package/dist/network-intelligence.js +0 -424
- package/dist/notify.d.ts +0 -5
- package/dist/notify.js +0 -50
- package/dist/page-classifier.d.ts +0 -33
- package/dist/page-classifier.js +0 -1000
- package/dist/paginate.d.ts +0 -42
- package/dist/paginate.js +0 -693
- package/dist/recording.d.ts +0 -72
- package/dist/recording.js +0 -934
- package/dist/script-executor.d.ts +0 -31
- package/dist/script-executor.js +0 -249
- package/dist/session-hud.d.ts +0 -20
- package/dist/session-hud.js +0 -134
- package/dist/sidecar.d.ts +0 -25
- package/dist/sidecar.js +0 -140
- package/dist/snapshot-differ.d.ts +0 -26
- package/dist/snapshot-differ.js +0 -225
- package/dist/ssrf.d.ts +0 -28
- package/dist/ssrf.js +0 -290
- package/dist/stealth-audit.d.ts +0 -27
- package/dist/stealth-audit.js +0 -719
- package/dist/stealth-bandit.d.ts +0 -64
- package/dist/stealth-bandit.js +0 -163
- package/dist/stealth.d.ts +0 -195
- package/dist/stealth.js +0 -1157
- package/dist/tab-manager.d.ts +0 -14
- package/dist/tab-manager.js +0 -306
- package/dist/tiles-coordinator.d.ts +0 -106
- package/dist/tiles-coordinator.js +0 -358
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<p align="center"><strong>Multi-session browser MCP for AI agents.</strong><br/>36 tools. 15 parallel sessions. Stealth. HUD. Self-improvement. Up to 10x fewer tokens.</p>
|
|
7
7
|
|
|
8
8
|
<p align="center">
|
|
9
|
-
<code>npm i leapfrog</code> | Works with Claude Code, Cursor, Windsurf
|
|
9
|
+
<code>npm i leapfrog-mcp</code> | Works with Claude Code, Cursor, Windsurf
|
|
10
10
|
</p>
|
|
11
11
|
|
|
12
12
|
---
|
|
@@ -33,9 +33,9 @@ Savings range from 2-10x depending on page complexity. Content-heavy pages see t
|
|
|
33
33
|
## Quick Start
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
-
npx leapfrog --doctor # verify everything works
|
|
37
|
-
npx leapfrog --stealth-audit # test all 19 stealth patches
|
|
38
|
-
npx leapfrog --config # print MCP config to paste
|
|
36
|
+
npx leapfrog-mcp --doctor # verify everything works
|
|
37
|
+
npx leapfrog-mcp --stealth-audit # test all 19 stealth patches
|
|
38
|
+
npx leapfrog-mcp --config # print MCP config to paste
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
Add to `~/.mcp.json` (Claude Code) or your editor's MCP config:
|
|
@@ -44,12 +44,11 @@ Add to `~/.mcp.json` (Claude Code) or your editor's MCP config:
|
|
|
44
44
|
{
|
|
45
45
|
"leapfrog": {
|
|
46
46
|
"command": "npx",
|
|
47
|
-
"args": ["-y", "leapfrog"],
|
|
47
|
+
"args": ["-y", "leapfrog-mcp"],
|
|
48
48
|
"env": {
|
|
49
49
|
"LEAP_MAX_SESSIONS": "15",
|
|
50
50
|
"LEAP_TILE": "true",
|
|
51
51
|
"LEAP_HUD": "true",
|
|
52
|
-
"LEAP_SOUND": "true",
|
|
53
52
|
"LEAP_AUTO_CONSENT": "true"
|
|
54
53
|
}
|
|
55
54
|
}
|
|
@@ -57,8 +56,9 @@ Add to `~/.mcp.json` (Claude Code) or your editor's MCP config:
|
|
|
57
56
|
```
|
|
58
57
|
|
|
59
58
|
Leapfrog uses `playwright-core` (15MB) instead of `playwright` (1.6GB) and does **not** bundle a browser. Either:
|
|
60
|
-
- Set `LEAP_CHANNEL=chrome` to use your installed Chrome/Chromium
|
|
59
|
+
- Set `LEAP_CHANNEL=chrome` to use your installed Chrome/Chromium (recommended)
|
|
61
60
|
- Or run `npx playwright-core install chromium` to install the bundled Chromium binary
|
|
61
|
+
- Or set `LEAP_CDP_ENDPOINT` to connect to an already-running Chrome instance
|
|
62
62
|
|
|
63
63
|
## Feature Matrix
|
|
64
64
|
|
|
@@ -94,7 +94,14 @@ Leapfrog uses `playwright-core` (15MB) instead of `playwright` (1.6GB) and does
|
|
|
94
94
|
|
|
95
95
|
## Stealth
|
|
96
96
|
|
|
97
|
-
Leapfrog ships 19 anti-detection patches enabled by default (`LEAP_STEALTH=true`).
|
|
97
|
+
Leapfrog ships 19 anti-detection patches enabled by default (`LEAP_STEALTH=true`). Four modes:
|
|
98
|
+
|
|
99
|
+
- **`true`** (default) — all 19 patches active
|
|
100
|
+
- **`passive`** — removes automation signals only (webdriver, HeadlessChrome). Does NOT fake identity (WebGL, fonts, audio). Better for sites where trust matters more than evasion.
|
|
101
|
+
- **`auto`** — per-domain EXP3 bandit selects the optimal stealth configuration based on what's worked before
|
|
102
|
+
- **`false`** — no stealth patches
|
|
103
|
+
|
|
104
|
+
These cover the vectors that fingerprint services like CreepJS and fingerprint-pro actually check:
|
|
98
105
|
|
|
99
106
|
- Client Hints brands (strips HeadlessChrome)
|
|
100
107
|
- `navigator.webdriver` forced to `undefined`
|
|
@@ -231,7 +238,7 @@ Leapfrog learns from every visit. Per-domain knowledge persists at `~/.leapfrog/
|
|
|
231
238
|
| 6 | **Selector healing** | Remembers element fingerprints → selectors, heals broken refs across visits |
|
|
232
239
|
| 7 | **API endpoint caching** | Discovered API endpoints persist across sessions |
|
|
233
240
|
| 8 | **Interaction heat maps** | Tracks which elements agents actually use, suppresses untouched elements _(coming)_ |
|
|
234
|
-
| 9 | **Strategy selection** | Adversarial bandit (EXP3) for stealth config optimization
|
|
241
|
+
| 9 | **Strategy selection** | Adversarial bandit (EXP3) for stealth config optimization. Use `LEAP_STEALTH=auto` to enable. |
|
|
235
242
|
|
|
236
243
|
LRU eviction at 500 domains. Inspect with the `domain_knowledge` tool.
|
|
237
244
|
|
|
@@ -323,23 +330,29 @@ Leapfrog uses pond metaphors to keep things memorable. Your agent is the frog.
|
|
|
323
330
|
| `LEAP_MAX_SESSIONS` | `15` | Max concurrent sessions |
|
|
324
331
|
| `LEAP_IDLE_TIMEOUT` | `1800000` | Session idle timeout in ms (30 min). Set `0` to disable. |
|
|
325
332
|
| `LEAP_HEADLESS` | `true` | Set `false` to watch the browser |
|
|
333
|
+
| `LEAP_HEADED` | `false` | Set `true` to watch the browser (positive alternative to `LEAP_HEADLESS`) |
|
|
326
334
|
| `LEAP_CHANNEL` | _(bundled chromium)_ | Set `chrome` to use your installed Chrome |
|
|
335
|
+
| `LEAP_CDP_ENDPOINT` | _(none)_ | Connect to a running Chrome instance (e.g. `http://localhost:9222`) |
|
|
336
|
+
| `LEAP_EXTENSIONS` | _(none)_ | Comma-separated paths to browser extensions to load |
|
|
327
337
|
| `LEAP_ALLOW_JS` | `true` | Allow JS evaluation in `extract` and `wait_for` |
|
|
328
|
-
| `LEAP_STEALTH` | `true` | Stealth mode
|
|
338
|
+
| `LEAP_STEALTH` | `true` | Stealth mode: `true` \| `passive` \| `auto` \| `false`. See Stealth section. |
|
|
339
|
+
| `LEAP_STEALTH_PROFILES` | `false` | Enable stealth patches on profile (auth'd) sessions |
|
|
340
|
+
| `LEAP_CDP_STEALTH` | `true` | CDP detection evasion (`Runtime.enable` filtering) |
|
|
329
341
|
| `LEAP_HUMANIZE` | `false` | Experimental. Human-like mouse movement, typing cadence, and scroll behavior. |
|
|
330
342
|
| `LEAP_ALLOW_EXECUTE` | `true` | Allow the `execute` tool (sandboxed Playwright scripts) |
|
|
331
343
|
| `LEAP_BLOCK_LOCALHOST` | `false` | Block localhost/127.x.x.x (allowed by default for local dev) |
|
|
332
344
|
| `LEAP_PROFILES_DIR` | `~/.leapfrog/chrome-profiles` | Directory for persistent browser profiles |
|
|
333
345
|
| `LEAP_TILE` | `false` | Tile sessions in a grid (`true` \| `master` \| `false`) |
|
|
334
346
|
| `LEAP_TILE_PADDING` | `8` | Padding between tiled windows (px) |
|
|
347
|
+
| `LEAP_MULTI_TILE` | `false` | Multi-terminal tiling coordination across Leapfrog instances |
|
|
348
|
+
| `LEAP_SCREEN_WIDTH` | _(auto)_ | Explicit screen width for tiling calculations |
|
|
349
|
+
| `LEAP_SCREEN_HEIGHT` | _(auto)_ | Explicit screen height for tiling calculations |
|
|
335
350
|
| `LEAP_HUD` | `false` | Click ripple, zoom-to-target, scroll-to-target on agent actions |
|
|
336
|
-
| `LEAP_SOUND` | `false` | Marimba chime on intervention detection (macOS) |
|
|
337
|
-
| `LEAP_NOTIFY` | `false` | macOS notification center alerts on intervention detection |
|
|
338
351
|
| `LEAP_AUTO_CONSENT` | `true` | Auto-dismiss cookie consent banners (10 frameworks + fallback) |
|
|
339
352
|
| `LEAP_TRACE` | `false` | Per-session Playwright tracing (screenshots + DOM snapshots) |
|
|
340
353
|
| `LEAP_RECORD` | `false` | Session recording (action history export) |
|
|
341
|
-
| `
|
|
342
|
-
| `
|
|
354
|
+
| `LEAP_REBROWSER` | `false` | Enable Rebrowser integration |
|
|
355
|
+
| `LEAP_AUTO_WARM` | `false` | Auto-warm profiles by loading key URLs on session create |
|
|
343
356
|
| `LEAP_CAPTCHA_PROVIDER` | _(none)_ | External CAPTCHA solver: `capsolver` \| `2captcha` \| `nopecha` |
|
|
344
357
|
| `LEAP_CAPTCHA_API_KEY` | _(none)_ | API key for the configured CAPTCHA provider |
|
|
345
358
|
| `LEAP_MAX_SESSIONS_PER_CLIENT` | _(none)_ | Per-client session pool limit |
|
|
@@ -348,10 +361,10 @@ Leapfrog uses pond metaphors to keep things memorable. Your agent is the frog.
|
|
|
348
361
|
## Tests
|
|
349
362
|
|
|
350
363
|
```
|
|
351
|
-
|
|
364
|
+
769 passing across 31 suites
|
|
352
365
|
```
|
|
353
366
|
|
|
354
|
-
Session management, snapshot engine, network intelligence, tab management, security, SSRF protection, stealth patches (19), humanization (mouse, typing, scroll), page classification, harness intelligence, API intelligence, script executor, extended actions, HUD overlays, human intervention, cookie consent, domain knowledge,
|
|
367
|
+
Session management, snapshot engine, snapshot differ, network intelligence, tab management, security, SSRF protection, stealth patches (19), stealth enhanced, humanization (mouse, typing, scroll), page classification, harness intelligence, API intelligence, script executor, extended actions, HUD overlays, human intervention, cookie consent, domain knowledge, selector healing, stable elements, tile manager, bug regression, integration smoke, stress tests, benchmarks.
|
|
355
368
|
|
|
356
369
|
```bash
|
|
357
370
|
npm test
|
package/dist/index.js
CHANGED
|
@@ -49,7 +49,9 @@ const MAX_SNAPSHOT_CHARS = 10000;
|
|
|
49
49
|
const ALLOW_JS = process.env.LEAP_ALLOW_JS !== "false";
|
|
50
50
|
const ALLOW_EXECUTE = process.env.LEAP_ALLOW_EXECUTE !== "false";
|
|
51
51
|
const LEAP_PROFILES_DIR = process.env.LEAP_PROFILES_DIR ?? path.join(os.homedir(), ".leapfrog", "chrome-profiles");
|
|
52
|
-
|
|
52
|
+
// WORKAROUND: Claude Code on Windows does not pass mcp.json env vars to child process.
|
|
53
|
+
// Default to "grid" so tiling works out of the box on all platforms.
|
|
54
|
+
const LEAP_TILE = process.env.LEAP_TILE || "grid";
|
|
53
55
|
const LEAP_TILE_PADDING = Number(process.env.LEAP_TILE_PADDING ?? 8);
|
|
54
56
|
const LEAP_SCREEN_WIDTH = Number(process.env.LEAP_SCREEN_WIDTH || 0);
|
|
55
57
|
const LEAP_SCREEN_HEIGHT = Number(process.env.LEAP_SCREEN_HEIGHT || 0);
|
|
@@ -79,9 +81,10 @@ if (LEAP_TILE && LEAP_TILE !== "false") {
|
|
|
79
81
|
// Zero cost for single-terminal (just tracks one instance). No extra env var needed.
|
|
80
82
|
let tilesCoord = null;
|
|
81
83
|
if (LEAP_TILE && LEAP_TILE !== "false") {
|
|
82
|
-
// Screen size: prefer env vars, fall back to 1920x1080.
|
|
83
|
-
const
|
|
84
|
-
const
|
|
84
|
+
// Screen size: prefer env vars, then auto-detected screen, fall back to 1920x1080.
|
|
85
|
+
const detectedScreen = tileManager.getScreenSize();
|
|
86
|
+
const defaultW = LEAP_SCREEN_WIDTH > 0 ? LEAP_SCREEN_WIDTH : detectedScreen?.width ?? 1920;
|
|
87
|
+
const defaultH = LEAP_SCREEN_HEIGHT > 0 ? LEAP_SCREEN_HEIGHT : detectedScreen?.height ?? 1080;
|
|
85
88
|
tilesCoord = new TilesCoordinator(defaultW, defaultH);
|
|
86
89
|
// File watcher only needed for multi-terminal mode (multiple Leapfrog instances).
|
|
87
90
|
// In single-instance mode, the watcher causes spurious reflows that fight
|
|
@@ -3002,7 +3005,7 @@ function printConfig() {
|
|
|
3002
3005
|
const config = {
|
|
3003
3006
|
leapfrog: {
|
|
3004
3007
|
command: "npx",
|
|
3005
|
-
args: ["-y", "leapfrog"],
|
|
3008
|
+
args: ["-y", "leapfrog-mcp"],
|
|
3006
3009
|
env: {
|
|
3007
3010
|
LEAP_MAX_SESSIONS: "15",
|
|
3008
3011
|
},
|
package/dist/session-manager.js
CHANGED
|
@@ -288,10 +288,9 @@ export class SessionManager {
|
|
|
288
288
|
if (stealth.isEnabled()) {
|
|
289
289
|
launchArgs.push(...stealth.getLaunchArgs());
|
|
290
290
|
}
|
|
291
|
-
// Windows DPI:
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
291
|
+
// Windows DPI: --force-device-scale-factor=1 REMOVED
|
|
292
|
+
// On high-DPI Windows (250%), it renders content at 1x = unreadable tiny text.
|
|
293
|
+
// Let Chrome auto-detect DPI; CDP handles window positioning correctly without it.
|
|
295
294
|
// ── Window position args ───────────────────────────────────────
|
|
296
295
|
// When tiling: grid position. Otherwise: just place on the detected screen.
|
|
297
296
|
const screen = tileManager.getScreenSize();
|
|
@@ -578,6 +577,22 @@ export class SessionManager {
|
|
|
578
577
|
logger.warn("tile.position_failed", { error: e.message });
|
|
579
578
|
}
|
|
580
579
|
}
|
|
580
|
+
// ── Debounced reflow after creation (Windows only) ─────────────
|
|
581
|
+
// On Windows, launch args position each window for a grid that includes
|
|
582
|
+
// only the sessions created so far. Earlier windows end up at stale positions.
|
|
583
|
+
// Reflow all after a 500ms debounce so rapid batch creates settle into one reflow.
|
|
584
|
+
// Skipped on macOS where CDP reflow can move windows to the wrong screen.
|
|
585
|
+
if (process.platform === "win32" && tileManager.isEnabled() && this.sessions.size > 1) {
|
|
586
|
+
clearTimeout(globalThis.__leapReflowTimer);
|
|
587
|
+
globalThis.__leapReflowTimer = setTimeout(async () => {
|
|
588
|
+
try {
|
|
589
|
+
await tileManager.reflowAll(this.sessions);
|
|
590
|
+
}
|
|
591
|
+
catch (e) {
|
|
592
|
+
logger.warn("tile.reflow_after_create_failed", { error: e.message });
|
|
593
|
+
}
|
|
594
|
+
}, 500);
|
|
595
|
+
}
|
|
581
596
|
// ── Auto-reflow on external close ──────────────────────────────
|
|
582
597
|
// When the user manually closes a browser window (X button), clean up
|
|
583
598
|
// the session and reflow remaining tiled windows. Without this, closing
|
package/dist/tile-manager.d.ts
CHANGED
|
@@ -48,8 +48,8 @@ declare class TileManager {
|
|
|
48
48
|
*/
|
|
49
49
|
static detectTerminalScreen(): ScreenWorkArea | null;
|
|
50
50
|
/**
|
|
51
|
-
* Windows: detect
|
|
52
|
-
* Uses
|
|
51
|
+
* Windows: detect primary screen working area via PowerShell.
|
|
52
|
+
* Uses System.Windows.Forms.Screen — no DllImport, no escaping issues.
|
|
53
53
|
*/
|
|
54
54
|
static detectScreenViaPowershell(): ScreenWorkArea | null;
|
|
55
55
|
detectScreen(page: Page): Promise<ScreenWorkArea>;
|
package/dist/tile-manager.js
CHANGED
|
@@ -76,36 +76,12 @@ class TileManager {
|
|
|
76
76
|
return null;
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
|
-
* Windows: detect
|
|
80
|
-
* Uses
|
|
79
|
+
* Windows: detect primary screen working area via PowerShell.
|
|
80
|
+
* Uses System.Windows.Forms.Screen — no DllImport, no escaping issues.
|
|
81
81
|
*/
|
|
82
82
|
static detectScreenViaPowershell() {
|
|
83
83
|
try {
|
|
84
|
-
|
|
85
|
-
// 1. Get foreground window handle via user32.dll
|
|
86
|
-
// 2. Get window RECT via user32.dll
|
|
87
|
-
// 3. Find which Screen contains that RECT
|
|
88
|
-
// 4. Output WorkingArea (excludes taskbar) as "x y width height"
|
|
89
|
-
const script = `powershell -NoProfile -NonInteractive -Command "
|
|
90
|
-
Add-Type -AssemblyName System.Windows.Forms
|
|
91
|
-
Add-Type -TypeDefinition '
|
|
92
|
-
using System;
|
|
93
|
-
using System.Runtime.InteropServices;
|
|
94
|
-
public class WinAPI {
|
|
95
|
-
[DllImport(\\\"user32.dll\\\")] public static extern IntPtr GetForegroundWindow();
|
|
96
|
-
[DllImport(\\\"user32.dll\\\")] public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
|
|
97
|
-
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left, Top, Right, Bottom; }
|
|
98
|
-
}
|
|
99
|
-
'
|
|
100
|
-
$hwnd = [WinAPI]::GetForegroundWindow()
|
|
101
|
-
$rect = New-Object WinAPI+RECT
|
|
102
|
-
[void][WinAPI]::GetWindowRect($hwnd, [ref]$rect)
|
|
103
|
-
$pt = New-Object System.Drawing.Point($rect.Left, $rect.Top)
|
|
104
|
-
$scr = [System.Windows.Forms.Screen]::FromPoint($pt)
|
|
105
|
-
$wa = $scr.WorkingArea
|
|
106
|
-
Write-Output ('{0} {1} {2} {3}' -f $wa.X, $wa.Y, $wa.Width, $wa.Height)
|
|
107
|
-
"`;
|
|
108
|
-
const result = execSync(script, { timeout: 10000, encoding: "utf-8" }).trim();
|
|
84
|
+
const result = execSync('powershell -NoProfile -NonInteractive -Command "Add-Type -AssemblyName System.Windows.Forms; $wa = [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea; Write-Output ($wa.X.ToString() + \' \' + $wa.Y.ToString() + \' \' + $wa.Width.ToString() + \' \' + $wa.Height.ToString())"', { timeout: 10000, encoding: "utf-8" }).trim();
|
|
109
85
|
const parts = result.split(/\s+/).map(Number);
|
|
110
86
|
if (parts.length === 4 && parts.every((n) => !isNaN(n))) {
|
|
111
87
|
return { x: parts[0], y: parts[1], width: parts[2], height: parts[3] };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "leapfrog-mcp",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Multi-session browser MCP for AI agents — 36 tools, stealth, persistent auth, code-first scripts, API sniffer, agent intelligence",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
package/dist/adaptive-wait.d.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { Page } from "playwright-core";
|
|
2
|
-
import type { Session, SnapshotResult } from "./types.js";
|
|
3
|
-
import { type ClassificationResult } from "./page-classifier.js";
|
|
4
|
-
import type { SessionManager } from "./session-manager.js";
|
|
5
|
-
type WaitStrategy = "load" | "domcontentloaded" | "networkidle";
|
|
6
|
-
export interface AdaptiveNavigateOptions {
|
|
7
|
-
/** Wait strategy to start with. Default: "load" */
|
|
8
|
-
waitUntil?: WaitStrategy;
|
|
9
|
-
/** Enable auto-retry stealth escalation. Default: true */
|
|
10
|
-
autoRetry?: boolean;
|
|
11
|
-
/** Max escalation level (0-5). Default: 3 */
|
|
12
|
-
maxRetryLevel?: number;
|
|
13
|
-
/** Stealth mode override from bandit selection. Applied per-page via stealth.applyToPage(). */
|
|
14
|
-
stealthModeOverride?: 'off' | 'passive' | 'active';
|
|
15
|
-
/** Bandit arm index for this navigation (passed through for outcome tracking). */
|
|
16
|
-
banditArmIndex?: number;
|
|
17
|
-
}
|
|
18
|
-
export type PageQuality = "GOOD" | "EMPTY" | "TIMEOUT" | "BLOCKED";
|
|
19
|
-
export interface AdaptiveNavigateResult {
|
|
20
|
-
/** The snapshot result from the best attempt */
|
|
21
|
-
snapshot: SnapshotResult;
|
|
22
|
-
/** Page classification */
|
|
23
|
-
classification: ClassificationResult;
|
|
24
|
-
/** Final page URL after navigation */
|
|
25
|
-
url: string;
|
|
26
|
-
/** Page title */
|
|
27
|
-
title: string;
|
|
28
|
-
/** The page quality assessment */
|
|
29
|
-
quality: PageQuality;
|
|
30
|
-
/** Which waitUntil strategy succeeded */
|
|
31
|
-
finalStrategy: WaitStrategy;
|
|
32
|
-
/** Escalation metadata if stealth retries were used */
|
|
33
|
-
escalation?: EscalationMeta;
|
|
34
|
-
/** Bandit arm index used for this navigation (for outcome tracking) */
|
|
35
|
-
banditArmIndex?: number;
|
|
36
|
-
/** Stealth mode override applied by the bandit */
|
|
37
|
-
stealthModeOverride?: string;
|
|
38
|
-
/** The session that owns the page (may change if session was rotated) */
|
|
39
|
-
session: Session;
|
|
40
|
-
/** The page instance (may change if session was rotated) */
|
|
41
|
-
page: Page;
|
|
42
|
-
}
|
|
43
|
-
export interface EscalationMeta {
|
|
44
|
-
/** Level at which navigation succeeded (0-5) */
|
|
45
|
-
level: number;
|
|
46
|
-
/** Human-readable label for the level */
|
|
47
|
-
label: string;
|
|
48
|
-
/** Total retries attempted */
|
|
49
|
-
attempts: number;
|
|
50
|
-
/** Whether the session was rotated (Level 3+) */
|
|
51
|
-
sessionRotated: boolean;
|
|
52
|
-
/** New session ID if rotated */
|
|
53
|
-
newSessionId?: string;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Adaptive navigate: replaces the naive page.goto() in the navigate tool.
|
|
57
|
-
*
|
|
58
|
-
* 1. Tries the requested waitUntil strategy
|
|
59
|
-
* 2. Evaluates page quality (snapshot + classification)
|
|
60
|
-
* 3. Retries with alternative strategies if EMPTY/TIMEOUT
|
|
61
|
-
* 4. Escalates with stealth retries if BLOCKED/CHALLENGE
|
|
62
|
-
*
|
|
63
|
-
* Returns a rich result with snapshot, classification, escalation metadata,
|
|
64
|
-
* and the final session/page (which may differ if session was rotated).
|
|
65
|
-
*/
|
|
66
|
-
export declare function adaptiveNavigate(page: Page, session: Session, url: string, sessionManager: SessionManager, options?: AdaptiveNavigateOptions): Promise<AdaptiveNavigateResult>;
|
|
67
|
-
/**
|
|
68
|
-
* Format the AdaptiveNavigateResult into the text output for the MCP tool response.
|
|
69
|
-
* Matches the existing navigate output format with optional escalation metadata.
|
|
70
|
-
*/
|
|
71
|
-
export declare function formatAdaptiveResult(result: AdaptiveNavigateResult): string;
|
|
72
|
-
export {};
|