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
@@ -0,0 +1,224 @@
1
+ #!/usr/bin/env python3
2
+ """intent_router.py — 高层意图路由(--intent)。
3
+
4
+ 把「调用方记忆 explicit_only 引擎名」转为「声明查询意图」:
5
+ - news 时事/动态:有密钥且未超预算(且非 fast 模式)走 deepseek_search,
6
+ 否则透明降级到自动路由 + domain=news 并附降级说明;
7
+ - academic 学术多源:depth 至少为 deep + domain=academic;
8
+ - social 社交与社区:domain=social;
9
+ - image-reverse 反搜图:自动从 animetrace/tracemoe/saucenao/google_lens 选取可用源;
10
+ - calc 精确计算/换算:wolframalpha 可用时自动启用,否则降级 auto 并提示。
11
+
12
+ 设计约束:
13
+ - 仅在显式传入 --intent 时由 search_cli.py 懒加载,默认路径零启动开销;
14
+ - 所有环境/配额/配置探测器均支持依赖注入,便于离线单测与回退验证。
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from typing import Any, Callable
20
+
21
+ SUPPORTED_INTENTS: tuple[str, ...] = (
22
+ "news",
23
+ "academic",
24
+ "social",
25
+ "image-reverse",
26
+ "calc",
27
+ )
28
+
29
+ _REVERSE_IMAGE_CANDIDATES: tuple[str, ...] = (
30
+ "animetrace",
31
+ "tracemoe",
32
+ "saucenao",
33
+ "google_lens",
34
+ )
35
+
36
+ # 垂直意图引擎前置表(传给 super_search.engines_boost,真正驱动选源而不仅改缓存键)
37
+ _INTENT_BOOST: dict[str, list[str]] = {
38
+ "academic": ["arxiv", "openalex", "semantic_scholar", "local_pubmed"],
39
+ "social": ["anysearch", "reddit", "zhihu", "hackernews"],
40
+ "news_fallback": ["anysearch", "google_news", "em_global_news", "cn_ai_news"],
41
+ }
42
+
43
+
44
+ def _default_get_engines() -> dict[str, dict[str, Any]]:
45
+ from config import get_engines
46
+ return get_engines()
47
+
48
+
49
+ def _default_missing_env(engine_id: str, spec: dict[str, Any] | None) -> list[str]:
50
+ from engine_env import missing_env_for
51
+ return missing_env_for(engine_id, spec)
52
+
53
+
54
+ def _default_quota_available(engine_id: str, mode: str) -> bool:
55
+ from quota import get_quota_manager
56
+ return get_quota_manager().is_available(engine_id, mode=mode)
57
+
58
+
59
+ def _engine_ready(
60
+ engine_id: str,
61
+ engines_cfg: dict[str, dict[str, Any]],
62
+ mode: str,
63
+ check_env: Callable[[str, dict[str, Any] | None], list[str]],
64
+ check_quota: Callable[[str, str], bool],
65
+ ) -> tuple[bool, str]:
66
+ """检查单个目标引擎是否可用,返回 (ready, unavailable_reason)。"""
67
+ spec = engines_cfg.get(engine_id)
68
+ if not isinstance(spec, dict) or not spec.get("enabled", True):
69
+ return False, f"{engine_id} 未启用"
70
+ missing = check_env(engine_id, spec)
71
+ if missing:
72
+ return False, f"{engine_id} 缺少环境变量 {', '.join(missing)}"
73
+ if not check_quota(engine_id, mode):
74
+ return False, f"{engine_id} 配额或月度预算已耗尽"
75
+ return True, ""
76
+
77
+
78
+ def resolve_intent(
79
+ intent: str,
80
+ *,
81
+ engine: str = "auto",
82
+ domain: str | None = None,
83
+ depth: str = "fast",
84
+ mode: str = "auto",
85
+ get_engines_fn: Callable[[], dict[str, dict[str, Any]]] | None = None,
86
+ check_env_fn: Callable[[str, dict[str, Any] | None], list[str]] | None = None,
87
+ check_quota_fn: Callable[[str, str], bool] | None = None,
88
+ ) -> dict[str, Any]:
89
+ """将高层意图解析为 (engine, domain, depth) 与可审计的降级说明。"""
90
+ if intent not in SUPPORTED_INTENTS:
91
+ raise ValueError(
92
+ f"不支持的意图 {intent!r},可选: {', '.join(SUPPORTED_INTENTS)}"
93
+ )
94
+
95
+ explicit_engine = bool(engine and engine != "auto")
96
+ resolved_engine = engine or "auto"
97
+ resolved_domain = domain or None
98
+ resolved_depth = depth or "fast"
99
+ degraded = False
100
+ reason = ""
101
+ warnings: list[str] = []
102
+
103
+ if intent == "academic":
104
+ if not resolved_domain:
105
+ resolved_domain = "academic"
106
+ if resolved_depth == "fast":
107
+ resolved_depth = "deep"
108
+ boost = None if explicit_engine else list(_INTENT_BOOST["academic"])
109
+ reason = ("学术多源模式(depth=deep,引擎前置 arxiv/openalex/"
110
+ "semantic_scholar/local_pubmed)")
111
+ if explicit_engine:
112
+ warnings.append(f"--engine {engine} 覆盖了 --intent {intent} 的默认多源路由")
113
+ return _pack(
114
+ intent, resolved_engine, resolved_domain, resolved_depth,
115
+ degraded, reason, explicit_engine, warnings, engines_boost=boost,
116
+ )
117
+
118
+ if intent == "social":
119
+ if not resolved_domain:
120
+ resolved_domain = "social"
121
+ boost = None if explicit_engine else list(_INTENT_BOOST["social"])
122
+ # reason 只说真实发生的事:本意图靠 engines_boost 把社交源前置,
123
+ # `domain=social` 只是缓存键隔离标记,不参与选源(route_query 从不读
124
+ # engine_domain)。旧措辞「社交与社区垂直域」会让调用方以为结果已被
125
+ # 限定在社区域内——实测同一 query 带不带该 domain,路由逐位相同。
126
+ reason = ("社交意图(引擎前置 anysearch/reddit/zhihu/hackernews;"
127
+ "domain 不参与选源,仅隔离缓存键)")
128
+ if explicit_engine:
129
+ warnings.append(f"--engine {engine} 覆盖了 --intent {intent} 的默认多源路由")
130
+ return _pack(
131
+ intent, resolved_engine, resolved_domain, resolved_depth,
132
+ degraded, reason, explicit_engine, warnings, engines_boost=boost,
133
+ )
134
+
135
+ if explicit_engine:
136
+ warnings.append(f"--engine {engine} 覆盖了 --intent {intent} 的默认引擎选择")
137
+ if intent == "news" and not resolved_domain:
138
+ resolved_domain = "news"
139
+ return _pack(
140
+ intent, resolved_engine, resolved_domain, resolved_depth,
141
+ False, f"已由显式 --engine {engine} 覆盖", True, warnings,
142
+ )
143
+
144
+ engines_cfg = (get_engines_fn or _default_get_engines)()
145
+ check_env = check_env_fn or _default_missing_env
146
+ check_quota = check_quota_fn or _default_quota_available
147
+
148
+ engines_boost: list[str] | None = None
149
+ if intent == "news":
150
+ if mode == "fast":
151
+ degraded = True
152
+ resolved_domain = resolved_domain or "news"
153
+ engines_boost = list(_INTENT_BOOST["news_fallback"])
154
+ reason = "mode=fast 跳过付费时事源 deepseek_search,已降级为免费新闻优先路由"
155
+ warnings.append(f"[intent:news] {reason}")
156
+ else:
157
+ ok, why = _engine_ready("deepseek_search", engines_cfg, mode, check_env, check_quota)
158
+ if ok:
159
+ resolved_engine = "deepseek_search"
160
+ reason = "时事意图自动命中 deepseek_search(密钥与预算均可用)"
161
+ else:
162
+ degraded = True
163
+ resolved_domain = resolved_domain or "news"
164
+ engines_boost = list(_INTENT_BOOST["news_fallback"])
165
+ reason = f"{why},已降级为新闻优先自动路由(domain=news)"
166
+ warnings.append(f"[intent:news] {reason}")
167
+
168
+ elif intent == "image-reverse":
169
+ usable: list[str] = []
170
+ block_reasons: list[str] = []
171
+ for cand in _REVERSE_IMAGE_CANDIDATES:
172
+ ok, why = _engine_ready(cand, engines_cfg, mode, check_env, check_quota)
173
+ if ok:
174
+ usable.append(cand)
175
+ elif why:
176
+ block_reasons.append(why)
177
+ if usable:
178
+ chosen = usable[:2]
179
+ resolved_engine = ",".join(chosen)
180
+ reason = f"反搜图自动选取可用源: {resolved_engine}"
181
+ else:
182
+ degraded = True
183
+ reason = f"反搜图候选源均不可用({'; '.join(block_reasons[:3])}),已降级为自动路由"
184
+ warnings.append(f"[intent:image-reverse] {reason}")
185
+
186
+ elif intent == "calc":
187
+ ok, why = _engine_ready("wolframalpha", engines_cfg, mode, check_env, check_quota)
188
+ if ok:
189
+ resolved_engine = "wolframalpha"
190
+ reason = "计算意图自动命中 wolframalpha"
191
+ else:
192
+ degraded = True
193
+ reason = f"{why},已降级为自动路由"
194
+ warnings.append(f"[intent:calc] {reason}")
195
+
196
+ return _pack(
197
+ intent, resolved_engine, resolved_domain, resolved_depth,
198
+ degraded, reason, False, warnings, engines_boost=engines_boost,
199
+ )
200
+
201
+
202
+ def _pack(
203
+ intent: str,
204
+ engine: str,
205
+ domain: str | None,
206
+ depth: str,
207
+ degraded: bool,
208
+ reason: str,
209
+ overridden: bool,
210
+ warnings: list[str],
211
+ *,
212
+ engines_boost: list[str] | None = None,
213
+ ) -> dict[str, Any]:
214
+ return {
215
+ "intent": intent,
216
+ "engine": engine,
217
+ "domain": domain,
218
+ "depth": depth,
219
+ "engines_boost": engines_boost,
220
+ "degraded": degraded,
221
+ "reason": reason,
222
+ "overridden_by_engine": overridden,
223
+ "warnings": warnings,
224
+ }
@@ -35,6 +35,8 @@ def _compact_search_result(result: dict[str, Any], summary: bool = False) -> dic
35
35
  "input_kind": result.get("input_kind"),
36
36
  "login_hint": result.get("login_hint"),
37
37
  }
38
+ if result.get("errors"):
39
+ out["errors"] = result["errors"][:12]
38
40
  results = []
39
41
  for r in result.get("results") or []:
40
42
  if not isinstance(r, dict):
@@ -95,6 +97,7 @@ def _compact_search_result(result: dict[str, Any], summary: bool = False) -> dic
95
97
  "status": o.get("status"),
96
98
  "latency_ms": o.get("latency_ms"),
97
99
  "results_count": o.get("results_count"),
100
+ **({"error_kind": o["error_kind"]} if o.get("error_kind") else {}),
98
101
  }
99
102
  for o in outcomes
100
103
  if isinstance(o, dict)
@@ -132,10 +132,10 @@ def _resolve_research_profile(arguments: dict[str, Any]) -> tuple[dict[str, Any]
132
132
 
133
133
 
134
134
  def _search_social_platforms(
135
- platforms: list[str], query: str, n: int, timeout: float = 20.0,
135
+ platforms: list[str], query: str, n: int, timeout: float = 20.0, **kwargs,
136
136
  ) -> tuple[dict[str, list], list[str], list[str]]:
137
137
  """并行抓取多社交平台(MCP 热路径)。"""
138
- return _warm_search_social_platforms(platforms, query, n, timeout=timeout, lazy_cached_fn=_lazy_cached)
138
+ return _warm_search_social_platforms(platforms, query, n, timeout=timeout, lazy_cached_fn=_lazy_cached, **kwargs)
139
139
 
140
140
 
141
141
  def _env_bool(name: str, default: bool = False) -> bool:
@@ -260,7 +260,14 @@ def execute_tool(name: str, arguments: dict[str, Any]) -> dict[str, Any]:
260
260
  query = arguments["query"]
261
261
  n = _clamp_int(
262
262
  arguments.get("max_results", arguments.get("num", 5)), 5, 1, 20)
263
- platform_results, engines_used, errors = _search_social_platforms(platforms, query, n)
263
+ from x_keyword_route import X_ENGINES
264
+ engine = arguments.get("engine", "auto")
265
+ if engine in X_ENGINES:
266
+ platforms = ["twitter"]
267
+ outcomes = []
268
+ platform_results, engines_used, errors = _search_social_platforms(
269
+ platforms, query, n, x_engine=engine if engine in X_ENGINES else "auto",
270
+ since=arguments.get("since"), until=arguments.get("until"), outcomes=outcomes)
264
271
  if str(arguments.get("mode", "text")).strip().lower() in (
265
272
  "sentiment", "social-sentiment"):
266
273
  research_mod = _lazy_cached("research")
@@ -278,6 +285,9 @@ def execute_tool(name: str, arguments: dict[str, Any]) -> dict[str, Any]:
278
285
  "count": len(all_results),
279
286
  "engines_used": engines_used,
280
287
  }
288
+ if outcomes:
289
+ output["engine_outcomes"] = outcomes
290
+ output["engines_used"] = engines_used
281
291
  if errors:
282
292
  output["errors"] = errors
283
293
  return _ok(output, pretty=pretty)
@@ -431,6 +441,13 @@ def execute_tool(name: str, arguments: dict[str, Any]) -> dict[str, Any]:
431
441
  url = arguments["url"]
432
442
  mode = arguments.get("mode", "text")
433
443
 
444
+ if "answer_offset" in arguments and (mode != "text" or type(arguments["answer_offset"]) is not int or arguments["answer_offset"] < 0):
445
+ raise ValueError("answer_offset 仅用于 text 模式,须为非负整数。")
446
+ if "answer_offset" in arguments:
447
+ from zhihu_answer_fetch import match_answer
448
+ if not match_answer(url):
449
+ raise ValueError("answer_offset 需要精确的知乎回答 URL。")
450
+
434
451
  # 微信公众号文章原生自适应
435
452
  if "mp.weixin.qq.com" in url or mode == "article":
436
453
  article_mod = _lazy_cached("article")
@@ -497,14 +514,17 @@ def execute_tool(name: str, arguments: dict[str, Any]) -> dict[str, Any]:
497
514
  timeout=_env_int("ARGO_MCP_TIMEOUT_FETCH", _int_param(arguments, "timeout", 15)),
498
515
  use_browser_fallback=True,
499
516
  force_browser=arguments.get("use_browser", False),
517
+ answer_offset=arguments.get("answer_offset"),
500
518
  )
501
519
  if focus_query and result.get("success"):
502
520
  focus_mod = _lazy_cached("focus_extract")
503
521
  focus_mod.apply_focus(result, focus_query,
504
522
  max_chars=_clamp_int(
505
523
  _int_param(arguments, "max_chars", 8000), 8000, 500, 50000))
524
+ from zhihu_answer_fetch import finish_focus
525
+ finish_focus(result, _clamp_int(_int_param(arguments, "max_chars", 8000), 8000, 500, 50000))
506
526
  if not result.get("focus_applied"):
507
- result["focus_note"] = "内容未达聚焦阈值,返回全文"
527
+ result["focus_note"] = "内容未达聚焦阈值,按字符上限返回"
508
528
  if arguments.get("summary", True) and isinstance(result.get("content"), str):
509
529
  max_c = _clamp_int(_int_param(arguments, "max_chars", 8000), 8000, 500, 50000)
510
530
  if len(result["content"]) > max_c:
@@ -117,6 +117,7 @@ TOOLS = [
117
117
  "properties": {
118
118
  "query": {"type": "string", "description": "搜索查询词"},
119
119
  "domain": {"type": "string", "enum": ["web", "social", "job", "local"], "description": "搜索领域:web 统一网络搜索(默认),social 社交媒体/论坛讨论,job 招聘岗位聚合,local 本机文件搜索"},
120
+ "platforms": {"type": "string", "description": "domain=social 的平台名,逗号分隔。twitter 表示 X 关键词自动选路;固定通道用 engine=fxtwitter/twitter_cli/twitter。"},
120
121
  "engine": {"type": "string", "description": "指定搜索引擎(auto 自动选择;可选 octen/anysearch/exa/zhihu/eastmoney/arxiv/byted/bocha/tavily/deepseek_search/github/wikipedia/semantic_scholar/local_search 等,默认 auto;deepseek_search 为按次计费的官方 DeepSeek 搜索,结果带权威分级与发布时间,新闻时事类查询优先考虑)"},
121
122
  "max_results": {"type": "integer", "description": "返回结果条数(1-20,默认 5)"},
122
123
  "depth": {"type": "string", "enum": ["fast", "balanced", "deep"], "description": "搜索深度:fast 快、deep 全(慢),默认 fast"},
@@ -245,6 +246,7 @@ TOOLS = [
245
246
  "extract_mode": {"type": "string", "enum": ["tables", "metadata", "jsonld", "all"], "description": "mode=extract 时的提取子模式,默认 all"},
246
247
  "focus": {"type": "string", "description": "BM25 聚焦查询词:只返回相关段落,省 token(仅 mode=text)"},
247
248
  "max_chars": {"type": "integer", "description": "返回正文最大字符数(500-50000,默认 8000)"},
249
+ "answer_offset": {"type": "integer", "description": "知乎回答摘要查询偏移:首轮省略;仅在用户明确要求续查时传上次的 next_offset"},
248
250
  "use_browser": {"type": "boolean", "description": "强制用反检测浏览器(HTTP 失败时已自动升级,默认关)"},
249
251
  "include_links": {"type": "boolean", "description": "附带正文内链接(最多 30 条;默认只回 links_count,省 token,默认关)"},
250
252
  },
@@ -39,7 +39,7 @@ except Exception: # pragma: no cover
39
39
 
40
40
  # 版本来源:与 package.json / SKILL.md 保持一致(发布时统一升版;
41
41
  # tests/test_consistency_gates.py 会四端对账,漂移即红)
42
- ARGO_MCP_VERSION = "2.16.0"
42
+ ARGO_MCP_VERSION = "2.18.0"
43
43
 
44
44
  _response_format = "content-length" # 根据客户端请求自动切换
45
45
 
@@ -155,10 +155,29 @@ def run_stdio():
155
155
  continue
156
156
  else:
157
157
  _response_format = "content-length"
158
- length = int(header_str.split(":")[1].strip())
159
- sys.stdin.buffer.readline() # skip blank line
160
- body = sys.stdin.buffer.read(length).decode("utf-8")
161
- request = json.loads(body)
158
+ try:
159
+ length = int(header_str.split(":", 1)[1].strip())
160
+ except ValueError:
161
+ _send_error(None, -32700, "Invalid Content-Length")
162
+ continue
163
+ # 读取后续扩展头(如 Content-Type)直至空行,符合 LSP/MCP 帧规范
164
+ while True:
165
+ hdr_line = sys.stdin.buffer.readline()
166
+ if not hdr_line or hdr_line in (b"\r\n", b"\n"):
167
+ break
168
+ if length <= 0 or length > 10_000_000:
169
+ _send_error(None, -32600, "Invalid Request: Content-Length out of bounds")
170
+ continue
171
+ body = sys.stdin.buffer.read(length).decode("utf-8", errors="replace")
172
+ try:
173
+ request = json.loads(body)
174
+ except json.JSONDecodeError:
175
+ _send_error(None, -32700, "Parse error")
176
+ continue
177
+
178
+ if not isinstance(request, dict):
179
+ _send_error(None, -32600, "Invalid Request")
180
+ continue
162
181
 
163
182
  method = request.get("method", "")
164
183
  params = request.get("params", {})
@@ -87,22 +87,26 @@ def _resolve_research_profile(arguments: dict[str, Any], lazy_cached_fn) -> tupl
87
87
 
88
88
  def _search_social_platforms(
89
89
  platforms: list[str], query: str, n: int, timeout: float = 20.0,
90
- lazy_cached_fn=None,
90
+ lazy_cached_fn=None, *, x_engine="auto", since=None, until=None, outcomes=None,
91
91
  ) -> tuple[dict[str, list], list[str], list[str]]:
92
92
  """并行抓取多社交平台(MCP 热路径)。"""
93
93
  platform_results: dict[str, list] = {}
94
94
  errors: list[str] = []
95
95
  engines_used: list[str] = []
96
96
 
97
- def _one(platform: str) -> tuple[str, list, str | None]:
97
+ def _one(platform: str):
98
+ if platform in ("twitter", "x"):
99
+ from x_keyword_route import search_x_keywords
100
+ result = search_x_keywords(query, n, engine=x_engine, since=since, until=until, timeout=timeout)
101
+ return result["results"], result["errors"], result["engines_used"], result["engine_outcomes"]
98
102
  module_name = platform.replace("-", "_") + "_engine"
99
103
  try:
100
104
  mod = lazy_cached_fn(f"social_engines.{module_name}")
101
- return platform, mod.search(query, n=n), None
105
+ return mod.search(query, n=n), [], [platform], []
102
106
  except ImportError:
103
- return platform, [], f"Platform {platform} not available (module social_engines.{module_name})"
107
+ return [], [f"Platform {platform} not available (module social_engines.{module_name})"], [], []
104
108
  except Exception as e:
105
- return platform, [], f"{platform}: {str(e)[:100]}"
109
+ return [], [f"{platform}: {str(e)[:100]}"], [], []
106
110
 
107
111
  workers = min(max(len(platforms), 1), 4)
108
112
  import concurrent.futures
@@ -110,12 +114,12 @@ def _search_social_platforms(
110
114
  futs = {ex.submit(_one, p): p for p in platforms}
111
115
  try:
112
116
  for fut in concurrent.futures.as_completed(futs, timeout=timeout):
113
- platform, results, err = fut.result()
114
- platform_results[platform] = results
115
- if err:
116
- errors.append(err)
117
- elif results is not None:
118
- engines_used.append(platform)
117
+ results, issues, used, attempts = fut.result()
118
+ platform_results[futs[fut]] = results
119
+ errors.extend(issues)
120
+ engines_used.extend(used)
121
+ if outcomes is not None:
122
+ outcomes.extend(attempts)
119
123
  except concurrent.futures.TimeoutError:
120
124
  for fut, platform in futs.items():
121
125
  if not fut.done():
@@ -241,18 +241,27 @@ def numeric_verify_results(results: list[dict[str, Any]],
241
241
  # 顺序固定为 export 契约(调用方按这些键读 summary);词表值来自
242
242
  # engine_states,键序留在这里。
243
243
  counts = {v: 0 for v in VERDICTS}
244
+ from evidence_grounding import extract_anchored_context
245
+
244
246
  for r, nums, val in outcomes:
245
247
  page, method = val
248
+ anchored: list[dict[str, Any]] = []
246
249
  if not page or len(page.strip()) < 100:
247
250
  # 正文过短:无数可比,不伪造 verdict(unfetchable,不惩罚)
248
251
  verdict, hits, misses = (
249
252
  engine_states.NUMERIC_UNFETCHABLE, [], [n["raw"] for n in nums])
250
253
  else:
251
254
  verdict, hits, misses = _verdict_for(nums, page)
255
+ entity_hint = (query or "").strip() or str(r.get("title") or "")[:40]
256
+ for h in hits[:3]:
257
+ ctx = extract_anchored_context(page, h, entity=entity_hint)
258
+ if ctx.get("excerpt"):
259
+ anchored.append({"value": h, **ctx})
252
260
  counts[verdict] += 1
253
261
  r["numeric_verification"] = {
254
262
  "verdict": verdict,
255
263
  "checked": [n["raw"] for n in nums],
264
+ **({"anchored_excerpts": anchored} if anchored else {}),
256
265
  "hits": hits,
257
266
  "misses": misses,
258
267
  "fetch_method": method,
@@ -101,6 +101,16 @@ def build_failures(result: dict[str, Any], limit: int = 6) -> list[dict[str, Any
101
101
  seen.add(key)
102
102
  category, action, retryable = _FAILURE_META.get(
103
103
  status, ("unknown", "源端异常;可重试或换源", True))
104
+ # 当 status 落入通用 error/unknown 但携带原始 HTTP 状态码时,按状态码兜底
105
+ # 归因,避免 429/401/403/5xx 被降级成 failure_kinds=unknown 污染坏例账本。
106
+ http_st = o.get("http_status")
107
+ if category == "unknown" and isinstance(http_st, int):
108
+ if http_st == 429:
109
+ category, action, retryable = _FAILURE_META[engine_states.OUTCOME_RATE_LIMITED]
110
+ elif http_st in (401, 403):
111
+ category, action, retryable = _FAILURE_META[engine_states.OUTCOME_AUTH_FAILED]
112
+ elif 500 <= http_st < 600:
113
+ category, action, retryable = ("transient", f"源端 HTTP {http_st} 临时故障;可重试或换源", True)
104
114
  item: dict[str, Any] = {
105
115
  "engine": engine,
106
116
  "status": status,
@@ -50,9 +50,13 @@
50
50
  # AGENTS.md 的「~13s」漂移注释修为实测值:hook 实测 20.8s(已超自设 20s
51
51
  # 红线)回到 ~17s,新门禁是在这个余量里加的。
52
52
  # 2026-11-14 清单单真源收口:42 文件手工枚举迁到 tests/gate_manifest.txt
53
- # (49 条:42 + env/config 对账门补册 6 + 本门禁自身 1;13 项登记 skip 豁免
54
- # 带理由),漏册由 test_gate_manifest.py 反向断言拦截,本文件不再随新门禁
55
- # 逐轮追加。补册 6 项实测 +1.7s,合计 ~19s,仍在 20s 红线内。
53
+ # (49 条:42 + env/config 对账门补册 6 + 本门禁自身 1),漏册由
54
+ # test_gate_manifest.py 反向断言拦截,本文件不再随新门禁逐轮追加。
55
+ # 2026-11-21 根因修复:13 项 skip 豁免全部入册(实测均 <1s),清单 73 条;
56
+ # 串行实测 19.2~21.5s 已跨 20s 红线,故改 4 片并行(墙钟 ~8s,824 用例
57
+ # 零丢失)。取消 skip 层的原因:豁免项只由 CI 兜底,而本地连续 36 笔未推、
58
+ # CI 零覆盖,两次「本地绿、全量红」由此漏库(test_http_attribution、
59
+ # test_subprocess_encoding_gate)。拦截点必须留在本地。
56
60
  #
57
61
  # 安装:bash scripts/install.sh 自动装调度器 hooks/pre-commit(原有 hook 改名
58
62
  # pre-commit.user 先跑,再直接执行本文件,不拷贝)。手动跑:sh scripts/pre-commit
@@ -113,7 +117,6 @@ if [ -z "$PY" ]; then
113
117
  exit 1
114
118
  fi
115
119
 
116
- printf "[pre-commit] argo 快门禁(~19s,解释器 %s;全量回归请手动跑 tests/)...\n" "$PY"
117
120
  # 测试清单单真源:tests/gate_manifest.txt(2026-11-14 收口)。
118
121
  # 清单曾在此手工枚举 42 个文件,每轮新门禁「漏一道加一道」(头注释史
119
122
  # 至少 6 轮),env/config 对账门三道长期漏册——现由 tests/test_gate_manifest.py
@@ -126,7 +129,53 @@ if [ ! -f "$MANIFEST" ]; then
126
129
  echo "[pre-commit] 缺 $MANIFEST,快门禁清单无真源,门禁视为失败" >&2
127
130
  exit 1
128
131
  fi
129
- "$PY" -m pytest -q $(grep -Ev '(^[[:space:]]*#|^[[:space:]]*$)' "$MANIFEST")
132
+ # 条数从清单真源现算(2026-11-24):这里是手抄数字的第三个副本,manifest 从
133
+ # 74 涨到 76 时不会变红——AGENTS.md 有 test_agents_md_precommit_file_count_matches
134
+ # 对拍,本行没有。打印值与实际跑的分片内容不一致会误导「跑了多少道门」的判断。
135
+ GATE_COUNT=$(grep -Ev '(^[[:space:]]*#|^[[:space:]]*$)' "$MANIFEST" | wc -l | tr -d ' ')
136
+ printf "[pre-commit] argo 快门禁(%s 条 4 片并行,实测 ~8s,解释器 %s;全量回归请手动跑 tests/)...\n" "$GATE_COUNT" "$PY"
137
+ # 新增测试文件当场归类(2026-11-21 审计):test_gate_manifest.py 的词根
138
+ # 反向断言拦不住命名不带 gate/… 的 <1s 文件(两个漏册实证),本检查把
139
+ # 拦截点前移到 commit 时刻——staged 新增 tests/test_*.py 必须入册;存量
140
+ # 未登记文件不受影响。实测 <0.2s。
141
+ "$PY" scripts/gate_manifest_check.py
142
+
143
+ # 快门禁分片并行(2026-11-21 根因修复)。
144
+ #
145
+ # 为什么必须并行:清单是全量收录(skip 豁免层已取消),串行实测 19.2~21.5s,
146
+ # 波动跨过自设 20s 红线——而「慢于 20s 就会被 --no-verify 绕过」正是这份
147
+ # 清单当初把 13 道门豁免给 CI 的原因。豁免的代价已实证两次:本地连续 36 笔
148
+ # 未推、CI 零覆盖,test_http_attribution 与 test_subprocess_encoding_gate
149
+ # 两次「本地绿、全量红」漏进库。所以正解不是把门挪走,而是让本地跑得起:
150
+ # 4 片并行墙钟 ~8s(实测两轮 7.88/7.77s,824 用例零丢失、4 片全 rc=0)。
151
+ #
152
+ # 分片插件与 CI 同源(pytest-split + tests/.test_durations),保证本地与
153
+ # CI 看到同一份清单。pytest-split 缺失时回落串行并显式告警——不静默跳过。
154
+ GATE_SPLITS=4
155
+ if ! "$PY" -c "import pytest_split" >/dev/null 2>&1; then
156
+ echo "[pre-commit] 警告:缺 pytest-split,快门禁回落串行(本地与 CI 清单仍一致,只是慢)" >&2
157
+ "$PY" -m pytest -q -p no:cacheprovider $(grep -Ev '(^[[:space:]]*#|^[[:space:]]*$)' "$MANIFEST")
158
+ else
159
+ pids=""; failed=0
160
+ for g in $(seq 1 "$GATE_SPLITS"); do
161
+ "$PY" -m pytest -q -p no:cacheprovider \
162
+ --splits "$GATE_SPLITS" --group "$g" \
163
+ --durations-path tests/.test_durations \
164
+ $(grep -Ev '(^[[:space:]]*#|^[[:space:]]*$)' "$MANIFEST") &
165
+ pids="$pids $!"
166
+ done
167
+ for p in $pids; do
168
+ wait "$p" || failed=1
169
+ done
170
+ if [ "$failed" -ne 0 ]; then
171
+ echo "[pre-commit] 快门禁有分片失败(见上方输出)" >&2
172
+ exit 1
173
+ fi
174
+ fi
175
+
176
+ # L2 变更感知增量选测(2026-11-24 方案三):按 staged 改动反查未入册的 343 个
177
+ # 存量单测并在 8s 预算内精准执行,补齐「本地绿、全量红」盲区;无命中 <0.25s。
178
+ "$PY" scripts/affected_tests.py --staged --run --budget 8
130
179
 
131
180
  # 派生件一致性门禁(P0-2):写完 spec 不跑 sync 就提交,派生件会过期。
132
181
  # 实测 0.13s,进 pre-commit 不触发 --no-verify 绕过。
@@ -135,15 +184,23 @@ if ! "$PY" scripts/sync_backends.py --check; then
135
184
  echo "[pre-commit] 派生件过期,正在自动执行同步刷新..."
136
185
  "$PY" scripts/sync_backends.py
137
186
  "$PY" scripts/gen_engine_catalog.py
138
- echo "[pre-commit] 派生件已自动刷新,请检查并暂存相关修改: git add backends/ docs/ENGINE_CATALOG.md assets/readme/" >&2
187
+ echo "[pre-commit] 派生件已自动刷新,请检查并暂存相关修改: git add backends/ docs/ENGINE_CATALOG.md" >&2
139
188
  # 这里必须 exit 1,不能刷新后放行:钩子改的是工作区,暂存区里仍是旧版
140
189
  # 派生件;若返回 0,git 会把旧内容提交进去,校验反而形同虚设。也不自动
141
190
  # git add——把「刷新了什么」留给用户过目。
142
191
  exit 1
143
192
  fi
144
193
 
145
- if command -v node >/dev/null 2>&1 && [ -f packages/dsh-plugin/test/size-gate.test.js ]; then
146
- node --test packages/dsh-plugin/test/size-gate.test.js packages/dsh-plugin/test/client.test.js
194
+ # 子技能快门禁(2026-11-21 方案 B 补盲):ego-search 回归测试耗时 <1s,
195
+ # 纳入本地快门禁消除子技能门禁真空带。
196
+ if [ -d sub-skills/ego-search/tests ]; then
197
+ "$PY" -m pytest -q -p no:cacheprovider sub-skills/ego-search/tests
198
+ fi
199
+
200
+ # DSH 插件全量 Node 测试(2026-11-21 方案 B 补盲):含 workbench / concurrency /
201
+ # client / index / diagnostics / config / size-gate,136 用例实测 ~2.5s。
202
+ if command -v node >/dev/null 2>&1 && [ -d packages/dsh-plugin/test ]; then
203
+ node --test packages/dsh-plugin/test/*.test.js
147
204
  fi
148
205
 
149
206
  # 高风险提交的检查清单提示(2026-11-10):只警告不硬拦。