@jayyuen66/dsh-scrapling 0.1.10 → 0.1.12

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/CHANGELOG.md CHANGED
@@ -6,6 +6,33 @@
6
6
  标准六类之外的小节(本仓的 `Boundaries` 收各版本的验证范围与能力边界,即哪些平台/档位真跑过、
7
7
  哪些只到本地夹具为止)。
8
8
 
9
+ ## 0.1.12
10
+
11
+ 设置卡的下拉候选与说明浮层不再漂到浏览器最左边;shared 抬到 `^0.2.8`(含运行时几何自检),CI 的 action 钉版升到最新。`MCP_SERVER_VERSION` 随包版本同步。
12
+
13
+ ### Fixed
14
+
15
+ - **下拉候选与说明浮层被钉在视口左边缘**:`.dsu-menu` 与 `.dsu-tip` 的 `position-area: block-end span-inline-start` 选中的是「行内起始列 + 中间列」,而 `position: fixed` 下该区域的起始边是**视口左边缘**、不是触发器左边缘,再叠一条 `justify-self: start`,浮层就落在 `x=0`。改为 `block-end span-inline-end`——真实 Chromium(patchright headless,156.0.8078.4)实测:1440px 视口、触发器左边缘 860px,改前浮层左边缘 0,改后 860;触发器贴到右侧时 `flip-inline` 会改成右边缘对齐,贴到视口底部时 `flip-block` 翻到上方。
16
+ - **锚定没兑现时改回 JS 矩形定位**:`select.ts` 与 `field.ts` 的 `place()` 此前只要 `CSS.supports("position-area: block-end")` 为真就直接 `return`,方向性错误没有任何兜底。现在锚定后先量一次浮层矩形,用 shared 0.2.8 的 `anchorPlacementOff` 判它是否真贴在触发器上(行内起始边或结束边任一在 2px 容差内贴住,且块向落在触发器下方或上方),不通过才把 `position-area` 显式置 `none` 再写 `left` / `top`。顺序是承重的:实测同时留着 `position-area` 只写坐标时块向仍由锚定决定(浮层 `y` 落在 314 而不是 160),必须先关。回退是单向的——同一个浮层一旦走过 JS 路径,后续 `resize` 不再尝试锚定,避免两个定位源来回抢。
17
+ - **回归测试**:`test/card-ui.test.ts` 新增 `anchorPlacementOff` 的四种对齐形态(左边缘对齐、`flip-inline` 右对齐、`flip-block` 翻上方、两轴都不沾)与容差边界,以及三条锚定用例(浮层真贴住时不写 JS 坐标、被钉到视口左侧时改写坐标并关掉 `position-area`、回退过的浮层不再重试锚定)。
18
+
19
+ ### Changed
20
+
21
+ - **运行时依赖 shared 抬到 `^0.2.8`**:`pnpm-workspace.yaml` 的 catalog 由根 `sync` 投影,`pnpm-lock.yaml` 随 `sync:lock` 重解;`client.js` 按新 shared 重建,内联的 `CARD_UI_CSS` 逐字节等于已装 shared 导出的那一份。0.2.8 新增的 `anchorPlacementOff` / `ANCHOR_PLACEMENT_TOLERANCE` 只被卡片内部使用,本包对外工具与 Remote 方法名单不变。
22
+ - **CI 的 action 钉版升到最新**:`github/codeql-action` 的 `init` / `analyze` / `upload-sarif` 由 `v4.39.2` 升到 `v4.39.3`(`33d7b85da1a04171e211befe2c739303b9a4c066`)。钉版仍是 40 位 commit SHA + 版本注释,由根 `scripts/upgrade-actions.mjs` 现量比对上游 tag 后改写,`--check` 可复跑。
23
+
24
+ ## 0.1.11
25
+
26
+ Scrapling 钉版抬到 `0.5.1`;MCP 接入支持宿主 mcpManager 动态注册;宿主开发基线抬到 `0.2.2-rc.2`,支持窗口收到 `^0.2.2-rc.1`。
27
+
28
+ ### Changed
29
+
30
+ - **Scrapling 钉版抬到 `0.5.1`**:`py/runtime-requirements.txt` 的 scrapling 由 `0.5` 抬到 `0.5.1`(wheel 哈希重算,传递依赖地板已满足);契约探针与 sidecar 端到端在 0.5.1 上取证通过(调用面零违规、零静默丢弃)。`bridge.py` 的版本闸 `>=0.5,<0.6` 不变。
31
+ - **MCP 动态注册**:`mcp` 模式起好自有 HTTP server 后、`official-mcp` 模式启用时,探测宿主 `ctx.get("mcpManager")` 并动态注册(streamable-http / stdio),注册项随插件生命周期撤除;取不到 mcpManager(CLI/headless 无此服务)或注册失败(重名等)时回退既有接入方式(手配 dsh-mcp-client / setup 产 patch)。`MCP_SERVER_VERSION` 同步到包版本。
32
+ - **宿主开发基线抬到 `0.2.2-rc.2`**:`devDependencies` 整组 `@deepseek-ai/dsh-*` 抬到 `0.2.2-rc.2`;rc.2 新增的 `@deepseek-ai/dsh-error` 作为 devDependency 直接钉到 `0.2.2-rc.2` —— 它是 `dsh-llm` / `dsh-jobs` / `dsh-subprocess` 的字面 peer,本仓 `autoInstallPeers: false`,不显式声明就装不进来,`dsh-llm` 的 `HarnessError` 类型会解析失败。
33
+ - **MCP 客户端默认钉版抬到 `0.2.2-rc.2`**:`@deepseek-ai/dsh-mcp-client` 对宿主各包的 peer 是逐字同版,rc.2 宿主上装 rc.1 客户端会被宿主按 peer 不匹配拒绝装载;`setup` 打印的安装命令与 `official-mcp` 的安装提示随开发基线走到 rc.2。放行名单同时保留 `0.2.2-rc.1`(窗口内仍停在 rc.1 的宿主)与 `next`,`doctor` 三档都认。
34
+ - **支持窗口收到 `^0.2.2-rc.1`**:`engines.dsh` 与 `@deepseek-ai/dsh*` peer 由 `^0.2.1-rc.5 || ^0.2.2-alpha.3` 改为 `^0.2.2-rc.1`(单条 0.2.2 线);`@deepseek-ai/schemastery` peer 由 `^3.18.5 || ^3.18.6-alpha.1` 收到 `^3.19.0`。devDependencies 仍精确钉版。
35
+
9
36
  ## 0.1.10
10
37
 
11
38
  真机验收(dsh 宿主 0.2.2-rc.1,标准/PTC/极简/创造四种 Agent 预设 × native/mcp/official-mcp 三种集成模式)发现的两处功能缺陷与两处排障缺口:登录态存取在目录缺失时的失败形态,与宿主侧 DNS 停摆时抓取全部挂到工具超时的形态。工具与设置界面不变。
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
  <a href="https://github.com/JayYuen666/dsh-scrapling/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/JayYuen666/dsh-scrapling/ci.yml?branch=main&style=flat-square&label=ci" alt="ci" /></a>
13
13
  <img src="https://img.shields.io/badge/license-MIT-4c1?style=flat-square" alt="MIT" />
14
14
  <img src="https://img.shields.io/badge/node-%3E%3D24.9-4c1?style=flat-square&logo=nodedotjs&logoColor=white" alt="node" />
15
- <img src="https://img.shields.io/badge/dsh-%5E0.2.1--rc.5-658EFF?style=flat-square" alt="dsh" />
15
+ <img src="https://img.shields.io/badge/dsh-%5E0.2.2--rc.1-658EFF?style=flat-square" alt="dsh" />
16
16
  <a href="https://github.com/deepseek-ai/deepseek-harness"><img src="https://img.shields.io/badge/powered_by_dsh-4D6BFE?style=flat-square&logo=deepseek&logoColor=white" alt="powered by dsh" /></a>
17
17
  </p>
18
18
 
@@ -31,23 +31,27 @@
31
31
 
32
32
  ## <img src="https://api.iconify.design/lucide/file-text.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Contents
33
33
 
