@querying/sneaky 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anymorph AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,160 @@
1
- # Temporary Holding Version
1
+ # `@querying/sneaky`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Unified stealth web automation & Chrome-stack HTTP suite by **anymorph-ai** — available as an **npm package (`@querying/sneaky`)**, **CLI (`sneaky`)**, **MCP server (stdio & Streamable HTTP)**, and **zero-dependency TypeScript/Go SDK**.
4
+
5
+ Use each capability **standalone** or **composed together** under one shared Persona, Proxy, and bidirectional Cookie Bridge (with local ↔ `querying.ai Browser` cloud parity).
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ # Run CLI or MCP with zero setup
11
+ npx @querying/sneaky doctor
12
+ npx @querying/sneaky probe https://example.com
13
+ npx @querying/sneaky mcp
14
+
15
+ # Or install globally for `sneaky` and `sneaky-mcp` commands
16
+ npm install -g @querying/sneaky
17
+
18
+ # Or add the SDK to a Node.js / TypeScript project (>= 22)
19
+ npm install @querying/sneaky
20
+ ```
21
+
22
+ Platform binaries (`@querying/sneaky-{darwin-arm64,darwin-x64,linux-x64,linux-arm64,win32-x64}`) are installed automatically via npm `optionalDependencies` (esbuild pattern) — no runtime download or compiler needed.
23
+
24
+ ## What's Inside
25
+
26
+ | Layer | Standalone Usage | Composed Usage (`Sneaky` / `sneaky serve`) |
27
+ |---|---|---|
28
+ | **Chrome-stack HTTP (`tfrd`)** | `sneaky fetch <url>` or `@querying/sneaky/request` (~32 KB/session, real BoringSSL/HTTP2/HTTP3) | Lazy HTTP lane inside a unified `Session` sharing Persona + Proxy + CookieJar |
29
+ | **Browser Persona & Flags** | `@querying/sneaky/browser` (`buildArgs`, `buildEnv`, `profileSeed`, zero Playwright dep) | Automatic `sneaky-browser` flag/fontconfig/proxy-auth launch + `Browser.humanized*` C++ input |
30
+ | **Zero-`Runtime.enable` Agent** | `@querying/sneaky/agent` or `@querying/sneaky/driver` (Playwright-aligned TS CDP driver) | Lazy Browser lane (`goto`, `snapshot`, `act`, `extract`, `network`, WS RPC) |
31
+ | **Bidirectional Cookie Bridge** | `sneaky cookies get\|sync` | Auto-syncs HTTP `Set-Cookie` (including 3xx redirects) → Browser CDP on promote, and Browser CDP cookies → HTTP `tfrd` |
32
+ | **MCP Server (stdio + HTTP)** | `npx -y @querying/sneaky mcp` or `sneaky-mcp` | Also mounted at `POST /mcp` on `sneaky serve` (Streamable HTTP MCP) |
33
+ | **Optional Captcha Hook** | External sidecar (`SNEAKY_CAPTCHA_URL`) or custom `CaptchaPlugin` | Zero ONNX/Playwright bloat in core binary; opt-in only |
34
+
35
+ Heavy engine/model builds remain in their dedicated repositories (`anymorph-ai/sneaky-browser`, `anymorph-ai/sneaky-request`, `anymorph-ai/sneaky-captcha`); `sneaky install` downloads version-pinned engine binaries with SHA-256 verification into `~/.sneaky/bin`.
36
+
37
+ ## MCP Setup (Claude Code, Codex, Cursor, Claude Desktop)
38
+
39
+ Print ready-to-paste config anytime:
40
+
41
+ ```bash
42
+ npx @querying/sneaky mcp config --client json # Claude Desktop / Cursor / Claude Code
43
+ npx @querying/sneaky mcp config --client codex # Codex ~/.codex/config.toml
44
+ npx @querying/sneaky mcp config --client http # Remote / local Streamable HTTP (/mcp)
45
+ ```
46
+
47
+ **Claude Desktop / Cursor / Claude Code (stdio):**
48
+
49
+ ```json
50
+ {
51
+ "mcpServers": {
52
+ "sneaky": {
53
+ "command": "npx",
54
+ "args": ["-y", "@querying/sneaky", "mcp"]
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ **Codex (`~/.codex/config.toml`):**
61
+
62
+ ```toml
63
+ [mcp_servers.sneaky]
64
+ command = "npx"
65
+ args = ["-y", "@querying/sneaky", "mcp"]
66
+ ```
67
+
68
+ **Streamable HTTP MCP (when running `sneaky serve`):**
69
+
70
+ ```bash
71
+ sneaky serve --listen 127.0.0.1:9333
72
+ # MCP endpoint available at http://127.0.0.1:9333/mcp
73
+ ```
74
+
75
+ ## TypeScript SDK (`@querying/sneaky`)
76
+
77
+ Zero runtime dependencies. Tree-shakable subpath exports let you import only what you need, or compose everything via the root client.
78
+
79
+ ### Zero-Config Managed Daemon (`Sneaky.start()`)
80
+
81
+ ```ts
82
+ import { Sneaky } from "@querying/sneaky";
83
+
84
+ const sneaky = await Sneaky.start(); // spawns bundled Go daemon on a free port
85
+ try {
86
+ const session = await sneaky.createSession({
87
+ mode: "auto", // lazy: neither tfrd nor Chromium starts until called
88
+ persona: { seed: 42, platform: "macos", locale: "ko-KR", tlsProfile: "chrome-146" },
89
+ proxyServer: "http://user:pass@proxy.example:8080",
90
+ });
91
+
92
+ await session.connectRPC(); // optional persistent WS RPC for both HTTP & browser calls
93
+
94
+ // 1. Fast Chrome-stack HTTP via tfrd (optional auto-escalation to browser on 403/503)
95
+ const res = await session.fetch("https://target.example/api", {
96
+ escalateOnStatus: [403, 503],
97
+ escalateMode: "retry",
98
+ });
99
+
100
+ // 2. Or explicitly drive the browser with the same Persona + Proxy + HTTP cookies
101
+ await session.goto("https://target.example/login", { returnSnapshot: true });
102
+ await session.fill("#email", "alice@example.com");
103
+ await session.click("button[type=submit]", { speed: "stealth" });
104
+
105
+ // 3. Pull cleared browser cookies back to fast tfrd HTTP lane
106
+ await session.syncBrowserToHttp();
107
+ const data = await session.fetch("https://target.example/api/me");
108
+
109
+ await session.close();
110
+ } finally {
111
+ await sneaky.stop();
112
+ }
113
+ ```
114
+
115
+ Pass `{ apiKey }` to `new Sneaky({ apiKey })` to target remote **`querying.ai Browser`** with the same API.
116
+
117
+ ### Standalone Subpath Imports
118
+
119
+ ```ts
120
+ // Standalone tfrd HTTP/WS client (no Chromium)
121
+ import { Daemon } from "@querying/sneaky/request";
122
+
123
+ // Standalone sneaky-browser persona flags, fontconfig & profileSeed (no Playwright)
124
+ import { buildArgs, buildEnv, profileSeed } from "@querying/sneaky/browser";
125
+
126
+ // Standalone zero-Runtime.enable agent client
127
+ import { SneakyAgent } from "@querying/sneaky/agent";
128
+
129
+ // Standalone Playwright-aligned zero-Runtime.enable CDP driver
130
+ import { chromium } from "@querying/sneaky/driver";
131
+
132
+ // Programmatic binary resolver & daemon launcher
133
+ import { resolveBinaryPath, startDaemon } from "@querying/sneaky/cli";
134
+ ```
135
+
136
+ ## CLI Quick Reference
137
+
138
+ ```bash
139
+ sneaky doctor # inspect detected Chrome/sneaky-browser & tfrd
140
+ sneaky install [all|browser|tfrd] # install pinned engine binaries into ~/.sneaky/bin
141
+ sneaky fetch https://example.com --locale ko-KR # standalone Chrome-stack HTTP via tfrd
142
+ sneaky probe https://example.com # one-shot browser probe (local or querying.ai cloud)
143
+ sneaky serve --listen 127.0.0.1:9333 # unified HTTP + WS RPC + Streamable HTTP MCP (/mcp)
144
+ sneaky mcp # stdio MCP server (13 unified tools)
145
+ ```
146
+
147
+ ## Building & Publishing npm Packages
148
+
149
+ ```bash
150
+ # Test Go + TS SDK locally
151
+ go vet ./...
152
+ go test -race -count=1 ./...
153
+ go build -o bin/sneaky ./cmd/sneaky
154
+ (cd sdk/ts && npm ci && npm run build && npm test)
155
+
156
+ # Cross-compile all 5 platform packages + assembled @querying/sneaky into dist-npm/
157
+ node scripts/build-npm-packages.mjs --version 0.1.0
158
+ ```
159
+
160
+ Pushing a `v*` tag triggers [`.github/workflows/release.yml`](.github/workflows/release.yml), which cross-compiles all 5 platform binaries, attaches checksums to a GitHub Release, and publishes `@querying/sneaky-*` + `@querying/sneaky` to npm when `NPM_TOKEN` is configured.
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { resolveBinaryPath } from "../dist/cli/index.js";
4
+
5
+ let bin;
6
+ try {
7
+ bin = resolveBinaryPath();
8
+ } catch (err) {
9
+ console.error(`sneaky-mcp: ${err instanceof Error ? err.message : String(err)}`);
10
+ process.exit(1);
11
+ }
12
+
13
+ const child = spawn(bin, ["mcp", ...process.argv.slice(2)], { stdio: "inherit" });
14
+
15
+ for (const sig of ["SIGINT", "SIGTERM"]) {
16
+ process.on(sig, () => {
17
+ try {
18
+ child.kill(sig);
19
+ } catch {
20
+ // Ignore if child already exited.
21
+ }
22
+ });
23
+ }
24
+
25
+ child.on("error", (err) => {
26
+ console.error(`sneaky-mcp: failed to launch ${bin}: ${err.message}`);
27
+ process.exit(1);
28
+ });
29
+
30
+ child.on("exit", (code, signal) => {
31
+ if (signal) {
32
+ process.kill(process.pid, signal);
33
+ return;
34
+ }
35
+ process.exit(code ?? 1);
36
+ });
package/bin/sneaky.mjs ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { resolveBinaryPath } from "../dist/cli/index.js";
4
+
5
+ let bin;
6
+ try {
7
+ bin = resolveBinaryPath();
8
+ } catch (err) {
9
+ console.error(`sneaky: ${err instanceof Error ? err.message : String(err)}`);
10
+ process.exit(1);
11
+ }
12
+
13
+ const child = spawn(bin, process.argv.slice(2), { stdio: "inherit" });
14
+
15
+ for (const sig of ["SIGINT", "SIGTERM"]) {
16
+ process.on(sig, () => {
17
+ try {
18
+ child.kill(sig);
19
+ } catch {
20
+ // Ignore if child already exited.
21
+ }
22
+ });
23
+ }
24
+
25
+ child.on("error", (err) => {
26
+ console.error(`sneaky: failed to launch ${bin}: ${err.message}`);
27
+ process.exit(1);
28
+ });
29
+
30
+ child.on("exit", (code, signal) => {
31
+ if (signal) {
32
+ process.kill(process.pid, signal);
33
+ return;
34
+ }
35
+ process.exit(code ?? 1);
36
+ });
@@ -0,0 +1,275 @@
1
+ export type SnapshotMode = "interactive" | "compact" | "full";
2
+ export type SnapshotSource = "dom" | "ax";
3
+ export type ActionSpeed = "fast" | "natural" | "stealth";
4
+ export type WaitUntil = "commit" | "domcontentloaded" | "load" | "networkidle";
5
+ export type ExtractKind = "markdown" | "text" | "html" | "links" | "json_ld";
6
+ export type BlockResourceType = "image" | "font" | "media" | "stylesheet";
7
+ export declare const DEFAULT_LOCAL_URL = "http://127.0.0.1:9333";
8
+ export declare const DEFAULT_REMOTE_URL = "https://api.querying.ai/browser";
9
+ export declare class SneakyError extends Error {
10
+ readonly status: number;
11
+ readonly code: string;
12
+ readonly extra?: Record<string, unknown> | undefined;
13
+ constructor(message: string, status: number, code: string, extra?: Record<string, unknown> | undefined);
14
+ }
15
+ export interface SneakyAgentOptions {
16
+ /** Local daemon URL or remote querying.ai Browser URL. Defaults to remote when apiKey is set, otherwise local. */
17
+ baseUrl?: string;
18
+ /** Optional querying.ai vt_ API key for remote cloud sessions. */
19
+ apiKey?: string;
20
+ timeoutMs?: number;
21
+ fetch?: typeof fetch;
22
+ }
23
+ export interface CreateSessionOptions {
24
+ headless?: boolean;
25
+ stealth?: boolean;
26
+ country?: string;
27
+ proxyServer?: string;
28
+ userDataDir?: string;
29
+ viewport?: {
30
+ width: number;
31
+ height: number;
32
+ };
33
+ url?: string;
34
+ }
35
+ export interface SessionInfo {
36
+ session_id: string;
37
+ cdp_ws_url?: string;
38
+ browser_live_view_url?: string;
39
+ headless?: boolean;
40
+ stealth?: boolean;
41
+ [key: string]: unknown;
42
+ }
43
+ export interface Target {
44
+ ref?: string;
45
+ snapshot_id?: string;
46
+ selector?: string;
47
+ role?: string;
48
+ name?: string;
49
+ text?: string;
50
+ exact?: boolean;
51
+ nth?: number;
52
+ x?: number;
53
+ y?: number;
54
+ }
55
+ export type TargetInput = string | Target;
56
+ export interface Action {
57
+ type: "click" | "dblclick" | "hover" | "fill" | "type" | "press" | "select" | "scroll" | "wait" | "extract" | "navigate" | "back" | "forward" | "reload";
58
+ target?: Target;
59
+ text?: string;
60
+ value?: string;
61
+ label?: string;
62
+ key?: string;
63
+ url?: string;
64
+ wait_until?: WaitUntil;
65
+ button?: "left" | "right" | "middle";
66
+ click_count?: number;
67
+ clear?: boolean;
68
+ speed?: ActionSpeed;
69
+ humanize?: boolean;
70
+ dx?: number;
71
+ dy?: number;
72
+ timeout_ms?: number;
73
+ wait_ms?: number;
74
+ url_contains?: string;
75
+ }
76
+ export interface PageMeta {
77
+ url: string;
78
+ title: string;
79
+ ready_state: string;
80
+ viewport: {
81
+ width: number;
82
+ height: number;
83
+ };
84
+ scroll: {
85
+ x: number;
86
+ y: number;
87
+ width: number;
88
+ height: number;
89
+ };
90
+ active_tag?: string;
91
+ }
92
+ export interface SnapshotRef {
93
+ ref: string;
94
+ role: string;
95
+ name?: string;
96
+ value?: string;
97
+ states?: Record<string, unknown>;
98
+ }
99
+ export interface SnapshotDiff {
100
+ base_snapshot_id: string;
101
+ added?: string[];
102
+ removed?: string[];
103
+ unchanged_count: number;
104
+ }
105
+ export interface SnapshotResult {
106
+ snapshot_id: string;
107
+ mode: SnapshotMode;
108
+ source?: SnapshotSource;
109
+ page: PageMeta;
110
+ tree?: string;
111
+ refs: Record<string, SnapshotRef>;
112
+ ref_count: number;
113
+ truncated: boolean;
114
+ diff?: SnapshotDiff;
115
+ screenshot?: string;
116
+ }
117
+ export interface ActOptions {
118
+ returnSnapshot?: boolean;
119
+ snapshotMode?: SnapshotMode;
120
+ snapshotSource?: SnapshotSource;
121
+ diffFrom?: string;
122
+ diffFromLast?: boolean;
123
+ settleMs?: number;
124
+ screenshot?: boolean;
125
+ speed?: ActionSpeed;
126
+ humanize?: boolean;
127
+ timeoutMs?: number;
128
+ }
129
+ export interface ActResult {
130
+ ok: boolean;
131
+ failed_step?: number;
132
+ results: Array<{
133
+ index: number;
134
+ type: string;
135
+ ok: boolean;
136
+ duration_ms: number;
137
+ data?: Record<string, unknown>;
138
+ error?: string;
139
+ code?: string;
140
+ }>;
141
+ page: PageMeta;
142
+ snapshot?: SnapshotResult;
143
+ }
144
+ export interface NetworkEntry {
145
+ seq: number;
146
+ request_id: string;
147
+ method: string;
148
+ url: string;
149
+ resource_type: string;
150
+ status?: number;
151
+ mime_type?: string;
152
+ duration_ms?: number;
153
+ encoded_bytes?: number;
154
+ failed?: boolean;
155
+ error_text?: string;
156
+ request_headers?: Record<string, string>;
157
+ response_headers?: Record<string, string>;
158
+ body_available: boolean;
159
+ body?: string;
160
+ }
161
+ export declare function parseTarget(input: TargetInput): Target;
162
+ export declare class SneakyAgent {
163
+ readonly baseUrl: string;
164
+ private readonly apiKey?;
165
+ private readonly timeoutMs;
166
+ private readonly fetchImpl;
167
+ constructor(options?: SneakyAgentOptions);
168
+ request<T>(method: "GET" | "POST" | "DELETE", path: string, options?: {
169
+ body?: unknown;
170
+ query?: Record<string, string | number | undefined>;
171
+ }): Promise<T>;
172
+ create(options?: CreateSessionOptions): Promise<Session>;
173
+ attach(sessionId: string): Session;
174
+ list(): Promise<SessionInfo[]>;
175
+ close(sessionId: string): Promise<void>;
176
+ }
177
+ export declare class Session {
178
+ private readonly client;
179
+ readonly id: string;
180
+ readonly info?: SessionInfo | undefined;
181
+ readonly network: Network;
182
+ private rpcWs?;
183
+ private rpcSeq;
184
+ private rpcPending;
185
+ constructor(client: SneakyAgent, id: string, info?: SessionInfo | undefined);
186
+ private p;
187
+ /** Open a persistent multiplexed WebSocket RPC channel to eliminate per-call HTTP overhead. */
188
+ connectRPC(): Promise<void>;
189
+ private callRPC;
190
+ private tryCallRPC;
191
+ private invoke;
192
+ goto(url: string, options?: {
193
+ waitUntil?: WaitUntil;
194
+ timeoutMs?: number;
195
+ returnSnapshot?: boolean;
196
+ snapshotMode?: SnapshotMode;
197
+ }): Promise<{
198
+ url: string;
199
+ title: string;
200
+ ready_state: string;
201
+ duration_ms: number;
202
+ snapshot?: SnapshotResult;
203
+ }>;
204
+ snapshot(options?: {
205
+ mode?: SnapshotMode;
206
+ source?: SnapshotSource;
207
+ diffFrom?: string;
208
+ maxNodes?: number;
209
+ maxChars?: number;
210
+ screenshot?: boolean;
211
+ }): Promise<SnapshotResult>;
212
+ act(actions: Action | Action[], options?: ActOptions): Promise<ActResult>;
213
+ click(target: TargetInput, options?: ActOptions): Promise<ActResult>;
214
+ fill(target: TargetInput, text: string, options?: ActOptions & {
215
+ clear?: boolean;
216
+ }): Promise<ActResult>;
217
+ press(key: string, options?: ActOptions): Promise<ActResult>;
218
+ locator(selector: string): Locator;
219
+ getByRole(role: string, options?: {
220
+ name?: string;
221
+ exact?: boolean;
222
+ }): Locator;
223
+ getByText(text: string, options?: {
224
+ exact?: boolean;
225
+ }): Locator;
226
+ extract(options?: {
227
+ kind?: ExtractKind;
228
+ target?: TargetInput;
229
+ maxChars?: number;
230
+ }): Promise<Record<string, unknown>>;
231
+ close(): Promise<void>;
232
+ }
233
+ export declare class Locator {
234
+ private readonly session;
235
+ private readonly target;
236
+ constructor(session: Session, target: Target);
237
+ first(): Locator;
238
+ last(): Locator;
239
+ nth(index: number): Locator;
240
+ click(options?: ActOptions): Promise<ActResult>;
241
+ fill(text: string, options?: ActOptions & {
242
+ clear?: boolean;
243
+ }): Promise<ActResult>;
244
+ }
245
+ export declare class Network {
246
+ private readonly client;
247
+ private readonly sessionId;
248
+ private readonly tryRPC?;
249
+ constructor(client: SneakyAgent, sessionId: string, tryRPC?: (<T>(method: string, params: unknown) => Promise<T> | undefined) | undefined);
250
+ private p;
251
+ capture(options?: {
252
+ enabled?: boolean;
253
+ resourceTypes?: string[];
254
+ urlContains?: string;
255
+ captureBodies?: boolean;
256
+ blockResourceTypes?: BlockResourceType[];
257
+ }): Promise<{
258
+ enabled: boolean;
259
+ blocked_urls?: number;
260
+ }>;
261
+ list(filter?: {
262
+ resourceType?: string;
263
+ method?: string;
264
+ urlContains?: string;
265
+ limit?: number;
266
+ }): Promise<{
267
+ enabled: boolean;
268
+ count: number;
269
+ requests: NetworkEntry[];
270
+ }>;
271
+ get(requestId: string): Promise<NetworkEntry>;
272
+ clear(): Promise<{
273
+ cleared: boolean;
274
+ }>;
275
+ }