argo-search 2.9.9 → 2.10.0

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.
Files changed (90) hide show
  1. package/README.en.md +24 -21
  2. package/README.es.md +24 -21
  3. package/README.ja.md +23 -20
  4. package/README.ko.md +23 -20
  5. package/README.md +26 -21
  6. package/SKILL.md +5 -5
  7. package/backends/domain_profiles.json +76 -0
  8. package/backends/engine_registry.yaml +161 -5
  9. package/backends/quota_profiles.json +122 -2
  10. package/bin/argo +22 -1
  11. package/bin/argo.js +3 -3
  12. package/config.yaml +128 -21
  13. package/docs/ARGO_INTRO.md +4 -4
  14. package/docs/ENGINE_CATALOG.md +64 -44
  15. package/docs/MCP_SETUP.md +1 -1
  16. package/docs/RELEASE_NOTES_v2.10.0.md +85 -0
  17. package/docs/RELEASE_NOTES_v2.9.8.md +1 -1
  18. package/docs//344/270/272/344/273/200/344/271/210/351/200/211/346/213/251argo.md +9 -9
  19. package/engines/specs/clawhub.yaml +16 -15
  20. package/engines/specs/deepseek1024.yaml +46 -0
  21. package/engines/specs/dsh_hub.yaml +44 -0
  22. package/engines/specs/dshopen.yaml +32 -0
  23. package/engines/specs/explainx.yaml +32 -0
  24. package/engines/specs/gbfs_nyc.yaml +6 -1
  25. package/engines/specs/metaso_doc.yaml +49 -0
  26. package/engines/specs/metaso_image.yaml +65 -0
  27. package/engines/specs/metaso_podcast.yaml +60 -0
  28. package/engines/specs/metaso_scholar.yaml +57 -0
  29. package/engines/specs/metaso_video.yaml +62 -0
  30. package/engines/specs/ncpssd.yaml +41 -0
  31. package/engines/specs/sciverse.yaml +72 -0
  32. package/engines/specs/skills_sh.yaml +32 -0
  33. package/engines/specs/skillsmp.yaml +18 -16
  34. package/package.json +3 -2
  35. package/packages/dsh-plugin/README.md +3 -2
  36. package/packages/dsh-plugin/package.json +1 -1
  37. package/packages/dsh-plugin/test/size-gate.test.js +113 -0
  38. package/scripts/adaptive.py +41 -14
  39. package/scripts/article.py +6 -1
  40. package/scripts/article_meta.py +151 -2
  41. package/scripts/bench_general_pool.py +145 -0
  42. package/scripts/candidate_envelope.py +45 -4
  43. package/scripts/charset_decode.py +127 -0
  44. package/scripts/crawl.py +240 -74
  45. package/scripts/crawl_frontier.py +217 -0
  46. package/scripts/crawl_policy.py +174 -0
  47. package/scripts/engine_dispatch.py +22 -15
  48. package/scripts/engine_failure.py +15 -0
  49. package/scripts/engine_validate.py +8 -0
  50. package/scripts/engines.py +10 -0
  51. package/scripts/engines_base.py +12 -0
  52. package/scripts/engines_builders.py +14 -0
  53. package/scripts/engines_builders_dsh.py +330 -0
  54. package/scripts/engines_builders_skill.py +314 -0
  55. package/scripts/fetch_v3.py +37 -5
  56. package/scripts/gen_engine_catalog.py +218 -2
  57. package/scripts/general_pool.py +162 -0
  58. package/scripts/http_client.py +38 -42
  59. package/scripts/image_ops.py +4 -0
  60. package/scripts/install.ps1 +47 -19
  61. package/scripts/install.sh +45 -20
  62. package/scripts/matrix_search_eval.py +17 -1
  63. package/scripts/mcp_transport.py +1 -1
  64. package/scripts/ncpssd_bridge.py +123 -0
  65. package/scripts/paid_policy.py +109 -13
  66. package/scripts/pre-commit +19 -4
  67. package/scripts/query_signals.py +156 -3
  68. package/scripts/redskill/redskill_engine.py +29 -2
  69. package/scripts/release_check.py +209 -0
  70. package/scripts/retry_policy.py +22 -1
  71. package/scripts/robots_guard.py +26 -0
  72. package/scripts/route.py +11 -8
  73. package/scripts/route_cache.py +6 -0
  74. package/scripts/route_combo.py +37 -59
  75. package/scripts/route_domains.py +4 -1
  76. package/scripts/route_policy.py +6 -0
  77. package/scripts/search.py +9 -1
  78. package/scripts/search_cli.py +27 -0
  79. package/scripts/search_entry.py +9 -0
  80. package/scripts/search_output.py +29 -0
  81. package/scripts/search_pipeline.py +39 -1
  82. package/scripts/search_rank.py +1 -0
  83. package/scripts/social_engines/bilibili_engine.py +163 -26
  84. package/scripts/social_engines/reddit_engine.py +52 -51
  85. package/scripts/source_selection.py +302 -0
  86. package/scripts/video_fetch.py +303 -0
  87. package/scripts/video_meta.py +225 -0
  88. package/scripts/video_route.py +65 -0
  89. package/scripts/watch.py +123 -0
  90. package/scripts/local_engines.py +0 -321
