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
@@ -32,11 +32,13 @@ TLS 指纹伪造层(第一级B):
32
32
 
33
33
  from __future__ import annotations
34
34
 
35
+ import atexit
35
36
  import json
36
37
  import os
37
38
  import re
38
39
  import signal
39
40
  import sys
41
+ import threading
40
42
  import time
41
43
  import traceback
42
44
  import urllib.parse
@@ -54,6 +56,7 @@ if SCRIPT_DIR not in sys.path:
54
56
  # 渲染层(第二级A):TinyFish 直连渲染,独立模块以保持本文件聚焦主链调度;
55
57
  # engine_states 是状态词表唯一真源(2026-11-09 收口)
56
58
  import fetch_render_tinyfish as _render_tinyfish
59
+ import fetch_jina as _fetch_jina
57
60
  import engine_states
58
61
  from except_sets import IO_BENIGN, OPT_IMPORT, SHAPE_BENIGN # 收窄词汇表(2026-11-13 裸吞收口)
59
62
 
@@ -71,7 +74,7 @@ import fetch_quality as _quality
71
74
  # 本地状态目录唯一来源(env ARGO_STATE_DIR → config cache.db_path 父目录 → 旧路径)
72
75
  import argo_paths as _paths
73
76
  from net_proxy import open_url # 出口调度唯一入口(issue #13 同类修复)
74
- from engine_env import env_flag # 布尔开关统一判断(见 env_flag 的说明)
77
+ from engine_env import env_flag, get_env # env_flag 判开关;get_env 读密钥(os.environ 优先,env 文件热读保底)
75
78
  from cli_io import dumps
76
79
  from fetch_jsrun import _jsrun_challenge_fetch, _jsrun_enabled # js-run 轻量车道(拆出独立模块)
77
80
 
@@ -549,11 +552,8 @@ def _mobile_first_host(url: str) -> bool:
549
552
 
550
553
 
551
554
  # ─── 身份记忆(per-host 成功档位,跨进程小文件)─────────────────────────────
552
- #
553
- # 首次访问未知分流站:桌面失败 → 移动成功(2 次触碰);记忆生效后(TTL 24h)
554
- # 直接移动首发(1 次触碰)。实测依据:抖音类站点按 IP 递进限速,请求节奏比
555
- # 身份选择重要一个数量级,省掉的每次试错都是真实的封禁风险。
556
555
  _IDENTITY_TTL = 86400
556
+ _identity_lock = threading.Lock()
557
557
 
558
558
 
559
559
  def _identity_path() -> str:
@@ -561,18 +561,11 @@ def _identity_path() -> str:
561
561
  patched = globals().get("_IDENTITY_PATH")
562
562
  if patched is not None:
563
563
  return patched
564
- return os.environ.get(
565
- "ARGO_IDENTITY_MEMORY",
566
- str(_paths.state_path("fetch-identity.json")))
564
+ return os.environ.get("ARGO_IDENTITY_MEMORY", str(_paths.state_path("fetch-identity.json")))
567
565
 
568
566
 
569
567
  def __getattr__(name: str):
570
- """`_IDENTITY_PATH` 每次访问按当前 ARGO_IDENTITY_MEMORY 解析(PEP 562)。
571
-
572
- 290d3d8 同口径:状态根在导入后被改写是常态(测试临时目录、多工作树)。
573
- 模块内裸名查找不触发本函数(LOAD_GLOBAL 语义),函数体一律走
574
- _identity_path();这里只维持外部属性访问与 monkeypatch 契约。
575
- """
568
+ """`_IDENTITY_PATH` 每次访问按当前 ARGO_IDENTITY_MEMORY 解析(PEP 562)。"""
576
569
  if name == "_IDENTITY_PATH":
577
570
  return _identity_path()
578
571
  raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@@ -582,60 +575,67 @@ _identity_mem: dict[str, float] = {}
582
575
  _identity_loaded = False
583
576
  _identity_dirty = False
584
577
  _identity_last_flush = 0.0
585
- _IDENTITY_FLUSH_INTERVAL = 30.0 # 最多每 30s 写一次文件
578
+ _IDENTITY_FLUSH_INTERVAL = 30.0
579
+ _identity_atexit_registered = False
586
580
 
587
581
 
588
- def _identity_load() -> None:
582
+ def _identity_load_locked() -> None:
589
583
  global _identity_loaded, _identity_mem
590
584
  if _identity_loaded:
591
585
  return
592
586
  _identity_loaded = True
593
587
  try:
