argo-search 2.16.0 → 2.18.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 (126) hide show
  1. package/AGENTS.md +4 -2
  2. package/README.es.md +15 -5
  3. package/README.ja.md +15 -5
  4. package/README.ko.md +15 -5
  5. package/README.md +16 -6
  6. package/README.zh.md +16 -6
  7. package/SKILL.md +12 -11
  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 +121 -18
  13. package/backends/engine_registry.yaml +23 -0
  14. package/backends/env_passthrough.txt +2 -0
  15. package/backends/quota_profiles.json +20 -0
  16. package/bin/argo +78 -12
  17. package/docs/CHANGELOG.md +35 -1
  18. package/docs/COMMIT_STANDARD.md +12 -2
  19. package/docs/ENGINE_CATALOG.md +36 -33
  20. package/docs/RELEASE_NOTES_v2.17.0.md +66 -0
  21. package/docs/RELEASE_NOTES_v2.18.0.md +87 -0
  22. package/docs/RELEASING.md +2 -2
  23. package/engines/specs/crossref.yaml +2 -0
  24. package/engines/specs/hackernews.yaml +2 -0
  25. package/engines/specs/helve.yaml +49 -0
  26. package/engines/specs/hf_papers.yaml +2 -0
  27. package/engines/specs/openalex.yaml +9 -2
  28. package/engines/specs/twitter_cli.yaml +17 -0
  29. package/engines/specs/twitter_syndication.yaml +2 -3
  30. package/package.json +3 -1
  31. package/packages/dsh-plugin/README.md +5 -2
  32. package/packages/dsh-plugin/cordis.patch.yml +4 -1
  33. package/packages/dsh-plugin/dsh/client.js +57 -63
  34. package/packages/dsh-plugin/dsh/diagnostics.js +25 -4
  35. package/packages/dsh-plugin/dsh/index.js +109 -21
  36. package/packages/dsh-plugin/dsh/native-tools.mjs +10 -0
  37. package/packages/dsh-plugin/dsh/route-guard.js +95 -0
  38. package/packages/dsh-plugin/dsh/runner.js +49 -6
  39. package/packages/dsh-plugin/dsh/wide-research.js +20 -18
  40. package/packages/dsh-plugin/dsh/workbench-client.js +119 -20
  41. package/packages/dsh-plugin/dsh/workbench-io.js +182 -0
  42. package/packages/dsh-plugin/dsh/workbench-search.js +445 -0
  43. package/packages/dsh-plugin/dsh/workbench-suggestions.js +387 -75
  44. package/packages/dsh-plugin/dsh/workbench.js +277 -497
  45. package/packages/dsh-plugin/package.json +4 -3
  46. package/packages/dsh-plugin/scripts/sync-local.mjs +4 -2
  47. package/packages/dsh-plugin/scripts/sync-local.sh +4 -2
  48. package/packages/dsh-plugin/test/client.test.js +26 -0
  49. package/packages/dsh-plugin/test/diagnostics.test.js +5 -2
  50. package/packages/dsh-plugin/test/index.test.js +150 -1
  51. package/packages/dsh-plugin/test/workbench-concurrency.test.js +96 -0
  52. package/packages/dsh-plugin/test/workbench.test.js +422 -9
  53. package/scripts/adaptive.py +13 -11
  54. package/scripts/affected_tests.py +324 -0
  55. package/scripts/badcase_ledger.py +93 -2
  56. package/scripts/browser_auth.py +178 -4
  57. package/scripts/cache.py +68 -69
  58. package/scripts/check_commit_report.py +59 -9
  59. package/scripts/chrome_cdp.py +71 -0
  60. package/scripts/circuit_breaker.py +77 -12
  61. package/scripts/cli_io.py +8 -3
  62. package/scripts/config_cache.py +4 -3
  63. package/scripts/daemon.py +9 -2
  64. package/scripts/engine_add.py +45 -0
  65. package/scripts/engine_dispatch.py +27 -47
  66. package/scripts/engine_failure.py +33 -0
  67. package/scripts/engine_families.py +1 -0
  68. package/scripts/engine_fingerprint.py +114 -0
  69. package/scripts/engine_health.py +130 -0
  70. package/scripts/engine_states.py +54 -4
  71. package/scripts/engines.py +2 -0
  72. package/scripts/engines_base.py +19 -44
  73. package/scripts/engines_builders_intl.py +20 -94
  74. package/scripts/engines_builders_search.py +19 -8
  75. package/scripts/engines_builders_tech.py +16 -16
  76. package/scripts/engines_fields.py +23 -0
  77. package/scripts/engines_twitter_cli.py +182 -0
  78. package/scripts/evidence_grounding.py +182 -0
  79. package/scripts/fetch_browser.py +25 -10
  80. package/scripts/fetch_cli_output.py +75 -0
  81. package/scripts/fetch_dispatch.py +248 -0
  82. package/scripts/fetch_quality.py +11 -0
  83. package/scripts/fetch_v3.py +48 -114
  84. package/scripts/gate_manifest_check.py +75 -0
  85. package/scripts/gen_readme_art.py +264 -0
  86. package/scripts/intent_router.py +224 -0
  87. package/scripts/mcp_compact.py +3 -0
  88. package/scripts/mcp_handlers.py +24 -4
  89. package/scripts/mcp_tools.py +2 -0
  90. package/scripts/mcp_transport.py +24 -5
  91. package/scripts/mcp_warm.py +15 -11
  92. package/scripts/numeric_verify.py +9 -0
  93. package/scripts/output_transparency.py +10 -0
  94. package/scripts/pre-commit +65 -8
  95. package/scripts/query_operators.py +229 -1
  96. package/scripts/quota.py +19 -37
  97. package/scripts/release.py +16 -1
  98. package/scripts/release_check.py +1 -2
  99. package/scripts/research_gates.py +85 -1
  100. package/scripts/research_notes.py +52 -5
  101. package/scripts/retry_policy.py +17 -3
  102. package/scripts/route_combo.py +21 -4
  103. package/scripts/search.py +29 -29
  104. package/scripts/search_cli.py +104 -8
  105. package/scripts/search_output.py +4 -1
  106. package/scripts/social_research.py +8 -6
  107. package/scripts/source_discovery.py +611 -0
  108. package/scripts/sync_backends.py +45 -0
  109. package/scripts/time_utils.py +28 -0
  110. package/scripts/twitter_single_read.py +107 -0
  111. package/scripts/x_keyword_route.py +138 -0
  112. package/scripts/x_search.py +24 -33
  113. package/scripts/zhihu_answer_body.py +96 -0
  114. package/scripts/zhihu_answer_fetch.py +66 -0
  115. package/scripts/zhihu_answer_lookup.py +138 -0
  116. package/sub-skills/ego-search/README.md +9 -0
  117. package/sub-skills/ego-search/scripts/ego_search.py +182 -15
  118. package/sub-skills/ego-search/scripts/pacing.py +291 -0
  119. package/sub-skills/ego-search/scripts/quality.py +262 -6
  120. package/sub-skills/ego-search/scripts/runtime.py +7 -1
  121. package/sub-skills/ego-search/scripts/site_profiles.py +157 -0
  122. package/sub-skills/ego-search/scripts/webbridge_adapter.py +7 -1
  123. package/sub-skills/local-seek/SKILL.md +3 -1
  124. package/sub-skills/local-seek/scripts/seek.py +80 -109
  125. package/sub-skills/local-seek/scripts/seek_git.py +65 -0
  126. package/sub-skills/local-seek/scripts/seek_inspect.py +242 -0