@@ -0,0 +1,330 @@
1
+ #!/usr/bin/env python3
2
+ """DSH 插件目录构建器 —— DeepSeek Harness 插件生态检索。
3
+
4
+ 三个 DSH 插件数据源的形态各不相同,接入方式也分三档:
5
+
6
+ · deepseek1024(13855 条)/ dsh_hub(18933 条)—— 标准搜索 API,
7
+ 走 L1 声明式(`engines/specs/deepseek1024.yaml`、`engines/specs/dsh_hub.yaml`),
8
+ 本文件不含它们的实现。
9
+ · dshopen(894 条精选)—— **无搜索 API**:`/index.json` 是静态全量目录,
10
+ 任何 query 参数都返回同一份 1.3MB 文件(实测 `/index.json?query=x` 与不带参数
11
+ 逐字节相同)。这类「全量目录 + 本地匹配」没有声明式表达方式,故落到 L3。
12
+
13
+ 为什么 dshopen 值得单独一个 builder:它是四个候选源里**精选质量最高**的一个
14
+ (894 条零空标题/零空描述、53 条 verified 标签、labels 体系规范、601 条带
15
+ `engines.dsh` 版本约束),且与 deepseek1024 只重叠 562 条——两个源是互补而非
16
+ 替代。它缺的是 API,不是数据。
17
+
18
+ 缓存策略(为什么不用 ETag):上游支持 ETag,但 `http_open` 会把 304 归因为
19
+ 「HTTP 失败」(非 2xx 一律走 `_note_http_failure`),一次正常的缓存命中会在
20
+ 失败寄存器里留一条假记录。改用 TTL 缓存绕开:1.3MB 全量、每天重建,12h TTL
21
+ 意味着最多半天延迟,比污染归因划算。
22
+ """
23
+
24
+ from __future__ import annotations
25
+
26
+ import json
27
+ import math
28
+ import re
29
+ import time
30
+ import urllib.request
31
+ from pathlib import Path
32
+ from typing import Any
33
+
34
+ from engines_base import safe_search, http_open, rank_score
35
+
36
+ # 上游:静态全量目录。Cloudflare 前置,支持 ETag(本 builder 刻意不用,见文件头)。
37
+ _DSHOPEN_INDEX_URL = "https://dshopen.org/index.json"
38
+
39
+ # 12h。dshopen 每天全量重建(sitemap 的 lastmod 全为当天),半天延迟可接受;
40
+ # 再短就会让「同一天多次搜索」反复拉 1.3MB。
41
+ _CACHE_TTL = 12 * 3600
42
+
43
+ _CACHE_FILE = "dshopen_index.json"
44
+ _META_FILE = "dshopen_index.meta.json"
45
+
46
+ # 字段权重:名字最重(用户找的往往是包名),中文描述次之,分类与英文再次。
47
+ # 与 find_dsh_plugin.py 的 FIELD_WEIGHT 同一口径,便于两处结果互相对照。
48
+ _FIELD_WEIGHTS: dict[str, float] = {
49
+ "name": 3.0,
50
+ "title_zh": 2.0,
51
+ "title_en": 1.5,
52
+ "desc_zh": 1.5,
53
+ "desc_en": 1.0,
54
+ "keywords": 1.2,
55
+ "category": 0.8,
56
+ }
57
+
58
+ # 引擎档位分(rank_score 的 base):dshopen 是精选源、覆盖最小,档位低于
59
+ # 通用源但高于长尾垂直源——它「条条可信」的优势要能压过「只有 894 条」的劣势。
60
+ _BASE_SCORE = 0.75
61
+
62
+ # 上游把星数写进了描述开头(881/894 条形如「★ 15 │ 分层蒸馏记忆:…」),
63
+ # 方便它自己的卡片渲染。搜素结果里星数已有独立字段,这个前缀只剩噪音,剥掉。
64
+ # 星号可能是 ★ 或 *,数字含千分位与小数(如 ★ 89,165 │)。
65
+ _STAR_PREFIX_RE = re.compile(r"^[★*]\s*\d[\d,\.]*\s*│\s*")
66
+
67
+ # dshopen 的 11 个分类 → 中文展示名(取自上游 metadata.categories 的 zh 标题)。
68
+ # 用于摘要前缀,让用户一眼看出「这是哪类插件」。
69
+ _CATEGORY_ZH: dict[str, str] = {
70
+ "interface": "界面",
71
+ "tools": "工具",
72
+ "skills": "技能",
73
+ "memory": "记忆",
74
+ "providers": "模型供应商",
75
+ "usage": "用量与费用",
76
+ "integrations": "集成",
77
+ "appearance": "外观",
78
+ "workflow": "工作流与协作",
79
+ "development": "开发与运维",
80
+ "knowledge": "知识",
81
+ }
82
+
83
+
84
+ def _cache_dir() -> Path:
85
+ """缓存目录。优先走 argo_paths(与 cache.db 同根),失败回落 ~/.cache。"""
86
+ try:
87
+ from argo_paths import ensure_state_dir
88
+
89
+ return ensure_state_dir("engines")
90
+ except Exception:
91
+ return Path.home() / ".cache" / "unified-search" / "engines"
92
+
93
+
94
+ def _load_plugins(timeout: float) -> list[dict[str, Any]]:
95
+ """读 dshopen 全量目录:缓存新鲜直接用,否则拉取并落盘。
96
+
97
+ 任何一步失败都返回已缓存的那份(哪怕过期)——目录搜索是「有旧数据胜过
98
+ 没数据」的场景,上游抖动不该让整个引擎空转。
99
+ """
100
+ cdir = _cache_dir()
101
+ cache_file = cdir / _CACHE_FILE
102
+ meta_file = cdir / _META_FILE
103
+
104
+ stale: list[dict[str, Any]] | None = None
105
+ try:
106
+ meta = json.loads(meta_file.read_text(encoding="utf-8"))
107
+ data = json.loads(cache_file.read_text(encoding="utf-8"))
108
+ plugins = data.get("plugins")
109
+ if isinstance(plugins, list):
110
+ stale = plugins
111
+ if time.time() - float(meta.get("ts") or 0) < _CACHE_TTL:
112
+ return plugins
113
+ except Exception:
114
+ stale = None
115
+
116
+ try:
117
+ req = urllib.request.Request(
118
+ _DSHOPEN_INDEX_URL,
119
+ headers={"User-Agent": "argo-search/1.0", "Accept": "application/json"},
120
+ )
121
+ with http_open(req, timeout=timeout, engine="dshopen") as resp:
122
+ payload = json.loads(resp.read())
123
+ plugins = payload.get("plugins") if isinstance(payload, dict) else None
124
+ if not isinstance(plugins, list):
125
+ return stale or []
126
+ try:
127
+ cdir.mkdir(parents=True, exist_ok=True)
128
+ cache_file.write_text(
129
+ json.dumps(payload, ensure_ascii=False), encoding="utf-8"
130
+ )
131
+ meta_file.write_text(
132
+ json.dumps({"ts": time.time()}), encoding="utf-8"
133
+ )
134
+ except OSError:
135
+ pass # 只读挂载 / 权限受限:内存里这份仍然可用
136
+ return plugins
137
+ except Exception:
138
+ return stale or []
139
+
140
+
141
+ def _entry_fields(entry: dict[str, Any]) -> dict[str, str]:
142
+ """摊平成待匹配文本。title/description 是 {en, zh} 双语对象,缺失侧留空。"""
143
+ meta = entry.get("metadata") or {}
144
+ title = entry.get("title") or {}
145
+ desc = entry.get("description") or {}
146
+ return {
147
+ "name": entry.get("name") or "",
148
+ "title_zh": title.get("zh") or "",
149
+ "title_en": title.get("en") or "",
150
+ "desc_zh": desc.get("zh") or "",
151
+ "desc_en": desc.get("en") or "",
152
+ "keywords": " ".join(meta.get("keywords") or []),
153
+ "category": meta.get("category") or "",
154
+ }
155
+
156
+
157
+ def _tokens(query: str) -> list[str]:
158
+ """查询切分:英文按词(≥2 字符)、中文按 2 字以上片段,去重保序。
159
+
160
+ 英文单词不切单字符——`a`/`x` 这类在包名里无处不在,切了只会把不相关的
161
+ 条目全捞进来。中文同理:单字噪音大,2 字片段是「记忆」「插件」这类词的
162
+ 自然粒度。整段中文(如「后台任务」)作为一个 token 保留,比切成二字
163
+ 滑窗更准。
164
+ """
165
+ q = (query or "").lower().strip()
166
+ if not q:
167
+ return []
168
+ toks: list[str] = []
169
+ for w in re.findall(r"[a-z0-9]+", q):
170
+ if len(w) >= 2:
171
+ toks.append(w)
172
+ for seg in re.findall(r"[一-鿿]{2,}", q):
173
+ toks.append(seg)
174
+ if not toks:
175
+ toks = re.findall(r"[一-鿿]", q)
176
+ seen: set[str] = set()
177
+ out: list[str] = []
178
+ for t in toks:
179
+ if t and t not in seen:
180
+ seen.add(t)
181
+ out.append(t)
182
+ return out
183
+
184
+
185
+ def _build_idf(plugins: list[dict[str, Any]], tokens: list[str]) -> dict[str, float]:
186
+ """IDF:罕见 token 权重大,满语料 token 权重小。
187
+
188
+ 为什么必须有:dshopen 的 894 条里几乎每条都含「dsh」(包名前缀),
189
+ 纯布尔命中下「dsh」对**所有**条目同加 3.0 分——区分度为零,top-10
190
+ 会退化成「按星数排」。实测查询「dsh 插件 记忆」有 887/894 条命中,
191
+ 真正相关的「记忆」类条目排不上来。IDF 把这类满语料词压到接近 0。
192
+ """
193
+ n = len(plugins) or 1
194
+ idf: dict[str, float] = {}
195
+ for tok in tokens:
196
+ hits = 0
197
+ for entry in plugins:
198
+ fields = _entry_fields(entry)
199
+ if any(tok in (v or "").lower() for v in fields.values()):
200
+ hits += 1
201
+ if hits >= n: # 满语料:不必再数
202
+ break
203
+ # +1 平滑:避免 log(0);满语料词得 ≈1.0(不是 0,仍保留微弱信号)
204
+ idf[tok] = math.log((n + 1) / (hits + 1)) + 1.0
205
+ return idf
206
+
207
+
208
+ def _score(
209
+ fields: dict[str, str], tokens: list[str], idf: dict[str, float]
210
+ ) -> float:
211
+ """命中字段权重 × token IDF 求和。未命中任何字段的条目直接淘汰。"""
212
+ lowered = {k: v.lower() for k, v in fields.items()}
213
+ total = 0.0
214
+ for tok in tokens:
215
+ w_tok = idf.get(tok, 1.0)
216
+ for field, weight in _FIELD_WEIGHTS.items():
217
+ if tok in lowered.get(field, ""):
218
+ total += weight * w_tok
219
+ return total
220
+
221
+
222
+ def _star_boost(entry: dict[str, Any]) -> float:
223
+ """星数加权:log 尺度,避免大仓碾压。
224
+
225
+ 注意 dshopen 的星数有**父仓污染**:19 个多包仓库(58 个条目,占 6.5%)取的是
226
+ 父仓星数(如 @linxin666/* 显示 9511 星,repo 实为 zhu1090093659/dsh-web)。
227
+ 这个偏差无法在索引侧修正,只能在解读时留意——加权幅度因此压得很低
228
+ (log1p/10,0 星与 1 万星只差约 0.92 倍)。
229
+ """
230
+ meta = entry.get("metadata") or {}
231
+ stars = (meta.get("sortKeys") or {}).get("github-stars") or 0
232
+ try:
233
+ stars = float(stars)
234
+ except (TypeError, ValueError):
235
+ return 1.0
236
+ if stars <= 0:
237
+ return 1.0
238
+ return 1.0 + math.log1p(stars) / 10.0
239
+
240
+
241
+ def _iso(epoch: Any) -> str:
242
+ try:
243
+ return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(int(epoch)))
244
+ except (TypeError, ValueError, OSError):
245
+ return ""
246
+
247
+
248
+ def _build_dshopen_engine(spec: dict[str, Any]) -> Any:
249
+ """dshopen 插件目录(静态全量索引 + 本地匹配)。"""
250
+ timeout = float(spec.get("timeout", 15))
251
+
252
+ @safe_search
253
+ def _engine(
254
+ query: str, n: int = 5, _timeout: float | None = None, **kwargs: Any
255
+ ) -> list[dict[str, Any]]:
256
+ to = _timeout or timeout
257
+ tokens = _tokens(query)
258
+ if not tokens:
259
+ return []
260
+ plugins = _load_plugins(to)
261
+
262
+ idf = _build_idf(plugins, tokens)
263
+ scored: list[tuple[float, dict[str, Any]]] = []
264
+ for entry in plugins:
265
+ if not isinstance(entry, dict):
266
+ continue
267
+ s = _score(_entry_fields(entry), tokens, idf)
268
+ if s <= 0:
269
+ continue
270
+ scored.append((s * _star_boost(entry), entry))
271
+
272
+ # 稳定排序:同分按包名字典序,避免同批查询的结果顺序抖动
273
+ scored.sort(key=lambda x: (-x[0], (x[1].get("name") or "")))
274
+
275
+ results: list[dict[str, Any]] = []
276
+ for rank, (_, entry) in enumerate(scored[: max(1, n)]):
277
+ repo = (entry.get("repository") or {}).get("url") or ""
278
+ url = repo or entry.get("homepage") or ""
279
+ if not url:
280
+ continue
281
+ meta = entry.get("metadata") or {}
282
+ desc = (entry.get("description") or {}).get("zh") or ""
283
+ desc = _STAR_PREFIX_RE.sub("", desc).strip()
284
+ # 摘要前缀带分类。两个理由:一是给用户看「这是哪类插件」;二是
285
+ # 五维精排的「相关性」维度比对摘要与查询——上游摘要只写功能
286
+ # (「为 DSH 接入记忆服务」),不含「插件」二字,中文查询
287
+ # 「dsh 插件 记忆」的 CJK 二元组匹配不上,实测同批条目会输给
288
+ # 通用源的文章标题(那边标题恰好含「DSH 记忆插件」全词)。
289
+ # 前缀是真实分类信息,不是凑词。
290
+ cat = _CATEGORY_ZH.get(meta.get("category") or "", "")
291
+ if cat:
292
+ desc = f"DSH 插件({cat}):{desc}" if desc else f"DSH 插件({cat})"
293
+ versions = entry.get("versions") or []
294
+ published = versions[0].get("publishTimestamp") if versions else None
295
+ # 标题取中文展示名(title.zh),不是 npm 包名。原因:五维精排的
296
+ # 「相关性」维度比对标题与查询,中文查询(「dsh 记忆插件」)对上
297
+ # 中文标题(「OpenViking 记忆」)得分高,对上英文包名
298
+ # (@openviking/dsh-memory-plugin)几乎不得分——实测同一批条目
299
+ # 因标题形态不同,最终 top-6 全被通用源占据。包名仍保留在
300
+ # upstream(install 的权威答案)与 metadata 里,不丢。
301
+ title_obj = entry.get("title") or {}
302
+ title = (
303
+ title_obj.get("zh")
304
+ or title_obj.get("en")
305
+ or entry.get("name")
306
+ or ""
307
+ )
308
+ results.append(
309
+ {
310
+ "title": title,
311
+ "url": url,
312
+ "snippet": desc[:300],
313
+ "source": "dshopen",
314
+ "score": rank_score(_BASE_SCORE, rank),
315
+ "published_at": _iso(published),
316
+ # 可验证出处:npm 包名是「装什么」的权威答案
317
+ "upstream": entry.get("name") or "",
318
+ "metadata": {
319
+ "category": meta.get("category") or "",
320
+ "labels": meta.get("labels") or [],
321
+ "stars": (meta.get("sortKeys") or {}).get("github-stars") or 0,
322
+ "engines_dsh": (
323
+ (versions[0].get("engines") or {}).get("dsh") if versions else ""
324
+ ) or "",
325
+ },
326
+ }
327
+ )
328
+ return results
329
+
330
+ return _engine
@@ -0,0 +1,314 @@
1
+ #!/usr/bin/env python3
2
+ """技能目录构建器 —— explainx 与 skills.sh 两个新源的接入实现。
3
+
4
+ 为什么这两个走 L3 而不是 L1 声明式:它们的核心价值是**安装量**,而 L1 的
5
+ `output_map` 只能把单个上游字段映射成 `item_summary`(不支持模板拼接)。
6
+ 把「安装 216877 次 · anthropics/skills」这样一行说清楚,只能自己拼——
7
+ 否则用户搜「pdf」看到的是干巴巴的仓库名,判断不出哪个值得装。
8
+
9
+ 两个源的口径不可比(跨源别混用):
10
+ · explainx totalInstalls/weeklyInstalls —— 平台统计的安装数
11
+ · skills.sh installs —— Vercel 官方安装遥测(头部技能 21 万+)
12
+ Argo 已有的 skillsmp(仓库星数)、clawhub(生态下载量)是另外两套口径。
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import urllib.parse
19
+ import urllib.request
20
+ from typing import Any
21
+
22
+ from engines_base import safe_search, http_open, rank_score
23
+
24
+ # ── explainx.ai(12075 条,安装量 + 分类 + 官方标记)────────────────────────
25
+ _EXPLAINX_URL = "https://explainx.ai/api/skills"
26
+
27
+ # ── skills.sh(Vercel,57k+,官方安装遥测)──────────────────────────────────
28
+ _SKILLS_SH_URL = "https://www.skills.sh/api/search"
29
+ _SKILLS_SH_PAGE = "https://skills.sh/"
30
+
31
+ # ── SkillsMP(200 万+,仓库星数口径)────────────────────────────────────────
32
+ _SKILLSMP_URL = "https://skillsmp.com/api/v1/skills/search"
33
+
34
+ # ── ClawHub(OpenClaw 生态,下载量口径)─────────────────────────────────────
35
+ _CLAWHUB_URL = "https://clawhub.ai/api/search"
36
+ _CLAWHUB_PAGE = "https://clawhub.ai"
37
+
38
+
39
+ def _normalize_epoch(val: Any) -> str:
40
+ """epoch → ISO8601 日期。上游两种量级:SkillsMP/ClawHub 的 updatedAt 是
41
+ **毫秒**(13 位),skills.sh 系是秒——按位数归一,避免 1000 倍错位。"""
42
+ try:
43
+ n = int(val)
44
+ except (TypeError, ValueError):
45
+ return ""
46
+ if n <= 0:
47
+ return ""
48
+ # 13 位(毫秒)vs 10 位(秒):毫秒转秒
49
+ if n > 10_000_000_000:
50
+ n //= 1000
51
+ try:
52
+ import time as _t
53
+
54
+ return _t.strftime("%Y-%m-%d", _t.gmtime(n))
55
+ except (OverflowError, OSError, ValueError):
56
+ return ""
57
+
58
+
59
+ def _get_json(url: str, timeout: float, engine: str) -> Any:
60
+ req = urllib.request.Request(
61
+ url, headers={"User-Agent": "argo-search/1.0", "Accept": "application/json"}
62
+ )
63
+ with http_open(req, timeout=timeout, engine=engine) as resp:
64
+ return json.loads(resp.read())
65
+
66
+
67
+ def _build_explainx_engine(spec: dict[str, Any]) -> Any:
68
+ """explainx.ai —— 带安装量/分类/官方标记的技能目录。
69
+
70
+ 字段口径(跨源不可比):totalInstalls/weeklyInstalls 是平台安装统计;
71
+ isOfficial 标记官方出品;category 是平台分类(Productivity/Frontend/…)。
72
+ 条目只给 repoOwner/repoName(GitHub 仓),无技能在仓内的子路径,故 URL
73
+ 只能到仓级别——这是上游数据的边界,不是取舍。
74
+ """
75
+ timeout = float(spec.get("timeout", 15))
76
+
77
+ @safe_search
78
+ def _engine(
79
+ query: str, n: int = 5, _timeout: float | None = None, **kwargs: Any
80
+ ) -> list[dict[str, Any]]:
81
+ to = _timeout or timeout
82
+ q = (query or "").strip()
83
+ if not q:
84
+ return []
85
+ url = f"{_EXPLAINX_URL}?q={urllib.parse.quote(q)}&limit={max(1, n)}"
86
+ data = _get_json(url, to, "explainx")
87
+ skills = data.get("skills") if isinstance(data, dict) else None
88
+ if not isinstance(skills, list):
89
+ return []
90
+
91
+ results: list[dict[str, Any]] = []
92
+ for rank, s in enumerate(skills[: max(1, n)]):
93
+ if not isinstance(s, dict):
94
+ continue
95
+ owner = s.get("repoOwner") or ""
96
+ repo = s.get("repoName") or ""
97
+ if not owner or not repo:
98
+ continue
99
+ installs = s.get("totalInstalls") or 0
100
+ weekly = s.get("weeklyInstalls")
101
+ category = s.get("category") or ""
102
+ # 安装量是这一源的核心价值,必须出现在摘要里(L1 做不到)
103
+ bits = [f"安装 {installs}"]
104
+ if weekly is not None and weekly != installs:
105
+ bits.append(f"本周 +{weekly}")
106
+ if s.get("isOfficial"):
107
+ bits.append("官方")
108
+ summary = " · ".join(bits)
109
+ if category:
110
+ summary = f"{category}|{summary}"
111
+ results.append(
112
+ {
113
+ "title": s.get("name") or "",
114
+ "url": f"https://github.com/{owner}/{repo}",
115
+ "snippet": summary,
116
+ "source": "explainx",
117
+ "score": rank_score(0.75, rank),
118
+ # 可验证出处:owner/repo 是「装什么」的权威答案
119
+ "upstream": f"{owner}/{repo}",
120
+ "metadata": {
121
+ "category": category,
122
+ "totalInstalls": installs,
123
+ "weeklyInstalls": weekly,
124
+ "isOfficial": bool(s.get("isOfficial")),
125
+ },
126
+ }
127
+ )
128
+ return results
129
+
130
+ return _engine
131
+
132
+
133
+ def _build_skillsmp_engine(spec: dict[str, Any]) -> Any:
134
+ """SkillsMP —— 200 万+ 开源技能独立索引(原 L1 声明式,改 L3 补字段)。
135
+
136
+ 为什么改 L3:上游有 `stars`(源仓库星数)与 `githubUrl`(**能安装**的
137
+ GitHub 目录),而 L1 的 output_map 只能把单字段映射成 summary,透不出
138
+ 这两个维度。星数是「这个技能多受欢迎」的唯一硬指标,githubUrl 比市场页
139
+ 更接近「装什么」——两者都值得进结果。
140
+
141
+ 口径:stars 是**源仓库星数**(不是安装量),与 skills.sh 的 Vercel 遥测、
142
+ explainx 的平台统计互不可比。
143
+ """
144
+ timeout = float(spec.get("timeout", 15))
145
+
146
+ @safe_search
147
+ def _engine(
148
+ query: str, n: int = 5, _timeout: float | None = None, **kwargs: Any
149
+ ) -> list[dict[str, Any]]:
150
+ to = _timeout or timeout
151
+ q = (query or "").strip()
152
+ if not q:
153
+ return []
154
+ url = (
155
+ f"{_SKILLSMP_URL}?q={urllib.parse.quote(q)}"
156
+ f"&limit={max(1, n)}&sortBy=stars"
157
+ )
158
+ data = _get_json(url, to, "skillsmp")
159
+ skills = (data.get("data") or {}).get("skills") if isinstance(data, dict) else None
160
+ if not isinstance(skills, list):
161
+ return []
162
+
163
+ results: list[dict[str, Any]] = []
164
+ for rank, s in enumerate(skills[: max(1, n)]):
165
+ if not isinstance(s, dict):
166
+ continue
167
+ # 优先给「能装」的 GitHub 目录;上游缺失时回落市场页
168
+ github = s.get("githubUrl") or ""
169
+ market = s.get("skillUrl") or ""
170
+ url_final = github or market
171
+ if not url_final:
172
+ continue
173
+ stars = s.get("stars") or 0
174
+ summary = str(s.get("description") or "")
175
+ if stars:
176
+ summary = f"★ {stars}|{summary}" if summary else f"★ {stars}"
177
+ results.append(
178
+ {
179
+ "title": s.get("name") or "",
180
+ "url": url_final,
181
+ "snippet": summary[:400],
182
+ "source": "skillsmp",
183
+ "score": rank_score(0.75, rank),
184
+ "published_at": _normalize_epoch(s.get("updatedAt")),
185
+ "upstream": github or market,
186
+ "metadata": {
187
+ "stars": stars,
188
+ "author": s.get("author") or "",
189
+ "contentLanguage": s.get("contentLanguage") or "",
190
+ },
191
+ }
192
+ )
193
+ return results
194
+
195
+ return _engine
196
+
197
+
198
+ def _build_clawhub_engine(spec: dict[str, Any]) -> Any:
199
+ """ClawHub —— OpenClaw 技能生态聚合(原 L1 声明式,改 L3 补字段)。
200
+
201
+ 为什么改 L3:上游有 `downloads`(生态下载量)与 `official`(官方标记),
202
+ L1 透不出。下载量是这一源独有的口径(skills.sh 是 Vercel 遥测、
203
+ SkillsMP 是仓库星数),值得单列。
204
+
205
+ 口径:downloads 是 ClawHub 生态下载量,与其它源的安装量互不可比。
206
+ """
207
+ timeout = float(spec.get("timeout", 15))
208
+
209
+ @safe_search
210
+ def _engine(
211
+ query: str, n: int = 5, _timeout: float | None = None, **kwargs: Any
212
+ ) -> list[dict[str, Any]]:
213
+ to = _timeout or timeout
214
+ q = (query or "").strip()
215
+ if not q:
216
+ return []
217
+ url = f"{_CLAWHUB_URL}?q={urllib.parse.quote(q)}&limit={max(1, n)}"
218
+ data = _get_json(url, to, "clawhub")
219
+ items = data.get("results") if isinstance(data, dict) else None
220
+ if not isinstance(items, list):
221
+ return []
222
+
223
+ results: list[dict[str, Any]] = []
224
+ for rank, s in enumerate(items[: max(1, n)]):
225
+ if not isinstance(s, dict):
226
+ continue
227
+ canonical = s.get("canonicalUrl") or ""
228
+ if not canonical:
229
+ continue
230
+ downloads = s.get("downloads") or 0
231
+ official = bool(s.get("official"))
232
+ summary = str(s.get("summary") or "")
233
+ bits = [f"下载 {downloads}"]
234
+ if official:
235
+ bits.append("官方")
236
+ summary = f"{' · '.join(bits)}|{summary}" if summary else " · ".join(bits)
237
+ results.append(
238
+ {
239
+ "title": s.get("displayName") or "",
240
+ "url": f"https://clawhub.ai{canonical}",
241
+ "snippet": summary[:400],
242
+ "source": "clawhub",
243
+ "score": rank_score(0.75, rank),
244
+ "published_at": _normalize_epoch(s.get("updatedAt")),
245
+ # install.reference 是 owner/slug 形式的安装引用
246
+ "upstream": ((s.get("install") or {}).get("reference")) or "",
247
+ "metadata": {
248
+ "downloads": downloads,
249
+ "official": official,
250
+ "owner": s.get("owner") or "",
251
+ "slug": s.get("slug") or "",
252
+ "version": s.get("version") or "",
253
+ },
254
+ }
255
+ )
256
+ return results
257
+
258
+ return _engine
259
+
260
+
261
+ def _build_skills_sh_engine(spec: dict[str, Any]) -> Any:
262
+ """skills.sh(Vercel)—— 官方安装遥测口径的技能目录。
263
+
264
+ 为什么 clawhub 不够:clawhub 声称聚合了 skills.sh 条目,但**聚合时丢了
265
+ installs 字段**(实测 clawhub 返回里只有 title/url/snippet/score)。
266
+ 安装量是判断「这个技能有多少人在用」的唯一硬指标,故单列一源。
267
+
268
+ 字段口径:installs 是 Vercel 官方遥测(头部 pdf 技能 21 万+),与
269
+ explainx 的平台统计、skillsmp 的仓库星数互不可比。
270
+ """
271
+ timeout = float(spec.get("timeout", 15))
272
+
273
+ @safe_search
274
+ def _engine(
275
+ query: str, n: int = 5, _timeout: float | None = None, **kwargs: Any
276
+ ) -> list[dict[str, Any]]:
277
+ to = _timeout or timeout
278
+ q = (query or "").strip()
279
+ if not q:
280
+ return []
281
+ url = f"{_SKILLS_SH_URL}?q={urllib.parse.quote(q)}&limit={max(1, n)}"
282
+ data = _get_json(url, to, "skills_sh")
283
+ skills = data.get("skills") if isinstance(data, dict) else None
284
+ if not isinstance(skills, list):
285
+ return []
286
+
287
+ results: list[dict[str, Any]] = []
288
+ for rank, s in enumerate(skills[: max(1, n)]):
289
+ if not isinstance(s, dict):
290
+ continue
291
+ sid = s.get("id") or ""
292
+ if not sid:
293
+ continue
294
+ installs = s.get("installs") or 0
295
+ source = s.get("source") or ""
296
+ results.append(
297
+ {
298
+ "title": s.get("name") or "",
299
+ # id 是 owner/repo/skill 三段式,直接拼站内页(实测 200)
300
+ "url": f"{_SKILLS_SH_PAGE}{sid}",
301
+ "snippet": f"安装 {installs} · {source}",
302
+ "source": "skills_sh",
303
+ "score": rank_score(0.75, rank),
304
+ # 可验证出处:三段式 id 指向技能本身(比市场页更精确)
305
+ "upstream": sid,
306
+ "metadata": {
307
+ "installs": installs,
308
+ "source": source,
309
+ },
310
+ }
311
+ )
312
+ return results
313
+
314
+ return _engine