argo-search 2.10.1 → 2.11.2
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/README.en.md +48 -11
- package/README.es.md +48 -11
- package/README.ja.md +48 -11
- package/README.ko.md +47 -10
- package/README.md +48 -31
- package/SKILL.md +16 -15
- package/backends/concept_vectors.bin +0 -0
- package/backends/domain_profiles.json +18 -6
- package/backends/engine_concept_vectors.json +3104 -0
- package/backends/engine_registry.yaml +38 -13
- package/backends/quota_profiles.json +30 -10
- package/bin/argo +6 -0
- package/config.yaml +98 -31
- package/docs/ENGINE_CATALOG.md +11 -8
- package/docs/RELEASE_NOTES_v2.10.2.md +48 -0
- package/docs/RELEASE_NOTES_v2.11.2.md +50 -0
- package/engines/specs/animetrace.yaml +35 -0
- package/engines/specs/google_lens.yaml +50 -0
- package/engines/specs/saucenao.yaml +45 -0
- package/package.json +4 -2
- package/packages/dsh-plugin/dsh/diagnostics.js +8 -3
- package/packages/dsh-plugin/dsh/index.js +12 -7
- package/packages/dsh-plugin/dsh/runner.js +79 -47
- package/packages/dsh-plugin/package.json +1 -1
- package/packages/dsh-plugin/test/index.test.js +64 -0
- package/scripts/argo_engine_registry.py +30 -4
- package/scripts/argo_paths.py +7 -1
- package/scripts/budget.py +13 -3
- package/scripts/build_concept_table.py +612 -0
- package/scripts/build_route_labels.py +285 -0
- package/scripts/caliber_dedupe.py +66 -0
- package/scripts/caliber_isolation.py +4 -2
- package/scripts/circuit_breaker.py +25 -3
- package/scripts/concept_lookup.py +212 -0
- package/scripts/engine_dispatch.py +2 -1
- package/scripts/engine_families.py +7 -3
- package/scripts/engines.py +34 -9
- package/scripts/engines_base.py +17 -2
- package/scripts/engines_builders.py +0 -1
- package/scripts/engines_builders_intl.py +4 -4
- package/scripts/engines_builders_reverse_image.py +783 -0
- package/scripts/engines_builders_skill.py +87 -10
- package/scripts/engines_builders_tech.py +0 -78
- package/scripts/extend_route_labels.py +239 -0
- package/scripts/extend_route_labels_by_capability.py +344 -0
- package/scripts/extend_route_labels_by_language.py +306 -0
- package/scripts/gen_routing_snapshot.py +22 -3
- package/scripts/job.py +2 -1
- package/scripts/lang_detect.py +12 -3
- package/scripts/lint_spec_contracts.py +110 -0
- package/scripts/lint_stub_targets.py +130 -0
- package/scripts/local_image.py +3 -3
- package/scripts/local_seek.py +13 -3
- package/scripts/mcp_compact.py +5 -0
- package/scripts/mcp_transport.py +1 -1
- package/scripts/net_proxy.py +47 -0
- package/scripts/numeric_verify.py +330 -0
- package/scripts/plan.py +36 -4
- package/scripts/pre-commit +21 -13
- package/scripts/quota.py +109 -10
- package/scripts/rank_signals.py +48 -4
- package/scripts/ranking_eval.py +23 -1
- package/scripts/regression_p0p1.py +7 -2
- package/scripts/route.py +24 -3
- package/scripts/route_accuracy_eval.py +191 -0
- package/scripts/route_combo.py +32 -1
- package/scripts/route_domains.py +242 -5
- package/scripts/route_primary.py +101 -0
- package/scripts/search.py +14 -12
- package/scripts/search_cli.py +89 -7
- package/scripts/search_output.py +59 -1
- package/scripts/search_pipeline.py +20 -15
- package/scripts/snippet_clean.py +60 -0
- package/scripts/social_engines/twitter_engine.py +159 -42
- package/scripts/social_engines/xiaohongshu_engine.py +36 -1
- package/scripts/tfidf_router.py +52 -2
- package/scripts/train.py +15 -0
- package/scripts/verify_with.py +124 -0
- package/sub-skills/local-search/SKILL.md +3 -2
- package/sub-skills/local-search/bm25.py +89 -8
- package/sub-skills/local-search/config.yaml +12 -0
- package/sub-skills/local-search/parse_maps.yaml +8 -0
- package/sub-skills/local-search/parsers.py +5 -2
- package/sub-skills/local-search/search_v3.py +87 -1
- package/sub-skills/local-search/smart_router.py +1 -1
- package/sub-skills/local-seek/SKILL.md +6 -5
- package/sub-skills/local-seek/scripts/eval_rank.py +1 -1
- package/sub-skills/local-seek/scripts/seek.py +152 -36
- package/sub-skills/local-seek/scripts/seek_rank.py +191 -11
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""numeric_verify.py — 数值印证切片:摘要里的关键数字,打开原文确认。
|
|
3
|
+
|
|
4
|
+
问题重定义(第一性,2026-11-01 实测):
|
|
5
|
+
搜索摘要里带着价格/百分比这类「关键数字」,且互相冲突。同一 query
|
|
6
|
+
「iPhone 17 Pro Max 官方价格」的 top-8 里:博彩 SEO 毒内容(挂医院域名)
|
|
7
|
+
说「Pro Max 5999 元起」,财联社说系列起价 5999,苹果官网摘要 RMB 11,999。
|
|
8
|
+
融合排序对数字无感,把 5999 混进 Pro Max 的答案只差一次引用。
|
|
9
|
+
|
|
10
|
+
外部佐证:X 帖(@qi9098,2026-10-31)把同一条经验写成铁律——「搜索返回的
|
|
11
|
+
摘要只当线索,价格、日期这些关键数字要打开原页面确认」。本模块把它做成
|
|
12
|
+
确定性切片:正则检出关键数字 → fetch 原文 → 数字比对 → 冲突者降权。
|
|
13
|
+
|
|
14
|
+
设计取舍(与 evidence_loop.reorder_by_evidence 同一哲学):
|
|
15
|
+
① 只降不升。印证只覆盖 top-k,加分等于奖励「恰好被抓取」;降权表达的
|
|
16
|
+
「原文对不上摘要的数字」是真实信号。
|
|
17
|
+
② 拿不到正文不惩罚(unfetchable 与 verify 的 pending 同语义)——不伪造。
|
|
18
|
+
③ 比对用「数字 token 集」不用子串:摘要数字的规范化形态在页面数字
|
|
19
|
+
token 集里即算命中。宁漏杀不误伤:partial/confirmed 不惩罚。
|
|
20
|
+
④ v1 范围 = 价格(货币符号前缀 / 「N元」后缀)+ 百分比 + 完整日期。
|
|
21
|
+
「N万/N亿」记数法不抽——「2.5万」vs「25000」的换算噪音会制造假冲突,
|
|
22
|
+
收益撑不起风险(留作有标注数据后的扩展点)。
|
|
23
|
+
|
|
24
|
+
降权语义(reorder_by_numeric):
|
|
25
|
+
missing 摘要有数字、原文一个都没有 → ×(1-weight) 强信号
|
|
26
|
+
partial 部分命中 → ×(1-weight/2) 弱信号
|
|
27
|
+
confirmed 全部命中 → 不动
|
|
28
|
+
unfetchable fetch 失败/超时 → 不动
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
from __future__ import annotations
|
|
32
|
+
|
|
33
|
+
import re
|
|
34
|
+
from typing import Any, Callable, Optional
|
|
35
|
+
|
|
36
|
+
# 数字 token:页面侧与摘要侧统一用同一套抽取+规范化,比对才是同构的。
|
|
37
|
+
_NUM_TOKEN_RE = re.compile(r"\d[\d,,]*(?:\.\d+)?")
|
|
38
|
+
# 价格:货币符号/代码前缀($1,299 / ¥5999 / RMB 11,999 / US$799)
|
|
39
|
+
_PRICE_PREFIX_RE = re.compile(
|
|
40
|
+
r"(?:US\$|[$€£¥¥]|RMB|CNY|USD|EUR|GBP|JPY)\s?(\d[\d,,]*(?:\.\d+)?)")
|
|
41
|
+
# 价格:中文元后缀(5999元 / 1,299 块钱),不吞「万/亿」记数法(见模块头④)
|
|
42
|
+
_PRICE_SUFFIX_RE = re.compile(
|
|
43
|
+
r"(\d[\d,,]*(?:\.\d+)?)\s?(?:元|块钱)")
|
|
44
|
+
# 百分比(37.5% / 37.5%)
|
|
45
|
+
_PCT_RE = re.compile(r"(\d{1,3}(?:\.\d+)?)\s?[%%]")
|
|
46
|
+
# 日期:完整「2025年9月10日」「2025-09-10」与无年「9月10日」
|
|
47
|
+
_DATE_FULL_RE = re.compile(r"(?:(20\d{2})\s?[年\-/.]\s?)?(\d{1,2})\s?月\s?(\d{1,2})\s?[日号]?")
|
|
48
|
+
_DATE_ISO_RE = re.compile(r"(20\d{2})[-/.](\d{1,2})[-/.](\d{1,2})")
|
|
49
|
+
|
|
50
|
+
# 结果字段上 verdict 的规范值
|
|
51
|
+
VERDICTS = ("confirmed", "partial", "missing", "unfetchable")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _norm_num(s: str) -> str:
|
|
55
|
+
"""数字字符串规范化:去千分位逗号(全半角),保留小数点。"""
|
|
56
|
+
return s.replace(",", "").replace(",", "").strip()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def extract_critical_numbers(text: str) -> list[dict[str, str]]:
|
|
60
|
+
"""从摘要/标题抽关键数字。返回 [{kind, raw, norm}],按出现顺序去重。"""
|
|
61
|
+
if not text:
|
|
62
|
+
return []
|
|
63
|
+
out: list[dict[str, str]] = []
|
|
64
|
+
seen: set[tuple[str, str]] = set()
|
|
65
|
+
|
|
66
|
+
def _add(kind: str, raw: str, norm: str) -> None:
|
|
67
|
+
key = (kind, norm)
|
|
68
|
+
if norm and key not in seen:
|
|
69
|
+
seen.add(key)
|
|
70
|
+
out.append({"kind": kind, "raw": raw, "norm": norm})
|
|
71
|
+
|
|
72
|
+
for m in _PRICE_PREFIX_RE.finditer(text):
|
|
73
|
+
_add("price", m.group(0), _norm_num(m.group(1)))
|
|
74
|
+
for m in _PRICE_SUFFIX_RE.finditer(text):
|
|
75
|
+
_add("price", m.group(0), _norm_num(m.group(1)))
|
|
76
|
+
for m in _PCT_RE.finditer(text):
|
|
77
|
+
_add("pct", m.group(0), _norm_num(m.group(1)))
|
|
78
|
+
for m in _DATE_ISO_RE.finditer(text):
|
|
79
|
+
y, mo, d = m.group(1), m.group(2), m.group(3)
|
|
80
|
+
_add("date", m.group(0), f"{y}-{int(mo):02d}-{int(d):02d}")
|
|
81
|
+
for m in _DATE_FULL_RE.finditer(text):
|
|
82
|
+
y, mo, d = m.group(1), m.group(2), m.group(3)
|
|
83
|
+
if not (1 <= int(mo) <= 12 and 1 <= int(d) <= 31):
|
|
84
|
+
continue # 「12 组 3 通道」这类数字+量词不是日期
|
|
85
|
+
norm = f"{int(mo)}月{int(d)}日" + (f"{y}年" if y else "")
|
|
86
|
+
_add("date", m.group(0), norm)
|
|
87
|
+
return out
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _page_number_tokens(page: str) -> set[str]:
|
|
91
|
+
"""页面文本的数字 token 集(同样去千分位),供 token 级比对。"""
|
|
92
|
+
return {_norm_num(t) for t in _NUM_TOKEN_RE.findall(page or "")}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _page_date_hit(norm: str, page: str) -> bool:
|
|
96
|
+
"""日期命中:规范化形态(如 9月10日2025年 / 2025-09-10)任一子串出现。"""
|
|
97
|
+
if not norm:
|
|
98
|
+
return False
|
|
99
|
+
# 提取年/月日成分,允许页面用不同分隔符写同一天
|
|
100
|
+
y = re.search(r"(20\d{2})年", norm)
|
|
101
|
+
md = re.search(r"(\d{1,2})月(\d{1,2})日", norm)
|
|
102
|
+
cands: list[str] = [norm]
|
|
103
|
+
if y and md:
|
|
104
|
+
yy, mo, d = y.group(1), int(md.group(1)), int(md.group(2))
|
|
105
|
+
cands += [f"{yy}-{mo:02d}-{d:02d}", f"{yy}/{mo:02d}/{d:02d}",
|
|
106
|
+
f"{yy}年{mo}月{d}日", f"{yy}-{mo}-{d}"]
|
|
107
|
+
if md:
|
|
108
|
+
cands.append(md.group(0))
|
|
109
|
+
return any(c in page for c in cands)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _verdict_for(nums: list[dict[str, str]], page: str) -> tuple[str, list[str], list[str]]:
|
|
113
|
+
"""比对一组摘要数字与页面文本 → (verdict, hits, misses)。"""
|
|
114
|
+
tokens = _page_number_tokens(page)
|
|
115
|
+
hits: list[str] = []
|
|
116
|
+
misses: list[str] = []
|
|
117
|
+
for n in nums:
|
|
118
|
+
if n["kind"] == "date":
|
|
119
|
+
hit = _page_date_hit(n["norm"], page)
|
|
120
|
+
else:
|
|
121
|
+
hit = n["norm"] in tokens
|
|
122
|
+
(hits if hit else misses).append(n["raw"])
|
|
123
|
+
if not misses:
|
|
124
|
+
return "confirmed", hits, misses
|
|
125
|
+
if hits:
|
|
126
|
+
return "partial", hits, misses
|
|
127
|
+
return "missing", hits, misses
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def numeric_verify_results(results: list[dict[str, Any]],
|
|
131
|
+
query: str,
|
|
132
|
+
top_k: int = 3,
|
|
133
|
+
fetch_fn: Callable[..., dict[str, Any]] | None = None,
|
|
134
|
+
max_chars: int = 8000,
|
|
135
|
+
timeout: float = 4.0) -> dict[str, Any]:
|
|
136
|
+
"""对 top_k 条「摘要含关键数字」的结果 fetch 原文,比对数字并回填字段。
|
|
137
|
+
|
|
138
|
+
与 evidence_loop.verify_results 同构但不混用:verify 量「正文吸收分」,
|
|
139
|
+
本切片量「摘要数字与原文是否对得上」。选择面从 results 头部起扫,只取
|
|
140
|
+
摘要含关键数字且非 SERP 的条目(数字才值得付 RTT)。
|
|
141
|
+
|
|
142
|
+
回填(原地,不改排序——排序见 reorder_by_numeric):
|
|
143
|
+
r["numeric_verification"] = {verdict, checked, hits, misses, fetch_method}
|
|
144
|
+
|
|
145
|
+
返回:
|
|
146
|
+
- verified: [{url, title, verdict, hits, misses, fetch_method}]
|
|
147
|
+
- summary: {checked, confirmed, partial, missing, unfetchable}
|
|
148
|
+
- pending: 未取到正文的 URL
|
|
149
|
+
"""
|
|
150
|
+
# 守卫:top_k 非正数按默认 3(与 verify_results 同款,避免反向切片)
|
|
151
|
+
try:
|
|
152
|
+
top_k = int(top_k)
|
|
153
|
+
except (TypeError, ValueError):
|
|
154
|
+
top_k = 3
|
|
155
|
+
if top_k <= 0:
|
|
156
|
+
top_k = 3
|
|
157
|
+
|
|
158
|
+
if fetch_fn is None:
|
|
159
|
+
from fetch_v3 import fetch_v3
|
|
160
|
+
|
|
161
|
+
def _fast_fetch(url: str, max_chars: int, timeout: float) -> dict:
|
|
162
|
+
# 核验快道:与 verify_results 一致,关浏览器兜底、8s deadline 硬顶
|
|
163
|
+
return fetch_v3(url, max_chars=max_chars, timeout=timeout,
|
|
164
|
+
use_browser_fallback=False, deadline_s=8.0)
|
|
165
|
+
fetch_fn = _fast_fetch
|
|
166
|
+
|
|
167
|
+
# 选样:头部起扫,只收「摘要含关键数字」的非 SERP 条目
|
|
168
|
+
targets: list[tuple[dict, list[dict[str, str]]]] = []
|
|
169
|
+
for r in results:
|
|
170
|
+
if len(targets) >= top_k:
|
|
171
|
+
break
|
|
172
|
+
if not isinstance(r, dict):
|
|
173
|
+
continue
|
|
174
|
+
url = r.get("url") or ""
|
|
175
|
+
if not url:
|
|
176
|
+
continue
|
|
177
|
+
try:
|
|
178
|
+
from serp_guard import is_serp_or_jump_url
|
|
179
|
+
if is_serp_or_jump_url(url):
|
|
180
|
+
continue
|
|
181
|
+
except Exception: # pragma: no cover
|
|
182
|
+
pass
|
|
183
|
+
nums = extract_critical_numbers(
|
|
184
|
+
f"{r.get('title') or ''} {r.get('snippet') or r.get('summary') or ''}")
|
|
185
|
+
if not nums:
|
|
186
|
+
continue
|
|
187
|
+
targets.append((r, nums))
|
|
188
|
+
|
|
189
|
+
def _fetch_one(item: tuple[dict, list[dict[str, str]]]):
|
|
190
|
+
# 只返回载荷 (page, method):item 本身(r, nums)由 run_bounded 的
|
|
191
|
+
# finished 原样带回,调用方用 (*item, value) 拼回三元组——worker 再
|
|
192
|
+
# 捎一份 item 会造成双层嵌套(2026-11-01 实测踩中:并行路径
|
|
193
|
+
# page, method = val 炸 ValueError,单条串行路径测不出来)。
|
|
194
|
+
r, _nums = item
|
|
195
|
+
url = r.get("url") or ""
|
|
196
|
+
try:
|
|
197
|
+
fr = fetch_fn(url, max_chars=max_chars, timeout=timeout)
|
|
198
|
+
except Exception: # pragma: no cover
|
|
199
|
+
return None
|
|
200
|
+
page = (fr.get("content") or "") if isinstance(fr, dict) else ""
|
|
201
|
+
method = fr.get("fetch_method") if isinstance(fr, dict) else None
|
|
202
|
+
return page, method
|
|
203
|
+
|
|
204
|
+
# 墙钟预算与 verify 同一开关(ARGO_VERIFY_BUDGET_S,默认 5s):到点未回的
|
|
205
|
+
# URL 记 pending,语义与 fetch 失败一致
|
|
206
|
+
from evidence_loop import _verify_budget_s
|
|
207
|
+
budget_s = _verify_budget_s()
|
|
208
|
+
|
|
209
|
+
outcomes: list[tuple[dict, list, tuple[str, str] | None]] = []
|
|
210
|
+
pending: list[str] = []
|
|
211
|
+
if not targets:
|
|
212
|
+
pass
|
|
213
|
+
elif budget_s > 0 and len(targets) > 1:
|
|
214
|
+
from bounded_run import TaskError, run_bounded
|
|
215
|
+
finished, unfinished = run_bounded(
|
|
216
|
+
targets, _fetch_one, budget_s, max_workers=min(len(targets), 3))
|
|
217
|
+
for item, value in finished:
|
|
218
|
+
if isinstance(value, TaskError):
|
|
219
|
+
pending.append(item[0].get("url") or "")
|
|
220
|
+
continue
|
|
221
|
+
outcomes.append((*item, value))
|
|
222
|
+
for item in unfinished:
|
|
223
|
+
pending.append(item[0].get("url") or "")
|
|
224
|
+
else:
|
|
225
|
+
for item in targets:
|
|
226
|
+
val = _fetch_one(item)
|
|
227
|
+
if val is None:
|
|
228
|
+
pending.append(item[0].get("url") or "")
|
|
229
|
+
else:
|
|
230
|
+
outcomes.append((*item, val))
|
|
231
|
+
|
|
232
|
+
verified: list[dict[str, Any]] = []
|
|
233
|
+
counts = {"confirmed": 0, "partial": 0, "missing": 0, "unfetchable": 0}
|
|
234
|
+
for r, nums, val in outcomes:
|
|
235
|
+
page, method = val
|
|
236
|
+
if not page or len(page.strip()) < 100:
|
|
237
|
+
# 正文过短:无数可比,不伪造 verdict(unfetchable,不惩罚)
|
|
238
|
+
verdict, hits, misses = "unfetchable", [], [n["raw"] for n in nums]
|
|
239
|
+
else:
|
|
240
|
+
verdict, hits, misses = _verdict_for(nums, page)
|
|
241
|
+
counts[verdict] += 1
|
|
242
|
+
r["numeric_verification"] = {
|
|
243
|
+
"verdict": verdict,
|
|
244
|
+
"checked": [n["raw"] for n in nums],
|
|
245
|
+
"hits": hits,
|
|
246
|
+
"misses": misses,
|
|
247
|
+
"fetch_method": method,
|
|
248
|
+
}
|
|
249
|
+
verified.append({
|
|
250
|
+
"url": r.get("url") or "",
|
|
251
|
+
"title": (r.get("title") or "")[:120],
|
|
252
|
+
"verdict": verdict,
|
|
253
|
+
"hits": hits,
|
|
254
|
+
"misses": misses,
|
|
255
|
+
"fetch_method": method,
|
|
256
|
+
})
|
|
257
|
+
for url in pending:
|
|
258
|
+
counts["unfetchable"] += 1
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
"query": query,
|
|
262
|
+
"verified": verified,
|
|
263
|
+
"summary": {"checked": len(verified), **counts},
|
|
264
|
+
"pending": pending,
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def reorder_by_numeric(results: list[dict[str, Any]],
|
|
269
|
+
weight: float = 0.35) -> dict[str, Any]:
|
|
270
|
+
"""把数值印证的冲突信号写回排序(只降不升,中性=不动)。
|
|
271
|
+
|
|
272
|
+
missing → ×(1-weight) 摘要数字在原文里一个都没有:文不对题/毒内容
|
|
273
|
+
partial → ×(1-weight/2) 部分对不上:可能是改版/语境差异,弱惩罚
|
|
274
|
+
其余(confirmed/unfetchable/未核验)不动——未核验条目不参与比较,避免
|
|
275
|
+
「没验证的因为没被降权而反超」的采样偏差(与 reorder_by_evidence 同款)。
|
|
276
|
+
"""
|
|
277
|
+
if not results:
|
|
278
|
+
return {"reordered": False, "adjusted": [], "moved": 0}
|
|
279
|
+
try:
|
|
280
|
+
weight = max(0.0, min(1.0, float(weight)))
|
|
281
|
+
except (TypeError, ValueError):
|
|
282
|
+
weight = 0.35
|
|
283
|
+
|
|
284
|
+
adjusted: list[dict[str, Any]] = []
|
|
285
|
+
old_order = [(r.get("url") or "") for r in results]
|
|
286
|
+
for r in results:
|
|
287
|
+
if not isinstance(r, dict):
|
|
288
|
+
continue
|
|
289
|
+
nv = r.get("numeric_verification") or {}
|
|
290
|
+
verdict = nv.get("verdict")
|
|
291
|
+
if verdict not in ("missing", "partial"):
|
|
292
|
+
continue
|
|
293
|
+
try:
|
|
294
|
+
base = float(r.get("score") or 0.0)
|
|
295
|
+
except (TypeError, ValueError):
|
|
296
|
+
continue
|
|
297
|
+
factor = 1.0 - weight if verdict == "missing" else 1.0 - weight / 2.0
|
|
298
|
+
new_score = base * factor
|
|
299
|
+
if new_score == base:
|
|
300
|
+
continue
|
|
301
|
+
r["score"] = round(new_score, 4)
|
|
302
|
+
adjusted.append({
|
|
303
|
+
"url": r.get("url") or "",
|
|
304
|
+
"verdict": verdict,
|
|
305
|
+
"pre_score": round(base, 4),
|
|
306
|
+
"post_score": round(new_score, 4),
|
|
307
|
+
})
|
|
308
|
+
if not adjusted:
|
|
309
|
+
return {"reordered": False, "adjusted": [], "moved": 0}
|
|
310
|
+
results.sort(key=lambda r: r.get("score", 0) or 0, reverse=True)
|
|
311
|
+
new_order = [(r.get("url") or "") for r in results]
|
|
312
|
+
moved = sum(1 for i, u in enumerate(new_order)
|
|
313
|
+
if i < len(old_order) and u != old_order[i])
|
|
314
|
+
return {"reordered": True, "adjusted": adjusted, "moved": moved}
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def maybe_verify_numbers(results: list[dict[str, Any]],
|
|
318
|
+
query: str,
|
|
319
|
+
top_k: int = 3,
|
|
320
|
+
fetch_fn: Callable[..., dict[str, Any]] | None = None,
|
|
321
|
+
) -> Optional[dict[str, Any]]:
|
|
322
|
+
"""便利入口:无数字可核时返回 None(调用方不落任何键,输出逐位不变)。"""
|
|
323
|
+
has_nums = any(
|
|
324
|
+
isinstance(r, dict) and extract_critical_numbers(
|
|
325
|
+
f"{r.get('title') or ''} {r.get('snippet') or r.get('summary') or ''}")
|
|
326
|
+
for r in (results or [])[:max(top_k, 1) * 3]
|
|
327
|
+
)
|
|
328
|
+
if not has_nums:
|
|
329
|
+
return None
|
|
330
|
+
return numeric_verify_results(results, query, top_k=top_k, fetch_fn=fetch_fn)
|
package/scripts/plan.py
CHANGED
|
@@ -30,6 +30,7 @@ import hashlib
|
|
|
30
30
|
import os
|
|
31
31
|
import re
|
|
32
32
|
import sys
|
|
33
|
+
import time
|
|
33
34
|
from typing import Any, Literal
|
|
34
35
|
from urllib.parse import urlparse, parse_qsl, urlencode, urlunparse
|
|
35
36
|
from cli_io import dumps
|
|
@@ -41,6 +42,17 @@ _URL_RE = re.compile(r"https?://[^\s<>\"']+", re.I)
|
|
|
41
42
|
|
|
42
43
|
ExecutionTier = Literal["daily", "professional", "deep_research"]
|
|
43
44
|
|
|
45
|
+
# 按 URL 取单条的抽取引擎:query 本身就是要处理的目标(单条推文 URL、公网图片
|
|
46
|
+
# URL),显式指定时不能被 known-url handoff 当成「读链接」拦下。
|
|
47
|
+
URL_INPUT_ENGINES = frozenset(
|
|
48
|
+
{"twitter_syndication", "saucenao", "animetrace", "google_lens"}
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# 以图搜图引擎:返回的是「这张图出现在哪些作品/页面」,条目是出处页而非图片文件,
|
|
52
|
+
# 图片可用性过滤与空结果恢复链对它们都是错的判据(出处页没有分辨率,替身网页也不
|
|
53
|
+
# 是这张图)。显式只点这些引擎时,两处都要让路。
|
|
54
|
+
REVERSE_IMAGE_ENGINES = frozenset({"saucenao", "animetrace", "google_lens"})
|
|
55
|
+
|
|
44
56
|
|
|
45
57
|
def execution_tier(
|
|
46
58
|
mode: str = "auto",
|
|
@@ -173,8 +185,16 @@ def build_plan(
|
|
|
173
185
|
input_kind: str = "auto",
|
|
174
186
|
login_approved: bool = False,
|
|
175
187
|
context: str = "search",
|
|
188
|
+
timing: Any = None,
|
|
176
189
|
) -> dict[str, Any]:
|
|
177
|
-
"""离线计划。永不调用搜索后端;永不回调 super_search/research。
|
|
190
|
+
"""离线计划。永不调用搜索后端;永不回调 super_search/research。
|
|
191
|
+
|
|
192
|
+
timing:调用方传入的 StageTiming(`--timing` 时由 search_cli 构造)。
|
|
193
|
+
此前 plan-only 路径在 search.py 里 `return build_plan(...)` 直接返回,
|
|
194
|
+
既不走 route_query_cached 也不产生任何 timing 键——`--explain-timing`
|
|
195
|
+
在这条路径上恒为空,而它恰恰是「离线路由慢在哪」的唯一观测口。这里把
|
|
196
|
+
路由那段单独计时并挂到返回体的 `timing` 键(与主搜索同一结构)。
|
|
197
|
+
"""
|
|
178
198
|
kind = classify_input_kind(query, input_kind)
|
|
179
199
|
urls = extract_urls(query)
|
|
180
200
|
limitations: list[str] = []
|
|
@@ -277,12 +297,20 @@ def build_plan(
|
|
|
277
297
|
}
|
|
278
298
|
|
|
279
299
|
# ── 正常 keyword / url-seed:保持一致 route_query(离线,无网络)──
|
|
300
|
+
# 走 route_query_cached 而非 route_query:同一个路由决策,search 主路径
|
|
301
|
+
# (search.py:746)早已走缓存,plan-only 这条离线路径此前是唯一不走的——
|
|
302
|
+
# 实测冷进程 route_query 47ms vs route_query_cached 命中 4ms,而 plan-only
|
|
303
|
+
# 是「本该最快」的那条路径,没理由每次重付。缓存契约(命中返回深拷贝、
|
|
304
|
+
# 不改变功能)由 tests/test_route_cache.py 锁住;本函数只读 decision。
|
|
280
305
|
try:
|
|
281
|
-
from route import
|
|
282
|
-
|
|
306
|
+
from route import route_query_cached
|
|
307
|
+
_t_route = time.perf_counter() if timing is not None else None
|
|
308
|
+
decision = route_query_cached(
|
|
283
309
|
search_query, engine_override=engine, mode=mode,
|
|
284
310
|
depth=depth, context=context,
|
|
285
311
|
)
|
|
312
|
+
if timing is not None and _t_route is not None:
|
|
313
|
+
timing.add("route", (time.perf_counter() - _t_route) * 1000.0)
|
|
286
314
|
except Exception as e:
|
|
287
315
|
return {
|
|
288
316
|
"schema_version": "1.0",
|
|
@@ -348,7 +376,7 @@ def build_plan(
|
|
|
348
376
|
if max_results > 10:
|
|
349
377
|
limitations.append("Some backends clamp max_results ≤10; request may be truncated per engine.")
|
|
350
378
|
|
|
351
|
-
|
|
379
|
+
out = {
|
|
352
380
|
"schema_version": "1.0",
|
|
353
381
|
"status": "ready",
|
|
354
382
|
"authorization": "not_required",
|
|
@@ -381,6 +409,10 @@ def build_plan(
|
|
|
381
409
|
"mode": mode,
|
|
382
410
|
"depth": depth,
|
|
383
411
|
}
|
|
412
|
+
# timing 只在调用方显式传入时出现(`--timing`),默认输出结构逐字节不变。
|
|
413
|
+
if timing is not None:
|
|
414
|
+
out["timing"] = timing.summary()
|
|
415
|
+
return out
|
|
384
416
|
|
|
385
417
|
|
|
386
418
|
def main() -> int:
|
package/scripts/pre-commit
CHANGED
|
@@ -5,15 +5,18 @@
|
|
|
5
5
|
# 6 道门禁红 + 阻塞全量收集,故障在树里躺了幾小时才被人工发现。「改了没
|
|
6
6
|
# 验证就提交」没有机制拦截,只靠自觉。本 hook 把拦截点放在提交层。
|
|
7
7
|
#
|
|
8
|
-
#
|
|
8
|
+
# 只跑快的八道(实测合计 ~12s):static_lint(语法/重复键/未声明 env)、
|
|
9
9
|
# module_size_gate(1000 行门禁与祖父登记)、usage_doc(ARGO_* 开关总表)、
|
|
10
10
|
# consistency(版本/徽章/工具数五语对账)、routing_snapshot(路由决策漂移)、
|
|
11
|
-
# context_budget + engine_catalog
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
11
|
+
# context_budget + engine_catalog(常驻文档预算、源文档/死源/声明一致)、
|
|
12
|
+
# spec_contracts + stub_targets(2026-11-04 补的 B 类复发护栏:规格契约
|
|
13
|
+
# ——bilibili/xhs 缺 --json 同类根因;打桩目标存在性——重构后打桩落转出
|
|
14
|
+
# 副本的三例同类根因,实测合计 +0.7s)。
|
|
15
|
+
# 2026-10-18 补的两道(context_budget + engine_catalog):f702ee2 把
|
|
16
|
+
# SKILL.md 压到 8049B、4a71693 让 deepseek_search 成死源,两笔都过了 hook
|
|
17
|
+
# 却在全量回归里红——正是「改完没跑到那条门」的同一个洞。全量回归 ~5 分钟
|
|
18
|
+
# 留给 CI 或手动(python3 -m pytest tests/ -q),不进 hook——hook 慢于 20s
|
|
19
|
+
# 就会被用户 --no-verify 绕过,那是更坏的结局。
|
|
17
20
|
#
|
|
18
21
|
# 安装:bash scripts/install.sh 自动装(链式:不覆盖 privacy-guard 等既有
|
|
19
22
|
# hook,装成 hooks/pre-commit-argo 并追一行调用)。手动:
|
|
@@ -35,11 +38,14 @@ cd "$root" || exit 1
|
|
|
35
38
|
# 裸 `command -v python3`——2026-10-26 实测,默认 PATH 的 python3 是 3.15
|
|
36
39
|
# (无 pytest),hook 每次提交都死在 pytest 收集之前,拦截层形同虚设。
|
|
37
40
|
# 与 6971c73 给 eval 侧加的自愈重入是同一类根因(解释器选择散落多处、没有
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
+
# 单一真源),这里把门禁这一处也收进候选链。2026-11-04 补 .venv 首选:
|
|
42
|
+
# homebrew 升级清掉 python3.14 后候选链第 4 次漂移断链,根治靠仓内钉版
|
|
43
|
+
# .venv(uv venv .venv --python 3.14 && uv pip install -p .venv -r
|
|
44
|
+
# requirements-dev.txt),PATH 散装解释器只作回落。真 import 而非 find_spec:
|
|
45
|
+
# 半装的 pytest、被 sitecustomize 顶掉的包都属「说在其实不在」(见 bin/argo
|
|
46
|
+
# 严格档的同类教训)。候选全空时维持原口径 fail closed,绝不静默放行。
|
|
41
47
|
PY=""
|
|
42
|
-
for cand in "${ARGO_GATE_PYTHON:-}" python3.14 python3 python; do
|
|
48
|
+
for cand in "${ARGO_GATE_PYTHON:-}" .venv/bin/python python3.14 python3.13 python3.12 python3.11 python3.10 python3 python; do
|
|
43
49
|
if [ -n "$cand" ] && command -v "$cand" >/dev/null 2>&1 \
|
|
44
50
|
&& "$cand" -c "import pytest, yaml" >/dev/null 2>&1; then
|
|
45
51
|
PY=$cand
|
|
@@ -47,7 +53,7 @@ for cand in "${ARGO_GATE_PYTHON:-}" python3.14 python3 python; do
|
|
|
47
53
|
fi
|
|
48
54
|
done
|
|
49
55
|
if [ -z "$PY" ]; then
|
|
50
|
-
echo "[pre-commit] 找不到带 pytest+yaml 的解释器(候选:\$ARGO_GATE_PYTHON、python3.14、python3、python),门禁视为失败" >&2
|
|
56
|
+
echo "[pre-commit] 找不到带 pytest+yaml 的解释器(候选:\$ARGO_GATE_PYTHON、仓内 .venv、python3.14/3.13/3.12/3.11/3.10、python3、python),门禁视为失败" >&2
|
|
51
57
|
exit 1
|
|
52
58
|
fi
|
|
53
59
|
|
|
@@ -60,4 +66,6 @@ echo "[pre-commit] argo 快门禁(~12s,解释器 $PY;全量回归请手动
|
|
|
60
66
|
tests/test_routing_snapshot.py \
|
|
61
67
|
tests/test_context_budget.py \
|
|
62
68
|
tests/test_engine_catalog.py \
|
|
63
|
-
tests/test_release_consistency.py
|
|
69
|
+
tests/test_release_consistency.py \
|
|
70
|
+
tests/test_spec_contracts.py \
|
|
71
|
+
tests/test_stub_targets.py
|
package/scripts/quota.py
CHANGED
|
@@ -145,11 +145,71 @@ def _at_or_over_budget(cost_used: float, budget: float) -> bool:
|
|
|
145
145
|
return round(float(cost_used), 6) >= round(float(budget), 6)
|
|
146
146
|
|
|
147
147
|
|
|
148
|
+
# 远端配额报错的默认冷却(秒):不依赖 profile 的 period 字段(那是本地记账
|
|
149
|
+
# 周期)。远端配额报错分两类,“多久能好”取决于归因类别,而不取决于“这条限制
|
|
150
|
+
# 是按天还是按月”:
|
|
151
|
+
# - 预充值余额不足(HTTP 402 insufficient balance / “not enough money”):
|
|
152
|
+
# 账户余额问题,充值或换 Key 立即恢复,绝不会到月底自动恢复。锁 30 天是
|
|
153
|
+
# 最坏组合(#42 实测:充值后每次调用 55ms 返回 skipped,自愈日期写着下月)。
|
|
154
|
+
# 默认 1h——够覆盖一次误充/换 Key 的操作窗口,又不至于让用户干等。
|
|
155
|
+
# - 免费额度耗尽(10406 Free quota exhausted 等):多数按下月重置,沿用既有
|
|
156
|
+
# period 口径(默认 24h 兜底,避免 second/minute 的限频周期被误当配额周期)。
|
|
157
|
+
# 换 Key 自愈(key_fp 对比)对两类都生效,见 _mark_expired。
|
|
158
|
+
_BALANCE_QUOTA_COOLDOWN_S = 3600
|
|
159
|
+
_DEFAULT_QUOTA_COOLDOWN_S = 86400
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _quota_cooldown_seconds(category: str | None, reason: str,
|
|
163
|
+
period: str | None) -> int:
|
|
164
|
+
"""远端配额耗尽的冷却秒数(单一计算点,mark 与文案都读它)。
|
|
165
|
+
|
|
166
|
+
余额不足类固定短冷却、与 period 解耦;其余按 period 映射,过短按 24h 兜底。
|
|
167
|
+
坏值一律回落默认,不让一次异常把某种引擎永久锁死。
|
|
168
|
+
"""
|
|
169
|
+
if category == "quota_exhausted" and _looks_like_balance_error(reason):
|
|
170
|
+
return _BALANCE_QUOTA_COOLDOWN_S
|
|
171
|
+
seconds = {"hour": 3600, "day": 86400, "month": 30 * 86400}.get(
|
|
172
|
+
str(period or "day"), _DEFAULT_QUOTA_COOLDOWN_S)
|
|
173
|
+
return seconds if seconds >= 3600 else _DEFAULT_QUOTA_COOLDOWN_S
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _looks_like_balance_error(reason: str) -> bool:
|
|
177
|
+
"""错误文本是否是「账户余额不足」(预充值用尽,充值即恢复)。"""
|
|
178
|
+
m = str(reason or "").lower()
|
|
179
|
+
return any(k in m for k in ("insufficient balance", "insufficient funds",
|
|
180
|
+
"not enough money", "余额不足", "402"))
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def _required_candidates(engine: str, spec: dict[str, Any]) -> list[str]:
|
|
184
|
+
"""引擎 key 的候选环境变量名(含 ARGO_ 变体与占位符别名展开)。
|
|
185
|
+
|
|
186
|
+
与 engine_env.missing_env_for 的候选构造同源;这里只是把「候选」摊平成
|
|
187
|
+
一条可读的名单,供取指纹用。无 required_env 时返回空(由调用方回退)。
|
|
188
|
+
"""
|
|
189
|
+
from engine_env import PLACEHOLDER_ALIASES
|
|
190
|
+
explicit = spec.get("required_env")
|
|
191
|
+
if not explicit:
|
|
192
|
+
return []
|
|
193
|
+
out: list[str] = []
|
|
194
|
+
for item in explicit:
|
|
195
|
+
if isinstance(item, list):
|
|
196
|
+
out.extend(str(x) for x in item if x)
|
|
197
|
+
elif isinstance(item, str) and item:
|
|
198
|
+
if item in PLACEHOLDER_ALIASES:
|
|
199
|
+
out.extend(PLACEHOLDER_ALIASES[item])
|
|
200
|
+
elif item.startswith("ARGO_"):
|
|
201
|
+
out.extend([item, item[len("ARGO_"):]])
|
|
202
|
+
else:
|
|
203
|
+
out.extend([f"ARGO_{item}", item])
|
|
204
|
+
return out
|
|
205
|
+
|
|
206
|
+
|
|
148
207
|
class QuotaManager:
|
|
149
208
|
"""配额追踪与消耗速率计算(v2)。"""
|
|
150
209
|
|
|
151
|
-
|
|
152
|
-
#
|
|
210
|
+
|
|
211
|
+
# 远端配额周期候选(模块级 _quota_cooldown_seconds 是唯一计算点;本地
|
|
212
|
+
# period=second/minute 只是限频口径,不代表远端配额周期,过短按 24h 兜底)
|
|
153
213
|
_PERIOD_SECONDS = {"hour": 3600, "day": 86400, "month": 30 * 86400}
|
|
154
214
|
|
|
155
215
|
def __init__(self):
|
|
@@ -405,12 +465,48 @@ class QuotaManager:
|
|
|
405
465
|
|
|
406
466
|
@staticmethod
|
|
407
467
|
def _engine_key_fp(engine: str) -> str:
|
|
408
|
-
"""当前引擎生效密钥的短指纹(8 hex);无密钥或读取失败返回空串。
|
|
468
|
+
"""当前引擎生效密钥的短指纹(8 hex);无密钥或读取失败返回空串。
|
|
469
|
+
|
|
470
|
+
**必须与实际取 key 的地方同源**(issue #42):指纹的用途是「换 Key 就
|
|
471
|
+
自愈」,所以它算的必须是引擎运行时真正读的那个环境变量。此前用
|
|
472
|
+
resolve_env_name 按 `<ENGINE>_API_KEY` 拼名,与 spec.required_env 对不上
|
|
473
|
+
的 13 个引擎(deepseek_search 读 DEEPSEEK_API_KEY、metaso_* 读
|
|
474
|
+
ARGO_METASO_API_KEY、you 读 YDC_API_KEY 等)指纹恒为空串,于是
|
|
475
|
+
`_mark_expired` 的换 Key 分支永远不触发,换新 Key 也解不了熔断。
|
|
476
|
+
改为与 search._missing_env_for 同一条链:先取 spec,用
|
|
477
|
+
required_env_for/missing_env_for 的候选解析逻辑取值,无 spec 再回退
|
|
478
|
+
resolve_env_name。任一候选有值即算命中——与「路由认为它可用」同口径。
|
|
479
|
+
"""
|
|
409
480
|
try:
|
|
410
481
|
import hashlib
|
|
411
|
-
from engine_env import get_env, resolve_env_name
|
|
412
|
-
|
|
413
|
-
|
|
482
|
+
from engine_env import get_env, missing_env_for, resolve_env_name
|
|
483
|
+
spec = None
|
|
484
|
+
try:
|
|
485
|
+
from engines import get_engine_spec
|
|
486
|
+
spec = get_engine_spec(engine)
|
|
487
|
+
except Exception:
|
|
488
|
+
spec = None
|
|
489
|
+
val = ""
|
|
490
|
+
if spec is not None:
|
|
491
|
+
# required_env 声明的是「主名」,但候选链(PLACEHOLDER_ALIASES /
|
|
492
|
+
# ARGO_ 变体)里任一有值都算配置了 key——与 missing_env_for 同源。
|
|
493
|
+
missing = missing_env_for(engine, spec)
|
|
494
|
+
if not missing:
|
|
495
|
+
# 有声明且都齐了:取主名的实际值算指纹
|
|
496
|
+
from engine_env import required_env_for
|
|
497
|
+
for name in required_env_for(engine, spec):
|
|
498
|
+
cand = [name] if name.startswith("ARGO_") else [f"ARGO_{name}", name]
|
|
499
|
+
got = get_env(cand)
|
|
500
|
+
if got:
|
|
501
|
+
val = got
|
|
502
|
+
break
|
|
503
|
+
else:
|
|
504
|
+
# 声明了但缺:仍尝试按声明候选读(可能只有可选键齐)
|
|
505
|
+
val = get_env(_required_candidates(engine, spec))
|
|
506
|
+
if not val:
|
|
507
|
+
val = get_env(resolve_env_name(engine))
|
|
508
|
+
return (hashlib.sha256(val.encode("utf-8")).hexdigest()[:8]
|
|
509
|
+
if val else "")
|
|
414
510
|
except Exception:
|
|
415
511
|
return ""
|
|
416
512
|
|
|
@@ -427,13 +523,18 @@ class QuotaManager:
|
|
|
427
523
|
return False
|
|
428
524
|
|
|
429
525
|
def mark_remote_exhausted(self, engine: str, reason: str = "",
|
|
430
|
-
period: str | None = None
|
|
526
|
+
period: str | None = None,
|
|
527
|
+
category: str | None = None) -> None:
|
|
431
528
|
"""远端明示「配额耗尽」(如火山 10406 Free quota exhausted)时调用。
|
|
432
529
|
|
|
433
530
|
设计目标:配额问题不需要人工改配置——标记后路由组合层全模式排除
|
|
434
531
|
该引擎,备用源自然接管;到下一周期边界或更换新 Key 时惰性自愈(is_available /
|
|
435
532
|
is_hard_down 检查时清除),恢复后引擎自动回归。提前恢复(如原 Key 充值)
|
|
436
533
|
可执行 `python3 scripts/quota.py reset <engine>`。
|
|
534
|
+
|
|
535
|
+
`category`(如 "quota_exhausted")与 `reason` 一起决定冷却时长:余额不足
|
|
536
|
+
类(402 insufficient balance)与月度预算周期解耦、固定短冷却,避免一次
|
|
537
|
+
欠费把引擎锁死 30 天(issue #42)。
|
|
437
538
|
"""
|
|
438
539
|
key_fp = self._engine_key_fp(engine)
|
|
439
540
|
with self._lock:
|
|
@@ -444,9 +545,7 @@ class QuotaManager:
|
|
|
444
545
|
})
|
|
445
546
|
profile = self._profiles.get(engine, {})
|
|
446
547
|
p = period or profile.get("period") or "day"
|
|
447
|
-
seconds =
|
|
448
|
-
if seconds < 3600:
|
|
449
|
-
seconds = 86400
|
|
548
|
+
seconds = _quota_cooldown_seconds(category, reason, p)
|
|
450
549
|
st["remote_exhausted"] = {
|
|
451
550
|
"until": time.time() + seconds,
|
|
452
551
|
"reason": (reason or "")[:200],
|