@@ -75,7 +75,7 @@ import fetch_quality as _quality
75
75
  import argo_paths as _paths
76
76
  from net_proxy import open_url # 出口调度唯一入口(issue #13 同类修复)
77
77
  from engine_env import env_flag, get_env # env_flag 判开关;get_env 读密钥(os.environ 优先,env 文件热读保底)
78
- from cli_io import dumps
78
+ from fetch_cli_output import print_result
79
79
  from fetch_jsrun import _jsrun_challenge_fetch, _jsrun_enabled # js-run 轻量车道(拆出独立模块)
80
80
 
81
81
 
@@ -1202,7 +1202,8 @@ def fetch_v3(url: str, max_chars: int = 8000, timeout: float = 8.0,
1202
1202
  force_browser: bool = False,
1203
1203
  skip_cache: bool = False,
1204
1204
  need_html: bool = False,
1205
- deadline_s: float | None = None) -> dict:
1205
+ deadline_s: float | None = None,
1206
+ answer_offset: int | None = None) -> dict:
1206
1207
  """多级抓取降级链主函数(逐级升级,受全局 deadline 约束)。
1207
1208
 
1208
1209
  执行顺序:
@@ -1248,6 +1249,16 @@ def fetch_v3(url: str, max_chars: int = 8000, timeout: float = 8.0,
1248
1249
  except ImportError:
1249
1250
  pass
1250
1251
 
1252
+ from zhihu_answer_fetch import fetch_answer, match_answer
1253
+ if answer_offset is not None or (not need_html and not actions and match_answer(url)):
1254
+ if deadline_s is None:
1255
+ try:
1256
+ deadline_s = float(os.environ.get("ARGO_FETCH_DEADLINE_S", "60") or 60)
1257
+ except ValueError:
1258
+ deadline_s = 60.0
1259
+ return fetch_answer(url, offset=answer_offset, max_chars=max_chars, timeout=timeout,
1260
+ deadline_s=deadline_s, browser=force_browser or use_browser_fallback)
1261
+
1251
1262
  # URL 优化(Reddit 重写、追踪参数清理)
1252
1263
  url = _optimize_url(url)
1253
1264
 
@@ -1274,46 +1285,19 @@ def fetch_v3(url: str, max_chars: int = 8000, timeout: float = 8.0,
1274
1285
  _video["cached"] = False
1275
1286
  return _strip_html_unless_needed(_video, need_html)
1276
1287
 
1277
- # 微信专用降级链(HTTP→CDP→搜狗,wechat_article.py,`argo wx` 同实现——用户
1278
- # 显式取文不走匿名爬虫 robots 口径)【必须在 robots 闸前】mp.weixin/robots.txt
1279
- # 是 Disallow: /(11-15 实测),闸先跑分支永不可达(6ebb625 实跑复现)。让路同前。
1280
- if (_is_wechat_article_url(url) and not need_html and not actions
1281
- and not force_browser):
1282
- try:
1283
- from wechat_article import fetch_wechat_article
1284
- _wx = fetch_wechat_article(url)
1285
- except Exception:
1286
- _wx = None
1287
- if _wx and _wx.get("ok"):
1288
- _wx_result = {
1289
- "url": url,
1290
- "title": _wx.get("title") or "",
1291
- "content": (_wx.get("content") or "")[:max_chars],
1292
- "html": "",
1293
- "length": int(_wx.get("char_count") or 0),
1294
- "success": True,
1295
- "fetch_method": engine_states.FETCH_WECHAT + str(
1296
- _wx.get("fetch_method") or engine_states.FETCH_HTTP_DIRECT),
1297
- "author": _wx.get("author") or "",
1298
- "publish_time": _wx.get("publish_time") or "",
1299
- }
1300
- try:
1301
- _wx_result = _assess_quality(_wx_result)
1302
- except SHAPE_BENIGN:
1303
- pass
1304
- _wx_result["cached"] = False
1305
- return _strip_html_unless_needed(_wx_result, need_html)
1306
- # 专用链三级全败即结构化失败、不落回通用链:通用链对 mp.weixin 只会拿
1307
- # JS 骨架冒充成功(11-01 实测病灶);_has_content 保证到这里的是真失败。
1308
- return _strip_html_unless_needed({
1309
- "url": url,
1310
- "title": "", "content": "", "html": "",
1311
- "length": 0, "success": False,
1312
- "error": (_wx or {}).get("error")
1313
- or "微信公众号文章抓取失败(HTTP/浏览器/搜狗三通道均未取到正文)",
1314
- "fetch_method": engine_states.FETCH_WECHAT_FAILED,
1315
- "cached": False,
1316
- }, need_html)
1288
+ # 专用 URL 自动分发(微信 / X 推文 / arXiv 论文 / PDF,fetch_dispatch.py)
1289
+ # 【必须在 robots 闸前】mp.weixin/robots.txt 为 Disallow: /,让路同前。
1290
+ if not need_html and not actions and not force_browser:
1291
+ from fetch_dispatch import dispatch_specialized_fetch
1292
+ _spec = dispatch_specialized_fetch(url, max_chars=max_chars, timeout=timeout)
1293
+ if _spec is not None:
1294
+ if _spec.get("success"):
1295
+ try:
1296
+ _spec = _assess_quality(_spec)
1297
+ except SHAPE_BENIGN:
1298
+ pass
1299
+ _spec["cached"] = False
1300
+ return _strip_html_unless_needed(_spec, need_html)
1317
1301
 
1318
1302
  # robots.txt 尊重(合规检查):被禁路径直接拒绝,抓取失败放行
1319
1303
  try:
@@ -1593,8 +1577,10 @@ def fetch_v3(url: str, max_chars: int = 8000, timeout: float = 8.0,
1593
1577
  if deadline_hit["flag"]:
1594
1578
  result["deadline_exhausted"] = True
1595
1579
 
1596
- # 第三级:质量评估
1580
+ # 第三级:质量评估 + 空正文假成功守卫(统一收口在 fetch_quality)
1597
1581
  result = _assess_quality(result)
1582
+ from fetch_quality import guard_empty_unknown_result
1583
+ result = guard_empty_unknown_result(result)
1598
1584
 
1599
1585
  # 文章级元数据(链接/作者/站点名/摘要):与正文同源于本次 HTML,一次解析
1600
1586
  # 拿全;调用方不必为了顺着引用继续取证而重抓页面。缓存一起存(链接上限
@@ -1711,7 +1697,8 @@ def _full_view(url: str, args) -> dict:
1711
1697
  有了这条通道,「先看 8,000 字摘要、需要时再翻全文」才成立。
1712
1698
  """
