argo-search 2.15.0 → 2.17.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 (183) hide show
  1. package/AGENTS.md +3 -1
  2. package/README.es.md +32 -5
  3. package/README.ja.md +32 -5
  4. package/README.ko.md +32 -5
  5. package/README.md +73 -19
  6. package/README.zh.md +73 -19
  7. package/SKILL.md +7 -7
  8. package/assets/readme/counts.json +1 -1
  9. package/assets/readme/hero.svg +3 -3
  10. package/assets/readme/hero.template.svg +121 -0
  11. package/assets/readme/proof-routes.svg +17 -16
  12. package/backends/domain_profiles.json +222 -24
  13. package/backends/engine_registry.yaml +26 -2
  14. package/backends/env_passthrough.txt +2 -0
  15. package/backends/quota_profiles.json +23 -3
  16. package/bin/argo +3 -0
  17. package/config.yaml +16 -0
  18. package/docs/CHANGELOG.md +31 -0
  19. package/docs/COMMIT_STANDARD.md +10 -0
  20. package/docs/ENGINE_CATALOG.md +40 -37
  21. package/docs/MCP_SETUP.md +9 -0
  22. package/docs/RELEASE_NOTES_v2.16.0.md +58 -0
  23. package/docs/RELEASE_NOTES_v2.17.0.md +64 -0
  24. package/docs/RELEASING.md +1 -1
  25. package/engines/specs/archive_org.yaml +1 -1
  26. package/engines/specs/carbon_intensity.yaml +1 -1
  27. package/engines/specs/crates.yaml +1 -1
  28. package/engines/specs/crossref.yaml +6 -2
  29. package/engines/specs/crt_sh.yaml +1 -1
  30. package/engines/specs/dblp.yaml +1 -1
  31. package/engines/specs/devto.yaml +1 -1
  32. package/engines/specs/docker_hub.yaml +1 -1
  33. package/engines/specs/europepmc.yaml +1 -1
  34. package/engines/specs/fxtwitter.yaml +1 -1
  35. package/engines/specs/gbfs_nyc.yaml +1 -1
  36. package/engines/specs/gleif.yaml +1 -1
  37. package/engines/specs/gov_regulations.yaml +1 -1
  38. package/engines/specs/hackernews.yaml +2 -0
  39. package/engines/specs/helve.yaml +49 -0
  40. package/engines/specs/hf_datasets.yaml +1 -1
  41. package/engines/specs/hf_papers.yaml +2 -0
  42. package/engines/specs/huggingface.yaml +1 -1
  43. package/engines/specs/keenable.yaml +7 -1
  44. package/engines/specs/linux_do.yaml +63 -0
  45. package/engines/specs/local_crossref.yaml +3 -1
  46. package/engines/specs/local_github.yaml +1 -1
  47. package/engines/specs/local_npm.yaml +6 -0
  48. package/engines/specs/local_openstreetmap.yaml +1 -1
  49. package/engines/specs/maven.yaml +1 -1
  50. package/engines/specs/mdn.yaml +1 -1
  51. package/engines/specs/musicbrainz.yaml +1 -1
  52. package/engines/specs/nasa_images.yaml +1 -1
  53. package/engines/specs/nhtsa_vpic.yaml +6 -3
  54. package/engines/specs/npm.yaml +1 -1
  55. package/engines/specs/nuget.yaml +1 -1
  56. package/engines/specs/nvd.yaml +1 -1
  57. package/engines/specs/openalex.yaml +13 -4
  58. package/engines/specs/openreview.yaml +1 -1
  59. package/engines/specs/polymarket.yaml +1 -1
  60. package/engines/specs/sec_edgar.yaml +1 -1
  61. package/engines/specs/steam.yaml +1 -1
  62. package/engines/specs/vam.yaml +1 -1
  63. package/engines/specs/wikidata.yaml +1 -1
  64. package/engines/specs/wikipedia.yaml +1 -1
  65. package/engines/specs/zhihu_hot_app.yaml +1 -1
  66. package/package.json +3 -1
  67. package/packages/dsh-plugin/README.md +5 -2
  68. package/packages/dsh-plugin/cordis.patch.yml +4 -1
  69. package/packages/dsh-plugin/dsh/client.js +69 -74
  70. package/packages/dsh-plugin/dsh/diagnostics.js +25 -4
  71. package/packages/dsh-plugin/dsh/index.js +115 -21
  72. package/packages/dsh-plugin/dsh/route-guard.js +95 -0
  73. package/packages/dsh-plugin/dsh/runner.js +50 -7
  74. package/packages/dsh-plugin/dsh/wide-research.js +20 -18
  75. package/packages/dsh-plugin/dsh/workbench-client.js +895 -0
  76. package/packages/dsh-plugin/dsh/workbench-io.js +163 -0
  77. package/packages/dsh-plugin/dsh/workbench-md.js +386 -0
  78. package/packages/dsh-plugin/dsh/workbench-search.js +385 -0
  79. package/packages/dsh-plugin/dsh/workbench-suggestions.js +460 -0
  80. package/packages/dsh-plugin/dsh/workbench.js +703 -0
  81. package/packages/dsh-plugin/icon.svg +23 -0
  82. package/packages/dsh-plugin/package.json +6 -3
  83. package/packages/dsh-plugin/scripts/sync-local.mjs +4 -2
  84. package/packages/dsh-plugin/scripts/sync-local.sh +4 -2
  85. package/packages/dsh-plugin/test/client.test.js +26 -0
  86. package/packages/dsh-plugin/test/diagnostics.test.js +5 -2
  87. package/packages/dsh-plugin/test/index.test.js +150 -1
  88. package/packages/dsh-plugin/test/workbench-concurrency.test.js +98 -0
  89. package/packages/dsh-plugin/test/workbench.test.js +420 -0
  90. package/scripts/adaptive.py +13 -11
  91. package/scripts/argo_paths.py +2 -2
  92. package/scripts/badcase_ledger.py +9 -0
  93. package/scripts/browser_auth.py +178 -4
  94. package/scripts/cache.py +69 -70
  95. package/scripts/check_commit_report.py +46 -0
  96. package/scripts/chrome_cdp.py +71 -0
  97. package/scripts/circuit_breaker.py +91 -13
  98. package/scripts/config_cache.py +23 -10
  99. package/scripts/daemon.py +14 -2
  100. package/scripts/engine_add.py +45 -0
  101. package/scripts/engine_dispatch.py +32 -49
  102. package/scripts/engine_env.py +13 -4
  103. package/scripts/engine_failure.py +33 -0
  104. package/scripts/engine_fingerprint.py +114 -0
  105. package/scripts/engine_health.py +130 -0
  106. package/scripts/engine_states.py +50 -0
  107. package/scripts/engines_base.py +31 -19
  108. package/scripts/engines_builders_archive.py +4 -3
  109. package/scripts/engines_builders_batch11.py +2 -1
  110. package/scripts/engines_builders_batch13.py +4 -3
  111. package/scripts/engines_builders_batch14.py +2 -1
  112. package/scripts/engines_builders_batch15.py +2 -1
  113. package/scripts/engines_builders_batch9.py +2 -2
  114. package/scripts/engines_builders_cn.py +7 -7
  115. package/scripts/engines_builders_data.py +12 -11
  116. package/scripts/engines_builders_data_macro.py +5 -4
  117. package/scripts/engines_builders_dsh.py +2 -1
  118. package/scripts/engines_builders_feeds.py +34 -19
  119. package/scripts/engines_builders_finance.py +2 -1
  120. package/scripts/engines_builders_intl.py +3 -2
  121. package/scripts/engines_builders_media.py +59 -12
  122. package/scripts/engines_builders_science.py +8 -7
  123. package/scripts/engines_builders_search.py +19 -8
  124. package/scripts/engines_builders_skill.py +2 -1
  125. package/scripts/engines_builders_tech.py +19 -19
  126. package/scripts/engines_builders_weather.py +9 -4
  127. package/scripts/engines_fields.py +23 -0
  128. package/scripts/engines_http.py +50 -1
  129. package/scripts/engines_mcp.py +28 -6
  130. package/scripts/evidence_grounding.py +182 -0
  131. package/scripts/evidence_loop.py +15 -1
  132. package/scripts/extend_route_labels.py +6 -0
  133. package/scripts/fetch_browser.py +25 -10
  134. package/scripts/fetch_jina.py +98 -0
  135. package/scripts/fetch_v3.py +52 -93
  136. package/scripts/gate_manifest_check.py +75 -0
  137. package/scripts/gen_readme_art.py +264 -0
  138. package/scripts/image_vision/vision_probe +0 -0
  139. package/scripts/install.sh +2 -0
  140. package/scripts/matrix_search_eval.py +8 -10
  141. package/scripts/mcp_transport.py +33 -9
  142. package/scripts/numeric_verify.py +12 -2
  143. package/scripts/output_transparency.py +3 -0
  144. package/scripts/pre-commit +57 -8
  145. package/scripts/query_operators.py +229 -1
  146. package/scripts/quota.py +46 -63
  147. package/scripts/recovery.py +19 -16
  148. package/scripts/recovery_runner.py +29 -10
  149. package/scripts/redskill/redskill_engine.py +2 -1
  150. package/scripts/release.py +16 -1
  151. package/scripts/research_gates.py +85 -1
  152. package/scripts/route.py +8 -0
  153. package/scripts/route_combo.py +24 -3
  154. package/scripts/route_policy.py +1 -1
  155. package/scripts/search_attribution.py +20 -0
  156. package/scripts/search_entry.py +27 -0
  157. package/scripts/search_output.py +18 -7
  158. package/scripts/search_pipeline.py +3 -3
  159. package/scripts/semantic_evidence.py +20 -11
  160. package/scripts/serp_guard.py +13 -1
  161. package/scripts/settings_page.py +1 -0
  162. package/scripts/single_flight.py +1 -1
  163. package/scripts/social_engines/hackernews_engine.py +2 -1
  164. package/scripts/social_engines/reddit_engine.py +2 -1
  165. package/scripts/social_engines/zhihu_engine.py +2 -1
  166. package/scripts/source_audit.py +42 -7
  167. package/scripts/source_discovery.py +611 -0
  168. package/scripts/sync_backends.py +45 -0
  169. package/scripts/usage_log.py +24 -9
  170. package/scripts/watch.py +3 -3
  171. package/scripts/zhihu_quota.py +2 -1
  172. package/sub-skills/argo-wide-research/SKILL.md +7 -5
  173. package/sub-skills/ego-search/{SKILL.md → README.md} +24 -47
  174. package/sub-skills/ego-search/scripts/ego_search.py +195 -19
  175. package/sub-skills/ego-search/scripts/pacing.py +291 -0
  176. package/sub-skills/ego-search/scripts/quality.py +262 -6
  177. package/sub-skills/ego-search/scripts/runtime.py +7 -1
  178. package/sub-skills/ego-search/scripts/site_profiles.py +157 -0
  179. package/sub-skills/ego-search/scripts/webbridge_adapter.py +7 -1
  180. package/sub-skills/js-run/{SKILL.md → README.md} +3 -20
  181. package/sub-skills/local-search/{SKILL.md → README.md} +3 -8
  182. package/sub-skills/local-search/engine_registry.py +32 -7
  183. package/sub-skills/local-seek/SKILL.md +20 -22
