argo-search 2.14.1 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/AGENTS.md +8 -6
  2. package/README.es.md +54 -832
  3. package/README.ja.md +53 -833
  4. package/README.ko.md +53 -831
  5. package/README.md +126 -769
  6. package/README.zh.md +124 -893
  7. package/SKILL.md +17 -18
  8. package/assets/readme/counts.json +1 -1
  9. package/assets/readme/hero.svg +23 -23
  10. package/backends/concept_vectors.bin +0 -0
  11. package/backends/domain_profiles.json +42 -0
  12. package/backends/engine_concept_vectors.json +1525 -1525
  13. package/backends/engine_registry.yaml +124 -28
  14. package/backends/quota_profiles.json +70 -0
  15. package/bin/argo +30 -17
  16. package/config.yaml +173 -33
  17. package/docs/ADDING_NEW_ENGINE.md +10 -0
  18. package/docs/ARGO_INTRO.md +1 -1
  19. package/docs/CHANGELOG.md +23 -0
  20. package/docs/ENGINE_CATALOG.md +97 -85
  21. package/docs/MCP_SETUP.md +1 -1
  22. package/docs/RELEASE_NOTES_v2.14.1.md +4 -4
  23. package/docs/RELEASE_NOTES_v2.15.0.md +50 -0
  24. package/docs/RELEASING.md +1 -1
  25. package/engines/specs/ai_labs.yaml +89 -0
  26. package/engines/specs/bilibili_hot.yaml +11 -1
  27. package/engines/specs/brave.yaml +3 -3
  28. package/engines/specs/cisa_alerts.yaml +40 -0
  29. package/engines/specs/cn_ai_news.yaml +10 -8
  30. package/engines/specs/digup.yaml +11 -6
  31. package/engines/specs/douyin_hot.yaml +11 -1
  32. package/engines/specs/dw_news.yaml +4 -2
  33. package/engines/specs/eng_blogs.yaml +63 -0
  34. package/engines/specs/europeana.yaml +3 -4
  35. package/engines/specs/felo.yaml +3 -3
  36. package/engines/specs/firecrawl.yaml +3 -0
  37. package/engines/specs/fourget.yaml +5 -2
  38. package/engines/specs/france24.yaml +6 -4
  39. package/engines/specs/fxtwitter.yaml +29 -6
  40. package/engines/specs/grepapp_mcp.yaml +62 -0
  41. package/engines/specs/guardian_rss.yaml +6 -4
  42. package/engines/specs/itotii.yaml +13 -1
  43. package/engines/specs/lobsters.yaml +41 -0
  44. package/engines/specs/local_seek.yaml +6 -0
  45. package/engines/specs/open_meteo.yaml +1 -1
  46. package/engines/specs/redskill.yaml +2 -0
  47. package/engines/specs/searxng.yaml +4 -2
  48. package/engines/specs/sec_edgar.yaml +8 -3
  49. package/engines/specs/tinyfish.yaml +2 -0
  50. package/engines/specs/tinyfish_news.yaml +2 -0
  51. package/engines/specs/tinyfish_paper.yaml +2 -0
  52. package/engines/specs/toutiao_hot.yaml +11 -1
  53. package/engines/specs/train.yaml +3 -0
  54. package/engines/specs/twitter.yaml +4 -0
  55. package/engines/specs/unpaywall.yaml +6 -0
  56. package/engines/specs/vam.yaml +17 -3
  57. package/engines/specs/weibo_hot.yaml +11 -1
  58. package/engines/specs/wolframalpha.yaml +3 -3
  59. package/engines/specs/xiaohongshu.yaml +2 -0
  60. package/engines/specs/zhihu.yaml +3 -18
  61. package/engines/specs/zhihu_kb.yaml +18 -0
  62. package/engines/specs/zhihu_questions.yaml +19 -0
  63. package/package.json +3 -2
  64. package/packages/dsh-plugin/README.md +9 -14
  65. package/packages/dsh-plugin/dsh/client.js +467 -1024
  66. package/packages/dsh-plugin/dsh/diagnostics.js +71 -20
  67. package/packages/dsh-plugin/dsh/runner.js +2 -0
  68. package/packages/dsh-plugin/package.json +8 -3
  69. package/packages/dsh-plugin/scripts/sync-local.mjs +87 -0
  70. package/packages/dsh-plugin/scripts/sync-local.sh +13 -1
  71. package/packages/dsh-plugin/test/diagnostics.test.js +38 -1
  72. package/packages/dsh-plugin/test/size-gate.test.js +2 -9
  73. package/scripts/adaptive.py +7 -1
  74. package/scripts/archive_run.py +112 -53
  75. package/scripts/argo_paths.py +40 -3
  76. package/scripts/badcase_ledger.py +108 -9
  77. package/scripts/build_concept_table.py +112 -55
  78. package/scripts/cache.py +5 -1
  79. package/scripts/caliber_isolation.py +60 -23
  80. package/scripts/circuit_breaker.py +56 -8
  81. package/scripts/cli_io.py +20 -2
  82. package/scripts/config_cache.py +31 -0
  83. package/scripts/daemon.py +146 -51
  84. package/scripts/dormant_ledger.py +23 -9
  85. package/scripts/engine_dispatch.py +3 -3
  86. package/scripts/engine_env.py +182 -1
  87. package/scripts/engine_families.py +50 -7
  88. package/scripts/engine_states.py +3 -50
  89. package/scripts/engine_validate.py +13 -45
  90. package/scripts/engines.py +15 -31
  91. package/scripts/engines_base.py +42 -58
  92. package/scripts/engines_builders.py +0 -15
  93. package/scripts/engines_builders_batch10.py +346 -100
  94. package/scripts/engines_builders_batch11.py +2 -75
  95. package/scripts/engines_builders_batch9.py +15 -24
  96. package/scripts/engines_builders_cn.py +0 -194
  97. package/scripts/engines_builders_feeds.py +55 -5
  98. package/scripts/engines_builders_intl.py +15 -115
  99. package/scripts/engines_builders_pixiv.py +2 -16
  100. package/scripts/engines_builders_search.py +7 -14
  101. package/scripts/engines_builders_tech.py +5 -14
  102. package/scripts/engines_builders_weather.py +236 -0
  103. package/scripts/engines_fields.py +91 -0
  104. package/scripts/engines_http.py +135 -0
  105. package/scripts/engines_mcp.py +383 -0
  106. package/scripts/engines_parsers.py +13 -369
  107. package/scripts/engines_schema_drift.py +260 -0
  108. package/scripts/evidence.py +13 -0
  109. package/scripts/evidence_loop.py +4 -3
  110. package/scripts/fetch_jsrun.py +15 -11
  111. package/scripts/fetch_v3.py +28 -28
  112. package/scripts/fulltext_store.py +42 -1
  113. package/scripts/fxtwitter_api.py +8 -7
  114. package/scripts/gen_engine_catalog.py +2 -2
  115. package/scripts/general_pool.py +15 -4
  116. package/scripts/health_check.py +1 -1
  117. package/scripts/link_source.py +65 -24
  118. package/scripts/local_seek_adapter.py +57 -17
  119. package/scripts/mcp_handlers.py +53 -31
  120. package/scripts/mcp_handlers_surface.py +6 -18
  121. package/scripts/mcp_transport.py +1 -1
  122. package/scripts/min_version_scan.py +7 -3
  123. package/scripts/network_aware.py +7 -13
  124. package/scripts/pre-commit +45 -43
  125. package/scripts/query_understanding.py +30 -6
  126. package/scripts/quota.py +6 -1
  127. package/scripts/rank_signals.py +9 -0
  128. package/scripts/recompute.py +15 -5
  129. package/scripts/recovery.py +21 -15
  130. package/scripts/release.py +14 -26
  131. package/scripts/release_check.py +5 -25
  132. package/scripts/replay_eval.py +2 -2
  133. package/scripts/research_cli.py +40 -0
  134. package/scripts/research_notes.py +368 -0
  135. package/scripts/route.py +32 -70
  136. package/scripts/route_audit.py +259 -0
  137. package/scripts/route_combo.py +10 -4
  138. package/scripts/route_domains.py +150 -23
  139. package/scripts/route_lang.py +20 -7
  140. package/scripts/route_log.py +26 -9
  141. package/scripts/route_policy.py +85 -6
  142. package/scripts/route_telemetry_export.py +199 -0
  143. package/scripts/rrf_classic.py +5 -22
  144. package/scripts/search.py +2 -1
  145. package/scripts/search_attribution.py +33 -10
  146. package/scripts/search_entry.py +5 -1
  147. package/scripts/search_output.py +5 -4
  148. package/scripts/search_pipeline.py +12 -0
  149. package/scripts/search_rank.py +21 -11
  150. package/scripts/semantic_evidence.py +375 -168
  151. package/scripts/settings_page.py +3 -3
  152. package/scripts/social_engines/xiaohongshu_engine.py +2 -1
  153. package/scripts/social_engines/zhihu_engine.py +251 -43
  154. package/scripts/sogou_weixin_browser.py +5 -6
  155. package/scripts/source_audit.py +2 -2
  156. package/scripts/source_ledger.py +2 -15
  157. package/scripts/source_selection.py +45 -20
  158. package/scripts/straggler_policy.py +1 -2
  159. package/scripts/sync_backends.py +17 -0
  160. package/scripts/tfidf_router.py +23 -11
  161. package/scripts/time_utils.py +54 -1
  162. package/scripts/train.py +68 -2
  163. package/scripts/usage_log.py +26 -1
  164. package/sub-skills/argo-wide-research/SKILL.md +68 -0
  165. package/sub-skills/ego-search/SKILL.md +1 -1
  166. package/sub-skills/local-seek/scripts/seek_fts.py +58 -3
  167. package/scripts/caliber_dedupe.py +0 -66
  168. package/scripts/engines_builders_batch16.py +0 -13
  169. package/scripts/health_probe.py +0 -253
  170. package/scripts/social_engines/twitter_engine.py +0 -514
  171. package/scripts/sync_installs.py +0 -29
