argo-search 2.14.1 → 2.16.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 (245) hide show
  1. package/AGENTS.md +8 -6
  2. package/README.es.md +57 -813
  3. package/README.ja.md +56 -814
  4. package/README.ko.md +56 -812
  5. package/README.md +160 -754
  6. package/README.zh.md +152 -872
  7. package/SKILL.md +22 -23
  8. package/assets/readme/counts.json +1 -1
  9. package/assets/readme/hero.svg +23 -23
  10. package/backends/concept_vectors.bin +0 -0
  11. package/backends/domain_profiles.json +149 -6
  12. package/backends/engine_concept_vectors.json +1525 -1525
  13. package/backends/engine_registry.yaml +139 -30
  14. package/backends/quota_profiles.json +83 -3
  15. package/bin/argo +33 -17
  16. package/config.yaml +189 -33
  17. package/docs/ADDING_NEW_ENGINE.md +10 -0
  18. package/docs/ARGO_INTRO.md +1 -1
  19. package/docs/CHANGELOG.md +38 -0
  20. package/docs/ENGINE_CATALOG.md +102 -89
  21. package/docs/MCP_SETUP.md +10 -1
  22. package/docs/RELEASE_NOTES_v2.14.1.md +4 -4
  23. package/docs/RELEASE_NOTES_v2.15.0.md +50 -0
  24. package/docs/RELEASE_NOTES_v2.16.0.md +58 -0
  25. package/docs/RELEASING.md +1 -1
  26. package/engines/specs/ai_labs.yaml +89 -0
  27. package/engines/specs/archive_org.yaml +1 -1
  28. package/engines/specs/bilibili_hot.yaml +11 -1
  29. package/engines/specs/brave.yaml +3 -3
  30. package/engines/specs/carbon_intensity.yaml +1 -1
  31. package/engines/specs/cisa_alerts.yaml +40 -0
  32. package/engines/specs/cn_ai_news.yaml +10 -8
  33. package/engines/specs/crates.yaml +1 -1
  34. package/engines/specs/crossref.yaml +4 -2
  35. package/engines/specs/crt_sh.yaml +1 -1
  36. package/engines/specs/dblp.yaml +1 -1
  37. package/engines/specs/devto.yaml +1 -1
  38. package/engines/specs/digup.yaml +11 -6
  39. package/engines/specs/docker_hub.yaml +1 -1
  40. package/engines/specs/douyin_hot.yaml +11 -1
  41. package/engines/specs/dw_news.yaml +4 -2
  42. package/engines/specs/eng_blogs.yaml +63 -0
  43. package/engines/specs/europeana.yaml +3 -4
  44. package/engines/specs/europepmc.yaml +1 -1
  45. package/engines/specs/felo.yaml +3 -3
  46. package/engines/specs/firecrawl.yaml +3 -0
  47. package/engines/specs/fourget.yaml +5 -2
  48. package/engines/specs/france24.yaml +6 -4
  49. package/engines/specs/fxtwitter.yaml +30 -7
  50. package/engines/specs/gbfs_nyc.yaml +1 -1
  51. package/engines/specs/gleif.yaml +1 -1
  52. package/engines/specs/gov_regulations.yaml +1 -1
  53. package/engines/specs/grepapp_mcp.yaml +62 -0
  54. package/engines/specs/guardian_rss.yaml +6 -4
  55. package/engines/specs/hf_datasets.yaml +1 -1
  56. package/engines/specs/huggingface.yaml +1 -1
  57. package/engines/specs/itotii.yaml +13 -1
  58. package/engines/specs/keenable.yaml +7 -1
  59. package/engines/specs/linux_do.yaml +63 -0
  60. package/engines/specs/lobsters.yaml +41 -0
  61. package/engines/specs/local_crossref.yaml +3 -1
  62. package/engines/specs/local_github.yaml +1 -1
  63. package/engines/specs/local_npm.yaml +6 -0
  64. package/engines/specs/local_openstreetmap.yaml +1 -1
  65. package/engines/specs/local_seek.yaml +6 -0
  66. package/engines/specs/maven.yaml +1 -1
  67. package/engines/specs/mdn.yaml +1 -1
  68. package/engines/specs/musicbrainz.yaml +1 -1
  69. package/engines/specs/nasa_images.yaml +1 -1
  70. package/engines/specs/nhtsa_vpic.yaml +6 -3
  71. package/engines/specs/npm.yaml +1 -1
  72. package/engines/specs/nuget.yaml +1 -1
  73. package/engines/specs/nvd.yaml +1 -1
  74. package/engines/specs/open_meteo.yaml +1 -1
  75. package/engines/specs/openalex.yaml +4 -2
  76. package/engines/specs/openreview.yaml +1 -1
  77. package/engines/specs/polymarket.yaml +1 -1
  78. package/engines/specs/redskill.yaml +2 -0
  79. package/engines/specs/searxng.yaml +4 -2
  80. package/engines/specs/sec_edgar.yaml +9 -4
  81. package/engines/specs/steam.yaml +1 -1
  82. package/engines/specs/tinyfish.yaml +2 -0
  83. package/engines/specs/tinyfish_news.yaml +2 -0
  84. package/engines/specs/tinyfish_paper.yaml +2 -0
  85. package/engines/specs/toutiao_hot.yaml +11 -1
  86. package/engines/specs/train.yaml +3 -0
  87. package/engines/specs/twitter.yaml +4 -0
  88. package/engines/specs/unpaywall.yaml +6 -0
  89. package/engines/specs/vam.yaml +17 -3
  90. package/engines/specs/weibo_hot.yaml +11 -1
  91. package/engines/specs/wikidata.yaml +1 -1
  92. package/engines/specs/wikipedia.yaml +1 -1
  93. package/engines/specs/wolframalpha.yaml +3 -3
  94. package/engines/specs/xiaohongshu.yaml +2 -0
  95. package/engines/specs/zhihu.yaml +3 -18
  96. package/engines/specs/zhihu_hot_app.yaml +1 -1
  97. package/engines/specs/zhihu_kb.yaml +18 -0
  98. package/engines/specs/zhihu_questions.yaml +19 -0
  99. package/package.json +4 -2
  100. package/packages/dsh-plugin/README.md +9 -14
  101. package/packages/dsh-plugin/dsh/client.js +481 -1037
  102. package/packages/dsh-plugin/dsh/diagnostics.js +71 -20
  103. package/packages/dsh-plugin/dsh/index.js +6 -0
  104. package/packages/dsh-plugin/dsh/runner.js +3 -1
  105. package/packages/dsh-plugin/dsh/workbench-client.js +796 -0
  106. package/packages/dsh-plugin/dsh/workbench-md.js +386 -0
  107. package/packages/dsh-plugin/dsh/workbench-suggestions.js +148 -0
  108. package/packages/dsh-plugin/dsh/workbench.js +966 -0
  109. package/packages/dsh-plugin/icon.svg +23 -0
  110. package/packages/dsh-plugin/package.json +10 -3
  111. package/packages/dsh-plugin/scripts/sync-local.mjs +87 -0
  112. package/packages/dsh-plugin/scripts/sync-local.sh +13 -1
  113. package/packages/dsh-plugin/test/diagnostics.test.js +38 -1
  114. package/packages/dsh-plugin/test/size-gate.test.js +2 -9
  115. package/packages/dsh-plugin/test/workbench.test.js +92 -0
  116. package/scripts/adaptive.py +7 -1
  117. package/scripts/archive_run.py +112 -53
  118. package/scripts/argo_paths.py +42 -5
  119. package/scripts/badcase_ledger.py +117 -9
  120. package/scripts/build_concept_table.py +112 -55
  121. package/scripts/cache.py +6 -2
  122. package/scripts/caliber_isolation.py +60 -23
  123. package/scripts/circuit_breaker.py +72 -11
  124. package/scripts/cli_io.py +20 -2
  125. package/scripts/config_cache.py +44 -1
  126. package/scripts/daemon.py +151 -51
  127. package/scripts/dormant_ledger.py +23 -9
  128. package/scripts/engine_dispatch.py +8 -5
  129. package/scripts/engine_env.py +191 -1
  130. package/scripts/engine_families.py +50 -7
  131. package/scripts/engine_states.py +3 -50
  132. package/scripts/engine_validate.py +13 -45
  133. package/scripts/engines.py +15 -31
  134. package/scripts/engines_base.py +66 -61
  135. package/scripts/engines_builders.py +0 -15
  136. package/scripts/engines_builders_archive.py +4 -3
  137. package/scripts/engines_builders_batch10.py +346 -100
  138. package/scripts/engines_builders_batch11.py +4 -76
  139. package/scripts/engines_builders_batch13.py +4 -3
  140. package/scripts/engines_builders_batch14.py +2 -1
  141. package/scripts/engines_builders_batch15.py +2 -1
  142. package/scripts/engines_builders_batch9.py +16 -25
  143. package/scripts/engines_builders_cn.py +7 -201
  144. package/scripts/engines_builders_data.py +12 -11
  145. package/scripts/engines_builders_data_macro.py +5 -4
  146. package/scripts/engines_builders_dsh.py +2 -1
  147. package/scripts/engines_builders_feeds.py +76 -11
  148. package/scripts/engines_builders_finance.py +2 -1
  149. package/scripts/engines_builders_intl.py +18 -117
  150. package/scripts/engines_builders_media.py +59 -12
  151. package/scripts/engines_builders_pixiv.py +2 -16
  152. package/scripts/engines_builders_science.py +8 -7
  153. package/scripts/engines_builders_search.py +7 -14
  154. package/scripts/engines_builders_skill.py +2 -1
  155. package/scripts/engines_builders_tech.py +8 -17
  156. package/scripts/engines_builders_weather.py +241 -0
  157. package/scripts/engines_fields.py +91 -0
  158. package/scripts/engines_http.py +184 -0
  159. package/scripts/engines_mcp.py +405 -0
  160. package/scripts/engines_parsers.py +13 -369
  161. package/scripts/engines_schema_drift.py +260 -0
  162. package/scripts/evidence.py +13 -0
  163. package/scripts/evidence_loop.py +19 -4
  164. package/scripts/extend_route_labels.py +6 -0
  165. package/scripts/fetch_jina.py +98 -0
  166. package/scripts/fetch_jsrun.py +15 -11
  167. package/scripts/fetch_v3.py +79 -120
  168. package/scripts/fulltext_store.py +42 -1
  169. package/scripts/fxtwitter_api.py +8 -7
  170. package/scripts/gen_engine_catalog.py +2 -2
  171. package/scripts/general_pool.py +15 -4
  172. package/scripts/health_check.py +1 -1
  173. package/scripts/image_vision/vision_probe +0 -0
  174. package/scripts/install.sh +2 -0
  175. package/scripts/link_source.py +65 -24
  176. package/scripts/local_seek_adapter.py +57 -17
  177. package/scripts/matrix_search_eval.py +8 -10
  178. package/scripts/mcp_handlers.py +53 -31
  179. package/scripts/mcp_handlers_surface.py +6 -18
  180. package/scripts/mcp_transport.py +10 -5
  181. package/scripts/min_version_scan.py +7 -3
  182. package/scripts/network_aware.py +7 -13
  183. package/scripts/numeric_verify.py +3 -2
  184. package/scripts/output_transparency.py +3 -0
  185. package/scripts/pre-commit +45 -43
  186. package/scripts/query_understanding.py +30 -6
  187. package/scripts/quota.py +36 -30
  188. package/scripts/rank_signals.py +9 -0
  189. package/scripts/recompute.py +15 -5
  190. package/scripts/recovery.py +38 -29
  191. package/scripts/recovery_runner.py +29 -10
  192. package/scripts/redskill/redskill_engine.py +2 -1
  193. package/scripts/release.py +14 -26
  194. package/scripts/release_check.py +5 -25
  195. package/scripts/replay_eval.py +2 -2
  196. package/scripts/research_cli.py +40 -0
  197. package/scripts/research_notes.py +368 -0
  198. package/scripts/route.py +40 -70
  199. package/scripts/route_audit.py +259 -0
  200. package/scripts/route_combo.py +21 -6
  201. package/scripts/route_domains.py +150 -23
  202. package/scripts/route_lang.py +20 -7
  203. package/scripts/route_log.py +26 -9
  204. package/scripts/route_policy.py +85 -6
  205. package/scripts/route_telemetry_export.py +199 -0
  206. package/scripts/rrf_classic.py +5 -22
  207. package/scripts/search.py +2 -1
  208. package/scripts/search_attribution.py +53 -10
  209. package/scripts/search_entry.py +32 -1
  210. package/scripts/search_output.py +23 -11
  211. package/scripts/search_pipeline.py +15 -3
  212. package/scripts/search_rank.py +21 -11
  213. package/scripts/semantic_evidence.py +394 -178
  214. package/scripts/serp_guard.py +13 -1
  215. package/scripts/settings_page.py +4 -3
  216. package/scripts/single_flight.py +1 -1
  217. package/scripts/social_engines/hackernews_engine.py +2 -1
  218. package/scripts/social_engines/reddit_engine.py +2 -1
  219. package/scripts/social_engines/xiaohongshu_engine.py +2 -1
  220. package/scripts/social_engines/zhihu_engine.py +252 -43
  221. package/scripts/sogou_weixin_browser.py +5 -6
  222. package/scripts/source_audit.py +44 -9
  223. package/scripts/source_ledger.py +2 -15
  224. package/scripts/source_selection.py +45 -20
  225. package/scripts/straggler_policy.py +1 -2
  226. package/scripts/sync_backends.py +17 -0
  227. package/scripts/tfidf_router.py +23 -11
  228. package/scripts/time_utils.py +54 -1
  229. package/scripts/train.py +68 -2
  230. package/scripts/usage_log.py +50 -10
  231. package/scripts/watch.py +3 -3
  232. package/scripts/zhihu_quota.py +2 -1
  233. package/sub-skills/argo-wide-research/SKILL.md +70 -0
  234. package/sub-skills/ego-search/{SKILL.md → README.md} +15 -47
  235. package/sub-skills/ego-search/scripts/ego_search.py +13 -4
  236. package/sub-skills/js-run/{SKILL.md → README.md} +3 -20
  237. package/sub-skills/local-search/{SKILL.md → README.md} +3 -8
  238. package/sub-skills/local-search/engine_registry.py +32 -7
  239. package/sub-skills/local-seek/SKILL.md +20 -22
  240. package/sub-skills/local-seek/scripts/seek_fts.py +58 -3
  241. package/scripts/caliber_dedupe.py +0 -66
  242. package/scripts/engines_builders_batch16.py +0 -13
  243. package/scripts/health_probe.py +0 -253
  244. package/scripts/social_engines/twitter_engine.py +0 -514
  245. package/scripts/sync_installs.py +0 -29