@@ -17,6 +17,7 @@ from typing import Any
17
17
 
18
18
  from cjk_tokens import cjk_term_grams, signal_tokens
19
19
  from engine_env import get_env
20
+ from engines_http import UA
20
21
  from engines_base import (
21
22
  rank_score,
22
23
  safe_search, _run, _resolve, _get_path, _coerce_field, _detect_anti_bot,
@@ -42,7 +43,7 @@ def _build_open_library_engine(spec: dict[str, Any]) -> Any:
42
43
  })
43
44
  try:
44
45
  with http_open(urllib.request.Request(
45
- url, headers={"User-Agent": "argo-search/2.4 (unified-search@local)"}), timeout=to, engine=spec.get("_name", "")) as resp:
46
+ url, headers={"User-Agent": UA}), timeout=to, engine=spec.get("_name", "")) as resp:
46
47
  data = json.loads(resp.read().decode("utf-8", "replace"))
47
48
  except Exception as e:
48
49
  logger.warning(f"Open Library 失败: {e}")
@@ -96,7 +97,7 @@ def _build_weread_engine(spec: dict[str, Any]) -> Any:
96
97
  headers={
97
98
  "Authorization": f"Bearer {key}",
98
99
  "Content-Type": "application/json",
99
- "User-Agent": "argo-search/2.4 (unified-search@local)",
100
+ "User-Agent": UA,
100
101
  },
