argo-search 2.14.0 → 2.15.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.
- package/AGENTS.md +8 -6
- package/README.es.md +56 -824
- package/README.ja.md +55 -825
- package/README.ko.md +55 -823
- package/README.md +128 -868
- package/README.zh.md +206 -0
- package/SKILL.md +17 -18
- package/assets/readme/counts.json +1 -1
- package/assets/readme/hero.svg +23 -23
- package/backends/concept_vectors.bin +0 -0
- package/backends/domain_profiles.json +66 -0
- package/backends/engine_concept_vectors.json +1525 -1525
- package/backends/engine_registry.yaml +193 -46
- package/backends/quota_profiles.json +110 -0
- package/bin/argo +30 -17
- package/config.yaml +196 -36
- package/docs/ADDING_NEW_ENGINE.md +10 -0
- package/docs/ARGO_INTRO.md +1 -1
- package/docs/CHANGELOG.md +45 -0
- package/docs/ENGINE_CATALOG.md +128 -112
- package/docs/MCP_SETUP.md +2 -2
- package/docs/RELEASE_NOTES_v2.14.0.md +12 -1
- package/docs/RELEASE_NOTES_v2.14.1.md +80 -0
- package/docs/RELEASE_NOTES_v2.15.0.md +50 -0
- package/docs/RELEASING.md +53 -1
- package/engines/specs/ai_labs.yaml +89 -0
- package/engines/specs/artic.yaml +11 -1
- package/engines/specs/bilibili_hot.yaml +11 -1
- package/engines/specs/brave.yaml +3 -3
- package/engines/specs/cisa_alerts.yaml +40 -0
- package/engines/specs/cleveland.yaml +15 -1
- package/engines/specs/clinicaltrials.yaml +16 -1
- package/engines/specs/cn_ai_news.yaml +10 -8
- package/engines/specs/cnii.yaml +15 -4
- package/engines/specs/deezer.yaml +12 -1
- package/engines/specs/digup.yaml +11 -6
- package/engines/specs/doaj.yaml +14 -1
- package/engines/specs/douyin_hot.yaml +11 -1
- package/engines/specs/dw_news.yaml +4 -2
- package/engines/specs/endoflife.yaml +16 -1
- package/engines/specs/eng_blogs.yaml +63 -0
- package/engines/specs/eu_opendata.yaml +11 -1
- package/engines/specs/europeana.yaml +22 -5
- package/engines/specs/feed.yaml +62 -0
- package/engines/specs/felo.yaml +3 -3
- package/engines/specs/figshare.yaml +12 -1
- package/engines/specs/firecrawl.yaml +3 -0
- package/engines/specs/fourget.yaml +5 -2
- package/engines/specs/france24.yaml +6 -4
- package/engines/specs/fxtwitter.yaml +29 -6
- package/engines/specs/grepapp_mcp.yaml +62 -0
- package/engines/specs/guardian_rss.yaml +6 -4
- package/engines/specs/hackernews.yaml +17 -2
- package/engines/specs/hal.yaml +19 -1
- package/engines/specs/hf_datasets.yaml +59 -0
- package/engines/specs/hf_papers.yaml +17 -1
- package/engines/specs/itotii.yaml +13 -1
- package/engines/specs/jikan.yaml +12 -10
- package/engines/specs/kaggle.yaml +5 -3
- package/engines/specs/lobsters.yaml +41 -0
- package/engines/specs/local_seek.yaml +6 -0
- package/engines/specs/maven.yaml +61 -0
- package/engines/specs/nasa_cmr.yaml +12 -1
- package/engines/specs/nuget.yaml +57 -0
- package/engines/specs/open_meteo.yaml +1 -1
- package/engines/specs/redskill.yaml +2 -0
- package/engines/specs/searxng.yaml +4 -2
- package/engines/specs/sec_edgar.yaml +8 -3
- package/engines/specs/tatoeba.yaml +14 -1
- package/engines/specs/tinyfish.yaml +2 -0
- package/engines/specs/tinyfish_news.yaml +2 -0
- package/engines/specs/tinyfish_paper.yaml +2 -0
- package/engines/specs/toutiao_hot.yaml +11 -1
- package/engines/specs/train.yaml +3 -0
- package/engines/specs/tvmaze.yaml +5 -1
- package/engines/specs/twitter.yaml +4 -0
- package/engines/specs/unpaywall.yaml +6 -0
- package/engines/specs/usda.yaml +14 -1
- package/engines/specs/vam.yaml +17 -3
- package/engines/specs/weibo_hot.yaml +11 -1
- package/engines/specs/wolframalpha.yaml +3 -3
- package/engines/specs/xiaohongshu.yaml +2 -0
- package/engines/specs/zhihu.yaml +3 -18
- package/engines/specs/zhihu_kb.yaml +18 -0
- package/engines/specs/zhihu_questions.yaml +19 -0
- package/package.json +4 -2
- package/packages/dsh-plugin/README.md +9 -14
- package/packages/dsh-plugin/dsh/client.js +467 -1024
- package/packages/dsh-plugin/dsh/diagnostics.js +71 -20
- package/packages/dsh-plugin/dsh/native-tools.mjs +61 -113
- package/packages/dsh-plugin/dsh/runner.js +2 -0
- package/packages/dsh-plugin/dsh/wide-research.js +1 -1
- package/packages/dsh-plugin/package.json +8 -3
- package/packages/dsh-plugin/scripts/sync-local.mjs +87 -0
- package/packages/dsh-plugin/scripts/sync-local.sh +13 -1
- package/packages/dsh-plugin/test/diagnostics.test.js +38 -1
- package/packages/dsh-plugin/test/size-gate.test.js +2 -9
- package/scripts/adaptive.py +7 -1
- package/scripts/archive_run.py +112 -53
- package/scripts/argo_paths.py +40 -3
- package/scripts/badcase_ledger.py +153 -10
- package/scripts/build_concept_table.py +112 -55
- package/scripts/build_release_assets.sh +43 -15
- package/scripts/cache.py +5 -1
- package/scripts/caliber_isolation.py +60 -23
- package/scripts/circuit_breaker.py +56 -8
- package/scripts/cli_io.py +20 -2
- package/scripts/config_cache.py +31 -0
- package/scripts/daemon.py +146 -51
- package/scripts/dormant_ledger.py +239 -0
- package/scripts/engine_dispatch.py +3 -3
- package/scripts/engine_env.py +182 -1
- package/scripts/engine_families.py +50 -7
- package/scripts/engine_states.py +9 -51
- package/scripts/engine_validate.py +150 -6
- package/scripts/engines.py +15 -67
- package/scripts/engines_base.py +68 -124
- package/scripts/engines_builders.py +0 -51
- package/scripts/engines_builders_batch10.py +346 -100
- package/scripts/engines_builders_batch11.py +2 -75
- package/scripts/engines_builders_batch9.py +15 -228
- package/scripts/engines_builders_cn.py +0 -194
- package/scripts/engines_builders_feeds.py +203 -35
- package/scripts/engines_builders_intl.py +15 -443
- package/scripts/engines_builders_pixiv.py +2 -16
- package/scripts/engines_builders_science.py +0 -85
- package/scripts/engines_builders_search.py +7 -14
- package/scripts/engines_builders_tech.py +5 -112
- package/scripts/engines_builders_weather.py +236 -0
- package/scripts/engines_fields.py +91 -0
- package/scripts/engines_http.py +135 -0
- package/scripts/engines_mcp.py +383 -0
- package/scripts/engines_parsers.py +196 -27
- package/scripts/engines_schema_drift.py +260 -0
- package/scripts/evidence.py +13 -0
- package/scripts/evidence_loop.py +93 -5
- package/scripts/fetch_jsrun.py +15 -11
- package/scripts/fetch_v3.py +28 -28
- package/scripts/fulltext_store.py +42 -1
- package/scripts/fxtwitter_api.py +8 -7
- package/scripts/gen_engine_catalog.py +4 -4
- package/scripts/gen_native_tools.py +2 -1
- package/scripts/general_pool.py +15 -4
- package/scripts/health_check.py +1 -1
- package/scripts/link_source.py +65 -24
- package/scripts/local_intent.py +51 -15
- package/scripts/local_seek.py +37 -4
- package/scripts/local_seek_adapter.py +57 -17
- package/scripts/mcp_handlers.py +173 -99
- package/scripts/mcp_handlers_surface.py +6 -18
- package/scripts/mcp_server.py +1 -1
- package/scripts/mcp_tools.py +143 -61
- package/scripts/mcp_transport.py +42 -10
- package/scripts/min_version_scan.py +7 -3
- package/scripts/network_aware.py +7 -13
- package/scripts/pre-commit +57 -31
- package/scripts/query_understanding.py +30 -6
- package/scripts/quota.py +6 -1
- package/scripts/rank_signals.py +9 -0
- package/scripts/recompute.py +15 -5
- package/scripts/recovery.py +21 -15
- package/scripts/release.py +29 -32
- package/scripts/release_check.py +6 -26
- package/scripts/replay_eval.py +2 -2
- package/scripts/research_cli.py +40 -0
- package/scripts/research_notes.py +368 -0
- package/scripts/route.py +32 -70
- package/scripts/route_audit.py +259 -0
- package/scripts/route_combo.py +10 -4
- package/scripts/route_domains.py +150 -23
- package/scripts/route_lang.py +20 -7
- package/scripts/route_log.py +26 -9
- package/scripts/route_policy.py +91 -7
- package/scripts/route_telemetry_export.py +199 -0
- package/scripts/rrf_classic.py +5 -22
- package/scripts/search.py +2 -1
- package/scripts/search_attribution.py +33 -10
- package/scripts/search_cli.py +44 -7
- package/scripts/search_entry.py +5 -1
- package/scripts/search_output.py +5 -4
- package/scripts/search_pipeline.py +12 -0
- package/scripts/search_rank.py +21 -11
- package/scripts/secret_guard.py +106 -0
- package/scripts/semantic_evidence.py +539 -117
- package/scripts/settings_page.py +83 -11
- package/scripts/social_engines/xiaohongshu_engine.py +2 -1
- package/scripts/social_engines/zhihu_engine.py +251 -43
- package/scripts/sogou_weixin_browser.py +5 -6
- package/scripts/source_audit.py +77 -0
- package/scripts/source_ledger.py +2 -15
- package/scripts/source_selection.py +45 -20
- package/scripts/straggler_policy.py +1 -2
- package/scripts/sync_backends.py +24 -0
- package/scripts/tfidf_router.py +23 -11
- package/scripts/time_utils.py +54 -1
- package/scripts/train.py +68 -2
- package/scripts/usage_log.py +26 -1
- package/sub-skills/argo-wide-research/SKILL.md +68 -0
- package/sub-skills/ego-search/SKILL.md +1 -1
- package/sub-skills/local-seek/scripts/seek_fts.py +67 -4
- package/README.en.md +0 -826
- package/scripts/caliber_dedupe.py +0 -66
- package/scripts/engines_builders_batch16.py +0 -186
- package/scripts/health_probe.py +0 -253
- package/scripts/image_vision/vision_probe +0 -0
- package/scripts/social_engines/twitter_engine.py +0 -514
- 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
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
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=
|
|
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"))
|