foxfetch 0.1.0__py3-none-any.whl
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.
- foxfetch/__init__.py +5 -0
- foxfetch/__main__.py +3 -0
- foxfetch/cli.py +80 -0
- foxfetch/config.py +56 -0
- foxfetch/contexts.py +235 -0
- foxfetch/doctor.py +217 -0
- foxfetch/engine.py +502 -0
- foxfetch/probe.py +187 -0
- foxfetch/server.py +160 -0
- foxfetch/shapes.py +172 -0
- foxfetch-0.1.0.dist-info/METADATA +171 -0
- foxfetch-0.1.0.dist-info/RECORD +15 -0
- foxfetch-0.1.0.dist-info/WHEEL +4 -0
- foxfetch-0.1.0.dist-info/entry_points.txt +2 -0
- foxfetch-0.1.0.dist-info/licenses/LICENSE +24 -0
foxfetch/server.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""MCP entry point: stdio server exposing the foxfetch tools.
|
|
2
|
+
|
|
3
|
+
One service serves every client (Pi, Claude Code, Codex, DSH via its MCP client).
|
|
4
|
+
The protocol carries request ids, so a stray line of output can no longer desync a
|
|
5
|
+
call — the failure mode the old line-based bridge had to patch around.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import logging
|
|
12
|
+
import sys
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from mcp.server.fastmcp import FastMCP
|
|
16
|
+
|
|
17
|
+
from . import engine
|
|
18
|
+
from .config import SETTINGS
|
|
19
|
+
from .contexts import POOL
|
|
20
|
+
from .doctor import doctor as run_doctor
|
|
21
|
+
|
|
22
|
+
INSTRUCTIONS = """Use foxfetch only when a page cannot be read over plain HTTP.
|
|
23
|
+
|
|
24
|
+
Decision order (cheapest first):
|
|
25
|
+
1. Try a plain HTTP request. If the document comes back complete, stop there.
|
|
26
|
+
2. If it is blocked or empty, call `probe` — it reports the evidence (status, marker,
|
|
27
|
+
size) and tells you which layer the page needs.
|
|
28
|
+
3. `run` executes JavaScript in a real Firefox engine (SpiderMonkey + Necko, no window,
|
|
29
|
+
no renderer) and keeps the page alive between calls on the same origin.
|
|
30
|
+
4. `handoff` exports cookies, localStorage and the user agent, and writes a Playwright
|
|
31
|
+
script when Chromium is installed. Use it only when a screenshot or a click is needed.
|
|
32
|
+
|
|
33
|
+
The engine cannot screenshot, click, scroll or report layout — hand those to Chromium.
|
|
34
|
+
Contexts die on idle, on `close`, or when the pool evicts the least recently used one.
|
|
35
|
+
Artifacts under FOXFETCH_HOME (default: local app data / foxfetch) hold live credentials:
|
|
36
|
+
call `cleanup` after delivering results, and pass `keep` for files the user still needs.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
mcp = FastMCP("foxfetch", instructions=INSTRUCTIONS)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _json(payload: dict[str, Any]) -> str:
|
|
43
|
+
return json.dumps(payload, ensure_ascii=False)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@mcp.tool()
|
|
47
|
+
def probe(url: str, timeout_s: float = 15.0) -> str:
|
|
48
|
+
"""Check a URL over plain HTTP and say which layer it needs.
|
|
49
|
+
|
|
50
|
+
Returns verdict = plain_http | needs_engine | blocked, with the evidence that led
|
|
51
|
+
there (HTTP status, matched bot-check markers, body size, empty mount points).
|
|
52
|
+
Call this before `run`: most pages do not need a browser engine at all.
|
|
53
|
+
"""
|
|
54
|
+
from .probe import probe as _probe
|
|
55
|
+
|
|
56
|
+
return _json(_probe(url, timeout_s))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@mcp.tool()
|
|
60
|
+
def run(
|
|
61
|
+
js: str,
|
|
62
|
+
url: str | None = None,
|
|
63
|
+
context_id: str | None = None,
|
|
64
|
+
advance_ms: int | None = None,
|
|
65
|
+
read: str | None = None,
|
|
66
|
+
proxy: str | None = None,
|
|
67
|
+
fingerprint: dict[str, Any] | None = None,
|
|
68
|
+
timeout_ms: int | None = None,
|
|
69
|
+
max_bytes: int | None = None,
|
|
70
|
+
) -> str:
|
|
71
|
+
"""Run JavaScript in a real Firefox engine and return its value.
|
|
72
|
+
|
|
73
|
+
Pass `url` to open the page (an existing context for that origin is reused). Omit it
|
|
74
|
+
to keep working in the session's live context. `advance_ms` lets timers, fetch and
|
|
75
|
+
promises settle; `read` is evaluated afterwards and its value is what you get back.
|
|
76
|
+
Variables and the loaded page persist between calls on the same origin, so split a
|
|
77
|
+
multi-step flow instead of writing one huge script.
|
|
78
|
+
"""
|
|
79
|
+
return _json(
|
|
80
|
+
engine.run(
|
|
81
|
+
js,
|
|
82
|
+
url=url,
|
|
83
|
+
context_id=context_id,
|
|
84
|
+
advance_ms=advance_ms,
|
|
85
|
+
read=read,
|
|
86
|
+
proxy=proxy,
|
|
87
|
+
fingerprint=fingerprint,
|
|
88
|
+
timeout_ms=timeout_ms,
|
|
89
|
+
max_bytes=max_bytes,
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@mcp.tool()
|
|
95
|
+
def net(url: str | None = None, context_id: str | None = None, count: int = 50) -> str:
|
|
96
|
+
"""Read the request log and console records of a live context, without new requests."""
|
|
97
|
+
return _json(engine.net(url=url, context_id=context_id, count=count))
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@mcp.tool()
|
|
101
|
+
def handoff(
|
|
102
|
+
url: str | None = None,
|
|
103
|
+
context_id: str | None = None,
|
|
104
|
+
keys: list[str] | None = None,
|
|
105
|
+
max_bytes: int | None = None,
|
|
106
|
+
) -> str:
|
|
107
|
+
"""Export the context's identity (cookies including HttpOnly, localStorage, UA).
|
|
108
|
+
|
|
109
|
+
Writes a ready-to-run Playwright script when Chromium is installed; otherwise it still
|
|
110
|
+
returns the identity and says what is missing. These values are live credentials.
|
|
111
|
+
"""
|
|
112
|
+
return _json(engine.handoff(url=url, context_id=context_id, keys=keys, max_bytes=max_bytes))
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@mcp.tool()
|
|
116
|
+
def close(url: str | None = None, context_id: str | None = None) -> str:
|
|
117
|
+
"""Close one context (by id or origin) or every context when neither is given."""
|
|
118
|
+
return _json(engine.close(url=url, context_id=context_id))
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@mcp.tool()
|
|
122
|
+
def cleanup(scope: str = "all", keep: list[str] | None = None) -> str:
|
|
123
|
+
"""Delete the artifacts this run produced and/or close live contexts.
|
|
124
|
+
|
|
125
|
+
scope = artifacts | contexts | all. Paths listed in `keep` survive (redirect the
|
|
126
|
+
screenshot or token the user still needs). Also sweeps Playwright and Chromium
|
|
127
|
+
scratch directories left in the temp path.
|
|
128
|
+
"""
|
|
129
|
+
return _json(engine.cleanup(scope=scope, keep=keep))
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@mcp.tool()
|
|
133
|
+
def status() -> str:
|
|
134
|
+
"""Report live contexts, artifact usage and the environment check (python, ruyijs, mcp, chromium)."""
|
|
135
|
+
payload = engine.inventory()
|
|
136
|
+
payload["doctor"] = run_doctor()
|
|
137
|
+
return _json(payload)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _configure_logging() -> None:
|
|
141
|
+
"""stdout belongs to the protocol: every log line goes to stderr."""
|
|
142
|
+
logging.basicConfig(stream=sys.stderr, level=logging.INFO, format="[foxfetch] %(levelname)s %(message)s")
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def main() -> None:
|
|
146
|
+
_configure_logging()
|
|
147
|
+
logging.getLogger("foxfetch").info(
|
|
148
|
+
"starting: contexts=%s idle=%ss artifacts=%s",
|
|
149
|
+
SETTINGS.max_contexts,
|
|
150
|
+
SETTINGS.idle_seconds,
|
|
151
|
+
SETTINGS.artifacts,
|
|
152
|
+
)
|
|
153
|
+
try:
|
|
154
|
+
mcp.run(transport="stdio")
|
|
155
|
+
finally:
|
|
156
|
+
POOL.shutdown()
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
if __name__ == "__main__":
|
|
160
|
+
main()
|
foxfetch/shapes.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"""Value shaping shared by every tool: clipping, artifact spill, uniform failures.
|
|
2
|
+
|
|
3
|
+
The clip path is byte-budgeted but never splits a UTF-8 sequence. The previous
|
|
4
|
+
implementation sliced the encoded bytes and decoded the fragment, which turned any
|
|
5
|
+
truncated Chinese text into a trailing U+FFFD replacement character.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import os
|
|
12
|
+
import time
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Any, Iterable
|
|
15
|
+
|
|
16
|
+
from .config import SETTINGS
|
|
17
|
+
|
|
18
|
+
ERROR_KINDS = ("js", "timeout", "nav", "env", "context", "protocol", "internal")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def dumps(value: Any) -> str:
|
|
22
|
+
"""JSON text for a value that may hold non-serialisable leaves."""
|
|
23
|
+
try:
|
|
24
|
+
return json.dumps(value, ensure_ascii=False, default=lambda o: repr(o))
|
|
25
|
+
except (TypeError, ValueError):
|
|
26
|
+
return repr(value)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def as_text(value: Any) -> str:
|
|
30
|
+
return value if isinstance(value, str) else dumps(value)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def clip_text(text: str, max_bytes: int) -> tuple[str, bool, int]:
|
|
34
|
+
"""Cut `text` to at most `max_bytes` UTF-8 bytes on a character boundary.
|
|
35
|
+
|
|
36
|
+
Returns (text, truncated, original_bytes). Decoding from the raw prefix with
|
|
37
|
+
`errors="ignore"` drops the partial trailing sequence instead of emitting U+FFFD.
|
|
38
|
+
"""
|
|
39
|
+
raw = text.encode("utf-8")
|
|
40
|
+
if len(raw) <= max_bytes:
|
|
41
|
+
return text, False, len(raw)
|
|
42
|
+
cut = raw[:max_bytes].decode("utf-8", "ignore")
|
|
43
|
+
return cut, True, len(raw)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def tail(items: Iterable[Any] | None, count: int) -> list[Any]:
|
|
47
|
+
if not isinstance(items, (list, tuple)):
|
|
48
|
+
return []
|
|
49
|
+
return list(items[-count:]) if count > 0 else []
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def ensure_artifacts_dir() -> Path:
|
|
53
|
+
path = SETTINGS.artifacts
|
|
54
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
55
|
+
_restrict(path)
|
|
56
|
+
return path
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _restrict(path: Path) -> None:
|
|
60
|
+
"""Best-effort: owner-only. Credentials pass through these files."""
|
|
61
|
+
try:
|
|
62
|
+
if os.name == "nt":
|
|
63
|
+
# Windows inherits the user profile ACL; the explicit icacls call keeps
|
|
64
|
+
# Administrators/System but removes inherited broader grants.
|
|
65
|
+
import subprocess
|
|
66
|
+
|
|
67
|
+
subprocess.run(
|
|
68
|
+
["icacls", str(path), "/inheritance:r", "/grant:r", f"{os.environ.get('USERNAME')}:(OI)(CI)F"],
|
|
69
|
+
capture_output=True,
|
|
70
|
+
timeout=10,
|
|
71
|
+
check=False,
|
|
72
|
+
creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0),
|
|
73
|
+
)
|
|
74
|
+
else:
|
|
75
|
+
os.chmod(path, 0o700)
|
|
76
|
+
except Exception:
|
|
77
|
+
pass
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def spill(label: str, text: str) -> str:
|
|
81
|
+
"""Write oversize output to an artifact file and return its path."""
|
|
82
|
+
directory = ensure_artifacts_dir()
|
|
83
|
+
stamp = time.strftime("%Y%m%d-%H%M%S", time.localtime())
|
|
84
|
+
safe = "".join(ch if ch.isalnum() or ch in "-_" else "-" for ch in label)[:40]
|
|
85
|
+
path = directory / f"{stamp}-{os.getpid()}-{safe}.txt"
|
|
86
|
+
path.write_text(text, encoding="utf-8")
|
|
87
|
+
prune_artifacts()
|
|
88
|
+
return str(path)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def prune_artifacts(protect: Iterable[str] = ()) -> dict[str, int]:
|
|
92
|
+
"""Drop artifacts past their TTL, then the oldest until the byte budget fits."""
|
|
93
|
+
directory = SETTINGS.artifacts
|
|
94
|
+
if not directory.is_dir():
|
|
95
|
+
return {"removed": 0, "freed": 0}
|
|
96
|
+
keep = {os.path.abspath(p) for p in protect}
|
|
97
|
+
cutoff = time.time() - SETTINGS.artifact_ttl_seconds
|
|
98
|
+
entries: list[tuple[float, int, str]] = []
|
|
99
|
+
removed = freed = 0
|
|
100
|
+
for entry in directory.iterdir():
|
|
101
|
+
try:
|
|
102
|
+
if not entry.is_file():
|
|
103
|
+
continue
|
|
104
|
+
stat = entry.stat()
|
|
105
|
+
except OSError:
|
|
106
|
+
continue
|
|
107
|
+
absolute = os.path.abspath(entry)
|
|
108
|
+
if absolute in keep:
|
|
109
|
+
continue
|
|
110
|
+
if stat.st_mtime < cutoff:
|
|
111
|
+
try:
|
|
112
|
+
entry.unlink()
|
|
113
|
+
removed += 1
|
|
114
|
+
freed += stat.st_size
|
|
115
|
+
continue
|
|
116
|
+
except OSError:
|
|
117
|
+
continue
|
|
118
|
+
entries.append((stat.st_mtime, stat.st_size, str(entry)))
|
|
119
|
+
|
|
120
|
+
total = sum(size for _, size, _ in entries) + freed
|
|
121
|
+
if total <= SETTINGS.artifact_max_bytes:
|
|
122
|
+
return {"removed": removed, "freed": freed}
|
|
123
|
+
for _, size, path in sorted(entries):
|
|
124
|
+
if total <= SETTINGS.artifact_max_bytes:
|
|
125
|
+
break
|
|
126
|
+
try:
|
|
127
|
+
os.unlink(path)
|
|
128
|
+
removed += 1
|
|
129
|
+
freed += size
|
|
130
|
+
total -= size
|
|
131
|
+
except OSError:
|
|
132
|
+
continue
|
|
133
|
+
return {"removed": removed, "freed": freed}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def purge_artifacts(protect: Iterable[str] = ()) -> dict[str, int]:
|
|
137
|
+
"""Delete every artifact except the protected ones, regardless of age.
|
|
138
|
+
|
|
139
|
+
`prune_artifacts` enforces a policy (TTL, byte budget); this is the explicit "I am done"
|
|
140
|
+
call, so a file written a minute ago is removed too — that is the whole point of cleanup.
|
|
141
|
+
"""
|
|
142
|
+
directory = SETTINGS.artifacts
|
|
143
|
+
keep = {os.path.abspath(p) for p in protect}
|
|
144
|
+
removed = freed = 0
|
|
145
|
+
if not directory.is_dir():
|
|
146
|
+
return {"removed": 0, "freed": 0}
|
|
147
|
+
for entry in directory.iterdir():
|
|
148
|
+
try:
|
|
149
|
+
if not entry.is_file() or os.path.abspath(entry) in keep:
|
|
150
|
+
continue
|
|
151
|
+
size = entry.stat().st_size
|
|
152
|
+
except OSError:
|
|
153
|
+
continue
|
|
154
|
+
try:
|
|
155
|
+
entry.unlink()
|
|
156
|
+
removed += 1
|
|
157
|
+
freed += size
|
|
158
|
+
except OSError:
|
|
159
|
+
continue
|
|
160
|
+
return {"removed": removed, "freed": freed}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def failure(message: str, *, kind: str = "internal", **extra: Any) -> dict[str, Any]:
|
|
164
|
+
"""Uniform failure payload, so an agent can branch on `error_kind` alone."""
|
|
165
|
+
payload: dict[str, Any] = {
|
|
166
|
+
"ok": False,
|
|
167
|
+
"error": message,
|
|
168
|
+
"error_kind": kind if kind in ERROR_KINDS else "internal",
|
|
169
|
+
"text": "",
|
|
170
|
+
}
|
|
171
|
+
payload.update(extra)
|
|
172
|
+
return payload
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: foxfetch
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fetch pages through a real Firefox engine (ruyijs) for AI agents: pass bot checks, run the page's own JavaScript, then hand the identity to Chromium when a screenshot is needed.
|
|
5
|
+
Project-URL: Homepage, https://github.com/zhuchongba-01/foxfetch
|
|
6
|
+
Project-URL: Repository, https://github.com/zhuchongba-01/foxfetch
|
|
7
|
+
Project-URL: Issues, https://github.com/zhuchongba-01/foxfetch/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/zhuchongba-01/foxfetch/commits/master
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026 foxfetch contributors
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
|
|
31
|
+
Note: `ruyijs`, the Firefox engine this package drives, is a separate project
|
|
32
|
+
under AGPL-3.0. foxfetch only imports and calls it; no ruyijs code is bundled.
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
Keywords: agent,anti-bot,firefox,mcp,playwright,ruyijs,scraping
|
|
35
|
+
Classifier: Environment :: Console
|
|
36
|
+
Classifier: Intended Audience :: Developers
|
|
37
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
38
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
39
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
40
|
+
Classifier: Programming Language :: Python :: 3
|
|
41
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
|
|
42
|
+
Requires-Python: >=3.10
|
|
43
|
+
Requires-Dist: mcp<2,>=1.30
|
|
44
|
+
Requires-Dist: ruyijs>=0.4.5
|
|
45
|
+
Provides-Extra: dev
|
|
46
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
47
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
48
|
+
Description-Content-Type: text/markdown
|
|
49
|
+
|
|
50
|
+
# foxfetch
|
|
51
|
+
|
|
52
|
+
**Read a page the way a browser does — only when plain HTTP is not enough.**
|
|
53
|
+
|
|
54
|
+
foxfetch drives a real Firefox engine (SpiderMonkey + Necko, no window, no renderer) to run
|
|
55
|
+
a site's own JavaScript: pass a bot check, read a DOM that only exists after the scripts run,
|
|
56
|
+
find the signature and the real API host. When a screenshot or a click is needed, it hands
|
|
57
|
+
the identity it earned to Chromium.
|
|
58
|
+
|
|
59
|
+
It speaks the Model Context Protocol, so one service serves every agent host — Pi, Claude
|
|
60
|
+
Code, Codex, DeepSeek Harness.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## The rule that saves the most time
|
|
65
|
+
|
|
66
|
+
| Situation | Use |
|
|
67
|
+
|---|---|
|
|
68
|
+
| Static HTML, JSON endpoints, RSS | **plain HTTP** — do not call foxfetch |
|
|
69
|
+
| Content appears after JS runs | `run` |
|
|
70
|
+
| 403 / Cloudflare / DataDome / Kasada | `probe`, then `run` |
|
|
71
|
+
| Someone needs to *see* the page | `handoff` → the generated Playwright script |
|
|
72
|
+
|
|
73
|
+
`probe` answers the first two questions with evidence, so the choice is not a guess:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
probe("https://shop.example/item")
|
|
77
|
+
→ verdict: blocked
|
|
78
|
+
evidence: HTTP 403, DataDome (matched 'datadome'), 512 bytes, 0 visible text
|
|
79
|
+
suggestion: use run — the engine's TLS and JS profile match a real Firefox
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Most pages do not need the engine. Reaching for it anyway costs ~90 MB of RAM and ~3 s per
|
|
83
|
+
open, and buys nothing on a document `curl` could have fetched.
|
|
84
|
+
|
|
85
|
+
## Tools
|
|
86
|
+
|
|
87
|
+
| Tool | What it does |
|
|
88
|
+
|---|---|
|
|
89
|
+
| `probe` | Classify a URL: `plain_http` / `needs_engine` / `blocked`, with the evidence |
|
|
90
|
+
| `run` | Evaluate JavaScript in the engine; returns the value, console and request log |
|
|
91
|
+
| `net` | Read the request log and console of a live context |
|
|
92
|
+
| `handoff` | Export cookies (including HttpOnly), localStorage, UA; write a Playwright script |
|
|
93
|
+
| `close` | Close one context (by id or origin) or all of them |
|
|
94
|
+
| `cleanup` | Delete every artifact except the ones in `keep`, close contexts, sweep temp scratch dirs |
|
|
95
|
+
| `status` | Live contexts, artifact usage, environment check |
|
|
96
|
+
|
|
97
|
+
## Contexts
|
|
98
|
+
|
|
99
|
+
One engine world per origin, kept alive between calls so a multi-step flow is several small
|
|
100
|
+
calls instead of one giant script:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
run("window.step = 1", url="https://x.test") # opens the page
|
|
104
|
+
run("window.step + 1") # → 2, same document
|
|
105
|
+
run("fetch('/api/me').then(r => r.text())",
|
|
106
|
+
advance_ms=800, read="window.__last") # carries the cookies earned above
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
A context dies on `close`, after `FOXFETCH_IDLE_SECONDS` (default 60) of silence, or when the
|
|
110
|
+
pool exceeds `FOXFETCH_MAX_CONTEXTS` (default 2) — the least recently used goes first.
|
|
111
|
+
|
|
112
|
+
## Install
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
pip install foxfetch
|
|
116
|
+
python -m foxfetch doctor # python, ruyijs, mcp, chromium, artifacts
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Then wire it into a host — see [SETUP.md](SETUP.md) for the per-host steps. The short version:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# Pi, Claude Code, Codex and other MCP clients
|
|
123
|
+
php -r '' 2>/dev/null; # (no shell hook needed) — add an mcpServers entry:
|
|
124
|
+
# "command": "python", "args": ["-m", "foxfetch", "serve"]
|
|
125
|
+
|
|
126
|
+
# DeepSeek Harness: install the plugin in dsh/, which forwards to the same service
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Chromium is optional: without it `handoff` still exports the identity, it just cannot write
|
|
130
|
+
the screenshot script.
|
|
131
|
+
|
|
132
|
+
## Configuration
|
|
133
|
+
|
|
134
|
+
| Variable | Default | Meaning |
|
|
135
|
+
|---|---|---|
|
|
136
|
+
| `FOXFETCH_HOME` | `%LOCALAPPDATA%\foxfetch` | Artifact root (credentials pass through it) |
|
|
137
|
+
| `FOXFETCH_MAX_CONTEXTS` | 2 | Live engine contexts before LRU eviction |
|
|
138
|
+
| `FOXFETCH_IDLE_SECONDS` | 60 | Silence before a context is killed |
|
|
139
|
+
| `FOXFETCH_TIMEOUT_MS` | 30000 | Default navigation budget |
|
|
140
|
+
| `FOXFETCH_MAX_BYTES` | 65536 | Output cap before spilling to a file |
|
|
141
|
+
| `FOXFETCH_ARTIFACT_TTL` | 86400 | Seconds before an artifact is deleted automatically |
|
|
142
|
+
| `FOXFETCH_REMIND_AFTER` | 600 | Seconds before tool results start mentioning pending artifacts (0 disables) |
|
|
143
|
+
| `FOXFETCH_PY` | — | Interpreter the DSH plugin should use |
|
|
144
|
+
|
|
145
|
+
## Safety
|
|
146
|
+
|
|
147
|
+
`handoff` writes **live credentials** — cookies including the HttpOnly ones page script cannot
|
|
148
|
+
read. They land under `FOXFETCH_HOME`, owner-only, and expire after `FOXFETCH_ARTIFACT_TTL`.
|
|
149
|
+
Call `cleanup` when the task is delivered, and pass `keep=[...]` for the screenshot or token
|
|
150
|
+
the user still needs to look at.
|
|
151
|
+
|
|
152
|
+
You do not have to remember on your own: **every tool response carries the artifact state**, and
|
|
153
|
+
once a file is older than `FOXFETCH_REMIND_AFTER` (default 600 s) the response grows a `reminder`
|
|
154
|
+
saying how many files are still on disk and that they may hold credentials. The field vanishes
|
|
155
|
+
the moment `cleanup` runs, so a stale reminder is a visible bug, not a silent one.
|
|
156
|
+
|
|
157
|
+
## Development
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
pip install -e '.[dev]'
|
|
161
|
+
pytest -q
|
|
162
|
+
mypy src
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The tests encode the bugs this rewrite exists to prevent: a clip that split UTF-8 sequences,
|
|
166
|
+
a URL compare that ignored the trailing slash, `sameSite: "Default"` rejected by Playwright,
|
|
167
|
+
and a runaway browser left behind when the screenshot threw.
|
|
168
|
+
|
|
169
|
+
## Licence
|
|
170
|
+
|
|
171
|
+
MIT. The engine (`ruyijs`) is a separate project under AGPL-3.0; foxfetch only calls it.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
foxfetch/__init__.py,sha256=Zip8ss9J7o6sEbfZd1siAOnWh8GjHmhu-vZhQOs1HJw,138
|
|
2
|
+
foxfetch/__main__.py,sha256=k1ocEWawweo1qCJWNFAAvyxz3tcY13dzvCenHszij30,48
|
|
3
|
+
foxfetch/cli.py,sha256=3pmwBZJGExHxlx-f2t092cFpdeibr0gnlNLVhpfekbk,2825
|
|
4
|
+
foxfetch/config.py,sha256=qgmKJqWG1Y8leXr4qJj9cFUKL8BbzSMp3C3TYzJUfhI,2378
|
|
5
|
+
foxfetch/contexts.py,sha256=zbfbNdc2w2PjP_KMM_NmklGaRU0EpJTnKDs7FW_1c58,8960
|
|
6
|
+
foxfetch/doctor.py,sha256=4nX-J2lZVeW0I1AU5Y5p2I-eGwlReVdoED01AvpJPC8,7869
|
|
7
|
+
foxfetch/engine.py,sha256=UVg6GV_ampCxXxIWnqJfX82w6KTnTenzTXiVb9u_NBM,19662
|
|
8
|
+
foxfetch/probe.py,sha256=CPrbMqDs-Bl5SvFVorM-bWoiFunuwdVnCbmIgkimvEs,6697
|
|
9
|
+
foxfetch/server.py,sha256=AxfqZNx5zln8glJxnBqm7zN6NVUWXyEIcfYGdjPkTBE,5625
|
|
10
|
+
foxfetch/shapes.py,sha256=xXXUCOjwusfEzuWwOQuFYz_1sbyv9WQxCvZIIQ_0D6g,5916
|
|
11
|
+
foxfetch-0.1.0.dist-info/METADATA,sha256=Q8MnNNP_zuztk1Lv4Kl-iW4Vj-bwtFkFM_2PCd0GMcY,7608
|
|
12
|
+
foxfetch-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
13
|
+
foxfetch-0.1.0.dist-info/entry_points.txt,sha256=TGRvomiApb51c7FMHfkJ8XULccftZwAlA8FEHPA3Mko,47
|
|
14
|
+
foxfetch-0.1.0.dist-info/licenses/LICENSE,sha256=EjsOiTmmBPv-XgrYXPNJfQxGe77tQUgc0NDyzvBwdlc,1236
|
|
15
|
+
foxfetch-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 foxfetch contributors
|
|
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.
|
|
22
|
+
|
|
23
|
+
Note: `ruyijs`, the Firefox engine this package drives, is a separate project
|
|
24
|
+
under AGPL-3.0. foxfetch only imports and calls it; no ruyijs code is bundled.
|