@@ -19,8 +19,13 @@
19
19
  | `patterns` | 触发词列表,每项是字符串或 `{match, unless}` |
20
20
  | `patterns[].match` | 正向触发词:命中即候选 |
21
21
  | `patterns[].unless` | **该触发词**的否决词:命中则这一条不算(**不要**手写 `^(?!.*...)`) |
22
+ | `priority` | 域优先级分(零基/乱序无关的主域裁决权重,未写按配置序兜底) |
23
+ | `intents` | 域回答的查询意图标签列表(如 `social` / `news` / `compare`) |
24
+ | `zh_lang_gated` | 是否开启非中文查询屏蔽门(跳过日/韩/英等非中文查询) |
25
+ | `pure_combo` | 保持纯结构化路径,不混入通用/地理/次域补充源(如 `modal_card`) |
26
+ | `zh_filter_en_only` | 中文查询时剔除 `langs=["en"]` 纯英文专源(如 `academic`/`tech_deep`) |
22
27
  | `intent_required` | 点查域意图豁免词:长主题句下必须命中其一,否则让位 |
23
- | `engines_combo` / `primary` / `parallel` / `no_early_stop` | 命中之后怎么执行(route_combo 消费) |
28
+ | `engines_combo` / `primary` / `parallel` / `no_early_stop` | 命中之后怎么执行(route_combo / route_policy 消费) |
24
29
 