1713
1699
  from_archive = True
1714
- text = _read_archived(url)
1700
+ from zhihu_answer_fetch import match_answer
1701
+ text = None if match_answer(url) else _read_archived(url)
1715
1702
  if text is None:
1716
1703
  from_archive = False
1717
1704
  r = fetch_v3(url, max_chars=0, timeout=args.timeout,
@@ -1733,23 +1720,17 @@ def _full_view(url: str, args) -> dict:
1733
1720
  "fetch_method": (engine_states.FETCH_FULLTEXT if from_archive
1734
1721
  else r.get("fetch_method", "full")),
1735
1722
  })
1723
+ if "next_offset" in out:
1724
+ out["truncated"] = out["length"] < out["total_length"]
1736
1725
  return out
1737
1726
 
1738
1727
 
1739
1728
  # ─── CLI ─────────────────────────────────────────────────────────────────────
1740
1729
 
1741
- # 人类可读输出的默认显示上限(字符)。--limit 管的是交付窗口,这里是显示上限;
1742
- # 显式 --full / --limit 时按调用方要求放开,截断时打印可翻页的提示。
1743
- _DISPLAY_CHARS = 2000
1744
-
1745
-
1746
1730
  def build_parser():
1747
- """CLI 参数表(独立成函数以便测试校验旗标契约)。
1748
-
1749
- `--use-browser` 与 `--browser` 同义:文档两处都写过前者,入口若只认后者,
1750
- 用户照文档敲命令即报错。两个名字都收,避免再出现「文档有、代码无」。
1751
- """
1731
+ """构建抓取命令的参数解析器。"""
1752
1732
  import argparse
