dsh-free-search 0.9.79 → 0.9.81
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 +24 -3
- package/bin/restore.js +82 -0
- package/lib/client.js +1 -1
- package/lib/mcp_server.js +52 -7
- package/lib/restore.js +234 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -257,6 +257,16 @@ dsh web
|
|
|
257
257
|
Error: configured web provider "ddg" is not registered
|
|
258
258
|
```
|
|
259
259
|
|
|
260
|
+
**已经卸掉了、忘了删?** 插件不在也能修——新增的 `restore` 命令直接改配置文件,不加载插件:
|
|
261
|
+
|
|
262
|
+
```
|
|
263
|
+
npx dsh-free-search restore # 所有 profile
|
|
264
|
+
npx dsh-free-search restore --profile web # 只清一个
|
|
265
|
+
npx dsh-free-search restore --dry-run # 只看会改什么,不写
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
它只删本插件自己写进去的两个值(`searchProvider: ddg`、`fetchProvider: fs-quality-fetch`);你自己显式选的 provider 不动;删完只剩 `id` + `name` 的行整行去掉;注释、顺序、引号风格和 CRLF 都保留;写入前先备份成 `*.bak-before-free-search-restore`。改完重启 `dsh` 让 web 服务重建。
|
|
269
|
+
|
|
260
270
|
更早的 DSH(0.1.x)由 patch 静态覆盖 config,不需要也更不该手写这段,这里不再赘述。
|
|
261
271
|
|
|
262
272
|
#### DSH 的「DeepSeek 搜索 API」开关
|
|
@@ -642,7 +652,7 @@ npx -y -p dsh-free-search dsh-free-search-mcp
|
|
|
642
652
|
|
|
643
653
|
#### 离线自检断言(tools/)
|
|
644
654
|
|
|
645
|
-
仓库自带 **
|
|
655
|
+
仓库自带 **99 个**零依赖断言脚本(合计 **1261 项**)
|
|
646
656
|
|
|
647
657
|
| 脚本 | 覆盖 | 运行(项数) |
|
|
648
658
|
|---|---|---|
|
|
@@ -682,6 +692,7 @@ npx -y -p dsh-free-search dsh-free-search-mcp
|
|
|
682
692
|
| `assert-serper.mjs` | Serper.dev 引擎(#157):端点常量、`X-API-KEY` 鉴权(非 Bearer)、`num` 上限 100、`tbs` 时间语法(含绝对日期 `cd_min`)、`organic` 映射、401/403/429 错误分类、缺 key 快速失败、catalog 与 MCP/设置页接线 | `node tools/assert-serper.mjs`(10) |
|
|
683
693
|
| `assert-tavily-endpoint.mjs` | Tavily 兼容端点(#153):留空 = 官方地址、base 自动补 `/search`、query/hash 被剥离、非 http(s) 拒绝、key 只走 Authorization 头、401 点名端点、配置与设置页接线 | `node tools/assert-tavily-endpoint.mjs`(8) |
|
|
684
694
|
| `assert-hint-card.mjs` | 字段说明悬停卡:长说明不再占正文、卡片经 portal 挂到 body(否则被卡片 `overflow:clip` 裁掉)、Esc 关闭、聚焦打开/失焦关闭、悬停有延迟、触屏可点、卡片不越出视口、深浅色都覆盖、标签文字在图标按钮外(否则被压成一字一行)、点图标不连带切换复选框 | `node tools/assert-hint-card.mjs`(14) |
|
|
695
|
+
| `assert-restore-cli.mjs` | 卸载后清理入口(#159):`restore` 子命令不依赖插件运行时、只删插件自己写进去的 `searchProvider: ddg` / `fetchProvider: fs-quality-fetch`、用户显式选的 provider 不动、只剩 id+name 的空行整行删除、注释/顺序/引号/CRLF 保留、写入前备份、重复运行无副作用、`--dry-run` 不写、`--profile` 只清指定 profile、参数不明时拒绝写入 | `node tools/assert-restore-cli.mjs`(12) |
|
|
685
696
|
| `assert-control-chrome.mjs` | 字段标题与复选框外观:标题字号/字重要高于正文、复选框由样式绘制(`appearance:none` + CSS 勾)、不确定态有独立横线、聚焦有描边、深浅色都覆盖、分组自动换行、全选不拉满整行、工具行复选框不再固定 150px | `node tools/assert-control-chrome.mjs`(9) |
|
|
686
697
|
| `assert-checkbox-labels.mjs` | 复选框不再重复标签:左侧栏入口 / 斜杠命令 / 免 key 优先三项各只出现一次标签、标签位于复选框同一行、其它输入类字段仍保留独立标题 | `node tools/assert-checkbox-labels.mjs`(5) |
|
|
687
698
|
| `assert-dropdown.mjs` | 自绘下拉:设置页不再有原生 `<select>`、11 处全部走同一个组件、保留 `onChange({ target })` 契约与 listbox 语义、键盘(↑↓/Home/End/Enter/Esc/Tab)可用、浮层限高滚动、深浅色都有样式 | `node tools/assert-dropdown.mjs`(6) |
|
|
@@ -696,7 +707,7 @@ npx -y -p dsh-free-search dsh-free-search-mcp
|
|
|
696
707
|
| `assert-pool-prompt.mjs` | 入池策略与提示词一致(#152):`off` 保留「只在显式选择时运行」、`auto` 改写为「最多一个、计费一次」、`multi` 改写为「每个引擎各计费一次」、Multi 池只在 `multi` 档列出按次计费引擎、中文文案同步 | `node tools/assert-pool-prompt.mjs`(5) |
|
|
697
708
|
| `assert-fetch-ssrf-wiring.mjs` | #156 回归:`lib/index.js` 必须以 provider 自己的选项名 `allowedCidrs` 传白名单(写成 `allowFakeIpCidrs` 会被静默丢弃)、白名单能到达 `validateUrl`、错拼的键回退为空列表 | `node tools/assert-fetch-ssrf-wiring.mjs`(3) |
|
|
698
709
|
| `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
|
|
710
|
+
| `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
711
|
| `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
712
|
| `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
713
|
| `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) |
|
|
@@ -1033,6 +1044,16 @@ So **remove those `- id: web` lines before disabling or uninstalling this plugin
|
|
|
1033
1044
|
Error: configured web provider "ddg" is not registered
|
|
1034
1045
|
```
|
|
1035
1046
|
|
|
1047
|
+
**Already uninstalled and forgot?** The `restore` command fixes the profile patch without loading the plugin:
|
|
1048
|
+
|
|
1049
|
+
```
|
|
1050
|
+
npx dsh-free-search restore # every profile
|
|
1051
|
+
npx dsh-free-search restore --profile web # one profile
|
|
1052
|
+
npx dsh-free-search restore --dry-run # report only, write nothing
|
|
1053
|
+
```
|
|
1054
|
+
|
|
1055
|
+
It removes only the two values this plugin wrote (`searchProvider: ddg`, `fetchProvider: fs-quality-fetch`); a provider you chose yourself is left alone; a row left with just `id` + `name` is dropped entirely; comments, ordering, quoting and CRLF survive; and it writes a `*.bak-before-free-search-restore` backup first. Restart `dsh` afterwards so the web service rebuilds.
|
|
1056
|
+
|
|
1036
1057
|
Older DSH (0.1.x) used a static patch layer for this; writing that row by hand there is neither needed nor recommended.
|
|
1037
1058
|
|
|
1038
1059
|
#### DSH's "DeepSeek search API" switch
|
|
@@ -1415,7 +1436,7 @@ Restart `dsh web` after switching to apply changes.
|
|
|
1415
1436
|
|
|
1416
1437
|
#### Offline self-check assertions (`tools/`)
|
|
1417
1438
|
|
|
1418
|
-
**Ninety-
|
|
1439
|
+
**Ninety-nine** zero-dependency assertion scripts ship with the repo (**1261 assertions** total)
|
|
1419
1440
|
|
|
1420
1441
|
| Script | Covers | Run (count) |
|
|
1421
1442
|
|---|---|---|
|
package/bin/restore.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// #159: restore the web provider fields this plugin wrote into the profile patch.
|
|
3
|
+
//
|
|
4
|
+
// Runs without loading the plugin, so it also works after the plugin was
|
|
5
|
+
// disabled or uninstalled - the exact state the residue is stuck in.
|
|
6
|
+
//
|
|
7
|
+
// npx dsh-free-search restore
|
|
8
|
+
// npx dsh-free-search restore --profile web --dry-run
|
|
9
|
+
import { cleanProfiles, describeResults, dshHomeDir } from "../lib/restore.js";
|
|
10
|
+
|
|
11
|
+
const args = process.argv.slice(2);
|
|
12
|
+
|
|
13
|
+
// Flags are parsed first: an unknown or bare invocation must never fall through
|
|
14
|
+
// to a real write. Anything short of an explicit `restore` prints usage and exits.
|
|
15
|
+
const HELP_FLAGS = new Set(["--help", "-h", "help", "--usage"]);
|
|
16
|
+
if (args.length === 0 || args.some((arg) => HELP_FLAGS.has(arg))) {
|
|
17
|
+
printUsage();
|
|
18
|
+
process.exit(args.length === 0 ? 2 : 0);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const command = args[0];
|
|
22
|
+
if (command !== "restore") {
|
|
23
|
+
console.error(`unknown command "${command}"`);
|
|
24
|
+
printUsage();
|
|
25
|
+
process.exit(2);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const profileIndex = args.indexOf("--profile");
|
|
29
|
+
const profile = profileIndex >= 0 ? args[profileIndex + 1] : undefined;
|
|
30
|
+
if (profileIndex >= 0 && (profile === undefined || profile.startsWith("-"))) {
|
|
31
|
+
console.error("--profile needs a profile name");
|
|
32
|
+
process.exit(2);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const homeIndex = args.indexOf("--home");
|
|
36
|
+
const home = homeIndex >= 0 ? args[homeIndex + 1] : dshHomeDir();
|
|
37
|
+
if (homeIndex >= 0 && (home === undefined || home.startsWith("-"))) {
|
|
38
|
+
console.error("--home needs a directory");
|
|
39
|
+
process.exit(2);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// An unknown flag is a typo, not consent to overwrite a profile patch.
|
|
43
|
+
const KNOWN_FLAGS = new Set(["restore", "--profile", "--home", "--dry-run"]);
|
|
44
|
+
const valueFlags = new Set(["--profile", "--home"]);
|
|
45
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
46
|
+
const arg = args[i];
|
|
47
|
+
if (KNOWN_FLAGS.has(arg)) {
|
|
48
|
+
if (valueFlags.has(arg)) i += 1;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
console.error(`unknown argument "${arg}"`);
|
|
52
|
+
printUsage();
|
|
53
|
+
process.exit(2);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const dryRun = args.includes("--dry-run");
|
|
57
|
+
|
|
58
|
+
const results = cleanProfiles({ home, profile, dryRun });
|
|
59
|
+
for (const line of describeResults(results)) console.log(line);
|
|
60
|
+
if (results.some((result) => result.ok && result.changed) && !dryRun) {
|
|
61
|
+
console.log("\nbackups were written next to each patch as *.bak-before-free-search-restore");
|
|
62
|
+
console.log("restart dsh so the web service rebuilds with the restored providers");
|
|
63
|
+
}
|
|
64
|
+
if (dryRun && results.some((result) => result.ok && result.changed)) {
|
|
65
|
+
console.log("\n(dry run: nothing was written)");
|
|
66
|
+
}
|
|
67
|
+
process.exit(results.every((result) => result.ok) ? 0 : 1);
|
|
68
|
+
|
|
69
|
+
function printUsage() {
|
|
70
|
+
console.log(`Usage:
|
|
71
|
+
dsh-free-search restore [--profile <name>] [--home <dir>] [--dry-run]
|
|
72
|
+
|
|
73
|
+
Removes the "searchProvider: ddg" / "fetchProvider: fs-quality-fetch" values
|
|
74
|
+
this plugin wrote into a profile's cordis.patch.yml. Values you set yourself are
|
|
75
|
+
left untouched, and a patch line surviving only because of them is dropped.
|
|
76
|
+
|
|
77
|
+
--profile <name> clean one profile under <home>/profiles
|
|
78
|
+
--home <dir> DSH home (defaults to $DSH_HOME or ~/.dsh)
|
|
79
|
+
--dry-run report what would change without writing
|
|
80
|
+
|
|
81
|
+
Nothing is written unless the word "restore" is the first argument.`);
|
|
82
|
+
}
|
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.
|
|
925
|
+
const PLUGIN_VERSION = "0.9.81";
|
|
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 =
|
|
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
|
|
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/lib/restore.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// #159: clean up the provider ids this plugin wrote into the profile patch.
|
|
2
|
+
//
|
|
3
|
+
// The runtime takeover persists `searchProvider: ddg` / `fetchProvider:
|
|
4
|
+
// fs-quality-fetch` into `profiles/<name>/cordis.patch.yml` through
|
|
5
|
+
// `settings.mutate("web", ...)`. That row outlives the plugin: after a disable
|
|
6
|
+
// or an uninstall the ids are still there while the providers are gone, and
|
|
7
|
+
// every `web_search` / `web_fetch` fails with WEB_PROVIDER_CONFIGURED_MISSING.
|
|
8
|
+
//
|
|
9
|
+
// This module does the cleanup without loading the plugin, so it works exactly
|
|
10
|
+
// in the state where nothing else can run. It edits the file as text instead of
|
|
11
|
+
// round-tripping YAML, so comments, ordering and quoting survive.
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import os from "node:os";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
|
|
16
|
+
/** Provider ids this plugin registers; a patch value equal to one of these is residue. */
|
|
17
|
+
export const OWNED_PROVIDER_IDS = {
|
|
18
|
+
searchProvider: ["ddg"],
|
|
19
|
+
fetchProvider: ["fs-quality-fetch"],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** The web row this plugin writes into. */
|
|
23
|
+
const WEB_ROW_ID = "web";
|
|
24
|
+
|
|
25
|
+
export function dshHomeDir(env = process.env) {
|
|
26
|
+
return env.DSH_HOME ?? path.join(os.homedir(), ".dsh");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** profile directory names under `<home>/profiles`, or an empty list. */
|
|
30
|
+
export function listProfiles(home = dshHomeDir()) {
|
|
31
|
+
const dir = path.join(home, "profiles");
|
|
32
|
+
try {
|
|
33
|
+
return fs
|
|
34
|
+
.readdirSync(dir, { withFileTypes: true })
|
|
35
|
+
.filter((entry) => entry.isDirectory())
|
|
36
|
+
.map((entry) => ({ name: entry.name, dir: path.join(dir, entry.name) }))
|
|
37
|
+
.filter((entry) => fs.existsSync(path.join(entry.dir, "cordis.patch.yml")));
|
|
38
|
+
} catch {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const unquote = (raw) => {
|
|
44
|
+
const text = String(raw ?? "").trim();
|
|
45
|
+
const m = /^(['"])([\s\S]*)\1$/.exec(text);
|
|
46
|
+
return m ? m[2] : text;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const indentOf = (line) => {
|
|
50
|
+
const match = /^[ \t]*/.exec(line);
|
|
51
|
+
return match === null ? 0 : match[0].length;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Split a patch document into blocks that each start at a top-level `- ` line.
|
|
56
|
+
* Everything before the first entry is kept as a prologue.
|
|
57
|
+
*/
|
|
58
|
+
export function splitEntries(text) {
|
|
59
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
60
|
+
const lines = text.split(/\r?\n/);
|
|
61
|
+
const blocks = [];
|
|
62
|
+
let prologue = [];
|
|
63
|
+
let current = null;
|
|
64
|
+
for (const line of lines) {
|
|
65
|
+
if (/^- /.test(line)) {
|
|
66
|
+
if (current !== null) blocks.push(current);
|
|
67
|
+
current = [line];
|
|
68
|
+
} else if (current === null) {
|
|
69
|
+
prologue.push(line);
|
|
70
|
+
} else {
|
|
71
|
+
current.push(line);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (current !== null) blocks.push(current);
|
|
75
|
+
return { prologue, blocks, eol };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The entry id of a block, from its leading `- id: <id>` line. */
|
|
79
|
+
export function blockId(block) {
|
|
80
|
+
const lead = block[0] ?? "";
|
|
81
|
+
const m = /^- (?:id|name):\s*(.*)$/.exec(lead);
|
|
82
|
+
if (!m) return null;
|
|
83
|
+
return unquote(m[1]);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** True when this block targets the web row (`- id: web`, or a named web entry). */
|
|
87
|
+
export function isWebEntry(block) {
|
|
88
|
+
const lead = block[0] ?? "";
|
|
89
|
+
if (/^- id:\s*["']?web["']?\s*$/.test(lead)) return true;
|
|
90
|
+
return block.some((line) => /^\s*name:\s*["']?@deepseek-ai\/dsh-web["']?\s*$/.test(line));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Remove residue from one web block. Returns { lines, removed, changed }.
|
|
95
|
+
* Only values that match the ids this plugin owns are removed; anything the
|
|
96
|
+
* user chose explicitly is left untouched.
|
|
97
|
+
*/
|
|
98
|
+
export function cleanWebEntry(block) {
|
|
99
|
+
const removed = [];
|
|
100
|
+
let kept = [];
|
|
101
|
+
|
|
102
|
+
for (const line of block) {
|
|
103
|
+
let drop = false;
|
|
104
|
+
const key = /^\s*(searchProvider|fetchProvider):\s*(.*)$/.exec(line);
|
|
105
|
+
if (key && OWNED_PROVIDER_IDS[key[1].includes("search") ? "searchProvider" : "fetchProvider"].includes(unquote(key[2]))) {
|
|
106
|
+
removed.push({ key: key[1], value: unquote(key[2]) });
|
|
107
|
+
drop = true;
|
|
108
|
+
}
|
|
109
|
+
if (!drop) kept.push(line);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// An empty `config:` would parse as null and break the loader, so drop it too.
|
|
113
|
+
kept = kept.filter((line, index) => {
|
|
114
|
+
if (!/^\s*config:\s*$/.test(line)) return true;
|
|
115
|
+
const next = kept.slice(index + 1).find((candidate) => candidate.trim() !== "");
|
|
116
|
+
if (next === undefined) return false;
|
|
117
|
+
return indentOf(next) > indentOf(line);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
return { lines: kept, removed, changed: removed.length > 0 };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** An entry that only restates the row (id + name) carries nothing; drop it. */
|
|
124
|
+
export function isRedundantEntry(block) {
|
|
125
|
+
const meaningful = block.filter((line) => {
|
|
126
|
+
const text = line.trim();
|
|
127
|
+
if (text === "" || text.startsWith("#")) return false;
|
|
128
|
+
// Both the leading `- id: …` and the indented `name: …` only identify the row.
|
|
129
|
+
if (/^-?\s*(?:id|name):/.test(text)) return false;
|
|
130
|
+
return true;
|
|
131
|
+
});
|
|
132
|
+
return meaningful.length === 0;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Clean one patch document. Returns { text, changed, removed, dropped }.
|
|
137
|
+
*/
|
|
138
|
+
export function cleanPatchText(text) {
|
|
139
|
+
const { prologue, blocks, eol } = splitEntries(text);
|
|
140
|
+
let changed = false;
|
|
141
|
+
let removed = [];
|
|
142
|
+
let dropped = [];
|
|
143
|
+
const keptBlocks = [];
|
|
144
|
+
|
|
145
|
+
for (const block of blocks) {
|
|
146
|
+
if (isWebEntry(block)) {
|
|
147
|
+
const result = cleanWebEntry(block);
|
|
148
|
+
if (result.changed) {
|
|
149
|
+
changed = true;
|
|
150
|
+
removed = removed.concat(result.removed);
|
|
151
|
+
if (isRedundantEntry(result.lines)) {
|
|
152
|
+
dropped.push(blockId(block) ?? "web");
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
keptBlocks.push(result.lines);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
keptBlocks.push(block);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const lines = [...prologue, ...keptBlocks.flat()];
|
|
163
|
+
const body = lines.join(eol);
|
|
164
|
+
// Preserve the original trailing newline shape.
|
|
165
|
+
const tail = text.endsWith("\n") ? eol : "";
|
|
166
|
+
const trimmed = body.replace(/\r?\n+$/, "");
|
|
167
|
+
return { text: trimmed + tail, changed, removed, dropped, eol };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Clean every profile patch under the home. Returns one result per profile.
|
|
172
|
+
*/
|
|
173
|
+
export function cleanProfiles({ home = dshHomeDir(), profile, dryRun = false } = {}) {
|
|
174
|
+
const profiles = listProfiles(home).filter((entry) => profile === undefined || entry.name === profile);
|
|
175
|
+
const results = [];
|
|
176
|
+
for (const entry of profiles) {
|
|
177
|
+
const file = path.join(entry.dir, "cordis.patch.yml");
|
|
178
|
+
let text;
|
|
179
|
+
try {
|
|
180
|
+
text = fs.readFileSync(file, "utf8");
|
|
181
|
+
} catch (error) {
|
|
182
|
+
results.push({ profile: entry.name, file, ok: false, error: String(error?.message ?? error) });
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const cleaned = cleanPatchText(text);
|
|
186
|
+
if (!cleaned.changed) {
|
|
187
|
+
results.push({ profile: entry.name, file, ok: true, changed: false, removed: [], dropped: [] });
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (!dryRun) {
|
|
191
|
+
try {
|
|
192
|
+
fs.writeFileSync(`${file}.bak-before-free-search-restore`, text);
|
|
193
|
+
fs.writeFileSync(file, cleaned.text);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
results.push({ profile: entry.name, file, ok: false, error: String(error?.message ?? error) });
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
results.push({
|
|
200
|
+
profile: entry.name,
|
|
201
|
+
file,
|
|
202
|
+
ok: true,
|
|
203
|
+
changed: true,
|
|
204
|
+
removed: cleaned.removed,
|
|
205
|
+
dropped: cleaned.dropped,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return results;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Human-readable summary lines for the CLI. */
|
|
212
|
+
export function describeResults(results) {
|
|
213
|
+
const lines = [];
|
|
214
|
+
if (results.length === 0) {
|
|
215
|
+
lines.push("no profile with a cordis.patch.yml was found");
|
|
216
|
+
return lines;
|
|
217
|
+
}
|
|
218
|
+
for (const result of results) {
|
|
219
|
+
if (!result.ok) {
|
|
220
|
+
lines.push(`${result.profile}: FAILED (${result.error})`);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (!result.changed) {
|
|
224
|
+
lines.push(`${result.profile}: nothing to clean`);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const parts = result.removed.map((entry) => `${entry.key}: ${entry.value}`);
|
|
228
|
+
lines.push(`${result.profile}: removed ${parts.join(", ")}`);
|
|
229
|
+
if (result.dropped.length > 0) {
|
|
230
|
+
lines.push(`${result.profile}: dropped the now-empty row ${result.dropped.map((id) => `"${id}"`).join(", ")}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return lines;
|
|
234
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-free-search",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.81",
|
|
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",
|
|
@@ -139,6 +139,7 @@
|
|
|
139
139
|
}
|
|
140
140
|
},
|
|
141
141
|
"bin": {
|
|
142
|
-
"dsh-free-search-mcp": "./bin/mcp.js"
|
|
142
|
+
"dsh-free-search-mcp": "./bin/mcp.js",
|
|
143
|
+
"dsh-free-search": "./bin/restore.js"
|
|
143
144
|
}
|
|
144
145
|
}
|