25
30
  `unless` 与 `intent_required` 是同一件事的两面,都在回答「什么情况下这条命中
26
31
  是假的」:前者是「查询里出现了别的语义」,后者是「查询里缺了本域的语义」。
@@ -479,6 +484,22 @@ _UNLESS_MACROS: dict[str, str] = {
479
484
  "@compare_or_award": (
480
485
  r"(?i)(区别|比较|对比|怎么选|哪个好|优劣|利弊|差异|权衡|\bvs\b|得主|获奖)"
481
486
  ),
487
+ # 社交平台语境否决集(2026-11-15):X/小红书/reddit 等平台名是**内容来源**,
488
+ # 不是论文主题。「X 上对 GPT-6 的评价」实测落 academic,arXiv 返回粒子物理
489
+ # 的 X(1870)/X(2370) 论文;「reddit 上对 rust 的讨论」落 chinese_tech_deep。
490
+ # 根因是主域打分 `span_len*2 - idx*0.1`:两域 span 相同时域序决定胜负,
491
+ # 而 academic(idx 75) 排在 social(idx 98) 前 23 位。
492
+ #
493
+ # **必须是「社交语境 ∧ 无论文词」的复合守卫**:实测裸社交词作 unless 会
494
+ # 误伤 6/8 真论文查询(「基于微博数据的舆情分析 论文」「Twitter 情感分析
495
+ # 研究综述」「GPT 评价指标 综述」)。本宏用负向前瞻把论文词排除在外。
496
+ # 复用方式:触发词条目的 unless 引用 `@social_context`,不要展开。
497
+ "@social_context": (
498
+ r"(?i)(?:推特|twitter|小红书|reddit|微博|知乎|\bX\s+上\b|\bX\s+平台\b|网友|热议|"
499
+ r"评价|测评|讨论|评论|帖子|点评|口碑)"
500
+ r"(?![\s\S]*(?:论文|paper|综述|文献|期刊|arXiv|DOI|研究|实验|数据集|dataset|"
501
+ r"survey|preprint|引用|学报|学术))"
502
+ ),
482
503
  # 本地/免 key 镜像通道否决集(2026-11-04):`local_*` 六个域是用户**显式
483
504
  # 选择**本地化通道的意图(`references/usage.md`:「local_ 前缀是本地化/免 key
484
505
  # 镜像通道」),但它们在 config 里排在末尾(idx 92-97),而域匹配先到先得——
@@ -505,6 +526,26 @@ _UNLESS_MACROS: dict[str, str] = {
505
526
  ),
506
527
  }
507
528
 
529
+ # 平台语境 → 平台原生源(2026-11-15):@social_context 守卫把平台查询从
530
+ # 论文/技术域救回 social 后,主位仍是域默认的 zhihu——「推特上大家对 GPT
531
+ # 的评价」主位给 zhihu 等于没接平台。原生源在 combo 内则扶正主位,不在则
532
+ # 顶替注入(见 route._route_by_domain 的消费点)。触发词收窄判据与
533
+ # @social_context 一致:裸「X」会撞 X(1870) 粒子物理与变量名,必须带
534
+ # 「上/平台/热帖/帖子」等语境修饰;论文词已被 @social_context 的负向前瞻
535
+ # 排除,本表不再重复。
536
+ _PLATFORM_NATIVE_ENGINES: tuple[tuple[str, "re.Pattern[str]"], ...] = (
537
+ ("fxtwitter", re.compile(r"(?i)(推特|twitter|\bX\s*(?:上|平台|热帖|帖子))")),
538
+ ("reddit", re.compile(r"(?i)reddit")),
539
+ )
540
+
541
+
542
+ def platform_native_engine(query: str) -> str | None:
543
+ """社交平台语境查询的平台原生源引擎名(无平台语境返回 None)。"""
544
+ for eng, pat in _PLATFORM_NATIVE_ENGINES:
545
+ if pat.search(query or ""):
546
+ return eng
547
+ return None
548
+
508
549
 
