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.
- package/LICENSE +201 -21
- package/README.en.md +735 -0
- package/README.es.md +777 -0
- package/README.ja.md +777 -0
- package/README.ko.md +777 -0
- package/README.md +778 -320
- package/SKILL.md +135 -0
- package/assets/readme/hero.svg +121 -0
- package/assets/readme/made-with-beautify.svg +10 -0
- package/assets/readme/proof-routes.svg +73 -0
- package/assets/readme/why-better.svg +104 -0
- package/assets/readme/workflow.svg +83 -0
- package/backends/domain_profiles.json +2356 -96
- package/backends/engine_registry.yaml +3428 -503
- package/backends/query_synonyms_cn.json +35 -0
- package/backends/quota_profiles.json +2488 -160
- package/backends/source_types_cn.json +109 -0
- package/backends/text_lexicon.json +44 -0
- package/bin/argo +772 -0
- package/bin/argo.js +102 -39
- package/config.yaml +5139 -367
- package/cordis.patch.yml +21 -0
- package/data/countries.json +40 -0
- package/data/lang_matrix/lang_capability.json +842 -0
- package/data/lang_matrix/matrix_2026-09-10.json +11921 -0
- package/data/regions_cn.json +1 -0
- package/docs/ADDING_NEW_ENGINE.md +184 -0
- package/docs/ARGO_INTRO.md +124 -0
- package/docs/DATA_SOURCE_GAPS.md +81 -0
- package/docs/DESIGN_LOCAL_DATA_FUSION.md +90 -0
- package/docs/ENGINE_CATALOG.md +575 -0
- package/docs/MCP_SETUP.md +108 -0
- package/docs/PLATFORM_PATHS.md +111 -0
- package/docs/RELEASE_NOTES_v2.8.0.md +71 -0
- package/docs/RELEASE_NOTES_v2.8.2.md +63 -0
- package/docs/RELEASE_NOTES_v2.8.3.md +55 -0
- package/docs/RELEASE_NOTES_v2.8.4.md +79 -0
- package/docs/RELEASE_NOTES_v2.8.5.md +102 -0
- package/docs/RELEASE_NOTES_v2.8.6.md +66 -0
- package/docs/RELEASE_NOTES_v2.8.7.md +65 -0
- package/docs/RELEASE_NOTES_v2.8.8.md +67 -0
- package/docs/RELEASE_NOTES_v2.8.9.md +67 -0
- package/docs/RELEASE_NOTES_v2.9.0.md +64 -0
- package/docs/RELEASE_NOTES_v2.9.8.md +73 -0
- package/docs/SEARCH_ARCHIVE.md +115 -0
- package/docs/assets/architecture.svg +104 -0
- package/docs/assets/hero.svg +98 -0
- package/docs/engines/bangumi.md +27 -0
- package/docs/engines/biorxiv.md +27 -0
- package/docs/engines/clawhub.md +27 -0
- package/docs/engines/crt_sh.md +27 -0
- package/docs/engines/datacite.md +27 -0
- package/docs/engines/deps_dev.md +27 -0
- package/docs/engines/douban_movie.md +27 -0
- package/docs/engines/endoflife.md +27 -0
- package/docs/engines/flk_law.md +27 -0
- package/docs/engines/fxtwitter.md +27 -0
- package/docs/engines/google_news.md +27 -0
- package/docs/engines/gov_regulations.md +27 -0
- package/docs/engines/guqian.md +27 -0
- package/docs/engines/hackernews.md +27 -0
- package/docs/engines/iplant.md +27 -0
- package/docs/engines/keenable.md +27 -0
- package/docs/engines/met_museum.md +27 -0
- package/docs/engines/nasa_images.md +27 -0
- package/docs/engines/netease_music.md +27 -0
- package/docs/engines/npm.md +27 -0
- package/docs/engines/nvd.md +27 -0
- package/docs/engines/openreview.md +27 -0
- package/docs/engines/openstd.md +27 -0
- package/docs/engines/parallel_free.md +27 -0
- package/docs/engines/people_daily.md +27 -0
- package/docs/engines/realtime_index.md +27 -0
- package/docs/engines/sec_edgar.md +27 -0
- package/docs/engines/seltz.md +27 -0
- package/docs/engines/skillsmp.md +27 -0
- package/docs/engines/sspai.md +27 -0
- package/docs/engines/std_samr.md +27 -0
- package/docs/engines/train.md +27 -0
- package/docs/engines/un_comtrade.md +27 -0
- package/docs/engines/wikisource.md +27 -0
- package/docs/engines/zdic.md +27 -0
- package/docs/engines/zenodo.md +27 -0
- package/docs/engines/zhihu_hot_app.md +27 -0
- package/docs//344/270/272/344/273/200/344/271/210/351/200/211/346/213/251argo.md +176 -0
- package/engines/README.md +10 -0
- package/engines/_template_cli.yaml +39 -0
- package/engines/_template_http.yaml +37 -0
- package/engines/plugins/_template_plugin.py +50 -0
- package/engines/specs/_cisa_kev.yaml +54 -0
- package/engines/specs/_osv.yaml +63 -0
- package/engines/specs/aljazeera.yaml +43 -0
- package/engines/specs/antara.yaml +43 -0
- package/engines/specs/artic.yaml +20 -0
- package/engines/specs/aviation_weather.yaml +39 -0
- package/engines/specs/bangumi.yaml +21 -0
- package/engines/specs/biorxiv.yaml +24 -0
- package/engines/specs/carbon_intensity.yaml +32 -0
- package/engines/specs/cfets.yaml +41 -0
- package/engines/specs/cinii.yaml +44 -0
- package/engines/specs/clawhub.yaml +49 -0
- package/engines/specs/cleveland.yaml +19 -0
- package/engines/specs/cn_ai_news.yaml +43 -0
- package/engines/specs/core.yaml +35 -0
- package/engines/specs/crt_sh.yaml +38 -0
- package/engines/specs/ct24.yaml +43 -0
- package/engines/specs/datacite.yaml +27 -0
- package/engines/specs/datagov_uk.yaml +41 -0
- package/engines/specs/ddgs_images.yaml +45 -0
- package/engines/specs/deepseek_search.yaml +74 -0
- package/engines/specs/deezer.yaml +20 -0
- package/engines/specs/defillama.yaml +38 -0
- package/engines/specs/deps_dev.yaml +21 -0
- package/engines/specs/digup.yaml +36 -0
- package/engines/specs/doi.yaml +39 -0
- package/engines/specs/douban_movie.yaml +22 -0
- package/engines/specs/dw_news.yaml +47 -0
- package/engines/specs/egov_law.yaml +21 -0
- package/engines/specs/elpais.yaml +43 -0
- package/engines/specs/endoflife.yaml +21 -0
- package/engines/specs/energy_charts.yaml +21 -0
- package/engines/specs/factcheck_org.yaml +52 -0
- package/engines/specs/faz.yaml +43 -0
- package/engines/specs/federal_register.yaml +57 -0
- package/engines/specs/firecrawl.yaml +53 -0
- package/engines/specs/flk_law.yaml +24 -0
- package/engines/specs/folha.yaml +43 -0
- package/engines/specs/france24.yaml +44 -0
- package/engines/specs/full_fact.yaml +47 -0
- package/engines/specs/fxtwitter.yaml +36 -0
- package/engines/specs/gbfs_nyc.yaml +32 -0
- package/engines/specs/gdacs.yaml +21 -0
- package/engines/specs/gdelt.yaml +64 -0
- package/engines/specs/gleif.yaml +55 -0
- package/engines/specs/google_news.yaml +22 -0
- package/engines/specs/gov_regulations.yaml +38 -0
- package/engines/specs/guardian_rss.yaml +59 -0
- package/engines/specs/hkex.yaml +40 -0
- package/engines/specs/hurriyet.yaml +43 -0
- package/engines/specs/iplant.yaml +25 -0
- package/engines/specs/jikan.yaml +24 -0
- package/engines/specs/jolpica.yaml +20 -0
- package/engines/specs/k10plus.yaml +20 -0
- package/engines/specs/keenable.yaml +44 -0
- package/engines/specs/keenable_free.yaml +36 -0
- package/engines/specs/lefigaro.yaml +43 -0
- package/engines/specs/listenbrainz.yaml +19 -0
- package/engines/specs/matichon.yaml +43 -0
- package/engines/specs/met_museum.yaml +21 -0
- package/engines/specs/nasa_images.yaml +45 -0
- package/engines/specs/netease_music.yaml +38 -0
- package/engines/specs/nhk.yaml +43 -0
- package/engines/specs/nhtsa_vpic.yaml +20 -0
- package/engines/specs/noaa_swpc.yaml +20 -0
- package/engines/specs/nvd.yaml +38 -0
- package/engines/specs/obis.yaml +20 -0
- package/engines/specs/opencitations.yaml +52 -0
- package/engines/specs/openf1.yaml +21 -0
- package/engines/specs/openfoodfacts.yaml +45 -0
- package/engines/specs/openligadb.yaml +20 -0
- package/engines/specs/openreview.yaml +37 -0
- package/engines/specs/openstd.yaml +21 -0
- package/engines/specs/people_daily.yaml +22 -0
- package/engines/specs/realtime_index.yaml +34 -0
- package/engines/specs/ror.yaml +20 -0
- package/engines/specs/satnogs.yaml +20 -0
- package/engines/specs/sec_edgar.yaml +46 -0
- package/engines/specs/shfe.yaml +39 -0
- package/engines/specs/skillsmp.yaml +50 -0
- package/engines/specs/sogou_weixin_browser.yaml +30 -0
- package/engines/specs/soilgrids.yaml +25 -0
- package/engines/specs/sspai.yaml +36 -0
- package/engines/specs/stackexchange.yaml +46 -0
- package/engines/specs/std_samr.yaml +21 -0
- package/engines/specs/tass.yaml +43 -0
- package/engines/specs/tavily_free.yaml +56 -0
- package/engines/specs/tle_mirror.yaml +21 -0
- package/engines/specs/train.yaml +37 -0
- package/engines/specs/tvmaze.yaml +20 -0
- package/engines/specs/twitter_syndication.yaml +31 -0
- package/engines/specs/un_comtrade.yaml +23 -0
- package/engines/specs/unpaywall.yaml +54 -0
- package/engines/specs/vnpress.yaml +43 -0
- package/engines/specs/weather.yaml +32 -0
- package/engines/specs/who_don.yaml +21 -0
- package/engines/specs/who_gho.yaml +20 -0
- package/engines/specs/wikimedia_commons.yaml +34 -0
- package/engines/specs/wikisource.yaml +22 -0
- package/engines/specs/worms.yaml +19 -0
- package/engines/specs/x_trending.yaml +34 -0
- package/engines/specs/yna.yaml +43 -0
- package/engines/specs/ynet.yaml +43 -0
- package/engines/specs/yuanbao.yaml +93 -0
- package/engines/specs/zbmath.yaml +40 -0
- package/engines/specs/zdic.yaml +22 -0
- package/engines/specs/zenodo.yaml +27 -0
- package/engines/specs/zhihu_hot_app.yaml +35 -0
- package/mcp/clients.yaml +106 -0
- package/package.json +55 -12
- package/packages/dsh-plugin/README.md +152 -0
- package/packages/dsh-plugin/cordis.patch.yml +48 -0
- package/packages/dsh-plugin/dsh/client.js +1533 -0
- package/packages/dsh-plugin/dsh/diagnostics.js +54 -0
- package/packages/dsh-plugin/dsh/index.js +527 -0
- package/packages/dsh-plugin/dsh/native-tools.mjs +749 -0
- package/packages/dsh-plugin/dsh/runner.js +666 -0
- package/packages/dsh-plugin/dsh/wide-research.js +878 -0
- package/packages/dsh-plugin/package.json +38 -0
- package/packages/dsh-plugin/scripts/sync-local.sh +70 -0
- package/packages/dsh-plugin/test/client.test.js +406 -0
- package/packages/dsh-plugin/test/config.test.js +30 -0
- package/packages/dsh-plugin/test/diagnostics.test.js +28 -0
- package/packages/dsh-plugin/test/index.test.js +1382 -0
- package/references/query-templates.md +96 -0
- package/references/query-templates.yaml +118 -0
- package/scripts/ab_eval.py +219 -0
- package/scripts/ab_eval_p0p1.py +266 -0
- package/scripts/adaptive.py +294 -70
- package/scripts/answer.py +154 -0
- package/scripts/archive_run.py +591 -0
- package/scripts/argo_engine_registry.py +172 -0
- package/scripts/argo_paths.py +728 -0
- package/scripts/article.py +136 -0
- package/scripts/article_meta.py +131 -0
- package/scripts/arxiv_source.py +201 -0
- package/scripts/badcase_ledger.py +252 -0
- package/scripts/batch_probe.py +241 -0
- package/scripts/benchmark.py +19 -0
- package/scripts/bounded_run.py +144 -0
- package/scripts/browser_auth.py +323 -0
- package/scripts/budget.py +247 -0
- package/scripts/budget_cli.py +93 -0
- package/scripts/build_release_assets.sh +65 -0
- package/scripts/burstiness_detector.py +147 -0
- package/scripts/cache.py +1066 -67
- package/scripts/cache_guard.py +271 -0
- package/scripts/cache_key_vdom.py +56 -0
- package/scripts/cache_similarity.py +170 -0
- package/scripts/caliber_isolation.py +195 -0
- package/scripts/calibrate_lowquality.py +210 -0
- package/scripts/candidate_envelope.py +366 -0
- package/scripts/chrome_cdp.py +871 -0
- package/scripts/ci_drift_gate.py +90 -0
- package/scripts/circuit_breaker.py +389 -0
- package/scripts/citations.py +334 -0
- package/scripts/cite_cli.py +59 -0
- package/scripts/cjk_tokens.py +95 -0
- package/scripts/clarify.py +47 -24
- package/scripts/cli_io.py +240 -0
- package/scripts/config.py +683 -45
- package/scripts/config_cache.py +402 -0
- package/scripts/conn_pool.py +220 -0
- package/scripts/content_boundary.py +46 -0
- package/scripts/content_security.py +685 -0
- package/scripts/content_signals.py +751 -0
- package/scripts/crawl.py +74 -35
- package/scripts/cross_lingual_trace.py +293 -0
- package/scripts/daemon.py +866 -0
- package/scripts/digup_bridge.py +214 -0
- package/scripts/dispatch_result.py +98 -0
- package/scripts/engine_admission.py +366 -0
- package/scripts/engine_dispatch.py +982 -0
- package/scripts/engine_env.py +539 -0
- package/scripts/engine_failure.py +411 -0
- package/scripts/engine_families.py +738 -0
- package/scripts/engine_policy.py +218 -0
- package/scripts/engine_requires.py +190 -0
- package/scripts/engine_status.py +322 -0
- package/scripts/engine_validate.py +638 -0
- package/scripts/engines.py +799 -294
- package/scripts/engines_base.py +1521 -0
- package/scripts/engines_builders.py +310 -0
- package/scripts/engines_builders_batch10.py +204 -0
- package/scripts/engines_builders_batch11.py +174 -0
- package/scripts/engines_builders_batch12.py +103 -0
- package/scripts/engines_builders_batch13.py +340 -0
- package/scripts/engines_builders_batch14.py +656 -0
- package/scripts/engines_builders_batch15.py +249 -0
- package/scripts/engines_builders_batch9.py +1468 -0
- package/scripts/engines_builders_cn.py +2283 -0
- package/scripts/engines_builders_data.py +2923 -0
- package/scripts/engines_builders_data_macro.py +775 -0
- package/scripts/engines_builders_feeds.py +255 -0
- package/scripts/engines_builders_intl.py +1239 -0
- package/scripts/engines_builders_keyless.py +111 -0
- package/scripts/engines_builders_search.py +440 -0
- package/scripts/engines_builders_tech.py +1359 -0
- package/scripts/evidence.py +620 -166
- package/scripts/evidence_loop.py +624 -0
- package/scripts/evidence_tier.py +298 -0
- package/scripts/except_sets.py +25 -0
- package/scripts/extract.py +55 -16
- package/scripts/fact_align.py +207 -0
- package/scripts/fact_crosscheck.py +230 -0
- package/scripts/fetch.py +25 -12
- package/scripts/fetch_browser.py +87 -0
- package/scripts/fetch_jsrun.py +122 -0
- package/scripts/fetch_quality.py +225 -0
- package/scripts/fetch_render_tinyfish.py +117 -0
- package/scripts/fetch_v3.py +1804 -0
- package/scripts/focus_extract.py +350 -0
- package/scripts/fulltext_store.py +169 -0
- package/scripts/fxtwitter_api.py +325 -0
- package/scripts/gen_engine_catalog.py +364 -0
- package/scripts/gen_native_tools.py +91 -0
- package/scripts/gen_routing_snapshot.py +195 -0
- package/scripts/health_check.py +140 -402
- package/scripts/health_probe.py +23 -8
- package/scripts/hot_state.py +134 -0
- package/scripts/http_client.py +1053 -0
- package/scripts/image_ops.py +430 -0
- package/scripts/image_vision/vision_probe.swift +126 -0
- package/scripts/install.ps1 +166 -0
- package/scripts/install.sh +221 -0
- package/scripts/job.py +1186 -0
- package/scripts/jump_resolver.py +235 -0
- package/scripts/lang_capability.py +150 -0
- package/scripts/lang_detect.py +289 -0
- package/scripts/lang_matrix_probe.py +329 -0
- package/scripts/lang_pref.py +311 -0
- package/scripts/link_source.py +340 -0
- package/scripts/local_image.py +970 -0
- package/scripts/local_seek.py +402 -0
- package/scripts/macro_countries.py +97 -0
- package/scripts/matrix_search_eval.py +1187 -0
- package/scripts/mcp_compact.py +234 -0
- package/scripts/mcp_diag.py +8 -3
- package/scripts/mcp_handlers.py +492 -0
- package/scripts/mcp_handlers_surface.py +157 -0
- package/scripts/mcp_launch.sh +124 -0
- package/scripts/mcp_local.py +241 -0
- package/scripts/mcp_server.py +125 -419
- package/scripts/mcp_setup.py +431 -0
- package/scripts/mcp_tools.py +331 -0
- package/scripts/mcp_transport.py +191 -0
- package/scripts/mcp_warm.py +127 -0
- package/scripts/min_version_scan.py +335 -0
- package/scripts/net_proxy.py +258 -0
- package/scripts/network_aware.py +152 -0
- package/scripts/output_transparency.py +200 -0
- package/scripts/paid_policy.py +98 -0
- package/scripts/paper.py +274 -0
- package/scripts/pdf_extract.py +518 -0
- package/scripts/phrase_filter.py +66 -0
- package/scripts/plan.py +422 -0
- package/scripts/postprocess_signals.py +150 -0
- package/scripts/pre-commit +48 -0
- package/scripts/query_enhance.py +157 -0
- package/scripts/query_operators.py +196 -0
- package/scripts/query_rewriter.py +116 -7
- package/scripts/query_signals.py +300 -0
- package/scripts/query_templates.py +167 -0
- package/scripts/query_understanding.py +411 -0
- package/scripts/query_variants.py +298 -0
- package/scripts/quota.py +633 -76
- package/scripts/rank_signals.py +775 -0
- package/scripts/ranking_eval.py +319 -0
- package/scripts/readability_extract.py +433 -0
- package/scripts/recompute.py +415 -0
- package/scripts/recovery.py +616 -0
- package/scripts/recovery_l0.py +160 -0
- package/scripts/recovery_runner.py +150 -0
- package/scripts/redskill/redskill_engine.py +332 -0
- package/scripts/regression_p0p1.py +318 -0
- package/scripts/replay_eval.py +658 -0
- package/scripts/rerank_tfidf.py +225 -0
- package/scripts/research.py +607 -403
- package/scripts/research_cli.py +361 -0
- package/scripts/research_dossier.py +492 -0
- package/scripts/research_expand.py +169 -0
- package/scripts/research_gates.py +272 -0
- package/scripts/research_report.py +209 -0
- package/scripts/research_strategy.py +37 -0
- package/scripts/research_work_packages.py +195 -0
- package/scripts/result_lang.py +311 -0
- package/scripts/retry_policy.py +76 -0
- package/scripts/robots_guard.py +259 -0
- package/scripts/route.py +921 -254
- package/scripts/route_bangs.py +40 -0
- package/scripts/route_cache.py +243 -0
- package/scripts/route_combo.py +917 -0
- package/scripts/route_domains.py +341 -0
- package/scripts/route_lang.py +605 -0
- package/scripts/route_log.py +63 -0
- package/scripts/route_policy.py +250 -0
- package/scripts/rrf_classic.py +66 -0
- package/scripts/screenshot.py +73 -0
- package/scripts/search.py +886 -406
- package/scripts/search_attribution.py +185 -0
- package/scripts/search_benchmark.py +407 -0
- package/scripts/search_cli.py +640 -0
- package/scripts/search_entry.py +395 -0
- package/scripts/search_output.py +690 -0
- package/scripts/search_pipeline.py +926 -0
- package/scripts/search_rank.py +991 -0
- package/scripts/search_types.py +129 -16
- package/scripts/seek_locator.py +68 -0
- package/scripts/semantic_evidence.py +391 -0
- package/scripts/serp_guard.py +336 -0
- package/scripts/serp_kill_log.py +74 -0
- package/scripts/single_flight.py +120 -0
- package/scripts/social_engines/__init__.py +10 -0
- package/scripts/social_engines/bilibili_engine.py +131 -0
- package/scripts/social_engines/hackernews_engine.py +113 -0
- package/scripts/social_engines/reddit_engine.py +172 -0
- package/scripts/social_engines/twitter_engine.py +397 -0
- package/scripts/social_engines/v2ex_engine.py +101 -0
- package/scripts/social_engines/weibo_engine.py +128 -0
- package/scripts/social_engines/xiaohongshu_engine.py +137 -0
- package/scripts/social_engines/zhihu_engine.py +139 -0
- package/scripts/social_research.py +201 -0
- package/scripts/sogou_weixin_browser.py +318 -0
- package/scripts/source_ledger.py +249 -0
- package/scripts/stage_timing.py +58 -0
- package/scripts/stats_cli.py +107 -0
- package/scripts/straggler_policy.py +60 -0
- package/scripts/stylometry_detector.py +231 -0
- package/scripts/sync_backends.py +353 -0
- package/scripts/sync_installs.py +29 -0
- package/scripts/template_cli.py +127 -0
- package/scripts/text_lexicon.py +72 -0
- package/scripts/tfidf_router.py +109 -37
- package/scripts/time_utils.py +233 -0
- package/scripts/topic_research_profiles.py +643 -0
- package/scripts/train.py +737 -0
- package/scripts/tweet.py +596 -0
- package/scripts/url_canon.py +217 -0
- package/scripts/url_optimize.py +56 -0
- package/scripts/url_safety.py +236 -0
- package/scripts/usage_log.py +116 -0
- package/scripts/usage_log_clean.py +113 -0
- package/scripts/v2ex_nodes.py +311 -0
- package/scripts/variant_recall.py +188 -0
- package/scripts/watch.py +205 -0
- package/scripts/wechat_article.py +258 -0
- package/scripts/wide_research.py +447 -0
- package/scripts/wx.py +349 -0
- package/scripts/x_article_fetch.py +141 -0
- package/scripts/x_search.py +234 -0
- package/scripts/x_trending.py +189 -0
- package/scripts/yaml_load.py +67 -0
- package/scripts/zhihu_quota.py +139 -0
- package/sub-skills/ego-search/SKILL.md +253 -0
- package/sub-skills/ego-search/scripts/ego_search.py +800 -0
- package/sub-skills/ego-search/scripts/merge.py +226 -0
- package/sub-skills/ego-search/scripts/quality.py +64 -0
- package/sub-skills/ego-search/scripts/runtime.py +172 -0
- package/sub-skills/ego-search/scripts/safety.py +109 -0
- package/sub-skills/ego-search/scripts/serp_spec.py +109 -0
- package/sub-skills/ego-search/scripts/webbridge_adapter.py +374 -0
- package/sub-skills/js-run/SKILL.md +67 -0
- package/sub-skills/js-run/scripts/jsrun.py +112 -0
- package/sub-skills/js-run/scripts/shim.js +188 -0
- package/sub-skills/local-search/SKILL.md +50 -53
- package/sub-skills/local-search/bm25.py +186 -0
- package/sub-skills/local-search/cli_runner.py +331 -0
- package/sub-skills/local-search/config.yaml +152 -55
- package/sub-skills/local-search/engine_registry.py +91 -26
- package/sub-skills/local-search/{health_check.py → local_health_check.py} +140 -10
- package/sub-skills/local-search/local_search_adapter.py +13 -2
- package/sub-skills/local-search/parse_maps.yaml +40 -42
- package/sub-skills/local-search/parsers.py +328 -0
- package/sub-skills/local-search/search_v3.py +716 -242
- package/sub-skills/local-search/smart_router.py +47 -7
- package/sub-skills/local-seek/SKILL.md +110 -0
- package/sub-skills/local-seek/config/domains.yaml +20 -0
- package/sub-skills/local-seek/scripts/eval_rank.py +216 -0
- package/sub-skills/local-seek/scripts/eval_seek.py +224 -0
- package/sub-skills/local-seek/scripts/seek.py +1465 -0
- package/sub-skills/local-seek/scripts/seek_frecency.py +126 -0
- package/sub-skills/local-seek/scripts/seek_fts.py +430 -0
- package/sub-skills/local-seek/scripts/seek_rank.py +197 -0
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* runner.js — argo-dsh 执行与连接池层(Runner & Connection Pool)
|
|
3
|
+
*
|
|
4
|
+
* 负责:
|
|
5
|
+
* 1. 常驻 stdio MCP 连接池(按需增长、并发独立、空闲回收、零泄漏)
|
|
6
|
+
* 2. 原生一等工具(makeNativeTool / runNativeCall)单发兜底与 MCP 优先调度
|
|
7
|
+
* 3. 宿主 web_search & web_fetch seam 结果映射与错误分类
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { spawn } from 'node:child_process'
|
|
11
|
+
import { readFileSync } from 'node:fs'
|
|
12
|
+
import { homedir } from 'node:os'
|
|
13
|
+
import { dirname, join } from 'node:path'
|
|
14
|
+
import { fileURLToPath } from 'node:url'
|
|
15
|
+
import { NATIVE_TOOLS as NATIVE_TOOL_SPECS } from './native-tools.mjs'
|
|
16
|
+
|
|
17
|
+
function resolvePluginVersion() {
|
|
18
|
+
try {
|
|
19
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
20
|
+
const raw = readFileSync(join(here, '..', 'package.json'), 'utf8')
|
|
21
|
+
const parsed = JSON.parse(raw)
|
|
22
|
+
if (typeof parsed?.version === 'string' && parsed.version !== '') return parsed.version
|
|
23
|
+
} catch { /* 打包裁剪/权限异常:回退,不阻断插件加载 */ }
|
|
24
|
+
return '0.0.0-unknown'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const PLUGIN_VERSION = resolvePluginVersion()
|
|
28
|
+
|
|
29
|
+
export const MCP_CHILD_TOOLS = Object.keys(NATIVE_TOOL_SPECS).map(name => `mcp__argo__${name}`)
|
|
30
|
+
export const DEFAULT_CHILD_TOOLS = Object.freeze([
|
|
31
|
+
...MCP_CHILD_TOOLS,
|
|
32
|
+
'argo_search',
|
|
33
|
+
'argo_fetch',
|
|
34
|
+
'web_search',
|
|
35
|
+
'web_fetch',
|
|
36
|
+
])
|
|
37
|
+
|
|
38
|
+
export const DEFAULTS = Object.freeze({
|
|
39
|
+
toolName: 'wide_research',
|
|
40
|
+
provider: 'spawn',
|
|
41
|
+
defaultWorkers: 6,
|
|
42
|
+
maxWorkers: 9,
|
|
43
|
+
maxTracks: 9,
|
|
44
|
+
maxSourcesPerTrack: 5,
|
|
45
|
+
workerMaxTokens: 5_000,
|
|
46
|
+
synthesisMaxTokens: 7_000,
|
|
47
|
+
childToolDeny: [],
|
|
48
|
+
childToolAllow: [...DEFAULT_CHILD_TOOLS],
|
|
49
|
+
searchProviderEnabled: true,
|
|
50
|
+
nativeTools: ['argo_search', 'argo_fetch'],
|
|
51
|
+
nativeTimeoutMs: 60_000,
|
|
52
|
+
nativeMaxChars: 24_000,
|
|
53
|
+
searchProviderId: 'argo',
|
|
54
|
+
fetchProviderEnabled: true,
|
|
55
|
+
fetchProviderId: 'argo',
|
|
56
|
+
fetchTimeoutMs: 25_000,
|
|
57
|
+
fetchMaxChars: 50_000,
|
|
58
|
+
searchCommand: process.env.ARGO_SEARCH_PYTHON || 'npx',
|
|
59
|
+
searchArgs: process.env.ARGO_SEARCH_MCP_SERVER
|
|
60
|
+
? [process.env.ARGO_SEARCH_MCP_SERVER]
|
|
61
|
+
: ['-y', 'github:taxueseek/argo'],
|
|
62
|
+
searchTimeoutMs: 30_000,
|
|
63
|
+
searchIdleMs: 60_000,
|
|
64
|
+
searchConcurrency: 3,
|
|
65
|
+
reportDir: join(homedir(), '.dsh-research'),
|
|
66
|
+
keyRefs: ['DEEPSEEK_API_KEY'],
|
|
67
|
+
argoEnv: [],
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const text = (value) => [{ type: 'text', text: value }]
|
|
71
|
+
const clip = (value, maximum) => value.length <= maximum ? value : `${value.slice(0, maximum - 1)}…`
|
|
72
|
+
const clamp = (value, fallback, minimum, maximum) => Number.isFinite(value)
|
|
73
|
+
? Math.max(minimum, Math.min(maximum, Math.floor(value)))
|
|
74
|
+
: fallback
|
|
75
|
+
|
|
76
|
+
export function argoAborted() {
|
|
77
|
+
const err = new Error('argo search aborted')
|
|
78
|
+
err.code = 'WEB_ABORTED'
|
|
79
|
+
return err
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function argoToolError(message) {
|
|
83
|
+
const err = new Error(message)
|
|
84
|
+
err.code = 'ARGO_TOOL_ERROR'
|
|
85
|
+
return err
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const stripBoundary = (v) => typeof v === 'string'
|
|
89
|
+
? v.replace(/<\s*\/?\s*untrusted-web-content\b[^>]*>/gi, '')
|
|
90
|
+
: v
|
|
91
|
+
|
|
92
|
+
export function mapArgoToWebResult(payload, query) {
|
|
93
|
+
const results = Array.isArray(payload?.results)
|
|
94
|
+
? payload.results.filter(r => r && typeof r.url === 'string' && r.url !== '')
|
|
95
|
+
: []
|
|
96
|
+
const sources = results.map(r => {
|
|
97
|
+
const source = { url: r.url }
|
|
98
|
+
const title = stripBoundary(r.title)
|
|
99
|
+
const snippet = stripBoundary(r.snippet)
|
|
100
|
+
if (typeof title === 'string' && title !== '') source.title = title
|
|
101
|
+
if (typeof snippet === 'string' && snippet !== '') source.snippet = snippet
|
|
102
|
+
return source
|
|
103
|
+
})
|
|
104
|
+
return { content: undefined, sources, truncated: false, engine: payload?.engine ?? 'argo' }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let activeEnvResolver = null
|
|
108
|
+
|
|
109
|
+
export function setEnvResolver(fn) {
|
|
110
|
+
activeEnvResolver = fn
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function resolveEnv(options = {}, config = undefined) {
|
|
114
|
+
if (typeof activeEnvResolver === 'function') {
|
|
115
|
+
return activeEnvResolver(options, config)
|
|
116
|
+
}
|
|
117
|
+
return undefined
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export const mcpPool = []
|
|
121
|
+
|
|
122
|
+
export function dropFromPool(conn) {
|
|
123
|
+
const index = mcpPool.indexOf(conn)
|
|
124
|
+
if (index >= 0) mcpPool.splice(index, 1)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function createMcpConnection(options) {
|
|
128
|
+
const { command, args, idleMs, env } = options
|
|
129
|
+
let proc = null
|
|
130
|
+
let buffer = ''
|
|
131
|
+
let nextId = 1
|
|
132
|
+
let chain = Promise.resolve()
|
|
133
|
+
let idleTimer = null
|
|
134
|
+
let disposed = false
|
|
135
|
+
let claims = 0
|
|
136
|
+
const pending = new Map()
|
|
137
|
+
|
|
138
|
+
const touchIdle = () => {
|
|
139
|
+
if (idleTimer !== null) clearTimeout(idleTimer)
|
|
140
|
+
if (idleMs > 0) {
|
|
141
|
+
idleTimer = setTimeout(() => { close() }, idleMs)
|
|
142
|
+
if (idleTimer.unref) idleTimer.unref()
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const close = () => {
|
|
147
|
+
if (disposed) return
|
|
148
|
+
disposed = true
|
|
149
|
+
if (idleTimer !== null) clearTimeout(idleTimer)
|
|
150
|
+
if (proc !== null) {
|
|
151
|
+
try { proc.kill() } catch { /* already gone */ }
|
|
152
|
+
proc = null
|
|
153
|
+
}
|
|
154
|
+
const err = new Error('argo MCP connection closed')
|
|
155
|
+
for (const entry of pending.values()) entry.rej(err)
|
|
156
|
+
pending.clear()
|
|
157
|
+
dropFromPool(conn)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const send = (method, params, timeoutMs = 0) => {
|
|
161
|
+
touchIdle()
|
|
162
|
+
const run = () => new Promise((res, rej) => {
|
|
163
|
+
if (proc === null || proc.stdin.destroyed) {
|
|
164
|
+
rej(new Error('argo MCP process not running'))
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
const id = nextId
|
|
168
|
+
nextId += 1
|
|
169
|
+
const entry = { res, rej }
|
|
170
|
+
pending.set(id, entry)
|
|
171
|
+
|
|
172
|
+
let reqTimer = null
|
|
173
|
+
if (timeoutMs > 0) {
|
|
174
|
+
reqTimer = setTimeout(() => {
|
|
175
|
+
pending.delete(id)
|
|
176
|
+
const err = new Error(`argo MCP request timed out after ${timeoutMs}ms: ${method}`)
|
|
177
|
+
err.code = 'ARGO_TIMEOUT'
|
|
178
|
+
rej(err)
|
|
179
|
+
close()
|
|
180
|
+
}, timeoutMs)
|
|
181
|
+
if (reqTimer.unref) reqTimer.unref()
|
|
182
|
+
}
|
|
183
|
+
const settle = (fn, value) => {
|
|
184
|
+
if (reqTimer !== null) clearTimeout(reqTimer)
|
|
185
|
+
fn(value)
|
|
186
|
+
}
|
|
187
|
+
entry.res = (v) => settle(res, v)
|
|
188
|
+
entry.rej = (e) => settle(rej, e)
|
|
189
|
+
try {
|
|
190
|
+
proc.stdin.write(JSON.stringify({ jsonrpc: '2.0', id, method, params }) + '\n')
|
|
191
|
+
} catch (err) {
|
|
192
|
+
pending.delete(id)
|
|
193
|
+
rej(err)
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
const result = chain.then(run)
|
|
197
|
+
chain = result.catch(() => { /* 失败不中断后续请求 */ })
|
|
198
|
+
return result
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const conn = {
|
|
202
|
+
initialize: async (timeoutMs = 0) => {
|
|
203
|
+
if (proc !== null) return
|
|
204
|
+
proc = spawn(command, args, { stdio: ['pipe', 'pipe', 'pipe'], env: env ?? process.env })
|
|
205
|
+
proc.on('error', () => close())
|
|
206
|
+
proc.on('exit', () => close())
|
|
207
|
+
proc.stderr.on('data', () => { /* 预热日志忽略 */ })
|
|
208
|
+
proc.stdout.setEncoding('utf8')
|
|
209
|
+
proc.stdout.on('data', (chunk) => {
|
|
210
|
+
buffer += chunk
|
|
211
|
+
let nl
|
|
212
|
+
while ((nl = buffer.indexOf('\n')) >= 0) {
|
|
213
|
+
const line = buffer.slice(0, nl).trim()
|
|
214
|
+
buffer = buffer.slice(nl + 1)
|
|
215
|
+
if (line === '') continue
|
|
216
|
+
let msg
|
|
217
|
+
try {
|
|
218
|
+
msg = JSON.parse(line)
|
|
219
|
+
} catch {
|
|
220
|
+
continue
|
|
221
|
+
}
|
|
222
|
+
const entry = pending.get(msg.id)
|
|
223
|
+
if (entry === undefined) continue
|
|
224
|
+
pending.delete(msg.id)
|
|
225
|
+
if (msg.error !== undefined) entry.rej(new Error(msg.error.message ?? 'argo MCP error'))
|
|
226
|
+
else entry.res(msg.result)
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
await new Promise((res, rej) => {
|
|
230
|
+
proc.once('spawn', res)
|
|
231
|
+
proc.once('error', rej)
|
|
232
|
+
})
|
|
233
|
+
const init = await send('initialize', {
|
|
234
|
+
protocolVersion: '2025-06-18',
|
|
235
|
+
capabilities: {},
|
|
236
|
+
clientInfo: { name: 'argo-dsh', version: PLUGIN_VERSION }
|
|
237
|
+
}, timeoutMs)
|
|
238
|
+
conn.notify('notifications/initialized', {})
|
|
239
|
+
return init
|
|
240
|
+
},
|
|
241
|
+
request: (method, params, timeoutMs = 0) => {
|
|
242
|
+
if (claims > 0) claims -= 1
|
|
243
|
+
return send(method, params, timeoutMs)
|
|
244
|
+
},
|
|
245
|
+
claim: () => {
|
|
246
|
+
claims += 1
|
|
247
|
+
touchIdle()
|
|
248
|
+
},
|
|
249
|
+
release: () => {
|
|
250
|
+
if (claims > 0) claims -= 1
|
|
251
|
+
touchIdle()
|
|
252
|
+
},
|
|
253
|
+
load: () => pending.size + claims,
|
|
254
|
+
notify: (method, params) => {
|
|
255
|
+
if (proc !== null && !proc.stdin.destroyed) {
|
|
256
|
+
try {
|
|
257
|
+
proc.stdin.write(JSON.stringify({ jsonrpc: '2.0', method, params }) + '\n')
|
|
258
|
+
} catch { /* ignore */ }
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
close
|
|
262
|
+
}
|
|
263
|
+
return conn
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function initializeWithSignal(conn, initMs, signal) {
|
|
267
|
+
if (signal?.aborted) {
|
|
268
|
+
conn.close()
|
|
269
|
+
return Promise.reject(argoAborted())
|
|
270
|
+
}
|
|
271
|
+
if (signal === undefined) return conn.initialize(initMs)
|
|
272
|
+
return new Promise((resolve, reject) => {
|
|
273
|
+
const onAbort = () => {
|
|
274
|
+
conn.close()
|
|
275
|
+
reject(argoAborted())
|
|
276
|
+
}
|
|
277
|
+
signal.addEventListener('abort', onAbort, { once: true })
|
|
278
|
+
conn.initialize(initMs).then(
|
|
279
|
+
(value) => { signal.removeEventListener('abort', onAbort); resolve(value) },
|
|
280
|
+
(err) => { signal.removeEventListener('abort', onAbort); reject(err) },
|
|
281
|
+
)
|
|
282
|
+
})
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export async function acquireMcp(options, signal) {
|
|
286
|
+
const max = Math.max(1, Number(options.max) || DEFAULTS.searchConcurrency)
|
|
287
|
+
const initMs = Math.max(0, Number(options.initMs) || 0)
|
|
288
|
+
const idle = mcpPool.find(entry => entry.load() === 0)
|
|
289
|
+
if (idle !== undefined) {
|
|
290
|
+
idle.claim()
|
|
291
|
+
try {
|
|
292
|
+
await initializeWithSignal(idle, initMs, signal)
|
|
293
|
+
return idle
|
|
294
|
+
} catch (err) {
|
|
295
|
+
dropFromPool(idle)
|
|
296
|
+
idle.close()
|
|
297
|
+
if (mcpPool.length >= max) throw err
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (mcpPool.length < max) {
|
|
301
|
+
const env = await resolveEnv(options)
|
|
302
|
+
const conn = createMcpConnection({ ...options, env })
|
|
303
|
+
mcpPool.push(conn)
|
|
304
|
+
conn.claim()
|
|
305
|
+
try {
|
|
306
|
+
await initializeWithSignal(conn, initMs, signal)
|
|
307
|
+
} catch (err) {
|
|
308
|
+
dropFromPool(conn)
|
|
309
|
+
conn.close()
|
|
310
|
+
throw err
|
|
311
|
+
}
|
|
312
|
+
return conn
|
|
313
|
+
}
|
|
314
|
+
const least = mcpPool.reduce((a, b) => (a.load() <= b.load() ? a : b))
|
|
315
|
+
least.claim()
|
|
316
|
+
try {
|
|
317
|
+
await initializeWithSignal(least, initMs, signal)
|
|
318
|
+
} catch (err) {
|
|
319
|
+
dropFromPool(least)
|
|
320
|
+
least.close()
|
|
321
|
+
throw err
|
|
322
|
+
}
|
|
323
|
+
return least
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export function disposeSharedMcp() {
|
|
327
|
+
for (const conn of [...mcpPool]) conn.close()
|
|
328
|
+
mcpPool.length = 0
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function classifyFetchError(err, url) {
|
|
332
|
+
const raw = String(err?.message ?? err ?? '')
|
|
333
|
+
const lower = raw.toLowerCase()
|
|
334
|
+
const prefix = (label, hint) => {
|
|
335
|
+
const e = new Error(`argo fetch ${label}: ${hint} (url=${url})`)
|
|
336
|
+
e.code = `ARGO_FETCH_${label.toUpperCase().replace(/-/g, '_')}`
|
|
337
|
+
return e
|
|
338
|
+
}
|
|
339
|
+
if (err?.code === 'WEB_ABORTED' || /abort/i.test(raw)) {
|
|
340
|
+
return prefix('aborted', 'cancelled by caller')
|
|
341
|
+
}
|
|
342
|
+
if (err?.code === 'ARGO_TIMEOUT' || /timed out|timeout/i.test(lower)) {
|
|
343
|
+
return prefix('timeout', 'the page took too long; try a more specific URL or retry')
|
|
344
|
+
}
|
|
345
|
+
if (/blocked|forbidden|403|robots|captcha|cloudflare|denied/i.test(lower)) {
|
|
346
|
+
return prefix('blocked', 'the source refused automated access; use a search result URL instead')
|
|
347
|
+
}
|
|
348
|
+
if (/no readable|no content|nothing extracted|no results|empty/i.test(lower)) {
|
|
349
|
+
return prefix('empty', 'no readable content was extracted from the page')
|
|
350
|
+
}
|
|
351
|
+
const e = new Error(`argo fetch failed: ${clip(raw, 300)} (url=${url})`)
|
|
352
|
+
e.code = 'ARGO_FETCH_FAILED'
|
|
353
|
+
return e
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export function mapArgoToWebFetch(payload, requestUrl, maxChars) {
|
|
357
|
+
const url = typeof payload?.url === 'string' && payload.url !== '' ? payload.url : requestUrl
|
|
358
|
+
const content = typeof payload?.content === 'string' ? stripBoundary(payload.content) : ''
|
|
359
|
+
const clipped = content.length > maxChars
|
|
360
|
+
return {
|
|
361
|
+
url,
|
|
362
|
+
statusCode: 200,
|
|
363
|
+
body: { kind: 'text', content: clipped ? content.slice(0, maxChars) : content },
|
|
364
|
+
truncated: Boolean(payload?.truncated) || clipped,
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export async function fetchViaArgo(url, signal, options = {}, deps = {}) {
|
|
369
|
+
const command = options.command ?? DEFAULTS.searchCommand
|
|
370
|
+
const args = options.args ?? DEFAULTS.searchArgs
|
|
371
|
+
const timeoutMs = options.timeoutMs ?? DEFAULTS.fetchTimeoutMs
|
|
372
|
+
const maxChars = clamp(options.maxChars ?? DEFAULTS.fetchMaxChars,
|
|
373
|
+
DEFAULTS.fetchMaxChars, 500, 50_000)
|
|
374
|
+
const argsObj = { url, max_chars: maxChars }
|
|
375
|
+
const spawnRun = deps.run ?? runNativeCall
|
|
376
|
+
|
|
377
|
+
const acquireOptions = {
|
|
378
|
+
command,
|
|
379
|
+
args,
|
|
380
|
+
idleMs: options.idleMs ?? DEFAULTS.searchIdleMs,
|
|
381
|
+
max: options.max ?? DEFAULTS.searchConcurrency,
|
|
382
|
+
initMs: timeoutMs,
|
|
383
|
+
credentials: options.credentials,
|
|
384
|
+
config: options.config,
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
let raw
|
|
388
|
+
try {
|
|
389
|
+
const conn = await acquireMcp(acquireOptions, signal)
|
|
390
|
+
raw = await new Promise((resolve, reject) => {
|
|
391
|
+
const onAbort = () => reject(argoAborted())
|
|
392
|
+
if (signal?.aborted) {
|
|
393
|
+
conn.release()
|
|
394
|
+
reject(argoAborted())
|
|
395
|
+
return
|
|
396
|
+
}
|
|
397
|
+
if (signal !== undefined) signal.addEventListener('abort', onAbort, { once: true })
|
|
398
|
+
conn.request('tools/call', { name: 'argo_fetch', arguments: argsObj }, timeoutMs).then((value) => {
|
|
399
|
+
if (signal !== undefined) signal.removeEventListener('abort', onAbort)
|
|
400
|
+
if (value?.isError) {
|
|
401
|
+
const body = value?.content?.[0]?.text
|
|
402
|
+
reject(argoToolError(typeof body === 'string' && body !== ''
|
|
403
|
+
? body
|
|
404
|
+
: `argo tool argo_fetch returned an error`))
|
|
405
|
+
return
|
|
406
|
+
}
|
|
407
|
+
const text = value?.content?.[0]?.text
|
|
408
|
+
resolve(typeof text === 'string' ? JSON.parse(text) : {})
|
|
409
|
+
}, (err) => {
|
|
410
|
+
if (signal !== undefined) signal.removeEventListener('abort', onAbort)
|
|
411
|
+
reject(err)
|
|
412
|
+
})
|
|
413
|
+
})
|
|
414
|
+
} catch (err) {
|
|
415
|
+
if (err?.code === 'ARGO_TOOL_ERROR' || err?.code === 'ARGO_TIMEOUT' || err?.code === 'WEB_ABORTED') {
|
|
416
|
+
throw classifyFetchError(err, url)
|
|
417
|
+
}
|
|
418
|
+
try {
|
|
419
|
+
const spawnSpec = resolveNativeSpawn(
|
|
420
|
+
{ searchCommand: command, searchArgs: args },
|
|
421
|
+
'argo_fetch',
|
|
422
|
+
JSON.stringify(argsObj),
|
|
423
|
+
)
|
|
424
|
+
const env = await resolveEnv(options)
|
|
425
|
+
const stdout = await spawnRun(env !== undefined ? { ...spawnSpec, env } : spawnSpec, timeoutMs, signal)
|
|
426
|
+
const parsed = JSON.parse(stdout)
|
|
427
|
+
if (parsed?.isError) {
|
|
428
|
+
const body = parsed?.content?.[0]?.text
|
|
429
|
+
throw argoToolError(typeof body === 'string' && body !== '' ? body : 'argo_fetch failed')
|
|
430
|
+
}
|
|
431
|
+
raw = JSON.parse(parsed?.content?.[0]?.text ?? '{}')
|
|
432
|
+
} catch (spawnErr) {
|
|
433
|
+
throw classifyFetchError(spawnErr, url)
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (raw?.success === false) {
|
|
438
|
+
throw classifyFetchError(new Error(String(raw?.error ?? 'fetch failed')), url)
|
|
439
|
+
}
|
|
440
|
+
return mapArgoToWebFetch(raw, url, maxChars)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export async function searchViaArgoMCP(query, maxResults = 5, signal, options = {}) {
|
|
444
|
+
const command = options.command ?? DEFAULTS.searchCommand
|
|
445
|
+
const args = options.args ?? DEFAULTS.searchArgs
|
|
446
|
+
const timeoutMs = options.timeoutMs ?? DEFAULTS.searchTimeoutMs
|
|
447
|
+
const count = clamp(maxResults ?? 5, 5, 1, 20)
|
|
448
|
+
|
|
449
|
+
const conn = await acquireMcp({
|
|
450
|
+
command,
|
|
451
|
+
args,
|
|
452
|
+
idleMs: options.idleMs ?? DEFAULTS.searchIdleMs,
|
|
453
|
+
max: options.max ?? DEFAULTS.searchConcurrency,
|
|
454
|
+
initMs: timeoutMs,
|
|
455
|
+
credentials: options.credentials,
|
|
456
|
+
config: options.config,
|
|
457
|
+
}, signal)
|
|
458
|
+
|
|
459
|
+
const result = await new Promise((resolve, reject) => {
|
|
460
|
+
const onAbort = () => reject(argoAborted())
|
|
461
|
+
if (signal !== undefined) {
|
|
462
|
+
if (signal.aborted) {
|
|
463
|
+
conn.release()
|
|
464
|
+
reject(argoAborted())
|
|
465
|
+
return
|
|
466
|
+
}
|
|
467
|
+
signal.addEventListener('abort', onAbort, { once: true })
|
|
468
|
+
}
|
|
469
|
+
conn.request('tools/call', {
|
|
470
|
+
name: 'argo_search',
|
|
471
|
+
arguments: { query, max_results: count, summary: true }
|
|
472
|
+
}, timeoutMs).then((value) => {
|
|
473
|
+
if (signal !== undefined) signal.removeEventListener('abort', onAbort)
|
|
474
|
+
resolve(value)
|
|
475
|
+
}, (err) => {
|
|
476
|
+
if (signal !== undefined) signal.removeEventListener('abort', onAbort)
|
|
477
|
+
reject(err)
|
|
478
|
+
})
|
|
479
|
+
})
|
|
480
|
+
|
|
481
|
+
let payload
|
|
482
|
+
try {
|
|
483
|
+
const raw = result?.content?.[0]?.text
|
|
484
|
+
payload = typeof raw === 'string' ? JSON.parse(raw) : {}
|
|
485
|
+
} catch (err) {
|
|
486
|
+
throw new Error(`argo search returned an unprocessable response: ${String(err)}`)
|
|
487
|
+
}
|
|
488
|
+
return mapArgoToWebResult(payload, query)
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export function resolveNativeSpawn(config, tool, payload) {
|
|
492
|
+
const command = typeof config.searchCommand === 'string' && config.searchCommand !== ''
|
|
493
|
+
? config.searchCommand
|
|
494
|
+
: DEFAULTS.searchCommand
|
|
495
|
+
const args = Array.isArray(config.searchArgs) && config.searchArgs.length > 0
|
|
496
|
+
? config.searchArgs
|
|
497
|
+
: DEFAULTS.searchArgs
|
|
498
|
+
if (args.some(arg => typeof arg === 'string' && arg.endsWith('mcp_server.py'))) {
|
|
499
|
+
return { command, args: [...args, '--call', tool, payload] }
|
|
500
|
+
}
|
|
501
|
+
return { command, args: [...args, 'call', tool, payload] }
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export function nativeErrorText(stdout, stderr) {
|
|
505
|
+
try {
|
|
506
|
+
const parsed = JSON.parse(stdout)
|
|
507
|
+
const body = parsed?.content?.[0]?.text
|
|
508
|
+
if (typeof body === 'string' && body !== '') return body
|
|
509
|
+
} catch { /* ignore */ }
|
|
510
|
+
return stderr.trim() !== '' ? stderr : stdout
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export function runNativeCall({ command, args, env }, timeoutMs, signal) {
|
|
514
|
+
return new Promise((resolve, reject) => {
|
|
515
|
+
if (signal && signal.aborted) {
|
|
516
|
+
reject(argoAborted())
|
|
517
|
+
return
|
|
518
|
+
}
|
|
519
|
+
const child = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'], env: env ?? process.env })
|
|
520
|
+
let stdout = ''
|
|
521
|
+
let stderr = ''
|
|
522
|
+
let settled = false
|
|
523
|
+
let timer = null
|
|
524
|
+
let detachAbort = null
|
|
525
|
+
|
|
526
|
+
const settle = (fn, value) => {
|
|
527
|
+
if (settled) return
|
|
528
|
+
settled = true
|
|
529
|
+
if (timer !== null) clearTimeout(timer)
|
|
530
|
+
if (detachAbort !== null) detachAbort()
|
|
531
|
+
fn(value)
|
|
532
|
+
}
|
|
533
|
+
const onAbort = () => {
|
|
534
|
+
try { child.kill('SIGKILL') } catch { /* already gone */ }
|
|
535
|
+
settle(reject, argoAborted())
|
|
536
|
+
}
|
|
537
|
+
if (signal) {
|
|
538
|
+
signal.addEventListener('abort', onAbort, { once: true })
|
|
539
|
+
detachAbort = () => signal.removeEventListener('abort', onAbort)
|
|
540
|
+
}
|
|
541
|
+
timer = setTimeout(() => {
|
|
542
|
+
try { child.kill('SIGKILL') } catch { /* already gone */ }
|
|
543
|
+
settle(reject, new Error(`argo native call timed out after ${timeoutMs}ms`))
|
|
544
|
+
}, timeoutMs)
|
|
545
|
+
child.stdout.on('data', (chunk) => { stdout += chunk })
|
|
546
|
+
child.stderr.on('data', (chunk) => { stderr += chunk })
|
|
547
|
+
child.on('error', (err) => settle(reject, err))
|
|
548
|
+
child.on('close', (code) => {
|
|
549
|
+
if (code === 0) { settle(resolve, stdout); return }
|
|
550
|
+
settle(reject, new Error(`argo native call exited ${code}: ${clip(nativeErrorText(stdout, stderr), 500)}`))
|
|
551
|
+
})
|
|
552
|
+
})
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
export function resolveEntry(config) {
|
|
556
|
+
const command = typeof config.searchCommand === 'string' && config.searchCommand !== ''
|
|
557
|
+
? config.searchCommand
|
|
558
|
+
: DEFAULTS.searchCommand
|
|
559
|
+
const args = Array.isArray(config.searchArgs) && config.searchArgs.length > 0
|
|
560
|
+
? config.searchArgs
|
|
561
|
+
: DEFAULTS.searchArgs
|
|
562
|
+
return { command, args }
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export function pickArgs(args, allowed) {
|
|
566
|
+
const out = {}
|
|
567
|
+
for (const [key, value] of Object.entries(args ?? {})) {
|
|
568
|
+
if (allowed.includes(key) && value !== undefined && value !== null && value !== '') {
|
|
569
|
+
out[key] = value
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return out
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
export async function nativeViaMcpPool(config, kind, argsObj, timeoutMs, signal) {
|
|
576
|
+
const { command, args } = resolveEntry(config)
|
|
577
|
+
const conn = await acquireMcp({
|
|
578
|
+
command,
|
|
579
|
+
args,
|
|
580
|
+
idleMs: config.searchIdleMs ?? DEFAULTS.searchIdleMs,
|
|
581
|
+
max: config.searchConcurrency ?? DEFAULTS.searchConcurrency,
|
|
582
|
+
initMs: timeoutMs,
|
|
583
|
+
credentials: config.credentials,
|
|
584
|
+
config,
|
|
585
|
+
}, signal)
|
|
586
|
+
const result = await new Promise((resolve, reject) => {
|
|
587
|
+
const onAbort = () => reject(argoAborted())
|
|
588
|
+
if (signal !== undefined) {
|
|
589
|
+
if (signal.aborted) {
|
|
590
|
+
conn.release()
|
|
591
|
+
reject(argoAborted())
|
|
592
|
+
return
|
|
593
|
+
}
|
|
594
|
+
signal.addEventListener('abort', onAbort, { once: true })
|
|
595
|
+
}
|
|
596
|
+
conn.request('tools/call', { name: kind, arguments: argsObj }, timeoutMs).then((value) => {
|
|
597
|
+
if (signal !== undefined) signal.removeEventListener('abort', onAbort)
|
|
598
|
+
resolve(value)
|
|
599
|
+
}, (err) => {
|
|
600
|
+
if (signal !== undefined) signal.removeEventListener('abort', onAbort)
|
|
601
|
+
reject(err)
|
|
602
|
+
})
|
|
603
|
+
})
|
|
604
|
+
if (result?.isError) {
|
|
605
|
+
const body = result?.content?.[0]?.text
|
|
606
|
+
throw argoToolError(typeof body === 'string' && body !== ''
|
|
607
|
+
? body
|
|
608
|
+
: `argo tool ${kind} returned an error`)
|
|
609
|
+
}
|
|
610
|
+
return JSON.stringify(result ?? {})
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
export function makeNativeTool(config, kind, deps = {}) {
|
|
614
|
+
const spec = NATIVE_TOOL_SPECS[kind]
|
|
615
|
+
if (!spec) {
|
|
616
|
+
throw new Error(`argo-dsh: unknown native tool "${kind}" (known: ${Object.keys(NATIVE_TOOL_SPECS).join(', ')})`)
|
|
617
|
+
}
|
|
618
|
+
const spawnRun = deps.run ?? runNativeCall
|
|
619
|
+
const mcpCall = deps.mcpCall ?? nativeViaMcpPool
|
|
620
|
+
const forceSpawn = deps.run !== undefined && deps.mcpCall === undefined
|
|
621
|
+
|
|
622
|
+
const currentTimeout = () => {
|
|
623
|
+
const value = Number(config.nativeTimeoutMs)
|
|
624
|
+
return Number.isFinite(value) && value > 0 ? value : DEFAULTS.nativeTimeoutMs
|
|
625
|
+
}
|
|
626
|
+
const currentMaxChars = () => {
|
|
627
|
+
const value = Number(config.nativeMaxChars)
|
|
628
|
+
return Number.isFinite(value) && value > 0 ? value : DEFAULTS.nativeMaxChars
|
|
629
|
+
}
|
|
630
|
+
return {
|
|
631
|
+
name: kind,
|
|
632
|
+
description: spec.description,
|
|
633
|
+
parameters: spec.parameters,
|
|
634
|
+
isConcurrencySafe: () => true,
|
|
635
|
+
output: {
|
|
636
|
+
schema: { type: 'object' },
|
|
637
|
+
render: (_args, value) => {
|
|
638
|
+
let body = ''
|
|
639
|
+
try {
|
|
640
|
+
const parsed = JSON.parse(value.stdout)
|
|
641
|
+
body = parsed?.content?.[0]?.text ?? value.stdout
|
|
642
|
+
} catch {
|
|
643
|
+
body = value.stdout
|
|
644
|
+
}
|
|
645
|
+
return text(clip(body, currentMaxChars()))
|
|
646
|
+
},
|
|
647
|
+
},
|
|
648
|
+
async execute(args, exec) {
|
|
649
|
+
const argsObj = pickArgs(args, spec.allowed)
|
|
650
|
+
const payload = JSON.stringify(argsObj)
|
|
651
|
+
const timeoutMs = currentTimeout()
|
|
652
|
+
const signal = exec?.signal
|
|
653
|
+
if (!forceSpawn) {
|
|
654
|
+
try {
|
|
655
|
+
return { stdout: await mcpCall(config, kind, argsObj, timeoutMs, signal) }
|
|
656
|
+
} catch (err) {
|
|
657
|
+
if (err?.code === 'ARGO_TOOL_ERROR' || err?.code === 'ARGO_TIMEOUT' || err?.code === 'WEB_ABORTED') throw err
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
const spawnSpec = resolveNativeSpawn(config, kind, payload)
|
|
661
|
+
const env = await resolveEnv(undefined, config)
|
|
662
|
+
const stdout = await spawnRun(env !== undefined ? { ...spawnSpec, env } : spawnSpec, timeoutMs, signal)
|
|
663
|
+
return { stdout }
|
|
664
|
+
},
|
|
665
|
+
}
|
|
666
|
+
}
|