101
102
  )
102
103
  try:
@@ -225,7 +226,7 @@ def _build_free_dictionary_engine(spec: dict[str, Any]) -> Any:
225
226
  url = f"https://api.dictionaryapi.dev/api/v2/entries/en/{up.quote(word)}"
226
227
  try:
227
228
  with http_open(urllib.request.Request(
228
- url, headers={"User-Agent": "argo-search/2.4"}), timeout=to, engine=spec.get("_name", "")) as resp:
229
+ url, headers={"User-Agent": UA}), timeout=to, engine=spec.get("_name", "")) as resp:
229
230
  entries = json.loads(resp.read().decode("utf-8", "replace"))
230
231
  except Exception:
231
232
  return []
@@ -362,7 +363,7 @@ def _build_pypi_engine(spec: dict[str, Any]) -> Any:
362
363
  to = _timeout or timeout
363
364
  results: list[dict[str, Any]] = []
364
365
  seen: set[str] = set()
365
- headers = {"User-Agent": "argo-search/2.5 (unified-search@local)", "Accept": "application/json"}
366
+ headers = {"User-Agent": UA, "Accept": "application/json"}
366
367
  for _rk4, name in enumerate(_candidates(query)):
367
368
  if len(results) >= n:
368
369
  break
@@ -479,7 +480,7 @@ def _build_models_dev_engine(spec: dict[str, Any]) -> Any:
479
480
  if cached is None or (now - ts) > _MODELS_DEV_TTL:
480
481
  req = urllib.request.Request(
481
482
  "https://models.dev/api.json",
482
- headers={"User-Agent": "argo-search/1.0 (+models.dev)"},
483
+ headers={"User-Agent": UA},
483
484
  )
484
485
  with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
485
486
  cached = json.loads(resp.read().decode("utf-8"))
@@ -592,7 +593,7 @@ def _build_qweather_engine(spec: dict[str, Any]) -> Any:
592
593
 
593
594
  # 1) GeoAPI: 城市 → LocationID
594
595
  geo_url = f"https://geoapi.qweather.com/v2/city/lookup?location={up.quote(city)}&key={key}"
595
- req = urllib.request.Request(geo_url, headers={"User-Agent": "argo-search/1.0"})
596
+ req = urllib.request.Request(geo_url, headers={"User-Agent": UA})
596
597
  with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
597
598
  geo = json.loads(resp.read().decode("utf-8"))
598
599
  locations = geo.get("location") or []
@@ -604,7 +605,7 @@ def _build_qweather_engine(spec: dict[str, Any]) -> Any:
604
605
 
605
606
  # 2) 实时天气
606
607
  now_url = f"https://devapi.qweather.com/v7/weather/now?location={loc_id}&key={key}"
607
- req2 = urllib.request.Request(now_url, headers={"User-Agent": "argo-search/1.0"})
608
+ req2 = urllib.request.Request(now_url, headers={"User-Agent": UA})
608
609
  with http_open(req2, timeout=to, engine=spec.get("_name", "")) as resp:
609
610
  data = json.loads(resp.read().decode("utf-8"))
610
611
  now = data.get("now") or {}
@@ -731,7 +732,7 @@ def _build_rfc_editor_engine(spec: dict[str, Any]) -> Any:
731
732
  「RFC 9000」直接定位单篇;「QUIC RFC」按标题搜索 RFC 类型文档。
732
733
  """
733
734
  timeout = spec.get("timeout", 15)
734
- _HEADERS = {"User-Agent": "argo-search/2.6 (unified-search@local)", "Accept": "application/json"}
735
+ _HEADERS = {"User-Agent": UA, "Accept": "application/json"}
735
736
 
736
737
  def _jget(url: str, to: float) -> dict:
737
738
  req = urllib.request.Request(url, headers=_HEADERS)
@@ -813,7 +814,7 @@ def _build_marginalia_engine(spec: dict[str, Any]) -> Any:
813
814
  url = f"{base}/search?query={up.quote(query)}"
814
815
  try:
815
816
  with http_open(urllib.request.Request(
816
- url, headers={"User-Agent": "argo-search/2.4 (unified-search@local)"}), timeout=to, engine=spec.get("_name", "")) as resp:
817
+ url, headers={"User-Agent": UA}), timeout=to, engine=spec.get("_name", "")) as resp:
817
818
  page = resp.read().decode("utf-8", "replace")
818
819
  except Exception as e:
819
820
  logger.warning(f"Marginalia 失败: {e}")
@@ -824,7 +825,7 @@ def _build_marginalia_engine(spec: dict[str, Any]) -> Any:
824
825
  try:
825
826
  with http_open(urllib.request.Request(
826
827
  base + gate.group(1).replace("&", "&"),
827
- headers={"User-Agent": "argo-search/2.4 (unified-search@local)"}), timeout=to, engine=spec.get("_name", "")) as resp:
828
+ headers={"User-Agent": UA}), timeout=to, engine=spec.get("_name", "")) as resp:
828
829
  page = resp.read().decode("utf-8", "replace")
829
830
  except Exception as e:
830
831
  logger.warning(f"Marginalia sst 复访失败: {e}")
@@ -885,7 +886,7 @@ def _build_wiby_engine(spec: dict[str, Any]) -> Any:
885
886
  url = f"https://wiby.me/json/?q={up.quote(query)}"
886
887
  try:
887
888
  with http_open(urllib.request.Request(
888
- url, headers={"User-Agent": "argo-search/2.4 (unified-search@local)"}), timeout=to, engine=spec.get("_name", "")) as resp:
889
+ url, headers={"User-Agent": UA}), timeout=to, engine=spec.get("_name", "")) as resp:
889
890
  data = json.loads(resp.read().decode("utf-8", "replace"))
890
891
  except Exception as e:
891
892
  logger.warning(f"Wiby 失败: {e}")
@@ -16,6 +16,7 @@ import urllib.parse
16
16
  import urllib.request
17
17
  from typing import Any
18
18
 
19
+ from engines_http import UA
19
20
  from engines_base import (
20
21
  safe_search, _run, _resolve, _get_path, _coerce_field, _detect_anti_bot,
21
22
  http_open, rank_score,
@@ -94,7 +95,7 @@ def _build_fred_engine(spec: dict[str, Any]) -> Any:
94
95
  return []
95
96
  url = f"https://fred.stlouisfed.org/graph/fredgraph.csv?id={series_id}"
96
97
  try:
97
- req = urllib.request.Request(url, headers={"User-Agent": "argo-search/2.4 (unified-search@local)"})
98
+ req = urllib.request.Request(url, headers={"User-Agent": UA})
98
99
  with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
99
100
  text = resp.read().decode("utf-8", "replace")
100
101
  except Exception as e:
@@ -258,7 +259,7 @@ def _build_fx_rate_engine(spec: dict[str, Any]) -> Any:
258
259
  if not base or not target:
259
260
  return []
260
261
  try:
261
- req = urllib.request.Request(api_url + base, headers={"User-Agent": "argo-search/2.4 (unified-search@local)"})
262
+ req = urllib.request.Request(api_url + base, headers={"User-Agent": UA})
262
263
  with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
263
264
  data = json.loads(resp.read().decode("utf-8", "replace"))
264
265
  except Exception as e:
@@ -331,7 +332,7 @@ def _build_worldbank_engine(spec: dict[str, Any]) -> Any:
331
332
  def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
332
333
  import urllib.parse as up
333
334
  to = _timeout or timeout
334
- headers = {"User-Agent": "argo-search/2.4 (unified-search@local)"}
335
+ headers = {"User-Agent": UA}
335
336
  cc, ind, ind_label = _parse(query)
336
337
  if not cc or not ind:
337
338
  return []
@@ -693,7 +694,7 @@ def _build_eurostat_engine(spec: dict[str, Any]) -> Any:
693
694
  支持 EU 国家/欧盟/欧元区的 GDP、人均GDP、失业率、人口年度查询。
694
695
  """