509
550
  def _split_pattern_entry(entry: Any) -> tuple[Any, Any]:
510
551
  """触发词条目的两种形态:字符串,或 `{match, unless}`(unless 支持 @宏名 展开)。
@@ -782,55 +823,141 @@ def _channel_intent_gate(hits: list[dict[str, Any]], query: str) -> list[dict[st
782
823
 
783
824
  # ── 对外入口 ──────────────────────────────────────────────────────────────────
784
825
 
826
+ # 域 → 它回答的意图(query_understanding._INTENT_PATTERNS 的子集)。
827
+ # 只登记语义明确的域;未登记的域 bonus 恒为 0(等价旧行为)。
828
+ #
829
+ # 为什么放代码表而不是 config 字段:`intents` 是 query_understanding 的
830
+ # 分类产物,域与它的对应关系当前只有一处消费者(本打分),且需要与
831
+ # `_INTENT_PATTERNS` 的词表保持同步——放 config 会变成第三份要同步的真源。
832
+ # 判据同 `_ZH_LANG_GATED_DOMAINS`:成员若各自有理由再上 config。
833
+ _DOMAIN_INTENTS: dict[str, tuple[str, ...]] = {
834
+ "social": ("social",),
835
+ "zhihu_content": ("social",),
836
+ "zhihu_hot_list": ("social",),
837
+ "hot_trending": ("social", "news"),
838
+ "news_realtime": ("news",),
839
+ "financial_news": ("news",),
840
+ "wechat_search": ("news",),
841
+ # 比较决策题:中文技术社区(V2EX/掘金)与知乎讨论是主要答案面,
842
+ # 「最好用的 AI 编程助手 X/Y 对比」类查询由它们承接(实测 chinese_tech_deep
843
+ # 的 byted 能交付,非误判)。2026-11-15 补,与度量的 product_daily 语境对齐。
844
+ "chinese_tech_deep": ("compare",),
845
+ }
846
+
847
+ _INTENT_BONUS = 1.5
848
+
849
+
850
+ def _is_zh_lang_gated(domain: dict[str, Any]) -> bool:
851
+ """判定域是否受非中文屏蔽门约束(优先读 config 声明 zh_lang_gated)。"""
852
+ flag = domain.get("zh_lang_gated")
853
+ if flag is not None:
854
+ return bool(flag)
855
+ return domain.get("name") in _ZH_LANG_GATED_DOMAINS
856
+
857
+
858
+ def _intent_bonus(domain: dict[str, Any], intents: list[str] | None) -> float:
859
+ """查询 intent 命中该域声明 intent 时的加分;无交集返回 0。"""
860
+ want = domain.get("intents") or _DOMAIN_INTENTS.get(domain.get("name") or "")
861
+ if not want or not intents:
862
+ return 0.0
863
+ return _INTENT_BONUS if any(i in want for i in intents) else 0.0
864
+
865
+
866
+ def _domain_priority(domain: dict[str, Any], idx: int, total: int) -> float:
867
+ """返回域优先级分:显式声明 priority 优先,缺省按配置顺序派生。"""
868
+ raw = domain.get("priority")
869
+ if isinstance(raw, (int, float)) and not isinstance(raw, bool):
870
+ return float(raw)
871
+ return float((total - idx) * 10)
872
+
873
+
874
+ def score_domain(
875
+ domain: dict[str, Any],
876
+ idx: int,
877
+ total: int,
878
+ query: str,
879
+ q_lower: str,
880
+ q_len: int,
881
+ intents: list[str] | None = None,
882
+ ) -> tuple[float, float, int, int] | None:
883
+ """统一零基域打分:未命中返回 None,命中返回 (priority, sec_score, span_start, span_len)。"""
884
+ fires, span_start, span_len = _domain_fires_with_span(domain, query, q_lower)
885
+ if not fires:
886
+ return None
887
+ prio = _domain_priority(domain, idx, total)
888
+ pos_ratio = span_start / max(q_len, 1)
889
+ sec_score = (
890
+ (span_len * 2.0)
891
+ + (prio * 0.01)
892
+ + (pos_ratio * 0.01)
893
+ + _intent_bonus(domain, intents)
894
+ )
895
+ return prio, sec_score, span_start, span_len
896
+
897
+
785
898
  def match_domains(query: str, domains: list[dict[str, Any]] | None = None,
786
899
  max_n: int = 3,
787
- primary_lang: str | None = None) -> list[dict[str, Any]]:
788
- """按 config.yaml domains 顺序返回全部命中域(多意图,主域 1 + 次域 max_n-1)。
900
+ primary_lang: str | None = None,
901
+ intents: list[str] | None = None) -> list[dict[str, Any]]:
902
+ """按域声明 priority 与统一零基评分返回命中域(主域 1 + 次域 max_n-1)。
789
903
 
790
- 旧 match_domain 单射只取首个命中域,多意图查询(如「北京 AI 公司融资」同时
791
- 命中 geo/finance/tech)只走一个域。本函数返回命中列表供 route 主域执行 +
792
- 次域按预算补充。catch-all(无 patterns)只做垫底:有命中时不掺入。
793
- max_n 限制命中数,防止正则宽泛的域批量命中稀释主域。
904
+ 旧实现按 config.yaml 物理遍历首命中为主域并在 max_n 处截断,任何物理顺序
905
+ 调整都会引发漂移。现改为扫描全部非门控候选后按 `priority` 取主域、按
906
+ `sec_score`(span 跨度 + priority + 位置 + intent 加成)排次域并做意图让位,
907
+ 配置重排时保持路由决策逐位一致。
794
908
 
795
909
  primary_lang:查询主语言(来自 extract_features)。当为明确的非中文语言
796
910
  (ja/ko/en/latin/cyrillic/thai 等)时,跳过中文内容域白名单,避免韩/日查询
797
911
  被中文泛内容域误捕获。传 None 时不做门控(兼容旧调用方)。
798
912
 
799
- 三阶段顺序(截断 → 结构化域提前 → 意图门)是契约,见模块 docstring。
913
+ 三阶段顺序(候选截断 → 结构化域提前 → 意图门)是契约,见模块 docstring。
800
914
  """
