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,201 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
social_research.py — 社交舆情研究模块(从 research.py 拆分)
|
|
4
|
+
|
|
5
|
+
承载跨平台 UGC 情绪与讨论分析:
|
|
6
|
+
- social_sentiment_research:并行抓取多平台 → 互动聚合 → 话题提取
|
|
7
|
+
- aggregate_social_sentiment:MCP argo_social_search mode=sentiment 用
|
|
8
|
+
- _extract_topics:中英文兼容话题提取
|
|
9
|
+
- _print_social_report:终端报告输出
|
|
10
|
+
|
|
11
|
+
从 research.py 拆分以控制文件规模(code-review:单文件 <1k 行)。
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import time
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
from bounded_run import run_bounded, TaskError
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def social_sentiment_research(query: str, platforms: list[str] | None = None,
|
|
23
|
+
max_results: int = 5) -> dict[str, Any]:
|
|
24
|
+
"""社交舆情研究:跨平台 UGC 情绪与讨论分析"""
|
|
25
|
+
if platforms is None:
|
|
26
|
+
platforms = ["twitter", "reddit", "xiaohongshu"]
|
|
27
|
+
|
|
28
|
+
from search import super_search
|
|
29
|
+
|
|
30
|
+
platform_results: dict[str, list] = {}
|
|
31
|
+
all_results: list[dict] = []
|
|
32
|
+
engines_used: set[str] = set()
|
|
33
|
+
t0 = time.time()
|
|
34
|
+
|
|
35
|
+
def _one(platform: str) -> tuple[str, list[dict], set[str]]:
|
|
36
|
+
try:
|
|
37
|
+
result = super_search(query, engine=platform, n=max_results, mode="fast")
|
|
38
|
+
return platform, result.get("results", []), set(result.get("engines_used", []))
|
|
39
|
+
except Exception:
|
|
40
|
+
return platform, [], set()
|
|
41
|
+
|
|
42
|
+
# 并行抓取各平台(串行时 3 平台 × 秒级延迟累积;并行取最慢平台耗时)。
|
|
43
|
+
# 总时限 90s:到点就拿已完成部分返回,没完成的平台记空结果,不再被卡住的
|
|
44
|
+
# 平台拖住、也不会因超时异常中断整次调用。
|
|
45
|
+
social_errors: list[str] = []
|
|
46
|
+
finished, unfinished = run_bounded(
|
|
47
|
+
platforms, _one, 90.0, max_workers=min(max(len(platforms), 1), 4))
|
|
48
|
+
for platform, value in finished:
|
|
49
|
+
if isinstance(value, TaskError):
|
|
50
|
+
platform_results[platform] = []
|
|
51
|
+
social_errors.append(f"{platform}: {type(value.exc).__name__}")
|
|
52
|
+
continue
|
|
53
|
+
_platform, results, used = value
|
|
54
|
+
platform_results[_platform] = results
|
|
55
|
+
all_results.extend(results)
|
|
56
|
+
engines_used.update(used)
|
|
57
|
+
for platform in unfinished:
|
|
58
|
+
platform_results[platform] = []
|
|
59
|
+
social_errors.append(f"{platform}: timeout (>90s)")
|
|
60
|
+
|
|
61
|
+
# 互动数据聚合
|
|
62
|
+
engagement_totals = {"likes": 0, "comments": 0, "shares": 0, "views": 0}
|
|
63
|
+
titles: list[str] = []
|
|
64
|
+
|
|
65
|
+
for r in all_results:
|
|
66
|
+
meta = r.get("social_meta", {})
|
|
67
|
+
if isinstance(meta, dict):
|
|
68
|
+
engagement_totals["likes"] += meta.get("likes", meta.get("upvotes", meta.get("attitudes_count", 0)))
|
|
69
|
+
engagement_totals["comments"] += meta.get("comments", meta.get("num_comments", 0))
|
|
70
|
+
engagement_totals["shares"] += meta.get("shares", meta.get("retweets", meta.get("reposts_count", 0)))
|
|
71
|
+
engagement_totals["views"] += meta.get("views", meta.get("play_count", 0))
|
|
72
|
+
# 收集标题用于话题提取
|
|
73
|
+
title = r.get("title", "")
|
|
74
|
+
if title:
|
|
75
|
+
titles.append(title)
|
|
76
|
+
|
|
77
|
+
# 中英文兼容的话题提取
|
|
78
|
+
top_topics_list = _extract_topics(titles, top_k=10)
|
|
79
|
+
elapsed = int((time.time() - t0) * 1000)
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
"query": query,
|
|
83
|
+
"mode": "social-sentiment",
|
|
84
|
+
"platforms": platforms,
|
|
85
|
+
"total_posts": len(all_results),
|
|
86
|
+
"platform_breakdown": {p: len(r) for p, r in platform_results.items()},
|
|
87
|
+
"engagement_totals": engagement_totals,
|
|
88
|
+
"top_topics": top_topics_list,
|
|
89
|
+
"cross_platform_posts": [
|
|
90
|
+
{
|
|
91
|
+
"platform": r.get("source", ""),
|
|
92
|
+
"title": r.get("title", "")[:100],
|
|
93
|
+
"url": r.get("url", ""),
|
|
94
|
+
"snippet": r.get("snippet", "")[:200],
|
|
95
|
+
"social_meta": r.get("social_meta", {}),
|
|
96
|
+
}
|
|
97
|
+
for r in all_results[:15]
|
|
98
|
+
],
|
|
99
|
+
"engines_used": sorted(engines_used),
|
|
100
|
+
"errors": social_errors,
|
|
101
|
+
"elapsed_ms": elapsed,
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def aggregate_social_sentiment(query: str, platforms: list[str],
|
|
106
|
+
platform_results: dict[str, list]) -> dict[str, Any]:
|
|
107
|
+
"""社交舆情聚合(MCP argo_social_search mode=sentiment 用)。
|
|
108
|
+
|
|
109
|
+
输入为按平台分组的已抓取帖子(social_engines 输出,含 social_meta),
|
|
110
|
+
聚合互动数据汇总与平台分布,限流返回代表性帖子。原为 MCP 分发层的
|
|
111
|
+
内联逻辑,下沉到本模块避免逻辑放错层。
|
|
112
|
+
"""
|
|
113
|
+
all_posts: list = []
|
|
114
|
+
for p in platforms:
|
|
115
|
+
all_posts.extend(platform_results.get(p) or [])
|
|
116
|
+
|
|
117
|
+
engagement_totals = {"likes": 0, "comments": 0, "reposts": 0, "shares": 0}
|
|
118
|
+
for post in all_posts:
|
|
119
|
+
meta = post.get("social_meta", {}) if isinstance(post, dict) else {}
|
|
120
|
+
engagement_totals["likes"] += meta.get("likes", 0) or meta.get("like_count", 0) or 0
|
|
121
|
+
engagement_totals["comments"] += meta.get("comments", 0) or 0
|
|
122
|
+
engagement_totals["reposts"] += meta.get("reposts", 0) or 0
|
|
123
|
+
engagement_totals["shares"] += meta.get("shares", 0) or 0
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
"query": query,
|
|
127
|
+
"platforms": platforms,
|
|
128
|
+
"platform_breakdown": {p: len(platform_results.get(p) or []) for p in platforms},
|
|
129
|
+
"total_posts": len(all_posts),
|
|
130
|
+
"engagement_totals": engagement_totals,
|
|
131
|
+
"posts": all_posts[:30], # 限流
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _extract_topics(titles: list[str], top_k: int = 10) -> list[dict]:
|
|
136
|
+
"""从标题列表提取话题(中英文兼容)。
|
|
137
|
+
|
|
138
|
+
英文用 split() 分词,中文用字符级 bigram。
|
|
139
|
+
过滤单字停用词,返回 top_k 个话题。
|
|
140
|
+
"""
|
|
141
|
+
import re
|
|
142
|
+
from collections import Counter
|
|
143
|
+
|
|
144
|
+
chinese_stopwords = set(
|
|
145
|
+
'的了是在和我你她他它这就也不很但而或如果因为所以而且或者虽然但是可以应该需要已经正在'
|
|
146
|
+
'之前之后时候地方问题工作生活东西事情时间今天昨天明天今年去年明年个些吗呢啊吧哦嗯哈'
|
|
147
|
+
'呀嘛哪谁什么怎么多少几样种类下上里中后前时来回过开给让把被对从向比跟和与及当比'
|
|
148
|
+
'如例包括相关关于根据通过进行使用作为成为具有属于位于来自获得达到实现完成产生形成'
|
|
149
|
+
'存在发生发展提供包含涉及适用于'
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
topic_counter = Counter()
|
|
153
|
+
|
|
154
|
+
for title in titles:
|
|
155
|
+
# 英文分词(仅保留长度 >= 3 的词)
|
|
156
|
+
en_words = re.findall(r'[a-zA-Z]{2,}', title.lower())
|
|
157
|
+
for w in en_words:
|
|
158
|
+
if len(w) >= 3:
|
|
159
|
+
topic_counter[w] += 1
|
|
160
|
+
|
|
161
|
+
# 中文 bigram(连续 2 个中文字符)
|
|
162
|
+
chinese_chars = re.findall(r'[一-鿿]', title)
|
|
163
|
+
for i in range(len(chinese_chars) - 1):
|
|
164
|
+
bigram = chinese_chars[i] + chinese_chars[i + 1]
|
|
165
|
+
if bigram[0] not in chinese_stopwords and bigram[1] not in chinese_stopwords:
|
|
166
|
+
topic_counter[bigram] += 1
|
|
167
|
+
|
|
168
|
+
return [{"topic": t, "mentions": c} for t, c in topic_counter.most_common(top_k)]
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _print_social_report(report: dict):
|
|
172
|
+
"""打印社交舆情报告"""
|
|
173
|
+
print(f"\n{'='*60}")
|
|
174
|
+
print(f"社交舆情分析:{report['query']}")
|
|
175
|
+
print(f"{'='*60}")
|
|
176
|
+
print(f"平台:{', '.join(report['platforms'])} | 引擎:{', '.join(report['engines_used'])}")
|
|
177
|
+
print(f"抓取帖子:{report['total_posts']} | 耗时:{report['elapsed_ms']}ms")
|
|
178
|
+
print()
|
|
179
|
+
print("── 平台分布 ──")
|
|
180
|
+
for platform, count in report["platform_breakdown"].items():
|
|
181
|
+
print(f" {platform}: {count} 条")
|
|
182
|
+
print()
|
|
183
|
+
print("── 互动数据汇总 ──")
|
|
184
|
+
eng = report["engagement_totals"]
|
|
185
|
+
print(f" 点赞/投票:{eng['likes']:,} | 评论:{eng['comments']:,} | 转发:{eng['shares']:,} | 观看:{eng['views']:,}")
|
|
186
|
+
print()
|
|
187
|
+
print("── 高频讨论话题 ──")
|
|
188
|
+
for topic in report["top_topics"]:
|
|
189
|
+
print(f" 「{topic['topic']}」 ({topic['mentions']} 次)")
|
|
190
|
+
print()
|
|
191
|
+
print("── 代表性内容 ──")
|
|
192
|
+
for post in report["cross_platform_posts"][:5]:
|
|
193
|
+
meta = post.get("social_meta", {})
|
|
194
|
+
engagement = ""
|
|
195
|
+
if isinstance(meta, dict):
|
|
196
|
+
likes = meta.get("likes", meta.get("upvotes", meta.get("attitudes_count", 0)))
|
|
197
|
+
comments = meta.get("comments", meta.get("num_comments", 0))
|
|
198
|
+
engagement = f" | 👍{likes} 💬{comments}"
|
|
199
|
+
print(f" [{post['platform']}] {post['title'][:60]}{engagement}")
|
|
200
|
+
print(f" {post['url']}")
|
|
201
|
+
print()
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""搜狗微信搜索·浏览器兜底通道(ego-browser,纯标准库)。
|
|
3
|
+
|
|
4
|
+
定位:HTTP 快车道 wechat_sogou(engines_builders_tech._build_wechat_sogou_engine)
|
|
5
|
+
被搜狗反爬墙拦截(302 antispiderwall,实测 raw curl 第 2 次查询即触发)时的
|
|
6
|
+
域内兜底车道——借 ego-browser 驱动用户默认浏览器(Ego Lite)里的真实会话拉取
|
|
7
|
+
weixin.sogou.com 结果页:指纹与 cookie 连续,2026-09-30 实测连查无风控。
|
|
8
|
+
|
|
9
|
+
与 HTTP 车道输出同构(字段语义对齐):
|
|
10
|
+
- published_at:timeConvert('unix') → 本时区 ISO(同 HTTP 车道格式)
|
|
11
|
+
- url_resolved:中间链解析成功 true / 失败回落中间链 false(同语义)
|
|
12
|
+
- 解析封顶:单轮 ≤5 条(同 _SOGOU_RESOLVE_MAX_PER_CALL),带 cookie 的
|
|
13
|
+
浏览器内 fetch 拉反爬 JS 页,`url += '片段'` 拼回真实链接
|
|
14
|
+
- account 字段 CLI 解析器(_parse_yaml_output)不保留,折进 snippet 头部
|
|
15
|
+
「公众号「X」 」前缀,信息不丢
|
|
16
|
+
|
|
17
|
+
会话复用:task space 与 page 持久化在状态文件 _state_path(),跨调用复用同一
|
|
18
|
+
浏览器页——保持指纹与 cookie 连续性正是本通道的降反爬手段,故刻意不走
|
|
19
|
+
task.finish()(ego-browser「默认关闭空间」之例外:结果必须留在浏览器里供
|
|
20
|
+
下一轮复用)。Ego Lite 重启后空间失效则自动新建。文件锁串行化并发调用;
|
|
21
|
+
调用间最小间隔默认 6 秒(状态文件记最近调用时刻),贴近 HTTP 车道的
|
|
22
|
+
域族节流量级。
|
|
23
|
+
|
|
24
|
+
依赖:ego-browser CLI。缺失 / Ego Lite 未运行 / 反爬墙拦截 → stderr 报因、
|
|
25
|
+
退出码 1(argo _run 对 rc!=0 只取 stderr 留痕,引擎返回空,路由轮到下一候选)。
|
|
26
|
+
|
|
27
|
+
用法:
|
|
28
|
+
python3 scripts/sogou_weixin_browser.py "<query>" --n 5
|
|
29
|
+
python3 scripts/sogou_weixin_browser.py "<query>" --resolve-limit 3 --min-interval 8
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
from __future__ import annotations
|
|
33
|
+
|
|
34
|
+
import argparse
|
|
35
|
+
import fcntl
|
|
36
|
+
import json
|
|
37
|
+
import os
|
|
38
|
+
import re
|
|
39
|
+
import shutil
|
|
40
|
+
import subprocess
|
|
41
|
+
import sys
|
|
42
|
+
import tempfile
|
|
43
|
+
import time
|
|
44
|
+
from datetime import datetime
|
|
45
|
+
from urllib.parse import quote
|
|
46
|
+
|
|
47
|
+
def _state_path() -> str:
|
|
48
|
+
"""登录态文件路径:ARGO_STATE_DIR 显式隔离时跟随,否则维持历史位置。
|
|
49
|
+
|
|
50
|
+
存量优先:默认仍用 ~/.config/argo/(老用户登录态原地复用,不静默搬家);
|
|
51
|
+
测试/多实例隔离设 ARGO_STATE_DIR 后登录态随状态根走,互不共享。
|
|
52
|
+
"""
|
|
53
|
+
override = os.environ.get("ARGO_STATE_DIR", "").strip()
|
|
54
|
+
if override:
|
|
55
|
+
return os.path.join(os.path.expanduser(override),
|
|
56
|
+
"sogou_weixin_browser.json")
|
|
57
|
+
return os.path.expanduser("~/.config/argo/sogou_weixin_browser.json")
|
|
58
|
+
DEFAULT_MIN_INTERVAL = 6.0 # 调用间最小间隔(秒),贴近域族节流量级
|
|
59
|
+
MIN_INTERVAL_CAP = 20.0 # 补睡封顶:状态漂移时不至于睡死
|
|
60
|
+
JS_RESULT_WAIT_S = 15 # 浏览器内等结果/判反爬的墙钟
|
|
61
|
+
RESOLVE_FETCH_TIMEOUT_MS = 6000
|
|
62
|
+
SUBPROC_TIMEOUT = 70 # ego-browser 子进程墙钟封顶(argo spec timeout=75 先杀)
|
|
63
|
+
SOGOU_SEARCH_URL = "https://weixin.sogou.com/weixin?type={type}&query={query}&ie=utf8"
|
|
64
|
+
JSON_MARKER = "@@JSON@@"
|
|
65
|
+
|
|
66
|
+
# 反爬信号:与 HTTP 车道同一目标页,命中即宣告车道被墙
|
|
67
|
+
_ANTISPIDER_RE = re.compile(r"antispider|验证码|异常访问|请输入")
|
|
68
|
+
|
|
69
|
+
# JS 侧:结果抽取 + 中间链片段抓取。CFG 为 JSON 字面量(ensure_ascii 注入,
|
|
70
|
+
# 不存在引号/换行逃逸问题)。查询 URL 由 Python 拼好后注入,JS 不再做编码。
|
|
71
|
+
# 抽原始片段不在浏览器里拼接——拼接与校验放 Python 侧(_assemble_link),可离线单测。
|
|
72
|
+
_JS_TEMPLATE = """
|
|
73
|
+
const CFG = %(cfg)s;
|
|
74
|
+
let task = null;
|
|
75
|
+
if (CFG.spaceId) {
|
|
76
|
+
try { task = await taskSpace(CFG.spaceId); } catch (e) { task = null; }
|
|
77
|
+
}
|
|
78
|
+
if (!task) task = await taskSpace("argo 搜狗微信兜底");
|
|
79
|
+
let page = null;
|
|
80
|
+
try { page = task.page("p1"); } catch (e) { page = null; }
|
|
81
|
+
if (!page) page = await task.newPage();
|
|
82
|
+
await page.goto(%(search_url)s);
|
|
83
|
+
let blocked = false, got = false;
|
|
84
|
+
for (let i = 0; i < %(wait_s)d; i++) {
|
|
85
|
+
await page.waitForTimeout(1000);
|
|
86
|
+
const st = await page.evaluate(() => ({
|
|
87
|
+
n: document.querySelectorAll('li[id^="sogou_vr_11002601_box_"]').length,
|
|
88
|
+
text: document.body.innerText.slice(0, 2500),
|
|
89
|
+
}));
|
|
90
|
+
if (/(antispider|验证码|异常访问|请输入)/.test(st.text)) { blocked = true; break; }
|
|
91
|
+
if (st.n > 0) { got = true; break; }
|
|
92
|
+
}
|
|
93
|
+
let items = [];
|
|
94
|
+
if (!blocked) {
|
|
95
|
+
items = await page.evaluate(() => {
|
|
96
|
+
const out = [];
|
|
97
|
+
for (const li of document.querySelectorAll('li[id^="sogou_vr_11002601_box_"]')) {
|
|
98
|
+
const a = li.querySelector("h3 a");
|
|
99
|
+
if (!a) continue;
|
|
100
|
+
const info = li.querySelector(".txt-info");
|
|
101
|
+
const acc = li.querySelector(".all-time-y2");
|
|
102
|
+
const tm = li.innerHTML.match(/timeConvert\\('?([0-9]{10})'?\\)/);
|
|
103
|
+
out.push({
|
|
104
|
+
title: a.innerText.trim(),
|
|
105
|
+
url: a.href,
|
|
106
|
+
snippet: info ? info.innerText.trim() : "",
|
|
107
|
+
account: acc ? acc.innerText.trim() : "",
|
|
108
|
+
epoch: tm ? tm[1] : "",
|
|
109
|
+
frag: [],
|
|
110
|
+
fallback_url: "",
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
});
|
|
115
|
+
let resolvedCount = 0;
|
|
116
|
+
for (const it of items) {
|
|
117
|
+
if (resolvedCount >= CFG.resolveLimit) break;
|
|
118
|
+
if (!/weixin\\.sogou\\.com.*(\\/link\\?|\\/weixin\\?)/.test(it.url)) continue;
|
|
119
|
+
try {
|
|
120
|
+
const resp = await page.fetch(it.url, { timeout: %(resolve_to_ms)d });
|
|
121
|
+
const body = String(resp.body || "");
|
|
122
|
+
const frags = [];
|
|
123
|
+
for (const m of body.matchAll(/url\\s*\\+=\\s*(['"])(.*?)\\1/g)) frags.push(m[2]);
|
|
124
|
+
const fb = body.match(/https?:\\/\\/mp\\.weixin\\.qq\\.com[^'"<>\\s]+/);
|
|
125
|
+
it.frag = frags;
|
|
126
|
+
it.fallback_url = fb ? fb[0] : "";
|
|
127
|
+
resolvedCount++;
|
|
128
|
+
} catch (e) { /* 解析失败保留中间链,Python 侧标 url_resolved=false */ }
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
console.log("%(marker)s" + JSON.stringify({
|
|
132
|
+
ok: !blocked,
|
|
133
|
+
space_id: task.spaceId,
|
|
134
|
+
blocked: blocked,
|
|
135
|
+
got: got,
|
|
136
|
+
items: items.slice(0, CFG.n),
|
|
137
|
+
}));
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _build_js(query: str, n: int, stype: int, resolve_limit: int,
|
|
142
|
+
space_id: object) -> str:
|
|
143
|
+
"""把配置注入 JS 模板。ensure_ascii 保证任意查询词的引号/换行/行分隔符全转义。"""
|
|
144
|
+
final_url = SOGOU_SEARCH_URL.format(type=stype, query=quote(query))
|
|
145
|
+
js = _JS_TEMPLATE % {
|
|
146
|
+
"cfg": json.dumps({"n": n, "resolveLimit": resolve_limit,
|
|
147
|
+
"spaceId": space_id}, ensure_ascii=True),
|
|
148
|
+
"search_url": json.dumps(final_url),
|
|
149
|
+
"wait_s": JS_RESULT_WAIT_S,
|
|
150
|
+
"resolve_to_ms": RESOLVE_FETCH_TIMEOUT_MS,
|
|
151
|
+
"marker": JSON_MARKER,
|
|
152
|
+
}
|
|
153
|
+
return js
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _assemble_link(frag: list | None, fallback_url: str | None,
|
|
157
|
+
original: str) -> tuple[str, bool]:
|
|
158
|
+
"""搜狗反爬 JS 页 → 真实链接。与 HTTP 车道 _resolve_sogou_link 同判据:
|
|
159
|
+
url += 片段拼接优先,拼不出 http(s) 时回落响应体内的 mp.weixin 直链,
|
|
160
|
+
再不行保留中间链并标 false(降级不丢结果)。入参容忍 None(JS 侧缺键)。"""
|
|
161
|
+
real = "".join(frag or [])
|
|
162
|
+
if real.startswith(("http://", "https://")):
|
|
163
|
+
return real, True
|
|
164
|
+
if (fallback_url or "").startswith(("http://", "https://")):
|
|
165
|
+
return fallback_url, True
|
|
166
|
+
return original, False
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _norm_published_at(epoch: str) -> str:
|
|
170
|
+
"""10 位 unix 秒 → 本时区 ISO(与 HTTP 车道 datetime.fromtimestamp().astimezone() 一致)。"""
|
|
171
|
+
if not epoch or not str(epoch).isdigit():
|
|
172
|
+
return ""
|
|
173
|
+
try:
|
|
174
|
+
return datetime.fromtimestamp(int(epoch)).astimezone().isoformat(timespec="seconds")
|
|
175
|
+
except (ValueError, OSError):
|
|
176
|
+
return ""
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _extract_json(stdout: str) -> dict | None:
|
|
180
|
+
"""从 ego-browser 输出里取标记行 JSON(CLI 可能夹杂 notice 行)。"""
|
|
181
|
+
for line in reversed((stdout or "").splitlines()):
|
|
182
|
+
if line.startswith(JSON_MARKER):
|
|
183
|
+
try:
|
|
184
|
+
return json.loads(line[len(JSON_MARKER):])
|
|
185
|
+
except json.JSONDecodeError:
|
|
186
|
+
continue
|
|
187
|
+
return None
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def _safe_state_path(p: str) -> str:
|
|
191
|
+
"""状态文件路径硬化:白名单限定在 ~/.config/argo/ 或系统临时目录(测试)
|
|
192
|
+
之内,显式拒绝 .. 段。路径是模块常量面,不随命令行开放。"""
|
|
193
|
+
norm = os.path.normpath(os.path.abspath(os.path.expanduser(p)))
|
|
194
|
+
if ".." in norm.split(os.sep):
|
|
195
|
+
raise ValueError(f"state 路径不允许包含 ..:{p}")
|
|
196
|
+
allowed_roots = [
|
|
197
|
+
os.path.realpath(os.path.expanduser("~/.config/argo")),
|
|
198
|
+
os.path.realpath(tempfile.gettempdir()),
|
|
199
|
+
]
|
|
200
|
+
# ARGO_STATE_DIR 隔离态:状态根也是合法落点(与 _state_path 的解析对齐)
|
|
201
|
+
_override = os.environ.get("ARGO_STATE_DIR", "").strip()
|
|
202
|
+
if _override:
|
|
203
|
+
allowed_roots.append(os.path.realpath(os.path.expanduser(_override)))
|
|
204
|
+
rp = os.path.realpath(norm)
|
|
205
|
+
if not any(rp == root or rp.startswith(root + os.sep) for root in allowed_roots):
|
|
206
|
+
raise ValueError(f"state 路径必须在 {' 或 '.join(allowed_roots)} 之内:{p}")
|
|
207
|
+
return rp
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _load_state(path: str) -> dict:
|
|
211
|
+
try:
|
|
212
|
+
with open(path, encoding="utf-8") as f:
|
|
213
|
+
return json.load(f)
|
|
214
|
+
except (OSError, json.JSONDecodeError):
|
|
215
|
+
return {}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _save_state(path: str, state: dict) -> None:
|
|
219
|
+
os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
|
|
220
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
221
|
+
json.dump(state, f, ensure_ascii=False)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def main(argv: list | None = None) -> int:
|
|
225
|
+
ap = argparse.ArgumentParser(description="搜狗微信搜索·浏览器兜底通道")
|
|
226
|
+
ap.add_argument("query")
|
|
227
|
+
ap.add_argument("--n", type=int, default=5)
|
|
228
|
+
ap.add_argument("--type", type=int, choices=(1, 2), default=2,
|
|
229
|
+
help="2=文章(默认)1=公众号")
|
|
230
|
+
ap.add_argument("--resolve-limit", type=int, default=5)
|
|
231
|
+
ap.add_argument("--min-interval", type=float, default=DEFAULT_MIN_INTERVAL)
|
|
232
|
+
args = ap.parse_args(argv)
|
|
233
|
+
try:
|
|
234
|
+
state_path = _safe_state_path(_state_path())
|
|
235
|
+
except ValueError as e:
|
|
236
|
+
print(f"sogou_weixin_browser: {e}", file=sys.stderr)
|
|
237
|
+
return 1
|
|
238
|
+
|
|
239
|
+
if not shutil.which("ego-browser"):
|
|
240
|
+
print("sogou_weixin_browser: ego-browser CLI 不存在(Ego Lite 未安装?)",
|
|
241
|
+
file=sys.stderr)
|
|
242
|
+
return 1
|
|
243
|
+
|
|
244
|
+
# 文件锁串行化:并发调用会争抢同一浏览器页(goto 竞态)与节流窗口
|
|
245
|
+
lock_path = state_path + ".lock"
|
|
246
|
+
os.makedirs(os.path.dirname(lock_path) or ".", exist_ok=True)
|
|
247
|
+
with open(lock_path, "w", encoding="utf-8") as lock_f:
|
|
248
|
+
fcntl.flock(lock_f, fcntl.LOCK_EX)
|
|
249
|
+
state = _load_state(state_path)
|
|
250
|
+
last_ts = float(state.get("last_ts") or 0)
|
|
251
|
+
wait = args.min_interval - (time.time() - last_ts)
|
|
252
|
+
if 0 < wait <= MIN_INTERVAL_CAP:
|
|
253
|
+
time.sleep(wait)
|
|
254
|
+
|
|
255
|
+
js = _build_js(args.query, args.n, args.type, args.resolve_limit,
|
|
256
|
+
state.get("space_id"))
|
|
257
|
+
try:
|
|
258
|
+
proc = subprocess.run(
|
|
259
|
+
["ego-browser", "nodejs", "-e", js],
|
|
260
|
+
capture_output=True, text=True, encoding="utf-8",
|
|
261
|
+
errors="replace", timeout=SUBPROC_TIMEOUT)
|
|
262
|
+
except subprocess.TimeoutExpired:
|
|
263
|
+
print(f"sogou_weixin_browser: ego-browser 超时(>{SUBPROC_TIMEOUT}s)",
|
|
264
|
+
file=sys.stderr)
|
|
265
|
+
return 1
|
|
266
|
+
except FileNotFoundError:
|
|
267
|
+
print("sogou_weixin_browser: ego-browser 调用失败", file=sys.stderr)
|
|
268
|
+
return 1
|
|
269
|
+
|
|
270
|
+
if proc.returncode != 0:
|
|
271
|
+
tail = (proc.stderr or "").strip()[:200]
|
|
272
|
+
print(f"sogou_weixin_browser: ego-browser rc={proc.returncode}: {tail}",
|
|
273
|
+
file=sys.stderr)
|
|
274
|
+
return 1
|
|
275
|
+
data = _extract_json(proc.stdout) or _extract_json(proc.stderr)
|
|
276
|
+
if not data:
|
|
277
|
+
print("sogou_weixin_browser: 未能解析 ego-browser 输出", file=sys.stderr)
|
|
278
|
+
return 1
|
|
279
|
+
|
|
280
|
+
# 空间句柄持久化(Ego Lite 重启后 taskSpace(id) 会抛错 → 下轮自动新建)
|
|
281
|
+
if data.get("space_id"):
|
|
282
|
+
state["space_id"] = data["space_id"]
|
|
283
|
+
state["last_ts"] = time.time()
|
|
284
|
+
_save_state(state_path, state)
|
|
285
|
+
|
|
286
|
+
if data.get("blocked"):
|
|
287
|
+
print("sogou_weixin_browser: 搜狗反爬墙拦截——请在浏览器打开 "
|
|
288
|
+
"weixin.sogou.com 手动通过验证后重试", file=sys.stderr)
|
|
289
|
+
return 1
|
|
290
|
+
if not data.get("ok"):
|
|
291
|
+
print("sogou_weixin_browser: 浏览器通道未取到结果页", file=sys.stderr)
|
|
292
|
+
return 1
|
|
293
|
+
|
|
294
|
+
rows = []
|
|
295
|
+
for it in data.get("items", []):
|
|
296
|
+
title = str(it.get("title") or "").strip()
|
|
297
|
+
url = str(it.get("url") or "").strip()
|
|
298
|
+
if not title and not url:
|
|
299
|
+
continue
|
|
300
|
+
real, resolved = _assemble_link(it.get("frag"), it.get("fallback_url"), url)
|
|
301
|
+
snippet = str(it.get("snippet") or "").strip()[:200]
|
|
302
|
+
account = str(it.get("account") or "").strip()
|
|
303
|
+
if account:
|
|
304
|
+
snippet = f"公众号「{account}」 {snippet}".strip()
|
|
305
|
+
row = {"title": title[:80], "url": real, "snippet": snippet}
|
|
306
|
+
published = _norm_published_at(it.get("epoch", ""))
|
|
307
|
+
if published:
|
|
308
|
+
row["published_at"] = published
|
|
309
|
+
row["url_resolved"] = resolved
|
|
310
|
+
rows.append(row)
|
|
311
|
+
|
|
312
|
+
import yaml
|
|
313
|
+
print(yaml.safe_dump(rows[: max(1, args.n)], allow_unicode=True, sort_keys=False))
|
|
314
|
+
return 0
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
if __name__ == "__main__":
|
|
318
|
+
sys.exit(main())
|