dsh-free-search 0.9.79 → 0.9.80

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
@@ -642,7 +642,7 @@ npx -y -p dsh-free-search dsh-free-search-mcp
642
642
 
643
643
  #### 离线自检断言(tools/)
644
644
 
645
- 仓库自带 **98 个**零依赖断言脚本(合计 **1243 项**)
645
+ 仓库自带 **98 个**零依赖断言脚本(合计 **1249 项**)
646
646
 
647
647
  | 脚本 | 覆盖 | 运行(项数) |
648
648
  |---|---|---|
@@ -696,7 +696,7 @@ npx -y -p dsh-free-search dsh-free-search-mcp
696
696
  | `assert-pool-prompt.mjs` | 入池策略与提示词一致(#152):`off` 保留「只在显式选择时运行」、`auto` 改写为「最多一个、计费一次」、`multi` 改写为「每个引擎各计费一次」、Multi 池只在 `multi` 档列出按次计费引擎、中文文案同步 | `node tools/assert-pool-prompt.mjs`(5) |
697
697
  | `assert-fetch-ssrf-wiring.mjs` | #156 回归:`lib/index.js` 必须以 provider 自己的选项名 `allowedCidrs` 传白名单(写成 `allowFakeIpCidrs` 会被静默丢弃)、白名单能到达 `validateUrl`、错拼的键回退为空列表 | `node tools/assert-fetch-ssrf-wiring.mjs`(3) |
698
698
  | `assert-rail-keys.mjs` | 侧栏目录的渲染 key:每项圆点与文字两个子元素都必须带稳定 key,避免 React 在每次渲染时报 unique key 警告 | `node tools/assert-rail-keys.mjs`(3) |
699
- | `assert-mcp-response-cap.mjs` | #147 MCP stdio 单条响应上限:字符/字节双上限默认值与环境覆盖、0 关闭、多字节文本不超 64KB 行、handler 对结果与错误统一截断、web_fetch 先按上限收缩、research 文档按剩余预算均分 | `node tools/assert-mcp-response-cap.mjs`(12) |
699
+ | `assert-mcp-response-cap.mjs` | #147 MCP stdio 单条响应上限:字符/字节/整行三重上限默认值与环境覆盖、0 关闭、多字节文本不超 64KB 行、**JSON 转义后的整行不超 64KB**(引号/换行/反斜杠密集三种形状)、不重复叠加截断提示、不切在代理对中间、handler 对结果与错误统一截断、web_fetch 先按上限收缩、research 文档按剩余预算均分 | `node tools/assert-mcp-response-cap.mjs`(18) |
700
700
  | `assert-fetch-ssrf.mjs` | 抓取 SSRF 防护:公网/私网/保留地址判定、DNS 解析到私网拒绝、localhost 与 IP 字面量拒绝、`http://` 与 `https://` 放行而其他协议与带凭据 URL 拒绝、http 目标解析到私网同样拒绝、fake-ip 网段默认拒绝且仅按配置放行、IPv6 ULA 显式放行、放行后仍拒绝回环/IPv4 私网/链路本地、provider 接线与设置项 | `node tools/assert-fetch-ssrf.mjs`(10) |
701
701
  | `assert-fetch-http.mjs` | 明文 http 目标(#143):直连层按协议选 transport、http 重定向可跟随、provider 不再在入口拒绝 http 而交给 tier 链、全层失败报直连原因而不再报 only https、非 http(s) 协议仍拒、`agentForUrl` 为 http 目标选明文隧道 agent、经 `CONNECT` 隧道抓取 http 页面 | `node tools/assert-fetch-http.mjs`(7) |
702
702
  | `assert-mcp.mjs` | MCP stdio 面:initialize 协议协商、tools/list 的 JSON Schema、tools/call 文本结果、工具错误与 JSON-RPC 错误区分、必填参数校验、显式付费引擎与新 provider、advanced/multi/domain/platform/video/research/weather 新工具、bin/files 打包 | `node tools/assert-mcp.mjs`(10) |
@@ -1415,7 +1415,7 @@ Restart `dsh web` after switching to apply changes.
1415
1415
 
1416
1416
  #### Offline self-check assertions (`tools/`)
1417
1417
 
1418
- **Ninety-eight** zero-dependency assertion scripts ship with the repo (**1243 assertions** total)
1418
+ **Ninety-eight** zero-dependency assertion scripts ship with the repo (**1249 assertions** total)
1419
1419
 
1420
1420
  | Script | Covers | Run (count) |
1421
1421
  |---|---|---|
package/lib/client.js CHANGED
@@ -922,7 +922,7 @@ window.__ModuleLoader__.load({
922
922
  "cache_search",
923
923
  "domain_search",
924
924
  ];
925
- const PLUGIN_VERSION = "0.9.79";
925
+ const PLUGIN_VERSION = "0.9.80";
926
926
  const PLUGIN_REPO_URL = "https://github.com/DDDMUC/dsh-free-search";
927
927
  // 右侧浮动目录(#85):条目顺序即页面顺序,anchor 是页面里对应 field 的 id。
928
928
  const NAV_ITEMS = [
package/lib/mcp_server.js CHANGED
@@ -248,6 +248,52 @@ export function responseCapBytes() {
248
248
  return Math.floor(raw);
249
249
  }
250
250
 
251
+ // #147(补充):正文字节预算管不住真正发出去的那一行。stdout 上发的是一行 JSON,
252
+ // 正文里的 `"` 会变成 `\"`、换行变成 `\n`、反斜杠变成 `\\`,字节数最多接近翻倍,
253
+ // 48 KB 引号密集的正文序列化后能到 72 KB。所以再加一道「整行」上限。
254
+ export function responseCapLine() {
255
+ const raw = Number(env("MCP_MAX_RESPONSE_LINE_BYTES", String(64 * 1024)));
256
+ if (!Number.isFinite(raw) || raw < 0) return 64 * 1024;
257
+ return Math.floor(raw);
258
+ }
259
+
260
+ const truncationNote = (cap, bytes) =>
261
+ `\n\n[truncated${cap > 0 ? ` to ${cap} characters` : ""}${cap > 0 && bytes > 0 ? " / " : ""}${bytes > 0 ? `${bytes} bytes` : ""}; raise MCP_MAX_RESPONSE_CHARS / MCP_MAX_RESPONSE_BYTES to allow more]`;
262
+
263
+ const existingNote = /\n\n\[truncated[^\]]*\]\s*$/;
264
+
265
+ const lineNote = (cap) =>
266
+ `\n\n[truncated to fit the ${cap}-byte MCP stdio line; raise MCP_MAX_RESPONSE_LINE_BYTES to allow more]`;
267
+
268
+ // 把已经按字符/字节截过的正文,再收口到「信封 + JSON 转义后的正文」不越过整行上限。
269
+ // 用二分法找最长可行前缀,序列化次数是 log2(长度),对 48 KB 正文也就十几次。
270
+ export function fitResponseLine(text, envelope) {
271
+ const capped = clipResponse(text);
272
+ const cap = responseCapLine();
273
+ if (cap === 0) return capped;
274
+ const lineBytes = (body) => Buffer.byteLength(JSON.stringify(envelope(body)), "utf8");
275
+ if (lineBytes(capped) <= cap) return capped;
276
+
277
+ const note = lineNote(cap);
278
+ if (lineBytes(note) > cap) {
279
+ // 上限小到连提示语都放不下:只保留提示,并且绝不越界。
280
+ return note.slice(0, Math.max(0, cap - 2));
281
+ }
282
+ // 先剥掉上一轮截断留下的提示语,避免两条提示叠在一起。
283
+ const body = capped.replace(existingNote, "");
284
+ let low = 0;
285
+ let high = body.length;
286
+ while (low < high) {
287
+ const mid = Math.ceil((low + high) / 2);
288
+ if (lineBytes(body.slice(0, mid) + note) <= cap) low = mid;
289
+ else high = mid - 1;
290
+ }
291
+ // 不要切在代理对中间,否则会留下孤立的高位代理(JSON 里会变成乱码)。
292
+ const lastCode = low > 0 ? body.charCodeAt(low - 1) : 0;
293
+ if (lastCode >= 0xd800 && lastCode <= 0xdbff) low -= 1;
294
+ return body.slice(0, low) + note;
295
+ }
296
+
251
297
  // research 的文档预算:把剩余字符额度平均分给 n 篇文档,留出标题/分隔符余量。
252
298
  // 上限仍是原来的 8000 字符/篇;cap=0 时保持原行为。
253
299
  export function perDocumentBudget(count) {
@@ -267,7 +313,7 @@ export function clipResponse(text) {
267
313
  const tooLong = (candidate) =>
268
314
  (cap > 0 && candidate.length > cap) || (bytes > 0 && Buffer.byteLength(candidate, "utf8") > bytes);
269
315
  if (!tooLong(value)) return value;
270
- const note = `\n\n[truncated${cap > 0 ? ` to ${cap} characters` : ""}${cap > 0 && bytes > 0 ? " / " : ""}${bytes > 0 ? `${bytes} bytes` : ""}; raise MCP_MAX_RESPONSE_CHARS / MCP_MAX_RESPONSE_BYTES to allow more]`;
316
+ const note = truncationNote(cap, bytes);
271
317
  // 极端小的上限下,提示语本身就可能超限:只保留提示,绝不越过上限。
272
318
  if (cap > 0 && note.length >= cap) return note.slice(0, cap);
273
319
  if (bytes > 0 && Buffer.byteLength(note, "utf8") >= bytes) {
@@ -781,15 +827,14 @@ export function createMcpHandler({
781
827
  if (method === "tools/list") return { jsonrpc: "2.0", id, result: { tools: TOOLS } };
782
828
  if (method === "tools/call") {
783
829
  const name = String(params?.name ?? "");
830
+ // 信封里除了正文什么都不带,其余字段固定,序列化成本可忽略。
831
+ const envelope = (text) => ({ jsonrpc: "2.0", id, result: { content: [{ type: "text", text }], isError: false } });
832
+ const errorEnvelope = (text) => ({ jsonrpc: "2.0", id, result: { content: [{ type: "text", text }], isError: true } });
784
833
  try {
785
834
  const text = await handleTool(name, params?.arguments ?? {});
786
- return { jsonrpc: "2.0", id, result: { content: [{ type: "text", text: clipResponse(text) }], isError: false } };
835
+ return envelope(fitResponseLine(text, envelope));
787
836
  } catch (error) {
788
- return {
789
- jsonrpc: "2.0",
790
- id,
791
- result: { content: [{ type: "text", text: clipResponse(error?.message ?? String(error)) }], isError: true },
792
- };
837
+ return errorEnvelope(fitResponseLine(error?.message ?? String(error), errorEnvelope));
793
838
  }
794
839
  }
795
840
  if (method.startsWith("notifications/")) return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-free-search",
3
- "version": "0.9.79",
3
+ "version": "0.9.80",
4
4
  "description": "Free web search for DeepSeek Harness: 42 engines (Bing/DuckDuckGo/AnySearch/SearXNG/Exa/Tavily/Keenable/Firecrawl/Parallel/Brave/Zhipu/You.com keyless; Zhihu global/site via MCP and Perplexity/SerpBase/DeepSeek (official + native tools/search)/Baidu/Kimi/Aliyun/Doubao/Google CSE/Metaso/Yandex/Yuanbao/SpecStream with key; OpenAI/Gemini/Claude model built-in search, explicit-only) + auto smart routing + global engine enable/disable & fallback priority + editable zh/en language pools + multi mode (parallel full language-pool merge) + multi_search cross-source tool + failure-aware fallback (quota/auth cooldown, transient retry, fallbackOn) + time filtering + platform search + domain blocklist (blockedDomains) + web_fetch, with web settings UI, plus a standalone stdio MCP server.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",