801
915
  if domains is None:
802
916
  domains = get_domains()
803
917
  compiled = _get_compiled_domains(domains)
804
918
  hits: list[dict[str, Any]] = []
805
- secondary_hits: list[tuple[dict[str, Any], float]] = []
919
+ fired: list[tuple[float, int, dict[str, Any], float]] = []
806
920
  catch_all: dict[str, Any] | None = None
807
921
  non_zh = bool(primary_lang and primary_lang not in ("zh", "mixed", "other"))
808
922
  candidates = _get_candidate_domain_indices(query)
809
923
  q_len = max(len(query), 1)
810
924
  q_lower = query.lower()
925
+ total = len(compiled)
811
926
 
812
927
  for idx, domain in enumerate(compiled):
813
928
  if not domain.get("patterns", []):
814
929
  catch_all = domain
815
930
  continue
816
- if non_zh and domain.get("name") in _ZH_LANG_GATED_DOMAINS:
931
+ if non_zh and _is_zh_lang_gated(domain):
817
932
  continue
818
933
  if candidates is not None and idx not in candidates:
819
934
  continue
820
- fires, span_start, span_len = _domain_fires_with_span(domain, query, q_lower)
821
- if fires:
822
- if not hits:
823
- hits.append(domain)
824
- else:
825
- pos_ratio = span_start / q_len
826
- # 方案二:跨度高(特异性强)优先提拔;同跨度下严格保持前序特化域顺位稳定
827
- score = (span_len * 2.0) - (idx * 0.1) + (pos_ratio * 0.01)
828
- secondary_hits.append((domain, score))
829
- if len(hits) + len(secondary_hits) >= max_n:
830
- break
831
-
832
- if secondary_hits:
935
+ scored = score_domain(domain, idx, total, query, q_lower, q_len, intents)
936
+ if scored is not None:
937
+ prio, sec_score, _, _ = scored
938
+ fired.append((prio, -idx, domain, sec_score))
939
+
940
+ if fired:
941
+ # 显式优先级(同分保持配置顺序)决定主域与进入次域竞选的前 max_n 候选
942
+ fired.sort(key=lambda x: (x[0], x[1]), reverse=True)
943
+ top_fired = fired[:max_n]
944
+ hits.append(top_fired[0][2])
945
+ secondary_hits = [(item[2], item[3]) for item in top_fired]
833
946
  secondary_hits.sort(key=lambda x: x[1], reverse=True)
947
+ # intent 让位(2026-11-15):主域本身没拿到 intent 加分,而某个次域
948
+ # 拿到了 —— 说明查询意图明确指向那个域,但域优先级让主域先命中。此时让位。
949
+ if hits and secondary_hits:
950
+ primary_bonus = _intent_bonus(hits[0], intents)
951
+ best_bonus = _intent_bonus(secondary_hits[0][0], intents)
952
+ # 不抢「比 social 更具体」的域的主位:与 `_social_domain_first` 的
953
+ # `_SPECIFIC_BEFORE_SOCIAL` 同名单。
954
+ _specific = {"redskill_search", "zhihu_user_data",
955
+ "hot_trending", "video"}
956
+ primary_specific = hits[0].get("name") in _specific
957
+ if (primary_bonus == 0.0 and best_bonus > 0.0
958
+ and not primary_specific):
959
+ promoted = secondary_hits.pop(0)[0]
960
+ hits.insert(0, promoted)
834
961
  hits.extend(h[0] for h in secondary_hits)