34
- - [What it does](#what-it-does)
35
- - [Install](#install)
34
+ - [ Contents](#-contents)
35
+ - [ What it does](#-what-it-does)
36
+ - [ Install](#-install)
37
+ - [ Shared version floor](#-shared-version-floor)
36
38
  - [Runtime packs (macOS arm64)](#runtime-packs-macos-arm64)
37
- - [Verify it is live](#verify-it-is-live)
38
- - [What it does not provide](#what-it-does-not-provide)
39
- - [Enabling it in dsh](#enabling-it-in-dsh)
40
- - [The tools](#the-tools)
41
- - [Replacing the built-in fetch and search](#replacing-the-built-in-fetch-and-search)
42
- - [MCP mode](#mcp-mode)
43
- - [Settings](#settings)
44
- - [Proxies](#proxies)
45
- - [Security](#security)
46
- - [Data and privacy](#data-and-privacy)
47
- - [Known boundaries](#known-boundaries)
48
- - [FAQ](#faq)
49
- - [Development](#development)
50
- - [License](#license)
39
+ - [ Verify it is live](#-verify-it-is-live)
40
+ - [ What it does not provide](#-what-it-does-not-provide)
41
+ - [ Enabling it in dsh](#-enabling-it-in-dsh)
42
+ - [ The tools](#-the-tools)
43
+ - [Render or static](#render-or-static)
44
+ - [ Replacing the built-in fetch and search](#-replacing-the-built-in-fetch-and-search)
45
+ - [ MCP mode](#-mcp-mode)
46
+ - [ `setup --mode` and `doctor`](#-setup---mode-and-doctor)
47
+ - [ Settings](#-settings)
48
+ - [ Proxies](#-proxies)
49
+ - [ Security](#-security)
50
+ - [ Data and privacy](#-data-and-privacy)
51
+ - [ Known boundaries](#-known-boundaries)
52
+ - [ FAQ](#-faq)
53
+ - [ Development](#-development)
54
+ - [ License](#-license)
51
55
 
52
56
  ## <img src="https://api.iconify.design/lucide/shield.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> What it does
53
57
 
@@ -76,7 +80,7 @@ dsh plugin --profile web add @jayyuen66/dsh-scrapling
76
80
  Remove with `dsh plugin --profile web remove @jayyuen66/dsh-scrapling`. The package is on the public npm registry, so installation needs no credentials and no scoped-registry line.
77
81
 
78
82
  - **Requires Node.js `>= 24.9`.** This is an ESM-only package, and the build entry points (`build-client.ts`, `build-host.ts`, `build-cli.ts`) are executed by `node` directly, so the floor has to sit where TypeScript type stripping is on by default (Node 22.18 up). The number itself is the host floor: `0.2.2` hosts declare Node `>= 24.9.0`, and a host below it never starts.
79
- - **Requires host `dsh` at the `0.2.1-rc.5` or `0.2.2-alpha.3` line.** The requirement the host actually reads is `engines.dsh` (`^0.2.1-rc.5 || ^0.2.2-alpha.3`), and it decides alone; a host on a later line is refused and needs the explicit risk grant `dsh plugin --profile <p> allow-version <pkg>@<ver> --dsh-version <exact> --accept-risk`. The support window rolls: this package is verified against every released host version inside the window at publish time and re-verified once the window moves, so the version number in this bullet is not a standing promise.
83
+ - **Requires host `dsh` at the `0.2.2-rc.1` line or later.** The requirement the host actually reads is `engines.dsh` (`^0.2.2-rc.1`), and it decides alone; a host on a later line is refused and needs the explicit risk grant `dsh plugin --profile <p> allow-version <pkg>@<ver> --dsh-version <exact> --accept-risk`. The support window rolls: this package is verified against every released host version inside the window at publish time and re-verified once the window moves, so the version number in this bullet is not a standing promise.
80
84
  - **Requires Python 3.14+ with Scrapling installed** — named by `pythonBin`, or found by the fixed chain in `lib/runtime.ts` (managed runtime under `dataDir/runtime`, then the repository's `_env/.venv`, then `PATH`). In an installed package the `_env/.venv` leg does not exist, so after `setup --feature core --apply` the interpreter is that managed Python and otherwise the `python3` on your `PATH` (`python` on Windows); whichever one is chosen is logged at load time, and a missing Scrapling reports an error carrying the install line to copy.
81
85
 
82
86
  ```sh
@@ -110,7 +114,7 @@ dsh-scrapling setup --status
110
114
  - `--offline <dir>` installs with no network at all: `<dir>` must hold the Python archive named exactly as the manifest URL's last segment (browser and `curl -O` both keep `cpython-3.14.9+…-install_only.tar.gz`, and the percent-encoded spelling is accepted too) plus a `wheels/` directory with one wheel per pinned requirement - `pip download --only-binary=:all: --require-hashes -r py/runtime-requirements.txt -d <dir>/wheels` produces it. The hash check on the Python archive is the same one the networked path runs, and pip is invoked with `--no-index`; a missing archive or wheelhouse fails as `INSTALL_OFFLINE_ASSETS` instead of silently going online.
111
115
  - `setup --status` prints one JSON document: `dataDir`, `profile`, `runtime`, `packs` and `state`. With `--profile <dir>` it reads that profile's `cordis.patch.yml`, resolves the interpreter from this package's `pythonBin` and the data directory from `dataDir` (the two settings the host actually uses); `packs` and `state` are then reported for that directory — when the entry carries no `dataDir`, both fall back to the CLI's own default. Without `--profile`, `profile.path` is `null`, a note says the profile was not read, and `runtime` falls back to the CLI's own chain (managed runtime → repo `_env/.venv` → PATH `python3`). Pass `--profile` whenever you compare the card's interpreter with what `--status` reports.
112
116
  - The settings card can start the same install/repair/cancel actions through the `scraplingRuntime` remote when the profile has both a remote surface and a jobs backend; otherwise it prints the CLI command.
113
- - `integrationMode` is deployment-only; `setup --mode` prints or writes the client entry for the two MCP shapes and `doctor` checks a profile against it — see [MCP mode](#mcp-mode). `official-mcp` starts `scrapling-mcp` from the managed venv, which the `mcp` pack provisions (`setup --feature mcp --apply`).
117
+ - `integrationMode` is deployment-only; on a host that exposes `mcpManager` (the rc.2 web bundle) the MCP server is registered dynamically at load, while `setup --mode` prints or writes the client entry for CLI/headless profiles and `doctor` checks a profile against it — see [MCP mode](#mcp-mode). `official-mcp` starts `scrapling-mcp` from the managed venv, which the `mcp` pack provisions (`setup --feature mcp --apply`).
114
118
  - Only **macOS arm64** is verified. Windows, Linux and macOS x64 are blocked (B1/B2): every pack reports `blocked` and the installer refuses rather than guessing an asset path.
115
119
 
116
120
  ## <img src="https://api.iconify.design/lucide/circle-check.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Verify it is live
@@ -126,7 +130,7 @@ dsh-scrapling setup --status
126
130
  - **It is not a search engine.** Discovery runs in the Python sidecar against one of six backends (`searchBackend`: `auto` / `tavily` / `bing` / `brave` / `serper` / `duckduckgo` / `searxng`); Scrapling's own `google_search` option only sets a referer header. Each backend needs its own setting (`tavilyApiKey`, `braveApiKey`, `serperApiKey`, `searxngEndpoint`) — a backend that is selected but not configured reports `SEARCH_AUTH` instead of silently switching to another one.
127
131
  - **The npm tarball bundles no interpreter or browser.** They come from your machine or from the optional CLI installer, which downloads the verified macOS arm64 set into `dataDir/runtime`; missing pieces remove the matching tools instead of being fetched at load time.
128
132
  - **It adds no HTTP route on the host side.** The settings card is a host config form and this package exposes no `/api` surface. The one socket that really listens is the MCP server under `integrationMode: mcp`, bound to `127.0.0.1` (`http://127.0.0.1:<mcpPort>/mcp`): any other path gets 404, a declared body over 1 MiB gets 413, a request without `Content-Length` gets 411, and the bearer token is read only from `DSH_SCRAPLING_MCP_TOKEN` — with no token set, startup prints a stderr notice that the endpoint is unauthenticated and reachable from any local process.
129
- - **It adds no dsh subcommand.** The package's own `dsh-scrapling` CLI manages runtime packs, plus the two halves of the MCP hookup: `setup --mode native|mcp|official-mcp` generates the client entry and, with `--apply`, writes it to `<dataDir>/mcp/<mode>.patch.yml` (the profile itself is never touched), while `doctor --mode` compares that entry against the profile's `cordis.patch.yml` item by item. Given `--profile`, `setup --status` reads `pythonBin` and `dataDir` from that same file.
133
+ - **It adds no dsh subcommand.** The package's own `dsh-scrapling` CLI manages runtime packs, plus the manual half of the MCP hookup for profiles without `mcpManager`: `setup --mode native|mcp|official-mcp` generates the client entry and, with `--apply`, writes it to `<dataDir>/mcp/<mode>.patch.yml` (the profile itself is never touched), while `doctor --mode` compares that entry against the profile's `cordis.patch.yml` item by item. Given `--profile`, `setup --status` reads `pythonBin` and `dataDir` from that same file.
130
134
 
131
135
  ## <img src="https://api.iconify.design/lucide/plug.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Enabling it in dsh
132
136
 
@@ -195,7 +199,7 @@ One consequence to know: `dsh-web`'s fetch body is a **closed** union of `html |
195
199
  |---|---|
196
200
  | `native` (default) | the `scrapling_*` tools listed above |
197
201
  | `mcp` | no native tools; the plugin serves the same tool table over MCP |
198
- | `official-mcp` | no native tools and no server from this plugin; `setup` only generates the `dsh-mcp-client` entry for the official `scrapling-mcp`, which runs in its own process, with its own sessions, and **without this plugin's URL guard** |
202
+ | `official-mcp` | no native tools and no server from this plugin; on a host that exposes `mcpManager` it registers the official `scrapling-mcp` dynamically, otherwise `setup` generates the `dsh-mcp-client` entry for it - it runs in its own process, with its own sessions, and **without this plugin's URL guard** |
199
203
 
200
204
  In `mcp` mode the server runs inside the plugin's own host process and calls the same sidecar, so the URL guard, sessions, jobs and adaptive storage are the same ones the native tools use — there is no second implementation to drift.
201
205
 
@@ -227,12 +231,12 @@ In `mcp` mode the server runs inside the plugin's own host process and calls the
227
231
  | `scrapling_screenshot` | `screenshot` |
228
232
  | — (`ctx.web` only) | `search` |
229
233
 
230
- Connecting dsh needs `@deepseek-ai/dsh-mcp-client`, which this plugin deliberately does not depend on. Pin the build that matches the current host — npm `latest` is older than the host's own line and the host rejects the mismatch:
234
+ On a host that exposes the `mcpManager` service (the rc.2 web/desktop bundle) the plugin registers its server there at load: no `dsh-mcp-client` install and no profile entry are needed, and `mcpPort` alone decides the endpoint. The manual entry below is for CLI/headless profiles, where that service is absent. If an upgraded profile still carries the manual entry, remove it when relying on dynamic registration - otherwise the manager refuses the duplicate server name and the old entry keeps serving.
235
+
236
+ Connecting dsh needs `@deepseek-ai/dsh-mcp-client`, which this plugin deliberately does not depend on. Pin the exact build matching the host version - npm `latest` is older than the host's own line, and the client's peer versions are literal, so one prerelease off installs but never activates. `0.2.2-rc.2` is the default; a host still on rc.1 takes `0.2.2-rc.1`, and `next` tracks the official beta line:
231
237
 
232
238
  ```bash
233
- dsh plugin --profile <name> add @deepseek-ai/dsh-mcp-client@0.2.2-rc.1
234
- # host on the 0.2.2-alpha.3 line: @deepseek-ai/dsh-mcp-client@0.2.2-alpha.3
235
- # host on the 0.2.1-rc.5 line: @deepseek-ai/dsh-mcp-client@0.2.1-rc.5
239
+ dsh plugin --profile <name> add @deepseek-ai/dsh-mcp-client@0.2.2-rc.2
236
240
  ```
237
241
 
238
242
  Then add one entry to that profile's `cordis.patch.yml` — this is exactly what `dsh-scrapling setup --mode mcp` prints, so you can also let the CLI write it (drop `headers` when no token is configured):
@@ -265,9 +269,9 @@ dsh-scrapling setup --mode native --apply # a file that deliberately contain
265
269
  dsh-scrapling doctor --mode mcp --profile <profileDir>
266
270
  ```
267
271
 
268
- `doctor` reads what the profile actually says - `cordis.patch.yml` plus that profile's `package.json` - and prints one line per problem: two entries under `serverName: scrapling`, this plugin's entry next to an official `stdio` one, entries that do not match the mode, an entry whose port disagrees with `--port`, a profile without `@deepseek-ai/dsh-mcp-client` or with it pinned to something other than `0.2.2-rc.1` / `0.2.2-alpha.3` / `0.2.1-rc.5` / `next`, and an official entry while `officialMcpEnabled` is off. Exit `0` is "consistent", `1` names at least one problem, `2` is a bad argument. `integrationMode` itself is a plugin setting the CLI cannot read, so `--mode` is the claim being checked and has to match the deployment.
272
+ `doctor` reads what the profile actually says - `cordis.patch.yml` plus that profile's `package.json` - and prints one line per problem: two entries under `serverName: scrapling`, this plugin's entry next to an official `stdio` one, entries that do not match the mode, an entry whose port disagrees with `--port`, a profile without `@deepseek-ai/dsh-mcp-client` or with it pinned to something other than `0.2.2-rc.2` / `0.2.2-rc.1` / `next`, and an official entry while `officialMcpEnabled` is off. Exit `0` is "consistent", `1` names at least one problem, `2` is a bad argument. `integrationMode` itself is a plugin setting the CLI cannot read, so `--mode` is the claim being checked and has to match the deployment.
269
273
 
270
- `official-mcp` asks for two separate statements before it produces anything: `officialMcpEnabled: true` in the profile and `--accept-risk` on the command line; missing either one prints `OFFICIAL_MCP_DISABLED` / `RISK_NOT_ACCEPTED` and writes nothing. The entry it generates starts `<dataDir>/runtime/venv/bin/scrapling-mcp`, so run `setup --feature mcp --apply` first - see [Runtime packs](#runtime-packs-macos-arm64). When that binary is missing, `setup` prints a line saying so.
274
+ `setup` for `official-mcp` asks for two separate statements before it writes anything: `officialMcpEnabled: true` in the profile and `--accept-risk` on the command line; missing either one prints `OFFICIAL_MCP_DISABLED` / `RISK_NOT_ACCEPTED` and writes nothing. At load time the host-side path is gated by `officialMcpEnabled` alone: a host exposing `mcpManager` registers the managed `scrapling-mcp` directly, while the `setup`-generated `dsh-mcp-client` entry is the fallback for CLI/headless profiles. Either path starts `<dataDir>/runtime/venv/bin/scrapling-mcp`, so run `setup --feature mcp --apply` first - see [Runtime packs](#runtime-packs-macos-arm64). When that binary is missing, `setup` prints a line saying so.
271
275
 
272
276
  ## <img src="https://api.iconify.design/lucide/sliders-horizontal.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> Settings
273
277
 
@@ -392,7 +396,7 @@ Registered honestly, one entry per class.
392
396
  - **Shopify crawl mode walks the store's JSON API.** `mode=shopify` uses the store's `/collections.json` and each collection's `/products.json` (upstream's `ShopifySpider`) and yields one row per variant — `name` (product + variant, minus `Default Title`), `price`, `sku`, `stock` (`null` when available, `0` when not), `identifier`, `brand`, `category`, `image_url`, `url`, `barcode`, `old_price`, `description`. It never scrapes product HTML, and it obeys the same URL gate, robots setting, delay and concurrency knobs as the other crawl modes. Verified against a local fixture store; a real Shopify store has not been exercised (B11).
393
397
  - **`maxPages` caps the pages collected, not the requests the spider makes.** The link discovery layer keeps requesting queued pages (one measured `maxPages=3` crawl issued about 680 requests while collecting 3). Politeness toward the target site is governed by the deployment knobs: `crawlRespectRobots`, `crawlDownloadDelayMs`, `crawlConcurrentRequests`, `crawlAutothrottle`.
394
398
  - **Heavy pages can keep the browser path from ever settling.** When resources stay in flight past the default 30-second page timeout, `scrapling_session_fetch` / `scrapling_render` fail while a static fetch of the same URL succeeds. Mitigations: `waitSelector` (wait for a key element) or `disableResources` (block images and fonts), both per-call parameters the model can pass.
395
- - **`official-mcp` generates configuration only.** `integrationMode=official-mcp` registers no native tool and starts no server from this plugin; `setup --mode official-mcp --accept-risk` produces the `dsh-mcp-client` entry for the official server, whose binary comes from the `mcp` pack (B10 is the risk decision that entry stands on).
399
+ - **`official-mcp` connects the upstream server.** `integrationMode=official-mcp` registers no native tool and starts no server from this plugin; on a host that exposes `mcpManager` (the rc.2 web bundle) the managed `scrapling-mcp` is registered dynamically, and where that service is absent (CLI/headless) `setup --mode official-mcp --accept-risk` produces the `dsh-mcp-client` entry instead. The binary comes from the `mcp` pack (B10 is the risk decision that entry stands on).
396
400
 
397
401
  ## <img src="https://api.iconify.design/lucide/circle-help.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> FAQ
398
402
 
package/README.zh-CN.md CHANGED
@@ -12,7 +12,7 @@
12
12
  <a href="https://github.com/JayYuen666/dsh-scrapling/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/JayYuen666/dsh-scrapling/ci.yml?branch=main&style=flat-square&label=ci" alt="ci" /></a>
13
13
  <img src="https://img.shields.io/badge/license-MIT-4c1?style=flat-square" alt="MIT" />
14
14
  <img src="https://img.shields.io/badge/node-%3E%3D24.9-4c1?style=flat-square&logo=nodedotjs&logoColor=white" alt="node" />
15
- <img src="https://img.shields.io/badge/dsh-%5E0.2.1--rc.5-658EFF?style=flat-square" alt="dsh" />
15
+ <img src="https://img.shields.io/badge/dsh-%5E0.2.2--rc.1-658EFF?style=flat-square" alt="dsh" />
16
16
  <a href="https://github.com/deepseek-ai/deepseek-harness"><img src="https://img.shields.io/badge/powered_by_dsh-4D6BFE?style=flat-square&logo=deepseek&logoColor=white" alt="powered by dsh" /></a>
17
17
  </p>
18
18
 
@@ -31,23 +31,27 @@
31
31
 
32
32
  ## <img src="https://api.iconify.design/lucide/file-text.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> 目录
33
33
 
34
- - [它做什么](#它做什么)
35
- - [安装](#安装)
34
+ - [ 目录](#-目录)
35
+ - [ 它做什么](#-它做什么)
36
+ - [ 安装](#-安装)
37
+ - [ shared 的版本下限](#-shared-的版本下限)
36
38
  - [运行时能力包(macOS arm64)](#运行时能力包macos-arm64)
37
- - [确认它真的在工作](#确认它真的在工作)
38
- - [它不提供什么](#它不提供什么)
39
- - [在 dsh 里启用](#在-dsh-里启用)
40
- - [工具一览](#工具一览)
41
- - [替代内置的抓取与搜索](#替代内置的抓取与搜索)
42
- - [MCP 模式](#mcp-模式)
43
- - [设置项](#设置项)
44
- - [代理](#代理)
45
- - [安全说明](#安全说明)
46
- - [数据与隐私](#数据与隐私)
47
- - [已知边界](#已知边界)
48
- - [常见问题](#常见问题)
49
- - [开发](#开发)
50
- - [许可证](#许可证)
39
+ - [ 确认它真的在工作](#-确认它真的在工作)
40
+ - [ 它不提供什么](#-它不提供什么)
41
+ - [ 在 dsh 里启用](#-在-dsh-里启用)
42
+ - [ 工具一览](#-工具一览)
43
+ - [渲染还是静态](#渲染还是静态)
44
+ - [ 替代内置的抓取与搜索](#-替代内置的抓取与搜索)
45
+ - [ MCP 模式](#-mcp-模式)
46
+ - [ `setup --mode` 与 `doctor`](#-setup---mode-与-doctor)
47
+ - [ 设置项](#-设置项)
48
+ - [ 代理](#-代理)
49
+ - [ 安全说明](#-安全说明)
50
+ - [ 数据与隐私](#-数据与隐私)
51
+ - [ 已知边界](#-已知边界)
52
+ - [ 常见问题](#-常见问题)
53
+ - [ 开发](#-开发)
54
+ - [ 许可证](#-许可证)
51
55
 
52
56
  ## <img src="https://api.iconify.design/lucide/shield.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> 它做什么
53
57
 
@@ -76,7 +80,7 @@ dsh plugin --profile web add @jayyuen66/dsh-scrapling
76
80
  卸载用 `dsh plugin --profile web remove @jayyuen66/dsh-scrapling`。包在公共 npm registry 上,安装不需要凭据,也不需要 scoped-registry 配置行。
77
81
 
78
82
  - **需要 Node.js `>= 24.9`。** 本包是 ESM-only,且构建入口(`build-client.ts`、`build-host.ts`、`build-cli.ts`)由 `node` 直接执行,所以下限必须落在 TypeScript 类型剥离默认开启的那批版本上(Node 22.18 起)。数字本身取自宿主:`0.2.2` 系列宿主声明 Node `>= 24.9.0`,低于它的宿主根本起不来。
79
- - **需要宿主 `dsh` 处在 `0.2.1-rc.5` 或 `0.2.2-alpha.3` 版本线。** 宿主真正读的是 `engines.dsh`(`^0.2.1-rc.5 || ^0.2.2-alpha.3`),且它**单独决定**;更新版本线的宿主会被拒,需要显式风险授权 `dsh plugin --profile <p> allow-version <pkg>@<ver> --dsh-version <exact> --accept-risk`。支持窗口是滚动的:本包在发布时把窗口内的每个已发布宿主版本逐版取证,窗口滚动后重新取证,不把这一句里的版本号当长期承诺。
83
+ - **需要宿主 `dsh` 处在 `0.2.2-rc.1` 或更新的 `0.2.2` 版本线。** 宿主真正读的是 `engines.dsh`(`^0.2.2-rc.1`),且它**单独决定**;更新版本线的宿主会被拒,需要显式风险授权 `dsh plugin --profile <p> allow-version <pkg>@<ver> --dsh-version <exact> --accept-risk`。支持窗口是滚动的:本包在发布时把窗口内的每个已发布宿主版本逐版取证,窗口滚动后重新取证,不把这一句里的版本号当长期承诺。
80
84
  - **需要 Python 3.14+ 且装好 Scrapling** —— 由 `pythonBin` 指定,或按 `lib/runtime.ts` 的固定链找到:`dataDir/runtime` 下的托管 runtime → 仓内 `_env/.venv` → `PATH`。装出去的包里没有 `_env/.venv` 这一档,所以跑过 `setup --feature core --apply` 的机器用的是那支托管解释器,没装过就是你 `PATH` 上的 `python3`(Windows 上是 `python`);选中哪一支会在装载时写进日志,缺 Scrapling 时报错里带着可直接照抄的安装命令。
81
85
 
82
86
  ```sh
@@ -110,7 +114,7 @@ dsh-scrapling setup --status
110
114
  - `--offline <目录>` 全程不联网:`<目录>` 里要有 Python 归档(文件名与清单 URL 的最后一段一致,浏览器与 `curl -O` 写到磁盘的 `cpython-3.14.9+…-install_only.tar.gz` 可用,百分号转义那种写法也认),以及一个 `wheels/` 目录(每条钉版一枚 wheel,可用 `pip download --only-binary=:all: --require-hashes -r py/runtime-requirements.txt -d <目录>/wheels` 生成)。Python 归档的哈希校验与联网路径一致,pip 带 `--no-index`;缺归档或缺 wheelhouse 时报 `INSTALL_OFFLINE_ASSETS`,不会悄悄退回联网。
111
115
  - `setup --status` 打印一份 JSON:`dataDir`、`profile`、`runtime`、`packs` 与 `state`。带 `--profile <目录>` 时读该 profile 的 `cordis.patch.yml`,按本包条目里的 `pythonBin` 与 `dataDir`(宿主真正在用的那两个设置)解析解释器,`packs` 与 `state` 也改报那份目录——条目里没写 `dataDir` 时这两项回落 CLI 自己的默认目录;不带 `--profile` 时 `profile.path` 为 `null`,输出里有一句说明没读 profile,`runtime` 回落到 CLI 自己的链(托管 runtime → 仓内 `_env/.venv` → PATH `python3`)。要拿 `--status` 和设置卡上的解释器对照,就带上 `--profile`。
112
116
  - profile 同时有远程读取接口与作业后端时,设置卡能经 `scraplingRuntime` 发起同一套安装/修复/取消;否则显示可照抄的 CLI 命令。
113
- - `integrationMode` 只在部署配置里;`setup --mode` 负责打印或写出两种 MCP 接法的客户端条目,`doctor` 用来核对一份 profile —— 见 [MCP 模式](#mcp-模式)。`official-mcp` 起的是托管 venv 里的 `scrapling-mcp`,由 `mcp` 能力包装进去(`setup --feature mcp --apply`)。
117
+ - `integrationMode` 只在部署配置里;宿主有 `mcpManager`(rc.2 的 web 组合包)时,MCP server 在装载时自动动态注册;`setup --mode` 负责为没有该服务的 CLI/headless profile 打印或写出客户端条目,`doctor` 用来核对一份 profile —— 见 [MCP 模式](#mcp-模式)。`official-mcp` 起的是托管 venv 里的 `scrapling-mcp`,由 `mcp` 能力包装进去(`setup --feature mcp --apply`)。
114
118
  - 只验证了 **macOS arm64**。Windows、Linux 与 macOS x64 是 blocked(B1/B2):所有包都报 `blocked`,安装器直接拒绝,不猜资产路径。
115
119
 
116
120
  ## <img src="https://api.iconify.design/lucide/circle-check.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> 确认它真的在工作
@@ -126,7 +130,7 @@ dsh-scrapling setup --status
126
130
  - **它不是搜索引擎。** 检索由 Python sidecar 走六条后端之一(`searchBackend`:`auto` / `tavily` / `bing` / `brave` / `serper` / `duckduckgo` / `searxng`);Scrapling 自己的 `google_search` 选项只是加一个 Google referer 头。每条后端都要自己的配置(`tavilyApiKey`、`braveApiKey`、`serperApiKey`、`searxngEndpoint`)—— 选中却没配的后端报 `SEARCH_AUTH`,不会静默换到别的后端。
127
131
  - **npm tarball 里没有解释器与浏览器。** 它们来自你的机器,或来自可选的 CLI 安装器 —— 后者把已验证的 macOS arm64 资产装进 `dataDir/runtime`;装载时缺什么就少注册什么,不会临时去下载。
128
132
  - **它不在宿主侧新增 HTTP 路由。** 设置卡是宿主的配置表单,本包没有自己的 `/api` 面。唯一真会 listen 的是 `integrationMode: mcp` 下那个 MCP server,只绑 `127.0.0.1`(`http://127.0.0.1:<mcpPort>/mcp`):非 `/mcp` 路径回 404,声明超过 1 MiB 的正文回 413、不带 `Content-Length` 的回 411,Bearer token 只从环境变量 `DSH_SCRAPLING_MCP_TOKEN` 读,没设时启动会往 stderr 打一条「无鉴权、本机任意进程可调」的告知。
129
- - **它不加 dsh 子命令。** 本包自己的 `dsh-scrapling` CLI 管运行时能力包,另外管 MCP 接法的两件事:`setup --mode native|mcp|official-mcp` 生成客户端条目、带 `--apply` 时写到 `<dataDir>/mcp/<模式>.patch.yml`(profile 本体一个字不改),`doctor --mode` 拿那份条目与 profile 的 `cordis.patch.yml` 逐条核对。`setup --status` 给了 `--profile` 时读的也是那份文件里的 `pythonBin` 与 `dataDir`。
133
+ - **它不加 dsh 子命令。** 本包自己的 `dsh-scrapling` CLI 管运行时能力包,另外管没有 `mcpManager` 的 profile 上那半套手工 MCP 接法:`setup --mode native|mcp|official-mcp` 生成客户端条目、带 `--apply` 时写到 `<dataDir>/mcp/<模式>.patch.yml`(profile 本体一个字不改),`doctor --mode` 拿那份条目与 profile 的 `cordis.patch.yml` 逐条核对。`setup --status` 给了 `--profile` 时读的也是那份文件里的 `pythonBin` 与 `dataDir`。
130
134
 
131
135
  ## <img src="https://api.iconify.design/lucide/plug.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> 在 dsh 里启用
132
136
 
@@ -195,7 +199,7 @@ dsh-scrapling setup --status
195
199
  |---|---|
196
200
  | `native`(默认) | 上面列出的 `scrapling_*` 工具 |
197
201
  | `mcp` | 不注册原生工具;把同一份工具表端成 MCP server |
198
- | `official-mcp` | 既不注册原生工具,也不起本插件的 server;`setup` 只生成官方 `scrapling-mcp` 的 `dsh-mcp-client` 条目 —— 它跑在自己的进程与会话里,**不经本插件的 URL 闸门** |
202
+ | `official-mcp` | 既不注册原生工具,也不起本插件的 server;宿主有 `mcpManager` 时它动态注册官方 `scrapling-mcp`,没有时由 `setup` 生成官方 `scrapling-mcp` 的 `dsh-mcp-client` 条目 —— 它跑在自己的进程与会话里,**不经本插件的 URL 闸门** |
199
203
 
200
204
  `mcp` 模式的 server 跑在插件自己的宿主进程里,调的还是同一个 sidecar,所以 URL 闸门、会话、作业与 adaptive 存储都是原生工具那一份 —— 不存在第二套实现可以漂移。
201
205
 
@@ -227,12 +231,12 @@ dsh-scrapling setup --status
227
231
  | `scrapling_screenshot` | `screenshot` |
228
232
  | —(只在 `ctx.web`) | `search` |
229
233
 
230
- 要接进 dsh 需要 `@deepseek-ai/dsh-mcp-client`,本插件刻意不依赖它。装与当期宿主同一条线的版本 —— npm 的 `latest` 比宿主还旧,宿主对不匹配的对端是直接拒绝:
234
+ 宿主有 `mcpManager` 服务时(rc.2 的 web/桌面组合包),插件在装载时把自己的 server 注册进去:不用装 `dsh-mcp-client`,也不用往 profile 加条目,只有 `mcpPort` 决定端点。下面的手工条目是给没有该服务的 CLI/headless profile 用的。升级上来的 profile 若还留着那条手工条目,切到动态注册时请把它删掉 —— 否则 manager 会因重名拒绝动态注册,实际仍由旧条目提供服务。
235
+
236
+ 要接进 dsh 需要 `@deepseek-ai/dsh-mcp-client`,本插件刻意不依赖它。装与宿主**逐版**相同的那一支 —— npm 的 `latest` 比宿主还旧,而客户端对宿主各包的 peer 是逐字同版,差一个预发布就会「装得上、永不生效」。默认是 `0.2.2-rc.2`;仍停在 rc.1 的宿主装 `0.2.2-rc.1`,`next` 跟官方 beta 线:
231
237
 
232
238
  ```bash
233
- dsh plugin --profile <名> add @deepseek-ai/dsh-mcp-client@0.2.2-rc.1
234
- # 宿主在 0.2.2-alpha.3 线时改用 @deepseek-ai/dsh-mcp-client@0.2.2-alpha.3
235
- # 宿主在 0.2.1-rc.5 线时改用 @deepseek-ai/dsh-mcp-client@0.2.1-rc.5
239
+ dsh plugin --profile <名> add @deepseek-ai/dsh-mcp-client@0.2.2-rc.2
236
240
  ```
237
241
 
238
242
  再往那个 profile 的 `cordis.patch.yml` 加一条(没配 token 就不写 `headers`):
@@ -265,9 +269,9 @@ dsh-scrapling setup --mode native --apply # 写出的文件里一条条目
265
269
  dsh-scrapling doctor --mode mcp --profile <profileDir>
266
270
  ```
267
271
 
268
- `doctor` 读的是 profile 自己写下的东西 —— `cordis.patch.yml` 加那份 `package.json` —— 每处问题打一行:`serverName: scrapling` 下有两条例目、本插件的条目与官方 `stdio` 那条并存、条目类型与模式不符、条目的端口与 `--port` 说的不一致、profile 里没有 `@deepseek-ai/dsh-mcp-client` 或它钉的不是 `0.2.2-rc.1` / `0.2.2-alpha.3` / `0.2.1-rc.5` / `next`、以及 `officialMcpEnabled` 关着却留着官方条目。退 `0` 是一致,`1` 是至少点出一处,`2` 是参数不对。`integrationMode` 本身是插件设置,CLI 读不到,所以 `--mode` 就是被核对的那一句声明,它必须和部署配置说的是同一件事。
272
+ `doctor` 读的是 profile 自己写下的东西 —— `cordis.patch.yml` 加那份 `package.json` —— 每处问题打一行:`serverName: scrapling` 下有两条例目、本插件的条目与官方 `stdio` 那条并存、条目类型与模式不符、条目的端口与 `--port` 说的不一致、profile 里没有 `@deepseek-ai/dsh-mcp-client` 或它钉的不是 `0.2.2-rc.2` / `0.2.2-rc.1` / `next`、以及 `officialMcpEnabled` 关着却留着官方条目。退 `0` 是一致,`1` 是至少点出一处,`2` 是参数不对。`integrationMode` 本身是插件设置,CLI 读不到,所以 `--mode` 就是被核对的那一句声明,它必须和部署配置说的是同一件事。
269
273
 
270
- `official-mcp` 要两处分开表态才会产出:profile 里的 `officialMcpEnabled: true`,以及命令行的 `--accept-risk`;缺任何一处只打 `OFFICIAL_MCP_DISABLED` / `RISK_NOT_ACCEPTED`,一个字节都不写。它生成的条目起的是 `<dataDir>/runtime/venv/bin/scrapling-mcp`,所以要先跑 `setup --feature mcp --apply` —— 见[运行时能力包](#运行时能力包macos-arm64)。那枚二进制不存在时,`setup` 会额外打一行说明这条条目现在起不来。
274
+ `setup` 生成 `official-mcp` 条目要两处分开表态:profile 里的 `officialMcpEnabled: true`,以及命令行的 `--accept-risk`;缺任何一处只打 `OFFICIAL_MCP_DISABLED` / `RISK_NOT_ACCEPTED`,一个字节都不写。装载时的宿主侧路径只由 `officialMcpEnabled` 决定:有 `mcpManager` 的宿主直接动态注册托管的 `scrapling-mcp`,`setup` 生成的 `dsh-mcp-client` 条目则留给没有该服务的 CLI/headless profile。两条路径起的都是 `<dataDir>/runtime/venv/bin/scrapling-mcp`,所以要先跑 `setup --feature mcp --apply` —— 见[运行时能力包](#运行时能力包macos-arm64)。那枚二进制不存在时,`setup` 会额外打一行说明这条条目现在起不来。
271
275
 
272
276
  ## <img src="https://api.iconify.design/lucide/sliders-horizontal.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> 设置项
273
277
 
@@ -392,7 +396,7 @@ dsh-scrapling doctor --mode mcp --profile <profileDir>
392
396
  - **Shopify 爬虫模式走店铺的 JSON 接口。** `mode=shopify` 用店铺的 `/collections.json` 与每个集合的 `/products.json`(上游的 `ShopifySpider`),按变体出行 —— `name`(商品名 + 变体名,`Default Title` 不拼)、`price`、`sku`、`stock`(有货为 `null`、缺货为 `0`)、`identifier`、`brand`、`category`、`image_url`、`url`、`barcode`、`old_price`、`description`。它不抓商品 HTML,URL 闸门、robots、间隔与并发与其他爬虫模式同一批旋钮。已在本地测试数据店上验证;真实 Shopify 店铺未跑过(B11)。
393
397
  - **`maxPages` 收敛的是收进结果的页数,不是爬虫发出的请求量。** 链接发现层会继续请求队列里的页面(实测一次 `maxPages=3` 的爬取发出了约 680 个请求,收页 3)。对目标站点的礼貌性由部署侧旋钮控制:`crawlRespectRobots`、`crawlDownloadDelayMs`、`crawlConcurrentRequests`、`crawlAutothrottle`。
394
398
  - **重资源站点在浏览器支路上可能等不到 `load` 事件。** 默认页面超时 30 秒内一直有资源在途时,`scrapling_session_fetch` / `scrapling_render` 以抓取失败收场,而同一 URL的静态抓取正常。缓解:`waitSelector`(等到关键元素出现)或 `disableResources`(拦截图片与字体),两者都是模型可按次传的参数。
395
- - **`official-mcp` 只生成配置。** `integrationMode=official-mcp` 不注册原生工具、也不起本插件的 server;`setup --mode official-mcp --accept-risk` 交回官方 server 的 `dsh-mcp-client` 条目,而它指向的那枚二进制由 `mcp` 能力包提供(B10 就是这条条目背后那次风险确认)。
399
+ - **`official-mcp` 接的是上游 server。** `integrationMode=official-mcp` 不注册原生工具、也不起本插件的 server;宿主有 `mcpManager`(rc.2 的 web 组合包)时动态注册托管的 `scrapling-mcp`,没有该服务(CLI/headless)时改由 `setup --mode official-mcp --accept-risk` 交回 `dsh-mcp-client` 条目。那枚二进制由 `mcp` 能力包提供(B10 就是这条条目背后那次风险确认)。
396
400
 
397
401
  ## <img src="https://api.iconify.design/lucide/circle-help.svg?color=%23658EFF&height=22" height="22" width="22" align="absmiddle" alt="" /> 常见问题
398
402
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as e}from"node:module";import{accessSync as t,constants as n,existsSync as r,readFileSync as i,statSync as a}from"node:fs";import{access as o,chmod as s,cp as c,mkdir as l,open as u,readFile as d,readdir as f,rename as p,rm as m,rmdir as h,writeFile as ee}from"node:fs/promises";import te from"node:os";import g from"node:path";import{createHash as ne,randomUUID as re}from"node:crypto";import{spawn as ie}from"node:child_process";const ae=`scrapling`,oe=`streamable-http`,se=`stdio`,ce=`DSH_SCRAPLING_MCP_TOKEN`,_=`@deepseek-ai/dsh-mcp-client`,le=`0.2.2-rc.1`,ue=[le,`0.2.2-alpha.3`,`0.2.1-rc.5`,`next`],de=[`native`,`mcp`,`official-mcp`],fe=new Set(de);function pe(e){return fe.has(e)}function me(e,t){if(!Number.isInteger(e)||e<1||e>65535)throw Error(`MCP port must be an integer in 1..65535, got ${String(e)}`);return`http://${t.includes(`:`)&&!t.startsWith(`[`)?`[${t}]`:t}:${String(e)}/mcp`}function he(e=le){if(!ue.includes(e))throw Error(`unsupported MCP client pin: ${JSON.stringify(e)}`);return`dsh plugin --profile <profile> add ${_}@${e}`}var ge=class extends Error{code;constructor(e,t){super(t),this.name=`OfficialMcpError`,this.code=e}};function _e(e){let t=g.join(e,`runtime`,`venv`);return process.platform===`win32`?g.join(t,`Scripts`,`scrapling-mcp.exe`):g.join(t,`bin`,`scrapling-mcp`)}function ve(e){switch(e){case`"`:return String.raw`\"`;case`\\`:return String.raw`\\`;case`
3
- `:return String.raw`\n`;case`\r`:return String.raw`\r`;case` `:return String.raw`\t`;default:return`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`}}const ye=/[\u0000-\u001F\u007F-\u009F"\\]/gu;function be(e){return`"${e.replaceAll(ye,e=>ve(e))}"`}const xe="official-mcp 直连官方 scrapling-mcp:它的全部工具不经本插件的 URL 守卫与会话闸门(钉住的 scrapling 版本里有 `browser_evaluate` 这类任意 JS 执行),用的是它自己的会话与状态,本插件既不复用也不拦截。";function Se(e){if(!e.enabled)throw new ge(`OFFICIAL_MCP_DISABLED`,`official-mcp 未启用:部署配置里把 officialMcpEnabled 设为 true 才会生成接入配置`);if(!e.acceptedRisk)throw new ge(`RISK_NOT_ACCEPTED`,`${xe} 确认接受请再跑一次 setup 并带 --accept-risk。`);let t=_e(e.dataDir);return{command:t,args:[],serverName:ae,risk:xe,installCommand:he(`0.2.2-rc.1`),patch:[`- insert:`,` - id: scrapling-official-mcp`,` name: '${_}'`,` config:`,` serverName: ${ae}`,` transport: ${se}`,` command: ${be(t)}`,` args: []`,` failOnStartupError: true`,``].join(`
2
+ import{createRequire as e}from"node:module";import{accessSync as t,constants as n,existsSync as r,readFileSync as i,statSync as a}from"node:fs";import{access as o,chmod as s,cp as c,mkdir as l,open as u,readFile as d,readdir as f,rename as p,rm as m,rmdir as h,writeFile as ee}from"node:fs/promises";import te from"node:os";import g from"node:path";import{createHash as ne,randomUUID as re}from"node:crypto";import{spawn as ie}from"node:child_process";const ae=`scrapling`,oe=`streamable-http`,se=`stdio`,ce=`DSH_SCRAPLING_MCP_TOKEN`,_=`@deepseek-ai/dsh-mcp-client`,le=`0.2.2-rc.2`,ue=[le,`0.2.2-rc.1`,`next`],de=[`native`,`mcp`,`official-mcp`],fe=new Set(de);function pe(e){return fe.has(e)}function me(e,t){if(!Number.isInteger(e)||e<1||e>65535)throw Error(`MCP port must be an integer in 1..65535, got ${String(e)}`);return`http://${t.includes(`:`)&&!t.startsWith(`[`)?`[${t}]`:t}:${String(e)}/mcp`}function he(e=le){if(!ue.includes(e))throw Error(`unsupported MCP client pin: ${JSON.stringify(e)}`);return`dsh plugin --profile <profile> add ${_}@${e}`}var ge=class extends Error{code;constructor(e,t){super(t),this.name=`OfficialMcpError`,this.code=e}};function _e(e){let t=g.join(e,`runtime`,`venv`);return process.platform===`win32`?g.join(t,`Scripts`,`scrapling-mcp.exe`):g.join(t,`bin`,`scrapling-mcp`)}function ve(e){switch(e){case`"`:return String.raw`\"`;case`\\`:return String.raw`\\`;case`
3
+ `:return String.raw`\n`;case`\r`:return String.raw`\r`;case` `:return String.raw`\t`;default:return`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`}}const ye=/[\u0000-\u001F\u007F-\u009F"\\]/gu;function be(e){return`"${e.replaceAll(ye,e=>ve(e))}"`}const xe="official-mcp 直连官方 scrapling-mcp:它的全部工具不经本插件的 URL 守卫与会话闸门(钉住的 scrapling 版本里有 `browser_evaluate` 这类任意 JS 执行),用的是它自己的会话与状态,本插件既不复用也不拦截。";function Se(e){if(!e.enabled)throw new ge(`OFFICIAL_MCP_DISABLED`,`official-mcp 未启用:部署配置里把 officialMcpEnabled 设为 true 才会生成接入配置`);if(!e.acceptedRisk)throw new ge(`RISK_NOT_ACCEPTED`,`${xe} 确认接受请再跑一次 setup 并带 --accept-risk。`);let t=_e(e.dataDir);return{command:t,args:[],serverName:ae,risk:xe,installCommand:he(`0.2.2-rc.2`),patch:[`- insert:`,` - id: scrapling-official-mcp`,` name: '${_}'`,` config:`,` serverName: ${ae}`,` transport: ${se}`,` command: ${be(t)}`,` args: []`,` failOnStartupError: true`,``].join(`
4
4
  `)}}function Ce(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const we=/\r\n|\n|\r/u,Te=/:(?<port>\d+)/u,Ee=/[\t ]#.*$/u,De=/^(?:"(?<double>[^"]*)"|'(?<single>[^']*)')$/u,Oe=/^(?:-[\t ]*)?name:(?<value>.*)$/u,ke=/^(?<key>[\w-]+):[\t ]+(?<value>\S.*)$/u;function Ae(e){let t=e.replace(Ee,``).trim(),n=De.exec(t)?.groups,r=n?.double??n?.single;return r===void 0?t.length===0?void 0:t:r}function je(e){return e.split(we)}function Me(e){let t=[],n;for(let r of je(e)){let e=r.length-r.trimStart().length,i=r.slice(e),a=Ae(Oe.exec(i)?.groups?.value??``),o=ke.exec(i)?.groups;a===void 0?o?.key!==void 0&&o.value!==void 0&&n!==void 0&&e>n.indent&&(n.entry.config[o.key]=Ae(o.value)):(n={entry:{name:a,config:{}},indent:e},t.push(n.entry))}return t}function Ne(e){let{url:t}=e.config,n;if(t!==void 0)try{let{port:e,protocol:r}=new URL(t);e===``?r===`http:`?n=`80`:r===`https:`&&(n=`443`):n=e}catch{n=Te.exec(t)?.groups?.port}return n}function Pe(e){return e.config.transport===se}function Fe(e){let t=[];e.mode!==`native`&&e.clientVersion===void 0&&t.push({code:`MCP_CLIENT_MISSING`,detail:`profile 没有 ${_}:跑 ${he()} 装上它`});let n=e.clientVersion;return n!==void 0&&!ue.includes(n)&&t.push({code:`MCP_CLIENT_UNPINNED`,detail:`客户端钉的是 ${e.clientVersion},只接受 ${ue.join(` 或 `)} —— 宿主对不匹配的对端拒绝装载`}),t}function Ie(e,t){let n=[];t.length>1&&n.push({code:`DUPLICATE_SCRAPLING_ENTRY`,detail:`serverName 为 scrapling 的条目有 ${String(t.length)} 条,一个名字只能有一个 server`}),t.some(e=>Pe(e))&&t.some(e=>!Pe(e))&&n.push({code:`MCP_MODE_CONFLICT`,detail:`本插件的 ${oe} 条目与官方 ${se} 条目并存;同一时刻只能一种`});let r=e.mode===`official-mcp`,i=t.some(e=>r===Pe(e));return e.mode===`native`&&t.length>0?n.push({code:`MCP_MODE_ENTRY_MISMATCH`,detail:`integrationMode=native 却留着 scrapling 的 MCP 条目:模型会同时看到两套工具`}):e.mode!==`native`&&!i&&n.push({code:`MCP_MODE_ENTRY_MISMATCH`,detail:`integrationMode=${e.mode} 需要 ${r?se:oe} 条目,profile 里没有`}),r&&!e.officialMcpEnabled&&t.some(e=>Pe(e))&&n.push({code:`MCP_OFFICIAL_SWITCH_OFF`,detail:`留着官方 stdio 条目但 officialMcpEnabled=false:官方 server 的工具不经本插件守卫,开关要明说`}),n}function Le(e,t){let n=[...new Set(e.map(e=>Ne(e)).filter(e=>e!==void 0))];if(n.length===0)return[];let r=t===void 0?void 0:String(t);return n.length<2&&(r===void 0||n.includes(r))?[]:[{code:`MCP_PORT_MISMATCH`,detail:`条目里的端口是 ${n.join(`, `)}${r===void 0?``:`,--port 说的是 ${r}`};改过 mcpPort 就要重新应用 patch`}]}function Re(e){let t=Me(e.patchText).filter(e=>e.name===`@deepseek-ai/dsh-mcp-client`&&e.config.serverName===`scrapling`);return[...Fe(e),...Ie(e,t),...Le(t,e.expectedPort)]}const ze=/^[\t ]*officialMcpEnabled:(?<value>[^\r\n]*)$/gmu;function Be(e){let t;for(let n of e.matchAll(ze))t=n.groups?.value;let n=t?.replace(Ee,``).trim(),r=n===void 0?void 0:De.exec(n)?.groups;return r?.double??r?.single??n}function Ve(e){let t=Be(e);return t===`true`||t===`True`||t===`TRUE`}async function He(e){try{return await d(e,`utf8`)}catch(t){if(Ce(t)&&t.code===`ENOENT`)return``;throw Error(`读不出 ${e}:${String(t)}`,{cause:t})}}function Ue(e){try{let t=JSON.parse(e);return Ce(t)?t:{}}catch{return{}}}function We(e){let{dependencies:t}=Ue(e),n=Ce(t)?t[_]:void 0;return typeof n==`string`?n:void 0}async function Ge(e){let[t,n]=await Promise.all([He(g.join(e,`cordis.patch.yml`)),He(g.join(e,`package.json`))]);return{patchText:t,clientVersion:We(n),officialMcpEnabled:Ve(t)}}function Ke(e){return`${e}.patch.yml`}function qe(e){let t=[`- insert:`,` - id: scrapling-mcp`,` name: '${_}'`,` config:`,` serverName: ${ae}`,` transport: ${oe}`,` url: ${me(e.port,`127.0.0.1`)}`,` failOnStartupError: false`];return e.withAuth&&t.push(` headers:`,` Authorization: !!js '\`Bearer \${process.env.${ce}}\`'`),`${t.join(`
5
5
  `)}\n`}function Je(){return[`# integrationMode=native:profile 里不留 scrapling 的 MCP 条目。`,`# 留着条目时模型会同时看到原生工具与 mcp__scrapling__* 两套同名不同层的工具。`,`# 这份文本本身不删任何东西:profile 里若已有 name: '${_}' 的条目,`,"# 要手工删掉它再重启宿主,否则 `doctor --mode native` 会按事实报 MCP_MODE_ENTRY_MISMATCH。",``].join(`
6
6
  `)}const Ye=[`auto`,`tavily`,`bing`,`brave`,`serper`,`duckduckgo`,`searxng`];function Xe(e){return Ye.includes(e)}function Ze(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function Qe(e,t=`|`){return e.map(e=>_t(e)).join(t)}function $e(e,t){return typeof t==`bigint`?t.toString():t}var et=class{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return e!==void 0&&(this._value=e(),this._getter=void 0),this._value}};function tt(e){return new et(e)}function nt(e){return e==null}function rt(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function it(e,t){let n=e/t,r=Math.round(n),i=4*2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}function v(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function at(e){let t=Object.getOwnPropertyDescriptor(e,`shape`);return t?.get?t.get.raw:t?.value}function y(e){return at(e._zod.def)??e._zod.def.shape}function ot(e,t,n){Object.defineProperty(e,t,{get(){let e=n();return v(this,t,e),e},enumerable:!0,configurable:!0})}function st(e,t,n){t in e?v(e,t,n):e[t]=n}function b(e,t,n,r){let i=y(t);for(let a of n){let n=Object.getOwnPropertyDescriptor(i,a);n.enumerable&&(n.get?ot(e,a,()=>{let e=t._zod.def.shape[a];return r?r(e,a):e}):st(e,a,r?r(n.value,a):n.value))}}function ct(e,t){for(let n of Reflect.ownKeys(t)){let r=Object.getOwnPropertyDescriptor(t,n);r.enumerable&&(r.get?ot(e,n,()=>t[n]):st(e,n,r.value))}}function x(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function lt(e){return JSON.stringify(e)}function ut(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}const dt=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function ft(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const pt=/* @__PURE__*/ tt(()=>{if(N.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function S(e){if(ft(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return ft(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function mt(e){return S(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}const ht=/* @__PURE__*/ new Set([`string`,`number`,`symbol`]);function gt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function C(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function w(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function _t(e){return typeof e==`bigint`?e.toString()+`n`:typeof e==`string`?`"${e}"`:`${e}`}function vt(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout===`optional`)}const yt={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},bt={int64:[/* @__PURE__*/ BigInt(`-9223372036854775808`),/* @__PURE__*/ BigInt(`9223372036854775807`)],uint64:[/* @__PURE__*/ BigInt(0),/* @__PURE__*/ BigInt(`18446744073709551615`)]};function xt(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);let i={};return b(i,e,St(e,t)),C(e,x(n,{shape:i,checks:[]}))}function St(e,t){let n=y(e),r=[];for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(n,e)?.enumerable)throw Error(`Unrecognized key: "${String(e)}"`);t[e]&&r.push(e)}return r}function Ct(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);let i=new Set(St(e,t)),a={};return b(a,e,Reflect.ownKeys(y(e)).filter(e=>!i.has(e))),C(e,x(n,{shape:a,checks:[]}))}function wt(e,t){if(!S(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=y(e);for(let e of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return C(e,x(e._zod.def,{shape:Tt(e,t)}))}function Tt(e,t){let n={};return b(n,e,Reflect.ownKeys(y(e))),ct(n,t),n}function Et(e,t){if(!S(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return C(e,x(e._zod.def,{shape:Tt(e,t)}))}function Dt(e,t){if(!t?._zod?.def)throw Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);let n={};return b(n,e,Reflect.ownKeys(y(e))),b(n,t,Reflect.ownKeys(y(t))),C(e,x(e._zod.def,{shape:n,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function Ot(e,t,n,r=`partial`){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${r}() cannot be used on object schemas containing refinements`);let a=n?new Set(St(t,n)):void 0,o={};return b(o,t,Reflect.ownKeys(y(t)),e&&((t,n)=>a&&!a.has(n)?t:new e({type:`optional`,innerType:t}))),C(t,x(t._zod.def,{shape:o,checks:[]}))}function kt(e,t,n){let r=n?new Set(St(t,n)):void 0,i={};return b(i,t,Reflect.ownKeys(y(t)),(t,n)=>r&&!r.has(n)?t:new e({type:`nonoptional`,innerType:t})),C(t,x(t._zod.def,{shape:i}))}function T(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function At(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function E(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function jt(e){return typeof e==`string`?e:e?.message}function Mt(e){let t=[];for(let n of e??[]){let e=n._zod.def;if(!/_(length|size)$|_equals$/.test(e.check))break;let r=e.maximum??e.length??e.size;r>=0&&t.push([r,n])}return t}function Nt(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function D(e,t,n){var r;let i=e.inst?._zod?.traits;i?.has(`$ZodType`)&&(i.has(`$ZodCheck`)?(r=e).schema??(r.schema=e.inst):e.schema=e.inst);let a=e.schema===e.inst?void 0:e.schema?._zod.def?.error,o=e.message?e.message:jt(e.inst?._zod.def?.error?.(e))??jt(a?.(e))??jt(t?.error?.(e))??jt(n.customError?.(e))??jt(n.localeError?.(e))??`Invalid input`,s={};for(let t of Object.keys(e))t!==`inst`&&t!==`schema`&&t!==`continue`&&t!==`input`&&t!==`__proto__`&&(s[t]=e[t]);return s.path??=[],s.message=o,t?.reportInput&&(s.input=e.input),s}const Pt=/[\uD800-\uDBFF]/;function Ft(e){let t=e.length;if(!Pt.test(e))return t;let n=t;for(let r=0;r<t-1;r++)(e.charCodeAt(r)&64512)==55296&&(e.charCodeAt(r+1)&64512)==56320&&(n--,r++);return n}function It(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function Lt(e){let t=typeof e;switch(t){case`number`:return Number.isNaN(e)?`nan`:`number`;case`object`:{if(e===null)return`null`;if(Array.isArray(e))return`array`;let t=e;if(t&&Object.getPrototypeOf(t)!==Object.prototype&&`constructor`in t&&t.constructor)return t.constructor.name}}return t}function Rt(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function zt(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):Ht(e,n,r.value)}}function O(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function Bt(e,t,n){return O(e,t,n,!1)}/* @__NO_SIDE_EFFECTS__ */