argo-search 2.13.0 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/AGENTS.md +93 -0
  2. package/README.en.md +16 -4
  3. package/README.es.md +16 -4
  4. package/README.ja.md +16 -4
  5. package/README.ko.md +16 -4
  6. package/README.md +16 -4
  7. package/SKILL.md +1 -1
  8. package/assets/readme/counts.json +1 -1
  9. package/backends/domain_profiles.json +66 -6
  10. package/backends/engine_registry.yaml +154 -15
  11. package/backends/env_passthrough.txt +2 -0
  12. package/backends/quota_profiles.json +111 -11
  13. package/bin/argo +3 -0
  14. package/config.yaml +27 -1
  15. package/docs/CHANGELOG.md +23 -0
  16. package/docs/COMMIT_STANDARD.md +98 -0
  17. package/docs/ENGINE_CATALOG.md +94 -79
  18. package/docs/RELEASE_NOTES_v2.14.0.md +77 -0
  19. package/engines/specs/clinicaltrials.yaml +8 -0
  20. package/engines/specs/cnii.yaml +5 -0
  21. package/engines/specs/coingecko.yaml +10 -2
  22. package/engines/specs/dbpedia.yaml +32 -0
  23. package/engines/specs/fourget.yaml +23 -0
  24. package/engines/specs/grep_app.yaml +19 -0
  25. package/engines/specs/hackernews.yaml +1 -0
  26. package/engines/specs/hf_papers.yaml +26 -0
  27. package/engines/specs/kaggle.yaml +44 -0
  28. package/engines/specs/local_baidu.yaml +5 -0
  29. package/engines/specs/local_seek.yaml +34 -0
  30. package/engines/specs/local_yandex.yaml +37 -0
  31. package/engines/specs/mojeek.yaml +31 -0
  32. package/engines/specs/mwmbl.yaml +39 -0
  33. package/engines/specs/openaire.yaml +34 -0
  34. package/engines/specs/repology.yaml +18 -0
  35. package/package.json +13 -10
  36. package/packages/dsh-plugin/dsh/client.js +1 -0
  37. package/packages/dsh-plugin/dsh/native-tools.mjs +24 -3
  38. package/packages/dsh-plugin/dsh/runner.js +35 -1
  39. package/packages/dsh-plugin/dsh/specs.js +3 -1
  40. package/packages/dsh-plugin/dsh/wide-research.js +4 -2
  41. package/packages/dsh-plugin/package.json +1 -1
  42. package/packages/dsh-plugin/test/client.test.js +6 -0
  43. package/packages/dsh-plugin/test/config.test.js +5 -1
  44. package/packages/dsh-plugin/test/index.test.js +3 -1
  45. package/packages/dsh-plugin/test/size-gate.test.js +2 -2
  46. package/scripts/badcase_causes.py +81 -0
  47. package/scripts/badcase_ledger.py +287 -14
  48. package/scripts/cache.py +3 -3
  49. package/scripts/check_commit_report.py +168 -0
  50. package/scripts/engine_admission.py +9 -5
  51. package/scripts/engine_families.py +13 -2
  52. package/scripts/engine_policy.py +1 -1
  53. package/scripts/engine_states.py +393 -8
  54. package/scripts/engine_status.py +31 -0
  55. package/scripts/engine_validate.py +47 -39
  56. package/scripts/engines.py +6 -0
  57. package/scripts/engines_base.py +26 -80
  58. package/scripts/engines_builders.py +5 -0
  59. package/scripts/engines_builders_batch12.py +168 -0
  60. package/scripts/engines_builders_batch16.py +186 -0
  61. package/scripts/engines_parsers.py +399 -0
  62. package/scripts/fetch_browser.py +4 -2
  63. package/scripts/fetch_jsrun.py +2 -1
  64. package/scripts/fetch_v3.py +22 -22
  65. package/scripts/gen_native_tools.py +44 -17
  66. package/scripts/local_intent.py +139 -0
  67. package/scripts/local_seek.py +223 -91
  68. package/scripts/local_seek_adapter.py +87 -0
  69. package/scripts/mcp_transport.py +1 -1
  70. package/scripts/pre-commit +44 -1
  71. package/scripts/recovery.py +14 -5
  72. package/scripts/recovery_l0.py +5 -3
  73. package/scripts/research.py +1 -1
  74. package/scripts/research_gates.py +3 -3
  75. package/scripts/route_lang.py +6 -1
  76. package/scripts/route_policy.py +21 -14
  77. package/scripts/search.py +33 -25
  78. package/scripts/search_cli.py +10 -1
  79. package/scripts/search_output.py +83 -16
  80. package/scripts/source_audit.py +331 -0
  81. package/scripts/sync_backends.py +31 -1
  82. package/scripts/wechat_article.py +5 -3
  83. package/scripts/wide_research.py +4 -1
  84. package/scripts/x_article_fetch.py +2 -1
  85. package/sub-skills/local-search/parsers.py +6 -1
  86. package/sub-skills/local-seek/scripts/seek.py +390 -24
  87. package/sub-skills/local-seek/scripts/seek_fts.py +20 -9
  88. package/sub-skills/local-seek/scripts/seek_rank.py +64 -1
  89. package/engines/specs/cinii.yaml +0 -44
