@jayyuen66/dsh-scrapling 0.0.1-rc.3 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -68,7 +68,13 @@ would throw all of that away.
68
68
 
69
69
  `scrapling_crawl` returns a **job id immediately** rather than blocking: a crawl takes
70
70
  minutes, a tool call has a timeout. Watch it with `job_list`, read it with
71
- `job_output`, stop it with `job_kill`.
71
+ `job_output`, stop it with `job_kill`. A crawl also has a wall-clock ceiling
72
+ (`crawlMaxRuntimeSeconds`) and never leaves the start domain. Politeness is the
73
+ deployment's call, stated in the open: Scrapling's spider defaults are kept as-is —
74
+ robots.txt is **not** obeyed, per-domain delay is 0, and up to 4 requests run in
75
+ parallel. The crawl is confined to the start domain, so it never fans out across
76
+ unrelated sites; a target that needs gentler behaviour should sit behind a rate
77
+ limiter on the deployment side.
72
78
 
73
79
  ## Requirements
74
80
 
@@ -174,6 +180,10 @@ Notable switches:
174
180
  ceiling over the model-supplied `maxPages`; an out-of-range `maxPages` (0, negative,
175
181
  NaN) is passed through unchanged so the sidecar reports the parameter error rather
176
182
  than this plugin silently clamping it into a legal-looking value.
183
+ `crawlMaxRuntimeSeconds` is the crawl's wall-clock ceiling: the page cap says nothing
184
+ about a site that takes a minute per page, and a crawl is a background thread nobody
185
+ is watching. On expiry the spider winds down through its own stop channel instead of
186
+ running until the site runs out.
177
187
  - `stripInlineImages` - **on** by default: inline `data:` URI images are dropped from
178
188
  the body and only their alt text is kept. Such an image is pure token noise - a
179
189
  base64 SVG costs characters in the context while the model cannot read a shape out
@@ -223,8 +233,8 @@ Notable switches:
223
233
 
224
234
  **Deployment-grade knobs** (not on the settings card; set them in the `config:` block of
225
235
  `cordis.patch.yml`): `requestTimeoutSeconds`, `maxUrlLength`, `browserExecutablePath`,
226
- `browserCdpUrl`, `searchEndpoint`, `searchRenderTopN`. The first two of the browser pair are
227
- strong capabilities - one hands Chromium a file
236
+ `browserCdpUrl`, `searchEndpoint`, `searchRenderTopN`, `crawlMaxRuntimeSeconds`. The first
237
+ two of the browser pair are strong capabilities - one hands Chromium a file
228
238
  to execute, the other hands the browser to a debugger endpoint - so they come only from
229
239
  deployment config and are unreachable from model input.
230
240
 
@@ -369,14 +379,15 @@ JSON endpoint.
369
379
  address, not only the ones inside the RFC 6052 segment.
370
380
  - **No port allowlist** (any port allowed by default), matching dsh's own built-in
371
381
  fetch provider.
372
- - **`scrapling_crawl` re-checks addresses itself, but redirect targets still rest on
373
- domain consistency alone.** The start URL goes through `guard.url_allowed` (the same
374
- implementation the browser path uses, so both layers agree), the crawl session sets
375
- `follow_redirects="safe"` so curl_cffi refuses to follow a jump into a private range, and
376
- each page's final URL is re-checked before it enters the result set. Scrapling's
377
- `allow_domains`, though, is a string comparison that covers links found in the page and
378
- not redirect targets - so on that seam the host gate's start-URL check is still the only
379
- defence.
382
+ - **`scrapling_crawl` re-checks addresses itself, but the start-URL gate is still the
383
+ first line.** The start URL goes through `guard.url_allowed` (the same implementation
384
+ the browser path uses, so both layers agree), the crawl session sets
385
+ `follow_redirects="safe"` so curl_cffi refuses to follow a jump into a private range,
386
+ and each page is re-checked **twice** before it enters the result set: once against
387
+ the guard (the final URL may still have landed somewhere private) and once against the
388
+ start domain - Scrapling's `allow_domains` is a string comparison that covers links
389
+ found in the page and not redirect targets, so an off-site jump on a public host has to
390
+ be caught here.
380
391
  - **WebSocket coverage depends on the Playwright version.** The guard intercepts
381
392
  handshakes via `route_web_socket`. Older builds lack that method, WebSocket is then
382
393
  outside the guard, and the plugin says so in the log and in the capability report
@@ -387,7 +398,9 @@ JSON endpoint.
387
398
 
388
399
  The host-side policy is enforced by `SidecarClient.call`, so it covers every tool and
389
400
  the `web_fetch` provider alike; a rejection throws `URL_BLOCKED` before the request is