695
696
  timeout = spec.get("timeout", 15)
696
- _HEADERS = {"User-Agent": "argo-search/2.6 (unified-search@local)", "Accept": "application/json"}
697
+ _HEADERS = {"User-Agent": UA, "Accept": "application/json"}
697
698
  _BASE = "https://ec.europa.eu/eurostat/api/dissemination/statistics/1.0/data"
698
699
 
699
700
  def _jget(url: str, to: float) -> dict:
@@ -31,6 +31,7 @@ import urllib.request
31
31
  from pathlib import Path
32
32
  from typing import Any
33
33
 
34
+ from engines_http import UA
34
35
  from engines_base import safe_search, http_open, rank_score
35
36
 
36
37
  # 上游:静态全量目录。Cloudflare 前置,支持 ETag(本 builder 刻意不用,见文件头)。
@@ -116,7 +117,7 @@ def _load_plugins(timeout: float) -> list[dict[str, Any]]:
116
117
  try:
117
118
  req = urllib.request.Request(
118
119
  _DSHOPEN_INDEX_URL,
119
- headers={"User-Agent": "argo-search/1.0", "Accept": "application/json"},
120
+ headers={"User-Agent": UA, "Accept": "application/json"},
120
121
  )
121
122
  with http_open(req, timeout=timeout, engine="dshopen") as resp:
122
123
  payload = json.loads(resp.read())
@@ -85,25 +85,26 @@ def _read_disk_feed(url: str) -> list[dict[str, Any]] | None:
85
85
 
86
86
 
87
87
  def _write_disk_feed(url: str, items: list[dict[str, Any]]) -> None:
88
- """原子更新跨进程轻量磁盘缓存。"""
88
+ """原子更新跨进程轻量磁盘缓存(读改写全程持锁,防并发互覆盖)。"""
89
89
  if not items or "example.test" in url:
90
90
  return
91
91
  try:
92
92
  import argo_paths
93
93
  import json
94
94
  p = argo_paths.state_path("feed_cache.json")
95
- data: dict[str, Any] = {}
96
- if p.is_file():
97
- try:
98
- with open(p, "r", encoding="utf-8") as f:
99
- data = json.load(f)
100
- except Exception:
101
- data = {}
102
- data[url] = {"ts": time.time(), "items": items}
103
- now = time.time()
104
- # 清理 24h 前历史条目,防无界膨胀
105
- data = {k: v for k, v in data.items() if isinstance(v, dict) and (now - float(v.get("ts", 0))) < 86400}
106
- argo_paths.atomic_write_json(p, data)
95
+ with argo_paths.file_lock(p):
96
+ data: dict[str, Any] = {}
97
+ if p.is_file():
98
+ try:
99
+ with open(p, "r", encoding="utf-8") as f:
100
+ data = json.load(f)
101
+ except Exception:
102
+ data = {}
103
+ data[url] = {"ts": time.time(), "items": items}
104
+ now = time.time()
105
+ # 清理 24h 前历史条目,防无界膨胀
106
+ data = {k: v for k, v in data.items() if isinstance(v, dict) and (now - float(v.get("ts", 0))) < 86400}
107
+ argo_paths.atomic_write_json(p, data)
107
108
  except Exception:
108
109
  pass
109
110
 
@@ -301,6 +302,10 @@ def _build_rss_feed_engine(spec: dict[str, Any]) -> Any:
301
302
  min_ratio = float(spec.get("match_min_ratio", 0.34))
302
303
  snippet_max = int(spec.get("snippet_max", 300))
303
304
  hot_base = float(spec.get("hot_base_score", 0.55))
305
+ # 部分站点(如 linux.do)的 Cloudflare 按 TLS 指纹拦 Python 客户端:
306
+ # urllib 403、curl/curl_cffi 200。声明 tls_impersonate: true 的源走
307
+ # curl_cffi 指纹伪造;其余源保持 urllib 路径,行为不变。
308
+ tls_impersonate = bool(spec.get("tls_impersonate"))
304
309
 
305
310
  def _row(it: dict[str, Any], rank: int, score: float,
306
311
  label: str = "") -> dict[str, Any]:
@@ -330,12 +335,22 @@ def _build_rss_feed_engine(spec: dict[str, Any]) -> Any:
330
335
  last_exc: Exception | None = None