1733
+
1753
1734
  p = argparse.ArgumentParser(description="Argo fetch v3 — 四级抓取(零依赖)")
1754
1735
  p.add_argument("url", help="目标 URL")
1755
1736
  p.add_argument("--max-chars", type=int, default=8000)
@@ -1767,6 +1748,7 @@ def build_parser():
1767
1748
  p.add_argument("--full", action="store_true",
1768
1749
  help="取全文:优先读本地全文存档,没有则按抓取全量取回,"
1769
1750
  "不受 --max-chars 限制(用于复核被截断的部分)")
1751
+ p.add_argument("--answer-offset", type=int, help="仅在用户明确要求续查知乎回答摘要时传入 next_offset")
1770
1752
  p.add_argument("--offset", type=int, default=0,
1771
1753
  help="从正文第 N 个字符开始输出(配合 --limit 翻页读长文)")
1772
1754
  p.add_argument("--limit", type=int, default=0,
@@ -1781,7 +1763,10 @@ def build_parser():
1781
1763
 
1782
1764
 
1783
1765
  if __name__ == "__main__":
1784
- args = build_parser().parse_args()
1766
+ parser = build_parser()
1767
+ args = parser.parse_args()
1768
+ if args.answer_offset is not None and (args.full or args.offset or args.limit or args.actions):
1769
+ parser.error("--answer-offset 仅用于回答摘要续查,不能与正文切片或页面交互组合。")
1785
1770
 
1786
1771
  actions = None
1787
1772
  if args.actions:
@@ -1797,68 +1782,17 @@ if __name__ == "__main__":
1797
1782
  timeout=args.timeout,
1798
1783
  force_browser=args.browser,
1799
1784
  use_browser_fallback=not args.no_fallback,
1800
- actions=actions)
1785
+ actions=actions, answer_offset=args.answer_offset)
1801
1786
 
