argo-search 2.12.0 → 2.14.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 (371) hide show
  1. package/AGENTS.md +93 -0
  2. package/README.en.md +35 -12
  3. package/README.es.md +35 -12
  4. package/README.ja.md +38 -13
  5. package/README.ko.md +35 -12
  6. package/README.md +69 -42
  7. package/SKILL.md +4 -4
  8. package/assets/readme/counts.json +1 -0
  9. package/assets/readme/hero.svg +1 -1
  10. package/backends/domain_profiles.json +78 -6
  11. package/backends/engine_registry.yaml +188 -22
  12. package/backends/env_passthrough.txt +75 -0
  13. package/backends/quota_profiles.json +132 -12
  14. package/bin/argo +3 -0
  15. package/config.yaml +34 -3524
  16. package/docs/ARGO_INTRO.md +4 -3
  17. package/docs/CHANGELOG.md +337 -0
  18. package/docs/COMMIT_STANDARD.md +98 -0
  19. package/docs/ENGINE_CATALOG.md +65 -48
  20. package/docs/QUALITY_OF_SLOW_SOURCES.md +115 -0
  21. package/docs/RELEASE_NOTES_v2.13.0.md +66 -0
  22. package/docs/RELEASE_NOTES_v2.14.0.md +77 -0
  23. package/docs/RELEASING.md +47 -0
  24. package/docs//344/270/272/344/273/200/344/271/210/351/200/211/346/213/251argo.md +7 -7
  25. package/engines/specs/anysearch.yaml +33 -0
  26. package/engines/specs/archive_org.yaml +31 -0
  27. package/engines/specs/arxiv.yaml +18 -0
  28. package/engines/specs/baidu_baike.yaml +16 -0
  29. package/engines/specs/baidu_hot.yaml +19 -0
  30. package/engines/specs/bilibili.yaml +33 -0
  31. package/engines/specs/bilibili_hot.yaml +19 -0
  32. package/engines/specs/bing_rss.yaml +17 -0
  33. package/engines/specs/biorxiv.yaml +2 -0
  34. package/engines/specs/bocha.yaml +26 -0
  35. package/engines/specs/bocha_ai.yaml +27 -0
  36. package/engines/specs/brave.yaml +20 -0
  37. package/engines/specs/byted.yaml +33 -0
  38. package/engines/specs/clinicaltrials.yaml +23 -0
  39. package/engines/specs/cls_telegraph.yaml +19 -0
  40. package/engines/specs/cnii.yaml +21 -0
  41. package/engines/specs/cninfo.yaml +14 -0
  42. package/engines/specs/coingecko.yaml +33 -0
  43. package/engines/specs/courtlistener.yaml +15 -0
  44. package/engines/specs/crates.yaml +30 -0
  45. package/engines/specs/crossref.yaml +27 -0
  46. package/engines/specs/csdn.yaml +18 -0
  47. package/engines/specs/dblp.yaml +29 -0
  48. package/engines/specs/dbpedia.yaml +32 -0
  49. package/engines/specs/devto.yaml +26 -0
  50. package/engines/specs/dnb.yaml +17 -0
  51. package/engines/specs/doaj.yaml +17 -0
  52. package/engines/specs/docker_hub.yaml +30 -0
  53. package/engines/specs/douban_book.yaml +14 -0
  54. package/engines/specs/douyin_hot.yaml +21 -0
  55. package/engines/specs/eastmoney.yaml +16 -0
  56. package/engines/specs/ecosia.yaml +18 -0
  57. package/engines/specs/electricity_maps.yaml +17 -0
  58. package/engines/specs/em_flow.yaml +14 -0
  59. package/engines/specs/em_global_news.yaml +17 -0
  60. package/engines/specs/em_miaoxiang.yaml +14 -0
  61. package/engines/specs/eu_opendata.yaml +16 -0
  62. package/engines/specs/europeana.yaml +19 -0
  63. package/engines/specs/europepmc.yaml +29 -0
  64. package/engines/specs/eurostat.yaml +14 -0
  65. package/engines/specs/exa.yaml +20 -0
  66. package/engines/specs/felo.yaml +25 -0
  67. package/engines/specs/figshare.yaml +17 -0
  68. package/engines/specs/finviz.yaml +15 -0
  69. package/engines/specs/fourget.yaml +23 -0
  70. package/engines/specs/fr_opendata.yaml +28 -0
  71. package/engines/specs/frankfurter.yaml +21 -0
  72. package/engines/specs/fred.yaml +15 -0
  73. package/engines/specs/free_dictionary.yaml +16 -0
  74. package/engines/specs/fx_rate.yaml +14 -0
  75. package/engines/specs/gbfs_nyc.yaml +3 -0
  76. package/engines/specs/gbif.yaml +15 -0
  77. package/engines/specs/github.yaml +25 -0
  78. package/engines/specs/google_patents.yaml +16 -0
  79. package/engines/specs/google_scholar.yaml +16 -0
  80. package/engines/specs/gov_policy.yaml +31 -0
  81. package/engines/specs/grep_app.yaml +19 -0
  82. package/engines/specs/gutenberg.yaml +15 -0
  83. package/engines/specs/hackernews.yaml +18 -0
  84. package/engines/specs/hal.yaml +16 -0
  85. package/engines/specs/hatena_bookmark.yaml +20 -0
  86. package/engines/specs/hf_papers.yaml +26 -0
  87. package/engines/specs/huggingface.yaml +31 -0
  88. package/engines/specs/imdb.yaml +18 -0
  89. package/engines/specs/itotii.yaml +17 -0
  90. package/engines/specs/itunes.yaml +19 -0
  91. package/engines/specs/jin10.yaml +15 -0
  92. package/engines/specs/juejin.yaml +16 -0
  93. package/engines/specs/kaggle.yaml +44 -0
  94. package/engines/specs/know_your_meme.yaml +18 -0
  95. package/engines/specs/kor_law.yaml +17 -0
  96. package/engines/specs/lieu.yaml +18 -0
  97. package/engines/specs/listenbrainz.yaml +4 -0
  98. package/engines/specs/local_arxiv.yaml +18 -0
  99. package/engines/specs/local_baidu.yaml +35 -0
  100. package/engines/specs/local_bing.yaml +16 -0
  101. package/engines/specs/local_bing_news.yaml +22 -0
  102. package/engines/specs/local_crossref.yaml +23 -0
  103. package/engines/specs/local_github.yaml +27 -0
  104. package/engines/specs/local_gitlab.yaml +23 -0
  105. package/engines/specs/local_goodreads.yaml +16 -0
  106. package/engines/specs/local_google_news.yaml +15 -0
  107. package/engines/specs/local_imdb.yaml +17 -0
  108. package/engines/specs/local_npm.yaml +25 -0
  109. package/engines/specs/local_openstreetmap.yaml +36 -0
  110. package/engines/specs/local_pubmed.yaml +21 -0
  111. package/engines/specs/local_search.yaml +22 -0
  112. package/engines/specs/local_seek.yaml +34 -0
  113. package/engines/specs/local_semantic_scholar.yaml +23 -0
  114. package/engines/specs/local_sogou.yaml +15 -0
  115. package/engines/specs/local_stackoverflow.yaml +26 -0
  116. package/engines/specs/local_wikipedia.yaml +26 -0
  117. package/engines/specs/local_wikiquote.yaml +26 -0
  118. package/engines/specs/local_wiktionary.yaml +26 -0
  119. package/engines/specs/local_yandex.yaml +37 -0
  120. package/engines/specs/marginalia.yaml +22 -0
  121. package/engines/specs/mdn.yaml +32 -0
  122. package/engines/specs/met_museum.yaml +4 -2
  123. package/engines/specs/metaso.yaml +19 -0
  124. package/engines/specs/models_dev.yaml +16 -0
  125. package/engines/specs/moegirl.yaml +19 -0
  126. package/engines/specs/mojeek.yaml +31 -0
  127. package/engines/specs/musicbrainz.yaml +31 -0
  128. package/engines/specs/mwmbl.yaml +39 -0
  129. package/engines/specs/nasa_cmr.yaml +15 -0
  130. package/engines/specs/nbs_stats.yaml +16 -0
  131. package/engines/specs/ndl.yaml +17 -0
  132. package/engines/specs/noaa_swpc.yaml +3 -0
  133. package/engines/specs/npm.yaml +62 -0
  134. package/engines/specs/octen.yaml +16 -0
  135. package/engines/specs/open_library.yaml +15 -0
  136. package/engines/specs/open_meteo.yaml +17 -0
  137. package/engines/specs/openaire.yaml +34 -0
  138. package/engines/specs/openalex.yaml +27 -0
  139. package/engines/specs/opencitations.yaml +4 -1
  140. package/engines/specs/opencorporates.yaml +19 -0
  141. package/engines/specs/openfda.yaml +15 -0
  142. package/engines/specs/opensky.yaml +17 -0
  143. package/engines/specs/openverse.yaml +42 -0
  144. package/engines/specs/parallel.yaml +22 -0
  145. package/engines/specs/parallel_free.yaml +20 -0
  146. package/engines/specs/polymarket.yaml +26 -0
  147. package/engines/specs/pubchem.yaml +15 -0
  148. package/engines/specs/pypi.yaml +16 -0
  149. package/engines/specs/qiita.yaml +28 -0
  150. package/engines/specs/qq_music.yaml +17 -0
  151. package/engines/specs/qwant.yaml +19 -0
  152. package/engines/specs/qweather.yaml +14 -0
  153. package/engines/specs/rcsb_pdb.yaml +15 -0
  154. package/engines/specs/reddit.yaml +28 -0
  155. package/engines/specs/redskill.yaml +24 -0
  156. package/engines/specs/repology.yaml +18 -0
  157. package/engines/specs/rfc_editor.yaml +15 -0
  158. package/engines/specs/satnogs.yaml +5 -1
  159. package/engines/specs/searchmysite.yaml +18 -0
  160. package/engines/specs/searxng.yaml +18 -0
  161. package/engines/specs/sec_companyfacts.yaml +22 -0
  162. package/engines/specs/seeking_alpha.yaml +15 -0
  163. package/engines/specs/seltz.yaml +39 -0
  164. package/engines/specs/semantic_scholar.yaml +18 -0
  165. package/engines/specs/shenma.yaml +13 -0
  166. package/engines/specs/sina_quote.yaml +15 -0
  167. package/engines/specs/so.yaml +13 -0
  168. package/engines/specs/stackoverflow.yaml +18 -0
  169. package/engines/specs/steam.yaml +30 -0
  170. package/engines/specs/tatoeba.yaml +17 -0
  171. package/engines/specs/tavily.yaml +26 -0
  172. package/engines/specs/tencent_kline.yaml +18 -0
  173. package/engines/specs/tencent_quote.yaml +14 -0
  174. package/engines/specs/thesportsdb.yaml +18 -0
  175. package/engines/specs/ths_hot.yaml +19 -0
  176. package/engines/specs/tinyfish.yaml +36 -0
  177. package/engines/specs/tinyfish_news.yaml +34 -0
  178. package/engines/specs/tinyfish_paper.yaml +34 -0
  179. package/engines/specs/toutiao_hot.yaml +19 -0
  180. package/engines/specs/twitter.yaml +36 -0
  181. package/engines/specs/uapi.yaml +18 -0
  182. package/engines/specs/uniprot.yaml +16 -0
  183. package/engines/specs/urban_dictionary.yaml +25 -0
  184. package/engines/specs/usda.yaml +17 -0
  185. package/engines/specs/usgs.yaml +15 -0
  186. package/engines/specs/v2ex.yaml +33 -0
  187. package/engines/specs/vam.yaml +34 -0
  188. package/engines/specs/wallhaven.yaml +51 -0
  189. package/engines/specs/wallstreetcn.yaml +31 -0
  190. package/engines/specs/wayback_cdx.yaml +15 -0
  191. package/engines/specs/weather_cn.yaml +33 -0
  192. package/engines/specs/wechat_sogou.yaml +13 -0
  193. package/engines/specs/weibo.yaml +21 -0
  194. package/engines/specs/weibo_hot.yaml +21 -0
  195. package/engines/specs/wenshu.yaml +14 -0
  196. package/engines/specs/weread.yaml +14 -0
  197. package/engines/specs/wiby.yaml +18 -0
  198. package/engines/specs/wikidata.yaml +33 -0
  199. package/engines/specs/wikipedia.yaml +36 -0
  200. package/engines/specs/wolframalpha.yaml +18 -0
  201. package/engines/specs/worldbank.yaml +15 -0
  202. package/engines/specs/xiaohongshu.yaml +25 -0
  203. package/engines/specs/yahoo_finance.yaml +22 -0
  204. package/engines/specs/you.yaml +22 -0
  205. package/engines/specs/zh_wikipedia.yaml +35 -0
  206. package/engines/specs/zhihu.yaml +33 -0
  207. package/engines/specs/zhihu_global.yaml +18 -0
  208. package/engines/specs/zhihu_hot.yaml +36 -0
  209. package/engines/specs/zhihu_user.yaml +14 -0
  210. package/package.json +25 -22
  211. package/packages/dsh-plugin/README.md +11 -6
  212. package/packages/dsh-plugin/cordis.patch.yml +6 -2
  213. package/packages/dsh-plugin/dsh/client.js +65 -116
  214. package/packages/dsh-plugin/dsh/index.js +2 -2
  215. package/packages/dsh-plugin/dsh/native-tools.mjs +24 -3
  216. package/packages/dsh-plugin/dsh/runner.js +35 -1
  217. package/packages/dsh-plugin/dsh/specs.js +3 -1
  218. package/packages/dsh-plugin/dsh/wide-research.js +4 -2
  219. package/packages/dsh-plugin/package.json +1 -1
  220. package/packages/dsh-plugin/scripts/sync-local.sh +13 -11
  221. package/packages/dsh-plugin/test/client.test.js +22 -5
  222. package/packages/dsh-plugin/test/config.test.js +5 -1
  223. package/packages/dsh-plugin/test/index.test.js +3 -1
  224. package/packages/dsh-plugin/test/size-gate.test.js +2 -2
  225. package/scripts/ab_eval_p0p1.py +10 -4
  226. package/scripts/archive_run.py +4 -2
  227. package/scripts/badcase_causes.py +81 -0
  228. package/scripts/badcase_ledger.py +290 -15
  229. package/scripts/batch_probe.py +10 -8
  230. package/scripts/build_release_assets.sh +17 -5
  231. package/scripts/cache.py +8 -8
  232. package/scripts/cache_guard.py +10 -5
  233. package/scripts/candidate_envelope.py +7 -3
  234. package/scripts/check_commit_report.py +168 -0
  235. package/scripts/circuit_breaker.py +220 -36
  236. package/scripts/config.py +9 -10
  237. package/scripts/daemon.py +11 -2
  238. package/scripts/engine_add.py +32 -0
  239. package/scripts/engine_admission.py +9 -5
  240. package/scripts/engine_dispatch.py +49 -46
  241. package/scripts/engine_failure.py +14 -18
  242. package/scripts/engine_families.py +13 -2
  243. package/scripts/engine_health.py +184 -0
  244. package/scripts/engine_policy.py +1 -1
  245. package/scripts/engine_states.py +989 -0
  246. package/scripts/engine_status.py +49 -11
  247. package/scripts/engine_validate.py +47 -39
  248. package/scripts/engines.py +8 -0
  249. package/scripts/engines_base.py +34 -88
  250. package/scripts/engines_builders.py +36 -19
  251. package/scripts/engines_builders_archive.py +303 -0
  252. package/scripts/engines_builders_batch11.py +63 -1
  253. package/scripts/engines_builders_batch12.py +168 -0
  254. package/scripts/engines_builders_batch16.py +186 -0
  255. package/scripts/engines_builders_batch9.py +9 -1
  256. package/scripts/engines_builders_data.py +69 -2090
  257. package/scripts/engines_builders_finance.py +354 -0
  258. package/scripts/engines_builders_intl.py +4 -1
  259. package/scripts/engines_builders_media.py +724 -0
  260. package/scripts/engines_builders_science.py +784 -0
  261. package/scripts/engines_parsers.py +399 -0
  262. package/scripts/fetch_browser.py +4 -2
  263. package/scripts/fetch_jsrun.py +2 -1
  264. package/scripts/fetch_v3.py +38 -38
  265. package/scripts/gen_engine_catalog.py +58 -153
  266. package/scripts/gen_native_tools.py +44 -17
  267. package/scripts/gen_routing_snapshot.py +8 -6
  268. package/scripts/health_check.py +37 -4
  269. package/scripts/health_probe.py +28 -8
  270. package/scripts/install.ps1 +31 -15
  271. package/scripts/install.sh +266 -142
  272. package/scripts/job.py +8 -70
  273. package/scripts/lint_spec_contracts.py +7 -12
  274. package/scripts/local_intent.py +139 -0
  275. package/scripts/local_seek.py +223 -91
  276. package/scripts/local_seek_adapter.py +87 -0
  277. package/scripts/mcp_launch.sh +9 -17
  278. package/scripts/mcp_transport.py +1 -1
  279. package/scripts/net_proxy.py +47 -0
  280. package/scripts/numeric_verify.py +20 -9
  281. package/scripts/output_transparency.py +21 -13
  282. package/scripts/plan.py +8 -5
  283. package/scripts/pre-commit +93 -23
  284. package/scripts/quota.py +11 -7
  285. package/scripts/recovery.py +14 -5
  286. package/scripts/recovery_l0.py +5 -3
  287. package/scripts/redskill/redskill_engine.py +3 -9
  288. package/scripts/release.py +60 -24
  289. package/scripts/release_check.py +20 -3
  290. package/scripts/research.py +1 -1
  291. package/scripts/research_dossier.py +10 -5
  292. package/scripts/research_gates.py +8 -4
  293. package/scripts/retry_policy.py +8 -7
  294. package/scripts/route.py +2 -24
  295. package/scripts/route_combo.py +11 -26
  296. package/scripts/route_lang.py +6 -1
  297. package/scripts/route_policy.py +21 -14
  298. package/scripts/search.py +36 -35
  299. package/scripts/search_attribution.py +34 -3
  300. package/scripts/search_cli.py +22 -12
  301. package/scripts/search_entry.py +15 -3
  302. package/scripts/search_output.py +87 -18
  303. package/scripts/search_pipeline.py +14 -10
  304. package/scripts/search_rank.py +23 -62
  305. package/scripts/search_types.py +5 -0
  306. package/scripts/social_engines/bilibili_engine.py +2 -30
  307. package/scripts/social_engines/hackernews_engine.py +4 -12
  308. package/scripts/social_engines/reddit_engine.py +4 -13
  309. package/scripts/social_engines/v2ex_engine.py +3 -12
  310. package/scripts/social_engines/weibo_engine.py +2 -30
  311. package/scripts/social_engines/zhihu_engine.py +4 -5
  312. package/scripts/source_audit.py +331 -0
  313. package/scripts/stats_cli.py +17 -1
  314. package/scripts/sync_backends.py +241 -8
  315. package/scripts/sync_requirements.py +159 -0
  316. package/scripts/tweet.py +3 -6
  317. package/scripts/usage_log.py +28 -9
  318. package/scripts/video_fetch.py +2 -5
  319. package/scripts/watch.py +11 -6
  320. package/scripts/wechat_article.py +11 -12
  321. package/scripts/wide_research.py +4 -1
  322. package/scripts/wx.py +6 -13
  323. package/scripts/x_article_fetch.py +2 -1
  324. package/sub-skills/local-search/SKILL.md +2 -2
  325. package/sub-skills/local-search/config.yaml +2 -1
  326. package/sub-skills/local-search/parsers.py +6 -1
  327. package/sub-skills/local-seek/scripts/seek.py +390 -24
  328. package/sub-skills/local-seek/scripts/seek_fts.py +20 -9
  329. package/sub-skills/local-seek/scripts/seek_rank.py +64 -1
  330. package/docs/DATA_SOURCE_GAPS.md +0 -81
  331. package/docs/DESIGN_LOCAL_DATA_FUSION.md +0 -90
  332. package/docs/PLATFORM_PATHS.md +0 -111
  333. package/docs/engines/bangumi.md +0 -27
  334. package/docs/engines/biorxiv.md +0 -27
  335. package/docs/engines/clawhub.md +0 -27
  336. package/docs/engines/crt_sh.md +0 -27
  337. package/docs/engines/datacite.md +0 -27
  338. package/docs/engines/deps_dev.md +0 -27
  339. package/docs/engines/douban_movie.md +0 -27
  340. package/docs/engines/endoflife.md +0 -27
  341. package/docs/engines/flk_law.md +0 -27
  342. package/docs/engines/fxtwitter.md +0 -27
  343. package/docs/engines/google_news.md +0 -27
  344. package/docs/engines/gov_regulations.md +0 -27
  345. package/docs/engines/guqian.md +0 -27
  346. package/docs/engines/hackernews.md +0 -27
  347. package/docs/engines/iplant.md +0 -27
  348. package/docs/engines/keenable.md +0 -27
  349. package/docs/engines/met_museum.md +0 -27
  350. package/docs/engines/nasa_images.md +0 -27
  351. package/docs/engines/netease_music.md +0 -27
  352. package/docs/engines/npm.md +0 -27
  353. package/docs/engines/nvd.md +0 -27
  354. package/docs/engines/openreview.md +0 -27
  355. package/docs/engines/openstd.md +0 -27
  356. package/docs/engines/parallel_free.md +0 -27
  357. package/docs/engines/people_daily.md +0 -27
  358. package/docs/engines/pixiv.md +0 -27
  359. package/docs/engines/realtime_index.md +0 -27
  360. package/docs/engines/sec_edgar.md +0 -27
  361. package/docs/engines/seltz.md +0 -27
  362. package/docs/engines/skillsmp.md +0 -27
  363. package/docs/engines/sspai.md +0 -27
  364. package/docs/engines/std_samr.md +0 -27
  365. package/docs/engines/train.md +0 -27
  366. package/docs/engines/un_comtrade.md +0 -27
  367. package/docs/engines/wikisource.md +0 -27
  368. package/docs/engines/zdic.md +0 -27
  369. package/docs/engines/zenodo.md +0 -27
  370. package/docs/engines/zhihu_hot_app.md +0 -27
  371. package/engines/specs/cinii.yaml +0 -44
