argo-search 1.0.1 → 2.9.8

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 (472) hide show
  1. package/LICENSE +201 -21
  2. package/README.en.md +735 -0
  3. package/README.es.md +777 -0
  4. package/README.ja.md +777 -0
  5. package/README.ko.md +777 -0
  6. package/README.md +778 -320
  7. package/SKILL.md +135 -0
  8. package/assets/readme/hero.svg +121 -0
  9. package/assets/readme/made-with-beautify.svg +10 -0
  10. package/assets/readme/proof-routes.svg +73 -0
  11. package/assets/readme/why-better.svg +104 -0
  12. package/assets/readme/workflow.svg +83 -0
  13. package/backends/domain_profiles.json +2356 -96
  14. package/backends/engine_registry.yaml +3428 -503
  15. package/backends/query_synonyms_cn.json +35 -0
  16. package/backends/quota_profiles.json +2488 -160
  17. package/backends/source_types_cn.json +109 -0
  18. package/backends/text_lexicon.json +44 -0
  19. package/bin/argo +772 -0
  20. package/bin/argo.js +102 -39
  21. package/config.yaml +5139 -367
  22. package/cordis.patch.yml +21 -0
  23. package/data/countries.json +40 -0
  24. package/data/lang_matrix/lang_capability.json +842 -0
  25. package/data/lang_matrix/matrix_2026-09-10.json +11921 -0
  26. package/data/regions_cn.json +1 -0
  27. package/docs/ADDING_NEW_ENGINE.md +184 -0
  28. package/docs/ARGO_INTRO.md +124 -0
  29. package/docs/DATA_SOURCE_GAPS.md +81 -0
  30. package/docs/DESIGN_LOCAL_DATA_FUSION.md +90 -0
  31. package/docs/ENGINE_CATALOG.md +575 -0
  32. package/docs/MCP_SETUP.md +108 -0
  33. package/docs/PLATFORM_PATHS.md +111 -0
  34. package/docs/RELEASE_NOTES_v2.8.0.md +71 -0
  35. package/docs/RELEASE_NOTES_v2.8.2.md +63 -0
  36. package/docs/RELEASE_NOTES_v2.8.3.md +55 -0
  37. package/docs/RELEASE_NOTES_v2.8.4.md +79 -0
  38. package/docs/RELEASE_NOTES_v2.8.5.md +102 -0
  39. package/docs/RELEASE_NOTES_v2.8.6.md +66 -0
  40. package/docs/RELEASE_NOTES_v2.8.7.md +65 -0
  41. package/docs/RELEASE_NOTES_v2.8.8.md +67 -0
  42. package/docs/RELEASE_NOTES_v2.8.9.md +67 -0
  43. package/docs/RELEASE_NOTES_v2.9.0.md +64 -0
  44. package/docs/RELEASE_NOTES_v2.9.8.md +73 -0
  45. package/docs/SEARCH_ARCHIVE.md +115 -0
  46. package/docs/assets/architecture.svg +104 -0
  47. package/docs/assets/hero.svg +98 -0
  48. package/docs/engines/bangumi.md +27 -0
  49. package/docs/engines/biorxiv.md +27 -0
  50. package/docs/engines/clawhub.md +27 -0
  51. package/docs/engines/crt_sh.md +27 -0
  52. package/docs/engines/datacite.md +27 -0
  53. package/docs/engines/deps_dev.md +27 -0
  54. package/docs/engines/douban_movie.md +27 -0
  55. package/docs/engines/endoflife.md +27 -0
  56. package/docs/engines/flk_law.md +27 -0
  57. package/docs/engines/fxtwitter.md +27 -0
  58. package/docs/engines/google_news.md +27 -0
  59. package/docs/engines/gov_regulations.md +27 -0
  60. package/docs/engines/guqian.md +27 -0
  61. package/docs/engines/hackernews.md +27 -0
  62. package/docs/engines/iplant.md +27 -0
  63. package/docs/engines/keenable.md +27 -0
  64. package/docs/engines/met_museum.md +27 -0
  65. package/docs/engines/nasa_images.md +27 -0
  66. package/docs/engines/netease_music.md +27 -0
  67. package/docs/engines/npm.md +27 -0
  68. package/docs/engines/nvd.md +27 -0
  69. package/docs/engines/openreview.md +27 -0
  70. package/docs/engines/openstd.md +27 -0
  71. package/docs/engines/parallel_free.md +27 -0
  72. package/docs/engines/people_daily.md +27 -0
  73. package/docs/engines/realtime_index.md +27 -0
  74. package/docs/engines/sec_edgar.md +27 -0
  75. package/docs/engines/seltz.md +27 -0
  76. package/docs/engines/skillsmp.md +27 -0
  77. package/docs/engines/sspai.md +27 -0
  78. package/docs/engines/std_samr.md +27 -0
  79. package/docs/engines/train.md +27 -0
  80. package/docs/engines/un_comtrade.md +27 -0
  81. package/docs/engines/wikisource.md +27 -0
  82. package/docs/engines/zdic.md +27 -0
  83. package/docs/engines/zenodo.md +27 -0
  84. package/docs/engines/zhihu_hot_app.md +27 -0
  85. package/docs//344/270/272/344/273/200/344/271/210/351/200/211/346/213/251argo.md +176 -0
  86. package/engines/README.md +10 -0
  87. package/engines/_template_cli.yaml +39 -0
  88. package/engines/_template_http.yaml +37 -0
  89. package/engines/plugins/_template_plugin.py +50 -0
  90. package/engines/specs/_cisa_kev.yaml +54 -0
  91. package/engines/specs/_osv.yaml +63 -0
  92. package/engines/specs/aljazeera.yaml +43 -0
  93. package/engines/specs/antara.yaml +43 -0
  94. package/engines/specs/artic.yaml +20 -0
  95. package/engines/specs/aviation_weather.yaml +39 -0
  96. package/engines/specs/bangumi.yaml +21 -0
  97. package/engines/specs/biorxiv.yaml +24 -0
  98. package/engines/specs/carbon_intensity.yaml +32 -0
  99. package/engines/specs/cfets.yaml +41 -0
  100. package/engines/specs/cinii.yaml +44 -0
  101. package/engines/specs/clawhub.yaml +49 -0
  102. package/engines/specs/cleveland.yaml +19 -0
  103. package/engines/specs/cn_ai_news.yaml +43 -0
  104. package/engines/specs/core.yaml +35 -0
  105. package/engines/specs/crt_sh.yaml +38 -0
  106. package/engines/specs/ct24.yaml +43 -0
  107. package/engines/specs/datacite.yaml +27 -0
  108. package/engines/specs/datagov_uk.yaml +41 -0
  109. package/engines/specs/ddgs_images.yaml +45 -0
  110. package/engines/specs/deepseek_search.yaml +74 -0
  111. package/engines/specs/deezer.yaml +20 -0
  112. package/engines/specs/defillama.yaml +38 -0
  113. package/engines/specs/deps_dev.yaml +21 -0
  114. package/engines/specs/digup.yaml +36 -0
  115. package/engines/specs/doi.yaml +39 -0
  116. package/engines/specs/douban_movie.yaml +22 -0
  117. package/engines/specs/dw_news.yaml +47 -0
  118. package/engines/specs/egov_law.yaml +21 -0
  119. package/engines/specs/elpais.yaml +43 -0
  120. package/engines/specs/endoflife.yaml +21 -0
  121. package/engines/specs/energy_charts.yaml +21 -0
  122. package/engines/specs/factcheck_org.yaml +52 -0
  123. package/engines/specs/faz.yaml +43 -0
  124. package/engines/specs/federal_register.yaml +57 -0
  125. package/engines/specs/firecrawl.yaml +53 -0
  126. package/engines/specs/flk_law.yaml +24 -0
  127. package/engines/specs/folha.yaml +43 -0
  128. package/engines/specs/france24.yaml +44 -0
  129. package/engines/specs/full_fact.yaml +47 -0
  130. package/engines/specs/fxtwitter.yaml +36 -0
  131. package/engines/specs/gbfs_nyc.yaml +32 -0
  132. package/engines/specs/gdacs.yaml +21 -0
  133. package/engines/specs/gdelt.yaml +64 -0
  134. package/engines/specs/gleif.yaml +55 -0
  135. package/engines/specs/google_news.yaml +22 -0
  136. package/engines/specs/gov_regulations.yaml +38 -0
  137. package/engines/specs/guardian_rss.yaml +59 -0
  138. package/engines/specs/hkex.yaml +40 -0
  139. package/engines/specs/hurriyet.yaml +43 -0
  140. package/engines/specs/iplant.yaml +25 -0
  141. package/engines/specs/jikan.yaml +24 -0
  142. package/engines/specs/jolpica.yaml +20 -0
  143. package/engines/specs/k10plus.yaml +20 -0
  144. package/engines/specs/keenable.yaml +44 -0
  145. package/engines/specs/keenable_free.yaml +36 -0
  146. package/engines/specs/lefigaro.yaml +43 -0
  147. package/engines/specs/listenbrainz.yaml +19 -0
  148. package/engines/specs/matichon.yaml +43 -0
  149. package/engines/specs/met_museum.yaml +21 -0
  150. package/engines/specs/nasa_images.yaml +45 -0
  151. package/engines/specs/netease_music.yaml +38 -0
  152. package/engines/specs/nhk.yaml +43 -0
  153. package/engines/specs/nhtsa_vpic.yaml +20 -0
  154. package/engines/specs/noaa_swpc.yaml +20 -0
  155. package/engines/specs/nvd.yaml +38 -0
  156. package/engines/specs/obis.yaml +20 -0
  157. package/engines/specs/opencitations.yaml +52 -0
  158. package/engines/specs/openf1.yaml +21 -0
  159. package/engines/specs/openfoodfacts.yaml +45 -0
  160. package/engines/specs/openligadb.yaml +20 -0
  161. package/engines/specs/openreview.yaml +37 -0
  162. package/engines/specs/openstd.yaml +21 -0
  163. package/engines/specs/people_daily.yaml +22 -0
  164. package/engines/specs/realtime_index.yaml +34 -0
  165. package/engines/specs/ror.yaml +20 -0
  166. package/engines/specs/satnogs.yaml +20 -0
  167. package/engines/specs/sec_edgar.yaml +46 -0
  168. package/engines/specs/shfe.yaml +39 -0
  169. package/engines/specs/skillsmp.yaml +50 -0
  170. package/engines/specs/sogou_weixin_browser.yaml +30 -0
  171. package/engines/specs/soilgrids.yaml +25 -0
  172. package/engines/specs/sspai.yaml +36 -0
  173. package/engines/specs/stackexchange.yaml +46 -0
  174. package/engines/specs/std_samr.yaml +21 -0
  175. package/engines/specs/tass.yaml +43 -0
  176. package/engines/specs/tavily_free.yaml +56 -0
  177. package/engines/specs/tle_mirror.yaml +21 -0
  178. package/engines/specs/train.yaml +37 -0
  179. package/engines/specs/tvmaze.yaml +20 -0
  180. package/engines/specs/twitter_syndication.yaml +31 -0
  181. package/engines/specs/un_comtrade.yaml +23 -0
  182. package/engines/specs/unpaywall.yaml +54 -0
  183. package/engines/specs/vnpress.yaml +43 -0
  184. package/engines/specs/weather.yaml +32 -0
  185. package/engines/specs/who_don.yaml +21 -0
  186. package/engines/specs/who_gho.yaml +20 -0
  187. package/engines/specs/wikimedia_commons.yaml +34 -0
  188. package/engines/specs/wikisource.yaml +22 -0
  189. package/engines/specs/worms.yaml +19 -0
  190. package/engines/specs/x_trending.yaml +34 -0
  191. package/engines/specs/yna.yaml +43 -0
  192. package/engines/specs/ynet.yaml +43 -0
  193. package/engines/specs/yuanbao.yaml +93 -0
  194. package/engines/specs/zbmath.yaml +40 -0
  195. package/engines/specs/zdic.yaml +22 -0
  196. package/engines/specs/zenodo.yaml +27 -0
  197. package/engines/specs/zhihu_hot_app.yaml +35 -0
  198. package/mcp/clients.yaml +106 -0
  199. package/package.json +55 -12
  200. package/packages/dsh-plugin/README.md +152 -0
  201. package/packages/dsh-plugin/cordis.patch.yml +48 -0
  202. package/packages/dsh-plugin/dsh/client.js +1533 -0
  203. package/packages/dsh-plugin/dsh/diagnostics.js +54 -0
  204. package/packages/dsh-plugin/dsh/index.js +527 -0
  205. package/packages/dsh-plugin/dsh/native-tools.mjs +749 -0
  206. package/packages/dsh-plugin/dsh/runner.js +666 -0
  207. package/packages/dsh-plugin/dsh/wide-research.js +878 -0
  208. package/packages/dsh-plugin/package.json +38 -0
  209. package/packages/dsh-plugin/scripts/sync-local.sh +70 -0
  210. package/packages/dsh-plugin/test/client.test.js +406 -0
  211. package/packages/dsh-plugin/test/config.test.js +30 -0
  212. package/packages/dsh-plugin/test/diagnostics.test.js +28 -0
  213. package/packages/dsh-plugin/test/index.test.js +1382 -0
  214. package/references/query-templates.md +96 -0
  215. package/references/query-templates.yaml +118 -0
  216. package/scripts/ab_eval.py +219 -0
  217. package/scripts/ab_eval_p0p1.py +266 -0
  218. package/scripts/adaptive.py +294 -70
  219. package/scripts/answer.py +154 -0
  220. package/scripts/archive_run.py +591 -0
  221. package/scripts/argo_engine_registry.py +172 -0
  222. package/scripts/argo_paths.py +728 -0
  223. package/scripts/article.py +136 -0
  224. package/scripts/article_meta.py +131 -0
  225. package/scripts/arxiv_source.py +201 -0
  226. package/scripts/badcase_ledger.py +252 -0
  227. package/scripts/batch_probe.py +241 -0
  228. package/scripts/benchmark.py +19 -0
  229. package/scripts/bounded_run.py +144 -0
  230. package/scripts/browser_auth.py +323 -0
  231. package/scripts/budget.py +247 -0
  232. package/scripts/budget_cli.py +93 -0
  233. package/scripts/build_release_assets.sh +65 -0
  234. package/scripts/burstiness_detector.py +147 -0
  235. package/scripts/cache.py +1066 -67
  236. package/scripts/cache_guard.py +271 -0
  237. package/scripts/cache_key_vdom.py +56 -0
  238. package/scripts/cache_similarity.py +170 -0
  239. package/scripts/caliber_isolation.py +195 -0
  240. package/scripts/calibrate_lowquality.py +210 -0
  241. package/scripts/candidate_envelope.py +366 -0
  242. package/scripts/chrome_cdp.py +871 -0
  243. package/scripts/ci_drift_gate.py +90 -0
  244. package/scripts/circuit_breaker.py +389 -0
  245. package/scripts/citations.py +334 -0
  246. package/scripts/cite_cli.py +59 -0
  247. package/scripts/cjk_tokens.py +95 -0
  248. package/scripts/clarify.py +47 -24
  249. package/scripts/cli_io.py +240 -0
  250. package/scripts/config.py +683 -45
  251. package/scripts/config_cache.py +402 -0
  252. package/scripts/conn_pool.py +220 -0
  253. package/scripts/content_boundary.py +46 -0
  254. package/scripts/content_security.py +685 -0
  255. package/scripts/content_signals.py +751 -0
  256. package/scripts/crawl.py +74 -35
  257. package/scripts/cross_lingual_trace.py +293 -0
  258. package/scripts/daemon.py +866 -0
  259. package/scripts/digup_bridge.py +214 -0
  260. package/scripts/dispatch_result.py +98 -0
  261. package/scripts/engine_admission.py +366 -0
  262. package/scripts/engine_dispatch.py +982 -0
  263. package/scripts/engine_env.py +539 -0
  264. package/scripts/engine_failure.py +411 -0
  265. package/scripts/engine_families.py +738 -0
  266. package/scripts/engine_policy.py +218 -0
  267. package/scripts/engine_requires.py +190 -0
  268. package/scripts/engine_status.py +322 -0
  269. package/scripts/engine_validate.py +638 -0
  270. package/scripts/engines.py +799 -294
  271. package/scripts/engines_base.py +1521 -0
  272. package/scripts/engines_builders.py +310 -0
  273. package/scripts/engines_builders_batch10.py +204 -0
  274. package/scripts/engines_builders_batch11.py +174 -0
  275. package/scripts/engines_builders_batch12.py +103 -0
  276. package/scripts/engines_builders_batch13.py +340 -0
  277. package/scripts/engines_builders_batch14.py +656 -0
  278. package/scripts/engines_builders_batch15.py +249 -0
  279. package/scripts/engines_builders_batch9.py +1468 -0
  280. package/scripts/engines_builders_cn.py +2283 -0
  281. package/scripts/engines_builders_data.py +2923 -0
  282. package/scripts/engines_builders_data_macro.py +775 -0
  283. package/scripts/engines_builders_feeds.py +255 -0
  284. package/scripts/engines_builders_intl.py +1239 -0
  285. package/scripts/engines_builders_keyless.py +111 -0
  286. package/scripts/engines_builders_search.py +440 -0
  287. package/scripts/engines_builders_tech.py +1359 -0
  288. package/scripts/evidence.py +620 -166
  289. package/scripts/evidence_loop.py +624 -0
  290. package/scripts/evidence_tier.py +298 -0
  291. package/scripts/except_sets.py +25 -0
  292. package/scripts/extract.py +55 -16
  293. package/scripts/fact_align.py +207 -0
  294. package/scripts/fact_crosscheck.py +230 -0
  295. package/scripts/fetch.py +25 -12
  296. package/scripts/fetch_browser.py +87 -0
  297. package/scripts/fetch_jsrun.py +122 -0
  298. package/scripts/fetch_quality.py +225 -0
  299. package/scripts/fetch_render_tinyfish.py +117 -0
  300. package/scripts/fetch_v3.py +1804 -0
  301. package/scripts/focus_extract.py +350 -0
  302. package/scripts/fulltext_store.py +169 -0
  303. package/scripts/fxtwitter_api.py +325 -0
  304. package/scripts/gen_engine_catalog.py +364 -0
  305. package/scripts/gen_native_tools.py +91 -0
  306. package/scripts/gen_routing_snapshot.py +195 -0
  307. package/scripts/health_check.py +140 -402
  308. package/scripts/health_probe.py +23 -8
  309. package/scripts/hot_state.py +134 -0
  310. package/scripts/http_client.py +1053 -0
  311. package/scripts/image_ops.py +430 -0
  312. package/scripts/image_vision/vision_probe.swift +126 -0
  313. package/scripts/install.ps1 +166 -0
  314. package/scripts/install.sh +221 -0
  315. package/scripts/job.py +1186 -0
  316. package/scripts/jump_resolver.py +235 -0
  317. package/scripts/lang_capability.py +150 -0
  318. package/scripts/lang_detect.py +289 -0
  319. package/scripts/lang_matrix_probe.py +329 -0
  320. package/scripts/lang_pref.py +311 -0
  321. package/scripts/link_source.py +340 -0
  322. package/scripts/local_image.py +970 -0
  323. package/scripts/local_seek.py +402 -0
  324. package/scripts/macro_countries.py +97 -0
  325. package/scripts/matrix_search_eval.py +1187 -0
  326. package/scripts/mcp_compact.py +234 -0
  327. package/scripts/mcp_diag.py +8 -3
  328. package/scripts/mcp_handlers.py +492 -0
  329. package/scripts/mcp_handlers_surface.py +157 -0
  330. package/scripts/mcp_launch.sh +124 -0
  331. package/scripts/mcp_local.py +241 -0
  332. package/scripts/mcp_server.py +125 -419
  333. package/scripts/mcp_setup.py +431 -0
  334. package/scripts/mcp_tools.py +331 -0
  335. package/scripts/mcp_transport.py +191 -0
  336. package/scripts/mcp_warm.py +127 -0
  337. package/scripts/min_version_scan.py +335 -0
  338. package/scripts/net_proxy.py +258 -0
  339. package/scripts/network_aware.py +152 -0
  340. package/scripts/output_transparency.py +200 -0
  341. package/scripts/paid_policy.py +98 -0
  342. package/scripts/paper.py +274 -0
  343. package/scripts/pdf_extract.py +518 -0
  344. package/scripts/phrase_filter.py +66 -0
  345. package/scripts/plan.py +422 -0
  346. package/scripts/postprocess_signals.py +150 -0
  347. package/scripts/pre-commit +48 -0
  348. package/scripts/query_enhance.py +157 -0
  349. package/scripts/query_operators.py +196 -0
  350. package/scripts/query_rewriter.py +116 -7
  351. package/scripts/query_signals.py +300 -0
  352. package/scripts/query_templates.py +167 -0
  353. package/scripts/query_understanding.py +411 -0
  354. package/scripts/query_variants.py +298 -0
  355. package/scripts/quota.py +633 -76
  356. package/scripts/rank_signals.py +775 -0
  357. package/scripts/ranking_eval.py +319 -0
  358. package/scripts/readability_extract.py +433 -0
  359. package/scripts/recompute.py +415 -0
  360. package/scripts/recovery.py +616 -0
  361. package/scripts/recovery_l0.py +160 -0
  362. package/scripts/recovery_runner.py +150 -0
  363. package/scripts/redskill/redskill_engine.py +332 -0
  364. package/scripts/regression_p0p1.py +318 -0
  365. package/scripts/replay_eval.py +658 -0
  366. package/scripts/rerank_tfidf.py +225 -0
  367. package/scripts/research.py +607 -403
  368. package/scripts/research_cli.py +361 -0
  369. package/scripts/research_dossier.py +492 -0
  370. package/scripts/research_expand.py +169 -0
  371. package/scripts/research_gates.py +272 -0
  372. package/scripts/research_report.py +209 -0
  373. package/scripts/research_strategy.py +37 -0
  374. package/scripts/research_work_packages.py +195 -0
  375. package/scripts/result_lang.py +311 -0
  376. package/scripts/retry_policy.py +76 -0
  377. package/scripts/robots_guard.py +259 -0
  378. package/scripts/route.py +921 -254
  379. package/scripts/route_bangs.py +40 -0
  380. package/scripts/route_cache.py +243 -0
  381. package/scripts/route_combo.py +917 -0
  382. package/scripts/route_domains.py +341 -0
  383. package/scripts/route_lang.py +605 -0
  384. package/scripts/route_log.py +63 -0
  385. package/scripts/route_policy.py +250 -0
  386. package/scripts/rrf_classic.py +66 -0
  387. package/scripts/screenshot.py +73 -0
  388. package/scripts/search.py +886 -406
  389. package/scripts/search_attribution.py +185 -0
  390. package/scripts/search_benchmark.py +407 -0
  391. package/scripts/search_cli.py +640 -0
  392. package/scripts/search_entry.py +395 -0
  393. package/scripts/search_output.py +690 -0
  394. package/scripts/search_pipeline.py +926 -0
  395. package/scripts/search_rank.py +991 -0
  396. package/scripts/search_types.py +129 -16
  397. package/scripts/seek_locator.py +68 -0
  398. package/scripts/semantic_evidence.py +391 -0
  399. package/scripts/serp_guard.py +336 -0
  400. package/scripts/serp_kill_log.py +74 -0
  401. package/scripts/single_flight.py +120 -0
  402. package/scripts/social_engines/__init__.py +10 -0
  403. package/scripts/social_engines/bilibili_engine.py +131 -0
  404. package/scripts/social_engines/hackernews_engine.py +113 -0
  405. package/scripts/social_engines/reddit_engine.py +172 -0
  406. package/scripts/social_engines/twitter_engine.py +397 -0
  407. package/scripts/social_engines/v2ex_engine.py +101 -0
  408. package/scripts/social_engines/weibo_engine.py +128 -0
  409. package/scripts/social_engines/xiaohongshu_engine.py +137 -0
  410. package/scripts/social_engines/zhihu_engine.py +139 -0
  411. package/scripts/social_research.py +201 -0
  412. package/scripts/sogou_weixin_browser.py +318 -0
  413. package/scripts/source_ledger.py +249 -0
  414. package/scripts/stage_timing.py +58 -0
  415. package/scripts/stats_cli.py +107 -0
  416. package/scripts/straggler_policy.py +60 -0
  417. package/scripts/stylometry_detector.py +231 -0
  418. package/scripts/sync_backends.py +353 -0
  419. package/scripts/sync_installs.py +29 -0
  420. package/scripts/template_cli.py +127 -0
  421. package/scripts/text_lexicon.py +72 -0
  422. package/scripts/tfidf_router.py +109 -37
  423. package/scripts/time_utils.py +233 -0
  424. package/scripts/topic_research_profiles.py +643 -0
  425. package/scripts/train.py +737 -0
  426. package/scripts/tweet.py +596 -0
  427. package/scripts/url_canon.py +217 -0
  428. package/scripts/url_optimize.py +56 -0
  429. package/scripts/url_safety.py +236 -0
  430. package/scripts/usage_log.py +116 -0
  431. package/scripts/usage_log_clean.py +113 -0
  432. package/scripts/v2ex_nodes.py +311 -0
  433. package/scripts/variant_recall.py +188 -0
  434. package/scripts/watch.py +205 -0
  435. package/scripts/wechat_article.py +258 -0
  436. package/scripts/wide_research.py +447 -0
  437. package/scripts/wx.py +349 -0
  438. package/scripts/x_article_fetch.py +141 -0
  439. package/scripts/x_search.py +234 -0
  440. package/scripts/x_trending.py +189 -0
  441. package/scripts/yaml_load.py +67 -0
  442. package/scripts/zhihu_quota.py +139 -0
  443. package/sub-skills/ego-search/SKILL.md +253 -0
  444. package/sub-skills/ego-search/scripts/ego_search.py +800 -0
  445. package/sub-skills/ego-search/scripts/merge.py +226 -0
  446. package/sub-skills/ego-search/scripts/quality.py +64 -0
  447. package/sub-skills/ego-search/scripts/runtime.py +172 -0
  448. package/sub-skills/ego-search/scripts/safety.py +109 -0
  449. package/sub-skills/ego-search/scripts/serp_spec.py +109 -0
  450. package/sub-skills/ego-search/scripts/webbridge_adapter.py +374 -0
  451. package/sub-skills/js-run/SKILL.md +67 -0
  452. package/sub-skills/js-run/scripts/jsrun.py +112 -0
  453. package/sub-skills/js-run/scripts/shim.js +188 -0
  454. package/sub-skills/local-search/SKILL.md +50 -53
  455. package/sub-skills/local-search/bm25.py +186 -0
  456. package/sub-skills/local-search/cli_runner.py +331 -0
  457. package/sub-skills/local-search/config.yaml +152 -55
  458. package/sub-skills/local-search/engine_registry.py +91 -26
  459. package/sub-skills/local-search/{health_check.py → local_health_check.py} +140 -10
  460. package/sub-skills/local-search/local_search_adapter.py +13 -2
  461. package/sub-skills/local-search/parse_maps.yaml +40 -42
  462. package/sub-skills/local-search/parsers.py +328 -0
  463. package/sub-skills/local-search/search_v3.py +716 -242
  464. package/sub-skills/local-search/smart_router.py +47 -7
  465. package/sub-skills/local-seek/SKILL.md +110 -0
  466. package/sub-skills/local-seek/config/domains.yaml +20 -0
  467. package/sub-skills/local-seek/scripts/eval_rank.py +216 -0
  468. package/sub-skills/local-seek/scripts/eval_seek.py +224 -0
  469. package/sub-skills/local-seek/scripts/seek.py +1465 -0
  470. package/sub-skills/local-seek/scripts/seek_frecency.py +126 -0
  471. package/sub-skills/local-seek/scripts/seek_fts.py +430 -0
  472. package/sub-skills/local-seek/scripts/seek_rank.py +197 -0