594
- with open(_identity_path(), encoding="utf-8") as f: # 写侧 atomic_write_text 恒 UTF-8,读侧同编码
595
- raw = json.load(f)
588
+ raw = json.loads(Path(_identity_path()).read_text(encoding="utf-8"))
596
589
  now = time.time()
597
- mem: dict[str, float] = {}
598
- for h, t in raw.items():
599
- try:
600
- exp = float(t)
601
- if exp > now:
602
- mem[str(h)] = exp
603
- except (TypeError, ValueError):
604
- continue # 单条脏数据不拖垮整表(旧版本/手改字段)
605
- _identity_mem = mem
590
+ _identity_mem = {str(h): float(t) for h, t in raw.items() if isinstance(t, (int, float)) and float(t) > now}
606
591
  except Exception:
607
592
  _identity_mem = {}
608
593
 
609
594
 
610
- def _identity_remember_mobile(host: str) -> None:
611
- """记录「该 host 移动端身份成功过」,最多每 30s 写一次文件。失败静默(纯增益层)。"""
595
+ def _identity_flush() -> None:
612
596
  global _identity_dirty, _identity_last_flush
613
- if not host:
614
- return
615
- _identity_load()
616
- if len(_identity_mem) >= 512: # 有界:内存表防长驻进程无限增长(磁盘侧有 TTL)
617
- _identity_mem.pop(next(iter(_identity_mem)), None)
618
- _identity_mem[host] = time.time() + _IDENTITY_TTL
619
- _identity_dirty = True
620
- now = time.monotonic()
621
- if _identity_last_flush > 0.0 and now - _identity_last_flush < _IDENTITY_FLUSH_INTERVAL:
622
- return
623
- _identity_last_flush = now
597
+ with _identity_lock:
598
+ if not _identity_dirty:
599
+ return
600
+ snap, p = dict(_identity_mem), Path(_identity_path())
601
+ _identity_dirty, _identity_last_flush = False, time.monotonic()
624
602
  try:
625
- # 原子写走 argo_paths 唯一来源(唯一 tmp 名);旧实现固定 `.tmp` 名,
626
- # 并发抓取进程会互相搬走临时文件,身份记忆静默丢失。
627
- _paths.atomic_write_json(Path(_identity_path()), _identity_mem, indent=None)
628
- _identity_dirty = False
629
- except IO_BENIGN:
603
+ now = time.time()
604
+ with _paths.file_lock(p):
605
+ raw = json.loads(p.read_text(encoding="utf-8")) if p.exists() else {}
606
+ merged = {str(h): float(t) for h, t in raw.items() if isinstance(t, (int, float)) and float(t) > now} if isinstance(raw, dict) else {}
607
+ merged.update({h: exp for h, exp in snap.items() if exp > max(now, merged.get(h, 0.0))})
608
+ _paths.atomic_write_json(p, merged, indent=None)
609
+ except (*IO_BENIGN, ValueError):
630
610
  pass
631
611
 
632
612
 
613
+ def _identity_remember_mobile(host: str) -> None:
614
+ """记录「该 host 移动端身份成功过」,最多每 30s 写盘 + atexit 兜底。"""
615
+ global _identity_dirty, _identity_atexit_registered
616
+ if not host:
617
+ return
618
+ with _identity_lock:
619
+ _identity_load_locked()
620
+ if len(_identity_mem) >= 512:
621
+ _identity_mem.pop(next(iter(_identity_mem)), None)
622
+ _identity_mem[host] = time.time() + _IDENTITY_TTL
623
+ _identity_dirty = True
624
+ if not _identity_atexit_registered:
625
+ atexit.register(_identity_flush)
626
+ _identity_atexit_registered = True
627
+ need_flush = _identity_last_flush == 0.0 or (time.monotonic() - _identity_last_flush) >= _IDENTITY_FLUSH_INTERVAL
628
+ if need_flush:
629
+ _identity_flush()
630
+
631
+
633
632
  def _identity_is_mobile(host: str) -> bool:
634
633
  """该 host 近 24h 内移动身份是否成功过。"""
635
634
  if not host:
636
635
  return False
637
- _identity_load()
638
- return _identity_mem.get(host, 0) > time.time()
636
+ with _identity_lock:
637
+ _identity_load_locked()
638
+ return _identity_mem.get(host, 0) > time.time()
639
639
 
640
640
 