@@ -80,6 +80,8 @@ from engines_builders_cn import (
80
80
  from engines_builders_batch12 import (
81
81
  _build_so_engine,
82
82
  _build_shenma_engine,
83
+ _build_repology_engine,
84
+ _build_grep_app_engine,
83
85
  )
84
86
 
85
87
  from engines_builders_batch13 import (
@@ -96,42 +98,53 @@ from engines_builders_batch14 import (
96
98
  from engines_builders_batch15 import (
97
99
  _build_yuanbao_engine,
98
100
  )
101
+ from engines_builders_batch16 import (
102
+ _build_hf_papers_engine,
103
+ )
99
104
  from engines_builders_data import (
100
105
  _build_open_library_engine,
101
106
  _build_weread_engine,
102
107
  _build_douban_book_engine,
108
+ _build_rfc_editor_engine,
109
+ _build_free_dictionary_engine,
110
+ _build_baidu_baike_engine,
111
+ _build_pypi_engine,
112
+ _build_juejin_engine,
113
+ _build_models_dev_engine,
114
+ _build_qweather_engine,
115
+ _build_octen_engine,
116
+ _build_marginalia_engine,
117
+ _build_wiby_engine,
118
+ )
119
+ from engines_builders_media import (
120
+ _build_imdb_engine,
121
+ _build_thesportsdb_engine,
122
+ _build_itunes_engine,
123
+ )
124
+ from engines_builders_science import (
103
125
  _build_pubchem_engine,
104
126
  _build_gbif_engine,
105
- _build_rfc_editor_engine,
106
127
  _build_uniprot_engine,
107
128
  _build_biorxiv_engine,
108
- _build_un_comtrade_engine,
109
129
  _build_rcsb_pdb_engine,
110
- _build_courtlistener_engine,
111
- _build_gutenberg_engine,
112
- _build_wayback_cdx_engine,
113
130
  _build_usgs_engine,
114
131
  _build_nasa_cmr_engine,
115
- _build_free_dictionary_engine,
116
- _build_baidu_baike_engine,
117
- _build_pypi_engine,
118
132
  _build_clinicaltrials_engine,
119
133
  _build_openfda_engine,
120
- _build_juejin_engine,
121
- _build_models_dev_engine,
134
+ )
135
+ from engines_builders_finance import (
136
+ _build_un_comtrade_engine,
122
137
  _build_finviz_engine,
123
138
  _build_seeking_alpha_engine,
124
- _build_qweather_engine,
125
- _build_wenshu_engine,
126
139
  _build_jin10_engine,
127
- _build_octen_engine,
128
- _build_imdb_engine,
129
- _build_thesportsdb_engine,
130
- _build_itunes_engine,
131
140
  _build_opencorporates_engine,
141
+ )
142
+ from engines_builders_archive import (
143
+ _build_courtlistener_engine,
144
+ _build_gutenberg_engine,
145
+ _build_wayback_cdx_engine,
146
+ _build_wenshu_engine,
132
147
  _build_google_patents_engine,
133
- _build_marginalia_engine,
134
- _build_wiby_engine,
135
148
  )
136
149
  from engines_builders_data_macro import (
137
150
  _build_fred_engine,
@@ -172,6 +185,10 @@ from engines_builders_intl import (
172
185
  _build_google_news_engine,
173
186
  _build_met_museum_engine,
174
187
  )
188
+ # vam 与 wikimedia_commons 同属图源补强模块(batch11),不进 intl 组
189
+ from engines_builders_batch11 import (
190
+ _build_vam_engine,
191
+ )
175
192
  from engines_builders_feeds import (
176
193
  _build_rss_feed_engine,
177
194
  )
@@ -211,6 +228,7 @@ __all__ = [
211
228
  "_build_weather_cn_engine",
212
229
  "_build_google_news_engine",
213
230
  "_build_met_museum_engine",
231
+ "_build_vam_engine",
214
232
  "_build_google_scholar_engine",
215
233
  "_build_v2ex_engine",
216
234
  "_build_github_engine",
@@ -275,7 +293,6 @@ __all__ = [
275
293
  "_build_open_meteo_engine",
276
294
  "_build_twitter_syndication_engine",
277
295
  "_build_searchmysite_engine",
278
- "_build_searchmysite_engine",
279
296
  "_build_lieu_engine",
280
297
  "_build_opensky_engine",
281
298
  "_build_electricity_maps_engine",
@@ -0,0 +1,303 @@
1
+ #!/usr/bin/env python3
2
+ """专用构建器:法律文书、专利、公版书与网页存档(CourtListener / 裁判文书 / Gutenberg / Wayback / Google Patents)
3
+
4
+ 自 engines_builders_data.py 按主题拆出(2026-11-08)。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ import logging
11
+ import re
12
+ import urllib.error
13
+ import urllib.parse
14
+ import urllib.request
15
+ from datetime import datetime
16
+ from typing import Any
17
+
18
+ from engines_base import (
19
+ rank_score,
20
+ safe_search, _detect_anti_bot,
21
+ http_open,
22
+ )
23
+
24
+ logger = logging.getLogger("unified_search.engines")
25
+
26
+ # ── 中国裁判文书网引擎(HTML/JSON 抓取)──────────────────────────────────────────
27
+
28
+ def _build_wenshu_engine(spec: dict[str, Any]) -> Any:
29
+ """中国裁判文书网(wenshu.court.gov.cn)法律文书检索。
30
+
31
+ 该站有较强反爬(参数加密),此处走公开列表接口,尽力而为;
32
+ 失败或被拦截时显式返回 [](不伪造结果)。
33
+ 提取:案号、案由、裁判日期、法院。
34
+ """
35
+ timeout = spec.get("timeout", 12)
36
+
37
+ @safe_search
38
+ def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
39
+ import urllib.parse as up
40
+ to = _timeout or timeout
41
+ # 公开检索页(列表 HTML)——政府站结构可能变化,解析失败即空
42
+ url = f"https://wenshu.court.gov.cn/website/wenshu/181217BMTKHNT2W0/index.html?q={up.quote(query)}"
43
+ headers = {
44
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
45
+ "(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
46
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
47
+ "Referer": "https://wenshu.court.gov.cn/",
48
+ }
49
+ try:
50
+ req = urllib.request.Request(url, headers=headers)
51
+ with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
52
+ html = resp.read().decode("utf-8", errors="replace")
53
+ except Exception as e:
54
+ logger.warning(f"裁判文书网访问失败: {e}")
55
+ return []
56
+ if _detect_anti_bot(html):
57
+ return []
58
+
59
+ results: list[dict[str, Any]] = []
60
+ # 尝试解析嵌入的 JSON 数据块(站点结构变化时降级为空)
61
+ blocks = re.findall(r'\{[^{}]*"caseName"[^{}]*\}', html)
62
+ for b in blocks[:n]:
63
+ try:
64
+ item = json.loads(b)
65
+ except Exception:
66
+ continue
67
+ results.append({
68
+ "title": item.get("caseName", "")[:100],
69
+ "url": "https://wenshu.court.gov.cn/",
70
+ "snippet": (f"案号 {item.get('caseNo', '')} | 案由 {item.get('caseType', '')} | "
71
+ f"法院 {item.get('court', '')} | 裁判日期 {item.get('judgeDate', '')}")[:300],
72
+ "source": "wenshu",
73
+ "facts": {"case_no": item.get("caseNo", ""), "court": item.get("court", ""),
74
+ "judge_date": item.get("judgeDate", "")},
75
+ })
76
+ return results
77
+ return _engine
78
+
79
+ # ── CourtListener 美国判例引擎 ───────────────────────────────────────────────
80
+
81
+ _COURTLISTENER_API = "https://www.courtlistener.com/api/rest/v4/search/"
82
+
83
+
84
+ def _build_courtlistener_engine(spec: dict[str, Any]) -> Any:
85
+ """CourtListener 美国判例检索(courtlistener.com/api/rest/v4,匿名可用)。
86
+
87
+ 注意 2026-05 起限额骤降(免费档约 5 次/分、125 次/天),qps 已压到 1。
88
+ """
89
+ timeout = spec.get("timeout", 12)
90
+ _HEADERS = {"User-Agent": "argo-search/2.6 (unified-search@local)", "Accept": "application/json"}
91
+
92
+ @safe_search
93
+ def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
94
+ q = query.strip()
95
+ if not q:
96
+ return []
97
+ to = _timeout or timeout
98
+ url = _COURTLISTENER_API + "?" + urllib.parse.urlencode({
99
+ "q": q, "format": "json", "page_size": min(n, 10), "order_by": "score desc",
100
+ })
101
+ try:
102
+ with http_open(urllib.request.Request(url, headers=_HEADERS), timeout=to, engine=spec.get("_name", "")) as resp:
103
+ data = json.loads(resp.read().decode("utf-8", "replace"))
104
+ except Exception as e:
105
+ logger.warning(f"CourtListener 失败: {e}")
106
+ return []
107
+ results = []
108
+ for _rk12, x in enumerate((data.get("results") or [])[:n]):
109
+ name = x.get("caseName") or q
110
+ rel = x.get("absolute_url") or ""
111
+ date = (x.get("dateFiled") or "")[:10]
112
+ snip = str(x.get("snippet") or "")[:280]
113
+ body_txt = str(x.get("plain_text") or "")[:280]
114
+ snip = snip or body_txt
115
+ parts = [p for p in (date, snip) if p]
116
+ results.append({
117
+ "title": name,
118
+ "url": f"https://www.courtlistener.com{rel}" if rel else "",
119
+ "snippet": " · ".join(parts)[:300],
120
+ "source": "courtlistener",
121
+ "score": rank_score(0.9, _rk12),
122
+ })
123
+ return results
124
+ return _engine
125
+
126
+
127
+ # ── Project Gutenberg 公版书引擎(Gutendex) ─────────────────────────────────
128
+
129
+ _GUTENDEX_API = "https://gutendex.com/books"
130
+
131
+
132
+ def _build_gutenberg_engine(spec: dict[str, Any]) -> Any:
133
+ """Project Gutenberg 公版书检索(gutendex.com,免认证)。
134
+
135
+ 返回书名/作者/语言与 Gutenberg 书目页链接;Gutenberg 提供结构化全文。
136
+ """
137
+ timeout = spec.get("timeout", 15)
138
+ _HEADERS = {"User-Agent": "argo-search/2.6 (unified-search@local)", "Accept": "application/json"}
139
+
140
+ @safe_search
141
+ def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
142
+ q = query.strip()
143
+ if not q:
144
+ return []
145
+ to = _timeout or timeout
146
+ url = _GUTENDEX_API + "?" + urllib.parse.urlencode({"search": q, "page_size": min(n, 10)})
147
+ try:
148
+ with http_open(urllib.request.Request(url, headers=_HEADERS), timeout=to, engine=spec.get("_name", "")) as resp:
149
+ data = json.loads(resp.read().decode("utf-8", "replace"))
150
+ except Exception as e:
151
+ logger.warning(f"Gutendex 失败: {e}")
152
+ return []
153
+ results = []
154
+ for _rk13, x in enumerate((data.get("results") or [])[:n]):
155
+ title = x.get("title") or q
156
+ gid = x.get("id") or ""
157
+ authors = ", ".join((a.get("name") or "") for a in (x.get("authors") or [])[:2])
158
+ langs = ",".join(x.get("languages") or [])
159
+ fmt = x.get("formats") or {}
160
+ txt = fmt.get("text/plain; charset=us-ascii") or fmt.get("text/html")
161
+ snip = " · ".join(p for p in (authors, langs, "公版书全文") if p)
162
+ _row = {
163
+ "title": title,
164
+ "url": f"https://www.gutenberg.org/ebooks/{gid}" if gid else txt or "",
165
+ "snippet": snip[:300],
166
+ "source": "gutenberg",
167
+ "score": rank_score(0.85, _rk13),
168
+ }
169
+ # 源内全文直出:`/ebooks/{id}` 是下载门户页(实测首段全是 noprint
170
+ # 脚本),不是正文;gutendex 本来就把纯文本 URL 放在 formats 里,
171
+ # 此前只在缺 id 时当保底,正常路径直接丢掉。这里单独带上,供下游
172
+ # 取正文时优先使用(省掉从门户页找下载链这一步)。
173
+ if txt:
174
+ _row["full_text_url"] = txt
175
+ results.append(_row)
176
+ return results
177
+ return _engine
178
+
179
+
180
+ # ── Wayback CDX 已删除内容检索引擎 ───────────────────────────────────────────
181
+
182
+ _CDX_API = "https://web.archive.org/cdx/search/cdx"
183
+
184
+
185
+ def _build_wayback_cdx_engine(spec: dict[str, Any]) -> Any:
186
+ """Wayback Machine CDX 快照检索(web.archive.org/cdx,免认证)。
187
+
188
+ 输入域名/URL,返回历史快照时间戳与状态码,是查已删除页面的唯一路径。
189
+ """
190
+ timeout = spec.get("timeout", 20)
191
+ _HEADERS = {"User-Agent": "argo-search/2.6 (unified-search@local)", "Accept": "application/json"}
192
+
193
+ @safe_search
194
+ def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
195
+ q = query.strip().lower()
196
+ if not q:
197
+ return []
198
+ # 剥离常见协议前缀,CDX 用裸域名/host 查询
199
+ q = re.sub(r"^https?://", "", q).strip()
200
+ if not q:
201
+ return []
202
+ to = _timeout or timeout
203
+ url = _CDX_API + "?" + urllib.parse.urlencode({
204
+ "url": q, "output": "json", "limit": min(n, 10),
205
+ "fl": "timestamp,original,statuscode",
206
+ })
207
+ try:
208
+ with http_open(urllib.request.Request(url, headers=_HEADERS), timeout=to, engine=spec.get("_name", "")) as resp:
209
+ data = json.loads(resp.read().decode("utf-8", "replace"))
210
+ except Exception as e:
211
+ logger.warning(f"Wayback CDX 失败: {e}")
212
+ return []
213
+ rows = data if isinstance(data, list) else []
214
+ # 带 fl 时首行是列名
215
+ if rows and rows[0] and rows[0][0] == "timestamp":
216
+ rows = rows[1:]
217
+ results = []
218
+ for _rk14, r in enumerate(rows[:n]):
219
+ if len(r) < 3:
220
+ continue
221
+ ts, orig, status = r[0], r[1], r[2]
222
+ # CDX 时间戳 YYYYMMDDHHMMSS → 标准 published_at(最早快照语义)
223
+ published_at = ""
224
+ try:
225
+ published_at = datetime.strptime(ts, "%Y%m%d%H%M%S").isoformat(timespec="seconds")
226
+ except ValueError:
227
+ pass
228
+ item = {
229
+ "title": f"快照 {orig}({ts[:8]})",
230
+ "url": f"https://web.archive.org/web/{ts}/{orig}",
231
+ "snippet": f"Wayback 快照 {ts} · HTTP {status}"[:300],
232
+ "source": "wayback_cdx",
233
+ "score": rank_score(0.8, _rk14),
234
+ }
235
+ if published_at:
236
+ item["published_at"] = published_at
237
+ results.append(item)
238
+ return results
239
+ return _engine
240
+
241
+
242
+ # ── Google Patents 专利搜索 ──────────────────────────────────────────────────
243
+
244
+ def _build_google_patents_engine(spec: dict[str, Any]) -> Any:
245
+ """Google Patents 专利搜索(patents.google.com/xhr/query,免认证)。
246
+
247
+ 技术尽调/竞品分析:专利标题、公开号、公开日期、申请人。
248
+ 用 patents.google.com 的公开 XHR 接口,免 key、返回 JSON。
249
+ argo 现有引擎无专利数据源,这是技术尽调的核心空白。
250
+ """
251
+ timeout = spec.get("timeout", 10)
252
+
253
+ @safe_search
254
+ def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
255
+ to = _timeout or timeout
256
+ q = query.strip()
257
+ # 去常见修饰语
258
+ q2 = re.sub(r"(?i)\b(patent|专利|查询|搜索|检索)\b", " ", q)
259
+ q2 = re.sub(r"\s+", " ", q2).strip() or q
260
+ url = "https://patents.google.com/xhr/query"
261
+ params = {
262
+ "url": f"q={urllib.parse.quote(q2)}",
263
+ "exp": "",
264
+ }
265
+ full_url = url + "?" + urllib.parse.urlencode(params)
266
+ headers = {
267
+ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36",
268
+ "Accept": "application/json",
269
+ }
270
+ try:
271
+ with http_open(urllib.request.Request(full_url, headers=headers), timeout=to, engine=spec.get("_name", "")) as resp:
272
+ data = json.loads(resp.read().decode("utf-8", "replace"))
273
+ except Exception:
274
+ return []
275
+ results: list[dict[str, Any]] = []
276
+ try:
277
+ cluster = (data.get("results") or {}).get("cluster") or []
278
+ for c in cluster:
279
+ for r in (c.get("result") or []):
280
+ if len(results) >= n:
281
+ break
282
+ pat = r.get("patent") or {}
283
+ title = pat.get("title") or ""
284
+ if not title:
285
+ continue
286
+ pub_date = pat.get("publication_date") or ""
287
+ pub_num = pat.get("publication_number") or ""
288
+ assignee = (pat.get("assignee") or [{}])[0].get("name") if isinstance(pat.get("assignee"), list) else ""
289
+ pub_id = pat.get("publication_number") or pub_num or ""
290
+ results.append({
291
+ "title": title[:200],
292
+ "url": f"https://patents.google.com/patent/{pub_id}" if pub_id else "",
293
+ "snippet": (r.get("snippet") or "")[:300],
294
+ "source": "google_patents",
295
+ "score": rank_score(0.8, len(results)),
296
+ "publication_date": pub_date,
297
+ "publication_number": pub_num,
298
+ "assignee": assignee,
299
+ })
300
+ except Exception:
301
+ pass
302
+ return results
303
+ return _engine
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env python3
2
- """批次十一构建器:图片检索能力的两个补强源(2026-09-26)。
2
+ """批次十一构建器:图片检索能力的补强源(2026-09-26 起,2026-11-08 增补 vam)。
3
3
 
4
4
  本批只收图源,目标是修「搜到图源却拿不到图」这一类缺陷的通用面:
5
5
 
6
6
  wikimedia_commons Wikimedia Commons(免 key,通用图库,带 CC 许可与宽高)
7
+ vam V&A 博物馆馆藏(免 key,IIIF 直链组装)
7
8
 
8
9
  为什么单独建一个 builder 而不是声明式 spec:Commons 的 `query.pages` 是
9
10
  **以 pageid 为键的字典**,不是数组——`_extract_items` 遇到 dict 会把它当成
@@ -25,6 +26,7 @@ from engines_base import (
25
26
  rank_score,
26
27
  safe_search,
27
28
  http_open,
29
+ _http_get_raw,
28
30
  )
29
31
 
30
32
 
@@ -172,3 +174,63 @@ def _build_wikimedia_commons_engine(spec: dict[str, Any]) -> Any:
172
174
  return finalize_image_fields(results, spec.get("image_license") or "")
173
175
 
174
176
  return _engine
177
+
178
+
179
+ def _build_vam_engine(spec: dict[str, Any]) -> Any:
180
+ """V&A 博物馆馆藏(api.vam.ac.uk/v2/objects/search,免 key,单跳)。
181
+
182
+ 装饰艺术/设计垂直,与 met/artic/cleveland 同面。records._images 只给 IIIF
183
+ base 与 !100,100 缩略图,800px 直链按 IIIF 尺寸语法组装:
184
+ `{base}full/!800,800/0/default.jpg`(实测 2026-11-08 200 可取图)。
185
+ 落地页用短链 `collections.vam.ac.uk/item/{systemNumber}/`(自带 O 前缀,无 slug 200 直开)。
186
+ 上游不逐件给许可字段,不造 image_license;商用判定照 ddgs_images 口径(未判定)。
187
+ """
188
+ timeout = spec.get("timeout", 15)
189
+
190
+ @safe_search
191
+ def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
192
+ q = query.strip()
193
+ if not q:
194
+ return []
195
+ to = _timeout or timeout
196
+ engine_name = spec.get("_name", "vam")
197
+ headers = {"User-Agent": "argo-search/1.0 (+vam)", "Accept": "application/json"}
198
+ url = (f"https://api.vam.ac.uk/v2/objects/search?q={urllib.parse.quote(q)}"
199
+ f"&images_exist=1&page_size={min(max(int(n), 1), 8)}")
200
+ raw = _http_get_raw(url, headers, to, engine=engine_name)
201
+ if raw is None:
202
+ return []
203
+ try:
204
+ d = json.loads(raw) or {}
205
+ except (json.JSONDecodeError, ValueError):
206
+ return []
207
+ out = []
208
+ for r in d.get("records") or []:
209
+ if not isinstance(r, dict):
210
+ continue
211
+ title = str(r.get("_primaryTitle") or "").strip()
212
+ imgs = r.get("_images") or {}
213
+ base = str(imgs.get("_iiif_image_base_url") or "").strip()
214
+ if not title and not base:
215
+ continue
216
+ row: dict[str, Any] = {}
217
+ if title:
218
+ row["title"] = title[:80]
219
+ maker = r.get("_primaryMaker") or {}
220
+ row["snippet"] = " · ".join(b for b in (
221
+ str(maker.get("name") or "").strip(),
222
+ str(r.get("_primaryDate") or "").strip(),
223
+ str(r.get("objectType") or "").strip()) if b)[:300]
224
+ if base:
225
+ row["image_url"] = base + "full/!800,800/0/default.jpg"
226
+ # systemNumber 自带 O 前缀(如 O417199);再拼一个 O 会变成
227
+ # OO417199(302 跳转),直接用原值才是 200 的规范落地页。
228
+ sn = str(r.get("systemNumber") or "").strip()
229
+ if sn:
230
+ row["url"] = f"https://collections.vam.ac.uk/item/{sn}/"
231
+ row["source"] = engine_name
232
+ out.append(row)
233
+ if len(out) >= max(int(n), 1):
234
+ break
235
+ return out
236
+ return _engine
@@ -13,6 +13,7 @@ tests/test_new_source_reachability.py::_DORMANT_ALLOWLIST。
13
13
 
14
14
  from __future__ import annotations
15
15
 
16
+ import json
16
17
  import logging
17
18
  import re
18
19
  import urllib.request
@@ -101,3 +102,170 @@ def _build_shenma_engine(spec: dict[str, Any]) -> Any:
101
102
  logger.warning(f"神马搜索失败: {e}")
102
103
  return []
103
104
  return _engine
105
+
106
+
107
+ # ── Repology 跨发行版包生态版本与状态真相(免认证)────────────────────
108
+
109
+ def _build_repology_engine(spec: dict[str, Any]) -> Any:
110
+ """Repology 全网 Linux/UNIX 跨包管理器生态版本真相(免认证)。
111
+
112
+ 覆盖 Debian、Arch、Nix、Alpine、Homebrew、Fedora 等数百个仓库的真实版本与生命周期状态。
113
+ """
114
+ timeout = spec.get("timeout", 10)
115
+
116
+ @safe_search
117
+ def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
118
+ to = _timeout or timeout
119
+ cleaned = re.sub(r"[,,。?!?\s]+", " ", query or "").strip()
120
+ tokens = [t for t in cleaned.split(" ") if t and not any(w in t.lower() for w in ("包", "版本", "依赖", "软件", "package", "version"))]
121
+ q = tokens[0] if tokens else (cleaned.split(" ")[0] if cleaned else "")
122
+ if not q:
123
+ return []
124
+
125
+ import urllib.parse as up
126
+ url = f"https://repology.org/api/v1/projects/?search={up.quote(q)}"
127
+ from engines_base import _http_get_raw
128
+ raw = _http_get_raw(url, {"Accept": "application/json", "User-Agent": "Mozilla/5.0"}, to, engine="repology")
129
+ if not raw:
130
+ return []
131
+ try:
132
+ data = json.loads(raw)
133
+ except json.JSONDecodeError:
134
+ return []
135
+ if not isinstance(data, dict):
136
+ return []
137
+
138
+ results: list[dict[str, Any]] = []
139
+ for proj_name, entries in list(data.items())[:n]:
140
+ if not isinstance(entries, list) or not entries:
141
+ continue
142
+ newest_ver = ""
143
+ repos_summary = []
144
+ for item in entries:
145
+ if not isinstance(item, dict):
146
+ continue
147
+ v = item.get("version") or ""
148
+ repo = item.get("repo") or ""
149
+ status = item.get("status") or ""
150
+ if status == "newest" and not newest_ver:
151
+ newest_ver = v
152
+ if any(k in repo for k in ("debian", "arch", "nix", "homebrew", "alpine", "fedora", "ubuntu")):
153
+ if len(repos_summary) < 4:
154
+ repos_summary.append(f"{repo}: {v}")
155
+ if not newest_ver and entries:
156
+ newest_ver = entries[0].get("version", "?")
157
+
158
+ repo_text = " · ".join(repos_summary) if repos_summary else f"共收录于 {len(entries)} 个仓库"
159
+ snippet = f"最新版本: {newest_ver} | 主要发行版: {repo_text}"
160
+ results.append({
161
+ "title": f"{proj_name} (Repology 跨发行版包详情)",
162
+ "url": f"https://repology.org/project/{proj_name}/versions",
163
+ "snippet": snippet,
164
+ "source": "repology",
165
+ })
166
+ return results
167
+ return _engine
168
+
169
+
170
+ # ── Grep.app 全球百万 GitHub 核心代码正则检索(官方 MCP 传输免认证)─────
171
+
172
+ _GREP_APP_MCP_URL = "https://mcp.grep.app"
173
+
174
+
175
+ def _build_grep_app_engine(spec: dict[str, Any]) -> Any:
176
+ """Grep.app 全网开源代码精准检索引擎(官方 MCP 通道,免认证)。
177
+
178
+ 通过官方 MCP 端点直接调用 searchGitHub,避开常规前端 WAF 挑战,
179
+ 支持字面量代码匹配与正则搜索,返回包含仓库、文件路径与行号的真实代码片段。
180
+ """
181
+ timeout = spec.get("timeout", 10)
182
+
183
+ @safe_search
184
+ def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
185
+ to = _timeout or timeout
186
+ q = (query or "").strip()
187
+ if not q:
188
+ return []
189
+
190
+ from engines_builders_tech import _parse_mcp_wire, _mcp_error_of
191
+
192
+ payload = {
193
+ "jsonrpc": "2.0",
194
+ "id": 1,
195
+ "method": "tools/call",
196
+ "params": {
197
+ "name": "searchGitHub",
198
+ "arguments": {
199
+ "query": q,
200
+ },
201
+ },
202
+ }
203
+ body = json.dumps(payload).encode("utf-8")
204
+ headers = {
205
+ "Content-Type": "application/json",
206
+ "Accept": "application/json, text/event-stream",
207
+ "User-Agent": (
208
+ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
209
+ "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
210
+ ),
211
+ }
212
+
213
+ req = urllib.request.Request(_GREP_APP_MCP_URL, data=body, headers=headers)
214
+ try:
215
+ with http_open(req, timeout=to, engine=spec.get("_name", "grep_app")) as resp:
216
+ raw = resp.read().decode("utf-8", "replace")
217
+ except Exception as e:
218
+ logger.warning(f"grep_app MCP 请求失败: {e}")
219
+ return []
220
+
221
+ data = _parse_mcp_wire(raw)
222
+ if not isinstance(data, dict):
223
+ return []
224
+
225
+ mcp_err = _mcp_error_of(data)
226
+ if mcp_err:
227
+ logger.warning(f"grep_app MCP 上游错误: {mcp_err}")
228
+ return []
229
+
230
+ result = data.get("result")
231
+ if not isinstance(result, dict):
232
+ return []
233
+
234
+ content = result.get("content") or []
235
+ results: list[dict[str, Any]] = []
236
+
237
+ for item in content:
238
+ if not isinstance(item, dict):
239
+ continue
240
+ text = item.get("text") or ""
241
+ if not text:
242
+ continue
243
+
244
+ repo_m = re.search(r"Repository:\s*(\S+)", text)
245
+ path_m = re.search(r"Path:\s*(\S+)", text)
246
+ url_m = re.search(r"URL:\s*(\S+)", text)
247
+ snip_m = re.search(r"Snippets:\s*(.*)", text, re.S)
248
+
249
+ repo = repo_m.group(1) if repo_m else ""
250
+ path = path_m.group(1) if path_m else ""
251
+ url = url_m.group(1) if url_m else ""
252
+ snippet = snip_m.group(1).strip() if snip_m else text[:250]
253
+
254
+ if not url:
255
+ continue
256
+
257
+ title = f"{repo}: {path}" if repo and path else (path or repo or "code snippet")
258
+ results.append({
259
+ "title": title,
260
+ "url": url,
261
+ "snippet": snippet[:350],
262
+ "source": "grep_app",
263
+ })
264
+ if len(results) >= n:
265
+ break
266
+
267
+ return results
268
+
269
+ return _engine
270
+
271
+