1802
1787
  focus_requested = bool(args.focus)
1803
1788
  pre_focus_len = r.get("length", 0)
1804
1789
  r = _apply_focus_to_result(r, args.focus, top_k=args.focus_top,
1805
1790
  max_chars=args.max_chars)
1806
1791
 
1807
- # 输出摘要
1808
- summary = {k: r[k] for k in ("success", "fetch_method", "content_ok",
1809
- "quality_score", "page_type", "source_type",
1810
- "is_official", "length", "url",
1811
- "video_meta") if k in r}
1812
- # 截断必须可见:只给 8,000 字却不说明「还有多少没给」,调用方会当全文用
1813
- for k in ("truncated", "full_length", "full_text_path", "total_length",
1814
- "offset", "full_source", "final_url",
1815
- "login_state_used", "cache_eligible"):
1816
- if k in r:
1817
- summary[k] = r[k]
1818
- if focus_requested:
1819
- # 显式回报聚焦是否真的生效:正文过短时 focus_applied=False,
1820
- # 不谎报「已省 token」
1821
- summary["focus_applied"] = bool(r.get("focus_applied"))
1822
- if r.get("error"):
1823
- summary["error"] = r["error"]
1824
- if r.get("links"):
1825
- summary["links_count"] = len(r["links"])
1826
- if args.include_links:
1827
- summary["links"] = r["links"]
1828
- print(dumps(summary))
1829
- # __main__ 块是模块级代码,不能用 return 短路——用 if 包住人类可读段
1830
- if not args.json:
1831
- if r.get("title"):
1832
- print(f"\nTitle: {r['title']}")
1833
- if focus_requested:
1834
- print(f"\n[focus] query={args.focus!r} applied={bool(r.get('focus_applied'))} "
1835
- f"chars={pre_focus_len} → {r.get('length', 0)}")
1836
- print(f"\n--- CONTENT ({r['length']} chars) ---")
1837
- # 默认档保持 2000 字显示上限(护住 agent 上下文),但显式 --full /
1838
- # --limit 时必须按调用方要求显示完整交付窗口:此前这行硬编码
1839
- # [:2000],与 --limit 的语义(本次输出字符数上限,0 表示不限)冲突,
1840
- # 且表头写的是交付长度,于是「说 8000 字、只给 2000 字、不说明还剩
1841
- # 多少」——调用方会把截断正文当全文用(证据核验场景尤其危险)。
1842
- delivered = r.get("content", "") or ""
1843
- show_all = bool(args.full) or bool(args.limit and args.limit > 0)
1844
- shown = delivered if show_all else delivered[:_DISPLAY_CHARS]
1845
- print(shown)
1846
- if len(shown) < len(delivered):
1847
- # 两个字段是不同代码路径写的同一事实:fetch_v3 路径给 full_length,
1848
- # _full_view 路径给 total_length,故这里按可用者兜底。
1849
- full_len = r.get("full_length") or r.get("total_length") or len(delivered)
1850
- if focus_requested:
1851
- # --focus 之后 content 是重排后的段落抽取,不再是正文的连续窗口,
1852
- # 按「本页起点 + 本页长度」推 --offset 会指向无关区间。宁可不给
1853
- # 翻页建议,也不能给错的。
1854
- print(f"\n[truncated] 已显示 {len(shown)}/{len(delivered)} 字"
1855
- f"(页面全文 {full_len} 字)。当前为 --focus 抽取结果,"
1856
- f"非正文连续窗口;要完整正文请用 --full")
1857
- else:
1858
- # --offset 是相对正文全文的绝对偏移(见 _full_view),所以下一页
1859
- # 要从「本页起点 + 本页长度」继续,否则已翻过页的调用方会原地打转。
1860
- next_offset = int(r.get("offset") or 0) + len(shown)
1861
- print(f"\n[truncated] 已显示 {len(shown)}/{len(delivered)} 字"
1862
- f"(页面全文 {full_len} 字)。"
1863
- f"继续读:--offset {next_offset} --limit {_DISPLAY_CHARS};"
1864
- f"全文:--full")
1792
+ if focus_requested and not (args.full or args.offset or args.limit):
1793
+ from zhihu_answer_fetch import finish_focus
1794
+ finish_focus(r, args.max_chars)
1795
+
1796
+ print_result(r, json_only=args.json, include_links=args.include_links,
1797
+ focus=args.focus, pre_focus_len=pre_focus_len,
1798
+ full=args.full, limit=args.limit)
@@ -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())