331
336
  for attempt in (1, 2):
332
337
  try:
333
- req = urllib.request.Request(
334
- url, headers={"User-Agent": _UA, "Accept": "*/*"})
335
- with http_open(req, timeout=one_timeout, engine=name) as resp:
336
- # utf-8-sig 去掉美联储 press_all.xml 开头的 BOM。
337
- # ElementTree 见到 U+FEFF 会整份解析失败。
338
- raw = resp.read().decode("utf-8-sig", "replace")
338
+ if tls_impersonate:
339
+ from http_client import HttpClient
340
+ client = HttpClient(timeout=one_timeout, max_retries=0)
341
+ resp = client.get_impersonated(
342
+ url, extra_headers={"User-Agent": _UA,
343
+ "Accept": "*/*"})
344
+ if resp.get("status") != 200:
345
+ raise IOError(f"HTTP {resp.get('status')}")
346
+ raw = resp.get("text") or ""
347
+ else:
348
+ req = urllib.request.Request(
349
+ url, headers={"User-Agent": _UA, "Accept": "*/*"})
350
+ with http_open(req, timeout=one_timeout, engine=name) as resp:
351
+ # utf-8-sig 去掉美联储 press_all.xml 开头的 BOM。
352
+ # ElementTree 见到 U+FEFF 会整份解析失败。
353
+ raw = resp.read().decode("utf-8-sig", "replace")
339
354
  items = _parse_feed(raw)
340
355
  _feed_cache[url] = (time.monotonic(), items)
341
356
  _write_disk_feed(url, items)
@@ -16,6 +16,7 @@ import urllib.request
16
16
  from typing import Any
17
17
 
18
18
  from engine_env import get_env
19
+ from engines_http import UA
19
20
  from engines_base import (
20
21
  rank_score,
21
22
  safe_search, _detect_anti_bot,
@@ -220,7 +221,7 @@ def _build_opencorporates_engine(spec: dict[str, Any]) -> Any:
220
221
  f"?q={urllib.parse.quote(q2)}&per_page={min(n, 10)}"
221
222
  + (f"&api_token={urllib.parse.quote(_token)}" if _token else "")
222
223
  )
223
- headers = {"User-Agent": "argo-search/2.6 (unified-search@local)", "Accept": "application/json"}
224
+ headers = {"User-Agent": UA, "Accept": "application/json"}
224
225
  try:
225
226
  with http_open(urllib.request.Request(url, headers=headers), timeout=to, engine=spec.get("_name", "")) as resp:
226
227
  data = json.loads(resp.read().decode("utf-8", "replace"))
@@ -24,6 +24,7 @@ import urllib.request
24
24
  import xml.etree.ElementTree as ET
25
25
  from typing import Any
26
26
 
27
+ from engines_http import UA
27
28
  from engines_base import safe_search, _http_get_raw, http_open, rank_score
28
29
  from bounded_run import run_bounded