@@ -388,10 +388,10 @@ def _ai_variant_candidates(url: str) -> list[tuple[str, str]]:
388
388
  out: list[tuple[str, str]] = []
389
389
  md = _md_variant_url(url)
390
390
  if md:
391
- out.append((md, "md_variant"))
391
+ out.append((md, engine_states.FETCH_MD_VARIANT))
392
392
  llms = _llms_txt_url(url)
393
393
  if llms:
394
- out.append((llms, "llms_txt"))
394
+ out.append((llms, engine_states.FETCH_LLMS_TXT))
395
395
  # token 炸弹守卫:全站合并类变体永不进候选(见 _BANNED_AI_VARIANTS)
396
396
  return [(u, k) for u, k in out if not _is_banned_ai_variant(u)]
397
397
 
@@ -649,7 +649,7 @@ def _mobile_http_fetch(url: str, max_chars: int = 8000,
649
649
  from url_safety import check_url
650
650
  ok, reason = check_url(url)
651
651
  if not ok:
652
- return _make_result(url, "", 0, "http_mobile", ok=False,
652
+ return _make_result(url, "", 0, engine_states.FETCH_HTTP_MOBILE, ok=False,
653
653
  error=f"URL 被 SSRF 防护拦截: {reason}")
654
654
  except ImportError:
655
655
  pass
@@ -666,17 +666,17 @@ def _mobile_http_fetch(url: str, max_chars: int = 8000,
666
666
  return _make_result(url, _decode_charset(r.read(), r.headers.get("Content-Type", "")),
667
667
  max_chars, "http_mobile")
668
668
  except Exception as e:
669
- return _make_result(url, "", 0, "http_mobile", ok=False,
669
+ return _make_result(url, "", 0, engine_states.FETCH_HTTP_MOBILE, ok=False,
670
670
  error=str(e)[:100])
671
671
  if resp.get("status", 0) >= 400:
672
- result = _make_result(url, "", 0, "http_mobile", ok=False,
672
+ result = _make_result(url, "", 0, engine_states.FETCH_HTTP_MOBILE, ok=False,
673
673
  error=f"HTTP {resp.get('status')}")
674
674
  _mark_stop_signal(result, resp)
675
675
  return result
676
676
  if not resp.get("text"):
677
- return _make_result(url, "", 0, "http_mobile", ok=False,
677
+ return _make_result(url, "", 0, engine_states.FETCH_HTTP_MOBILE, ok=False,
678
678
  error="empty response")
679
- result = _make_result(url, resp["text"], max_chars, "http_mobile")
679
+ result = _make_result(url, resp["text"], max_chars, engine_states.FETCH_HTTP_MOBILE)
680
680
  _mark_stop_signal(result, resp)
681
681
  return result
682
682
 
@@ -713,7 +713,7 @@ def _http_fetch(url: str, max_chars: int = 8000, timeout: float = 8.0,
713
713
  from url_safety import check_url
714
714
  ok, reason = check_url(url)
715
715
  if not ok:
716
- return _make_result(url, "", 0, "http", ok=False,
716
+ return _make_result(url, "", 0, engine_states.FETCH_HTTP, ok=False,
717
717
  error=f"URL 被 SSRF 防护拦截: {reason}")
718
718
  except ImportError:
719
719
  pass
@@ -732,17 +732,17 @@ def _http_fetch(url: str, max_chars: int = 8000, timeout: float = 8.0,
732
732
  try:
733
733
  with open_url(req, timeout=timeout) as r:
734
734
  return _make_result(url, _decode_charset(r.read(), r.headers.get("Content-Type", "")),
735
- max_chars, "http")
735
+ max_chars, engine_states.FETCH_HTTP)
736
736
  except Exception as e:
737
- return _make_result(url, "", 0, "http", ok=False, error=str(e)[:100])
737
+ return _make_result(url, "", 0, engine_states.FETCH_HTTP, ok=False, error=str(e)[:100])
738
738
 
739
739
  if resp.get("status", 0) >= 400:
740
- result = _make_result(url, "", 0, "http", ok=False,
740
+ result = _make_result(url, "", 0, engine_states.FETCH_HTTP, ok=False,
741
741
  error=f"HTTP {resp.get('status')}")
742
742
  _mark_stop_signal(result, resp)
743
743
  return result
744
744
  if not resp.get("text"):
745
- return _make_result(url, "", 0, "http", ok=False, error="empty response")
745
+ return _make_result(url, "", 0, engine_states.FETCH_HTTP, ok=False, error="empty response")
746
746
 
747
747
  if negotiate:
748
748
  text = _negotiated_markdown(resp)
@@ -750,7 +750,7 @@ def _http_fetch(url: str, max_chars: int = 8000, timeout: float = 8.0,
750
750
  return _markdown_result(url, text, max_chars, "http_md",
751
751
  final_url=resp.get("url", ""))
752
752
 
753
- return _make_result(url, resp["text"], max_chars, "http")
753
+ return _make_result(url, resp["text"], max_chars, engine_states.FETCH_HTTP)
754
754
 
755
755
 
756
756
  def _tls_spoof_fetch(url: str, max_chars: int = 8000, timeout: float = 8.0) -> dict:
@@ -766,7 +766,7 @@ def _tls_spoof_fetch(url: str, max_chars: int = 8000, timeout: float = 8.0) -> d
766
766
  from url_safety import check_url
767
767
  ok, reason = check_url(url)
768
768
  if not ok:
769
- return _make_result(url, "", 0, "tls_spoof", ok=False,
769
+ return _make_result(url, "", 0, engine_states.FETCH_TLS_SPOOF, ok=False,
770
770
  error=f"URL 被 SSRF 防护拦截: {reason}")
771
771
  except ImportError:
772
772
  pass
@@ -776,19 +776,19 @@ def _tls_spoof_fetch(url: str, max_chars: int = 8000, timeout: float = 8.0) -> d
776
776
  client = HttpClient(timeout=timeout, max_retries=1, jitter=False)
777
777
  resp = client.get_impersonated(url, timeout=timeout)
778
778
  except ImportError:
779
- return _make_result(url, "", 0, "tls_spoof", ok=False,
779
+ return _make_result(url, "", 0, engine_states.FETCH_TLS_SPOOF, ok=False,
780
780
  error="http_client not available")
781
781
 
782
782
  if resp.get("status", 0) >= 400:
783
- result = _make_result(url, "", 0, "tls_spoof", ok=False,
783
+ result = _make_result(url, "", 0, engine_states.FETCH_TLS_SPOOF, ok=False,
784
784
  error=f"HTTP {resp.get('status')}")
785
785
  _mark_stop_signal(result, resp)
786
786
  return result
787
787
  if not resp.get("text"):
788
- return _make_result(url, "", 0, "tls_spoof", ok=False,
788
+ return _make_result(url, "", 0, engine_states.FETCH_TLS_SPOOF, ok=False,
789
789
  error=resp.get("error", "empty response"))
790
790
 
791
- result = _make_result(url, resp["text"], max_chars, "tls_spoof")
791
+ result = _make_result(url, resp["text"], max_chars, engine_states.FETCH_TLS_SPOOF)
792
792
  result["impersonate"] = resp.get("impersonate", "")
793
793
  return result
794
794
 
@@ -962,7 +962,7 @@ def _jina_reader_fetch(url: str, max_chars: int = 8000,
962
962
  raw = raw.split("Markdown Content:", 1)[1].lstrip()
963
963
  if not _looks_like_markdown(raw):
964
964
  return None
965
- result = _make_result(url, "", max_chars, "jina_reader")
965
+ result = _make_result(url, "", max_chars, engine_states.FETCH_JINA_READER)
966
966
  result["content"] = raw[:max_chars]
967
967
  result["length"] = len(result["content"])
968
968
  result["title"] = title
@@ -1318,7 +1318,7 @@ def fetch_v3(url: str, max_chars: int = 8000, timeout: float = 8.0,
1318
1318
  try:
1319
1319
  from robots_guard import robots_blocked
1320
1320
  if robots_blocked(url, timeout=min(timeout, 5.0)):
1321
- result = _make_result(url, "", 0, "robots_blocked", ok=False,
1321
+ result = _make_result(url, "", 0, engine_states.FETCH_ROBOTS_BLOCKED, ok=False,
1322
1322
  error="robots.txt 禁止抓取")
1323
1323
  result = _assess_quality(result)
1324
1324
  result["cached"] = False
@@ -1346,7 +1346,7 @@ def fetch_v3(url: str, max_chars: int = 8000, timeout: float = 8.0,
1346
1346
  "length": int(_wx.get("char_count") or 0),
1347
1347
  "success": True,
1348
1348
  "fetch_method": engine_states.FETCH_WECHAT + str(
1349
- _wx.get("fetch_method") or "http_direct"),
1349
+ _wx.get("fetch_method") or engine_states.FETCH_HTTP_DIRECT),
1350
1350
  "author": _wx.get("author") or "",
1351
1351
  "publish_time": _wx.get("publish_time") or "",
1352
1352
  }
@@ -1531,7 +1531,7 @@ def fetch_v3(url: str, max_chars: int = 8000, timeout: float = 8.0,
1531
1531
  # 该类分流与 TLS 指纹无关,stdlib 免费尝试即可,命中则免去
1532
1532
  # TLS 伪造与浏览器冷启动。ARGO_FETCH_MOBILE=0 关闭。
1533
1533
  if (_mobile_branch_enabled() and not gated
1534
- and result.get("fetch_method") != "http_mobile"
1534
+ and result.get("fetch_method") != engine_states.FETCH_HTTP_MOBILE
1535
1535
  and (not result.get("success")
1536
1536
  or _needs_browser(result))):
1537
1537
  mob = _mobile_http_fetch(url, max_chars,
@@ -1,17 +1,20 @@
1
1
  #!/usr/bin/env python3
2
- """gen_native_tools.py — 从 schema 唯一来源生成 DSH 原生工具规格表。
2
+ """gen_native_tools.py — 从 Python 真源生成 DSH 侧两个 ESM 常量表。
3
3
 
4
- schema 来源是 scripts/mcp_tools.py(模型可见 inputSchema 只在该文件维护)。
5
- 本脚本把它翻译为 packages/dsh-plugin/dsh/native-tools.mjs(纯 ESM 常量,
6
- Node 18 可直接 import),使 DSH 原生一等工具(nativeTools 配置)无需手写
7
- 第二份 schema——此前 index.js 手写 argo_search/argo_fetch 两个规格,与
8
- Python 侧已经出现措辞/参数漂移空间。
4
+ 两张表都走同一份生成物 `packages/dsh-plugin/dsh/native-tools.mjs`(纯 ESM,
5
+ Node 18 可直接 import),避免 JS 侧手写第二份声明:
6
+
7
+ 1. `NATIVE_TOOLS`:来源 `scripts/mcp_tools.py` 的 inputSchema。此前 index.js
8
+ 手写 argo_search/argo_fetch 两个规格,与 Python 侧已出现措辞/参数漂移空间。
9
+ 2. `STATES`:来源 `scripts/engine_states.py` 的状态词表。此前 DSH 面板的
10
+ ready/loading/unavailable、wide-research 的 conclusion_cap 三态、ZCode 桥
11
+ 的 daemon 四态全靠字面量,改词表不会让任何东西变红(2026-11-10 审计)。
9
12
 
10
13
  生成的规格覆盖除 argo_research 外的全部工具:research 是分钟级调度,
11
14
  CLI 单发默认 60s 超时会拦腰杀研究,只应经 MCP 或 wide_research 入口使用。
12
15
 
13
16
  漂移检查:tests/test_native_tools_sync.py 重算本脚本输出并与仓库内文件
14
- 逐字节比对——改 mcp_tools.py 后必须重新生成,否则测试红。
17
+ 逐字节比对——改 mcp_tools.py 或 engine_states.py 后必须重新生成,否则红。
15
18
 
16
19
  用法:
17
20
  python3 scripts/gen_native_tools.py # 写文件
@@ -27,6 +30,7 @@ from cli_io import dumps_pretty
27
30
  SCRIPT_DIR = Path(__file__).resolve().parent
28
31
  sys.path.insert(0, str(SCRIPT_DIR))
29
32
 
33
+ import engine_states # noqa: E402
30
34
  from mcp_tools import TOOLS # noqa: E402
31
35
 
32
36
  OUT_PATH = SCRIPT_DIR.parent / "packages" / "dsh-plugin" / "dsh" / "native-tools.mjs"
@@ -35,15 +39,17 @@ OUT_PATH = SCRIPT_DIR.parent / "packages" / "dsh-plugin" / "dsh" / "native-tools
35
39
  _EXCLUDED = {"argo_research"}
36
40
 
37
41
  HEADER = """\
38
- // 本文件由 scripts/gen_native_tools.py 从 schema 唯一真源
39
- // scripts/mcp_tools.py 生成 —— 勿手改;改 schema 后重新生成,
42
+ // 本文件由 scripts/gen_native_tools.py 从 Python 真源生成 —— 勿手改;
43
+ // 改 mcp_tools.py 或 engine_states.py 后重新生成,
40
44
  // tests/test_native_tools_sync.py 负责漂移门禁。
41
45
  //
42
46
  // 说明:
43
- // - description / parameters 与 MCP 模型可见 schema 完全一致
47
+ // - NATIVE_TOOLS:description / parameters 与 MCP 模型可见 schema 完全一致
44
48
  // - allowed = parameters.properties 键序(原生侧 pickArgs 白名单)
45
49
  // - 不含 argo_research:分钟级编排不适合 CLI 单发(默认超时会中断),
46
50
  // 走 MCP 形态或 wide_research 入口
51
+ // - STATES:engine_states.py 状态词表的只读投影,按状态机分组;
52
+ // JS 侧一律从这里取值,不再手写 ready/low/running 等字面量
47
53
  //
48
54
  """
49
55
 
@@ -66,24 +72,45 @@ def build_native_tools() -> dict:
66
72
  return out
67
73
 
68
74
 
69
- def render(native_tools: dict) -> str:
70
- body = dumps_pretty(native_tools)
71
- return HEADER + "export const NATIVE_TOOLS = " + body + ";\n"
75
+ def build_states() -> dict:
76
+ """engine_states.py 跨侧需要的词表投影(按状态机分组)。
77
+
78
+ 每组输出 `{语义名: 状态值}` 而非数组:JS 侧按名字取值
79
+ (`STATES.conclusionCap.low`),不依赖数组顺序——此前按字母序解构
80
+ 会把 low/medium/high 全对错位。排序只为生成物稳定。
81
+ """
82
+ def as_enum(values) -> dict:
83
+ return {v: v for v in sorted(values)}
84
+
85
+ return {
86
+ "plugin": as_enum(engine_states.PLUGIN_STATES),
87
+ "daemon": as_enum(engine_states.DAEMON_STATES),
88
+ "conclusionCap": as_enum(engine_states.CONCLUSION_CAP_STATUSES),
89
+ }
90
+
91
+
92
+ def render(native_tools: dict, states: dict) -> str:
93
+ tools_body = dumps_pretty(native_tools)
94
+ states_body = dumps_pretty(states)
95
+ return (HEADER
96
+ + "export const NATIVE_TOOLS = " + tools_body + ";\n\n"
97
+ + "export const STATES = " + states_body + ";\n")
72
98
 
73
99
 
74
100
  def main() -> int:
75
101
  native_tools = build_native_tools()
76
- rendered = render(native_tools)
102
+ states = build_states()
103
+ rendered = render(native_tools, states)
77
104
  if "--check" in sys.argv:
78
105
  current = OUT_PATH.read_text(encoding="utf-8") if OUT_PATH.exists() else ""
79
106
  if current != rendered:
80
- print(f"FAIL: {OUT_PATH.name} 与 mcp_tools.py 漂移——请运行 "
107
+ print(f"FAIL: {OUT_PATH.name} 与 Python 真源漂移——请运行 "
81
108
  f"python3 scripts/gen_native_tools.py 重新生成", file=sys.stderr)
82
109
  return 1
83
- print(f"OK: {len(native_tools)} 个原生工具规格与 mcp_tools.py 一致")
110
+ print(f"OK: {len(native_tools)} 个原生工具规格 + {len(states)} 组状态词表与真源一致")
84
111
  return 0
85
112
  OUT_PATH.write_text(rendered, encoding="utf-8")
86
- print(f"已生成 {OUT_PATH}({len(native_tools)} 个工具)")
113
+ print(f"已生成 {OUT_PATH}({len(native_tools)} 个工具 + {len(states)} 组状态词表)")
87
114
  return 0
88
115
 
89
116
 
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env python3
2
+ """local_intent.py — 查询是否值得检索本机文件的单点判据。
3
+
4
+ 为什么独立成模块(奥卡姆剃刀):判据只有两条,但被两处消费——
5
+ 提交前的「跳过判定」(search.py)与提交后的「是否记账」(同处)。
6
+ 塞进任一处都会让另一处变成「读了对方代码的隐式耦合」,独立成模块后
7
+ 两处共用同一份口径,改判据只改这里。
8
+
9
+ 判据(两条都满足才跳过,缺一搜):
10
+ 1. 查询命中明确的公域域(天气/行情/汇率/宏观/新闻等答案型域);
11
+ 2. 查询不含本地工程/文件意图信号。
12
+
13
+ 反向保护:纯英文泛词查询("latest news")不命中域时**不跳过**,
14
+ 宁可多搜一次本地也不误杀;只有「明确公域 + 无本地信号」才跳。
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import re
20
+
21
+ # 本地工程/文件意图信号:
22
+ # 1. 显式工程信号:代码关键字、扩展名、工程配置文件、中文本地说法
23
+ # 2. 隐式工程信号:代码异常类(ZeroDivisionError 等)、内部私有标识符(_foo_bar)、函数调用特征(foo())
24
+ # 与 local_seek._LOCAL_INTENT_PATTERN 同口径,两处必须逐字一致——见下方 test_local_intent_parity。
25
+ _LOCAL_SIGNAL_RE = re.compile(
26
+ r"(?i)(?:\b(?:def|class|function|fn|import|export|const|var|struct|enum)\b|"
27
+ r"\.(?:py|js|ts|tsx|jsx|json|yaml|yml|toml|md|rs|go|c|cpp|h|hpp|sh|sql|conf|cfg|ini|log)\b|"
28
+ r"(?:readme|config|package\.json|cargo\.toml|dockerfile|makefile|pyproject\.toml|tsconfig\.json|go\.mod|requirements\.txt|Cargo\.lock|\.gitignore|\.env)|"
29
+ r"\b[A-Za-z0-9_]+(?:Error|Exception|Fault|Warning)\b|"
30
+ r"\b_[a-zA-Z0-9_]{2,}\b|"
31
+ r"\b[a-zA-Z0-9_]+\([^\)]*\)|"
32
+ r"(?:本工程|本项目|代码库|本地文件|本地脚本|脚本文件|架构实现|函数|方法|源码|接口定义|"
33
+ # 2026-11-10 P0-1 补:实测「我的 .agents/skills 有哪些」「我的文件」
34
+ # 「仓库里」「本机」这类说法在默认路径下被误判为公网查询,漏搜本机。
35
+ # 补的都是「本机/我的/仓库」语义,不会误伤公网查询("我的" 单独出现
36
+ # 不算,必须带 文件/笔记/电脑/代码 等宾语)。
37
+ r"本机|本地代码|本地笔记|我的文件|我的笔记|我的电脑|我的代码|"
38
+ r"仓库里|仓库中|工程里|项目里|当前目录|工作目录|\.agents/skills|\.obsidian))"
39
+ )
40
+
41
+ # 公域答案型域:这些域的答案只可能来自公网(天气/行情/汇率/宏观/
42
+ # 新闻/法律/学术),本机文件命中对它们是纯噪声。
43
+ # 名单与 config.yaml 的 domains 段对齐,但**只收「答案型」域**——
44
+ # skill_search/wechat_search 这类「本机也可能有」的域不在内。
45
+ _PUBLIC_ONLY_DOMAINS = frozenset({
46
+ "weather_query", "aviation_weather",
47
+ "stock_query", "us_stock", "hk_filings", "sec_filings",
48
+ "fund_query", "us_fundamentals", "futures_market",
49
+ "fx_query", "macro_data", "crypto_search",
50
+ "financial_news", "cls_telegraph_search", "em_news_search",
51
+ "jin10_flash", "zhihu_hot_list", "hot_trending",
52
+ "thsl_hot_search", "ths_hot_search",
53
+ "law_text", "legal", "us_legal", "japan_law", "kor_law",
54
+ "wenshu_query", "patent_search",
55
+ "scholar_search", "medical", "outbreak_health",
56
+ "astro_space", "earth_science", "energy_grid", "transport_rt",
57
+ "trade_stats", "vehicle_data", "soil_agri", "standards",
58
+ "dataset_search", "chem_search", "species_search", "protein_search",
59
+ "rfc_search", "package_intel", "package_search",
60
+ })
61
+
62
+
63
+ def has_local_signal(query: str) -> bool:
64
+ """查询是否带有本地工程/文件意图信号。"""
65
+ if not query:
66
+ return False
67
+ return bool(_LOCAL_SIGNAL_RE.search(query))
68
+
69
+
70
+ def should_skip_local(domain: str | None, query: str) -> bool:
71
+ """是否跳过本机检索。
72
+
73
+ 跳过条件(两条都满足):
74
+ - domain 命中公域答案型名单;
75
+ - query 不含本地工程/文件意图信号。
76
+
77
+ 显式 `--include-local` / MCP include_local=True 不受此判定影响
78
+ (调用方已经点名要搜,判据不该推翻用户意图)。
79
+ """
80
+ if not domain or domain not in _PUBLIC_ONLY_DOMAINS:
81
+ return False
82
+ return not has_local_signal(query)
83
+
84
+
85
+ # ── 信号驱动判据(2026-11-10 P0-1)─────────────────────────────────────────
86
+ # 为什么需要:默认双轨下,本机轨对纯公网查询不是「空跑」——实测
87
+ # 「attention mechanism paper」「红烧肉 做法」等查询本机轨同样返回 3 条命中,
88
+ # 经 shape_response 并入总结果(总条数 8 条里 3 条是本地噪声),还白付 100-160ms。
89
+ # 原判据只覆盖「公域答案型域」(实测只跳过 36% 的样本),泛查询仍默认双轨。
90
+ #
91
+ # 新判据把默认翻转为信号驱动:**只有查询明确带本地意图才跑本机轨**。
92
+ # 判据失败 fail-open(宁可多搜也不误杀)——见 should_run_local_by_signal。
93
+
94
+ # 单一真源:强弱工程意图信号统一由 _LOCAL_SIGNAL_RE 判定(单一事实来源,消除漂移)
95
+ _STRONG_LOCAL_SIGNAL_RE = _LOCAL_SIGNAL_RE
96
+
97
+
98
+ def has_strong_local_signal(query: str) -> bool:
99
+ """查询是否带本地意图信号(复用 _LOCAL_SIGNAL_RE,含词边界保护)。
100
+
101
+ 为什么复用而不是新写正则:_LOCAL_SIGNAL_RE 已用 `\\b` 词边界处理了
102
+ `def`/`class` 与 `default`/`classic` 的歧义("default" 不匹配 `def`),
103
+ 且覆盖异常类、私有符号、扩展名、工程文件、中文本地说法。重写一份必然引入漂移。
104
+ """
105
+ if not query:
106
+ return False
107
+ return has_local_signal(query)
108
+
109
+
110
+ def should_run_local_by_signal(query: str, domain: str | None = None) -> bool:
111
+ """信号驱动:查询带本地意图信号时才跑本机轨。
112
+
113
+ 这是默认路径(include_local=None)的主判据。与 should_skip_local 的分工:
114
+ - should_skip_local:公域答案型域的补充跳过(仍保留,覆盖
115
+ 「域已确定是天气但查询写法不含强信号」的漏网情形);
116
+ - should_run_local_by_signal:默认路径的主判据(无域信息时靠它)。
117
+
118
+ 判据(两层信号,任一命中即跑):
119
+ 1. 强信号:路径前缀、文件扩展名、工程文件、中文本地说法;
120
+ 2. 弱信号 + 中文:代码关键词(def/class/fn)+ 中文语境
121
+ —— 「def cache_key 怎么实现的」是明确的本地代码检索意图,
122
+ 但纯英文「python asyncio error handling」不是。
123
+
124
+ 公域答案型域(天气/汇率等)且无强信号时,即使有弱信号也不跑
125
+ ——这类查询的本机结果必然是噪声。
126
+ """
127
+ if has_strong_local_signal(query):
128
+ return True
129
+ # 弱信号(代码词)+ 中文语境:中文出现时「def」几乎必然指代码
130
+ if domain and domain in _PUBLIC_ONLY_DOMAINS:
131
+ return False
132
+ if has_local_signal(query) and _has_cjk(query):
133
+ return True
134
+ return False
135
+
136
+
137
+ def _has_cjk(query: str) -> bool:
138
+ """查询是否含中文(CJK 统一表意文字)。"""
139
+ return any('\u4e00' <= ch <= '\u9fff' for ch in query)