@@ -0,0 +1,368 @@
1
+ #!/usr/bin/env python3
2
+ """research_notes.py — 研报标准化落盘与轻量索引。"""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import json
8
+ import os
9
+ import re
10
+ import sys
11
+ from datetime import datetime
12
+ from pathlib import Path
13
+ from typing import Any
14
+
15
+ from cli_io import dumps
16
+
17
+ KINDS = ("study", "explore")
18
+ _KIND_SUFFIX = {"study": "研究", "explore": "探索"}
19
+
20
+ SECTIONS = [
21
+ ("0. 结论速览", "3-7 条,每条一句话;读完能回答「所以呢」"),
22
+ ("1. 关键事实", "带来源的事实,标注 [已验证] / [推断];每条可回源"),
23
+ ("2. 机制拆解", "原文/对象怎么做到的,拆到可复用粒度;不是摘要,是结构"),
24
+ ("3. 可迁移判断", "对我们工作有什么用,写条件与风险;面向决策,不空谈"),
25
+ ("4. 边界与后续", "未解决 / 待核验 / 后续动作;未知项写补证动作"),
26
+ ]
27
+
28
+ _STRONG_MARKERS = (".git", "AGENTS.md", "WORKSPACE")
29
+ _WEAK_MARKERS = ("pyproject.toml", "package.json", "Cargo.toml", "go.mod")
30
+ WORKSPACE_MARKERS = _STRONG_MARKERS + _WEAK_MARKERS
31
+
32
+
33
+ def _now_iso() -> str:
34
+ return datetime.now().astimezone().isoformat(timespec="seconds")
35
+
36
+
37
+ def slugify(text: str, fallback: str = "note") -> str:
38
+ """URL 或问题标题 → 安全文件名 slug。"""
39
+ tail = text.rstrip("/").rsplit("/", 1)[-1] or text
40
+ tail = re.sub(r"[?#].*$", "", tail)
41
+ tail = re.sub(r"\s+", "-", tail.strip())
42
+ tail = re.sub(r"[^0-9A-Za-z\u4e00-\u9fff._-]+", "-", tail).strip("-.")
43
+ return tail[:80] or fallback
44
+
45
+
46
+ def find_workspace_root(start_path: Path | None = None) -> Path:
47
+ """从当前路径向上寻找工作区根目录。"""
48
+ curr = (start_path or Path.cwd()).resolve()
49
+ parents = [curr, *curr.parents]
50
+ for markers in (_STRONG_MARKERS, _WEAK_MARKERS):
51
+ for parent in parents:
52
+ if any((parent / marker).exists() for marker in markers):
53
+ return parent
54
+ if parent == parent.parent:
55
+ break
56
+ return curr
57
+
58
+
59
+ def resolve_research_base(workspace: Path | None = None) -> Path:
60
+ """研究与归档共用的基目录。"""
61
+ ws = workspace or find_workspace_root()
62
+ if (ws / "docs" / "research").is_dir():
63
+ return ws / "docs" / "research"
64
+ if (ws / "research").is_dir():
65
+ return ws / "research"
66
+ if (ws / "docs").is_dir():
67
+ return ws / "docs" / "research"
68
+ return ws / "research"
69
+
70
+
71
+ _ARGO_SELF_ROOT = Path(__file__).resolve().parent.parent
72
+
73
+
74
+ def is_argo_self_workspace(workspace: Path | None = None) -> bool:
75
+ """判断工作区是否为 argo 工具自身仓库,避免把个人探索产物落进工具仓。"""
76
+ try:
77
+ ws = (workspace or find_workspace_root()).resolve()
78
+ return ws == _ARGO_SELF_ROOT
79
+ except OSError:
80
+ return False
81
+
82
+
83
+ def workspace_anchorable(workspace: Path | None = None) -> bool:
84
+ """当前工作区是否可锚定(argo 工具自身仓库不作为个人研究落盘工作区)。"""
85
+ try:
86
+ ws = workspace or find_workspace_root()
87
+ if is_argo_self_workspace(ws):
88
+ return False
89
+ return any((ws / m).exists() for m in WORKSPACE_MARKERS)
90
+ except Exception:
91
+ return False
92
+
93
+
94
+ def should_anchor_workspace(workspace: Path | None = None) -> bool:
95
+ """统一判断默认解析是否应落到工作区(而非用户级 research_root)。"""
96
+ ws = workspace or find_workspace_root()
97
+ if is_argo_self_workspace(ws):
98
+ return False
99
+ base = resolve_research_base(ws)
100
+ try:
101
+ if base.is_dir():
102
+ return True
103
+ except OSError:
104
+ pass
105
+ return workspace_anchorable(ws)
106
+
107
+
108
+ def resolve_root(explicit: str | Path | None = None) -> Path:
109
+ """解析研报保存根目录。"""
110
+ return resolve_root_with_source(explicit)[0]
111
+
112
+
113
+ def resolve_root_with_source(explicit: str | Path | None = None) -> tuple[Path, str]:
114
+ """解析研报根目录并返回来源说明。"""
115
+ if explicit:
116
+ return Path(explicit).expanduser().resolve(), f"--root/--dir={explicit}"
117
+ for env in ("ARGO_RESEARCH_ROOT", "ARGO_ARCHIVE_ROOT"):
118
+ val = os.environ.get(env, "").strip()
119
+ if val:
120
+ return Path(val).expanduser().resolve(), f"{env}={val}"
121
+
122
+ ws = find_workspace_root()
123
+ base = resolve_research_base(ws)
124
+ if should_anchor_workspace(ws):
125
+ return base, f"工作区锚定 {base}"
126
+
127
+ try:
128
+ from argo_paths import research_root
129
+ user_root = research_root().expanduser().resolve()
130
+ return user_root, f"用户级兜底 {user_root}"
131
+ except Exception:
132
+ return base, f"工作区锚定 {base}"
133
+
134
+
135
+ def index_path(root: Path | None = None) -> Path:
136
+ return (root or resolve_root()) / "research-index.jsonl"
137
+
138
+
139
+ def append_index(row: dict[str, Any], root: Path | None = None) -> dict[str, Any]:
140
+ """追加一行研究笔记索引。"""
141
+ p = index_path(root)
142
+ try:
143
+ p.parent.mkdir(parents=True, exist_ok=True)
144
+ with p.open("a", encoding="utf-8") as f:
145
+ f.write(json.dumps(row, ensure_ascii=False) + "\n")
146
+ except OSError:
147
+ return {"indexed": False, "path": str(p), "error": "write_failed"}
148
+ return {"indexed": True, "path": str(p)}
149
+
150
+
151
+ def _body_excerpt(note_path: Path, limit: int = 200) -> str:
152
+ """提取 Markdown 正文首行非标题内容用于检索。"""
153
+ try:
154
+ text = note_path.read_text(encoding="utf-8", errors="replace")
155
+ except OSError:
156
+ return ""
157
+ if text.startswith("---"):
158
+ parts = text.split("---", 2)
159
+ if len(parts) >= 3:
160
+ text = parts[2]
161
+ # 纯横线行(frontmatter 结束后的水平线 "---")不是正文——实测骨架与填实
162
+ # 两种形态都会在标题块后紧跟一条水平线,不跳过它 excerpt 恒为 "---"。
163
+ skip_prefixes = ("#", "<!--", "研究对象", "调研日期", "证据口径", "关联", "---")
164
+ for line in text.splitlines():
165
+ s = line.strip()
166
+ if s and not any(s.startswith(p) for p in skip_prefixes):
167
+ return s[:limit]
168
+ return ""
169
+
170
+
171
+ def search_index(
172
+ query: str,
173
+ root: Path | None = None,
174
+ kind: str | None = None,
175
+ limit: int = 10,
176
+ ) -> list[dict[str, Any]]:
177
+ """检索研报索引(支持 slug / title / url / related / 研报正文内容匹配)。"""
178
+ p = index_path(root)
179
+ if not p.is_file():
180
+ return []
181
+ kw = (query or "").strip().lower()
182
+ out: list[dict[str, Any]] = []
183
+ with p.open(encoding="utf-8") as f:
184
+ for line in f:
185
+ line = line.strip()
186
+ if not line:
187
+ continue
188
+ try:
189
+ row = json.loads(line)
190
+ except ValueError:
191
+ continue
192
+ if kind and row.get("kind") != kind:
193
+ continue
194
+ hay = " ".join(
195
+ str(row.get(k) or "") for k in ("slug", "title", "url", "related", "body_excerpt")
196
+ ).lower()
197
+ matched = not kw or kw in hay
198
+ if not matched:
199
+ note_file = row.get("note_file")
200
+ if note_file and Path(note_file).is_file():
201
+ try:
202
+ matched = kw in Path(note_file).read_text(encoding="utf-8", errors="replace").lower()
203
+ except OSError:
204
+ pass
205
+ if matched:
206
+ out.append(row)
207
+ return out[-limit:][::-1]
208
+
209
+
210
+ def build_markdown_report(
211
+ *,
212
+ kind: str,
213
+ title: str,
214
+ slug: str,
215
+ url_or_problem: str,
216
+ date: str,
217
+ related: str = "无",
218
+ archive_text: str = "",
219
+ output_path: Path,
220
+ ) -> Path:
221
+ """生成标准化单一 Markdown 研报(含标准 YAML Frontmatter 与五段式结构)。"""
222
+ output_path.parent.mkdir(parents=True, exist_ok=True)
223
+ fm = {
224
+ "title": title, "slug": slug, "kind": kind,
225
+ "target": url_or_problem, "date": date,
226
+ "created_at": _now_iso(), "related": related,
227
+ }
228
+ lines = [
229
+ "---",
230
+ *[f"{k}: {json.dumps(v, ensure_ascii=False)}" for k, v in fm.items()],
231
+ "---", "",
232
+ f"# {title}", "",
233
+ f"研究对象:{url_or_problem}",
234
+ f"调研日期:{date}",
235
+ "证据口径:`[已验证]` = 直接读到原文内容;`[推断]` = 基于原文事实的判断,未直接证实",
236
+ f"关联:{related}", "", "---", "",
237
+ *[f"## {heading}\n\n<!-- {hint} -->\n" for heading, hint in SECTIONS],
238
+ ]
239
+ if kind == "explore":
240
+ lines.append("## 5. 候选方向\n\n<!-- 每条含:问题陈述 / 为什么值得 / 怎么证伪 / 第一步取证动作 -->\n")
241
+ if archive_text.strip():
242
+ lines.append("---\n\n## 附录:参考原文\n\n" + archive_text.strip() + "\n")
243
+ output_path.write_text("\n".join(lines), encoding="utf-8")
244
+ return output_path
245
+
246
+
247
+ def _create_note_bundle(
248
+ kind: str,
249
+ *,
250
+ root: Path | None = None,
251
+ slug: str,
252
+ title: str,
253
+ target: str,
254
+ related: str = "无",
255
+ archive_text: str = "",
256
+ output: Path | None = None,
257
+ ) -> dict[str, Any]:
258
+ rt = root or resolve_root()
259
+ out_file = output or (rt / kind / slug / f"{slug}-{_KIND_SUFFIX[kind]}.md")
260
+ build_markdown_report(
261
+ kind=kind, title=title or slug, slug=slug, url_or_problem=target,
262
+ date=datetime.now().strftime("%Y%m%d"), related=related,
263
+ archive_text=archive_text, output_path=out_file,
264
+ )
265
+ row: dict[str, Any] = {
266
+ "schema_version": 2, "kind": kind, "slug": slug,
267
+ "title": title or slug, "url": target, "note_file": str(out_file),
268
+ "related": related or "", "body_excerpt": _body_excerpt(out_file),
269
+ "created_at": _now_iso(),
270
+ }
271
+ if kind == "study":
272
+ row["archive_sha256"] = "embedded" if archive_text else ""
273
+ meta = append_index(row, root=rt)
274
+ return {
275
+ "kind": kind, "slug": slug, "note": str(out_file),
276
+ "output": str(out_file), "bundle_dir": str(out_file.parent), "index": meta,
277
+ }
278
+
279
+
280
+ def create_study_bundle(
281
+ *, root: Path | None = None, slug: str, title: str, url: str,
282
+ archive_text: str = "", related: str = "无", output: Path | None = None,
283
+ ) -> dict[str, Any]:
284
+ """单篇精研研报标准化生成。"""
285
+ return _create_note_bundle(
286
+ "study", root=root, slug=slug, title=title, target=url,
287
+ related=related, archive_text=archive_text, output=output,
288
+ )
289
+
290
+
291
+ def create_explore_bundle(
292
+ *, root: Path | None = None, slug: str, title: str, problem: str,
293
+ related: str = "无", output: Path | None = None,
294
+ ) -> dict[str, Any]:
295
+ """方向探索研报标准化生成。"""
296
+ return _create_note_bundle(
297
+ "explore", root=root, slug=slug, title=title, target=problem,
298
+ related=related, output=output,
299
+ )
300
+
301
+
302
+ def _cmd_create(args: argparse.Namespace) -> int:
303
+ kind = args.command
304
+ target = args.url if kind == "study" else args.problem
305
+ slug = args.slug or slugify(target)
306
+ out_path = Path(args.output).expanduser().resolve() if args.output else None
307
+ archive_text = ""
308
+ if kind == "study":
309
+ archive_text = args.archive_text or ""
310
+ if not archive_text and args.archive and Path(args.archive).is_file():
311
+ try:
312
+ archive_text = Path(args.archive).read_text(encoding="utf-8", errors="replace")
313
+ except OSError:
314
+ pass
315
+ res = _create_note_bundle(
316
+ kind, root=resolve_root(args.root), slug=slug, title=args.title or slug,
317
+ target=target, related=args.related or "无",
318
+ archive_text=archive_text, output=out_path,
319
+ )
320
+ print(dumps(res))
321
+ return 0
322
+
323
+
324
+ def _cmd_list(args: argparse.Namespace) -> int:
325
+ root, root_source = resolve_root_with_source(args.root)
326
+ rows = search_index(args.query or "", root=root, kind=args.kind, limit=args.limit)
327
+ out: dict[str, Any] = {"count": len(rows), "notes": rows, "root": str(root), "root_source": root_source}
328
+ if not rows:
329
+ out["hint"] = f"当前归档根 {root} 下没有命中。可指定 --dir 或设置 ARGO_RESEARCH_ROOT。"
330
+ print(dumps(out))
331
+ return 0
332
+
333
+
334
+ def build_parser() -> argparse.ArgumentParser:
335
+ p = argparse.ArgumentParser(prog="argo note", description="研究笔记生成与归档:单一自包含 Markdown 研报输出")
336
+ sub = p.add_subparsers(dest="command", required=True)
337
+ for name, arg_name, arg_help, desc in (
338
+ ("study", "url", "研究对象 URL", "生成单篇精研研报(标准 Markdown + Frontmatter)"),
339
+ ("explore", "problem", "探索问题或主题", "生成方向探索研报(标准 Markdown + Frontmatter)"),
340
+ ):
341
+ sp = sub.add_parser(name, help=desc)
342
+ sp.add_argument(arg_name, help=arg_help)
343
+ sp.add_argument("--title", help="标题(缺省用 slug)")
344
+ sp.add_argument("--slug", help="标识符(缺省从对象推导)")
345
+ sp.add_argument("-o", "--output", help="直接指定研报输出文件路径")
346
+ if name == "study":
347
+ sp.add_argument("--archive", help="原文文件(直接作为附录内嵌)")
348
+ sp.add_argument("--archive-text", help="直接提供原文文本(作为附录内嵌)")
349
+ sp.add_argument("--related", help="关联引用")
350
+ sp.add_argument("--root", "--dir", dest="root", help="归档根目录(缺省自动锚定工作区)")
351
+ sp.set_defaults(func=_cmd_create)
352
+
353
+ pl = sub.add_parser("list", help="检索研报索引")
354
+ pl.add_argument("query", nargs="?", help="检索关键词")
355
+ pl.add_argument("--kind", choices=KINDS, help="只看 study 或 explore")
356
+ pl.add_argument("--limit", type=int, default=10)
357
+ pl.add_argument("--root", "--dir", dest="root", help="归档根目录")
358
+ pl.set_defaults(func=_cmd_list)
359
+ return p
360
+
361
+
362
+ def main(argv: list[str] | None = None) -> int:
363
+ args = build_parser().parse_args(argv)
364
+ return int(args.func(args))
365
+
366
+
367
+ if __name__ == "__main__":
368
+ sys.exit(main())
package/scripts/route.py CHANGED
@@ -76,6 +76,7 @@ from route_domains import ( # noqa: E402
76
76
  _ZH_LANG_GATED_DOMAINS,
77
77
  _DIFFUSE_SIGNAL_RE,
78
78
  _INTENT_MIN_TOKENS,
79
+ platform_native_engine,
79
80
  )