390
- written to the pipe.
401
+ written to the pipe. The `web_search` provider runs the same gate over the URLs it is
402
+ about to hand back: a hit the gate rejects never becomes a citeable source, so the model
403
+ is never offered an address the next fetch would refuse.
391
404
  - **Browser engines ignore proxy environment variables.** Playwright does not read
392
405
  `HTTP_PROXY` / `HTTPS_PROXY`, so `scrapling_render` / `scrapling_capture_xhr` /
393
406
  `scrapling_stealth_fetch` connect **directly** even when the rest of the system is
@@ -415,11 +428,41 @@ JSON endpoint.
415
428
 
416
429
  ```sh
417
430
  pnpm install # install dependencies
418
- pnpm run check # typecheck + lint + build + test + format check
431
+ pnpm run check # typecheck + lint + build + test + format check, TS *and* Python
419
432
  pnpm run build # bundles host.ts / src/client-entry.ts into host.js / client.js
420
433
  pnpm run test:py # end-to-end check of the Python sidecar (needs _env/.venv)
421
434
  ```
422
435
 
436
+ **The Python half is gated too.** The four `.py` files ship with this package
437
+ (`package.json`'s `files` lists them one by one) and run on the user's machine, so they
438
+ get the same treatment as `host.ts`: `pnpm run check` runs `ruff check` and
439
+ `ruff format --check` over `py/`, and fails hard when the tools are missing rather than
440
+ skipping quietly. Install them into whichever interpreter `python3` resolves to:
441
+
442
+ ```sh
443
+ pip install -r py/requirements-dev.txt
444
+ ```
445
+
446
+ Two more commands measure rather than gate:
447
+
448
+ ```sh
449
+ pnpm run typecheck:py # mypy over py/ (currently clean; why it stays advisory is below)
450
+ pnpm run cov:py # coverage for the four shipped modules + the test script
451
+ ```
452
+
453
+ Run both with an interpreter that has Scrapling installed (the same one `test:py` uses).
454
+ That is not decoration: mypy's findings depend on it. From an interpreter without
455
+ Scrapling every Scrapling type degrades to `Any` and the check reports nothing at all.
456
+
457
+ `mypy` stays advisory because this side is duck-typed on purpose — Playwright's `page`,
458
+ `route` and `websocket` have no shape until runtime — and a strict profile would buy a
459
+ pile of `ignore` comments that exist only to silence it. `cov:py` is advisory because its
460
+ honest number needs the subprocess wired in: `bridge.py` and the `adapters` methods live
461
+ in the sidecar child, so `test_bridge.py` spawns that child under `coverage run` when
462
+ `DSH_PY_COVERAGE=1`. Without it the report reads `adapters.py` 20% while none of its fetch
463
+ paths have been counted at all — a number that measures nothing. Current shape:
464
+ `adapters` 65%, `bridge` 37%, `crawl` 89%, `guard` 85%.
465
+
423
466
  Sources are all TypeScript. `host.js` and `client.js` are **build artifacts** and are
424
467
  deliberately `.js`: Node refuses to strip types for packages inside `node_modules`,
425
468
  which is exactly where dsh loads the plugin from.
package/README.zh-CN.md CHANGED
@@ -59,7 +59,11 @@ cookie,浏览器引擎要保留页面池,`adaptive` 要保留 SQLite 指纹
59
59
  这些东西全都会丢。
60
60
 
61
61
  `scrapling_crawl` **立刻返回作业 id** 而不是阻塞:一次爬取是分钟级的,而工具调用有超时。
62
- 用 `job_list` 看进度、`job_output` 读结果、`job_kill` 中断。
62
+ 用 `job_list` 看进度、`job_output` 读结果、`job_kill` 中断。爬虫另有总时长上限
63
+ (`crawlMaxRuntimeSeconds`),且不会爬出起始域。礼貌性由部署方定夺,这里如实声明:
64
+ 沿用了 Scrapling spider 的默认值 —— **不遵守** robots.txt、每域延迟为 0、最多 4 个请求
65
+ 并发。爬取被锁在起始域内,不会向无关站点扩散;需要更温和行为的站点,请在部署侧套一层
66
+ 限速。
63
67
 
64
68
  ## 环境要求
65
69
 
@@ -163,7 +167,9 @@ Scrapling 的 Markdown 输出报成 `text`,内置渲染路径显示完全正
163
167
  - `*MaxOutputChars` —— 各工具的输出封顶。宿主侧的封顶只影响进模型上下文的那一段,
164
168
  真正的字节上限在 Python 侧(`maxContentChars`)。`crawlMaxItems` 是部署侧给模型可传的
165
169
  `maxPages` 封的顶;越界的 `maxPages`(0、负数、NaN)**原样透传**,让 sidecar 报参数错误,
166
- 而不是由本插件悄悄夹成一个看起来合法的值。
170
+ 而不是由本插件悄悄夹成一个看起来合法的值。`crawlMaxRuntimeSeconds` 是爬虫的**墙上时钟**
171
+ 上限:页数上限管不了一页等一分钟的站点,而爬虫是没人看的后台线程。到点由蜘蛛走引擎自己
172
+ 的停机通道收尾,而不是等站点自己没得爬。
167
173
  - `stripInlineImages` —— 默认**开**:剥掉正文里内嵌的 `data:` URI 图片,只留 alt 文本。
168
174
  这类图片对模型是纯 token 噪音 —— 一段 base64 SVG 编码进上下文要按字符计费,而模型从里面
169
175
  读不出任何图形信息。**不含内联图的页面逐字节不变**;含内联的页面省掉的量取决于内联图有多少 ——
@@ -184,7 +190,7 @@ Scrapling 的 Markdown 输出报成 `text`,内置渲染路径显示完全正
184
190
 
185
191
  **部署级旋钮**(不在设置卡上,只走 [`cordis.patch.yml`](./cordis.patch.yml) 的 `config:`
186
192
  块):`requestTimeoutSeconds`、`maxUrlLength`、`browserExecutablePath`、`browserCdpUrl`、
187
- `searchEndpoint`、`searchRenderTopN`。
193
+ `searchEndpoint`、`searchRenderTopN`、`crawlMaxRuntimeSeconds`。
188
194
  其中 `browserExecutablePath` 与 `browserCdpUrl` 是强能力 —— 前者等于让 Chromium 执行指定文件,
189
195
  后者等于把浏览器交给指定调试端点 —— 所以它们只从部署配置来,模型入参到不了。
190
196
 
@@ -298,11 +304,12 @@ PAC 是唯一还需要手工填一次的形态:求值 PAC 要下载脚本并
298
304
  会被当成普通公网 IPv6 放行。反过来,自建前缀一旦声明就**对所有 IPv6 生效**,不限于
299
305
  落在 RFC 6052 段里的那些。
300
306
  - **没有端口白名单**(默认不限端口),与 dsh 内置 fetch provider 的取舍一致。
301
- - **`scrapling_crawl` 已有自己的地址复核,但重定向目标仍只靠域名一致性。** 起点 URL 过
307
+ - **`scrapling_crawl` 已有自己的地址复核,但起点那一关仍是第一道。** 起点 URL 过
302
308
  `guard.url_allowed`(与浏览器路径同一个实现,两侧同解),爬虫会话设了
303
- `follow_redirects="safe"` 让 curl_cffi 拒绝跳向私网的跳转,每一页收进结果前再复判一次
304
- 最终 URL。但 Scrapling 的 `allow_domains` 是字符串比较,只管页面里发现的链接、不管重定向
305
- 目标 —— 重定向这条缝上真正的防线仍只有 Host 闸门起点那一道。
309
+ `follow_redirects="safe"` 让 curl_cffi 拒绝跳向私网的跳转,每一页收进结果前再复判
310
+ **两次**:一次过守卫(最终 URL 仍可能落在私网上),一次过起始域 —— Scrapling 的
311
+ `allow_domains` 是字符串比较,只管页面里发现的链接、不管重定向目标,所以跳向站外
312
+ 公网主机的那一跳必须在这里拦住。
306
313
  - **WebSocket 覆盖依赖 Playwright 版本。** 守卫用 `route_web_socket` 拦握手;更老的
307
314
  Playwright 没有这个方法,那种情况下 WebSocket 不在守卫范围内,插件会往日志与能力报告
308
315
  里如实标出,不会静默降级。
@@ -310,7 +317,9 @@ PAC 是唯一还需要手工填一次的形态:求值 PAC 要下载脚本并
310
317
  指向它们等于交出「执行这个文件」与「把浏览器交给这个调试端点」。
311
318
 
312
319
  Host 侧那道策略由 `SidecarClient.call` 统一执行,因此覆盖每一个工具,也覆盖
313
- `web_fetch` provider;判否时抛 `URL_BLOCKED`,请求根本不会写进管道。
320
+ `web_fetch` provider;判否时抛 `URL_BLOCKED`,请求根本不会写进管道。`web_search` provider
321
+ 也对它准备交回的 URL 跑同一道闸门:被闸门判否的命中不会成为可引用的 source,模型因此不会
322
+ 拿到一个「下一次抓取必然被拒」的地址。
314
323
 
315
324
  - **浏览器引擎不认代理环境变量。** Playwright 不读 `HTTP_PROXY` / `HTTPS_PROXY`,所以
316
325
  `scrapling_render` / `scrapling_capture_xhr` / `scrapling_stealth_fetch` 即使在整台机器