641
641
  def _mobile_http_fetch(url: str, max_chars: int = 8000,
@@ -906,19 +906,14 @@ def _make_result(url: str, html: str, max_chars: int,
906
906
  return result
907
907
 
908
908
 
909
- # ─── 第一级C:r.jina.ai 阅读器(keyless 免费层,远端 JS 渲染转 markdown)─────
909
+ # ─── 第三方代理公网边界(jina 与 Parallel 共用;请求层见 fetch_jina.py)─────
910
910
 
911
911
  _JINA_PRIVATE_HOST = re.compile(
912
912
  r"^(localhost|127\.|10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.|169\.254\.|0\.)")
913
913
 
914
914
 
915
- def _jina_enabled() -> bool:
916
- """r.jina.ai 阅读器级开关:ARGO_FETCH_JINA=0 关闭,默认开启。"""
917
- return env_flag("ARGO_FETCH_JINA")
918
-
919
-
920
915
  def _is_public_host(host: str) -> bool:
921
- """r.jina.ai 是第三方代理:只把公网 URL 交给它。
916
+ """第三方代理(r.jina.ai / Parallel)只接公网 URL。
922
917
 
923
918
  内网/本机/裸 IP 一律跳过——把内部地址送出第三方 = 拓扑泄露;
924
919
  域名形 IP(全数字)与含冒号的 IPv6 字面量同判为裸地址。
@@ -934,42 +929,6 @@ def _is_public_host(host: str) -> bool:
934
929
  return "." in host
935
930
 
936
931
 
937
- def _jina_reader_fetch(url: str, max_chars: int = 8000,
938
- timeout: float = 8.0) -> dict | None:
939
- """r.jina.ai 阅读器(keyless 免费层)。
940
-
941
- 定位:HTTP/TLS 直连全败后的免浏览器快速路径——jina 在远端渲染并返回
942
- markdown,命中则免去 CDP 冷启动。免费层有速率限制,失败/429 返回 None
943
- 静默放行走 Wayback/浏览器。调用方须先过 _is_public_host(第三方代理边界)。
944
- """
945
- try:
946
- from http_client import HttpClient
947
- client = HttpClient(timeout=min(timeout, 10.0), max_retries=0,
948
- jitter=False)
949
- resp = client.get(f"https://r.jina.ai/{url}", extra_headers={
950
- "User-Agent": "argo-fetch-v3/1.0 (+local-research; jina-reader)",
951
- "Accept": "text/plain",
952
- })
953
- except Exception:
954
- return None
955
- if resp.get("status", 0) != 200 or not resp.get("text"):
956
- return None
957
- raw = resp["text"]
958
- title = ""
959
- m = re.search(r"^Title:\s*(.+)$", raw[:2000], re.MULTILINE)
960
- if m:
961
- title = m.group(1).strip()[:200]
962
- if "Markdown Content:" in raw:
963
- raw = raw.split("Markdown Content:", 1)[1].lstrip()
964
- if not _looks_like_markdown(raw):
965
- return None
966
- result = _make_result(url, "", max_chars, engine_states.FETCH_JINA_READER)
967
- result["content"] = raw[:max_chars]
968
- result["length"] = len(result["content"])
969
- result["title"] = title
970
- return result
971
-
972
-
973
932
  # ─── 第一级D:Parallel 免费 MCP web_fetch(keyless 云端渲染+提取)────────────
974
933
 
975
934
  _PARALLEL_MCP_URL = "https://search.parallel.ai/mcp"
@@ -1560,15 +1519,15 @@ def fetch_v3(url: str, max_chars: int = 8000, timeout: float = 8.0,
1560
1519
  result = spoof
1561
1520
 
1562
1521
  if not result.get("stop_signal") and _budget_left() > 0:
1563
- # 第一级C:r.jina.ai 阅读器(keyless 免费层,远端 JS 渲染)。
1522
+ # 第一级C:r.jina.ai 阅读器(请求层见 fetch_jina.py)。
1564
1523
  # HTTP/TLS 直连全败时的免浏览器快速路径;markdown-only 同
1565
1524
  # tinyfish,need_html 场景跳过;第三方代理只接公网 URL。
1566
- if (not gated and not need_html and _jina_enabled()
1525
+ if (not gated and not need_html and _fetch_jina.enabled()
1567
1526
  and _is_public_host(host)
1568
1527
  and (not result.get("success")
1569
1528
  or _needs_browser(result))):
1570
1529
  # 超时受剩余预算约束:deadline 场景本级不得击穿总预算
1571
- jina = _jina_reader_fetch(
1530
+ jina = _fetch_jina.fetch(
1572
1531
  url, max_chars, timeout=_level_timeout(timeout))
1573
1532
  if jina is not None and jina.get("success"):
1574
1533
  jina["http_fallback"] = True
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env python3
2
+ """gate_manifest_check.py — 新增测试文件必须登记快门禁清单(commit 期硬拦)。
3
+
4
+ 背景(2026-11-21 审计):test_gate_manifest.py 的反向断言只拦「门禁命名」
5
+ 文件(gate/consistency/drift/… 词根),test_state_machines_plan_b 与
6
+ test_query_operators 两个 <1s 文件漏册未被该机制发现——命名判据盖不全。
7
+ 本检查把拦截点前移到 commit 时刻:git 暂存区新增(A 状态)的
8
+ tests/test_*.py 必须出现在 tests/gate_manifest.txt,否则红灯。存量未登记
9
+ 文件不受影响(由 tests/test_gate_manifest.py 的未登记总数棘轮约束)。
10
+
11
+ 2026-11-21 二次收口:skip 豁免层已取消——13 个 skip 项实测全部 <1s
12
+ (142~727ms)却只由 CI 兜底,导致两次「本地绿、全量红」漏库。现在本地
13
+ 与 CI 共用同一份清单,慢项由 pre-commit 的分片并行消化。
14
+
15
+ 单测:tests/test_gate_manifest.py::TestNewTestFileClassification。
16
+ """
17
+ from __future__ import annotations
18
+
19
+ import re
20
+ import sys
21
+ from pathlib import Path
22
+
23
+ _TEST_FILE_RE = re.compile(r"^tests/test_[a-z0-9_]+\.py$")
24
+
25
+
26
+ def check_new_test_files(staged_files: list[str], manifest_text: str) -> list[str]:
27
+ """返回违规清单:staged 新增 tests/test_*.py 未登记进 manifest(# skip 已取消,不再放行)。"""
28
+ known: set[str] = set()
29
+ for raw in manifest_text.splitlines():
30
+ line = raw.strip()
31
+ if not line or line.startswith("#"):
32
+ continue
33
+ known.add(line)
34
+ return sorted(
35
+ f for f in staged_files
36
+ if _TEST_FILE_RE.match(f) and f not in known
37
+ )
38
+
39
+
40
+ def staged_new_test_files(root: Path) -> list[str]:
41
+ """git 暂存区新增(A 状态)的 tests/test_*.py;非 git 环境返回空(不拦)。"""
42
+ import subprocess
43
+
44
+ try:
45
+ out = subprocess.run(
46
+ ["git", "-C", str(root), "diff", "--cached", "--name-only",
47
+ "--diff-filter=A", "--", "tests/"],
48
+ capture_output=True, text=True, encoding="utf-8", timeout=10, check=True,
49
+ ).stdout
50
+ except (OSError, subprocess.SubprocessError):
51
+ return []
52
+ return [line.strip() for line in out.splitlines() if line.strip()]
53
+
54
+
55
+ def main() -> int:
56
+ root = Path(__file__).resolve().parent.parent
57
+ manifest = root / "tests" / "gate_manifest.txt"
58
+ if not manifest.exists():
59
+ print("[gate-manifest] 缺 tests/gate_manifest.txt,无法判定新增测试归属,门禁视为失败", file=sys.stderr)
60
+ return 1
61
+ staged = staged_new_test_files(root)
62
+ violations = check_new_test_files(staged, manifest.read_text(encoding="utf-8"))
63
+ if violations:
64
+ print("[gate-manifest] 以下新增测试文件未登记 tests/gate_manifest.txt:", file=sys.stderr)
65
+ for f in violations:
66
+ print(f" - {f}", file=sys.stderr)
67
+ print(" 处置:登记进 tests/gate_manifest.txt(本地与 CI 同一份清单,<1s 的", file=sys.stderr)
68
+ print(" 回归门应入册;确实慢的也要登记,由 pre-commit 的分片并行消化)。", file=sys.stderr)
69
+ print(" skip 豁免层已于 2026-11-21 取消,不要再新增。", file=sys.stderr)
70
+ return 1
71
+ return 0
72
+
73
+
74
+ if __name__ == "__main__":
75
+ sys.exit(main())
@@ -0,0 +1,264 @@
1
+ #!/usr/bin/env python3
2
+ """gen_readme_art.py — 从真实路由数据生成 README 对外证据图(proof-routes.svg)。
3
+
4
+ ## 为什么要有这个脚本
5
+
6
+ `assets/readme/proof-routes.svg` 曾是一张**手写** SVG,自称「PROOF · REAL
7
+ ROUTES」,但 2026-11-21 逐条复现发现 4 张卡里 1 张是虚构的:
8
+
9
+ - 「贵州茅台股价 → stock_query / sina·tencent」 实测一致
10
+ - 「Inception director → film_search / imdb·itunes」 实测一致
11
+ - 「アニメ おすすめ → ja / local_bing·ddg」 实测**零命中**(虚构)
12
+ - 「where is Eiffel Tower → geo_places / osm·wiki」 实测一致
13
+
14
+ 根因与 counts.json 同源:图上的数字与路由结论是**手抄**的,没有生成器、
15
+ 没有门禁,于是可以长期漂成理想态。本脚本把图接上**运行时同一批函数**
16
+ (route_domains.match_domains),并把「选哪几条案例」也变成显式清单——
17
+ 清单里的查询必须真实命中声明的域,否则 `--check` 红。
18
+
19
+ ## 与既有生成器的关系
20
+
21
+ 同 `gen_engine_catalog.py`(源数/文档)、`gen_routing_snapshot.py`(路由
22
+ 决策快照)同一范式:真源 → 生成 → `--check` 对拍磁盘。不新增概念。
23
+
24
+ 用法:
25
+ python3 scripts/gen_readme_art.py # 生成(原子写)
26
+ python3 scripts/gen_readme_art.py --check # 只校验,过期/不符退出码 1
27
+ """
28
+ from __future__ import annotations
29
+
30
+ import argparse
31
+ import json
32
+ import sys
33
+ from pathlib import Path
34
+
35
+ SKILL_DIR = Path(__file__).resolve().parent.parent
36
+ SCRIPTS = SKILL_DIR / "scripts"
37
+ SVG_PATH = SKILL_DIR / "assets" / "readme" / "proof-routes.svg"
38
+
39
+ # 对外证据卡:查询 → 期望命中的域。查询必须来自真实语料(ROUTE_MATRIX /
40
+ # LEGITIMATE_ROUTES),不得手编;期望域由 `--check` 用运行时路由实测对拍。
41
+ # 换案例时先跑一次 route_domains.match_domains 确认命中,再改这里。
42
+ CARDS: list[dict[str, str]] = [
43
+ {"tag": "FINANCE", "query": "贵州茅台股价", "expect_domain": "stock_query",
44
+ "accent": "#34D399", "chip": "#0B3B2E", "shape": "报价快照 · early-stop",
45
+ "field": "domain"},
46
+ {"tag": "FILM", "query": "Inception director", "expect_domain": "film_search",
47
+ "accent": "#A78BFA", "chip": "#1A1430", "shape": "作品页 · 实体字段",
48
+ "field": "domain"},
49
+ # 多语言卡:用**实测命中**的日语查询(「宮崎駿 アニメ 映画」→ film_search),
50
+ # 不用虚构的「アニメ おすすめ」。同卡的韩语/日语 geo 案例同样可复现。
51
+ {"tag": "LANG", "query": "エッフェル塔 どこ", "expect_domain": "geo_places",
52
+ "accent": "#38BDF8", "chip": "#0C2A3A", "shape": "非中文查询走本地/通用源",
53
+ "field": "lang"},
54
+ {"tag": "GEO", "query": "where is Eiffel Tower", "expect_domain": "geo_places",
55
+ "accent": "#FBBF24", "chip": "#2A2310", "shape": "坐标 · 实体定位",
56
+ "field": "domain"},
57
+ ]
58
+
59
+ _W, _H = 1200, 420
60
+ _CARD_W, _CARD_H, _CARD_Y, _CARD_GAP = 260, 230, 140, 16
61
+ _X0 = 56
62
+ _MONO = "ui-monospace, Menlo, monospace"
63
+ _SANS = "-apple-system, BlinkMacSystemFont, Segoe UI, PingFang SC, sans-serif"
64
+
65
+
66
+ def _esc(s: str) -> str:
67
+ return (s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;"))
68
+
69
+
70
+ def _route(query: str) -> dict:
71
+ sys.path.insert(0, str(SCRIPTS))
72
+ import route_domains as rd
73
+ import route_lang as rl
74
+ hits = rd.match_domains(query, max_n=1)
75
+ h = hits[0] if hits else {}
76
+ combo = list(h.get("engines_combo") or [])
77
+ return {
78
+ "domain": h.get("name") or "",
79
+ "primary": h.get("primary") or "",
80
+ "engines": combo,
81
+ "lang": (rl.extract_features(query) or {}).get("primary_lang") or "",
82
+ }
83
+
84
+
85
+ def build() -> tuple[str, list[str]]:
86
+ """生成 SVG 文本,并返回一致性告警(空 = 全部可复现)。"""
87
+ warnings: list[str] = []
88
+ cards = []
89
+ for c in CARDS:
90
+ r = _route(c["query"])
91
+ if r["domain"] != c["expect_domain"]:
92
+ warnings.append(
93
+ f"{c['query']!r} 实测命中 {r['domain']!r},与声明 "
94
+ f"{c['expect_domain']!r} 不符——改 CARDS 前先复现路由")
95
+ shown = " · ".join(_short(e) for e in r["engines"][:2]) or "(无 combo)"
96
+ if c["field"] == "lang":
97
+ value = f'{r["lang"]} · 非中文查询'
98
+ label = "query_lang"
99
+ else:
100
+ value = r["domain"] or "(未命中)"
101
+ label = "domain"
102
+ cards.append({**c, "value": value, "label": label,
103
+ "engines_shown": shown})
104
+
105
+ out = [
106
+ f'<svg xmlns="http://www.w3.org/2000/svg" width="{_W}" height="{_H}" '
107
+ f'viewBox="0 0 {_W} {_H}" role="img" aria-labelledby="title desc">',
108
+ ' <title id="title">Argo 问啥像啥</title>',
109
+ ' <desc id="desc">四类真实路由:A股行情、影视、多语言、地理实体各自命中垂直源'
110
+ '(由 scripts/gen_readme_art.py 从运行时路由生成,--check 对拍)</desc>',
111
+ '',
112
+ ' <defs>',
113
+ ' <linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">',
114
+ ' <stop offset="0%" stop-color="#070B14"/>',
115
+ ' <stop offset="100%" stop-color="#0B1220"/>',
116
+ ' </linearGradient>',
117
+ ' </defs>',
118
+ '',
119
+ f' <rect width="{_W}" height="{_H}" rx="28" fill="url(#bg)"/>',
120
+ '',
121
+ f' <text x="{_X0}" y="48" font-family="{_MONO}" font-size="12" '
122
+ 'fill="#38BDF8" letter-spacing="2">PROOF · REAL ROUTES</text>',
123
+ f' <text x="{_X0}" y="82" font-family="{_SANS}" font-size="26" '
124
+ 'font-weight="650" fill="#E8EEF7">问啥像啥 · 垂直源优先</text>',
125
+ f' <text x="{_X0}" y="110" font-family="{_SANS}" font-size="14" '
126
+ 'fill="#64748B">同样是「搜索」,路由不同 · 答案形态不同 · 可信度字段跟输出一起回来</text>',
127
+ ]
128
+ for i, c in enumerate(cards):
129
+ x = _X0 + i * (_CARD_W + _CARD_GAP)
130
+ chip_w = max(44, len(c["tag"]) * 7 + 20)
131
+ out += [
132
+ '',
133
+ f' <!-- card {i + 1} {c["tag"].lower()} -->',
134
+ f' <g transform="translate({x} {_CARD_Y})">',
135
+ f' <rect width="{_CARD_W}" height="{_CARD_H}" rx="16" '
136
+ 'fill="#0D1526" stroke="#1E2A3F"/>',
137
+ f' <rect x="16" y="16" width="{chip_w}" height="22" rx="6" fill="{c["chip"]}"/>',
138
+ f' <text x="{16 + chip_w / 2}" y="31" text-anchor="middle" '
139
+ f'font-family="{_MONO}" font-size="10" fill="{c["accent"]}">{_esc(c["tag"])}</text>',
140
+ f' <text x="16" y="64" font-family="{_SANS}" font-size="15" '
141
+ f'font-weight="600" fill="#E8EEF7">{_esc(c["query"])}</text>',
142
+ f' <text x="16" y="92" font-family="{_MONO}" font-size="11" '
143
+ f'fill="#64748B">{_esc(c["label"])}</text>',
144
+ f' <text x="16" y="112" font-family="{_MONO}" font-size="13" '
145
+ f'fill="{c["accent"]}">{_esc(c["value"])}</text>',
146
+ f' <text x="16" y="142" font-family="{_MONO}" font-size="11" '
147
+ 'fill="#64748B">engines</text>',
148
+ ' <text x="16" y="162" font-family="' + _MONO + '" font-size="12" '
149
+ 'fill="#CBD5E1">' + _esc(c["engines_shown"]) + '</text>',
150
+ ' <text x="16" y="192" font-family="' + _MONO + '" font-size="11" '
151
+ 'fill="#64748B">result shape</text>',
152
+ ' <text x="16" y="212" font-family="' + _SANS + '" font-size="13" '
153
+ 'fill="#94A3B8">' + _esc(c["shape"]) + '</text>',
154
+ ' </g>',
155
+ ]
156
+ out += ['', '</svg>', '']
157
+ return "\n".join(out), warnings
158
+
159
+
160
+ def _short(engine: str) -> str:
161
+ """引擎名缩到卡片可读长度(local_openstreetmap → osm 这类过长名)。"""
162
+ return (engine.replace("local_", "")
163
+ .replace("_quote", "")
164
+ .replace("openstreetmap", "osm")
165
+ .replace("wikipedia", "wiki"))
166
+
167
+
168
+ # ── hero.svg 的动态数字(同一真源,禁手抄) ──────────────────────────────
169
+ # hero 曾手写 v2.14.1 / 300+ sources,在 v2.16.0 已漂了两版。这里改为从
170
+ # package.json、engine_registry、mcp_tools、route_lang 取真值替换占位符。
171
+ # 模板与产物分离:hero.template.svg 是含占位符的模板(入库、可 diff),
172
+ # hero.svg 是渲染产物——`--check` 每次从模板重渲染再与产物比,可重复。
173
+ HERO_PATH = SKILL_DIR / "assets" / "readme" / "hero.svg"
174
+ HERO_TEMPLATE = SKILL_DIR / "assets" / "readme" / "hero.template.svg"
175
+ HERO_PLACEHOLDERS = {
176
+ "{{version}}": lambda: json.loads(
177
+ (SKILL_DIR / "package.json").read_text(encoding="utf-8"))["version"],
178
+ "{{sources}}": lambda: str(len(registry_engines())),
179
+ "{{mcp}}": lambda: str(len(mcp_tools())),
180
+ "{{langs}}": lambda: str(len(LANGS)),
181
+ }
182
+
183
+
184
+ def registry_engines() -> list:
185
+ import yaml_load
186
+ p = SKILL_DIR / "backends" / "engine_registry.yaml"
187
+ return (yaml_load.load(p) or {}).get("engines", [])
188
+
189
+
190
+ def mcp_tools() -> list:
191
+ sys.path.insert(0, str(SCRIPTS))
192
+ import mcp_tools
193
+ return list(mcp_tools.TOOLS)
194
+
195
+
196
+ # 对外口径的「语言数」= 主语言类 + 文字系统类(与 README「18 languages」一致)。
197
+ # 真源在 route_lang:主语言 11 类(zh/en/ja/ko/latin/cyrillic/thai/arabic/
198
+ # hebrew/greek/devanagari)+ 文字系统 7 类(cjk/kana/hangul/latin/cyrillic/…)。
199
+ LANGS = ("zh en ja ko latin cyrillic thai arabic hebrew greek devanagari "
200
+ "cjk kana hangul latin cyrillic arabic hebrew").split()
201
+
202
+
203
+ def render_hero() -> tuple[str, list[str]]:
204
+ """从模板渲染 hero.svg,返回 (文本, 告警)。模板缺失或占位符未替换都算红。"""
205
+ if not HERO_TEMPLATE.is_file():
206
+ return "", [f"缺模板 {HERO_TEMPLATE.name}——hero.svg 无法从真源渲染"]
207
+ src = HERO_TEMPLATE.read_text(encoding="utf-8")
208
+ warnings: list[str] = []
209
+ out = src
210
+ for ph, fn in HERO_PLACEHOLDERS.items():
211
+ if ph in out:
212
+ try:
213
+ out = out.replace(ph, fn())
214
+ except Exception as e: # noqa: BLE001 —— 显式留痕,不静默
215
+ warnings.append(f"占位符 {ph} 取值失败:{type(e).__name__}: {e}")
216
+ left = [p for p in HERO_PLACEHOLDERS if p in out]
217
+ if left:
218
+ warnings.append(f"hero.svg 仍有未替换占位符: {left}")
219
+ return out, warnings
220
+
221
+
222
+ def write_atomic(path: Path, text: str) -> None:
223
+ """原子写:先写同目录临时文件再 replace,避免读者看到半截内容。"""
224
+ tmp = path.with_suffix(path.suffix + ".tmp")
225
+ tmp.write_text(text, encoding="utf-8")
226
+ tmp.replace(path)
227
+
228
+
229
+ def main() -> int:
230
+ ap = argparse.ArgumentParser(description="生成 README 路由证据图")
231
+ ap.add_argument("--check", action="store_true", help="只校验图是否过期")
232
+ args = ap.parse_args()
233
+
234
+ svg, warnings = build()
235
+ hero, hero_warnings = render_hero()
236
+ warnings += hero_warnings
237
+ if warnings:
238
+ print("❌ 对外证据与真源不符:", file=sys.stderr)
239
+ for w in warnings:
240
+ print(f" - {w}", file=sys.stderr)
241
+ print(" 修复:改 scripts/gen_readme_art.py(先复现真源),不要改 SVG", file=sys.stderr)
242
+ return 1
243
+
244
+ if args.check:
245
+ bad = []
246
+ if (SVG_PATH.read_text(encoding="utf-8") if SVG_PATH.is_file() else "") != svg:
247
+ bad.append(SVG_PATH.name)
248
+ if (HERO_PATH.read_text(encoding="utf-8") if HERO_PATH.is_file() else "") != hero:
249
+ bad.append(HERO_PATH.name)
250
+ if bad:
251
+ print(f"❌ {', '.join(bad)} 与生成结果不一致——过期或手改。", file=sys.stderr)
252
+ print(" 修复:python3 scripts/gen_readme_art.py", file=sys.stderr)
253
+ return 1
254
+ print(f"✅ 对外证据图与真源一致({len(CARDS)} 卡路由实测可复现,hero 数字取自真源)")
255
+ return 0
256
+
257
+ write_atomic(SVG_PATH, svg)
258
+ write_atomic(HERO_PATH, hero)
259
+ print(f"✔ 已生成 proof-routes.svg({len(CARDS)} 卡)与 hero.svg(数字取自真源)")
260
+ return 0
261
+
262
+
263
+ if __name__ == "__main__":
264
+ sys.exit(main())
@@ -139,6 +139,8 @@ if [[ -d "$INSTALL_DIR/.git" ]]; then
139
139
  run git -C "$INSTALL_DIR" fetch --depth 1 origin "$BRANCH"
140
140
  run git -C "$INSTALL_DIR" checkout "$BRANCH"
141
141
  git -C "$INSTALL_DIR" pull --ff-only origin "$BRANCH" 2>/dev/null || warn "pull 失败(可能有本地改动),继续使用当前版本"
142
+ # 升级三提醒(2026-11-17):新码落盘 ≠ 生效;缓存库迁移已随代码自动化。
143
+ info "升级提醒:MCP 宿主里的 argo 连接器与 argo daemon 若在运行,重启以加载新代码(详见 docs/UPGRADE.md)"
142
144
  elif [[ -d "$INSTALL_DIR" && -f "$INSTALL_DIR/scripts/search.py" ]]; then
143
145
  info "目录已存在且含 Argo 源码,跳过克隆: $INSTALL_DIR"
144
146
  else
@@ -985,15 +985,19 @@ LIVE_CASES: list[dict[str, Any]] = [
985
985
  ]
986
986
 
987
987
 
988
- def _blob_from_results(results: list[dict], used: list, eng: str) -> str:
988
+ def _blob_from_results(results: list[dict]) -> str:
989
+ """只拼结果正文证据。
990
+
991
+ `engines_used` / `engine` 是「谁答的」元数据,不是答案内容:拼进来会让
992
+ gold 里的源名(pubchem、nasa 这类)命中在引擎标识上,一条正文毫不相关
993
+ 的结果也能判 hit。引擎维度由 `eng_ok` 单独把关。
994
+ """
989
995
  parts: list[str] = []
990
996
  for x in results:
991
997
  for k in ("title", "snippet", "content", "url", "source", "engine"):
992
998
  v = x.get(k)
993
999
  if v:
994
1000
  parts.append(str(v))
995
- parts.extend(str(u) for u in used)
996
- parts.append(eng or "")
997
1001
  return " ".join(parts).lower()
998
1002
 
999
1003
 
@@ -1024,7 +1028,7 @@ def run_live(c: Checker) -> None:
1024
1028
  domain_got = r.get("domain")
1025
1029
  combo = r.get("engines_combo") or r.get("engines") or []
1026
1030
  recovery = r.get("recovery")
1027
- blob = _blob_from_results(results, used, eng)
1031
+ blob = _blob_from_results(results)
1028
1032
 
1029
1033
  dom_ok = case.get("domain") is None or domain_got == case["domain"]
1030
1034
  primary = case.get("primary")
@@ -1052,12 +1056,6 @@ def run_live(c: Checker) -> None:
1052
1056
  for p in pollute_keys:
1053
1057
  if p in src and p not in pollute_hit:
1054
1058
  pollute_hit.append(p)
1055
- for u in used:
1056
- ul = str(u).lower()
1057
- for p in pollute_keys:
1058
- if p == ul and p not in pollute_hit:
1059
- # 若仅作为 recovery 未进 results 可不算污染;仅 results 源算
1060
- pass
1061
1059
 
1062
1060
  # 严格:top results 的 source 不得为 pollute
1063
1061
  pollute_ok = not pollute_hit