argo-search 2.16.0 → 2.17.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 +3 -1
- package/README.es.md +9 -4
- package/README.ja.md +9 -4
- package/README.ko.md +9 -4
- package/README.md +9 -4
- package/README.zh.md +9 -4
- package/SKILL.md +1 -1
- package/assets/readme/counts.json +1 -1
- package/assets/readme/hero.svg +3 -3
- package/assets/readme/hero.template.svg +121 -0
- package/assets/readme/proof-routes.svg +17 -16
- package/backends/domain_profiles.json +115 -18
- package/backends/engine_registry.yaml +11 -0
- package/backends/env_passthrough.txt +2 -0
- package/backends/quota_profiles.json +10 -0
- package/docs/CHANGELOG.md +17 -1
- package/docs/COMMIT_STANDARD.md +10 -0
- package/docs/ENGINE_CATALOG.md +32 -30
- package/docs/RELEASE_NOTES_v2.17.0.md +64 -0
- package/docs/RELEASING.md +1 -1
- package/engines/specs/crossref.yaml +2 -0
- package/engines/specs/hackernews.yaml +2 -0
- package/engines/specs/helve.yaml +49 -0
- package/engines/specs/hf_papers.yaml +2 -0
- package/engines/specs/openalex.yaml +9 -2
- package/package.json +2 -1
- package/packages/dsh-plugin/README.md +5 -2
- package/packages/dsh-plugin/cordis.patch.yml +4 -1
- package/packages/dsh-plugin/dsh/client.js +57 -63
- package/packages/dsh-plugin/dsh/diagnostics.js +25 -4
- package/packages/dsh-plugin/dsh/index.js +109 -21
- package/packages/dsh-plugin/dsh/route-guard.js +95 -0
- package/packages/dsh-plugin/dsh/runner.js +49 -6
- package/packages/dsh-plugin/dsh/wide-research.js +20 -18
- package/packages/dsh-plugin/dsh/workbench-client.js +119 -20
- package/packages/dsh-plugin/dsh/workbench-io.js +163 -0
- package/packages/dsh-plugin/dsh/workbench-search.js +385 -0
- package/packages/dsh-plugin/dsh/workbench-suggestions.js +387 -75
- package/packages/dsh-plugin/dsh/workbench.js +234 -497
- package/packages/dsh-plugin/package.json +4 -3
- package/packages/dsh-plugin/scripts/sync-local.mjs +4 -2
- package/packages/dsh-plugin/scripts/sync-local.sh +4 -2
- package/packages/dsh-plugin/test/client.test.js +26 -0
- package/packages/dsh-plugin/test/diagnostics.test.js +5 -2
- package/packages/dsh-plugin/test/index.test.js +150 -1
- package/packages/dsh-plugin/test/workbench-concurrency.test.js +98 -0
- package/packages/dsh-plugin/test/workbench.test.js +337 -9
- package/scripts/adaptive.py +13 -11
- package/scripts/browser_auth.py +178 -4
- package/scripts/cache.py +68 -69
- package/scripts/check_commit_report.py +46 -0
- package/scripts/chrome_cdp.py +71 -0
- package/scripts/circuit_breaker.py +77 -12
- package/scripts/config_cache.py +4 -3
- package/scripts/daemon.py +9 -2
- package/scripts/engine_add.py +45 -0
- package/scripts/engine_dispatch.py +27 -47
- package/scripts/engine_failure.py +33 -0
- package/scripts/engine_fingerprint.py +114 -0
- package/scripts/engine_health.py +130 -0
- package/scripts/engine_states.py +50 -0
- package/scripts/engines_base.py +7 -16
- package/scripts/engines_builders_search.py +19 -8
- package/scripts/engines_builders_tech.py +16 -16
- package/scripts/engines_fields.py +23 -0
- package/scripts/evidence_grounding.py +182 -0
- package/scripts/fetch_browser.py +25 -10
- package/scripts/gate_manifest_check.py +75 -0
- package/scripts/gen_readme_art.py +264 -0
- package/scripts/mcp_transport.py +24 -5
- package/scripts/numeric_verify.py +9 -0
- package/scripts/pre-commit +57 -8
- package/scripts/query_operators.py +229 -1
- package/scripts/quota.py +19 -37
- package/scripts/release.py +16 -1
- package/scripts/research_gates.py +85 -1
- package/scripts/route_combo.py +13 -1
- package/scripts/source_discovery.py +611 -0
- package/scripts/sync_backends.py +45 -0
- package/sub-skills/ego-search/README.md +9 -0
- package/sub-skills/ego-search/scripts/ego_search.py +182 -15
- package/sub-skills/ego-search/scripts/pacing.py +291 -0
- package/sub-skills/ego-search/scripts/quality.py +262 -6
- package/sub-skills/ego-search/scripts/runtime.py +7 -1
- package/sub-skills/ego-search/scripts/site_profiles.py +157 -0
- package/sub-skills/ego-search/scripts/webbridge_adapter.py +7 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""evidence_grounding.py — 确定性原文摘录锚定、防编造数字门禁与量级单位归一化。
|
|
3
|
+
|
|
4
|
+
纯确定性证据锚定与量级换算内核(零 LLM 依赖):
|
|
5
|
+
1. fold_digits:NFKC 折叠全半角数字与千分位分隔符;
|
|
6
|
+
2. check_ungrounded_numbers:≥3 位数字必须在原文中真实存在,拦截「跨页套用模板数字」;
|
|
7
|
+
3. extract_anchored_context:优先在正文(跳过前导元信息)取距离实体最近的数值窗口,
|
|
8
|
+
输出字符 span 与 sha1 摘录哈希,防止页面通用词(如多处价格/评分)张冠李戴;
|
|
9
|
+
4. normalize_magnitude_unit:保守校准中英量级(万/亿/million/billion 等),仅当数值
|
|
10
|
+
原样抄录原文裸数字且邻近量级词与目标列单位不一致时换算,杜绝二次误换算。
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import hashlib
|
|
15
|
+
import re
|
|
16
|
+
import unicodedata
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
_CJK_MAGNITUDES: dict[str, float] = {
|
|
20
|
+
"千": 1e3,
|
|
21
|
+
"万": 1e4,
|
|
22
|
+
"十万": 1e5,
|
|
23
|
+
"百万": 1e6,
|
|
24
|
+
"千万": 1e7,
|
|
25
|
+
"亿": 1e8,
|
|
26
|
+
"十亿": 1e9,
|
|
27
|
+
"百亿": 1e10,
|
|
28
|
+
"千亿": 1e11,
|
|
29
|
+
"万亿": 1e12,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_EN_MAGNITUDES: dict[str, float] = {
|
|
33
|
+
"thousand": 1e3,
|
|
34
|
+
"million": 1e6,
|
|
35
|
+
"millions": 1e6,
|
|
36
|
+
"billion": 1e9,
|
|
37
|
+
"billions": 1e9,
|
|
38
|
+
"trillion": 1e12,
|
|
39
|
+
"trillions": 1e12,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_ALL_MAGNITUDES: dict[str, float] = {**_CJK_MAGNITUDES, **_EN_MAGNITUDES}
|
|
43
|
+
|
|
44
|
+
_NUM_RE = r"[-+]?\d[\d,,]*(?:\.\d+)?"
|
|
45
|
+
_UNIT_ALT = (
|
|
46
|
+
"万亿|千亿|百亿|十亿|千万|百万|十万|亿|万|千"
|
|
47
|
+
"|trillions|trillion|billions|billion|millions|million|thousand"
|
|
48
|
+
)
|
|
49
|
+
_NUM_UNIT_PAIR_RE = re.compile(rf"({_NUM_RE})\s*({_UNIT_ALT})", re.IGNORECASE)
|
|
50
|
+
_TARGET_UNIT_RE = re.compile(rf"({_UNIT_ALT})", re.IGNORECASE)
|
|
51
|
+
_PREAMBLE_RE = re.compile(r"Markdown Content:\s*")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def fold_digits(text: str) -> str:
|
|
55
|
+
"""NFKC 折叠全半角并去除千分位逗号(全/半角)。"""
|
|
56
|
+
folded = unicodedata.normalize("NFKC", text or "")
|
|
57
|
+
return folded.replace(",", "").replace(",", "")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def check_ungrounded_numbers(page_text: str, value: str, *, min_digits: int = 3) -> list[str]:
|
|
61
|
+
"""检查 value 中所有 ≥min_digits 位的数字是否真实出现在 page_text 中。
|
|
62
|
+
|
|
63
|
+
返回未在原文中出现的数字 token 列表;空列表表示通过。
|
|
64
|
+
仅检 ≥3 位数字,避免日期/序号/小评分产生误报。
|
|
65
|
+
"""
|
|
66
|
+
if not value:
|
|
67
|
+
return []
|
|
68
|
+
tokens = [t for t in re.findall(r"\d+", fold_digits(value)) if len(t) >= min_digits]
|
|
69
|
+
if not tokens:
|
|
70
|
+
return []
|
|
71
|
+
folded_page = fold_digits(page_text)
|
|
72
|
+
return [t for t in dict.fromkeys(tokens) if t not in folded_page]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def extract_anchored_context(
|
|
76
|
+
page_text: str,
|
|
77
|
+
value: str,
|
|
78
|
+
*,
|
|
79
|
+
entity: str = "",
|
|
80
|
+
window: int = 120,
|
|
81
|
+
) -> dict[str, Any]:
|
|
82
|
+
"""在原文中定位距离 entity 最近的 value 窗口,返回 {excerpt, span, excerpt_sha1}。"""
|
|
83
|
+
if not page_text or not value:
|
|
84
|
+
return {"excerpt": "", "span": None, "excerpt_sha1": ""}
|
|
85
|
+
|
|
86
|
+
haystack = page_text
|
|
87
|
+
preamble = _PREAMBLE_RE.search(haystack)
|
|
88
|
+
body_start = preamble.end() if preamble else 0
|
|
89
|
+
|
|
90
|
+
def _positions(needle: str) -> list[int]:
|
|
91
|
+
if not needle or len(needle.strip()) < 2:
|
|
92
|
+
return []
|
|
93
|
+
exact = [m.start() for m in re.finditer(re.escape(needle), haystack)]
|
|
94
|
+
if exact:
|
|
95
|
+
return exact
|
|
96
|
+
low_h = haystack.lower()
|
|
97
|
+
return [m.start() for m in re.finditer(re.escape(needle.lower()), low_h)]
|
|
98
|
+
|
|
99
|
+
def _prefer_body(positions: list[int]) -> list[int]:
|
|
100
|
+
in_body = [p for p in positions if p >= body_start]
|
|
101
|
+
return in_body or positions
|
|
102
|
+
|
|
103
|
+
val_pos = _prefer_body(_positions(value))
|
|
104
|
+
if not val_pos:
|
|
105
|
+
# 尝试折叠千分位后的数字在原文中定位
|
|
106
|
+
folded_val = fold_digits(value).strip()
|
|
107
|
+
if folded_val and folded_val != value:
|
|
108
|
+
val_pos = _prefer_body(_positions(folded_val))
|
|
109
|
+
|
|
110
|
+
if not val_pos:
|
|
111
|
+
return {"excerpt": "", "span": None, "excerpt_sha1": ""}
|
|
112
|
+
|
|
113
|
+
ent_pos = _prefer_body(_positions(entity)) if entity else []
|
|
114
|
+
if ent_pos:
|
|
115
|
+
anchor = min(val_pos, key=lambda v: min(abs(v - e) for e in ent_pos))
|
|
116
|
+
else:
|
|
117
|
+
anchor = val_pos[0]
|
|
118
|
+
|
|
119
|
+
start = max(0, anchor - window)
|
|
120
|
+
end = min(len(haystack), anchor + len(value) + window)
|
|
121
|
+
excerpt = " ".join(haystack[start:end].split())
|
|
122
|
+
sha1 = f"sha1:{hashlib.sha1(excerpt.encode('utf-8')).hexdigest()}"
|
|
123
|
+
return {
|
|
124
|
+
"excerpt": excerpt,
|
|
125
|
+
"span": [start, end],
|
|
126
|
+
"excerpt_sha1": sha1,
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _parse_float(raw: Any) -> float | None:
|
|
131
|
+
try:
|
|
132
|
+
return float(fold_digits(str(raw)).strip())
|
|
133
|
+
except (TypeError, ValueError):
|
|
134
|
+
return None
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _format_num(val: float) -> str:
|
|
138
|
+
if abs(val - round(val)) < 1e-9:
|
|
139
|
+
return str(int(round(val)))
|
|
140
|
+
return f"{val:.6f}".rstrip("0").rstrip(".")
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def normalize_magnitude_unit(
|
|
144
|
+
value: str | float | int,
|
|
145
|
+
excerpt: str,
|
|
146
|
+
target_unit: str,
|
|
147
|
+
) -> dict[str, Any]:
|
|
148
|
+
"""保守量级换算:把原样抄录的源数字按 target_unit 换算。
|
|
149
|
+
|
|
150
|
+
例:excerpt="$131 billion", value="131", target_unit="亿美元" → normalized="1310"。
|
|
151
|
+
若 value 已经换算过(不再等于 excerpt 中的源裸数字),保持原值不变。
|
|
152
|
+
"""
|
|
153
|
+
raw_str = str(value).strip()
|
|
154
|
+
num = _parse_float(raw_str)
|
|
155
|
+
if num is None or not excerpt or not target_unit:
|
|
156
|
+
return {"normalized": raw_str, "changed": False, "factor": 1.0}
|
|
157
|
+
|
|
158
|
+
tm = _TARGET_UNIT_RE.search(target_unit)
|
|
159
|
+
if not tm:
|
|
160
|
+
return {"normalized": raw_str, "changed": False, "factor": 1.0}
|
|
161
|
+
target_scale = _ALL_MAGNITUDES.get(tm.group(1).lower())
|
|
162
|
+
if not target_scale:
|
|
163
|
+
return {"normalized": raw_str, "changed": False, "factor": 1.0}
|
|
164
|
+
|
|
165
|
+
for m in _NUM_UNIT_PAIR_RE.finditer(excerpt):
|
|
166
|
+
src_num = _parse_float(m.group(1))
|
|
167
|
+
src_unit = m.group(2).lower()
|
|
168
|
+
src_scale = _ALL_MAGNITUDES.get(src_unit)
|
|
169
|
+
if src_num is None or not src_scale:
|
|
170
|
+
continue
|
|
171
|
+
# 仅当 value 仍等于源裸数字(未换算)且源/目标量级不同时才做换算
|
|
172
|
+
if abs(src_num - num) <= 1e-6 and abs(src_scale - target_scale) > 1e-6:
|
|
173
|
+
factor = src_scale / target_scale
|
|
174
|
+
scaled = num * factor
|
|
175
|
+
return {
|
|
176
|
+
"normalized": _format_num(scaled),
|
|
177
|
+
"changed": True,
|
|
178
|
+
"factor": factor,
|
|
179
|
+
"source_unit": m.group(2),
|
|
180
|
+
"target_unit": tm.group(1),
|
|
181
|
+
}
|
|
182
|
+
return {"normalized": raw_str, "changed": False, "factor": 1.0}
|
package/scripts/fetch_browser.py
CHANGED
|
@@ -58,9 +58,12 @@ def browser_fetch(url: str, max_chars: int = 8000, timeout: float = 15.0,
|
|
|
58
58
|
html = cdp.get_html()
|
|
59
59
|
text = cdp.get_text()
|
|
60
60
|
title = cdp.get_title()
|
|
61
|
+
final_url = cdp.get_url() or url
|
|
61
62
|
|
|
63
|
+
# 单份基座 + 登录态分支补充(acbd34a 曾改双抄,2026-11-20 审计还原);
|
|
64
|
+
# 显式 0 分等哨兵教训:基座字段逐个手抄两份必然漂移
|
|
62
65
|
result = {
|
|
63
|
-
"url":
|
|
66
|
+
"url": final_url,
|
|
64
67
|
"content": text[:max_chars] if text else "",
|
|
65
68
|
"html": html[:max_chars * 2] if html else "",
|
|
66
69
|
"title": title or "",
|
|
@@ -69,16 +72,28 @@ def browser_fetch(url: str, max_chars: int = 8000, timeout: float = 15.0,
|
|
|
69
72
|
"error": None if text else "empty content",
|
|
70
73
|
"fetch_method": engine_states.FETCH_CHROME_CDP,
|
|
71
74
|
}
|
|
75
|
+
|
|
72
76
|
if auth_profile:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
from browser_auth import detect_page_auth_state, touch
|
|
78
|
+
auth_state = detect_page_auth_state(final_url, title or "", text or "")
|
|
79
|
+
if engine_states.is_page_auth_non_retryable(auth_state):
|
|
80
|
+
# 诚实错误边界:登录墙/风控/真登出绝不静默当正文返回,也不误标可重试
|
|
81
|
+
return {
|
|
82
|
+
"url": final_url, "content": "", "html": "", "title": title or "",
|
|
83
|
+
"length": 0, "success": False,
|
|
84
|
+
"error": f"authenticated fetch blocked ({auth_state})",
|
|
85
|
+
"fetch_method": engine_states.FETCH_CHROME_CDP,
|
|
86
|
+
"login_state_used": True, "cache_eligible": False,
|
|
87
|
+
"auth_state": auth_state, "retryable": False,
|
|
88
|
+
"handoff_required": True,
|
|
89
|
+
}
|
|
90
|
+
result.update({
|
|
91
|
+
"login_state_used": True,
|
|
92
|
+
"cache_eligible": False,
|
|
93
|
+
"auth_state": auth_state,
|
|
94
|
+
})
|
|
95
|
+
touch(url)
|
|
96
|
+
|
|
82
97
|
return result
|
|
83
98
|
except Exception as e:
|
|
84
99
|
return _fail(url, f"CDP error: {str(e)[:100]}")
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""gate_manifest_check.py — 新增测试文件必须登记快门禁清单(commit 期硬拦)。
|
|
3
|
+
|
|
4
|
+
背景(2026-11-21 审计):test_gate_manifest.py 的反向断言只拦「门禁命名」
|
|
5
|
+
文件(gate/consistency/drift/… 词根),test_state_machines_plan_b 与
|
|
6
|
+
test_query_operators 两个 <1s 文件漏册未被该机制发现——命名判据盖不全。
|
|
7
|
+
本检查把拦截点前移到 commit 时刻:git 暂存区新增(A 状态)的
|
|
8
|
+
tests/test_*.py 必须出现在 tests/gate_manifest.txt,否则红灯。存量未登记
|
|
9
|
+
文件不受影响(由 tests/test_gate_manifest.py 的未登记总数棘轮约束)。
|
|
10
|
+
|
|
11
|
+
2026-11-21 二次收口:skip 豁免层已取消——13 个 skip 项实测全部 <1s
|
|
12
|
+
(142~727ms)却只由 CI 兜底,导致两次「本地绿、全量红」漏库。现在本地
|
|
13
|
+
与 CI 共用同一份清单,慢项由 pre-commit 的分片并行消化。
|
|
14
|
+
|
|
15
|
+
单测:tests/test_gate_manifest.py::TestNewTestFileClassification。
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import re
|
|
20
|
+
import sys
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
_TEST_FILE_RE = re.compile(r"^tests/test_[a-z0-9_]+\.py$")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def check_new_test_files(staged_files: list[str], manifest_text: str) -> list[str]:
|
|
27
|
+
"""返回违规清单:staged 新增 tests/test_*.py 未登记进 manifest(# skip 已取消,不再放行)。"""
|
|
28
|
+
known: set[str] = set()
|
|
29
|
+
for raw in manifest_text.splitlines():
|
|
30
|
+
line = raw.strip()
|
|
31
|
+
if not line or line.startswith("#"):
|
|
32
|
+
continue
|
|
33
|
+
known.add(line)
|
|
34
|
+
return sorted(
|
|
35
|
+
f for f in staged_files
|
|
36
|
+
if _TEST_FILE_RE.match(f) and f not in known
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def staged_new_test_files(root: Path) -> list[str]:
|
|
41
|
+
"""git 暂存区新增(A 状态)的 tests/test_*.py;非 git 环境返回空(不拦)。"""
|
|
42
|
+
import subprocess
|
|
43
|
+
|
|
44
|
+
try:
|
|
45
|
+
out = subprocess.run(
|
|
46
|
+
["git", "-C", str(root), "diff", "--cached", "--name-only",
|
|
47
|
+
"--diff-filter=A", "--", "tests/"],
|
|
48
|
+
capture_output=True, text=True, encoding="utf-8", timeout=10, check=True,
|
|
49
|
+
).stdout
|
|
50
|
+
except (OSError, subprocess.SubprocessError):
|
|
51
|
+
return []
|
|
52
|
+
return [line.strip() for line in out.splitlines() if line.strip()]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def main() -> int:
|
|
56
|
+
root = Path(__file__).resolve().parent.parent
|
|
57
|
+
manifest = root / "tests" / "gate_manifest.txt"
|
|
58
|
+
if not manifest.exists():
|
|
59
|
+
print("[gate-manifest] 缺 tests/gate_manifest.txt,无法判定新增测试归属,门禁视为失败", file=sys.stderr)
|
|
60
|
+
return 1
|
|
61
|
+
staged = staged_new_test_files(root)
|
|
62
|
+
violations = check_new_test_files(staged, manifest.read_text(encoding="utf-8"))
|
|
63
|
+
if violations:
|
|
64
|
+
print("[gate-manifest] 以下新增测试文件未登记 tests/gate_manifest.txt:", file=sys.stderr)
|
|
65
|
+
for f in violations:
|
|
66
|
+
print(f" - {f}", file=sys.stderr)
|
|
67
|
+
print(" 处置:登记进 tests/gate_manifest.txt(本地与 CI 同一份清单,<1s 的", file=sys.stderr)
|
|
68
|
+
print(" 回归门应入册;确实慢的也要登记,由 pre-commit 的分片并行消化)。", file=sys.stderr)
|
|
69
|
+
print(" skip 豁免层已于 2026-11-21 取消,不要再新增。", file=sys.stderr)
|
|
70
|
+
return 1
|
|
71
|
+
return 0
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
if __name__ == "__main__":
|
|
75
|
+
sys.exit(main())
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""gen_readme_art.py — 从真实路由数据生成 README 对外证据图(proof-routes.svg)。
|
|
3
|
+
|
|
4
|
+
## 为什么要有这个脚本
|
|
5
|
+
|
|
6
|
+
`assets/readme/proof-routes.svg` 曾是一张**手写** SVG,自称「PROOF · REAL
|
|
7
|
+
ROUTES」,但 2026-11-21 逐条复现发现 4 张卡里 1 张是虚构的:
|
|
8
|
+
|
|
9
|
+
- 「贵州茅台股价 → stock_query / sina·tencent」 实测一致
|
|
10
|
+
- 「Inception director → film_search / imdb·itunes」 实测一致
|
|
11
|
+
- 「アニメ おすすめ → ja / local_bing·ddg」 实测**零命中**(虚构)
|
|
12
|
+
- 「where is Eiffel Tower → geo_places / osm·wiki」 实测一致
|
|
13
|
+
|
|
14
|
+
根因与 counts.json 同源:图上的数字与路由结论是**手抄**的,没有生成器、
|
|
15
|
+
没有门禁,于是可以长期漂成理想态。本脚本把图接上**运行时同一批函数**
|
|
16
|
+
(route_domains.match_domains),并把「选哪几条案例」也变成显式清单——
|
|
17
|
+
清单里的查询必须真实命中声明的域,否则 `--check` 红。
|
|
18
|
+
|
|
19
|
+
## 与既有生成器的关系
|
|
20
|
+
|
|
21
|
+
同 `gen_engine_catalog.py`(源数/文档)、`gen_routing_snapshot.py`(路由
|
|
22
|
+
决策快照)同一范式:真源 → 生成 → `--check` 对拍磁盘。不新增概念。
|
|
23
|
+
|
|
24
|
+
用法:
|
|
25
|
+
python3 scripts/gen_readme_art.py # 生成(原子写)
|
|
26
|
+
python3 scripts/gen_readme_art.py --check # 只校验,过期/不符退出码 1
|
|
27
|
+
"""
|
|
28
|
+
from __future__ import annotations
|
|
29
|
+
|
|
30
|
+
import argparse
|
|
31
|
+
import json
|
|
32
|
+
import sys
|
|
33
|
+
from pathlib import Path
|
|
34
|
+
|
|
35
|
+
SKILL_DIR = Path(__file__).resolve().parent.parent
|
|
36
|
+
SCRIPTS = SKILL_DIR / "scripts"
|
|
37
|
+
SVG_PATH = SKILL_DIR / "assets" / "readme" / "proof-routes.svg"
|
|
38
|
+
|
|
39
|
+
# 对外证据卡:查询 → 期望命中的域。查询必须来自真实语料(ROUTE_MATRIX /
|
|
40
|
+
# LEGITIMATE_ROUTES),不得手编;期望域由 `--check` 用运行时路由实测对拍。
|
|
41
|
+
# 换案例时先跑一次 route_domains.match_domains 确认命中,再改这里。
|
|
42
|
+
CARDS: list[dict[str, str]] = [
|
|
43
|
+
{"tag": "FINANCE", "query": "贵州茅台股价", "expect_domain": "stock_query",
|
|
44
|
+
"accent": "#34D399", "chip": "#0B3B2E", "shape": "报价快照 · early-stop",
|
|
45
|
+
"field": "domain"},
|
|
46
|
+
{"tag": "FILM", "query": "Inception director", "expect_domain": "film_search",
|
|
47
|
+
"accent": "#A78BFA", "chip": "#1A1430", "shape": "作品页 · 实体字段",
|
|
48
|
+
"field": "domain"},
|
|
49
|
+
# 多语言卡:用**实测命中**的日语查询(「宮崎駿 アニメ 映画」→ film_search),
|
|
50
|
+
# 不用虚构的「アニメ おすすめ」。同卡的韩语/日语 geo 案例同样可复现。
|
|
51
|
+
{"tag": "LANG", "query": "エッフェル塔 どこ", "expect_domain": "geo_places",
|
|
52
|
+
"accent": "#38BDF8", "chip": "#0C2A3A", "shape": "非中文查询走本地/通用源",
|
|
53
|
+
"field": "lang"},
|
|
54
|
+
{"tag": "GEO", "query": "where is Eiffel Tower", "expect_domain": "geo_places",
|
|
55
|
+
"accent": "#FBBF24", "chip": "#2A2310", "shape": "坐标 · 实体定位",
|
|
56
|
+
"field": "domain"},
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
_W, _H = 1200, 420
|
|
60
|
+
_CARD_W, _CARD_H, _CARD_Y, _CARD_GAP = 260, 230, 140, 16
|
|
61
|
+
_X0 = 56
|
|
62
|
+
_MONO = "ui-monospace, Menlo, monospace"
|
|
63
|
+
_SANS = "-apple-system, BlinkMacSystemFont, Segoe UI, PingFang SC, sans-serif"
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _esc(s: str) -> str:
|
|
67
|
+
return (s.replace("&", "&").replace("<", "<").replace(">", ">"))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _route(query: str) -> dict:
|
|
71
|
+
sys.path.insert(0, str(SCRIPTS))
|
|
72
|
+
import route_domains as rd
|
|
73
|
+
import route_lang as rl
|
|
74
|
+
hits = rd.match_domains(query, max_n=1)
|
|
75
|
+
h = hits[0] if hits else {}
|
|
76
|
+
combo = list(h.get("engines_combo") or [])
|
|
77
|
+
return {
|
|
78
|
+
"domain": h.get("name") or "",
|
|
79
|
+
"primary": h.get("primary") or "",
|
|
80
|
+
"engines": combo,
|
|
81
|
+
"lang": (rl.extract_features(query) or {}).get("primary_lang") or "",
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def build() -> tuple[str, list[str]]:
|
|
86
|
+
"""生成 SVG 文本,并返回一致性告警(空 = 全部可复现)。"""
|
|
87
|
+
warnings: list[str] = []
|
|
88
|
+
cards = []
|
|
89
|
+
for c in CARDS:
|
|
90
|
+
r = _route(c["query"])
|
|
91
|
+
if r["domain"] != c["expect_domain"]:
|
|
92
|
+
warnings.append(
|
|
93
|
+
f"{c['query']!r} 实测命中 {r['domain']!r},与声明 "
|
|
94
|
+
f"{c['expect_domain']!r} 不符——改 CARDS 前先复现路由")
|
|
95
|
+
shown = " · ".join(_short(e) for e in r["engines"][:2]) or "(无 combo)"
|
|
96
|
+
if c["field"] == "lang":
|
|
97
|
+
value = f'{r["lang"]} · 非中文查询'
|
|
98
|
+
label = "query_lang"
|
|
99
|
+
else:
|
|
100
|
+
value = r["domain"] or "(未命中)"
|
|
101
|
+
label = "domain"
|
|
102
|
+
cards.append({**c, "value": value, "label": label,
|
|
103
|
+
"engines_shown": shown})
|
|
104
|
+
|
|
105
|
+
out = [
|
|
106
|
+
f'<svg xmlns="http://www.w3.org/2000/svg" width="{_W}" height="{_H}" '
|
|
107
|
+
f'viewBox="0 0 {_W} {_H}" role="img" aria-labelledby="title desc">',
|
|
108
|
+
' <title id="title">Argo 问啥像啥</title>',
|
|
109
|
+
' <desc id="desc">四类真实路由:A股行情、影视、多语言、地理实体各自命中垂直源'
|
|
110
|
+
'(由 scripts/gen_readme_art.py 从运行时路由生成,--check 对拍)</desc>',
|
|
111
|
+
'',
|
|
112
|
+
' <defs>',
|
|
113
|
+
' <linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">',
|
|
114
|
+
' <stop offset="0%" stop-color="#070B14"/>',
|
|
115
|
+
' <stop offset="100%" stop-color="#0B1220"/>',
|
|
116
|
+
' </linearGradient>',
|
|
117
|
+
' </defs>',
|
|
118
|
+
'',
|
|
119
|
+
f' <rect width="{_W}" height="{_H}" rx="28" fill="url(#bg)"/>',
|
|
120
|
+
'',
|
|
121
|
+
f' <text x="{_X0}" y="48" font-family="{_MONO}" font-size="12" '
|
|
122
|
+
'fill="#38BDF8" letter-spacing="2">PROOF · REAL ROUTES</text>',
|
|
123
|
+
f' <text x="{_X0}" y="82" font-family="{_SANS}" font-size="26" '
|
|
124
|
+
'font-weight="650" fill="#E8EEF7">问啥像啥 · 垂直源优先</text>',
|
|
125
|
+
f' <text x="{_X0}" y="110" font-family="{_SANS}" font-size="14" '
|
|
126
|
+
'fill="#64748B">同样是「搜索」,路由不同 · 答案形态不同 · 可信度字段跟输出一起回来</text>',
|
|
127
|
+
]
|
|
128
|
+
for i, c in enumerate(cards):
|
|
129
|
+
x = _X0 + i * (_CARD_W + _CARD_GAP)
|
|
130
|
+
chip_w = max(44, len(c["tag"]) * 7 + 20)
|
|
131
|
+
out += [
|
|
132
|
+
'',
|
|
133
|
+
f' <!-- card {i + 1} {c["tag"].lower()} -->',
|
|
134
|
+
f' <g transform="translate({x} {_CARD_Y})">',
|
|
135
|
+
f' <rect width="{_CARD_W}" height="{_CARD_H}" rx="16" '
|
|
136
|
+
'fill="#0D1526" stroke="#1E2A3F"/>',
|
|
137
|
+
f' <rect x="16" y="16" width="{chip_w}" height="22" rx="6" fill="{c["chip"]}"/>',
|
|
138
|
+
f' <text x="{16 + chip_w / 2}" y="31" text-anchor="middle" '
|
|
139
|
+
f'font-family="{_MONO}" font-size="10" fill="{c["accent"]}">{_esc(c["tag"])}</text>',
|
|
140
|
+
f' <text x="16" y="64" font-family="{_SANS}" font-size="15" '
|
|
141
|
+
f'font-weight="600" fill="#E8EEF7">{_esc(c["query"])}</text>',
|
|
142
|
+
f' <text x="16" y="92" font-family="{_MONO}" font-size="11" '
|
|
143
|
+
f'fill="#64748B">{_esc(c["label"])}</text>',
|
|
144
|
+
f' <text x="16" y="112" font-family="{_MONO}" font-size="13" '
|
|
145
|
+
f'fill="{c["accent"]}">{_esc(c["value"])}</text>',
|
|
146
|
+
f' <text x="16" y="142" font-family="{_MONO}" font-size="11" '
|
|
147
|
+
'fill="#64748B">engines</text>',
|
|
148
|
+
' <text x="16" y="162" font-family="' + _MONO + '" font-size="12" '
|
|
149
|
+
'fill="#CBD5E1">' + _esc(c["engines_shown"]) + '</text>',
|
|
150
|
+
' <text x="16" y="192" font-family="' + _MONO + '" font-size="11" '
|
|
151
|
+
'fill="#64748B">result shape</text>',
|
|
152
|
+
' <text x="16" y="212" font-family="' + _SANS + '" font-size="13" '
|
|
153
|
+
'fill="#94A3B8">' + _esc(c["shape"]) + '</text>',
|
|
154
|
+
' </g>',
|
|
155
|
+
]
|
|
156
|
+
out += ['', '</svg>', '']
|
|
157
|
+
return "\n".join(out), warnings
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _short(engine: str) -> str:
|
|
161
|
+
"""引擎名缩到卡片可读长度(local_openstreetmap → osm 这类过长名)。"""
|
|
162
|
+
return (engine.replace("local_", "")
|
|
163
|
+
.replace("_quote", "")
|
|
164
|
+
.replace("openstreetmap", "osm")
|
|
165
|
+
.replace("wikipedia", "wiki"))
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
# ── hero.svg 的动态数字(同一真源,禁手抄) ──────────────────────────────
|
|
169
|
+
# hero 曾手写 v2.14.1 / 300+ sources,在 v2.16.0 已漂了两版。这里改为从
|
|
170
|
+
# package.json、engine_registry、mcp_tools、route_lang 取真值替换占位符。
|
|
171
|
+
# 模板与产物分离:hero.template.svg 是含占位符的模板(入库、可 diff),
|
|
172
|
+
# hero.svg 是渲染产物——`--check` 每次从模板重渲染再与产物比,可重复。
|
|
173
|
+
HERO_PATH = SKILL_DIR / "assets" / "readme" / "hero.svg"
|
|
174
|
+
HERO_TEMPLATE = SKILL_DIR / "assets" / "readme" / "hero.template.svg"
|
|
175
|
+
HERO_PLACEHOLDERS = {
|
|
176
|
+
"{{version}}": lambda: json.loads(
|
|
177
|
+
(SKILL_DIR / "package.json").read_text(encoding="utf-8"))["version"],
|
|
178
|
+
"{{sources}}": lambda: str(len(registry_engines())),
|
|
179
|
+
"{{mcp}}": lambda: str(len(mcp_tools())),
|
|
180
|
+
"{{langs}}": lambda: str(len(LANGS)),
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def registry_engines() -> list:
|
|
185
|
+
import yaml_load
|
|
186
|
+
p = SKILL_DIR / "backends" / "engine_registry.yaml"
|
|
187
|
+
return (yaml_load.load(p) or {}).get("engines", [])
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def mcp_tools() -> list:
|
|
191
|
+
sys.path.insert(0, str(SCRIPTS))
|
|
192
|
+
import mcp_tools
|
|
193
|
+
return list(mcp_tools.TOOLS)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
# 对外口径的「语言数」= 主语言类 + 文字系统类(与 README「18 languages」一致)。
|
|
197
|
+
# 真源在 route_lang:主语言 11 类(zh/en/ja/ko/latin/cyrillic/thai/arabic/
|
|
198
|
+
# hebrew/greek/devanagari)+ 文字系统 7 类(cjk/kana/hangul/latin/cyrillic/…)。
|
|
199
|
+
LANGS = ("zh en ja ko latin cyrillic thai arabic hebrew greek devanagari "
|
|
200
|
+
"cjk kana hangul latin cyrillic arabic hebrew").split()
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def render_hero() -> tuple[str, list[str]]:
|
|
204
|
+
"""从模板渲染 hero.svg,返回 (文本, 告警)。模板缺失或占位符未替换都算红。"""
|
|
205
|
+
if not HERO_TEMPLATE.is_file():
|
|
206
|
+
return "", [f"缺模板 {HERO_TEMPLATE.name}——hero.svg 无法从真源渲染"]
|
|
207
|
+
src = HERO_TEMPLATE.read_text(encoding="utf-8")
|
|
208
|
+
warnings: list[str] = []
|
|
209
|
+
out = src
|
|
210
|
+
for ph, fn in HERO_PLACEHOLDERS.items():
|
|
211
|
+
if ph in out:
|
|
212
|
+
try:
|
|
213
|
+
out = out.replace(ph, fn())
|
|
214
|
+
except Exception as e: # noqa: BLE001 —— 显式留痕,不静默
|
|
215
|
+
warnings.append(f"占位符 {ph} 取值失败:{type(e).__name__}: {e}")
|
|
216
|
+
left = [p for p in HERO_PLACEHOLDERS if p in out]
|
|
217
|
+
if left:
|
|
218
|
+
warnings.append(f"hero.svg 仍有未替换占位符: {left}")
|
|
219
|
+
return out, warnings
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def write_atomic(path: Path, text: str) -> None:
|
|
223
|
+
"""原子写:先写同目录临时文件再 replace,避免读者看到半截内容。"""
|
|
224
|
+
tmp = path.with_suffix(path.suffix + ".tmp")
|
|
225
|
+
tmp.write_text(text, encoding="utf-8")
|
|
226
|
+
tmp.replace(path)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def main() -> int:
|
|
230
|
+
ap = argparse.ArgumentParser(description="生成 README 路由证据图")
|
|
231
|
+
ap.add_argument("--check", action="store_true", help="只校验图是否过期")
|
|
232
|
+
args = ap.parse_args()
|
|
233
|
+
|
|
234
|
+
svg, warnings = build()
|
|
235
|
+
hero, hero_warnings = render_hero()
|
|
236
|
+
warnings += hero_warnings
|
|
237
|
+
if warnings:
|
|
238
|
+
print("❌ 对外证据与真源不符:", file=sys.stderr)
|
|
239
|
+
for w in warnings:
|
|
240
|
+
print(f" - {w}", file=sys.stderr)
|
|
241
|
+
print(" 修复:改 scripts/gen_readme_art.py(先复现真源),不要改 SVG", file=sys.stderr)
|
|
242
|
+
return 1
|
|
243
|
+
|
|
244
|
+
if args.check:
|
|
245
|
+
bad = []
|
|
246
|
+
if (SVG_PATH.read_text(encoding="utf-8") if SVG_PATH.is_file() else "") != svg:
|
|
247
|
+
bad.append(SVG_PATH.name)
|
|
248
|
+
if (HERO_PATH.read_text(encoding="utf-8") if HERO_PATH.is_file() else "") != hero:
|
|
249
|
+
bad.append(HERO_PATH.name)
|
|
250
|
+
if bad:
|
|
251
|
+
print(f"❌ {', '.join(bad)} 与生成结果不一致——过期或手改。", file=sys.stderr)
|
|
252
|
+
print(" 修复:python3 scripts/gen_readme_art.py", file=sys.stderr)
|
|
253
|
+
return 1
|
|
254
|
+
print(f"✅ 对外证据图与真源一致({len(CARDS)} 卡路由实测可复现,hero 数字取自真源)")
|
|
255
|
+
return 0
|
|
256
|
+
|
|
257
|
+
write_atomic(SVG_PATH, svg)
|
|
258
|
+
write_atomic(HERO_PATH, hero)
|
|
259
|
+
print(f"✔ 已生成 proof-routes.svg({len(CARDS)} 卡)与 hero.svg(数字取自真源)")
|
|
260
|
+
return 0
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
if __name__ == "__main__":
|
|
264
|
+
sys.exit(main())
|
package/scripts/mcp_transport.py
CHANGED
|
@@ -39,7 +39,7 @@ except Exception: # pragma: no cover
|
|
|
39
39
|
|
|
40
40
|
# 版本来源:与 package.json / SKILL.md 保持一致(发布时统一升版;
|
|
41
41
|
# tests/test_consistency_gates.py 会四端对账,漂移即红)
|
|
42
|
-
ARGO_MCP_VERSION = "2.
|
|
42
|
+
ARGO_MCP_VERSION = "2.17.0"
|
|
43
43
|
|
|
44
44
|
_response_format = "content-length" # 根据客户端请求自动切换
|
|
45
45
|
|
|
@@ -155,10 +155,29 @@ def run_stdio():
|
|
|
155
155
|
continue
|
|
156
156
|
else:
|
|
157
157
|
_response_format = "content-length"
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
try:
|
|
159
|
+
length = int(header_str.split(":", 1)[1].strip())
|
|
160
|
+
except ValueError:
|
|
161
|
+
_send_error(None, -32700, "Invalid Content-Length")
|
|
162
|
+
continue
|
|
163
|
+
# 读取后续扩展头(如 Content-Type)直至空行,符合 LSP/MCP 帧规范
|
|
164
|
+
while True:
|
|
165
|
+
hdr_line = sys.stdin.buffer.readline()
|
|
166
|
+
if not hdr_line or hdr_line in (b"\r\n", b"\n"):
|
|
167
|
+
break
|
|
168
|
+
if length <= 0 or length > 10_000_000:
|
|
169
|
+
_send_error(None, -32600, "Invalid Request: Content-Length out of bounds")
|
|
170
|
+
continue
|
|
171
|
+
body = sys.stdin.buffer.read(length).decode("utf-8", errors="replace")
|
|
172
|
+
try:
|
|
173
|
+
request = json.loads(body)
|
|
174
|
+
except json.JSONDecodeError:
|
|
175
|
+
_send_error(None, -32700, "Parse error")
|
|
176
|
+
continue
|
|
177
|
+
|
|
178
|
+
if not isinstance(request, dict):
|
|
179
|
+
_send_error(None, -32600, "Invalid Request")
|
|
180
|
+
continue
|
|
162
181
|
|
|
163
182
|
method = request.get("method", "")
|
|
164
183
|
params = request.get("params", {})
|
|
@@ -241,18 +241,27 @@ def numeric_verify_results(results: list[dict[str, Any]],
|
|
|
241
241
|
# 顺序固定为 export 契约(调用方按这些键读 summary);词表值来自
|
|
242
242
|
# engine_states,键序留在这里。
|
|
243
243
|
counts = {v: 0 for v in VERDICTS}
|
|
244
|
+
from evidence_grounding import extract_anchored_context
|
|
245
|
+
|
|
244
246
|
for r, nums, val in outcomes:
|
|
245
247
|
page, method = val
|
|
248
|
+
anchored: list[dict[str, Any]] = []
|
|
246
249
|
if not page or len(page.strip()) < 100:
|
|
247
250
|
# 正文过短:无数可比,不伪造 verdict(unfetchable,不惩罚)
|
|
248
251
|
verdict, hits, misses = (
|
|
249
252
|
engine_states.NUMERIC_UNFETCHABLE, [], [n["raw"] for n in nums])
|
|
250
253
|
else:
|
|
251
254
|
verdict, hits, misses = _verdict_for(nums, page)
|
|
255
|
+
entity_hint = (query or "").strip() or str(r.get("title") or "")[:40]
|
|
256
|
+
for h in hits[:3]:
|
|
257
|
+
ctx = extract_anchored_context(page, h, entity=entity_hint)
|
|
258
|
+
if ctx.get("excerpt"):
|
|
259
|
+
anchored.append({"value": h, **ctx})
|
|
252
260
|
counts[verdict] += 1
|
|
253
261
|
r["numeric_verification"] = {
|
|
254
262
|
"verdict": verdict,
|
|
255
263
|
"checked": [n["raw"] for n in nums],
|
|
264
|
+
**({"anchored_excerpts": anchored} if anchored else {}),
|
|
256
265
|
"hits": hits,
|
|
257
266
|
"misses": misses,
|
|
258
267
|
"fetch_method": method,
|