835
962
 
836
963
  hits = _social_domain_first(hits)
@@ -105,6 +105,7 @@ def apply_lang_override(features: dict[str, Any],
105
105
  return features
106
106
  out = dict(features)
107
107
  out["primary_lang"] = valid[0]
108
+ out["effective_lang"] = valid[0]
108
109
  out["operator_langs"] = valid
109
110
  return out
110
111
 
@@ -183,6 +184,7 @@ def extract_features(query: str) -> dict[str, Any]:
183
184
  import logging
184
185
  logging.getLogger("unified_search.route").debug(
185
186
  f"查询理解特征跳过: {type(e).__name__}")
187
+ features["effective_lang"] = effective_lang(features, query)
186
188
  return features
187
189
 
188
190
 
@@ -244,7 +246,7 @@ def _inject_multilingual_backup(engines_combo: list[str], enabled: set[str],
244
246
  通用保底源被截断剪掉)在声明来源层修,见 config.yaml 各域 engines_combo
245
247
  的顺序约定与 tests/test_combo_budget_coverage.py 检查。
246
248
  """
247
- if features.get("primary_lang") not in ("ja", "ko"):
249
+ if effective_lang(features) not in ("ja", "ko"):
248
250
  return engines_combo
249
251
  if "anysearch" not in enabled or not engines_combo:
250
252
  return engines_combo
@@ -356,7 +358,7 @@ def _merge_language_engines(engine_list: list[str], features: dict | None,
356
358
  return engine_list
357
359
  result = list(engine_list)
358
360
  # P2-3:显式语言覆盖 ja/ko 与主语言 ja/ko 同等对待(噪声剔除同一套规则)
359
- if (features.get("lang_override") or features.get("primary_lang")) in ("ja", "ko"):
361
+ if effective_lang(features) in ("ja", "ko"):
360
362
  cn_noise = {"bocha", "byted", "wechat_sogou", "zhihu", "zhihu_global", "baidu_baike"}
361
363
  result = [e for e in result if e not in cn_noise]
362
364
  for eng in lang_engines[:2]:
@@ -468,20 +470,31 @@ def _lang_aware_combo_order(combo: list[str], features: dict | None,
468
470
  return _filter_lang_bound_family(ordered, features, _specs_snapshot(), query)
469
471
 
470
472
 
471
- def _family_lang(features: dict | None, query: str = "") -> str:
472
- """选源用的查询语言:lang_override > primary_lang > 查询实词兜底。
473
+ def effective_lang(features: dict | None, query: str = "") -> str:
474
+ """统一的路由、选源与学习器分桶有效语言解析。
473
475
 
474
- 第三档专门补拉丁字母语言的判定缺口(lang_detect 对 noticias/berita/
475
- tin tức 只给 en/latin),见 engine_families._LANG_HINT_WORDS 的说明。
476
+ 优先级:lang_override > primary_lang(非笼统值)> 查询实词兜底。
476
477
  """
477
- lang = (features or {}).get("lang_override") or (features or {}).get("primary_lang") or ""
478
+ feats = features or {}
479
+ override = str(feats.get("lang_override") or "").strip().lower()
480
+ if override:
481
+ return override
482
+ lang = str(feats.get("primary_lang") or "").strip().lower()
478
483
  if lang in ("", "en", "latin", "mixed", "other"):
479
484
  hint = lang_hint_from_query(query)
480
485
  if hint:
481
486
  return hint
487
+ cached = str(feats.get("effective_lang") or "").strip().lower()
488
+ if cached and cached not in ("", "en", "latin", "mixed", "other"):
489
+ return cached
482
490
  return lang
483
491
 
484
492
 
493
+ def _family_lang(features: dict | None, query: str = "") -> str:
494
+ """选源用的查询语言(委托给 effective_lang 单一真源)。"""
495
+ return effective_lang(features, query)
496
+
497
+
485
498
  def _filter_lang_bound_family(combo: list[str], features: dict | None,
486
499
  specs: dict[str, dict[str, Any]] | None,
487
500
  query: str = "") -> list[str]:
@@ -11,18 +11,15 @@
11
11
  from __future__ import annotations
12
12
 
13
13
  import os
14
+ import random
14
15
  from typing import Any
15
16
 
16
17
 
17
18
  def _env_int(name: str, default: int, minimum: int = 1) -> int:
18
19
  """读整型环境变量,任何异常都退回 default。
19
20
 
20
- 为什么必须有:这一行原本裸写 `int(os.environ.get(...))`,于是
21
- `ARGO_ROUTE_SAMPLE_RATE=abc` 在**模块导入期**抛 ValueError,经
22
- route.py 的导入链直接把整个 `argo search` 打挂——与本模块 docstring
23
- 写的「必须永远 fail-open,使用日志写失败绝不能让一次搜索失败」正好相反,
24
- 而且触发它的只是一个拼错的采样率。mcp_handlers 早有同名 _env_int,
25
- 两处各写各的才是这个 bug 的成因。
21
+ 调用期按需解析(不在模块导入期读 os.environ),避免导入链失败或测试改写
22
+ 环境变量后仍沿用旧采样率。
26
23
  """
27
24
  try:
28
25
  return max(minimum, int(str(os.environ.get(name, "")).strip() or default))
@@ -30,18 +27,37 @@ def _env_int(name: str, default: int, minimum: int = 1) -> int:
30
27
  return default
31
28
 
32
29
 
33
- _ROUTE_SAMPLE_RATE = _env_int("ARGO_ROUTE_SAMPLE_RATE", 20)
30
+ _DEFAULT_ROUTE_SAMPLE_RATE = 20
31
+ # 模块级覆盖槽:仅测试用 monkeypatch 注入确定采样率(=1 时每调必落)。
32
+ # 运行期**不做 env→本值的缓存**:一旦缓存,「先设 env 再删」的进程会在后续调用
33
+ # 静默退回缓存值(实测 1 → 20),与「运行期生效」的意图相反。
34
+ _ROUTE_SAMPLE_RATE = _DEFAULT_ROUTE_SAMPLE_RATE
34
35
  _route_sample_counter = 0
35
36
 
36
37
 
38
+ def _resolve_rate() -> int:
39
+ """采样率:显式覆盖槽优先(测试注入),否则每次调用现读 env。"""
40
+ if _ROUTE_SAMPLE_RATE != _DEFAULT_ROUTE_SAMPLE_RATE:
41
+ return _ROUTE_SAMPLE_RATE
42
+ return _env_int("ARGO_ROUTE_SAMPLE_RATE", _DEFAULT_ROUTE_SAMPLE_RATE)
43
+
44
+
37
45
  def sample_route(done: dict[str, Any], kw: dict[str, Any]) -> None:
38
46
  """按采样率把路由决策落一条使用日志记录。"""
39
47
  global _route_sample_counter
40
48
  if "features" not in kw or not kw.get("features"):
41
49
  return # engine_override 直通等无语义分支不采样
50
+ rate = max(1, int(_resolve_rate()))
42
51
  _route_sample_counter += 1
43
- if _route_sample_counter % _ROUTE_SAMPLE_RATE != 0:
44
- return
52
+ if rate > 1:
53
+ # 单次 CLI 进程只有第 1 次调用:若只看 `_route_sample_counter % rate == 0`,
54
+ # 每次退出后计数器归零导致 CLI 路径零采样;首次调用用无状态随机采样,
55
+ # 长驻进程(daemon/MCP)第 2 次起继续按固定步长采样。
56
+ should_emit = (random.randrange(rate) == 0
57
+ if _route_sample_counter == 1
58
+ else (_route_sample_counter % rate == 0))
59
+ if not should_emit:
60
+ return
45
61
  f = kw.get("features") or {}
46
62
  try:
47
63
  from usage_log import emit
@@ -53,6 +69,7 @@ def sample_route(done: dict[str, Any], kw: dict[str, Any]) -> None:
53
69
  "mode": kw.get("mode"),
54
70
  "lang_override": f.get("lang_override"),
55
71
  "primary_lang": f.get("primary_lang"),
72
+ "effective_lang": f.get("effective_lang"),
56
73
  "script": f.get("script"),
57
74
  "has_compare": f.get("has_compare"),
58
75
  "has_technical": f.get("has_technical"),
@@ -69,6 +69,10 @@ _VERTICAL_NEW_SOURCE: dict[str, tuple[str, ...]] = {
69
69
  # 2026-11-11:maven/nuget 补 Java/JVM 与 .NET 两个生态的关键词发现,
70
70
  # 声明在 crates 之后(位次 4/5)。本域基础预算 3,两源需加槽通电。
71
71
  "package_search": ("maven", "nuget"),
72
+ # 2026-11-11:cisa_alerts 声明在 crt_sh 之后(位次 4),加槽扩容,不挤掉 crt_sh
73
+ "security_search": ("cisa_alerts",),
74
+ # 2026-11-11:eng_blogs 顶尖架构博客聚合加槽
75
+ "english_tech": ("eng_blogs",),
72
76
  }
73
77
 
74
78
 
@@ -252,9 +256,10 @@ def _apply_policy_with_new_source_slots(
252
256
  live = [e for e in _VERTICAL_NEW_SOURCE.get((domain or {}).get("name"), ())
253
257
  if e in declared and (enabled is None or e in enabled)]
254
258
  keep = list(must_keep or [])
255
- for e in live:
256
- if e not in engines_combo and e not in keep:
257
- keep.append(e)
259
+ if (mode or "auto") not in ("fast", "budget"):
260
+ for e in live:
261
+ if e not in engines_combo and e not in keep:
262
+ keep.append(e)
258
263
  return _apply_engine_policy(
259
264
  engines_combo, mode=mode, depth=depth, context=context,
260
265
  engines_boost=engines_boost, enabled=enabled,
@@ -262,7 +267,81 @@ def _apply_policy_with_new_source_slots(
262
267
  budget_extra=_new_source_budget_extra(
263
268
  domain, declared or engines_combo, enabled or set(),
264
269
  mode=mode, depth=depth, context=context,
265
- # 传当前 combo:新源还在里面但被重排推出窗口时,额度要按它在
266
- # 当前 combo 的位次算(只在声明位次上算会得到 0,见该函数说明)
267
- live_combo=engines_combo),
270
+ # 传当前 combo:新源还在里面但被重排推出窗口时,额度要按它在
271
+ # 当前 combo 的位次算(只在声明位次上算会得到 0,见该函数说明)
272
+ live_combo=engines_combo),
268
273
  )
274
+
275
+
276
+ def is_pure_combo_domain(domain: dict[str, Any] | None) -> bool:
277
+ """域是否声明 pure_combo(保持纯结构化路径,不混入通用/地理/次域源)。"""
278
+ d = domain or {}
279
+ return bool(d.get("pure_combo")) or d.get("name") == "modal_card"
280
+
281
+
282
+ def apply_domain_combo_rules(
283
+ domain: dict[str, Any],
284
+ engines_combo: list[str],
285
+ query: str,
286
+ enabled: set[str],
287
+ specs: dict[str, Any],
288
+ ) -> list[str]:
289
+ """应用声明式域策略(zh_filter_en_only / 宏观区域前置),减轻 route.py 负担。"""
290
+ zh_filter = bool(domain.get("zh_filter_en_only")) or (
291
+ domain.get("name") in ("tech_deep", "academic")
292
+ )
293
+ if zh_filter and any("\u4e00" <= ch <= "\u9fff" for ch in query):
294
+ from engine_families import engine_langs
295
+ engines_combo = [
296
+ e for e in engines_combo
297
+ if engine_langs(e, specs.get(e)) != {"en"}
298
+ ]
299
+ if not engines_combo:
300
+ engines_combo = [e for e in ["arxiv", "anysearch", "local_search"] if e in enabled]
301
+
302
+ if domain.get("name") == "macro_data":
303
+ from macro_countries import is_foreign_macro_query
304
+ if is_foreign_macro_query(query) and "worldbank" in engines_combo:
305
+ engines_combo = ["worldbank"] + [e for e in engines_combo if e != "worldbank"]
306
+ if "nbs_stats" in engines_combo and ("中国" in query or "china" in query.lower()):
307
+ engines_combo = ["nbs_stats"] + [e for e in engines_combo if e != "nbs_stats"]
308
+ return engines_combo
309
+
310
+
311
+ def resolve_pure_combo_fallback(domain: dict[str, Any]) -> list[str]:
312
+ """pure_combo 域(如 modal_card)缺可用引擎时保留声明组合,避免误入通用兜底。"""
313
+ declared = list(domain.get("engines_combo") or [])
314
+ if not declared and domain.get("primary"):
315
+ declared = [domain["primary"]]
316
+ try:
317
+ from engine_env import is_engine_allowed_by_env
318
+ return [e for e in declared if is_engine_allowed_by_env(e)] or declared
319
+ except ImportError:
320
+ return declared
321
+
322
+
323
+ def build_domain_must_keep(
324
+ domain: dict[str, Any],
325
+ features: dict[str, Any] | None,
326
+ enabled: set[str],
327
+ pure_combo: bool,
328
+ is_dead_fn,
329
+ ) -> list[str]:
330
+ """组装域级保底列表(地理特征 + 垂直域主源 + modal_card/geo_places 专属项)。"""
331
+ must_keep: list[str] = []
332
+ if (features or {}).get("has_geo") and "local_openstreetmap" in enabled and not pure_combo:
333
+ must_keep.append("local_openstreetmap")
334
+ if domain.get("name") in _VERTICAL_KEEP:
335
+ p = domain.get("primary")
336
+ if p and p not in must_keep and (p in enabled or pure_combo) and not is_dead_fn(p):
337
+ must_keep.append(p)
338
+ if domain.get("name") == "modal_card":
339
+ for e in domain.get("engines_combo") or []:
340
+ if e not in must_keep and (e in enabled or pure_combo):
341
+ must_keep.append(e)
342
+ elif p and p in enabled and p not in must_keep and not is_dead_fn(p):
343
+ must_keep.append(p)
344
+ if domain.get("name") == "geo_places" and "local_openstreetmap" in enabled:
345
+ if "local_openstreetmap" not in must_keep:
346
+ must_keep.append("local_openstreetmap")
347
+ return must_keep