argo-search 2.14.1 → 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 +54 -832
- package/README.ja.md +53 -833
- package/README.ko.md +53 -831
- package/README.md +126 -769
- package/README.zh.md +124 -893
- 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 +42 -0
- package/backends/engine_concept_vectors.json +1525 -1525
- package/backends/engine_registry.yaml +124 -28
- package/backends/quota_profiles.json +70 -0
- package/bin/argo +30 -17
- package/config.yaml +173 -33
- package/docs/ADDING_NEW_ENGINE.md +10 -0
- package/docs/ARGO_INTRO.md +1 -1
- package/docs/CHANGELOG.md +23 -0
- package/docs/ENGINE_CATALOG.md +97 -85
- package/docs/MCP_SETUP.md +1 -1
- package/docs/RELEASE_NOTES_v2.14.1.md +4 -4
- package/docs/RELEASE_NOTES_v2.15.0.md +50 -0
- package/docs/RELEASING.md +1 -1
- package/engines/specs/ai_labs.yaml +89 -0
- 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/cn_ai_news.yaml +10 -8
- package/engines/specs/digup.yaml +11 -6
- package/engines/specs/douyin_hot.yaml +11 -1
- package/engines/specs/dw_news.yaml +4 -2
- package/engines/specs/eng_blogs.yaml +63 -0
- package/engines/specs/europeana.yaml +3 -4
- package/engines/specs/felo.yaml +3 -3
- 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/itotii.yaml +13 -1
- package/engines/specs/lobsters.yaml +41 -0
- package/engines/specs/local_seek.yaml +6 -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/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/twitter.yaml +4 -0
- package/engines/specs/unpaywall.yaml +6 -0
- 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 +3 -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/runner.js +2 -0
- 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 +108 -9
- package/scripts/build_concept_table.py +112 -55
- 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 +23 -9
- 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 +3 -50
- package/scripts/engine_validate.py +13 -45
- package/scripts/engines.py +15 -31
- package/scripts/engines_base.py +42 -58
- package/scripts/engines_builders.py +0 -15
- package/scripts/engines_builders_batch10.py +346 -100
- package/scripts/engines_builders_batch11.py +2 -75
- package/scripts/engines_builders_batch9.py +15 -24
- package/scripts/engines_builders_cn.py +0 -194
- package/scripts/engines_builders_feeds.py +55 -5
- package/scripts/engines_builders_intl.py +15 -115
- package/scripts/engines_builders_pixiv.py +2 -16
- package/scripts/engines_builders_search.py +7 -14
- package/scripts/engines_builders_tech.py +5 -14
- 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 +13 -369
- package/scripts/engines_schema_drift.py +260 -0
- package/scripts/evidence.py +13 -0
- package/scripts/evidence_loop.py +4 -3
- 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 +2 -2
- package/scripts/general_pool.py +15 -4
- package/scripts/health_check.py +1 -1
- package/scripts/link_source.py +65 -24
- package/scripts/local_seek_adapter.py +57 -17
- package/scripts/mcp_handlers.py +53 -31
- package/scripts/mcp_handlers_surface.py +6 -18
- package/scripts/mcp_transport.py +1 -1
- package/scripts/min_version_scan.py +7 -3
- package/scripts/network_aware.py +7 -13
- package/scripts/pre-commit +45 -43
- 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 +14 -26
- package/scripts/release_check.py +5 -25
- 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 +85 -6
- 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_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/semantic_evidence.py +375 -168
- package/scripts/settings_page.py +3 -3
- 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 +2 -2
- 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 +17 -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 +58 -3
- package/scripts/caliber_dedupe.py +0 -66
- package/scripts/engines_builders_batch16.py +0 -13
- package/scripts/health_probe.py +0 -253
- package/scripts/social_engines/twitter_engine.py +0 -514
- package/scripts/sync_installs.py +0 -29
package/scripts/release.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
## 为什么要它
|
|
5
5
|
|
|
6
|
-
版本号散在
|
|
6
|
+
版本号散在 8 处机器声明、五语 README 的徽标 / 散文 / 发布表,外加发布说明
|
|
7
7
|
与 npm files 白名单。v2.10.0 发版时手改了 26 个文件,v2.9.8 更漏过 README
|
|
8
8
|
「最近更新」条目——漏改往往等 npm 包发出去才发现。release_check.py 只能事后
|
|
9
9
|
报错,本脚本把「改」和「发」也收成确定性步骤。
|
|
@@ -69,8 +69,8 @@ def parse_version(v: str) -> tuple[int, int, int]:
|
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
# ── 改号规则 ────────────────────────────────────────────────────────────────
|
|
72
|
-
# 2026-11-09 收口:机器声明(pyproject / package.json / server.json /
|
|
73
|
-
# __version__ / SKILL.md / mcp_transport
|
|
72
|
+
# 2026-11-09 收口:机器声明(pyproject / package.json / server.json /
|
|
73
|
+
# __version__ / SKILL.md / mcp_transport)此前在 rules() 里手写一份
|
|
74
74
|
# 路径清单,release_check 另写一份 JSON_DECLS / SRC_DECLS,两份清单靠
|
|
75
75
|
# check_rule_parity() 机械对账。a5cc97b 把 panel_server.mjs 改成运行时读版本后,
|
|
76
76
|
# 源码常量删了、改号清单那行没删,bump 在第一步就中止(三连红)。
|
|
@@ -91,32 +91,20 @@ def rules(old: str, new: str) -> list[tuple[str, str, str, int]]:
|
|
|
91
91
|
("README.ja.md", f"badge/version-{o}-", f"badge/version-{n}-", 1),
|
|
92
92
|
("README.ko.md", f"badge/version-{o}-", f"badge/version-{n}-", 1),
|
|
93
93
|
("README.es.md", f"badge/version-{o}-", f"badge/version-{n}-", 1),
|
|
94
|
-
#
|
|
95
|
-
("README.
|
|
96
|
-
|
|
97
|
-
("README.
|
|
98
|
-
|
|
99
|
-
("README.md", f"
|
|
100
|
-
f"
|
|
101
|
-
("README.md", f"**npm install is supported, current version {o}**",
|
|
102
|
-
f"**npm install is supported, current version {n}**", 1),
|
|
103
|
-
("README.ja.md", f"現在 {o}。tag ごとに公開", f"現在 {n}。tag ごとに公開", 1),
|
|
104
|
-
("README.ja.md", f"**npm インストールに対応済みで、最新版は {o}**",
|
|
105
|
-
f"**npm インストールに対応済みで、最新版は {n}**", 1),
|
|
106
|
-
("README.ko.md", f"현재 {o}, tag마다 배포", f"현재 {n}, tag마다 배포", 1),
|
|
107
|
-
("README.ko.md", f"**npm 설치를 지원하며 최신 버전은 {o}**",
|
|
108
|
-
f"**npm 설치를 지원하며 최신 버전은 {n}**", 1),
|
|
109
|
-
("README.es.md", f"versión actual {o}; se publica por tag",
|
|
110
|
-
f"versión actual {n}; se publica por tag", 1),
|
|
111
|
-
("README.es.md", f"**La instalación por npm está soportada y la versión actual es {o}**",
|
|
112
|
-
f"**La instalación por npm está soportada y la versión actual es {n}**", 1),
|
|
94
|
+
# 五语折叠摘要标题
|
|
95
|
+
("README.md", f"<summary>v{o}", f"<summary>v{n}", 1),
|
|
96
|
+
("README.zh.md", f"<summary>v{o}", f"<summary>v{n}", 1),
|
|
97
|
+
("README.ja.md", f"<summary>v{o}", f"<summary>v{n}", 1),
|
|
98
|
+
("README.ko.md", f"<summary>v{o}", f"<summary>v{n}", 1),
|
|
99
|
+
("README.es.md", f"Resumen de la versión v{o}</summary>",
|
|
100
|
+
f"Resumen de la versión v{n}</summary>", 1),
|
|
113
101
|
# 五语「当前大致能力」标题
|
|
114
102
|
("README.zh.md", f"### 当前大致能力(v{o})", f"### 当前大致能力(v{n})", 1),
|
|
115
|
-
("README.md", f"###
|
|
103
|
+
("README.md", f"### Capabilities (v{o})", f"### Capabilities (v{n})", 1),
|
|
116
104
|
("README.ja.md", f"### 現時点の能力概要(v{o})", f"### 現時点の能力概要(v{n})", 1),
|
|
117
|
-
("README.ko.md", f"###
|
|
118
|
-
("README.es.md", f"###
|
|
119
|
-
f"###
|
|
105
|
+
("README.ko.md", f"### 현재 기능 개요 (v{o})", f"### 현재 기능 개요 (v{n})", 1),
|
|
106
|
+
("README.es.md", f"### Capacidades actuales (v{o})",
|
|
107
|
+
f"### Capacidades actuales (v{n})", 1),
|
|
120
108
|
]
|
|
121
109
|
|
|
122
110
|
|
package/scripts/release_check.py
CHANGED
|
@@ -13,7 +13,7 @@ MCP Registry 清单 / ZCode 插件清单 / argo_search.__version__ / SKILL.md
|
|
|
13
13
|
|
|
14
14
|
## 检什么(全部是结构化事实,不做散文匹配)
|
|
15
15
|
|
|
16
|
-
1.
|
|
16
|
+
1. 八处机器声明与 pyproject.toml 的 version 完全一致;
|
|
17
17
|
2. 五语 README 的徽标 `badge/version-<v>-` 与发布表行 `| **v<v>** |` 都在;
|
|
18
18
|
3. `docs/RELEASE_NOTES_v<v>.md` 存在;
|
|
19
19
|
4. package.json 的 files 白名单包含当前发布说明,且**盘上每份**发布说明都在
|
|
@@ -38,20 +38,18 @@ import re
|
|
|
38
38
|
import sys
|
|
39
39
|
from pathlib import Path
|
|
40
40
|
|
|
41
|
-
#
|
|
41
|
+
# 八处机器声明的相对路径(顺序即报错输出顺序;2026-11-13 ZCode 插件随
|
|
42
|
+
# packages/argo-zcode 剥离,插件清单/面板 UI/插件市场三处声明同步退出)
|
|
42
43
|
JSON_DECLS = (
|
|
43
44
|
"package.json",
|
|
44
45
|
"packages/dsh-plugin/package.json",
|
|
45
46
|
"server.json",
|
|
46
|
-
"packages/argo-zcode/.zcode-plugin/plugin.json",
|
|
47
47
|
)
|
|
48
48
|
README_LANGS = ("README.md", "README.zh.md", "README.ja.md", "README.ko.md", "README.es.md")
|
|
49
49
|
|
|
50
50
|
# 源码里的版本常量(正则取,避免 import 副作用;panel_server.mjs 已改为运行时读 plugin.json)
|
|
51
51
|
SRC_DECLS = (
|
|
52
52
|
("scripts/mcp_transport.py", r'ARGO_MCP_VERSION\s*=\s*"([^"]+)"'),
|
|
53
|
-
("packages/argo-zcode/ui/panel.html",
|
|
54
|
-
r'new App\(\{\s*name:\s*"argo-panel",\s*version:\s*"([^"]+)"'),
|
|
55
53
|
)
|
|
56
54
|
|
|
57
55
|
# 机器声明规格:每条 (相对路径, 提取正则, 期望出现次数)。
|
|
@@ -62,13 +60,8 @@ MACHINE_DECL_SPECS: tuple[tuple[str, str, int], ...] = (
|
|
|
62
60
|
("pyproject.toml", r'(?m)^version\s*=\s*"([^"]+)"', 1),
|
|
63
61
|
("package.json", r'"version":\s*"([^"]+)"', 1),
|
|
64
62
|
("packages/dsh-plugin/package.json", r'"version":\s*"([^"]+)"', 1),
|
|
65
|
-
("packages/marketplace.json", r'"version":\s*"([^"]+)"', 1),
|
|
66
63
|
("server.json", r'"version":\s*"([^"]+)"', 2),
|
|
67
|
-
("packages/argo-zcode/.zcode-plugin/plugin.json",
|
|
68
|
-
r'"version":\s*"([^"]+)"', 1),
|
|
69
64
|
("scripts/mcp_transport.py", r'ARGO_MCP_VERSION\s*=\s*"([^"]+)"', 1),
|
|
70
|
-
("packages/argo-zcode/ui/panel.html",
|
|
71
|
-
r'new App\(\{\s*name:\s*"argo-panel",\s*version:\s*"([^"]+)"', 1),
|
|
72
65
|
("argo_search/__init__.py", r'__version__\s*=\s*"([^"]+)"', 1),
|
|
73
66
|
("SKILL.md", r'(?m)^version:\s*(\S+)', 1),
|
|
74
67
|
)
|
|
@@ -118,20 +111,7 @@ def check(root: Path) -> list[str]:
|
|
|
118
111
|
if got != ver:
|
|
119
112
|
problems.append(f"{rel}: {got} ≠ pyproject {ver}")
|
|
120
113
|
|
|
121
|
-
# 2)
|
|
122
|
-
text = _safe_read(root, "packages/marketplace.json", problems)
|
|
123
|
-
if text is not None:
|
|
124
|
-
try:
|
|
125
|
-
market = json.loads(text)
|
|
126
|
-
for plugin in market.get("plugins") or []:
|
|
127
|
-
got = str(plugin.get("version") or "")
|
|
128
|
-
if got != ver:
|
|
129
|
-
problems.append(
|
|
130
|
-
f"packages/marketplace.json[{plugin.get('name')}]: {got} ≠ {ver}")
|
|
131
|
-
except (OSError, ValueError) as e:
|
|
132
|
-
problems.append(f"packages/marketplace.json: 读取失败({e})")
|
|
133
|
-
|
|
134
|
-
# 2b) MCP Registry 清单(packages[] 每条的版本也要对上)
|
|
114
|
+
# 2) MCP Registry 清单(packages[] 每条的版本也要对上)
|
|
135
115
|
text = _safe_read(root, "server.json", problems)
|
|
136
116
|
if text is not None:
|
|
137
117
|
try:
|
|
@@ -218,7 +198,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
218
198
|
for p in problems:
|
|
219
199
|
print(f" !! {p}", file=sys.stderr)
|
|
220
200
|
return 1
|
|
221
|
-
print(f"release_check: v{ver} 一致(
|
|
201
|
+
print(f"release_check: v{ver} 一致(8 处机器声明 + 五语 README + 发布说明与白名单)")
|
|
222
202
|
return 0
|
|
223
203
|
|
|
224
204
|
|
package/scripts/replay_eval.py
CHANGED
|
@@ -467,7 +467,7 @@ def check_limits(report: dict, doc: dict) -> list[str]:
|
|
|
467
467
|
|
|
468
468
|
def save_baseline(report: dict, path: Path) -> None:
|
|
469
469
|
path.write_text(dumps_pretty({
|
|
470
|
-
"_meta": {"saved_at": datetime.now().isoformat(timespec="seconds"),
|
|
470
|
+
"_meta": {"saved_at": datetime.now().astimezone().isoformat(timespec="seconds"),
|
|
471
471
|
"note": "对照基准:--compare 用它算差异"},
|
|
472
472
|
"report": report,
|
|
473
473
|
}), encoding="utf-8")
|
|
@@ -567,7 +567,7 @@ def _cmd_record(args) -> int:
|
|
|
567
567
|
return 1
|
|
568
568
|
doc = {
|
|
569
569
|
"_meta": {
|
|
570
|
-
"recorded_at": datetime.now().isoformat(timespec="seconds"),
|
|
570
|
+
"recorded_at": datetime.now().astimezone().isoformat(timespec="seconds"),
|
|
571
571
|
"note": "真实引擎返回的录制数据。改动之后如果确定变好,"
|
|
572
572
|
"请更新各条的下限并在这里记一笔。",
|
|
573
573
|
"usage": "录下来的引擎返回只属于录制那一天。重跑保证的是"
|
package/scripts/research_cli.py
CHANGED
|
@@ -61,6 +61,11 @@ def main() -> None:
|
|
|
61
61
|
parser.add_argument("--archive-dir", type=str, default=None)
|
|
62
62
|
parser.add_argument("--archive-tag", default=None)
|
|
63
63
|
parser.add_argument("--archive-note", default=None)
|
|
64
|
+
parser.add_argument(
|
|
65
|
+
"--auto-note",
|
|
66
|
+
action="store_true",
|
|
67
|
+
help="研究完成后自动生成研究笔记骨架并入库索引(打通 argo note)",
|
|
68
|
+
)
|
|
64
69
|
parser.add_argument(
|
|
65
70
|
"--verify", nargs="?", const=3, type=int, default=None, metavar="TOP_K",
|
|
66
71
|
)
|
|
@@ -78,6 +83,11 @@ def main() -> None:
|
|
|
78
83
|
)
|
|
79
84
|
parser.add_argument("--archive-since", default=None, help="归档检索起始日期")
|
|
80
85
|
parser.add_argument("--archive-until", default=None, help="归档检索截止日期")
|
|
86
|
+
parser.add_argument(
|
|
87
|
+
"--include-notes", action="store_true",
|
|
88
|
+
help="归档检索时并入研究笔记索引(research-index.jsonl),"
|
|
89
|
+
"让上次得到的结论也能被搜到",
|
|
90
|
+
)
|
|
81
91
|
args = parser.parse_args()
|
|
82
92
|
do_archive = not args.no_archive
|
|
83
93
|
|
|
@@ -87,6 +97,7 @@ def main() -> None:
|
|
|
87
97
|
hits = search_archive(
|
|
88
98
|
args.search_archive,
|
|
89
99
|
since=args.archive_since, until=args.archive_until,
|
|
100
|
+
include_notes=args.include_notes,
|
|
90
101
|
)
|
|
91
102
|
except Exception as e:
|
|
92
103
|
print(f"[search-archive] {type(e).__name__}: {e}")
|
|
@@ -342,6 +353,35 @@ def main() -> None:
|
|
|
342
353
|
report["archive"] = meta
|
|
343
354
|
if not args.json:
|
|
344
355
|
print(f" [archive] {meta.get('run_id')} → {meta.get('run_dir')}", file=sys.stderr)
|
|
356
|
+
|
|
357
|
+
if args.auto_note:
|
|
358
|
+
try:
|
|
359
|
+
from research_notes import (
|
|
360
|
+
create_explore_bundle,
|
|
361
|
+
resolve_root as resolve_note_root,
|
|
362
|
+
slugify,
|
|
363
|
+
)
|
|
364
|
+
n_root = resolve_note_root(args.archive_dir)
|
|
365
|
+
run_ref = f"run:{meta.get('run_id')}" if meta else "无"
|
|
366
|
+
# 与 `argo note explore` 共用同一个单文件落盘函数(内嵌 Frontmatter 与索引)。
|
|
367
|
+
note_topic = (args.topic or args.query or "").strip() or "research"
|
|
368
|
+
bundle = create_explore_bundle(
|
|
369
|
+
root=n_root,
|
|
370
|
+
slug=slugify(note_topic),
|
|
371
|
+
title=note_topic,
|
|
372
|
+
problem=args.query or note_topic,
|
|
373
|
+
related=run_ref,
|
|
374
|
+
)
|
|
375
|
+
report["note"] = {
|
|
376
|
+
"note": bundle["note"],
|
|
377
|
+
"index": bundle["index"],
|
|
378
|
+
}
|
|
379
|
+
if not args.json:
|
|
380
|
+
print(f" [note] {bundle['note']}", file=sys.stderr)
|
|
381
|
+
except Exception as ne:
|
|
382
|
+
msg = f"{type(ne).__name__}: {ne}"
|
|
383
|
+
report.setdefault("errors", []).append(f"auto-note: {msg}")
|
|
384
|
+
print(f" [note error] {msg}", file=sys.stderr)
|
|
345
385
|
except Exception as e:
|
|
346
386
|
print(f" [archive error] {type(e).__name__}: {e}", file=sys.stderr)
|
|
347
387
|
|
|
@@ -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())
|