@@ -0,0 +1,331 @@
1
+ #!/usr/bin/env python3
2
+ """mcp_tools.py — MCP 工具 schema 唯一来源(P2-4 拆分自 mcp_server.py)。
3
+
4
+ 工具数以 len(TOOLS) 为唯一事实(2026-09-26 起 19 个,与 CLI 能力面对齐:
5
+ extract/preflight/answer/watch/cite 补齐);mcp_transport 的 tools/list 与
6
+ mcp_server 的兼容导出均从本模块取。改 schema 只动这一个文件。
7
+
8
+ tools/list 默认只注入 CORE 三件套(search/fetch/local_search,约 3.6KB/轮);
9
+ 全量设 ARGO_MCP_TOOLS=all。execute_tool / --call / DSH 原生规格仍吃全量 TOOLS,
10
+ 能力不删。未知名单不回退成全量(同类:过滤失败吐全量)。
11
+
12
+ schema 设计原则(质量第一,token 第二):
13
+ - 工具 description:第一句「做什么」,第二句「何时用 / 关键注意」。
14
+ 删除内部实现机制(引擎数、TF-IDF/RRF、协议文件引用)——模型不靠这些决策。
15
+ - 参数 description:语义 + 何时用。默认值由 schema 的 default 字段表达,
16
+ 不在 description 里重复;删除「下推到引擎」类实现细节。
17
+ - 调试/运行配置(pretty / skip_cache / timeout)不暴露给模型:
18
+ 这些不是模型决策输入,由 server 层环境变量接管(见 mcp_handlers.execute_tool:
19
+ ARGO_MCP_PRETTY / ARGO_MCP_SKIP_CACHE / ARGO_MCP_TIMEOUT[_CRAWL|_FETCH])。
20
+ 功能参数全部保留,质量不受影响。
21
+ """
22
+
23
+ from __future__ import annotations
24
+
25
+ import os
26
+
27
+ # 日常 90% 调用只需要这 3 个;顺序即 tools/list 默认顺序。
28
+ CORE_TOOL_NAMES = ("argo_search", "argo_fetch", "argo_local_search")
29
+
30
+ TOOLS = [
31
+ {
32
+ "name": "argo_search",
33
+ "description": "统一网络搜索:多引擎融合、支持时间过滤与域名过滤,返回带来源与摘要的结果。查资料、找答案、搜新闻/学术/代码/多语言内容等通用场景的首选工具。",
34
+ "inputSchema": {
35
+ "type": "object",
36
+ "properties": {
37
+ "query": {"type": "string", "description": "搜索查询词"},
38
+ "engine": {"type": "string", "description": "指定搜索引擎(auto 自动选择;可选 octen/anysearch/exa/zhihu/eastmoney/arxiv/byted/bocha/tavily/deepseek_search/github/wikipedia/semantic_scholar/local_search 等;deepseek_search 为按次计费的官方 DeepSeek 搜索,结果带权威分级与发布时间,新闻时事类查询优先考虑)", "default": "auto"},
39
+ "max_results": {"type": "integer", "description": "返回结果条数", "default": 5, "minimum": 1, "maximum": 20},
40
+ "depth": {"type": "string", "enum": ["fast", "balanced", "deep"], "description": "搜索深度:fast 快、deep 全(慢)", "default": "fast"},
41
+ "mode": {"type": "string", "enum": ["fast", "auto", "deep", "budget"], "description": "预算模式:fast=免费优先, auto=成本感知, deep=质量优先, budget=配额控制", "default": "auto"},
42
+ "since": {"type": "string", "description": "发布时间下限,如 7d / 2026-08-01"},
43
+ "until": {"type": "string", "description": "发布时间上限,如 7d / 2026-08-01"},
44
+ "sort": {"type": "string", "enum": ["relevance", "oldest", "newest"], "description": "排序:relevance=相关度, oldest=最早在前, newest=最新在前", "default": "relevance"},
45
+ "include_domains": {"type": "array", "items": {"type": "string"}, "description": "仅保留这些域名(含子域),如 [\"github.com\"]", "default": []},
46
+ "exclude_domains": {"type": "array", "items": {"type": "string"}, "description": "排除这些域名(含子域),如 [\"pinterest.com\"]", "default": []},
47
+ "include_local": {"type": "boolean", "description": "并入本机文件命中(seek 结果尾部,source=local_files,不参与融合评分;默认开)", "default": True},
48
+ "summary": {"type": "boolean", "description": "精简输出:截断摘要、去掉重字段,省 token", "default": True},
49
+ },
50
+ "required": ["query"],
51
+ },
52
+ },
53
+ {
54
+ "name": "argo_local_search",
55
+ "description": "本机文件/笔记/代码搜索(非联网):返回文件路径与行号。搜本地资料时用,与网络搜索互补。",
56
+ "inputSchema": {
57
+ "type": "object",
58
+ "properties": {
59
+ "query": {"type": "string", "description": "搜索查询词(中文自动扩展召回)"},
60
+ "path": {"type": "string", "description": "搜索目录;缩小范围更快更准", "default": "~"},
61
+ "max_results": {"type": "integer", "description": "返回结果条数", "default": 5, "minimum": 1, "maximum": 20},
62
+ "exact": {"type": "boolean", "description": "精确匹配,关闭中文扩展", "default": False},
63
+ },
64
+ "required": ["query"],
65
+ },
66
+ },
67
+ {
68
+ "name": "argo_local_read",
69
+ "description": "读取白名单内的本地文本文件(预览,非全文):用于分析本地数据/笔记/研究成果。白名单目录由 ARGO_LOCAL_READ_DIRS 配置(逗号分隔),未配置或路径越权时拒绝(默认拒绝)。",
70
+ "inputSchema": {
71
+ "type": "object",
72
+ "properties": {
73
+ "path": {"type": "string", "description": "文件路径(必须位于白名单目录内)"},
74
+ "max_chars": {"type": "integer", "description": "预览字符数上限", "default": 4000, "minimum": 200, "maximum": 20000},
75
+ "line_start": {"type": "integer", "description": "起始行号(1 基,可选)", "minimum": 1},
76
+ "line_end": {"type": "integer", "description": "结束行号(可选)"},
77
+ },
78
+ "required": ["path"],
79
+ },
80
+ },
81
+ {
82
+ "name": "argo_recompute",
83
+ "description": "可复算执行器(默认拒绝):在受限子进程中运行计算脚本(只读白名单输入、断网、超时硬杀、内存软限),验证本地数据重算出的数值。用于结论承重要重算数字时;默认拒绝,需显式授权。",
84
+ "inputSchema": {
85
+ "type": "object",
86
+ "properties": {
87
+ "script": {"type": "string", "description": "要运行的计算代码(Python)"},
88
+ "file_inputs": {"type": "string", "description": "白名单输入文件 JSON 数组:[{\"path\":\"...\",\"role\":\"原始数据\"}]"},
89
+ "timeout_s": {"type": "integer", "description": "超时秒数", "default": 30, "minimum": 1, "maximum": 120},
90
+ "max_mem_mb": {"type": "integer", "description": "内存上限 MB(尽力而为)", "default": 512},
91
+ "allow_exec": {"type": "boolean", "description": "是否授权运行(不授权就不执行;未授权时返回 skipped_reason)", "default": False},
92
+ },
93
+ "required": ["script"],
94
+ },
95
+ },
96
+ {
97
+ "name": "argo_research",
98
+ "description": "深度研究取证:多子查询并行检索,返回带来源/覆盖/缺口/质量门禁的 dossier。适合复杂、多步骤、需要交叉验证的研究问题;简单快问用 argo_search。",
99
+ "inputSchema": {
100
+ "type": "object",
101
+ "properties": {
102
+ "query": {"type": "string", "description": "研究问题(可以是复杂、多步骤的)"},
103
+ "topic": {"type": "string", "description": "选题 profile:ai/investment/finance/academic/tech/tool/internet/social;省略则自动推断"},
104
+ "auto_topic": {"type": "boolean", "description": "无 topic 时是否自动推断", "default": True},
105
+ "num_sub_queries": {"type": "integer", "description": "子查询数量;有 work_packages 时忽略", "minimum": 2, "maximum": 8},
106
+ "max_results": {"type": "integer", "description": "每个子查询的结果条数", "default": 5},
107
+ "depth": {"type": "string", "enum": ["fast", "balanced", "deep"], "description": "搜索深度", "default": "balanced"},
108
+ "mode": {"type": "string", "enum": ["fast", "auto", "deep", "budget", "social-sentiment"], "description": "预算/模式;社交舆情用 social-sentiment", "default": "auto"},
109
+ "work_packages": {"type": "string", "description": "工作包 JSON 数组:id, question, query?, file_inputs?(本地一手数据, 白名单制), recompute?({script,budget{timeout_s,max_mem_mb}}), depends_on?。有则跳过扩词,按依赖分阶段取证"},
110
+ "allow_recompute": {"type": "boolean", "description": "授权执行工作包 recompute 计算脚本(不授权就不执行;未授权时 recompute 跳过并触发 recompute_skipped 门禁)", "default": False},
111
+ "platforms": {"type": "string", "description": "social-sentiment 平台列表,逗号分隔"},
112
+ "summary": {"type": "boolean", "description": "精简研究包,省 token", "default": True},
113
+ },
114
+ "required": ["query"],
115
+ },
116
+ },
117
+ {
118
+ "name": "argo_evidence",
119
+ "description": "来源可信度评估:对搜索结果做权威性+时效性+交叉验证评分,输出逐条可信度分解。用于事实核查、高后果决策、学术引用。",
120
+ "inputSchema": {
121
+ "type": "object",
122
+ "properties": {
123
+ "query": {"type": "string", "description": "搜索查询词(用于交叉验证)"},
124
+ "results_json": {"type": "string", "description": "待评估的搜索结果 JSON(为空时自动搜索)。格式:{\"results\": [{\"title\":\"...\",\"url\":\"...\",\"snippet\":\"...\",\"source\":\"...\",\"score\":0.8}]}"},
125
+ "max_results": {"type": "integer", "description": "自动搜索时的结果条数", "default": 10},
126
+ },
127
+ "required": ["query"],
128
+ },
129
+ },
130
+ {
131
+ "name": "argo_clarify",
132
+ "description": "意图消歧:识别查询中的歧义词与多义实体,给出意图分类与推荐搜索策略。查询含歧义词(苹果=公司/水果)或意图不明时用。",
133
+ "inputSchema": {
134
+ "type": "object",
135
+ "properties": {
136
+ "query": {"type": "string", "description": "需要消歧的查询"},
137
+ },
138
+ "required": ["query"],
139
+ },
140
+ },
141
+ {
142
+ "name": "argo_crawl",
143
+ "description": "站点级爬取:按 sitemap 或 BFS 批量抓取整站页面,返回 URL、正文片段与深度。适合整站内容审计、站内多页对比。",
144
+ "inputSchema": {
145
+ "type": "object",
146
+ "properties": {
147
+ "url": {"type": "string", "description": "站点根 URL"},
148
+ "strategy": {"type": "string", "enum": ["sitemap", "bfs"], "description": "爬取策略", "default": "bfs"},
149
+ "max_pages": {"type": "integer", "description": "最大抓取页数", "default": 10, "minimum": 1, "maximum": 50},
150
+ "max_depth": {"type": "integer", "description": "BFS 最大深度", "default": 2, "minimum": 1, "maximum": 5},
151
+ },
152
+ "required": ["url"],
153
+ },
154
+ },
155
+ {
156
+ "name": "argo_fetch",
157
+ "description": "智能页面抓取:HTTP 优先,遇 Cloudflare/JS 渲染自动升级反检测浏览器。支持 BM25 聚焦提取(focus 省 80%+ token)与结构化提取(mode=extract 抽表格/元数据/JSON-LD)。",
158
+ "inputSchema": {
159
+ "type": "object",
160
+ "properties": {
161
+ "url": {"type": "string", "description": "目标 URL"},
162
+ "mode": {"type": "string", "enum": ["text", "extract"], "description": "text=正文/聚焦文本, extract=结构化提取", "default": "text"},
163
+ "extract_mode": {"type": "string", "enum": ["tables", "metadata", "jsonld", "all"], "description": "mode=extract 时的提取子模式", "default": "all"},
164
+ "focus": {"type": "string", "description": "BM25 聚焦查询词:只返回相关段落,省 token(仅 mode=text)"},
165
+ "max_chars": {"type": "integer", "description": "返回正文最大字符数", "default": 8000, "minimum": 500, "maximum": 50000},
166
+ "use_browser": {"type": "boolean", "description": "强制用反检测浏览器(HTTP 失败时已自动升级)", "default": False},
167
+ "include_links": {"type": "boolean", "description": "附带正文内链接(最多 30 条;默认只回 links_count,省 token)", "default": False},
168
+ },
169
+ "required": ["url"],
170
+ },
171
+ },
172
+ {
173
+ "name": "argo_screenshot",
174
+ "description": "网页截图(PNG):分析页面布局、验证渲染结果、存档快照。支持全页与视口截图。",
175
+ "inputSchema": {
176
+ "type": "object",
177
+ "properties": {
178
+ "url": {"type": "string", "description": "目标 URL"},
179
+ "full_page": {"type": "boolean", "description": "全页截图(默认仅当前视口)", "default": False},
180
+ "output_path": {"type": "string", "description": "输出路径(默认写入系统临时目录:<temp>/argo_screenshot_<timestamp>.png)"},
181
+ },
182
+ "required": ["url"],
183
+ },
184
+ },
185
+ {
186
+ "name": "argo_pdf",
187
+ "description": "PDF 结构化提取:转为 Markdown(含表格、目录、元数据),支持 URL 下载与本地文件。",
188
+ "inputSchema": {
189
+ "type": "object",
190
+ "properties": {
191
+ "url": {"type": "string", "description": "PDF URL 或本地文件路径"},
192
+ "pages": {"type": "string", "description": "页码范围,如 \"1-5\" 或 \"1,3,5\"(默认全部)"},
193
+ "password": {"type": "string", "description": "加密 PDF 密码"},
194
+ },
195
+ "required": ["url"],
196
+ },
197
+ },
198
+ {
199
+ "name": "argo_social_search",
200
+ "description": "社交平台搜索:知乎、Hacker News、B站、V2EX、Twitter/X、Reddit、小红书、微博等 UGC 内容。mode=sentiment 输出舆情聚合。注意:hackernews/v2ex/zhihu/bilibili 零密钥可用;twitter/reddit/weibo/xiaohongshu 依赖登录态或第三方 API,可能返回空。",
201
+ "inputSchema": {
202
+ "type": "object",
203
+ "properties": {
204
+ "query": {"type": "string", "description": "搜索查询词"},
205
+ "mode": {"type": "string", "enum": ["text", "sentiment"], "description": "text=帖子列表, sentiment=舆情聚合分析", "default": "text"},
206
+ "platforms": {"type": "string", "description": "平台列表,逗号分隔;可选 hackernews,v2ex,zhihu,bilibili,twitter,reddit,xiaohongshu,weibo", "default": "hackernews,zhihu,bilibili"},
207
+ "max_results": {"type": "integer", "description": "每个平台的结果条数", "default": 5, "minimum": 1, "maximum": 20},
208
+ },
209
+ "required": ["query"],
210
+ },
211
+ },
212
+ {
213
+ "name": "argo_article",
214
+ "description": "微信公众号文章全文抓取:标题/作者/发布时间/正文纯文本/图片列表。仅支持 mp.weixin.qq.com 链接;要读公众号文章全文时用(普通网页走 argo_fetch)。",
215
+ "inputSchema": {
216
+ "type": "object",
217
+ "properties": {
218
+ "url": {"type": "string", "description": "mp.weixin.qq.com 文章链接"},
219
+ "max_chars": {"type": "integer", "description": "返回正文最大字符数", "default": 20000, "minimum": 500, "maximum": 50000},
220
+ },
221
+ "required": ["url"],
222
+ },
223
+ },
224
+ {
225
+ "name": "argo_job",
226
+ "description": "招聘岗位多平台聚合:BOSS直聘/猎聘/智联/前程无忧/597/今日招聘,职位+地区并发搜索,三级地区命中判定+结构化字段(薪资/学历/经验)+跨平台去重。招聘市场调研时用。",
227
+ "inputSchema": {
228
+ "type": "object",
229
+ "properties": {
230
+ "query": {"type": "string", "description": "职位关键词,如:工艺工程师、会计、电工"},
231
+ "city": {"type": "string", "description": "地区:省/市/县或海外城市(成都、昆山、新加坡…),空=不过滤地区"},
232
+ "num": {"type": "integer", "description": "每后端条数", "default": 5, "minimum": 1, "maximum": 20},
233
+ "platforms": {"type": "string", "description": "逗号分隔平台: zhipin,liepin,zhaopin,51job,597,jrzp;空=全部", "default": ""},
234
+ "loose": {"type": "boolean", "description": "宽松:异地岗位也保留;默认严格地区过滤", "default": False},
235
+ "fetch_detail": {"type": "integer", "description": "对前 N 条高命中结果抓详情页补全结构化字段(0=仅 snippet 提取)", "default": 0, "minimum": 0, "maximum": 10},
236
+ },
237
+ "required": ["query"],
238
+ },
239
+ },
240
+ {
241
+ "name": "argo_extract",
242
+ "description": "网页结构化提取:表格、Meta 元数据(og:/description)、JSON-LD 结构化数据。要拿页面的表格数据或结构化字段时用;正文通读走 argo_fetch。",
243
+ "inputSchema": {
244
+ "type": "object",
245
+ "properties": {
246
+ "url": {"type": "string", "description": "目标网页链接"},
247
+ "mode": {"type": "string", "enum": ["tables", "metadata", "jsonld", "all"], "description": "提取内容:tables=HTML表格, metadata=Meta元数据, jsonld=JSON-LD, all=全部", "default": "all"},
248
+ "max_chars": {"type": "integer", "description": "抓取页面最大字符数", "default": 50000, "minimum": 1000, "maximum": 200000},
249
+ },
250
+ "required": ["url"],
251
+ },
252
+ },
253
+ {
254
+ "name": "argo_preflight",
255
+ "description": "批量 URL 预检:把候选链接分类为可用/登录墙/已失效/需联网确认,probe 开启时实测存活。引用或抓取一批来源前先过一遍,避免把死链和登录墙当信源。",
256
+ "inputSchema": {
257
+ "type": "object",
258
+ "properties": {
259
+ "urls": {"type": "array", "items": {"type": "string"}, "description": "待预检的 URL 列表", "minItems": 1},
260
+ "probe": {"type": "boolean", "description": "联网探测存活(404/410 判死;默认纯本地规则)", "default": False},
261
+ },
262
+ "required": ["urls"],
263
+ },
264
+ },
265
+ {
266
+ "name": "argo_answer",
267
+ "description": "直答:对事实型问题返回带引用的合成答案与置信口径。要一句话答案而非链接列表时用;开放式调研走 argo_research。",
268
+ "inputSchema": {
269
+ "type": "object",
270
+ "properties": {
271
+ "query": {"type": "string", "description": "要回答的问题"},
272
+ "scope": {"type": "string", "description": "答案域(如 news);空=默认"},
273
+ "model": {"type": "string", "description": "答案模型;空=默认"},
274
+ },
275
+ "required": ["query"],
276
+ },
277
+ },
278
+ {
279
+ "name": "argo_watch",
280
+ "description": "网页变化监控:对关注页面做快照并在复查时报告变化。add 登记关注、check 复查变化、list 看清单、remove 取消;适合盯价格/公告/版本发布页。",
281
+ "inputSchema": {
282
+ "type": "object",
283
+ "properties": {
284
+ "action": {"type": "string", "enum": ["add", "check", "list", "remove"], "description": "add=登记快照, check=复查变化(可指定单个 url), list=看清单, remove=取消关注"},
285
+ "url": {"type": "string", "description": "目标页面(add/remove 必填;check 可选=只查这一条)"},
286
+ "note": {"type": "string", "description": "备注(add 可选)", "default": ""},
287
+ },
288
+ "required": ["action"],
289
+ },
290
+ },
291
+ {
292
+ "name": "argo_cite",
293
+ "description": "DOI → 引用条目:GB/T 7714 / 顺序编码 / APA / BibTeX 四格式,Crossref+OpenAlex 免 key。论文引用、参考文献列表生成时用。",
294
+ "inputSchema": {
295
+ "type": "object",
296
+ "properties": {
297
+ "dois": {"type": "array", "items": {"type": "string"}, "description": "DOI 列表,如 [\"10.1038/s41586-024-0001-x\"]", "minItems": 1},
298
+ "style": {"type": "string", "enum": ["gbt7714", "numeric", "apa", "bibtex"], "description": "引用格式", "default": "gbt7714"},
299
+ },
300
+ "required": ["dois"],
301
+ },
302
+ },
303
+ ]
304
+
305
+
306
+ def listed_tools(spec: str | None = None) -> list[dict]:
307
+ """tools/list 返回集。默认 CORE 三件套;all 全量;逗号名单按名取。
308
+
309
+ 未知名字忽略,空结果也不回退成全量——曾经「过滤失败吐全量」把 12KB
310
+ schema 砸进每一轮。execute_tool 不受此限制。
311
+ """
312
+ raw = spec if spec is not None else os.environ.get("ARGO_MCP_TOOLS", "")
313
+ raw = (raw or "").strip().lower()
314
+ by_name = {t["name"]: t for t in TOOLS}
315
+ if raw in ("", "core", "default"):
316
+ return [by_name[n] for n in CORE_TOOL_NAMES if n in by_name]
317
+ if raw in ("all", "*"):
318
+ return list(TOOLS)
319
+ out: list[dict] = []
320
+ seen: set[str] = set()
321
+ for part in raw.split(","):
322
+ name = part.strip()
323
+ if not name:
324
+ continue
325
+ key = name if name in by_name else (
326
+ f"argo_{name}" if f"argo_{name}" in by_name else None
327
+ )
328
+ if key and key not in seen:
329
+ out.append(by_name[key])
330
+ seen.add(key)
331
+ return out
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/env python3
2
+ """mcp_transport.py — MCP JSON-RPC 分发 + stdio 帧协议(P2-4 拆分自 mcp_server.py)。
3
+
4
+ handle_rpc 按方法分发(initialize / tools/list / tools/call / ping);
5
+ run_stdio 支持 Content-Length 帧与 NDJSON 两种输入格式。
6
+ 工具 schema 在 mcp_tools.py,执行逻辑在 mcp_handlers.py。
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import json
12
+ import sys
13
+ from typing import Any
14
+
15
+ from mcp_handlers import _warm_core_async, execute_tool
16
+ from mcp_tools import listed_tools
17
+
18
+ try:
19
+ import hot_state # 代码/配置指纹自重启(失效则退化为旧行为:进程常驻)
20
+ except Exception: # pragma: no cover
21
+ hot_state = None # type: ignore[assignment]
22
+
23
+ # 版本来源:与 package.json / SKILL.md 保持一致(发布时统一升版;
24
+ # tests/test_consistency_gates.py 会四端对账,漂移即红)
25
+ ARGO_MCP_VERSION = "2.9.8"
26
+
27
+ _response_format = "content-length" # 根据客户端请求自动切换
28
+
29
+
30
+ def handle_rpc(method: str, params: dict[str, Any]) -> dict[str, Any]:
31
+ """处理 JSON-RPC 请求。"""
32
+ if method == "initialize":
33
+ _warm_core_async()
34
+ return {
35
+ "protocolVersion": "2025-06-18",
36
+ "capabilities": {"tools": {"listChanged": False}},
37
+ "serverInfo": {
38
+ "name": "argo",
39
+ "version": ARGO_MCP_VERSION
40
+ },
41
+ # 短指令:降 tools 上下文;细节在 tool schema。
42
+ # URL 在 results[].url(默认 envelope=False,不生成 sources)。
43
+ "instructions": (
44
+ "Argo:日常 argo_search(精简 JSON,URL 在 results[].url)"
45
+ "、argo_fetch、argo_local_search。"
46
+ "深度研究只用 argo_research(内建 academic/finance topic,不调用外部 skill)。"
47
+ "其余默认不注入 schema,ARGO_MCP_TOOLS=all 打开:"
48
+ "evidence/clarify/crawl/article/job/pdf/screenshot/social_search/"
49
+ "local_read/recompute。"
50
+ ),
51
+ }
52
+
53
+ elif method == "tools/list":
54
+ _warm_core_async()
55
+ return {"tools": listed_tools()}
56
+
57
+ elif method == "tools/call":
58
+ tool_name = params.get("name", "")
59
+ arguments = params.get("arguments")
60
+ if not isinstance(arguments, dict):
61
+ # 宿主可能发 "arguments": null / 字符串(实测:AttributeError 逃到
62
+ # run_stdio 兜底 except,响应 -32000 且 id 打成 null,宿主无法
63
+ # 对账)。MCP 规范里 arguments 是 object,畸形一律按空对象走
64
+ # 正常缺参校验。
65
+ arguments = {}
66
+ return execute_tool(tool_name, arguments)
67
+
68
+ elif method == "ping":
69
+ return {}
70
+
71
+ elif method.startswith("notifications/"):
72
+ # 通知消息无需回复
73
+ return None
74
+
75
+ else:
76
+ return {"error": {"code": -32601, "message": f"Method not found: {method}"}}
77
+
78
+
79
+ def run_stdio():
80
+ """运行 MCP stdio 服务。MCP 帧协议:Content-Length: N\\r\\n\\r\\n{json}"""
81
+ import sys, os, time as _time
82
+
83
+ global _response_format
84
+
85
+ sys.stderr.write("[argo-mcp] ready, waiting for stdin\n")
86
+ sys.stderr.flush()
87
+
88
+ while True:
89
+ # 每轮先归零:兜底 except 发错误响应时带本轮 id——若沿用上一轮残值,
90
+ # 会把错误对账到不相干的请求上(解析失败轮则保持 null)
91
+ request_id = None
92
+ try:
93
+ # 代码/配置热生效:循环顶部 = 上一个响应已 flush、无在途工作,
94
+ # 此刻 execv 最安全。stdio fd 跨 exec 继承,客户端连接不断;
95
+ # 磁盘状态(quota/熔断/缓存)天然存活。
96
+ if hot_state is not None and hot_state.should_reload():
97
+ sys.stderr.write("[argo-mcp] fingerprint changed → self-exec reload\n")
98
+ sys.stderr.flush()
99
+ if hot_state.self_exec():
100
+ continue
101
+
102
+ # 读取 Content-Length 头
103
+ header = sys.stdin.buffer.readline()
104
+ if not header:
105
+ sys.stderr.write("[argo-mcp] EOF on stdin, exiting\n")
106
+ sys.stderr.flush()
107
+ break # EOF
108
+ header_str = header.decode("utf-8", errors="replace").strip()
109
+ if not header_str:
110
+ continue
111
+ if not header_str.startswith("Content-Length:"):
112
+ # NDJSON 格式(Kimix 等)
113
+ _response_format = "ndjson"
114
+ try:
115
+ request = json.loads(header_str)
116
+ except json.JSONDecodeError:
117
+ _send_error(None, -32700, "Parse error")
118
+ continue
119
+ else:
120
+ _response_format = "content-length"
121
+ length = int(header_str.split(":")[1].strip())
122
+ sys.stdin.buffer.readline() # skip blank line
123
+ body = sys.stdin.buffer.read(length).decode("utf-8")
124
+ request = json.loads(body)
125
+
126
+ method = request.get("method", "")
127
+ params = request.get("params", {})
128
+ request_id = request.get("id")
129
+
130
+ response = handle_rpc(method, params)
131
+
132
+ # 通知消息无需回复
133
+ if response is None:
134
+ continue
135
+
136
+ # 协议级错误(handle_rpc 的裸 {"error": {code, message}} 形态)
137
+ # 必须走 JSON-RPC error 通道;包成成功 result 会让客户端把
138
+ # 「Method not found」这类错误当正常响应解析。
139
+ if isinstance(response, dict) and "error" in response and "content" not in response:
140
+ err = response["error"]
141
+ _send_error(request_id, int(err.get("code", -32000) or -32000),
142
+ str(err.get("message", "internal error")))
143
+ continue
144
+
145
+ if request_id is not None:
146
+ _send_response({
147
+ "jsonrpc": "2.0",
148
+ "id": request_id,
149
+ "result": response
150
+ })
151
+
152
+ except json.JSONDecodeError:
153
+ _send_error(None, -32700, "Parse error")
154
+ except KeyboardInterrupt:
155
+ # Windows 控制台 Ctrl+C 会广播到同控制台 python 子进程,
156
+ # readline 被打断抛 KeyboardInterrupt(继承 BaseException,上面
157
+ # except Exception 接不住)。视同 EOF 干净退出,避免裸 traceback。
158
+ sys.stderr.write("[argo-mcp] interrupted, exiting\n")
159
+ sys.stderr.flush()
160
+ break
161
+ except Exception as e:
162
+ _send_error(request_id, -32000, f"Internal error: {e}")
163
+
164
+ # EOF/中断后硬退:在途引擎线程(社会搜并行池,非 daemon)会让解释器
165
+ # 退出时的 atexit join 拖到引擎内部超时(实测最长 ~15s)——宿主侧表现
166
+ # 为「会话已关、argo 进程残留」。此刻响应已全部 flush,盘上状态
167
+ # (quota/缓存/熔断)都是处理期间同步落盘的,直接硬退,不做任何 join。
168
+ sys.stdout.flush()
169
+ os._exit(0)
170
+
171
+
172
+ def _send_response(response: dict):
173
+ """发送 MCP 响应,根据客户端请求格式自动选择。紧凑 separators 省传输体积。"""
174
+ data = json.dumps(response, ensure_ascii=False, separators=(",", ":"))
175
+ if _response_format == "ndjson":
176
+ sys.stdout.write(data + "\n")
177
+ else:
178
+ encoded = data.encode("utf-8")
179
+ sys.stdout.buffer.write(f"Content-Length: {len(encoded)}\r\n\r\n".encode() + encoded)
180
+ sys.stdout.flush()
181
+
182
+
183
+ def _send_error(request_id, code: int, message: str):
184
+ """发送 JSON-RPC 错误响应。"""
185
+ resp = {
186
+ "jsonrpc": "2.0",
187
+ "id": request_id,
188
+ "error": {"code": code, "message": message}
189
+ }
190
+ _send_response(resp)
191
+
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env python3
2
+ """mcp_warm.py — MCP 核心预热、连接池预建与社交抓取并发编排。
3
+
4
+ 拆分自 mcp_handlers.py:隔离后台异步预热线程模型与社交平台并发调度。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import os
10
+ import sys
11
+ import threading
12
+ from typing import Any
13
+
14
+ _warm_started = False
15
+
16
+
17
+ def _prewarm_anysearch_connection() -> None:
18
+ """在 warm 线程里预建 anysearch 的隧道连接(2026-10-18)。"""
19
+ if os.environ.get("ARGO_NO_PREWARM", "").strip() not in ("", "0"):
20
+ return
21
+ try:
22
+ import urllib.parse
23
+ from conn_pool import give_back, key_for, stats as pool_stats
24
+ from net_proxy import open_connection, resolve_proxy
25
+ if not pool_stats().get("enabled"):
26
+ return
27
+ url = "https://api.anysearch.com/mcp"
28
+ parsed = urllib.parse.urlparse(url)
29
+ proxy_url = resolve_proxy(url)
30
+ conn, _via = open_connection(parsed, 8.0, proxy_url)
31
+ conn.connect()
32
+ give_back(key_for(parsed, proxy_url), conn)
33
+ except Exception as e:
34
+ sys.stderr.write(f"[argo-mcp] prewarm-skip: {type(e).__name__}: {e}\n")
35
+
36
+
37
+ def _warm_core_async(lazy_cached_fn, get_cache_fn) -> None:
38
+ """initialize 后后台预热 search+cache,摊平首次 tools/call 延迟。"""
39
+ global _warm_started
40
+ if _warm_started:
41
+ return
42
+ _warm_started = True
43
+
44
+ def _run() -> None:
45
+ t0 = __import__("time").time()
46
+ try:
47
+ lazy_cached_fn("search")
48
+ get_cache_fn()
49
+ try:
50
+ from route_domains import warm_compiled_domains
51
+ warm_compiled_domains()
52
+ except Exception:
53
+ pass
54
+ _prewarm_anysearch_connection()
55
+ ms = int((__import__("time").time() - t0) * 1000)
56
+ sys.stderr.write(f"[argo-mcp] warm-core ok {ms}ms\n")
57
+ except Exception as e:
58
+ sys.stderr.write(f"[argo-mcp] warm-core fail: {type(e).__name__}: {e}\n")
59
+ sys.stderr.flush()
60
+
61
+ threading.Thread(target=_run, name="argo-mcp-warm", daemon=True).start()
62
+
63
+
64
+ def _resolve_research_profile(arguments: dict[str, Any], lazy_cached_fn) -> tuple[dict[str, Any] | None, str | None]:
65
+ """解析 topic profile;全部在 argo 内,不加载外部 skill。"""
66
+ try:
67
+ profiles = lazy_cached_fn("topic_research_profiles")
68
+ except Exception:
69
+ return None, None
70
+ if not profiles:
71
+ return None, None
72
+ topic = arguments.get("topic")
73
+ key = None
74
+ if topic:
75
+ prof = profiles.get_profile(str(topic))
76
+ if prof:
77
+ raw = str(topic).strip()
78
+ key = profiles.ALIASES.get(raw) or profiles.ALIASES.get(raw.lower()) or raw.lower()
79
+ return prof, key
80
+ return None, None
81
+ if arguments.get("auto_topic", True):
82
+ key = profiles.detect_topic_from_query(arguments.get("query") or "")
83
+ if key:
84
+ return profiles.get_profile(key), key
85
+ return None, None
86
+
87
+
88
+ def _search_social_platforms(
89
+ platforms: list[str], query: str, n: int, timeout: float = 20.0,
90
+ lazy_cached_fn=None,
91
+ ) -> tuple[dict[str, list], list[str], list[str]]:
92
+ """并行抓取多社交平台(MCP 热路径)。"""
93
+ platform_results: dict[str, list] = {}
94
+ errors: list[str] = []
95
+ engines_used: list[str] = []
96
+
97
+ def _one(platform: str) -> tuple[str, list, str | None]:
98
+ module_name = platform.replace("-", "_") + "_engine"
99
+ try:
100
+ mod = lazy_cached_fn(f"social_engines.{module_name}")
101
+ return platform, mod.search(query, n=n), None
102
+ except ImportError:
103
+ return platform, [], f"Platform {platform} not available (module social_engines.{module_name})"
104
+ except Exception as e:
105
+ return platform, [], f"{platform}: {str(e)[:100]}"
106
+
107
+ workers = min(max(len(platforms), 1), 4)
108
+ import concurrent.futures
109
+ ex = concurrent.futures.ThreadPoolExecutor(max_workers=workers)
110
+ futs = {ex.submit(_one, p): p for p in platforms}
111
+ try:
112
+ for fut in concurrent.futures.as_completed(futs, timeout=timeout):
113
+ platform, results, err = fut.result()
114
+ platform_results[platform] = results
115
+ if err:
116
+ errors.append(err)
117
+ elif results is not None:
118
+ engines_used.append(platform)
119
+ except concurrent.futures.TimeoutError:
120
+ for fut, platform in futs.items():
121
+ if not fut.done():
122
+ fut.cancel()
123
+ platform_results[platform] = []
124
+ errors.append(f"{platform}: timeout (>{timeout}s)")
125
+ finally:
126
+ ex.shutdown(wait=False, cancel_futures=True)
127
+ return platform_results, engines_used, errors