29
30
  from engines_http import (
@@ -710,7 +711,7 @@ def _build_google_news_engine(spec: dict[str, Any]) -> Any:
710
711
  hl, gl, ceid = _news_locale(q)
711
712
  url = (f"https://news.google.com/rss/search?q={urllib.parse.quote(q)}"
712
713
  f"&hl={hl}&gl={gl}&ceid={ceid}")
713
- raw = _http_get_raw(url, {"User-Agent": "argo-search/1.0 (+google_news)", "Accept": "application/rss+xml"},
714
+ raw = _http_get_raw(url, {"User-Agent": UA, "Accept": "application/rss+xml"},
714
715
  to, engine=spec.get("_name", "google_news"))
715
716
  if raw is None:
716
717
  return []
@@ -763,7 +764,7 @@ def _build_met_museum_engine(spec: dict[str, Any]) -> Any:
763
764
  return []
764
765
  to = _timeout or timeout
765
766
  engine_name = spec.get("_name", "met_museum")
766
- headers = {"User-Agent": "argo-search/1.0 (+met_museum)", "Accept": "application/json"}
767
+ headers = {"User-Agent": UA, "Accept": "application/json"}
767
768
  search_url = f"{_SEARCH_BASE}/search?q={urllib.parse.quote(q)}&hasImages=true"
768
769
  raw = _http_get_raw(search_url, headers, to, engine=engine_name)
769
770
  if raw is None:
@@ -15,10 +15,15 @@ import urllib.request
15
15
  from html import unescape as _unescape
16
16
  from typing import Any
17
17
 
18
+ from engines_http import UA
18
19
  from engines_base import (
19
20
  rank_score,
20
21
  safe_search, http_open,
21
22
  )
23
+ from retry_policy import (
24
+ NON_RETRYABLE_STATUS as _NON_RETRYABLE_STATUS,
25
+ classify_error_status,
26
+ )
22
27
 
23
28
  logger = logging.getLogger("unified_search.engines")
24
29
 
@@ -213,7 +218,7 @@ def _build_itunes_engine(spec: dict[str, Any]) -> Any:
213
218
  base = spec.get("url") or "https://itunes.apple.com/search"
214
219
  lookup_base = (base.replace("/search", "/lookup") if "/search" in base
215
220
  else "https://itunes.apple.com/lookup")
216
- ua_headers = {"User-Agent": "argo-search/2.6 (itunes)", "Accept": "application/json"}
221
+ ua_headers = {"User-Agent": UA, "Accept": "application/json"}
217
222
 
218
223
  def _get_json(url: str, to: float) -> dict[str, Any]:
219
224
  req = urllib.request.Request(url, headers=ua_headers)
@@ -464,10 +469,18 @@ def _build_itunes_engine(spec: dict[str, Any]) -> Any:
464
469
  return _engine
465
470
 
466
471
 
467
- # ── TheSportsDB 体育(免认证 test key=3) ────────────────────────────────────
472
+ # ── TheSportsDB 体育(免认证 test key=123) ──────────────────────────────────
473
+ # 旧免费 key=3 已被厂方永久停用(403 正文:"The old '3' Free Sports API key is
474
+ # permanently disabled, Please use the new test key \"123\"")。2026-11-17 实测
475
+ # key=123 对 searchplayers/searchteams 返回 200,key=3 恒 403、key=1 报
476
+ # "Invalid Premium API key"。换 key 前该源对任何查询都是确定性 403。
468
477
 
469
- _SPORTSDB_BASE = "https://www.thesportsdb.com/api/v1/json/3"
470
- _SPORTSDB_UA = "argo-search/2.6 (unified-search@local)"
478
+ _SPORTSDB_BASE = "https://www.thesportsdb.com/api/v1/json/123"
479
+ _SPORTSDB_UA = UA
480
+ # 实体问早停线:player/team 单条 rel 到这条线就说明主实体已到手,继续扇出
481
+ # 只是同一答案的重复请求(旧实现最多 15 次串行请求,实测 34s 直接吃掉引擎
482
+ # 超时)。赛事问不套这条线——「World Cup 2022」要的是多实体多样性。
483
+ _ENTITY_HIT_FLOOR = 0.9
471
484
 
472
485
  # 高频中文球员/球队 → TheSportsDB 英文检索名(公开 API 基本只认拉丁文)
473
486
  _SPORTS_ZH_ALIASES: dict[str, str] = {
@@ -511,7 +524,7 @@ def _sports_expand_aliases(query: str) -> list[str]:
511
524
 
512
525
 
513
526
  def _build_thesportsdb_engine(spec: dict[str, Any]) -> Any:
514
- """TheSportsDB 球员/球队/赛事搜索(api key=3 公开测试钥,免认证)。
527
+ """TheSportsDB 球员/球队/赛事搜索(api key=123 公开测试钥,免认证)。
515
528
 
516
529
  并行查 searchplayers / searchteams / searchevents,合并去重。
517
530
  """
@@ -520,11 +533,21 @@ def _build_thesportsdb_engine(spec: dict[str, Any]) -> Any:
520
533
 
521
534
  def _fetch(path: str, params: dict[str, str], to: float) -> Any:
522
535
  url = f"{_SPORTSDB_BASE}/{path}?" + urllib.parse.urlencode(params)
523
- req = urllib.request.Request(
524
- url, headers={"User-Agent": _SPORTSDB_UA, "Accept": "application/json"},
525
- )
526
- with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
527
- return json.loads(resp.read().decode("utf-8", "replace"))
536
+ # 瞬时错误(SSL EOF、握手超时、5xx)重试一次:实体问早停后整台引擎只剩
537
+ # 一次请求,一次网络抖动就是全盘 0 结果,而 403/配额这类确定性失败不重试。
538
+ last: Exception | None = None
539
+ for _attempt in range(2):
540
+ req = urllib.request.Request(
541
+ url, headers={"User-Agent": _SPORTSDB_UA, "Accept": "application/json"},
542
+ )
543
+ try:
544
+ with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
545
+ return json.loads(resp.read().decode("utf-8", "replace"))
546
+ except Exception as e:
547
+ last = e
548
+ if classify_error_status(str(e)) in _NON_RETRYABLE_STATUS:
549
+ raise
550
+ raise last # type: ignore[misc]
528
551
 
529
552
  @safe_search
530
553
  def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
@@ -623,12 +646,22 @@ def _build_thesportsdb_engine(spec: dict[str, Any]) -> Any:
623
646
 
624
647
  q_token_set = {t.lower() for t in meaningful}
625
648
 
649
+ # 确定性失败(配额/鉴权/封锁)不重试:变体与端点只是同一堵墙的不同叫法。
650
+ fatal = False
651
+ strong_hit = False
626
652
  for v in variants:
653
+ if fatal or strong_hit:
654
+ break
627
655
  for path, param_k, kind, title_k, id_k, snip_fn in endpoints:
656
+ if strong_hit:
657
+ break
628
658
  try:
629
659
  data = _fetch(path, {param_k: v}, to)
630
660
  except Exception as e:
631
661
  logger.warning(f"TheSportsDB {path} 失败: {e}")
662
+ if classify_error_status(str(e)) in _NON_RETRYABLE_STATUS:
663
+ fatal = True
664
+ break
632
665
  continue
633
666
  items = data.get(list_keys[path]) if isinstance(data, dict) else None
634
667
  if not items:
@@ -685,8 +718,13 @@ def _build_thesportsdb_engine(spec: dict[str, Any]) -> Any:
685
718
  rel = 0.35 + 0.25 * overlap
686
719
  if v.lower() in title.lower():
687
720
  rel += 0.25
688
- # 全名变体(Stephen Curry)精确命中加权
689
- if " " in v and v.lower() == title.lower():
721
+ # 全名变体(Stephen Curry)精确命中加权。整句变体带停用词
722
+ # (club/球队)时与 title 不等,但剥掉停用词后全等,同样算
723
+ # 精确命中——否则首个变体永远吃不到这条加权。
724
+ v_norm = " ".join(meaningful).lower()
725
+ if (" " in v and v.lower() == title.lower()) or (
726
+ v_norm and v_norm == title.lower()
727
+ ):
690
728
  rel += 0.3
691
729
  seen.add(key)
692
730
  href = url_tpl[kind].format(id=iid) if iid else ""
@@ -700,6 +738,15 @@ def _build_thesportsdb_engine(spec: dict[str, Any]) -> Any:
700
738
  "_kind": kind,
701
739
  "_rel": rel,
702
740
  })
741
+ # 实体问早停:球员/球队强命中即收工。判据不能只看 prefer_entity——
742
+ # 调度层 _entity_core_query 会剥掉 club/球队 等属性词,「Cristiano
743
+ # Ronaldo」这类裸实体名到引擎时已无属性词,仍必须早停,否则扇出
744
+ # 十几次请求(实测 8s,管道 6s 预算下直接 0 结果)。赛事问
745
+ # (prefer_event)不套这条线,保持多实体多样性。
746
+ if (kind in ("player", "team") and not prefer_event
747
+ and rel >= _ENTITY_HIT_FLOOR):
748
+ strong_hit = True
749
+ break
703
750
  # 已有高相关实体则早停
704
751
  if sum(1 for r in bucket if r.get("_rel", 0) >= 0.5) >= n:
705
752
  break
@@ -16,6 +16,7 @@ import urllib.request
16
16
  from typing import Any
17
17
 
18
18
  from cjk_tokens import cjk_term_grams
19
+ from engines_http import UA
19
20
  from engines_base import (
20
21
  rank_score,
21
22
  safe_search, http_open,
@@ -44,7 +45,7 @@ def _build_openfda_engine(spec: dict[str, Any]) -> Any:
44
45
  "search": search, "limit": min(n, 20)})
45
46
  try:
46
47
  with http_open(urllib.request.Request(
47
- url, headers={"User-Agent": "argo-search/2.5", "Accept": "application/json"}), timeout=to, engine=spec.get("_name", "")) as resp:
48
+ url, headers={"User-Agent": UA, "Accept": "application/json"}), timeout=to, engine=spec.get("_name", "")) as resp:
48
49
  data = json.loads(resp.read().decode("utf-8", "replace"))
49
50
  except Exception as e:
50
51
  # 回退:全文检索
@@ -53,7 +54,7 @@ def _build_openfda_engine(spec: dict[str, Any]) -> Any:
53
54
  "search": q, "limit": min(n, 20),
54
55
  })
55
56
  with http_open(urllib.request.Request(
56
- url2, headers={"User-Agent": "argo-search/2.5"}), timeout=to, engine=spec.get("_name", "")) as resp:
57
+ url2, headers={"User-Agent": UA}), timeout=to, engine=spec.get("_name", "")) as resp:
57
58
  data = json.loads(resp.read().decode("utf-8", "replace"))
58
59
  except Exception as e2:
59
60
  logger.warning(f"openfda 失败: {e2}")
@@ -199,7 +200,7 @@ def _build_pubchem_engine(spec: dict[str, Any]) -> Any:
199
200
  质量闸门:ChEMBL 结果须与查询 token 重叠,否则丢弃当 no-results(宁空勿假)。
200
201
  """
201
202
  timeout = spec.get("timeout", 10)
202
- _HEADERS = {"User-Agent": "argo-search/2.6 (unified-search@local)", "Accept": "application/json"}
203
+ _HEADERS = {"User-Agent": UA, "Accept": "application/json"}
203
204
 
204
205
  def _jget(url: str, to: float) -> dict:
205
206
  req = urllib.request.Request(url, headers=_HEADERS)
@@ -329,7 +330,7 @@ def _build_gbif_engine(spec: dict[str, Any]) -> Any:
329
330
  学名/俗名搜索,优先学名包含查询词的 ACCEPTED 物种条目。
330
331
  """
331
332
  timeout = spec.get("timeout", 12)
332
- _HEADERS = {"User-Agent": "argo-search/2.6 (unified-search@local)"}
333
+ _HEADERS = {"User-Agent": UA}
333
334
 
334
335
  def _jget(url: str, to: float) -> dict:
335
336
  req = urllib.request.Request(url, headers=_HEADERS)
@@ -426,7 +427,7 @@ def _build_uniprot_engine(spec: dict[str, Any]) -> Any:
426
427
  中英混合查询只取 ASCII token(UniProt 不索引中文),纯中文查高频蛋白名映射表。
427
428
  """
428
429
  timeout = spec.get("timeout", 12)
429
- _HEADERS = {"User-Agent": "argo-search/2.6 (unified-search@local)", "Accept": "application/json"}
430
+ _HEADERS = {"User-Agent": UA, "Accept": "application/json"}
430
431
 
431
432
  @safe_search
432
433
  def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
@@ -482,7 +483,7 @@ def _build_rcsb_pdb_engine(spec: dict[str, Any]) -> Any:
482
483
  全文搜索返回 PDB ID 列表,链接到 rcsb.org/structure/{id}。
483
484
  """
484
485
  timeout = spec.get("timeout", 15)
485
- _HEADERS = {"User-Agent": "argo-search/2.6 (unified-search@local)",
486
+ _HEADERS = {"User-Agent": UA,
486
487
  "Accept": "application/json", "Content-Type": "application/json"}
487
488
 
488
489
  @safe_search
@@ -550,7 +551,7 @@ def _build_usgs_engine(spec: dict[str, Any]) -> Any:
550
551
  按 place 字段过滤,命中地点相关地震。
551
552
  """
552
553
  timeout = spec.get("timeout", 12)
553
- _HEADERS = {"User-Agent": "argo-search/2.6 (unified-search@local)", "Accept": "application/json"}
554
+ _HEADERS = {"User-Agent": UA, "Accept": "application/json"}
554
555
 
555
556
  @safe_search
556
557
  def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
@@ -78,12 +78,13 @@ def _build_parallel_engine(spec: dict[str, Any]) -> Any:
78
78
  "excerpt_settings": {"max_chars_per_result": 300},
79
79
  },
80
80
  }
81
- # argo 时间窗 --since → after_date(官方 --after-date)
82
- since = kwargs.get("since")
83
- if since:
84
- date_str = str(since)[:10]
85
- if re.fullmatch(r"\d{4}-\d{2}-\d{2}", date_str):
86
- body["advanced_settings"]["source_policy"] = {"after_date": date_str}
81
+ # argo 原生能力下推:since/until/sites/exclude_sites → source_policy
82
+ from query_operators import compile_provider_params
83
+ _p_hints = compile_provider_params(
84
+ "parallel", query, operators=kwargs.get("operators"),
85
+ since=kwargs.get("since"), until=kwargs.get("until"), depth=depth)
86
+ if _p_hints.get("source_policy"):
87
+ body["advanced_settings"]["source_policy"] = _p_hints["source_policy"]
87
88
  req = urllib.request.Request(
88
89
  _PARALLEL_URL,
89
90
  data=json.dumps(body).encode("utf-8"),
@@ -325,10 +326,20 @@ def _build_you_engine(spec: dict[str, Any]) -> Any:
325
326
  if not key:
326
327
  return [{"error": "YDC_API_KEY 未设置", "source": "you"}]
327
328
  body: dict[str, Any] = {"query": query, "count": max(1, int(n or 5))}
328
- freshness = _you_freshness(query)
329
+ from query_operators import compile_provider_params, is_evergreen_tech_query
330
+ _y_hints = compile_provider_params(
331
+ "you", query, operators=kwargs.get("operators"),
332
+ since=kwargs.get("since"), until=kwargs.get("until"))
333
+ # you 分支只产出 boost_domains/country/language(query_operators.compile_provider_params),
334
+ # 不产 freshness——此前的 _y_hints.get("freshness") 是永远取不到值的死读取
335
+ # (2026-11-20 审计:接线到一半),freshness 走下面的动态兜底。
336
+ freshness = "" if is_evergreen_tech_query(query) else _you_freshness(query)
329
337
  if freshness:
330
338
  body["freshness"] = freshness
331
- body["language"] = _you_language(query)
339
+ body["language"] = _y_hints.get("language") or _you_language(query)
340
+ for _k in ("country", "boost_domains"):
341
+ if _k in _y_hints:
342
+ body[_k] = _y_hints[_k]
332
343
  req = urllib.request.Request(
333
344
  _YOU_URL,
334
345
  data=json.dumps(body).encode("utf-8"),
@@ -21,6 +21,7 @@ import urllib.parse
21
21
  import urllib.request
22
22
  from typing import Any
23
23
 
24
+ from engines_http import UA
24
25
  from engines_base import safe_search, http_open, rank_score
25
26
 
26
27
  # ── 面向英文技能目录(explainx/skills.sh/skillsmp/clawhub)的轻量中英概念映射 ──
@@ -130,7 +131,7 @@ def _normalize_epoch(val: Any) -> str:
130
131
 
131
132
  def _get_json(url: str, timeout: float, engine: str) -> Any:
132
133
  req = urllib.request.Request(
133
- url, headers={"User-Agent": "argo-search/1.0", "Accept": "application/json"}
134
+ url, headers={"User-Agent": UA, "Accept": "application/json"}
134
135
  )
135
136
  with http_open(req, timeout=timeout, engine=engine) as resp:
136
137
  return json.loads(resp.read())
@@ -16,7 +16,7 @@ from datetime import datetime
16
16
  from email.utils import parsedate_to_datetime
17
17
  from typing import Any
18
18
 
19
- from engines_base import (safe_search, _run, _resolve, _get_path, _coerce_field, rank_score,
19
+ from engines_base import (safe_search, _run, _resolve, _get_path, _coerce_field, rank_score, UA,
20
20
  _http_get_raw, mcp_error_of as _mcp_error_of, http_open, _note_http_failure)
21
21
  from engine_env import get_env
22
22
 
@@ -181,40 +181,40 @@ def _build_exa_engine(spec: dict[str, Any]) -> Any:
181
181
  if not api_key:
182
182
  return _exa_mcp_keyless(query, n, to, spec)
183
183
  url = "https://api.exa.ai/search"
184
- body = json.dumps({
184
+ payload: dict[str, Any] = {
185
185
  "query": query,
186
186
  "type": "auto",
187
187
  "numResults": min(n, 10),
188
188
  "contents": {"text": {"maxCharacters": 400}},
189
- }).encode("utf-8")
189
+ }
190
+ from query_operators import compile_provider_params, format_exa_notices
191
+ payload.update(compile_provider_params(
192
+ "exa", query, operators=kwargs.get("operators"),
193
+ since=kwargs.get("since"), until=kwargs.get("until"), depth=depth))
194
+ body = json.dumps(payload).encode("utf-8")
190
195
  headers = {"x-api-key": api_key, "Content-Type": "application/json"}
191
196
  req = urllib.request.Request(url, data=body, headers=headers)
192
197
  try:
193
198
  with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
194
199
  data = json.loads(resp.read().decode("utf-8"))
200
+ notices = format_exa_notices(data.get("notices"))
195
201
  results = []
196
202
  for r in data.get("results", []):
197
203
  snippet = (r.get("text") or r.get("snippet") or "")[:300]
198
- # 轻量清洗:去掉 YAML front-matter(--- 开头的内容块)与导航噪声
199
204
  if snippet.startswith("---"):
200
205
  idx = snippet.find("---", 3)
201
206
  if idx != -1:
202
207
  snippet = snippet[idx + 3:].strip()
203
- # type:auto 模式不返回 score 字段(恒 0 会被 RRF 埋没),
204
- # 无 score 时给固定基线分;并叠加位次衰减。
205
- # 用 None/空串哨兵而不是 `or`:显式 0 分(上游判定不相关)
206
- # 会经 or 被抬成 0.75,与 2026-09-30 修过的同类
207
- # 「0 分垫底变中游」逐字同构。
208
208
  _raw_score = r.get("score")
209
- _base_score = 0.75 if _raw_score is None or _raw_score == "" \
210
- else _raw_score
211
- results.append({
212
- "title": r.get("title", ""),
213
- "url": r.get("url", ""),
214
- "snippet": snippet,
215
- "source": "exa",
209
+ _base_score = 0.75 if _raw_score is None or _raw_score == "" else _raw_score
210
+ item = {
211
+ "title": r.get("title", ""), "url": r.get("url", ""),
212
+ "snippet": snippet, "source": "exa",
216
213
  "score": rank_score(_base_score, len(results)),
217
- })
214
+ }
215
+ if notices and not results:
216
+ item["_notices"] = notices
217
+ results.append(item)
218
218
  return results
219
219
  except Exception as e:
220
220
  logger.warning(f"Exa 引擎失败: {e}")
@@ -533,7 +533,7 @@ def _build_stackoverflow_engine(spec: dict[str, Any]) -> Any:
533
533
  if not q:
534
534
  return []
535
535
  url = f"https://api.stackexchange.com/2.3/search/advanced?order=desc&sort=relevance&q={up.quote(q)}&site={site}&pagesize={min(n, 10)}"
536
- headers = {"User-Agent": "argo-search/1.0", "Accept-Encoding": "gzip"}
536
+ headers = {"User-Agent": UA, "Accept-Encoding": "gzip"}
537
537
  req = urllib.request.Request(url, headers=headers)
538
538
  try:
539
539
  with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
@@ -667,7 +667,7 @@ def _build_github_engine(spec: dict[str, Any]) -> Any:
667
667
  endpoint = _github_endpoint(query, bool(token))
668
668
  url = _github_url(endpoint, query, n)
669
669
  headers = {
670
- "User-Agent": "argo-search/1.0 (+github)",
670
+ "User-Agent": UA,
671
671
  "Accept": "application/vnd.github+json",
672
672
  "X-GitHub-Api-Version": "2022-11-28",
673
673
  }