80
81
 
81
82
  # 路由决策缓存(存储层)住在 route_cache;route_query_cached 是本模块的编排
@@ -157,6 +158,10 @@ from route_policy import ( # noqa: E402
157
158
  _new_source_budget_extra,
158
159
  _apply_engine_policy,
159
160
  _apply_policy_with_new_source_slots,
161
+ is_pure_combo_domain,
162
+ apply_domain_combo_rules,
163
+ resolve_pure_combo_fallback,
164
+ build_domain_must_keep,
160
165
  )
161
166
 
162
167
  # ── 特征提取 ──────────────────────────────────────────────────────────────────
@@ -365,49 +370,16 @@ def _route_by_domain(ctx: _RouteCtx, domain: dict[str, Any], secondary: list[dic
365
370
  _specs_snapshot()))
366
371
  _filtered = [e for e in engines_combo if e not in _drop]
367
372
  engines_combo = _filtered or [e for e in ["anysearch"] if e in enabled] or engines_combo
368
- # 🔑 中文查询 + 学术类域 → 剔除纯英文论文源(ENGINE_LANGS 声明 langs=["en"])
369
- if (domain.get("name") in ("tech_deep", "academic")
370
- and any("\u4e00" <= ch <= "\u9fff" for ch in query)):
371
- engines_combo = [e for e in engines_combo
372
- if engine_langs(e, _specs_snapshot().get(e)) != {"en"}]
373
- if not engines_combo:
374
- engines_combo = [e for e in ["arxiv", "anysearch", "local_search"]
375
- if e in enabled]
376
- # 🔑 macro_data 域 + 非美国国家词 → worldbank 前置(FRED 无该国数据,
377
- # 且错误结果会触发 early-stop 短路,导致「中国GDP」只回美国数据)
378
- if (domain.get("name") == "macro_data"
379
- and is_foreign_macro_query(query)
380
- and "worldbank" in engines_combo):
381
- engines_combo = ["worldbank"] + [e for e in engines_combo if e != "worldbank"]
382
- # 🔑 macro_data 域 + 中国宏观词 → nbs_stats(国家统计局)前置:
383
- # 本国宏观数据权威源,最新年份比 worldbank 全(worldbank 有 1-2 年
384
- # 数据滞后,「2025 年 GDP」类查询会空手)。与上方 worldbank 前置
385
- # 配合,中国查询最终位次 [nbs_stats, worldbank, ...]
386
- if (domain.get("name") == "macro_data"
387
- and "nbs_stats" in engines_combo
388
- and ("中国" in query or "china" in query.lower())):
389
- engines_combo = ["nbs_stats"] + [e for e in engines_combo if e != "nbs_stats"]
390
- # 🔑 为中文/学术查询追加本地引擎
391
- # modal_card 保持纯结构化路径:只走 bocha_ai → bocha,不混 web/geo 补充源
392
- _pure_combo = domain.get("name") == "modal_card"
373
+ engines_combo = apply_domain_combo_rules(
374
+ domain, engines_combo, query, enabled, _specs_snapshot())
375
+ _pure_combo = is_pure_combo_domain(domain)
393
376
  if not _pure_combo:
394
377
  engines_combo = _merge_language_engines(engines_combo, features, lang_engines)
395
378
  engines_combo = _lang_aware_combo_order(
396
379
  engines_combo, features, domain.get("name"), enabled, query)
397
380
  if not engines_combo:
398
381
  if _pure_combo:
399
- # 密钥缺失时 env_ready 会踢 combo;仍保留域声明引擎,
400
- # 执行层返回 error item,避免静默改走 anysearch 污染结构化语义
401
- declared = list(domain.get("engines_combo") or [])
402
- if not declared and domain.get("primary"):
403
- declared = [domain["primary"]]
404
- try:
405
- from engine_env import is_engine_allowed_by_env
406
- engines_combo = [
407
- e for e in declared if is_engine_allowed_by_env(e)
408
- ] or declared
409
- except ImportError:
410
- engines_combo = declared
382
+ engines_combo = resolve_pure_combo_fallback(domain)
411
383
  if not engines_combo:
412
384
  # 域内引擎全被过滤,回退(本地优先 + 通用免费源唯一来源)
413
385
  engines_combo = _general_fallback(
@@ -482,32 +454,8 @@ def _route_by_domain(ctx: _RouteCtx, domain: dict[str, Any], secondary: list[dic
482
454
  # 注意:本分支的 must_keep 组装**不能**并成一次调用——geo 项与 lang 项
483
455
  # 之间夹着垂直域主源保护,而 policy 是按 must_keep 的**顺序**补位的
484
456
  # (见 _apply_engine_policy 的 `for e in must_keep`),合并会改变 combo 次序。
485
- must_keep = []
486
- if features.get("has_geo") and "local_openstreetmap" in enabled and not _pure_combo:
487
- must_keep.append("local_openstreetmap")
488
- # 垂直域主源保护(名单见模块级 _VERTICAL_KEEP):这些域的专属源在
489
- # combo 里不是「通用源」,被 budget 截断后该域等于没源可用(实测
490
- # medical 的 who_don、japan_law 的 egov_law 均因 budget=2 被裁掉
491
- # → 路由命中但零结果)。
492
- if domain.get("name") in _VERTICAL_KEEP:
493
- p = domain.get("primary")
494
- # modal_card 可在缺 key(不在 enabled)时仍 must_keep,避免 budget 再裁
495
- # primary 受死源地板约束(engine_is_dead,与 GEC 同口径):
496
- # 死源进 must_keep 会被策略层强制补回 combo,撤销 GEC 地板过滤
497
- if p and p not in must_keep and (p in enabled or _pure_combo) \
498
- and not engine_is_dead(p):
499
- must_keep.append(p)
500
- # modal_card 整 combo 保底(bocha_ai 无配额时 bocha 必须在位)
501
- if domain.get("name") == "modal_card":
502
- for e in domain.get("engines_combo") or []:
503
- if e not in must_keep and (e in enabled or _pure_combo):
504
- must_keep.append(e)
505
- elif (p and p in enabled and p not in must_keep
506
- and not engine_is_dead(p)):
507
- must_keep.append(p)
508
- if domain.get("name") == "geo_places" and "local_openstreetmap" in enabled:
509
- if "local_openstreetmap" not in must_keep:
510
- must_keep.append("local_openstreetmap")
457
+ must_keep = build_domain_must_keep(
458
+ domain, features, enabled, _pure_combo, engine_is_dead)
511
459
 
512
460
  if not _pure_combo:
513
461
  must_keep.extend(_lang_must_keep(features, enabled, engines_combo, query))
@@ -554,7 +502,7 @@ def _route_by_domain(ctx: _RouteCtx, domain: dict[str, Any], secondary: list[dic
554
502
  try:
555
503
  from circuit_breaker import get_breaker
556
504
  st = get_breaker().status(p)
557
- if (st.get("state") == engine_states.BREAKER_OPEN and int(st.get("cooldown_remain") or 0) > 0):
505
+ if st.get("state") == engine_states.BREAKER_DISABLED or int(st.get("cooldown_remain") or 0) > 0:
558
506
  p = None
559
507
  except Exception as _exc: # 侧信道:熔断状态只影响 primary 扶正提示(规则见 except_sets)
560
508
  import logging
@@ -563,6 +511,18 @@ def _route_by_domain(ctx: _RouteCtx, domain: dict[str, Any], secondary: list[dic
563
511
  if p and p in engines_combo:
564
512
  engines_combo = [p] + [e for e in engines_combo if e != p]
565
513
 
514
+ # 平台原生主源(2026-11-15):X/推特/reddit 语境查询的主位应是平台原生
515
+ # 通道而非同域通用社区源——「推特上大家对 GPT 的评价」主位给 zhihu 等于
516
+ # 没接平台(实测公开版还把这类查询劫持到 academic/arXiv,@social_context
517
+ # 守卫已救回 social,这里是最后一步:原生源扶正/注入主位)。原生源未
518
+ # 启用或熔断时保持原序;注入时顶掉末位成员,预算窗口内保住原生主位。
519
+ _native = platform_native_engine(query) if domain.get("name") == "social" else None
520
+ if _native and _native in enabled and engines_combo \
521
+ and _native != engines_combo[0]:
522
+ _pre_len = len(engines_combo)
523
+ engines_combo = [_native] + [e for e in engines_combo if e != _native]
524
+ engines_combo = engines_combo[:max(_pre_len, 1)]
525
+
566
526
  # 强语义注入(v2.7.10):判据与「为什么放在 primary 扶正之后」见
567
527
  # route_combo.inject_strong_semantic 的 docstring。
568
528
  engines_combo, _strong = inject_strong_semantic(
@@ -830,15 +790,16 @@ def route_query(query: str, engine_override: str = "auto",
830
790
  # → 熔断器空键 ''),MCP/外部调用可能传入空 engine 参数
831
791
  # 显式引擎也补 domain 判定:让缓存 TTL 按真实域分域(财经 5min /
832
792
  # 新闻 10min / 学术 2h),usage_log 统计不再全糊成 general。
833
- _domain = None
834
- _hits = match_domains(query, max_n=1)
835
- if _hits:
836
- _domain = _hits[0].get("name")
793
+ _feats = extract_features(query)
794
+ if lang_override:
795
+ _feats = apply_lang_override(_feats, lang_override)
796
+ _hits = match_domains(query, max_n=1, intents=_feats.get("intents"))
797
+ _domain = _hits[0].get("name") if _hits else None
837
798
  return _done(
838
799
  engine=engines[0], engines=engines,
839
800
  engines_combo=engines,
840
801
  reason=f"用户指定: {', '.join(engines)}", confidence=1.0,
841
- features={}, domain=_domain, parallel=False, mode=mode,
802
+ features=_feats, domain=_domain, parallel=False, mode=mode,
842
803
  depth=depth, context=context,
843
804
  login_hint=_detect_login_intent(query, None),
844
805
  )
@@ -871,7 +832,8 @@ def route_query(query: str, engine_override: str = "auto",
871
832
  # (见 route_domains 模块 docstring):域精度的全部规则只有那一个实现,
872
833
  # 这里不再各调一次,避免「某个守卫忘了在另一条路径上施加」。
873
834
  _domain_hits = match_domains(query, domains_cfg,
874
- primary_lang=features.get("primary_lang"))
835
+ primary_lang=features.get("primary_lang"),
836
+ intents=features.get("intents"))
875
837
  domain = _domain_hits[0] if _domain_hits else None
876
838
  secondary = _domain_hits[1:] if len(_domain_hits) > 1 else []
877
839
  hard_domain = bool(domain and domain.get("patterns"))
@@ -971,6 +933,14 @@ def route_query_cached(query: str, engine_override: str = "auto",
971
933
  decision["route_cached"] = True
972
934
  # 用真实耗时覆盖存档值:这个字段会经 plan 输出给用户,报旧值就是撒谎
973
935
  decision["elapsed_ms"] = round((time.time() - t0) * 1000, 2)
936
+ # 采样旁路必须覆盖命中路径。此前只在 route_query._done 里采样,命中
937
+ # 直接 return 不经过它——于是「同一查询第二次起」全都不留路由记录。
938
+ # 生产日志实测:route.jsonl 停在 2026-11-11,此后 5 天零条,而 query
939
+ # 流同期 700+ 条;source_audit 的 route_hits 因此恒为 0,把 163 个源
940
+ # 判成「0 次路由命中,建议停用」,其中 69 个在 query 流里有真实调用。
941
+ # 采样率语义不变(仍受 ARGO_ROUTE_SAMPLE_RATE 控制),只是把「算过的
942
+ # 决策」从「未命中才算」改成「命中与未命中都算」。
943
+ sample_route(decision, decision)
974
944
  return decision
975
945
 
976
946
  decision = route_query(query, engine_override=engine_override, mode=mode,